]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.8.5-201304022025.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.5-201304022025.patch
CommitLineData
1cc08c9e
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 14b38cf..90b3a74 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+HOSTCLFAGS += $(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..0e40765 100644
810--- a/arch/arm/Kconfig
811+++ b/arch/arm/Kconfig
812@@ -1813,7 +1813,7 @@ config ALIGNMENT_TRAP
813
814 config UACCESS_WITH_MEMCPY
815 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
816- depends on MMU
817+ depends on MMU && !PAX_MEMORY_UDEREF
818 default y if CPU_FEROCEON
819 help
820 Implement faster copy_to_user and clear_user methods for CPU
821diff --git a/arch/arm/common/gic.c b/arch/arm/common/gic.c
822index 87dfa902..3a523fc 100644
823--- a/arch/arm/common/gic.c
824+++ b/arch/arm/common/gic.c
825@@ -81,7 +81,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
826 * Supported arch specific GIC irq extension.
827 * Default make them NULL.
828 */
829-struct irq_chip gic_arch_extn = {
830+irq_chip_no_const gic_arch_extn __read_only = {
831 .irq_eoi = NULL,
832 .irq_mask = NULL,
833 .irq_unmask = NULL,
834@@ -329,7 +329,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
835 chained_irq_exit(chip, desc);
836 }
837
838-static struct irq_chip gic_chip = {
839+static irq_chip_no_const gic_chip __read_only = {
840 .name = "GIC",
841 .irq_mask = gic_mask_irq,
842 .irq_unmask = gic_unmask_irq,
843diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
844index c79f61f..9ac0642 100644
845--- a/arch/arm/include/asm/atomic.h
846+++ b/arch/arm/include/asm/atomic.h
847@@ -17,17 +17,35 @@
848 #include <asm/barrier.h>
849 #include <asm/cmpxchg.h>
850
851+#ifdef CONFIG_GENERIC_ATOMIC64
852+#include <asm-generic/atomic64.h>
853+#endif
854+
855 #define ATOMIC_INIT(i) { (i) }
856
857 #ifdef __KERNEL__
858
859+#define _ASM_EXTABLE(from, to) \
860+" .pushsection __ex_table,\"a\"\n"\
861+" .align 3\n" \
862+" .long " #from ", " #to"\n" \
863+" .popsection"
864+
865 /*
866 * On ARM, ordinary assignment (str instruction) doesn't clear the local
867 * strex/ldrex monitor on some implementations. The reason we can use it for
868 * atomic_set() is the clrex or dummy strex done on every exception return.
869 */
870 #define atomic_read(v) (*(volatile int *)&(v)->counter)
871+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
872+{
873+ return v->counter;
874+}
875 #define atomic_set(v,i) (((v)->counter) = (i))
876+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
877+{
878+ v->counter = i;
879+}
880
881 #if __LINUX_ARM_ARCH__ >= 6
882
883@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
884 int result;
885
886 __asm__ __volatile__("@ atomic_add\n"
887+"1: ldrex %1, [%3]\n"
888+" adds %0, %1, %4\n"
889+
890+#ifdef CONFIG_PAX_REFCOUNT
891+" bvc 3f\n"
892+"2: bkpt 0xf103\n"
893+"3:\n"
894+#endif
895+
896+" strex %1, %0, [%3]\n"
897+" teq %1, #0\n"
898+" bne 1b"
899+
900+#ifdef CONFIG_PAX_REFCOUNT
901+"\n4:\n"
902+ _ASM_EXTABLE(2b, 4b)
903+#endif
904+
905+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
906+ : "r" (&v->counter), "Ir" (i)
907+ : "cc");
908+}
909+
910+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
911+{
912+ unsigned long tmp;
913+ int result;
914+
915+ __asm__ __volatile__("@ atomic_add_unchecked\n"
916 "1: ldrex %0, [%3]\n"
917 " add %0, %0, %4\n"
918 " strex %1, %0, [%3]\n"
919@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
920 smp_mb();
921
922 __asm__ __volatile__("@ atomic_add_return\n"
923+"1: ldrex %1, [%3]\n"
924+" adds %0, %1, %4\n"
925+
926+#ifdef CONFIG_PAX_REFCOUNT
927+" bvc 3f\n"
928+" mov %0, %1\n"
929+"2: bkpt 0xf103\n"
930+"3:\n"
931+#endif
932+
933+" strex %1, %0, [%3]\n"
934+" teq %1, #0\n"
935+" bne 1b"
936+
937+#ifdef CONFIG_PAX_REFCOUNT
938+"\n4:\n"
939+ _ASM_EXTABLE(2b, 4b)
940+#endif
941+
942+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
943+ : "r" (&v->counter), "Ir" (i)
944+ : "cc");
945+
946+ smp_mb();
947+
948+ return result;
949+}
950+
951+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
952+{
953+ unsigned long tmp;
954+ int result;
955+
956+ smp_mb();
957+
958+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
959 "1: ldrex %0, [%3]\n"
960 " add %0, %0, %4\n"
961 " strex %1, %0, [%3]\n"
962@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
963 int result;
964
965 __asm__ __volatile__("@ atomic_sub\n"
966+"1: ldrex %1, [%3]\n"
967+" subs %0, %1, %4\n"
968+
969+#ifdef CONFIG_PAX_REFCOUNT
970+" bvc 3f\n"
971+"2: bkpt 0xf103\n"
972+"3:\n"
973+#endif
974+
975+" strex %1, %0, [%3]\n"
976+" teq %1, #0\n"
977+" bne 1b"
978+
979+#ifdef CONFIG_PAX_REFCOUNT
980+"\n4:\n"
981+ _ASM_EXTABLE(2b, 4b)
982+#endif
983+
984+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
985+ : "r" (&v->counter), "Ir" (i)
986+ : "cc");
987+}
988+
989+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
990+{
991+ unsigned long tmp;
992+ int result;
993+
994+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
995 "1: ldrex %0, [%3]\n"
996 " sub %0, %0, %4\n"
997 " strex %1, %0, [%3]\n"
998@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
999 smp_mb();
1000
1001 __asm__ __volatile__("@ atomic_sub_return\n"
1002-"1: ldrex %0, [%3]\n"
1003-" sub %0, %0, %4\n"
1004+"1: ldrex %1, [%3]\n"
1005+" subs %0, %1, %4\n"
1006+
1007+#ifdef CONFIG_PAX_REFCOUNT
1008+" bvc 3f\n"
1009+" mov %0, %1\n"
1010+"2: bkpt 0xf103\n"
1011+"3:\n"
1012+#endif
1013+
1014 " strex %1, %0, [%3]\n"
1015 " teq %1, #0\n"
1016 " bne 1b"
1017+
1018+#ifdef CONFIG_PAX_REFCOUNT
1019+"\n4:\n"
1020+ _ASM_EXTABLE(2b, 4b)
1021+#endif
1022+
1023 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1024 : "r" (&v->counter), "Ir" (i)
1025 : "cc");
1026@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1027 return oldval;
1028 }
1029
1030+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1031+{
1032+ unsigned long oldval, res;
1033+
1034+ smp_mb();
1035+
1036+ do {
1037+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1038+ "ldrex %1, [%3]\n"
1039+ "mov %0, #0\n"
1040+ "teq %1, %4\n"
1041+ "strexeq %0, %5, [%3]\n"
1042+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1043+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1044+ : "cc");
1045+ } while (res);
1046+
1047+ smp_mb();
1048+
1049+ return oldval;
1050+}
1051+
1052 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1053 {
1054 unsigned long tmp, tmp2;
1055@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1056
1057 return val;
1058 }
1059+
1060+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1061+{
1062+ return atomic_add_return(i, v);
1063+}
1064+
1065 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1066+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1067+{
1068+ (void) atomic_add_return(i, v);
1069+}
1070
1071 static inline int atomic_sub_return(int i, atomic_t *v)
1072 {
1073@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1074 return val;
1075 }
1076 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1077+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1078+{
1079+ (void) atomic_sub_return(i, v);
1080+}
1081
1082 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1083 {
1084@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1085 return ret;
1086 }
1087
1088+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1089+{
1090+ return atomic_cmpxchg(v, old, new);
1091+}
1092+
1093 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1094 {
1095 unsigned long flags;
1096@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1097 #endif /* __LINUX_ARM_ARCH__ */
1098
1099 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1100+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1101+{
1102+ return xchg(&v->counter, new);
1103+}
1104
1105 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1106 {
1107@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1108 }
1109
1110 #define atomic_inc(v) atomic_add(1, v)
1111+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1112+{
1113+ atomic_add_unchecked(1, v);
1114+}
1115 #define atomic_dec(v) atomic_sub(1, v)
1116+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1117+{
1118+ atomic_sub_unchecked(1, v);
1119+}
1120
1121 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1122+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1123+{
1124+ return atomic_add_return_unchecked(1, v) == 0;
1125+}
1126 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1127 #define atomic_inc_return(v) (atomic_add_return(1, v))
1128+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1129+{
1130+ return atomic_add_return_unchecked(1, v);
1131+}
1132 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1133 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1134
1135@@ -241,6 +428,14 @@ typedef struct {
1136 u64 __aligned(8) counter;
1137 } atomic64_t;
1138
1139+#ifdef CONFIG_PAX_REFCOUNT
1140+typedef struct {
1141+ u64 __aligned(8) counter;
1142+} atomic64_unchecked_t;
1143+#else
1144+typedef atomic64_t atomic64_unchecked_t;
1145+#endif
1146+
1147 #define ATOMIC64_INIT(i) { (i) }
1148
1149 static inline u64 atomic64_read(const atomic64_t *v)
1150@@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1151 return result;
1152 }
1153
1154+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1155+{
1156+ u64 result;
1157+
1158+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1159+" ldrexd %0, %H0, [%1]"
1160+ : "=&r" (result)
1161+ : "r" (&v->counter), "Qo" (v->counter)
1162+ );
1163+
1164+ return result;
1165+}
1166+
1167 static inline void atomic64_set(atomic64_t *v, u64 i)
1168 {
1169 u64 tmp;
1170@@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1171 : "cc");
1172 }
1173
1174+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1175+{
1176+ u64 tmp;
1177+
1178+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1179+"1: ldrexd %0, %H0, [%2]\n"
1180+" strexd %0, %3, %H3, [%2]\n"
1181+" teq %0, #0\n"
1182+" bne 1b"
1183+ : "=&r" (tmp), "=Qo" (v->counter)
1184+ : "r" (&v->counter), "r" (i)
1185+ : "cc");
1186+}
1187+
1188 static inline void atomic64_add(u64 i, atomic64_t *v)
1189 {
1190 u64 result;
1191@@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1192 __asm__ __volatile__("@ atomic64_add\n"
1193 "1: ldrexd %0, %H0, [%3]\n"
1194 " adds %0, %0, %4\n"
1195+" adcs %H0, %H0, %H4\n"
1196+
1197+#ifdef CONFIG_PAX_REFCOUNT
1198+" bvc 3f\n"
1199+"2: bkpt 0xf103\n"
1200+"3:\n"
1201+#endif
1202+
1203+" strexd %1, %0, %H0, [%3]\n"
1204+" teq %1, #0\n"
1205+" bne 1b"
1206+
1207+#ifdef CONFIG_PAX_REFCOUNT
1208+"\n4:\n"
1209+ _ASM_EXTABLE(2b, 4b)
1210+#endif
1211+
1212+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1213+ : "r" (&v->counter), "r" (i)
1214+ : "cc");
1215+}
1216+
1217+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1218+{
1219+ u64 result;
1220+ unsigned long tmp;
1221+
1222+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1223+"1: ldrexd %0, %H0, [%3]\n"
1224+" adds %0, %0, %4\n"
1225 " adc %H0, %H0, %H4\n"
1226 " strexd %1, %0, %H0, [%3]\n"
1227 " teq %1, #0\n"
1228@@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1229
1230 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1231 {
1232- u64 result;
1233- unsigned long tmp;
1234+ u64 result, tmp;
1235
1236 smp_mb();
1237
1238 __asm__ __volatile__("@ atomic64_add_return\n"
1239+"1: ldrexd %1, %H1, [%3]\n"
1240+" adds %0, %1, %4\n"
1241+" adcs %H0, %H1, %H4\n"
1242+
1243+#ifdef CONFIG_PAX_REFCOUNT
1244+" bvc 3f\n"
1245+" mov %0, %1\n"
1246+" mov %H0, %H1\n"
1247+"2: bkpt 0xf103\n"
1248+"3:\n"
1249+#endif
1250+
1251+" strexd %1, %0, %H0, [%3]\n"
1252+" teq %1, #0\n"
1253+" bne 1b"
1254+
1255+#ifdef CONFIG_PAX_REFCOUNT
1256+"\n4:\n"
1257+ _ASM_EXTABLE(2b, 4b)
1258+#endif
1259+
1260+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1261+ : "r" (&v->counter), "r" (i)
1262+ : "cc");
1263+
1264+ smp_mb();
1265+
1266+ return result;
1267+}
1268+
1269+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1270+{
1271+ u64 result;
1272+ unsigned long tmp;
1273+
1274+ smp_mb();
1275+
1276+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1277 "1: ldrexd %0, %H0, [%3]\n"
1278 " adds %0, %0, %4\n"
1279 " adc %H0, %H0, %H4\n"
1280@@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1281 __asm__ __volatile__("@ atomic64_sub\n"
1282 "1: ldrexd %0, %H0, [%3]\n"
1283 " subs %0, %0, %4\n"
1284+" sbcs %H0, %H0, %H4\n"
1285+
1286+#ifdef CONFIG_PAX_REFCOUNT
1287+" bvc 3f\n"
1288+"2: bkpt 0xf103\n"
1289+"3:\n"
1290+#endif
1291+
1292+" strexd %1, %0, %H0, [%3]\n"
1293+" teq %1, #0\n"
1294+" bne 1b"
1295+
1296+#ifdef CONFIG_PAX_REFCOUNT
1297+"\n4:\n"
1298+ _ASM_EXTABLE(2b, 4b)
1299+#endif
1300+
1301+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1302+ : "r" (&v->counter), "r" (i)
1303+ : "cc");
1304+}
1305+
1306+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1307+{
1308+ u64 result;
1309+ unsigned long tmp;
1310+
1311+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1312+"1: ldrexd %0, %H0, [%3]\n"
1313+" subs %0, %0, %4\n"
1314 " sbc %H0, %H0, %H4\n"
1315 " strexd %1, %0, %H0, [%3]\n"
1316 " teq %1, #0\n"
1317@@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1318
1319 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1320 {
1321- u64 result;
1322- unsigned long tmp;
1323+ u64 result, tmp;
1324
1325 smp_mb();
1326
1327 __asm__ __volatile__("@ atomic64_sub_return\n"
1328-"1: ldrexd %0, %H0, [%3]\n"
1329-" subs %0, %0, %4\n"
1330-" sbc %H0, %H0, %H4\n"
1331+"1: ldrexd %1, %H1, [%3]\n"
1332+" subs %0, %1, %4\n"
1333+" sbcs %H0, %H1, %H4\n"
1334+
1335+#ifdef CONFIG_PAX_REFCOUNT
1336+" bvc 3f\n"
1337+" mov %0, %1\n"
1338+" mov %H0, %H1\n"
1339+"2: bkpt 0xf103\n"
1340+"3:\n"
1341+#endif
1342+
1343 " strexd %1, %0, %H0, [%3]\n"
1344 " teq %1, #0\n"
1345 " bne 1b"
1346+
1347+#ifdef CONFIG_PAX_REFCOUNT
1348+"\n4:\n"
1349+ _ASM_EXTABLE(2b, 4b)
1350+#endif
1351+
1352 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1353 : "r" (&v->counter), "r" (i)
1354 : "cc");
1355@@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1356 return oldval;
1357 }
1358
1359+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1360+{
1361+ u64 oldval;
1362+ unsigned long res;
1363+
1364+ smp_mb();
1365+
1366+ do {
1367+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1368+ "ldrexd %1, %H1, [%3]\n"
1369+ "mov %0, #0\n"
1370+ "teq %1, %4\n"
1371+ "teqeq %H1, %H4\n"
1372+ "strexdeq %0, %5, %H5, [%3]"
1373+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1374+ : "r" (&ptr->counter), "r" (old), "r" (new)
1375+ : "cc");
1376+ } while (res);
1377+
1378+ smp_mb();
1379+
1380+ return oldval;
1381+}
1382+
1383 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1384 {
1385 u64 result;
1386@@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1387
1388 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1389 {
1390- u64 result;
1391- unsigned long tmp;
1392+ u64 result, tmp;
1393
1394 smp_mb();
1395
1396 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1397-"1: ldrexd %0, %H0, [%3]\n"
1398-" subs %0, %0, #1\n"
1399-" sbc %H0, %H0, #0\n"
1400+"1: ldrexd %1, %H1, [%3]\n"
1401+" subs %0, %1, #1\n"
1402+" sbcs %H0, %H1, #0\n"
1403+
1404+#ifdef CONFIG_PAX_REFCOUNT
1405+" bvc 3f\n"
1406+" mov %0, %1\n"
1407+" mov %H0, %H1\n"
1408+"2: bkpt 0xf103\n"
1409+"3:\n"
1410+#endif
1411+
1412 " teq %H0, #0\n"
1413-" bmi 2f\n"
1414+" bmi 4f\n"
1415 " strexd %1, %0, %H0, [%3]\n"
1416 " teq %1, #0\n"
1417 " bne 1b\n"
1418-"2:"
1419+"4:\n"
1420+
1421+#ifdef CONFIG_PAX_REFCOUNT
1422+ _ASM_EXTABLE(2b, 4b)
1423+#endif
1424+
1425 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1426 : "r" (&v->counter)
1427 : "cc");
1428@@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1429 " teq %0, %5\n"
1430 " teqeq %H0, %H5\n"
1431 " moveq %1, #0\n"
1432-" beq 2f\n"
1433+" beq 4f\n"
1434 " adds %0, %0, %6\n"
1435-" adc %H0, %H0, %H6\n"
1436+" adcs %H0, %H0, %H6\n"
1437+
1438+#ifdef CONFIG_PAX_REFCOUNT
1439+" bvc 3f\n"
1440+"2: bkpt 0xf103\n"
1441+"3:\n"
1442+#endif
1443+
1444 " strexd %2, %0, %H0, [%4]\n"
1445 " teq %2, #0\n"
1446 " bne 1b\n"
1447-"2:"
1448+"4:\n"
1449+
1450+#ifdef CONFIG_PAX_REFCOUNT
1451+ _ASM_EXTABLE(2b, 4b)
1452+#endif
1453+
1454 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1455 : "r" (&v->counter), "r" (u), "r" (a)
1456 : "cc");
1457@@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1458
1459 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1460 #define atomic64_inc(v) atomic64_add(1LL, (v))
1461+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1462 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1463+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1464 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1465 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1466 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1467+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1468 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1469 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1470 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1471diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1472index 75fe66b..ba3dee4 100644
1473--- a/arch/arm/include/asm/cache.h
1474+++ b/arch/arm/include/asm/cache.h
1475@@ -4,8 +4,10 @@
1476 #ifndef __ASMARM_CACHE_H
1477 #define __ASMARM_CACHE_H
1478
1479+#include <linux/const.h>
1480+
1481 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1482-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1483+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1484
1485 /*
1486 * Memory returned by kmalloc() may be used for DMA, so we must make
1487@@ -24,5 +26,6 @@
1488 #endif
1489
1490 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1491+#define __read_only __attribute__ ((__section__(".data..read_only")))
1492
1493 #endif
1494diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1495index e1489c5..d418304 100644
1496--- a/arch/arm/include/asm/cacheflush.h
1497+++ b/arch/arm/include/asm/cacheflush.h
1498@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1499 void (*dma_unmap_area)(const void *, size_t, int);
1500
1501 void (*dma_flush_range)(const void *, const void *);
1502-};
1503+} __no_const;
1504
1505 /*
1506 * Select the calling method
1507diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1508index 6dcc164..b14d917 100644
1509--- a/arch/arm/include/asm/checksum.h
1510+++ b/arch/arm/include/asm/checksum.h
1511@@ -37,7 +37,19 @@ __wsum
1512 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1513
1514 __wsum
1515-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1516+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1517+
1518+static inline __wsum
1519+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1520+{
1521+ __wsum ret;
1522+ pax_open_userland();
1523+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1524+ pax_close_userland();
1525+ return ret;
1526+}
1527+
1528+
1529
1530 /*
1531 * Fold a partial checksum without adding pseudo headers
1532diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1533index 7eb18c1..e38b6d2 100644
1534--- a/arch/arm/include/asm/cmpxchg.h
1535+++ b/arch/arm/include/asm/cmpxchg.h
1536@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1537
1538 #define xchg(ptr,x) \
1539 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1540+#define xchg_unchecked(ptr,x) \
1541+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1542
1543 #include <asm-generic/cmpxchg-local.h>
1544
1545diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1546index 720799f..2f67631 100644
1547--- a/arch/arm/include/asm/delay.h
1548+++ b/arch/arm/include/asm/delay.h
1549@@ -25,9 +25,9 @@ extern struct arm_delay_ops {
1550 void (*const_udelay)(unsigned long);
1551 void (*udelay)(unsigned long);
1552 bool const_clock;
1553-} arm_delay_ops;
1554+} *arm_delay_ops;
1555
1556-#define __delay(n) arm_delay_ops.delay(n)
1557+#define __delay(n) arm_delay_ops->delay(n)
1558
1559 /*
1560 * This function intentionally does not exist; if you see references to
1561@@ -48,8 +48,8 @@ extern void __bad_udelay(void);
1562 * first constant multiplications gets optimized away if the delay is
1563 * a constant)
1564 */
1565-#define __udelay(n) arm_delay_ops.udelay(n)
1566-#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1567+#define __udelay(n) arm_delay_ops->udelay(n)
1568+#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1569
1570 #define udelay(n) \
1571 (__builtin_constant_p(n) ? \
1572diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1573index 6ddbe44..b5e38b1 100644
1574--- a/arch/arm/include/asm/domain.h
1575+++ b/arch/arm/include/asm/domain.h
1576@@ -48,18 +48,37 @@
1577 * Domain types
1578 */
1579 #define DOMAIN_NOACCESS 0
1580-#define DOMAIN_CLIENT 1
1581 #ifdef CONFIG_CPU_USE_DOMAINS
1582+#define DOMAIN_USERCLIENT 1
1583+#define DOMAIN_KERNELCLIENT 1
1584 #define DOMAIN_MANAGER 3
1585+#define DOMAIN_VECTORS DOMAIN_USER
1586 #else
1587+
1588+#ifdef CONFIG_PAX_KERNEXEC
1589 #define DOMAIN_MANAGER 1
1590+#define DOMAIN_KERNEXEC 3
1591+#else
1592+#define DOMAIN_MANAGER 1
1593+#endif
1594+
1595+#ifdef CONFIG_PAX_MEMORY_UDEREF
1596+#define DOMAIN_USERCLIENT 0
1597+#define DOMAIN_UDEREF 1
1598+#define DOMAIN_VECTORS DOMAIN_KERNEL
1599+#else
1600+#define DOMAIN_USERCLIENT 1
1601+#define DOMAIN_VECTORS DOMAIN_USER
1602+#endif
1603+#define DOMAIN_KERNELCLIENT 1
1604+
1605 #endif
1606
1607 #define domain_val(dom,type) ((type) << (2*(dom)))
1608
1609 #ifndef __ASSEMBLY__
1610
1611-#ifdef CONFIG_CPU_USE_DOMAINS
1612+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1613 static inline void set_domain(unsigned val)
1614 {
1615 asm volatile(
1616@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1617 isb();
1618 }
1619
1620-#define modify_domain(dom,type) \
1621- do { \
1622- struct thread_info *thread = current_thread_info(); \
1623- unsigned int domain = thread->cpu_domain; \
1624- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1625- thread->cpu_domain = domain | domain_val(dom, type); \
1626- set_domain(thread->cpu_domain); \
1627- } while (0)
1628-
1629+extern void modify_domain(unsigned int dom, unsigned int type);
1630 #else
1631 static inline void set_domain(unsigned val) { }
1632 static inline void modify_domain(unsigned dom, unsigned type) { }
1633diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1634index 38050b1..9d90e8b 100644
1635--- a/arch/arm/include/asm/elf.h
1636+++ b/arch/arm/include/asm/elf.h
1637@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1638 the loader. We need to make sure that it is out of the way of the program
1639 that it will "exec", and that there is sufficient room for the brk. */
1640
1641-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1642+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1643+
1644+#ifdef CONFIG_PAX_ASLR
1645+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1646+
1647+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1648+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1649+#endif
1650
1651 /* When the program starts, a1 contains a pointer to a function to be
1652 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1653@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1654 extern void elf_set_personality(const struct elf32_hdr *);
1655 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1656
1657-struct mm_struct;
1658-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1659-#define arch_randomize_brk arch_randomize_brk
1660-
1661 #endif
1662diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1663index de53547..52b9a28 100644
1664--- a/arch/arm/include/asm/fncpy.h
1665+++ b/arch/arm/include/asm/fncpy.h
1666@@ -81,7 +81,9 @@
1667 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1668 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1669 \
1670+ pax_open_kernel(); \
1671 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1672+ pax_close_kernel(); \
1673 flush_icache_range((unsigned long)(dest_buf), \
1674 (unsigned long)(dest_buf) + (size)); \
1675 \
1676diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1677index e42cf59..7b94b8f 100644
1678--- a/arch/arm/include/asm/futex.h
1679+++ b/arch/arm/include/asm/futex.h
1680@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1681 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1682 return -EFAULT;
1683
1684+ pax_open_userland();
1685+
1686 smp_mb();
1687 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1688 "1: ldrex %1, [%4]\n"
1689@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1690 : "cc", "memory");
1691 smp_mb();
1692
1693+ pax_close_userland();
1694+
1695 *uval = val;
1696 return ret;
1697 }
1698@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1699 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1700 return -EFAULT;
1701
1702+ pax_open_userland();
1703+
1704 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1705 "1: " TUSER(ldr) " %1, [%4]\n"
1706 " teq %1, %2\n"
1707@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1708 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1709 : "cc", "memory");
1710
1711+ pax_close_userland();
1712+
1713 *uval = val;
1714 return ret;
1715 }
1716@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1717 return -EFAULT;
1718
1719 pagefault_disable(); /* implies preempt_disable() */
1720+ pax_open_userland();
1721
1722 switch (op) {
1723 case FUTEX_OP_SET:
1724@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1725 ret = -ENOSYS;
1726 }
1727
1728+ pax_close_userland();
1729 pagefault_enable(); /* subsumes preempt_enable() */
1730
1731 if (!ret) {
1732diff --git a/arch/arm/include/asm/hardware/gic.h b/arch/arm/include/asm/hardware/gic.h
1733index 4b1ce6c..bea3f73 100644
1734--- a/arch/arm/include/asm/hardware/gic.h
1735+++ b/arch/arm/include/asm/hardware/gic.h
1736@@ -34,9 +34,10 @@
1737
1738 #ifndef __ASSEMBLY__
1739 #include <linux/irqdomain.h>
1740+#include <linux/irq.h>
1741 struct device_node;
1742
1743-extern struct irq_chip gic_arch_extn;
1744+extern irq_chip_no_const gic_arch_extn;
1745
1746 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
1747 u32 offset, struct device_node *);
1748diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1749index 83eb2f7..ed77159 100644
1750--- a/arch/arm/include/asm/kmap_types.h
1751+++ b/arch/arm/include/asm/kmap_types.h
1752@@ -4,6 +4,6 @@
1753 /*
1754 * This is the "bare minimum". AIO seems to require this.
1755 */
1756-#define KM_TYPE_NR 16
1757+#define KM_TYPE_NR 17
1758
1759 #endif
1760diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1761index 9e614a1..3302cca 100644
1762--- a/arch/arm/include/asm/mach/dma.h
1763+++ b/arch/arm/include/asm/mach/dma.h
1764@@ -22,7 +22,7 @@ struct dma_ops {
1765 int (*residue)(unsigned int, dma_t *); /* optional */
1766 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1767 const char *type;
1768-};
1769+} __do_const;
1770
1771 struct dma_struct {
1772 void *addr; /* single DMA address */
1773diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1774index 2fe141f..192dc01 100644
1775--- a/arch/arm/include/asm/mach/map.h
1776+++ b/arch/arm/include/asm/mach/map.h
1777@@ -27,13 +27,16 @@ struct map_desc {
1778 #define MT_MINICLEAN 6
1779 #define MT_LOW_VECTORS 7
1780 #define MT_HIGH_VECTORS 8
1781-#define MT_MEMORY 9
1782+#define MT_MEMORY_RWX 9
1783 #define MT_ROM 10
1784-#define MT_MEMORY_NONCACHED 11
1785+#define MT_MEMORY_NONCACHED_RX 11
1786 #define MT_MEMORY_DTCM 12
1787 #define MT_MEMORY_ITCM 13
1788 #define MT_MEMORY_SO 14
1789 #define MT_MEMORY_DMA_READY 15
1790+#define MT_MEMORY_RW 16
1791+#define MT_MEMORY_RX 17
1792+#define MT_MEMORY_NONCACHED_RW 18
1793
1794 #ifdef CONFIG_MMU
1795 extern void iotable_init(struct map_desc *, int);
1796diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1797index 53426c6..c7baff3 100644
1798--- a/arch/arm/include/asm/outercache.h
1799+++ b/arch/arm/include/asm/outercache.h
1800@@ -35,7 +35,7 @@ struct outer_cache_fns {
1801 #endif
1802 void (*set_debug)(unsigned long);
1803 void (*resume)(void);
1804-};
1805+} __no_const;
1806
1807 #ifdef CONFIG_OUTER_CACHE
1808
1809diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1810index 812a494..71fc0b6 100644
1811--- a/arch/arm/include/asm/page.h
1812+++ b/arch/arm/include/asm/page.h
1813@@ -114,7 +114,7 @@ struct cpu_user_fns {
1814 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1815 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1816 unsigned long vaddr, struct vm_area_struct *vma);
1817-};
1818+} __no_const;
1819
1820 #ifdef MULTI_USER
1821 extern struct cpu_user_fns cpu_user;
1822diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1823index 943504f..c37a730 100644
1824--- a/arch/arm/include/asm/pgalloc.h
1825+++ b/arch/arm/include/asm/pgalloc.h
1826@@ -17,6 +17,7 @@
1827 #include <asm/processor.h>
1828 #include <asm/cacheflush.h>
1829 #include <asm/tlbflush.h>
1830+#include <asm/system_info.h>
1831
1832 #define check_pgt_cache() do { } while (0)
1833
1834@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1835 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1836 }
1837
1838+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1839+{
1840+ pud_populate(mm, pud, pmd);
1841+}
1842+
1843 #else /* !CONFIG_ARM_LPAE */
1844
1845 /*
1846@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1847 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1848 #define pmd_free(mm, pmd) do { } while (0)
1849 #define pud_populate(mm,pmd,pte) BUG()
1850+#define pud_populate_kernel(mm,pmd,pte) BUG()
1851
1852 #endif /* CONFIG_ARM_LPAE */
1853
1854@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1855 __free_page(pte);
1856 }
1857
1858+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1859+{
1860+#ifdef CONFIG_ARM_LPAE
1861+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1862+#else
1863+ if (addr & SECTION_SIZE)
1864+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1865+ else
1866+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1867+#endif
1868+ flush_pmd_entry(pmdp);
1869+}
1870+
1871 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1872 pmdval_t prot)
1873 {
1874@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1875 static inline void
1876 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1877 {
1878- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1879+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1880 }
1881 #define pmd_pgtable(pmd) pmd_page(pmd)
1882
1883diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1884index 5cfba15..f415e1a 100644
1885--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1886+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1887@@ -20,12 +20,15 @@
1888 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1889 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1890 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1891+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1892 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1893 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1894 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1895+
1896 /*
1897 * - section
1898 */
1899+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1900 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1901 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1902 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1903@@ -37,6 +40,7 @@
1904 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1905 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1906 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1907+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1908
1909 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1910 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1911@@ -66,6 +70,7 @@
1912 * - extended small page/tiny page
1913 */
1914 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1915+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1916 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1917 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1918 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1919diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1920index f97ee02..07f1be5 100644
1921--- a/arch/arm/include/asm/pgtable-2level.h
1922+++ b/arch/arm/include/asm/pgtable-2level.h
1923@@ -125,6 +125,7 @@
1924 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1925 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1926 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1927+#define L_PTE_PXN (_AT(pteval_t, 1) << 12) /* v7*/
1928
1929 /*
1930 * These are the memory types, defined to be compatible with
1931diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1932index d795282..a43ea90 100644
1933--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1934+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1935@@ -32,15 +32,18 @@
1936 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1937 #define PMD_BIT4 (_AT(pmdval_t, 0))
1938 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1939+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1940
1941 /*
1942 * - section
1943 */
1944 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1945 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1946+#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1947 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1948 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1949 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1950+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1951 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1952 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1953 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1954@@ -66,6 +69,7 @@
1955 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1956 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1957 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1958+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1959 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1960
1961 /*
1962diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1963index a3f3792..7b932a6 100644
1964--- a/arch/arm/include/asm/pgtable-3level.h
1965+++ b/arch/arm/include/asm/pgtable-3level.h
1966@@ -74,6 +74,7 @@
1967 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1968 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1969 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1970+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1971 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1972 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1973 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1974@@ -82,6 +83,7 @@
1975 /*
1976 * To be used in assembly code with the upper page attributes.
1977 */
1978+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1979 #define L_PTE_XN_HIGH (1 << (54 - 32))
1980 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1981
1982diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1983index c094749..a6ff605 100644
1984--- a/arch/arm/include/asm/pgtable.h
1985+++ b/arch/arm/include/asm/pgtable.h
1986@@ -30,6 +30,9 @@
1987 #include <asm/pgtable-2level.h>
1988 #endif
1989
1990+#define ktla_ktva(addr) (addr)
1991+#define ktva_ktla(addr) (addr)
1992+
1993 /*
1994 * Just any arbitrary offset to the start of the vmalloc VM area: the
1995 * current 8MB value just means that there will be a 8MB "hole" after the
1996@@ -45,6 +48,9 @@
1997 #define LIBRARY_TEXT_START 0x0c000000
1998
1999 #ifndef __ASSEMBLY__
2000+extern pteval_t __supported_pte_mask;
2001+extern pmdval_t __supported_pmd_mask;
2002+
2003 extern void __pte_error(const char *file, int line, pte_t);
2004 extern void __pmd_error(const char *file, int line, pmd_t);
2005 extern void __pgd_error(const char *file, int line, pgd_t);
2006@@ -53,6 +59,50 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2007 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2008 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2009
2010+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2011+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2012+
2013+#ifdef CONFIG_PAX_KERNEXEC
2014+#include <asm/domain.h>
2015+#include <linux/thread_info.h>
2016+#include <linux/preempt.h>
2017+#endif
2018+
2019+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2020+static inline int test_domain(int domain, int domaintype)
2021+{
2022+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2023+}
2024+#endif
2025+
2026+#ifdef CONFIG_PAX_KERNEXEC
2027+static inline unsigned long pax_open_kernel(void) {
2028+#ifdef CONFIG_ARM_LPAE
2029+ /* TODO */
2030+#else
2031+ preempt_disable();
2032+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2033+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2034+#endif
2035+ return 0;
2036+}
2037+
2038+static inline unsigned long pax_close_kernel(void) {
2039+#ifdef CONFIG_ARM_LPAE
2040+ /* TODO */
2041+#else
2042+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2043+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2044+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2045+ preempt_enable_no_resched();
2046+#endif
2047+ return 0;
2048+}
2049+#else
2050+static inline unsigned long pax_open_kernel(void) { return 0; }
2051+static inline unsigned long pax_close_kernel(void) { return 0; }
2052+#endif
2053+
2054 /*
2055 * This is the lowest virtual address we can permit any user space
2056 * mapping to be mapped at. This is particularly important for
2057@@ -63,8 +113,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2058 /*
2059 * The pgprot_* and protection_map entries will be fixed up in runtime
2060 * to include the cachable and bufferable bits based on memory policy,
2061- * as well as any architecture dependent bits like global/ASID and SMP
2062- * shared mapping bits.
2063+ * as well as any architecture dependent bits like global/ASID, PXN,
2064+ * and SMP shared mapping bits.
2065 */
2066 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2067
2068@@ -241,7 +291,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2069 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2070 {
2071 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2072- L_PTE_NONE | L_PTE_VALID;
2073+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2074 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2075 return pte;
2076 }
2077diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2078index f3628fb..a0672dd 100644
2079--- a/arch/arm/include/asm/proc-fns.h
2080+++ b/arch/arm/include/asm/proc-fns.h
2081@@ -75,7 +75,7 @@ extern struct processor {
2082 unsigned int suspend_size;
2083 void (*do_suspend)(void *);
2084 void (*do_resume)(void *);
2085-} processor;
2086+} __do_const processor;
2087
2088 #ifndef MULTI_CPU
2089 extern void cpu_proc_init(void);
2090diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
2091index 06e7d50..8a8e251 100644
2092--- a/arch/arm/include/asm/processor.h
2093+++ b/arch/arm/include/asm/processor.h
2094@@ -65,9 +65,8 @@ struct thread_struct {
2095 regs->ARM_cpsr |= PSR_ENDSTATE; \
2096 regs->ARM_pc = pc & ~1; /* pc */ \
2097 regs->ARM_sp = sp; /* sp */ \
2098- regs->ARM_r2 = stack[2]; /* r2 (envp) */ \
2099- regs->ARM_r1 = stack[1]; /* r1 (argv) */ \
2100- regs->ARM_r0 = stack[0]; /* r0 (argc) */ \
2101+ /* r2 (envp), r1 (argv), r0 (argc) */ \
2102+ (void)copy_from_user(&regs->ARM_r0, (const char __user *)stack, 3 * sizeof(unsigned long)); \
2103 nommu_start_thread(regs); \
2104 })
2105
2106diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2107index d3a22be..3a69ad5 100644
2108--- a/arch/arm/include/asm/smp.h
2109+++ b/arch/arm/include/asm/smp.h
2110@@ -107,7 +107,7 @@ struct smp_operations {
2111 int (*cpu_disable)(unsigned int cpu);
2112 #endif
2113 #endif
2114-};
2115+} __no_const;
2116
2117 /*
2118 * set platform specific SMP operations
2119diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2120index cddda1f..ff357f7 100644
2121--- a/arch/arm/include/asm/thread_info.h
2122+++ b/arch/arm/include/asm/thread_info.h
2123@@ -77,9 +77,9 @@ struct thread_info {
2124 .flags = 0, \
2125 .preempt_count = INIT_PREEMPT_COUNT, \
2126 .addr_limit = KERNEL_DS, \
2127- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2128- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2129- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2130+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2131+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2132+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2133 .restart_block = { \
2134 .fn = do_no_restart_syscall, \
2135 }, \
2136@@ -152,6 +152,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2137 #define TIF_SYSCALL_AUDIT 9
2138 #define TIF_SYSCALL_TRACEPOINT 10
2139 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2140+
2141+/* within 8 bits of TIF_SYSCALL_TRACE
2142+ * to meet flexible second operand requirements
2143+ */
2144+#define TIF_GRSEC_SETXID 12
2145+
2146 #define TIF_USING_IWMMXT 17
2147 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2148 #define TIF_RESTORE_SIGMASK 20
2149@@ -165,10 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2150 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2151 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2152 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2153+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2154
2155 /* Checks for any syscall work in entry-common.S */
2156 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2157- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2158+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2159
2160 /*
2161 * Change these and you break ASM code in entry-common.S
2162diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2163index 7e1f760..752fcb7 100644
2164--- a/arch/arm/include/asm/uaccess.h
2165+++ b/arch/arm/include/asm/uaccess.h
2166@@ -18,6 +18,7 @@
2167 #include <asm/domain.h>
2168 #include <asm/unified.h>
2169 #include <asm/compiler.h>
2170+#include <asm/pgtable.h>
2171
2172 #define VERIFY_READ 0
2173 #define VERIFY_WRITE 1
2174@@ -60,10 +61,34 @@ extern int __put_user_bad(void);
2175 #define USER_DS TASK_SIZE
2176 #define get_fs() (current_thread_info()->addr_limit)
2177
2178+static inline void pax_open_userland(void)
2179+{
2180+
2181+#ifdef CONFIG_PAX_MEMORY_UDEREF
2182+ if (get_fs() == USER_DS) {
2183+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2184+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2185+ }
2186+#endif
2187+
2188+}
2189+
2190+static inline void pax_close_userland(void)
2191+{
2192+
2193+#ifdef CONFIG_PAX_MEMORY_UDEREF
2194+ if (get_fs() == USER_DS) {
2195+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2196+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2197+ }
2198+#endif
2199+
2200+}
2201+
2202 static inline void set_fs(mm_segment_t fs)
2203 {
2204 current_thread_info()->addr_limit = fs;
2205- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2206+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2207 }
2208
2209 #define segment_eq(a,b) ((a) == (b))
2210@@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2211
2212 #define get_user(x,p) \
2213 ({ \
2214+ int __e; \
2215 might_fault(); \
2216- __get_user_check(x,p); \
2217+ pax_open_userland(); \
2218+ __e = __get_user_check(x,p); \
2219+ pax_close_userland(); \
2220+ __e; \
2221 })
2222
2223 extern int __put_user_1(void *, unsigned int);
2224@@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2225
2226 #define put_user(x,p) \
2227 ({ \
2228+ int __e; \
2229 might_fault(); \
2230- __put_user_check(x,p); \
2231+ pax_open_userland(); \
2232+ __e = __put_user_check(x,p); \
2233+ pax_close_userland(); \
2234+ __e; \
2235 })
2236
2237 #else /* CONFIG_MMU */
2238@@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2239 #define __get_user(x,ptr) \
2240 ({ \
2241 long __gu_err = 0; \
2242+ pax_open_userland(); \
2243 __get_user_err((x),(ptr),__gu_err); \
2244+ pax_close_userland(); \
2245 __gu_err; \
2246 })
2247
2248 #define __get_user_error(x,ptr,err) \
2249 ({ \
2250+ pax_open_userland(); \
2251 __get_user_err((x),(ptr),err); \
2252+ pax_close_userland(); \
2253 (void) 0; \
2254 })
2255
2256@@ -312,13 +349,17 @@ do { \
2257 #define __put_user(x,ptr) \
2258 ({ \
2259 long __pu_err = 0; \
2260+ pax_open_userland(); \
2261 __put_user_err((x),(ptr),__pu_err); \
2262+ pax_close_userland(); \
2263 __pu_err; \
2264 })
2265
2266 #define __put_user_error(x,ptr,err) \
2267 ({ \
2268+ pax_open_userland(); \
2269 __put_user_err((x),(ptr),err); \
2270+ pax_close_userland(); \
2271 (void) 0; \
2272 })
2273
2274@@ -418,11 +459,44 @@ do { \
2275
2276
2277 #ifdef CONFIG_MMU
2278-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2279-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2280+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2281+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2282+
2283+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2284+{
2285+ unsigned long ret;
2286+
2287+ check_object_size(to, n, false);
2288+ pax_open_userland();
2289+ ret = ___copy_from_user(to, from, n);
2290+ pax_close_userland();
2291+ return ret;
2292+}
2293+
2294+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2295+{
2296+ unsigned long ret;
2297+
2298+ check_object_size(from, n, true);
2299+ pax_open_userland();
2300+ ret = ___copy_to_user(to, from, n);
2301+ pax_close_userland();
2302+ return ret;
2303+}
2304+
2305 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2306-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2307+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2308 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2309+
2310+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2311+{
2312+ unsigned long ret;
2313+ pax_open_userland();
2314+ ret = ___clear_user(addr, n);
2315+ pax_close_userland();
2316+ return ret;
2317+}
2318+
2319 #else
2320 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2321 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2322@@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2323
2324 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2325 {
2326+ if ((long)n < 0)
2327+ return n;
2328+
2329 if (access_ok(VERIFY_READ, from, n))
2330 n = __copy_from_user(to, from, n);
2331 else /* security hole - plug it */
2332@@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2333
2334 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2335 {
2336+ if ((long)n < 0)
2337+ return n;
2338+
2339 if (access_ok(VERIFY_WRITE, to, n))
2340 n = __copy_to_user(to, from, n);
2341 return n;
2342diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2343index 96ee092..37f1844 100644
2344--- a/arch/arm/include/uapi/asm/ptrace.h
2345+++ b/arch/arm/include/uapi/asm/ptrace.h
2346@@ -73,7 +73,7 @@
2347 * ARMv7 groups of PSR bits
2348 */
2349 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2350-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2351+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2352 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2353 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2354
2355diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2356index 60d3b73..d27ee09 100644
2357--- a/arch/arm/kernel/armksyms.c
2358+++ b/arch/arm/kernel/armksyms.c
2359@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2360 #ifdef CONFIG_MMU
2361 EXPORT_SYMBOL(copy_page);
2362
2363-EXPORT_SYMBOL(__copy_from_user);
2364-EXPORT_SYMBOL(__copy_to_user);
2365-EXPORT_SYMBOL(__clear_user);
2366+EXPORT_SYMBOL(___copy_from_user);
2367+EXPORT_SYMBOL(___copy_to_user);
2368+EXPORT_SYMBOL(___clear_user);
2369
2370 EXPORT_SYMBOL(__get_user_1);
2371 EXPORT_SYMBOL(__get_user_2);
2372diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2373index 0f82098..3dbd3ee 100644
2374--- a/arch/arm/kernel/entry-armv.S
2375+++ b/arch/arm/kernel/entry-armv.S
2376@@ -47,6 +47,87 @@
2377 9997:
2378 .endm
2379
2380+ .macro pax_enter_kernel
2381+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2382+ @ make aligned space for saved DACR
2383+ sub sp, sp, #8
2384+ @ save regs
2385+ stmdb sp!, {r1, r2}
2386+ @ read DACR from cpu_domain into r1
2387+ mov r2, sp
2388+ @ assume 8K pages, since we have to split the immediate in two
2389+ bic r2, r2, #(0x1fc0)
2390+ bic r2, r2, #(0x3f)
2391+ ldr r1, [r2, #TI_CPU_DOMAIN]
2392+ @ store old DACR on stack
2393+ str r1, [sp, #8]
2394+#ifdef CONFIG_PAX_KERNEXEC
2395+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2396+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2397+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2398+#endif
2399+#ifdef CONFIG_PAX_MEMORY_UDEREF
2400+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2401+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2402+#endif
2403+ @ write r1 to current_thread_info()->cpu_domain
2404+ str r1, [r2, #TI_CPU_DOMAIN]
2405+ @ write r1 to DACR
2406+ mcr p15, 0, r1, c3, c0, 0
2407+ @ instruction sync
2408+ instr_sync
2409+ @ restore regs
2410+ ldmia sp!, {r1, r2}
2411+#endif
2412+ .endm
2413+
2414+ .macro pax_open_userland
2415+#ifdef CONFIG_PAX_MEMORY_UDEREF
2416+ @ save regs
2417+ stmdb sp!, {r0, r1}
2418+ @ read DACR from cpu_domain into r1
2419+ mov r0, sp
2420+ @ assume 8K pages, since we have to split the immediate in two
2421+ bic r0, r0, #(0x1fc0)
2422+ bic r0, r0, #(0x3f)
2423+ ldr r1, [r0, #TI_CPU_DOMAIN]
2424+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2425+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2426+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2427+ @ write r1 to current_thread_info()->cpu_domain
2428+ str r1, [r0, #TI_CPU_DOMAIN]
2429+ @ write r1 to DACR
2430+ mcr p15, 0, r1, c3, c0, 0
2431+ @ instruction sync
2432+ instr_sync
2433+ @ restore regs
2434+ ldmia sp!, {r0, r1}
2435+#endif
2436+ .endm
2437+
2438+ .macro pax_close_userland
2439+#ifdef CONFIG_PAX_MEMORY_UDEREF
2440+ @ save regs
2441+ stmdb sp!, {r0, r1}
2442+ @ read DACR from cpu_domain into r1
2443+ mov r0, sp
2444+ @ assume 8K pages, since we have to split the immediate in two
2445+ bic r0, r0, #(0x1fc0)
2446+ bic r0, r0, #(0x3f)
2447+ ldr r1, [r0, #TI_CPU_DOMAIN]
2448+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2449+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2450+ @ write r1 to current_thread_info()->cpu_domain
2451+ str r1, [r0, #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!, {r0, r1}
2458+#endif
2459+ .endm
2460+
2461 .macro pabt_helper
2462 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2463 #ifdef MULTI_PABORT
2464@@ -89,11 +170,15 @@
2465 * Invalid mode handlers
2466 */
2467 .macro inv_entry, reason
2468+
2469+ pax_enter_kernel
2470+
2471 sub sp, sp, #S_FRAME_SIZE
2472 ARM( stmib sp, {r1 - lr} )
2473 THUMB( stmia sp, {r0 - r12} )
2474 THUMB( str sp, [sp, #S_SP] )
2475 THUMB( str lr, [sp, #S_LR] )
2476+
2477 mov r1, #\reason
2478 .endm
2479
2480@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2481 .macro svc_entry, stack_hole=0
2482 UNWIND(.fnstart )
2483 UNWIND(.save {r0 - pc} )
2484+
2485+ pax_enter_kernel
2486+
2487 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2488+
2489 #ifdef CONFIG_THUMB2_KERNEL
2490 SPFIX( str r0, [sp] ) @ temporarily saved
2491 SPFIX( mov r0, sp )
2492@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2493 ldmia r0, {r3 - r5}
2494 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2495 mov r6, #-1 @ "" "" "" ""
2496+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2497+ @ offset sp by 8 as done in pax_enter_kernel
2498+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2499+#else
2500 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2501+#endif
2502 SPFIX( addeq r2, r2, #4 )
2503 str r3, [sp, #-4]! @ save the "real" r0 copied
2504 @ from the exception stack
2505@@ -359,6 +453,9 @@ ENDPROC(__pabt_svc)
2506 .macro usr_entry
2507 UNWIND(.fnstart )
2508 UNWIND(.cantunwind ) @ don't unwind the user space
2509+
2510+ pax_enter_kernel_user
2511+
2512 sub sp, sp, #S_FRAME_SIZE
2513 ARM( stmib sp, {r1 - r12} )
2514 THUMB( stmia sp, {r0 - r12} )
2515@@ -456,7 +553,9 @@ __und_usr:
2516 tst r3, #PSR_T_BIT @ Thumb mode?
2517 bne __und_usr_thumb
2518 sub r4, r2, #4 @ ARM instr at LR - 4
2519+ pax_open_userland
2520 1: ldrt r0, [r4]
2521+ pax_close_userland
2522 #ifdef CONFIG_CPU_ENDIAN_BE8
2523 rev r0, r0 @ little endian instruction
2524 #endif
2525@@ -491,10 +590,14 @@ __und_usr_thumb:
2526 */
2527 .arch armv6t2
2528 #endif
2529+ pax_open_userland
2530 2: ldrht r5, [r4]
2531+ pax_close_userland
2532 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2533 blo __und_usr_fault_16 @ 16bit undefined instruction
2534+ pax_open_userland
2535 3: ldrht r0, [r2]
2536+ pax_close_userland
2537 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2538 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2539 orr r0, r0, r5, lsl #16
2540@@ -733,7 +836,7 @@ ENTRY(__switch_to)
2541 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2542 THUMB( str sp, [ip], #4 )
2543 THUMB( str lr, [ip], #4 )
2544-#ifdef CONFIG_CPU_USE_DOMAINS
2545+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2546 ldr r6, [r2, #TI_CPU_DOMAIN]
2547 #endif
2548 set_tls r3, r4, r5
2549@@ -742,7 +845,7 @@ ENTRY(__switch_to)
2550 ldr r8, =__stack_chk_guard
2551 ldr r7, [r7, #TSK_STACK_CANARY]
2552 #endif
2553-#ifdef CONFIG_CPU_USE_DOMAINS
2554+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2555 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2556 #endif
2557 mov r5, r0
2558diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2559index a6c301e..908821b 100644
2560--- a/arch/arm/kernel/entry-common.S
2561+++ b/arch/arm/kernel/entry-common.S
2562@@ -10,18 +10,46 @@
2563
2564 #include <asm/unistd.h>
2565 #include <asm/ftrace.h>
2566+#include <asm/domain.h>
2567 #include <asm/unwind.h>
2568
2569+#include "entry-header.S"
2570+
2571 #ifdef CONFIG_NEED_RET_TO_USER
2572 #include <mach/entry-macro.S>
2573 #else
2574 .macro arch_ret_to_user, tmp1, tmp2
2575+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2576+ @ save regs
2577+ stmdb sp!, {r1, r2}
2578+ @ read DACR from cpu_domain into r1
2579+ mov r2, sp
2580+ @ assume 8K pages, since we have to split the immediate in two
2581+ bic r2, r2, #(0x1fc0)
2582+ bic r2, r2, #(0x3f)
2583+ ldr r1, [r2, #TI_CPU_DOMAIN]
2584+#ifdef CONFIG_PAX_KERNEXEC
2585+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2586+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2587+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2588+#endif
2589+#ifdef CONFIG_PAX_MEMORY_UDEREF
2590+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2591+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2592+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2593+#endif
2594+ @ write r1 to current_thread_info()->cpu_domain
2595+ str r1, [r2, #TI_CPU_DOMAIN]
2596+ @ write r1 to DACR
2597+ mcr p15, 0, r1, c3, c0, 0
2598+ @ instruction sync
2599+ instr_sync
2600+ @ restore regs
2601+ ldmia sp!, {r1, r2}
2602+#endif
2603 .endm
2604 #endif
2605
2606-#include "entry-header.S"
2607-
2608-
2609 .align 5
2610 /*
2611 * This is the fast syscall return path. We do as little as
2612@@ -339,6 +367,7 @@ ENDPROC(ftrace_stub)
2613
2614 .align 5
2615 ENTRY(vector_swi)
2616+
2617 sub sp, sp, #S_FRAME_SIZE
2618 stmia sp, {r0 - r12} @ Calling r0 - r12
2619 ARM( add r8, sp, #S_PC )
2620@@ -388,6 +417,12 @@ ENTRY(vector_swi)
2621 ldr scno, [lr, #-4] @ get SWI instruction
2622 #endif
2623
2624+ /*
2625+ * do this here to avoid a performance hit of wrapping the code above
2626+ * that directly dereferences userland to parse the SWI instruction
2627+ */
2628+ pax_enter_kernel_user
2629+
2630 #ifdef CONFIG_ALIGNMENT_TRAP
2631 ldr ip, __cr_alignment
2632 ldr ip, [ip]
2633diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2634index 9a8531e..812e287 100644
2635--- a/arch/arm/kernel/entry-header.S
2636+++ b/arch/arm/kernel/entry-header.S
2637@@ -73,9 +73,66 @@
2638 msr cpsr_c, \rtemp @ switch back to the SVC mode
2639 .endm
2640
2641+ .macro pax_enter_kernel_user
2642+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2643+ @ save regs
2644+ stmdb sp!, {r0, r1}
2645+ @ read DACR from cpu_domain into r1
2646+ mov r0, sp
2647+ @ assume 8K pages, since we have to split the immediate in two
2648+ bic r0, r0, #(0x1fc0)
2649+ bic r0, r0, #(0x3f)
2650+ ldr r1, [r0, #TI_CPU_DOMAIN]
2651+#ifdef CONFIG_PAX_MEMORY_UDEREF
2652+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2653+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2654+#endif
2655+#ifdef CONFIG_PAX_KERNEXEC
2656+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2657+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2658+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2659+#endif
2660+ @ write r1 to current_thread_info()->cpu_domain
2661+ str r1, [r0, #TI_CPU_DOMAIN]
2662+ @ write r1 to DACR
2663+ mcr p15, 0, r1, c3, c0, 0
2664+ @ instruction sync
2665+ instr_sync
2666+ @ restore regs
2667+ ldmia sp!, {r0, r1}
2668+#endif
2669+ .endm
2670+
2671+ .macro pax_exit_kernel
2672+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2673+ @ save regs
2674+ stmdb sp!, {r0, r1}
2675+ @ read old DACR from stack into r1
2676+ ldr r1, [sp, #(8 + S_SP)]
2677+ sub r1, r1, #8
2678+ ldr r1, [r1]
2679+
2680+ @ write r1 to current_thread_info()->cpu_domain
2681+ mov r0, sp
2682+ @ assume 8K pages, since we have to split the immediate in two
2683+ bic r0, r0, #(0x1fc0)
2684+ bic r0, r0, #(0x3f)
2685+ str r1, [r0, #TI_CPU_DOMAIN]
2686+ @ write r1 to DACR
2687+ mcr p15, 0, r1, c3, c0, 0
2688+ @ instruction sync
2689+ instr_sync
2690+ @ restore regs
2691+ ldmia sp!, {r0, r1}
2692+#endif
2693+ .endm
2694+
2695 #ifndef CONFIG_THUMB2_KERNEL
2696 .macro svc_exit, rpsr
2697 msr spsr_cxsf, \rpsr
2698+
2699+ pax_exit_kernel
2700+
2701 #if defined(CONFIG_CPU_V6)
2702 ldr r0, [sp]
2703 strex r1, r2, [sp] @ clear the exclusive monitor
2704@@ -121,6 +178,9 @@
2705 .endm
2706 #else /* CONFIG_THUMB2_KERNEL */
2707 .macro svc_exit, rpsr
2708+
2709+ pax_exit_kernel
2710+
2711 ldr lr, [sp, #S_SP] @ top of the stack
2712 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2713 clrex @ clear the exclusive monitor
2714diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2715index 2adda11..7fbe958 100644
2716--- a/arch/arm/kernel/fiq.c
2717+++ b/arch/arm/kernel/fiq.c
2718@@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2719 #if defined(CONFIG_CPU_USE_DOMAINS)
2720 memcpy((void *)0xffff001c, start, length);
2721 #else
2722+ pax_open_kernel();
2723 memcpy(vectors_page + 0x1c, start, length);
2724+ pax_close_kernel();
2725 #endif
2726 flush_icache_range(0xffff001c, 0xffff001c + length);
2727 if (!vectors_high())
2728diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2729index e0eb9a1..c7d74a3 100644
2730--- a/arch/arm/kernel/head.S
2731+++ b/arch/arm/kernel/head.S
2732@@ -52,7 +52,9 @@
2733 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2734
2735 .macro pgtbl, rd, phys
2736- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2737+ mov \rd, #TEXT_OFFSET
2738+ sub \rd, #PG_DIR_SIZE
2739+ add \rd, \rd, \phys
2740 .endm
2741
2742 /*
2743@@ -434,7 +436,7 @@ __enable_mmu:
2744 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2745 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2746 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2747- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2748+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2749 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2750 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2751 #endif
2752diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2753index 5ff2e77..556d030 100644
2754--- a/arch/arm/kernel/hw_breakpoint.c
2755+++ b/arch/arm/kernel/hw_breakpoint.c
2756@@ -1011,7 +1011,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2757 return NOTIFY_OK;
2758 }
2759
2760-static struct notifier_block __cpuinitdata dbg_reset_nb = {
2761+static struct notifier_block dbg_reset_nb = {
2762 .notifier_call = dbg_reset_notify,
2763 };
2764
2765diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2766index 1e9be5d..03edbc2 100644
2767--- a/arch/arm/kernel/module.c
2768+++ b/arch/arm/kernel/module.c
2769@@ -37,12 +37,37 @@
2770 #endif
2771
2772 #ifdef CONFIG_MMU
2773-void *module_alloc(unsigned long size)
2774+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2775 {
2776+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2777+ return NULL;
2778 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2779- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2780+ GFP_KERNEL, prot, -1,
2781 __builtin_return_address(0));
2782 }
2783+
2784+void *module_alloc(unsigned long size)
2785+{
2786+
2787+#ifdef CONFIG_PAX_KERNEXEC
2788+ return __module_alloc(size, PAGE_KERNEL);
2789+#else
2790+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2791+#endif
2792+
2793+}
2794+
2795+#ifdef CONFIG_PAX_KERNEXEC
2796+void module_free_exec(struct module *mod, void *module_region)
2797+{
2798+ module_free(mod, module_region);
2799+}
2800+
2801+void *module_alloc_exec(unsigned long size)
2802+{
2803+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2804+}
2805+#endif
2806 #endif
2807
2808 int
2809diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2810index 07314af..c46655c 100644
2811--- a/arch/arm/kernel/patch.c
2812+++ b/arch/arm/kernel/patch.c
2813@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2814 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2815 int size;
2816
2817+ pax_open_kernel();
2818 if (thumb2 && __opcode_is_thumb16(insn)) {
2819 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2820 size = sizeof(u16);
2821@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2822 *(u32 *)addr = insn;
2823 size = sizeof(u32);
2824 }
2825+ pax_close_kernel();
2826
2827 flush_icache_range((uintptr_t)(addr),
2828 (uintptr_t)(addr) + size);
2829diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2830index 5f66206..dce492f 100644
2831--- a/arch/arm/kernel/perf_event_cpu.c
2832+++ b/arch/arm/kernel/perf_event_cpu.c
2833@@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2834 return NOTIFY_OK;
2835 }
2836
2837-static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2838+static struct notifier_block cpu_pmu_hotplug_notifier = {
2839 .notifier_call = cpu_pmu_notify,
2840 };
2841
2842diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2843index c6dec5f..e0fddd1 100644
2844--- a/arch/arm/kernel/process.c
2845+++ b/arch/arm/kernel/process.c
2846@@ -28,7 +28,6 @@
2847 #include <linux/tick.h>
2848 #include <linux/utsname.h>
2849 #include <linux/uaccess.h>
2850-#include <linux/random.h>
2851 #include <linux/hw_breakpoint.h>
2852 #include <linux/cpuidle.h>
2853 #include <linux/leds.h>
2854@@ -256,9 +255,10 @@ void machine_power_off(void)
2855 machine_shutdown();
2856 if (pm_power_off)
2857 pm_power_off();
2858+ BUG();
2859 }
2860
2861-void machine_restart(char *cmd)
2862+__noreturn void machine_restart(char *cmd)
2863 {
2864 machine_shutdown();
2865
2866@@ -283,8 +283,8 @@ void __show_regs(struct pt_regs *regs)
2867 init_utsname()->release,
2868 (int)strcspn(init_utsname()->version, " "),
2869 init_utsname()->version);
2870- print_symbol("PC is at %s\n", instruction_pointer(regs));
2871- print_symbol("LR is at %s\n", regs->ARM_lr);
2872+ printk("PC is at %pA\n", instruction_pointer(regs));
2873+ printk("LR is at %pA\n", regs->ARM_lr);
2874 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2875 "sp : %08lx ip : %08lx fp : %08lx\n",
2876 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2877@@ -452,12 +452,6 @@ unsigned long get_wchan(struct task_struct *p)
2878 return 0;
2879 }
2880
2881-unsigned long arch_randomize_brk(struct mm_struct *mm)
2882-{
2883- unsigned long range_end = mm->brk + 0x02000000;
2884- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2885-}
2886-
2887 #ifdef CONFIG_MMU
2888 /*
2889 * The vectors page is always readable from user space for the
2890@@ -470,9 +464,8 @@ static int __init gate_vma_init(void)
2891 {
2892 gate_vma.vm_start = 0xffff0000;
2893 gate_vma.vm_end = 0xffff0000 + PAGE_SIZE;
2894- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2895- gate_vma.vm_flags = VM_READ | VM_EXEC |
2896- VM_MAYREAD | VM_MAYEXEC;
2897+ gate_vma.vm_flags = VM_NONE;
2898+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2899 return 0;
2900 }
2901 arch_initcall(gate_vma_init);
2902diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2903index 03deeff..741ce88 100644
2904--- a/arch/arm/kernel/ptrace.c
2905+++ b/arch/arm/kernel/ptrace.c
2906@@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2907 return current_thread_info()->syscall;
2908 }
2909
2910+#ifdef CONFIG_GRKERNSEC_SETXID
2911+extern void gr_delayed_cred_worker(void);
2912+#endif
2913+
2914 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2915 {
2916 current_thread_info()->syscall = scno;
2917
2918+#ifdef CONFIG_GRKERNSEC_SETXID
2919+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2920+ gr_delayed_cred_worker();
2921+#endif
2922+
2923 /* Do the secure computing check first; failures should be fast. */
2924 if (secure_computing(scno) == -1)
2925 return -1;
2926diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2927index 3f6cbb2..6d856f5 100644
2928--- a/arch/arm/kernel/setup.c
2929+++ b/arch/arm/kernel/setup.c
2930@@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2931 unsigned int elf_hwcap __read_mostly;
2932 EXPORT_SYMBOL(elf_hwcap);
2933
2934+pteval_t __supported_pte_mask __read_only;
2935+pmdval_t __supported_pmd_mask __read_only;
2936
2937 #ifdef MULTI_CPU
2938-struct processor processor __read_mostly;
2939+struct processor processor;
2940 #endif
2941 #ifdef MULTI_TLB
2942-struct cpu_tlb_fns cpu_tlb __read_mostly;
2943+struct cpu_tlb_fns cpu_tlb __read_only;
2944 #endif
2945 #ifdef MULTI_USER
2946-struct cpu_user_fns cpu_user __read_mostly;
2947+struct cpu_user_fns cpu_user __read_only;
2948 #endif
2949 #ifdef MULTI_CACHE
2950-struct cpu_cache_fns cpu_cache __read_mostly;
2951+struct cpu_cache_fns cpu_cache __read_only;
2952 #endif
2953 #ifdef CONFIG_OUTER_CACHE
2954-struct outer_cache_fns outer_cache __read_mostly;
2955+struct outer_cache_fns outer_cache __read_only;
2956 EXPORT_SYMBOL(outer_cache);
2957 #endif
2958
2959@@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2960 asm("mrc p15, 0, %0, c0, c1, 4"
2961 : "=r" (mmfr0));
2962 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2963- (mmfr0 & 0x000000f0) >= 0x00000030)
2964+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2965 cpu_arch = CPU_ARCH_ARMv7;
2966- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2967+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2968+ __supported_pte_mask |= L_PTE_PXN;
2969+ __supported_pmd_mask |= PMD_PXNTABLE;
2970+ }
2971+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2972 (mmfr0 & 0x000000f0) == 0x00000020)
2973 cpu_arch = CPU_ARCH_ARMv6;
2974 else
2975@@ -462,7 +468,7 @@ static void __init setup_processor(void)
2976 __cpu_architecture = __get_cpu_architecture();
2977
2978 #ifdef MULTI_CPU
2979- processor = *list->proc;
2980+ memcpy((void *)&processor, list->proc, sizeof processor);
2981 #endif
2982 #ifdef MULTI_TLB
2983 cpu_tlb = *list->tlb;
2984diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
2985index 56f72d2..6924200 100644
2986--- a/arch/arm/kernel/signal.c
2987+++ b/arch/arm/kernel/signal.c
2988@@ -433,22 +433,14 @@ setup_return(struct pt_regs *regs, struct k_sigaction *ka,
2989 __put_user(sigreturn_codes[idx+1], rc+1))
2990 return 1;
2991
2992- if (cpsr & MODE32_BIT) {
2993- /*
2994- * 32-bit code can use the new high-page
2995- * signal return code support.
2996- */
2997- retcode = KERN_SIGRETURN_CODE + (idx << 2) + thumb;
2998- } else {
2999- /*
3000- * Ensure that the instruction cache sees
3001- * the return code written onto the stack.
3002- */
3003- flush_icache_range((unsigned long)rc,
3004- (unsigned long)(rc + 2));
3005+ /*
3006+ * Ensure that the instruction cache sees
3007+ * the return code written onto the stack.
3008+ */
3009+ flush_icache_range((unsigned long)rc,
3010+ (unsigned long)(rc + 2));
3011
3012- retcode = ((unsigned long)rc) + thumb;
3013- }
3014+ retcode = ((unsigned long)rc) + thumb;
3015 }
3016
3017 regs->ARM_r0 = usig;
3018diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3019index 58af91c..343ce99 100644
3020--- a/arch/arm/kernel/smp.c
3021+++ b/arch/arm/kernel/smp.c
3022@@ -70,7 +70,7 @@ enum ipi_msg_type {
3023
3024 static DECLARE_COMPLETION(cpu_running);
3025
3026-static struct smp_operations smp_ops;
3027+static struct smp_operations smp_ops __read_only;
3028
3029 void __init smp_set_ops(struct smp_operations *ops)
3030 {
3031diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3032index b0179b8..829510e 100644
3033--- a/arch/arm/kernel/traps.c
3034+++ b/arch/arm/kernel/traps.c
3035@@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3036 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3037 {
3038 #ifdef CONFIG_KALLSYMS
3039- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3040+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3041 #else
3042 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3043 #endif
3044@@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3045 static int die_owner = -1;
3046 static unsigned int die_nest_count;
3047
3048+extern void gr_handle_kernel_exploit(void);
3049+
3050 static unsigned long oops_begin(void)
3051 {
3052 int cpu;
3053@@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3054 panic("Fatal exception in interrupt");
3055 if (panic_on_oops)
3056 panic("Fatal exception");
3057+
3058+ gr_handle_kernel_exploit();
3059+
3060 if (signr)
3061 do_exit(signr);
3062 }
3063@@ -601,7 +606,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3064 * The user helper at 0xffff0fe0 must be used instead.
3065 * (see entry-armv.S for details)
3066 */
3067+ pax_open_kernel();
3068 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3069+ pax_close_kernel();
3070 }
3071 return 0;
3072
3073@@ -841,13 +848,10 @@ void __init early_trap_init(void *vectors_base)
3074 */
3075 kuser_get_tls_init(vectors);
3076
3077- /*
3078- * Copy signal return handlers into the vector page, and
3079- * set sigreturn to be a pointer to these.
3080- */
3081- memcpy((void *)(vectors + KERN_SIGRETURN_CODE - CONFIG_VECTORS_BASE),
3082- sigreturn_codes, sizeof(sigreturn_codes));
3083-
3084 flush_icache_range(vectors, vectors + PAGE_SIZE);
3085- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3086+
3087+#ifndef CONFIG_PAX_MEMORY_UDEREF
3088+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3089+#endif
3090+
3091 }
3092diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3093index 11c1785..c67d54c 100644
3094--- a/arch/arm/kernel/vmlinux.lds.S
3095+++ b/arch/arm/kernel/vmlinux.lds.S
3096@@ -8,7 +8,11 @@
3097 #include <asm/thread_info.h>
3098 #include <asm/memory.h>
3099 #include <asm/page.h>
3100-
3101+
3102+#ifdef CONFIG_PAX_KERNEXEC
3103+#include <asm/pgtable.h>
3104+#endif
3105+
3106 #define PROC_INFO \
3107 . = ALIGN(4); \
3108 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3109@@ -90,6 +94,11 @@ SECTIONS
3110 _text = .;
3111 HEAD_TEXT
3112 }
3113+
3114+#ifdef CONFIG_PAX_KERNEXEC
3115+ . = ALIGN(1<<SECTION_SHIFT);
3116+#endif
3117+
3118 .text : { /* Real text segment */
3119 _stext = .; /* Text and read-only data */
3120 __exception_text_start = .;
3121@@ -144,6 +153,10 @@ SECTIONS
3122
3123 _etext = .; /* End of text and rodata section */
3124
3125+#ifdef CONFIG_PAX_KERNEXEC
3126+ . = ALIGN(1<<SECTION_SHIFT);
3127+#endif
3128+
3129 #ifndef CONFIG_XIP_KERNEL
3130 . = ALIGN(PAGE_SIZE);
3131 __init_begin = .;
3132@@ -203,6 +216,11 @@ SECTIONS
3133 . = PAGE_OFFSET + TEXT_OFFSET;
3134 #else
3135 __init_end = .;
3136+
3137+#ifdef CONFIG_PAX_KERNEXEC
3138+ . = ALIGN(1<<SECTION_SHIFT);
3139+#endif
3140+
3141 . = ALIGN(THREAD_SIZE);
3142 __data_loc = .;
3143 #endif
3144diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3145index 14a0d98..7771a7d 100644
3146--- a/arch/arm/lib/clear_user.S
3147+++ b/arch/arm/lib/clear_user.S
3148@@ -12,14 +12,14 @@
3149
3150 .text
3151
3152-/* Prototype: int __clear_user(void *addr, size_t sz)
3153+/* Prototype: int ___clear_user(void *addr, size_t sz)
3154 * Purpose : clear some user memory
3155 * Params : addr - user memory address to clear
3156 * : sz - number of bytes to clear
3157 * Returns : number of bytes NOT cleared
3158 */
3159 ENTRY(__clear_user_std)
3160-WEAK(__clear_user)
3161+WEAK(___clear_user)
3162 stmfd sp!, {r1, lr}
3163 mov r2, #0
3164 cmp r1, #4
3165@@ -44,7 +44,7 @@ WEAK(__clear_user)
3166 USER( strnebt r2, [r0])
3167 mov r0, #0
3168 ldmfd sp!, {r1, pc}
3169-ENDPROC(__clear_user)
3170+ENDPROC(___clear_user)
3171 ENDPROC(__clear_user_std)
3172
3173 .pushsection .fixup,"ax"
3174diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3175index 66a477a..bee61d3 100644
3176--- a/arch/arm/lib/copy_from_user.S
3177+++ b/arch/arm/lib/copy_from_user.S
3178@@ -16,7 +16,7 @@
3179 /*
3180 * Prototype:
3181 *
3182- * size_t __copy_from_user(void *to, const void *from, size_t n)
3183+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3184 *
3185 * Purpose:
3186 *
3187@@ -84,11 +84,11 @@
3188
3189 .text
3190
3191-ENTRY(__copy_from_user)
3192+ENTRY(___copy_from_user)
3193
3194 #include "copy_template.S"
3195
3196-ENDPROC(__copy_from_user)
3197+ENDPROC(___copy_from_user)
3198
3199 .pushsection .fixup,"ax"
3200 .align 0
3201diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3202index 6ee2f67..d1cce76 100644
3203--- a/arch/arm/lib/copy_page.S
3204+++ b/arch/arm/lib/copy_page.S
3205@@ -10,6 +10,7 @@
3206 * ASM optimised string functions
3207 */
3208 #include <linux/linkage.h>
3209+#include <linux/const.h>
3210 #include <asm/assembler.h>
3211 #include <asm/asm-offsets.h>
3212 #include <asm/cache.h>
3213diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3214index d066df6..df28194 100644
3215--- a/arch/arm/lib/copy_to_user.S
3216+++ b/arch/arm/lib/copy_to_user.S
3217@@ -16,7 +16,7 @@
3218 /*
3219 * Prototype:
3220 *
3221- * size_t __copy_to_user(void *to, const void *from, size_t n)
3222+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3223 *
3224 * Purpose:
3225 *
3226@@ -88,11 +88,11 @@
3227 .text
3228
3229 ENTRY(__copy_to_user_std)
3230-WEAK(__copy_to_user)
3231+WEAK(___copy_to_user)
3232
3233 #include "copy_template.S"
3234
3235-ENDPROC(__copy_to_user)
3236+ENDPROC(___copy_to_user)
3237 ENDPROC(__copy_to_user_std)
3238
3239 .pushsection .fixup,"ax"
3240diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3241index 7d08b43..f7ca7ea 100644
3242--- a/arch/arm/lib/csumpartialcopyuser.S
3243+++ b/arch/arm/lib/csumpartialcopyuser.S
3244@@ -57,8 +57,8 @@
3245 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3246 */
3247
3248-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3249-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3250+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3251+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3252
3253 #include "csumpartialcopygeneric.S"
3254
3255diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3256index 6b93f6a..1aa92d0 100644
3257--- a/arch/arm/lib/delay.c
3258+++ b/arch/arm/lib/delay.c
3259@@ -28,12 +28,15 @@
3260 /*
3261 * Default to the loop-based delay implementation.
3262 */
3263-struct arm_delay_ops arm_delay_ops = {
3264+static struct arm_delay_ops arm_loop_delay_ops = {
3265 .delay = __loop_delay,
3266 .const_udelay = __loop_const_udelay,
3267 .udelay = __loop_udelay,
3268+ .const_clock = false,
3269 };
3270
3271+struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
3272+
3273 static const struct delay_timer *delay_timer;
3274 static bool delay_calibrated;
3275
3276@@ -67,6 +70,13 @@ static void __timer_udelay(unsigned long usecs)
3277 __timer_const_udelay(usecs * UDELAY_MULT);
3278 }
3279
3280+static struct arm_delay_ops arm_timer_delay_ops = {
3281+ .delay = __timer_delay,
3282+ .const_udelay = __timer_const_udelay,
3283+ .udelay = __timer_udelay,
3284+ .const_clock = true,
3285+};
3286+
3287 void __init register_current_timer_delay(const struct delay_timer *timer)
3288 {
3289 if (!delay_calibrated) {
3290@@ -74,10 +84,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
3291 delay_timer = timer;
3292 lpj_fine = timer->freq / HZ;
3293 loops_per_jiffy = lpj_fine;
3294- arm_delay_ops.delay = __timer_delay;
3295- arm_delay_ops.const_udelay = __timer_const_udelay;
3296- arm_delay_ops.udelay = __timer_udelay;
3297- arm_delay_ops.const_clock = true;
3298+ arm_delay_ops = &arm_timer_delay_ops;
3299 delay_calibrated = true;
3300 } else {
3301 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
3302diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3303index 025f742..8432b08 100644
3304--- a/arch/arm/lib/uaccess_with_memcpy.c
3305+++ b/arch/arm/lib/uaccess_with_memcpy.c
3306@@ -104,7 +104,7 @@ out:
3307 }
3308
3309 unsigned long
3310-__copy_to_user(void __user *to, const void *from, unsigned long n)
3311+___copy_to_user(void __user *to, const void *from, unsigned long n)
3312 {
3313 /*
3314 * This test is stubbed out of the main function above to keep
3315diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3316index bac21a5..b67ef8e 100644
3317--- a/arch/arm/mach-kirkwood/common.c
3318+++ b/arch/arm/mach-kirkwood/common.c
3319@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3320 clk_gate_ops.disable(hw);
3321 }
3322
3323-static struct clk_ops clk_gate_fn_ops;
3324+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3325+{
3326+ return clk_gate_ops.is_enabled(hw);
3327+}
3328+
3329+static struct clk_ops clk_gate_fn_ops = {
3330+ .enable = clk_gate_fn_enable,
3331+ .disable = clk_gate_fn_disable,
3332+ .is_enabled = clk_gate_fn_is_enabled,
3333+};
3334
3335 static struct clk __init *clk_register_gate_fn(struct device *dev,
3336 const char *name,
3337@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3338 gate_fn->fn_en = fn_en;
3339 gate_fn->fn_dis = fn_dis;
3340
3341- /* ops is the gate ops, but with our enable/disable functions */
3342- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3343- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3344- clk_gate_fn_ops = clk_gate_ops;
3345- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3346- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3347- }
3348-
3349 clk = clk_register(dev, &gate_fn->gate.hw);
3350
3351 if (IS_ERR(clk))
3352diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3353index 0abb30f..54064da 100644
3354--- a/arch/arm/mach-omap2/board-n8x0.c
3355+++ b/arch/arm/mach-omap2/board-n8x0.c
3356@@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3357 }
3358 #endif
3359
3360-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3361+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3362 .late_init = n8x0_menelaus_late_init,
3363 };
3364
3365diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3366index 8033cb7..2f7cb62 100644
3367--- a/arch/arm/mach-omap2/gpmc.c
3368+++ b/arch/arm/mach-omap2/gpmc.c
3369@@ -139,7 +139,6 @@ struct omap3_gpmc_regs {
3370 };
3371
3372 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3373-static struct irq_chip gpmc_irq_chip;
3374 static unsigned gpmc_irq_start;
3375
3376 static struct resource gpmc_mem_root;
3377@@ -700,6 +699,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3378
3379 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3380
3381+static struct irq_chip gpmc_irq_chip = {
3382+ .name = "gpmc",
3383+ .irq_startup = gpmc_irq_noop_ret,
3384+ .irq_enable = gpmc_irq_enable,
3385+ .irq_disable = gpmc_irq_disable,
3386+ .irq_shutdown = gpmc_irq_noop,
3387+ .irq_ack = gpmc_irq_noop,
3388+ .irq_mask = gpmc_irq_noop,
3389+ .irq_unmask = gpmc_irq_noop,
3390+
3391+};
3392+
3393 static int gpmc_setup_irq(void)
3394 {
3395 int i;
3396@@ -714,15 +725,6 @@ static int gpmc_setup_irq(void)
3397 return gpmc_irq_start;
3398 }
3399
3400- gpmc_irq_chip.name = "gpmc";
3401- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3402- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3403- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3404- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3405- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3406- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3407- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3408-
3409 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3410 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3411
3412diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3413index 5d3b4f4..ddba3c0 100644
3414--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3415+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3416@@ -340,7 +340,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3417 return NOTIFY_OK;
3418 }
3419
3420-static struct notifier_block __refdata irq_hotplug_notifier = {
3421+static struct notifier_block irq_hotplug_notifier = {
3422 .notifier_call = irq_cpu_hotplug_notify,
3423 };
3424
3425diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3426index e065daa..7b1ad9b 100644
3427--- a/arch/arm/mach-omap2/omap_device.c
3428+++ b/arch/arm/mach-omap2/omap_device.c
3429@@ -686,7 +686,7 @@ void omap_device_delete(struct omap_device *od)
3430 * passes along the return value of omap_device_build_ss().
3431 */
3432 struct platform_device __init *omap_device_build(const char *pdev_name, int pdev_id,
3433- struct omap_hwmod *oh, void *pdata,
3434+ struct omap_hwmod *oh, const void *pdata,
3435 int pdata_len,
3436 struct omap_device_pm_latency *pm_lats,
3437 int pm_lats_cnt, int is_early_device)
3438@@ -720,7 +720,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name, int pdev
3439 */
3440 struct platform_device __init *omap_device_build_ss(const char *pdev_name, int pdev_id,
3441 struct omap_hwmod **ohs, int oh_cnt,
3442- void *pdata, int pdata_len,
3443+ const void *pdata, int pdata_len,
3444 struct omap_device_pm_latency *pm_lats,
3445 int pm_lats_cnt, int is_early_device)
3446 {
3447diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3448index 0933c59..42b8e2d 100644
3449--- a/arch/arm/mach-omap2/omap_device.h
3450+++ b/arch/arm/mach-omap2/omap_device.h
3451@@ -91,14 +91,14 @@ int omap_device_shutdown(struct platform_device *pdev);
3452 /* Core code interface */
3453
3454 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3455- struct omap_hwmod *oh, void *pdata,
3456+ struct omap_hwmod *oh, const void *pdata,
3457 int pdata_len,
3458 struct omap_device_pm_latency *pm_lats,
3459 int pm_lats_cnt, int is_early_device);
3460
3461 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3462 struct omap_hwmod **oh, int oh_cnt,
3463- void *pdata, int pdata_len,
3464+ const void *pdata, int pdata_len,
3465 struct omap_device_pm_latency *pm_lats,
3466 int pm_lats_cnt, int is_early_device);
3467
3468diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3469index 4653efb..8c60bf7 100644
3470--- a/arch/arm/mach-omap2/omap_hwmod.c
3471+++ b/arch/arm/mach-omap2/omap_hwmod.c
3472@@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
3473 int (*init_clkdm)(struct omap_hwmod *oh);
3474 void (*update_context_lost)(struct omap_hwmod *oh);
3475 int (*get_context_lost)(struct omap_hwmod *oh);
3476-};
3477+} __no_const;
3478
3479 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3480-static struct omap_hwmod_soc_ops soc_ops;
3481+static struct omap_hwmod_soc_ops soc_ops __read_only;
3482
3483 /* omap_hwmod_list contains all registered struct omap_hwmods */
3484 static LIST_HEAD(omap_hwmod_list);
3485diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3486index 7c2b4ed..b2ea51f 100644
3487--- a/arch/arm/mach-omap2/wd_timer.c
3488+++ b/arch/arm/mach-omap2/wd_timer.c
3489@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3490 struct omap_hwmod *oh;
3491 char *oh_name = "wd_timer2";
3492 char *dev_name = "omap_wdt";
3493- struct omap_wd_timer_platform_data pdata;
3494+ static struct omap_wd_timer_platform_data pdata = {
3495+ .read_reset_sources = prm_read_reset_sources
3496+ };
3497
3498 if (!cpu_class_is_omap2() || of_have_populated_dt())
3499 return 0;
3500@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3501 return -EINVAL;
3502 }
3503
3504- pdata.read_reset_sources = prm_read_reset_sources;
3505-
3506 pdev = omap_device_build(dev_name, id, oh, &pdata,
3507 sizeof(struct omap_wd_timer_platform_data),
3508 NULL, 0, 0);
3509diff --git a/arch/arm/mach-ux500/include/mach/setup.h b/arch/arm/mach-ux500/include/mach/setup.h
3510index 6be4c4d..32ac32a 100644
3511--- a/arch/arm/mach-ux500/include/mach/setup.h
3512+++ b/arch/arm/mach-ux500/include/mach/setup.h
3513@@ -38,13 +38,6 @@ extern struct sys_timer ux500_timer;
3514 .type = MT_DEVICE, \
3515 }
3516
3517-#define __MEM_DEV_DESC(x, sz) { \
3518- .virtual = IO_ADDRESS(x), \
3519- .pfn = __phys_to_pfn(x), \
3520- .length = sz, \
3521- .type = MT_MEMORY, \
3522-}
3523-
3524 extern struct smp_operations ux500_smp_ops;
3525 extern void ux500_cpu_die(unsigned int cpu);
3526
3527diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3528index 3fd629d..8b1aca9 100644
3529--- a/arch/arm/mm/Kconfig
3530+++ b/arch/arm/mm/Kconfig
3531@@ -425,7 +425,7 @@ config CPU_32v5
3532
3533 config CPU_32v6
3534 bool
3535- select CPU_USE_DOMAINS if CPU_V6 && MMU
3536+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC
3537 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3538
3539 config CPU_32v6K
3540@@ -577,6 +577,7 @@ config CPU_CP15_MPU
3541
3542 config CPU_USE_DOMAINS
3543 bool
3544+ depends on !ARM_LPAE && !PAX_KERNEXEC
3545 help
3546 This option enables or disables the use of domain switching
3547 via the set_fs() function.
3548diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3549index db26e2e..ee44569 100644
3550--- a/arch/arm/mm/alignment.c
3551+++ b/arch/arm/mm/alignment.c
3552@@ -211,10 +211,12 @@ union offset_union {
3553 #define __get16_unaligned_check(ins,val,addr) \
3554 do { \
3555 unsigned int err = 0, v, a = addr; \
3556+ pax_open_userland(); \
3557 __get8_unaligned_check(ins,v,a,err); \
3558 val = v << ((BE) ? 8 : 0); \
3559 __get8_unaligned_check(ins,v,a,err); \
3560 val |= v << ((BE) ? 0 : 8); \
3561+ pax_close_userland(); \
3562 if (err) \
3563 goto fault; \
3564 } while (0)
3565@@ -228,6 +230,7 @@ union offset_union {
3566 #define __get32_unaligned_check(ins,val,addr) \
3567 do { \
3568 unsigned int err = 0, v, a = addr; \
3569+ pax_open_userland(); \
3570 __get8_unaligned_check(ins,v,a,err); \
3571 val = v << ((BE) ? 24 : 0); \
3572 __get8_unaligned_check(ins,v,a,err); \
3573@@ -236,6 +239,7 @@ union offset_union {
3574 val |= v << ((BE) ? 8 : 16); \
3575 __get8_unaligned_check(ins,v,a,err); \
3576 val |= v << ((BE) ? 0 : 24); \
3577+ pax_close_userland(); \
3578 if (err) \
3579 goto fault; \
3580 } while (0)
3581@@ -249,6 +253,7 @@ union offset_union {
3582 #define __put16_unaligned_check(ins,val,addr) \
3583 do { \
3584 unsigned int err = 0, v = val, a = addr; \
3585+ pax_open_userland(); \
3586 __asm__( FIRST_BYTE_16 \
3587 ARM( "1: "ins" %1, [%2], #1\n" ) \
3588 THUMB( "1: "ins" %1, [%2]\n" ) \
3589@@ -268,6 +273,7 @@ union offset_union {
3590 " .popsection\n" \
3591 : "=r" (err), "=&r" (v), "=&r" (a) \
3592 : "0" (err), "1" (v), "2" (a)); \
3593+ pax_close_userland(); \
3594 if (err) \
3595 goto fault; \
3596 } while (0)
3597@@ -281,6 +287,7 @@ union offset_union {
3598 #define __put32_unaligned_check(ins,val,addr) \
3599 do { \
3600 unsigned int err = 0, v = val, a = addr; \
3601+ pax_open_userland(); \
3602 __asm__( FIRST_BYTE_32 \
3603 ARM( "1: "ins" %1, [%2], #1\n" ) \
3604 THUMB( "1: "ins" %1, [%2]\n" ) \
3605@@ -310,6 +317,7 @@ union offset_union {
3606 " .popsection\n" \
3607 : "=r" (err), "=&r" (v), "=&r" (a) \
3608 : "0" (err), "1" (v), "2" (a)); \
3609+ pax_close_userland(); \
3610 if (err) \
3611 goto fault; \
3612 } while (0)
3613diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3614index 5dbf13f..1a60561 100644
3615--- a/arch/arm/mm/fault.c
3616+++ b/arch/arm/mm/fault.c
3617@@ -25,6 +25,7 @@
3618 #include <asm/system_misc.h>
3619 #include <asm/system_info.h>
3620 #include <asm/tlbflush.h>
3621+#include <asm/sections.h>
3622
3623 #include "fault.h"
3624
3625@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3626 if (fixup_exception(regs))
3627 return;
3628
3629+#ifdef CONFIG_PAX_KERNEXEC
3630+ if ((fsr & FSR_WRITE) &&
3631+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3632+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3633+ {
3634+ if (current->signal->curr_ip)
3635+ 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),
3636+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3637+ else
3638+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3639+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3640+ }
3641+#endif
3642+
3643 /*
3644 * No handler, we'll have to terminate things with extreme prejudice.
3645 */
3646@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3647 }
3648 #endif
3649
3650+#ifdef CONFIG_PAX_PAGEEXEC
3651+ if (fsr & FSR_LNX_PF) {
3652+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3653+ do_group_exit(SIGKILL);
3654+ }
3655+#endif
3656+
3657 tsk->thread.address = addr;
3658 tsk->thread.error_code = fsr;
3659 tsk->thread.trap_no = 14;
3660@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3661 }
3662 #endif /* CONFIG_MMU */
3663
3664+#ifdef CONFIG_PAX_PAGEEXEC
3665+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3666+{
3667+ long i;
3668+
3669+ printk(KERN_ERR "PAX: bytes at PC: ");
3670+ for (i = 0; i < 20; i++) {
3671+ unsigned char c;
3672+ if (get_user(c, (__force unsigned char __user *)pc+i))
3673+ printk(KERN_CONT "?? ");
3674+ else
3675+ printk(KERN_CONT "%02x ", c);
3676+ }
3677+ printk("\n");
3678+
3679+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3680+ for (i = -1; i < 20; i++) {
3681+ unsigned long c;
3682+ if (get_user(c, (__force unsigned long __user *)sp+i))
3683+ printk(KERN_CONT "???????? ");
3684+ else
3685+ printk(KERN_CONT "%08lx ", c);
3686+ }
3687+ printk("\n");
3688+}
3689+#endif
3690+
3691 /*
3692 * First Level Translation Fault Handler
3693 *
3694@@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3695 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3696 struct siginfo info;
3697
3698+#ifdef CONFIG_PAX_MEMORY_UDEREF
3699+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3700+ if (current->signal->curr_ip)
3701+ 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),
3702+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3703+ else
3704+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3705+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3706+ goto die;
3707+ }
3708+#endif
3709+
3710 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3711 return;
3712
3713+die:
3714 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3715 inf->name, fsr, addr);
3716
3717@@ -575,9 +637,49 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3718 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3719 struct siginfo info;
3720
3721+ if (user_mode(regs)) {
3722+ if (addr == 0xffff0fe0UL) {
3723+ /*
3724+ * PaX: __kuser_get_tls emulation
3725+ */
3726+ regs->ARM_r0 = current_thread_info()->tp_value;
3727+ regs->ARM_pc = regs->ARM_lr;
3728+ return;
3729+ }
3730+ }
3731+
3732+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3733+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3734+ if (current->signal->curr_ip)
3735+ 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),
3736+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3737+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3738+ else
3739+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3740+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3741+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3742+ goto die;
3743+ }
3744+#endif
3745+
3746+#ifdef CONFIG_PAX_REFCOUNT
3747+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3748+ unsigned int bkpt;
3749+
3750+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3751+ current->thread.error_code = ifsr;
3752+ current->thread.trap_no = 0;
3753+ pax_report_refcount_overflow(regs);
3754+ fixup_exception(regs);
3755+ return;
3756+ }
3757+ }
3758+#endif
3759+
3760 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3761 return;
3762
3763+die:
3764 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3765 inf->name, ifsr, addr);
3766
3767diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3768index cf08bdf..772656c 100644
3769--- a/arch/arm/mm/fault.h
3770+++ b/arch/arm/mm/fault.h
3771@@ -3,6 +3,7 @@
3772
3773 /*
3774 * Fault status register encodings. We steal bit 31 for our own purposes.
3775+ * Set when the FSR value is from an instruction fault.
3776 */
3777 #define FSR_LNX_PF (1 << 31)
3778 #define FSR_WRITE (1 << 11)
3779@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3780 }
3781 #endif
3782
3783+/* valid for LPAE and !LPAE */
3784+static inline int is_xn_fault(unsigned int fsr)
3785+{
3786+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3787+}
3788+
3789+static inline int is_domain_fault(unsigned int fsr)
3790+{
3791+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3792+}
3793+
3794 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3795 unsigned long search_exception_table(unsigned long addr);
3796
3797diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3798index ad722f1..763fdd3 100644
3799--- a/arch/arm/mm/init.c
3800+++ b/arch/arm/mm/init.c
3801@@ -30,6 +30,8 @@
3802 #include <asm/setup.h>
3803 #include <asm/tlb.h>
3804 #include <asm/fixmap.h>
3805+#include <asm/system_info.h>
3806+#include <asm/cp15.h>
3807
3808 #include <asm/mach/arch.h>
3809 #include <asm/mach/map.h>
3810@@ -736,7 +738,46 @@ void free_initmem(void)
3811 {
3812 #ifdef CONFIG_HAVE_TCM
3813 extern char __tcm_start, __tcm_end;
3814+#endif
3815
3816+#ifdef CONFIG_PAX_KERNEXEC
3817+ unsigned long addr;
3818+ pgd_t *pgd;
3819+ pud_t *pud;
3820+ pmd_t *pmd;
3821+ int cpu_arch = cpu_architecture();
3822+ unsigned int cr = get_cr();
3823+
3824+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3825+ /* make pages tables, etc before .text NX */
3826+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3827+ pgd = pgd_offset_k(addr);
3828+ pud = pud_offset(pgd, addr);
3829+ pmd = pmd_offset(pud, addr);
3830+ __section_update(pmd, addr, PMD_SECT_XN);
3831+ }
3832+ /* make init NX */
3833+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3834+ pgd = pgd_offset_k(addr);
3835+ pud = pud_offset(pgd, addr);
3836+ pmd = pmd_offset(pud, addr);
3837+ __section_update(pmd, addr, PMD_SECT_XN);
3838+ }
3839+ /* make kernel code/rodata RX */
3840+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3841+ pgd = pgd_offset_k(addr);
3842+ pud = pud_offset(pgd, addr);
3843+ pmd = pmd_offset(pud, addr);
3844+#ifdef CONFIG_ARM_LPAE
3845+ __section_update(pmd, addr, PMD_SECT_RDONLY);
3846+#else
3847+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3848+#endif
3849+ }
3850+ }
3851+#endif
3852+
3853+#ifdef CONFIG_HAVE_TCM
3854 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3855 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
3856 __phys_to_pfn(__pa(&__tcm_end)),
3857diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3858index 88fd86c..7a224ce 100644
3859--- a/arch/arm/mm/ioremap.c
3860+++ b/arch/arm/mm/ioremap.c
3861@@ -335,9 +335,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3862 unsigned int mtype;
3863
3864 if (cached)
3865- mtype = MT_MEMORY;
3866+ mtype = MT_MEMORY_RX;
3867 else
3868- mtype = MT_MEMORY_NONCACHED;
3869+ mtype = MT_MEMORY_NONCACHED_RX;
3870
3871 return __arm_ioremap_caller(phys_addr, size, mtype,
3872 __builtin_return_address(0));
3873diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3874index 10062ce..aa96dd7 100644
3875--- a/arch/arm/mm/mmap.c
3876+++ b/arch/arm/mm/mmap.c
3877@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3878 struct vm_area_struct *vma;
3879 int do_align = 0;
3880 int aliasing = cache_is_vipt_aliasing();
3881+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3882 struct vm_unmapped_area_info info;
3883
3884 /*
3885@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3886 if (len > TASK_SIZE)
3887 return -ENOMEM;
3888
3889+#ifdef CONFIG_PAX_RANDMMAP
3890+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3891+#endif
3892+
3893 if (addr) {
3894 if (do_align)
3895 addr = COLOUR_ALIGN(addr, pgoff);
3896@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3897 addr = PAGE_ALIGN(addr);
3898
3899 vma = find_vma(mm, addr);
3900- if (TASK_SIZE - len >= addr &&
3901- (!vma || addr + len <= vma->vm_start))
3902+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3903 return addr;
3904 }
3905
3906@@ -112,6 +116,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3907 unsigned long addr = addr0;
3908 int do_align = 0;
3909 int aliasing = cache_is_vipt_aliasing();
3910+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3911 struct vm_unmapped_area_info info;
3912
3913 /*
3914@@ -132,6 +137,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3915 return addr;
3916 }
3917
3918+#ifdef CONFIG_PAX_RANDMMAP
3919+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3920+#endif
3921+
3922 /* requesting a specific address */
3923 if (addr) {
3924 if (do_align)
3925@@ -139,8 +148,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3926 else
3927 addr = PAGE_ALIGN(addr);
3928 vma = find_vma(mm, addr);
3929- if (TASK_SIZE - len >= addr &&
3930- (!vma || addr + len <= vma->vm_start))
3931+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3932 return addr;
3933 }
3934
3935@@ -162,6 +170,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3936 VM_BUG_ON(addr != -ENOMEM);
3937 info.flags = 0;
3938 info.low_limit = mm->mmap_base;
3939+
3940+#ifdef CONFIG_PAX_RANDMMAP
3941+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3942+ info.low_limit += mm->delta_mmap;
3943+#endif
3944+
3945 info.high_limit = TASK_SIZE;
3946 addr = vm_unmapped_area(&info);
3947 }
3948@@ -173,6 +187,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3949 {
3950 unsigned long random_factor = 0UL;
3951
3952+#ifdef CONFIG_PAX_RANDMMAP
3953+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3954+#endif
3955+
3956 /* 8 bits of randomness in 20 address space bits */
3957 if ((current->flags & PF_RANDOMIZE) &&
3958 !(current->personality & ADDR_NO_RANDOMIZE))
3959@@ -180,10 +198,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3960
3961 if (mmap_is_legacy()) {
3962 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3963+
3964+#ifdef CONFIG_PAX_RANDMMAP
3965+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3966+ mm->mmap_base += mm->delta_mmap;
3967+#endif
3968+
3969 mm->get_unmapped_area = arch_get_unmapped_area;
3970 mm->unmap_area = arch_unmap_area;
3971 } else {
3972 mm->mmap_base = mmap_base(random_factor);
3973+
3974+#ifdef CONFIG_PAX_RANDMMAP
3975+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3976+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3977+#endif
3978+
3979 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3980 mm->unmap_area = arch_unmap_area_topdown;
3981 }
3982diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
3983index ce328c7..35b88dc 100644
3984--- a/arch/arm/mm/mmu.c
3985+++ b/arch/arm/mm/mmu.c
3986@@ -35,6 +35,23 @@
3987
3988 #include "mm.h"
3989
3990+
3991+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3992+void modify_domain(unsigned int dom, unsigned int type)
3993+{
3994+ struct thread_info *thread = current_thread_info();
3995+ unsigned int domain = thread->cpu_domain;
3996+ /*
3997+ * DOMAIN_MANAGER might be defined to some other value,
3998+ * use the arch-defined constant
3999+ */
4000+ domain &= ~domain_val(dom, 3);
4001+ thread->cpu_domain = domain | domain_val(dom, type);
4002+ set_domain(thread->cpu_domain);
4003+}
4004+EXPORT_SYMBOL(modify_domain);
4005+#endif
4006+
4007 /*
4008 * empty_zero_page is a special page that is used for
4009 * zero-initialized data and COW.
4010@@ -195,10 +212,18 @@ void adjust_cr(unsigned long mask, unsigned long set)
4011 }
4012 #endif
4013
4014-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4015+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4016 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4017
4018-static struct mem_type mem_types[] = {
4019+#ifdef CONFIG_PAX_KERNEXEC
4020+#define L_PTE_KERNEXEC L_PTE_RDONLY
4021+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4022+#else
4023+#define L_PTE_KERNEXEC L_PTE_DIRTY
4024+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4025+#endif
4026+
4027+static struct mem_type mem_types[] __read_only = {
4028 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4029 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4030 L_PTE_SHARED,
4031@@ -227,16 +252,16 @@ static struct mem_type mem_types[] = {
4032 [MT_UNCACHED] = {
4033 .prot_pte = PROT_PTE_DEVICE,
4034 .prot_l1 = PMD_TYPE_TABLE,
4035- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4036+ .prot_sect = PROT_SECT_DEVICE,
4037 .domain = DOMAIN_IO,
4038 },
4039 [MT_CACHECLEAN] = {
4040- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4041+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4042 .domain = DOMAIN_KERNEL,
4043 },
4044 #ifndef CONFIG_ARM_LPAE
4045 [MT_MINICLEAN] = {
4046- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4047+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4048 .domain = DOMAIN_KERNEL,
4049 },
4050 #endif
4051@@ -244,36 +269,54 @@ static struct mem_type mem_types[] = {
4052 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4053 L_PTE_RDONLY,
4054 .prot_l1 = PMD_TYPE_TABLE,
4055- .domain = DOMAIN_USER,
4056+ .domain = DOMAIN_VECTORS,
4057 },
4058 [MT_HIGH_VECTORS] = {
4059 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4060- L_PTE_USER | L_PTE_RDONLY,
4061+ L_PTE_RDONLY,
4062 .prot_l1 = PMD_TYPE_TABLE,
4063- .domain = DOMAIN_USER,
4064+ .domain = DOMAIN_VECTORS,
4065 },
4066- [MT_MEMORY] = {
4067+ [MT_MEMORY_RWX] = {
4068 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4069 .prot_l1 = PMD_TYPE_TABLE,
4070 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4071 .domain = DOMAIN_KERNEL,
4072 },
4073+ [MT_MEMORY_RW] = {
4074+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4075+ .prot_l1 = PMD_TYPE_TABLE,
4076+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4077+ .domain = DOMAIN_KERNEL,
4078+ },
4079+ [MT_MEMORY_RX] = {
4080+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4081+ .prot_l1 = PMD_TYPE_TABLE,
4082+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4083+ .domain = DOMAIN_KERNEL,
4084+ },
4085 [MT_ROM] = {
4086- .prot_sect = PMD_TYPE_SECT,
4087+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4088 .domain = DOMAIN_KERNEL,
4089 },
4090- [MT_MEMORY_NONCACHED] = {
4091+ [MT_MEMORY_NONCACHED_RW] = {
4092 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4093 L_PTE_MT_BUFFERABLE,
4094 .prot_l1 = PMD_TYPE_TABLE,
4095 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4096 .domain = DOMAIN_KERNEL,
4097 },
4098+ [MT_MEMORY_NONCACHED_RX] = {
4099+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4100+ L_PTE_MT_BUFFERABLE,
4101+ .prot_l1 = PMD_TYPE_TABLE,
4102+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4103+ .domain = DOMAIN_KERNEL,
4104+ },
4105 [MT_MEMORY_DTCM] = {
4106- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4107- L_PTE_XN,
4108+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4109 .prot_l1 = PMD_TYPE_TABLE,
4110- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4111+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4112 .domain = DOMAIN_KERNEL,
4113 },
4114 [MT_MEMORY_ITCM] = {
4115@@ -283,10 +326,10 @@ static struct mem_type mem_types[] = {
4116 },
4117 [MT_MEMORY_SO] = {
4118 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4119- L_PTE_MT_UNCACHED | L_PTE_XN,
4120+ L_PTE_MT_UNCACHED,
4121 .prot_l1 = PMD_TYPE_TABLE,
4122 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4123- PMD_SECT_UNCACHED | PMD_SECT_XN,
4124+ PMD_SECT_UNCACHED,
4125 .domain = DOMAIN_KERNEL,
4126 },
4127 [MT_MEMORY_DMA_READY] = {
4128@@ -371,9 +414,35 @@ static void __init build_mem_type_table(void)
4129 * to prevent speculative instruction fetches.
4130 */
4131 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4132+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4133 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4134+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4135 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4136+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4137 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4138+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4139+
4140+ /* Mark other regions on ARMv6+ as execute-never */
4141+
4142+#ifdef CONFIG_PAX_KERNEXEC
4143+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4144+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4145+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4146+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4147+#ifndef CONFIG_ARM_LPAE
4148+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4149+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4150+#endif
4151+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4152+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4153+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4154+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4155+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4156+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4157+#endif
4158+
4159+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4160+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4161 }
4162 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4163 /*
4164@@ -432,6 +501,9 @@ static void __init build_mem_type_table(void)
4165 * from SVC mode and no access from userspace.
4166 */
4167 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4168+#ifdef CONFIG_PAX_KERNEXEC
4169+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4170+#endif
4171 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4172 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4173 #endif
4174@@ -448,11 +520,17 @@ static void __init build_mem_type_table(void)
4175 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4176 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4177 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4178- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4179- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4180+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4181+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4182+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4183+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4184+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4185+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4186 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4187- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4188- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4189+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4190+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4191+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4192+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4193 }
4194 }
4195
4196@@ -463,15 +541,20 @@ static void __init build_mem_type_table(void)
4197 if (cpu_arch >= CPU_ARCH_ARMv6) {
4198 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4199 /* Non-cacheable Normal is XCB = 001 */
4200- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4201+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4202+ PMD_SECT_BUFFERED;
4203+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4204 PMD_SECT_BUFFERED;
4205 } else {
4206 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4207- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4208+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4209+ PMD_SECT_TEX(1);
4210+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4211 PMD_SECT_TEX(1);
4212 }
4213 } else {
4214- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4215+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4216+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4217 }
4218
4219 #ifdef CONFIG_ARM_LPAE
4220@@ -487,6 +570,8 @@ static void __init build_mem_type_table(void)
4221 vecs_pgprot |= PTE_EXT_AF;
4222 #endif
4223
4224+ user_pgprot |= __supported_pte_mask;
4225+
4226 for (i = 0; i < 16; i++) {
4227 pteval_t v = pgprot_val(protection_map[i]);
4228 protection_map[i] = __pgprot(v | user_pgprot);
4229@@ -501,10 +586,15 @@ static void __init build_mem_type_table(void)
4230
4231 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4232 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4233- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4234- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4235+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4236+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4237+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4238+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4239+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4240+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4241 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4242- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4243+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4244+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4245 mem_types[MT_ROM].prot_sect |= cp->pmd;
4246
4247 switch (cp->pmd) {
4248@@ -1105,18 +1195,15 @@ void __init arm_mm_memblock_reserve(void)
4249 * called function. This means you can't use any function or debugging
4250 * method which may touch any device, otherwise the kernel _will_ crash.
4251 */
4252+
4253+static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
4254+
4255 static void __init devicemaps_init(struct machine_desc *mdesc)
4256 {
4257 struct map_desc map;
4258 unsigned long addr;
4259- void *vectors;
4260
4261- /*
4262- * Allocate the vector page early.
4263- */
4264- vectors = early_alloc(PAGE_SIZE);
4265-
4266- early_trap_init(vectors);
4267+ early_trap_init(&vectors);
4268
4269 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4270 pmd_clear(pmd_off_k(addr));
4271@@ -1156,7 +1243,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4272 * location (0xffff0000). If we aren't using high-vectors, also
4273 * create a mapping at the low-vectors virtual address.
4274 */
4275- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4276+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4277 map.virtual = 0xffff0000;
4278 map.length = PAGE_SIZE;
4279 map.type = MT_HIGH_VECTORS;
4280@@ -1214,8 +1301,39 @@ static void __init map_lowmem(void)
4281 map.pfn = __phys_to_pfn(start);
4282 map.virtual = __phys_to_virt(start);
4283 map.length = end - start;
4284- map.type = MT_MEMORY;
4285
4286+#ifdef CONFIG_PAX_KERNEXEC
4287+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4288+ struct map_desc kernel;
4289+ struct map_desc initmap;
4290+
4291+ /* when freeing initmem we will make this RW */
4292+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4293+ initmap.virtual = (unsigned long)__init_begin;
4294+ initmap.length = _sdata - __init_begin;
4295+ initmap.type = MT_MEMORY_RWX;
4296+ create_mapping(&initmap);
4297+
4298+ /* when freeing initmem we will make this RX */
4299+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4300+ kernel.virtual = (unsigned long)_stext;
4301+ kernel.length = __init_begin - _stext;
4302+ kernel.type = MT_MEMORY_RWX;
4303+ create_mapping(&kernel);
4304+
4305+ if (map.virtual < (unsigned long)_stext) {
4306+ map.length = (unsigned long)_stext - map.virtual;
4307+ map.type = MT_MEMORY_RWX;
4308+ create_mapping(&map);
4309+ }
4310+
4311+ map.pfn = __phys_to_pfn(__pa(_sdata));
4312+ map.virtual = (unsigned long)_sdata;
4313+ map.length = end - __pa(_sdata);
4314+ }
4315+#endif
4316+
4317+ map.type = MT_MEMORY_RW;
4318 create_mapping(&map);
4319 }
4320 }
4321diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4322index 6d98c13..3cfb174 100644
4323--- a/arch/arm/mm/proc-v7-2level.S
4324+++ b/arch/arm/mm/proc-v7-2level.S
4325@@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4326 tst r1, #L_PTE_XN
4327 orrne r3, r3, #PTE_EXT_XN
4328
4329+ tst r1, #L_PTE_PXN
4330+ orrne r3, r3, #PTE_EXT_PXN
4331+
4332 tst r1, #L_PTE_YOUNG
4333 tstne r1, #L_PTE_VALID
4334 #ifndef CONFIG_CPU_USE_DOMAINS
4335diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4336index a5bc92d..0bb4730 100644
4337--- a/arch/arm/plat-omap/sram.c
4338+++ b/arch/arm/plat-omap/sram.c
4339@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4340 * Looks like we need to preserve some bootloader code at the
4341 * beginning of SRAM for jumping to flash for reboot to work...
4342 */
4343+ pax_open_kernel();
4344 memset_io(omap_sram_base + omap_sram_skip, 0,
4345 omap_sram_size - omap_sram_skip);
4346+ pax_close_kernel();
4347 }
4348diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4349index f5144cd..71f6d1f 100644
4350--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4351+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4352@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4353 int (*started)(unsigned ch);
4354 int (*flush)(unsigned ch);
4355 int (*stop)(unsigned ch);
4356-};
4357+} __no_const;
4358
4359 extern void *samsung_dmadev_get_ops(void);
4360 extern void *s3c_dma_get_ops(void);
4361diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4362index 0c3ba9f..95722b3 100644
4363--- a/arch/arm64/kernel/debug-monitors.c
4364+++ b/arch/arm64/kernel/debug-monitors.c
4365@@ -151,7 +151,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4366 return NOTIFY_OK;
4367 }
4368
4369-static struct notifier_block __cpuinitdata os_lock_nb = {
4370+static struct notifier_block os_lock_nb = {
4371 .notifier_call = os_lock_notify,
4372 };
4373
4374diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4375index 5ab825c..96aaec8 100644
4376--- a/arch/arm64/kernel/hw_breakpoint.c
4377+++ b/arch/arm64/kernel/hw_breakpoint.c
4378@@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4379 return NOTIFY_OK;
4380 }
4381
4382-static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4383+static struct notifier_block hw_breakpoint_reset_nb = {
4384 .notifier_call = hw_breakpoint_reset_notify,
4385 };
4386
4387diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4388index c3a58a1..78fbf54 100644
4389--- a/arch/avr32/include/asm/cache.h
4390+++ b/arch/avr32/include/asm/cache.h
4391@@ -1,8 +1,10 @@
4392 #ifndef __ASM_AVR32_CACHE_H
4393 #define __ASM_AVR32_CACHE_H
4394
4395+#include <linux/const.h>
4396+
4397 #define L1_CACHE_SHIFT 5
4398-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4399+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4400
4401 /*
4402 * Memory returned by kmalloc() may be used for DMA, so we must make
4403diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4404index e2c3287..6c4f98c 100644
4405--- a/arch/avr32/include/asm/elf.h
4406+++ b/arch/avr32/include/asm/elf.h
4407@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4408 the loader. We need to make sure that it is out of the way of the program
4409 that it will "exec", and that there is sufficient room for the brk. */
4410
4411-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4412+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4413
4414+#ifdef CONFIG_PAX_ASLR
4415+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4416+
4417+#define PAX_DELTA_MMAP_LEN 15
4418+#define PAX_DELTA_STACK_LEN 15
4419+#endif
4420
4421 /* This yields a mask that user programs can use to figure out what
4422 instruction set this CPU supports. This could be done in user space,
4423diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4424index 479330b..53717a8 100644
4425--- a/arch/avr32/include/asm/kmap_types.h
4426+++ b/arch/avr32/include/asm/kmap_types.h
4427@@ -2,9 +2,9 @@
4428 #define __ASM_AVR32_KMAP_TYPES_H
4429
4430 #ifdef CONFIG_DEBUG_HIGHMEM
4431-# define KM_TYPE_NR 29
4432+# define KM_TYPE_NR 30
4433 #else
4434-# define KM_TYPE_NR 14
4435+# define KM_TYPE_NR 15
4436 #endif
4437
4438 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4439diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4440index b2f2d2d..d1c85cb 100644
4441--- a/arch/avr32/mm/fault.c
4442+++ b/arch/avr32/mm/fault.c
4443@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4444
4445 int exception_trace = 1;
4446
4447+#ifdef CONFIG_PAX_PAGEEXEC
4448+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4449+{
4450+ unsigned long i;
4451+
4452+ printk(KERN_ERR "PAX: bytes at PC: ");
4453+ for (i = 0; i < 20; i++) {
4454+ unsigned char c;
4455+ if (get_user(c, (unsigned char *)pc+i))
4456+ printk(KERN_CONT "???????? ");
4457+ else
4458+ printk(KERN_CONT "%02x ", c);
4459+ }
4460+ printk("\n");
4461+}
4462+#endif
4463+
4464 /*
4465 * This routine handles page faults. It determines the address and the
4466 * problem, and then passes it off to one of the appropriate routines.
4467@@ -174,6 +191,16 @@ bad_area:
4468 up_read(&mm->mmap_sem);
4469
4470 if (user_mode(regs)) {
4471+
4472+#ifdef CONFIG_PAX_PAGEEXEC
4473+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4474+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4475+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4476+ do_group_exit(SIGKILL);
4477+ }
4478+ }
4479+#endif
4480+
4481 if (exception_trace && printk_ratelimit())
4482 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4483 "sp %08lx ecr %lu\n",
4484diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4485index 568885a..f8008df 100644
4486--- a/arch/blackfin/include/asm/cache.h
4487+++ b/arch/blackfin/include/asm/cache.h
4488@@ -7,6 +7,7 @@
4489 #ifndef __ARCH_BLACKFIN_CACHE_H
4490 #define __ARCH_BLACKFIN_CACHE_H
4491
4492+#include <linux/const.h>
4493 #include <linux/linkage.h> /* for asmlinkage */
4494
4495 /*
4496@@ -14,7 +15,7 @@
4497 * Blackfin loads 32 bytes for cache
4498 */
4499 #define L1_CACHE_SHIFT 5
4500-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4501+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4502 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4503
4504 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4505diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4506index aea2718..3639a60 100644
4507--- a/arch/cris/include/arch-v10/arch/cache.h
4508+++ b/arch/cris/include/arch-v10/arch/cache.h
4509@@ -1,8 +1,9 @@
4510 #ifndef _ASM_ARCH_CACHE_H
4511 #define _ASM_ARCH_CACHE_H
4512
4513+#include <linux/const.h>
4514 /* Etrax 100LX have 32-byte cache-lines. */
4515-#define L1_CACHE_BYTES 32
4516 #define L1_CACHE_SHIFT 5
4517+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4518
4519 #endif /* _ASM_ARCH_CACHE_H */
4520diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4521index 7caf25d..ee65ac5 100644
4522--- a/arch/cris/include/arch-v32/arch/cache.h
4523+++ b/arch/cris/include/arch-v32/arch/cache.h
4524@@ -1,11 +1,12 @@
4525 #ifndef _ASM_CRIS_ARCH_CACHE_H
4526 #define _ASM_CRIS_ARCH_CACHE_H
4527
4528+#include <linux/const.h>
4529 #include <arch/hwregs/dma.h>
4530
4531 /* A cache-line is 32 bytes. */
4532-#define L1_CACHE_BYTES 32
4533 #define L1_CACHE_SHIFT 5
4534+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4535
4536 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4537
4538diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4539index b86329d..6709906 100644
4540--- a/arch/frv/include/asm/atomic.h
4541+++ b/arch/frv/include/asm/atomic.h
4542@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4543 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4544 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4545
4546+#define atomic64_read_unchecked(v) atomic64_read(v)
4547+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4548+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4549+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4550+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4551+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4552+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4553+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4554+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4555+
4556 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4557 {
4558 int c, old;
4559diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4560index 2797163..c2a401d 100644
4561--- a/arch/frv/include/asm/cache.h
4562+++ b/arch/frv/include/asm/cache.h
4563@@ -12,10 +12,11 @@
4564 #ifndef __ASM_CACHE_H
4565 #define __ASM_CACHE_H
4566
4567+#include <linux/const.h>
4568
4569 /* bytes per L1 cache line */
4570 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4571-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4572+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4573
4574 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4575 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4576diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4577index 43901f2..0d8b865 100644
4578--- a/arch/frv/include/asm/kmap_types.h
4579+++ b/arch/frv/include/asm/kmap_types.h
4580@@ -2,6 +2,6 @@
4581 #ifndef _ASM_KMAP_TYPES_H
4582 #define _ASM_KMAP_TYPES_H
4583
4584-#define KM_TYPE_NR 17
4585+#define KM_TYPE_NR 18
4586
4587 #endif
4588diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4589index 385fd30..3aaf4fe 100644
4590--- a/arch/frv/mm/elf-fdpic.c
4591+++ b/arch/frv/mm/elf-fdpic.c
4592@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4593 {
4594 struct vm_area_struct *vma;
4595 unsigned long limit;
4596+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4597
4598 if (len > TASK_SIZE)
4599 return -ENOMEM;
4600@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4601 if (addr) {
4602 addr = PAGE_ALIGN(addr);
4603 vma = find_vma(current->mm, addr);
4604- if (TASK_SIZE - len >= addr &&
4605- (!vma || addr + len <= vma->vm_start))
4606+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4607 goto success;
4608 }
4609
4610@@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4611 for (; vma; vma = vma->vm_next) {
4612 if (addr > limit)
4613 break;
4614- if (addr + len <= vma->vm_start)
4615+ if (check_heap_stack_gap(vma, addr, len, offset))
4616 goto success;
4617 addr = vma->vm_end;
4618 }
4619@@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4620 for (; vma; vma = vma->vm_next) {
4621 if (addr > limit)
4622 break;
4623- if (addr + len <= vma->vm_start)
4624+ if (check_heap_stack_gap(vma, addr, len, offset))
4625 goto success;
4626 addr = vma->vm_end;
4627 }
4628diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4629index f4ca594..adc72fd6 100644
4630--- a/arch/hexagon/include/asm/cache.h
4631+++ b/arch/hexagon/include/asm/cache.h
4632@@ -21,9 +21,11 @@
4633 #ifndef __ASM_CACHE_H
4634 #define __ASM_CACHE_H
4635
4636+#include <linux/const.h>
4637+
4638 /* Bytes per L1 cache line */
4639-#define L1_CACHE_SHIFT (5)
4640-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4641+#define L1_CACHE_SHIFT 5
4642+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4643
4644 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4645 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4646diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4647index 6e6fe18..a6ae668 100644
4648--- a/arch/ia64/include/asm/atomic.h
4649+++ b/arch/ia64/include/asm/atomic.h
4650@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4651 #define atomic64_inc(v) atomic64_add(1, (v))
4652 #define atomic64_dec(v) atomic64_sub(1, (v))
4653
4654+#define atomic64_read_unchecked(v) atomic64_read(v)
4655+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4656+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4657+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4658+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4659+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4660+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4661+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4662+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4663+
4664 /* Atomic operations are already serializing */
4665 #define smp_mb__before_atomic_dec() barrier()
4666 #define smp_mb__after_atomic_dec() barrier()
4667diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4668index 988254a..e1ee885 100644
4669--- a/arch/ia64/include/asm/cache.h
4670+++ b/arch/ia64/include/asm/cache.h
4671@@ -1,6 +1,7 @@
4672 #ifndef _ASM_IA64_CACHE_H
4673 #define _ASM_IA64_CACHE_H
4674
4675+#include <linux/const.h>
4676
4677 /*
4678 * Copyright (C) 1998-2000 Hewlett-Packard Co
4679@@ -9,7 +10,7 @@
4680
4681 /* Bytes per L1 (data) cache line. */
4682 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4683-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4684+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4685
4686 #ifdef CONFIG_SMP
4687 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4688diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4689index b5298eb..67c6e62 100644
4690--- a/arch/ia64/include/asm/elf.h
4691+++ b/arch/ia64/include/asm/elf.h
4692@@ -42,6 +42,13 @@
4693 */
4694 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4695
4696+#ifdef CONFIG_PAX_ASLR
4697+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4698+
4699+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4700+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4701+#endif
4702+
4703 #define PT_IA_64_UNWIND 0x70000001
4704
4705 /* IA-64 relocations: */
4706diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4707index 96a8d92..617a1cf 100644
4708--- a/arch/ia64/include/asm/pgalloc.h
4709+++ b/arch/ia64/include/asm/pgalloc.h
4710@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4711 pgd_val(*pgd_entry) = __pa(pud);
4712 }
4713
4714+static inline void
4715+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4716+{
4717+ pgd_populate(mm, pgd_entry, pud);
4718+}
4719+
4720 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4721 {
4722 return quicklist_alloc(0, GFP_KERNEL, NULL);
4723@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4724 pud_val(*pud_entry) = __pa(pmd);
4725 }
4726
4727+static inline void
4728+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4729+{
4730+ pud_populate(mm, pud_entry, pmd);
4731+}
4732+
4733 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4734 {
4735 return quicklist_alloc(0, GFP_KERNEL, NULL);
4736diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4737index 815810c..d60bd4c 100644
4738--- a/arch/ia64/include/asm/pgtable.h
4739+++ b/arch/ia64/include/asm/pgtable.h
4740@@ -12,7 +12,7 @@
4741 * David Mosberger-Tang <davidm@hpl.hp.com>
4742 */
4743
4744-
4745+#include <linux/const.h>
4746 #include <asm/mman.h>
4747 #include <asm/page.h>
4748 #include <asm/processor.h>
4749@@ -142,6 +142,17 @@
4750 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4751 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4752 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4753+
4754+#ifdef CONFIG_PAX_PAGEEXEC
4755+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4756+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4757+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4758+#else
4759+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4760+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4761+# define PAGE_COPY_NOEXEC PAGE_COPY
4762+#endif
4763+
4764 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4765 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4766 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4767diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4768index 54ff557..70c88b7 100644
4769--- a/arch/ia64/include/asm/spinlock.h
4770+++ b/arch/ia64/include/asm/spinlock.h
4771@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4772 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4773
4774 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4775- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4776+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4777 }
4778
4779 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4780diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4781index 449c8c0..50cdf87 100644
4782--- a/arch/ia64/include/asm/uaccess.h
4783+++ b/arch/ia64/include/asm/uaccess.h
4784@@ -42,6 +42,8 @@
4785 #include <asm/pgtable.h>
4786 #include <asm/io.h>
4787
4788+extern void check_object_size(const void *ptr, unsigned long n, bool to);
4789+
4790 /*
4791 * For historical reasons, the following macros are grossly misnamed:
4792 */
4793@@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4794 static inline unsigned long
4795 __copy_to_user (void __user *to, const void *from, unsigned long count)
4796 {
4797+ if (count > INT_MAX)
4798+ return count;
4799+
4800+ if (!__builtin_constant_p(count))
4801+ check_object_size(from, count, true);
4802+
4803 return __copy_user(to, (__force void __user *) from, count);
4804 }
4805
4806 static inline unsigned long
4807 __copy_from_user (void *to, const void __user *from, unsigned long count)
4808 {
4809+ if (count > INT_MAX)
4810+ return count;
4811+
4812+ if (!__builtin_constant_p(count))
4813+ check_object_size(to, count, false);
4814+
4815 return __copy_user((__force void __user *) to, from, count);
4816 }
4817
4818@@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4819 ({ \
4820 void __user *__cu_to = (to); \
4821 const void *__cu_from = (from); \
4822- long __cu_len = (n); \
4823+ unsigned long __cu_len = (n); \
4824 \
4825- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4826+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4827+ if (!__builtin_constant_p(n)) \
4828+ check_object_size(__cu_from, __cu_len, true); \
4829 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4830+ } \
4831 __cu_len; \
4832 })
4833
4834@@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4835 ({ \
4836 void *__cu_to = (to); \
4837 const void __user *__cu_from = (from); \
4838- long __cu_len = (n); \
4839+ unsigned long __cu_len = (n); \
4840 \
4841 __chk_user_ptr(__cu_from); \
4842- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4843+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4844+ if (!__builtin_constant_p(n)) \
4845+ check_object_size(__cu_to, __cu_len, false); \
4846 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4847+ } \
4848 __cu_len; \
4849 })
4850
4851diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4852index 2d67317..07d8bfa 100644
4853--- a/arch/ia64/kernel/err_inject.c
4854+++ b/arch/ia64/kernel/err_inject.c
4855@@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4856 return NOTIFY_OK;
4857 }
4858
4859-static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4860+static struct notifier_block err_inject_cpu_notifier =
4861 {
4862 .notifier_call = err_inject_cpu_callback,
4863 };
4864diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4865index 65bf9cd..794f06b 100644
4866--- a/arch/ia64/kernel/mca.c
4867+++ b/arch/ia64/kernel/mca.c
4868@@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4869 return NOTIFY_OK;
4870 }
4871
4872-static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4873+static struct notifier_block mca_cpu_notifier = {
4874 .notifier_call = mca_cpu_callback
4875 };
4876
4877diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4878index 24603be..948052d 100644
4879--- a/arch/ia64/kernel/module.c
4880+++ b/arch/ia64/kernel/module.c
4881@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4882 void
4883 module_free (struct module *mod, void *module_region)
4884 {
4885- if (mod && mod->arch.init_unw_table &&
4886- module_region == mod->module_init) {
4887+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4888 unw_remove_unwind_table(mod->arch.init_unw_table);
4889 mod->arch.init_unw_table = NULL;
4890 }
4891@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4892 }
4893
4894 static inline int
4895+in_init_rx (const struct module *mod, uint64_t addr)
4896+{
4897+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4898+}
4899+
4900+static inline int
4901+in_init_rw (const struct module *mod, uint64_t addr)
4902+{
4903+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4904+}
4905+
4906+static inline int
4907 in_init (const struct module *mod, uint64_t addr)
4908 {
4909- return addr - (uint64_t) mod->module_init < mod->init_size;
4910+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4911+}
4912+
4913+static inline int
4914+in_core_rx (const struct module *mod, uint64_t addr)
4915+{
4916+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4917+}
4918+
4919+static inline int
4920+in_core_rw (const struct module *mod, uint64_t addr)
4921+{
4922+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4923 }
4924
4925 static inline int
4926 in_core (const struct module *mod, uint64_t addr)
4927 {
4928- return addr - (uint64_t) mod->module_core < mod->core_size;
4929+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4930 }
4931
4932 static inline int
4933@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4934 break;
4935
4936 case RV_BDREL:
4937- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4938+ if (in_init_rx(mod, val))
4939+ val -= (uint64_t) mod->module_init_rx;
4940+ else if (in_init_rw(mod, val))
4941+ val -= (uint64_t) mod->module_init_rw;
4942+ else if (in_core_rx(mod, val))
4943+ val -= (uint64_t) mod->module_core_rx;
4944+ else if (in_core_rw(mod, val))
4945+ val -= (uint64_t) mod->module_core_rw;
4946 break;
4947
4948 case RV_LTV:
4949@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4950 * addresses have been selected...
4951 */
4952 uint64_t gp;
4953- if (mod->core_size > MAX_LTOFF)
4954+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4955 /*
4956 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4957 * at the end of the module.
4958 */
4959- gp = mod->core_size - MAX_LTOFF / 2;
4960+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4961 else
4962- gp = mod->core_size / 2;
4963- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4964+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4965+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4966 mod->arch.gp = gp;
4967 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4968 }
4969diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4970index 77597e5..6f28f3f 100644
4971--- a/arch/ia64/kernel/palinfo.c
4972+++ b/arch/ia64/kernel/palinfo.c
4973@@ -1045,7 +1045,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4974 return NOTIFY_OK;
4975 }
4976
4977-static struct notifier_block __refdata palinfo_cpu_notifier =
4978+static struct notifier_block palinfo_cpu_notifier =
4979 {
4980 .notifier_call = palinfo_cpu_callback,
4981 .priority = 0,
4982diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4983index 79802e5..1a89ec5 100644
4984--- a/arch/ia64/kernel/salinfo.c
4985+++ b/arch/ia64/kernel/salinfo.c
4986@@ -616,7 +616,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4987 return NOTIFY_OK;
4988 }
4989
4990-static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
4991+static struct notifier_block salinfo_cpu_notifier =
4992 {
4993 .notifier_call = salinfo_cpu_callback,
4994 .priority = 0,
4995diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
4996index d9439ef..d0cac6b 100644
4997--- a/arch/ia64/kernel/sys_ia64.c
4998+++ b/arch/ia64/kernel/sys_ia64.c
4999@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5000 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
5001 struct mm_struct *mm = current->mm;
5002 struct vm_area_struct *vma;
5003+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5004
5005 if (len > RGN_MAP_LIMIT)
5006 return -ENOMEM;
5007@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5008 if (REGION_NUMBER(addr) == RGN_HPAGE)
5009 addr = 0;
5010 #endif
5011+
5012+#ifdef CONFIG_PAX_RANDMMAP
5013+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5014+ addr = mm->free_area_cache;
5015+ else
5016+#endif
5017+
5018 if (!addr)
5019 addr = mm->free_area_cache;
5020
5021@@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5022 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
5023 /* At this point: (!vma || addr < vma->vm_end). */
5024 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
5025- if (start_addr != TASK_UNMAPPED_BASE) {
5026+ if (start_addr != mm->mmap_base) {
5027 /* Start a new search --- just in case we missed some holes. */
5028- addr = TASK_UNMAPPED_BASE;
5029+ addr = mm->mmap_base;
5030 goto full_search;
5031 }
5032 return -ENOMEM;
5033 }
5034- if (!vma || addr + len <= vma->vm_start) {
5035+ if (check_heap_stack_gap(vma, addr, len, offset)) {
5036 /* Remember the address where we stopped this search: */
5037 mm->free_area_cache = addr + len;
5038 return addr;
5039diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
5040index dc00b2c..cce53c2 100644
5041--- a/arch/ia64/kernel/topology.c
5042+++ b/arch/ia64/kernel/topology.c
5043@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
5044 return NOTIFY_OK;
5045 }
5046
5047-static struct notifier_block __cpuinitdata cache_cpu_notifier =
5048+static struct notifier_block cache_cpu_notifier =
5049 {
5050 .notifier_call = cache_cpu_callback
5051 };
5052diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5053index 0ccb28f..8992469 100644
5054--- a/arch/ia64/kernel/vmlinux.lds.S
5055+++ b/arch/ia64/kernel/vmlinux.lds.S
5056@@ -198,7 +198,7 @@ SECTIONS {
5057 /* Per-cpu data: */
5058 . = ALIGN(PERCPU_PAGE_SIZE);
5059 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5060- __phys_per_cpu_start = __per_cpu_load;
5061+ __phys_per_cpu_start = per_cpu_load;
5062 /*
5063 * ensure percpu data fits
5064 * into percpu page size
5065diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5066index 6cf0341..d352594 100644
5067--- a/arch/ia64/mm/fault.c
5068+++ b/arch/ia64/mm/fault.c
5069@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5070 return pte_present(pte);
5071 }
5072
5073+#ifdef CONFIG_PAX_PAGEEXEC
5074+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5075+{
5076+ unsigned long i;
5077+
5078+ printk(KERN_ERR "PAX: bytes at PC: ");
5079+ for (i = 0; i < 8; i++) {
5080+ unsigned int c;
5081+ if (get_user(c, (unsigned int *)pc+i))
5082+ printk(KERN_CONT "???????? ");
5083+ else
5084+ printk(KERN_CONT "%08x ", c);
5085+ }
5086+ printk("\n");
5087+}
5088+#endif
5089+
5090 # define VM_READ_BIT 0
5091 # define VM_WRITE_BIT 1
5092 # define VM_EXEC_BIT 2
5093@@ -149,8 +166,21 @@ retry:
5094 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5095 goto bad_area;
5096
5097- if ((vma->vm_flags & mask) != mask)
5098+ if ((vma->vm_flags & mask) != mask) {
5099+
5100+#ifdef CONFIG_PAX_PAGEEXEC
5101+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5102+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5103+ goto bad_area;
5104+
5105+ up_read(&mm->mmap_sem);
5106+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5107+ do_group_exit(SIGKILL);
5108+ }
5109+#endif
5110+
5111 goto bad_area;
5112+ }
5113
5114 /*
5115 * If for any reason at all we couldn't handle the fault, make
5116diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5117index 5ca674b..127c3cb 100644
5118--- a/arch/ia64/mm/hugetlbpage.c
5119+++ b/arch/ia64/mm/hugetlbpage.c
5120@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5121 unsigned long pgoff, unsigned long flags)
5122 {
5123 struct vm_area_struct *vmm;
5124+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5125
5126 if (len > RGN_MAP_LIMIT)
5127 return -ENOMEM;
5128@@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5129 /* At this point: (!vmm || addr < vmm->vm_end). */
5130 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
5131 return -ENOMEM;
5132- if (!vmm || (addr + len) <= vmm->vm_start)
5133+ if (check_heap_stack_gap(vmm, addr, len, offset))
5134 return addr;
5135 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
5136 }
5137diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5138index b755ea9..b9a969e 100644
5139--- a/arch/ia64/mm/init.c
5140+++ b/arch/ia64/mm/init.c
5141@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5142 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5143 vma->vm_end = vma->vm_start + PAGE_SIZE;
5144 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5145+
5146+#ifdef CONFIG_PAX_PAGEEXEC
5147+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5148+ vma->vm_flags &= ~VM_EXEC;
5149+
5150+#ifdef CONFIG_PAX_MPROTECT
5151+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5152+ vma->vm_flags &= ~VM_MAYEXEC;
5153+#endif
5154+
5155+ }
5156+#endif
5157+
5158 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5159 down_write(&current->mm->mmap_sem);
5160 if (insert_vm_struct(current->mm, vma)) {
5161diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5162index 40b3ee9..8c2c112 100644
5163--- a/arch/m32r/include/asm/cache.h
5164+++ b/arch/m32r/include/asm/cache.h
5165@@ -1,8 +1,10 @@
5166 #ifndef _ASM_M32R_CACHE_H
5167 #define _ASM_M32R_CACHE_H
5168
5169+#include <linux/const.h>
5170+
5171 /* L1 cache line size */
5172 #define L1_CACHE_SHIFT 4
5173-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5174+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5175
5176 #endif /* _ASM_M32R_CACHE_H */
5177diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5178index 82abd15..d95ae5d 100644
5179--- a/arch/m32r/lib/usercopy.c
5180+++ b/arch/m32r/lib/usercopy.c
5181@@ -14,6 +14,9 @@
5182 unsigned long
5183 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5184 {
5185+ if ((long)n < 0)
5186+ return n;
5187+
5188 prefetch(from);
5189 if (access_ok(VERIFY_WRITE, to, n))
5190 __copy_user(to,from,n);
5191@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5192 unsigned long
5193 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5194 {
5195+ if ((long)n < 0)
5196+ return n;
5197+
5198 prefetchw(to);
5199 if (access_ok(VERIFY_READ, from, n))
5200 __copy_user_zeroing(to,from,n);
5201diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5202index 0395c51..5f26031 100644
5203--- a/arch/m68k/include/asm/cache.h
5204+++ b/arch/m68k/include/asm/cache.h
5205@@ -4,9 +4,11 @@
5206 #ifndef __ARCH_M68K_CACHE_H
5207 #define __ARCH_M68K_CACHE_H
5208
5209+#include <linux/const.h>
5210+
5211 /* bytes per L1 cache line */
5212 #define L1_CACHE_SHIFT 4
5213-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5214+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5215
5216 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5217
5218diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5219index 4efe96a..60e8699 100644
5220--- a/arch/microblaze/include/asm/cache.h
5221+++ b/arch/microblaze/include/asm/cache.h
5222@@ -13,11 +13,12 @@
5223 #ifndef _ASM_MICROBLAZE_CACHE_H
5224 #define _ASM_MICROBLAZE_CACHE_H
5225
5226+#include <linux/const.h>
5227 #include <asm/registers.h>
5228
5229 #define L1_CACHE_SHIFT 5
5230 /* word-granular cache in microblaze */
5231-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5232+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5233
5234 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5235
5236diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5237index 01cc6ba..bcb7a5d 100644
5238--- a/arch/mips/include/asm/atomic.h
5239+++ b/arch/mips/include/asm/atomic.h
5240@@ -21,6 +21,10 @@
5241 #include <asm/cmpxchg.h>
5242 #include <asm/war.h>
5243
5244+#ifdef CONFIG_GENERIC_ATOMIC64
5245+#include <asm-generic/atomic64.h>
5246+#endif
5247+
5248 #define ATOMIC_INIT(i) { (i) }
5249
5250 /*
5251@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5252 */
5253 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
5254
5255+#define atomic64_read_unchecked(v) atomic64_read(v)
5256+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5257+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5258+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5259+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5260+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5261+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5262+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5263+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5264+
5265 #endif /* CONFIG_64BIT */
5266
5267 /*
5268diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
5269index b4db69f..8f3b093 100644
5270--- a/arch/mips/include/asm/cache.h
5271+++ b/arch/mips/include/asm/cache.h
5272@@ -9,10 +9,11 @@
5273 #ifndef _ASM_CACHE_H
5274 #define _ASM_CACHE_H
5275
5276+#include <linux/const.h>
5277 #include <kmalloc.h>
5278
5279 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
5280-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5281+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5282
5283 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5284 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5285diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
5286index 455c0ac..ad65fbe 100644
5287--- a/arch/mips/include/asm/elf.h
5288+++ b/arch/mips/include/asm/elf.h
5289@@ -372,13 +372,16 @@ extern const char *__elf_platform;
5290 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5291 #endif
5292
5293+#ifdef CONFIG_PAX_ASLR
5294+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5295+
5296+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5297+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5298+#endif
5299+
5300 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5301 struct linux_binprm;
5302 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5303 int uses_interp);
5304
5305-struct mm_struct;
5306-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5307-#define arch_randomize_brk arch_randomize_brk
5308-
5309 #endif /* _ASM_ELF_H */
5310diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5311index c1f6afa..38cc6e9 100644
5312--- a/arch/mips/include/asm/exec.h
5313+++ b/arch/mips/include/asm/exec.h
5314@@ -12,6 +12,6 @@
5315 #ifndef _ASM_EXEC_H
5316 #define _ASM_EXEC_H
5317
5318-extern unsigned long arch_align_stack(unsigned long sp);
5319+#define arch_align_stack(x) ((x) & ~0xfUL)
5320
5321 #endif /* _ASM_EXEC_H */
5322diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5323index dbaec94..6a14935 100644
5324--- a/arch/mips/include/asm/page.h
5325+++ b/arch/mips/include/asm/page.h
5326@@ -96,7 +96,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5327 #ifdef CONFIG_CPU_MIPS32
5328 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5329 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5330- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5331+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5332 #else
5333 typedef struct { unsigned long long pte; } pte_t;
5334 #define pte_val(x) ((x).pte)
5335diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5336index 881d18b..cea38bc 100644
5337--- a/arch/mips/include/asm/pgalloc.h
5338+++ b/arch/mips/include/asm/pgalloc.h
5339@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5340 {
5341 set_pud(pud, __pud((unsigned long)pmd));
5342 }
5343+
5344+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5345+{
5346+ pud_populate(mm, pud, pmd);
5347+}
5348 #endif
5349
5350 /*
5351diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5352index b2050b9..d71bb1b 100644
5353--- a/arch/mips/include/asm/thread_info.h
5354+++ b/arch/mips/include/asm/thread_info.h
5355@@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
5356 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5357 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5358 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5359+/* li takes a 32bit immediate */
5360+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5361 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5362
5363 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5364@@ -126,15 +128,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
5365 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5366 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5367 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5368+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5369+
5370+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5371
5372 /* work to do in syscall_trace_leave() */
5373-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5374+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5375
5376 /* work to do on interrupt/exception return */
5377 #define _TIF_WORK_MASK \
5378 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5379 /* work to do on any return to u-space */
5380-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5381+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5382
5383 #endif /* __KERNEL__ */
5384
5385diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5386index 9fdd8bc..4bd7f1a 100644
5387--- a/arch/mips/kernel/binfmt_elfn32.c
5388+++ b/arch/mips/kernel/binfmt_elfn32.c
5389@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5390 #undef ELF_ET_DYN_BASE
5391 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5392
5393+#ifdef CONFIG_PAX_ASLR
5394+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5395+
5396+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5397+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5398+#endif
5399+
5400 #include <asm/processor.h>
5401 #include <linux/module.h>
5402 #include <linux/elfcore.h>
5403diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5404index ff44823..97f8906 100644
5405--- a/arch/mips/kernel/binfmt_elfo32.c
5406+++ b/arch/mips/kernel/binfmt_elfo32.c
5407@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5408 #undef ELF_ET_DYN_BASE
5409 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5410
5411+#ifdef CONFIG_PAX_ASLR
5412+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5413+
5414+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5415+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5416+#endif
5417+
5418 #include <asm/processor.h>
5419
5420 /*
5421diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5422index a11c6f9..be5e164 100644
5423--- a/arch/mips/kernel/process.c
5424+++ b/arch/mips/kernel/process.c
5425@@ -460,15 +460,3 @@ unsigned long get_wchan(struct task_struct *task)
5426 out:
5427 return pc;
5428 }
5429-
5430-/*
5431- * Don't forget that the stack pointer must be aligned on a 8 bytes
5432- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5433- */
5434-unsigned long arch_align_stack(unsigned long sp)
5435-{
5436- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5437- sp -= get_random_int() & ~PAGE_MASK;
5438-
5439- return sp & ALMASK;
5440-}
5441diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5442index 4812c6d..2069554 100644
5443--- a/arch/mips/kernel/ptrace.c
5444+++ b/arch/mips/kernel/ptrace.c
5445@@ -528,6 +528,10 @@ static inline int audit_arch(void)
5446 return arch;
5447 }
5448
5449+#ifdef CONFIG_GRKERNSEC_SETXID
5450+extern void gr_delayed_cred_worker(void);
5451+#endif
5452+
5453 /*
5454 * Notification of system call entry/exit
5455 * - triggered by current->work.syscall_trace
5456@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5457 /* do the secure computing check first */
5458 secure_computing_strict(regs->regs[2]);
5459
5460+#ifdef CONFIG_GRKERNSEC_SETXID
5461+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5462+ gr_delayed_cred_worker();
5463+#endif
5464+
5465 if (!(current->ptrace & PT_PTRACED))
5466 goto out;
5467
5468diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5469index d20a4bc..7096ae5 100644
5470--- a/arch/mips/kernel/scall32-o32.S
5471+++ b/arch/mips/kernel/scall32-o32.S
5472@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5473
5474 stack_done:
5475 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5476- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5477+ li t1, _TIF_SYSCALL_WORK
5478 and t0, t1
5479 bnez t0, syscall_trace_entry # -> yes
5480
5481diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5482index b64f642..0fe6eab 100644
5483--- a/arch/mips/kernel/scall64-64.S
5484+++ b/arch/mips/kernel/scall64-64.S
5485@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5486
5487 sd a3, PT_R26(sp) # save a3 for syscall restarting
5488
5489- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5490+ li t1, _TIF_SYSCALL_WORK
5491 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5492 and t0, t1, t0
5493 bnez t0, syscall_trace_entry
5494diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5495index c29ac19..c592d05 100644
5496--- a/arch/mips/kernel/scall64-n32.S
5497+++ b/arch/mips/kernel/scall64-n32.S
5498@@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5499
5500 sd a3, PT_R26(sp) # save a3 for syscall restarting
5501
5502- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5503+ li t1, _TIF_SYSCALL_WORK
5504 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5505 and t0, t1, t0
5506 bnez t0, n32_syscall_trace_entry
5507diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5508index cf3e75e..72e93fe 100644
5509--- a/arch/mips/kernel/scall64-o32.S
5510+++ b/arch/mips/kernel/scall64-o32.S
5511@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5512 PTR 4b, bad_stack
5513 .previous
5514
5515- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5516+ li t1, _TIF_SYSCALL_WORK
5517 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5518 and t0, t1, t0
5519 bnez t0, trace_a_syscall
5520diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5521index ddcec1e..c7f983e 100644
5522--- a/arch/mips/mm/fault.c
5523+++ b/arch/mips/mm/fault.c
5524@@ -27,6 +27,23 @@
5525 #include <asm/highmem.h> /* For VMALLOC_END */
5526 #include <linux/kdebug.h>
5527
5528+#ifdef CONFIG_PAX_PAGEEXEC
5529+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5530+{
5531+ unsigned long i;
5532+
5533+ printk(KERN_ERR "PAX: bytes at PC: ");
5534+ for (i = 0; i < 5; i++) {
5535+ unsigned int c;
5536+ if (get_user(c, (unsigned int *)pc+i))
5537+ printk(KERN_CONT "???????? ");
5538+ else
5539+ printk(KERN_CONT "%08x ", c);
5540+ }
5541+ printk("\n");
5542+}
5543+#endif
5544+
5545 /*
5546 * This routine handles page faults. It determines the address,
5547 * and the problem, and then passes it off to one of the appropriate
5548diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5549index 7e5fe27..479a219 100644
5550--- a/arch/mips/mm/mmap.c
5551+++ b/arch/mips/mm/mmap.c
5552@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5553 struct vm_area_struct *vma;
5554 unsigned long addr = addr0;
5555 int do_color_align;
5556+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5557 struct vm_unmapped_area_info info;
5558
5559 if (unlikely(len > TASK_SIZE))
5560@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5561 do_color_align = 1;
5562
5563 /* requesting a specific address */
5564+
5565+#ifdef CONFIG_PAX_RANDMMAP
5566+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5567+#endif
5568+
5569 if (addr) {
5570 if (do_color_align)
5571 addr = COLOUR_ALIGN(addr, pgoff);
5572@@ -91,8 +97,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5573 addr = PAGE_ALIGN(addr);
5574
5575 vma = find_vma(mm, addr);
5576- if (TASK_SIZE - len >= addr &&
5577- (!vma || addr + len <= vma->vm_start))
5578+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5579 return addr;
5580 }
5581
5582@@ -146,6 +151,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5583 {
5584 unsigned long random_factor = 0UL;
5585
5586+#ifdef CONFIG_PAX_RANDMMAP
5587+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5588+#endif
5589+
5590 if (current->flags & PF_RANDOMIZE) {
5591 random_factor = get_random_int();
5592 random_factor = random_factor << PAGE_SHIFT;
5593@@ -157,42 +166,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5594
5595 if (mmap_is_legacy()) {
5596 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5597+
5598+#ifdef CONFIG_PAX_RANDMMAP
5599+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5600+ mm->mmap_base += mm->delta_mmap;
5601+#endif
5602+
5603 mm->get_unmapped_area = arch_get_unmapped_area;
5604 mm->unmap_area = arch_unmap_area;
5605 } else {
5606 mm->mmap_base = mmap_base(random_factor);
5607+
5608+#ifdef CONFIG_PAX_RANDMMAP
5609+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5610+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5611+#endif
5612+
5613 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5614 mm->unmap_area = arch_unmap_area_topdown;
5615 }
5616 }
5617
5618-static inline unsigned long brk_rnd(void)
5619-{
5620- unsigned long rnd = get_random_int();
5621-
5622- rnd = rnd << PAGE_SHIFT;
5623- /* 8MB for 32bit, 256MB for 64bit */
5624- if (TASK_IS_32BIT_ADDR)
5625- rnd = rnd & 0x7ffffful;
5626- else
5627- rnd = rnd & 0xffffffful;
5628-
5629- return rnd;
5630-}
5631-
5632-unsigned long arch_randomize_brk(struct mm_struct *mm)
5633-{
5634- unsigned long base = mm->brk;
5635- unsigned long ret;
5636-
5637- ret = PAGE_ALIGN(base + brk_rnd());
5638-
5639- if (ret < mm->brk)
5640- return mm->brk;
5641-
5642- return ret;
5643-}
5644-
5645 int __virt_addr_valid(const volatile void *kaddr)
5646 {
5647 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5648diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5649index 967d144..db12197 100644
5650--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5651+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5652@@ -11,12 +11,14 @@
5653 #ifndef _ASM_PROC_CACHE_H
5654 #define _ASM_PROC_CACHE_H
5655
5656+#include <linux/const.h>
5657+
5658 /* L1 cache */
5659
5660 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5661 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5662-#define L1_CACHE_BYTES 16 /* bytes per entry */
5663 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5664+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5665 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5666
5667 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5668diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5669index bcb5df2..84fabd2 100644
5670--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5671+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5672@@ -16,13 +16,15 @@
5673 #ifndef _ASM_PROC_CACHE_H
5674 #define _ASM_PROC_CACHE_H
5675
5676+#include <linux/const.h>
5677+
5678 /*
5679 * L1 cache
5680 */
5681 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5682 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5683-#define L1_CACHE_BYTES 32 /* bytes per entry */
5684 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5685+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5686 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5687
5688 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5689diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5690index 4ce7a01..449202a 100644
5691--- a/arch/openrisc/include/asm/cache.h
5692+++ b/arch/openrisc/include/asm/cache.h
5693@@ -19,11 +19,13 @@
5694 #ifndef __ASM_OPENRISC_CACHE_H
5695 #define __ASM_OPENRISC_CACHE_H
5696
5697+#include <linux/const.h>
5698+
5699 /* FIXME: How can we replace these with values from the CPU...
5700 * they shouldn't be hard-coded!
5701 */
5702
5703-#define L1_CACHE_BYTES 16
5704 #define L1_CACHE_SHIFT 4
5705+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5706
5707 #endif /* __ASM_OPENRISC_CACHE_H */
5708diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5709index af9cf30..2aae9b2 100644
5710--- a/arch/parisc/include/asm/atomic.h
5711+++ b/arch/parisc/include/asm/atomic.h
5712@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5713
5714 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5715
5716+#define atomic64_read_unchecked(v) atomic64_read(v)
5717+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5718+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5719+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5720+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5721+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5722+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5723+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5724+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5725+
5726 #endif /* !CONFIG_64BIT */
5727
5728
5729diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5730index 47f11c7..3420df2 100644
5731--- a/arch/parisc/include/asm/cache.h
5732+++ b/arch/parisc/include/asm/cache.h
5733@@ -5,6 +5,7 @@
5734 #ifndef __ARCH_PARISC_CACHE_H
5735 #define __ARCH_PARISC_CACHE_H
5736
5737+#include <linux/const.h>
5738
5739 /*
5740 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5741@@ -15,13 +16,13 @@
5742 * just ruin performance.
5743 */
5744 #ifdef CONFIG_PA20
5745-#define L1_CACHE_BYTES 64
5746 #define L1_CACHE_SHIFT 6
5747 #else
5748-#define L1_CACHE_BYTES 32
5749 #define L1_CACHE_SHIFT 5
5750 #endif
5751
5752+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5753+
5754 #ifndef __ASSEMBLY__
5755
5756 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5757diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5758index 19f6cb1..6c78cf2 100644
5759--- a/arch/parisc/include/asm/elf.h
5760+++ b/arch/parisc/include/asm/elf.h
5761@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5762
5763 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5764
5765+#ifdef CONFIG_PAX_ASLR
5766+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5767+
5768+#define PAX_DELTA_MMAP_LEN 16
5769+#define PAX_DELTA_STACK_LEN 16
5770+#endif
5771+
5772 /* This yields a mask that user programs can use to figure out what
5773 instruction set this CPU supports. This could be done in user space,
5774 but it's not easy, and we've already done it here. */
5775diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5776index fc987a1..6e068ef 100644
5777--- a/arch/parisc/include/asm/pgalloc.h
5778+++ b/arch/parisc/include/asm/pgalloc.h
5779@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5780 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5781 }
5782
5783+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5784+{
5785+ pgd_populate(mm, pgd, pmd);
5786+}
5787+
5788 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5789 {
5790 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5791@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5792 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5793 #define pmd_free(mm, x) do { } while (0)
5794 #define pgd_populate(mm, pmd, pte) BUG()
5795+#define pgd_populate_kernel(mm, pmd, pte) BUG()
5796
5797 #endif
5798
5799diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5800index 7df49fa..38b62bf 100644
5801--- a/arch/parisc/include/asm/pgtable.h
5802+++ b/arch/parisc/include/asm/pgtable.h
5803@@ -218,6 +218,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
5804 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5805 #define PAGE_COPY PAGE_EXECREAD
5806 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5807+
5808+#ifdef CONFIG_PAX_PAGEEXEC
5809+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5810+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5811+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5812+#else
5813+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5814+# define PAGE_COPY_NOEXEC PAGE_COPY
5815+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5816+#endif
5817+
5818 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5819 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5820 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5821diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5822index 4ba2c93..f5e3974 100644
5823--- a/arch/parisc/include/asm/uaccess.h
5824+++ b/arch/parisc/include/asm/uaccess.h
5825@@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5826 const void __user *from,
5827 unsigned long n)
5828 {
5829- int sz = __compiletime_object_size(to);
5830+ size_t sz = __compiletime_object_size(to);
5831 int ret = -EFAULT;
5832
5833- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5834+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5835 ret = __copy_from_user(to, from, n);
5836 else
5837 copy_from_user_overflow();
5838diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5839index 2a625fb..9908930 100644
5840--- a/arch/parisc/kernel/module.c
5841+++ b/arch/parisc/kernel/module.c
5842@@ -98,16 +98,38 @@
5843
5844 /* three functions to determine where in the module core
5845 * or init pieces the location is */
5846+static inline int in_init_rx(struct module *me, void *loc)
5847+{
5848+ return (loc >= me->module_init_rx &&
5849+ loc < (me->module_init_rx + me->init_size_rx));
5850+}
5851+
5852+static inline int in_init_rw(struct module *me, void *loc)
5853+{
5854+ return (loc >= me->module_init_rw &&
5855+ loc < (me->module_init_rw + me->init_size_rw));
5856+}
5857+
5858 static inline int in_init(struct module *me, void *loc)
5859 {
5860- return (loc >= me->module_init &&
5861- loc <= (me->module_init + me->init_size));
5862+ return in_init_rx(me, loc) || in_init_rw(me, loc);
5863+}
5864+
5865+static inline int in_core_rx(struct module *me, void *loc)
5866+{
5867+ return (loc >= me->module_core_rx &&
5868+ loc < (me->module_core_rx + me->core_size_rx));
5869+}
5870+
5871+static inline int in_core_rw(struct module *me, void *loc)
5872+{
5873+ return (loc >= me->module_core_rw &&
5874+ loc < (me->module_core_rw + me->core_size_rw));
5875 }
5876
5877 static inline int in_core(struct module *me, void *loc)
5878 {
5879- return (loc >= me->module_core &&
5880- loc <= (me->module_core + me->core_size));
5881+ return in_core_rx(me, loc) || in_core_rw(me, loc);
5882 }
5883
5884 static inline int in_local(struct module *me, void *loc)
5885@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5886 }
5887
5888 /* align things a bit */
5889- me->core_size = ALIGN(me->core_size, 16);
5890- me->arch.got_offset = me->core_size;
5891- me->core_size += gots * sizeof(struct got_entry);
5892+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5893+ me->arch.got_offset = me->core_size_rw;
5894+ me->core_size_rw += gots * sizeof(struct got_entry);
5895
5896- me->core_size = ALIGN(me->core_size, 16);
5897- me->arch.fdesc_offset = me->core_size;
5898- me->core_size += fdescs * sizeof(Elf_Fdesc);
5899+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5900+ me->arch.fdesc_offset = me->core_size_rw;
5901+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5902
5903 me->arch.got_max = gots;
5904 me->arch.fdesc_max = fdescs;
5905@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5906
5907 BUG_ON(value == 0);
5908
5909- got = me->module_core + me->arch.got_offset;
5910+ got = me->module_core_rw + me->arch.got_offset;
5911 for (i = 0; got[i].addr; i++)
5912 if (got[i].addr == value)
5913 goto out;
5914@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5915 #ifdef CONFIG_64BIT
5916 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5917 {
5918- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5919+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5920
5921 if (!value) {
5922 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5923@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5924
5925 /* Create new one */
5926 fdesc->addr = value;
5927- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5928+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5929 return (Elf_Addr)fdesc;
5930 }
5931 #endif /* CONFIG_64BIT */
5932@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5933
5934 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5935 end = table + sechdrs[me->arch.unwind_section].sh_size;
5936- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5937+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5938
5939 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5940 me->arch.unwind_section, table, end, gp);
5941diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5942index f76c108..92bad82 100644
5943--- a/arch/parisc/kernel/sys_parisc.c
5944+++ b/arch/parisc/kernel/sys_parisc.c
5945@@ -33,9 +33,11 @@
5946 #include <linux/utsname.h>
5947 #include <linux/personality.h>
5948
5949-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5950+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5951+ unsigned long flags)
5952 {
5953 struct vm_area_struct *vma;
5954+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5955
5956 addr = PAGE_ALIGN(addr);
5957
5958@@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5959 /* At this point: (!vma || addr < vma->vm_end). */
5960 if (TASK_SIZE - len < addr)
5961 return -ENOMEM;
5962- if (!vma || addr + len <= vma->vm_start)
5963+ if (check_heap_stack_gap(vma, addr, len, offset))
5964 return addr;
5965 addr = vma->vm_end;
5966 }
5967@@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
5968 return offset & 0x3FF000;
5969 }
5970
5971-static unsigned long get_shared_area(struct address_space *mapping,
5972- unsigned long addr, unsigned long len, unsigned long pgoff)
5973+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5974+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5975 {
5976 struct vm_area_struct *vma;
5977 int offset = mapping ? get_offset(mapping) : 0;
5978+ unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5979
5980 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
5981
5982@@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5983 /* At this point: (!vma || addr < vma->vm_end). */
5984 if (TASK_SIZE - len < addr)
5985 return -ENOMEM;
5986- if (!vma || addr + len <= vma->vm_start)
5987+ if (check_heap_stack_gap(vma, addr, len, rand_offset))
5988 return addr;
5989 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
5990 if (addr < vma->vm_end) /* handle wraparound */
5991@@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5992 if (flags & MAP_FIXED)
5993 return addr;
5994 if (!addr)
5995- addr = TASK_UNMAPPED_BASE;
5996+ addr = current->mm->mmap_base;
5997
5998 if (filp) {
5999- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
6000+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
6001 } else if(flags & MAP_SHARED) {
6002- addr = get_shared_area(NULL, addr, len, pgoff);
6003+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
6004 } else {
6005- addr = get_unshared_area(addr, len);
6006+ addr = get_unshared_area(filp, addr, len, flags);
6007 }
6008 return addr;
6009 }
6010diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
6011index 45ba99f..8e22c33 100644
6012--- a/arch/parisc/kernel/traps.c
6013+++ b/arch/parisc/kernel/traps.c
6014@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
6015
6016 down_read(&current->mm->mmap_sem);
6017 vma = find_vma(current->mm,regs->iaoq[0]);
6018- if (vma && (regs->iaoq[0] >= vma->vm_start)
6019- && (vma->vm_flags & VM_EXEC)) {
6020-
6021+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
6022 fault_address = regs->iaoq[0];
6023 fault_space = regs->iasq[0];
6024
6025diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
6026index 18162ce..94de376 100644
6027--- a/arch/parisc/mm/fault.c
6028+++ b/arch/parisc/mm/fault.c
6029@@ -15,6 +15,7 @@
6030 #include <linux/sched.h>
6031 #include <linux/interrupt.h>
6032 #include <linux/module.h>
6033+#include <linux/unistd.h>
6034
6035 #include <asm/uaccess.h>
6036 #include <asm/traps.h>
6037@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
6038 static unsigned long
6039 parisc_acctyp(unsigned long code, unsigned int inst)
6040 {
6041- if (code == 6 || code == 16)
6042+ if (code == 6 || code == 7 || code == 16)
6043 return VM_EXEC;
6044
6045 switch (inst & 0xf0000000) {
6046@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
6047 }
6048 #endif
6049
6050+#ifdef CONFIG_PAX_PAGEEXEC
6051+/*
6052+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
6053+ *
6054+ * returns 1 when task should be killed
6055+ * 2 when rt_sigreturn trampoline was detected
6056+ * 3 when unpatched PLT trampoline was detected
6057+ */
6058+static int pax_handle_fetch_fault(struct pt_regs *regs)
6059+{
6060+
6061+#ifdef CONFIG_PAX_EMUPLT
6062+ int err;
6063+
6064+ do { /* PaX: unpatched PLT emulation */
6065+ unsigned int bl, depwi;
6066+
6067+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
6068+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
6069+
6070+ if (err)
6071+ break;
6072+
6073+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
6074+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
6075+
6076+ err = get_user(ldw, (unsigned int *)addr);
6077+ err |= get_user(bv, (unsigned int *)(addr+4));
6078+ err |= get_user(ldw2, (unsigned int *)(addr+8));
6079+
6080+ if (err)
6081+ break;
6082+
6083+ if (ldw == 0x0E801096U &&
6084+ bv == 0xEAC0C000U &&
6085+ ldw2 == 0x0E881095U)
6086+ {
6087+ unsigned int resolver, map;
6088+
6089+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
6090+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
6091+ if (err)
6092+ break;
6093+
6094+ regs->gr[20] = instruction_pointer(regs)+8;
6095+ regs->gr[21] = map;
6096+ regs->gr[22] = resolver;
6097+ regs->iaoq[0] = resolver | 3UL;
6098+ regs->iaoq[1] = regs->iaoq[0] + 4;
6099+ return 3;
6100+ }
6101+ }
6102+ } while (0);
6103+#endif
6104+
6105+#ifdef CONFIG_PAX_EMUTRAMP
6106+
6107+#ifndef CONFIG_PAX_EMUSIGRT
6108+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
6109+ return 1;
6110+#endif
6111+
6112+ do { /* PaX: rt_sigreturn emulation */
6113+ unsigned int ldi1, ldi2, bel, nop;
6114+
6115+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
6116+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
6117+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
6118+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
6119+
6120+ if (err)
6121+ break;
6122+
6123+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
6124+ ldi2 == 0x3414015AU &&
6125+ bel == 0xE4008200U &&
6126+ nop == 0x08000240U)
6127+ {
6128+ regs->gr[25] = (ldi1 & 2) >> 1;
6129+ regs->gr[20] = __NR_rt_sigreturn;
6130+ regs->gr[31] = regs->iaoq[1] + 16;
6131+ regs->sr[0] = regs->iasq[1];
6132+ regs->iaoq[0] = 0x100UL;
6133+ regs->iaoq[1] = regs->iaoq[0] + 4;
6134+ regs->iasq[0] = regs->sr[2];
6135+ regs->iasq[1] = regs->sr[2];
6136+ return 2;
6137+ }
6138+ } while (0);
6139+#endif
6140+
6141+ return 1;
6142+}
6143+
6144+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6145+{
6146+ unsigned long i;
6147+
6148+ printk(KERN_ERR "PAX: bytes at PC: ");
6149+ for (i = 0; i < 5; i++) {
6150+ unsigned int c;
6151+ if (get_user(c, (unsigned int *)pc+i))
6152+ printk(KERN_CONT "???????? ");
6153+ else
6154+ printk(KERN_CONT "%08x ", c);
6155+ }
6156+ printk("\n");
6157+}
6158+#endif
6159+
6160 int fixup_exception(struct pt_regs *regs)
6161 {
6162 const struct exception_table_entry *fix;
6163@@ -192,8 +303,33 @@ good_area:
6164
6165 acc_type = parisc_acctyp(code,regs->iir);
6166
6167- if ((vma->vm_flags & acc_type) != acc_type)
6168+ if ((vma->vm_flags & acc_type) != acc_type) {
6169+
6170+#ifdef CONFIG_PAX_PAGEEXEC
6171+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
6172+ (address & ~3UL) == instruction_pointer(regs))
6173+ {
6174+ up_read(&mm->mmap_sem);
6175+ switch (pax_handle_fetch_fault(regs)) {
6176+
6177+#ifdef CONFIG_PAX_EMUPLT
6178+ case 3:
6179+ return;
6180+#endif
6181+
6182+#ifdef CONFIG_PAX_EMUTRAMP
6183+ case 2:
6184+ return;
6185+#endif
6186+
6187+ }
6188+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
6189+ do_group_exit(SIGKILL);
6190+ }
6191+#endif
6192+
6193 goto bad_area;
6194+ }
6195
6196 /*
6197 * If for any reason at all we couldn't handle the fault, make
6198diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
6199index e3b1d41..8e81edf 100644
6200--- a/arch/powerpc/include/asm/atomic.h
6201+++ b/arch/powerpc/include/asm/atomic.h
6202@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
6203 return t1;
6204 }
6205
6206+#define atomic64_read_unchecked(v) atomic64_read(v)
6207+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6208+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6209+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6210+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6211+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6212+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6213+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6214+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6215+
6216 #endif /* __powerpc64__ */
6217
6218 #endif /* __KERNEL__ */
6219diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
6220index 9e495c9..b6878e5 100644
6221--- a/arch/powerpc/include/asm/cache.h
6222+++ b/arch/powerpc/include/asm/cache.h
6223@@ -3,6 +3,7 @@
6224
6225 #ifdef __KERNEL__
6226
6227+#include <linux/const.h>
6228
6229 /* bytes per L1 cache line */
6230 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
6231@@ -22,7 +23,7 @@
6232 #define L1_CACHE_SHIFT 7
6233 #endif
6234
6235-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6236+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6237
6238 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6239
6240diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
6241index 6abf0a1..459d0f1 100644
6242--- a/arch/powerpc/include/asm/elf.h
6243+++ b/arch/powerpc/include/asm/elf.h
6244@@ -28,8 +28,19 @@
6245 the loader. We need to make sure that it is out of the way of the program
6246 that it will "exec", and that there is sufficient room for the brk. */
6247
6248-extern unsigned long randomize_et_dyn(unsigned long base);
6249-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
6250+#define ELF_ET_DYN_BASE (0x20000000)
6251+
6252+#ifdef CONFIG_PAX_ASLR
6253+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
6254+
6255+#ifdef __powerpc64__
6256+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
6257+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
6258+#else
6259+#define PAX_DELTA_MMAP_LEN 15
6260+#define PAX_DELTA_STACK_LEN 15
6261+#endif
6262+#endif
6263
6264 /*
6265 * Our registers are always unsigned longs, whether we're a 32 bit
6266@@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6267 (0x7ff >> (PAGE_SHIFT - 12)) : \
6268 (0x3ffff >> (PAGE_SHIFT - 12)))
6269
6270-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6271-#define arch_randomize_brk arch_randomize_brk
6272-
6273-
6274 #ifdef CONFIG_SPU_BASE
6275 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
6276 #define NT_SPU 1
6277diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
6278index 8196e9c..d83a9f3 100644
6279--- a/arch/powerpc/include/asm/exec.h
6280+++ b/arch/powerpc/include/asm/exec.h
6281@@ -4,6 +4,6 @@
6282 #ifndef _ASM_POWERPC_EXEC_H
6283 #define _ASM_POWERPC_EXEC_H
6284
6285-extern unsigned long arch_align_stack(unsigned long sp);
6286+#define arch_align_stack(x) ((x) & ~0xfUL)
6287
6288 #endif /* _ASM_POWERPC_EXEC_H */
6289diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
6290index 5acabbd..7ea14fa 100644
6291--- a/arch/powerpc/include/asm/kmap_types.h
6292+++ b/arch/powerpc/include/asm/kmap_types.h
6293@@ -10,7 +10,7 @@
6294 * 2 of the License, or (at your option) any later version.
6295 */
6296
6297-#define KM_TYPE_NR 16
6298+#define KM_TYPE_NR 17
6299
6300 #endif /* __KERNEL__ */
6301 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
6302diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6303index 8565c25..2865190 100644
6304--- a/arch/powerpc/include/asm/mman.h
6305+++ b/arch/powerpc/include/asm/mman.h
6306@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6307 }
6308 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6309
6310-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6311+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6312 {
6313 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6314 }
6315diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6316index f072e97..b436dee 100644
6317--- a/arch/powerpc/include/asm/page.h
6318+++ b/arch/powerpc/include/asm/page.h
6319@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6320 * and needs to be executable. This means the whole heap ends
6321 * up being executable.
6322 */
6323-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6324- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6325+#define VM_DATA_DEFAULT_FLAGS32 \
6326+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6327+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6328
6329 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6330 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6331@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6332 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6333 #endif
6334
6335+#define ktla_ktva(addr) (addr)
6336+#define ktva_ktla(addr) (addr)
6337+
6338 /*
6339 * Use the top bit of the higher-level page table entries to indicate whether
6340 * the entries we point to contain hugepages. This works because we know that
6341diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6342index cd915d6..c10cee8 100644
6343--- a/arch/powerpc/include/asm/page_64.h
6344+++ b/arch/powerpc/include/asm/page_64.h
6345@@ -154,15 +154,18 @@ do { \
6346 * stack by default, so in the absence of a PT_GNU_STACK program header
6347 * we turn execute permission off.
6348 */
6349-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6350- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6351+#define VM_STACK_DEFAULT_FLAGS32 \
6352+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6353+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6354
6355 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6356 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6357
6358+#ifndef CONFIG_PAX_PAGEEXEC
6359 #define VM_STACK_DEFAULT_FLAGS \
6360 (is_32bit_task() ? \
6361 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6362+#endif
6363
6364 #include <asm-generic/getorder.h>
6365
6366diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6367index 292725c..f87ae14 100644
6368--- a/arch/powerpc/include/asm/pgalloc-64.h
6369+++ b/arch/powerpc/include/asm/pgalloc-64.h
6370@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6371 #ifndef CONFIG_PPC_64K_PAGES
6372
6373 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6374+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6375
6376 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6377 {
6378@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6379 pud_set(pud, (unsigned long)pmd);
6380 }
6381
6382+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6383+{
6384+ pud_populate(mm, pud, pmd);
6385+}
6386+
6387 #define pmd_populate(mm, pmd, pte_page) \
6388 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6389 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6390@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6391 #else /* CONFIG_PPC_64K_PAGES */
6392
6393 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6394+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6395
6396 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6397 pte_t *pte)
6398diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6399index a9cbd3b..3b67efa 100644
6400--- a/arch/powerpc/include/asm/pgtable.h
6401+++ b/arch/powerpc/include/asm/pgtable.h
6402@@ -2,6 +2,7 @@
6403 #define _ASM_POWERPC_PGTABLE_H
6404 #ifdef __KERNEL__
6405
6406+#include <linux/const.h>
6407 #ifndef __ASSEMBLY__
6408 #include <asm/processor.h> /* For TASK_SIZE */
6409 #include <asm/mmu.h>
6410diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6411index 4aad413..85d86bf 100644
6412--- a/arch/powerpc/include/asm/pte-hash32.h
6413+++ b/arch/powerpc/include/asm/pte-hash32.h
6414@@ -21,6 +21,7 @@
6415 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6416 #define _PAGE_USER 0x004 /* usermode access allowed */
6417 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6418+#define _PAGE_EXEC _PAGE_GUARDED
6419 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6420 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6421 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6422diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6423index 3d5c9dc..62f8414 100644
6424--- a/arch/powerpc/include/asm/reg.h
6425+++ b/arch/powerpc/include/asm/reg.h
6426@@ -215,6 +215,7 @@
6427 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6428 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6429 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6430+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6431 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6432 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6433 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6434diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6435index 406b7b9..af63426 100644
6436--- a/arch/powerpc/include/asm/thread_info.h
6437+++ b/arch/powerpc/include/asm/thread_info.h
6438@@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
6439 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6440 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6441 #define TIF_SINGLESTEP 8 /* singlestepping active */
6442-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
6443 #define TIF_SECCOMP 10 /* secure computing */
6444 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
6445 #define TIF_NOERROR 12 /* Force successful syscall return */
6446@@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6447 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
6448 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6449 for stack store? */
6450+#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6451+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6452+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
6453
6454 /* as above, but as bit values */
6455 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6456@@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
6457 #define _TIF_UPROBE (1<<TIF_UPROBE)
6458 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6459 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6460+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6461 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6462- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
6463+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6464+ _TIF_GRSEC_SETXID)
6465
6466 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6467 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6468diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6469index 4db4959..335e00c 100644
6470--- a/arch/powerpc/include/asm/uaccess.h
6471+++ b/arch/powerpc/include/asm/uaccess.h
6472@@ -13,6 +13,8 @@
6473 #define VERIFY_READ 0
6474 #define VERIFY_WRITE 1
6475
6476+extern void check_object_size(const void *ptr, unsigned long n, bool to);
6477+
6478 /*
6479 * The fs value determines whether argument validity checking should be
6480 * performed or not. If get_fs() == USER_DS, checking is performed, with
6481@@ -318,52 +320,6 @@ do { \
6482 extern unsigned long __copy_tofrom_user(void __user *to,
6483 const void __user *from, unsigned long size);
6484
6485-#ifndef __powerpc64__
6486-
6487-static inline unsigned long copy_from_user(void *to,
6488- const void __user *from, unsigned long n)
6489-{
6490- unsigned long over;
6491-
6492- if (access_ok(VERIFY_READ, from, n))
6493- return __copy_tofrom_user((__force void __user *)to, from, n);
6494- if ((unsigned long)from < TASK_SIZE) {
6495- over = (unsigned long)from + n - TASK_SIZE;
6496- return __copy_tofrom_user((__force void __user *)to, from,
6497- n - over) + over;
6498- }
6499- return n;
6500-}
6501-
6502-static inline unsigned long copy_to_user(void __user *to,
6503- const void *from, unsigned long n)
6504-{
6505- unsigned long over;
6506-
6507- if (access_ok(VERIFY_WRITE, to, n))
6508- return __copy_tofrom_user(to, (__force void __user *)from, n);
6509- if ((unsigned long)to < TASK_SIZE) {
6510- over = (unsigned long)to + n - TASK_SIZE;
6511- return __copy_tofrom_user(to, (__force void __user *)from,
6512- n - over) + over;
6513- }
6514- return n;
6515-}
6516-
6517-#else /* __powerpc64__ */
6518-
6519-#define __copy_in_user(to, from, size) \
6520- __copy_tofrom_user((to), (from), (size))
6521-
6522-extern unsigned long copy_from_user(void *to, const void __user *from,
6523- unsigned long n);
6524-extern unsigned long copy_to_user(void __user *to, const void *from,
6525- unsigned long n);
6526-extern unsigned long copy_in_user(void __user *to, const void __user *from,
6527- unsigned long n);
6528-
6529-#endif /* __powerpc64__ */
6530-
6531 static inline unsigned long __copy_from_user_inatomic(void *to,
6532 const void __user *from, unsigned long n)
6533 {
6534@@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6535 if (ret == 0)
6536 return 0;
6537 }
6538+
6539+ if (!__builtin_constant_p(n))
6540+ check_object_size(to, n, false);
6541+
6542 return __copy_tofrom_user((__force void __user *)to, from, n);
6543 }
6544
6545@@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6546 if (ret == 0)
6547 return 0;
6548 }
6549+
6550+ if (!__builtin_constant_p(n))
6551+ check_object_size(from, n, true);
6552+
6553 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6554 }
6555
6556@@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6557 return __copy_to_user_inatomic(to, from, size);
6558 }
6559
6560+#ifndef __powerpc64__
6561+
6562+static inline unsigned long __must_check copy_from_user(void *to,
6563+ const void __user *from, unsigned long n)
6564+{
6565+ unsigned long over;
6566+
6567+ if ((long)n < 0)
6568+ return n;
6569+
6570+ if (access_ok(VERIFY_READ, from, n)) {
6571+ if (!__builtin_constant_p(n))
6572+ check_object_size(to, n, false);
6573+ return __copy_tofrom_user((__force void __user *)to, from, n);
6574+ }
6575+ if ((unsigned long)from < TASK_SIZE) {
6576+ over = (unsigned long)from + n - TASK_SIZE;
6577+ if (!__builtin_constant_p(n - over))
6578+ check_object_size(to, n - over, false);
6579+ return __copy_tofrom_user((__force void __user *)to, from,
6580+ n - over) + over;
6581+ }
6582+ return n;
6583+}
6584+
6585+static inline unsigned long __must_check copy_to_user(void __user *to,
6586+ const void *from, unsigned long n)
6587+{
6588+ unsigned long over;
6589+
6590+ if ((long)n < 0)
6591+ return n;
6592+
6593+ if (access_ok(VERIFY_WRITE, to, n)) {
6594+ if (!__builtin_constant_p(n))
6595+ check_object_size(from, n, true);
6596+ return __copy_tofrom_user(to, (__force void __user *)from, n);
6597+ }
6598+ if ((unsigned long)to < TASK_SIZE) {
6599+ over = (unsigned long)to + n - TASK_SIZE;
6600+ if (!__builtin_constant_p(n))
6601+ check_object_size(from, n - over, true);
6602+ return __copy_tofrom_user(to, (__force void __user *)from,
6603+ n - over) + over;
6604+ }
6605+ return n;
6606+}
6607+
6608+#else /* __powerpc64__ */
6609+
6610+#define __copy_in_user(to, from, size) \
6611+ __copy_tofrom_user((to), (from), (size))
6612+
6613+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6614+{
6615+ if ((long)n < 0 || n > INT_MAX)
6616+ return n;
6617+
6618+ if (!__builtin_constant_p(n))
6619+ check_object_size(to, n, false);
6620+
6621+ if (likely(access_ok(VERIFY_READ, from, n)))
6622+ n = __copy_from_user(to, from, n);
6623+ else
6624+ memset(to, 0, n);
6625+ return n;
6626+}
6627+
6628+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6629+{
6630+ if ((long)n < 0 || n > INT_MAX)
6631+ return n;
6632+
6633+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
6634+ if (!__builtin_constant_p(n))
6635+ check_object_size(from, n, true);
6636+ n = __copy_to_user(to, from, n);
6637+ }
6638+ return n;
6639+}
6640+
6641+extern unsigned long copy_in_user(void __user *to, const void __user *from,
6642+ unsigned long n);
6643+
6644+#endif /* __powerpc64__ */
6645+
6646 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6647
6648 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6649diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6650index 4684e33..acc4d19e 100644
6651--- a/arch/powerpc/kernel/exceptions-64e.S
6652+++ b/arch/powerpc/kernel/exceptions-64e.S
6653@@ -715,6 +715,7 @@ storage_fault_common:
6654 std r14,_DAR(r1)
6655 std r15,_DSISR(r1)
6656 addi r3,r1,STACK_FRAME_OVERHEAD
6657+ bl .save_nvgprs
6658 mr r4,r14
6659 mr r5,r15
6660 ld r14,PACA_EXGEN+EX_R14(r13)
6661@@ -723,8 +724,7 @@ storage_fault_common:
6662 cmpdi r3,0
6663 bne- 1f
6664 b .ret_from_except_lite
6665-1: bl .save_nvgprs
6666- mr r5,r3
6667+1: mr r5,r3
6668 addi r3,r1,STACK_FRAME_OVERHEAD
6669 ld r4,_DAR(r1)
6670 bl .bad_page_fault
6671diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6672index 3684cbd..bc89eab 100644
6673--- a/arch/powerpc/kernel/exceptions-64s.S
6674+++ b/arch/powerpc/kernel/exceptions-64s.S
6675@@ -1206,10 +1206,10 @@ handle_page_fault:
6676 11: ld r4,_DAR(r1)
6677 ld r5,_DSISR(r1)
6678 addi r3,r1,STACK_FRAME_OVERHEAD
6679+ bl .save_nvgprs
6680 bl .do_page_fault
6681 cmpdi r3,0
6682 beq+ 12f
6683- bl .save_nvgprs
6684 mr r5,r3
6685 addi r3,r1,STACK_FRAME_OVERHEAD
6686 lwz r4,_DAR(r1)
6687diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6688index 2e3200c..72095ce 100644
6689--- a/arch/powerpc/kernel/module_32.c
6690+++ b/arch/powerpc/kernel/module_32.c
6691@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6692 me->arch.core_plt_section = i;
6693 }
6694 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6695- printk("Module doesn't contain .plt or .init.plt sections.\n");
6696+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6697 return -ENOEXEC;
6698 }
6699
6700@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6701
6702 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6703 /* Init, or core PLT? */
6704- if (location >= mod->module_core
6705- && location < mod->module_core + mod->core_size)
6706+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6707+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6708 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6709- else
6710+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6711+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6712 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6713+ else {
6714+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6715+ return ~0UL;
6716+ }
6717
6718 /* Find this entry, or if that fails, the next avail. entry */
6719 while (entry->jump[0]) {
6720diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6721index 8143067..21ae55b 100644
6722--- a/arch/powerpc/kernel/process.c
6723+++ b/arch/powerpc/kernel/process.c
6724@@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
6725 * Lookup NIP late so we have the best change of getting the
6726 * above info out without failing
6727 */
6728- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6729- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6730+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6731+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6732 #endif
6733 show_stack(current, (unsigned long *) regs->gpr[1]);
6734 if (!user_mode(regs))
6735@@ -1129,10 +1129,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6736 newsp = stack[0];
6737 ip = stack[STACK_FRAME_LR_SAVE];
6738 if (!firstframe || ip != lr) {
6739- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6740+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6741 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6742 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6743- printk(" (%pS)",
6744+ printk(" (%pA)",
6745 (void *)current->ret_stack[curr_frame].ret);
6746 curr_frame--;
6747 }
6748@@ -1152,7 +1152,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6749 struct pt_regs *regs = (struct pt_regs *)
6750 (sp + STACK_FRAME_OVERHEAD);
6751 lr = regs->link;
6752- printk("--- Exception: %lx at %pS\n LR = %pS\n",
6753+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
6754 regs->trap, (void *)regs->nip, (void *)lr);
6755 firstframe = 1;
6756 }
6757@@ -1194,58 +1194,3 @@ void __ppc64_runlatch_off(void)
6758 mtspr(SPRN_CTRLT, ctrl);
6759 }
6760 #endif /* CONFIG_PPC64 */
6761-
6762-unsigned long arch_align_stack(unsigned long sp)
6763-{
6764- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6765- sp -= get_random_int() & ~PAGE_MASK;
6766- return sp & ~0xf;
6767-}
6768-
6769-static inline unsigned long brk_rnd(void)
6770-{
6771- unsigned long rnd = 0;
6772-
6773- /* 8MB for 32bit, 1GB for 64bit */
6774- if (is_32bit_task())
6775- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6776- else
6777- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6778-
6779- return rnd << PAGE_SHIFT;
6780-}
6781-
6782-unsigned long arch_randomize_brk(struct mm_struct *mm)
6783-{
6784- unsigned long base = mm->brk;
6785- unsigned long ret;
6786-
6787-#ifdef CONFIG_PPC_STD_MMU_64
6788- /*
6789- * If we are using 1TB segments and we are allowed to randomise
6790- * the heap, we can put it above 1TB so it is backed by a 1TB
6791- * segment. Otherwise the heap will be in the bottom 1TB
6792- * which always uses 256MB segments and this may result in a
6793- * performance penalty.
6794- */
6795- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6796- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6797-#endif
6798-
6799- ret = PAGE_ALIGN(base + brk_rnd());
6800-
6801- if (ret < mm->brk)
6802- return mm->brk;
6803-
6804- return ret;
6805-}
6806-
6807-unsigned long randomize_et_dyn(unsigned long base)
6808-{
6809- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6810-
6811- if (ret < base)
6812- return base;
6813-
6814- return ret;
6815-}
6816diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6817index c497000..8fde506 100644
6818--- a/arch/powerpc/kernel/ptrace.c
6819+++ b/arch/powerpc/kernel/ptrace.c
6820@@ -1737,6 +1737,10 @@ long arch_ptrace(struct task_struct *child, long request,
6821 return ret;
6822 }
6823
6824+#ifdef CONFIG_GRKERNSEC_SETXID
6825+extern void gr_delayed_cred_worker(void);
6826+#endif
6827+
6828 /*
6829 * We must return the syscall number to actually look up in the table.
6830 * This can be -1L to skip running any syscall at all.
6831@@ -1747,6 +1751,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6832
6833 secure_computing_strict(regs->gpr[0]);
6834
6835+#ifdef CONFIG_GRKERNSEC_SETXID
6836+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6837+ gr_delayed_cred_worker();
6838+#endif
6839+
6840 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6841 tracehook_report_syscall_entry(regs))
6842 /*
6843@@ -1781,6 +1790,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6844 {
6845 int step;
6846
6847+#ifdef CONFIG_GRKERNSEC_SETXID
6848+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6849+ gr_delayed_cred_worker();
6850+#endif
6851+
6852 audit_syscall_exit(regs);
6853
6854 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6855diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6856index 804e323..79181c1 100644
6857--- a/arch/powerpc/kernel/signal_32.c
6858+++ b/arch/powerpc/kernel/signal_32.c
6859@@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6860 /* Save user registers on the stack */
6861 frame = &rt_sf->uc.uc_mcontext;
6862 addr = frame;
6863- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6864+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6865 if (save_user_regs(regs, frame, 0, 1))
6866 goto badframe;
6867 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6868diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6869index 1ca045d..139c3f7 100644
6870--- a/arch/powerpc/kernel/signal_64.c
6871+++ b/arch/powerpc/kernel/signal_64.c
6872@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6873 current->thread.fpscr.val = 0;
6874
6875 /* Set up to return from userspace. */
6876- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6877+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6878 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6879 } else {
6880 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6881diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6882index 3ce1f86..c30e629 100644
6883--- a/arch/powerpc/kernel/sysfs.c
6884+++ b/arch/powerpc/kernel/sysfs.c
6885@@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6886 return NOTIFY_OK;
6887 }
6888
6889-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6890+static struct notifier_block sysfs_cpu_nb = {
6891 .notifier_call = sysfs_cpu_notify,
6892 };
6893
6894diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6895index 3251840..3f7c77a 100644
6896--- a/arch/powerpc/kernel/traps.c
6897+++ b/arch/powerpc/kernel/traps.c
6898@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6899 return flags;
6900 }
6901
6902+extern void gr_handle_kernel_exploit(void);
6903+
6904 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6905 int signr)
6906 {
6907@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6908 panic("Fatal exception in interrupt");
6909 if (panic_on_oops)
6910 panic("Fatal exception");
6911+
6912+ gr_handle_kernel_exploit();
6913+
6914 do_exit(signr);
6915 }
6916
6917diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6918index 1b2076f..835e4be 100644
6919--- a/arch/powerpc/kernel/vdso.c
6920+++ b/arch/powerpc/kernel/vdso.c
6921@@ -34,6 +34,7 @@
6922 #include <asm/firmware.h>
6923 #include <asm/vdso.h>
6924 #include <asm/vdso_datapage.h>
6925+#include <asm/mman.h>
6926
6927 #include "setup.h"
6928
6929@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6930 vdso_base = VDSO32_MBASE;
6931 #endif
6932
6933- current->mm->context.vdso_base = 0;
6934+ current->mm->context.vdso_base = ~0UL;
6935
6936 /* vDSO has a problem and was disabled, just don't "enable" it for the
6937 * process
6938@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6939 vdso_base = get_unmapped_area(NULL, vdso_base,
6940 (vdso_pages << PAGE_SHIFT) +
6941 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6942- 0, 0);
6943+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
6944 if (IS_ERR_VALUE(vdso_base)) {
6945 rc = vdso_base;
6946 goto fail_mmapsem;
6947diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6948index 5eea6f3..5d10396 100644
6949--- a/arch/powerpc/lib/usercopy_64.c
6950+++ b/arch/powerpc/lib/usercopy_64.c
6951@@ -9,22 +9,6 @@
6952 #include <linux/module.h>
6953 #include <asm/uaccess.h>
6954
6955-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6956-{
6957- if (likely(access_ok(VERIFY_READ, from, n)))
6958- n = __copy_from_user(to, from, n);
6959- else
6960- memset(to, 0, n);
6961- return n;
6962-}
6963-
6964-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6965-{
6966- if (likely(access_ok(VERIFY_WRITE, to, n)))
6967- n = __copy_to_user(to, from, n);
6968- return n;
6969-}
6970-
6971 unsigned long copy_in_user(void __user *to, const void __user *from,
6972 unsigned long n)
6973 {
6974@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
6975 return n;
6976 }
6977
6978-EXPORT_SYMBOL(copy_from_user);
6979-EXPORT_SYMBOL(copy_to_user);
6980 EXPORT_SYMBOL(copy_in_user);
6981
6982diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
6983index 3a8489a..6a63b3b 100644
6984--- a/arch/powerpc/mm/fault.c
6985+++ b/arch/powerpc/mm/fault.c
6986@@ -32,6 +32,10 @@
6987 #include <linux/perf_event.h>
6988 #include <linux/magic.h>
6989 #include <linux/ratelimit.h>
6990+#include <linux/slab.h>
6991+#include <linux/pagemap.h>
6992+#include <linux/compiler.h>
6993+#include <linux/unistd.h>
6994
6995 #include <asm/firmware.h>
6996 #include <asm/page.h>
6997@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
6998 }
6999 #endif
7000
7001+#ifdef CONFIG_PAX_PAGEEXEC
7002+/*
7003+ * PaX: decide what to do with offenders (regs->nip = fault address)
7004+ *
7005+ * returns 1 when task should be killed
7006+ */
7007+static int pax_handle_fetch_fault(struct pt_regs *regs)
7008+{
7009+ return 1;
7010+}
7011+
7012+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7013+{
7014+ unsigned long i;
7015+
7016+ printk(KERN_ERR "PAX: bytes at PC: ");
7017+ for (i = 0; i < 5; i++) {
7018+ unsigned int c;
7019+ if (get_user(c, (unsigned int __user *)pc+i))
7020+ printk(KERN_CONT "???????? ");
7021+ else
7022+ printk(KERN_CONT "%08x ", c);
7023+ }
7024+ printk("\n");
7025+}
7026+#endif
7027+
7028 /*
7029 * Check whether the instruction at regs->nip is a store using
7030 * an update addressing form which will update r1.
7031@@ -213,7 +244,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
7032 * indicate errors in DSISR but can validly be set in SRR1.
7033 */
7034 if (trap == 0x400)
7035- error_code &= 0x48200000;
7036+ error_code &= 0x58200000;
7037 else
7038 is_write = error_code & DSISR_ISSTORE;
7039 #else
7040@@ -364,7 +395,7 @@ good_area:
7041 * "undefined". Of those that can be set, this is the only
7042 * one which seems bad.
7043 */
7044- if (error_code & 0x10000000)
7045+ if (error_code & DSISR_GUARDED)
7046 /* Guarded storage error. */
7047 goto bad_area;
7048 #endif /* CONFIG_8xx */
7049@@ -379,7 +410,7 @@ good_area:
7050 * processors use the same I/D cache coherency mechanism
7051 * as embedded.
7052 */
7053- if (error_code & DSISR_PROTFAULT)
7054+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
7055 goto bad_area;
7056 #endif /* CONFIG_PPC_STD_MMU */
7057
7058@@ -462,6 +493,23 @@ bad_area:
7059 bad_area_nosemaphore:
7060 /* User mode accesses cause a SIGSEGV */
7061 if (user_mode(regs)) {
7062+
7063+#ifdef CONFIG_PAX_PAGEEXEC
7064+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
7065+#ifdef CONFIG_PPC_STD_MMU
7066+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
7067+#else
7068+ if (is_exec && regs->nip == address) {
7069+#endif
7070+ switch (pax_handle_fetch_fault(regs)) {
7071+ }
7072+
7073+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
7074+ do_group_exit(SIGKILL);
7075+ }
7076+ }
7077+#endif
7078+
7079 _exception(SIGSEGV, regs, code, address);
7080 return 0;
7081 }
7082diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
7083index 67a42ed..cd463e0 100644
7084--- a/arch/powerpc/mm/mmap_64.c
7085+++ b/arch/powerpc/mm/mmap_64.c
7086@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
7087 {
7088 unsigned long rnd = 0;
7089
7090+#ifdef CONFIG_PAX_RANDMMAP
7091+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7092+#endif
7093+
7094 if (current->flags & PF_RANDOMIZE) {
7095 /* 8MB for 32bit, 1GB for 64bit */
7096 if (is_32bit_task())
7097@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7098 */
7099 if (mmap_is_legacy()) {
7100 mm->mmap_base = TASK_UNMAPPED_BASE;
7101+
7102+#ifdef CONFIG_PAX_RANDMMAP
7103+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7104+ mm->mmap_base += mm->delta_mmap;
7105+#endif
7106+
7107 mm->get_unmapped_area = arch_get_unmapped_area;
7108 mm->unmap_area = arch_unmap_area;
7109 } else {
7110 mm->mmap_base = mmap_base();
7111+
7112+#ifdef CONFIG_PAX_RANDMMAP
7113+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7114+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7115+#endif
7116+
7117 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7118 mm->unmap_area = arch_unmap_area_topdown;
7119 }
7120diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
7121index e779642..e5bb889 100644
7122--- a/arch/powerpc/mm/mmu_context_nohash.c
7123+++ b/arch/powerpc/mm/mmu_context_nohash.c
7124@@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
7125 return NOTIFY_OK;
7126 }
7127
7128-static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
7129+static struct notifier_block mmu_context_cpu_nb = {
7130 .notifier_call = mmu_context_cpu_notify,
7131 };
7132
7133diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
7134index bba87ca..c346a33 100644
7135--- a/arch/powerpc/mm/numa.c
7136+++ b/arch/powerpc/mm/numa.c
7137@@ -932,7 +932,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
7138 return ret;
7139 }
7140
7141-static struct notifier_block __cpuinitdata ppc64_numa_nb = {
7142+static struct notifier_block ppc64_numa_nb = {
7143 .notifier_call = cpu_numa_callback,
7144 .priority = 1 /* Must run before sched domains notifier. */
7145 };
7146diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
7147index cf9dada..241529f 100644
7148--- a/arch/powerpc/mm/slice.c
7149+++ b/arch/powerpc/mm/slice.c
7150@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
7151 if ((mm->task_size - len) < addr)
7152 return 0;
7153 vma = find_vma(mm, addr);
7154- return (!vma || (addr + len) <= vma->vm_start);
7155+ return check_heap_stack_gap(vma, addr, len, 0);
7156 }
7157
7158 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
7159@@ -272,7 +272,7 @@ full_search:
7160 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
7161 continue;
7162 }
7163- if (!vma || addr + len <= vma->vm_start) {
7164+ if (check_heap_stack_gap(vma, addr, len, 0)) {
7165 /*
7166 * Remember the place where we stopped the search:
7167 */
7168@@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7169 }
7170 }
7171
7172- addr = mm->mmap_base;
7173- while (addr > len) {
7174+ if (mm->mmap_base < len)
7175+ addr = -ENOMEM;
7176+ else
7177+ addr = mm->mmap_base - len;
7178+
7179+ while (!IS_ERR_VALUE(addr)) {
7180 /* Go down by chunk size */
7181- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
7182+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
7183
7184 /* Check for hit with different page size */
7185 mask = slice_range_to_mask(addr, len);
7186@@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7187 * return with success:
7188 */
7189 vma = find_vma(mm, addr);
7190- if (!vma || (addr + len) <= vma->vm_start) {
7191+ if (check_heap_stack_gap(vma, addr, len, 0)) {
7192 /* remember the address as a hint for next time */
7193 if (use_cache)
7194 mm->free_area_cache = addr;
7195@@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7196 mm->cached_hole_size = vma->vm_start - addr;
7197
7198 /* try just below the current vma->vm_start */
7199- addr = vma->vm_start;
7200+ addr = skip_heap_stack_gap(vma, len, 0);
7201 }
7202
7203 /*
7204@@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
7205 if (fixed && addr > (mm->task_size - len))
7206 return -EINVAL;
7207
7208+#ifdef CONFIG_PAX_RANDMMAP
7209+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
7210+ addr = 0;
7211+#endif
7212+
7213 /* If hint, make sure it matches our alignment restrictions */
7214 if (!fixed && addr) {
7215 addr = _ALIGN_UP(addr, 1ul << pshift);
7216diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
7217index bdb738a..49c9f95 100644
7218--- a/arch/powerpc/platforms/powermac/smp.c
7219+++ b/arch/powerpc/platforms/powermac/smp.c
7220@@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
7221 return NOTIFY_OK;
7222 }
7223
7224-static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
7225+static struct notifier_block smp_core99_cpu_nb = {
7226 .notifier_call = smp_core99_cpu_notify,
7227 };
7228 #endif /* CONFIG_HOTPLUG_CPU */
7229diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
7230index c797832..ce575c8 100644
7231--- a/arch/s390/include/asm/atomic.h
7232+++ b/arch/s390/include/asm/atomic.h
7233@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
7234 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
7235 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7236
7237+#define atomic64_read_unchecked(v) atomic64_read(v)
7238+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7239+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7240+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7241+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7242+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7243+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7244+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7245+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7246+
7247 #define smp_mb__before_atomic_dec() smp_mb()
7248 #define smp_mb__after_atomic_dec() smp_mb()
7249 #define smp_mb__before_atomic_inc() smp_mb()
7250diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
7251index 4d7ccac..d03d0ad 100644
7252--- a/arch/s390/include/asm/cache.h
7253+++ b/arch/s390/include/asm/cache.h
7254@@ -9,8 +9,10 @@
7255 #ifndef __ARCH_S390_CACHE_H
7256 #define __ARCH_S390_CACHE_H
7257
7258-#define L1_CACHE_BYTES 256
7259+#include <linux/const.h>
7260+
7261 #define L1_CACHE_SHIFT 8
7262+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7263 #define NET_SKB_PAD 32
7264
7265 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7266diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
7267index 178ff96..8c93bd1 100644
7268--- a/arch/s390/include/asm/elf.h
7269+++ b/arch/s390/include/asm/elf.h
7270@@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
7271 the loader. We need to make sure that it is out of the way of the program
7272 that it will "exec", and that there is sufficient room for the brk. */
7273
7274-extern unsigned long randomize_et_dyn(unsigned long base);
7275-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
7276+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
7277+
7278+#ifdef CONFIG_PAX_ASLR
7279+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
7280+
7281+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7282+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7283+#endif
7284
7285 /* This yields a mask that user programs can use to figure out what
7286 instruction set this CPU supports. */
7287@@ -210,9 +216,6 @@ struct linux_binprm;
7288 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7289 int arch_setup_additional_pages(struct linux_binprm *, int);
7290
7291-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7292-#define arch_randomize_brk arch_randomize_brk
7293-
7294 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
7295
7296 #endif
7297diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
7298index c4a93d6..4d2a9b4 100644
7299--- a/arch/s390/include/asm/exec.h
7300+++ b/arch/s390/include/asm/exec.h
7301@@ -7,6 +7,6 @@
7302 #ifndef __ASM_EXEC_H
7303 #define __ASM_EXEC_H
7304
7305-extern unsigned long arch_align_stack(unsigned long sp);
7306+#define arch_align_stack(x) ((x) & ~0xfUL)
7307
7308 #endif /* __ASM_EXEC_H */
7309diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7310index 34268df..ea97318 100644
7311--- a/arch/s390/include/asm/uaccess.h
7312+++ b/arch/s390/include/asm/uaccess.h
7313@@ -252,6 +252,10 @@ static inline unsigned long __must_check
7314 copy_to_user(void __user *to, const void *from, unsigned long n)
7315 {
7316 might_fault();
7317+
7318+ if ((long)n < 0)
7319+ return n;
7320+
7321 if (access_ok(VERIFY_WRITE, to, n))
7322 n = __copy_to_user(to, from, n);
7323 return n;
7324@@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7325 static inline unsigned long __must_check
7326 __copy_from_user(void *to, const void __user *from, unsigned long n)
7327 {
7328+ if ((long)n < 0)
7329+ return n;
7330+
7331 if (__builtin_constant_p(n) && (n <= 256))
7332 return uaccess.copy_from_user_small(n, from, to);
7333 else
7334@@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7335 static inline unsigned long __must_check
7336 copy_from_user(void *to, const void __user *from, unsigned long n)
7337 {
7338- unsigned int sz = __compiletime_object_size(to);
7339+ size_t sz = __compiletime_object_size(to);
7340
7341 might_fault();
7342- if (unlikely(sz != -1 && sz < n)) {
7343+
7344+ if ((long)n < 0)
7345+ return n;
7346+
7347+ if (unlikely(sz != (size_t)-1 && sz < n)) {
7348 copy_from_user_overflow();
7349 return n;
7350 }
7351diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7352index 4610dea..cf0af21 100644
7353--- a/arch/s390/kernel/module.c
7354+++ b/arch/s390/kernel/module.c
7355@@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7356
7357 /* Increase core size by size of got & plt and set start
7358 offsets for got and plt. */
7359- me->core_size = ALIGN(me->core_size, 4);
7360- me->arch.got_offset = me->core_size;
7361- me->core_size += me->arch.got_size;
7362- me->arch.plt_offset = me->core_size;
7363- me->core_size += me->arch.plt_size;
7364+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
7365+ me->arch.got_offset = me->core_size_rw;
7366+ me->core_size_rw += me->arch.got_size;
7367+ me->arch.plt_offset = me->core_size_rx;
7368+ me->core_size_rx += me->arch.plt_size;
7369 return 0;
7370 }
7371
7372@@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7373 if (info->got_initialized == 0) {
7374 Elf_Addr *gotent;
7375
7376- gotent = me->module_core + me->arch.got_offset +
7377+ gotent = me->module_core_rw + me->arch.got_offset +
7378 info->got_offset;
7379 *gotent = val;
7380 info->got_initialized = 1;
7381@@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7382 else if (r_type == R_390_GOTENT ||
7383 r_type == R_390_GOTPLTENT)
7384 *(unsigned int *) loc =
7385- (val + (Elf_Addr) me->module_core - loc) >> 1;
7386+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
7387 else if (r_type == R_390_GOT64 ||
7388 r_type == R_390_GOTPLT64)
7389 *(unsigned long *) loc = val;
7390@@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7391 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7392 if (info->plt_initialized == 0) {
7393 unsigned int *ip;
7394- ip = me->module_core + me->arch.plt_offset +
7395+ ip = me->module_core_rx + me->arch.plt_offset +
7396 info->plt_offset;
7397 #ifndef CONFIG_64BIT
7398 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7399@@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7400 val - loc + 0xffffUL < 0x1ffffeUL) ||
7401 (r_type == R_390_PLT32DBL &&
7402 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7403- val = (Elf_Addr) me->module_core +
7404+ val = (Elf_Addr) me->module_core_rx +
7405 me->arch.plt_offset +
7406 info->plt_offset;
7407 val += rela->r_addend - loc;
7408@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7409 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7410 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7411 val = val + rela->r_addend -
7412- ((Elf_Addr) me->module_core + me->arch.got_offset);
7413+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7414 if (r_type == R_390_GOTOFF16)
7415 *(unsigned short *) loc = val;
7416 else if (r_type == R_390_GOTOFF32)
7417@@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7418 break;
7419 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7420 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7421- val = (Elf_Addr) me->module_core + me->arch.got_offset +
7422+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7423 rela->r_addend - loc;
7424 if (r_type == R_390_GOTPC)
7425 *(unsigned int *) loc = val;
7426diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7427index 536d645..4a5bd9e 100644
7428--- a/arch/s390/kernel/process.c
7429+++ b/arch/s390/kernel/process.c
7430@@ -250,39 +250,3 @@ unsigned long get_wchan(struct task_struct *p)
7431 }
7432 return 0;
7433 }
7434-
7435-unsigned long arch_align_stack(unsigned long sp)
7436-{
7437- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7438- sp -= get_random_int() & ~PAGE_MASK;
7439- return sp & ~0xf;
7440-}
7441-
7442-static inline unsigned long brk_rnd(void)
7443-{
7444- /* 8MB for 32bit, 1GB for 64bit */
7445- if (is_32bit_task())
7446- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7447- else
7448- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7449-}
7450-
7451-unsigned long arch_randomize_brk(struct mm_struct *mm)
7452-{
7453- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7454-
7455- if (ret < mm->brk)
7456- return mm->brk;
7457- return ret;
7458-}
7459-
7460-unsigned long randomize_et_dyn(unsigned long base)
7461-{
7462- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7463-
7464- if (!(current->flags & PF_RANDOMIZE))
7465- return base;
7466- if (ret < base)
7467- return base;
7468- return ret;
7469-}
7470diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7471index c59a5ef..3fae59c 100644
7472--- a/arch/s390/mm/mmap.c
7473+++ b/arch/s390/mm/mmap.c
7474@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7475 */
7476 if (mmap_is_legacy()) {
7477 mm->mmap_base = TASK_UNMAPPED_BASE;
7478+
7479+#ifdef CONFIG_PAX_RANDMMAP
7480+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7481+ mm->mmap_base += mm->delta_mmap;
7482+#endif
7483+
7484 mm->get_unmapped_area = arch_get_unmapped_area;
7485 mm->unmap_area = arch_unmap_area;
7486 } else {
7487 mm->mmap_base = mmap_base();
7488+
7489+#ifdef CONFIG_PAX_RANDMMAP
7490+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7491+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7492+#endif
7493+
7494 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7495 mm->unmap_area = arch_unmap_area_topdown;
7496 }
7497@@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7498 */
7499 if (mmap_is_legacy()) {
7500 mm->mmap_base = TASK_UNMAPPED_BASE;
7501+
7502+#ifdef CONFIG_PAX_RANDMMAP
7503+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7504+ mm->mmap_base += mm->delta_mmap;
7505+#endif
7506+
7507 mm->get_unmapped_area = s390_get_unmapped_area;
7508 mm->unmap_area = arch_unmap_area;
7509 } else {
7510 mm->mmap_base = mmap_base();
7511+
7512+#ifdef CONFIG_PAX_RANDMMAP
7513+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7514+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7515+#endif
7516+
7517 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7518 mm->unmap_area = arch_unmap_area_topdown;
7519 }
7520diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7521index ae3d59f..f65f075 100644
7522--- a/arch/score/include/asm/cache.h
7523+++ b/arch/score/include/asm/cache.h
7524@@ -1,7 +1,9 @@
7525 #ifndef _ASM_SCORE_CACHE_H
7526 #define _ASM_SCORE_CACHE_H
7527
7528+#include <linux/const.h>
7529+
7530 #define L1_CACHE_SHIFT 4
7531-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7532+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7533
7534 #endif /* _ASM_SCORE_CACHE_H */
7535diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7536index f9f3cd5..58ff438 100644
7537--- a/arch/score/include/asm/exec.h
7538+++ b/arch/score/include/asm/exec.h
7539@@ -1,6 +1,6 @@
7540 #ifndef _ASM_SCORE_EXEC_H
7541 #define _ASM_SCORE_EXEC_H
7542
7543-extern unsigned long arch_align_stack(unsigned long sp);
7544+#define arch_align_stack(x) (x)
7545
7546 #endif /* _ASM_SCORE_EXEC_H */
7547diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7548index 7956846..5f37677 100644
7549--- a/arch/score/kernel/process.c
7550+++ b/arch/score/kernel/process.c
7551@@ -134,8 +134,3 @@ unsigned long get_wchan(struct task_struct *task)
7552
7553 return task_pt_regs(task)->cp0_epc;
7554 }
7555-
7556-unsigned long arch_align_stack(unsigned long sp)
7557-{
7558- return sp;
7559-}
7560diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7561index ef9e555..331bd29 100644
7562--- a/arch/sh/include/asm/cache.h
7563+++ b/arch/sh/include/asm/cache.h
7564@@ -9,10 +9,11 @@
7565 #define __ASM_SH_CACHE_H
7566 #ifdef __KERNEL__
7567
7568+#include <linux/const.h>
7569 #include <linux/init.h>
7570 #include <cpu/cache.h>
7571
7572-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7573+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7574
7575 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7576
7577diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7578index 03f2b55..b027032 100644
7579--- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7580+++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7581@@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7582 return NOTIFY_OK;
7583 }
7584
7585-static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7586+static struct notifier_block shx3_cpu_notifier = {
7587 .notifier_call = shx3_cpu_callback,
7588 };
7589
7590diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7591index 6777177..cb5e44f 100644
7592--- a/arch/sh/mm/mmap.c
7593+++ b/arch/sh/mm/mmap.c
7594@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7595 struct mm_struct *mm = current->mm;
7596 struct vm_area_struct *vma;
7597 int do_colour_align;
7598+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7599 struct vm_unmapped_area_info info;
7600
7601 if (flags & MAP_FIXED) {
7602@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7603 if (filp || (flags & MAP_SHARED))
7604 do_colour_align = 1;
7605
7606+#ifdef CONFIG_PAX_RANDMMAP
7607+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7608+#endif
7609+
7610 if (addr) {
7611 if (do_colour_align)
7612 addr = COLOUR_ALIGN(addr, pgoff);
7613@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7614 addr = PAGE_ALIGN(addr);
7615
7616 vma = find_vma(mm, addr);
7617- if (TASK_SIZE - len >= addr &&
7618- (!vma || addr + len <= vma->vm_start))
7619+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7620 return addr;
7621 }
7622
7623 info.flags = 0;
7624 info.length = len;
7625- info.low_limit = TASK_UNMAPPED_BASE;
7626+ info.low_limit = mm->mmap_base;
7627 info.high_limit = TASK_SIZE;
7628 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7629 info.align_offset = pgoff << PAGE_SHIFT;
7630@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7631 struct mm_struct *mm = current->mm;
7632 unsigned long addr = addr0;
7633 int do_colour_align;
7634+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7635 struct vm_unmapped_area_info info;
7636
7637 if (flags & MAP_FIXED) {
7638@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7639 if (filp || (flags & MAP_SHARED))
7640 do_colour_align = 1;
7641
7642+#ifdef CONFIG_PAX_RANDMMAP
7643+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7644+#endif
7645+
7646 /* requesting a specific address */
7647 if (addr) {
7648 if (do_colour_align)
7649@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7650 addr = PAGE_ALIGN(addr);
7651
7652 vma = find_vma(mm, addr);
7653- if (TASK_SIZE - len >= addr &&
7654- (!vma || addr + len <= vma->vm_start))
7655+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7656 return addr;
7657 }
7658
7659@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7660 VM_BUG_ON(addr != -ENOMEM);
7661 info.flags = 0;
7662 info.low_limit = TASK_UNMAPPED_BASE;
7663+
7664+#ifdef CONFIG_PAX_RANDMMAP
7665+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7666+ info.low_limit += mm->delta_mmap;
7667+#endif
7668+
7669 info.high_limit = TASK_SIZE;
7670 addr = vm_unmapped_area(&info);
7671 }
7672diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7673index be56a24..443328f 100644
7674--- a/arch/sparc/include/asm/atomic_64.h
7675+++ b/arch/sparc/include/asm/atomic_64.h
7676@@ -14,18 +14,40 @@
7677 #define ATOMIC64_INIT(i) { (i) }
7678
7679 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7680+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7681+{
7682+ return v->counter;
7683+}
7684 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7685+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7686+{
7687+ return v->counter;
7688+}
7689
7690 #define atomic_set(v, i) (((v)->counter) = i)
7691+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7692+{
7693+ v->counter = i;
7694+}
7695 #define atomic64_set(v, i) (((v)->counter) = i)
7696+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7697+{
7698+ v->counter = i;
7699+}
7700
7701 extern void atomic_add(int, atomic_t *);
7702+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7703 extern void atomic64_add(long, atomic64_t *);
7704+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7705 extern void atomic_sub(int, atomic_t *);
7706+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7707 extern void atomic64_sub(long, atomic64_t *);
7708+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7709
7710 extern int atomic_add_ret(int, atomic_t *);
7711+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7712 extern long atomic64_add_ret(long, atomic64_t *);
7713+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7714 extern int atomic_sub_ret(int, atomic_t *);
7715 extern long atomic64_sub_ret(long, atomic64_t *);
7716
7717@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7718 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7719
7720 #define atomic_inc_return(v) atomic_add_ret(1, v)
7721+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7722+{
7723+ return atomic_add_ret_unchecked(1, v);
7724+}
7725 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7726+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7727+{
7728+ return atomic64_add_ret_unchecked(1, v);
7729+}
7730
7731 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7732 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7733
7734 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7735+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7736+{
7737+ return atomic_add_ret_unchecked(i, v);
7738+}
7739 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7740+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7741+{
7742+ return atomic64_add_ret_unchecked(i, v);
7743+}
7744
7745 /*
7746 * atomic_inc_and_test - increment and test
7747@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7748 * other cases.
7749 */
7750 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7751+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7752+{
7753+ return atomic_inc_return_unchecked(v) == 0;
7754+}
7755 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7756
7757 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7758@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7759 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7760
7761 #define atomic_inc(v) atomic_add(1, v)
7762+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7763+{
7764+ atomic_add_unchecked(1, v);
7765+}
7766 #define atomic64_inc(v) atomic64_add(1, v)
7767+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7768+{
7769+ atomic64_add_unchecked(1, v);
7770+}
7771
7772 #define atomic_dec(v) atomic_sub(1, v)
7773+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7774+{
7775+ atomic_sub_unchecked(1, v);
7776+}
7777 #define atomic64_dec(v) atomic64_sub(1, v)
7778+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7779+{
7780+ atomic64_sub_unchecked(1, v);
7781+}
7782
7783 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7784 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7785
7786 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7787+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7788+{
7789+ return cmpxchg(&v->counter, old, new);
7790+}
7791 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7792+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7793+{
7794+ return xchg(&v->counter, new);
7795+}
7796
7797 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7798 {
7799- int c, old;
7800+ int c, old, new;
7801 c = atomic_read(v);
7802 for (;;) {
7803- if (unlikely(c == (u)))
7804+ if (unlikely(c == u))
7805 break;
7806- old = atomic_cmpxchg((v), c, c + (a));
7807+
7808+ asm volatile("addcc %2, %0, %0\n"
7809+
7810+#ifdef CONFIG_PAX_REFCOUNT
7811+ "tvs %%icc, 6\n"
7812+#endif
7813+
7814+ : "=r" (new)
7815+ : "0" (c), "ir" (a)
7816+ : "cc");
7817+
7818+ old = atomic_cmpxchg(v, c, new);
7819 if (likely(old == c))
7820 break;
7821 c = old;
7822@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7823 #define atomic64_cmpxchg(v, o, n) \
7824 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7825 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7826+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7827+{
7828+ return xchg(&v->counter, new);
7829+}
7830
7831 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7832 {
7833- long c, old;
7834+ long c, old, new;
7835 c = atomic64_read(v);
7836 for (;;) {
7837- if (unlikely(c == (u)))
7838+ if (unlikely(c == u))
7839 break;
7840- old = atomic64_cmpxchg((v), c, c + (a));
7841+
7842+ asm volatile("addcc %2, %0, %0\n"
7843+
7844+#ifdef CONFIG_PAX_REFCOUNT
7845+ "tvs %%xcc, 6\n"
7846+#endif
7847+
7848+ : "=r" (new)
7849+ : "0" (c), "ir" (a)
7850+ : "cc");
7851+
7852+ old = atomic64_cmpxchg(v, c, new);
7853 if (likely(old == c))
7854 break;
7855 c = old;
7856 }
7857- return c != (u);
7858+ return c != u;
7859 }
7860
7861 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7862diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7863index 5bb6991..5c2132e 100644
7864--- a/arch/sparc/include/asm/cache.h
7865+++ b/arch/sparc/include/asm/cache.h
7866@@ -7,10 +7,12 @@
7867 #ifndef _SPARC_CACHE_H
7868 #define _SPARC_CACHE_H
7869
7870+#include <linux/const.h>
7871+
7872 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7873
7874 #define L1_CACHE_SHIFT 5
7875-#define L1_CACHE_BYTES 32
7876+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7877
7878 #ifdef CONFIG_SPARC32
7879 #define SMP_CACHE_BYTES_SHIFT 5
7880diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7881index ac74a2c..a9e58af 100644
7882--- a/arch/sparc/include/asm/elf_32.h
7883+++ b/arch/sparc/include/asm/elf_32.h
7884@@ -114,6 +114,13 @@ typedef struct {
7885
7886 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7887
7888+#ifdef CONFIG_PAX_ASLR
7889+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7890+
7891+#define PAX_DELTA_MMAP_LEN 16
7892+#define PAX_DELTA_STACK_LEN 16
7893+#endif
7894+
7895 /* This yields a mask that user programs can use to figure out what
7896 instruction set this cpu supports. This can NOT be done in userspace
7897 on Sparc. */
7898diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7899index 370ca1e..d4f4a98 100644
7900--- a/arch/sparc/include/asm/elf_64.h
7901+++ b/arch/sparc/include/asm/elf_64.h
7902@@ -189,6 +189,13 @@ typedef struct {
7903 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7904 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7905
7906+#ifdef CONFIG_PAX_ASLR
7907+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7908+
7909+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7910+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7911+#endif
7912+
7913 extern unsigned long sparc64_elf_hwcap;
7914 #define ELF_HWCAP sparc64_elf_hwcap
7915
7916diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7917index 9b1c36d..209298b 100644
7918--- a/arch/sparc/include/asm/pgalloc_32.h
7919+++ b/arch/sparc/include/asm/pgalloc_32.h
7920@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7921 }
7922
7923 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7924+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7925
7926 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7927 unsigned long address)
7928diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7929index bcfe063..b333142 100644
7930--- a/arch/sparc/include/asm/pgalloc_64.h
7931+++ b/arch/sparc/include/asm/pgalloc_64.h
7932@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7933 }
7934
7935 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7936+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7937
7938 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7939 {
7940diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7941index 6fc1348..390c50a 100644
7942--- a/arch/sparc/include/asm/pgtable_32.h
7943+++ b/arch/sparc/include/asm/pgtable_32.h
7944@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7945 #define PAGE_SHARED SRMMU_PAGE_SHARED
7946 #define PAGE_COPY SRMMU_PAGE_COPY
7947 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7948+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7949+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7950+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7951 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7952
7953 /* Top-level page directory - dummy used by init-mm.
7954@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7955
7956 /* xwr */
7957 #define __P000 PAGE_NONE
7958-#define __P001 PAGE_READONLY
7959-#define __P010 PAGE_COPY
7960-#define __P011 PAGE_COPY
7961+#define __P001 PAGE_READONLY_NOEXEC
7962+#define __P010 PAGE_COPY_NOEXEC
7963+#define __P011 PAGE_COPY_NOEXEC
7964 #define __P100 PAGE_READONLY
7965 #define __P101 PAGE_READONLY
7966 #define __P110 PAGE_COPY
7967 #define __P111 PAGE_COPY
7968
7969 #define __S000 PAGE_NONE
7970-#define __S001 PAGE_READONLY
7971-#define __S010 PAGE_SHARED
7972-#define __S011 PAGE_SHARED
7973+#define __S001 PAGE_READONLY_NOEXEC
7974+#define __S010 PAGE_SHARED_NOEXEC
7975+#define __S011 PAGE_SHARED_NOEXEC
7976 #define __S100 PAGE_READONLY
7977 #define __S101 PAGE_READONLY
7978 #define __S110 PAGE_SHARED
7979diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7980index 79da178..c2eede8 100644
7981--- a/arch/sparc/include/asm/pgtsrmmu.h
7982+++ b/arch/sparc/include/asm/pgtsrmmu.h
7983@@ -115,6 +115,11 @@
7984 SRMMU_EXEC | SRMMU_REF)
7985 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7986 SRMMU_EXEC | SRMMU_REF)
7987+
7988+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
7989+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7990+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7991+
7992 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
7993 SRMMU_DIRTY | SRMMU_REF)
7994
7995diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
7996index 9689176..63c18ea 100644
7997--- a/arch/sparc/include/asm/spinlock_64.h
7998+++ b/arch/sparc/include/asm/spinlock_64.h
7999@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
8000
8001 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
8002
8003-static void inline arch_read_lock(arch_rwlock_t *lock)
8004+static inline void arch_read_lock(arch_rwlock_t *lock)
8005 {
8006 unsigned long tmp1, tmp2;
8007
8008 __asm__ __volatile__ (
8009 "1: ldsw [%2], %0\n"
8010 " brlz,pn %0, 2f\n"
8011-"4: add %0, 1, %1\n"
8012+"4: addcc %0, 1, %1\n"
8013+
8014+#ifdef CONFIG_PAX_REFCOUNT
8015+" tvs %%icc, 6\n"
8016+#endif
8017+
8018 " cas [%2], %0, %1\n"
8019 " cmp %0, %1\n"
8020 " bne,pn %%icc, 1b\n"
8021@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
8022 " .previous"
8023 : "=&r" (tmp1), "=&r" (tmp2)
8024 : "r" (lock)
8025- : "memory");
8026+ : "memory", "cc");
8027 }
8028
8029-static int inline arch_read_trylock(arch_rwlock_t *lock)
8030+static inline int arch_read_trylock(arch_rwlock_t *lock)
8031 {
8032 int tmp1, tmp2;
8033
8034@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8035 "1: ldsw [%2], %0\n"
8036 " brlz,a,pn %0, 2f\n"
8037 " mov 0, %0\n"
8038-" add %0, 1, %1\n"
8039+" addcc %0, 1, %1\n"
8040+
8041+#ifdef CONFIG_PAX_REFCOUNT
8042+" tvs %%icc, 6\n"
8043+#endif
8044+
8045 " cas [%2], %0, %1\n"
8046 " cmp %0, %1\n"
8047 " bne,pn %%icc, 1b\n"
8048@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8049 return tmp1;
8050 }
8051
8052-static void inline arch_read_unlock(arch_rwlock_t *lock)
8053+static inline void arch_read_unlock(arch_rwlock_t *lock)
8054 {
8055 unsigned long tmp1, tmp2;
8056
8057 __asm__ __volatile__(
8058 "1: lduw [%2], %0\n"
8059-" sub %0, 1, %1\n"
8060+" subcc %0, 1, %1\n"
8061+
8062+#ifdef CONFIG_PAX_REFCOUNT
8063+" tvs %%icc, 6\n"
8064+#endif
8065+
8066 " cas [%2], %0, %1\n"
8067 " cmp %0, %1\n"
8068 " bne,pn %%xcc, 1b\n"
8069@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
8070 : "memory");
8071 }
8072
8073-static void inline arch_write_lock(arch_rwlock_t *lock)
8074+static inline void arch_write_lock(arch_rwlock_t *lock)
8075 {
8076 unsigned long mask, tmp1, tmp2;
8077
8078@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
8079 : "memory");
8080 }
8081
8082-static void inline arch_write_unlock(arch_rwlock_t *lock)
8083+static inline void arch_write_unlock(arch_rwlock_t *lock)
8084 {
8085 __asm__ __volatile__(
8086 " stw %%g0, [%0]"
8087@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
8088 : "memory");
8089 }
8090
8091-static int inline arch_write_trylock(arch_rwlock_t *lock)
8092+static inline int arch_write_trylock(arch_rwlock_t *lock)
8093 {
8094 unsigned long mask, tmp1, tmp2, result;
8095
8096diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
8097index 25849ae..924c54b 100644
8098--- a/arch/sparc/include/asm/thread_info_32.h
8099+++ b/arch/sparc/include/asm/thread_info_32.h
8100@@ -49,6 +49,8 @@ struct thread_info {
8101 unsigned long w_saved;
8102
8103 struct restart_block restart_block;
8104+
8105+ unsigned long lowest_stack;
8106 };
8107
8108 /*
8109diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
8110index 269bd92..e46a9b8 100644
8111--- a/arch/sparc/include/asm/thread_info_64.h
8112+++ b/arch/sparc/include/asm/thread_info_64.h
8113@@ -63,6 +63,8 @@ struct thread_info {
8114 struct pt_regs *kern_una_regs;
8115 unsigned int kern_una_insn;
8116
8117+ unsigned long lowest_stack;
8118+
8119 unsigned long fpregs[0] __attribute__ ((aligned(64)));
8120 };
8121
8122@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
8123 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
8124 /* flag bit 6 is available */
8125 #define TIF_32BIT 7 /* 32-bit binary */
8126-/* flag bit 8 is available */
8127+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
8128 #define TIF_SECCOMP 9 /* secure computing */
8129 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
8130 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
8131+
8132 /* NOTE: Thread flags >= 12 should be ones we have no interest
8133 * in using in assembly, else we can't use the mask as
8134 * an immediate value in instructions such as andcc.
8135@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
8136 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
8137 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8138 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
8139+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8140
8141 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
8142 _TIF_DO_NOTIFY_RESUME_MASK | \
8143 _TIF_NEED_RESCHED)
8144 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
8145
8146+#define _TIF_WORK_SYSCALL \
8147+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
8148+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
8149+
8150+
8151 /*
8152 * Thread-synchronous status.
8153 *
8154diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
8155index 0167d26..9acd8ed 100644
8156--- a/arch/sparc/include/asm/uaccess.h
8157+++ b/arch/sparc/include/asm/uaccess.h
8158@@ -1,5 +1,13 @@
8159 #ifndef ___ASM_SPARC_UACCESS_H
8160 #define ___ASM_SPARC_UACCESS_H
8161+
8162+#ifdef __KERNEL__
8163+#ifndef __ASSEMBLY__
8164+#include <linux/types.h>
8165+extern void check_object_size(const void *ptr, unsigned long n, bool to);
8166+#endif
8167+#endif
8168+
8169 #if defined(__sparc__) && defined(__arch64__)
8170 #include <asm/uaccess_64.h>
8171 #else
8172diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
8173index 53a28dd..50c38c3 100644
8174--- a/arch/sparc/include/asm/uaccess_32.h
8175+++ b/arch/sparc/include/asm/uaccess_32.h
8176@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
8177
8178 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8179 {
8180- if (n && __access_ok((unsigned long) to, n))
8181+ if ((long)n < 0)
8182+ return n;
8183+
8184+ if (n && __access_ok((unsigned long) to, n)) {
8185+ if (!__builtin_constant_p(n))
8186+ check_object_size(from, n, true);
8187 return __copy_user(to, (__force void __user *) from, n);
8188- else
8189+ } else
8190 return n;
8191 }
8192
8193 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
8194 {
8195+ if ((long)n < 0)
8196+ return n;
8197+
8198+ if (!__builtin_constant_p(n))
8199+ check_object_size(from, n, true);
8200+
8201 return __copy_user(to, (__force void __user *) from, n);
8202 }
8203
8204 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8205 {
8206- if (n && __access_ok((unsigned long) from, n))
8207+ if ((long)n < 0)
8208+ return n;
8209+
8210+ if (n && __access_ok((unsigned long) from, n)) {
8211+ if (!__builtin_constant_p(n))
8212+ check_object_size(to, n, false);
8213 return __copy_user((__force void __user *) to, from, n);
8214- else
8215+ } else
8216 return n;
8217 }
8218
8219 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
8220 {
8221+ if ((long)n < 0)
8222+ return n;
8223+
8224 return __copy_user((__force void __user *) to, from, n);
8225 }
8226
8227diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
8228index e562d3c..191f176 100644
8229--- a/arch/sparc/include/asm/uaccess_64.h
8230+++ b/arch/sparc/include/asm/uaccess_64.h
8231@@ -10,6 +10,7 @@
8232 #include <linux/compiler.h>
8233 #include <linux/string.h>
8234 #include <linux/thread_info.h>
8235+#include <linux/kernel.h>
8236 #include <asm/asi.h>
8237 #include <asm/spitfire.h>
8238 #include <asm-generic/uaccess-unaligned.h>
8239@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
8240 static inline unsigned long __must_check
8241 copy_from_user(void *to, const void __user *from, unsigned long size)
8242 {
8243- unsigned long ret = ___copy_from_user(to, from, size);
8244+ unsigned long ret;
8245
8246+ if ((long)size < 0 || size > INT_MAX)
8247+ return size;
8248+
8249+ if (!__builtin_constant_p(size))
8250+ check_object_size(to, size, false);
8251+
8252+ ret = ___copy_from_user(to, from, size);
8253 if (unlikely(ret))
8254 ret = copy_from_user_fixup(to, from, size);
8255
8256@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
8257 static inline unsigned long __must_check
8258 copy_to_user(void __user *to, const void *from, unsigned long size)
8259 {
8260- unsigned long ret = ___copy_to_user(to, from, size);
8261+ unsigned long ret;
8262
8263+ if ((long)size < 0 || size > INT_MAX)
8264+ return size;
8265+
8266+ if (!__builtin_constant_p(size))
8267+ check_object_size(from, size, true);
8268+
8269+ ret = ___copy_to_user(to, from, size);
8270 if (unlikely(ret))
8271 ret = copy_to_user_fixup(to, from, size);
8272 return ret;
8273diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
8274index 6cf591b..b49e65a 100644
8275--- a/arch/sparc/kernel/Makefile
8276+++ b/arch/sparc/kernel/Makefile
8277@@ -3,7 +3,7 @@
8278 #
8279
8280 asflags-y := -ansi
8281-ccflags-y := -Werror
8282+#ccflags-y := -Werror
8283
8284 extra-y := head_$(BITS).o
8285
8286diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
8287index be8e862..5b50b12 100644
8288--- a/arch/sparc/kernel/process_32.c
8289+++ b/arch/sparc/kernel/process_32.c
8290@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
8291
8292 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
8293 r->psr, r->pc, r->npc, r->y, print_tainted());
8294- printk("PC: <%pS>\n", (void *) r->pc);
8295+ printk("PC: <%pA>\n", (void *) r->pc);
8296 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8297 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
8298 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
8299 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8300 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
8301 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
8302- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8303+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8304
8305 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8306 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8307@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8308 rw = (struct reg_window32 *) fp;
8309 pc = rw->ins[7];
8310 printk("[%08lx : ", pc);
8311- printk("%pS ] ", (void *) pc);
8312+ printk("%pA ] ", (void *) pc);
8313 fp = rw->ins[6];
8314 } while (++count < 16);
8315 printk("\n");
8316diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8317index cdb80b2..5ca141d 100644
8318--- a/arch/sparc/kernel/process_64.c
8319+++ b/arch/sparc/kernel/process_64.c
8320@@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
8321 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8322 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8323 if (regs->tstate & TSTATE_PRIV)
8324- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8325+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8326 }
8327
8328 void show_regs(struct pt_regs *regs)
8329 {
8330 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8331 regs->tpc, regs->tnpc, regs->y, print_tainted());
8332- printk("TPC: <%pS>\n", (void *) regs->tpc);
8333+ printk("TPC: <%pA>\n", (void *) regs->tpc);
8334 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8335 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8336 regs->u_regs[3]);
8337@@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
8338 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8339 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8340 regs->u_regs[15]);
8341- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8342+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8343 show_regwindow(regs);
8344 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8345 }
8346@@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
8347 ((tp && tp->task) ? tp->task->pid : -1));
8348
8349 if (gp->tstate & TSTATE_PRIV) {
8350- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8351+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8352 (void *) gp->tpc,
8353 (void *) gp->o7,
8354 (void *) gp->i7,
8355diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8356index 7ff45e4..a58f271 100644
8357--- a/arch/sparc/kernel/ptrace_64.c
8358+++ b/arch/sparc/kernel/ptrace_64.c
8359@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8360 return ret;
8361 }
8362
8363+#ifdef CONFIG_GRKERNSEC_SETXID
8364+extern void gr_delayed_cred_worker(void);
8365+#endif
8366+
8367 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8368 {
8369 int ret = 0;
8370@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8371 /* do the secure computing check first */
8372 secure_computing_strict(regs->u_regs[UREG_G1]);
8373
8374+#ifdef CONFIG_GRKERNSEC_SETXID
8375+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8376+ gr_delayed_cred_worker();
8377+#endif
8378+
8379 if (test_thread_flag(TIF_SYSCALL_TRACE))
8380 ret = tracehook_report_syscall_entry(regs);
8381
8382@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8383
8384 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8385 {
8386+#ifdef CONFIG_GRKERNSEC_SETXID
8387+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8388+ gr_delayed_cred_worker();
8389+#endif
8390+
8391 audit_syscall_exit(regs);
8392
8393 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8394diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8395index 2da0bdc..79128d2 100644
8396--- a/arch/sparc/kernel/sys_sparc_32.c
8397+++ b/arch/sparc/kernel/sys_sparc_32.c
8398@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8399 if (len > TASK_SIZE - PAGE_SIZE)
8400 return -ENOMEM;
8401 if (!addr)
8402- addr = TASK_UNMAPPED_BASE;
8403+ addr = current->mm->mmap_base;
8404
8405 info.flags = 0;
8406 info.length = len;
8407diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8408index 708bc29..f0129cb 100644
8409--- a/arch/sparc/kernel/sys_sparc_64.c
8410+++ b/arch/sparc/kernel/sys_sparc_64.c
8411@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8412 struct vm_area_struct * vma;
8413 unsigned long task_size = TASK_SIZE;
8414 int do_color_align;
8415+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8416 struct vm_unmapped_area_info info;
8417
8418 if (flags & MAP_FIXED) {
8419 /* We do not accept a shared mapping if it would violate
8420 * cache aliasing constraints.
8421 */
8422- if ((flags & MAP_SHARED) &&
8423+ if ((filp || (flags & MAP_SHARED)) &&
8424 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8425 return -EINVAL;
8426 return addr;
8427@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8428 if (filp || (flags & MAP_SHARED))
8429 do_color_align = 1;
8430
8431+#ifdef CONFIG_PAX_RANDMMAP
8432+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8433+#endif
8434+
8435 if (addr) {
8436 if (do_color_align)
8437 addr = COLOR_ALIGN(addr, pgoff);
8438@@ -118,14 +123,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8439 addr = PAGE_ALIGN(addr);
8440
8441 vma = find_vma(mm, addr);
8442- if (task_size - len >= addr &&
8443- (!vma || addr + len <= vma->vm_start))
8444+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8445 return addr;
8446 }
8447
8448 info.flags = 0;
8449 info.length = len;
8450- info.low_limit = TASK_UNMAPPED_BASE;
8451+ info.low_limit = mm->mmap_base;
8452 info.high_limit = min(task_size, VA_EXCLUDE_START);
8453 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8454 info.align_offset = pgoff << PAGE_SHIFT;
8455@@ -134,6 +138,12 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8456 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8457 VM_BUG_ON(addr != -ENOMEM);
8458 info.low_limit = VA_EXCLUDE_END;
8459+
8460+#ifdef CONFIG_PAX_RANDMMAP
8461+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8462+ info.low_limit += mm->delta_mmap;
8463+#endif
8464+
8465 info.high_limit = task_size;
8466 addr = vm_unmapped_area(&info);
8467 }
8468@@ -151,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8469 unsigned long task_size = STACK_TOP32;
8470 unsigned long addr = addr0;
8471 int do_color_align;
8472+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8473 struct vm_unmapped_area_info info;
8474
8475 /* This should only ever run for 32-bit processes. */
8476@@ -160,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8477 /* We do not accept a shared mapping if it would violate
8478 * cache aliasing constraints.
8479 */
8480- if ((flags & MAP_SHARED) &&
8481+ if ((filp || (flags & MAP_SHARED)) &&
8482 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8483 return -EINVAL;
8484 return addr;
8485@@ -173,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8486 if (filp || (flags & MAP_SHARED))
8487 do_color_align = 1;
8488
8489+#ifdef CONFIG_PAX_RANDMMAP
8490+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8491+#endif
8492+
8493 /* requesting a specific address */
8494 if (addr) {
8495 if (do_color_align)
8496@@ -181,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8497 addr = PAGE_ALIGN(addr);
8498
8499 vma = find_vma(mm, addr);
8500- if (task_size - len >= addr &&
8501- (!vma || addr + len <= vma->vm_start))
8502+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8503 return addr;
8504 }
8505
8506@@ -204,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8507 VM_BUG_ON(addr != -ENOMEM);
8508 info.flags = 0;
8509 info.low_limit = TASK_UNMAPPED_BASE;
8510+
8511+#ifdef CONFIG_PAX_RANDMMAP
8512+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8513+ info.low_limit += mm->delta_mmap;
8514+#endif
8515+
8516 info.high_limit = STACK_TOP32;
8517 addr = vm_unmapped_area(&info);
8518 }
8519@@ -264,6 +284,10 @@ static unsigned long mmap_rnd(void)
8520 {
8521 unsigned long rnd = 0UL;
8522
8523+#ifdef CONFIG_PAX_RANDMMAP
8524+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8525+#endif
8526+
8527 if (current->flags & PF_RANDOMIZE) {
8528 unsigned long val = get_random_int();
8529 if (test_thread_flag(TIF_32BIT))
8530@@ -289,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8531 gap == RLIM_INFINITY ||
8532 sysctl_legacy_va_layout) {
8533 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8534+
8535+#ifdef CONFIG_PAX_RANDMMAP
8536+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8537+ mm->mmap_base += mm->delta_mmap;
8538+#endif
8539+
8540 mm->get_unmapped_area = arch_get_unmapped_area;
8541 mm->unmap_area = arch_unmap_area;
8542 } else {
8543@@ -301,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8544 gap = (task_size / 6 * 5);
8545
8546 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8547+
8548+#ifdef CONFIG_PAX_RANDMMAP
8549+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8550+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8551+#endif
8552+
8553 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8554 mm->unmap_area = arch_unmap_area_topdown;
8555 }
8556diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8557index e0fed77..604a7e5 100644
8558--- a/arch/sparc/kernel/syscalls.S
8559+++ b/arch/sparc/kernel/syscalls.S
8560@@ -58,7 +58,7 @@ sys32_rt_sigreturn:
8561 #endif
8562 .align 32
8563 1: ldx [%g6 + TI_FLAGS], %l5
8564- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8565+ andcc %l5, _TIF_WORK_SYSCALL, %g0
8566 be,pt %icc, rtrap
8567 nop
8568 call syscall_trace_leave
8569@@ -190,7 +190,7 @@ linux_sparc_syscall32:
8570
8571 srl %i5, 0, %o5 ! IEU1
8572 srl %i2, 0, %o2 ! IEU0 Group
8573- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8574+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8575 bne,pn %icc, linux_syscall_trace32 ! CTI
8576 mov %i0, %l5 ! IEU1
8577 call %l7 ! CTI Group brk forced
8578@@ -213,7 +213,7 @@ linux_sparc_syscall:
8579
8580 mov %i3, %o3 ! IEU1
8581 mov %i4, %o4 ! IEU0 Group
8582- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8583+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8584 bne,pn %icc, linux_syscall_trace ! CTI Group
8585 mov %i0, %l5 ! IEU0
8586 2: call %l7 ! CTI Group brk forced
8587@@ -229,7 +229,7 @@ ret_sys_call:
8588
8589 cmp %o0, -ERESTART_RESTARTBLOCK
8590 bgeu,pn %xcc, 1f
8591- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8592+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8593 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8594
8595 2:
8596diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8597index 654e8aa..45f431b 100644
8598--- a/arch/sparc/kernel/sysfs.c
8599+++ b/arch/sparc/kernel/sysfs.c
8600@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8601 return NOTIFY_OK;
8602 }
8603
8604-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8605+static struct notifier_block sysfs_cpu_nb = {
8606 .notifier_call = sysfs_cpu_notify,
8607 };
8608
8609diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8610index a5785ea..405c5f7 100644
8611--- a/arch/sparc/kernel/traps_32.c
8612+++ b/arch/sparc/kernel/traps_32.c
8613@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8614 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8615 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8616
8617+extern void gr_handle_kernel_exploit(void);
8618+
8619 void die_if_kernel(char *str, struct pt_regs *regs)
8620 {
8621 static int die_counter;
8622@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8623 count++ < 30 &&
8624 (((unsigned long) rw) >= PAGE_OFFSET) &&
8625 !(((unsigned long) rw) & 0x7)) {
8626- printk("Caller[%08lx]: %pS\n", rw->ins[7],
8627+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
8628 (void *) rw->ins[7]);
8629 rw = (struct reg_window32 *)rw->ins[6];
8630 }
8631 }
8632 printk("Instruction DUMP:");
8633 instruction_dump ((unsigned long *) regs->pc);
8634- if(regs->psr & PSR_PS)
8635+ if(regs->psr & PSR_PS) {
8636+ gr_handle_kernel_exploit();
8637 do_exit(SIGKILL);
8638+ }
8639 do_exit(SIGSEGV);
8640 }
8641
8642diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8643index e7ecf15..6520e65 100644
8644--- a/arch/sparc/kernel/traps_64.c
8645+++ b/arch/sparc/kernel/traps_64.c
8646@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8647 i + 1,
8648 p->trapstack[i].tstate, p->trapstack[i].tpc,
8649 p->trapstack[i].tnpc, p->trapstack[i].tt);
8650- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8651+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8652 }
8653 }
8654
8655@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8656
8657 lvl -= 0x100;
8658 if (regs->tstate & TSTATE_PRIV) {
8659+
8660+#ifdef CONFIG_PAX_REFCOUNT
8661+ if (lvl == 6)
8662+ pax_report_refcount_overflow(regs);
8663+#endif
8664+
8665 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8666 die_if_kernel(buffer, regs);
8667 }
8668@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8669 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8670 {
8671 char buffer[32];
8672-
8673+
8674 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8675 0, lvl, SIGTRAP) == NOTIFY_STOP)
8676 return;
8677
8678+#ifdef CONFIG_PAX_REFCOUNT
8679+ if (lvl == 6)
8680+ pax_report_refcount_overflow(regs);
8681+#endif
8682+
8683 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8684
8685 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8686@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8687 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8688 printk("%s" "ERROR(%d): ",
8689 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8690- printk("TPC<%pS>\n", (void *) regs->tpc);
8691+ printk("TPC<%pA>\n", (void *) regs->tpc);
8692 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8693 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8694 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8695@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8696 smp_processor_id(),
8697 (type & 0x1) ? 'I' : 'D',
8698 regs->tpc);
8699- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8700+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8701 panic("Irrecoverable Cheetah+ parity error.");
8702 }
8703
8704@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8705 smp_processor_id(),
8706 (type & 0x1) ? 'I' : 'D',
8707 regs->tpc);
8708- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8709+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8710 }
8711
8712 struct sun4v_error_entry {
8713@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8714
8715 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8716 regs->tpc, tl);
8717- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8718+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8719 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8720- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8721+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8722 (void *) regs->u_regs[UREG_I7]);
8723 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8724 "pte[%lx] error[%lx]\n",
8725@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8726
8727 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8728 regs->tpc, tl);
8729- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8730+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8731 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8732- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8733+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8734 (void *) regs->u_regs[UREG_I7]);
8735 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8736 "pte[%lx] error[%lx]\n",
8737@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8738 fp = (unsigned long)sf->fp + STACK_BIAS;
8739 }
8740
8741- printk(" [%016lx] %pS\n", pc, (void *) pc);
8742+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8743 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8744 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8745 int index = tsk->curr_ret_stack;
8746 if (tsk->ret_stack && index >= graph) {
8747 pc = tsk->ret_stack[index - graph].ret;
8748- printk(" [%016lx] %pS\n", pc, (void *) pc);
8749+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8750 graph++;
8751 }
8752 }
8753@@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8754 return (struct reg_window *) (fp + STACK_BIAS);
8755 }
8756
8757+extern void gr_handle_kernel_exploit(void);
8758+
8759 void die_if_kernel(char *str, struct pt_regs *regs)
8760 {
8761 static int die_counter;
8762@@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8763 while (rw &&
8764 count++ < 30 &&
8765 kstack_valid(tp, (unsigned long) rw)) {
8766- printk("Caller[%016lx]: %pS\n", rw->ins[7],
8767+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
8768 (void *) rw->ins[7]);
8769
8770 rw = kernel_stack_up(rw);
8771@@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8772 }
8773 user_instruction_dump ((unsigned int __user *) regs->tpc);
8774 }
8775- if (regs->tstate & TSTATE_PRIV)
8776+ if (regs->tstate & TSTATE_PRIV) {
8777+ gr_handle_kernel_exploit();
8778 do_exit(SIGKILL);
8779+ }
8780 do_exit(SIGSEGV);
8781 }
8782 EXPORT_SYMBOL(die_if_kernel);
8783diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8784index 8201c25e..072a2a7 100644
8785--- a/arch/sparc/kernel/unaligned_64.c
8786+++ b/arch/sparc/kernel/unaligned_64.c
8787@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8788 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8789
8790 if (__ratelimit(&ratelimit)) {
8791- printk("Kernel unaligned access at TPC[%lx] %pS\n",
8792+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
8793 regs->tpc, (void *) regs->tpc);
8794 }
8795 }
8796diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8797index 8410065f2..4fd4ca22 100644
8798--- a/arch/sparc/lib/Makefile
8799+++ b/arch/sparc/lib/Makefile
8800@@ -2,7 +2,7 @@
8801 #
8802
8803 asflags-y := -ansi -DST_DIV0=0x02
8804-ccflags-y := -Werror
8805+#ccflags-y := -Werror
8806
8807 lib-$(CONFIG_SPARC32) += ashrdi3.o
8808 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8809diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8810index 85c233d..68500e0 100644
8811--- a/arch/sparc/lib/atomic_64.S
8812+++ b/arch/sparc/lib/atomic_64.S
8813@@ -17,7 +17,12 @@
8814 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8815 BACKOFF_SETUP(%o2)
8816 1: lduw [%o1], %g1
8817- add %g1, %o0, %g7
8818+ addcc %g1, %o0, %g7
8819+
8820+#ifdef CONFIG_PAX_REFCOUNT
8821+ tvs %icc, 6
8822+#endif
8823+
8824 cas [%o1], %g1, %g7
8825 cmp %g1, %g7
8826 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8827@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8828 2: BACKOFF_SPIN(%o2, %o3, 1b)
8829 ENDPROC(atomic_add)
8830
8831+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8832+ BACKOFF_SETUP(%o2)
8833+1: lduw [%o1], %g1
8834+ add %g1, %o0, %g7
8835+ cas [%o1], %g1, %g7
8836+ cmp %g1, %g7
8837+ bne,pn %icc, 2f
8838+ nop
8839+ retl
8840+ nop
8841+2: BACKOFF_SPIN(%o2, %o3, 1b)
8842+ENDPROC(atomic_add_unchecked)
8843+
8844 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8845 BACKOFF_SETUP(%o2)
8846 1: lduw [%o1], %g1
8847- sub %g1, %o0, %g7
8848+ subcc %g1, %o0, %g7
8849+
8850+#ifdef CONFIG_PAX_REFCOUNT
8851+ tvs %icc, 6
8852+#endif
8853+
8854 cas [%o1], %g1, %g7
8855 cmp %g1, %g7
8856 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8857@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8858 2: BACKOFF_SPIN(%o2, %o3, 1b)
8859 ENDPROC(atomic_sub)
8860
8861+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8862+ BACKOFF_SETUP(%o2)
8863+1: lduw [%o1], %g1
8864+ sub %g1, %o0, %g7
8865+ cas [%o1], %g1, %g7
8866+ cmp %g1, %g7
8867+ bne,pn %icc, 2f
8868+ nop
8869+ retl
8870+ nop
8871+2: BACKOFF_SPIN(%o2, %o3, 1b)
8872+ENDPROC(atomic_sub_unchecked)
8873+
8874 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8875 BACKOFF_SETUP(%o2)
8876 1: lduw [%o1], %g1
8877- add %g1, %o0, %g7
8878+ addcc %g1, %o0, %g7
8879+
8880+#ifdef CONFIG_PAX_REFCOUNT
8881+ tvs %icc, 6
8882+#endif
8883+
8884 cas [%o1], %g1, %g7
8885 cmp %g1, %g7
8886 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8887@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8888 2: BACKOFF_SPIN(%o2, %o3, 1b)
8889 ENDPROC(atomic_add_ret)
8890
8891+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8892+ BACKOFF_SETUP(%o2)
8893+1: lduw [%o1], %g1
8894+ addcc %g1, %o0, %g7
8895+ cas [%o1], %g1, %g7
8896+ cmp %g1, %g7
8897+ bne,pn %icc, 2f
8898+ add %g7, %o0, %g7
8899+ sra %g7, 0, %o0
8900+ retl
8901+ nop
8902+2: BACKOFF_SPIN(%o2, %o3, 1b)
8903+ENDPROC(atomic_add_ret_unchecked)
8904+
8905 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8906 BACKOFF_SETUP(%o2)
8907 1: lduw [%o1], %g1
8908- sub %g1, %o0, %g7
8909+ subcc %g1, %o0, %g7
8910+
8911+#ifdef CONFIG_PAX_REFCOUNT
8912+ tvs %icc, 6
8913+#endif
8914+
8915 cas [%o1], %g1, %g7
8916 cmp %g1, %g7
8917 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8918@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
8919 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8920 BACKOFF_SETUP(%o2)
8921 1: ldx [%o1], %g1
8922- add %g1, %o0, %g7
8923+ addcc %g1, %o0, %g7
8924+
8925+#ifdef CONFIG_PAX_REFCOUNT
8926+ tvs %xcc, 6
8927+#endif
8928+
8929 casx [%o1], %g1, %g7
8930 cmp %g1, %g7
8931 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8932@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8933 2: BACKOFF_SPIN(%o2, %o3, 1b)
8934 ENDPROC(atomic64_add)
8935
8936+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8937+ BACKOFF_SETUP(%o2)
8938+1: ldx [%o1], %g1
8939+ addcc %g1, %o0, %g7
8940+ casx [%o1], %g1, %g7
8941+ cmp %g1, %g7
8942+ bne,pn %xcc, 2f
8943+ nop
8944+ retl
8945+ nop
8946+2: BACKOFF_SPIN(%o2, %o3, 1b)
8947+ENDPROC(atomic64_add_unchecked)
8948+
8949 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8950 BACKOFF_SETUP(%o2)
8951 1: ldx [%o1], %g1
8952- sub %g1, %o0, %g7
8953+ subcc %g1, %o0, %g7
8954+
8955+#ifdef CONFIG_PAX_REFCOUNT
8956+ tvs %xcc, 6
8957+#endif
8958+
8959 casx [%o1], %g1, %g7
8960 cmp %g1, %g7
8961 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8962@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8963 2: BACKOFF_SPIN(%o2, %o3, 1b)
8964 ENDPROC(atomic64_sub)
8965
8966+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8967+ BACKOFF_SETUP(%o2)
8968+1: ldx [%o1], %g1
8969+ subcc %g1, %o0, %g7
8970+ casx [%o1], %g1, %g7
8971+ cmp %g1, %g7
8972+ bne,pn %xcc, 2f
8973+ nop
8974+ retl
8975+ nop
8976+2: BACKOFF_SPIN(%o2, %o3, 1b)
8977+ENDPROC(atomic64_sub_unchecked)
8978+
8979 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8980 BACKOFF_SETUP(%o2)
8981 1: ldx [%o1], %g1
8982- add %g1, %o0, %g7
8983+ addcc %g1, %o0, %g7
8984+
8985+#ifdef CONFIG_PAX_REFCOUNT
8986+ tvs %xcc, 6
8987+#endif
8988+
8989 casx [%o1], %g1, %g7
8990 cmp %g1, %g7
8991 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8992@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8993 2: BACKOFF_SPIN(%o2, %o3, 1b)
8994 ENDPROC(atomic64_add_ret)
8995
8996+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8997+ BACKOFF_SETUP(%o2)
8998+1: ldx [%o1], %g1
8999+ addcc %g1, %o0, %g7
9000+ casx [%o1], %g1, %g7
9001+ cmp %g1, %g7
9002+ bne,pn %xcc, 2f
9003+ add %g7, %o0, %g7
9004+ mov %g7, %o0
9005+ retl
9006+ nop
9007+2: BACKOFF_SPIN(%o2, %o3, 1b)
9008+ENDPROC(atomic64_add_ret_unchecked)
9009+
9010 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9011 BACKOFF_SETUP(%o2)
9012 1: ldx [%o1], %g1
9013- sub %g1, %o0, %g7
9014+ subcc %g1, %o0, %g7
9015+
9016+#ifdef CONFIG_PAX_REFCOUNT
9017+ tvs %xcc, 6
9018+#endif
9019+
9020 casx [%o1], %g1, %g7
9021 cmp %g1, %g7
9022 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9023diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
9024index 0c4e35e..745d3e4 100644
9025--- a/arch/sparc/lib/ksyms.c
9026+++ b/arch/sparc/lib/ksyms.c
9027@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
9028
9029 /* Atomic counter implementation. */
9030 EXPORT_SYMBOL(atomic_add);
9031+EXPORT_SYMBOL(atomic_add_unchecked);
9032 EXPORT_SYMBOL(atomic_add_ret);
9033+EXPORT_SYMBOL(atomic_add_ret_unchecked);
9034 EXPORT_SYMBOL(atomic_sub);
9035+EXPORT_SYMBOL(atomic_sub_unchecked);
9036 EXPORT_SYMBOL(atomic_sub_ret);
9037 EXPORT_SYMBOL(atomic64_add);
9038+EXPORT_SYMBOL(atomic64_add_unchecked);
9039 EXPORT_SYMBOL(atomic64_add_ret);
9040+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
9041 EXPORT_SYMBOL(atomic64_sub);
9042+EXPORT_SYMBOL(atomic64_sub_unchecked);
9043 EXPORT_SYMBOL(atomic64_sub_ret);
9044 EXPORT_SYMBOL(atomic64_dec_if_positive);
9045
9046diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
9047index 30c3ecc..736f015 100644
9048--- a/arch/sparc/mm/Makefile
9049+++ b/arch/sparc/mm/Makefile
9050@@ -2,7 +2,7 @@
9051 #
9052
9053 asflags-y := -ansi
9054-ccflags-y := -Werror
9055+#ccflags-y := -Werror
9056
9057 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
9058 obj-y += fault_$(BITS).o
9059diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
9060index e98bfda..ea8d221 100644
9061--- a/arch/sparc/mm/fault_32.c
9062+++ b/arch/sparc/mm/fault_32.c
9063@@ -21,6 +21,9 @@
9064 #include <linux/perf_event.h>
9065 #include <linux/interrupt.h>
9066 #include <linux/kdebug.h>
9067+#include <linux/slab.h>
9068+#include <linux/pagemap.h>
9069+#include <linux/compiler.h>
9070
9071 #include <asm/page.h>
9072 #include <asm/pgtable.h>
9073@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
9074 return safe_compute_effective_address(regs, insn);
9075 }
9076
9077+#ifdef CONFIG_PAX_PAGEEXEC
9078+#ifdef CONFIG_PAX_DLRESOLVE
9079+static void pax_emuplt_close(struct vm_area_struct *vma)
9080+{
9081+ vma->vm_mm->call_dl_resolve = 0UL;
9082+}
9083+
9084+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9085+{
9086+ unsigned int *kaddr;
9087+
9088+ vmf->page = alloc_page(GFP_HIGHUSER);
9089+ if (!vmf->page)
9090+ return VM_FAULT_OOM;
9091+
9092+ kaddr = kmap(vmf->page);
9093+ memset(kaddr, 0, PAGE_SIZE);
9094+ kaddr[0] = 0x9DE3BFA8U; /* save */
9095+ flush_dcache_page(vmf->page);
9096+ kunmap(vmf->page);
9097+ return VM_FAULT_MAJOR;
9098+}
9099+
9100+static const struct vm_operations_struct pax_vm_ops = {
9101+ .close = pax_emuplt_close,
9102+ .fault = pax_emuplt_fault
9103+};
9104+
9105+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9106+{
9107+ int ret;
9108+
9109+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9110+ vma->vm_mm = current->mm;
9111+ vma->vm_start = addr;
9112+ vma->vm_end = addr + PAGE_SIZE;
9113+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9114+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9115+ vma->vm_ops = &pax_vm_ops;
9116+
9117+ ret = insert_vm_struct(current->mm, vma);
9118+ if (ret)
9119+ return ret;
9120+
9121+ ++current->mm->total_vm;
9122+ return 0;
9123+}
9124+#endif
9125+
9126+/*
9127+ * PaX: decide what to do with offenders (regs->pc = fault address)
9128+ *
9129+ * returns 1 when task should be killed
9130+ * 2 when patched PLT trampoline was detected
9131+ * 3 when unpatched PLT trampoline was detected
9132+ */
9133+static int pax_handle_fetch_fault(struct pt_regs *regs)
9134+{
9135+
9136+#ifdef CONFIG_PAX_EMUPLT
9137+ int err;
9138+
9139+ do { /* PaX: patched PLT emulation #1 */
9140+ unsigned int sethi1, sethi2, jmpl;
9141+
9142+ err = get_user(sethi1, (unsigned int *)regs->pc);
9143+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
9144+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
9145+
9146+ if (err)
9147+ break;
9148+
9149+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9150+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9151+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9152+ {
9153+ unsigned int addr;
9154+
9155+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9156+ addr = regs->u_regs[UREG_G1];
9157+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9158+ regs->pc = addr;
9159+ regs->npc = addr+4;
9160+ return 2;
9161+ }
9162+ } while (0);
9163+
9164+ do { /* PaX: patched PLT emulation #2 */
9165+ unsigned int ba;
9166+
9167+ err = get_user(ba, (unsigned int *)regs->pc);
9168+
9169+ if (err)
9170+ break;
9171+
9172+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9173+ unsigned int addr;
9174+
9175+ if ((ba & 0xFFC00000U) == 0x30800000U)
9176+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9177+ else
9178+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9179+ regs->pc = addr;
9180+ regs->npc = addr+4;
9181+ return 2;
9182+ }
9183+ } while (0);
9184+
9185+ do { /* PaX: patched PLT emulation #3 */
9186+ unsigned int sethi, bajmpl, nop;
9187+
9188+ err = get_user(sethi, (unsigned int *)regs->pc);
9189+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
9190+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9191+
9192+ if (err)
9193+ break;
9194+
9195+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9196+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9197+ nop == 0x01000000U)
9198+ {
9199+ unsigned int addr;
9200+
9201+ addr = (sethi & 0x003FFFFFU) << 10;
9202+ regs->u_regs[UREG_G1] = addr;
9203+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9204+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9205+ else
9206+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9207+ regs->pc = addr;
9208+ regs->npc = addr+4;
9209+ return 2;
9210+ }
9211+ } while (0);
9212+
9213+ do { /* PaX: unpatched PLT emulation step 1 */
9214+ unsigned int sethi, ba, nop;
9215+
9216+ err = get_user(sethi, (unsigned int *)regs->pc);
9217+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
9218+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9219+
9220+ if (err)
9221+ break;
9222+
9223+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9224+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9225+ nop == 0x01000000U)
9226+ {
9227+ unsigned int addr, save, call;
9228+
9229+ if ((ba & 0xFFC00000U) == 0x30800000U)
9230+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9231+ else
9232+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9233+
9234+ err = get_user(save, (unsigned int *)addr);
9235+ err |= get_user(call, (unsigned int *)(addr+4));
9236+ err |= get_user(nop, (unsigned int *)(addr+8));
9237+ if (err)
9238+ break;
9239+
9240+#ifdef CONFIG_PAX_DLRESOLVE
9241+ if (save == 0x9DE3BFA8U &&
9242+ (call & 0xC0000000U) == 0x40000000U &&
9243+ nop == 0x01000000U)
9244+ {
9245+ struct vm_area_struct *vma;
9246+ unsigned long call_dl_resolve;
9247+
9248+ down_read(&current->mm->mmap_sem);
9249+ call_dl_resolve = current->mm->call_dl_resolve;
9250+ up_read(&current->mm->mmap_sem);
9251+ if (likely(call_dl_resolve))
9252+ goto emulate;
9253+
9254+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9255+
9256+ down_write(&current->mm->mmap_sem);
9257+ if (current->mm->call_dl_resolve) {
9258+ call_dl_resolve = current->mm->call_dl_resolve;
9259+ up_write(&current->mm->mmap_sem);
9260+ if (vma)
9261+ kmem_cache_free(vm_area_cachep, vma);
9262+ goto emulate;
9263+ }
9264+
9265+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9266+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9267+ up_write(&current->mm->mmap_sem);
9268+ if (vma)
9269+ kmem_cache_free(vm_area_cachep, vma);
9270+ return 1;
9271+ }
9272+
9273+ if (pax_insert_vma(vma, call_dl_resolve)) {
9274+ up_write(&current->mm->mmap_sem);
9275+ kmem_cache_free(vm_area_cachep, vma);
9276+ return 1;
9277+ }
9278+
9279+ current->mm->call_dl_resolve = call_dl_resolve;
9280+ up_write(&current->mm->mmap_sem);
9281+
9282+emulate:
9283+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9284+ regs->pc = call_dl_resolve;
9285+ regs->npc = addr+4;
9286+ return 3;
9287+ }
9288+#endif
9289+
9290+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9291+ if ((save & 0xFFC00000U) == 0x05000000U &&
9292+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9293+ nop == 0x01000000U)
9294+ {
9295+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9296+ regs->u_regs[UREG_G2] = addr + 4;
9297+ addr = (save & 0x003FFFFFU) << 10;
9298+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9299+ regs->pc = addr;
9300+ regs->npc = addr+4;
9301+ return 3;
9302+ }
9303+ }
9304+ } while (0);
9305+
9306+ do { /* PaX: unpatched PLT emulation step 2 */
9307+ unsigned int save, call, nop;
9308+
9309+ err = get_user(save, (unsigned int *)(regs->pc-4));
9310+ err |= get_user(call, (unsigned int *)regs->pc);
9311+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
9312+ if (err)
9313+ break;
9314+
9315+ if (save == 0x9DE3BFA8U &&
9316+ (call & 0xC0000000U) == 0x40000000U &&
9317+ nop == 0x01000000U)
9318+ {
9319+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9320+
9321+ regs->u_regs[UREG_RETPC] = regs->pc;
9322+ regs->pc = dl_resolve;
9323+ regs->npc = dl_resolve+4;
9324+ return 3;
9325+ }
9326+ } while (0);
9327+#endif
9328+
9329+ return 1;
9330+}
9331+
9332+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9333+{
9334+ unsigned long i;
9335+
9336+ printk(KERN_ERR "PAX: bytes at PC: ");
9337+ for (i = 0; i < 8; i++) {
9338+ unsigned int c;
9339+ if (get_user(c, (unsigned int *)pc+i))
9340+ printk(KERN_CONT "???????? ");
9341+ else
9342+ printk(KERN_CONT "%08x ", c);
9343+ }
9344+ printk("\n");
9345+}
9346+#endif
9347+
9348 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9349 int text_fault)
9350 {
9351@@ -230,6 +504,24 @@ good_area:
9352 if (!(vma->vm_flags & VM_WRITE))
9353 goto bad_area;
9354 } else {
9355+
9356+#ifdef CONFIG_PAX_PAGEEXEC
9357+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9358+ up_read(&mm->mmap_sem);
9359+ switch (pax_handle_fetch_fault(regs)) {
9360+
9361+#ifdef CONFIG_PAX_EMUPLT
9362+ case 2:
9363+ case 3:
9364+ return;
9365+#endif
9366+
9367+ }
9368+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9369+ do_group_exit(SIGKILL);
9370+ }
9371+#endif
9372+
9373 /* Allow reads even for write-only mappings */
9374 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9375 goto bad_area;
9376diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9377index 5062ff3..e0b75f3 100644
9378--- a/arch/sparc/mm/fault_64.c
9379+++ b/arch/sparc/mm/fault_64.c
9380@@ -21,6 +21,9 @@
9381 #include <linux/kprobes.h>
9382 #include <linux/kdebug.h>
9383 #include <linux/percpu.h>
9384+#include <linux/slab.h>
9385+#include <linux/pagemap.h>
9386+#include <linux/compiler.h>
9387
9388 #include <asm/page.h>
9389 #include <asm/pgtable.h>
9390@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9391 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9392 regs->tpc);
9393 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9394- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9395+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9396 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9397 dump_stack();
9398 unhandled_fault(regs->tpc, current, regs);
9399@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9400 show_regs(regs);
9401 }
9402
9403+#ifdef CONFIG_PAX_PAGEEXEC
9404+#ifdef CONFIG_PAX_DLRESOLVE
9405+static void pax_emuplt_close(struct vm_area_struct *vma)
9406+{
9407+ vma->vm_mm->call_dl_resolve = 0UL;
9408+}
9409+
9410+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9411+{
9412+ unsigned int *kaddr;
9413+
9414+ vmf->page = alloc_page(GFP_HIGHUSER);
9415+ if (!vmf->page)
9416+ return VM_FAULT_OOM;
9417+
9418+ kaddr = kmap(vmf->page);
9419+ memset(kaddr, 0, PAGE_SIZE);
9420+ kaddr[0] = 0x9DE3BFA8U; /* save */
9421+ flush_dcache_page(vmf->page);
9422+ kunmap(vmf->page);
9423+ return VM_FAULT_MAJOR;
9424+}
9425+
9426+static const struct vm_operations_struct pax_vm_ops = {
9427+ .close = pax_emuplt_close,
9428+ .fault = pax_emuplt_fault
9429+};
9430+
9431+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9432+{
9433+ int ret;
9434+
9435+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9436+ vma->vm_mm = current->mm;
9437+ vma->vm_start = addr;
9438+ vma->vm_end = addr + PAGE_SIZE;
9439+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9440+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9441+ vma->vm_ops = &pax_vm_ops;
9442+
9443+ ret = insert_vm_struct(current->mm, vma);
9444+ if (ret)
9445+ return ret;
9446+
9447+ ++current->mm->total_vm;
9448+ return 0;
9449+}
9450+#endif
9451+
9452+/*
9453+ * PaX: decide what to do with offenders (regs->tpc = fault address)
9454+ *
9455+ * returns 1 when task should be killed
9456+ * 2 when patched PLT trampoline was detected
9457+ * 3 when unpatched PLT trampoline was detected
9458+ */
9459+static int pax_handle_fetch_fault(struct pt_regs *regs)
9460+{
9461+
9462+#ifdef CONFIG_PAX_EMUPLT
9463+ int err;
9464+
9465+ do { /* PaX: patched PLT emulation #1 */
9466+ unsigned int sethi1, sethi2, jmpl;
9467+
9468+ err = get_user(sethi1, (unsigned int *)regs->tpc);
9469+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9470+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9471+
9472+ if (err)
9473+ break;
9474+
9475+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9476+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9477+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9478+ {
9479+ unsigned long addr;
9480+
9481+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9482+ addr = regs->u_regs[UREG_G1];
9483+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9484+
9485+ if (test_thread_flag(TIF_32BIT))
9486+ addr &= 0xFFFFFFFFUL;
9487+
9488+ regs->tpc = addr;
9489+ regs->tnpc = addr+4;
9490+ return 2;
9491+ }
9492+ } while (0);
9493+
9494+ do { /* PaX: patched PLT emulation #2 */
9495+ unsigned int ba;
9496+
9497+ err = get_user(ba, (unsigned int *)regs->tpc);
9498+
9499+ if (err)
9500+ break;
9501+
9502+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9503+ unsigned long addr;
9504+
9505+ if ((ba & 0xFFC00000U) == 0x30800000U)
9506+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9507+ else
9508+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9509+
9510+ if (test_thread_flag(TIF_32BIT))
9511+ addr &= 0xFFFFFFFFUL;
9512+
9513+ regs->tpc = addr;
9514+ regs->tnpc = addr+4;
9515+ return 2;
9516+ }
9517+ } while (0);
9518+
9519+ do { /* PaX: patched PLT emulation #3 */
9520+ unsigned int sethi, bajmpl, nop;
9521+
9522+ err = get_user(sethi, (unsigned int *)regs->tpc);
9523+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9524+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9525+
9526+ if (err)
9527+ break;
9528+
9529+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9530+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9531+ nop == 0x01000000U)
9532+ {
9533+ unsigned long addr;
9534+
9535+ addr = (sethi & 0x003FFFFFU) << 10;
9536+ regs->u_regs[UREG_G1] = addr;
9537+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9538+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9539+ else
9540+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9541+
9542+ if (test_thread_flag(TIF_32BIT))
9543+ addr &= 0xFFFFFFFFUL;
9544+
9545+ regs->tpc = addr;
9546+ regs->tnpc = addr+4;
9547+ return 2;
9548+ }
9549+ } while (0);
9550+
9551+ do { /* PaX: patched PLT emulation #4 */
9552+ unsigned int sethi, mov1, call, mov2;
9553+
9554+ err = get_user(sethi, (unsigned int *)regs->tpc);
9555+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9556+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
9557+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9558+
9559+ if (err)
9560+ break;
9561+
9562+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9563+ mov1 == 0x8210000FU &&
9564+ (call & 0xC0000000U) == 0x40000000U &&
9565+ mov2 == 0x9E100001U)
9566+ {
9567+ unsigned long addr;
9568+
9569+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9570+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9571+
9572+ if (test_thread_flag(TIF_32BIT))
9573+ addr &= 0xFFFFFFFFUL;
9574+
9575+ regs->tpc = addr;
9576+ regs->tnpc = addr+4;
9577+ return 2;
9578+ }
9579+ } while (0);
9580+
9581+ do { /* PaX: patched PLT emulation #5 */
9582+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9583+
9584+ err = get_user(sethi, (unsigned int *)regs->tpc);
9585+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9586+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9587+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9588+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9589+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9590+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9591+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9592+
9593+ if (err)
9594+ break;
9595+
9596+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9597+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9598+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9599+ (or1 & 0xFFFFE000U) == 0x82106000U &&
9600+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9601+ sllx == 0x83287020U &&
9602+ jmpl == 0x81C04005U &&
9603+ nop == 0x01000000U)
9604+ {
9605+ unsigned long addr;
9606+
9607+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9608+ regs->u_regs[UREG_G1] <<= 32;
9609+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9610+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9611+ regs->tpc = addr;
9612+ regs->tnpc = addr+4;
9613+ return 2;
9614+ }
9615+ } while (0);
9616+
9617+ do { /* PaX: patched PLT emulation #6 */
9618+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9619+
9620+ err = get_user(sethi, (unsigned int *)regs->tpc);
9621+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9622+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9623+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9624+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
9625+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9626+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9627+
9628+ if (err)
9629+ break;
9630+
9631+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9632+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9633+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9634+ sllx == 0x83287020U &&
9635+ (or & 0xFFFFE000U) == 0x8A116000U &&
9636+ jmpl == 0x81C04005U &&
9637+ nop == 0x01000000U)
9638+ {
9639+ unsigned long addr;
9640+
9641+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9642+ regs->u_regs[UREG_G1] <<= 32;
9643+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9644+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9645+ regs->tpc = addr;
9646+ regs->tnpc = addr+4;
9647+ return 2;
9648+ }
9649+ } while (0);
9650+
9651+ do { /* PaX: unpatched PLT emulation step 1 */
9652+ unsigned int sethi, ba, nop;
9653+
9654+ err = get_user(sethi, (unsigned int *)regs->tpc);
9655+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9656+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9657+
9658+ if (err)
9659+ break;
9660+
9661+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9662+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9663+ nop == 0x01000000U)
9664+ {
9665+ unsigned long addr;
9666+ unsigned int save, call;
9667+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9668+
9669+ if ((ba & 0xFFC00000U) == 0x30800000U)
9670+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9671+ else
9672+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9673+
9674+ if (test_thread_flag(TIF_32BIT))
9675+ addr &= 0xFFFFFFFFUL;
9676+
9677+ err = get_user(save, (unsigned int *)addr);
9678+ err |= get_user(call, (unsigned int *)(addr+4));
9679+ err |= get_user(nop, (unsigned int *)(addr+8));
9680+ if (err)
9681+ break;
9682+
9683+#ifdef CONFIG_PAX_DLRESOLVE
9684+ if (save == 0x9DE3BFA8U &&
9685+ (call & 0xC0000000U) == 0x40000000U &&
9686+ nop == 0x01000000U)
9687+ {
9688+ struct vm_area_struct *vma;
9689+ unsigned long call_dl_resolve;
9690+
9691+ down_read(&current->mm->mmap_sem);
9692+ call_dl_resolve = current->mm->call_dl_resolve;
9693+ up_read(&current->mm->mmap_sem);
9694+ if (likely(call_dl_resolve))
9695+ goto emulate;
9696+
9697+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9698+
9699+ down_write(&current->mm->mmap_sem);
9700+ if (current->mm->call_dl_resolve) {
9701+ call_dl_resolve = current->mm->call_dl_resolve;
9702+ up_write(&current->mm->mmap_sem);
9703+ if (vma)
9704+ kmem_cache_free(vm_area_cachep, vma);
9705+ goto emulate;
9706+ }
9707+
9708+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9709+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9710+ up_write(&current->mm->mmap_sem);
9711+ if (vma)
9712+ kmem_cache_free(vm_area_cachep, vma);
9713+ return 1;
9714+ }
9715+
9716+ if (pax_insert_vma(vma, call_dl_resolve)) {
9717+ up_write(&current->mm->mmap_sem);
9718+ kmem_cache_free(vm_area_cachep, vma);
9719+ return 1;
9720+ }
9721+
9722+ current->mm->call_dl_resolve = call_dl_resolve;
9723+ up_write(&current->mm->mmap_sem);
9724+
9725+emulate:
9726+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9727+ regs->tpc = call_dl_resolve;
9728+ regs->tnpc = addr+4;
9729+ return 3;
9730+ }
9731+#endif
9732+
9733+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9734+ if ((save & 0xFFC00000U) == 0x05000000U &&
9735+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9736+ nop == 0x01000000U)
9737+ {
9738+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9739+ regs->u_regs[UREG_G2] = addr + 4;
9740+ addr = (save & 0x003FFFFFU) << 10;
9741+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9742+
9743+ if (test_thread_flag(TIF_32BIT))
9744+ addr &= 0xFFFFFFFFUL;
9745+
9746+ regs->tpc = addr;
9747+ regs->tnpc = addr+4;
9748+ return 3;
9749+ }
9750+
9751+ /* PaX: 64-bit PLT stub */
9752+ err = get_user(sethi1, (unsigned int *)addr);
9753+ err |= get_user(sethi2, (unsigned int *)(addr+4));
9754+ err |= get_user(or1, (unsigned int *)(addr+8));
9755+ err |= get_user(or2, (unsigned int *)(addr+12));
9756+ err |= get_user(sllx, (unsigned int *)(addr+16));
9757+ err |= get_user(add, (unsigned int *)(addr+20));
9758+ err |= get_user(jmpl, (unsigned int *)(addr+24));
9759+ err |= get_user(nop, (unsigned int *)(addr+28));
9760+ if (err)
9761+ break;
9762+
9763+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9764+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9765+ (or1 & 0xFFFFE000U) == 0x88112000U &&
9766+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9767+ sllx == 0x89293020U &&
9768+ add == 0x8A010005U &&
9769+ jmpl == 0x89C14000U &&
9770+ nop == 0x01000000U)
9771+ {
9772+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9773+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9774+ regs->u_regs[UREG_G4] <<= 32;
9775+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9776+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9777+ regs->u_regs[UREG_G4] = addr + 24;
9778+ addr = regs->u_regs[UREG_G5];
9779+ regs->tpc = addr;
9780+ regs->tnpc = addr+4;
9781+ return 3;
9782+ }
9783+ }
9784+ } while (0);
9785+
9786+#ifdef CONFIG_PAX_DLRESOLVE
9787+ do { /* PaX: unpatched PLT emulation step 2 */
9788+ unsigned int save, call, nop;
9789+
9790+ err = get_user(save, (unsigned int *)(regs->tpc-4));
9791+ err |= get_user(call, (unsigned int *)regs->tpc);
9792+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9793+ if (err)
9794+ break;
9795+
9796+ if (save == 0x9DE3BFA8U &&
9797+ (call & 0xC0000000U) == 0x40000000U &&
9798+ nop == 0x01000000U)
9799+ {
9800+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9801+
9802+ if (test_thread_flag(TIF_32BIT))
9803+ dl_resolve &= 0xFFFFFFFFUL;
9804+
9805+ regs->u_regs[UREG_RETPC] = regs->tpc;
9806+ regs->tpc = dl_resolve;
9807+ regs->tnpc = dl_resolve+4;
9808+ return 3;
9809+ }
9810+ } while (0);
9811+#endif
9812+
9813+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9814+ unsigned int sethi, ba, nop;
9815+
9816+ err = get_user(sethi, (unsigned int *)regs->tpc);
9817+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9818+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9819+
9820+ if (err)
9821+ break;
9822+
9823+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9824+ (ba & 0xFFF00000U) == 0x30600000U &&
9825+ nop == 0x01000000U)
9826+ {
9827+ unsigned long addr;
9828+
9829+ addr = (sethi & 0x003FFFFFU) << 10;
9830+ regs->u_regs[UREG_G1] = addr;
9831+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9832+
9833+ if (test_thread_flag(TIF_32BIT))
9834+ addr &= 0xFFFFFFFFUL;
9835+
9836+ regs->tpc = addr;
9837+ regs->tnpc = addr+4;
9838+ return 2;
9839+ }
9840+ } while (0);
9841+
9842+#endif
9843+
9844+ return 1;
9845+}
9846+
9847+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9848+{
9849+ unsigned long i;
9850+
9851+ printk(KERN_ERR "PAX: bytes at PC: ");
9852+ for (i = 0; i < 8; i++) {
9853+ unsigned int c;
9854+ if (get_user(c, (unsigned int *)pc+i))
9855+ printk(KERN_CONT "???????? ");
9856+ else
9857+ printk(KERN_CONT "%08x ", c);
9858+ }
9859+ printk("\n");
9860+}
9861+#endif
9862+
9863 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9864 {
9865 struct mm_struct *mm = current->mm;
9866@@ -341,6 +804,29 @@ retry:
9867 if (!vma)
9868 goto bad_area;
9869
9870+#ifdef CONFIG_PAX_PAGEEXEC
9871+ /* PaX: detect ITLB misses on non-exec pages */
9872+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9873+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9874+ {
9875+ if (address != regs->tpc)
9876+ goto good_area;
9877+
9878+ up_read(&mm->mmap_sem);
9879+ switch (pax_handle_fetch_fault(regs)) {
9880+
9881+#ifdef CONFIG_PAX_EMUPLT
9882+ case 2:
9883+ case 3:
9884+ return;
9885+#endif
9886+
9887+ }
9888+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9889+ do_group_exit(SIGKILL);
9890+ }
9891+#endif
9892+
9893 /* Pure DTLB misses do not tell us whether the fault causing
9894 * load/store/atomic was a write or not, it only says that there
9895 * was no match. So in such a case we (carefully) read the
9896diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
9897index d2b5944..bd813f2 100644
9898--- a/arch/sparc/mm/hugetlbpage.c
9899+++ b/arch/sparc/mm/hugetlbpage.c
9900@@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9901
9902 info.flags = 0;
9903 info.length = len;
9904- info.low_limit = TASK_UNMAPPED_BASE;
9905+ info.low_limit = mm->mmap_base;
9906 info.high_limit = min(task_size, VA_EXCLUDE_START);
9907 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
9908 info.align_offset = 0;
9909@@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9910 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9911 VM_BUG_ON(addr != -ENOMEM);
9912 info.low_limit = VA_EXCLUDE_END;
9913+
9914+#ifdef CONFIG_PAX_RANDMMAP
9915+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9916+ info.low_limit += mm->delta_mmap;
9917+#endif
9918+
9919 info.high_limit = task_size;
9920 addr = vm_unmapped_area(&info);
9921 }
9922@@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9923 VM_BUG_ON(addr != -ENOMEM);
9924 info.flags = 0;
9925 info.low_limit = TASK_UNMAPPED_BASE;
9926+
9927+#ifdef CONFIG_PAX_RANDMMAP
9928+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9929+ info.low_limit += mm->delta_mmap;
9930+#endif
9931+
9932 info.high_limit = STACK_TOP32;
9933 addr = vm_unmapped_area(&info);
9934 }
9935@@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9936 struct mm_struct *mm = current->mm;
9937 struct vm_area_struct *vma;
9938 unsigned long task_size = TASK_SIZE;
9939+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
9940
9941 if (test_thread_flag(TIF_32BIT))
9942 task_size = STACK_TOP32;
9943@@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9944 return addr;
9945 }
9946
9947+#ifdef CONFIG_PAX_RANDMMAP
9948+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9949+#endif
9950+
9951 if (addr) {
9952 addr = ALIGN(addr, HPAGE_SIZE);
9953 vma = find_vma(mm, addr);
9954- if (task_size - len >= addr &&
9955- (!vma || addr + len <= vma->vm_start))
9956+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9957 return addr;
9958 }
9959 if (mm->get_unmapped_area == arch_get_unmapped_area)
9960diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
9961index f4500c6..889656c 100644
9962--- a/arch/tile/include/asm/atomic_64.h
9963+++ b/arch/tile/include/asm/atomic_64.h
9964@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9965
9966 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9967
9968+#define atomic64_read_unchecked(v) atomic64_read(v)
9969+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9970+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9971+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9972+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9973+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9974+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9975+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9976+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9977+
9978 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
9979 #define smp_mb__before_atomic_dec() smp_mb()
9980 #define smp_mb__after_atomic_dec() smp_mb()
9981diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
9982index a9a5299..0fce79e 100644
9983--- a/arch/tile/include/asm/cache.h
9984+++ b/arch/tile/include/asm/cache.h
9985@@ -15,11 +15,12 @@
9986 #ifndef _ASM_TILE_CACHE_H
9987 #define _ASM_TILE_CACHE_H
9988
9989+#include <linux/const.h>
9990 #include <arch/chip.h>
9991
9992 /* bytes per L1 data cache line */
9993 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
9994-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9995+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9996
9997 /* bytes per L2 cache line */
9998 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
9999diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
10000index 9ab078a..d6635c2 100644
10001--- a/arch/tile/include/asm/uaccess.h
10002+++ b/arch/tile/include/asm/uaccess.h
10003@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
10004 const void __user *from,
10005 unsigned long n)
10006 {
10007- int sz = __compiletime_object_size(to);
10008+ size_t sz = __compiletime_object_size(to);
10009
10010- if (likely(sz == -1 || sz >= n))
10011+ if (likely(sz == (size_t)-1 || sz >= n))
10012 n = _copy_from_user(to, from, n);
10013 else
10014 copy_from_user_overflow();
10015diff --git a/arch/um/Makefile b/arch/um/Makefile
10016index 133f7de..1d6f2f1 100644
10017--- a/arch/um/Makefile
10018+++ b/arch/um/Makefile
10019@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
10020 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
10021 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
10022
10023+ifdef CONSTIFY_PLUGIN
10024+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10025+endif
10026+
10027 #This will adjust *FLAGS accordingly to the platform.
10028 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
10029
10030diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
10031index 19e1bdd..3665b77 100644
10032--- a/arch/um/include/asm/cache.h
10033+++ b/arch/um/include/asm/cache.h
10034@@ -1,6 +1,7 @@
10035 #ifndef __UM_CACHE_H
10036 #define __UM_CACHE_H
10037
10038+#include <linux/const.h>
10039
10040 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
10041 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10042@@ -12,6 +13,6 @@
10043 # define L1_CACHE_SHIFT 5
10044 #endif
10045
10046-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10047+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10048
10049 #endif
10050diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
10051index 2e0a6b1..a64d0f5 100644
10052--- a/arch/um/include/asm/kmap_types.h
10053+++ b/arch/um/include/asm/kmap_types.h
10054@@ -8,6 +8,6 @@
10055
10056 /* No more #include "asm/arch/kmap_types.h" ! */
10057
10058-#define KM_TYPE_NR 14
10059+#define KM_TYPE_NR 15
10060
10061 #endif
10062diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
10063index 5ff53d9..5850cdf 100644
10064--- a/arch/um/include/asm/page.h
10065+++ b/arch/um/include/asm/page.h
10066@@ -14,6 +14,9 @@
10067 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
10068 #define PAGE_MASK (~(PAGE_SIZE-1))
10069
10070+#define ktla_ktva(addr) (addr)
10071+#define ktva_ktla(addr) (addr)
10072+
10073 #ifndef __ASSEMBLY__
10074
10075 struct page;
10076diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
10077index 0032f92..cd151e0 100644
10078--- a/arch/um/include/asm/pgtable-3level.h
10079+++ b/arch/um/include/asm/pgtable-3level.h
10080@@ -58,6 +58,7 @@
10081 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
10082 #define pud_populate(mm, pud, pmd) \
10083 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
10084+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
10085
10086 #ifdef CONFIG_64BIT
10087 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
10088diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
10089index b462b13..e7a19aa 100644
10090--- a/arch/um/kernel/process.c
10091+++ b/arch/um/kernel/process.c
10092@@ -386,22 +386,6 @@ int singlestepping(void * t)
10093 return 2;
10094 }
10095
10096-/*
10097- * Only x86 and x86_64 have an arch_align_stack().
10098- * All other arches have "#define arch_align_stack(x) (x)"
10099- * in their asm/system.h
10100- * As this is included in UML from asm-um/system-generic.h,
10101- * we can use it to behave as the subarch does.
10102- */
10103-#ifndef arch_align_stack
10104-unsigned long arch_align_stack(unsigned long sp)
10105-{
10106- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10107- sp -= get_random_int() % 8192;
10108- return sp & ~0xf;
10109-}
10110-#endif
10111-
10112 unsigned long get_wchan(struct task_struct *p)
10113 {
10114 unsigned long stack_page, sp, ip;
10115diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
10116index ad8f795..2c7eec6 100644
10117--- a/arch/unicore32/include/asm/cache.h
10118+++ b/arch/unicore32/include/asm/cache.h
10119@@ -12,8 +12,10 @@
10120 #ifndef __UNICORE_CACHE_H__
10121 #define __UNICORE_CACHE_H__
10122
10123-#define L1_CACHE_SHIFT (5)
10124-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10125+#include <linux/const.h>
10126+
10127+#define L1_CACHE_SHIFT 5
10128+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10129
10130 /*
10131 * Memory returned by kmalloc() may be used for DMA, so we must make
10132diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
10133index 0694d09..b58b3aa 100644
10134--- a/arch/x86/Kconfig
10135+++ b/arch/x86/Kconfig
10136@@ -238,7 +238,7 @@ config X86_HT
10137
10138 config X86_32_LAZY_GS
10139 def_bool y
10140- depends on X86_32 && !CC_STACKPROTECTOR
10141+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
10142
10143 config ARCH_HWEIGHT_CFLAGS
10144 string
10145@@ -1031,6 +1031,7 @@ config MICROCODE_OLD_INTERFACE
10146
10147 config X86_MSR
10148 tristate "/dev/cpu/*/msr - Model-specific register support"
10149+ depends on !GRKERNSEC_KMEM
10150 ---help---
10151 This device gives privileged processes access to the x86
10152 Model-Specific Registers (MSRs). It is a character device with
10153@@ -1054,7 +1055,7 @@ choice
10154
10155 config NOHIGHMEM
10156 bool "off"
10157- depends on !X86_NUMAQ
10158+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10159 ---help---
10160 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
10161 However, the address space of 32-bit x86 processors is only 4
10162@@ -1091,7 +1092,7 @@ config NOHIGHMEM
10163
10164 config HIGHMEM4G
10165 bool "4GB"
10166- depends on !X86_NUMAQ
10167+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10168 ---help---
10169 Select this if you have a 32-bit processor and between 1 and 4
10170 gigabytes of physical RAM.
10171@@ -1145,7 +1146,7 @@ config PAGE_OFFSET
10172 hex
10173 default 0xB0000000 if VMSPLIT_3G_OPT
10174 default 0x80000000 if VMSPLIT_2G
10175- default 0x78000000 if VMSPLIT_2G_OPT
10176+ default 0x70000000 if VMSPLIT_2G_OPT
10177 default 0x40000000 if VMSPLIT_1G
10178 default 0xC0000000
10179 depends on X86_32
10180@@ -1542,6 +1543,7 @@ config SECCOMP
10181
10182 config CC_STACKPROTECTOR
10183 bool "Enable -fstack-protector buffer overflow detection"
10184+ depends on X86_64 || !PAX_MEMORY_UDEREF
10185 ---help---
10186 This option turns on the -fstack-protector GCC feature. This
10187 feature puts, at the beginning of functions, a canary value on
10188@@ -1599,6 +1601,7 @@ config KEXEC_JUMP
10189 config PHYSICAL_START
10190 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
10191 default "0x1000000"
10192+ range 0x400000 0x40000000
10193 ---help---
10194 This gives the physical address where the kernel is loaded.
10195
10196@@ -1662,6 +1665,7 @@ config X86_NEED_RELOCS
10197 config PHYSICAL_ALIGN
10198 hex "Alignment value to which kernel should be aligned" if X86_32
10199 default "0x1000000"
10200+ range 0x400000 0x1000000 if PAX_KERNEXEC
10201 range 0x2000 0x1000000
10202 ---help---
10203 This value puts the alignment restrictions on physical address
10204@@ -1737,9 +1741,10 @@ config DEBUG_HOTPLUG_CPU0
10205 If unsure, say N.
10206
10207 config COMPAT_VDSO
10208- def_bool y
10209+ def_bool n
10210 prompt "Compat VDSO support"
10211 depends on X86_32 || IA32_EMULATION
10212+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
10213 ---help---
10214 Map the 32-bit VDSO to the predictable old-style address too.
10215
10216diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
10217index c026cca..14657ae 100644
10218--- a/arch/x86/Kconfig.cpu
10219+++ b/arch/x86/Kconfig.cpu
10220@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
10221
10222 config X86_F00F_BUG
10223 def_bool y
10224- depends on M586MMX || M586TSC || M586 || M486
10225+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
10226
10227 config X86_INVD_BUG
10228 def_bool y
10229@@ -327,7 +327,7 @@ config X86_INVD_BUG
10230
10231 config X86_ALIGNMENT_16
10232 def_bool y
10233- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10234+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10235
10236 config X86_INTEL_USERCOPY
10237 def_bool y
10238@@ -373,7 +373,7 @@ config X86_CMPXCHG64
10239 # generates cmov.
10240 config X86_CMOV
10241 def_bool y
10242- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10243+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10244
10245 config X86_MINIMUM_CPU_FAMILY
10246 int
10247diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
10248index b322f12..652d0d9 100644
10249--- a/arch/x86/Kconfig.debug
10250+++ b/arch/x86/Kconfig.debug
10251@@ -84,7 +84,7 @@ config X86_PTDUMP
10252 config DEBUG_RODATA
10253 bool "Write protect kernel read-only data structures"
10254 default y
10255- depends on DEBUG_KERNEL
10256+ depends on DEBUG_KERNEL && BROKEN
10257 ---help---
10258 Mark the kernel read-only data as write-protected in the pagetables,
10259 in order to catch accidental (and incorrect) writes to such const
10260@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
10261
10262 config DEBUG_SET_MODULE_RONX
10263 bool "Set loadable kernel module data as NX and text as RO"
10264- depends on MODULES
10265+ depends on MODULES && BROKEN
10266 ---help---
10267 This option helps catch unintended modifications to loadable
10268 kernel module's text and read-only data. It also prevents execution
10269@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
10270
10271 config DEBUG_STRICT_USER_COPY_CHECKS
10272 bool "Strict copy size checks"
10273- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
10274+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
10275 ---help---
10276 Enabling this option turns a certain set of sanity checks for user
10277 copy operations into compile time failures.
10278diff --git a/arch/x86/Makefile b/arch/x86/Makefile
10279index e71fc42..7829607 100644
10280--- a/arch/x86/Makefile
10281+++ b/arch/x86/Makefile
10282@@ -50,6 +50,7 @@ else
10283 UTS_MACHINE := x86_64
10284 CHECKFLAGS += -D__x86_64__ -m64
10285
10286+ biarch := $(call cc-option,-m64)
10287 KBUILD_AFLAGS += -m64
10288 KBUILD_CFLAGS += -m64
10289
10290@@ -230,3 +231,12 @@ define archhelp
10291 echo ' FDARGS="..." arguments for the booted kernel'
10292 echo ' FDINITRD=file initrd for the booted kernel'
10293 endef
10294+
10295+define OLD_LD
10296+
10297+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
10298+*** Please upgrade your binutils to 2.18 or newer
10299+endef
10300+
10301+archprepare:
10302+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10303diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10304index 379814b..add62ce 100644
10305--- a/arch/x86/boot/Makefile
10306+++ b/arch/x86/boot/Makefile
10307@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10308 $(call cc-option, -fno-stack-protector) \
10309 $(call cc-option, -mpreferred-stack-boundary=2)
10310 KBUILD_CFLAGS += $(call cc-option, -m32)
10311+ifdef CONSTIFY_PLUGIN
10312+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10313+endif
10314 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10315 GCOV_PROFILE := n
10316
10317diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10318index 878e4b9..20537ab 100644
10319--- a/arch/x86/boot/bitops.h
10320+++ b/arch/x86/boot/bitops.h
10321@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10322 u8 v;
10323 const u32 *p = (const u32 *)addr;
10324
10325- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10326+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10327 return v;
10328 }
10329
10330@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10331
10332 static inline void set_bit(int nr, void *addr)
10333 {
10334- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10335+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10336 }
10337
10338 #endif /* BOOT_BITOPS_H */
10339diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10340index 18997e5..83d9c67 100644
10341--- a/arch/x86/boot/boot.h
10342+++ b/arch/x86/boot/boot.h
10343@@ -85,7 +85,7 @@ static inline void io_delay(void)
10344 static inline u16 ds(void)
10345 {
10346 u16 seg;
10347- asm("movw %%ds,%0" : "=rm" (seg));
10348+ asm volatile("movw %%ds,%0" : "=rm" (seg));
10349 return seg;
10350 }
10351
10352@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10353 static inline int memcmp(const void *s1, const void *s2, size_t len)
10354 {
10355 u8 diff;
10356- asm("repe; cmpsb; setnz %0"
10357+ asm volatile("repe; cmpsb; setnz %0"
10358 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10359 return diff;
10360 }
10361diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10362index 8a84501..b2d165f 100644
10363--- a/arch/x86/boot/compressed/Makefile
10364+++ b/arch/x86/boot/compressed/Makefile
10365@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10366 KBUILD_CFLAGS += $(cflags-y)
10367 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10368 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10369+ifdef CONSTIFY_PLUGIN
10370+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10371+endif
10372
10373 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10374 GCOV_PROFILE := n
10375diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10376index c205035..5853587 100644
10377--- a/arch/x86/boot/compressed/eboot.c
10378+++ b/arch/x86/boot/compressed/eboot.c
10379@@ -150,7 +150,6 @@ again:
10380 *addr = max_addr;
10381 }
10382
10383-free_pool:
10384 efi_call_phys1(sys_table->boottime->free_pool, map);
10385
10386 fail:
10387@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10388 if (i == map_size / desc_size)
10389 status = EFI_NOT_FOUND;
10390
10391-free_pool:
10392 efi_call_phys1(sys_table->boottime->free_pool, map);
10393 fail:
10394 return status;
10395diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10396index 1e3184f..0d11e2e 100644
10397--- a/arch/x86/boot/compressed/head_32.S
10398+++ b/arch/x86/boot/compressed/head_32.S
10399@@ -118,7 +118,7 @@ preferred_addr:
10400 notl %eax
10401 andl %eax, %ebx
10402 #else
10403- movl $LOAD_PHYSICAL_ADDR, %ebx
10404+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10405 #endif
10406
10407 /* Target address to relocate to for decompression */
10408@@ -204,7 +204,7 @@ relocated:
10409 * and where it was actually loaded.
10410 */
10411 movl %ebp, %ebx
10412- subl $LOAD_PHYSICAL_ADDR, %ebx
10413+ subl $____LOAD_PHYSICAL_ADDR, %ebx
10414 jz 2f /* Nothing to be done if loaded at compiled addr. */
10415 /*
10416 * Process relocations.
10417@@ -212,8 +212,7 @@ relocated:
10418
10419 1: subl $4, %edi
10420 movl (%edi), %ecx
10421- testl %ecx, %ecx
10422- jz 2f
10423+ jecxz 2f
10424 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10425 jmp 1b
10426 2:
10427diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10428index f5d1aaa..cce11dc 100644
10429--- a/arch/x86/boot/compressed/head_64.S
10430+++ b/arch/x86/boot/compressed/head_64.S
10431@@ -91,7 +91,7 @@ ENTRY(startup_32)
10432 notl %eax
10433 andl %eax, %ebx
10434 #else
10435- movl $LOAD_PHYSICAL_ADDR, %ebx
10436+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10437 #endif
10438
10439 /* Target address to relocate to for decompression */
10440@@ -273,7 +273,7 @@ preferred_addr:
10441 notq %rax
10442 andq %rax, %rbp
10443 #else
10444- movq $LOAD_PHYSICAL_ADDR, %rbp
10445+ movq $____LOAD_PHYSICAL_ADDR, %rbp
10446 #endif
10447
10448 /* Target address to relocate to for decompression */
10449diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10450index 88f7ff6..ed695dd 100644
10451--- a/arch/x86/boot/compressed/misc.c
10452+++ b/arch/x86/boot/compressed/misc.c
10453@@ -303,7 +303,7 @@ static void parse_elf(void *output)
10454 case PT_LOAD:
10455 #ifdef CONFIG_RELOCATABLE
10456 dest = output;
10457- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10458+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10459 #else
10460 dest = (void *)(phdr->p_paddr);
10461 #endif
10462@@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10463 error("Destination address too large");
10464 #endif
10465 #ifndef CONFIG_RELOCATABLE
10466- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10467+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10468 error("Wrong destination address");
10469 #endif
10470
10471diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10472index 4d3ff03..e4972ff 100644
10473--- a/arch/x86/boot/cpucheck.c
10474+++ b/arch/x86/boot/cpucheck.c
10475@@ -74,7 +74,7 @@ static int has_fpu(void)
10476 u16 fcw = -1, fsw = -1;
10477 u32 cr0;
10478
10479- asm("movl %%cr0,%0" : "=r" (cr0));
10480+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
10481 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10482 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10483 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10484@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10485 {
10486 u32 f0, f1;
10487
10488- asm("pushfl ; "
10489+ asm volatile("pushfl ; "
10490 "pushfl ; "
10491 "popl %0 ; "
10492 "movl %0,%1 ; "
10493@@ -115,7 +115,7 @@ static void get_flags(void)
10494 set_bit(X86_FEATURE_FPU, cpu.flags);
10495
10496 if (has_eflag(X86_EFLAGS_ID)) {
10497- asm("cpuid"
10498+ asm volatile("cpuid"
10499 : "=a" (max_intel_level),
10500 "=b" (cpu_vendor[0]),
10501 "=d" (cpu_vendor[1]),
10502@@ -124,7 +124,7 @@ static void get_flags(void)
10503
10504 if (max_intel_level >= 0x00000001 &&
10505 max_intel_level <= 0x0000ffff) {
10506- asm("cpuid"
10507+ asm volatile("cpuid"
10508 : "=a" (tfms),
10509 "=c" (cpu.flags[4]),
10510 "=d" (cpu.flags[0])
10511@@ -136,7 +136,7 @@ static void get_flags(void)
10512 cpu.model += ((tfms >> 16) & 0xf) << 4;
10513 }
10514
10515- asm("cpuid"
10516+ asm volatile("cpuid"
10517 : "=a" (max_amd_level)
10518 : "a" (0x80000000)
10519 : "ebx", "ecx", "edx");
10520@@ -144,7 +144,7 @@ static void get_flags(void)
10521 if (max_amd_level >= 0x80000001 &&
10522 max_amd_level <= 0x8000ffff) {
10523 u32 eax = 0x80000001;
10524- asm("cpuid"
10525+ asm volatile("cpuid"
10526 : "+a" (eax),
10527 "=c" (cpu.flags[6]),
10528 "=d" (cpu.flags[1])
10529@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10530 u32 ecx = MSR_K7_HWCR;
10531 u32 eax, edx;
10532
10533- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10534+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10535 eax &= ~(1 << 15);
10536- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10537+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10538
10539 get_flags(); /* Make sure it really did something */
10540 err = check_flags();
10541@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10542 u32 ecx = MSR_VIA_FCR;
10543 u32 eax, edx;
10544
10545- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10546+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10547 eax |= (1<<1)|(1<<7);
10548- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10549+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10550
10551 set_bit(X86_FEATURE_CX8, cpu.flags);
10552 err = check_flags();
10553@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10554 u32 eax, edx;
10555 u32 level = 1;
10556
10557- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10558- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10559- asm("cpuid"
10560+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10561+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10562+ asm volatile("cpuid"
10563 : "+a" (level), "=d" (cpu.flags[0])
10564 : : "ecx", "ebx");
10565- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10566+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10567
10568 err = check_flags();
10569 }
10570diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10571index 944ce59..87ee37a 100644
10572--- a/arch/x86/boot/header.S
10573+++ b/arch/x86/boot/header.S
10574@@ -401,10 +401,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10575 # single linked list of
10576 # struct setup_data
10577
10578-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10579+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10580
10581 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10582+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10583+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10584+#else
10585 #define VO_INIT_SIZE (VO__end - VO__text)
10586+#endif
10587 #if ZO_INIT_SIZE > VO_INIT_SIZE
10588 #define INIT_SIZE ZO_INIT_SIZE
10589 #else
10590diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10591index db75d07..8e6d0af 100644
10592--- a/arch/x86/boot/memory.c
10593+++ b/arch/x86/boot/memory.c
10594@@ -19,7 +19,7 @@
10595
10596 static int detect_memory_e820(void)
10597 {
10598- int count = 0;
10599+ unsigned int count = 0;
10600 struct biosregs ireg, oreg;
10601 struct e820entry *desc = boot_params.e820_map;
10602 static struct e820entry buf; /* static so it is zeroed */
10603diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10604index 11e8c6e..fdbb1ed 100644
10605--- a/arch/x86/boot/video-vesa.c
10606+++ b/arch/x86/boot/video-vesa.c
10607@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10608
10609 boot_params.screen_info.vesapm_seg = oreg.es;
10610 boot_params.screen_info.vesapm_off = oreg.di;
10611+ boot_params.screen_info.vesapm_size = oreg.cx;
10612 }
10613
10614 /*
10615diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10616index 43eda28..5ab5fdb 100644
10617--- a/arch/x86/boot/video.c
10618+++ b/arch/x86/boot/video.c
10619@@ -96,7 +96,7 @@ static void store_mode_params(void)
10620 static unsigned int get_entry(void)
10621 {
10622 char entry_buf[4];
10623- int i, len = 0;
10624+ unsigned int i, len = 0;
10625 int key;
10626 unsigned int v;
10627
10628diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10629index 5b577d5..3c1fed4 100644
10630--- a/arch/x86/crypto/aes-x86_64-asm_64.S
10631+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10632@@ -8,6 +8,8 @@
10633 * including this sentence is retained in full.
10634 */
10635
10636+#include <asm/alternative-asm.h>
10637+
10638 .extern crypto_ft_tab
10639 .extern crypto_it_tab
10640 .extern crypto_fl_tab
10641@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
10642 je B192; \
10643 leaq 32(r9),r9;
10644
10645+#define ret pax_force_retaddr 0, 1; ret
10646+
10647 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10648 movq r1,r2; \
10649 movq r3,r4; \
10650diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10651index 3470624..201259d 100644
10652--- a/arch/x86/crypto/aesni-intel_asm.S
10653+++ b/arch/x86/crypto/aesni-intel_asm.S
10654@@ -31,6 +31,7 @@
10655
10656 #include <linux/linkage.h>
10657 #include <asm/inst.h>
10658+#include <asm/alternative-asm.h>
10659
10660 #ifdef __x86_64__
10661 .data
10662@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
10663 pop %r14
10664 pop %r13
10665 pop %r12
10666+ pax_force_retaddr 0, 1
10667 ret
10668+ENDPROC(aesni_gcm_dec)
10669
10670
10671 /*****************************************************************************
10672@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
10673 pop %r14
10674 pop %r13
10675 pop %r12
10676+ pax_force_retaddr 0, 1
10677 ret
10678+ENDPROC(aesni_gcm_enc)
10679
10680 #endif
10681
10682@@ -1714,6 +1719,7 @@ _key_expansion_256a:
10683 pxor %xmm1, %xmm0
10684 movaps %xmm0, (TKEYP)
10685 add $0x10, TKEYP
10686+ pax_force_retaddr_bts
10687 ret
10688
10689 .align 4
10690@@ -1738,6 +1744,7 @@ _key_expansion_192a:
10691 shufps $0b01001110, %xmm2, %xmm1
10692 movaps %xmm1, 0x10(TKEYP)
10693 add $0x20, TKEYP
10694+ pax_force_retaddr_bts
10695 ret
10696
10697 .align 4
10698@@ -1757,6 +1764,7 @@ _key_expansion_192b:
10699
10700 movaps %xmm0, (TKEYP)
10701 add $0x10, TKEYP
10702+ pax_force_retaddr_bts
10703 ret
10704
10705 .align 4
10706@@ -1769,6 +1777,7 @@ _key_expansion_256b:
10707 pxor %xmm1, %xmm2
10708 movaps %xmm2, (TKEYP)
10709 add $0x10, TKEYP
10710+ pax_force_retaddr_bts
10711 ret
10712
10713 /*
10714@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
10715 #ifndef __x86_64__
10716 popl KEYP
10717 #endif
10718+ pax_force_retaddr 0, 1
10719 ret
10720+ENDPROC(aesni_set_key)
10721
10722 /*
10723 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
10724@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
10725 popl KLEN
10726 popl KEYP
10727 #endif
10728+ pax_force_retaddr 0, 1
10729 ret
10730+ENDPROC(aesni_enc)
10731
10732 /*
10733 * _aesni_enc1: internal ABI
10734@@ -1959,6 +1972,7 @@ _aesni_enc1:
10735 AESENC KEY STATE
10736 movaps 0x70(TKEYP), KEY
10737 AESENCLAST KEY STATE
10738+ pax_force_retaddr_bts
10739 ret
10740
10741 /*
10742@@ -2067,6 +2081,7 @@ _aesni_enc4:
10743 AESENCLAST KEY STATE2
10744 AESENCLAST KEY STATE3
10745 AESENCLAST KEY STATE4
10746+ pax_force_retaddr_bts
10747 ret
10748
10749 /*
10750@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
10751 popl KLEN
10752 popl KEYP
10753 #endif
10754+ pax_force_retaddr 0, 1
10755 ret
10756+ENDPROC(aesni_dec)
10757
10758 /*
10759 * _aesni_dec1: internal ABI
10760@@ -2146,6 +2163,7 @@ _aesni_dec1:
10761 AESDEC KEY STATE
10762 movaps 0x70(TKEYP), KEY
10763 AESDECLAST KEY STATE
10764+ pax_force_retaddr_bts
10765 ret
10766
10767 /*
10768@@ -2254,6 +2272,7 @@ _aesni_dec4:
10769 AESDECLAST KEY STATE2
10770 AESDECLAST KEY STATE3
10771 AESDECLAST KEY STATE4
10772+ pax_force_retaddr_bts
10773 ret
10774
10775 /*
10776@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
10777 popl KEYP
10778 popl LEN
10779 #endif
10780+ pax_force_retaddr 0, 1
10781 ret
10782+ENDPROC(aesni_ecb_enc)
10783
10784 /*
10785 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10786@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
10787 popl KEYP
10788 popl LEN
10789 #endif
10790+ pax_force_retaddr 0, 1
10791 ret
10792+ENDPROC(aesni_ecb_dec)
10793
10794 /*
10795 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10796@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
10797 popl LEN
10798 popl IVP
10799 #endif
10800+ pax_force_retaddr 0, 1
10801 ret
10802+ENDPROC(aesni_cbc_enc)
10803
10804 /*
10805 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10806@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
10807 popl LEN
10808 popl IVP
10809 #endif
10810+ pax_force_retaddr 0, 1
10811 ret
10812+ENDPROC(aesni_cbc_dec)
10813
10814 #ifdef __x86_64__
10815 .align 16
10816@@ -2526,6 +2553,7 @@ _aesni_inc_init:
10817 mov $1, TCTR_LOW
10818 MOVQ_R64_XMM TCTR_LOW INC
10819 MOVQ_R64_XMM CTR TCTR_LOW
10820+ pax_force_retaddr_bts
10821 ret
10822
10823 /*
10824@@ -2554,6 +2582,7 @@ _aesni_inc:
10825 .Linc_low:
10826 movaps CTR, IV
10827 PSHUFB_XMM BSWAP_MASK IV
10828+ pax_force_retaddr_bts
10829 ret
10830
10831 /*
10832@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
10833 .Lctr_enc_ret:
10834 movups IV, (IVP)
10835 .Lctr_enc_just_ret:
10836+ pax_force_retaddr 0, 1
10837 ret
10838+ENDPROC(aesni_ctr_enc)
10839 #endif
10840diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10841index 391d245..67f35c2 100644
10842--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10843+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10844@@ -20,6 +20,8 @@
10845 *
10846 */
10847
10848+#include <asm/alternative-asm.h>
10849+
10850 .file "blowfish-x86_64-asm.S"
10851 .text
10852
10853@@ -151,9 +153,11 @@ __blowfish_enc_blk:
10854 jnz __enc_xor;
10855
10856 write_block();
10857+ pax_force_retaddr 0, 1
10858 ret;
10859 __enc_xor:
10860 xor_block();
10861+ pax_force_retaddr 0, 1
10862 ret;
10863
10864 .align 8
10865@@ -188,6 +192,7 @@ blowfish_dec_blk:
10866
10867 movq %r11, %rbp;
10868
10869+ pax_force_retaddr 0, 1
10870 ret;
10871
10872 /**********************************************************************
10873@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
10874
10875 popq %rbx;
10876 popq %rbp;
10877+ pax_force_retaddr 0, 1
10878 ret;
10879
10880 __enc_xor4:
10881@@ -349,6 +355,7 @@ __enc_xor4:
10882
10883 popq %rbx;
10884 popq %rbp;
10885+ pax_force_retaddr 0, 1
10886 ret;
10887
10888 .align 8
10889@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
10890 popq %rbx;
10891 popq %rbp;
10892
10893+ pax_force_retaddr 0, 1
10894 ret;
10895
10896diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
10897index 0b33743..7a56206 100644
10898--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
10899+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
10900@@ -20,6 +20,8 @@
10901 *
10902 */
10903
10904+#include <asm/alternative-asm.h>
10905+
10906 .file "camellia-x86_64-asm_64.S"
10907 .text
10908
10909@@ -229,12 +231,14 @@ __enc_done:
10910 enc_outunpack(mov, RT1);
10911
10912 movq RRBP, %rbp;
10913+ pax_force_retaddr 0, 1
10914 ret;
10915
10916 __enc_xor:
10917 enc_outunpack(xor, RT1);
10918
10919 movq RRBP, %rbp;
10920+ pax_force_retaddr 0, 1
10921 ret;
10922
10923 .global camellia_dec_blk;
10924@@ -275,6 +279,7 @@ __dec_rounds16:
10925 dec_outunpack();
10926
10927 movq RRBP, %rbp;
10928+ pax_force_retaddr 0, 1
10929 ret;
10930
10931 /**********************************************************************
10932@@ -468,6 +473,7 @@ __enc2_done:
10933
10934 movq RRBP, %rbp;
10935 popq %rbx;
10936+ pax_force_retaddr 0, 1
10937 ret;
10938
10939 __enc2_xor:
10940@@ -475,6 +481,7 @@ __enc2_xor:
10941
10942 movq RRBP, %rbp;
10943 popq %rbx;
10944+ pax_force_retaddr 0, 1
10945 ret;
10946
10947 .global camellia_dec_blk_2way;
10948@@ -517,4 +524,5 @@ __dec2_rounds16:
10949
10950 movq RRBP, %rbp;
10951 movq RXOR, %rbx;
10952+ pax_force_retaddr 0, 1
10953 ret;
10954diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10955index 15b00ac..2071784 100644
10956--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10957+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10958@@ -23,6 +23,8 @@
10959 *
10960 */
10961
10962+#include <asm/alternative-asm.h>
10963+
10964 .file "cast5-avx-x86_64-asm_64.S"
10965
10966 .extern cast_s1
10967@@ -281,6 +283,7 @@ __skip_enc:
10968 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10969 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10970
10971+ pax_force_retaddr 0, 1
10972 ret;
10973
10974 .align 16
10975@@ -353,6 +356,7 @@ __dec_tail:
10976 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10977 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10978
10979+ pax_force_retaddr 0, 1
10980 ret;
10981
10982 __skip_dec:
10983@@ -392,6 +396,7 @@ cast5_ecb_enc_16way:
10984 vmovdqu RR4, (6*4*4)(%r11);
10985 vmovdqu RL4, (7*4*4)(%r11);
10986
10987+ pax_force_retaddr
10988 ret;
10989
10990 .align 16
10991@@ -427,6 +432,7 @@ cast5_ecb_dec_16way:
10992 vmovdqu RR4, (6*4*4)(%r11);
10993 vmovdqu RL4, (7*4*4)(%r11);
10994
10995+ pax_force_retaddr
10996 ret;
10997
10998 .align 16
10999@@ -479,6 +485,7 @@ cast5_cbc_dec_16way:
11000
11001 popq %r12;
11002
11003+ pax_force_retaddr
11004 ret;
11005
11006 .align 16
11007@@ -555,4 +562,5 @@ cast5_ctr_16way:
11008
11009 popq %r12;
11010
11011+ pax_force_retaddr
11012 ret;
11013diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11014index 2569d0d..637c289 100644
11015--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11016+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11017@@ -23,6 +23,8 @@
11018 *
11019 */
11020
11021+#include <asm/alternative-asm.h>
11022+
11023 #include "glue_helper-asm-avx.S"
11024
11025 .file "cast6-avx-x86_64-asm_64.S"
11026@@ -294,6 +296,7 @@ __cast6_enc_blk8:
11027 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11028 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11029
11030+ pax_force_retaddr 0, 1
11031 ret;
11032
11033 .align 8
11034@@ -340,6 +343,7 @@ __cast6_dec_blk8:
11035 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11036 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11037
11038+ pax_force_retaddr 0, 1
11039 ret;
11040
11041 .align 8
11042@@ -361,6 +365,7 @@ cast6_ecb_enc_8way:
11043
11044 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11045
11046+ pax_force_retaddr
11047 ret;
11048
11049 .align 8
11050@@ -382,6 +387,7 @@ cast6_ecb_dec_8way:
11051
11052 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11053
11054+ pax_force_retaddr
11055 ret;
11056
11057 .align 8
11058@@ -408,6 +414,7 @@ cast6_cbc_dec_8way:
11059
11060 popq %r12;
11061
11062+ pax_force_retaddr
11063 ret;
11064
11065 .align 8
11066@@ -436,4 +443,5 @@ cast6_ctr_8way:
11067
11068 popq %r12;
11069
11070+ pax_force_retaddr
11071 ret;
11072diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11073index 6214a9b..1f4fc9a 100644
11074--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
11075+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11076@@ -1,3 +1,5 @@
11077+#include <asm/alternative-asm.h>
11078+
11079 # enter ECRYPT_encrypt_bytes
11080 .text
11081 .p2align 5
11082@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
11083 add %r11,%rsp
11084 mov %rdi,%rax
11085 mov %rsi,%rdx
11086+ pax_force_retaddr 0, 1
11087 ret
11088 # bytesatleast65:
11089 ._bytesatleast65:
11090@@ -891,6 +894,7 @@ ECRYPT_keysetup:
11091 add %r11,%rsp
11092 mov %rdi,%rax
11093 mov %rsi,%rdx
11094+ pax_force_retaddr
11095 ret
11096 # enter ECRYPT_ivsetup
11097 .text
11098@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
11099 add %r11,%rsp
11100 mov %rdi,%rax
11101 mov %rsi,%rdx
11102+ pax_force_retaddr
11103 ret
11104diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11105index 02b0e9f..cf4cf5c 100644
11106--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11107+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11108@@ -24,6 +24,8 @@
11109 *
11110 */
11111
11112+#include <asm/alternative-asm.h>
11113+
11114 #include "glue_helper-asm-avx.S"
11115
11116 .file "serpent-avx-x86_64-asm_64.S"
11117@@ -618,6 +620,7 @@ __serpent_enc_blk8_avx:
11118 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11119 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11120
11121+ pax_force_retaddr
11122 ret;
11123
11124 .align 8
11125@@ -673,6 +676,7 @@ __serpent_dec_blk8_avx:
11126 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11127 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11128
11129+ pax_force_retaddr
11130 ret;
11131
11132 .align 8
11133@@ -692,6 +696,7 @@ serpent_ecb_enc_8way_avx:
11134
11135 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11136
11137+ pax_force_retaddr
11138 ret;
11139
11140 .align 8
11141@@ -711,6 +716,7 @@ serpent_ecb_dec_8way_avx:
11142
11143 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11144
11145+ pax_force_retaddr
11146 ret;
11147
11148 .align 8
11149@@ -730,6 +736,7 @@ serpent_cbc_dec_8way_avx:
11150
11151 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11152
11153+ pax_force_retaddr
11154 ret;
11155
11156 .align 8
11157@@ -751,4 +758,5 @@ serpent_ctr_8way_avx:
11158
11159 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11160
11161+ pax_force_retaddr
11162 ret;
11163diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11164index 3ee1ff0..cbc568b 100644
11165--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11166+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11167@@ -24,6 +24,8 @@
11168 *
11169 */
11170
11171+#include <asm/alternative-asm.h>
11172+
11173 .file "serpent-sse2-x86_64-asm_64.S"
11174 .text
11175
11176@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
11177 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11178 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11179
11180+ pax_force_retaddr
11181 ret;
11182
11183 __enc_xor8:
11184 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11185 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11186
11187+ pax_force_retaddr
11188 ret;
11189
11190 .align 8
11191@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
11192 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11193 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11194
11195+ pax_force_retaddr
11196 ret;
11197diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
11198index 49d6987..df66bd4 100644
11199--- a/arch/x86/crypto/sha1_ssse3_asm.S
11200+++ b/arch/x86/crypto/sha1_ssse3_asm.S
11201@@ -28,6 +28,8 @@
11202 * (at your option) any later version.
11203 */
11204
11205+#include <asm/alternative-asm.h>
11206+
11207 #define CTX %rdi // arg1
11208 #define BUF %rsi // arg2
11209 #define CNT %rdx // arg3
11210@@ -104,6 +106,7 @@
11211 pop %r12
11212 pop %rbp
11213 pop %rbx
11214+ pax_force_retaddr 0, 1
11215 ret
11216
11217 .size \name, .-\name
11218diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11219index ebac16b..8092eb9 100644
11220--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11221+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11222@@ -23,6 +23,8 @@
11223 *
11224 */
11225
11226+#include <asm/alternative-asm.h>
11227+
11228 #include "glue_helper-asm-avx.S"
11229
11230 .file "twofish-avx-x86_64-asm_64.S"
11231@@ -283,6 +285,7 @@ __twofish_enc_blk8:
11232 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
11233 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
11234
11235+ pax_force_retaddr 0, 1
11236 ret;
11237
11238 .align 8
11239@@ -324,6 +327,7 @@ __twofish_dec_blk8:
11240 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
11241 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
11242
11243+ pax_force_retaddr 0, 1
11244 ret;
11245
11246 .align 8
11247@@ -345,6 +349,7 @@ twofish_ecb_enc_8way:
11248
11249 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11250
11251+ pax_force_retaddr 0, 1
11252 ret;
11253
11254 .align 8
11255@@ -366,6 +371,7 @@ twofish_ecb_dec_8way:
11256
11257 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11258
11259+ pax_force_retaddr 0, 1
11260 ret;
11261
11262 .align 8
11263@@ -392,6 +398,7 @@ twofish_cbc_dec_8way:
11264
11265 popq %r12;
11266
11267+ pax_force_retaddr 0, 1
11268 ret;
11269
11270 .align 8
11271@@ -420,4 +427,5 @@ twofish_ctr_8way:
11272
11273 popq %r12;
11274
11275+ pax_force_retaddr 0, 1
11276 ret;
11277diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11278index 5b012a2..36d5364 100644
11279--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11280+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11281@@ -20,6 +20,8 @@
11282 *
11283 */
11284
11285+#include <asm/alternative-asm.h>
11286+
11287 .file "twofish-x86_64-asm-3way.S"
11288 .text
11289
11290@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
11291 popq %r13;
11292 popq %r14;
11293 popq %r15;
11294+ pax_force_retaddr 0, 1
11295 ret;
11296
11297 __enc_xor3:
11298@@ -271,6 +274,7 @@ __enc_xor3:
11299 popq %r13;
11300 popq %r14;
11301 popq %r15;
11302+ pax_force_retaddr 0, 1
11303 ret;
11304
11305 .global twofish_dec_blk_3way
11306@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
11307 popq %r13;
11308 popq %r14;
11309 popq %r15;
11310+ pax_force_retaddr 0, 1
11311 ret;
11312
11313diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11314index 7bcf3fc..f53832f 100644
11315--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11316+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11317@@ -21,6 +21,7 @@
11318 .text
11319
11320 #include <asm/asm-offsets.h>
11321+#include <asm/alternative-asm.h>
11322
11323 #define a_offset 0
11324 #define b_offset 4
11325@@ -268,6 +269,7 @@ twofish_enc_blk:
11326
11327 popq R1
11328 movq $1,%rax
11329+ pax_force_retaddr 0, 1
11330 ret
11331
11332 twofish_dec_blk:
11333@@ -319,4 +321,5 @@ twofish_dec_blk:
11334
11335 popq R1
11336 movq $1,%rax
11337+ pax_force_retaddr 0, 1
11338 ret
11339diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11340index a703af1..f5b9c36 100644
11341--- a/arch/x86/ia32/ia32_aout.c
11342+++ b/arch/x86/ia32/ia32_aout.c
11343@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11344 unsigned long dump_start, dump_size;
11345 struct user32 dump;
11346
11347+ memset(&dump, 0, sizeof(dump));
11348+
11349 fs = get_fs();
11350 set_fs(KERNEL_DS);
11351 has_dumped = 1;
11352diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11353index a1daf4a..f8c4537 100644
11354--- a/arch/x86/ia32/ia32_signal.c
11355+++ b/arch/x86/ia32/ia32_signal.c
11356@@ -348,7 +348,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
11357 sp -= frame_size;
11358 /* Align the stack pointer according to the i386 ABI,
11359 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11360- sp = ((sp + 4) & -16ul) - 4;
11361+ sp = ((sp - 12) & -16ul) - 4;
11362 return (void __user *) sp;
11363 }
11364
11365@@ -406,7 +406,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
11366 * These are actually not used anymore, but left because some
11367 * gdb versions depend on them as a marker.
11368 */
11369- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11370+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11371 } put_user_catch(err);
11372
11373 if (err)
11374@@ -448,7 +448,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11375 0xb8,
11376 __NR_ia32_rt_sigreturn,
11377 0x80cd,
11378- 0,
11379+ 0
11380 };
11381
11382 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
11383@@ -471,16 +471,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11384
11385 if (ka->sa.sa_flags & SA_RESTORER)
11386 restorer = ka->sa.sa_restorer;
11387+ else if (current->mm->context.vdso)
11388+ /* Return stub is in 32bit vsyscall page */
11389+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11390 else
11391- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11392- rt_sigreturn);
11393+ restorer = &frame->retcode;
11394 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11395
11396 /*
11397 * Not actually used anymore, but left because some gdb
11398 * versions need it.
11399 */
11400- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11401+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11402 } put_user_catch(err);
11403
11404 err |= copy_siginfo_to_user32(&frame->info, info);
11405diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11406index 142c4ce..19b683f 100644
11407--- a/arch/x86/ia32/ia32entry.S
11408+++ b/arch/x86/ia32/ia32entry.S
11409@@ -15,8 +15,10 @@
11410 #include <asm/irqflags.h>
11411 #include <asm/asm.h>
11412 #include <asm/smap.h>
11413+#include <asm/pgtable.h>
11414 #include <linux/linkage.h>
11415 #include <linux/err.h>
11416+#include <asm/alternative-asm.h>
11417
11418 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11419 #include <linux/elf-em.h>
11420@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11421 ENDPROC(native_irq_enable_sysexit)
11422 #endif
11423
11424+ .macro pax_enter_kernel_user
11425+ pax_set_fptr_mask
11426+#ifdef CONFIG_PAX_MEMORY_UDEREF
11427+ call pax_enter_kernel_user
11428+#endif
11429+ .endm
11430+
11431+ .macro pax_exit_kernel_user
11432+#ifdef CONFIG_PAX_MEMORY_UDEREF
11433+ call pax_exit_kernel_user
11434+#endif
11435+#ifdef CONFIG_PAX_RANDKSTACK
11436+ pushq %rax
11437+ pushq %r11
11438+ call pax_randomize_kstack
11439+ popq %r11
11440+ popq %rax
11441+#endif
11442+ .endm
11443+
11444+.macro pax_erase_kstack
11445+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11446+ call pax_erase_kstack
11447+#endif
11448+.endm
11449+
11450 /*
11451 * 32bit SYSENTER instruction entry.
11452 *
11453@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11454 CFI_REGISTER rsp,rbp
11455 SWAPGS_UNSAFE_STACK
11456 movq PER_CPU_VAR(kernel_stack), %rsp
11457- addq $(KERNEL_STACK_OFFSET),%rsp
11458- /*
11459- * No need to follow this irqs on/off section: the syscall
11460- * disabled irqs, here we enable it straight after entry:
11461- */
11462- ENABLE_INTERRUPTS(CLBR_NONE)
11463 movl %ebp,%ebp /* zero extension */
11464 pushq_cfi $__USER32_DS
11465 /*CFI_REL_OFFSET ss,0*/
11466@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11467 CFI_REL_OFFSET rsp,0
11468 pushfq_cfi
11469 /*CFI_REL_OFFSET rflags,0*/
11470- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11471- CFI_REGISTER rip,r10
11472+ orl $X86_EFLAGS_IF,(%rsp)
11473+ GET_THREAD_INFO(%r11)
11474+ movl TI_sysenter_return(%r11), %r11d
11475+ CFI_REGISTER rip,r11
11476 pushq_cfi $__USER32_CS
11477 /*CFI_REL_OFFSET cs,0*/
11478 movl %eax, %eax
11479- pushq_cfi %r10
11480+ pushq_cfi %r11
11481 CFI_REL_OFFSET rip,0
11482 pushq_cfi %rax
11483 cld
11484 SAVE_ARGS 0,1,0
11485+ pax_enter_kernel_user
11486+
11487+#ifdef CONFIG_PAX_RANDKSTACK
11488+ pax_erase_kstack
11489+#endif
11490+
11491+ /*
11492+ * No need to follow this irqs on/off section: the syscall
11493+ * disabled irqs, here we enable it straight after entry:
11494+ */
11495+ ENABLE_INTERRUPTS(CLBR_NONE)
11496 /* no need to do an access_ok check here because rbp has been
11497 32bit zero extended */
11498+
11499+#ifdef CONFIG_PAX_MEMORY_UDEREF
11500+ mov $PAX_USER_SHADOW_BASE,%r11
11501+ add %r11,%rbp
11502+#endif
11503+
11504 ASM_STAC
11505 1: movl (%rbp),%ebp
11506 _ASM_EXTABLE(1b,ia32_badarg)
11507 ASM_CLAC
11508- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11509- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11510+ GET_THREAD_INFO(%r11)
11511+ orl $TS_COMPAT,TI_status(%r11)
11512+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11513 CFI_REMEMBER_STATE
11514 jnz sysenter_tracesys
11515 cmpq $(IA32_NR_syscalls-1),%rax
11516@@ -162,12 +204,15 @@ sysenter_do_call:
11517 sysenter_dispatch:
11518 call *ia32_sys_call_table(,%rax,8)
11519 movq %rax,RAX-ARGOFFSET(%rsp)
11520+ GET_THREAD_INFO(%r11)
11521 DISABLE_INTERRUPTS(CLBR_NONE)
11522 TRACE_IRQS_OFF
11523- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11524+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11525 jnz sysexit_audit
11526 sysexit_from_sys_call:
11527- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11528+ pax_exit_kernel_user
11529+ pax_erase_kstack
11530+ andl $~TS_COMPAT,TI_status(%r11)
11531 /* clear IF, that popfq doesn't enable interrupts early */
11532 andl $~0x200,EFLAGS-R11(%rsp)
11533 movl RIP-R11(%rsp),%edx /* User %eip */
11534@@ -193,6 +238,9 @@ sysexit_from_sys_call:
11535 movl %eax,%esi /* 2nd arg: syscall number */
11536 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11537 call __audit_syscall_entry
11538+
11539+ pax_erase_kstack
11540+
11541 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11542 cmpq $(IA32_NR_syscalls-1),%rax
11543 ja ia32_badsys
11544@@ -204,7 +252,7 @@ sysexit_from_sys_call:
11545 .endm
11546
11547 .macro auditsys_exit exit
11548- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11549+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11550 jnz ia32_ret_from_sys_call
11551 TRACE_IRQS_ON
11552 ENABLE_INTERRUPTS(CLBR_NONE)
11553@@ -215,11 +263,12 @@ sysexit_from_sys_call:
11554 1: setbe %al /* 1 if error, 0 if not */
11555 movzbl %al,%edi /* zero-extend that into %edi */
11556 call __audit_syscall_exit
11557+ GET_THREAD_INFO(%r11)
11558 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11559 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11560 DISABLE_INTERRUPTS(CLBR_NONE)
11561 TRACE_IRQS_OFF
11562- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11563+ testl %edi,TI_flags(%r11)
11564 jz \exit
11565 CLEAR_RREGS -ARGOFFSET
11566 jmp int_with_check
11567@@ -237,7 +286,7 @@ sysexit_audit:
11568
11569 sysenter_tracesys:
11570 #ifdef CONFIG_AUDITSYSCALL
11571- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11572+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11573 jz sysenter_auditsys
11574 #endif
11575 SAVE_REST
11576@@ -249,6 +298,9 @@ sysenter_tracesys:
11577 RESTORE_REST
11578 cmpq $(IA32_NR_syscalls-1),%rax
11579 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11580+
11581+ pax_erase_kstack
11582+
11583 jmp sysenter_do_call
11584 CFI_ENDPROC
11585 ENDPROC(ia32_sysenter_target)
11586@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11587 ENTRY(ia32_cstar_target)
11588 CFI_STARTPROC32 simple
11589 CFI_SIGNAL_FRAME
11590- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11591+ CFI_DEF_CFA rsp,0
11592 CFI_REGISTER rip,rcx
11593 /*CFI_REGISTER rflags,r11*/
11594 SWAPGS_UNSAFE_STACK
11595 movl %esp,%r8d
11596 CFI_REGISTER rsp,r8
11597 movq PER_CPU_VAR(kernel_stack),%rsp
11598+ SAVE_ARGS 8*6,0,0
11599+ pax_enter_kernel_user
11600+
11601+#ifdef CONFIG_PAX_RANDKSTACK
11602+ pax_erase_kstack
11603+#endif
11604+
11605 /*
11606 * No need to follow this irqs on/off section: the syscall
11607 * disabled irqs and here we enable it straight after entry:
11608 */
11609 ENABLE_INTERRUPTS(CLBR_NONE)
11610- SAVE_ARGS 8,0,0
11611 movl %eax,%eax /* zero extension */
11612 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11613 movq %rcx,RIP-ARGOFFSET(%rsp)
11614@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11615 /* no need to do an access_ok check here because r8 has been
11616 32bit zero extended */
11617 /* hardware stack frame is complete now */
11618+
11619+#ifdef CONFIG_PAX_MEMORY_UDEREF
11620+ mov $PAX_USER_SHADOW_BASE,%r11
11621+ add %r11,%r8
11622+#endif
11623+
11624 ASM_STAC
11625 1: movl (%r8),%r9d
11626 _ASM_EXTABLE(1b,ia32_badarg)
11627 ASM_CLAC
11628- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11629- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11630+ GET_THREAD_INFO(%r11)
11631+ orl $TS_COMPAT,TI_status(%r11)
11632+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11633 CFI_REMEMBER_STATE
11634 jnz cstar_tracesys
11635 cmpq $IA32_NR_syscalls-1,%rax
11636@@ -319,12 +384,15 @@ cstar_do_call:
11637 cstar_dispatch:
11638 call *ia32_sys_call_table(,%rax,8)
11639 movq %rax,RAX-ARGOFFSET(%rsp)
11640+ GET_THREAD_INFO(%r11)
11641 DISABLE_INTERRUPTS(CLBR_NONE)
11642 TRACE_IRQS_OFF
11643- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11644+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11645 jnz sysretl_audit
11646 sysretl_from_sys_call:
11647- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11648+ pax_exit_kernel_user
11649+ pax_erase_kstack
11650+ andl $~TS_COMPAT,TI_status(%r11)
11651 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11652 movl RIP-ARGOFFSET(%rsp),%ecx
11653 CFI_REGISTER rip,rcx
11654@@ -352,7 +420,7 @@ sysretl_audit:
11655
11656 cstar_tracesys:
11657 #ifdef CONFIG_AUDITSYSCALL
11658- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11659+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11660 jz cstar_auditsys
11661 #endif
11662 xchgl %r9d,%ebp
11663@@ -366,6 +434,9 @@ cstar_tracesys:
11664 xchgl %ebp,%r9d
11665 cmpq $(IA32_NR_syscalls-1),%rax
11666 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11667+
11668+ pax_erase_kstack
11669+
11670 jmp cstar_do_call
11671 END(ia32_cstar_target)
11672
11673@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11674 CFI_REL_OFFSET rip,RIP-RIP
11675 PARAVIRT_ADJUST_EXCEPTION_FRAME
11676 SWAPGS
11677- /*
11678- * No need to follow this irqs on/off section: the syscall
11679- * disabled irqs and here we enable it straight after entry:
11680- */
11681- ENABLE_INTERRUPTS(CLBR_NONE)
11682 movl %eax,%eax
11683 pushq_cfi %rax
11684 cld
11685 /* note the registers are not zero extended to the sf.
11686 this could be a problem. */
11687 SAVE_ARGS 0,1,0
11688- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11689- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11690+ pax_enter_kernel_user
11691+
11692+#ifdef CONFIG_PAX_RANDKSTACK
11693+ pax_erase_kstack
11694+#endif
11695+
11696+ /*
11697+ * No need to follow this irqs on/off section: the syscall
11698+ * disabled irqs and here we enable it straight after entry:
11699+ */
11700+ ENABLE_INTERRUPTS(CLBR_NONE)
11701+ GET_THREAD_INFO(%r11)
11702+ orl $TS_COMPAT,TI_status(%r11)
11703+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11704 jnz ia32_tracesys
11705 cmpq $(IA32_NR_syscalls-1),%rax
11706 ja ia32_badsys
11707@@ -442,6 +520,9 @@ ia32_tracesys:
11708 RESTORE_REST
11709 cmpq $(IA32_NR_syscalls-1),%rax
11710 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11711+
11712+ pax_erase_kstack
11713+
11714 jmp ia32_do_call
11715 END(ia32_syscall)
11716
11717diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11718index d0b689b..6811ddc 100644
11719--- a/arch/x86/ia32/sys_ia32.c
11720+++ b/arch/x86/ia32/sys_ia32.c
11721@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11722 */
11723 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11724 {
11725- typeof(ubuf->st_uid) uid = 0;
11726- typeof(ubuf->st_gid) gid = 0;
11727+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
11728+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
11729 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11730 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11731 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11732@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
11733 mm_segment_t old_fs = get_fs();
11734
11735 set_fs(KERNEL_DS);
11736- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
11737+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
11738 set_fs(old_fs);
11739 if (put_compat_timespec(&t, interval))
11740 return -EFAULT;
11741@@ -313,13 +313,13 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
11742 asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
11743 compat_size_t sigsetsize)
11744 {
11745- sigset_t s;
11746+ sigset_t s = { };
11747 compat_sigset_t s32;
11748 int ret;
11749 mm_segment_t old_fs = get_fs();
11750
11751 set_fs(KERNEL_DS);
11752- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
11753+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
11754 set_fs(old_fs);
11755 if (!ret) {
11756 switch (_NSIG_WORDS) {
11757@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
11758 if (copy_siginfo_from_user32(&info, uinfo))
11759 return -EFAULT;
11760 set_fs(KERNEL_DS);
11761- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
11762+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
11763 set_fs(old_fs);
11764 return ret;
11765 }
11766@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
11767 return -EFAULT;
11768
11769 set_fs(KERNEL_DS);
11770- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
11771+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
11772 count);
11773 set_fs(old_fs);
11774
11775diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11776index 372231c..a5aa1a1 100644
11777--- a/arch/x86/include/asm/alternative-asm.h
11778+++ b/arch/x86/include/asm/alternative-asm.h
11779@@ -18,6 +18,45 @@
11780 .endm
11781 #endif
11782
11783+#ifdef KERNEXEC_PLUGIN
11784+ .macro pax_force_retaddr_bts rip=0
11785+ btsq $63,\rip(%rsp)
11786+ .endm
11787+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11788+ .macro pax_force_retaddr rip=0, reload=0
11789+ btsq $63,\rip(%rsp)
11790+ .endm
11791+ .macro pax_force_fptr ptr
11792+ btsq $63,\ptr
11793+ .endm
11794+ .macro pax_set_fptr_mask
11795+ .endm
11796+#endif
11797+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11798+ .macro pax_force_retaddr rip=0, reload=0
11799+ .if \reload
11800+ pax_set_fptr_mask
11801+ .endif
11802+ orq %r10,\rip(%rsp)
11803+ .endm
11804+ .macro pax_force_fptr ptr
11805+ orq %r10,\ptr
11806+ .endm
11807+ .macro pax_set_fptr_mask
11808+ movabs $0x8000000000000000,%r10
11809+ .endm
11810+#endif
11811+#else
11812+ .macro pax_force_retaddr rip=0, reload=0
11813+ .endm
11814+ .macro pax_force_fptr ptr
11815+ .endm
11816+ .macro pax_force_retaddr_bts rip=0
11817+ .endm
11818+ .macro pax_set_fptr_mask
11819+ .endm
11820+#endif
11821+
11822 .macro altinstruction_entry orig alt feature orig_len alt_len
11823 .long \orig - .
11824 .long \alt - .
11825diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11826index 58ed6d9..f1cbe58 100644
11827--- a/arch/x86/include/asm/alternative.h
11828+++ b/arch/x86/include/asm/alternative.h
11829@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11830 ".pushsection .discard,\"aw\",@progbits\n" \
11831 DISCARD_ENTRY(1) \
11832 ".popsection\n" \
11833- ".pushsection .altinstr_replacement, \"ax\"\n" \
11834+ ".pushsection .altinstr_replacement, \"a\"\n" \
11835 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11836 ".popsection"
11837
11838@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11839 DISCARD_ENTRY(1) \
11840 DISCARD_ENTRY(2) \
11841 ".popsection\n" \
11842- ".pushsection .altinstr_replacement, \"ax\"\n" \
11843+ ".pushsection .altinstr_replacement, \"a\"\n" \
11844 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11845 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11846 ".popsection"
11847diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11848index 3388034..050f0b9 100644
11849--- a/arch/x86/include/asm/apic.h
11850+++ b/arch/x86/include/asm/apic.h
11851@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11852
11853 #ifdef CONFIG_X86_LOCAL_APIC
11854
11855-extern unsigned int apic_verbosity;
11856+extern int apic_verbosity;
11857 extern int local_apic_timer_c2_ok;
11858
11859 extern int disable_apic;
11860diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11861index 20370c6..a2eb9b0 100644
11862--- a/arch/x86/include/asm/apm.h
11863+++ b/arch/x86/include/asm/apm.h
11864@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11865 __asm__ __volatile__(APM_DO_ZERO_SEGS
11866 "pushl %%edi\n\t"
11867 "pushl %%ebp\n\t"
11868- "lcall *%%cs:apm_bios_entry\n\t"
11869+ "lcall *%%ss:apm_bios_entry\n\t"
11870 "setc %%al\n\t"
11871 "popl %%ebp\n\t"
11872 "popl %%edi\n\t"
11873@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
11874 __asm__ __volatile__(APM_DO_ZERO_SEGS
11875 "pushl %%edi\n\t"
11876 "pushl %%ebp\n\t"
11877- "lcall *%%cs:apm_bios_entry\n\t"
11878+ "lcall *%%ss:apm_bios_entry\n\t"
11879 "setc %%bl\n\t"
11880 "popl %%ebp\n\t"
11881 "popl %%edi\n\t"
11882diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
11883index 722aa3b..3a0bb27 100644
11884--- a/arch/x86/include/asm/atomic.h
11885+++ b/arch/x86/include/asm/atomic.h
11886@@ -22,7 +22,18 @@
11887 */
11888 static inline int atomic_read(const atomic_t *v)
11889 {
11890- return (*(volatile int *)&(v)->counter);
11891+ return (*(volatile const int *)&(v)->counter);
11892+}
11893+
11894+/**
11895+ * atomic_read_unchecked - read atomic variable
11896+ * @v: pointer of type atomic_unchecked_t
11897+ *
11898+ * Atomically reads the value of @v.
11899+ */
11900+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
11901+{
11902+ return (*(volatile const int *)&(v)->counter);
11903 }
11904
11905 /**
11906@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
11907 }
11908
11909 /**
11910+ * atomic_set_unchecked - set atomic variable
11911+ * @v: pointer of type atomic_unchecked_t
11912+ * @i: required value
11913+ *
11914+ * Atomically sets the value of @v to @i.
11915+ */
11916+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
11917+{
11918+ v->counter = i;
11919+}
11920+
11921+/**
11922 * atomic_add - add integer to atomic variable
11923 * @i: integer value to add
11924 * @v: pointer of type atomic_t
11925@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
11926 */
11927 static inline void atomic_add(int i, atomic_t *v)
11928 {
11929- asm volatile(LOCK_PREFIX "addl %1,%0"
11930+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
11931+
11932+#ifdef CONFIG_PAX_REFCOUNT
11933+ "jno 0f\n"
11934+ LOCK_PREFIX "subl %1,%0\n"
11935+ "int $4\n0:\n"
11936+ _ASM_EXTABLE(0b, 0b)
11937+#endif
11938+
11939+ : "+m" (v->counter)
11940+ : "ir" (i));
11941+}
11942+
11943+/**
11944+ * atomic_add_unchecked - add integer to atomic variable
11945+ * @i: integer value to add
11946+ * @v: pointer of type atomic_unchecked_t
11947+ *
11948+ * Atomically adds @i to @v.
11949+ */
11950+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
11951+{
11952+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
11953 : "+m" (v->counter)
11954 : "ir" (i));
11955 }
11956@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
11957 */
11958 static inline void atomic_sub(int i, atomic_t *v)
11959 {
11960- asm volatile(LOCK_PREFIX "subl %1,%0"
11961+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
11962+
11963+#ifdef CONFIG_PAX_REFCOUNT
11964+ "jno 0f\n"
11965+ LOCK_PREFIX "addl %1,%0\n"
11966+ "int $4\n0:\n"
11967+ _ASM_EXTABLE(0b, 0b)
11968+#endif
11969+
11970+ : "+m" (v->counter)
11971+ : "ir" (i));
11972+}
11973+
11974+/**
11975+ * atomic_sub_unchecked - subtract integer from atomic variable
11976+ * @i: integer value to subtract
11977+ * @v: pointer of type atomic_unchecked_t
11978+ *
11979+ * Atomically subtracts @i from @v.
11980+ */
11981+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
11982+{
11983+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
11984 : "+m" (v->counter)
11985 : "ir" (i));
11986 }
11987@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11988 {
11989 unsigned char c;
11990
11991- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
11992+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
11993+
11994+#ifdef CONFIG_PAX_REFCOUNT
11995+ "jno 0f\n"
11996+ LOCK_PREFIX "addl %2,%0\n"
11997+ "int $4\n0:\n"
11998+ _ASM_EXTABLE(0b, 0b)
11999+#endif
12000+
12001+ "sete %1\n"
12002 : "+m" (v->counter), "=qm" (c)
12003 : "ir" (i) : "memory");
12004 return c;
12005@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12006 */
12007 static inline void atomic_inc(atomic_t *v)
12008 {
12009- asm volatile(LOCK_PREFIX "incl %0"
12010+ asm volatile(LOCK_PREFIX "incl %0\n"
12011+
12012+#ifdef CONFIG_PAX_REFCOUNT
12013+ "jno 0f\n"
12014+ LOCK_PREFIX "decl %0\n"
12015+ "int $4\n0:\n"
12016+ _ASM_EXTABLE(0b, 0b)
12017+#endif
12018+
12019+ : "+m" (v->counter));
12020+}
12021+
12022+/**
12023+ * atomic_inc_unchecked - increment atomic variable
12024+ * @v: pointer of type atomic_unchecked_t
12025+ *
12026+ * Atomically increments @v by 1.
12027+ */
12028+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
12029+{
12030+ asm volatile(LOCK_PREFIX "incl %0\n"
12031 : "+m" (v->counter));
12032 }
12033
12034@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
12035 */
12036 static inline void atomic_dec(atomic_t *v)
12037 {
12038- asm volatile(LOCK_PREFIX "decl %0"
12039+ asm volatile(LOCK_PREFIX "decl %0\n"
12040+
12041+#ifdef CONFIG_PAX_REFCOUNT
12042+ "jno 0f\n"
12043+ LOCK_PREFIX "incl %0\n"
12044+ "int $4\n0:\n"
12045+ _ASM_EXTABLE(0b, 0b)
12046+#endif
12047+
12048+ : "+m" (v->counter));
12049+}
12050+
12051+/**
12052+ * atomic_dec_unchecked - decrement atomic variable
12053+ * @v: pointer of type atomic_unchecked_t
12054+ *
12055+ * Atomically decrements @v by 1.
12056+ */
12057+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
12058+{
12059+ asm volatile(LOCK_PREFIX "decl %0\n"
12060 : "+m" (v->counter));
12061 }
12062
12063@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
12064 {
12065 unsigned char c;
12066
12067- asm volatile(LOCK_PREFIX "decl %0; sete %1"
12068+ asm volatile(LOCK_PREFIX "decl %0\n"
12069+
12070+#ifdef CONFIG_PAX_REFCOUNT
12071+ "jno 0f\n"
12072+ LOCK_PREFIX "incl %0\n"
12073+ "int $4\n0:\n"
12074+ _ASM_EXTABLE(0b, 0b)
12075+#endif
12076+
12077+ "sete %1\n"
12078 : "+m" (v->counter), "=qm" (c)
12079 : : "memory");
12080 return c != 0;
12081@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
12082 {
12083 unsigned char c;
12084
12085- asm volatile(LOCK_PREFIX "incl %0; sete %1"
12086+ asm volatile(LOCK_PREFIX "incl %0\n"
12087+
12088+#ifdef CONFIG_PAX_REFCOUNT
12089+ "jno 0f\n"
12090+ LOCK_PREFIX "decl %0\n"
12091+ "int $4\n0:\n"
12092+ _ASM_EXTABLE(0b, 0b)
12093+#endif
12094+
12095+ "sete %1\n"
12096+ : "+m" (v->counter), "=qm" (c)
12097+ : : "memory");
12098+ return c != 0;
12099+}
12100+
12101+/**
12102+ * atomic_inc_and_test_unchecked - increment and test
12103+ * @v: pointer of type atomic_unchecked_t
12104+ *
12105+ * Atomically increments @v by 1
12106+ * and returns true if the result is zero, or false for all
12107+ * other cases.
12108+ */
12109+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
12110+{
12111+ unsigned char c;
12112+
12113+ asm volatile(LOCK_PREFIX "incl %0\n"
12114+ "sete %1\n"
12115 : "+m" (v->counter), "=qm" (c)
12116 : : "memory");
12117 return c != 0;
12118@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12119 {
12120 unsigned char c;
12121
12122- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
12123+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
12124+
12125+#ifdef CONFIG_PAX_REFCOUNT
12126+ "jno 0f\n"
12127+ LOCK_PREFIX "subl %2,%0\n"
12128+ "int $4\n0:\n"
12129+ _ASM_EXTABLE(0b, 0b)
12130+#endif
12131+
12132+ "sets %1\n"
12133 : "+m" (v->counter), "=qm" (c)
12134 : "ir" (i) : "memory");
12135 return c;
12136@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12137 */
12138 static inline int atomic_add_return(int i, atomic_t *v)
12139 {
12140+ return i + xadd_check_overflow(&v->counter, i);
12141+}
12142+
12143+/**
12144+ * atomic_add_return_unchecked - add integer and return
12145+ * @i: integer value to add
12146+ * @v: pointer of type atomic_unchecked_t
12147+ *
12148+ * Atomically adds @i to @v and returns @i + @v
12149+ */
12150+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
12151+{
12152 return i + xadd(&v->counter, i);
12153 }
12154
12155@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
12156 }
12157
12158 #define atomic_inc_return(v) (atomic_add_return(1, v))
12159+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
12160+{
12161+ return atomic_add_return_unchecked(1, v);
12162+}
12163 #define atomic_dec_return(v) (atomic_sub_return(1, v))
12164
12165 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12166@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12167 return cmpxchg(&v->counter, old, new);
12168 }
12169
12170+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
12171+{
12172+ return cmpxchg(&v->counter, old, new);
12173+}
12174+
12175 static inline int atomic_xchg(atomic_t *v, int new)
12176 {
12177 return xchg(&v->counter, new);
12178 }
12179
12180+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
12181+{
12182+ return xchg(&v->counter, new);
12183+}
12184+
12185 /**
12186 * __atomic_add_unless - add unless the number is already a given value
12187 * @v: pointer of type atomic_t
12188@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
12189 */
12190 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12191 {
12192- int c, old;
12193+ int c, old, new;
12194 c = atomic_read(v);
12195 for (;;) {
12196- if (unlikely(c == (u)))
12197+ if (unlikely(c == u))
12198 break;
12199- old = atomic_cmpxchg((v), c, c + (a));
12200+
12201+ asm volatile("addl %2,%0\n"
12202+
12203+#ifdef CONFIG_PAX_REFCOUNT
12204+ "jno 0f\n"
12205+ "subl %2,%0\n"
12206+ "int $4\n0:\n"
12207+ _ASM_EXTABLE(0b, 0b)
12208+#endif
12209+
12210+ : "=r" (new)
12211+ : "0" (c), "ir" (a));
12212+
12213+ old = atomic_cmpxchg(v, c, new);
12214 if (likely(old == c))
12215 break;
12216 c = old;
12217@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12218 }
12219
12220 /**
12221+ * atomic_inc_not_zero_hint - increment if not null
12222+ * @v: pointer of type atomic_t
12223+ * @hint: probable value of the atomic before the increment
12224+ *
12225+ * This version of atomic_inc_not_zero() gives a hint of probable
12226+ * value of the atomic. This helps processor to not read the memory
12227+ * before doing the atomic read/modify/write cycle, lowering
12228+ * number of bus transactions on some arches.
12229+ *
12230+ * Returns: 0 if increment was not done, 1 otherwise.
12231+ */
12232+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
12233+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
12234+{
12235+ int val, c = hint, new;
12236+
12237+ /* sanity test, should be removed by compiler if hint is a constant */
12238+ if (!hint)
12239+ return __atomic_add_unless(v, 1, 0);
12240+
12241+ do {
12242+ asm volatile("incl %0\n"
12243+
12244+#ifdef CONFIG_PAX_REFCOUNT
12245+ "jno 0f\n"
12246+ "decl %0\n"
12247+ "int $4\n0:\n"
12248+ _ASM_EXTABLE(0b, 0b)
12249+#endif
12250+
12251+ : "=r" (new)
12252+ : "0" (c));
12253+
12254+ val = atomic_cmpxchg(v, c, new);
12255+ if (val == c)
12256+ return 1;
12257+ c = val;
12258+ } while (c);
12259+
12260+ return 0;
12261+}
12262+
12263+/**
12264 * atomic_inc_short - increment of a short integer
12265 * @v: pointer to type int
12266 *
12267@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
12268 #endif
12269
12270 /* These are x86-specific, used by some header files */
12271-#define atomic_clear_mask(mask, addr) \
12272- asm volatile(LOCK_PREFIX "andl %0,%1" \
12273- : : "r" (~(mask)), "m" (*(addr)) : "memory")
12274+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
12275+{
12276+ asm volatile(LOCK_PREFIX "andl %1,%0"
12277+ : "+m" (v->counter)
12278+ : "r" (~(mask))
12279+ : "memory");
12280+}
12281
12282-#define atomic_set_mask(mask, addr) \
12283- asm volatile(LOCK_PREFIX "orl %0,%1" \
12284- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
12285- : "memory")
12286+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12287+{
12288+ asm volatile(LOCK_PREFIX "andl %1,%0"
12289+ : "+m" (v->counter)
12290+ : "r" (~(mask))
12291+ : "memory");
12292+}
12293+
12294+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
12295+{
12296+ asm volatile(LOCK_PREFIX "orl %1,%0"
12297+ : "+m" (v->counter)
12298+ : "r" (mask)
12299+ : "memory");
12300+}
12301+
12302+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12303+{
12304+ asm volatile(LOCK_PREFIX "orl %1,%0"
12305+ : "+m" (v->counter)
12306+ : "r" (mask)
12307+ : "memory");
12308+}
12309
12310 /* Atomic operations are already serializing on x86 */
12311 #define smp_mb__before_atomic_dec() barrier()
12312diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12313index b154de7..aadebd8 100644
12314--- a/arch/x86/include/asm/atomic64_32.h
12315+++ b/arch/x86/include/asm/atomic64_32.h
12316@@ -12,6 +12,14 @@ typedef struct {
12317 u64 __aligned(8) counter;
12318 } atomic64_t;
12319
12320+#ifdef CONFIG_PAX_REFCOUNT
12321+typedef struct {
12322+ u64 __aligned(8) counter;
12323+} atomic64_unchecked_t;
12324+#else
12325+typedef atomic64_t atomic64_unchecked_t;
12326+#endif
12327+
12328 #define ATOMIC64_INIT(val) { (val) }
12329
12330 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12331@@ -37,21 +45,31 @@ typedef struct {
12332 ATOMIC64_DECL_ONE(sym##_386)
12333
12334 ATOMIC64_DECL_ONE(add_386);
12335+ATOMIC64_DECL_ONE(add_unchecked_386);
12336 ATOMIC64_DECL_ONE(sub_386);
12337+ATOMIC64_DECL_ONE(sub_unchecked_386);
12338 ATOMIC64_DECL_ONE(inc_386);
12339+ATOMIC64_DECL_ONE(inc_unchecked_386);
12340 ATOMIC64_DECL_ONE(dec_386);
12341+ATOMIC64_DECL_ONE(dec_unchecked_386);
12342 #endif
12343
12344 #define alternative_atomic64(f, out, in...) \
12345 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12346
12347 ATOMIC64_DECL(read);
12348+ATOMIC64_DECL(read_unchecked);
12349 ATOMIC64_DECL(set);
12350+ATOMIC64_DECL(set_unchecked);
12351 ATOMIC64_DECL(xchg);
12352 ATOMIC64_DECL(add_return);
12353+ATOMIC64_DECL(add_return_unchecked);
12354 ATOMIC64_DECL(sub_return);
12355+ATOMIC64_DECL(sub_return_unchecked);
12356 ATOMIC64_DECL(inc_return);
12357+ATOMIC64_DECL(inc_return_unchecked);
12358 ATOMIC64_DECL(dec_return);
12359+ATOMIC64_DECL(dec_return_unchecked);
12360 ATOMIC64_DECL(dec_if_positive);
12361 ATOMIC64_DECL(inc_not_zero);
12362 ATOMIC64_DECL(add_unless);
12363@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12364 }
12365
12366 /**
12367+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12368+ * @p: pointer to type atomic64_unchecked_t
12369+ * @o: expected value
12370+ * @n: new value
12371+ *
12372+ * Atomically sets @v to @n if it was equal to @o and returns
12373+ * the old value.
12374+ */
12375+
12376+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12377+{
12378+ return cmpxchg64(&v->counter, o, n);
12379+}
12380+
12381+/**
12382 * atomic64_xchg - xchg atomic64 variable
12383 * @v: pointer to type atomic64_t
12384 * @n: value to assign
12385@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12386 }
12387
12388 /**
12389+ * atomic64_set_unchecked - set atomic64 variable
12390+ * @v: pointer to type atomic64_unchecked_t
12391+ * @n: value to assign
12392+ *
12393+ * Atomically sets the value of @v to @n.
12394+ */
12395+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12396+{
12397+ unsigned high = (unsigned)(i >> 32);
12398+ unsigned low = (unsigned)i;
12399+ alternative_atomic64(set, /* no output */,
12400+ "S" (v), "b" (low), "c" (high)
12401+ : "eax", "edx", "memory");
12402+}
12403+
12404+/**
12405 * atomic64_read - read atomic64 variable
12406 * @v: pointer to type atomic64_t
12407 *
12408@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12409 }
12410
12411 /**
12412+ * atomic64_read_unchecked - read atomic64 variable
12413+ * @v: pointer to type atomic64_unchecked_t
12414+ *
12415+ * Atomically reads the value of @v and returns it.
12416+ */
12417+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12418+{
12419+ long long r;
12420+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12421+ return r;
12422+ }
12423+
12424+/**
12425 * atomic64_add_return - add and return
12426 * @i: integer value to add
12427 * @v: pointer to type atomic64_t
12428@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12429 return i;
12430 }
12431
12432+/**
12433+ * atomic64_add_return_unchecked - add and return
12434+ * @i: integer value to add
12435+ * @v: pointer to type atomic64_unchecked_t
12436+ *
12437+ * Atomically adds @i to @v and returns @i + *@v
12438+ */
12439+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12440+{
12441+ alternative_atomic64(add_return_unchecked,
12442+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12443+ ASM_NO_INPUT_CLOBBER("memory"));
12444+ return i;
12445+}
12446+
12447 /*
12448 * Other variants with different arithmetic operators:
12449 */
12450@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12451 return a;
12452 }
12453
12454+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12455+{
12456+ long long a;
12457+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
12458+ "S" (v) : "memory", "ecx");
12459+ return a;
12460+}
12461+
12462 static inline long long atomic64_dec_return(atomic64_t *v)
12463 {
12464 long long a;
12465@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12466 }
12467
12468 /**
12469+ * atomic64_add_unchecked - add integer to atomic64 variable
12470+ * @i: integer value to add
12471+ * @v: pointer to type atomic64_unchecked_t
12472+ *
12473+ * Atomically adds @i to @v.
12474+ */
12475+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12476+{
12477+ __alternative_atomic64(add_unchecked, add_return_unchecked,
12478+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12479+ ASM_NO_INPUT_CLOBBER("memory"));
12480+ return i;
12481+}
12482+
12483+/**
12484 * atomic64_sub - subtract the atomic64 variable
12485 * @i: integer value to subtract
12486 * @v: pointer to type atomic64_t
12487diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12488index 0e1cbfc..5623683 100644
12489--- a/arch/x86/include/asm/atomic64_64.h
12490+++ b/arch/x86/include/asm/atomic64_64.h
12491@@ -18,7 +18,19 @@
12492 */
12493 static inline long atomic64_read(const atomic64_t *v)
12494 {
12495- return (*(volatile long *)&(v)->counter);
12496+ return (*(volatile const long *)&(v)->counter);
12497+}
12498+
12499+/**
12500+ * atomic64_read_unchecked - read atomic64 variable
12501+ * @v: pointer of type atomic64_unchecked_t
12502+ *
12503+ * Atomically reads the value of @v.
12504+ * Doesn't imply a read memory barrier.
12505+ */
12506+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12507+{
12508+ return (*(volatile const long *)&(v)->counter);
12509 }
12510
12511 /**
12512@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12513 }
12514
12515 /**
12516+ * atomic64_set_unchecked - set atomic64 variable
12517+ * @v: pointer to type atomic64_unchecked_t
12518+ * @i: required value
12519+ *
12520+ * Atomically sets the value of @v to @i.
12521+ */
12522+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12523+{
12524+ v->counter = i;
12525+}
12526+
12527+/**
12528 * atomic64_add - add integer to atomic64 variable
12529 * @i: integer value to add
12530 * @v: pointer to type atomic64_t
12531@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12532 */
12533 static inline void atomic64_add(long i, atomic64_t *v)
12534 {
12535+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
12536+
12537+#ifdef CONFIG_PAX_REFCOUNT
12538+ "jno 0f\n"
12539+ LOCK_PREFIX "subq %1,%0\n"
12540+ "int $4\n0:\n"
12541+ _ASM_EXTABLE(0b, 0b)
12542+#endif
12543+
12544+ : "=m" (v->counter)
12545+ : "er" (i), "m" (v->counter));
12546+}
12547+
12548+/**
12549+ * atomic64_add_unchecked - add integer to atomic64 variable
12550+ * @i: integer value to add
12551+ * @v: pointer to type atomic64_unchecked_t
12552+ *
12553+ * Atomically adds @i to @v.
12554+ */
12555+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12556+{
12557 asm volatile(LOCK_PREFIX "addq %1,%0"
12558 : "=m" (v->counter)
12559 : "er" (i), "m" (v->counter));
12560@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12561 */
12562 static inline void atomic64_sub(long i, atomic64_t *v)
12563 {
12564- asm volatile(LOCK_PREFIX "subq %1,%0"
12565+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12566+
12567+#ifdef CONFIG_PAX_REFCOUNT
12568+ "jno 0f\n"
12569+ LOCK_PREFIX "addq %1,%0\n"
12570+ "int $4\n0:\n"
12571+ _ASM_EXTABLE(0b, 0b)
12572+#endif
12573+
12574+ : "=m" (v->counter)
12575+ : "er" (i), "m" (v->counter));
12576+}
12577+
12578+/**
12579+ * atomic64_sub_unchecked - subtract the atomic64 variable
12580+ * @i: integer value to subtract
12581+ * @v: pointer to type atomic64_unchecked_t
12582+ *
12583+ * Atomically subtracts @i from @v.
12584+ */
12585+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12586+{
12587+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12588 : "=m" (v->counter)
12589 : "er" (i), "m" (v->counter));
12590 }
12591@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12592 {
12593 unsigned char c;
12594
12595- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12596+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
12597+
12598+#ifdef CONFIG_PAX_REFCOUNT
12599+ "jno 0f\n"
12600+ LOCK_PREFIX "addq %2,%0\n"
12601+ "int $4\n0:\n"
12602+ _ASM_EXTABLE(0b, 0b)
12603+#endif
12604+
12605+ "sete %1\n"
12606 : "=m" (v->counter), "=qm" (c)
12607 : "er" (i), "m" (v->counter) : "memory");
12608 return c;
12609@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12610 */
12611 static inline void atomic64_inc(atomic64_t *v)
12612 {
12613+ asm volatile(LOCK_PREFIX "incq %0\n"
12614+
12615+#ifdef CONFIG_PAX_REFCOUNT
12616+ "jno 0f\n"
12617+ LOCK_PREFIX "decq %0\n"
12618+ "int $4\n0:\n"
12619+ _ASM_EXTABLE(0b, 0b)
12620+#endif
12621+
12622+ : "=m" (v->counter)
12623+ : "m" (v->counter));
12624+}
12625+
12626+/**
12627+ * atomic64_inc_unchecked - increment atomic64 variable
12628+ * @v: pointer to type atomic64_unchecked_t
12629+ *
12630+ * Atomically increments @v by 1.
12631+ */
12632+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12633+{
12634 asm volatile(LOCK_PREFIX "incq %0"
12635 : "=m" (v->counter)
12636 : "m" (v->counter));
12637@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12638 */
12639 static inline void atomic64_dec(atomic64_t *v)
12640 {
12641- asm volatile(LOCK_PREFIX "decq %0"
12642+ asm volatile(LOCK_PREFIX "decq %0\n"
12643+
12644+#ifdef CONFIG_PAX_REFCOUNT
12645+ "jno 0f\n"
12646+ LOCK_PREFIX "incq %0\n"
12647+ "int $4\n0:\n"
12648+ _ASM_EXTABLE(0b, 0b)
12649+#endif
12650+
12651+ : "=m" (v->counter)
12652+ : "m" (v->counter));
12653+}
12654+
12655+/**
12656+ * atomic64_dec_unchecked - decrement atomic64 variable
12657+ * @v: pointer to type atomic64_t
12658+ *
12659+ * Atomically decrements @v by 1.
12660+ */
12661+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12662+{
12663+ asm volatile(LOCK_PREFIX "decq %0\n"
12664 : "=m" (v->counter)
12665 : "m" (v->counter));
12666 }
12667@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12668 {
12669 unsigned char c;
12670
12671- asm volatile(LOCK_PREFIX "decq %0; sete %1"
12672+ asm volatile(LOCK_PREFIX "decq %0\n"
12673+
12674+#ifdef CONFIG_PAX_REFCOUNT
12675+ "jno 0f\n"
12676+ LOCK_PREFIX "incq %0\n"
12677+ "int $4\n0:\n"
12678+ _ASM_EXTABLE(0b, 0b)
12679+#endif
12680+
12681+ "sete %1\n"
12682 : "=m" (v->counter), "=qm" (c)
12683 : "m" (v->counter) : "memory");
12684 return c != 0;
12685@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12686 {
12687 unsigned char c;
12688
12689- asm volatile(LOCK_PREFIX "incq %0; sete %1"
12690+ asm volatile(LOCK_PREFIX "incq %0\n"
12691+
12692+#ifdef CONFIG_PAX_REFCOUNT
12693+ "jno 0f\n"
12694+ LOCK_PREFIX "decq %0\n"
12695+ "int $4\n0:\n"
12696+ _ASM_EXTABLE(0b, 0b)
12697+#endif
12698+
12699+ "sete %1\n"
12700 : "=m" (v->counter), "=qm" (c)
12701 : "m" (v->counter) : "memory");
12702 return c != 0;
12703@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12704 {
12705 unsigned char c;
12706
12707- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12708+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
12709+
12710+#ifdef CONFIG_PAX_REFCOUNT
12711+ "jno 0f\n"
12712+ LOCK_PREFIX "subq %2,%0\n"
12713+ "int $4\n0:\n"
12714+ _ASM_EXTABLE(0b, 0b)
12715+#endif
12716+
12717+ "sets %1\n"
12718 : "=m" (v->counter), "=qm" (c)
12719 : "er" (i), "m" (v->counter) : "memory");
12720 return c;
12721@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12722 */
12723 static inline long atomic64_add_return(long i, atomic64_t *v)
12724 {
12725+ return i + xadd_check_overflow(&v->counter, i);
12726+}
12727+
12728+/**
12729+ * atomic64_add_return_unchecked - add and return
12730+ * @i: integer value to add
12731+ * @v: pointer to type atomic64_unchecked_t
12732+ *
12733+ * Atomically adds @i to @v and returns @i + @v
12734+ */
12735+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12736+{
12737 return i + xadd(&v->counter, i);
12738 }
12739
12740@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12741 }
12742
12743 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12744+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12745+{
12746+ return atomic64_add_return_unchecked(1, v);
12747+}
12748 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12749
12750 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12751@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12752 return cmpxchg(&v->counter, old, new);
12753 }
12754
12755+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12756+{
12757+ return cmpxchg(&v->counter, old, new);
12758+}
12759+
12760 static inline long atomic64_xchg(atomic64_t *v, long new)
12761 {
12762 return xchg(&v->counter, new);
12763@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12764 */
12765 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12766 {
12767- long c, old;
12768+ long c, old, new;
12769 c = atomic64_read(v);
12770 for (;;) {
12771- if (unlikely(c == (u)))
12772+ if (unlikely(c == u))
12773 break;
12774- old = atomic64_cmpxchg((v), c, c + (a));
12775+
12776+ asm volatile("add %2,%0\n"
12777+
12778+#ifdef CONFIG_PAX_REFCOUNT
12779+ "jno 0f\n"
12780+ "sub %2,%0\n"
12781+ "int $4\n0:\n"
12782+ _ASM_EXTABLE(0b, 0b)
12783+#endif
12784+
12785+ : "=r" (new)
12786+ : "0" (c), "ir" (a));
12787+
12788+ old = atomic64_cmpxchg(v, c, new);
12789 if (likely(old == c))
12790 break;
12791 c = old;
12792 }
12793- return c != (u);
12794+ return c != u;
12795 }
12796
12797 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12798diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12799index 6dfd019..28e188d 100644
12800--- a/arch/x86/include/asm/bitops.h
12801+++ b/arch/x86/include/asm/bitops.h
12802@@ -40,7 +40,7 @@
12803 * a mask operation on a byte.
12804 */
12805 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12806-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12807+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12808 #define CONST_MASK(nr) (1 << ((nr) & 7))
12809
12810 /**
12811@@ -486,7 +486,7 @@ static inline int fls(int x)
12812 * at position 64.
12813 */
12814 #ifdef CONFIG_X86_64
12815-static __always_inline int fls64(__u64 x)
12816+static __always_inline long fls64(__u64 x)
12817 {
12818 int bitpos = -1;
12819 /*
12820diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12821index 4fa687a..60f2d39 100644
12822--- a/arch/x86/include/asm/boot.h
12823+++ b/arch/x86/include/asm/boot.h
12824@@ -6,10 +6,15 @@
12825 #include <uapi/asm/boot.h>
12826
12827 /* Physical address where kernel should be loaded. */
12828-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12829+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12830 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12831 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12832
12833+#ifndef __ASSEMBLY__
12834+extern unsigned char __LOAD_PHYSICAL_ADDR[];
12835+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12836+#endif
12837+
12838 /* Minimum kernel alignment, as a power of two */
12839 #ifdef CONFIG_X86_64
12840 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12841diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12842index 48f99f1..d78ebf9 100644
12843--- a/arch/x86/include/asm/cache.h
12844+++ b/arch/x86/include/asm/cache.h
12845@@ -5,12 +5,13 @@
12846
12847 /* L1 cache line size */
12848 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12849-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12850+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12851
12852 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12853+#define __read_only __attribute__((__section__(".data..read_only")))
12854
12855 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12856-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12857+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12858
12859 #ifdef CONFIG_X86_VSMP
12860 #ifdef CONFIG_SMP
12861diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12862index 9863ee3..4a1f8e1 100644
12863--- a/arch/x86/include/asm/cacheflush.h
12864+++ b/arch/x86/include/asm/cacheflush.h
12865@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12866 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12867
12868 if (pg_flags == _PGMT_DEFAULT)
12869- return -1;
12870+ return ~0UL;
12871 else if (pg_flags == _PGMT_WC)
12872 return _PAGE_CACHE_WC;
12873 else if (pg_flags == _PGMT_UC_MINUS)
12874diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
12875index 46fc474..b02b0f9 100644
12876--- a/arch/x86/include/asm/checksum_32.h
12877+++ b/arch/x86/include/asm/checksum_32.h
12878@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
12879 int len, __wsum sum,
12880 int *src_err_ptr, int *dst_err_ptr);
12881
12882+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
12883+ int len, __wsum sum,
12884+ int *src_err_ptr, int *dst_err_ptr);
12885+
12886+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
12887+ int len, __wsum sum,
12888+ int *src_err_ptr, int *dst_err_ptr);
12889+
12890 /*
12891 * Note: when you get a NULL pointer exception here this means someone
12892 * passed in an incorrect kernel address to one of these functions.
12893@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
12894 int *err_ptr)
12895 {
12896 might_sleep();
12897- return csum_partial_copy_generic((__force void *)src, dst,
12898+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
12899 len, sum, err_ptr, NULL);
12900 }
12901
12902@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
12903 {
12904 might_sleep();
12905 if (access_ok(VERIFY_WRITE, dst, len))
12906- return csum_partial_copy_generic(src, (__force void *)dst,
12907+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
12908 len, sum, NULL, err_ptr);
12909
12910 if (len)
12911diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
12912index 8d871ea..c1a0dc9 100644
12913--- a/arch/x86/include/asm/cmpxchg.h
12914+++ b/arch/x86/include/asm/cmpxchg.h
12915@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
12916 __compiletime_error("Bad argument size for cmpxchg");
12917 extern void __xadd_wrong_size(void)
12918 __compiletime_error("Bad argument size for xadd");
12919+extern void __xadd_check_overflow_wrong_size(void)
12920+ __compiletime_error("Bad argument size for xadd_check_overflow");
12921 extern void __add_wrong_size(void)
12922 __compiletime_error("Bad argument size for add");
12923+extern void __add_check_overflow_wrong_size(void)
12924+ __compiletime_error("Bad argument size for add_check_overflow");
12925
12926 /*
12927 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
12928@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
12929 __ret; \
12930 })
12931
12932+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
12933+ ({ \
12934+ __typeof__ (*(ptr)) __ret = (arg); \
12935+ switch (sizeof(*(ptr))) { \
12936+ case __X86_CASE_L: \
12937+ asm volatile (lock #op "l %0, %1\n" \
12938+ "jno 0f\n" \
12939+ "mov %0,%1\n" \
12940+ "int $4\n0:\n" \
12941+ _ASM_EXTABLE(0b, 0b) \
12942+ : "+r" (__ret), "+m" (*(ptr)) \
12943+ : : "memory", "cc"); \
12944+ break; \
12945+ case __X86_CASE_Q: \
12946+ asm volatile (lock #op "q %q0, %1\n" \
12947+ "jno 0f\n" \
12948+ "mov %0,%1\n" \
12949+ "int $4\n0:\n" \
12950+ _ASM_EXTABLE(0b, 0b) \
12951+ : "+r" (__ret), "+m" (*(ptr)) \
12952+ : : "memory", "cc"); \
12953+ break; \
12954+ default: \
12955+ __ ## op ## _check_overflow_wrong_size(); \
12956+ } \
12957+ __ret; \
12958+ })
12959+
12960 /*
12961 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
12962 * Since this is generally used to protect other memory information, we
12963@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
12964 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
12965 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
12966
12967+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
12968+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
12969+
12970 #define __add(ptr, inc, lock) \
12971 ({ \
12972 __typeof__ (*(ptr)) __ret = (inc); \
12973diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
12974index 59c6c40..5e0b22c 100644
12975--- a/arch/x86/include/asm/compat.h
12976+++ b/arch/x86/include/asm/compat.h
12977@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
12978 typedef u32 compat_uint_t;
12979 typedef u32 compat_ulong_t;
12980 typedef u64 __attribute__((aligned(4))) compat_u64;
12981-typedef u32 compat_uptr_t;
12982+typedef u32 __user compat_uptr_t;
12983
12984 struct compat_timespec {
12985 compat_time_t tv_sec;
12986diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
12987index 2d9075e..b75a844 100644
12988--- a/arch/x86/include/asm/cpufeature.h
12989+++ b/arch/x86/include/asm/cpufeature.h
12990@@ -206,7 +206,7 @@
12991 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
12992 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
12993 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
12994-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
12995+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
12996 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
12997 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
12998 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
12999@@ -375,7 +375,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
13000 ".section .discard,\"aw\",@progbits\n"
13001 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
13002 ".previous\n"
13003- ".section .altinstr_replacement,\"ax\"\n"
13004+ ".section .altinstr_replacement,\"a\"\n"
13005 "3: movb $1,%0\n"
13006 "4:\n"
13007 ".previous\n"
13008diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
13009index 8bf1c06..b6ae785 100644
13010--- a/arch/x86/include/asm/desc.h
13011+++ b/arch/x86/include/asm/desc.h
13012@@ -4,6 +4,7 @@
13013 #include <asm/desc_defs.h>
13014 #include <asm/ldt.h>
13015 #include <asm/mmu.h>
13016+#include <asm/pgtable.h>
13017
13018 #include <linux/smp.h>
13019 #include <linux/percpu.h>
13020@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13021
13022 desc->type = (info->read_exec_only ^ 1) << 1;
13023 desc->type |= info->contents << 2;
13024+ desc->type |= info->seg_not_present ^ 1;
13025
13026 desc->s = 1;
13027 desc->dpl = 0x3;
13028@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13029 }
13030
13031 extern struct desc_ptr idt_descr;
13032-extern gate_desc idt_table[];
13033 extern struct desc_ptr nmi_idt_descr;
13034-extern gate_desc nmi_idt_table[];
13035-
13036-struct gdt_page {
13037- struct desc_struct gdt[GDT_ENTRIES];
13038-} __attribute__((aligned(PAGE_SIZE)));
13039-
13040-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
13041+extern gate_desc idt_table[256];
13042+extern gate_desc nmi_idt_table[256];
13043
13044+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
13045 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
13046 {
13047- return per_cpu(gdt_page, cpu).gdt;
13048+ return cpu_gdt_table[cpu];
13049 }
13050
13051 #ifdef CONFIG_X86_64
13052@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
13053 unsigned long base, unsigned dpl, unsigned flags,
13054 unsigned short seg)
13055 {
13056- gate->a = (seg << 16) | (base & 0xffff);
13057- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
13058+ gate->gate.offset_low = base;
13059+ gate->gate.seg = seg;
13060+ gate->gate.reserved = 0;
13061+ gate->gate.type = type;
13062+ gate->gate.s = 0;
13063+ gate->gate.dpl = dpl;
13064+ gate->gate.p = 1;
13065+ gate->gate.offset_high = base >> 16;
13066 }
13067
13068 #endif
13069@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
13070
13071 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
13072 {
13073+ pax_open_kernel();
13074 memcpy(&idt[entry], gate, sizeof(*gate));
13075+ pax_close_kernel();
13076 }
13077
13078 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
13079 {
13080+ pax_open_kernel();
13081 memcpy(&ldt[entry], desc, 8);
13082+ pax_close_kernel();
13083 }
13084
13085 static inline void
13086@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
13087 default: size = sizeof(*gdt); break;
13088 }
13089
13090+ pax_open_kernel();
13091 memcpy(&gdt[entry], desc, size);
13092+ pax_close_kernel();
13093 }
13094
13095 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
13096@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
13097
13098 static inline void native_load_tr_desc(void)
13099 {
13100+ pax_open_kernel();
13101 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
13102+ pax_close_kernel();
13103 }
13104
13105 static inline void native_load_gdt(const struct desc_ptr *dtr)
13106@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
13107 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
13108 unsigned int i;
13109
13110+ pax_open_kernel();
13111 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
13112 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
13113+ pax_close_kernel();
13114 }
13115
13116 #define _LDT_empty(info) \
13117@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
13118 preempt_enable();
13119 }
13120
13121-static inline unsigned long get_desc_base(const struct desc_struct *desc)
13122+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
13123 {
13124 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
13125 }
13126@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
13127 }
13128
13129 #ifdef CONFIG_X86_64
13130-static inline void set_nmi_gate(int gate, void *addr)
13131+static inline void set_nmi_gate(int gate, const void *addr)
13132 {
13133 gate_desc s;
13134
13135@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
13136 }
13137 #endif
13138
13139-static inline void _set_gate(int gate, unsigned type, void *addr,
13140+static inline void _set_gate(int gate, unsigned type, const void *addr,
13141 unsigned dpl, unsigned ist, unsigned seg)
13142 {
13143 gate_desc s;
13144@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
13145 * Pentium F0 0F bugfix can have resulted in the mapped
13146 * IDT being write-protected.
13147 */
13148-static inline void set_intr_gate(unsigned int n, void *addr)
13149+static inline void set_intr_gate(unsigned int n, const void *addr)
13150 {
13151 BUG_ON((unsigned)n > 0xFF);
13152 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
13153@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
13154 /*
13155 * This routine sets up an interrupt gate at directory privilege level 3.
13156 */
13157-static inline void set_system_intr_gate(unsigned int n, void *addr)
13158+static inline void set_system_intr_gate(unsigned int n, const void *addr)
13159 {
13160 BUG_ON((unsigned)n > 0xFF);
13161 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
13162 }
13163
13164-static inline void set_system_trap_gate(unsigned int n, void *addr)
13165+static inline void set_system_trap_gate(unsigned int n, const void *addr)
13166 {
13167 BUG_ON((unsigned)n > 0xFF);
13168 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
13169 }
13170
13171-static inline void set_trap_gate(unsigned int n, void *addr)
13172+static inline void set_trap_gate(unsigned int n, const void *addr)
13173 {
13174 BUG_ON((unsigned)n > 0xFF);
13175 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
13176@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
13177 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
13178 {
13179 BUG_ON((unsigned)n > 0xFF);
13180- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
13181+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
13182 }
13183
13184-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
13185+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
13186 {
13187 BUG_ON((unsigned)n > 0xFF);
13188 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
13189 }
13190
13191-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
13192+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
13193 {
13194 BUG_ON((unsigned)n > 0xFF);
13195 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
13196 }
13197
13198+#ifdef CONFIG_X86_32
13199+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
13200+{
13201+ struct desc_struct d;
13202+
13203+ if (likely(limit))
13204+ limit = (limit - 1UL) >> PAGE_SHIFT;
13205+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
13206+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
13207+}
13208+#endif
13209+
13210 #endif /* _ASM_X86_DESC_H */
13211diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
13212index 278441f..b95a174 100644
13213--- a/arch/x86/include/asm/desc_defs.h
13214+++ b/arch/x86/include/asm/desc_defs.h
13215@@ -31,6 +31,12 @@ struct desc_struct {
13216 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
13217 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
13218 };
13219+ struct {
13220+ u16 offset_low;
13221+ u16 seg;
13222+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
13223+ unsigned offset_high: 16;
13224+ } gate;
13225 };
13226 } __attribute__((packed));
13227
13228diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
13229index ced283a..ffe04cc 100644
13230--- a/arch/x86/include/asm/div64.h
13231+++ b/arch/x86/include/asm/div64.h
13232@@ -39,7 +39,7 @@
13233 __mod; \
13234 })
13235
13236-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13237+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13238 {
13239 union {
13240 u64 v64;
13241diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
13242index 9c999c1..3860cb8 100644
13243--- a/arch/x86/include/asm/elf.h
13244+++ b/arch/x86/include/asm/elf.h
13245@@ -243,7 +243,25 @@ extern int force_personality32;
13246 the loader. We need to make sure that it is out of the way of the program
13247 that it will "exec", and that there is sufficient room for the brk. */
13248
13249+#ifdef CONFIG_PAX_SEGMEXEC
13250+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
13251+#else
13252 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
13253+#endif
13254+
13255+#ifdef CONFIG_PAX_ASLR
13256+#ifdef CONFIG_X86_32
13257+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
13258+
13259+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13260+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13261+#else
13262+#define PAX_ELF_ET_DYN_BASE 0x400000UL
13263+
13264+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13265+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13266+#endif
13267+#endif
13268
13269 /* This yields a mask that user programs can use to figure out what
13270 instruction set this CPU supports. This could be done in user space,
13271@@ -296,16 +314,12 @@ do { \
13272
13273 #define ARCH_DLINFO \
13274 do { \
13275- if (vdso_enabled) \
13276- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13277- (unsigned long)current->mm->context.vdso); \
13278+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13279 } while (0)
13280
13281 #define ARCH_DLINFO_X32 \
13282 do { \
13283- if (vdso_enabled) \
13284- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13285- (unsigned long)current->mm->context.vdso); \
13286+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13287 } while (0)
13288
13289 #define AT_SYSINFO 32
13290@@ -320,7 +334,7 @@ else \
13291
13292 #endif /* !CONFIG_X86_32 */
13293
13294-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
13295+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
13296
13297 #define VDSO_ENTRY \
13298 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
13299@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
13300 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
13301 #define compat_arch_setup_additional_pages syscall32_setup_pages
13302
13303-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
13304-#define arch_randomize_brk arch_randomize_brk
13305-
13306 /*
13307 * True on X86_32 or when emulating IA32 on X86_64
13308 */
13309diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
13310index 75ce3f4..882e801 100644
13311--- a/arch/x86/include/asm/emergency-restart.h
13312+++ b/arch/x86/include/asm/emergency-restart.h
13313@@ -13,6 +13,6 @@ enum reboot_type {
13314
13315 extern enum reboot_type reboot_type;
13316
13317-extern void machine_emergency_restart(void);
13318+extern void machine_emergency_restart(void) __noreturn;
13319
13320 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
13321diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
13322index 41ab26e..a88c9e6 100644
13323--- a/arch/x86/include/asm/fpu-internal.h
13324+++ b/arch/x86/include/asm/fpu-internal.h
13325@@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
13326 ({ \
13327 int err; \
13328 asm volatile(ASM_STAC "\n" \
13329- "1:" #insn "\n\t" \
13330+ "1:" \
13331+ __copyuser_seg \
13332+ #insn "\n\t" \
13333 "2: " ASM_CLAC "\n" \
13334 ".section .fixup,\"ax\"\n" \
13335 "3: movl $-1,%[err]\n" \
13336@@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
13337 "emms\n\t" /* clear stack tags */
13338 "fildl %P[addr]", /* set F?P to defined value */
13339 X86_FEATURE_FXSAVE_LEAK,
13340- [addr] "m" (tsk->thread.fpu.has_fpu));
13341+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
13342
13343 return fpu_restore_checking(&tsk->thread.fpu);
13344 }
13345diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
13346index be27ba1..8f13ff9 100644
13347--- a/arch/x86/include/asm/futex.h
13348+++ b/arch/x86/include/asm/futex.h
13349@@ -12,6 +12,7 @@
13350 #include <asm/smap.h>
13351
13352 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
13353+ typecheck(u32 __user *, uaddr); \
13354 asm volatile("\t" ASM_STAC "\n" \
13355 "1:\t" insn "\n" \
13356 "2:\t" ASM_CLAC "\n" \
13357@@ -20,15 +21,16 @@
13358 "\tjmp\t2b\n" \
13359 "\t.previous\n" \
13360 _ASM_EXTABLE(1b, 3b) \
13361- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13362+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13363 : "i" (-EFAULT), "0" (oparg), "1" (0))
13364
13365 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13366+ typecheck(u32 __user *, uaddr); \
13367 asm volatile("\t" ASM_STAC "\n" \
13368 "1:\tmovl %2, %0\n" \
13369 "\tmovl\t%0, %3\n" \
13370 "\t" insn "\n" \
13371- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13372+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13373 "\tjnz\t1b\n" \
13374 "3:\t" ASM_CLAC "\n" \
13375 "\t.section .fixup,\"ax\"\n" \
13376@@ -38,7 +40,7 @@
13377 _ASM_EXTABLE(1b, 4b) \
13378 _ASM_EXTABLE(2b, 4b) \
13379 : "=&a" (oldval), "=&r" (ret), \
13380- "+m" (*uaddr), "=&r" (tem) \
13381+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13382 : "r" (oparg), "i" (-EFAULT), "1" (0))
13383
13384 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13385@@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13386
13387 switch (op) {
13388 case FUTEX_OP_SET:
13389- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13390+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13391 break;
13392 case FUTEX_OP_ADD:
13393- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13394+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13395 uaddr, oparg);
13396 break;
13397 case FUTEX_OP_OR:
13398@@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13399 return -EFAULT;
13400
13401 asm volatile("\t" ASM_STAC "\n"
13402- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13403+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13404 "2:\t" ASM_CLAC "\n"
13405 "\t.section .fixup, \"ax\"\n"
13406 "3:\tmov %3, %0\n"
13407 "\tjmp 2b\n"
13408 "\t.previous\n"
13409 _ASM_EXTABLE(1b, 3b)
13410- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13411+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13412 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13413 : "memory"
13414 );
13415diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13416index eb92a6e..b98b2f4 100644
13417--- a/arch/x86/include/asm/hw_irq.h
13418+++ b/arch/x86/include/asm/hw_irq.h
13419@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
13420 extern void enable_IO_APIC(void);
13421
13422 /* Statistics */
13423-extern atomic_t irq_err_count;
13424-extern atomic_t irq_mis_count;
13425+extern atomic_unchecked_t irq_err_count;
13426+extern atomic_unchecked_t irq_mis_count;
13427
13428 /* EISA */
13429 extern void eisa_set_level_irq(unsigned int irq);
13430diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
13431index a203659..9889f1c 100644
13432--- a/arch/x86/include/asm/i8259.h
13433+++ b/arch/x86/include/asm/i8259.h
13434@@ -62,7 +62,7 @@ struct legacy_pic {
13435 void (*init)(int auto_eoi);
13436 int (*irq_pending)(unsigned int irq);
13437 void (*make_irq)(unsigned int irq);
13438-};
13439+} __do_const;
13440
13441 extern struct legacy_pic *legacy_pic;
13442 extern struct legacy_pic null_legacy_pic;
13443diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13444index d8e8eef..1765f78 100644
13445--- a/arch/x86/include/asm/io.h
13446+++ b/arch/x86/include/asm/io.h
13447@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
13448 "m" (*(volatile type __force *)addr) barrier); }
13449
13450 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
13451-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
13452-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
13453+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
13454+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
13455
13456 build_mmio_read(__readb, "b", unsigned char, "=q", )
13457-build_mmio_read(__readw, "w", unsigned short, "=r", )
13458-build_mmio_read(__readl, "l", unsigned int, "=r", )
13459+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
13460+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
13461
13462 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
13463 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
13464@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13465 return ioremap_nocache(offset, size);
13466 }
13467
13468-extern void iounmap(volatile void __iomem *addr);
13469+extern void iounmap(const volatile void __iomem *addr);
13470
13471 extern void set_iounmap_nonlazy(void);
13472
13473@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13474
13475 #include <linux/vmalloc.h>
13476
13477+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13478+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13479+{
13480+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13481+}
13482+
13483+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13484+{
13485+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13486+}
13487+
13488 /*
13489 * Convert a virtual cached pointer to an uncached pointer
13490 */
13491diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13492index bba3cf8..06bc8da 100644
13493--- a/arch/x86/include/asm/irqflags.h
13494+++ b/arch/x86/include/asm/irqflags.h
13495@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13496 sti; \
13497 sysexit
13498
13499+#define GET_CR0_INTO_RDI mov %cr0, %rdi
13500+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13501+#define GET_CR3_INTO_RDI mov %cr3, %rdi
13502+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13503+
13504 #else
13505 #define INTERRUPT_RETURN iret
13506 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13507diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13508index d3ddd17..c9fb0cc 100644
13509--- a/arch/x86/include/asm/kprobes.h
13510+++ b/arch/x86/include/asm/kprobes.h
13511@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13512 #define RELATIVEJUMP_SIZE 5
13513 #define RELATIVECALL_OPCODE 0xe8
13514 #define RELATIVE_ADDR_SIZE 4
13515-#define MAX_STACK_SIZE 64
13516-#define MIN_STACK_SIZE(ADDR) \
13517- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13518- THREAD_SIZE - (unsigned long)(ADDR))) \
13519- ? (MAX_STACK_SIZE) \
13520- : (((unsigned long)current_thread_info()) + \
13521- THREAD_SIZE - (unsigned long)(ADDR)))
13522+#define MAX_STACK_SIZE 64UL
13523+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13524
13525 #define flush_insn_slot(p) do { } while (0)
13526
13527diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
13528index dc87b65..85039f9 100644
13529--- a/arch/x86/include/asm/kvm_host.h
13530+++ b/arch/x86/include/asm/kvm_host.h
13531@@ -419,8 +419,8 @@ struct kvm_vcpu_arch {
13532 gpa_t time;
13533 struct pvclock_vcpu_time_info hv_clock;
13534 unsigned int hw_tsc_khz;
13535- unsigned int time_offset;
13536- struct page *time_page;
13537+ struct gfn_to_hva_cache pv_time;
13538+ bool pv_time_enabled;
13539 /* set guest stopped flag in pvclock flags field */
13540 bool pvclock_set_guest_stopped_request;
13541
13542diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13543index 2d89e39..baee879 100644
13544--- a/arch/x86/include/asm/local.h
13545+++ b/arch/x86/include/asm/local.h
13546@@ -10,33 +10,97 @@ typedef struct {
13547 atomic_long_t a;
13548 } local_t;
13549
13550+typedef struct {
13551+ atomic_long_unchecked_t a;
13552+} local_unchecked_t;
13553+
13554 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13555
13556 #define local_read(l) atomic_long_read(&(l)->a)
13557+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13558 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13559+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13560
13561 static inline void local_inc(local_t *l)
13562 {
13563- asm volatile(_ASM_INC "%0"
13564+ asm volatile(_ASM_INC "%0\n"
13565+
13566+#ifdef CONFIG_PAX_REFCOUNT
13567+ "jno 0f\n"
13568+ _ASM_DEC "%0\n"
13569+ "int $4\n0:\n"
13570+ _ASM_EXTABLE(0b, 0b)
13571+#endif
13572+
13573+ : "+m" (l->a.counter));
13574+}
13575+
13576+static inline void local_inc_unchecked(local_unchecked_t *l)
13577+{
13578+ asm volatile(_ASM_INC "%0\n"
13579 : "+m" (l->a.counter));
13580 }
13581
13582 static inline void local_dec(local_t *l)
13583 {
13584- asm volatile(_ASM_DEC "%0"
13585+ asm volatile(_ASM_DEC "%0\n"
13586+
13587+#ifdef CONFIG_PAX_REFCOUNT
13588+ "jno 0f\n"
13589+ _ASM_INC "%0\n"
13590+ "int $4\n0:\n"
13591+ _ASM_EXTABLE(0b, 0b)
13592+#endif
13593+
13594+ : "+m" (l->a.counter));
13595+}
13596+
13597+static inline void local_dec_unchecked(local_unchecked_t *l)
13598+{
13599+ asm volatile(_ASM_DEC "%0\n"
13600 : "+m" (l->a.counter));
13601 }
13602
13603 static inline void local_add(long i, local_t *l)
13604 {
13605- asm volatile(_ASM_ADD "%1,%0"
13606+ asm volatile(_ASM_ADD "%1,%0\n"
13607+
13608+#ifdef CONFIG_PAX_REFCOUNT
13609+ "jno 0f\n"
13610+ _ASM_SUB "%1,%0\n"
13611+ "int $4\n0:\n"
13612+ _ASM_EXTABLE(0b, 0b)
13613+#endif
13614+
13615+ : "+m" (l->a.counter)
13616+ : "ir" (i));
13617+}
13618+
13619+static inline void local_add_unchecked(long i, local_unchecked_t *l)
13620+{
13621+ asm volatile(_ASM_ADD "%1,%0\n"
13622 : "+m" (l->a.counter)
13623 : "ir" (i));
13624 }
13625
13626 static inline void local_sub(long i, local_t *l)
13627 {
13628- asm volatile(_ASM_SUB "%1,%0"
13629+ asm volatile(_ASM_SUB "%1,%0\n"
13630+
13631+#ifdef CONFIG_PAX_REFCOUNT
13632+ "jno 0f\n"
13633+ _ASM_ADD "%1,%0\n"
13634+ "int $4\n0:\n"
13635+ _ASM_EXTABLE(0b, 0b)
13636+#endif
13637+
13638+ : "+m" (l->a.counter)
13639+ : "ir" (i));
13640+}
13641+
13642+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13643+{
13644+ asm volatile(_ASM_SUB "%1,%0\n"
13645 : "+m" (l->a.counter)
13646 : "ir" (i));
13647 }
13648@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13649 {
13650 unsigned char c;
13651
13652- asm volatile(_ASM_SUB "%2,%0; sete %1"
13653+ asm volatile(_ASM_SUB "%2,%0\n"
13654+
13655+#ifdef CONFIG_PAX_REFCOUNT
13656+ "jno 0f\n"
13657+ _ASM_ADD "%2,%0\n"
13658+ "int $4\n0:\n"
13659+ _ASM_EXTABLE(0b, 0b)
13660+#endif
13661+
13662+ "sete %1\n"
13663 : "+m" (l->a.counter), "=qm" (c)
13664 : "ir" (i) : "memory");
13665 return c;
13666@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13667 {
13668 unsigned char c;
13669
13670- asm volatile(_ASM_DEC "%0; sete %1"
13671+ asm volatile(_ASM_DEC "%0\n"
13672+
13673+#ifdef CONFIG_PAX_REFCOUNT
13674+ "jno 0f\n"
13675+ _ASM_INC "%0\n"
13676+ "int $4\n0:\n"
13677+ _ASM_EXTABLE(0b, 0b)
13678+#endif
13679+
13680+ "sete %1\n"
13681 : "+m" (l->a.counter), "=qm" (c)
13682 : : "memory");
13683 return c != 0;
13684@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13685 {
13686 unsigned char c;
13687
13688- asm volatile(_ASM_INC "%0; sete %1"
13689+ asm volatile(_ASM_INC "%0\n"
13690+
13691+#ifdef CONFIG_PAX_REFCOUNT
13692+ "jno 0f\n"
13693+ _ASM_DEC "%0\n"
13694+ "int $4\n0:\n"
13695+ _ASM_EXTABLE(0b, 0b)
13696+#endif
13697+
13698+ "sete %1\n"
13699 : "+m" (l->a.counter), "=qm" (c)
13700 : : "memory");
13701 return c != 0;
13702@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13703 {
13704 unsigned char c;
13705
13706- asm volatile(_ASM_ADD "%2,%0; sets %1"
13707+ asm volatile(_ASM_ADD "%2,%0\n"
13708+
13709+#ifdef CONFIG_PAX_REFCOUNT
13710+ "jno 0f\n"
13711+ _ASM_SUB "%2,%0\n"
13712+ "int $4\n0:\n"
13713+ _ASM_EXTABLE(0b, 0b)
13714+#endif
13715+
13716+ "sets %1\n"
13717 : "+m" (l->a.counter), "=qm" (c)
13718 : "ir" (i) : "memory");
13719 return c;
13720@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13721 static inline long local_add_return(long i, local_t *l)
13722 {
13723 long __i = i;
13724+ asm volatile(_ASM_XADD "%0, %1\n"
13725+
13726+#ifdef CONFIG_PAX_REFCOUNT
13727+ "jno 0f\n"
13728+ _ASM_MOV "%0,%1\n"
13729+ "int $4\n0:\n"
13730+ _ASM_EXTABLE(0b, 0b)
13731+#endif
13732+
13733+ : "+r" (i), "+m" (l->a.counter)
13734+ : : "memory");
13735+ return i + __i;
13736+}
13737+
13738+/**
13739+ * local_add_return_unchecked - add and return
13740+ * @i: integer value to add
13741+ * @l: pointer to type local_unchecked_t
13742+ *
13743+ * Atomically adds @i to @l and returns @i + @l
13744+ */
13745+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13746+{
13747+ long __i = i;
13748 asm volatile(_ASM_XADD "%0, %1;"
13749 : "+r" (i), "+m" (l->a.counter)
13750 : : "memory");
13751@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13752
13753 #define local_cmpxchg(l, o, n) \
13754 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13755+#define local_cmpxchg_unchecked(l, o, n) \
13756+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
13757 /* Always has a lock prefix */
13758 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13759
13760diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13761new file mode 100644
13762index 0000000..2bfd3ba
13763--- /dev/null
13764+++ b/arch/x86/include/asm/mman.h
13765@@ -0,0 +1,15 @@
13766+#ifndef _X86_MMAN_H
13767+#define _X86_MMAN_H
13768+
13769+#include <uapi/asm/mman.h>
13770+
13771+#ifdef __KERNEL__
13772+#ifndef __ASSEMBLY__
13773+#ifdef CONFIG_X86_32
13774+#define arch_mmap_check i386_mmap_check
13775+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13776+#endif
13777+#endif
13778+#endif
13779+
13780+#endif /* X86_MMAN_H */
13781diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13782index 5f55e69..e20bfb1 100644
13783--- a/arch/x86/include/asm/mmu.h
13784+++ b/arch/x86/include/asm/mmu.h
13785@@ -9,7 +9,7 @@
13786 * we put the segment information here.
13787 */
13788 typedef struct {
13789- void *ldt;
13790+ struct desc_struct *ldt;
13791 int size;
13792
13793 #ifdef CONFIG_X86_64
13794@@ -18,7 +18,19 @@ typedef struct {
13795 #endif
13796
13797 struct mutex lock;
13798- void *vdso;
13799+ unsigned long vdso;
13800+
13801+#ifdef CONFIG_X86_32
13802+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13803+ unsigned long user_cs_base;
13804+ unsigned long user_cs_limit;
13805+
13806+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13807+ cpumask_t cpu_user_cs_mask;
13808+#endif
13809+
13810+#endif
13811+#endif
13812 } mm_context_t;
13813
13814 #ifdef CONFIG_SMP
13815diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13816index cdbf367..adb37ac 100644
13817--- a/arch/x86/include/asm/mmu_context.h
13818+++ b/arch/x86/include/asm/mmu_context.h
13819@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13820
13821 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13822 {
13823+
13824+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13825+ unsigned int i;
13826+ pgd_t *pgd;
13827+
13828+ pax_open_kernel();
13829+ pgd = get_cpu_pgd(smp_processor_id());
13830+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13831+ set_pgd_batched(pgd+i, native_make_pgd(0));
13832+ pax_close_kernel();
13833+#endif
13834+
13835 #ifdef CONFIG_SMP
13836 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13837 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13838@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13839 struct task_struct *tsk)
13840 {
13841 unsigned cpu = smp_processor_id();
13842+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13843+ int tlbstate = TLBSTATE_OK;
13844+#endif
13845
13846 if (likely(prev != next)) {
13847 #ifdef CONFIG_SMP
13848+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13849+ tlbstate = this_cpu_read(cpu_tlbstate.state);
13850+#endif
13851 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13852 this_cpu_write(cpu_tlbstate.active_mm, next);
13853 #endif
13854 cpumask_set_cpu(cpu, mm_cpumask(next));
13855
13856 /* Re-load page tables */
13857+#ifdef CONFIG_PAX_PER_CPU_PGD
13858+ pax_open_kernel();
13859+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13860+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13861+ pax_close_kernel();
13862+ load_cr3(get_cpu_pgd(cpu));
13863+#else
13864 load_cr3(next->pgd);
13865+#endif
13866
13867 /* stop flush ipis for the previous mm */
13868 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13869@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13870 */
13871 if (unlikely(prev->context.ldt != next->context.ldt))
13872 load_LDT_nolock(&next->context);
13873- }
13874+
13875+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13876+ if (!(__supported_pte_mask & _PAGE_NX)) {
13877+ smp_mb__before_clear_bit();
13878+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13879+ smp_mb__after_clear_bit();
13880+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13881+ }
13882+#endif
13883+
13884+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13885+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13886+ prev->context.user_cs_limit != next->context.user_cs_limit))
13887+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13888 #ifdef CONFIG_SMP
13889+ else if (unlikely(tlbstate != TLBSTATE_OK))
13890+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13891+#endif
13892+#endif
13893+
13894+ }
13895 else {
13896+
13897+#ifdef CONFIG_PAX_PER_CPU_PGD
13898+ pax_open_kernel();
13899+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13900+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13901+ pax_close_kernel();
13902+ load_cr3(get_cpu_pgd(cpu));
13903+#endif
13904+
13905+#ifdef CONFIG_SMP
13906 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13907 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
13908
13909@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13910 * tlb flush IPI delivery. We must reload CR3
13911 * to make sure to use no freed page tables.
13912 */
13913+
13914+#ifndef CONFIG_PAX_PER_CPU_PGD
13915 load_cr3(next->pgd);
13916+#endif
13917+
13918 load_LDT_nolock(&next->context);
13919+
13920+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
13921+ if (!(__supported_pte_mask & _PAGE_NX))
13922+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13923+#endif
13924+
13925+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13926+#ifdef CONFIG_PAX_PAGEEXEC
13927+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
13928+#endif
13929+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13930+#endif
13931+
13932 }
13933+#endif
13934 }
13935-#endif
13936 }
13937
13938 #define activate_mm(prev, next) \
13939diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
13940index e3b7819..b257c64 100644
13941--- a/arch/x86/include/asm/module.h
13942+++ b/arch/x86/include/asm/module.h
13943@@ -5,6 +5,7 @@
13944
13945 #ifdef CONFIG_X86_64
13946 /* X86_64 does not define MODULE_PROC_FAMILY */
13947+#define MODULE_PROC_FAMILY ""
13948 #elif defined CONFIG_M486
13949 #define MODULE_PROC_FAMILY "486 "
13950 #elif defined CONFIG_M586
13951@@ -57,8 +58,20 @@
13952 #error unknown processor family
13953 #endif
13954
13955-#ifdef CONFIG_X86_32
13956-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
13957+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13958+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
13959+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
13960+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
13961+#else
13962+#define MODULE_PAX_KERNEXEC ""
13963 #endif
13964
13965+#ifdef CONFIG_PAX_MEMORY_UDEREF
13966+#define MODULE_PAX_UDEREF "UDEREF "
13967+#else
13968+#define MODULE_PAX_UDEREF ""
13969+#endif
13970+
13971+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
13972+
13973 #endif /* _ASM_X86_MODULE_H */
13974diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
13975index c0fa356..07a498a 100644
13976--- a/arch/x86/include/asm/nmi.h
13977+++ b/arch/x86/include/asm/nmi.h
13978@@ -42,11 +42,11 @@ struct nmiaction {
13979 nmi_handler_t handler;
13980 unsigned long flags;
13981 const char *name;
13982-};
13983+} __do_const;
13984
13985 #define register_nmi_handler(t, fn, fg, n, init...) \
13986 ({ \
13987- static struct nmiaction init fn##_na = { \
13988+ static const struct nmiaction init fn##_na = { \
13989 .handler = (fn), \
13990 .name = (n), \
13991 .flags = (fg), \
13992@@ -54,7 +54,7 @@ struct nmiaction {
13993 __register_nmi_handler((t), &fn##_na); \
13994 })
13995
13996-int __register_nmi_handler(unsigned int, struct nmiaction *);
13997+int __register_nmi_handler(unsigned int, const struct nmiaction *);
13998
13999 void unregister_nmi_handler(unsigned int, const char *);
14000
14001diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
14002index 320f7bb..e89f8f8 100644
14003--- a/arch/x86/include/asm/page_64_types.h
14004+++ b/arch/x86/include/asm/page_64_types.h
14005@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
14006
14007 /* duplicated to the one in bootmem.h */
14008 extern unsigned long max_pfn;
14009-extern unsigned long phys_base;
14010+extern const unsigned long phys_base;
14011
14012 extern unsigned long __phys_addr(unsigned long);
14013 #define __phys_reloc_hide(x) (x)
14014diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
14015index 5edd174..c395822 100644
14016--- a/arch/x86/include/asm/paravirt.h
14017+++ b/arch/x86/include/asm/paravirt.h
14018@@ -564,7 +564,7 @@ static inline pmd_t __pmd(pmdval_t val)
14019 return (pmd_t) { ret };
14020 }
14021
14022-static inline pmdval_t pmd_val(pmd_t pmd)
14023+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
14024 {
14025 pmdval_t ret;
14026
14027@@ -630,6 +630,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
14028 val);
14029 }
14030
14031+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14032+{
14033+ pgdval_t val = native_pgd_val(pgd);
14034+
14035+ if (sizeof(pgdval_t) > sizeof(long))
14036+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
14037+ val, (u64)val >> 32);
14038+ else
14039+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
14040+ val);
14041+}
14042+
14043 static inline void pgd_clear(pgd_t *pgdp)
14044 {
14045 set_pgd(pgdp, __pgd(0));
14046@@ -711,6 +723,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
14047 pv_mmu_ops.set_fixmap(idx, phys, flags);
14048 }
14049
14050+#ifdef CONFIG_PAX_KERNEXEC
14051+static inline unsigned long pax_open_kernel(void)
14052+{
14053+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
14054+}
14055+
14056+static inline unsigned long pax_close_kernel(void)
14057+{
14058+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
14059+}
14060+#else
14061+static inline unsigned long pax_open_kernel(void) { return 0; }
14062+static inline unsigned long pax_close_kernel(void) { return 0; }
14063+#endif
14064+
14065 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
14066
14067 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
14068@@ -927,7 +954,7 @@ extern void default_banner(void);
14069
14070 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
14071 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
14072-#define PARA_INDIRECT(addr) *%cs:addr
14073+#define PARA_INDIRECT(addr) *%ss:addr
14074 #endif
14075
14076 #define INTERRUPT_RETURN \
14077@@ -1002,6 +1029,21 @@ extern void default_banner(void);
14078 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
14079 CLBR_NONE, \
14080 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
14081+
14082+#define GET_CR0_INTO_RDI \
14083+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
14084+ mov %rax,%rdi
14085+
14086+#define SET_RDI_INTO_CR0 \
14087+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14088+
14089+#define GET_CR3_INTO_RDI \
14090+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
14091+ mov %rax,%rdi
14092+
14093+#define SET_RDI_INTO_CR3 \
14094+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
14095+
14096 #endif /* CONFIG_X86_32 */
14097
14098 #endif /* __ASSEMBLY__ */
14099diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
14100index 142236e..5446ffbc 100644
14101--- a/arch/x86/include/asm/paravirt_types.h
14102+++ b/arch/x86/include/asm/paravirt_types.h
14103@@ -84,7 +84,7 @@ struct pv_init_ops {
14104 */
14105 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
14106 unsigned long addr, unsigned len);
14107-};
14108+} __no_const;
14109
14110
14111 struct pv_lazy_ops {
14112@@ -97,7 +97,7 @@ struct pv_time_ops {
14113 unsigned long long (*sched_clock)(void);
14114 unsigned long long (*steal_clock)(int cpu);
14115 unsigned long (*get_tsc_khz)(void);
14116-};
14117+} __no_const;
14118
14119 struct pv_cpu_ops {
14120 /* hooks for various privileged instructions */
14121@@ -191,7 +191,7 @@ struct pv_cpu_ops {
14122
14123 void (*start_context_switch)(struct task_struct *prev);
14124 void (*end_context_switch)(struct task_struct *next);
14125-};
14126+} __no_const;
14127
14128 struct pv_irq_ops {
14129 /*
14130@@ -222,7 +222,7 @@ struct pv_apic_ops {
14131 unsigned long start_eip,
14132 unsigned long start_esp);
14133 #endif
14134-};
14135+} __no_const;
14136
14137 struct pv_mmu_ops {
14138 unsigned long (*read_cr2)(void);
14139@@ -312,6 +312,7 @@ struct pv_mmu_ops {
14140 struct paravirt_callee_save make_pud;
14141
14142 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
14143+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
14144 #endif /* PAGETABLE_LEVELS == 4 */
14145 #endif /* PAGETABLE_LEVELS >= 3 */
14146
14147@@ -323,6 +324,12 @@ struct pv_mmu_ops {
14148 an mfn. We can tell which is which from the index. */
14149 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
14150 phys_addr_t phys, pgprot_t flags);
14151+
14152+#ifdef CONFIG_PAX_KERNEXEC
14153+ unsigned long (*pax_open_kernel)(void);
14154+ unsigned long (*pax_close_kernel)(void);
14155+#endif
14156+
14157 };
14158
14159 struct arch_spinlock;
14160@@ -333,7 +340,7 @@ struct pv_lock_ops {
14161 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
14162 int (*spin_trylock)(struct arch_spinlock *lock);
14163 void (*spin_unlock)(struct arch_spinlock *lock);
14164-};
14165+} __no_const;
14166
14167 /* This contains all the paravirt structures: we get a convenient
14168 * number for each function using the offset which we use to indicate
14169diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
14170index b4389a4..7024269 100644
14171--- a/arch/x86/include/asm/pgalloc.h
14172+++ b/arch/x86/include/asm/pgalloc.h
14173@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
14174 pmd_t *pmd, pte_t *pte)
14175 {
14176 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14177+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
14178+}
14179+
14180+static inline void pmd_populate_user(struct mm_struct *mm,
14181+ pmd_t *pmd, pte_t *pte)
14182+{
14183+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14184 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
14185 }
14186
14187@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
14188
14189 #ifdef CONFIG_X86_PAE
14190 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
14191+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
14192+{
14193+ pud_populate(mm, pudp, pmd);
14194+}
14195 #else /* !CONFIG_X86_PAE */
14196 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14197 {
14198 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14199 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
14200 }
14201+
14202+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14203+{
14204+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14205+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
14206+}
14207 #endif /* CONFIG_X86_PAE */
14208
14209 #if PAGETABLE_LEVELS > 3
14210@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14211 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
14212 }
14213
14214+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14215+{
14216+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
14217+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
14218+}
14219+
14220 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
14221 {
14222 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
14223diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
14224index f2b489c..4f7e2e5 100644
14225--- a/arch/x86/include/asm/pgtable-2level.h
14226+++ b/arch/x86/include/asm/pgtable-2level.h
14227@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
14228
14229 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14230 {
14231+ pax_open_kernel();
14232 *pmdp = pmd;
14233+ pax_close_kernel();
14234 }
14235
14236 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14237diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
14238index 4cc9f2b..5fd9226 100644
14239--- a/arch/x86/include/asm/pgtable-3level.h
14240+++ b/arch/x86/include/asm/pgtable-3level.h
14241@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14242
14243 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14244 {
14245+ pax_open_kernel();
14246 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
14247+ pax_close_kernel();
14248 }
14249
14250 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14251 {
14252+ pax_open_kernel();
14253 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
14254+ pax_close_kernel();
14255 }
14256
14257 /*
14258diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
14259index 1c1a955..50f828c 100644
14260--- a/arch/x86/include/asm/pgtable.h
14261+++ b/arch/x86/include/asm/pgtable.h
14262@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14263
14264 #ifndef __PAGETABLE_PUD_FOLDED
14265 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
14266+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
14267 #define pgd_clear(pgd) native_pgd_clear(pgd)
14268 #endif
14269
14270@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14271
14272 #define arch_end_context_switch(prev) do {} while(0)
14273
14274+#define pax_open_kernel() native_pax_open_kernel()
14275+#define pax_close_kernel() native_pax_close_kernel()
14276 #endif /* CONFIG_PARAVIRT */
14277
14278+#define __HAVE_ARCH_PAX_OPEN_KERNEL
14279+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
14280+
14281+#ifdef CONFIG_PAX_KERNEXEC
14282+static inline unsigned long native_pax_open_kernel(void)
14283+{
14284+ unsigned long cr0;
14285+
14286+ preempt_disable();
14287+ barrier();
14288+ cr0 = read_cr0() ^ X86_CR0_WP;
14289+ BUG_ON(cr0 & X86_CR0_WP);
14290+ write_cr0(cr0);
14291+ return cr0 ^ X86_CR0_WP;
14292+}
14293+
14294+static inline unsigned long native_pax_close_kernel(void)
14295+{
14296+ unsigned long cr0;
14297+
14298+ cr0 = read_cr0() ^ X86_CR0_WP;
14299+ BUG_ON(!(cr0 & X86_CR0_WP));
14300+ write_cr0(cr0);
14301+ barrier();
14302+ preempt_enable_no_resched();
14303+ return cr0 ^ X86_CR0_WP;
14304+}
14305+#else
14306+static inline unsigned long native_pax_open_kernel(void) { return 0; }
14307+static inline unsigned long native_pax_close_kernel(void) { return 0; }
14308+#endif
14309+
14310 /*
14311 * The following only work if pte_present() is true.
14312 * Undefined behaviour if not..
14313 */
14314+static inline int pte_user(pte_t pte)
14315+{
14316+ return pte_val(pte) & _PAGE_USER;
14317+}
14318+
14319 static inline int pte_dirty(pte_t pte)
14320 {
14321 return pte_flags(pte) & _PAGE_DIRTY;
14322@@ -200,9 +240,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
14323 return pte_clear_flags(pte, _PAGE_RW);
14324 }
14325
14326+static inline pte_t pte_mkread(pte_t pte)
14327+{
14328+ return __pte(pte_val(pte) | _PAGE_USER);
14329+}
14330+
14331 static inline pte_t pte_mkexec(pte_t pte)
14332 {
14333- return pte_clear_flags(pte, _PAGE_NX);
14334+#ifdef CONFIG_X86_PAE
14335+ if (__supported_pte_mask & _PAGE_NX)
14336+ return pte_clear_flags(pte, _PAGE_NX);
14337+ else
14338+#endif
14339+ return pte_set_flags(pte, _PAGE_USER);
14340+}
14341+
14342+static inline pte_t pte_exprotect(pte_t pte)
14343+{
14344+#ifdef CONFIG_X86_PAE
14345+ if (__supported_pte_mask & _PAGE_NX)
14346+ return pte_set_flags(pte, _PAGE_NX);
14347+ else
14348+#endif
14349+ return pte_clear_flags(pte, _PAGE_USER);
14350 }
14351
14352 static inline pte_t pte_mkdirty(pte_t pte)
14353@@ -394,6 +454,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
14354 #endif
14355
14356 #ifndef __ASSEMBLY__
14357+
14358+#ifdef CONFIG_PAX_PER_CPU_PGD
14359+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
14360+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
14361+{
14362+ return cpu_pgd[cpu];
14363+}
14364+#endif
14365+
14366 #include <linux/mm_types.h>
14367
14368 static inline int pte_none(pte_t pte)
14369@@ -583,7 +652,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
14370
14371 static inline int pgd_bad(pgd_t pgd)
14372 {
14373- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
14374+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
14375 }
14376
14377 static inline int pgd_none(pgd_t pgd)
14378@@ -606,7 +675,12 @@ static inline int pgd_none(pgd_t pgd)
14379 * pgd_offset() returns a (pgd_t *)
14380 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
14381 */
14382-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
14383+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
14384+
14385+#ifdef CONFIG_PAX_PER_CPU_PGD
14386+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
14387+#endif
14388+
14389 /*
14390 * a shortcut which implies the use of the kernel's pgd, instead
14391 * of a process's
14392@@ -617,6 +691,20 @@ static inline int pgd_none(pgd_t pgd)
14393 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
14394 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
14395
14396+#ifdef CONFIG_X86_32
14397+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
14398+#else
14399+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
14400+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
14401+
14402+#ifdef CONFIG_PAX_MEMORY_UDEREF
14403+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
14404+#else
14405+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
14406+#endif
14407+
14408+#endif
14409+
14410 #ifndef __ASSEMBLY__
14411
14412 extern int direct_gbpages;
14413@@ -781,11 +869,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
14414 * dst and src can be on the same page, but the range must not overlap,
14415 * and must not cross a page boundary.
14416 */
14417-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
14418+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
14419 {
14420- memcpy(dst, src, count * sizeof(pgd_t));
14421+ pax_open_kernel();
14422+ while (count--)
14423+ *dst++ = *src++;
14424+ pax_close_kernel();
14425 }
14426
14427+#ifdef CONFIG_PAX_PER_CPU_PGD
14428+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
14429+#endif
14430+
14431+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14432+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
14433+#else
14434+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14435+#endif
14436
14437 #include <asm-generic/pgtable.h>
14438 #endif /* __ASSEMBLY__ */
14439diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14440index 8faa215..a8a17ea 100644
14441--- a/arch/x86/include/asm/pgtable_32.h
14442+++ b/arch/x86/include/asm/pgtable_32.h
14443@@ -25,9 +25,6 @@
14444 struct mm_struct;
14445 struct vm_area_struct;
14446
14447-extern pgd_t swapper_pg_dir[1024];
14448-extern pgd_t initial_page_table[1024];
14449-
14450 static inline void pgtable_cache_init(void) { }
14451 static inline void check_pgt_cache(void) { }
14452 void paging_init(void);
14453@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14454 # include <asm/pgtable-2level.h>
14455 #endif
14456
14457+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14458+extern pgd_t initial_page_table[PTRS_PER_PGD];
14459+#ifdef CONFIG_X86_PAE
14460+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14461+#endif
14462+
14463 #if defined(CONFIG_HIGHPTE)
14464 #define pte_offset_map(dir, address) \
14465 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14466@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14467 /* Clear a kernel PTE and flush it from the TLB */
14468 #define kpte_clear_flush(ptep, vaddr) \
14469 do { \
14470+ pax_open_kernel(); \
14471 pte_clear(&init_mm, (vaddr), (ptep)); \
14472+ pax_close_kernel(); \
14473 __flush_tlb_one((vaddr)); \
14474 } while (0)
14475
14476@@ -75,6 +80,9 @@ do { \
14477
14478 #endif /* !__ASSEMBLY__ */
14479
14480+#define HAVE_ARCH_UNMAPPED_AREA
14481+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14482+
14483 /*
14484 * kern_addr_valid() is (1) for FLATMEM and (0) for
14485 * SPARSEMEM and DISCONTIGMEM
14486diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14487index ed5903b..c7fe163 100644
14488--- a/arch/x86/include/asm/pgtable_32_types.h
14489+++ b/arch/x86/include/asm/pgtable_32_types.h
14490@@ -8,7 +8,7 @@
14491 */
14492 #ifdef CONFIG_X86_PAE
14493 # include <asm/pgtable-3level_types.h>
14494-# define PMD_SIZE (1UL << PMD_SHIFT)
14495+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14496 # define PMD_MASK (~(PMD_SIZE - 1))
14497 #else
14498 # include <asm/pgtable-2level_types.h>
14499@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14500 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14501 #endif
14502
14503+#ifdef CONFIG_PAX_KERNEXEC
14504+#ifndef __ASSEMBLY__
14505+extern unsigned char MODULES_EXEC_VADDR[];
14506+extern unsigned char MODULES_EXEC_END[];
14507+#endif
14508+#include <asm/boot.h>
14509+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14510+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14511+#else
14512+#define ktla_ktva(addr) (addr)
14513+#define ktva_ktla(addr) (addr)
14514+#endif
14515+
14516 #define MODULES_VADDR VMALLOC_START
14517 #define MODULES_END VMALLOC_END
14518 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14519diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14520index 47356f9..deb94a2 100644
14521--- a/arch/x86/include/asm/pgtable_64.h
14522+++ b/arch/x86/include/asm/pgtable_64.h
14523@@ -16,10 +16,14 @@
14524
14525 extern pud_t level3_kernel_pgt[512];
14526 extern pud_t level3_ident_pgt[512];
14527+extern pud_t level3_vmalloc_start_pgt[512];
14528+extern pud_t level3_vmalloc_end_pgt[512];
14529+extern pud_t level3_vmemmap_pgt[512];
14530+extern pud_t level2_vmemmap_pgt[512];
14531 extern pmd_t level2_kernel_pgt[512];
14532 extern pmd_t level2_fixmap_pgt[512];
14533-extern pmd_t level2_ident_pgt[512];
14534-extern pgd_t init_level4_pgt[];
14535+extern pmd_t level2_ident_pgt[512*2];
14536+extern pgd_t init_level4_pgt[512];
14537
14538 #define swapper_pg_dir init_level4_pgt
14539
14540@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14541
14542 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14543 {
14544+ pax_open_kernel();
14545 *pmdp = pmd;
14546+ pax_close_kernel();
14547 }
14548
14549 static inline void native_pmd_clear(pmd_t *pmd)
14550@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14551
14552 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14553 {
14554+ pax_open_kernel();
14555 *pudp = pud;
14556+ pax_close_kernel();
14557 }
14558
14559 static inline void native_pud_clear(pud_t *pud)
14560@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14561
14562 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14563 {
14564+ pax_open_kernel();
14565+ *pgdp = pgd;
14566+ pax_close_kernel();
14567+}
14568+
14569+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14570+{
14571 *pgdp = pgd;
14572 }
14573
14574diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14575index 766ea16..5b96cb3 100644
14576--- a/arch/x86/include/asm/pgtable_64_types.h
14577+++ b/arch/x86/include/asm/pgtable_64_types.h
14578@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
14579 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14580 #define MODULES_END _AC(0xffffffffff000000, UL)
14581 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14582+#define MODULES_EXEC_VADDR MODULES_VADDR
14583+#define MODULES_EXEC_END MODULES_END
14584+
14585+#define ktla_ktva(addr) (addr)
14586+#define ktva_ktla(addr) (addr)
14587
14588 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
14589diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14590index 3c32db8..1ddccf5 100644
14591--- a/arch/x86/include/asm/pgtable_types.h
14592+++ b/arch/x86/include/asm/pgtable_types.h
14593@@ -16,13 +16,12 @@
14594 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14595 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14596 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14597-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14598+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14599 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14600 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14601 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14602-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14603-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14604-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14605+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14606+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14607 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14608
14609 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14610@@ -40,7 +39,6 @@
14611 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14612 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14613 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14614-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14615 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14616 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14617 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14618@@ -57,8 +55,10 @@
14619
14620 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14621 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14622-#else
14623+#elif defined(CONFIG_KMEMCHECK)
14624 #define _PAGE_NX (_AT(pteval_t, 0))
14625+#else
14626+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14627 #endif
14628
14629 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14630@@ -116,6 +116,9 @@
14631 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14632 _PAGE_ACCESSED)
14633
14634+#define PAGE_READONLY_NOEXEC PAGE_READONLY
14635+#define PAGE_SHARED_NOEXEC PAGE_SHARED
14636+
14637 #define __PAGE_KERNEL_EXEC \
14638 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14639 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14640@@ -126,7 +129,7 @@
14641 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14642 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14643 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14644-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14645+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14646 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14647 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14648 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14649@@ -188,8 +191,8 @@
14650 * bits are combined, this will alow user to access the high address mapped
14651 * VDSO in the presence of CONFIG_COMPAT_VDSO
14652 */
14653-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14654-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14655+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14656+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14657 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14658 #endif
14659
14660@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14661 {
14662 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14663 }
14664+#endif
14665
14666+#if PAGETABLE_LEVELS == 3
14667+#include <asm-generic/pgtable-nopud.h>
14668+#endif
14669+
14670+#if PAGETABLE_LEVELS == 2
14671+#include <asm-generic/pgtable-nopmd.h>
14672+#endif
14673+
14674+#ifndef __ASSEMBLY__
14675 #if PAGETABLE_LEVELS > 3
14676 typedef struct { pudval_t pud; } pud_t;
14677
14678@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14679 return pud.pud;
14680 }
14681 #else
14682-#include <asm-generic/pgtable-nopud.h>
14683-
14684 static inline pudval_t native_pud_val(pud_t pud)
14685 {
14686 return native_pgd_val(pud.pgd);
14687@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14688 return pmd.pmd;
14689 }
14690 #else
14691-#include <asm-generic/pgtable-nopmd.h>
14692-
14693 static inline pmdval_t native_pmd_val(pmd_t pmd)
14694 {
14695 return native_pgd_val(pmd.pud.pgd);
14696@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14697
14698 extern pteval_t __supported_pte_mask;
14699 extern void set_nx(void);
14700-extern int nx_enabled;
14701
14702 #define pgprot_writecombine pgprot_writecombine
14703 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14704diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14705index 888184b..a07ac89 100644
14706--- a/arch/x86/include/asm/processor.h
14707+++ b/arch/x86/include/asm/processor.h
14708@@ -287,7 +287,7 @@ struct tss_struct {
14709
14710 } ____cacheline_aligned;
14711
14712-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14713+extern struct tss_struct init_tss[NR_CPUS];
14714
14715 /*
14716 * Save the original ist values for checking stack pointers during debugging
14717@@ -827,11 +827,18 @@ static inline void spin_lock_prefetch(const void *x)
14718 */
14719 #define TASK_SIZE PAGE_OFFSET
14720 #define TASK_SIZE_MAX TASK_SIZE
14721+
14722+#ifdef CONFIG_PAX_SEGMEXEC
14723+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14724+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14725+#else
14726 #define STACK_TOP TASK_SIZE
14727-#define STACK_TOP_MAX STACK_TOP
14728+#endif
14729+
14730+#define STACK_TOP_MAX TASK_SIZE
14731
14732 #define INIT_THREAD { \
14733- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14734+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14735 .vm86_info = NULL, \
14736 .sysenter_cs = __KERNEL_CS, \
14737 .io_bitmap_ptr = NULL, \
14738@@ -845,7 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
14739 */
14740 #define INIT_TSS { \
14741 .x86_tss = { \
14742- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14743+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14744 .ss0 = __KERNEL_DS, \
14745 .ss1 = __KERNEL_CS, \
14746 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14747@@ -856,11 +863,7 @@ static inline void spin_lock_prefetch(const void *x)
14748 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14749
14750 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14751-#define KSTK_TOP(info) \
14752-({ \
14753- unsigned long *__ptr = (unsigned long *)(info); \
14754- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14755-})
14756+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14757
14758 /*
14759 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14760@@ -875,7 +878,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14761 #define task_pt_regs(task) \
14762 ({ \
14763 struct pt_regs *__regs__; \
14764- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14765+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14766 __regs__ - 1; \
14767 })
14768
14769@@ -885,13 +888,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14770 /*
14771 * User space process size. 47bits minus one guard page.
14772 */
14773-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14774+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14775
14776 /* This decides where the kernel will search for a free chunk of vm
14777 * space during mmap's.
14778 */
14779 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14780- 0xc0000000 : 0xFFFFe000)
14781+ 0xc0000000 : 0xFFFFf000)
14782
14783 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14784 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14785@@ -902,11 +905,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14786 #define STACK_TOP_MAX TASK_SIZE_MAX
14787
14788 #define INIT_THREAD { \
14789- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14790+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14791 }
14792
14793 #define INIT_TSS { \
14794- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14795+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14796 }
14797
14798 /*
14799@@ -934,6 +937,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14800 */
14801 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14802
14803+#ifdef CONFIG_PAX_SEGMEXEC
14804+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14805+#endif
14806+
14807 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14808
14809 /* Get/set a process' ability to use the timestamp counter instruction */
14810@@ -994,12 +1001,12 @@ extern bool cpu_has_amd_erratum(const int *);
14811 #define cpu_has_amd_erratum(x) (false)
14812 #endif /* CONFIG_CPU_SUP_AMD */
14813
14814-extern unsigned long arch_align_stack(unsigned long sp);
14815+#define arch_align_stack(x) ((x) & ~0xfUL)
14816 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14817
14818 void default_idle(void);
14819 bool set_pm_idle_to_default(void);
14820
14821-void stop_this_cpu(void *dummy);
14822+void stop_this_cpu(void *dummy) __noreturn;
14823
14824 #endif /* _ASM_X86_PROCESSOR_H */
14825diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14826index 942a086..6c26446 100644
14827--- a/arch/x86/include/asm/ptrace.h
14828+++ b/arch/x86/include/asm/ptrace.h
14829@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14830 }
14831
14832 /*
14833- * user_mode_vm(regs) determines whether a register set came from user mode.
14834+ * user_mode(regs) determines whether a register set came from user mode.
14835 * This is true if V8086 mode was enabled OR if the register set was from
14836 * protected mode with RPL-3 CS value. This tricky test checks that with
14837 * one comparison. Many places in the kernel can bypass this full check
14838- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14839+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14840+ * be used.
14841 */
14842-static inline int user_mode(struct pt_regs *regs)
14843+static inline int user_mode_novm(struct pt_regs *regs)
14844 {
14845 #ifdef CONFIG_X86_32
14846 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
14847 #else
14848- return !!(regs->cs & 3);
14849+ return !!(regs->cs & SEGMENT_RPL_MASK);
14850 #endif
14851 }
14852
14853-static inline int user_mode_vm(struct pt_regs *regs)
14854+static inline int user_mode(struct pt_regs *regs)
14855 {
14856 #ifdef CONFIG_X86_32
14857 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
14858 USER_RPL;
14859 #else
14860- return user_mode(regs);
14861+ return user_mode_novm(regs);
14862 #endif
14863 }
14864
14865@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
14866 #ifdef CONFIG_X86_64
14867 static inline bool user_64bit_mode(struct pt_regs *regs)
14868 {
14869+ unsigned long cs = regs->cs & 0xffff;
14870 #ifndef CONFIG_PARAVIRT
14871 /*
14872 * On non-paravirt systems, this is the only long mode CPL 3
14873 * selector. We do not allow long mode selectors in the LDT.
14874 */
14875- return regs->cs == __USER_CS;
14876+ return cs == __USER_CS;
14877 #else
14878 /* Headers are too twisted for this to go in paravirt.h. */
14879- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
14880+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
14881 #endif
14882 }
14883
14884@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
14885 * Traps from the kernel do not save sp and ss.
14886 * Use the helper function to retrieve sp.
14887 */
14888- if (offset == offsetof(struct pt_regs, sp) &&
14889- regs->cs == __KERNEL_CS)
14890- return kernel_stack_pointer(regs);
14891+ if (offset == offsetof(struct pt_regs, sp)) {
14892+ unsigned long cs = regs->cs & 0xffff;
14893+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
14894+ return kernel_stack_pointer(regs);
14895+ }
14896 #endif
14897 return *(unsigned long *)((unsigned long)regs + offset);
14898 }
14899diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
14900index fe1ec5b..dc5c3fe 100644
14901--- a/arch/x86/include/asm/realmode.h
14902+++ b/arch/x86/include/asm/realmode.h
14903@@ -22,16 +22,14 @@ struct real_mode_header {
14904 #endif
14905 /* APM/BIOS reboot */
14906 u32 machine_real_restart_asm;
14907-#ifdef CONFIG_X86_64
14908 u32 machine_real_restart_seg;
14909-#endif
14910 };
14911
14912 /* This must match data at trampoline_32/64.S */
14913 struct trampoline_header {
14914 #ifdef CONFIG_X86_32
14915 u32 start;
14916- u16 gdt_pad;
14917+ u16 boot_cs;
14918 u16 gdt_limit;
14919 u32 gdt_base;
14920 #else
14921diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
14922index a82c4f1..ac45053 100644
14923--- a/arch/x86/include/asm/reboot.h
14924+++ b/arch/x86/include/asm/reboot.h
14925@@ -6,13 +6,13 @@
14926 struct pt_regs;
14927
14928 struct machine_ops {
14929- void (*restart)(char *cmd);
14930- void (*halt)(void);
14931- void (*power_off)(void);
14932+ void (* __noreturn restart)(char *cmd);
14933+ void (* __noreturn halt)(void);
14934+ void (* __noreturn power_off)(void);
14935 void (*shutdown)(void);
14936 void (*crash_shutdown)(struct pt_regs *);
14937- void (*emergency_restart)(void);
14938-};
14939+ void (* __noreturn emergency_restart)(void);
14940+} __no_const;
14941
14942 extern struct machine_ops machine_ops;
14943
14944diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
14945index 2dbe4a7..ce1db00 100644
14946--- a/arch/x86/include/asm/rwsem.h
14947+++ b/arch/x86/include/asm/rwsem.h
14948@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
14949 {
14950 asm volatile("# beginning down_read\n\t"
14951 LOCK_PREFIX _ASM_INC "(%1)\n\t"
14952+
14953+#ifdef CONFIG_PAX_REFCOUNT
14954+ "jno 0f\n"
14955+ LOCK_PREFIX _ASM_DEC "(%1)\n"
14956+ "int $4\n0:\n"
14957+ _ASM_EXTABLE(0b, 0b)
14958+#endif
14959+
14960 /* adds 0x00000001 */
14961 " jns 1f\n"
14962 " call call_rwsem_down_read_failed\n"
14963@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
14964 "1:\n\t"
14965 " mov %1,%2\n\t"
14966 " add %3,%2\n\t"
14967+
14968+#ifdef CONFIG_PAX_REFCOUNT
14969+ "jno 0f\n"
14970+ "sub %3,%2\n"
14971+ "int $4\n0:\n"
14972+ _ASM_EXTABLE(0b, 0b)
14973+#endif
14974+
14975 " jle 2f\n\t"
14976 LOCK_PREFIX " cmpxchg %2,%0\n\t"
14977 " jnz 1b\n\t"
14978@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
14979 long tmp;
14980 asm volatile("# beginning down_write\n\t"
14981 LOCK_PREFIX " xadd %1,(%2)\n\t"
14982+
14983+#ifdef CONFIG_PAX_REFCOUNT
14984+ "jno 0f\n"
14985+ "mov %1,(%2)\n"
14986+ "int $4\n0:\n"
14987+ _ASM_EXTABLE(0b, 0b)
14988+#endif
14989+
14990 /* adds 0xffff0001, returns the old value */
14991 " test %1,%1\n\t"
14992 /* was the count 0 before? */
14993@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
14994 long tmp;
14995 asm volatile("# beginning __up_read\n\t"
14996 LOCK_PREFIX " xadd %1,(%2)\n\t"
14997+
14998+#ifdef CONFIG_PAX_REFCOUNT
14999+ "jno 0f\n"
15000+ "mov %1,(%2)\n"
15001+ "int $4\n0:\n"
15002+ _ASM_EXTABLE(0b, 0b)
15003+#endif
15004+
15005 /* subtracts 1, returns the old value */
15006 " jns 1f\n\t"
15007 " call call_rwsem_wake\n" /* expects old value in %edx */
15008@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
15009 long tmp;
15010 asm volatile("# beginning __up_write\n\t"
15011 LOCK_PREFIX " xadd %1,(%2)\n\t"
15012+
15013+#ifdef CONFIG_PAX_REFCOUNT
15014+ "jno 0f\n"
15015+ "mov %1,(%2)\n"
15016+ "int $4\n0:\n"
15017+ _ASM_EXTABLE(0b, 0b)
15018+#endif
15019+
15020 /* subtracts 0xffff0001, returns the old value */
15021 " jns 1f\n\t"
15022 " call call_rwsem_wake\n" /* expects old value in %edx */
15023@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15024 {
15025 asm volatile("# beginning __downgrade_write\n\t"
15026 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
15027+
15028+#ifdef CONFIG_PAX_REFCOUNT
15029+ "jno 0f\n"
15030+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
15031+ "int $4\n0:\n"
15032+ _ASM_EXTABLE(0b, 0b)
15033+#endif
15034+
15035 /*
15036 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
15037 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
15038@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15039 */
15040 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15041 {
15042- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
15043+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
15044+
15045+#ifdef CONFIG_PAX_REFCOUNT
15046+ "jno 0f\n"
15047+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
15048+ "int $4\n0:\n"
15049+ _ASM_EXTABLE(0b, 0b)
15050+#endif
15051+
15052 : "+m" (sem->count)
15053 : "er" (delta));
15054 }
15055@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15056 */
15057 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
15058 {
15059- return delta + xadd(&sem->count, delta);
15060+ return delta + xadd_check_overflow(&sem->count, delta);
15061 }
15062
15063 #endif /* __KERNEL__ */
15064diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
15065index c48a950..c6d7468 100644
15066--- a/arch/x86/include/asm/segment.h
15067+++ b/arch/x86/include/asm/segment.h
15068@@ -64,10 +64,15 @@
15069 * 26 - ESPFIX small SS
15070 * 27 - per-cpu [ offset to per-cpu data area ]
15071 * 28 - stack_canary-20 [ for stack protector ]
15072- * 29 - unused
15073- * 30 - unused
15074+ * 29 - PCI BIOS CS
15075+ * 30 - PCI BIOS DS
15076 * 31 - TSS for double fault handler
15077 */
15078+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
15079+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
15080+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
15081+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
15082+
15083 #define GDT_ENTRY_TLS_MIN 6
15084 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
15085
15086@@ -79,6 +84,8 @@
15087
15088 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
15089
15090+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
15091+
15092 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
15093
15094 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
15095@@ -104,6 +111,12 @@
15096 #define __KERNEL_STACK_CANARY 0
15097 #endif
15098
15099+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
15100+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
15101+
15102+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
15103+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
15104+
15105 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
15106
15107 /*
15108@@ -141,7 +154,7 @@
15109 */
15110
15111 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
15112-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
15113+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
15114
15115
15116 #else
15117@@ -165,6 +178,8 @@
15118 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
15119 #define __USER32_DS __USER_DS
15120
15121+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
15122+
15123 #define GDT_ENTRY_TSS 8 /* needs two entries */
15124 #define GDT_ENTRY_LDT 10 /* needs two entries */
15125 #define GDT_ENTRY_TLS_MIN 12
15126@@ -185,6 +200,7 @@
15127 #endif
15128
15129 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
15130+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
15131 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
15132 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
15133 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
15134@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
15135 {
15136 unsigned long __limit;
15137 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
15138- return __limit + 1;
15139+ return __limit;
15140 }
15141
15142 #endif /* !__ASSEMBLY__ */
15143diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
15144index b073aae..39f9bdd 100644
15145--- a/arch/x86/include/asm/smp.h
15146+++ b/arch/x86/include/asm/smp.h
15147@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
15148 /* cpus sharing the last level cache: */
15149 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
15150 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
15151-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
15152+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
15153
15154 static inline struct cpumask *cpu_sibling_mask(int cpu)
15155 {
15156@@ -79,7 +79,7 @@ struct smp_ops {
15157
15158 void (*send_call_func_ipi)(const struct cpumask *mask);
15159 void (*send_call_func_single_ipi)(int cpu);
15160-};
15161+} __no_const;
15162
15163 /* Globals due to paravirt */
15164 extern void set_cpu_sibling_map(int cpu);
15165@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
15166 extern int safe_smp_processor_id(void);
15167
15168 #elif defined(CONFIG_X86_64_SMP)
15169-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15170-
15171-#define stack_smp_processor_id() \
15172-({ \
15173- struct thread_info *ti; \
15174- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
15175- ti->cpu; \
15176-})
15177+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15178+#define stack_smp_processor_id() raw_smp_processor_id()
15179 #define safe_smp_processor_id() smp_processor_id()
15180
15181 #endif
15182diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
15183index 33692ea..350a534 100644
15184--- a/arch/x86/include/asm/spinlock.h
15185+++ b/arch/x86/include/asm/spinlock.h
15186@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
15187 static inline void arch_read_lock(arch_rwlock_t *rw)
15188 {
15189 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
15190+
15191+#ifdef CONFIG_PAX_REFCOUNT
15192+ "jno 0f\n"
15193+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
15194+ "int $4\n0:\n"
15195+ _ASM_EXTABLE(0b, 0b)
15196+#endif
15197+
15198 "jns 1f\n"
15199 "call __read_lock_failed\n\t"
15200 "1:\n"
15201@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
15202 static inline void arch_write_lock(arch_rwlock_t *rw)
15203 {
15204 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
15205+
15206+#ifdef CONFIG_PAX_REFCOUNT
15207+ "jno 0f\n"
15208+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
15209+ "int $4\n0:\n"
15210+ _ASM_EXTABLE(0b, 0b)
15211+#endif
15212+
15213 "jz 1f\n"
15214 "call __write_lock_failed\n\t"
15215 "1:\n"
15216@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
15217
15218 static inline void arch_read_unlock(arch_rwlock_t *rw)
15219 {
15220- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
15221+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
15222+
15223+#ifdef CONFIG_PAX_REFCOUNT
15224+ "jno 0f\n"
15225+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
15226+ "int $4\n0:\n"
15227+ _ASM_EXTABLE(0b, 0b)
15228+#endif
15229+
15230 :"+m" (rw->lock) : : "memory");
15231 }
15232
15233 static inline void arch_write_unlock(arch_rwlock_t *rw)
15234 {
15235- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
15236+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
15237+
15238+#ifdef CONFIG_PAX_REFCOUNT
15239+ "jno 0f\n"
15240+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
15241+ "int $4\n0:\n"
15242+ _ASM_EXTABLE(0b, 0b)
15243+#endif
15244+
15245 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
15246 }
15247
15248diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
15249index 6a99859..03cb807 100644
15250--- a/arch/x86/include/asm/stackprotector.h
15251+++ b/arch/x86/include/asm/stackprotector.h
15252@@ -47,7 +47,7 @@
15253 * head_32 for boot CPU and setup_per_cpu_areas() for others.
15254 */
15255 #define GDT_STACK_CANARY_INIT \
15256- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
15257+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
15258
15259 /*
15260 * Initialize the stackprotector canary value.
15261@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
15262
15263 static inline void load_stack_canary_segment(void)
15264 {
15265-#ifdef CONFIG_X86_32
15266+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
15267 asm volatile ("mov %0, %%gs" : : "r" (0));
15268 #endif
15269 }
15270diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
15271index 70bbe39..4ae2bd4 100644
15272--- a/arch/x86/include/asm/stacktrace.h
15273+++ b/arch/x86/include/asm/stacktrace.h
15274@@ -11,28 +11,20 @@
15275
15276 extern int kstack_depth_to_print;
15277
15278-struct thread_info;
15279+struct task_struct;
15280 struct stacktrace_ops;
15281
15282-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
15283- unsigned long *stack,
15284- unsigned long bp,
15285- const struct stacktrace_ops *ops,
15286- void *data,
15287- unsigned long *end,
15288- int *graph);
15289+typedef unsigned long walk_stack_t(struct task_struct *task,
15290+ void *stack_start,
15291+ unsigned long *stack,
15292+ unsigned long bp,
15293+ const struct stacktrace_ops *ops,
15294+ void *data,
15295+ unsigned long *end,
15296+ int *graph);
15297
15298-extern unsigned long
15299-print_context_stack(struct thread_info *tinfo,
15300- unsigned long *stack, unsigned long bp,
15301- const struct stacktrace_ops *ops, void *data,
15302- unsigned long *end, int *graph);
15303-
15304-extern unsigned long
15305-print_context_stack_bp(struct thread_info *tinfo,
15306- unsigned long *stack, unsigned long bp,
15307- const struct stacktrace_ops *ops, void *data,
15308- unsigned long *end, int *graph);
15309+extern walk_stack_t print_context_stack;
15310+extern walk_stack_t print_context_stack_bp;
15311
15312 /* Generic stack tracer with callbacks */
15313
15314@@ -40,7 +32,7 @@ struct stacktrace_ops {
15315 void (*address)(void *data, unsigned long address, int reliable);
15316 /* On negative return stop dumping */
15317 int (*stack)(void *data, char *name);
15318- walk_stack_t walk_stack;
15319+ walk_stack_t *walk_stack;
15320 };
15321
15322 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
15323diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
15324index 4ec45b3..a4f0a8a 100644
15325--- a/arch/x86/include/asm/switch_to.h
15326+++ b/arch/x86/include/asm/switch_to.h
15327@@ -108,7 +108,7 @@ do { \
15328 "call __switch_to\n\t" \
15329 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
15330 __switch_canary \
15331- "movq %P[thread_info](%%rsi),%%r8\n\t" \
15332+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
15333 "movq %%rax,%%rdi\n\t" \
15334 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
15335 "jnz ret_from_fork\n\t" \
15336@@ -119,7 +119,7 @@ do { \
15337 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
15338 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
15339 [_tif_fork] "i" (_TIF_FORK), \
15340- [thread_info] "i" (offsetof(struct task_struct, stack)), \
15341+ [thread_info] "m" (current_tinfo), \
15342 [current_task] "m" (current_task) \
15343 __switch_canary_iparam \
15344 : "memory", "cc" __EXTRA_CLOBBER)
15345diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
15346index 2d946e6..e453ec4 100644
15347--- a/arch/x86/include/asm/thread_info.h
15348+++ b/arch/x86/include/asm/thread_info.h
15349@@ -10,6 +10,7 @@
15350 #include <linux/compiler.h>
15351 #include <asm/page.h>
15352 #include <asm/types.h>
15353+#include <asm/percpu.h>
15354
15355 /*
15356 * low level task data that entry.S needs immediate access to
15357@@ -24,7 +25,6 @@ struct exec_domain;
15358 #include <linux/atomic.h>
15359
15360 struct thread_info {
15361- struct task_struct *task; /* main task structure */
15362 struct exec_domain *exec_domain; /* execution domain */
15363 __u32 flags; /* low level flags */
15364 __u32 status; /* thread synchronous flags */
15365@@ -34,19 +34,13 @@ struct thread_info {
15366 mm_segment_t addr_limit;
15367 struct restart_block restart_block;
15368 void __user *sysenter_return;
15369-#ifdef CONFIG_X86_32
15370- unsigned long previous_esp; /* ESP of the previous stack in
15371- case of nested (IRQ) stacks
15372- */
15373- __u8 supervisor_stack[0];
15374-#endif
15375+ unsigned long lowest_stack;
15376 unsigned int sig_on_uaccess_error:1;
15377 unsigned int uaccess_err:1; /* uaccess failed */
15378 };
15379
15380-#define INIT_THREAD_INFO(tsk) \
15381+#define INIT_THREAD_INFO \
15382 { \
15383- .task = &tsk, \
15384 .exec_domain = &default_exec_domain, \
15385 .flags = 0, \
15386 .cpu = 0, \
15387@@ -57,7 +51,7 @@ struct thread_info {
15388 }, \
15389 }
15390
15391-#define init_thread_info (init_thread_union.thread_info)
15392+#define init_thread_info (init_thread_union.stack)
15393 #define init_stack (init_thread_union.stack)
15394
15395 #else /* !__ASSEMBLY__ */
15396@@ -98,6 +92,7 @@ struct thread_info {
15397 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
15398 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
15399 #define TIF_X32 30 /* 32-bit native x86-64 binary */
15400+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
15401
15402 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
15403 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
15404@@ -122,17 +117,18 @@ struct thread_info {
15405 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
15406 #define _TIF_ADDR32 (1 << TIF_ADDR32)
15407 #define _TIF_X32 (1 << TIF_X32)
15408+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
15409
15410 /* work to do in syscall_trace_enter() */
15411 #define _TIF_WORK_SYSCALL_ENTRY \
15412 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
15413 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
15414- _TIF_NOHZ)
15415+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15416
15417 /* work to do in syscall_trace_leave() */
15418 #define _TIF_WORK_SYSCALL_EXIT \
15419 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
15420- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
15421+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
15422
15423 /* work to do on interrupt/exception return */
15424 #define _TIF_WORK_MASK \
15425@@ -143,7 +139,7 @@ struct thread_info {
15426 /* work to do on any return to user space */
15427 #define _TIF_ALLWORK_MASK \
15428 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
15429- _TIF_NOHZ)
15430+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15431
15432 /* Only used for 64 bit */
15433 #define _TIF_DO_NOTIFY_MASK \
15434@@ -159,45 +155,40 @@ struct thread_info {
15435
15436 #define PREEMPT_ACTIVE 0x10000000
15437
15438-#ifdef CONFIG_X86_32
15439-
15440-#define STACK_WARN (THREAD_SIZE/8)
15441-/*
15442- * macros/functions for gaining access to the thread information structure
15443- *
15444- * preempt_count needs to be 1 initially, until the scheduler is functional.
15445- */
15446-#ifndef __ASSEMBLY__
15447-
15448-
15449-/* how to get the current stack pointer from C */
15450-register unsigned long current_stack_pointer asm("esp") __used;
15451-
15452-/* how to get the thread information struct from C */
15453-static inline struct thread_info *current_thread_info(void)
15454-{
15455- return (struct thread_info *)
15456- (current_stack_pointer & ~(THREAD_SIZE - 1));
15457-}
15458-
15459-#else /* !__ASSEMBLY__ */
15460-
15461+#ifdef __ASSEMBLY__
15462 /* how to get the thread information struct from ASM */
15463 #define GET_THREAD_INFO(reg) \
15464- movl $-THREAD_SIZE, reg; \
15465- andl %esp, reg
15466+ mov PER_CPU_VAR(current_tinfo), reg
15467
15468 /* use this one if reg already contains %esp */
15469-#define GET_THREAD_INFO_WITH_ESP(reg) \
15470- andl $-THREAD_SIZE, reg
15471+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15472+#else
15473+/* how to get the thread information struct from C */
15474+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15475+
15476+static __always_inline struct thread_info *current_thread_info(void)
15477+{
15478+ return this_cpu_read_stable(current_tinfo);
15479+}
15480+#endif
15481+
15482+#ifdef CONFIG_X86_32
15483+
15484+#define STACK_WARN (THREAD_SIZE/8)
15485+/*
15486+ * macros/functions for gaining access to the thread information structure
15487+ *
15488+ * preempt_count needs to be 1 initially, until the scheduler is functional.
15489+ */
15490+#ifndef __ASSEMBLY__
15491+
15492+/* how to get the current stack pointer from C */
15493+register unsigned long current_stack_pointer asm("esp") __used;
15494
15495 #endif
15496
15497 #else /* X86_32 */
15498
15499-#include <asm/percpu.h>
15500-#define KERNEL_STACK_OFFSET (5*8)
15501-
15502 /*
15503 * macros/functions for gaining access to the thread information structure
15504 * preempt_count needs to be 1 initially, until the scheduler is functional.
15505@@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
15506 #ifndef __ASSEMBLY__
15507 DECLARE_PER_CPU(unsigned long, kernel_stack);
15508
15509-static inline struct thread_info *current_thread_info(void)
15510-{
15511- struct thread_info *ti;
15512- ti = (void *)(this_cpu_read_stable(kernel_stack) +
15513- KERNEL_STACK_OFFSET - THREAD_SIZE);
15514- return ti;
15515-}
15516-
15517-#else /* !__ASSEMBLY__ */
15518-
15519-/* how to get the thread information struct from ASM */
15520-#define GET_THREAD_INFO(reg) \
15521- movq PER_CPU_VAR(kernel_stack),reg ; \
15522- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15523-
15524-/*
15525- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15526- * a certain register (to be used in assembler memory operands).
15527- */
15528-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15529-
15530+/* how to get the current stack pointer from C */
15531+register unsigned long current_stack_pointer asm("rsp") __used;
15532 #endif
15533
15534 #endif /* !X86_32 */
15535@@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
15536 extern void arch_task_cache_init(void);
15537 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15538 extern void arch_release_task_struct(struct task_struct *tsk);
15539+
15540+#define __HAVE_THREAD_FUNCTIONS
15541+#define task_thread_info(task) (&(task)->tinfo)
15542+#define task_stack_page(task) ((task)->stack)
15543+#define setup_thread_stack(p, org) do {} while (0)
15544+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15545+
15546 #endif
15547 #endif /* _ASM_X86_THREAD_INFO_H */
15548diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15549index 1709801..0a60f2f 100644
15550--- a/arch/x86/include/asm/uaccess.h
15551+++ b/arch/x86/include/asm/uaccess.h
15552@@ -7,6 +7,7 @@
15553 #include <linux/compiler.h>
15554 #include <linux/thread_info.h>
15555 #include <linux/string.h>
15556+#include <linux/sched.h>
15557 #include <asm/asm.h>
15558 #include <asm/page.h>
15559 #include <asm/smap.h>
15560@@ -29,7 +30,12 @@
15561
15562 #define get_ds() (KERNEL_DS)
15563 #define get_fs() (current_thread_info()->addr_limit)
15564+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15565+void __set_fs(mm_segment_t x);
15566+void set_fs(mm_segment_t x);
15567+#else
15568 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15569+#endif
15570
15571 #define segment_eq(a, b) ((a).seg == (b).seg)
15572
15573@@ -77,8 +83,33 @@
15574 * checks that the pointer is in the user space range - after calling
15575 * this function, memory access functions may still return -EFAULT.
15576 */
15577-#define access_ok(type, addr, size) \
15578- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15579+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15580+#define access_ok(type, addr, size) \
15581+({ \
15582+ long __size = size; \
15583+ unsigned long __addr = (unsigned long)addr; \
15584+ unsigned long __addr_ao = __addr & PAGE_MASK; \
15585+ unsigned long __end_ao = __addr + __size - 1; \
15586+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15587+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15588+ while(__addr_ao <= __end_ao) { \
15589+ char __c_ao; \
15590+ __addr_ao += PAGE_SIZE; \
15591+ if (__size > PAGE_SIZE) \
15592+ cond_resched(); \
15593+ if (__get_user(__c_ao, (char __user *)__addr)) \
15594+ break; \
15595+ if (type != VERIFY_WRITE) { \
15596+ __addr = __addr_ao; \
15597+ continue; \
15598+ } \
15599+ if (__put_user(__c_ao, (char __user *)__addr)) \
15600+ break; \
15601+ __addr = __addr_ao; \
15602+ } \
15603+ } \
15604+ __ret_ao; \
15605+})
15606
15607 /*
15608 * The exception table consists of pairs of addresses relative to the
15609@@ -189,13 +220,21 @@ extern int __get_user_bad(void);
15610 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15611 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15612
15613-
15614+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15615+#define __copyuser_seg "gs;"
15616+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15617+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15618+#else
15619+#define __copyuser_seg
15620+#define __COPYUSER_SET_ES
15621+#define __COPYUSER_RESTORE_ES
15622+#endif
15623
15624 #ifdef CONFIG_X86_32
15625 #define __put_user_asm_u64(x, addr, err, errret) \
15626 asm volatile(ASM_STAC "\n" \
15627- "1: movl %%eax,0(%2)\n" \
15628- "2: movl %%edx,4(%2)\n" \
15629+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15630+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15631 "3: " ASM_CLAC "\n" \
15632 ".section .fixup,\"ax\"\n" \
15633 "4: movl %3,%0\n" \
15634@@ -208,8 +247,8 @@ extern int __get_user_bad(void);
15635
15636 #define __put_user_asm_ex_u64(x, addr) \
15637 asm volatile(ASM_STAC "\n" \
15638- "1: movl %%eax,0(%1)\n" \
15639- "2: movl %%edx,4(%1)\n" \
15640+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15641+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15642 "3: " ASM_CLAC "\n" \
15643 _ASM_EXTABLE_EX(1b, 2b) \
15644 _ASM_EXTABLE_EX(2b, 3b) \
15645@@ -259,7 +298,7 @@ extern void __put_user_8(void);
15646 __typeof__(*(ptr)) __pu_val; \
15647 __chk_user_ptr(ptr); \
15648 might_fault(); \
15649- __pu_val = x; \
15650+ __pu_val = (x); \
15651 switch (sizeof(*(ptr))) { \
15652 case 1: \
15653 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15654@@ -358,7 +397,7 @@ do { \
15655
15656 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15657 asm volatile(ASM_STAC "\n" \
15658- "1: mov"itype" %2,%"rtype"1\n" \
15659+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15660 "2: " ASM_CLAC "\n" \
15661 ".section .fixup,\"ax\"\n" \
15662 "3: mov %3,%0\n" \
15663@@ -366,7 +405,7 @@ do { \
15664 " jmp 2b\n" \
15665 ".previous\n" \
15666 _ASM_EXTABLE(1b, 3b) \
15667- : "=r" (err), ltype(x) \
15668+ : "=r" (err), ltype (x) \
15669 : "m" (__m(addr)), "i" (errret), "0" (err))
15670
15671 #define __get_user_size_ex(x, ptr, size) \
15672@@ -391,7 +430,7 @@ do { \
15673 } while (0)
15674
15675 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15676- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15677+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15678 "2:\n" \
15679 _ASM_EXTABLE_EX(1b, 2b) \
15680 : ltype(x) : "m" (__m(addr)))
15681@@ -408,13 +447,24 @@ do { \
15682 int __gu_err; \
15683 unsigned long __gu_val; \
15684 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15685- (x) = (__force __typeof__(*(ptr)))__gu_val; \
15686+ (x) = (__typeof__(*(ptr)))__gu_val; \
15687 __gu_err; \
15688 })
15689
15690 /* FIXME: this hack is definitely wrong -AK */
15691 struct __large_struct { unsigned long buf[100]; };
15692-#define __m(x) (*(struct __large_struct __user *)(x))
15693+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15694+#define ____m(x) \
15695+({ \
15696+ unsigned long ____x = (unsigned long)(x); \
15697+ if (____x < PAX_USER_SHADOW_BASE) \
15698+ ____x += PAX_USER_SHADOW_BASE; \
15699+ (void __user *)____x; \
15700+})
15701+#else
15702+#define ____m(x) (x)
15703+#endif
15704+#define __m(x) (*(struct __large_struct __user *)____m(x))
15705
15706 /*
15707 * Tell gcc we read from memory instead of writing: this is because
15708@@ -423,7 +473,7 @@ struct __large_struct { unsigned long buf[100]; };
15709 */
15710 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15711 asm volatile(ASM_STAC "\n" \
15712- "1: mov"itype" %"rtype"1,%2\n" \
15713+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15714 "2: " ASM_CLAC "\n" \
15715 ".section .fixup,\"ax\"\n" \
15716 "3: mov %3,%0\n" \
15717@@ -431,10 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
15718 ".previous\n" \
15719 _ASM_EXTABLE(1b, 3b) \
15720 : "=r"(err) \
15721- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15722+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15723
15724 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15725- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15726+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15727 "2:\n" \
15728 _ASM_EXTABLE_EX(1b, 2b) \
15729 : : ltype(x), "m" (__m(addr)))
15730@@ -473,8 +523,12 @@ struct __large_struct { unsigned long buf[100]; };
15731 * On error, the variable @x is set to zero.
15732 */
15733
15734+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15735+#define __get_user(x, ptr) get_user((x), (ptr))
15736+#else
15737 #define __get_user(x, ptr) \
15738 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15739+#endif
15740
15741 /**
15742 * __put_user: - Write a simple value into user space, with less checking.
15743@@ -496,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
15744 * Returns zero on success, or -EFAULT on error.
15745 */
15746
15747+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15748+#define __put_user(x, ptr) put_user((x), (ptr))
15749+#else
15750 #define __put_user(x, ptr) \
15751 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15752+#endif
15753
15754 #define __get_user_unaligned __get_user
15755 #define __put_user_unaligned __put_user
15756@@ -515,7 +573,7 @@ struct __large_struct { unsigned long buf[100]; };
15757 #define get_user_ex(x, ptr) do { \
15758 unsigned long __gue_val; \
15759 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15760- (x) = (__force __typeof__(*(ptr)))__gue_val; \
15761+ (x) = (__typeof__(*(ptr)))__gue_val; \
15762 } while (0)
15763
15764 #define put_user_try uaccess_try
15765@@ -532,8 +590,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15766 extern __must_check long strlen_user(const char __user *str);
15767 extern __must_check long strnlen_user(const char __user *str, long n);
15768
15769-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
15770-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
15771+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15772+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15773
15774 /*
15775 * movsl can be slow when source and dest are not both 8-byte aligned
15776diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15777index 7f760a9..04b1c65 100644
15778--- a/arch/x86/include/asm/uaccess_32.h
15779+++ b/arch/x86/include/asm/uaccess_32.h
15780@@ -11,15 +11,15 @@
15781 #include <asm/page.h>
15782
15783 unsigned long __must_check __copy_to_user_ll
15784- (void __user *to, const void *from, unsigned long n);
15785+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15786 unsigned long __must_check __copy_from_user_ll
15787- (void *to, const void __user *from, unsigned long n);
15788+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15789 unsigned long __must_check __copy_from_user_ll_nozero
15790- (void *to, const void __user *from, unsigned long n);
15791+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15792 unsigned long __must_check __copy_from_user_ll_nocache
15793- (void *to, const void __user *from, unsigned long n);
15794+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15795 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15796- (void *to, const void __user *from, unsigned long n);
15797+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15798
15799 /**
15800 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15801@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15802 static __always_inline unsigned long __must_check
15803 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15804 {
15805+ if ((long)n < 0)
15806+ return n;
15807+
15808+ check_object_size(from, n, true);
15809+
15810 if (__builtin_constant_p(n)) {
15811 unsigned long ret;
15812
15813@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15814 __copy_to_user(void __user *to, const void *from, unsigned long n)
15815 {
15816 might_fault();
15817+
15818 return __copy_to_user_inatomic(to, from, n);
15819 }
15820
15821 static __always_inline unsigned long
15822 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15823 {
15824+ if ((long)n < 0)
15825+ return n;
15826+
15827 /* Avoid zeroing the tail if the copy fails..
15828 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15829 * but as the zeroing behaviour is only significant when n is not
15830@@ -137,6 +146,12 @@ static __always_inline unsigned long
15831 __copy_from_user(void *to, const void __user *from, unsigned long n)
15832 {
15833 might_fault();
15834+
15835+ if ((long)n < 0)
15836+ return n;
15837+
15838+ check_object_size(to, n, false);
15839+
15840 if (__builtin_constant_p(n)) {
15841 unsigned long ret;
15842
15843@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
15844 const void __user *from, unsigned long n)
15845 {
15846 might_fault();
15847+
15848+ if ((long)n < 0)
15849+ return n;
15850+
15851 if (__builtin_constant_p(n)) {
15852 unsigned long ret;
15853
15854@@ -181,15 +200,19 @@ static __always_inline unsigned long
15855 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
15856 unsigned long n)
15857 {
15858- return __copy_from_user_ll_nocache_nozero(to, from, n);
15859+ if ((long)n < 0)
15860+ return n;
15861+
15862+ return __copy_from_user_ll_nocache_nozero(to, from, n);
15863 }
15864
15865-unsigned long __must_check copy_to_user(void __user *to,
15866- const void *from, unsigned long n);
15867-unsigned long __must_check _copy_from_user(void *to,
15868- const void __user *from,
15869- unsigned long n);
15870-
15871+extern void copy_to_user_overflow(void)
15872+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15873+ __compiletime_error("copy_to_user() buffer size is not provably correct")
15874+#else
15875+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
15876+#endif
15877+;
15878
15879 extern void copy_from_user_overflow(void)
15880 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15881@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
15882 #endif
15883 ;
15884
15885-static inline unsigned long __must_check copy_from_user(void *to,
15886- const void __user *from,
15887- unsigned long n)
15888+/**
15889+ * copy_to_user: - Copy a block of data into user space.
15890+ * @to: Destination address, in user space.
15891+ * @from: Source address, in kernel space.
15892+ * @n: Number of bytes to copy.
15893+ *
15894+ * Context: User context only. This function may sleep.
15895+ *
15896+ * Copy data from kernel space to user space.
15897+ *
15898+ * Returns number of bytes that could not be copied.
15899+ * On success, this will be zero.
15900+ */
15901+static inline unsigned long __must_check
15902+copy_to_user(void __user *to, const void *from, unsigned long n)
15903 {
15904- int sz = __compiletime_object_size(to);
15905+ size_t sz = __compiletime_object_size(from);
15906
15907- if (likely(sz == -1 || sz >= n))
15908- n = _copy_from_user(to, from, n);
15909- else
15910+ if (unlikely(sz != (size_t)-1 && sz < n))
15911+ copy_to_user_overflow();
15912+ else if (access_ok(VERIFY_WRITE, to, n))
15913+ n = __copy_to_user(to, from, n);
15914+ return n;
15915+}
15916+
15917+/**
15918+ * copy_from_user: - Copy a block of data from user space.
15919+ * @to: Destination address, in kernel space.
15920+ * @from: Source address, in user space.
15921+ * @n: Number of bytes to copy.
15922+ *
15923+ * Context: User context only. This function may sleep.
15924+ *
15925+ * Copy data from user space to kernel space.
15926+ *
15927+ * Returns number of bytes that could not be copied.
15928+ * On success, this will be zero.
15929+ *
15930+ * If some data could not be copied, this function will pad the copied
15931+ * data to the requested size using zero bytes.
15932+ */
15933+static inline unsigned long __must_check
15934+copy_from_user(void *to, const void __user *from, unsigned long n)
15935+{
15936+ size_t sz = __compiletime_object_size(to);
15937+
15938+ check_object_size(to, n, false);
15939+
15940+ if (unlikely(sz != (size_t)-1 && sz < n))
15941 copy_from_user_overflow();
15942-
15943+ else if (access_ok(VERIFY_READ, from, n))
15944+ n = __copy_from_user(to, from, n);
15945+ else if ((long)n > 0)
15946+ memset(to, 0, n);
15947 return n;
15948 }
15949
15950diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
15951index 142810c..1f2a0a7 100644
15952--- a/arch/x86/include/asm/uaccess_64.h
15953+++ b/arch/x86/include/asm/uaccess_64.h
15954@@ -10,6 +10,9 @@
15955 #include <asm/alternative.h>
15956 #include <asm/cpufeature.h>
15957 #include <asm/page.h>
15958+#include <asm/pgtable.h>
15959+
15960+#define set_fs(x) (current_thread_info()->addr_limit = (x))
15961
15962 /*
15963 * Copy To/From Userspace
15964@@ -17,13 +20,13 @@
15965
15966 /* Handles exceptions in both to and from, but doesn't do access_ok */
15967 __must_check unsigned long
15968-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
15969+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
15970 __must_check unsigned long
15971-copy_user_generic_string(void *to, const void *from, unsigned len);
15972+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
15973 __must_check unsigned long
15974-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
15975+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
15976
15977-static __always_inline __must_check unsigned long
15978+static __always_inline __must_check __size_overflow(3) unsigned long
15979 copy_user_generic(void *to, const void *from, unsigned len)
15980 {
15981 unsigned ret;
15982@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
15983 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
15984 "=d" (len)),
15985 "1" (to), "2" (from), "3" (len)
15986- : "memory", "rcx", "r8", "r9", "r10", "r11");
15987+ : "memory", "rcx", "r8", "r9", "r11");
15988 return ret;
15989 }
15990
15991+static __always_inline __must_check unsigned long
15992+__copy_to_user(void __user *to, const void *from, unsigned long len);
15993+static __always_inline __must_check unsigned long
15994+__copy_from_user(void *to, const void __user *from, unsigned long len);
15995 __must_check unsigned long
15996-_copy_to_user(void __user *to, const void *from, unsigned len);
15997-__must_check unsigned long
15998-_copy_from_user(void *to, const void __user *from, unsigned len);
15999-__must_check unsigned long
16000-copy_in_user(void __user *to, const void __user *from, unsigned len);
16001+copy_in_user(void __user *to, const void __user *from, unsigned long len);
16002+
16003+extern void copy_to_user_overflow(void)
16004+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16005+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16006+#else
16007+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16008+#endif
16009+;
16010+
16011+extern void copy_from_user_overflow(void)
16012+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16013+ __compiletime_error("copy_from_user() buffer size is not provably correct")
16014+#else
16015+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
16016+#endif
16017+;
16018
16019 static inline unsigned long __must_check copy_from_user(void *to,
16020 const void __user *from,
16021 unsigned long n)
16022 {
16023- int sz = __compiletime_object_size(to);
16024-
16025 might_fault();
16026- if (likely(sz == -1 || sz >= n))
16027- n = _copy_from_user(to, from, n);
16028-#ifdef CONFIG_DEBUG_VM
16029- else
16030- WARN(1, "Buffer overflow detected!\n");
16031-#endif
16032+
16033+ check_object_size(to, n, false);
16034+
16035+ if (access_ok(VERIFY_READ, from, n))
16036+ n = __copy_from_user(to, from, n);
16037+ else if (n < INT_MAX)
16038+ memset(to, 0, n);
16039 return n;
16040 }
16041
16042 static __always_inline __must_check
16043-int copy_to_user(void __user *dst, const void *src, unsigned size)
16044+int copy_to_user(void __user *dst, const void *src, unsigned long size)
16045 {
16046 might_fault();
16047
16048- return _copy_to_user(dst, src, size);
16049+ if (access_ok(VERIFY_WRITE, dst, size))
16050+ size = __copy_to_user(dst, src, size);
16051+ return size;
16052 }
16053
16054 static __always_inline __must_check
16055-int __copy_from_user(void *dst, const void __user *src, unsigned size)
16056+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
16057 {
16058- int ret = 0;
16059+ size_t sz = __compiletime_object_size(dst);
16060+ unsigned ret = 0;
16061
16062 might_fault();
16063+
16064+ if (size > INT_MAX)
16065+ return size;
16066+
16067+ check_object_size(dst, size, false);
16068+
16069+#ifdef CONFIG_PAX_MEMORY_UDEREF
16070+ if (!__access_ok(VERIFY_READ, src, size))
16071+ return size;
16072+#endif
16073+
16074+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16075+ copy_from_user_overflow();
16076+ return size;
16077+ }
16078+
16079 if (!__builtin_constant_p(size))
16080- return copy_user_generic(dst, (__force void *)src, size);
16081+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16082 switch (size) {
16083- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
16084+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
16085 ret, "b", "b", "=q", 1);
16086 return ret;
16087- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
16088+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
16089 ret, "w", "w", "=r", 2);
16090 return ret;
16091- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
16092+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
16093 ret, "l", "k", "=r", 4);
16094 return ret;
16095- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
16096+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16097 ret, "q", "", "=r", 8);
16098 return ret;
16099 case 10:
16100- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16101+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16102 ret, "q", "", "=r", 10);
16103 if (unlikely(ret))
16104 return ret;
16105 __get_user_asm(*(u16 *)(8 + (char *)dst),
16106- (u16 __user *)(8 + (char __user *)src),
16107+ (const u16 __user *)(8 + (const char __user *)src),
16108 ret, "w", "w", "=r", 2);
16109 return ret;
16110 case 16:
16111- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16112+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16113 ret, "q", "", "=r", 16);
16114 if (unlikely(ret))
16115 return ret;
16116 __get_user_asm(*(u64 *)(8 + (char *)dst),
16117- (u64 __user *)(8 + (char __user *)src),
16118+ (const u64 __user *)(8 + (const char __user *)src),
16119 ret, "q", "", "=r", 8);
16120 return ret;
16121 default:
16122- return copy_user_generic(dst, (__force void *)src, size);
16123+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16124 }
16125 }
16126
16127 static __always_inline __must_check
16128-int __copy_to_user(void __user *dst, const void *src, unsigned size)
16129+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
16130 {
16131- int ret = 0;
16132+ size_t sz = __compiletime_object_size(src);
16133+ unsigned ret = 0;
16134
16135 might_fault();
16136+
16137+ if (size > INT_MAX)
16138+ return size;
16139+
16140+ check_object_size(src, size, true);
16141+
16142+#ifdef CONFIG_PAX_MEMORY_UDEREF
16143+ if (!__access_ok(VERIFY_WRITE, dst, size))
16144+ return size;
16145+#endif
16146+
16147+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16148+ copy_to_user_overflow();
16149+ return size;
16150+ }
16151+
16152 if (!__builtin_constant_p(size))
16153- return copy_user_generic((__force void *)dst, src, size);
16154+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16155 switch (size) {
16156- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
16157+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
16158 ret, "b", "b", "iq", 1);
16159 return ret;
16160- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
16161+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
16162 ret, "w", "w", "ir", 2);
16163 return ret;
16164- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
16165+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
16166 ret, "l", "k", "ir", 4);
16167 return ret;
16168- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
16169+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16170 ret, "q", "", "er", 8);
16171 return ret;
16172 case 10:
16173- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16174+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16175 ret, "q", "", "er", 10);
16176 if (unlikely(ret))
16177 return ret;
16178 asm("":::"memory");
16179- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
16180+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
16181 ret, "w", "w", "ir", 2);
16182 return ret;
16183 case 16:
16184- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16185+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16186 ret, "q", "", "er", 16);
16187 if (unlikely(ret))
16188 return ret;
16189 asm("":::"memory");
16190- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
16191+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
16192 ret, "q", "", "er", 8);
16193 return ret;
16194 default:
16195- return copy_user_generic((__force void *)dst, src, size);
16196+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16197 }
16198 }
16199
16200 static __always_inline __must_check
16201-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16202+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
16203 {
16204- int ret = 0;
16205+ unsigned ret = 0;
16206
16207 might_fault();
16208+
16209+ if (size > INT_MAX)
16210+ return size;
16211+
16212+#ifdef CONFIG_PAX_MEMORY_UDEREF
16213+ if (!__access_ok(VERIFY_READ, src, size))
16214+ return size;
16215+ if (!__access_ok(VERIFY_WRITE, dst, size))
16216+ return size;
16217+#endif
16218+
16219 if (!__builtin_constant_p(size))
16220- return copy_user_generic((__force void *)dst,
16221- (__force void *)src, size);
16222+ return copy_user_generic((__force_kernel void *)____m(dst),
16223+ (__force_kernel const void *)____m(src), size);
16224 switch (size) {
16225 case 1: {
16226 u8 tmp;
16227- __get_user_asm(tmp, (u8 __user *)src,
16228+ __get_user_asm(tmp, (const u8 __user *)src,
16229 ret, "b", "b", "=q", 1);
16230 if (likely(!ret))
16231 __put_user_asm(tmp, (u8 __user *)dst,
16232@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16233 }
16234 case 2: {
16235 u16 tmp;
16236- __get_user_asm(tmp, (u16 __user *)src,
16237+ __get_user_asm(tmp, (const u16 __user *)src,
16238 ret, "w", "w", "=r", 2);
16239 if (likely(!ret))
16240 __put_user_asm(tmp, (u16 __user *)dst,
16241@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16242
16243 case 4: {
16244 u32 tmp;
16245- __get_user_asm(tmp, (u32 __user *)src,
16246+ __get_user_asm(tmp, (const u32 __user *)src,
16247 ret, "l", "k", "=r", 4);
16248 if (likely(!ret))
16249 __put_user_asm(tmp, (u32 __user *)dst,
16250@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16251 }
16252 case 8: {
16253 u64 tmp;
16254- __get_user_asm(tmp, (u64 __user *)src,
16255+ __get_user_asm(tmp, (const u64 __user *)src,
16256 ret, "q", "", "=r", 8);
16257 if (likely(!ret))
16258 __put_user_asm(tmp, (u64 __user *)dst,
16259@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16260 return ret;
16261 }
16262 default:
16263- return copy_user_generic((__force void *)dst,
16264- (__force void *)src, size);
16265+ return copy_user_generic((__force_kernel void *)____m(dst),
16266+ (__force_kernel const void *)____m(src), size);
16267 }
16268 }
16269
16270 static __must_check __always_inline int
16271-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
16272+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
16273 {
16274- return copy_user_generic(dst, (__force const void *)src, size);
16275+ if (size > INT_MAX)
16276+ return size;
16277+
16278+#ifdef CONFIG_PAX_MEMORY_UDEREF
16279+ if (!__access_ok(VERIFY_READ, src, size))
16280+ return size;
16281+#endif
16282+
16283+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16284 }
16285
16286-static __must_check __always_inline int
16287-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
16288+static __must_check __always_inline unsigned long
16289+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
16290 {
16291- return copy_user_generic((__force void *)dst, src, size);
16292+ if (size > INT_MAX)
16293+ return size;
16294+
16295+#ifdef CONFIG_PAX_MEMORY_UDEREF
16296+ if (!__access_ok(VERIFY_WRITE, dst, size))
16297+ return size;
16298+#endif
16299+
16300+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16301 }
16302
16303-extern long __copy_user_nocache(void *dst, const void __user *src,
16304- unsigned size, int zerorest);
16305+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
16306+ unsigned long size, int zerorest) __size_overflow(3);
16307
16308-static inline int
16309-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
16310+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
16311 {
16312 might_sleep();
16313+
16314+ if (size > INT_MAX)
16315+ return size;
16316+
16317+#ifdef CONFIG_PAX_MEMORY_UDEREF
16318+ if (!__access_ok(VERIFY_READ, src, size))
16319+ return size;
16320+#endif
16321+
16322 return __copy_user_nocache(dst, src, size, 1);
16323 }
16324
16325-static inline int
16326-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16327- unsigned size)
16328+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16329+ unsigned long size)
16330 {
16331+ if (size > INT_MAX)
16332+ return size;
16333+
16334+#ifdef CONFIG_PAX_MEMORY_UDEREF
16335+ if (!__access_ok(VERIFY_READ, src, size))
16336+ return size;
16337+#endif
16338+
16339 return __copy_user_nocache(dst, src, size, 0);
16340 }
16341
16342-unsigned long
16343-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
16344+extern unsigned long
16345+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
16346
16347 #endif /* _ASM_X86_UACCESS_64_H */
16348diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
16349index 5b238981..77fdd78 100644
16350--- a/arch/x86/include/asm/word-at-a-time.h
16351+++ b/arch/x86/include/asm/word-at-a-time.h
16352@@ -11,7 +11,7 @@
16353 * and shift, for example.
16354 */
16355 struct word_at_a_time {
16356- const unsigned long one_bits, high_bits;
16357+ unsigned long one_bits, high_bits;
16358 };
16359
16360 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
16361diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
16362index 5769349..a3d3e2a 100644
16363--- a/arch/x86/include/asm/x86_init.h
16364+++ b/arch/x86/include/asm/x86_init.h
16365@@ -141,7 +141,7 @@ struct x86_init_ops {
16366 struct x86_init_timers timers;
16367 struct x86_init_iommu iommu;
16368 struct x86_init_pci pci;
16369-};
16370+} __no_const;
16371
16372 /**
16373 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
16374@@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
16375 void (*setup_percpu_clockev)(void);
16376 void (*early_percpu_clock_init)(void);
16377 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
16378-};
16379+} __no_const;
16380
16381 /**
16382 * struct x86_platform_ops - platform specific runtime functions
16383@@ -178,7 +178,7 @@ struct x86_platform_ops {
16384 void (*save_sched_clock_state)(void);
16385 void (*restore_sched_clock_state)(void);
16386 void (*apic_post_init)(void);
16387-};
16388+} __no_const;
16389
16390 struct pci_dev;
16391
16392@@ -187,14 +187,14 @@ struct x86_msi_ops {
16393 void (*teardown_msi_irq)(unsigned int irq);
16394 void (*teardown_msi_irqs)(struct pci_dev *dev);
16395 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
16396-};
16397+} __no_const;
16398
16399 struct x86_io_apic_ops {
16400 void (*init) (void);
16401 unsigned int (*read) (unsigned int apic, unsigned int reg);
16402 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
16403 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
16404-};
16405+} __no_const;
16406
16407 extern struct x86_init_ops x86_init;
16408 extern struct x86_cpuinit_ops x86_cpuinit;
16409diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
16410index 0415cda..b43d877 100644
16411--- a/arch/x86/include/asm/xsave.h
16412+++ b/arch/x86/include/asm/xsave.h
16413@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16414 return -EFAULT;
16415
16416 __asm__ __volatile__(ASM_STAC "\n"
16417- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
16418+ "1:"
16419+ __copyuser_seg
16420+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
16421 "2: " ASM_CLAC "\n"
16422 ".section .fixup,\"ax\"\n"
16423 "3: movl $-1,%[err]\n"
16424@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16425 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
16426 {
16427 int err;
16428- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
16429+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
16430 u32 lmask = mask;
16431 u32 hmask = mask >> 32;
16432
16433 __asm__ __volatile__(ASM_STAC "\n"
16434- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16435+ "1:"
16436+ __copyuser_seg
16437+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16438 "2: " ASM_CLAC "\n"
16439 ".section .fixup,\"ax\"\n"
16440 "3: movl $-1,%[err]\n"
16441diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16442index bbae024..e1528f9 100644
16443--- a/arch/x86/include/uapi/asm/e820.h
16444+++ b/arch/x86/include/uapi/asm/e820.h
16445@@ -63,7 +63,7 @@ struct e820map {
16446 #define ISA_START_ADDRESS 0xa0000
16447 #define ISA_END_ADDRESS 0x100000
16448
16449-#define BIOS_BEGIN 0x000a0000
16450+#define BIOS_BEGIN 0x000c0000
16451 #define BIOS_END 0x00100000
16452
16453 #define BIOS_ROM_BASE 0xffe00000
16454diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16455index 34e923a..0c6bb6e 100644
16456--- a/arch/x86/kernel/Makefile
16457+++ b/arch/x86/kernel/Makefile
16458@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16459 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16460 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16461 obj-y += probe_roms.o
16462-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16463+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16464 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16465 obj-y += syscall_$(BITS).o
16466 obj-$(CONFIG_X86_64) += vsyscall_64.o
16467diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
16468index bacf4b0..4ede72e 100644
16469--- a/arch/x86/kernel/acpi/boot.c
16470+++ b/arch/x86/kernel/acpi/boot.c
16471@@ -1358,7 +1358,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
16472 * If your system is blacklisted here, but you find that acpi=force
16473 * works for you, please contact linux-acpi@vger.kernel.org
16474 */
16475-static struct dmi_system_id __initdata acpi_dmi_table[] = {
16476+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
16477 /*
16478 * Boxes that need ACPI disabled
16479 */
16480@@ -1433,7 +1433,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
16481 };
16482
16483 /* second table for DMI checks that should run after early-quirks */
16484-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
16485+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
16486 /*
16487 * HP laptops which use a DSDT reporting as HP/SB400/10000,
16488 * which includes some code which overrides all temperature
16489diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16490index d5e0d71..6533e08 100644
16491--- a/arch/x86/kernel/acpi/sleep.c
16492+++ b/arch/x86/kernel/acpi/sleep.c
16493@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16494 #else /* CONFIG_64BIT */
16495 #ifdef CONFIG_SMP
16496 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16497+
16498+ pax_open_kernel();
16499 early_gdt_descr.address =
16500 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16501+ pax_close_kernel();
16502+
16503 initial_gs = per_cpu_offset(smp_processor_id());
16504 #endif
16505 initial_code = (unsigned long)wakeup_long64;
16506diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16507index 13ab720..95d5442 100644
16508--- a/arch/x86/kernel/acpi/wakeup_32.S
16509+++ b/arch/x86/kernel/acpi/wakeup_32.S
16510@@ -30,13 +30,11 @@ wakeup_pmode_return:
16511 # and restore the stack ... but you need gdt for this to work
16512 movl saved_context_esp, %esp
16513
16514- movl %cs:saved_magic, %eax
16515- cmpl $0x12345678, %eax
16516+ cmpl $0x12345678, saved_magic
16517 jne bogus_magic
16518
16519 # jump to place where we left off
16520- movl saved_eip, %eax
16521- jmp *%eax
16522+ jmp *(saved_eip)
16523
16524 bogus_magic:
16525 jmp bogus_magic
16526diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16527index ef5ccca..bd83949 100644
16528--- a/arch/x86/kernel/alternative.c
16529+++ b/arch/x86/kernel/alternative.c
16530@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16531 */
16532 for (a = start; a < end; a++) {
16533 instr = (u8 *)&a->instr_offset + a->instr_offset;
16534+
16535+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16536+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16537+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16538+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16539+#endif
16540+
16541 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16542 BUG_ON(a->replacementlen > a->instrlen);
16543 BUG_ON(a->instrlen > sizeof(insnbuf));
16544@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16545 for (poff = start; poff < end; poff++) {
16546 u8 *ptr = (u8 *)poff + *poff;
16547
16548+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16549+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16550+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16551+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16552+#endif
16553+
16554 if (!*poff || ptr < text || ptr >= text_end)
16555 continue;
16556 /* turn DS segment override prefix into lock prefix */
16557- if (*ptr == 0x3e)
16558+ if (*ktla_ktva(ptr) == 0x3e)
16559 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16560 }
16561 mutex_unlock(&text_mutex);
16562@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16563 for (poff = start; poff < end; poff++) {
16564 u8 *ptr = (u8 *)poff + *poff;
16565
16566+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16567+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16568+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16569+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16570+#endif
16571+
16572 if (!*poff || ptr < text || ptr >= text_end)
16573 continue;
16574 /* turn lock prefix into DS segment override prefix */
16575- if (*ptr == 0xf0)
16576+ if (*ktla_ktva(ptr) == 0xf0)
16577 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16578 }
16579 mutex_unlock(&text_mutex);
16580@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16581
16582 BUG_ON(p->len > MAX_PATCH_LEN);
16583 /* prep the buffer with the original instructions */
16584- memcpy(insnbuf, p->instr, p->len);
16585+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16586 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16587 (unsigned long)p->instr, p->len);
16588
16589@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16590 if (!uniproc_patched || num_possible_cpus() == 1)
16591 free_init_pages("SMP alternatives",
16592 (unsigned long)__smp_locks,
16593- (unsigned long)__smp_locks_end);
16594+ PAGE_ALIGN((unsigned long)__smp_locks_end));
16595 #endif
16596
16597 apply_paravirt(__parainstructions, __parainstructions_end);
16598@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16599 * instructions. And on the local CPU you need to be protected again NMI or MCE
16600 * handlers seeing an inconsistent instruction while you patch.
16601 */
16602-void *__init_or_module text_poke_early(void *addr, const void *opcode,
16603+void *__kprobes text_poke_early(void *addr, const void *opcode,
16604 size_t len)
16605 {
16606 unsigned long flags;
16607 local_irq_save(flags);
16608- memcpy(addr, opcode, len);
16609+
16610+ pax_open_kernel();
16611+ memcpy(ktla_ktva(addr), opcode, len);
16612 sync_core();
16613+ pax_close_kernel();
16614+
16615 local_irq_restore(flags);
16616 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16617 that causes hangs on some VIA CPUs. */
16618@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16619 */
16620 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16621 {
16622- unsigned long flags;
16623- char *vaddr;
16624+ unsigned char *vaddr = ktla_ktva(addr);
16625 struct page *pages[2];
16626- int i;
16627+ size_t i;
16628
16629 if (!core_kernel_text((unsigned long)addr)) {
16630- pages[0] = vmalloc_to_page(addr);
16631- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16632+ pages[0] = vmalloc_to_page(vaddr);
16633+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16634 } else {
16635- pages[0] = virt_to_page(addr);
16636+ pages[0] = virt_to_page(vaddr);
16637 WARN_ON(!PageReserved(pages[0]));
16638- pages[1] = virt_to_page(addr + PAGE_SIZE);
16639+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16640 }
16641 BUG_ON(!pages[0]);
16642- local_irq_save(flags);
16643- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16644- if (pages[1])
16645- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16646- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16647- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16648- clear_fixmap(FIX_TEXT_POKE0);
16649- if (pages[1])
16650- clear_fixmap(FIX_TEXT_POKE1);
16651- local_flush_tlb();
16652- sync_core();
16653- /* Could also do a CLFLUSH here to speed up CPU recovery; but
16654- that causes hangs on some VIA CPUs. */
16655+ text_poke_early(addr, opcode, len);
16656 for (i = 0; i < len; i++)
16657- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16658- local_irq_restore(flags);
16659+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16660 return addr;
16661 }
16662
16663diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16664index cbf5121..812b537 100644
16665--- a/arch/x86/kernel/apic/apic.c
16666+++ b/arch/x86/kernel/apic/apic.c
16667@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16668 /*
16669 * Debug level, exported for io_apic.c
16670 */
16671-unsigned int apic_verbosity;
16672+int apic_verbosity;
16673
16674 int pic_mode;
16675
16676@@ -1956,7 +1956,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16677 apic_write(APIC_ESR, 0);
16678 v1 = apic_read(APIC_ESR);
16679 ack_APIC_irq();
16680- atomic_inc(&irq_err_count);
16681+ atomic_inc_unchecked(&irq_err_count);
16682
16683 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16684 smp_processor_id(), v0 , v1);
16685diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16686index 00c77cf..2dc6a2d 100644
16687--- a/arch/x86/kernel/apic/apic_flat_64.c
16688+++ b/arch/x86/kernel/apic/apic_flat_64.c
16689@@ -157,7 +157,7 @@ static int flat_probe(void)
16690 return 1;
16691 }
16692
16693-static struct apic apic_flat = {
16694+static struct apic apic_flat __read_only = {
16695 .name = "flat",
16696 .probe = flat_probe,
16697 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16698@@ -271,7 +271,7 @@ static int physflat_probe(void)
16699 return 0;
16700 }
16701
16702-static struct apic apic_physflat = {
16703+static struct apic apic_physflat __read_only = {
16704
16705 .name = "physical flat",
16706 .probe = physflat_probe,
16707diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
16708index e145f28..2752888 100644
16709--- a/arch/x86/kernel/apic/apic_noop.c
16710+++ b/arch/x86/kernel/apic/apic_noop.c
16711@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
16712 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
16713 }
16714
16715-struct apic apic_noop = {
16716+struct apic apic_noop __read_only = {
16717 .name = "noop",
16718 .probe = noop_probe,
16719 .acpi_madt_oem_check = NULL,
16720diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16721index d50e364..543bee3 100644
16722--- a/arch/x86/kernel/apic/bigsmp_32.c
16723+++ b/arch/x86/kernel/apic/bigsmp_32.c
16724@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16725 return dmi_bigsmp;
16726 }
16727
16728-static struct apic apic_bigsmp = {
16729+static struct apic apic_bigsmp __read_only = {
16730
16731 .name = "bigsmp",
16732 .probe = probe_bigsmp,
16733diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16734index 0874799..a7a7892 100644
16735--- a/arch/x86/kernel/apic/es7000_32.c
16736+++ b/arch/x86/kernel/apic/es7000_32.c
16737@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16738 return ret && es7000_apic_is_cluster();
16739 }
16740
16741-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16742-static struct apic __refdata apic_es7000_cluster = {
16743+static struct apic apic_es7000_cluster __read_only = {
16744
16745 .name = "es7000",
16746 .probe = probe_es7000,
16747@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16748 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16749 };
16750
16751-static struct apic __refdata apic_es7000 = {
16752+static struct apic apic_es7000 __read_only = {
16753
16754 .name = "es7000",
16755 .probe = probe_es7000,
16756diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16757index b739d39..aebc14c 100644
16758--- a/arch/x86/kernel/apic/io_apic.c
16759+++ b/arch/x86/kernel/apic/io_apic.c
16760@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16761 }
16762 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16763
16764-void lock_vector_lock(void)
16765+void lock_vector_lock(void) __acquires(vector_lock)
16766 {
16767 /* Used to the online set of cpus does not change
16768 * during assign_irq_vector.
16769@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
16770 raw_spin_lock(&vector_lock);
16771 }
16772
16773-void unlock_vector_lock(void)
16774+void unlock_vector_lock(void) __releases(vector_lock)
16775 {
16776 raw_spin_unlock(&vector_lock);
16777 }
16778@@ -2399,7 +2399,7 @@ static void ack_apic_edge(struct irq_data *data)
16779 ack_APIC_irq();
16780 }
16781
16782-atomic_t irq_mis_count;
16783+atomic_unchecked_t irq_mis_count;
16784
16785 #ifdef CONFIG_GENERIC_PENDING_IRQ
16786 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16787@@ -2540,7 +2540,7 @@ static void ack_apic_level(struct irq_data *data)
16788 * at the cpu.
16789 */
16790 if (!(v & (1 << (i & 0x1f)))) {
16791- atomic_inc(&irq_mis_count);
16792+ atomic_inc_unchecked(&irq_mis_count);
16793
16794 eoi_ioapic_irq(irq, cfg);
16795 }
16796@@ -2567,11 +2567,13 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
16797
16798 static void irq_remap_modify_chip_defaults(struct irq_chip *chip)
16799 {
16800- chip->irq_print_chip = ir_print_prefix;
16801- chip->irq_ack = ir_ack_apic_edge;
16802- chip->irq_eoi = ir_ack_apic_level;
16803+ pax_open_kernel();
16804+ *(void **)&chip->irq_print_chip = ir_print_prefix;
16805+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
16806+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
16807
16808- chip->irq_set_affinity = set_remapped_irq_affinity;
16809+ *(void **)&chip->irq_set_affinity = set_remapped_irq_affinity;
16810+ pax_close_kernel();
16811 }
16812 #endif /* CONFIG_IRQ_REMAP */
16813
16814diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16815index d661ee9..791fd33 100644
16816--- a/arch/x86/kernel/apic/numaq_32.c
16817+++ b/arch/x86/kernel/apic/numaq_32.c
16818@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16819 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16820 }
16821
16822-/* Use __refdata to keep false positive warning calm. */
16823-static struct apic __refdata apic_numaq = {
16824+static struct apic apic_numaq __read_only = {
16825
16826 .name = "NUMAQ",
16827 .probe = probe_numaq,
16828diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16829index eb35ef9..f184a21 100644
16830--- a/arch/x86/kernel/apic/probe_32.c
16831+++ b/arch/x86/kernel/apic/probe_32.c
16832@@ -72,7 +72,7 @@ static int probe_default(void)
16833 return 1;
16834 }
16835
16836-static struct apic apic_default = {
16837+static struct apic apic_default __read_only = {
16838
16839 .name = "default",
16840 .probe = probe_default,
16841diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16842index 77c95c0..434f8a4 100644
16843--- a/arch/x86/kernel/apic/summit_32.c
16844+++ b/arch/x86/kernel/apic/summit_32.c
16845@@ -486,7 +486,7 @@ void setup_summit(void)
16846 }
16847 #endif
16848
16849-static struct apic apic_summit = {
16850+static struct apic apic_summit __read_only = {
16851
16852 .name = "summit",
16853 .probe = probe_summit,
16854diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16855index c88baa4..757aee1 100644
16856--- a/arch/x86/kernel/apic/x2apic_cluster.c
16857+++ b/arch/x86/kernel/apic/x2apic_cluster.c
16858@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
16859 return notifier_from_errno(err);
16860 }
16861
16862-static struct notifier_block __refdata x2apic_cpu_notifier = {
16863+static struct notifier_block x2apic_cpu_notifier = {
16864 .notifier_call = update_clusterinfo,
16865 };
16866
16867@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
16868 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
16869 }
16870
16871-static struct apic apic_x2apic_cluster = {
16872+static struct apic apic_x2apic_cluster __read_only = {
16873
16874 .name = "cluster x2apic",
16875 .probe = x2apic_cluster_probe,
16876diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
16877index 562a76d..a003c0f 100644
16878--- a/arch/x86/kernel/apic/x2apic_phys.c
16879+++ b/arch/x86/kernel/apic/x2apic_phys.c
16880@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
16881 return apic == &apic_x2apic_phys;
16882 }
16883
16884-static struct apic apic_x2apic_phys = {
16885+static struct apic apic_x2apic_phys __read_only = {
16886
16887 .name = "physical x2apic",
16888 .probe = x2apic_phys_probe,
16889diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
16890index 8cfade9..b9d04fc 100644
16891--- a/arch/x86/kernel/apic/x2apic_uv_x.c
16892+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
16893@@ -333,7 +333,7 @@ static int uv_probe(void)
16894 return apic == &apic_x2apic_uv_x;
16895 }
16896
16897-static struct apic __refdata apic_x2apic_uv_x = {
16898+static struct apic apic_x2apic_uv_x __read_only = {
16899
16900 .name = "UV large system",
16901 .probe = uv_probe,
16902diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
16903index d65464e..1035d31 100644
16904--- a/arch/x86/kernel/apm_32.c
16905+++ b/arch/x86/kernel/apm_32.c
16906@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
16907 * This is for buggy BIOS's that refer to (real mode) segment 0x40
16908 * even though they are called in protected mode.
16909 */
16910-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
16911+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
16912 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
16913
16914 static const char driver_version[] = "1.16ac"; /* no spaces */
16915@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
16916 BUG_ON(cpu != 0);
16917 gdt = get_cpu_gdt_table(cpu);
16918 save_desc_40 = gdt[0x40 / 8];
16919+
16920+ pax_open_kernel();
16921 gdt[0x40 / 8] = bad_bios_desc;
16922+ pax_close_kernel();
16923
16924 apm_irq_save(flags);
16925 APM_DO_SAVE_SEGS;
16926@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
16927 &call->esi);
16928 APM_DO_RESTORE_SEGS;
16929 apm_irq_restore(flags);
16930+
16931+ pax_open_kernel();
16932 gdt[0x40 / 8] = save_desc_40;
16933+ pax_close_kernel();
16934+
16935 put_cpu();
16936
16937 return call->eax & 0xff;
16938@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
16939 BUG_ON(cpu != 0);
16940 gdt = get_cpu_gdt_table(cpu);
16941 save_desc_40 = gdt[0x40 / 8];
16942+
16943+ pax_open_kernel();
16944 gdt[0x40 / 8] = bad_bios_desc;
16945+ pax_close_kernel();
16946
16947 apm_irq_save(flags);
16948 APM_DO_SAVE_SEGS;
16949@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
16950 &call->eax);
16951 APM_DO_RESTORE_SEGS;
16952 apm_irq_restore(flags);
16953+
16954+ pax_open_kernel();
16955 gdt[0x40 / 8] = save_desc_40;
16956+ pax_close_kernel();
16957+
16958 put_cpu();
16959 return error;
16960 }
16961@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
16962 * code to that CPU.
16963 */
16964 gdt = get_cpu_gdt_table(0);
16965+
16966+ pax_open_kernel();
16967 set_desc_base(&gdt[APM_CS >> 3],
16968 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
16969 set_desc_base(&gdt[APM_CS_16 >> 3],
16970 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
16971 set_desc_base(&gdt[APM_DS >> 3],
16972 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
16973+ pax_close_kernel();
16974
16975 proc_create("apm", 0, NULL, &apm_file_ops);
16976
16977diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
16978index 2861082..6d4718e 100644
16979--- a/arch/x86/kernel/asm-offsets.c
16980+++ b/arch/x86/kernel/asm-offsets.c
16981@@ -33,6 +33,8 @@ void common(void) {
16982 OFFSET(TI_status, thread_info, status);
16983 OFFSET(TI_addr_limit, thread_info, addr_limit);
16984 OFFSET(TI_preempt_count, thread_info, preempt_count);
16985+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
16986+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
16987
16988 BLANK();
16989 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
16990@@ -53,8 +55,26 @@ void common(void) {
16991 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
16992 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
16993 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
16994+
16995+#ifdef CONFIG_PAX_KERNEXEC
16996+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
16997 #endif
16998
16999+#ifdef CONFIG_PAX_MEMORY_UDEREF
17000+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
17001+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
17002+#ifdef CONFIG_X86_64
17003+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
17004+#endif
17005+#endif
17006+
17007+#endif
17008+
17009+ BLANK();
17010+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
17011+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
17012+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
17013+
17014 #ifdef CONFIG_XEN
17015 BLANK();
17016 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
17017diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
17018index 1b4754f..fbb4227 100644
17019--- a/arch/x86/kernel/asm-offsets_64.c
17020+++ b/arch/x86/kernel/asm-offsets_64.c
17021@@ -76,6 +76,7 @@ int main(void)
17022 BLANK();
17023 #undef ENTRY
17024
17025+ DEFINE(TSS_size, sizeof(struct tss_struct));
17026 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
17027 BLANK();
17028
17029diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
17030index a0e067d..9c7db16 100644
17031--- a/arch/x86/kernel/cpu/Makefile
17032+++ b/arch/x86/kernel/cpu/Makefile
17033@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
17034 CFLAGS_REMOVE_perf_event.o = -pg
17035 endif
17036
17037-# Make sure load_percpu_segment has no stackprotector
17038-nostackp := $(call cc-option, -fno-stack-protector)
17039-CFLAGS_common.o := $(nostackp)
17040-
17041 obj-y := intel_cacheinfo.o scattered.o topology.o
17042 obj-y += proc.o capflags.o powerflags.o common.o
17043 obj-y += vmware.o hypervisor.o mshyperv.o
17044diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
17045index 15239ff..e23e04e 100644
17046--- a/arch/x86/kernel/cpu/amd.c
17047+++ b/arch/x86/kernel/cpu/amd.c
17048@@ -733,7 +733,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
17049 unsigned int size)
17050 {
17051 /* AMD errata T13 (order #21922) */
17052- if ((c->x86 == 6)) {
17053+ if (c->x86 == 6) {
17054 /* Duron Rev A0 */
17055 if (c->x86_model == 3 && c->x86_mask == 0)
17056 size = 64;
17057diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
17058index 9c3ab43..51e6366 100644
17059--- a/arch/x86/kernel/cpu/common.c
17060+++ b/arch/x86/kernel/cpu/common.c
17061@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
17062
17063 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
17064
17065-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
17066-#ifdef CONFIG_X86_64
17067- /*
17068- * We need valid kernel segments for data and code in long mode too
17069- * IRET will check the segment types kkeil 2000/10/28
17070- * Also sysret mandates a special GDT layout
17071- *
17072- * TLS descriptors are currently at a different place compared to i386.
17073- * Hopefully nobody expects them at a fixed place (Wine?)
17074- */
17075- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
17076- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
17077- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
17078- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
17079- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
17080- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
17081-#else
17082- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
17083- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17084- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
17085- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
17086- /*
17087- * Segments used for calling PnP BIOS have byte granularity.
17088- * They code segments and data segments have fixed 64k limits,
17089- * the transfer segment sizes are set at run time.
17090- */
17091- /* 32-bit code */
17092- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17093- /* 16-bit code */
17094- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17095- /* 16-bit data */
17096- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
17097- /* 16-bit data */
17098- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
17099- /* 16-bit data */
17100- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
17101- /*
17102- * The APM segments have byte granularity and their bases
17103- * are set at run time. All have 64k limits.
17104- */
17105- /* 32-bit code */
17106- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17107- /* 16-bit code */
17108- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17109- /* data */
17110- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
17111-
17112- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17113- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17114- GDT_STACK_CANARY_INIT
17115-#endif
17116-} };
17117-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
17118-
17119 static int __init x86_xsave_setup(char *s)
17120 {
17121 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
17122@@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
17123 {
17124 struct desc_ptr gdt_descr;
17125
17126- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
17127+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17128 gdt_descr.size = GDT_SIZE - 1;
17129 load_gdt(&gdt_descr);
17130 /* Reload the per-cpu base */
17131@@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
17132 /* Filter out anything that depends on CPUID levels we don't have */
17133 filter_cpuid_features(c, true);
17134
17135+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
17136+ setup_clear_cpu_cap(X86_FEATURE_SEP);
17137+#endif
17138+
17139 /* If the model name is still unset, do table lookup. */
17140 if (!c->x86_model_id[0]) {
17141 const char *p;
17142@@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
17143 }
17144 __setup("clearcpuid=", setup_disablecpuid);
17145
17146+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
17147+EXPORT_PER_CPU_SYMBOL(current_tinfo);
17148+
17149 #ifdef CONFIG_X86_64
17150 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
17151-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
17152- (unsigned long) nmi_idt_table };
17153+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
17154
17155 DEFINE_PER_CPU_FIRST(union irq_stack_union,
17156 irq_stack_union) __aligned(PAGE_SIZE);
17157@@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
17158 EXPORT_PER_CPU_SYMBOL(current_task);
17159
17160 DEFINE_PER_CPU(unsigned long, kernel_stack) =
17161- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
17162+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
17163 EXPORT_PER_CPU_SYMBOL(kernel_stack);
17164
17165 DEFINE_PER_CPU(char *, irq_stack_ptr) =
17166@@ -1224,7 +1176,7 @@ void __cpuinit cpu_init(void)
17167 int i;
17168
17169 cpu = stack_smp_processor_id();
17170- t = &per_cpu(init_tss, cpu);
17171+ t = init_tss + cpu;
17172 oist = &per_cpu(orig_ist, cpu);
17173
17174 #ifdef CONFIG_NUMA
17175@@ -1250,7 +1202,7 @@ void __cpuinit cpu_init(void)
17176 switch_to_new_gdt(cpu);
17177 loadsegment(fs, 0);
17178
17179- load_idt((const struct desc_ptr *)&idt_descr);
17180+ load_idt(&idt_descr);
17181
17182 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
17183 syscall_init();
17184@@ -1259,7 +1211,6 @@ void __cpuinit cpu_init(void)
17185 wrmsrl(MSR_KERNEL_GS_BASE, 0);
17186 barrier();
17187
17188- x86_configure_nx();
17189 enable_x2apic();
17190
17191 /*
17192@@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
17193 {
17194 int cpu = smp_processor_id();
17195 struct task_struct *curr = current;
17196- struct tss_struct *t = &per_cpu(init_tss, cpu);
17197+ struct tss_struct *t = init_tss + cpu;
17198 struct thread_struct *thread = &curr->thread;
17199
17200 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
17201diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
17202index fcaabd0..7b55a26 100644
17203--- a/arch/x86/kernel/cpu/intel.c
17204+++ b/arch/x86/kernel/cpu/intel.c
17205@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
17206 * Update the IDT descriptor and reload the IDT so that
17207 * it uses the read-only mapped virtual address.
17208 */
17209- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
17210+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
17211 load_idt(&idt_descr);
17212 }
17213 #endif
17214diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
17215index 84c1309..39b7224 100644
17216--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
17217+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
17218@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
17219 };
17220
17221 #ifdef CONFIG_AMD_NB
17222+static struct attribute *default_attrs_amd_nb[] = {
17223+ &type.attr,
17224+ &level.attr,
17225+ &coherency_line_size.attr,
17226+ &physical_line_partition.attr,
17227+ &ways_of_associativity.attr,
17228+ &number_of_sets.attr,
17229+ &size.attr,
17230+ &shared_cpu_map.attr,
17231+ &shared_cpu_list.attr,
17232+ NULL,
17233+ NULL,
17234+ NULL,
17235+ NULL
17236+};
17237+
17238 static struct attribute ** __cpuinit amd_l3_attrs(void)
17239 {
17240 static struct attribute **attrs;
17241@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
17242
17243 n = ARRAY_SIZE(default_attrs);
17244
17245- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
17246- n += 2;
17247-
17248- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
17249- n += 1;
17250-
17251- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
17252- if (attrs == NULL)
17253- return attrs = default_attrs;
17254-
17255- for (n = 0; default_attrs[n]; n++)
17256- attrs[n] = default_attrs[n];
17257+ attrs = default_attrs_amd_nb;
17258
17259 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
17260 attrs[n++] = &cache_disable_0.attr;
17261@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
17262 .default_attrs = default_attrs,
17263 };
17264
17265+#ifdef CONFIG_AMD_NB
17266+static struct kobj_type ktype_cache_amd_nb = {
17267+ .sysfs_ops = &sysfs_ops,
17268+ .default_attrs = default_attrs_amd_nb,
17269+};
17270+#endif
17271+
17272 static struct kobj_type ktype_percpu_entry = {
17273 .sysfs_ops = &sysfs_ops,
17274 };
17275@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
17276 return retval;
17277 }
17278
17279+#ifdef CONFIG_AMD_NB
17280+ amd_l3_attrs();
17281+#endif
17282+
17283 for (i = 0; i < num_cache_leaves; i++) {
17284+ struct kobj_type *ktype;
17285+
17286 this_object = INDEX_KOBJECT_PTR(cpu, i);
17287 this_object->cpu = cpu;
17288 this_object->index = i;
17289
17290 this_leaf = CPUID4_INFO_IDX(cpu, i);
17291
17292- ktype_cache.default_attrs = default_attrs;
17293+ ktype = &ktype_cache;
17294 #ifdef CONFIG_AMD_NB
17295 if (this_leaf->base.nb)
17296- ktype_cache.default_attrs = amd_l3_attrs();
17297+ ktype = &ktype_cache_amd_nb;
17298 #endif
17299 retval = kobject_init_and_add(&(this_object->kobj),
17300- &ktype_cache,
17301+ ktype,
17302 per_cpu(ici_cache_kobject, cpu),
17303 "index%1lu", i);
17304 if (unlikely(retval)) {
17305@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
17306 return NOTIFY_OK;
17307 }
17308
17309-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
17310+static struct notifier_block cacheinfo_cpu_notifier = {
17311 .notifier_call = cacheinfo_cpu_callback,
17312 };
17313
17314diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
17315index 80dbda8..be16652 100644
17316--- a/arch/x86/kernel/cpu/mcheck/mce.c
17317+++ b/arch/x86/kernel/cpu/mcheck/mce.c
17318@@ -45,6 +45,7 @@
17319 #include <asm/processor.h>
17320 #include <asm/mce.h>
17321 #include <asm/msr.h>
17322+#include <asm/local.h>
17323
17324 #include "mce-internal.h"
17325
17326@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
17327 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
17328 m->cs, m->ip);
17329
17330- if (m->cs == __KERNEL_CS)
17331+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
17332 print_symbol("{%s}", m->ip);
17333 pr_cont("\n");
17334 }
17335@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
17336
17337 #define PANIC_TIMEOUT 5 /* 5 seconds */
17338
17339-static atomic_t mce_paniced;
17340+static atomic_unchecked_t mce_paniced;
17341
17342 static int fake_panic;
17343-static atomic_t mce_fake_paniced;
17344+static atomic_unchecked_t mce_fake_paniced;
17345
17346 /* Panic in progress. Enable interrupts and wait for final IPI */
17347 static void wait_for_panic(void)
17348@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17349 /*
17350 * Make sure only one CPU runs in machine check panic
17351 */
17352- if (atomic_inc_return(&mce_paniced) > 1)
17353+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
17354 wait_for_panic();
17355 barrier();
17356
17357@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17358 console_verbose();
17359 } else {
17360 /* Don't log too much for fake panic */
17361- if (atomic_inc_return(&mce_fake_paniced) > 1)
17362+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
17363 return;
17364 }
17365 /* First print corrected ones that are still unlogged */
17366@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
17367 * might have been modified by someone else.
17368 */
17369 rmb();
17370- if (atomic_read(&mce_paniced))
17371+ if (atomic_read_unchecked(&mce_paniced))
17372 wait_for_panic();
17373 if (!mca_cfg.monarch_timeout)
17374 goto out;
17375@@ -1662,7 +1663,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
17376 }
17377
17378 /* Call the installed machine check handler for this CPU setup. */
17379-void (*machine_check_vector)(struct pt_regs *, long error_code) =
17380+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
17381 unexpected_machine_check;
17382
17383 /*
17384@@ -1685,7 +1686,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17385 return;
17386 }
17387
17388+ pax_open_kernel();
17389 machine_check_vector = do_machine_check;
17390+ pax_close_kernel();
17391
17392 __mcheck_cpu_init_generic();
17393 __mcheck_cpu_init_vendor(c);
17394@@ -1699,7 +1702,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17395 */
17396
17397 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
17398-static int mce_chrdev_open_count; /* #times opened */
17399+static local_t mce_chrdev_open_count; /* #times opened */
17400 static int mce_chrdev_open_exclu; /* already open exclusive? */
17401
17402 static int mce_chrdev_open(struct inode *inode, struct file *file)
17403@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17404 spin_lock(&mce_chrdev_state_lock);
17405
17406 if (mce_chrdev_open_exclu ||
17407- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
17408+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
17409 spin_unlock(&mce_chrdev_state_lock);
17410
17411 return -EBUSY;
17412@@ -1715,7 +1718,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17413
17414 if (file->f_flags & O_EXCL)
17415 mce_chrdev_open_exclu = 1;
17416- mce_chrdev_open_count++;
17417+ local_inc(&mce_chrdev_open_count);
17418
17419 spin_unlock(&mce_chrdev_state_lock);
17420
17421@@ -1726,7 +1729,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
17422 {
17423 spin_lock(&mce_chrdev_state_lock);
17424
17425- mce_chrdev_open_count--;
17426+ local_dec(&mce_chrdev_open_count);
17427 mce_chrdev_open_exclu = 0;
17428
17429 spin_unlock(&mce_chrdev_state_lock);
17430@@ -2372,7 +2375,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
17431 return NOTIFY_OK;
17432 }
17433
17434-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
17435+static struct notifier_block mce_cpu_notifier = {
17436 .notifier_call = mce_cpu_callback,
17437 };
17438
17439@@ -2382,7 +2385,7 @@ static __init void mce_init_banks(void)
17440
17441 for (i = 0; i < mca_cfg.banks; i++) {
17442 struct mce_bank *b = &mce_banks[i];
17443- struct device_attribute *a = &b->attr;
17444+ device_attribute_no_const *a = &b->attr;
17445
17446 sysfs_attr_init(&a->attr);
17447 a->attr.name = b->attrname;
17448@@ -2450,7 +2453,7 @@ struct dentry *mce_get_debugfs_dir(void)
17449 static void mce_reset(void)
17450 {
17451 cpu_missing = 0;
17452- atomic_set(&mce_fake_paniced, 0);
17453+ atomic_set_unchecked(&mce_fake_paniced, 0);
17454 atomic_set(&mce_executing, 0);
17455 atomic_set(&mce_callin, 0);
17456 atomic_set(&global_nwo, 0);
17457diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
17458index 2d5454c..51987eb 100644
17459--- a/arch/x86/kernel/cpu/mcheck/p5.c
17460+++ b/arch/x86/kernel/cpu/mcheck/p5.c
17461@@ -11,6 +11,7 @@
17462 #include <asm/processor.h>
17463 #include <asm/mce.h>
17464 #include <asm/msr.h>
17465+#include <asm/pgtable.h>
17466
17467 /* By default disabled */
17468 int mce_p5_enabled __read_mostly;
17469@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
17470 if (!cpu_has(c, X86_FEATURE_MCE))
17471 return;
17472
17473+ pax_open_kernel();
17474 machine_check_vector = pentium_machine_check;
17475+ pax_close_kernel();
17476 /* Make sure the vector pointer is visible before we enable MCEs: */
17477 wmb();
17478
17479diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17480index 47a1870..8c019a7 100644
17481--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
17482+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17483@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
17484 return notifier_from_errno(err);
17485 }
17486
17487-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17488+static struct notifier_block thermal_throttle_cpu_notifier =
17489 {
17490 .notifier_call = thermal_throttle_cpu_callback,
17491 };
17492diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17493index 2d7998f..17c9de1 100644
17494--- a/arch/x86/kernel/cpu/mcheck/winchip.c
17495+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17496@@ -10,6 +10,7 @@
17497 #include <asm/processor.h>
17498 #include <asm/mce.h>
17499 #include <asm/msr.h>
17500+#include <asm/pgtable.h>
17501
17502 /* Machine check handler for WinChip C6: */
17503 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17504@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17505 {
17506 u32 lo, hi;
17507
17508+ pax_open_kernel();
17509 machine_check_vector = winchip_machine_check;
17510+ pax_close_kernel();
17511 /* Make sure the vector pointer is visible before we enable MCEs: */
17512 wmb();
17513
17514diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17515index 726bf96..81f0526 100644
17516--- a/arch/x86/kernel/cpu/mtrr/main.c
17517+++ b/arch/x86/kernel/cpu/mtrr/main.c
17518@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17519 u64 size_or_mask, size_and_mask;
17520 static bool mtrr_aps_delayed_init;
17521
17522-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17523+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17524
17525 const struct mtrr_ops *mtrr_if;
17526
17527diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17528index df5e41f..816c719 100644
17529--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17530+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17531@@ -25,7 +25,7 @@ struct mtrr_ops {
17532 int (*validate_add_page)(unsigned long base, unsigned long size,
17533 unsigned int type);
17534 int (*have_wrcomb)(void);
17535-};
17536+} __do_const;
17537
17538 extern int generic_get_free_region(unsigned long base, unsigned long size,
17539 int replace_reg);
17540diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17541index 6774c17..72c1b22 100644
17542--- a/arch/x86/kernel/cpu/perf_event.c
17543+++ b/arch/x86/kernel/cpu/perf_event.c
17544@@ -1305,7 +1305,7 @@ static void __init pmu_check_apic(void)
17545 pr_info("no hardware sampling interrupt available.\n");
17546 }
17547
17548-static struct attribute_group x86_pmu_format_group = {
17549+static attribute_group_no_const x86_pmu_format_group = {
17550 .name = "format",
17551 .attrs = NULL,
17552 };
17553@@ -1313,7 +1313,7 @@ static struct attribute_group x86_pmu_format_group = {
17554 struct perf_pmu_events_attr {
17555 struct device_attribute attr;
17556 u64 id;
17557-};
17558+} __do_const;
17559
17560 /*
17561 * Remove all undefined events (x86_pmu.event_map(id) == 0)
17562@@ -1381,7 +1381,7 @@ static struct attribute *events_attr[] = {
17563 NULL,
17564 };
17565
17566-static struct attribute_group x86_pmu_events_group = {
17567+static attribute_group_no_const x86_pmu_events_group = {
17568 .name = "events",
17569 .attrs = events_attr,
17570 };
17571@@ -1880,7 +1880,7 @@ static unsigned long get_segment_base(unsigned int segment)
17572 if (idx > GDT_ENTRIES)
17573 return 0;
17574
17575- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17576+ desc = get_cpu_gdt_table(smp_processor_id());
17577 }
17578
17579 return get_desc_base(desc + idx);
17580@@ -1970,7 +1970,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17581 break;
17582
17583 perf_callchain_store(entry, frame.return_address);
17584- fp = frame.next_frame;
17585+ fp = (const void __force_user *)frame.next_frame;
17586 }
17587 }
17588
17589diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17590index 4914e94..60b06e3 100644
17591--- a/arch/x86/kernel/cpu/perf_event_intel.c
17592+++ b/arch/x86/kernel/cpu/perf_event_intel.c
17593@@ -1958,10 +1958,10 @@ __init int intel_pmu_init(void)
17594 * v2 and above have a perf capabilities MSR
17595 */
17596 if (version > 1) {
17597- u64 capabilities;
17598+ u64 capabilities = x86_pmu.intel_cap.capabilities;
17599
17600- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17601- x86_pmu.intel_cap.capabilities = capabilities;
17602+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17603+ x86_pmu.intel_cap.capabilities = capabilities;
17604 }
17605
17606 intel_ds_init();
17607diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17608index b43200d..d235b3e 100644
17609--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17610+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17611@@ -2428,7 +2428,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
17612 static int __init uncore_type_init(struct intel_uncore_type *type)
17613 {
17614 struct intel_uncore_pmu *pmus;
17615- struct attribute_group *events_group;
17616+ attribute_group_no_const *attr_group;
17617 struct attribute **attrs;
17618 int i, j;
17619
17620@@ -2455,19 +2455,19 @@ static int __init uncore_type_init(struct intel_uncore_type *type)
17621 while (type->event_descs[i].attr.attr.name)
17622 i++;
17623
17624- events_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
17625- sizeof(*events_group), GFP_KERNEL);
17626- if (!events_group)
17627+ attr_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
17628+ sizeof(*attr_group), GFP_KERNEL);
17629+ if (!attr_group)
17630 goto fail;
17631
17632- attrs = (struct attribute **)(events_group + 1);
17633- events_group->name = "events";
17634- events_group->attrs = attrs;
17635+ attrs = (struct attribute **)(attr_group + 1);
17636+ attr_group->name = "events";
17637+ attr_group->attrs = attrs;
17638
17639 for (j = 0; j < i; j++)
17640 attrs[j] = &type->event_descs[j].attr.attr;
17641
17642- type->events_group = events_group;
17643+ type->events_group = attr_group;
17644 }
17645
17646 type->pmu_group = &uncore_pmu_attr_group;
17647@@ -2826,7 +2826,7 @@ static int
17648 return NOTIFY_OK;
17649 }
17650
17651-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17652+static struct notifier_block uncore_cpu_nb = {
17653 .notifier_call = uncore_cpu_notifier,
17654 /*
17655 * to migrate uncore events, our notifier should be executed
17656diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17657index e68a455..975a932 100644
17658--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17659+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17660@@ -428,7 +428,7 @@ struct intel_uncore_box {
17661 struct uncore_event_desc {
17662 struct kobj_attribute attr;
17663 const char *config;
17664-};
17665+} __do_const;
17666
17667 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
17668 { \
17669diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17670index 60c7891..9e911d3 100644
17671--- a/arch/x86/kernel/cpuid.c
17672+++ b/arch/x86/kernel/cpuid.c
17673@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17674 return notifier_from_errno(err);
17675 }
17676
17677-static struct notifier_block __refdata cpuid_class_cpu_notifier =
17678+static struct notifier_block cpuid_class_cpu_notifier =
17679 {
17680 .notifier_call = cpuid_class_cpu_callback,
17681 };
17682diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17683index 74467fe..18793d5 100644
17684--- a/arch/x86/kernel/crash.c
17685+++ b/arch/x86/kernel/crash.c
17686@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17687 {
17688 #ifdef CONFIG_X86_32
17689 struct pt_regs fixed_regs;
17690-#endif
17691
17692-#ifdef CONFIG_X86_32
17693- if (!user_mode_vm(regs)) {
17694+ if (!user_mode(regs)) {
17695 crash_fixup_ss_esp(&fixed_regs, regs);
17696 regs = &fixed_regs;
17697 }
17698diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17699index 37250fe..bf2ec74 100644
17700--- a/arch/x86/kernel/doublefault_32.c
17701+++ b/arch/x86/kernel/doublefault_32.c
17702@@ -11,7 +11,7 @@
17703
17704 #define DOUBLEFAULT_STACKSIZE (1024)
17705 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17706-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17707+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17708
17709 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17710
17711@@ -21,7 +21,7 @@ static void doublefault_fn(void)
17712 unsigned long gdt, tss;
17713
17714 store_gdt(&gdt_desc);
17715- gdt = gdt_desc.address;
17716+ gdt = (unsigned long)gdt_desc.address;
17717
17718 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17719
17720@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17721 /* 0x2 bit is always set */
17722 .flags = X86_EFLAGS_SF | 0x2,
17723 .sp = STACK_START,
17724- .es = __USER_DS,
17725+ .es = __KERNEL_DS,
17726 .cs = __KERNEL_CS,
17727 .ss = __KERNEL_DS,
17728- .ds = __USER_DS,
17729+ .ds = __KERNEL_DS,
17730 .fs = __KERNEL_PERCPU,
17731
17732 .__cr3 = __pa_nodebug(swapper_pg_dir),
17733diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17734index ae42418b..787c16b 100644
17735--- a/arch/x86/kernel/dumpstack.c
17736+++ b/arch/x86/kernel/dumpstack.c
17737@@ -2,6 +2,9 @@
17738 * Copyright (C) 1991, 1992 Linus Torvalds
17739 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17740 */
17741+#ifdef CONFIG_GRKERNSEC_HIDESYM
17742+#define __INCLUDED_BY_HIDESYM 1
17743+#endif
17744 #include <linux/kallsyms.h>
17745 #include <linux/kprobes.h>
17746 #include <linux/uaccess.h>
17747@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17748 static void
17749 print_ftrace_graph_addr(unsigned long addr, void *data,
17750 const struct stacktrace_ops *ops,
17751- struct thread_info *tinfo, int *graph)
17752+ struct task_struct *task, int *graph)
17753 {
17754- struct task_struct *task;
17755 unsigned long ret_addr;
17756 int index;
17757
17758 if (addr != (unsigned long)return_to_handler)
17759 return;
17760
17761- task = tinfo->task;
17762 index = task->curr_ret_stack;
17763
17764 if (!task->ret_stack || index < *graph)
17765@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17766 static inline void
17767 print_ftrace_graph_addr(unsigned long addr, void *data,
17768 const struct stacktrace_ops *ops,
17769- struct thread_info *tinfo, int *graph)
17770+ struct task_struct *task, int *graph)
17771 { }
17772 #endif
17773
17774@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17775 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17776 */
17777
17778-static inline int valid_stack_ptr(struct thread_info *tinfo,
17779- void *p, unsigned int size, void *end)
17780+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17781 {
17782- void *t = tinfo;
17783 if (end) {
17784 if (p < end && p >= (end-THREAD_SIZE))
17785 return 1;
17786@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17787 }
17788
17789 unsigned long
17790-print_context_stack(struct thread_info *tinfo,
17791+print_context_stack(struct task_struct *task, void *stack_start,
17792 unsigned long *stack, unsigned long bp,
17793 const struct stacktrace_ops *ops, void *data,
17794 unsigned long *end, int *graph)
17795 {
17796 struct stack_frame *frame = (struct stack_frame *)bp;
17797
17798- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17799+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17800 unsigned long addr;
17801
17802 addr = *stack;
17803@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17804 } else {
17805 ops->address(data, addr, 0);
17806 }
17807- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17808+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17809 }
17810 stack++;
17811 }
17812@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17813 EXPORT_SYMBOL_GPL(print_context_stack);
17814
17815 unsigned long
17816-print_context_stack_bp(struct thread_info *tinfo,
17817+print_context_stack_bp(struct task_struct *task, void *stack_start,
17818 unsigned long *stack, unsigned long bp,
17819 const struct stacktrace_ops *ops, void *data,
17820 unsigned long *end, int *graph)
17821@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17822 struct stack_frame *frame = (struct stack_frame *)bp;
17823 unsigned long *ret_addr = &frame->return_address;
17824
17825- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17826+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17827 unsigned long addr = *ret_addr;
17828
17829 if (!__kernel_text_address(addr))
17830@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17831 ops->address(data, addr, 1);
17832 frame = frame->next_frame;
17833 ret_addr = &frame->return_address;
17834- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17835+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17836 }
17837
17838 return (unsigned long)frame;
17839@@ -189,7 +188,7 @@ void dump_stack(void)
17840
17841 bp = stack_frame(current, NULL);
17842 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
17843- current->pid, current->comm, print_tainted(),
17844+ task_pid_nr(current), current->comm, print_tainted(),
17845 init_utsname()->release,
17846 (int)strcspn(init_utsname()->version, " "),
17847 init_utsname()->version);
17848@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
17849 }
17850 EXPORT_SYMBOL_GPL(oops_begin);
17851
17852+extern void gr_handle_kernel_exploit(void);
17853+
17854 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17855 {
17856 if (regs && kexec_should_crash(current))
17857@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17858 panic("Fatal exception in interrupt");
17859 if (panic_on_oops)
17860 panic("Fatal exception");
17861- do_exit(signr);
17862+
17863+ gr_handle_kernel_exploit();
17864+
17865+ do_group_exit(signr);
17866 }
17867
17868 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17869@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17870 print_modules();
17871 show_regs(regs);
17872 #ifdef CONFIG_X86_32
17873- if (user_mode_vm(regs)) {
17874+ if (user_mode(regs)) {
17875 sp = regs->sp;
17876 ss = regs->ss & 0xffff;
17877 } else {
17878@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
17879 unsigned long flags = oops_begin();
17880 int sig = SIGSEGV;
17881
17882- if (!user_mode_vm(regs))
17883+ if (!user_mode(regs))
17884 report_bug(regs->ip, regs);
17885
17886 if (__die(str, regs, err))
17887diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
17888index 1038a41..db2c12b 100644
17889--- a/arch/x86/kernel/dumpstack_32.c
17890+++ b/arch/x86/kernel/dumpstack_32.c
17891@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17892 bp = stack_frame(task, regs);
17893
17894 for (;;) {
17895- struct thread_info *context;
17896+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17897
17898- context = (struct thread_info *)
17899- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
17900- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
17901+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17902
17903- stack = (unsigned long *)context->previous_esp;
17904- if (!stack)
17905+ if (stack_start == task_stack_page(task))
17906 break;
17907+ stack = *(unsigned long **)stack_start;
17908 if (ops->stack(data, "IRQ") < 0)
17909 break;
17910 touch_nmi_watchdog();
17911@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
17912 {
17913 int i;
17914
17915- __show_regs(regs, !user_mode_vm(regs));
17916+ __show_regs(regs, !user_mode(regs));
17917
17918 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
17919 TASK_COMM_LEN, current->comm, task_pid_nr(current),
17920@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
17921 * When in-kernel, we also print out the stack and code at the
17922 * time of the fault..
17923 */
17924- if (!user_mode_vm(regs)) {
17925+ if (!user_mode(regs)) {
17926 unsigned int code_prologue = code_bytes * 43 / 64;
17927 unsigned int code_len = code_bytes;
17928 unsigned char c;
17929 u8 *ip;
17930+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
17931
17932 pr_emerg("Stack:\n");
17933 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
17934
17935 pr_emerg("Code:");
17936
17937- ip = (u8 *)regs->ip - code_prologue;
17938+ ip = (u8 *)regs->ip - code_prologue + cs_base;
17939 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
17940 /* try starting at IP */
17941- ip = (u8 *)regs->ip;
17942+ ip = (u8 *)regs->ip + cs_base;
17943 code_len = code_len - code_prologue + 1;
17944 }
17945 for (i = 0; i < code_len; i++, ip++) {
17946@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
17947 pr_cont(" Bad EIP value.");
17948 break;
17949 }
17950- if (ip == (u8 *)regs->ip)
17951+ if (ip == (u8 *)regs->ip + cs_base)
17952 pr_cont(" <%02x>", c);
17953 else
17954 pr_cont(" %02x", c);
17955@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
17956 {
17957 unsigned short ud2;
17958
17959+ ip = ktla_ktva(ip);
17960 if (ip < PAGE_OFFSET)
17961 return 0;
17962 if (probe_kernel_address((unsigned short *)ip, ud2))
17963@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
17964
17965 return ud2 == 0x0b0f;
17966 }
17967+
17968+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17969+void pax_check_alloca(unsigned long size)
17970+{
17971+ unsigned long sp = (unsigned long)&sp, stack_left;
17972+
17973+ /* all kernel stacks are of the same size */
17974+ stack_left = sp & (THREAD_SIZE - 1);
17975+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17976+}
17977+EXPORT_SYMBOL(pax_check_alloca);
17978+#endif
17979diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
17980index b653675..51cc8c0 100644
17981--- a/arch/x86/kernel/dumpstack_64.c
17982+++ b/arch/x86/kernel/dumpstack_64.c
17983@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17984 unsigned long *irq_stack_end =
17985 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
17986 unsigned used = 0;
17987- struct thread_info *tinfo;
17988 int graph = 0;
17989 unsigned long dummy;
17990+ void *stack_start;
17991
17992 if (!task)
17993 task = current;
17994@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17995 * current stack address. If the stacks consist of nested
17996 * exceptions
17997 */
17998- tinfo = task_thread_info(task);
17999 for (;;) {
18000 char *id;
18001 unsigned long *estack_end;
18002+
18003 estack_end = in_exception_stack(cpu, (unsigned long)stack,
18004 &used, &id);
18005
18006@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18007 if (ops->stack(data, id) < 0)
18008 break;
18009
18010- bp = ops->walk_stack(tinfo, stack, bp, ops,
18011+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
18012 data, estack_end, &graph);
18013 ops->stack(data, "<EOE>");
18014 /*
18015@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18016 * second-to-last pointer (index -2 to end) in the
18017 * exception stack:
18018 */
18019+ if ((u16)estack_end[-1] != __KERNEL_DS)
18020+ goto out;
18021 stack = (unsigned long *) estack_end[-2];
18022 continue;
18023 }
18024@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18025 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
18026 if (ops->stack(data, "IRQ") < 0)
18027 break;
18028- bp = ops->walk_stack(tinfo, stack, bp,
18029+ bp = ops->walk_stack(task, irq_stack, stack, bp,
18030 ops, data, irq_stack_end, &graph);
18031 /*
18032 * We link to the next stack (which would be
18033@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18034 /*
18035 * This handles the process stack:
18036 */
18037- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
18038+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18039+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18040+out:
18041 put_cpu();
18042 }
18043 EXPORT_SYMBOL(dump_trace);
18044@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
18045 {
18046 int i;
18047 unsigned long sp;
18048- const int cpu = smp_processor_id();
18049+ const int cpu = raw_smp_processor_id();
18050 struct task_struct *cur = current;
18051
18052 sp = regs->sp;
18053@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
18054
18055 return ud2 == 0x0b0f;
18056 }
18057+
18058+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18059+void pax_check_alloca(unsigned long size)
18060+{
18061+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
18062+ unsigned cpu, used;
18063+ char *id;
18064+
18065+ /* check the process stack first */
18066+ stack_start = (unsigned long)task_stack_page(current);
18067+ stack_end = stack_start + THREAD_SIZE;
18068+ if (likely(stack_start <= sp && sp < stack_end)) {
18069+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
18070+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18071+ return;
18072+ }
18073+
18074+ cpu = get_cpu();
18075+
18076+ /* check the irq stacks */
18077+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
18078+ stack_start = stack_end - IRQ_STACK_SIZE;
18079+ if (stack_start <= sp && sp < stack_end) {
18080+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
18081+ put_cpu();
18082+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18083+ return;
18084+ }
18085+
18086+ /* check the exception stacks */
18087+ used = 0;
18088+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
18089+ stack_start = stack_end - EXCEPTION_STKSZ;
18090+ if (stack_end && stack_start <= sp && sp < stack_end) {
18091+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
18092+ put_cpu();
18093+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18094+ return;
18095+ }
18096+
18097+ put_cpu();
18098+
18099+ /* unknown stack */
18100+ BUG();
18101+}
18102+EXPORT_SYMBOL(pax_check_alloca);
18103+#endif
18104diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
18105index 9b9f18b..9fcaa04 100644
18106--- a/arch/x86/kernel/early_printk.c
18107+++ b/arch/x86/kernel/early_printk.c
18108@@ -7,6 +7,7 @@
18109 #include <linux/pci_regs.h>
18110 #include <linux/pci_ids.h>
18111 #include <linux/errno.h>
18112+#include <linux/sched.h>
18113 #include <asm/io.h>
18114 #include <asm/processor.h>
18115 #include <asm/fcntl.h>
18116diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
18117index 6ed91d9..6cc365b 100644
18118--- a/arch/x86/kernel/entry_32.S
18119+++ b/arch/x86/kernel/entry_32.S
18120@@ -177,13 +177,153 @@
18121 /*CFI_REL_OFFSET gs, PT_GS*/
18122 .endm
18123 .macro SET_KERNEL_GS reg
18124+
18125+#ifdef CONFIG_CC_STACKPROTECTOR
18126 movl $(__KERNEL_STACK_CANARY), \reg
18127+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18128+ movl $(__USER_DS), \reg
18129+#else
18130+ xorl \reg, \reg
18131+#endif
18132+
18133 movl \reg, %gs
18134 .endm
18135
18136 #endif /* CONFIG_X86_32_LAZY_GS */
18137
18138-.macro SAVE_ALL
18139+.macro pax_enter_kernel
18140+#ifdef CONFIG_PAX_KERNEXEC
18141+ call pax_enter_kernel
18142+#endif
18143+.endm
18144+
18145+.macro pax_exit_kernel
18146+#ifdef CONFIG_PAX_KERNEXEC
18147+ call pax_exit_kernel
18148+#endif
18149+.endm
18150+
18151+#ifdef CONFIG_PAX_KERNEXEC
18152+ENTRY(pax_enter_kernel)
18153+#ifdef CONFIG_PARAVIRT
18154+ pushl %eax
18155+ pushl %ecx
18156+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
18157+ mov %eax, %esi
18158+#else
18159+ mov %cr0, %esi
18160+#endif
18161+ bts $16, %esi
18162+ jnc 1f
18163+ mov %cs, %esi
18164+ cmp $__KERNEL_CS, %esi
18165+ jz 3f
18166+ ljmp $__KERNEL_CS, $3f
18167+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
18168+2:
18169+#ifdef CONFIG_PARAVIRT
18170+ mov %esi, %eax
18171+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18172+#else
18173+ mov %esi, %cr0
18174+#endif
18175+3:
18176+#ifdef CONFIG_PARAVIRT
18177+ popl %ecx
18178+ popl %eax
18179+#endif
18180+ ret
18181+ENDPROC(pax_enter_kernel)
18182+
18183+ENTRY(pax_exit_kernel)
18184+#ifdef CONFIG_PARAVIRT
18185+ pushl %eax
18186+ pushl %ecx
18187+#endif
18188+ mov %cs, %esi
18189+ cmp $__KERNEXEC_KERNEL_CS, %esi
18190+ jnz 2f
18191+#ifdef CONFIG_PARAVIRT
18192+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
18193+ mov %eax, %esi
18194+#else
18195+ mov %cr0, %esi
18196+#endif
18197+ btr $16, %esi
18198+ ljmp $__KERNEL_CS, $1f
18199+1:
18200+#ifdef CONFIG_PARAVIRT
18201+ mov %esi, %eax
18202+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
18203+#else
18204+ mov %esi, %cr0
18205+#endif
18206+2:
18207+#ifdef CONFIG_PARAVIRT
18208+ popl %ecx
18209+ popl %eax
18210+#endif
18211+ ret
18212+ENDPROC(pax_exit_kernel)
18213+#endif
18214+
18215+.macro pax_erase_kstack
18216+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18217+ call pax_erase_kstack
18218+#endif
18219+.endm
18220+
18221+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18222+/*
18223+ * ebp: thread_info
18224+ */
18225+ENTRY(pax_erase_kstack)
18226+ pushl %edi
18227+ pushl %ecx
18228+ pushl %eax
18229+
18230+ mov TI_lowest_stack(%ebp), %edi
18231+ mov $-0xBEEF, %eax
18232+ std
18233+
18234+1: mov %edi, %ecx
18235+ and $THREAD_SIZE_asm - 1, %ecx
18236+ shr $2, %ecx
18237+ repne scasl
18238+ jecxz 2f
18239+
18240+ cmp $2*16, %ecx
18241+ jc 2f
18242+
18243+ mov $2*16, %ecx
18244+ repe scasl
18245+ jecxz 2f
18246+ jne 1b
18247+
18248+2: cld
18249+ mov %esp, %ecx
18250+ sub %edi, %ecx
18251+
18252+ cmp $THREAD_SIZE_asm, %ecx
18253+ jb 3f
18254+ ud2
18255+3:
18256+
18257+ shr $2, %ecx
18258+ rep stosl
18259+
18260+ mov TI_task_thread_sp0(%ebp), %edi
18261+ sub $128, %edi
18262+ mov %edi, TI_lowest_stack(%ebp)
18263+
18264+ popl %eax
18265+ popl %ecx
18266+ popl %edi
18267+ ret
18268+ENDPROC(pax_erase_kstack)
18269+#endif
18270+
18271+.macro __SAVE_ALL _DS
18272 cld
18273 PUSH_GS
18274 pushl_cfi %fs
18275@@ -206,7 +346,7 @@
18276 CFI_REL_OFFSET ecx, 0
18277 pushl_cfi %ebx
18278 CFI_REL_OFFSET ebx, 0
18279- movl $(__USER_DS), %edx
18280+ movl $\_DS, %edx
18281 movl %edx, %ds
18282 movl %edx, %es
18283 movl $(__KERNEL_PERCPU), %edx
18284@@ -214,6 +354,15 @@
18285 SET_KERNEL_GS %edx
18286 .endm
18287
18288+.macro SAVE_ALL
18289+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18290+ __SAVE_ALL __KERNEL_DS
18291+ pax_enter_kernel
18292+#else
18293+ __SAVE_ALL __USER_DS
18294+#endif
18295+.endm
18296+
18297 .macro RESTORE_INT_REGS
18298 popl_cfi %ebx
18299 CFI_RESTORE ebx
18300@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
18301 popfl_cfi
18302 jmp syscall_exit
18303 CFI_ENDPROC
18304-END(ret_from_fork)
18305+ENDPROC(ret_from_fork)
18306
18307 ENTRY(ret_from_kernel_thread)
18308 CFI_STARTPROC
18309@@ -344,7 +493,15 @@ ret_from_intr:
18310 andl $SEGMENT_RPL_MASK, %eax
18311 #endif
18312 cmpl $USER_RPL, %eax
18313+
18314+#ifdef CONFIG_PAX_KERNEXEC
18315+ jae resume_userspace
18316+
18317+ pax_exit_kernel
18318+ jmp resume_kernel
18319+#else
18320 jb resume_kernel # not returning to v8086 or userspace
18321+#endif
18322
18323 ENTRY(resume_userspace)
18324 LOCKDEP_SYS_EXIT
18325@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
18326 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
18327 # int/exception return?
18328 jne work_pending
18329- jmp restore_all
18330-END(ret_from_exception)
18331+ jmp restore_all_pax
18332+ENDPROC(ret_from_exception)
18333
18334 #ifdef CONFIG_PREEMPT
18335 ENTRY(resume_kernel)
18336@@ -372,7 +529,7 @@ need_resched:
18337 jz restore_all
18338 call preempt_schedule_irq
18339 jmp need_resched
18340-END(resume_kernel)
18341+ENDPROC(resume_kernel)
18342 #endif
18343 CFI_ENDPROC
18344 /*
18345@@ -406,30 +563,45 @@ sysenter_past_esp:
18346 /*CFI_REL_OFFSET cs, 0*/
18347 /*
18348 * Push current_thread_info()->sysenter_return to the stack.
18349- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
18350- * pushed above; +8 corresponds to copy_thread's esp0 setting.
18351 */
18352- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
18353+ pushl_cfi $0
18354 CFI_REL_OFFSET eip, 0
18355
18356 pushl_cfi %eax
18357 SAVE_ALL
18358+ GET_THREAD_INFO(%ebp)
18359+ movl TI_sysenter_return(%ebp),%ebp
18360+ movl %ebp,PT_EIP(%esp)
18361 ENABLE_INTERRUPTS(CLBR_NONE)
18362
18363 /*
18364 * Load the potential sixth argument from user stack.
18365 * Careful about security.
18366 */
18367+ movl PT_OLDESP(%esp),%ebp
18368+
18369+#ifdef CONFIG_PAX_MEMORY_UDEREF
18370+ mov PT_OLDSS(%esp),%ds
18371+1: movl %ds:(%ebp),%ebp
18372+ push %ss
18373+ pop %ds
18374+#else
18375 cmpl $__PAGE_OFFSET-3,%ebp
18376 jae syscall_fault
18377 ASM_STAC
18378 1: movl (%ebp),%ebp
18379 ASM_CLAC
18380+#endif
18381+
18382 movl %ebp,PT_EBP(%esp)
18383 _ASM_EXTABLE(1b,syscall_fault)
18384
18385 GET_THREAD_INFO(%ebp)
18386
18387+#ifdef CONFIG_PAX_RANDKSTACK
18388+ pax_erase_kstack
18389+#endif
18390+
18391 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18392 jnz sysenter_audit
18393 sysenter_do_call:
18394@@ -444,12 +616,24 @@ sysenter_do_call:
18395 testl $_TIF_ALLWORK_MASK, %ecx
18396 jne sysexit_audit
18397 sysenter_exit:
18398+
18399+#ifdef CONFIG_PAX_RANDKSTACK
18400+ pushl_cfi %eax
18401+ movl %esp, %eax
18402+ call pax_randomize_kstack
18403+ popl_cfi %eax
18404+#endif
18405+
18406+ pax_erase_kstack
18407+
18408 /* if something modifies registers it must also disable sysexit */
18409 movl PT_EIP(%esp), %edx
18410 movl PT_OLDESP(%esp), %ecx
18411 xorl %ebp,%ebp
18412 TRACE_IRQS_ON
18413 1: mov PT_FS(%esp), %fs
18414+2: mov PT_DS(%esp), %ds
18415+3: mov PT_ES(%esp), %es
18416 PTGS_TO_GS
18417 ENABLE_INTERRUPTS_SYSEXIT
18418
18419@@ -466,6 +650,9 @@ sysenter_audit:
18420 movl %eax,%edx /* 2nd arg: syscall number */
18421 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
18422 call __audit_syscall_entry
18423+
18424+ pax_erase_kstack
18425+
18426 pushl_cfi %ebx
18427 movl PT_EAX(%esp),%eax /* reload syscall number */
18428 jmp sysenter_do_call
18429@@ -491,10 +678,16 @@ sysexit_audit:
18430
18431 CFI_ENDPROC
18432 .pushsection .fixup,"ax"
18433-2: movl $0,PT_FS(%esp)
18434+4: movl $0,PT_FS(%esp)
18435+ jmp 1b
18436+5: movl $0,PT_DS(%esp)
18437+ jmp 1b
18438+6: movl $0,PT_ES(%esp)
18439 jmp 1b
18440 .popsection
18441- _ASM_EXTABLE(1b,2b)
18442+ _ASM_EXTABLE(1b,4b)
18443+ _ASM_EXTABLE(2b,5b)
18444+ _ASM_EXTABLE(3b,6b)
18445 PTGS_TO_GS_EX
18446 ENDPROC(ia32_sysenter_target)
18447
18448@@ -509,6 +702,11 @@ ENTRY(system_call)
18449 pushl_cfi %eax # save orig_eax
18450 SAVE_ALL
18451 GET_THREAD_INFO(%ebp)
18452+
18453+#ifdef CONFIG_PAX_RANDKSTACK
18454+ pax_erase_kstack
18455+#endif
18456+
18457 # system call tracing in operation / emulation
18458 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18459 jnz syscall_trace_entry
18460@@ -527,6 +725,15 @@ syscall_exit:
18461 testl $_TIF_ALLWORK_MASK, %ecx # current->work
18462 jne syscall_exit_work
18463
18464+restore_all_pax:
18465+
18466+#ifdef CONFIG_PAX_RANDKSTACK
18467+ movl %esp, %eax
18468+ call pax_randomize_kstack
18469+#endif
18470+
18471+ pax_erase_kstack
18472+
18473 restore_all:
18474 TRACE_IRQS_IRET
18475 restore_all_notrace:
18476@@ -583,14 +790,34 @@ ldt_ss:
18477 * compensating for the offset by changing to the ESPFIX segment with
18478 * a base address that matches for the difference.
18479 */
18480-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
18481+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
18482 mov %esp, %edx /* load kernel esp */
18483 mov PT_OLDESP(%esp), %eax /* load userspace esp */
18484 mov %dx, %ax /* eax: new kernel esp */
18485 sub %eax, %edx /* offset (low word is 0) */
18486+#ifdef CONFIG_SMP
18487+ movl PER_CPU_VAR(cpu_number), %ebx
18488+ shll $PAGE_SHIFT_asm, %ebx
18489+ addl $cpu_gdt_table, %ebx
18490+#else
18491+ movl $cpu_gdt_table, %ebx
18492+#endif
18493 shr $16, %edx
18494- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
18495- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
18496+
18497+#ifdef CONFIG_PAX_KERNEXEC
18498+ mov %cr0, %esi
18499+ btr $16, %esi
18500+ mov %esi, %cr0
18501+#endif
18502+
18503+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
18504+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
18505+
18506+#ifdef CONFIG_PAX_KERNEXEC
18507+ bts $16, %esi
18508+ mov %esi, %cr0
18509+#endif
18510+
18511 pushl_cfi $__ESPFIX_SS
18512 pushl_cfi %eax /* new kernel esp */
18513 /* Disable interrupts, but do not irqtrace this section: we
18514@@ -619,20 +846,18 @@ work_resched:
18515 movl TI_flags(%ebp), %ecx
18516 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
18517 # than syscall tracing?
18518- jz restore_all
18519+ jz restore_all_pax
18520 testb $_TIF_NEED_RESCHED, %cl
18521 jnz work_resched
18522
18523 work_notifysig: # deal with pending signals and
18524 # notify-resume requests
18525+ movl %esp, %eax
18526 #ifdef CONFIG_VM86
18527 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
18528- movl %esp, %eax
18529 jne work_notifysig_v86 # returning to kernel-space or
18530 # vm86-space
18531 1:
18532-#else
18533- movl %esp, %eax
18534 #endif
18535 TRACE_IRQS_ON
18536 ENABLE_INTERRUPTS(CLBR_NONE)
18537@@ -653,7 +878,7 @@ work_notifysig_v86:
18538 movl %eax, %esp
18539 jmp 1b
18540 #endif
18541-END(work_pending)
18542+ENDPROC(work_pending)
18543
18544 # perform syscall exit tracing
18545 ALIGN
18546@@ -661,11 +886,14 @@ syscall_trace_entry:
18547 movl $-ENOSYS,PT_EAX(%esp)
18548 movl %esp, %eax
18549 call syscall_trace_enter
18550+
18551+ pax_erase_kstack
18552+
18553 /* What it returned is what we'll actually use. */
18554 cmpl $(NR_syscalls), %eax
18555 jnae syscall_call
18556 jmp syscall_exit
18557-END(syscall_trace_entry)
18558+ENDPROC(syscall_trace_entry)
18559
18560 # perform syscall exit tracing
18561 ALIGN
18562@@ -678,21 +906,25 @@ syscall_exit_work:
18563 movl %esp, %eax
18564 call syscall_trace_leave
18565 jmp resume_userspace
18566-END(syscall_exit_work)
18567+ENDPROC(syscall_exit_work)
18568 CFI_ENDPROC
18569
18570 RING0_INT_FRAME # can't unwind into user space anyway
18571 syscall_fault:
18572+#ifdef CONFIG_PAX_MEMORY_UDEREF
18573+ push %ss
18574+ pop %ds
18575+#endif
18576 ASM_CLAC
18577 GET_THREAD_INFO(%ebp)
18578 movl $-EFAULT,PT_EAX(%esp)
18579 jmp resume_userspace
18580-END(syscall_fault)
18581+ENDPROC(syscall_fault)
18582
18583 syscall_badsys:
18584 movl $-ENOSYS,PT_EAX(%esp)
18585 jmp resume_userspace
18586-END(syscall_badsys)
18587+ENDPROC(syscall_badsys)
18588 CFI_ENDPROC
18589 /*
18590 * End of kprobes section
18591@@ -753,8 +985,15 @@ PTREGSCALL1(vm86old)
18592 * normal stack and adjusts ESP with the matching offset.
18593 */
18594 /* fixup the stack */
18595- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18596- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18597+#ifdef CONFIG_SMP
18598+ movl PER_CPU_VAR(cpu_number), %ebx
18599+ shll $PAGE_SHIFT_asm, %ebx
18600+ addl $cpu_gdt_table, %ebx
18601+#else
18602+ movl $cpu_gdt_table, %ebx
18603+#endif
18604+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18605+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18606 shl $16, %eax
18607 addl %esp, %eax /* the adjusted stack pointer */
18608 pushl_cfi $__KERNEL_DS
18609@@ -807,7 +1046,7 @@ vector=vector+1
18610 .endr
18611 2: jmp common_interrupt
18612 .endr
18613-END(irq_entries_start)
18614+ENDPROC(irq_entries_start)
18615
18616 .previous
18617 END(interrupt)
18618@@ -858,7 +1097,7 @@ ENTRY(coprocessor_error)
18619 pushl_cfi $do_coprocessor_error
18620 jmp error_code
18621 CFI_ENDPROC
18622-END(coprocessor_error)
18623+ENDPROC(coprocessor_error)
18624
18625 ENTRY(simd_coprocessor_error)
18626 RING0_INT_FRAME
18627@@ -880,7 +1119,7 @@ ENTRY(simd_coprocessor_error)
18628 #endif
18629 jmp error_code
18630 CFI_ENDPROC
18631-END(simd_coprocessor_error)
18632+ENDPROC(simd_coprocessor_error)
18633
18634 ENTRY(device_not_available)
18635 RING0_INT_FRAME
18636@@ -889,18 +1128,18 @@ ENTRY(device_not_available)
18637 pushl_cfi $do_device_not_available
18638 jmp error_code
18639 CFI_ENDPROC
18640-END(device_not_available)
18641+ENDPROC(device_not_available)
18642
18643 #ifdef CONFIG_PARAVIRT
18644 ENTRY(native_iret)
18645 iret
18646 _ASM_EXTABLE(native_iret, iret_exc)
18647-END(native_iret)
18648+ENDPROC(native_iret)
18649
18650 ENTRY(native_irq_enable_sysexit)
18651 sti
18652 sysexit
18653-END(native_irq_enable_sysexit)
18654+ENDPROC(native_irq_enable_sysexit)
18655 #endif
18656
18657 ENTRY(overflow)
18658@@ -910,7 +1149,7 @@ ENTRY(overflow)
18659 pushl_cfi $do_overflow
18660 jmp error_code
18661 CFI_ENDPROC
18662-END(overflow)
18663+ENDPROC(overflow)
18664
18665 ENTRY(bounds)
18666 RING0_INT_FRAME
18667@@ -919,7 +1158,7 @@ ENTRY(bounds)
18668 pushl_cfi $do_bounds
18669 jmp error_code
18670 CFI_ENDPROC
18671-END(bounds)
18672+ENDPROC(bounds)
18673
18674 ENTRY(invalid_op)
18675 RING0_INT_FRAME
18676@@ -928,7 +1167,7 @@ ENTRY(invalid_op)
18677 pushl_cfi $do_invalid_op
18678 jmp error_code
18679 CFI_ENDPROC
18680-END(invalid_op)
18681+ENDPROC(invalid_op)
18682
18683 ENTRY(coprocessor_segment_overrun)
18684 RING0_INT_FRAME
18685@@ -937,7 +1176,7 @@ ENTRY(coprocessor_segment_overrun)
18686 pushl_cfi $do_coprocessor_segment_overrun
18687 jmp error_code
18688 CFI_ENDPROC
18689-END(coprocessor_segment_overrun)
18690+ENDPROC(coprocessor_segment_overrun)
18691
18692 ENTRY(invalid_TSS)
18693 RING0_EC_FRAME
18694@@ -945,7 +1184,7 @@ ENTRY(invalid_TSS)
18695 pushl_cfi $do_invalid_TSS
18696 jmp error_code
18697 CFI_ENDPROC
18698-END(invalid_TSS)
18699+ENDPROC(invalid_TSS)
18700
18701 ENTRY(segment_not_present)
18702 RING0_EC_FRAME
18703@@ -953,7 +1192,7 @@ ENTRY(segment_not_present)
18704 pushl_cfi $do_segment_not_present
18705 jmp error_code
18706 CFI_ENDPROC
18707-END(segment_not_present)
18708+ENDPROC(segment_not_present)
18709
18710 ENTRY(stack_segment)
18711 RING0_EC_FRAME
18712@@ -961,7 +1200,7 @@ ENTRY(stack_segment)
18713 pushl_cfi $do_stack_segment
18714 jmp error_code
18715 CFI_ENDPROC
18716-END(stack_segment)
18717+ENDPROC(stack_segment)
18718
18719 ENTRY(alignment_check)
18720 RING0_EC_FRAME
18721@@ -969,7 +1208,7 @@ ENTRY(alignment_check)
18722 pushl_cfi $do_alignment_check
18723 jmp error_code
18724 CFI_ENDPROC
18725-END(alignment_check)
18726+ENDPROC(alignment_check)
18727
18728 ENTRY(divide_error)
18729 RING0_INT_FRAME
18730@@ -978,7 +1217,7 @@ ENTRY(divide_error)
18731 pushl_cfi $do_divide_error
18732 jmp error_code
18733 CFI_ENDPROC
18734-END(divide_error)
18735+ENDPROC(divide_error)
18736
18737 #ifdef CONFIG_X86_MCE
18738 ENTRY(machine_check)
18739@@ -988,7 +1227,7 @@ ENTRY(machine_check)
18740 pushl_cfi machine_check_vector
18741 jmp error_code
18742 CFI_ENDPROC
18743-END(machine_check)
18744+ENDPROC(machine_check)
18745 #endif
18746
18747 ENTRY(spurious_interrupt_bug)
18748@@ -998,7 +1237,7 @@ ENTRY(spurious_interrupt_bug)
18749 pushl_cfi $do_spurious_interrupt_bug
18750 jmp error_code
18751 CFI_ENDPROC
18752-END(spurious_interrupt_bug)
18753+ENDPROC(spurious_interrupt_bug)
18754 /*
18755 * End of kprobes section
18756 */
18757@@ -1101,7 +1340,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
18758
18759 ENTRY(mcount)
18760 ret
18761-END(mcount)
18762+ENDPROC(mcount)
18763
18764 ENTRY(ftrace_caller)
18765 cmpl $0, function_trace_stop
18766@@ -1134,7 +1373,7 @@ ftrace_graph_call:
18767 .globl ftrace_stub
18768 ftrace_stub:
18769 ret
18770-END(ftrace_caller)
18771+ENDPROC(ftrace_caller)
18772
18773 ENTRY(ftrace_regs_caller)
18774 pushf /* push flags before compare (in cs location) */
18775@@ -1235,7 +1474,7 @@ trace:
18776 popl %ecx
18777 popl %eax
18778 jmp ftrace_stub
18779-END(mcount)
18780+ENDPROC(mcount)
18781 #endif /* CONFIG_DYNAMIC_FTRACE */
18782 #endif /* CONFIG_FUNCTION_TRACER */
18783
18784@@ -1253,7 +1492,7 @@ ENTRY(ftrace_graph_caller)
18785 popl %ecx
18786 popl %eax
18787 ret
18788-END(ftrace_graph_caller)
18789+ENDPROC(ftrace_graph_caller)
18790
18791 .globl return_to_handler
18792 return_to_handler:
18793@@ -1309,15 +1548,18 @@ error_code:
18794 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18795 REG_TO_PTGS %ecx
18796 SET_KERNEL_GS %ecx
18797- movl $(__USER_DS), %ecx
18798+ movl $(__KERNEL_DS), %ecx
18799 movl %ecx, %ds
18800 movl %ecx, %es
18801+
18802+ pax_enter_kernel
18803+
18804 TRACE_IRQS_OFF
18805 movl %esp,%eax # pt_regs pointer
18806 call *%edi
18807 jmp ret_from_exception
18808 CFI_ENDPROC
18809-END(page_fault)
18810+ENDPROC(page_fault)
18811
18812 /*
18813 * Debug traps and NMI can happen at the one SYSENTER instruction
18814@@ -1360,7 +1602,7 @@ debug_stack_correct:
18815 call do_debug
18816 jmp ret_from_exception
18817 CFI_ENDPROC
18818-END(debug)
18819+ENDPROC(debug)
18820
18821 /*
18822 * NMI is doubly nasty. It can happen _while_ we're handling
18823@@ -1398,6 +1640,9 @@ nmi_stack_correct:
18824 xorl %edx,%edx # zero error code
18825 movl %esp,%eax # pt_regs pointer
18826 call do_nmi
18827+
18828+ pax_exit_kernel
18829+
18830 jmp restore_all_notrace
18831 CFI_ENDPROC
18832
18833@@ -1434,12 +1679,15 @@ nmi_espfix_stack:
18834 FIXUP_ESPFIX_STACK # %eax == %esp
18835 xorl %edx,%edx # zero error code
18836 call do_nmi
18837+
18838+ pax_exit_kernel
18839+
18840 RESTORE_REGS
18841 lss 12+4(%esp), %esp # back to espfix stack
18842 CFI_ADJUST_CFA_OFFSET -24
18843 jmp irq_return
18844 CFI_ENDPROC
18845-END(nmi)
18846+ENDPROC(nmi)
18847
18848 ENTRY(int3)
18849 RING0_INT_FRAME
18850@@ -1452,14 +1700,14 @@ ENTRY(int3)
18851 call do_int3
18852 jmp ret_from_exception
18853 CFI_ENDPROC
18854-END(int3)
18855+ENDPROC(int3)
18856
18857 ENTRY(general_protection)
18858 RING0_EC_FRAME
18859 pushl_cfi $do_general_protection
18860 jmp error_code
18861 CFI_ENDPROC
18862-END(general_protection)
18863+ENDPROC(general_protection)
18864
18865 #ifdef CONFIG_KVM_GUEST
18866 ENTRY(async_page_fault)
18867@@ -1468,7 +1716,7 @@ ENTRY(async_page_fault)
18868 pushl_cfi $do_async_page_fault
18869 jmp error_code
18870 CFI_ENDPROC
18871-END(async_page_fault)
18872+ENDPROC(async_page_fault)
18873 #endif
18874
18875 /*
18876diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
18877index cb3c591..bc63707 100644
18878--- a/arch/x86/kernel/entry_64.S
18879+++ b/arch/x86/kernel/entry_64.S
18880@@ -59,6 +59,8 @@
18881 #include <asm/context_tracking.h>
18882 #include <asm/smap.h>
18883 #include <linux/err.h>
18884+#include <asm/pgtable.h>
18885+#include <asm/alternative-asm.h>
18886
18887 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
18888 #include <linux/elf-em.h>
18889@@ -80,8 +82,9 @@
18890 #ifdef CONFIG_DYNAMIC_FTRACE
18891
18892 ENTRY(function_hook)
18893+ pax_force_retaddr
18894 retq
18895-END(function_hook)
18896+ENDPROC(function_hook)
18897
18898 /* skip is set if stack has been adjusted */
18899 .macro ftrace_caller_setup skip=0
18900@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
18901 #endif
18902
18903 GLOBAL(ftrace_stub)
18904+ pax_force_retaddr
18905 retq
18906-END(ftrace_caller)
18907+ENDPROC(ftrace_caller)
18908
18909 ENTRY(ftrace_regs_caller)
18910 /* Save the current flags before compare (in SS location)*/
18911@@ -191,7 +195,7 @@ ftrace_restore_flags:
18912 popfq
18913 jmp ftrace_stub
18914
18915-END(ftrace_regs_caller)
18916+ENDPROC(ftrace_regs_caller)
18917
18918
18919 #else /* ! CONFIG_DYNAMIC_FTRACE */
18920@@ -212,6 +216,7 @@ ENTRY(function_hook)
18921 #endif
18922
18923 GLOBAL(ftrace_stub)
18924+ pax_force_retaddr
18925 retq
18926
18927 trace:
18928@@ -225,12 +230,13 @@ trace:
18929 #endif
18930 subq $MCOUNT_INSN_SIZE, %rdi
18931
18932+ pax_force_fptr ftrace_trace_function
18933 call *ftrace_trace_function
18934
18935 MCOUNT_RESTORE_FRAME
18936
18937 jmp ftrace_stub
18938-END(function_hook)
18939+ENDPROC(function_hook)
18940 #endif /* CONFIG_DYNAMIC_FTRACE */
18941 #endif /* CONFIG_FUNCTION_TRACER */
18942
18943@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
18944
18945 MCOUNT_RESTORE_FRAME
18946
18947+ pax_force_retaddr
18948 retq
18949-END(ftrace_graph_caller)
18950+ENDPROC(ftrace_graph_caller)
18951
18952 GLOBAL(return_to_handler)
18953 subq $24, %rsp
18954@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
18955 movq 8(%rsp), %rdx
18956 movq (%rsp), %rax
18957 addq $24, %rsp
18958+ pax_force_fptr %rdi
18959 jmp *%rdi
18960+ENDPROC(return_to_handler)
18961 #endif
18962
18963
18964@@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
18965 ENDPROC(native_usergs_sysret64)
18966 #endif /* CONFIG_PARAVIRT */
18967
18968+ .macro ljmpq sel, off
18969+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
18970+ .byte 0x48; ljmp *1234f(%rip)
18971+ .pushsection .rodata
18972+ .align 16
18973+ 1234: .quad \off; .word \sel
18974+ .popsection
18975+#else
18976+ pushq $\sel
18977+ pushq $\off
18978+ lretq
18979+#endif
18980+ .endm
18981+
18982+ .macro pax_enter_kernel
18983+ pax_set_fptr_mask
18984+#ifdef CONFIG_PAX_KERNEXEC
18985+ call pax_enter_kernel
18986+#endif
18987+ .endm
18988+
18989+ .macro pax_exit_kernel
18990+#ifdef CONFIG_PAX_KERNEXEC
18991+ call pax_exit_kernel
18992+#endif
18993+ .endm
18994+
18995+#ifdef CONFIG_PAX_KERNEXEC
18996+ENTRY(pax_enter_kernel)
18997+ pushq %rdi
18998+
18999+#ifdef CONFIG_PARAVIRT
19000+ PV_SAVE_REGS(CLBR_RDI)
19001+#endif
19002+
19003+ GET_CR0_INTO_RDI
19004+ bts $16,%rdi
19005+ jnc 3f
19006+ mov %cs,%edi
19007+ cmp $__KERNEL_CS,%edi
19008+ jnz 2f
19009+1:
19010+
19011+#ifdef CONFIG_PARAVIRT
19012+ PV_RESTORE_REGS(CLBR_RDI)
19013+#endif
19014+
19015+ popq %rdi
19016+ pax_force_retaddr
19017+ retq
19018+
19019+2: ljmpq __KERNEL_CS,1f
19020+3: ljmpq __KERNEXEC_KERNEL_CS,4f
19021+4: SET_RDI_INTO_CR0
19022+ jmp 1b
19023+ENDPROC(pax_enter_kernel)
19024+
19025+ENTRY(pax_exit_kernel)
19026+ pushq %rdi
19027+
19028+#ifdef CONFIG_PARAVIRT
19029+ PV_SAVE_REGS(CLBR_RDI)
19030+#endif
19031+
19032+ mov %cs,%rdi
19033+ cmp $__KERNEXEC_KERNEL_CS,%edi
19034+ jz 2f
19035+1:
19036+
19037+#ifdef CONFIG_PARAVIRT
19038+ PV_RESTORE_REGS(CLBR_RDI);
19039+#endif
19040+
19041+ popq %rdi
19042+ pax_force_retaddr
19043+ retq
19044+
19045+2: GET_CR0_INTO_RDI
19046+ btr $16,%rdi
19047+ ljmpq __KERNEL_CS,3f
19048+3: SET_RDI_INTO_CR0
19049+ jmp 1b
19050+ENDPROC(pax_exit_kernel)
19051+#endif
19052+
19053+ .macro pax_enter_kernel_user
19054+ pax_set_fptr_mask
19055+#ifdef CONFIG_PAX_MEMORY_UDEREF
19056+ call pax_enter_kernel_user
19057+#endif
19058+ .endm
19059+
19060+ .macro pax_exit_kernel_user
19061+#ifdef CONFIG_PAX_MEMORY_UDEREF
19062+ call pax_exit_kernel_user
19063+#endif
19064+#ifdef CONFIG_PAX_RANDKSTACK
19065+ pushq %rax
19066+ call pax_randomize_kstack
19067+ popq %rax
19068+#endif
19069+ .endm
19070+
19071+#ifdef CONFIG_PAX_MEMORY_UDEREF
19072+ENTRY(pax_enter_kernel_user)
19073+ pushq %rdi
19074+ pushq %rbx
19075+
19076+#ifdef CONFIG_PARAVIRT
19077+ PV_SAVE_REGS(CLBR_RDI)
19078+#endif
19079+
19080+ GET_CR3_INTO_RDI
19081+ mov %rdi,%rbx
19082+ add $__START_KERNEL_map,%rbx
19083+ sub phys_base(%rip),%rbx
19084+
19085+#ifdef CONFIG_PARAVIRT
19086+ pushq %rdi
19087+ cmpl $0, pv_info+PARAVIRT_enabled
19088+ jz 1f
19089+ i = 0
19090+ .rept USER_PGD_PTRS
19091+ mov i*8(%rbx),%rsi
19092+ mov $0,%sil
19093+ lea i*8(%rbx),%rdi
19094+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19095+ i = i + 1
19096+ .endr
19097+ jmp 2f
19098+1:
19099+#endif
19100+
19101+ i = 0
19102+ .rept USER_PGD_PTRS
19103+ movb $0,i*8(%rbx)
19104+ i = i + 1
19105+ .endr
19106+
19107+#ifdef CONFIG_PARAVIRT
19108+2: popq %rdi
19109+#endif
19110+ SET_RDI_INTO_CR3
19111+
19112+#ifdef CONFIG_PAX_KERNEXEC
19113+ GET_CR0_INTO_RDI
19114+ bts $16,%rdi
19115+ SET_RDI_INTO_CR0
19116+#endif
19117+
19118+#ifdef CONFIG_PARAVIRT
19119+ PV_RESTORE_REGS(CLBR_RDI)
19120+#endif
19121+
19122+ popq %rbx
19123+ popq %rdi
19124+ pax_force_retaddr
19125+ retq
19126+ENDPROC(pax_enter_kernel_user)
19127+
19128+ENTRY(pax_exit_kernel_user)
19129+ push %rdi
19130+
19131+#ifdef CONFIG_PARAVIRT
19132+ pushq %rbx
19133+ PV_SAVE_REGS(CLBR_RDI)
19134+#endif
19135+
19136+#ifdef CONFIG_PAX_KERNEXEC
19137+ GET_CR0_INTO_RDI
19138+ btr $16,%rdi
19139+ SET_RDI_INTO_CR0
19140+#endif
19141+
19142+ GET_CR3_INTO_RDI
19143+ add $__START_KERNEL_map,%rdi
19144+ sub phys_base(%rip),%rdi
19145+
19146+#ifdef CONFIG_PARAVIRT
19147+ cmpl $0, pv_info+PARAVIRT_enabled
19148+ jz 1f
19149+ mov %rdi,%rbx
19150+ i = 0
19151+ .rept USER_PGD_PTRS
19152+ mov i*8(%rbx),%rsi
19153+ mov $0x67,%sil
19154+ lea i*8(%rbx),%rdi
19155+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19156+ i = i + 1
19157+ .endr
19158+ jmp 2f
19159+1:
19160+#endif
19161+
19162+ i = 0
19163+ .rept USER_PGD_PTRS
19164+ movb $0x67,i*8(%rdi)
19165+ i = i + 1
19166+ .endr
19167+
19168+#ifdef CONFIG_PARAVIRT
19169+2: PV_RESTORE_REGS(CLBR_RDI)
19170+ popq %rbx
19171+#endif
19172+
19173+ popq %rdi
19174+ pax_force_retaddr
19175+ retq
19176+ENDPROC(pax_exit_kernel_user)
19177+#endif
19178+
19179+.macro pax_erase_kstack
19180+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19181+ call pax_erase_kstack
19182+#endif
19183+.endm
19184+
19185+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19186+ENTRY(pax_erase_kstack)
19187+ pushq %rdi
19188+ pushq %rcx
19189+ pushq %rax
19190+ pushq %r11
19191+
19192+ GET_THREAD_INFO(%r11)
19193+ mov TI_lowest_stack(%r11), %rdi
19194+ mov $-0xBEEF, %rax
19195+ std
19196+
19197+1: mov %edi, %ecx
19198+ and $THREAD_SIZE_asm - 1, %ecx
19199+ shr $3, %ecx
19200+ repne scasq
19201+ jecxz 2f
19202+
19203+ cmp $2*8, %ecx
19204+ jc 2f
19205+
19206+ mov $2*8, %ecx
19207+ repe scasq
19208+ jecxz 2f
19209+ jne 1b
19210+
19211+2: cld
19212+ mov %esp, %ecx
19213+ sub %edi, %ecx
19214+
19215+ cmp $THREAD_SIZE_asm, %rcx
19216+ jb 3f
19217+ ud2
19218+3:
19219+
19220+ shr $3, %ecx
19221+ rep stosq
19222+
19223+ mov TI_task_thread_sp0(%r11), %rdi
19224+ sub $256, %rdi
19225+ mov %rdi, TI_lowest_stack(%r11)
19226+
19227+ popq %r11
19228+ popq %rax
19229+ popq %rcx
19230+ popq %rdi
19231+ pax_force_retaddr
19232+ ret
19233+ENDPROC(pax_erase_kstack)
19234+#endif
19235
19236 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
19237 #ifdef CONFIG_TRACE_IRQFLAGS
19238@@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
19239 .endm
19240
19241 .macro UNFAKE_STACK_FRAME
19242- addq $8*6, %rsp
19243- CFI_ADJUST_CFA_OFFSET -(6*8)
19244+ addq $8*6 + ARG_SKIP, %rsp
19245+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
19246 .endm
19247
19248 /*
19249@@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
19250 movq %rsp, %rsi
19251
19252 leaq -RBP(%rsp),%rdi /* arg1 for handler */
19253- testl $3, CS-RBP(%rsi)
19254+ testb $3, CS-RBP(%rsi)
19255 je 1f
19256 SWAPGS
19257 /*
19258@@ -498,9 +774,10 @@ ENTRY(save_rest)
19259 movq_cfi r15, R15+16
19260 movq %r11, 8(%rsp) /* return address */
19261 FIXUP_TOP_OF_STACK %r11, 16
19262+ pax_force_retaddr
19263 ret
19264 CFI_ENDPROC
19265-END(save_rest)
19266+ENDPROC(save_rest)
19267
19268 /* save complete stack frame */
19269 .pushsection .kprobes.text, "ax"
19270@@ -529,9 +806,10 @@ ENTRY(save_paranoid)
19271 js 1f /* negative -> in kernel */
19272 SWAPGS
19273 xorl %ebx,%ebx
19274-1: ret
19275+1: pax_force_retaddr_bts
19276+ ret
19277 CFI_ENDPROC
19278-END(save_paranoid)
19279+ENDPROC(save_paranoid)
19280 .popsection
19281
19282 /*
19283@@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
19284
19285 RESTORE_REST
19286
19287- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19288+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19289 jz 1f
19290
19291 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
19292@@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
19293 RESTORE_REST
19294 jmp int_ret_from_sys_call
19295 CFI_ENDPROC
19296-END(ret_from_fork)
19297+ENDPROC(ret_from_fork)
19298
19299 /*
19300 * System call entry. Up to 6 arguments in registers are supported.
19301@@ -608,7 +886,7 @@ END(ret_from_fork)
19302 ENTRY(system_call)
19303 CFI_STARTPROC simple
19304 CFI_SIGNAL_FRAME
19305- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
19306+ CFI_DEF_CFA rsp,0
19307 CFI_REGISTER rip,rcx
19308 /*CFI_REGISTER rflags,r11*/
19309 SWAPGS_UNSAFE_STACK
19310@@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
19311
19312 movq %rsp,PER_CPU_VAR(old_rsp)
19313 movq PER_CPU_VAR(kernel_stack),%rsp
19314+ SAVE_ARGS 8*6,0
19315+ pax_enter_kernel_user
19316+
19317+#ifdef CONFIG_PAX_RANDKSTACK
19318+ pax_erase_kstack
19319+#endif
19320+
19321 /*
19322 * No need to follow this irqs off/on section - it's straight
19323 * and short:
19324 */
19325 ENABLE_INTERRUPTS(CLBR_NONE)
19326- SAVE_ARGS 8,0
19327 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
19328 movq %rcx,RIP-ARGOFFSET(%rsp)
19329 CFI_REL_OFFSET rip,RIP-ARGOFFSET
19330- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19331+ GET_THREAD_INFO(%rcx)
19332+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
19333 jnz tracesys
19334 system_call_fastpath:
19335 #if __SYSCALL_MASK == ~0
19336@@ -640,7 +925,7 @@ system_call_fastpath:
19337 cmpl $__NR_syscall_max,%eax
19338 #endif
19339 ja badsys
19340- movq %r10,%rcx
19341+ movq R10-ARGOFFSET(%rsp),%rcx
19342 call *sys_call_table(,%rax,8) # XXX: rip relative
19343 movq %rax,RAX-ARGOFFSET(%rsp)
19344 /*
19345@@ -654,10 +939,13 @@ sysret_check:
19346 LOCKDEP_SYS_EXIT
19347 DISABLE_INTERRUPTS(CLBR_NONE)
19348 TRACE_IRQS_OFF
19349- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
19350+ GET_THREAD_INFO(%rcx)
19351+ movl TI_flags(%rcx),%edx
19352 andl %edi,%edx
19353 jnz sysret_careful
19354 CFI_REMEMBER_STATE
19355+ pax_exit_kernel_user
19356+ pax_erase_kstack
19357 /*
19358 * sysretq will re-enable interrupts:
19359 */
19360@@ -709,14 +997,18 @@ badsys:
19361 * jump back to the normal fast path.
19362 */
19363 auditsys:
19364- movq %r10,%r9 /* 6th arg: 4th syscall arg */
19365+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
19366 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
19367 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
19368 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
19369 movq %rax,%rsi /* 2nd arg: syscall number */
19370 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
19371 call __audit_syscall_entry
19372+
19373+ pax_erase_kstack
19374+
19375 LOAD_ARGS 0 /* reload call-clobbered registers */
19376+ pax_set_fptr_mask
19377 jmp system_call_fastpath
19378
19379 /*
19380@@ -737,7 +1029,7 @@ sysret_audit:
19381 /* Do syscall tracing */
19382 tracesys:
19383 #ifdef CONFIG_AUDITSYSCALL
19384- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19385+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
19386 jz auditsys
19387 #endif
19388 SAVE_REST
19389@@ -745,12 +1037,16 @@ tracesys:
19390 FIXUP_TOP_OF_STACK %rdi
19391 movq %rsp,%rdi
19392 call syscall_trace_enter
19393+
19394+ pax_erase_kstack
19395+
19396 /*
19397 * Reload arg registers from stack in case ptrace changed them.
19398 * We don't reload %rax because syscall_trace_enter() returned
19399 * the value it wants us to use in the table lookup.
19400 */
19401 LOAD_ARGS ARGOFFSET, 1
19402+ pax_set_fptr_mask
19403 RESTORE_REST
19404 #if __SYSCALL_MASK == ~0
19405 cmpq $__NR_syscall_max,%rax
19406@@ -759,7 +1055,7 @@ tracesys:
19407 cmpl $__NR_syscall_max,%eax
19408 #endif
19409 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
19410- movq %r10,%rcx /* fixup for C */
19411+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
19412 call *sys_call_table(,%rax,8)
19413 movq %rax,RAX-ARGOFFSET(%rsp)
19414 /* Use IRET because user could have changed frame */
19415@@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
19416 andl %edi,%edx
19417 jnz int_careful
19418 andl $~TS_COMPAT,TI_status(%rcx)
19419- jmp retint_swapgs
19420+ pax_exit_kernel_user
19421+ pax_erase_kstack
19422+ jmp retint_swapgs_pax
19423
19424 /* Either reschedule or signal or syscall exit tracking needed. */
19425 /* First do a reschedule test. */
19426@@ -826,7 +1124,7 @@ int_restore_rest:
19427 TRACE_IRQS_OFF
19428 jmp int_with_check
19429 CFI_ENDPROC
19430-END(system_call)
19431+ENDPROC(system_call)
19432
19433 /*
19434 * Certain special system calls that need to save a complete full stack frame.
19435@@ -842,7 +1140,7 @@ ENTRY(\label)
19436 call \func
19437 jmp ptregscall_common
19438 CFI_ENDPROC
19439-END(\label)
19440+ENDPROC(\label)
19441 .endm
19442
19443 .macro FORK_LIKE func
19444@@ -856,9 +1154,10 @@ ENTRY(stub_\func)
19445 DEFAULT_FRAME 0 8 /* offset 8: return address */
19446 call sys_\func
19447 RESTORE_TOP_OF_STACK %r11, 8
19448+ pax_force_retaddr
19449 ret $REST_SKIP /* pop extended registers */
19450 CFI_ENDPROC
19451-END(stub_\func)
19452+ENDPROC(stub_\func)
19453 .endm
19454
19455 FORK_LIKE clone
19456@@ -875,9 +1174,10 @@ ENTRY(ptregscall_common)
19457 movq_cfi_restore R12+8, r12
19458 movq_cfi_restore RBP+8, rbp
19459 movq_cfi_restore RBX+8, rbx
19460+ pax_force_retaddr
19461 ret $REST_SKIP /* pop extended registers */
19462 CFI_ENDPROC
19463-END(ptregscall_common)
19464+ENDPROC(ptregscall_common)
19465
19466 ENTRY(stub_execve)
19467 CFI_STARTPROC
19468@@ -891,7 +1191,7 @@ ENTRY(stub_execve)
19469 RESTORE_REST
19470 jmp int_ret_from_sys_call
19471 CFI_ENDPROC
19472-END(stub_execve)
19473+ENDPROC(stub_execve)
19474
19475 /*
19476 * sigreturn is special because it needs to restore all registers on return.
19477@@ -909,7 +1209,7 @@ ENTRY(stub_rt_sigreturn)
19478 RESTORE_REST
19479 jmp int_ret_from_sys_call
19480 CFI_ENDPROC
19481-END(stub_rt_sigreturn)
19482+ENDPROC(stub_rt_sigreturn)
19483
19484 #ifdef CONFIG_X86_X32_ABI
19485 ENTRY(stub_x32_rt_sigreturn)
19486@@ -975,7 +1275,7 @@ vector=vector+1
19487 2: jmp common_interrupt
19488 .endr
19489 CFI_ENDPROC
19490-END(irq_entries_start)
19491+ENDPROC(irq_entries_start)
19492
19493 .previous
19494 END(interrupt)
19495@@ -995,6 +1295,16 @@ END(interrupt)
19496 subq $ORIG_RAX-RBP, %rsp
19497 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
19498 SAVE_ARGS_IRQ
19499+#ifdef CONFIG_PAX_MEMORY_UDEREF
19500+ testb $3, CS(%rdi)
19501+ jnz 1f
19502+ pax_enter_kernel
19503+ jmp 2f
19504+1: pax_enter_kernel_user
19505+2:
19506+#else
19507+ pax_enter_kernel
19508+#endif
19509 call \func
19510 .endm
19511
19512@@ -1027,7 +1337,7 @@ ret_from_intr:
19513
19514 exit_intr:
19515 GET_THREAD_INFO(%rcx)
19516- testl $3,CS-ARGOFFSET(%rsp)
19517+ testb $3,CS-ARGOFFSET(%rsp)
19518 je retint_kernel
19519
19520 /* Interrupt came from user space */
19521@@ -1049,12 +1359,16 @@ retint_swapgs: /* return to user-space */
19522 * The iretq could re-enable interrupts:
19523 */
19524 DISABLE_INTERRUPTS(CLBR_ANY)
19525+ pax_exit_kernel_user
19526+retint_swapgs_pax:
19527 TRACE_IRQS_IRETQ
19528 SWAPGS
19529 jmp restore_args
19530
19531 retint_restore_args: /* return to kernel space */
19532 DISABLE_INTERRUPTS(CLBR_ANY)
19533+ pax_exit_kernel
19534+ pax_force_retaddr (RIP-ARGOFFSET)
19535 /*
19536 * The iretq could re-enable interrupts:
19537 */
19538@@ -1137,7 +1451,7 @@ ENTRY(retint_kernel)
19539 #endif
19540
19541 CFI_ENDPROC
19542-END(common_interrupt)
19543+ENDPROC(common_interrupt)
19544 /*
19545 * End of kprobes section
19546 */
19547@@ -1155,7 +1469,7 @@ ENTRY(\sym)
19548 interrupt \do_sym
19549 jmp ret_from_intr
19550 CFI_ENDPROC
19551-END(\sym)
19552+ENDPROC(\sym)
19553 .endm
19554
19555 #ifdef CONFIG_SMP
19556@@ -1211,12 +1525,22 @@ ENTRY(\sym)
19557 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19558 call error_entry
19559 DEFAULT_FRAME 0
19560+#ifdef CONFIG_PAX_MEMORY_UDEREF
19561+ testb $3, CS(%rsp)
19562+ jnz 1f
19563+ pax_enter_kernel
19564+ jmp 2f
19565+1: pax_enter_kernel_user
19566+2:
19567+#else
19568+ pax_enter_kernel
19569+#endif
19570 movq %rsp,%rdi /* pt_regs pointer */
19571 xorl %esi,%esi /* no error code */
19572 call \do_sym
19573 jmp error_exit /* %ebx: no swapgs flag */
19574 CFI_ENDPROC
19575-END(\sym)
19576+ENDPROC(\sym)
19577 .endm
19578
19579 .macro paranoidzeroentry sym do_sym
19580@@ -1229,15 +1553,25 @@ ENTRY(\sym)
19581 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19582 call save_paranoid
19583 TRACE_IRQS_OFF
19584+#ifdef CONFIG_PAX_MEMORY_UDEREF
19585+ testb $3, CS(%rsp)
19586+ jnz 1f
19587+ pax_enter_kernel
19588+ jmp 2f
19589+1: pax_enter_kernel_user
19590+2:
19591+#else
19592+ pax_enter_kernel
19593+#endif
19594 movq %rsp,%rdi /* pt_regs pointer */
19595 xorl %esi,%esi /* no error code */
19596 call \do_sym
19597 jmp paranoid_exit /* %ebx: no swapgs flag */
19598 CFI_ENDPROC
19599-END(\sym)
19600+ENDPROC(\sym)
19601 .endm
19602
19603-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19604+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19605 .macro paranoidzeroentry_ist sym do_sym ist
19606 ENTRY(\sym)
19607 INTR_FRAME
19608@@ -1248,14 +1582,30 @@ ENTRY(\sym)
19609 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19610 call save_paranoid
19611 TRACE_IRQS_OFF_DEBUG
19612+#ifdef CONFIG_PAX_MEMORY_UDEREF
19613+ testb $3, CS(%rsp)
19614+ jnz 1f
19615+ pax_enter_kernel
19616+ jmp 2f
19617+1: pax_enter_kernel_user
19618+2:
19619+#else
19620+ pax_enter_kernel
19621+#endif
19622 movq %rsp,%rdi /* pt_regs pointer */
19623 xorl %esi,%esi /* no error code */
19624+#ifdef CONFIG_SMP
19625+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19626+ lea init_tss(%r12), %r12
19627+#else
19628+ lea init_tss(%rip), %r12
19629+#endif
19630 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19631 call \do_sym
19632 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19633 jmp paranoid_exit /* %ebx: no swapgs flag */
19634 CFI_ENDPROC
19635-END(\sym)
19636+ENDPROC(\sym)
19637 .endm
19638
19639 .macro errorentry sym do_sym
19640@@ -1267,13 +1617,23 @@ ENTRY(\sym)
19641 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19642 call error_entry
19643 DEFAULT_FRAME 0
19644+#ifdef CONFIG_PAX_MEMORY_UDEREF
19645+ testb $3, CS(%rsp)
19646+ jnz 1f
19647+ pax_enter_kernel
19648+ jmp 2f
19649+1: pax_enter_kernel_user
19650+2:
19651+#else
19652+ pax_enter_kernel
19653+#endif
19654 movq %rsp,%rdi /* pt_regs pointer */
19655 movq ORIG_RAX(%rsp),%rsi /* get error code */
19656 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19657 call \do_sym
19658 jmp error_exit /* %ebx: no swapgs flag */
19659 CFI_ENDPROC
19660-END(\sym)
19661+ENDPROC(\sym)
19662 .endm
19663
19664 /* error code is on the stack already */
19665@@ -1287,13 +1647,23 @@ ENTRY(\sym)
19666 call save_paranoid
19667 DEFAULT_FRAME 0
19668 TRACE_IRQS_OFF
19669+#ifdef CONFIG_PAX_MEMORY_UDEREF
19670+ testb $3, CS(%rsp)
19671+ jnz 1f
19672+ pax_enter_kernel
19673+ jmp 2f
19674+1: pax_enter_kernel_user
19675+2:
19676+#else
19677+ pax_enter_kernel
19678+#endif
19679 movq %rsp,%rdi /* pt_regs pointer */
19680 movq ORIG_RAX(%rsp),%rsi /* get error code */
19681 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19682 call \do_sym
19683 jmp paranoid_exit /* %ebx: no swapgs flag */
19684 CFI_ENDPROC
19685-END(\sym)
19686+ENDPROC(\sym)
19687 .endm
19688
19689 zeroentry divide_error do_divide_error
19690@@ -1323,9 +1693,10 @@ gs_change:
19691 2: mfence /* workaround */
19692 SWAPGS
19693 popfq_cfi
19694+ pax_force_retaddr
19695 ret
19696 CFI_ENDPROC
19697-END(native_load_gs_index)
19698+ENDPROC(native_load_gs_index)
19699
19700 _ASM_EXTABLE(gs_change,bad_gs)
19701 .section .fixup,"ax"
19702@@ -1353,9 +1724,10 @@ ENTRY(call_softirq)
19703 CFI_DEF_CFA_REGISTER rsp
19704 CFI_ADJUST_CFA_OFFSET -8
19705 decl PER_CPU_VAR(irq_count)
19706+ pax_force_retaddr
19707 ret
19708 CFI_ENDPROC
19709-END(call_softirq)
19710+ENDPROC(call_softirq)
19711
19712 #ifdef CONFIG_XEN
19713 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19714@@ -1393,7 +1765,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19715 decl PER_CPU_VAR(irq_count)
19716 jmp error_exit
19717 CFI_ENDPROC
19718-END(xen_do_hypervisor_callback)
19719+ENDPROC(xen_do_hypervisor_callback)
19720
19721 /*
19722 * Hypervisor uses this for application faults while it executes.
19723@@ -1452,7 +1824,7 @@ ENTRY(xen_failsafe_callback)
19724 SAVE_ALL
19725 jmp error_exit
19726 CFI_ENDPROC
19727-END(xen_failsafe_callback)
19728+ENDPROC(xen_failsafe_callback)
19729
19730 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
19731 xen_hvm_callback_vector xen_evtchn_do_upcall
19732@@ -1501,16 +1873,31 @@ ENTRY(paranoid_exit)
19733 TRACE_IRQS_OFF_DEBUG
19734 testl %ebx,%ebx /* swapgs needed? */
19735 jnz paranoid_restore
19736- testl $3,CS(%rsp)
19737+ testb $3,CS(%rsp)
19738 jnz paranoid_userspace
19739+#ifdef CONFIG_PAX_MEMORY_UDEREF
19740+ pax_exit_kernel
19741+ TRACE_IRQS_IRETQ 0
19742+ SWAPGS_UNSAFE_STACK
19743+ RESTORE_ALL 8
19744+ pax_force_retaddr_bts
19745+ jmp irq_return
19746+#endif
19747 paranoid_swapgs:
19748+#ifdef CONFIG_PAX_MEMORY_UDEREF
19749+ pax_exit_kernel_user
19750+#else
19751+ pax_exit_kernel
19752+#endif
19753 TRACE_IRQS_IRETQ 0
19754 SWAPGS_UNSAFE_STACK
19755 RESTORE_ALL 8
19756 jmp irq_return
19757 paranoid_restore:
19758+ pax_exit_kernel
19759 TRACE_IRQS_IRETQ_DEBUG 0
19760 RESTORE_ALL 8
19761+ pax_force_retaddr_bts
19762 jmp irq_return
19763 paranoid_userspace:
19764 GET_THREAD_INFO(%rcx)
19765@@ -1539,7 +1926,7 @@ paranoid_schedule:
19766 TRACE_IRQS_OFF
19767 jmp paranoid_userspace
19768 CFI_ENDPROC
19769-END(paranoid_exit)
19770+ENDPROC(paranoid_exit)
19771
19772 /*
19773 * Exception entry point. This expects an error code/orig_rax on the stack.
19774@@ -1566,12 +1953,13 @@ ENTRY(error_entry)
19775 movq_cfi r14, R14+8
19776 movq_cfi r15, R15+8
19777 xorl %ebx,%ebx
19778- testl $3,CS+8(%rsp)
19779+ testb $3,CS+8(%rsp)
19780 je error_kernelspace
19781 error_swapgs:
19782 SWAPGS
19783 error_sti:
19784 TRACE_IRQS_OFF
19785+ pax_force_retaddr_bts
19786 ret
19787
19788 /*
19789@@ -1598,7 +1986,7 @@ bstep_iret:
19790 movq %rcx,RIP+8(%rsp)
19791 jmp error_swapgs
19792 CFI_ENDPROC
19793-END(error_entry)
19794+ENDPROC(error_entry)
19795
19796
19797 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19798@@ -1618,7 +2006,7 @@ ENTRY(error_exit)
19799 jnz retint_careful
19800 jmp retint_swapgs
19801 CFI_ENDPROC
19802-END(error_exit)
19803+ENDPROC(error_exit)
19804
19805 /*
19806 * Test if a given stack is an NMI stack or not.
19807@@ -1676,9 +2064,11 @@ ENTRY(nmi)
19808 * If %cs was not the kernel segment, then the NMI triggered in user
19809 * space, which means it is definitely not nested.
19810 */
19811+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
19812+ je 1f
19813 cmpl $__KERNEL_CS, 16(%rsp)
19814 jne first_nmi
19815-
19816+1:
19817 /*
19818 * Check the special variable on the stack to see if NMIs are
19819 * executing.
19820@@ -1847,6 +2237,17 @@ end_repeat_nmi:
19821 */
19822 movq %cr2, %r12
19823
19824+#ifdef CONFIG_PAX_MEMORY_UDEREF
19825+ testb $3, CS(%rsp)
19826+ jnz 1f
19827+ pax_enter_kernel
19828+ jmp 2f
19829+1: pax_enter_kernel_user
19830+2:
19831+#else
19832+ pax_enter_kernel
19833+#endif
19834+
19835 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
19836 movq %rsp,%rdi
19837 movq $-1,%rsi
19838@@ -1862,23 +2263,34 @@ end_repeat_nmi:
19839 testl %ebx,%ebx /* swapgs needed? */
19840 jnz nmi_restore
19841 nmi_swapgs:
19842+#ifdef CONFIG_PAX_MEMORY_UDEREF
19843+ pax_exit_kernel_user
19844+#else
19845+ pax_exit_kernel
19846+#endif
19847 SWAPGS_UNSAFE_STACK
19848+ RESTORE_ALL 6*8
19849+ /* Clear the NMI executing stack variable */
19850+ movq $0, 5*8(%rsp)
19851+ jmp irq_return
19852 nmi_restore:
19853+ pax_exit_kernel
19854 /* Pop the extra iret frame at once */
19855 RESTORE_ALL 6*8
19856+ pax_force_retaddr_bts
19857
19858 /* Clear the NMI executing stack variable */
19859 movq $0, 5*8(%rsp)
19860 jmp irq_return
19861 CFI_ENDPROC
19862-END(nmi)
19863+ENDPROC(nmi)
19864
19865 ENTRY(ignore_sysret)
19866 CFI_STARTPROC
19867 mov $-ENOSYS,%eax
19868 sysret
19869 CFI_ENDPROC
19870-END(ignore_sysret)
19871+ENDPROC(ignore_sysret)
19872
19873 /*
19874 * End of kprobes section
19875diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
19876index 1d41402..af9a46a 100644
19877--- a/arch/x86/kernel/ftrace.c
19878+++ b/arch/x86/kernel/ftrace.c
19879@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
19880 {
19881 unsigned char replaced[MCOUNT_INSN_SIZE];
19882
19883+ ip = ktla_ktva(ip);
19884+
19885 /*
19886 * Note: Due to modules and __init, code can
19887 * disappear and change, we need to protect against faulting
19888@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19889 unsigned char old[MCOUNT_INSN_SIZE], *new;
19890 int ret;
19891
19892- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
19893+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
19894 new = ftrace_call_replace(ip, (unsigned long)func);
19895
19896 /* See comment above by declaration of modifying_ftrace_code */
19897@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19898 /* Also update the regs callback function */
19899 if (!ret) {
19900 ip = (unsigned long)(&ftrace_regs_call);
19901- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
19902+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
19903 new = ftrace_call_replace(ip, (unsigned long)func);
19904 ret = ftrace_modify_code(ip, old, new);
19905 }
19906@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
19907 * kernel identity mapping to modify code.
19908 */
19909 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
19910- ip = (unsigned long)__va(__pa(ip));
19911+ ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
19912
19913 return probe_kernel_write((void *)ip, val, size);
19914 }
19915@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
19916 unsigned char replaced[MCOUNT_INSN_SIZE];
19917 unsigned char brk = BREAKPOINT_INSTRUCTION;
19918
19919- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
19920+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
19921 return -EFAULT;
19922
19923 /* Make sure it is what we expect it to be */
19924@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
19925 return ret;
19926
19927 fail_update:
19928- probe_kernel_write((void *)ip, &old_code[0], 1);
19929+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
19930 goto out;
19931 }
19932
19933@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
19934 {
19935 unsigned char code[MCOUNT_INSN_SIZE];
19936
19937+ ip = ktla_ktva(ip);
19938+
19939 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
19940 return -EFAULT;
19941
19942diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
19943index c18f59d..9c0c9f6 100644
19944--- a/arch/x86/kernel/head32.c
19945+++ b/arch/x86/kernel/head32.c
19946@@ -18,6 +18,7 @@
19947 #include <asm/io_apic.h>
19948 #include <asm/bios_ebda.h>
19949 #include <asm/tlbflush.h>
19950+#include <asm/boot.h>
19951
19952 static void __init i386_default_early_setup(void)
19953 {
19954@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
19955
19956 void __init i386_start_kernel(void)
19957 {
19958- memblock_reserve(__pa_symbol(&_text),
19959- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
19960+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
19961
19962 #ifdef CONFIG_BLK_DEV_INITRD
19963 /* Reserve INITRD */
19964diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
19965index c8932c7..d56b622 100644
19966--- a/arch/x86/kernel/head_32.S
19967+++ b/arch/x86/kernel/head_32.S
19968@@ -26,6 +26,12 @@
19969 /* Physical address */
19970 #define pa(X) ((X) - __PAGE_OFFSET)
19971
19972+#ifdef CONFIG_PAX_KERNEXEC
19973+#define ta(X) (X)
19974+#else
19975+#define ta(X) ((X) - __PAGE_OFFSET)
19976+#endif
19977+
19978 /*
19979 * References to members of the new_cpu_data structure.
19980 */
19981@@ -55,11 +61,7 @@
19982 * and small than max_low_pfn, otherwise will waste some page table entries
19983 */
19984
19985-#if PTRS_PER_PMD > 1
19986-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
19987-#else
19988-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
19989-#endif
19990+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
19991
19992 /* Number of possible pages in the lowmem region */
19993 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
19994@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
19995 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19996
19997 /*
19998+ * Real beginning of normal "text" segment
19999+ */
20000+ENTRY(stext)
20001+ENTRY(_stext)
20002+
20003+/*
20004 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
20005 * %esi points to the real-mode code as a 32-bit pointer.
20006 * CS and DS must be 4 GB flat segments, but we don't depend on
20007@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20008 * can.
20009 */
20010 __HEAD
20011+
20012+#ifdef CONFIG_PAX_KERNEXEC
20013+ jmp startup_32
20014+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
20015+.fill PAGE_SIZE-5,1,0xcc
20016+#endif
20017+
20018 ENTRY(startup_32)
20019 movl pa(stack_start),%ecx
20020
20021@@ -106,6 +121,59 @@ ENTRY(startup_32)
20022 2:
20023 leal -__PAGE_OFFSET(%ecx),%esp
20024
20025+#ifdef CONFIG_SMP
20026+ movl $pa(cpu_gdt_table),%edi
20027+ movl $__per_cpu_load,%eax
20028+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
20029+ rorl $16,%eax
20030+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
20031+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
20032+ movl $__per_cpu_end - 1,%eax
20033+ subl $__per_cpu_start,%eax
20034+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
20035+#endif
20036+
20037+#ifdef CONFIG_PAX_MEMORY_UDEREF
20038+ movl $NR_CPUS,%ecx
20039+ movl $pa(cpu_gdt_table),%edi
20040+1:
20041+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
20042+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
20043+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
20044+ addl $PAGE_SIZE_asm,%edi
20045+ loop 1b
20046+#endif
20047+
20048+#ifdef CONFIG_PAX_KERNEXEC
20049+ movl $pa(boot_gdt),%edi
20050+ movl $__LOAD_PHYSICAL_ADDR,%eax
20051+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
20052+ rorl $16,%eax
20053+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
20054+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
20055+ rorl $16,%eax
20056+
20057+ ljmp $(__BOOT_CS),$1f
20058+1:
20059+
20060+ movl $NR_CPUS,%ecx
20061+ movl $pa(cpu_gdt_table),%edi
20062+ addl $__PAGE_OFFSET,%eax
20063+1:
20064+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
20065+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
20066+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
20067+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
20068+ rorl $16,%eax
20069+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
20070+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
20071+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
20072+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
20073+ rorl $16,%eax
20074+ addl $PAGE_SIZE_asm,%edi
20075+ loop 1b
20076+#endif
20077+
20078 /*
20079 * Clear BSS first so that there are no surprises...
20080 */
20081@@ -196,8 +264,11 @@ ENTRY(startup_32)
20082 movl %eax, pa(max_pfn_mapped)
20083
20084 /* Do early initialization of the fixmap area */
20085- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20086- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
20087+#ifdef CONFIG_COMPAT_VDSO
20088+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
20089+#else
20090+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
20091+#endif
20092 #else /* Not PAE */
20093
20094 page_pde_offset = (__PAGE_OFFSET >> 20);
20095@@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20096 movl %eax, pa(max_pfn_mapped)
20097
20098 /* Do early initialization of the fixmap area */
20099- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20100- movl %eax,pa(initial_page_table+0xffc)
20101+#ifdef CONFIG_COMPAT_VDSO
20102+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
20103+#else
20104+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
20105+#endif
20106 #endif
20107
20108 #ifdef CONFIG_PARAVIRT
20109@@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20110 cmpl $num_subarch_entries, %eax
20111 jae bad_subarch
20112
20113- movl pa(subarch_entries)(,%eax,4), %eax
20114- subl $__PAGE_OFFSET, %eax
20115- jmp *%eax
20116+ jmp *pa(subarch_entries)(,%eax,4)
20117
20118 bad_subarch:
20119 WEAK(lguest_entry)
20120@@ -256,10 +328,10 @@ WEAK(xen_entry)
20121 __INITDATA
20122
20123 subarch_entries:
20124- .long default_entry /* normal x86/PC */
20125- .long lguest_entry /* lguest hypervisor */
20126- .long xen_entry /* Xen hypervisor */
20127- .long default_entry /* Moorestown MID */
20128+ .long ta(default_entry) /* normal x86/PC */
20129+ .long ta(lguest_entry) /* lguest hypervisor */
20130+ .long ta(xen_entry) /* Xen hypervisor */
20131+ .long ta(default_entry) /* Moorestown MID */
20132 num_subarch_entries = (. - subarch_entries) / 4
20133 .previous
20134 #else
20135@@ -335,6 +407,7 @@ default_entry:
20136 movl pa(mmu_cr4_features),%eax
20137 movl %eax,%cr4
20138
20139+#ifdef CONFIG_X86_PAE
20140 testb $X86_CR4_PAE, %al # check if PAE is enabled
20141 jz 6f
20142
20143@@ -363,6 +436,9 @@ default_entry:
20144 /* Make changes effective */
20145 wrmsr
20146
20147+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
20148+#endif
20149+
20150 6:
20151
20152 /*
20153@@ -460,14 +536,20 @@ is386: movl $2,%ecx # set MP
20154 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
20155 movl %eax,%ss # after changing gdt.
20156
20157- movl $(__USER_DS),%eax # DS/ES contains default USER segment
20158+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
20159 movl %eax,%ds
20160 movl %eax,%es
20161
20162 movl $(__KERNEL_PERCPU), %eax
20163 movl %eax,%fs # set this cpu's percpu
20164
20165+#ifdef CONFIG_CC_STACKPROTECTOR
20166 movl $(__KERNEL_STACK_CANARY),%eax
20167+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20168+ movl $(__USER_DS),%eax
20169+#else
20170+ xorl %eax,%eax
20171+#endif
20172 movl %eax,%gs
20173
20174 xorl %eax,%eax # Clear LDT
20175@@ -544,8 +626,11 @@ setup_once:
20176 * relocation. Manually set base address in stack canary
20177 * segment descriptor.
20178 */
20179- movl $gdt_page,%eax
20180+ movl $cpu_gdt_table,%eax
20181 movl $stack_canary,%ecx
20182+#ifdef CONFIG_SMP
20183+ addl $__per_cpu_load,%ecx
20184+#endif
20185 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
20186 shrl $16, %ecx
20187 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
20188@@ -576,7 +661,7 @@ ENDPROC(early_idt_handlers)
20189 /* This is global to keep gas from relaxing the jumps */
20190 ENTRY(early_idt_handler)
20191 cld
20192- cmpl $2,%ss:early_recursion_flag
20193+ cmpl $1,%ss:early_recursion_flag
20194 je hlt_loop
20195 incl %ss:early_recursion_flag
20196
20197@@ -614,8 +699,8 @@ ENTRY(early_idt_handler)
20198 pushl (20+6*4)(%esp) /* trapno */
20199 pushl $fault_msg
20200 call printk
20201-#endif
20202 call dump_stack
20203+#endif
20204 hlt_loop:
20205 hlt
20206 jmp hlt_loop
20207@@ -634,8 +719,11 @@ ENDPROC(early_idt_handler)
20208 /* This is the default interrupt "handler" :-) */
20209 ALIGN
20210 ignore_int:
20211- cld
20212 #ifdef CONFIG_PRINTK
20213+ cmpl $2,%ss:early_recursion_flag
20214+ je hlt_loop
20215+ incl %ss:early_recursion_flag
20216+ cld
20217 pushl %eax
20218 pushl %ecx
20219 pushl %edx
20220@@ -644,9 +732,6 @@ ignore_int:
20221 movl $(__KERNEL_DS),%eax
20222 movl %eax,%ds
20223 movl %eax,%es
20224- cmpl $2,early_recursion_flag
20225- je hlt_loop
20226- incl early_recursion_flag
20227 pushl 16(%esp)
20228 pushl 24(%esp)
20229 pushl 32(%esp)
20230@@ -680,29 +765,43 @@ ENTRY(setup_once_ref)
20231 /*
20232 * BSS section
20233 */
20234-__PAGE_ALIGNED_BSS
20235- .align PAGE_SIZE
20236 #ifdef CONFIG_X86_PAE
20237+.section .initial_pg_pmd,"a",@progbits
20238 initial_pg_pmd:
20239 .fill 1024*KPMDS,4,0
20240 #else
20241+.section .initial_page_table,"a",@progbits
20242 ENTRY(initial_page_table)
20243 .fill 1024,4,0
20244 #endif
20245+.section .initial_pg_fixmap,"a",@progbits
20246 initial_pg_fixmap:
20247 .fill 1024,4,0
20248+.section .empty_zero_page,"a",@progbits
20249 ENTRY(empty_zero_page)
20250 .fill 4096,1,0
20251+.section .swapper_pg_dir,"a",@progbits
20252 ENTRY(swapper_pg_dir)
20253+#ifdef CONFIG_X86_PAE
20254+ .fill 4,8,0
20255+#else
20256 .fill 1024,4,0
20257+#endif
20258+
20259+/*
20260+ * The IDT has to be page-aligned to simplify the Pentium
20261+ * F0 0F bug workaround.. We have a special link segment
20262+ * for this.
20263+ */
20264+.section .idt,"a",@progbits
20265+ENTRY(idt_table)
20266+ .fill 256,8,0
20267
20268 /*
20269 * This starts the data section.
20270 */
20271 #ifdef CONFIG_X86_PAE
20272-__PAGE_ALIGNED_DATA
20273- /* Page-aligned for the benefit of paravirt? */
20274- .align PAGE_SIZE
20275+.section .initial_page_table,"a",@progbits
20276 ENTRY(initial_page_table)
20277 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
20278 # if KPMDS == 3
20279@@ -721,12 +820,20 @@ ENTRY(initial_page_table)
20280 # error "Kernel PMDs should be 1, 2 or 3"
20281 # endif
20282 .align PAGE_SIZE /* needs to be page-sized too */
20283+
20284+#ifdef CONFIG_PAX_PER_CPU_PGD
20285+ENTRY(cpu_pgd)
20286+ .rept NR_CPUS
20287+ .fill 4,8,0
20288+ .endr
20289+#endif
20290+
20291 #endif
20292
20293 .data
20294 .balign 4
20295 ENTRY(stack_start)
20296- .long init_thread_union+THREAD_SIZE
20297+ .long init_thread_union+THREAD_SIZE-8
20298
20299 __INITRODATA
20300 int_msg:
20301@@ -754,7 +861,7 @@ fault_msg:
20302 * segment size, and 32-bit linear address value:
20303 */
20304
20305- .data
20306+.section .rodata,"a",@progbits
20307 .globl boot_gdt_descr
20308 .globl idt_descr
20309
20310@@ -763,7 +870,7 @@ fault_msg:
20311 .word 0 # 32 bit align gdt_desc.address
20312 boot_gdt_descr:
20313 .word __BOOT_DS+7
20314- .long boot_gdt - __PAGE_OFFSET
20315+ .long pa(boot_gdt)
20316
20317 .word 0 # 32-bit align idt_desc.address
20318 idt_descr:
20319@@ -774,7 +881,7 @@ idt_descr:
20320 .word 0 # 32 bit align gdt_desc.address
20321 ENTRY(early_gdt_descr)
20322 .word GDT_ENTRIES*8-1
20323- .long gdt_page /* Overwritten for secondary CPUs */
20324+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
20325
20326 /*
20327 * The boot_gdt must mirror the equivalent in setup.S and is
20328@@ -783,5 +890,65 @@ ENTRY(early_gdt_descr)
20329 .align L1_CACHE_BYTES
20330 ENTRY(boot_gdt)
20331 .fill GDT_ENTRY_BOOT_CS,8,0
20332- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
20333- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
20334+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
20335+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
20336+
20337+ .align PAGE_SIZE_asm
20338+ENTRY(cpu_gdt_table)
20339+ .rept NR_CPUS
20340+ .quad 0x0000000000000000 /* NULL descriptor */
20341+ .quad 0x0000000000000000 /* 0x0b reserved */
20342+ .quad 0x0000000000000000 /* 0x13 reserved */
20343+ .quad 0x0000000000000000 /* 0x1b reserved */
20344+
20345+#ifdef CONFIG_PAX_KERNEXEC
20346+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
20347+#else
20348+ .quad 0x0000000000000000 /* 0x20 unused */
20349+#endif
20350+
20351+ .quad 0x0000000000000000 /* 0x28 unused */
20352+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
20353+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
20354+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
20355+ .quad 0x0000000000000000 /* 0x4b reserved */
20356+ .quad 0x0000000000000000 /* 0x53 reserved */
20357+ .quad 0x0000000000000000 /* 0x5b reserved */
20358+
20359+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
20360+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
20361+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
20362+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
20363+
20364+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
20365+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
20366+
20367+ /*
20368+ * Segments used for calling PnP BIOS have byte granularity.
20369+ * The code segments and data segments have fixed 64k limits,
20370+ * the transfer segment sizes are set at run time.
20371+ */
20372+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
20373+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
20374+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
20375+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
20376+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
20377+
20378+ /*
20379+ * The APM segments have byte granularity and their bases
20380+ * are set at run time. All have 64k limits.
20381+ */
20382+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
20383+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
20384+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
20385+
20386+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
20387+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
20388+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
20389+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
20390+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
20391+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
20392+
20393+ /* Be sure this is zeroed to avoid false validations in Xen */
20394+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
20395+ .endr
20396diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
20397index 980053c..74d3b44 100644
20398--- a/arch/x86/kernel/head_64.S
20399+++ b/arch/x86/kernel/head_64.S
20400@@ -20,6 +20,8 @@
20401 #include <asm/processor-flags.h>
20402 #include <asm/percpu.h>
20403 #include <asm/nops.h>
20404+#include <asm/cpufeature.h>
20405+#include <asm/alternative-asm.h>
20406
20407 #ifdef CONFIG_PARAVIRT
20408 #include <asm/asm-offsets.h>
20409@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
20410 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
20411 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
20412 L3_START_KERNEL = pud_index(__START_KERNEL_map)
20413+L4_VMALLOC_START = pgd_index(VMALLOC_START)
20414+L3_VMALLOC_START = pud_index(VMALLOC_START)
20415+L4_VMALLOC_END = pgd_index(VMALLOC_END)
20416+L3_VMALLOC_END = pud_index(VMALLOC_END)
20417+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
20418+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
20419
20420 .text
20421 __HEAD
20422@@ -88,35 +96,23 @@ startup_64:
20423 */
20424 addq %rbp, init_level4_pgt + 0(%rip)
20425 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
20426+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
20427+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
20428+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
20429 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
20430
20431 addq %rbp, level3_ident_pgt + 0(%rip)
20432+#ifndef CONFIG_XEN
20433+ addq %rbp, level3_ident_pgt + 8(%rip)
20434+#endif
20435
20436- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
20437- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
20438+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
20439+
20440+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
20441+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
20442
20443 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
20444-
20445- /* Add an Identity mapping if I am above 1G */
20446- leaq _text(%rip), %rdi
20447- andq $PMD_PAGE_MASK, %rdi
20448-
20449- movq %rdi, %rax
20450- shrq $PUD_SHIFT, %rax
20451- andq $(PTRS_PER_PUD - 1), %rax
20452- jz ident_complete
20453-
20454- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
20455- leaq level3_ident_pgt(%rip), %rbx
20456- movq %rdx, 0(%rbx, %rax, 8)
20457-
20458- movq %rdi, %rax
20459- shrq $PMD_SHIFT, %rax
20460- andq $(PTRS_PER_PMD - 1), %rax
20461- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
20462- leaq level2_spare_pgt(%rip), %rbx
20463- movq %rdx, 0(%rbx, %rax, 8)
20464-ident_complete:
20465+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
20466
20467 /*
20468 * Fixup the kernel text+data virtual addresses. Note that
20469@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
20470 * after the boot processor executes this code.
20471 */
20472
20473- /* Enable PAE mode and PGE */
20474- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
20475+ /* Enable PAE mode and PSE/PGE */
20476+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
20477 movq %rax, %cr4
20478
20479 /* Setup early boot stage 4 level pagetables. */
20480@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
20481 movl $MSR_EFER, %ecx
20482 rdmsr
20483 btsl $_EFER_SCE, %eax /* Enable System Call */
20484- btl $20,%edi /* No Execute supported? */
20485+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
20486 jnc 1f
20487 btsl $_EFER_NX, %eax
20488+ leaq init_level4_pgt(%rip), %rdi
20489+#ifndef CONFIG_EFI
20490+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
20491+#endif
20492+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
20493+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
20494+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
20495+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
20496 1: wrmsr /* Make changes effective */
20497
20498 /* Setup cr0 */
20499@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
20500 * jump. In addition we need to ensure %cs is set so we make this
20501 * a far return.
20502 */
20503+ pax_set_fptr_mask
20504 movq initial_code(%rip),%rax
20505 pushq $0 # fake return address to stop unwinder
20506 pushq $__KERNEL_CS # set correct cs
20507@@ -284,7 +289,7 @@ ENDPROC(start_cpu0)
20508 bad_address:
20509 jmp bad_address
20510
20511- .section ".init.text","ax"
20512+ __INIT
20513 .globl early_idt_handlers
20514 early_idt_handlers:
20515 # 104(%rsp) %rflags
20516@@ -343,7 +348,7 @@ ENTRY(early_idt_handler)
20517 call dump_stack
20518 #ifdef CONFIG_KALLSYMS
20519 leaq early_idt_ripmsg(%rip),%rdi
20520- movq 40(%rsp),%rsi # %rip again
20521+ movq 88(%rsp),%rsi # %rip again
20522 call __print_symbol
20523 #endif
20524 #endif /* EARLY_PRINTK */
20525@@ -363,11 +368,15 @@ ENTRY(early_idt_handler)
20526 addq $16,%rsp # drop vector number and error code
20527 decl early_recursion_flag(%rip)
20528 INTERRUPT_RETURN
20529+ .previous
20530
20531+ __INITDATA
20532 .balign 4
20533 early_recursion_flag:
20534 .long 0
20535+ .previous
20536
20537+ .section .rodata,"a",@progbits
20538 #ifdef CONFIG_EARLY_PRINTK
20539 early_idt_msg:
20540 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
20541@@ -376,6 +385,7 @@ early_idt_ripmsg:
20542 #endif /* CONFIG_EARLY_PRINTK */
20543 .previous
20544
20545+ .section .rodata,"a",@progbits
20546 #define NEXT_PAGE(name) \
20547 .balign PAGE_SIZE; \
20548 ENTRY(name)
20549@@ -388,7 +398,6 @@ ENTRY(name)
20550 i = i + 1 ; \
20551 .endr
20552
20553- .data
20554 /*
20555 * This default setting generates an ident mapping at address 0x100000
20556 * and a mapping for the kernel that precisely maps virtual address
20557@@ -399,13 +408,41 @@ NEXT_PAGE(init_level4_pgt)
20558 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20559 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
20560 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20561+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
20562+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
20563+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
20564+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20565+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20566+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20567 .org init_level4_pgt + L4_START_KERNEL*8, 0
20568 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20569 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20570
20571+#ifdef CONFIG_PAX_PER_CPU_PGD
20572+NEXT_PAGE(cpu_pgd)
20573+ .rept NR_CPUS
20574+ .fill 512,8,0
20575+ .endr
20576+#endif
20577+
20578 NEXT_PAGE(level3_ident_pgt)
20579 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20580+#ifdef CONFIG_XEN
20581 .fill 511,8,0
20582+#else
20583+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20584+ .fill 510,8,0
20585+#endif
20586+
20587+NEXT_PAGE(level3_vmalloc_start_pgt)
20588+ .fill 512,8,0
20589+
20590+NEXT_PAGE(level3_vmalloc_end_pgt)
20591+ .fill 512,8,0
20592+
20593+NEXT_PAGE(level3_vmemmap_pgt)
20594+ .fill L3_VMEMMAP_START,8,0
20595+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20596
20597 NEXT_PAGE(level3_kernel_pgt)
20598 .fill L3_START_KERNEL,8,0
20599@@ -413,20 +450,23 @@ NEXT_PAGE(level3_kernel_pgt)
20600 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20601 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20602
20603+NEXT_PAGE(level2_vmemmap_pgt)
20604+ .fill 512,8,0
20605+
20606 NEXT_PAGE(level2_fixmap_pgt)
20607- .fill 506,8,0
20608- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20609- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20610- .fill 5,8,0
20611+ .fill 507,8,0
20612+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20613+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20614+ .fill 4,8,0
20615
20616-NEXT_PAGE(level1_fixmap_pgt)
20617+NEXT_PAGE(level1_vsyscall_pgt)
20618 .fill 512,8,0
20619
20620-NEXT_PAGE(level2_ident_pgt)
20621- /* Since I easily can, map the first 1G.
20622+ /* Since I easily can, map the first 2G.
20623 * Don't set NX because code runs from these pages.
20624 */
20625- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20626+NEXT_PAGE(level2_ident_pgt)
20627+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20628
20629 NEXT_PAGE(level2_kernel_pgt)
20630 /*
20631@@ -439,37 +479,59 @@ NEXT_PAGE(level2_kernel_pgt)
20632 * If you want to increase this then increase MODULES_VADDR
20633 * too.)
20634 */
20635- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
20636- KERNEL_IMAGE_SIZE/PMD_SIZE)
20637-
20638-NEXT_PAGE(level2_spare_pgt)
20639- .fill 512, 8, 0
20640+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
20641
20642 #undef PMDS
20643 #undef NEXT_PAGE
20644
20645- .data
20646+ .align PAGE_SIZE
20647+ENTRY(cpu_gdt_table)
20648+ .rept NR_CPUS
20649+ .quad 0x0000000000000000 /* NULL descriptor */
20650+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20651+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
20652+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
20653+ .quad 0x00cffb000000ffff /* __USER32_CS */
20654+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20655+ .quad 0x00affb000000ffff /* __USER_CS */
20656+
20657+#ifdef CONFIG_PAX_KERNEXEC
20658+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20659+#else
20660+ .quad 0x0 /* unused */
20661+#endif
20662+
20663+ .quad 0,0 /* TSS */
20664+ .quad 0,0 /* LDT */
20665+ .quad 0,0,0 /* three TLS descriptors */
20666+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
20667+ /* asm/segment.h:GDT_ENTRIES must match this */
20668+
20669+ /* zero the remaining page */
20670+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20671+ .endr
20672+
20673 .align 16
20674 .globl early_gdt_descr
20675 early_gdt_descr:
20676 .word GDT_ENTRIES*8-1
20677 early_gdt_descr_base:
20678- .quad INIT_PER_CPU_VAR(gdt_page)
20679+ .quad cpu_gdt_table
20680
20681 ENTRY(phys_base)
20682 /* This must match the first entry in level2_kernel_pgt */
20683 .quad 0x0000000000000000
20684
20685 #include "../../x86/xen/xen-head.S"
20686-
20687- .section .bss, "aw", @nobits
20688+
20689+ .section .rodata,"a",@progbits
20690 .align L1_CACHE_BYTES
20691 ENTRY(idt_table)
20692- .skip IDT_ENTRIES * 16
20693+ .fill 512,8,0
20694
20695 .align L1_CACHE_BYTES
20696 ENTRY(nmi_idt_table)
20697- .skip IDT_ENTRIES * 16
20698+ .fill 512,8,0
20699
20700 __PAGE_ALIGNED_BSS
20701 .align PAGE_SIZE
20702diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20703index 9c3bd4a..e1d9b35 100644
20704--- a/arch/x86/kernel/i386_ksyms_32.c
20705+++ b/arch/x86/kernel/i386_ksyms_32.c
20706@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20707 EXPORT_SYMBOL(cmpxchg8b_emu);
20708 #endif
20709
20710+EXPORT_SYMBOL_GPL(cpu_gdt_table);
20711+
20712 /* Networking helper routines. */
20713 EXPORT_SYMBOL(csum_partial_copy_generic);
20714+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20715+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20716
20717 EXPORT_SYMBOL(__get_user_1);
20718 EXPORT_SYMBOL(__get_user_2);
20719@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
20720
20721 EXPORT_SYMBOL(csum_partial);
20722 EXPORT_SYMBOL(empty_zero_page);
20723+
20724+#ifdef CONFIG_PAX_KERNEXEC
20725+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20726+#endif
20727diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20728index 245a71d..89d9ce4 100644
20729--- a/arch/x86/kernel/i387.c
20730+++ b/arch/x86/kernel/i387.c
20731@@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20732 static inline bool interrupted_user_mode(void)
20733 {
20734 struct pt_regs *regs = get_irq_regs();
20735- return regs && user_mode_vm(regs);
20736+ return regs && user_mode(regs);
20737 }
20738
20739 /*
20740diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20741index 9a5c460..b332a4b 100644
20742--- a/arch/x86/kernel/i8259.c
20743+++ b/arch/x86/kernel/i8259.c
20744@@ -209,7 +209,7 @@ spurious_8259A_irq:
20745 "spurious 8259A interrupt: IRQ%d.\n", irq);
20746 spurious_irq_mask |= irqmask;
20747 }
20748- atomic_inc(&irq_err_count);
20749+ atomic_inc_unchecked(&irq_err_count);
20750 /*
20751 * Theoretically we do not have to handle this IRQ,
20752 * but in Linux this does not cause problems and is
20753@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
20754 /* (slave's support for AEOI in flat mode is to be investigated) */
20755 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
20756
20757+ pax_open_kernel();
20758 if (auto_eoi)
20759 /*
20760 * In AEOI mode we just have to mask the interrupt
20761 * when acking.
20762 */
20763- i8259A_chip.irq_mask_ack = disable_8259A_irq;
20764+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
20765 else
20766- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20767+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20768+ pax_close_kernel();
20769
20770 udelay(100); /* wait for 8259A to initialize */
20771
20772diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
20773index a979b5b..1d6db75 100644
20774--- a/arch/x86/kernel/io_delay.c
20775+++ b/arch/x86/kernel/io_delay.c
20776@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
20777 * Quirk table for systems that misbehave (lock up, etc.) if port
20778 * 0x80 is used:
20779 */
20780-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
20781+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
20782 {
20783 .callback = dmi_io_delay_0xed_port,
20784 .ident = "Compaq Presario V6000",
20785diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20786index 8c96897..be66bfa 100644
20787--- a/arch/x86/kernel/ioport.c
20788+++ b/arch/x86/kernel/ioport.c
20789@@ -6,6 +6,7 @@
20790 #include <linux/sched.h>
20791 #include <linux/kernel.h>
20792 #include <linux/capability.h>
20793+#include <linux/security.h>
20794 #include <linux/errno.h>
20795 #include <linux/types.h>
20796 #include <linux/ioport.h>
20797@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20798
20799 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
20800 return -EINVAL;
20801+#ifdef CONFIG_GRKERNSEC_IO
20802+ if (turn_on && grsec_disable_privio) {
20803+ gr_handle_ioperm();
20804+ return -EPERM;
20805+ }
20806+#endif
20807 if (turn_on && !capable(CAP_SYS_RAWIO))
20808 return -EPERM;
20809
20810@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20811 * because the ->io_bitmap_max value must match the bitmap
20812 * contents:
20813 */
20814- tss = &per_cpu(init_tss, get_cpu());
20815+ tss = init_tss + get_cpu();
20816
20817 if (turn_on)
20818 bitmap_clear(t->io_bitmap_ptr, from, num);
20819@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
20820 return -EINVAL;
20821 /* Trying to gain more privileges? */
20822 if (level > old) {
20823+#ifdef CONFIG_GRKERNSEC_IO
20824+ if (grsec_disable_privio) {
20825+ gr_handle_iopl();
20826+ return -EPERM;
20827+ }
20828+#endif
20829 if (!capable(CAP_SYS_RAWIO))
20830 return -EPERM;
20831 }
20832diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
20833index e4595f1..ee3bfb8 100644
20834--- a/arch/x86/kernel/irq.c
20835+++ b/arch/x86/kernel/irq.c
20836@@ -18,7 +18,7 @@
20837 #include <asm/mce.h>
20838 #include <asm/hw_irq.h>
20839
20840-atomic_t irq_err_count;
20841+atomic_unchecked_t irq_err_count;
20842
20843 /* Function pointer for generic interrupt vector handling */
20844 void (*x86_platform_ipi_callback)(void) = NULL;
20845@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
20846 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
20847 seq_printf(p, " Machine check polls\n");
20848 #endif
20849- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
20850+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
20851 #if defined(CONFIG_X86_IO_APIC)
20852- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
20853+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
20854 #endif
20855 return 0;
20856 }
20857@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
20858
20859 u64 arch_irq_stat(void)
20860 {
20861- u64 sum = atomic_read(&irq_err_count);
20862+ u64 sum = atomic_read_unchecked(&irq_err_count);
20863
20864 #ifdef CONFIG_X86_IO_APIC
20865- sum += atomic_read(&irq_mis_count);
20866+ sum += atomic_read_unchecked(&irq_mis_count);
20867 #endif
20868 return sum;
20869 }
20870diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
20871index 344faf8..355f60d 100644
20872--- a/arch/x86/kernel/irq_32.c
20873+++ b/arch/x86/kernel/irq_32.c
20874@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
20875 __asm__ __volatile__("andl %%esp,%0" :
20876 "=r" (sp) : "0" (THREAD_SIZE - 1));
20877
20878- return sp < (sizeof(struct thread_info) + STACK_WARN);
20879+ return sp < STACK_WARN;
20880 }
20881
20882 static void print_stack_overflow(void)
20883@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
20884 * per-CPU IRQ handling contexts (thread information and stack)
20885 */
20886 union irq_ctx {
20887- struct thread_info tinfo;
20888- u32 stack[THREAD_SIZE/sizeof(u32)];
20889+ unsigned long previous_esp;
20890+ u32 stack[THREAD_SIZE/sizeof(u32)];
20891 } __attribute__((aligned(THREAD_SIZE)));
20892
20893 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
20894@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
20895 static inline int
20896 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20897 {
20898- union irq_ctx *curctx, *irqctx;
20899+ union irq_ctx *irqctx;
20900 u32 *isp, arg1, arg2;
20901
20902- curctx = (union irq_ctx *) current_thread_info();
20903 irqctx = __this_cpu_read(hardirq_ctx);
20904
20905 /*
20906@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20907 * handler) we can't do that and just have to keep using the
20908 * current stack (which is the irq stack already after all)
20909 */
20910- if (unlikely(curctx == irqctx))
20911+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
20912 return 0;
20913
20914 /* build the stack frame on the IRQ stack */
20915- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20916- irqctx->tinfo.task = curctx->tinfo.task;
20917- irqctx->tinfo.previous_esp = current_stack_pointer;
20918+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20919+ irqctx->previous_esp = current_stack_pointer;
20920
20921- /* Copy the preempt_count so that the [soft]irq checks work. */
20922- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
20923+#ifdef CONFIG_PAX_MEMORY_UDEREF
20924+ __set_fs(MAKE_MM_SEG(0));
20925+#endif
20926
20927 if (unlikely(overflow))
20928 call_on_stack(print_stack_overflow, isp);
20929@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20930 : "0" (irq), "1" (desc), "2" (isp),
20931 "D" (desc->handle_irq)
20932 : "memory", "cc", "ecx");
20933+
20934+#ifdef CONFIG_PAX_MEMORY_UDEREF
20935+ __set_fs(current_thread_info()->addr_limit);
20936+#endif
20937+
20938 return 1;
20939 }
20940
20941@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20942 */
20943 void __cpuinit irq_ctx_init(int cpu)
20944 {
20945- union irq_ctx *irqctx;
20946-
20947 if (per_cpu(hardirq_ctx, cpu))
20948 return;
20949
20950- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20951- THREADINFO_GFP,
20952- THREAD_SIZE_ORDER));
20953- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20954- irqctx->tinfo.cpu = cpu;
20955- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
20956- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20957-
20958- per_cpu(hardirq_ctx, cpu) = irqctx;
20959-
20960- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20961- THREADINFO_GFP,
20962- THREAD_SIZE_ORDER));
20963- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20964- irqctx->tinfo.cpu = cpu;
20965- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20966-
20967- per_cpu(softirq_ctx, cpu) = irqctx;
20968+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20969+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20970+
20971+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20972+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20973
20974 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20975 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20976@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
20977 asmlinkage void do_softirq(void)
20978 {
20979 unsigned long flags;
20980- struct thread_info *curctx;
20981 union irq_ctx *irqctx;
20982 u32 *isp;
20983
20984@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
20985 local_irq_save(flags);
20986
20987 if (local_softirq_pending()) {
20988- curctx = current_thread_info();
20989 irqctx = __this_cpu_read(softirq_ctx);
20990- irqctx->tinfo.task = curctx->task;
20991- irqctx->tinfo.previous_esp = current_stack_pointer;
20992+ irqctx->previous_esp = current_stack_pointer;
20993
20994 /* build the stack frame on the softirq stack */
20995- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20996+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20997+
20998+#ifdef CONFIG_PAX_MEMORY_UDEREF
20999+ __set_fs(MAKE_MM_SEG(0));
21000+#endif
21001
21002 call_on_stack(__do_softirq, isp);
21003+
21004+#ifdef CONFIG_PAX_MEMORY_UDEREF
21005+ __set_fs(current_thread_info()->addr_limit);
21006+#endif
21007+
21008 /*
21009 * Shouldn't happen, we returned above if in_interrupt():
21010 */
21011@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
21012 if (unlikely(!desc))
21013 return false;
21014
21015- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21016+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21017 if (unlikely(overflow))
21018 print_stack_overflow();
21019 desc->handle_irq(irq, desc);
21020diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
21021index d04d3ec..ea4b374 100644
21022--- a/arch/x86/kernel/irq_64.c
21023+++ b/arch/x86/kernel/irq_64.c
21024@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
21025 u64 estack_top, estack_bottom;
21026 u64 curbase = (u64)task_stack_page(current);
21027
21028- if (user_mode_vm(regs))
21029+ if (user_mode(regs))
21030 return;
21031
21032 if (regs->sp >= curbase + sizeof(struct thread_info) +
21033diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
21034index dc1404b..bbc43e7 100644
21035--- a/arch/x86/kernel/kdebugfs.c
21036+++ b/arch/x86/kernel/kdebugfs.c
21037@@ -27,7 +27,7 @@ struct setup_data_node {
21038 u32 len;
21039 };
21040
21041-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
21042+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
21043 size_t count, loff_t *ppos)
21044 {
21045 struct setup_data_node *node = file->private_data;
21046diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
21047index 836f832..a8bda67 100644
21048--- a/arch/x86/kernel/kgdb.c
21049+++ b/arch/x86/kernel/kgdb.c
21050@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
21051 #ifdef CONFIG_X86_32
21052 switch (regno) {
21053 case GDB_SS:
21054- if (!user_mode_vm(regs))
21055+ if (!user_mode(regs))
21056 *(unsigned long *)mem = __KERNEL_DS;
21057 break;
21058 case GDB_SP:
21059- if (!user_mode_vm(regs))
21060+ if (!user_mode(regs))
21061 *(unsigned long *)mem = kernel_stack_pointer(regs);
21062 break;
21063 case GDB_GS:
21064@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
21065 bp->attr.bp_addr = breakinfo[breakno].addr;
21066 bp->attr.bp_len = breakinfo[breakno].len;
21067 bp->attr.bp_type = breakinfo[breakno].type;
21068- info->address = breakinfo[breakno].addr;
21069+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
21070+ info->address = ktla_ktva(breakinfo[breakno].addr);
21071+ else
21072+ info->address = breakinfo[breakno].addr;
21073 info->len = breakinfo[breakno].len;
21074 info->type = breakinfo[breakno].type;
21075 val = arch_install_hw_breakpoint(bp);
21076@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
21077 case 'k':
21078 /* clear the trace bit */
21079 linux_regs->flags &= ~X86_EFLAGS_TF;
21080- atomic_set(&kgdb_cpu_doing_single_step, -1);
21081+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
21082
21083 /* set the trace bit if we're stepping */
21084 if (remcomInBuffer[0] == 's') {
21085 linux_regs->flags |= X86_EFLAGS_TF;
21086- atomic_set(&kgdb_cpu_doing_single_step,
21087+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
21088 raw_smp_processor_id());
21089 }
21090
21091@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
21092
21093 switch (cmd) {
21094 case DIE_DEBUG:
21095- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
21096+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
21097 if (user_mode(regs))
21098 return single_step_cont(regs, args);
21099 break;
21100@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21101 #endif /* CONFIG_DEBUG_RODATA */
21102
21103 bpt->type = BP_BREAKPOINT;
21104- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
21105+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
21106 BREAK_INSTR_SIZE);
21107 if (err)
21108 return err;
21109- err = probe_kernel_write((char *)bpt->bpt_addr,
21110+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21111 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
21112 #ifdef CONFIG_DEBUG_RODATA
21113 if (!err)
21114@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21115 return -EBUSY;
21116 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
21117 BREAK_INSTR_SIZE);
21118- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21119+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21120 if (err)
21121 return err;
21122 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
21123@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
21124 if (mutex_is_locked(&text_mutex))
21125 goto knl_write;
21126 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
21127- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21128+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21129 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
21130 goto knl_write;
21131 return err;
21132 knl_write:
21133 #endif /* CONFIG_DEBUG_RODATA */
21134- return probe_kernel_write((char *)bpt->bpt_addr,
21135+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21136 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
21137 }
21138
21139diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
21140index c5e410e..ed5a7f0 100644
21141--- a/arch/x86/kernel/kprobes-opt.c
21142+++ b/arch/x86/kernel/kprobes-opt.c
21143@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21144 * Verify if the address gap is in 2GB range, because this uses
21145 * a relative jump.
21146 */
21147- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
21148+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
21149 if (abs(rel) > 0x7fffffff)
21150 return -ERANGE;
21151
21152@@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21153 op->optinsn.size = ret;
21154
21155 /* Copy arch-dep-instance from template */
21156- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
21157+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
21158
21159 /* Set probe information */
21160 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
21161
21162 /* Set probe function call */
21163- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
21164+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
21165
21166 /* Set returning jmp instruction at the tail of out-of-line buffer */
21167- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
21168+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
21169 (u8 *)op->kp.addr + op->optinsn.size);
21170
21171 flush_icache_range((unsigned long) buf,
21172@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
21173 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
21174
21175 /* Backup instructions which will be replaced by jump address */
21176- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
21177+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
21178 RELATIVE_ADDR_SIZE);
21179
21180 insn_buf[0] = RELATIVEJUMP_OPCODE;
21181@@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
21182 /* This kprobe is really able to run optimized path. */
21183 op = container_of(p, struct optimized_kprobe, kp);
21184 /* Detour through copied instructions */
21185- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
21186+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
21187 if (!reenter)
21188 reset_current_kprobe();
21189 preempt_enable_no_resched();
21190diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
21191index 57916c0..9e0b9d0 100644
21192--- a/arch/x86/kernel/kprobes.c
21193+++ b/arch/x86/kernel/kprobes.c
21194@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
21195 s32 raddr;
21196 } __attribute__((packed)) *insn;
21197
21198- insn = (struct __arch_relative_insn *)from;
21199+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
21200+
21201+ pax_open_kernel();
21202 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
21203 insn->op = op;
21204+ pax_close_kernel();
21205 }
21206
21207 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
21208@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
21209 kprobe_opcode_t opcode;
21210 kprobe_opcode_t *orig_opcodes = opcodes;
21211
21212- if (search_exception_tables((unsigned long)opcodes))
21213+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
21214 return 0; /* Page fault may occur on this address. */
21215
21216 retry:
21217@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
21218 * for the first byte, we can recover the original instruction
21219 * from it and kp->opcode.
21220 */
21221- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21222+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21223 buf[0] = kp->opcode;
21224- return (unsigned long)buf;
21225+ return ktva_ktla((unsigned long)buf);
21226 }
21227
21228 /*
21229@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21230 /* Another subsystem puts a breakpoint, failed to recover */
21231 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
21232 return 0;
21233+ pax_open_kernel();
21234 memcpy(dest, insn.kaddr, insn.length);
21235+ pax_close_kernel();
21236
21237 #ifdef CONFIG_X86_64
21238 if (insn_rip_relative(&insn)) {
21239@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21240 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
21241 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
21242 disp = (u8 *) dest + insn_offset_displacement(&insn);
21243+ pax_open_kernel();
21244 *(s32 *) disp = (s32) newdisp;
21245+ pax_close_kernel();
21246 }
21247 #endif
21248 return insn.length;
21249@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21250 * nor set current_kprobe, because it doesn't use single
21251 * stepping.
21252 */
21253- regs->ip = (unsigned long)p->ainsn.insn;
21254+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21255 preempt_enable_no_resched();
21256 return;
21257 }
21258@@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21259 regs->flags &= ~X86_EFLAGS_IF;
21260 /* single step inline if the instruction is an int3 */
21261 if (p->opcode == BREAKPOINT_INSTRUCTION)
21262- regs->ip = (unsigned long)p->addr;
21263+ regs->ip = ktla_ktva((unsigned long)p->addr);
21264 else
21265- regs->ip = (unsigned long)p->ainsn.insn;
21266+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21267 }
21268
21269 /*
21270@@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
21271 setup_singlestep(p, regs, kcb, 0);
21272 return 1;
21273 }
21274- } else if (*addr != BREAKPOINT_INSTRUCTION) {
21275+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
21276 /*
21277 * The breakpoint instruction was removed right
21278 * after we hit it. Another cpu has removed
21279@@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
21280 " movq %rax, 152(%rsp)\n"
21281 RESTORE_REGS_STRING
21282 " popfq\n"
21283+#ifdef KERNEXEC_PLUGIN
21284+ " btsq $63,(%rsp)\n"
21285+#endif
21286 #else
21287 " pushf\n"
21288 SAVE_REGS_STRING
21289@@ -788,7 +798,7 @@ static void __kprobes
21290 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
21291 {
21292 unsigned long *tos = stack_addr(regs);
21293- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
21294+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
21295 unsigned long orig_ip = (unsigned long)p->addr;
21296 kprobe_opcode_t *insn = p->ainsn.insn;
21297
21298@@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
21299 struct die_args *args = data;
21300 int ret = NOTIFY_DONE;
21301
21302- if (args->regs && user_mode_vm(args->regs))
21303+ if (args->regs && user_mode(args->regs))
21304 return ret;
21305
21306 switch (val) {
21307diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
21308index 9c2bd8b..bb1131c 100644
21309--- a/arch/x86/kernel/kvm.c
21310+++ b/arch/x86/kernel/kvm.c
21311@@ -452,7 +452,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
21312 return NOTIFY_OK;
21313 }
21314
21315-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
21316+static struct notifier_block kvm_cpu_notifier = {
21317 .notifier_call = kvm_cpu_notify,
21318 };
21319 #endif
21320diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
21321index ebc9873..1b9724b 100644
21322--- a/arch/x86/kernel/ldt.c
21323+++ b/arch/x86/kernel/ldt.c
21324@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
21325 if (reload) {
21326 #ifdef CONFIG_SMP
21327 preempt_disable();
21328- load_LDT(pc);
21329+ load_LDT_nolock(pc);
21330 if (!cpumask_equal(mm_cpumask(current->mm),
21331 cpumask_of(smp_processor_id())))
21332 smp_call_function(flush_ldt, current->mm, 1);
21333 preempt_enable();
21334 #else
21335- load_LDT(pc);
21336+ load_LDT_nolock(pc);
21337 #endif
21338 }
21339 if (oldsize) {
21340@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
21341 return err;
21342
21343 for (i = 0; i < old->size; i++)
21344- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
21345+ write_ldt_entry(new->ldt, i, old->ldt + i);
21346 return 0;
21347 }
21348
21349@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
21350 retval = copy_ldt(&mm->context, &old_mm->context);
21351 mutex_unlock(&old_mm->context.lock);
21352 }
21353+
21354+ if (tsk == current) {
21355+ mm->context.vdso = 0;
21356+
21357+#ifdef CONFIG_X86_32
21358+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21359+ mm->context.user_cs_base = 0UL;
21360+ mm->context.user_cs_limit = ~0UL;
21361+
21362+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
21363+ cpus_clear(mm->context.cpu_user_cs_mask);
21364+#endif
21365+
21366+#endif
21367+#endif
21368+
21369+ }
21370+
21371 return retval;
21372 }
21373
21374@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
21375 }
21376 }
21377
21378+#ifdef CONFIG_PAX_SEGMEXEC
21379+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
21380+ error = -EINVAL;
21381+ goto out_unlock;
21382+ }
21383+#endif
21384+
21385 fill_ldt(&ldt, &ldt_info);
21386 if (oldmode)
21387 ldt.avl = 0;
21388diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
21389index 5b19e4d..6476a76 100644
21390--- a/arch/x86/kernel/machine_kexec_32.c
21391+++ b/arch/x86/kernel/machine_kexec_32.c
21392@@ -26,7 +26,7 @@
21393 #include <asm/cacheflush.h>
21394 #include <asm/debugreg.h>
21395
21396-static void set_idt(void *newidt, __u16 limit)
21397+static void set_idt(struct desc_struct *newidt, __u16 limit)
21398 {
21399 struct desc_ptr curidt;
21400
21401@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
21402 }
21403
21404
21405-static void set_gdt(void *newgdt, __u16 limit)
21406+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
21407 {
21408 struct desc_ptr curgdt;
21409
21410@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
21411 }
21412
21413 control_page = page_address(image->control_code_page);
21414- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
21415+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
21416
21417 relocate_kernel_ptr = control_page;
21418 page_list[PA_CONTROL_PAGE] = __pa(control_page);
21419diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
21420index 3a04b22..1d2eb09 100644
21421--- a/arch/x86/kernel/microcode_core.c
21422+++ b/arch/x86/kernel/microcode_core.c
21423@@ -512,7 +512,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21424 return NOTIFY_OK;
21425 }
21426
21427-static struct notifier_block __refdata mc_cpu_notifier = {
21428+static struct notifier_block mc_cpu_notifier = {
21429 .notifier_call = mc_cpu_callback,
21430 };
21431
21432diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
21433index 3544aed..01ddc1c 100644
21434--- a/arch/x86/kernel/microcode_intel.c
21435+++ b/arch/x86/kernel/microcode_intel.c
21436@@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21437
21438 static int get_ucode_user(void *to, const void *from, size_t n)
21439 {
21440- return copy_from_user(to, from, n);
21441+ return copy_from_user(to, (const void __force_user *)from, n);
21442 }
21443
21444 static enum ucode_state
21445 request_microcode_user(int cpu, const void __user *buf, size_t size)
21446 {
21447- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21448+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21449 }
21450
21451 static void microcode_fini_cpu(int cpu)
21452diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
21453index 216a4d7..228255a 100644
21454--- a/arch/x86/kernel/module.c
21455+++ b/arch/x86/kernel/module.c
21456@@ -43,15 +43,60 @@ do { \
21457 } while (0)
21458 #endif
21459
21460-void *module_alloc(unsigned long size)
21461+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
21462 {
21463- if (PAGE_ALIGN(size) > MODULES_LEN)
21464+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
21465 return NULL;
21466 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
21467- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
21468+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
21469 -1, __builtin_return_address(0));
21470 }
21471
21472+void *module_alloc(unsigned long size)
21473+{
21474+
21475+#ifdef CONFIG_PAX_KERNEXEC
21476+ return __module_alloc(size, PAGE_KERNEL);
21477+#else
21478+ return __module_alloc(size, PAGE_KERNEL_EXEC);
21479+#endif
21480+
21481+}
21482+
21483+#ifdef CONFIG_PAX_KERNEXEC
21484+#ifdef CONFIG_X86_32
21485+void *module_alloc_exec(unsigned long size)
21486+{
21487+ struct vm_struct *area;
21488+
21489+ if (size == 0)
21490+ return NULL;
21491+
21492+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
21493+ return area ? area->addr : NULL;
21494+}
21495+EXPORT_SYMBOL(module_alloc_exec);
21496+
21497+void module_free_exec(struct module *mod, void *module_region)
21498+{
21499+ vunmap(module_region);
21500+}
21501+EXPORT_SYMBOL(module_free_exec);
21502+#else
21503+void module_free_exec(struct module *mod, void *module_region)
21504+{
21505+ module_free(mod, module_region);
21506+}
21507+EXPORT_SYMBOL(module_free_exec);
21508+
21509+void *module_alloc_exec(unsigned long size)
21510+{
21511+ return __module_alloc(size, PAGE_KERNEL_RX);
21512+}
21513+EXPORT_SYMBOL(module_alloc_exec);
21514+#endif
21515+#endif
21516+
21517 #ifdef CONFIG_X86_32
21518 int apply_relocate(Elf32_Shdr *sechdrs,
21519 const char *strtab,
21520@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21521 unsigned int i;
21522 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
21523 Elf32_Sym *sym;
21524- uint32_t *location;
21525+ uint32_t *plocation, location;
21526
21527 DEBUGP("Applying relocate section %u to %u\n",
21528 relsec, sechdrs[relsec].sh_info);
21529 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
21530 /* This is where to make the change */
21531- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
21532- + rel[i].r_offset;
21533+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
21534+ location = (uint32_t)plocation;
21535+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
21536+ plocation = ktla_ktva((void *)plocation);
21537 /* This is the symbol it is referring to. Note that all
21538 undefined symbols have been resolved. */
21539 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
21540@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21541 switch (ELF32_R_TYPE(rel[i].r_info)) {
21542 case R_386_32:
21543 /* We add the value into the location given */
21544- *location += sym->st_value;
21545+ pax_open_kernel();
21546+ *plocation += sym->st_value;
21547+ pax_close_kernel();
21548 break;
21549 case R_386_PC32:
21550 /* Add the value, subtract its position */
21551- *location += sym->st_value - (uint32_t)location;
21552+ pax_open_kernel();
21553+ *plocation += sym->st_value - location;
21554+ pax_close_kernel();
21555 break;
21556 default:
21557 pr_err("%s: Unknown relocation: %u\n",
21558@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
21559 case R_X86_64_NONE:
21560 break;
21561 case R_X86_64_64:
21562+ pax_open_kernel();
21563 *(u64 *)loc = val;
21564+ pax_close_kernel();
21565 break;
21566 case R_X86_64_32:
21567+ pax_open_kernel();
21568 *(u32 *)loc = val;
21569+ pax_close_kernel();
21570 if (val != *(u32 *)loc)
21571 goto overflow;
21572 break;
21573 case R_X86_64_32S:
21574+ pax_open_kernel();
21575 *(s32 *)loc = val;
21576+ pax_close_kernel();
21577 if ((s64)val != *(s32 *)loc)
21578 goto overflow;
21579 break;
21580 case R_X86_64_PC32:
21581 val -= (u64)loc;
21582+ pax_open_kernel();
21583 *(u32 *)loc = val;
21584+ pax_close_kernel();
21585+
21586 #if 0
21587 if ((s64)val != *(s32 *)loc)
21588 goto overflow;
21589diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
21590index 4929502..686c291 100644
21591--- a/arch/x86/kernel/msr.c
21592+++ b/arch/x86/kernel/msr.c
21593@@ -234,7 +234,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
21594 return notifier_from_errno(err);
21595 }
21596
21597-static struct notifier_block __refdata msr_class_cpu_notifier = {
21598+static struct notifier_block msr_class_cpu_notifier = {
21599 .notifier_call = msr_class_cpu_callback,
21600 };
21601
21602diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21603index f84f5c5..f404e81 100644
21604--- a/arch/x86/kernel/nmi.c
21605+++ b/arch/x86/kernel/nmi.c
21606@@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
21607 return handled;
21608 }
21609
21610-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21611+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
21612 {
21613 struct nmi_desc *desc = nmi_to_desc(type);
21614 unsigned long flags;
21615@@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21616 * event confuses some handlers (kdump uses this flag)
21617 */
21618 if (action->flags & NMI_FLAG_FIRST)
21619- list_add_rcu(&action->list, &desc->head);
21620+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
21621 else
21622- list_add_tail_rcu(&action->list, &desc->head);
21623+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
21624
21625 spin_unlock_irqrestore(&desc->lock, flags);
21626 return 0;
21627@@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
21628 if (!strcmp(n->name, name)) {
21629 WARN(in_nmi(),
21630 "Trying to free NMI (%s) from NMI context!\n", n->name);
21631- list_del_rcu(&n->list);
21632+ pax_list_del_rcu((struct list_head *)&n->list);
21633 break;
21634 }
21635 }
21636@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21637 dotraplinkage notrace __kprobes void
21638 do_nmi(struct pt_regs *regs, long error_code)
21639 {
21640+
21641+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21642+ if (!user_mode(regs)) {
21643+ unsigned long cs = regs->cs & 0xFFFF;
21644+ unsigned long ip = ktva_ktla(regs->ip);
21645+
21646+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21647+ regs->ip = ip;
21648+ }
21649+#endif
21650+
21651 nmi_nesting_preprocess(regs);
21652
21653 nmi_enter();
21654diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
21655index 6d9582e..f746287 100644
21656--- a/arch/x86/kernel/nmi_selftest.c
21657+++ b/arch/x86/kernel/nmi_selftest.c
21658@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
21659 {
21660 /* trap all the unknown NMIs we may generate */
21661 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
21662- __initdata);
21663+ __initconst);
21664 }
21665
21666 static void __init cleanup_nmi_testsuite(void)
21667@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
21668 unsigned long timeout;
21669
21670 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
21671- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
21672+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
21673 nmi_fail = FAILURE;
21674 return;
21675 }
21676diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21677index 676b8c7..870ba04 100644
21678--- a/arch/x86/kernel/paravirt-spinlocks.c
21679+++ b/arch/x86/kernel/paravirt-spinlocks.c
21680@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21681 arch_spin_lock(lock);
21682 }
21683
21684-struct pv_lock_ops pv_lock_ops = {
21685+struct pv_lock_ops pv_lock_ops __read_only = {
21686 #ifdef CONFIG_SMP
21687 .spin_is_locked = __ticket_spin_is_locked,
21688 .spin_is_contended = __ticket_spin_is_contended,
21689diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21690index 17fff18..5cfa0f4 100644
21691--- a/arch/x86/kernel/paravirt.c
21692+++ b/arch/x86/kernel/paravirt.c
21693@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21694 {
21695 return x;
21696 }
21697+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21698+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21699+#endif
21700
21701 void __init default_banner(void)
21702 {
21703@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21704 if (opfunc == NULL)
21705 /* If there's no function, patch it with a ud2a (BUG) */
21706 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21707- else if (opfunc == _paravirt_nop)
21708+ else if (opfunc == (void *)_paravirt_nop)
21709 /* If the operation is a nop, then nop the callsite */
21710 ret = paravirt_patch_nop();
21711
21712 /* identity functions just return their single argument */
21713- else if (opfunc == _paravirt_ident_32)
21714+ else if (opfunc == (void *)_paravirt_ident_32)
21715 ret = paravirt_patch_ident_32(insnbuf, len);
21716- else if (opfunc == _paravirt_ident_64)
21717+ else if (opfunc == (void *)_paravirt_ident_64)
21718 ret = paravirt_patch_ident_64(insnbuf, len);
21719+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21720+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21721+ ret = paravirt_patch_ident_64(insnbuf, len);
21722+#endif
21723
21724 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21725 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21726@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21727 if (insn_len > len || start == NULL)
21728 insn_len = len;
21729 else
21730- memcpy(insnbuf, start, insn_len);
21731+ memcpy(insnbuf, ktla_ktva(start), insn_len);
21732
21733 return insn_len;
21734 }
21735@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
21736 preempt_enable();
21737 }
21738
21739-struct pv_info pv_info = {
21740+struct pv_info pv_info __read_only = {
21741 .name = "bare hardware",
21742 .paravirt_enabled = 0,
21743 .kernel_rpl = 0,
21744@@ -315,16 +322,16 @@ struct pv_info pv_info = {
21745 #endif
21746 };
21747
21748-struct pv_init_ops pv_init_ops = {
21749+struct pv_init_ops pv_init_ops __read_only = {
21750 .patch = native_patch,
21751 };
21752
21753-struct pv_time_ops pv_time_ops = {
21754+struct pv_time_ops pv_time_ops __read_only = {
21755 .sched_clock = native_sched_clock,
21756 .steal_clock = native_steal_clock,
21757 };
21758
21759-struct pv_irq_ops pv_irq_ops = {
21760+struct pv_irq_ops pv_irq_ops __read_only = {
21761 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21762 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21763 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21764@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21765 #endif
21766 };
21767
21768-struct pv_cpu_ops pv_cpu_ops = {
21769+struct pv_cpu_ops pv_cpu_ops __read_only = {
21770 .cpuid = native_cpuid,
21771 .get_debugreg = native_get_debugreg,
21772 .set_debugreg = native_set_debugreg,
21773@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21774 .end_context_switch = paravirt_nop,
21775 };
21776
21777-struct pv_apic_ops pv_apic_ops = {
21778+struct pv_apic_ops pv_apic_ops __read_only= {
21779 #ifdef CONFIG_X86_LOCAL_APIC
21780 .startup_ipi_hook = paravirt_nop,
21781 #endif
21782 };
21783
21784-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
21785+#ifdef CONFIG_X86_32
21786+#ifdef CONFIG_X86_PAE
21787+/* 64-bit pagetable entries */
21788+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
21789+#else
21790 /* 32-bit pagetable entries */
21791 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
21792+#endif
21793 #else
21794 /* 64-bit pagetable entries */
21795 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
21796 #endif
21797
21798-struct pv_mmu_ops pv_mmu_ops = {
21799+struct pv_mmu_ops pv_mmu_ops __read_only = {
21800
21801 .read_cr2 = native_read_cr2,
21802 .write_cr2 = native_write_cr2,
21803@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
21804 .make_pud = PTE_IDENT,
21805
21806 .set_pgd = native_set_pgd,
21807+ .set_pgd_batched = native_set_pgd_batched,
21808 #endif
21809 #endif /* PAGETABLE_LEVELS >= 3 */
21810
21811@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
21812 },
21813
21814 .set_fixmap = native_set_fixmap,
21815+
21816+#ifdef CONFIG_PAX_KERNEXEC
21817+ .pax_open_kernel = native_pax_open_kernel,
21818+ .pax_close_kernel = native_pax_close_kernel,
21819+#endif
21820+
21821 };
21822
21823 EXPORT_SYMBOL_GPL(pv_time_ops);
21824diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
21825index 35ccf75..7a15747 100644
21826--- a/arch/x86/kernel/pci-iommu_table.c
21827+++ b/arch/x86/kernel/pci-iommu_table.c
21828@@ -2,7 +2,7 @@
21829 #include <asm/iommu_table.h>
21830 #include <linux/string.h>
21831 #include <linux/kallsyms.h>
21832-
21833+#include <linux/sched.h>
21834
21835 #define DEBUG 1
21836
21837diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
21838index 6c483ba..d10ce2f 100644
21839--- a/arch/x86/kernel/pci-swiotlb.c
21840+++ b/arch/x86/kernel/pci-swiotlb.c
21841@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
21842 void *vaddr, dma_addr_t dma_addr,
21843 struct dma_attrs *attrs)
21844 {
21845- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
21846+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
21847 }
21848
21849 static struct dma_map_ops swiotlb_dma_ops = {
21850diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
21851index 2ed787f..f70c9f6 100644
21852--- a/arch/x86/kernel/process.c
21853+++ b/arch/x86/kernel/process.c
21854@@ -36,7 +36,8 @@
21855 * section. Since TSS's are completely CPU-local, we want them
21856 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
21857 */
21858-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
21859+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
21860+EXPORT_SYMBOL(init_tss);
21861
21862 #ifdef CONFIG_X86_64
21863 static DEFINE_PER_CPU(unsigned char, is_idle);
21864@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
21865 task_xstate_cachep =
21866 kmem_cache_create("task_xstate", xstate_size,
21867 __alignof__(union thread_xstate),
21868- SLAB_PANIC | SLAB_NOTRACK, NULL);
21869+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
21870 }
21871
21872 /*
21873@@ -105,7 +106,7 @@ void exit_thread(void)
21874 unsigned long *bp = t->io_bitmap_ptr;
21875
21876 if (bp) {
21877- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
21878+ struct tss_struct *tss = init_tss + get_cpu();
21879
21880 t->io_bitmap_ptr = NULL;
21881 clear_thread_flag(TIF_IO_BITMAP);
21882@@ -136,7 +137,7 @@ void show_regs_common(void)
21883 board = dmi_get_system_info(DMI_BOARD_NAME);
21884
21885 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
21886- current->pid, current->comm, print_tainted(),
21887+ task_pid_nr(current), current->comm, print_tainted(),
21888 init_utsname()->release,
21889 (int)strcspn(init_utsname()->version, " "),
21890 init_utsname()->version,
21891@@ -149,6 +150,9 @@ void flush_thread(void)
21892 {
21893 struct task_struct *tsk = current;
21894
21895+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
21896+ loadsegment(gs, 0);
21897+#endif
21898 flush_ptrace_hw_breakpoint(tsk);
21899 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
21900 drop_init_fpu(tsk);
21901@@ -301,7 +305,7 @@ static void __exit_idle(void)
21902 void exit_idle(void)
21903 {
21904 /* idle loop has pid 0 */
21905- if (current->pid)
21906+ if (task_pid_nr(current))
21907 return;
21908 __exit_idle();
21909 }
21910@@ -404,7 +408,7 @@ bool set_pm_idle_to_default(void)
21911
21912 return ret;
21913 }
21914-void stop_this_cpu(void *dummy)
21915+__noreturn void stop_this_cpu(void *dummy)
21916 {
21917 local_irq_disable();
21918 /*
21919@@ -632,16 +636,37 @@ static int __init idle_setup(char *str)
21920 }
21921 early_param("idle", idle_setup);
21922
21923-unsigned long arch_align_stack(unsigned long sp)
21924+#ifdef CONFIG_PAX_RANDKSTACK
21925+void pax_randomize_kstack(struct pt_regs *regs)
21926 {
21927- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
21928- sp -= get_random_int() % 8192;
21929- return sp & ~0xf;
21930-}
21931+ struct thread_struct *thread = &current->thread;
21932+ unsigned long time;
21933
21934-unsigned long arch_randomize_brk(struct mm_struct *mm)
21935-{
21936- unsigned long range_end = mm->brk + 0x02000000;
21937- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
21938-}
21939+ if (!randomize_va_space)
21940+ return;
21941+
21942+ if (v8086_mode(regs))
21943+ return;
21944
21945+ rdtscl(time);
21946+
21947+ /* P4 seems to return a 0 LSB, ignore it */
21948+#ifdef CONFIG_MPENTIUM4
21949+ time &= 0x3EUL;
21950+ time <<= 2;
21951+#elif defined(CONFIG_X86_64)
21952+ time &= 0xFUL;
21953+ time <<= 4;
21954+#else
21955+ time &= 0x1FUL;
21956+ time <<= 3;
21957+#endif
21958+
21959+ thread->sp0 ^= time;
21960+ load_sp0(init_tss + smp_processor_id(), thread);
21961+
21962+#ifdef CONFIG_X86_64
21963+ this_cpu_write(kernel_stack, thread->sp0);
21964+#endif
21965+}
21966+#endif
21967diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
21968index b5a8905..d9cacac 100644
21969--- a/arch/x86/kernel/process_32.c
21970+++ b/arch/x86/kernel/process_32.c
21971@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
21972 unsigned long thread_saved_pc(struct task_struct *tsk)
21973 {
21974 return ((unsigned long *)tsk->thread.sp)[3];
21975+//XXX return tsk->thread.eip;
21976 }
21977
21978 void __show_regs(struct pt_regs *regs, int all)
21979@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
21980 unsigned long sp;
21981 unsigned short ss, gs;
21982
21983- if (user_mode_vm(regs)) {
21984+ if (user_mode(regs)) {
21985 sp = regs->sp;
21986 ss = regs->ss & 0xffff;
21987- gs = get_user_gs(regs);
21988 } else {
21989 sp = kernel_stack_pointer(regs);
21990 savesegment(ss, ss);
21991- savesegment(gs, gs);
21992 }
21993+ gs = get_user_gs(regs);
21994
21995 show_regs_common();
21996
21997 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
21998 (u16)regs->cs, regs->ip, regs->flags,
21999- smp_processor_id());
22000+ raw_smp_processor_id());
22001 print_symbol("EIP is at %s\n", regs->ip);
22002
22003 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
22004@@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
22005 int copy_thread(unsigned long clone_flags, unsigned long sp,
22006 unsigned long arg, struct task_struct *p)
22007 {
22008- struct pt_regs *childregs = task_pt_regs(p);
22009+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
22010 struct task_struct *tsk;
22011 int err;
22012
22013 p->thread.sp = (unsigned long) childregs;
22014 p->thread.sp0 = (unsigned long) (childregs+1);
22015+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22016
22017 if (unlikely(p->flags & PF_KTHREAD)) {
22018 /* kernel thread */
22019 memset(childregs, 0, sizeof(struct pt_regs));
22020 p->thread.ip = (unsigned long) ret_from_kernel_thread;
22021- task_user_gs(p) = __KERNEL_STACK_CANARY;
22022- childregs->ds = __USER_DS;
22023- childregs->es = __USER_DS;
22024+ savesegment(gs, childregs->gs);
22025+ childregs->ds = __KERNEL_DS;
22026+ childregs->es = __KERNEL_DS;
22027 childregs->fs = __KERNEL_PERCPU;
22028 childregs->bx = sp; /* function */
22029 childregs->bp = arg;
22030@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22031 struct thread_struct *prev = &prev_p->thread,
22032 *next = &next_p->thread;
22033 int cpu = smp_processor_id();
22034- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22035+ struct tss_struct *tss = init_tss + cpu;
22036 fpu_switch_t fpu;
22037
22038 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
22039@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22040 */
22041 lazy_save_gs(prev->gs);
22042
22043+#ifdef CONFIG_PAX_MEMORY_UDEREF
22044+ __set_fs(task_thread_info(next_p)->addr_limit);
22045+#endif
22046+
22047 /*
22048 * Load the per-thread Thread-Local Storage descriptor.
22049 */
22050@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22051 */
22052 arch_end_context_switch(next_p);
22053
22054+ this_cpu_write(current_task, next_p);
22055+ this_cpu_write(current_tinfo, &next_p->tinfo);
22056+
22057 /*
22058 * Restore %gs if needed (which is common)
22059 */
22060@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22061
22062 switch_fpu_finish(next_p, fpu);
22063
22064- this_cpu_write(current_task, next_p);
22065-
22066 return prev_p;
22067 }
22068
22069@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
22070 } while (count++ < 16);
22071 return 0;
22072 }
22073-
22074diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
22075index 6e68a61..955a9a5 100644
22076--- a/arch/x86/kernel/process_64.c
22077+++ b/arch/x86/kernel/process_64.c
22078@@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
22079 struct pt_regs *childregs;
22080 struct task_struct *me = current;
22081
22082- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
22083+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
22084 childregs = task_pt_regs(p);
22085 p->thread.sp = (unsigned long) childregs;
22086 p->thread.usersp = me->thread.usersp;
22087+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22088 set_tsk_thread_flag(p, TIF_FORK);
22089 p->fpu_counter = 0;
22090 p->thread.io_bitmap_ptr = NULL;
22091@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22092 struct thread_struct *prev = &prev_p->thread;
22093 struct thread_struct *next = &next_p->thread;
22094 int cpu = smp_processor_id();
22095- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22096+ struct tss_struct *tss = init_tss + cpu;
22097 unsigned fsindex, gsindex;
22098 fpu_switch_t fpu;
22099
22100@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22101 prev->usersp = this_cpu_read(old_rsp);
22102 this_cpu_write(old_rsp, next->usersp);
22103 this_cpu_write(current_task, next_p);
22104+ this_cpu_write(current_tinfo, &next_p->tinfo);
22105
22106- this_cpu_write(kernel_stack,
22107- (unsigned long)task_stack_page(next_p) +
22108- THREAD_SIZE - KERNEL_STACK_OFFSET);
22109+ this_cpu_write(kernel_stack, next->sp0);
22110
22111 /*
22112 * Now maybe reload the debug registers and handle I/O bitmaps
22113@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
22114 if (!p || p == current || p->state == TASK_RUNNING)
22115 return 0;
22116 stack = (unsigned long)task_stack_page(p);
22117- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
22118+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
22119 return 0;
22120 fp = *(u64 *)(p->thread.sp);
22121 do {
22122- if (fp < (unsigned long)stack ||
22123- fp >= (unsigned long)stack+THREAD_SIZE)
22124+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
22125 return 0;
22126 ip = *(u64 *)(fp+8);
22127 if (!in_sched_functions(ip))
22128diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
22129index b629bbe..0fa615a 100644
22130--- a/arch/x86/kernel/ptrace.c
22131+++ b/arch/x86/kernel/ptrace.c
22132@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
22133 {
22134 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
22135 unsigned long sp = (unsigned long)&regs->sp;
22136- struct thread_info *tinfo;
22137
22138- if (context == (sp & ~(THREAD_SIZE - 1)))
22139+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
22140 return sp;
22141
22142- tinfo = (struct thread_info *)context;
22143- if (tinfo->previous_esp)
22144- return tinfo->previous_esp;
22145+ sp = *(unsigned long *)context;
22146+ if (sp)
22147+ return sp;
22148
22149 return (unsigned long)regs;
22150 }
22151@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
22152 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
22153 {
22154 int i;
22155- int dr7 = 0;
22156+ unsigned long dr7 = 0;
22157 struct arch_hw_breakpoint *info;
22158
22159 for (i = 0; i < HBP_NUM; i++) {
22160@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
22161 unsigned long addr, unsigned long data)
22162 {
22163 int ret;
22164- unsigned long __user *datap = (unsigned long __user *)data;
22165+ unsigned long __user *datap = (__force unsigned long __user *)data;
22166
22167 switch (request) {
22168 /* read the word at location addr in the USER area. */
22169@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
22170 if ((int) addr < 0)
22171 return -EIO;
22172 ret = do_get_thread_area(child, addr,
22173- (struct user_desc __user *)data);
22174+ (__force struct user_desc __user *) data);
22175 break;
22176
22177 case PTRACE_SET_THREAD_AREA:
22178 if ((int) addr < 0)
22179 return -EIO;
22180 ret = do_set_thread_area(child, addr,
22181- (struct user_desc __user *)data, 0);
22182+ (__force struct user_desc __user *) data, 0);
22183 break;
22184 #endif
22185
22186@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
22187
22188 #ifdef CONFIG_X86_64
22189
22190-static struct user_regset x86_64_regsets[] __read_mostly = {
22191+static user_regset_no_const x86_64_regsets[] __read_only = {
22192 [REGSET_GENERAL] = {
22193 .core_note_type = NT_PRSTATUS,
22194 .n = sizeof(struct user_regs_struct) / sizeof(long),
22195@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
22196 #endif /* CONFIG_X86_64 */
22197
22198 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
22199-static struct user_regset x86_32_regsets[] __read_mostly = {
22200+static user_regset_no_const x86_32_regsets[] __read_only = {
22201 [REGSET_GENERAL] = {
22202 .core_note_type = NT_PRSTATUS,
22203 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
22204@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
22205 */
22206 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
22207
22208-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22209+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22210 {
22211 #ifdef CONFIG_X86_64
22212 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
22213@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
22214 memset(info, 0, sizeof(*info));
22215 info->si_signo = SIGTRAP;
22216 info->si_code = si_code;
22217- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
22218+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
22219 }
22220
22221 void user_single_step_siginfo(struct task_struct *tsk,
22222@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
22223 # define IS_IA32 0
22224 #endif
22225
22226+#ifdef CONFIG_GRKERNSEC_SETXID
22227+extern void gr_delayed_cred_worker(void);
22228+#endif
22229+
22230 /*
22231 * We must return the syscall number to actually look up in the table.
22232 * This can be -1L to skip running any syscall at all.
22233@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
22234
22235 user_exit();
22236
22237+#ifdef CONFIG_GRKERNSEC_SETXID
22238+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22239+ gr_delayed_cred_worker();
22240+#endif
22241+
22242 /*
22243 * If we stepped into a sysenter/syscall insn, it trapped in
22244 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
22245@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
22246 */
22247 user_exit();
22248
22249+#ifdef CONFIG_GRKERNSEC_SETXID
22250+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22251+ gr_delayed_cred_worker();
22252+#endif
22253+
22254 audit_syscall_exit(regs);
22255
22256 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
22257diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
22258index 2cb9470..ff1fd80 100644
22259--- a/arch/x86/kernel/pvclock.c
22260+++ b/arch/x86/kernel/pvclock.c
22261@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
22262 return pv_tsc_khz;
22263 }
22264
22265-static atomic64_t last_value = ATOMIC64_INIT(0);
22266+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
22267
22268 void pvclock_resume(void)
22269 {
22270- atomic64_set(&last_value, 0);
22271+ atomic64_set_unchecked(&last_value, 0);
22272 }
22273
22274 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
22275@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
22276 * updating at the same time, and one of them could be slightly behind,
22277 * making the assumption that last_value always go forward fail to hold.
22278 */
22279- last = atomic64_read(&last_value);
22280+ last = atomic64_read_unchecked(&last_value);
22281 do {
22282 if (ret < last)
22283 return last;
22284- last = atomic64_cmpxchg(&last_value, last, ret);
22285+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
22286 } while (unlikely(last != ret));
22287
22288 return ret;
22289diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
22290index 76fa1e9..abf09ea 100644
22291--- a/arch/x86/kernel/reboot.c
22292+++ b/arch/x86/kernel/reboot.c
22293@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
22294 EXPORT_SYMBOL(pm_power_off);
22295
22296 static const struct desc_ptr no_idt = {};
22297-static int reboot_mode;
22298+static unsigned short reboot_mode;
22299 enum reboot_type reboot_type = BOOT_ACPI;
22300 int reboot_force;
22301
22302@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
22303
22304 void __noreturn machine_real_restart(unsigned int type)
22305 {
22306+
22307+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22308+ struct desc_struct *gdt;
22309+#endif
22310+
22311 local_irq_disable();
22312
22313 /*
22314@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
22315
22316 /* Jump to the identity-mapped low memory code */
22317 #ifdef CONFIG_X86_32
22318- asm volatile("jmpl *%0" : :
22319+
22320+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22321+ gdt = get_cpu_gdt_table(smp_processor_id());
22322+ pax_open_kernel();
22323+#ifdef CONFIG_PAX_MEMORY_UDEREF
22324+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
22325+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
22326+ loadsegment(ds, __KERNEL_DS);
22327+ loadsegment(es, __KERNEL_DS);
22328+ loadsegment(ss, __KERNEL_DS);
22329+#endif
22330+#ifdef CONFIG_PAX_KERNEXEC
22331+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
22332+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
22333+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
22334+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
22335+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
22336+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
22337+#endif
22338+ pax_close_kernel();
22339+#endif
22340+
22341+ asm volatile("ljmpl *%0" : :
22342 "rm" (real_mode_header->machine_real_restart_asm),
22343 "a" (type));
22344 #else
22345@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
22346 * try to force a triple fault and then cycle between hitting the keyboard
22347 * controller and doing that
22348 */
22349-static void native_machine_emergency_restart(void)
22350+static void __noreturn native_machine_emergency_restart(void)
22351 {
22352 int i;
22353 int attempt = 0;
22354@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
22355 #endif
22356 }
22357
22358-static void __machine_emergency_restart(int emergency)
22359+static void __noreturn __machine_emergency_restart(int emergency)
22360 {
22361 reboot_emergency = emergency;
22362 machine_ops.emergency_restart();
22363 }
22364
22365-static void native_machine_restart(char *__unused)
22366+static void __noreturn native_machine_restart(char *__unused)
22367 {
22368 pr_notice("machine restart\n");
22369
22370@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
22371 __machine_emergency_restart(0);
22372 }
22373
22374-static void native_machine_halt(void)
22375+static void __noreturn native_machine_halt(void)
22376 {
22377 /* Stop other cpus and apics */
22378 machine_shutdown();
22379@@ -679,7 +706,7 @@ static void native_machine_halt(void)
22380 stop_this_cpu(NULL);
22381 }
22382
22383-static void native_machine_power_off(void)
22384+static void __noreturn native_machine_power_off(void)
22385 {
22386 if (pm_power_off) {
22387 if (!reboot_force)
22388@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
22389 }
22390 /* A fallback in case there is no PM info available */
22391 tboot_shutdown(TB_SHUTDOWN_HALT);
22392+ unreachable();
22393 }
22394
22395-struct machine_ops machine_ops = {
22396+struct machine_ops machine_ops __read_only = {
22397 .power_off = native_machine_power_off,
22398 .shutdown = native_machine_shutdown,
22399 .emergency_restart = native_machine_emergency_restart,
22400diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
22401index 7a6f3b3..bed145d7 100644
22402--- a/arch/x86/kernel/relocate_kernel_64.S
22403+++ b/arch/x86/kernel/relocate_kernel_64.S
22404@@ -11,6 +11,7 @@
22405 #include <asm/kexec.h>
22406 #include <asm/processor-flags.h>
22407 #include <asm/pgtable_types.h>
22408+#include <asm/alternative-asm.h>
22409
22410 /*
22411 * Must be relocatable PIC code callable as a C function
22412@@ -160,13 +161,14 @@ identity_mapped:
22413 xorq %rbp, %rbp
22414 xorq %r8, %r8
22415 xorq %r9, %r9
22416- xorq %r10, %r9
22417+ xorq %r10, %r10
22418 xorq %r11, %r11
22419 xorq %r12, %r12
22420 xorq %r13, %r13
22421 xorq %r14, %r14
22422 xorq %r15, %r15
22423
22424+ pax_force_retaddr 0, 1
22425 ret
22426
22427 1:
22428diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
22429index 8b24289..d37b58b 100644
22430--- a/arch/x86/kernel/setup.c
22431+++ b/arch/x86/kernel/setup.c
22432@@ -437,7 +437,7 @@ static void __init parse_setup_data(void)
22433
22434 switch (data->type) {
22435 case SETUP_E820_EXT:
22436- parse_e820_ext(data);
22437+ parse_e820_ext((struct setup_data __force_kernel *)data);
22438 break;
22439 case SETUP_DTB:
22440 add_dtb(pa_data);
22441@@ -706,7 +706,7 @@ static void __init trim_bios_range(void)
22442 * area (640->1Mb) as ram even though it is not.
22443 * take them out.
22444 */
22445- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
22446+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
22447
22448 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
22449 }
22450@@ -830,14 +830,14 @@ void __init setup_arch(char **cmdline_p)
22451
22452 if (!boot_params.hdr.root_flags)
22453 root_mountflags &= ~MS_RDONLY;
22454- init_mm.start_code = (unsigned long) _text;
22455- init_mm.end_code = (unsigned long) _etext;
22456+ init_mm.start_code = ktla_ktva((unsigned long) _text);
22457+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
22458 init_mm.end_data = (unsigned long) _edata;
22459 init_mm.brk = _brk_end;
22460
22461- code_resource.start = virt_to_phys(_text);
22462- code_resource.end = virt_to_phys(_etext)-1;
22463- data_resource.start = virt_to_phys(_etext);
22464+ code_resource.start = virt_to_phys(ktla_ktva(_text));
22465+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
22466+ data_resource.start = virt_to_phys(_sdata);
22467 data_resource.end = virt_to_phys(_edata)-1;
22468 bss_resource.start = virt_to_phys(&__bss_start);
22469 bss_resource.end = virt_to_phys(&__bss_stop)-1;
22470diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
22471index 5cdff03..80fa283 100644
22472--- a/arch/x86/kernel/setup_percpu.c
22473+++ b/arch/x86/kernel/setup_percpu.c
22474@@ -21,19 +21,17 @@
22475 #include <asm/cpu.h>
22476 #include <asm/stackprotector.h>
22477
22478-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
22479+#ifdef CONFIG_SMP
22480+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
22481 EXPORT_PER_CPU_SYMBOL(cpu_number);
22482+#endif
22483
22484-#ifdef CONFIG_X86_64
22485 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
22486-#else
22487-#define BOOT_PERCPU_OFFSET 0
22488-#endif
22489
22490 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
22491 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
22492
22493-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
22494+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
22495 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
22496 };
22497 EXPORT_SYMBOL(__per_cpu_offset);
22498@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
22499 {
22500 #ifdef CONFIG_NEED_MULTIPLE_NODES
22501 pg_data_t *last = NULL;
22502- unsigned int cpu;
22503+ int cpu;
22504
22505 for_each_possible_cpu(cpu) {
22506 int node = early_cpu_to_node(cpu);
22507@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
22508 {
22509 #ifdef CONFIG_X86_32
22510 struct desc_struct gdt;
22511+ unsigned long base = per_cpu_offset(cpu);
22512
22513- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
22514- 0x2 | DESCTYPE_S, 0x8);
22515- gdt.s = 1;
22516+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
22517+ 0x83 | DESCTYPE_S, 0xC);
22518 write_gdt_entry(get_cpu_gdt_table(cpu),
22519 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
22520 #endif
22521@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
22522 /* alrighty, percpu areas up and running */
22523 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
22524 for_each_possible_cpu(cpu) {
22525+#ifdef CONFIG_CC_STACKPROTECTOR
22526+#ifdef CONFIG_X86_32
22527+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
22528+#endif
22529+#endif
22530 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
22531 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
22532 per_cpu(cpu_number, cpu) = cpu;
22533@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
22534 */
22535 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
22536 #endif
22537+#ifdef CONFIG_CC_STACKPROTECTOR
22538+#ifdef CONFIG_X86_32
22539+ if (!cpu)
22540+ per_cpu(stack_canary.canary, cpu) = canary;
22541+#endif
22542+#endif
22543 /*
22544 * Up to this point, the boot CPU has been using .init.data
22545 * area. Reload any changed state for the boot CPU.
22546diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
22547index d6bf1f3..3ffce5a 100644
22548--- a/arch/x86/kernel/signal.c
22549+++ b/arch/x86/kernel/signal.c
22550@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
22551 * Align the stack pointer according to the i386 ABI,
22552 * i.e. so that on function entry ((sp + 4) & 15) == 0.
22553 */
22554- sp = ((sp + 4) & -16ul) - 4;
22555+ sp = ((sp - 12) & -16ul) - 4;
22556 #else /* !CONFIG_X86_32 */
22557 sp = round_down(sp, 16) - 8;
22558 #endif
22559@@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
22560 }
22561
22562 if (current->mm->context.vdso)
22563- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22564+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22565 else
22566- restorer = &frame->retcode;
22567+ restorer = (void __user *)&frame->retcode;
22568 if (ka->sa.sa_flags & SA_RESTORER)
22569 restorer = ka->sa.sa_restorer;
22570
22571@@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
22572 * reasons and because gdb uses it as a signature to notice
22573 * signal handler stack frames.
22574 */
22575- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
22576+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
22577
22578 if (err)
22579 return -EFAULT;
22580@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
22581 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
22582
22583 /* Set up to return from userspace. */
22584- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22585+ if (current->mm->context.vdso)
22586+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22587+ else
22588+ restorer = (void __user *)&frame->retcode;
22589 if (ka->sa.sa_flags & SA_RESTORER)
22590 restorer = ka->sa.sa_restorer;
22591 put_user_ex(restorer, &frame->pretcode);
22592@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
22593 * reasons and because gdb uses it as a signature to notice
22594 * signal handler stack frames.
22595 */
22596- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
22597+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
22598 } put_user_catch(err);
22599
22600 err |= copy_siginfo_to_user(&frame->info, info);
22601diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
22602index 48d2b7d..90d328a 100644
22603--- a/arch/x86/kernel/smp.c
22604+++ b/arch/x86/kernel/smp.c
22605@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
22606
22607 __setup("nonmi_ipi", nonmi_ipi_setup);
22608
22609-struct smp_ops smp_ops = {
22610+struct smp_ops smp_ops __read_only = {
22611 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
22612 .smp_prepare_cpus = native_smp_prepare_cpus,
22613 .smp_cpus_done = native_smp_cpus_done,
22614diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
22615index ed0fe38..87fc692 100644
22616--- a/arch/x86/kernel/smpboot.c
22617+++ b/arch/x86/kernel/smpboot.c
22618@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22619 idle->thread.sp = (unsigned long) (((struct pt_regs *)
22620 (THREAD_SIZE + task_stack_page(idle))) - 1);
22621 per_cpu(current_task, cpu) = idle;
22622+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
22623
22624 #ifdef CONFIG_X86_32
22625 /* Stack for startup_32 can be just as for start_secondary onwards */
22626@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22627 #else
22628 clear_tsk_thread_flag(idle, TIF_FORK);
22629 initial_gs = per_cpu_offset(cpu);
22630- per_cpu(kernel_stack, cpu) =
22631- (unsigned long)task_stack_page(idle) -
22632- KERNEL_STACK_OFFSET + THREAD_SIZE;
22633+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
22634 #endif
22635+
22636+ pax_open_kernel();
22637 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22638+ pax_close_kernel();
22639+
22640 initial_code = (unsigned long)start_secondary;
22641 stack_start = idle->thread.sp;
22642
22643@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
22644 /* the FPU context is blank, nobody can own it */
22645 __cpu_disable_lazy_restore(cpu);
22646
22647+#ifdef CONFIG_PAX_PER_CPU_PGD
22648+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
22649+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22650+ KERNEL_PGD_PTRS);
22651+#endif
22652+
22653+ /* the FPU context is blank, nobody can own it */
22654+ __cpu_disable_lazy_restore(cpu);
22655+
22656 err = do_boot_cpu(apicid, cpu, tidle);
22657 if (err) {
22658 pr_debug("do_boot_cpu failed %d\n", err);
22659diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
22660index 9b4d51d..5d28b58 100644
22661--- a/arch/x86/kernel/step.c
22662+++ b/arch/x86/kernel/step.c
22663@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22664 struct desc_struct *desc;
22665 unsigned long base;
22666
22667- seg &= ~7UL;
22668+ seg >>= 3;
22669
22670 mutex_lock(&child->mm->context.lock);
22671- if (unlikely((seg >> 3) >= child->mm->context.size))
22672+ if (unlikely(seg >= child->mm->context.size))
22673 addr = -1L; /* bogus selector, access would fault */
22674 else {
22675 desc = child->mm->context.ldt + seg;
22676@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22677 addr += base;
22678 }
22679 mutex_unlock(&child->mm->context.lock);
22680- }
22681+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22682+ addr = ktla_ktva(addr);
22683
22684 return addr;
22685 }
22686@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22687 unsigned char opcode[15];
22688 unsigned long addr = convert_ip_to_linear(child, regs);
22689
22690+ if (addr == -EINVAL)
22691+ return 0;
22692+
22693 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22694 for (i = 0; i < copied; i++) {
22695 switch (opcode[i]) {
22696diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22697new file mode 100644
22698index 0000000..207bec6
22699--- /dev/null
22700+++ b/arch/x86/kernel/sys_i386_32.c
22701@@ -0,0 +1,250 @@
22702+/*
22703+ * This file contains various random system calls that
22704+ * have a non-standard calling sequence on the Linux/i386
22705+ * platform.
22706+ */
22707+
22708+#include <linux/errno.h>
22709+#include <linux/sched.h>
22710+#include <linux/mm.h>
22711+#include <linux/fs.h>
22712+#include <linux/smp.h>
22713+#include <linux/sem.h>
22714+#include <linux/msg.h>
22715+#include <linux/shm.h>
22716+#include <linux/stat.h>
22717+#include <linux/syscalls.h>
22718+#include <linux/mman.h>
22719+#include <linux/file.h>
22720+#include <linux/utsname.h>
22721+#include <linux/ipc.h>
22722+
22723+#include <linux/uaccess.h>
22724+#include <linux/unistd.h>
22725+
22726+#include <asm/syscalls.h>
22727+
22728+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
22729+{
22730+ unsigned long pax_task_size = TASK_SIZE;
22731+
22732+#ifdef CONFIG_PAX_SEGMEXEC
22733+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
22734+ pax_task_size = SEGMEXEC_TASK_SIZE;
22735+#endif
22736+
22737+ if (flags & MAP_FIXED)
22738+ if (len > pax_task_size || addr > pax_task_size - len)
22739+ return -EINVAL;
22740+
22741+ return 0;
22742+}
22743+
22744+unsigned long
22745+arch_get_unmapped_area(struct file *filp, unsigned long addr,
22746+ unsigned long len, unsigned long pgoff, unsigned long flags)
22747+{
22748+ struct mm_struct *mm = current->mm;
22749+ struct vm_area_struct *vma;
22750+ unsigned long start_addr, pax_task_size = TASK_SIZE;
22751+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22752+
22753+#ifdef CONFIG_PAX_SEGMEXEC
22754+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22755+ pax_task_size = SEGMEXEC_TASK_SIZE;
22756+#endif
22757+
22758+ pax_task_size -= PAGE_SIZE;
22759+
22760+ if (len > pax_task_size)
22761+ return -ENOMEM;
22762+
22763+ if (flags & MAP_FIXED)
22764+ return addr;
22765+
22766+#ifdef CONFIG_PAX_RANDMMAP
22767+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22768+#endif
22769+
22770+ if (addr) {
22771+ addr = PAGE_ALIGN(addr);
22772+ if (pax_task_size - len >= addr) {
22773+ vma = find_vma(mm, addr);
22774+ if (check_heap_stack_gap(vma, addr, len, offset))
22775+ return addr;
22776+ }
22777+ }
22778+ if (len > mm->cached_hole_size) {
22779+ start_addr = addr = mm->free_area_cache;
22780+ } else {
22781+ start_addr = addr = mm->mmap_base;
22782+ mm->cached_hole_size = 0;
22783+ }
22784+
22785+#ifdef CONFIG_PAX_PAGEEXEC
22786+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
22787+ start_addr = 0x00110000UL;
22788+
22789+#ifdef CONFIG_PAX_RANDMMAP
22790+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22791+ start_addr += mm->delta_mmap & 0x03FFF000UL;
22792+#endif
22793+
22794+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
22795+ start_addr = addr = mm->mmap_base;
22796+ else
22797+ addr = start_addr;
22798+ }
22799+#endif
22800+
22801+full_search:
22802+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22803+ /* At this point: (!vma || addr < vma->vm_end). */
22804+ if (pax_task_size - len < addr) {
22805+ /*
22806+ * Start a new search - just in case we missed
22807+ * some holes.
22808+ */
22809+ if (start_addr != mm->mmap_base) {
22810+ start_addr = addr = mm->mmap_base;
22811+ mm->cached_hole_size = 0;
22812+ goto full_search;
22813+ }
22814+ return -ENOMEM;
22815+ }
22816+ if (check_heap_stack_gap(vma, addr, len, offset))
22817+ break;
22818+ if (addr + mm->cached_hole_size < vma->vm_start)
22819+ mm->cached_hole_size = vma->vm_start - addr;
22820+ addr = vma->vm_end;
22821+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
22822+ start_addr = addr = mm->mmap_base;
22823+ mm->cached_hole_size = 0;
22824+ goto full_search;
22825+ }
22826+ }
22827+
22828+ /*
22829+ * Remember the place where we stopped the search:
22830+ */
22831+ mm->free_area_cache = addr + len;
22832+ return addr;
22833+}
22834+
22835+unsigned long
22836+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22837+ const unsigned long len, const unsigned long pgoff,
22838+ const unsigned long flags)
22839+{
22840+ struct vm_area_struct *vma;
22841+ struct mm_struct *mm = current->mm;
22842+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
22843+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22844+
22845+#ifdef CONFIG_PAX_SEGMEXEC
22846+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22847+ pax_task_size = SEGMEXEC_TASK_SIZE;
22848+#endif
22849+
22850+ pax_task_size -= PAGE_SIZE;
22851+
22852+ /* requested length too big for entire address space */
22853+ if (len > pax_task_size)
22854+ return -ENOMEM;
22855+
22856+ if (flags & MAP_FIXED)
22857+ return addr;
22858+
22859+#ifdef CONFIG_PAX_PAGEEXEC
22860+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
22861+ goto bottomup;
22862+#endif
22863+
22864+#ifdef CONFIG_PAX_RANDMMAP
22865+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22866+#endif
22867+
22868+ /* requesting a specific address */
22869+ if (addr) {
22870+ addr = PAGE_ALIGN(addr);
22871+ if (pax_task_size - len >= addr) {
22872+ vma = find_vma(mm, addr);
22873+ if (check_heap_stack_gap(vma, addr, len, offset))
22874+ return addr;
22875+ }
22876+ }
22877+
22878+ /* check if free_area_cache is useful for us */
22879+ if (len <= mm->cached_hole_size) {
22880+ mm->cached_hole_size = 0;
22881+ mm->free_area_cache = mm->mmap_base;
22882+ }
22883+
22884+ /* either no address requested or can't fit in requested address hole */
22885+ addr = mm->free_area_cache;
22886+
22887+ /* make sure it can fit in the remaining address space */
22888+ if (addr > len) {
22889+ vma = find_vma(mm, addr-len);
22890+ if (check_heap_stack_gap(vma, addr - len, len, offset))
22891+ /* remember the address as a hint for next time */
22892+ return (mm->free_area_cache = addr-len);
22893+ }
22894+
22895+ if (mm->mmap_base < len)
22896+ goto bottomup;
22897+
22898+ addr = mm->mmap_base-len;
22899+
22900+ do {
22901+ /*
22902+ * Lookup failure means no vma is above this address,
22903+ * else if new region fits below vma->vm_start,
22904+ * return with success:
22905+ */
22906+ vma = find_vma(mm, addr);
22907+ if (check_heap_stack_gap(vma, addr, len, offset))
22908+ /* remember the address as a hint for next time */
22909+ return (mm->free_area_cache = addr);
22910+
22911+ /* remember the largest hole we saw so far */
22912+ if (addr + mm->cached_hole_size < vma->vm_start)
22913+ mm->cached_hole_size = vma->vm_start - addr;
22914+
22915+ /* try just below the current vma->vm_start */
22916+ addr = skip_heap_stack_gap(vma, len, offset);
22917+ } while (!IS_ERR_VALUE(addr));
22918+
22919+bottomup:
22920+ /*
22921+ * A failed mmap() very likely causes application failure,
22922+ * so fall back to the bottom-up function here. This scenario
22923+ * can happen with large stack limits and large mmap()
22924+ * allocations.
22925+ */
22926+
22927+#ifdef CONFIG_PAX_SEGMEXEC
22928+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22929+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
22930+ else
22931+#endif
22932+
22933+ mm->mmap_base = TASK_UNMAPPED_BASE;
22934+
22935+#ifdef CONFIG_PAX_RANDMMAP
22936+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22937+ mm->mmap_base += mm->delta_mmap;
22938+#endif
22939+
22940+ mm->free_area_cache = mm->mmap_base;
22941+ mm->cached_hole_size = ~0UL;
22942+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
22943+ /*
22944+ * Restore the topdown base:
22945+ */
22946+ mm->mmap_base = base;
22947+ mm->free_area_cache = base;
22948+ mm->cached_hole_size = ~0UL;
22949+
22950+ return addr;
22951+}
22952diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
22953index 97ef74b..57a1882 100644
22954--- a/arch/x86/kernel/sys_x86_64.c
22955+++ b/arch/x86/kernel/sys_x86_64.c
22956@@ -81,8 +81,8 @@ out:
22957 return error;
22958 }
22959
22960-static void find_start_end(unsigned long flags, unsigned long *begin,
22961- unsigned long *end)
22962+static void find_start_end(struct mm_struct *mm, unsigned long flags,
22963+ unsigned long *begin, unsigned long *end)
22964 {
22965 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
22966 unsigned long new_begin;
22967@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
22968 *begin = new_begin;
22969 }
22970 } else {
22971- *begin = TASK_UNMAPPED_BASE;
22972+ *begin = mm->mmap_base;
22973 *end = TASK_SIZE;
22974 }
22975 }
22976@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
22977 struct vm_area_struct *vma;
22978 struct vm_unmapped_area_info info;
22979 unsigned long begin, end;
22980+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22981
22982 if (flags & MAP_FIXED)
22983 return addr;
22984
22985- find_start_end(flags, &begin, &end);
22986+ find_start_end(mm, flags, &begin, &end);
22987
22988 if (len > end)
22989 return -ENOMEM;
22990
22991+#ifdef CONFIG_PAX_RANDMMAP
22992+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22993+#endif
22994+
22995 if (addr) {
22996 addr = PAGE_ALIGN(addr);
22997 vma = find_vma(mm, addr);
22998- if (end - len >= addr &&
22999- (!vma || addr + len <= vma->vm_start))
23000+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23001 return addr;
23002 }
23003
23004@@ -161,6 +165,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23005 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
23006 goto bottomup;
23007
23008+#ifdef CONFIG_PAX_RANDMMAP
23009+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23010+#endif
23011+
23012 /* requesting a specific address */
23013 if (addr) {
23014 addr = PAGE_ALIGN(addr);
23015diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
23016index f84fe00..f41d9f1 100644
23017--- a/arch/x86/kernel/tboot.c
23018+++ b/arch/x86/kernel/tboot.c
23019@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
23020
23021 void tboot_shutdown(u32 shutdown_type)
23022 {
23023- void (*shutdown)(void);
23024+ void (* __noreturn shutdown)(void);
23025
23026 if (!tboot_enabled())
23027 return;
23028@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
23029
23030 switch_to_tboot_pt();
23031
23032- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
23033+ shutdown = (void *)tboot->shutdown_entry;
23034 shutdown();
23035
23036 /* should not reach here */
23037@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
23038 return 0;
23039 }
23040
23041-static atomic_t ap_wfs_count;
23042+static atomic_unchecked_t ap_wfs_count;
23043
23044 static int tboot_wait_for_aps(int num_aps)
23045 {
23046@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
23047 {
23048 switch (action) {
23049 case CPU_DYING:
23050- atomic_inc(&ap_wfs_count);
23051+ atomic_inc_unchecked(&ap_wfs_count);
23052 if (num_online_cpus() == 1)
23053- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
23054+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
23055 return NOTIFY_BAD;
23056 break;
23057 }
23058 return NOTIFY_OK;
23059 }
23060
23061-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
23062+static struct notifier_block tboot_cpu_notifier =
23063 {
23064 .notifier_call = tboot_cpu_callback,
23065 };
23066@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
23067
23068 tboot_create_trampoline();
23069
23070- atomic_set(&ap_wfs_count, 0);
23071+ atomic_set_unchecked(&ap_wfs_count, 0);
23072 register_hotcpu_notifier(&tboot_cpu_notifier);
23073
23074 acpi_os_set_prepare_sleep(&tboot_sleep);
23075diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
23076index 24d3c91..d06b473 100644
23077--- a/arch/x86/kernel/time.c
23078+++ b/arch/x86/kernel/time.c
23079@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
23080 {
23081 unsigned long pc = instruction_pointer(regs);
23082
23083- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
23084+ if (!user_mode(regs) && in_lock_functions(pc)) {
23085 #ifdef CONFIG_FRAME_POINTER
23086- return *(unsigned long *)(regs->bp + sizeof(long));
23087+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
23088 #else
23089 unsigned long *sp =
23090 (unsigned long *)kernel_stack_pointer(regs);
23091@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
23092 * or above a saved flags. Eflags has bits 22-31 zero,
23093 * kernel addresses don't.
23094 */
23095+
23096+#ifdef CONFIG_PAX_KERNEXEC
23097+ return ktla_ktva(sp[0]);
23098+#else
23099 if (sp[0] >> 22)
23100 return sp[0];
23101 if (sp[1] >> 22)
23102 return sp[1];
23103 #endif
23104+
23105+#endif
23106 }
23107 return pc;
23108 }
23109diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
23110index 9d9d2f9..cad418a 100644
23111--- a/arch/x86/kernel/tls.c
23112+++ b/arch/x86/kernel/tls.c
23113@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
23114 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
23115 return -EINVAL;
23116
23117+#ifdef CONFIG_PAX_SEGMEXEC
23118+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
23119+ return -EINVAL;
23120+#endif
23121+
23122 set_tls_desc(p, idx, &info, 1);
23123
23124 return 0;
23125@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
23126
23127 if (kbuf)
23128 info = kbuf;
23129- else if (__copy_from_user(infobuf, ubuf, count))
23130+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
23131 return -EFAULT;
23132 else
23133 info = infobuf;
23134diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
23135index ecffca1..95c4d13 100644
23136--- a/arch/x86/kernel/traps.c
23137+++ b/arch/x86/kernel/traps.c
23138@@ -68,12 +68,6 @@
23139 #include <asm/setup.h>
23140
23141 asmlinkage int system_call(void);
23142-
23143-/*
23144- * The IDT has to be page-aligned to simplify the Pentium
23145- * F0 0F bug workaround.
23146- */
23147-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
23148 #endif
23149
23150 DECLARE_BITMAP(used_vectors, NR_VECTORS);
23151@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
23152 }
23153
23154 static int __kprobes
23155-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23156+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
23157 struct pt_regs *regs, long error_code)
23158 {
23159 #ifdef CONFIG_X86_32
23160- if (regs->flags & X86_VM_MASK) {
23161+ if (v8086_mode(regs)) {
23162 /*
23163 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
23164 * On nmi (interrupt 2), do_trap should not be called.
23165@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23166 return -1;
23167 }
23168 #endif
23169- if (!user_mode(regs)) {
23170+ if (!user_mode_novm(regs)) {
23171 if (!fixup_exception(regs)) {
23172 tsk->thread.error_code = error_code;
23173 tsk->thread.trap_nr = trapnr;
23174+
23175+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23176+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
23177+ str = "PAX: suspicious stack segment fault";
23178+#endif
23179+
23180 die(str, regs, error_code);
23181 }
23182+
23183+#ifdef CONFIG_PAX_REFCOUNT
23184+ if (trapnr == 4)
23185+ pax_report_refcount_overflow(regs);
23186+#endif
23187+
23188 return 0;
23189 }
23190
23191@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23192 }
23193
23194 static void __kprobes
23195-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23196+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
23197 long error_code, siginfo_t *info)
23198 {
23199 struct task_struct *tsk = current;
23200@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23201 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
23202 printk_ratelimit()) {
23203 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
23204- tsk->comm, tsk->pid, str,
23205+ tsk->comm, task_pid_nr(tsk), str,
23206 regs->ip, regs->sp, error_code);
23207 print_vma_addr(" in ", regs->ip);
23208 pr_cont("\n");
23209@@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
23210 conditional_sti(regs);
23211
23212 #ifdef CONFIG_X86_32
23213- if (regs->flags & X86_VM_MASK) {
23214+ if (v8086_mode(regs)) {
23215 local_irq_enable();
23216 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
23217 goto exit;
23218@@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
23219 #endif
23220
23221 tsk = current;
23222- if (!user_mode(regs)) {
23223+ if (!user_mode_novm(regs)) {
23224 if (fixup_exception(regs))
23225 goto exit;
23226
23227 tsk->thread.error_code = error_code;
23228 tsk->thread.trap_nr = X86_TRAP_GP;
23229 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
23230- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
23231+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
23232+
23233+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23234+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
23235+ die("PAX: suspicious general protection fault", regs, error_code);
23236+ else
23237+#endif
23238+
23239 die("general protection fault", regs, error_code);
23240+ }
23241 goto exit;
23242 }
23243
23244+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23245+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
23246+ struct mm_struct *mm = tsk->mm;
23247+ unsigned long limit;
23248+
23249+ down_write(&mm->mmap_sem);
23250+ limit = mm->context.user_cs_limit;
23251+ if (limit < TASK_SIZE) {
23252+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
23253+ up_write(&mm->mmap_sem);
23254+ return;
23255+ }
23256+ up_write(&mm->mmap_sem);
23257+ }
23258+#endif
23259+
23260 tsk->thread.error_code = error_code;
23261 tsk->thread.trap_nr = X86_TRAP_GP;
23262
23263@@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23264 /* It's safe to allow irq's after DR6 has been saved */
23265 preempt_conditional_sti(regs);
23266
23267- if (regs->flags & X86_VM_MASK) {
23268+ if (v8086_mode(regs)) {
23269 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
23270 X86_TRAP_DB);
23271 preempt_conditional_cli(regs);
23272@@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23273 * We already checked v86 mode above, so we can check for kernel mode
23274 * by just checking the CPL of CS.
23275 */
23276- if ((dr6 & DR_STEP) && !user_mode(regs)) {
23277+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
23278 tsk->thread.debugreg6 &= ~DR_STEP;
23279 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
23280 regs->flags &= ~X86_EFLAGS_TF;
23281@@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
23282 return;
23283 conditional_sti(regs);
23284
23285- if (!user_mode_vm(regs))
23286+ if (!user_mode(regs))
23287 {
23288 if (!fixup_exception(regs)) {
23289 task->thread.error_code = error_code;
23290diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
23291index c71025b..b117501 100644
23292--- a/arch/x86/kernel/uprobes.c
23293+++ b/arch/x86/kernel/uprobes.c
23294@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
23295 int ret = NOTIFY_DONE;
23296
23297 /* We are only interested in userspace traps */
23298- if (regs && !user_mode_vm(regs))
23299+ if (regs && !user_mode(regs))
23300 return NOTIFY_DONE;
23301
23302 switch (val) {
23303diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
23304index b9242ba..50c5edd 100644
23305--- a/arch/x86/kernel/verify_cpu.S
23306+++ b/arch/x86/kernel/verify_cpu.S
23307@@ -20,6 +20,7 @@
23308 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
23309 * arch/x86/kernel/trampoline_64.S: secondary processor verification
23310 * arch/x86/kernel/head_32.S: processor startup
23311+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
23312 *
23313 * verify_cpu, returns the status of longmode and SSE in register %eax.
23314 * 0: Success 1: Failure
23315diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
23316index 1dfe69c..a3df6f6 100644
23317--- a/arch/x86/kernel/vm86_32.c
23318+++ b/arch/x86/kernel/vm86_32.c
23319@@ -43,6 +43,7 @@
23320 #include <linux/ptrace.h>
23321 #include <linux/audit.h>
23322 #include <linux/stddef.h>
23323+#include <linux/grsecurity.h>
23324
23325 #include <asm/uaccess.h>
23326 #include <asm/io.h>
23327@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
23328 do_exit(SIGSEGV);
23329 }
23330
23331- tss = &per_cpu(init_tss, get_cpu());
23332+ tss = init_tss + get_cpu();
23333 current->thread.sp0 = current->thread.saved_sp0;
23334 current->thread.sysenter_cs = __KERNEL_CS;
23335 load_sp0(tss, &current->thread);
23336@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
23337 struct task_struct *tsk;
23338 int tmp, ret = -EPERM;
23339
23340+#ifdef CONFIG_GRKERNSEC_VM86
23341+ if (!capable(CAP_SYS_RAWIO)) {
23342+ gr_handle_vm86();
23343+ goto out;
23344+ }
23345+#endif
23346+
23347 tsk = current;
23348 if (tsk->thread.saved_sp0)
23349 goto out;
23350@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
23351 int tmp, ret;
23352 struct vm86plus_struct __user *v86;
23353
23354+#ifdef CONFIG_GRKERNSEC_VM86
23355+ if (!capable(CAP_SYS_RAWIO)) {
23356+ gr_handle_vm86();
23357+ ret = -EPERM;
23358+ goto out;
23359+ }
23360+#endif
23361+
23362 tsk = current;
23363 switch (cmd) {
23364 case VM86_REQUEST_IRQ:
23365@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
23366 tsk->thread.saved_fs = info->regs32->fs;
23367 tsk->thread.saved_gs = get_user_gs(info->regs32);
23368
23369- tss = &per_cpu(init_tss, get_cpu());
23370+ tss = init_tss + get_cpu();
23371 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
23372 if (cpu_has_sep)
23373 tsk->thread.sysenter_cs = 0;
23374@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
23375 goto cannot_handle;
23376 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
23377 goto cannot_handle;
23378- intr_ptr = (unsigned long __user *) (i << 2);
23379+ intr_ptr = (__force unsigned long __user *) (i << 2);
23380 if (get_user(segoffs, intr_ptr))
23381 goto cannot_handle;
23382 if ((segoffs >> 16) == BIOSSEG)
23383diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
23384index 22a1530..8fbaaad 100644
23385--- a/arch/x86/kernel/vmlinux.lds.S
23386+++ b/arch/x86/kernel/vmlinux.lds.S
23387@@ -26,6 +26,13 @@
23388 #include <asm/page_types.h>
23389 #include <asm/cache.h>
23390 #include <asm/boot.h>
23391+#include <asm/segment.h>
23392+
23393+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23394+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
23395+#else
23396+#define __KERNEL_TEXT_OFFSET 0
23397+#endif
23398
23399 #undef i386 /* in case the preprocessor is a 32bit one */
23400
23401@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
23402
23403 PHDRS {
23404 text PT_LOAD FLAGS(5); /* R_E */
23405+#ifdef CONFIG_X86_32
23406+ module PT_LOAD FLAGS(5); /* R_E */
23407+#endif
23408+#ifdef CONFIG_XEN
23409+ rodata PT_LOAD FLAGS(5); /* R_E */
23410+#else
23411+ rodata PT_LOAD FLAGS(4); /* R__ */
23412+#endif
23413 data PT_LOAD FLAGS(6); /* RW_ */
23414-#ifdef CONFIG_X86_64
23415+ init.begin PT_LOAD FLAGS(6); /* RW_ */
23416 #ifdef CONFIG_SMP
23417 percpu PT_LOAD FLAGS(6); /* RW_ */
23418 #endif
23419+ text.init PT_LOAD FLAGS(5); /* R_E */
23420+ text.exit PT_LOAD FLAGS(5); /* R_E */
23421 init PT_LOAD FLAGS(7); /* RWE */
23422-#endif
23423 note PT_NOTE FLAGS(0); /* ___ */
23424 }
23425
23426 SECTIONS
23427 {
23428 #ifdef CONFIG_X86_32
23429- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
23430- phys_startup_32 = startup_32 - LOAD_OFFSET;
23431+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
23432 #else
23433- . = __START_KERNEL;
23434- phys_startup_64 = startup_64 - LOAD_OFFSET;
23435+ . = __START_KERNEL;
23436 #endif
23437
23438 /* Text and read-only data */
23439- .text : AT(ADDR(.text) - LOAD_OFFSET) {
23440- _text = .;
23441+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23442 /* bootstrapping code */
23443+#ifdef CONFIG_X86_32
23444+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23445+#else
23446+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23447+#endif
23448+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23449+ _text = .;
23450 HEAD_TEXT
23451 #ifdef CONFIG_X86_32
23452 . = ALIGN(PAGE_SIZE);
23453@@ -108,13 +128,48 @@ SECTIONS
23454 IRQENTRY_TEXT
23455 *(.fixup)
23456 *(.gnu.warning)
23457- /* End of text section */
23458- _etext = .;
23459 } :text = 0x9090
23460
23461- NOTES :text :note
23462+ . += __KERNEL_TEXT_OFFSET;
23463
23464- EXCEPTION_TABLE(16) :text = 0x9090
23465+#ifdef CONFIG_X86_32
23466+ . = ALIGN(PAGE_SIZE);
23467+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
23468+
23469+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
23470+ MODULES_EXEC_VADDR = .;
23471+ BYTE(0)
23472+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
23473+ . = ALIGN(HPAGE_SIZE) - 1;
23474+ MODULES_EXEC_END = .;
23475+#endif
23476+
23477+ } :module
23478+#endif
23479+
23480+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
23481+ /* End of text section */
23482+ BYTE(0)
23483+ _etext = . - __KERNEL_TEXT_OFFSET;
23484+ }
23485+
23486+#ifdef CONFIG_X86_32
23487+ . = ALIGN(PAGE_SIZE);
23488+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
23489+ *(.idt)
23490+ . = ALIGN(PAGE_SIZE);
23491+ *(.empty_zero_page)
23492+ *(.initial_pg_fixmap)
23493+ *(.initial_pg_pmd)
23494+ *(.initial_page_table)
23495+ *(.swapper_pg_dir)
23496+ } :rodata
23497+#endif
23498+
23499+ . = ALIGN(PAGE_SIZE);
23500+ NOTES :rodata :note
23501+
23502+ EXCEPTION_TABLE(16) :rodata
23503
23504 #if defined(CONFIG_DEBUG_RODATA)
23505 /* .text should occupy whole number of pages */
23506@@ -126,16 +181,20 @@ SECTIONS
23507
23508 /* Data */
23509 .data : AT(ADDR(.data) - LOAD_OFFSET) {
23510+
23511+#ifdef CONFIG_PAX_KERNEXEC
23512+ . = ALIGN(HPAGE_SIZE);
23513+#else
23514+ . = ALIGN(PAGE_SIZE);
23515+#endif
23516+
23517 /* Start of data section */
23518 _sdata = .;
23519
23520 /* init_task */
23521 INIT_TASK_DATA(THREAD_SIZE)
23522
23523-#ifdef CONFIG_X86_32
23524- /* 32 bit has nosave before _edata */
23525 NOSAVE_DATA
23526-#endif
23527
23528 PAGE_ALIGNED_DATA(PAGE_SIZE)
23529
23530@@ -176,12 +235,19 @@ SECTIONS
23531 #endif /* CONFIG_X86_64 */
23532
23533 /* Init code and data - will be freed after init */
23534- . = ALIGN(PAGE_SIZE);
23535 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
23536+ BYTE(0)
23537+
23538+#ifdef CONFIG_PAX_KERNEXEC
23539+ . = ALIGN(HPAGE_SIZE);
23540+#else
23541+ . = ALIGN(PAGE_SIZE);
23542+#endif
23543+
23544 __init_begin = .; /* paired with __init_end */
23545- }
23546+ } :init.begin
23547
23548-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
23549+#ifdef CONFIG_SMP
23550 /*
23551 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
23552 * output PHDR, so the next output section - .init.text - should
23553@@ -190,12 +256,27 @@ SECTIONS
23554 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
23555 #endif
23556
23557- INIT_TEXT_SECTION(PAGE_SIZE)
23558-#ifdef CONFIG_X86_64
23559- :init
23560-#endif
23561+ . = ALIGN(PAGE_SIZE);
23562+ init_begin = .;
23563+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
23564+ VMLINUX_SYMBOL(_sinittext) = .;
23565+ INIT_TEXT
23566+ VMLINUX_SYMBOL(_einittext) = .;
23567+ . = ALIGN(PAGE_SIZE);
23568+ } :text.init
23569
23570- INIT_DATA_SECTION(16)
23571+ /*
23572+ * .exit.text is discard at runtime, not link time, to deal with
23573+ * references from .altinstructions and .eh_frame
23574+ */
23575+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23576+ EXIT_TEXT
23577+ . = ALIGN(16);
23578+ } :text.exit
23579+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
23580+
23581+ . = ALIGN(PAGE_SIZE);
23582+ INIT_DATA_SECTION(16) :init
23583
23584 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
23585 __x86_cpu_dev_start = .;
23586@@ -257,19 +338,12 @@ SECTIONS
23587 }
23588
23589 . = ALIGN(8);
23590- /*
23591- * .exit.text is discard at runtime, not link time, to deal with
23592- * references from .altinstructions and .eh_frame
23593- */
23594- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
23595- EXIT_TEXT
23596- }
23597
23598 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
23599 EXIT_DATA
23600 }
23601
23602-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
23603+#ifndef CONFIG_SMP
23604 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
23605 #endif
23606
23607@@ -288,16 +362,10 @@ SECTIONS
23608 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
23609 __smp_locks = .;
23610 *(.smp_locks)
23611- . = ALIGN(PAGE_SIZE);
23612 __smp_locks_end = .;
23613+ . = ALIGN(PAGE_SIZE);
23614 }
23615
23616-#ifdef CONFIG_X86_64
23617- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
23618- NOSAVE_DATA
23619- }
23620-#endif
23621-
23622 /* BSS */
23623 . = ALIGN(PAGE_SIZE);
23624 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
23625@@ -313,6 +381,7 @@ SECTIONS
23626 __brk_base = .;
23627 . += 64 * 1024; /* 64k alignment slop space */
23628 *(.brk_reservation) /* areas brk users have reserved */
23629+ . = ALIGN(HPAGE_SIZE);
23630 __brk_limit = .;
23631 }
23632
23633@@ -339,13 +408,12 @@ SECTIONS
23634 * for the boot processor.
23635 */
23636 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
23637-INIT_PER_CPU(gdt_page);
23638 INIT_PER_CPU(irq_stack_union);
23639
23640 /*
23641 * Build-time check on the image size:
23642 */
23643-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
23644+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
23645 "kernel image bigger than KERNEL_IMAGE_SIZE");
23646
23647 #ifdef CONFIG_SMP
23648diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
23649index 9a907a6..f83f921 100644
23650--- a/arch/x86/kernel/vsyscall_64.c
23651+++ b/arch/x86/kernel/vsyscall_64.c
23652@@ -56,15 +56,13 @@
23653 DEFINE_VVAR(int, vgetcpu_mode);
23654 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
23655
23656-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
23657+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
23658
23659 static int __init vsyscall_setup(char *str)
23660 {
23661 if (str) {
23662 if (!strcmp("emulate", str))
23663 vsyscall_mode = EMULATE;
23664- else if (!strcmp("native", str))
23665- vsyscall_mode = NATIVE;
23666 else if (!strcmp("none", str))
23667 vsyscall_mode = NONE;
23668 else
23669@@ -323,8 +321,7 @@ do_ret:
23670 return true;
23671
23672 sigsegv:
23673- force_sig(SIGSEGV, current);
23674- return true;
23675+ do_group_exit(SIGKILL);
23676 }
23677
23678 /*
23679@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23680 extern char __vvar_page;
23681 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23682
23683- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23684- vsyscall_mode == NATIVE
23685- ? PAGE_KERNEL_VSYSCALL
23686- : PAGE_KERNEL_VVAR);
23687+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23688 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23689 (unsigned long)VSYSCALL_START);
23690
23691diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23692index 1330dd1..d220b99 100644
23693--- a/arch/x86/kernel/x8664_ksyms_64.c
23694+++ b/arch/x86/kernel/x8664_ksyms_64.c
23695@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23696 EXPORT_SYMBOL(copy_user_generic_unrolled);
23697 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23698 EXPORT_SYMBOL(__copy_user_nocache);
23699-EXPORT_SYMBOL(_copy_from_user);
23700-EXPORT_SYMBOL(_copy_to_user);
23701
23702 EXPORT_SYMBOL(copy_page);
23703 EXPORT_SYMBOL(clear_page);
23704diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23705index 7a3d075..6cb373d 100644
23706--- a/arch/x86/kernel/x86_init.c
23707+++ b/arch/x86/kernel/x86_init.c
23708@@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
23709 },
23710 };
23711
23712-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23713+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23714 .early_percpu_clock_init = x86_init_noop,
23715 .setup_percpu_clockev = setup_secondary_APIC_clock,
23716 };
23717@@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23718 static void default_nmi_init(void) { };
23719 static int default_i8042_detect(void) { return 1; };
23720
23721-struct x86_platform_ops x86_platform = {
23722+struct x86_platform_ops x86_platform __read_only = {
23723 .calibrate_tsc = native_calibrate_tsc,
23724 .get_wallclock = mach_get_cmos_time,
23725 .set_wallclock = mach_set_rtc_mmss,
23726@@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
23727 };
23728
23729 EXPORT_SYMBOL_GPL(x86_platform);
23730-struct x86_msi_ops x86_msi = {
23731+struct x86_msi_ops x86_msi __read_only = {
23732 .setup_msi_irqs = native_setup_msi_irqs,
23733 .teardown_msi_irq = native_teardown_msi_irq,
23734 .teardown_msi_irqs = default_teardown_msi_irqs,
23735 .restore_msi_irqs = default_restore_msi_irqs,
23736 };
23737
23738-struct x86_io_apic_ops x86_io_apic_ops = {
23739+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23740 .init = native_io_apic_init_mappings,
23741 .read = native_io_apic_read,
23742 .write = native_io_apic_write,
23743diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23744index ada87a3..afea76d 100644
23745--- a/arch/x86/kernel/xsave.c
23746+++ b/arch/x86/kernel/xsave.c
23747@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23748 {
23749 int err;
23750
23751+ buf = (struct xsave_struct __user *)____m(buf);
23752 if (use_xsave())
23753 err = xsave_user(buf);
23754 else if (use_fxsr())
23755@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
23756 */
23757 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
23758 {
23759+ buf = (void __user *)____m(buf);
23760 if (use_xsave()) {
23761 if ((unsigned long)buf % 64 || fx_only) {
23762 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
23763diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
23764index a20ecb5..d0e2194 100644
23765--- a/arch/x86/kvm/cpuid.c
23766+++ b/arch/x86/kvm/cpuid.c
23767@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
23768 struct kvm_cpuid2 *cpuid,
23769 struct kvm_cpuid_entry2 __user *entries)
23770 {
23771- int r;
23772+ int r, i;
23773
23774 r = -E2BIG;
23775 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
23776 goto out;
23777 r = -EFAULT;
23778- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
23779- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23780+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23781 goto out;
23782+ for (i = 0; i < cpuid->nent; ++i) {
23783+ struct kvm_cpuid_entry2 cpuid_entry;
23784+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
23785+ goto out;
23786+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
23787+ }
23788 vcpu->arch.cpuid_nent = cpuid->nent;
23789 kvm_apic_set_version(vcpu);
23790 kvm_x86_ops->cpuid_update(vcpu);
23791@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
23792 struct kvm_cpuid2 *cpuid,
23793 struct kvm_cpuid_entry2 __user *entries)
23794 {
23795- int r;
23796+ int r, i;
23797
23798 r = -E2BIG;
23799 if (cpuid->nent < vcpu->arch.cpuid_nent)
23800 goto out;
23801 r = -EFAULT;
23802- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
23803- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23804+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23805 goto out;
23806+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
23807+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
23808+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
23809+ goto out;
23810+ }
23811 return 0;
23812
23813 out:
23814diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
23815index a27e763..54bfe43 100644
23816--- a/arch/x86/kvm/emulate.c
23817+++ b/arch/x86/kvm/emulate.c
23818@@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23819
23820 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
23821 do { \
23822+ unsigned long _tmp; \
23823 __asm__ __volatile__ ( \
23824 _PRE_EFLAGS("0", "4", "2") \
23825 _op _suffix " %"_x"3,%1; " \
23826@@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23827 /* Raw emulation: instruction has two explicit operands. */
23828 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
23829 do { \
23830- unsigned long _tmp; \
23831- \
23832 switch ((ctxt)->dst.bytes) { \
23833 case 2: \
23834 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
23835@@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23836
23837 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
23838 do { \
23839- unsigned long _tmp; \
23840 switch ((ctxt)->dst.bytes) { \
23841 case 1: \
23842 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
23843diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
23844index 9392f52..0e56d77 100644
23845--- a/arch/x86/kvm/lapic.c
23846+++ b/arch/x86/kvm/lapic.c
23847@@ -55,7 +55,7 @@
23848 #define APIC_BUS_CYCLE_NS 1
23849
23850 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
23851-#define apic_debug(fmt, arg...)
23852+#define apic_debug(fmt, arg...) do {} while (0)
23853
23854 #define APIC_LVT_NUM 6
23855 /* 14 is the version for Xeon and Pentium 8.4.8*/
23856diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
23857index 891eb6d..e027900 100644
23858--- a/arch/x86/kvm/paging_tmpl.h
23859+++ b/arch/x86/kvm/paging_tmpl.h
23860@@ -208,7 +208,7 @@ retry_walk:
23861 if (unlikely(kvm_is_error_hva(host_addr)))
23862 goto error;
23863
23864- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
23865+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
23866 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
23867 goto error;
23868 walker->ptep_user[walker->level - 1] = ptep_user;
23869diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
23870index d29d3cd..ec9d522 100644
23871--- a/arch/x86/kvm/svm.c
23872+++ b/arch/x86/kvm/svm.c
23873@@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
23874 int cpu = raw_smp_processor_id();
23875
23876 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
23877+
23878+ pax_open_kernel();
23879 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
23880+ pax_close_kernel();
23881+
23882 load_TR_desc();
23883 }
23884
23885@@ -3881,6 +3885,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
23886 #endif
23887 #endif
23888
23889+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23890+ __set_fs(current_thread_info()->addr_limit);
23891+#endif
23892+
23893 reload_tss(vcpu);
23894
23895 local_irq_disable();
23896diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
23897index 9120ae1..238abc0 100644
23898--- a/arch/x86/kvm/vmx.c
23899+++ b/arch/x86/kvm/vmx.c
23900@@ -1370,7 +1370,11 @@ static void reload_tss(void)
23901 struct desc_struct *descs;
23902
23903 descs = (void *)gdt->address;
23904+
23905+ pax_open_kernel();
23906 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
23907+ pax_close_kernel();
23908+
23909 load_TR_desc();
23910 }
23911
23912@@ -1594,6 +1598,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
23913 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
23914 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
23915
23916+#ifdef CONFIG_PAX_PER_CPU_PGD
23917+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23918+#endif
23919+
23920 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
23921 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
23922 vmx->loaded_vmcs->cpu = cpu;
23923@@ -2738,8 +2746,11 @@ static __init int hardware_setup(void)
23924 if (!cpu_has_vmx_flexpriority())
23925 flexpriority_enabled = 0;
23926
23927- if (!cpu_has_vmx_tpr_shadow())
23928- kvm_x86_ops->update_cr8_intercept = NULL;
23929+ if (!cpu_has_vmx_tpr_shadow()) {
23930+ pax_open_kernel();
23931+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
23932+ pax_close_kernel();
23933+ }
23934
23935 if (enable_ept && !cpu_has_vmx_ept_2m_page())
23936 kvm_disable_largepages();
23937@@ -3782,7 +3793,10 @@ static void vmx_set_constant_host_state(void)
23938
23939 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
23940 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
23941+
23942+#ifndef CONFIG_PAX_PER_CPU_PGD
23943 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23944+#endif
23945
23946 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
23947 #ifdef CONFIG_X86_64
23948@@ -3803,7 +3817,7 @@ static void vmx_set_constant_host_state(void)
23949 native_store_idt(&dt);
23950 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
23951
23952- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
23953+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
23954
23955 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
23956 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
23957@@ -6355,6 +6369,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23958 "jmp 2f \n\t"
23959 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
23960 "2: "
23961+
23962+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23963+ "ljmp %[cs],$3f\n\t"
23964+ "3: "
23965+#endif
23966+
23967 /* Save guest registers, load host registers, keep flags */
23968 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
23969 "pop %0 \n\t"
23970@@ -6407,6 +6427,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23971 #endif
23972 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
23973 [wordsize]"i"(sizeof(ulong))
23974+
23975+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23976+ ,[cs]"i"(__KERNEL_CS)
23977+#endif
23978+
23979 : "cc", "memory"
23980 #ifdef CONFIG_X86_64
23981 , "rax", "rbx", "rdi", "rsi"
23982@@ -6420,7 +6445,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23983 if (debugctlmsr)
23984 update_debugctlmsr(debugctlmsr);
23985
23986-#ifndef CONFIG_X86_64
23987+#ifdef CONFIG_X86_32
23988 /*
23989 * The sysexit path does not restore ds/es, so we must set them to
23990 * a reasonable value ourselves.
23991@@ -6429,8 +6454,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23992 * may be executed in interrupt context, which saves and restore segments
23993 * around it, nullifying its effect.
23994 */
23995- loadsegment(ds, __USER_DS);
23996- loadsegment(es, __USER_DS);
23997+ loadsegment(ds, __KERNEL_DS);
23998+ loadsegment(es, __KERNEL_DS);
23999+ loadsegment(ss, __KERNEL_DS);
24000+
24001+#ifdef CONFIG_PAX_KERNEXEC
24002+ loadsegment(fs, __KERNEL_PERCPU);
24003+#endif
24004+
24005+#ifdef CONFIG_PAX_MEMORY_UDEREF
24006+ __set_fs(current_thread_info()->addr_limit);
24007+#endif
24008+
24009 #endif
24010
24011 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
24012diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
24013index c243b81..b692af3 100644
24014--- a/arch/x86/kvm/x86.c
24015+++ b/arch/x86/kvm/x86.c
24016@@ -1408,10 +1408,9 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
24017 unsigned long flags, this_tsc_khz;
24018 struct kvm_vcpu_arch *vcpu = &v->arch;
24019 struct kvm_arch *ka = &v->kvm->arch;
24020- void *shared_kaddr;
24021 s64 kernel_ns, max_kernel_ns;
24022 u64 tsc_timestamp, host_tsc;
24023- struct pvclock_vcpu_time_info *guest_hv_clock;
24024+ struct pvclock_vcpu_time_info guest_hv_clock;
24025 u8 pvclock_flags;
24026 bool use_master_clock;
24027
24028@@ -1465,7 +1464,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
24029
24030 local_irq_restore(flags);
24031
24032- if (!vcpu->time_page)
24033+ if (!vcpu->pv_time_enabled)
24034 return 0;
24035
24036 /*
24037@@ -1527,12 +1526,12 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
24038 */
24039 vcpu->hv_clock.version += 2;
24040
24041- shared_kaddr = kmap_atomic(vcpu->time_page);
24042-
24043- guest_hv_clock = shared_kaddr + vcpu->time_offset;
24044+ if (unlikely(kvm_read_guest_cached(v->kvm, &vcpu->pv_time,
24045+ &guest_hv_clock, sizeof(guest_hv_clock))))
24046+ return 0;
24047
24048 /* retain PVCLOCK_GUEST_STOPPED if set in guest copy */
24049- pvclock_flags = (guest_hv_clock->flags & PVCLOCK_GUEST_STOPPED);
24050+ pvclock_flags = (guest_hv_clock.flags & PVCLOCK_GUEST_STOPPED);
24051
24052 if (vcpu->pvclock_set_guest_stopped_request) {
24053 pvclock_flags |= PVCLOCK_GUEST_STOPPED;
24054@@ -1545,12 +1544,9 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
24055
24056 vcpu->hv_clock.flags = pvclock_flags;
24057
24058- memcpy(shared_kaddr + vcpu->time_offset, &vcpu->hv_clock,
24059- sizeof(vcpu->hv_clock));
24060-
24061- kunmap_atomic(shared_kaddr);
24062-
24063- mark_page_dirty(v->kvm, vcpu->time >> PAGE_SHIFT);
24064+ kvm_write_guest_cached(v->kvm, &vcpu->pv_time,
24065+ &vcpu->hv_clock,
24066+ sizeof(vcpu->hv_clock));
24067 return 0;
24068 }
24069
24070@@ -1692,8 +1688,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
24071 {
24072 struct kvm *kvm = vcpu->kvm;
24073 int lm = is_long_mode(vcpu);
24074- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24075- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24076+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24077+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24078 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
24079 : kvm->arch.xen_hvm_config.blob_size_32;
24080 u32 page_num = data & ~PAGE_MASK;
24081@@ -1839,10 +1835,7 @@ static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
24082
24083 static void kvmclock_reset(struct kvm_vcpu *vcpu)
24084 {
24085- if (vcpu->arch.time_page) {
24086- kvm_release_page_dirty(vcpu->arch.time_page);
24087- vcpu->arch.time_page = NULL;
24088- }
24089+ vcpu->arch.pv_time_enabled = false;
24090 }
24091
24092 static void accumulate_steal_time(struct kvm_vcpu *vcpu)
24093@@ -1948,6 +1941,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
24094 break;
24095 case MSR_KVM_SYSTEM_TIME_NEW:
24096 case MSR_KVM_SYSTEM_TIME: {
24097+ u64 gpa_offset;
24098 kvmclock_reset(vcpu);
24099
24100 vcpu->arch.time = data;
24101@@ -1957,14 +1951,17 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
24102 if (!(data & 1))
24103 break;
24104
24105- /* ...but clean it before doing the actual write */
24106- vcpu->arch.time_offset = data & ~(PAGE_MASK | 1);
24107+ gpa_offset = data & ~(PAGE_MASK | 1);
24108
24109- vcpu->arch.time_page =
24110- gfn_to_page(vcpu->kvm, data >> PAGE_SHIFT);
24111+ /* Check that the address is 32-byte aligned. */
24112+ if (gpa_offset & (sizeof(struct pvclock_vcpu_time_info) - 1))
24113+ break;
24114
24115- if (is_error_page(vcpu->arch.time_page))
24116- vcpu->arch.time_page = NULL;
24117+ if (kvm_gfn_to_hva_cache_init(vcpu->kvm,
24118+ &vcpu->arch.pv_time, data & ~1ULL))
24119+ vcpu->arch.pv_time_enabled = false;
24120+ else
24121+ vcpu->arch.pv_time_enabled = true;
24122
24123 break;
24124 }
24125@@ -2571,6 +2568,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
24126 if (n < msr_list.nmsrs)
24127 goto out;
24128 r = -EFAULT;
24129+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
24130+ goto out;
24131 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
24132 num_msrs_to_save * sizeof(u32)))
24133 goto out;
24134@@ -2700,7 +2699,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
24135 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
24136 struct kvm_interrupt *irq)
24137 {
24138- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
24139+ if (irq->irq >= KVM_NR_INTERRUPTS)
24140 return -EINVAL;
24141 if (irqchip_in_kernel(vcpu->kvm))
24142 return -ENXIO;
24143@@ -2967,7 +2966,7 @@ static int kvm_vcpu_ioctl_x86_set_xcrs(struct kvm_vcpu *vcpu,
24144 */
24145 static int kvm_set_guest_paused(struct kvm_vcpu *vcpu)
24146 {
24147- if (!vcpu->arch.time_page)
24148+ if (!vcpu->arch.pv_time_enabled)
24149 return -EINVAL;
24150 vcpu->arch.pvclock_set_guest_stopped_request = true;
24151 kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu);
24152@@ -5213,7 +5212,7 @@ static struct notifier_block pvclock_gtod_notifier = {
24153 };
24154 #endif
24155
24156-int kvm_arch_init(void *opaque)
24157+int kvm_arch_init(const void *opaque)
24158 {
24159 int r;
24160 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
24161@@ -6661,6 +6660,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
24162 goto fail_free_wbinvd_dirty_mask;
24163
24164 vcpu->arch.ia32_tsc_adjust_msr = 0x0;
24165+ vcpu->arch.pv_time_enabled = false;
24166 kvm_async_pf_hash_reset(vcpu);
24167 kvm_pmu_init(vcpu);
24168
24169diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
24170index df4176c..23ce092 100644
24171--- a/arch/x86/lguest/boot.c
24172+++ b/arch/x86/lguest/boot.c
24173@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
24174 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
24175 * Launcher to reboot us.
24176 */
24177-static void lguest_restart(char *reason)
24178+static __noreturn void lguest_restart(char *reason)
24179 {
24180 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
24181+ BUG();
24182 }
24183
24184 /*G:050
24185diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
24186index 00933d5..3a64af9 100644
24187--- a/arch/x86/lib/atomic64_386_32.S
24188+++ b/arch/x86/lib/atomic64_386_32.S
24189@@ -48,6 +48,10 @@ BEGIN(read)
24190 movl (v), %eax
24191 movl 4(v), %edx
24192 RET_ENDP
24193+BEGIN(read_unchecked)
24194+ movl (v), %eax
24195+ movl 4(v), %edx
24196+RET_ENDP
24197 #undef v
24198
24199 #define v %esi
24200@@ -55,6 +59,10 @@ BEGIN(set)
24201 movl %ebx, (v)
24202 movl %ecx, 4(v)
24203 RET_ENDP
24204+BEGIN(set_unchecked)
24205+ movl %ebx, (v)
24206+ movl %ecx, 4(v)
24207+RET_ENDP
24208 #undef v
24209
24210 #define v %esi
24211@@ -70,6 +78,20 @@ RET_ENDP
24212 BEGIN(add)
24213 addl %eax, (v)
24214 adcl %edx, 4(v)
24215+
24216+#ifdef CONFIG_PAX_REFCOUNT
24217+ jno 0f
24218+ subl %eax, (v)
24219+ sbbl %edx, 4(v)
24220+ int $4
24221+0:
24222+ _ASM_EXTABLE(0b, 0b)
24223+#endif
24224+
24225+RET_ENDP
24226+BEGIN(add_unchecked)
24227+ addl %eax, (v)
24228+ adcl %edx, 4(v)
24229 RET_ENDP
24230 #undef v
24231
24232@@ -77,6 +99,24 @@ RET_ENDP
24233 BEGIN(add_return)
24234 addl (v), %eax
24235 adcl 4(v), %edx
24236+
24237+#ifdef CONFIG_PAX_REFCOUNT
24238+ into
24239+1234:
24240+ _ASM_EXTABLE(1234b, 2f)
24241+#endif
24242+
24243+ movl %eax, (v)
24244+ movl %edx, 4(v)
24245+
24246+#ifdef CONFIG_PAX_REFCOUNT
24247+2:
24248+#endif
24249+
24250+RET_ENDP
24251+BEGIN(add_return_unchecked)
24252+ addl (v), %eax
24253+ adcl 4(v), %edx
24254 movl %eax, (v)
24255 movl %edx, 4(v)
24256 RET_ENDP
24257@@ -86,6 +126,20 @@ RET_ENDP
24258 BEGIN(sub)
24259 subl %eax, (v)
24260 sbbl %edx, 4(v)
24261+
24262+#ifdef CONFIG_PAX_REFCOUNT
24263+ jno 0f
24264+ addl %eax, (v)
24265+ adcl %edx, 4(v)
24266+ int $4
24267+0:
24268+ _ASM_EXTABLE(0b, 0b)
24269+#endif
24270+
24271+RET_ENDP
24272+BEGIN(sub_unchecked)
24273+ subl %eax, (v)
24274+ sbbl %edx, 4(v)
24275 RET_ENDP
24276 #undef v
24277
24278@@ -96,6 +150,27 @@ BEGIN(sub_return)
24279 sbbl $0, %edx
24280 addl (v), %eax
24281 adcl 4(v), %edx
24282+
24283+#ifdef CONFIG_PAX_REFCOUNT
24284+ into
24285+1234:
24286+ _ASM_EXTABLE(1234b, 2f)
24287+#endif
24288+
24289+ movl %eax, (v)
24290+ movl %edx, 4(v)
24291+
24292+#ifdef CONFIG_PAX_REFCOUNT
24293+2:
24294+#endif
24295+
24296+RET_ENDP
24297+BEGIN(sub_return_unchecked)
24298+ negl %edx
24299+ negl %eax
24300+ sbbl $0, %edx
24301+ addl (v), %eax
24302+ adcl 4(v), %edx
24303 movl %eax, (v)
24304 movl %edx, 4(v)
24305 RET_ENDP
24306@@ -105,6 +180,20 @@ RET_ENDP
24307 BEGIN(inc)
24308 addl $1, (v)
24309 adcl $0, 4(v)
24310+
24311+#ifdef CONFIG_PAX_REFCOUNT
24312+ jno 0f
24313+ subl $1, (v)
24314+ sbbl $0, 4(v)
24315+ int $4
24316+0:
24317+ _ASM_EXTABLE(0b, 0b)
24318+#endif
24319+
24320+RET_ENDP
24321+BEGIN(inc_unchecked)
24322+ addl $1, (v)
24323+ adcl $0, 4(v)
24324 RET_ENDP
24325 #undef v
24326
24327@@ -114,6 +203,26 @@ BEGIN(inc_return)
24328 movl 4(v), %edx
24329 addl $1, %eax
24330 adcl $0, %edx
24331+
24332+#ifdef CONFIG_PAX_REFCOUNT
24333+ into
24334+1234:
24335+ _ASM_EXTABLE(1234b, 2f)
24336+#endif
24337+
24338+ movl %eax, (v)
24339+ movl %edx, 4(v)
24340+
24341+#ifdef CONFIG_PAX_REFCOUNT
24342+2:
24343+#endif
24344+
24345+RET_ENDP
24346+BEGIN(inc_return_unchecked)
24347+ movl (v), %eax
24348+ movl 4(v), %edx
24349+ addl $1, %eax
24350+ adcl $0, %edx
24351 movl %eax, (v)
24352 movl %edx, 4(v)
24353 RET_ENDP
24354@@ -123,6 +232,20 @@ RET_ENDP
24355 BEGIN(dec)
24356 subl $1, (v)
24357 sbbl $0, 4(v)
24358+
24359+#ifdef CONFIG_PAX_REFCOUNT
24360+ jno 0f
24361+ addl $1, (v)
24362+ adcl $0, 4(v)
24363+ int $4
24364+0:
24365+ _ASM_EXTABLE(0b, 0b)
24366+#endif
24367+
24368+RET_ENDP
24369+BEGIN(dec_unchecked)
24370+ subl $1, (v)
24371+ sbbl $0, 4(v)
24372 RET_ENDP
24373 #undef v
24374
24375@@ -132,6 +255,26 @@ BEGIN(dec_return)
24376 movl 4(v), %edx
24377 subl $1, %eax
24378 sbbl $0, %edx
24379+
24380+#ifdef CONFIG_PAX_REFCOUNT
24381+ into
24382+1234:
24383+ _ASM_EXTABLE(1234b, 2f)
24384+#endif
24385+
24386+ movl %eax, (v)
24387+ movl %edx, 4(v)
24388+
24389+#ifdef CONFIG_PAX_REFCOUNT
24390+2:
24391+#endif
24392+
24393+RET_ENDP
24394+BEGIN(dec_return_unchecked)
24395+ movl (v), %eax
24396+ movl 4(v), %edx
24397+ subl $1, %eax
24398+ sbbl $0, %edx
24399 movl %eax, (v)
24400 movl %edx, 4(v)
24401 RET_ENDP
24402@@ -143,6 +286,13 @@ BEGIN(add_unless)
24403 adcl %edx, %edi
24404 addl (v), %eax
24405 adcl 4(v), %edx
24406+
24407+#ifdef CONFIG_PAX_REFCOUNT
24408+ into
24409+1234:
24410+ _ASM_EXTABLE(1234b, 2f)
24411+#endif
24412+
24413 cmpl %eax, %ecx
24414 je 3f
24415 1:
24416@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
24417 1:
24418 addl $1, %eax
24419 adcl $0, %edx
24420+
24421+#ifdef CONFIG_PAX_REFCOUNT
24422+ into
24423+1234:
24424+ _ASM_EXTABLE(1234b, 2f)
24425+#endif
24426+
24427 movl %eax, (v)
24428 movl %edx, 4(v)
24429 movl $1, %eax
24430@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
24431 movl 4(v), %edx
24432 subl $1, %eax
24433 sbbl $0, %edx
24434+
24435+#ifdef CONFIG_PAX_REFCOUNT
24436+ into
24437+1234:
24438+ _ASM_EXTABLE(1234b, 1f)
24439+#endif
24440+
24441 js 1f
24442 movl %eax, (v)
24443 movl %edx, 4(v)
24444diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
24445index f5cc9eb..51fa319 100644
24446--- a/arch/x86/lib/atomic64_cx8_32.S
24447+++ b/arch/x86/lib/atomic64_cx8_32.S
24448@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
24449 CFI_STARTPROC
24450
24451 read64 %ecx
24452+ pax_force_retaddr
24453 ret
24454 CFI_ENDPROC
24455 ENDPROC(atomic64_read_cx8)
24456
24457+ENTRY(atomic64_read_unchecked_cx8)
24458+ CFI_STARTPROC
24459+
24460+ read64 %ecx
24461+ pax_force_retaddr
24462+ ret
24463+ CFI_ENDPROC
24464+ENDPROC(atomic64_read_unchecked_cx8)
24465+
24466 ENTRY(atomic64_set_cx8)
24467 CFI_STARTPROC
24468
24469@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
24470 cmpxchg8b (%esi)
24471 jne 1b
24472
24473+ pax_force_retaddr
24474 ret
24475 CFI_ENDPROC
24476 ENDPROC(atomic64_set_cx8)
24477
24478+ENTRY(atomic64_set_unchecked_cx8)
24479+ CFI_STARTPROC
24480+
24481+1:
24482+/* we don't need LOCK_PREFIX since aligned 64-bit writes
24483+ * are atomic on 586 and newer */
24484+ cmpxchg8b (%esi)
24485+ jne 1b
24486+
24487+ pax_force_retaddr
24488+ ret
24489+ CFI_ENDPROC
24490+ENDPROC(atomic64_set_unchecked_cx8)
24491+
24492 ENTRY(atomic64_xchg_cx8)
24493 CFI_STARTPROC
24494
24495@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
24496 cmpxchg8b (%esi)
24497 jne 1b
24498
24499+ pax_force_retaddr
24500 ret
24501 CFI_ENDPROC
24502 ENDPROC(atomic64_xchg_cx8)
24503
24504-.macro addsub_return func ins insc
24505-ENTRY(atomic64_\func\()_return_cx8)
24506+.macro addsub_return func ins insc unchecked=""
24507+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24508 CFI_STARTPROC
24509 SAVE ebp
24510 SAVE ebx
24511@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
24512 movl %edx, %ecx
24513 \ins\()l %esi, %ebx
24514 \insc\()l %edi, %ecx
24515+
24516+.ifb \unchecked
24517+#ifdef CONFIG_PAX_REFCOUNT
24518+ into
24519+2:
24520+ _ASM_EXTABLE(2b, 3f)
24521+#endif
24522+.endif
24523+
24524 LOCK_PREFIX
24525 cmpxchg8b (%ebp)
24526 jne 1b
24527-
24528-10:
24529 movl %ebx, %eax
24530 movl %ecx, %edx
24531+
24532+.ifb \unchecked
24533+#ifdef CONFIG_PAX_REFCOUNT
24534+3:
24535+#endif
24536+.endif
24537+
24538 RESTORE edi
24539 RESTORE esi
24540 RESTORE ebx
24541 RESTORE ebp
24542+ pax_force_retaddr
24543 ret
24544 CFI_ENDPROC
24545-ENDPROC(atomic64_\func\()_return_cx8)
24546+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24547 .endm
24548
24549 addsub_return add add adc
24550 addsub_return sub sub sbb
24551+addsub_return add add adc _unchecked
24552+addsub_return sub sub sbb _unchecked
24553
24554-.macro incdec_return func ins insc
24555-ENTRY(atomic64_\func\()_return_cx8)
24556+.macro incdec_return func ins insc unchecked=""
24557+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24558 CFI_STARTPROC
24559 SAVE ebx
24560
24561@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
24562 movl %edx, %ecx
24563 \ins\()l $1, %ebx
24564 \insc\()l $0, %ecx
24565+
24566+.ifb \unchecked
24567+#ifdef CONFIG_PAX_REFCOUNT
24568+ into
24569+2:
24570+ _ASM_EXTABLE(2b, 3f)
24571+#endif
24572+.endif
24573+
24574 LOCK_PREFIX
24575 cmpxchg8b (%esi)
24576 jne 1b
24577
24578-10:
24579 movl %ebx, %eax
24580 movl %ecx, %edx
24581+
24582+.ifb \unchecked
24583+#ifdef CONFIG_PAX_REFCOUNT
24584+3:
24585+#endif
24586+.endif
24587+
24588 RESTORE ebx
24589+ pax_force_retaddr
24590 ret
24591 CFI_ENDPROC
24592-ENDPROC(atomic64_\func\()_return_cx8)
24593+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24594 .endm
24595
24596 incdec_return inc add adc
24597 incdec_return dec sub sbb
24598+incdec_return inc add adc _unchecked
24599+incdec_return dec sub sbb _unchecked
24600
24601 ENTRY(atomic64_dec_if_positive_cx8)
24602 CFI_STARTPROC
24603@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
24604 movl %edx, %ecx
24605 subl $1, %ebx
24606 sbb $0, %ecx
24607+
24608+#ifdef CONFIG_PAX_REFCOUNT
24609+ into
24610+1234:
24611+ _ASM_EXTABLE(1234b, 2f)
24612+#endif
24613+
24614 js 2f
24615 LOCK_PREFIX
24616 cmpxchg8b (%esi)
24617@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
24618 movl %ebx, %eax
24619 movl %ecx, %edx
24620 RESTORE ebx
24621+ pax_force_retaddr
24622 ret
24623 CFI_ENDPROC
24624 ENDPROC(atomic64_dec_if_positive_cx8)
24625@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
24626 movl %edx, %ecx
24627 addl %ebp, %ebx
24628 adcl %edi, %ecx
24629+
24630+#ifdef CONFIG_PAX_REFCOUNT
24631+ into
24632+1234:
24633+ _ASM_EXTABLE(1234b, 3f)
24634+#endif
24635+
24636 LOCK_PREFIX
24637 cmpxchg8b (%esi)
24638 jne 1b
24639@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
24640 CFI_ADJUST_CFA_OFFSET -8
24641 RESTORE ebx
24642 RESTORE ebp
24643+ pax_force_retaddr
24644 ret
24645 4:
24646 cmpl %edx, 4(%esp)
24647@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
24648 xorl %ecx, %ecx
24649 addl $1, %ebx
24650 adcl %edx, %ecx
24651+
24652+#ifdef CONFIG_PAX_REFCOUNT
24653+ into
24654+1234:
24655+ _ASM_EXTABLE(1234b, 3f)
24656+#endif
24657+
24658 LOCK_PREFIX
24659 cmpxchg8b (%esi)
24660 jne 1b
24661@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
24662 movl $1, %eax
24663 3:
24664 RESTORE ebx
24665+ pax_force_retaddr
24666 ret
24667 CFI_ENDPROC
24668 ENDPROC(atomic64_inc_not_zero_cx8)
24669diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
24670index 2af5df3..62b1a5a 100644
24671--- a/arch/x86/lib/checksum_32.S
24672+++ b/arch/x86/lib/checksum_32.S
24673@@ -29,7 +29,8 @@
24674 #include <asm/dwarf2.h>
24675 #include <asm/errno.h>
24676 #include <asm/asm.h>
24677-
24678+#include <asm/segment.h>
24679+
24680 /*
24681 * computes a partial checksum, e.g. for TCP/UDP fragments
24682 */
24683@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
24684
24685 #define ARGBASE 16
24686 #define FP 12
24687-
24688-ENTRY(csum_partial_copy_generic)
24689+
24690+ENTRY(csum_partial_copy_generic_to_user)
24691 CFI_STARTPROC
24692+
24693+#ifdef CONFIG_PAX_MEMORY_UDEREF
24694+ pushl_cfi %gs
24695+ popl_cfi %es
24696+ jmp csum_partial_copy_generic
24697+#endif
24698+
24699+ENTRY(csum_partial_copy_generic_from_user)
24700+
24701+#ifdef CONFIG_PAX_MEMORY_UDEREF
24702+ pushl_cfi %gs
24703+ popl_cfi %ds
24704+#endif
24705+
24706+ENTRY(csum_partial_copy_generic)
24707 subl $4,%esp
24708 CFI_ADJUST_CFA_OFFSET 4
24709 pushl_cfi %edi
24710@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
24711 jmp 4f
24712 SRC(1: movw (%esi), %bx )
24713 addl $2, %esi
24714-DST( movw %bx, (%edi) )
24715+DST( movw %bx, %es:(%edi) )
24716 addl $2, %edi
24717 addw %bx, %ax
24718 adcl $0, %eax
24719@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
24720 SRC(1: movl (%esi), %ebx )
24721 SRC( movl 4(%esi), %edx )
24722 adcl %ebx, %eax
24723-DST( movl %ebx, (%edi) )
24724+DST( movl %ebx, %es:(%edi) )
24725 adcl %edx, %eax
24726-DST( movl %edx, 4(%edi) )
24727+DST( movl %edx, %es:4(%edi) )
24728
24729 SRC( movl 8(%esi), %ebx )
24730 SRC( movl 12(%esi), %edx )
24731 adcl %ebx, %eax
24732-DST( movl %ebx, 8(%edi) )
24733+DST( movl %ebx, %es:8(%edi) )
24734 adcl %edx, %eax
24735-DST( movl %edx, 12(%edi) )
24736+DST( movl %edx, %es:12(%edi) )
24737
24738 SRC( movl 16(%esi), %ebx )
24739 SRC( movl 20(%esi), %edx )
24740 adcl %ebx, %eax
24741-DST( movl %ebx, 16(%edi) )
24742+DST( movl %ebx, %es:16(%edi) )
24743 adcl %edx, %eax
24744-DST( movl %edx, 20(%edi) )
24745+DST( movl %edx, %es:20(%edi) )
24746
24747 SRC( movl 24(%esi), %ebx )
24748 SRC( movl 28(%esi), %edx )
24749 adcl %ebx, %eax
24750-DST( movl %ebx, 24(%edi) )
24751+DST( movl %ebx, %es:24(%edi) )
24752 adcl %edx, %eax
24753-DST( movl %edx, 28(%edi) )
24754+DST( movl %edx, %es:28(%edi) )
24755
24756 lea 32(%esi), %esi
24757 lea 32(%edi), %edi
24758@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
24759 shrl $2, %edx # This clears CF
24760 SRC(3: movl (%esi), %ebx )
24761 adcl %ebx, %eax
24762-DST( movl %ebx, (%edi) )
24763+DST( movl %ebx, %es:(%edi) )
24764 lea 4(%esi), %esi
24765 lea 4(%edi), %edi
24766 dec %edx
24767@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
24768 jb 5f
24769 SRC( movw (%esi), %cx )
24770 leal 2(%esi), %esi
24771-DST( movw %cx, (%edi) )
24772+DST( movw %cx, %es:(%edi) )
24773 leal 2(%edi), %edi
24774 je 6f
24775 shll $16,%ecx
24776 SRC(5: movb (%esi), %cl )
24777-DST( movb %cl, (%edi) )
24778+DST( movb %cl, %es:(%edi) )
24779 6: addl %ecx, %eax
24780 adcl $0, %eax
24781 7:
24782@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
24783
24784 6001:
24785 movl ARGBASE+20(%esp), %ebx # src_err_ptr
24786- movl $-EFAULT, (%ebx)
24787+ movl $-EFAULT, %ss:(%ebx)
24788
24789 # zero the complete destination - computing the rest
24790 # is too much work
24791@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24792
24793 6002:
24794 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24795- movl $-EFAULT,(%ebx)
24796+ movl $-EFAULT,%ss:(%ebx)
24797 jmp 5000b
24798
24799 .previous
24800
24801+ pushl_cfi %ss
24802+ popl_cfi %ds
24803+ pushl_cfi %ss
24804+ popl_cfi %es
24805 popl_cfi %ebx
24806 CFI_RESTORE ebx
24807 popl_cfi %esi
24808@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24809 popl_cfi %ecx # equivalent to addl $4,%esp
24810 ret
24811 CFI_ENDPROC
24812-ENDPROC(csum_partial_copy_generic)
24813+ENDPROC(csum_partial_copy_generic_to_user)
24814
24815 #else
24816
24817 /* Version for PentiumII/PPro */
24818
24819 #define ROUND1(x) \
24820+ nop; nop; nop; \
24821 SRC(movl x(%esi), %ebx ) ; \
24822 addl %ebx, %eax ; \
24823- DST(movl %ebx, x(%edi) ) ;
24824+ DST(movl %ebx, %es:x(%edi)) ;
24825
24826 #define ROUND(x) \
24827+ nop; nop; nop; \
24828 SRC(movl x(%esi), %ebx ) ; \
24829 adcl %ebx, %eax ; \
24830- DST(movl %ebx, x(%edi) ) ;
24831+ DST(movl %ebx, %es:x(%edi)) ;
24832
24833 #define ARGBASE 12
24834-
24835-ENTRY(csum_partial_copy_generic)
24836+
24837+ENTRY(csum_partial_copy_generic_to_user)
24838 CFI_STARTPROC
24839+
24840+#ifdef CONFIG_PAX_MEMORY_UDEREF
24841+ pushl_cfi %gs
24842+ popl_cfi %es
24843+ jmp csum_partial_copy_generic
24844+#endif
24845+
24846+ENTRY(csum_partial_copy_generic_from_user)
24847+
24848+#ifdef CONFIG_PAX_MEMORY_UDEREF
24849+ pushl_cfi %gs
24850+ popl_cfi %ds
24851+#endif
24852+
24853+ENTRY(csum_partial_copy_generic)
24854 pushl_cfi %ebx
24855 CFI_REL_OFFSET ebx, 0
24856 pushl_cfi %edi
24857@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
24858 subl %ebx, %edi
24859 lea -1(%esi),%edx
24860 andl $-32,%edx
24861- lea 3f(%ebx,%ebx), %ebx
24862+ lea 3f(%ebx,%ebx,2), %ebx
24863 testl %esi, %esi
24864 jmp *%ebx
24865 1: addl $64,%esi
24866@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
24867 jb 5f
24868 SRC( movw (%esi), %dx )
24869 leal 2(%esi), %esi
24870-DST( movw %dx, (%edi) )
24871+DST( movw %dx, %es:(%edi) )
24872 leal 2(%edi), %edi
24873 je 6f
24874 shll $16,%edx
24875 5:
24876 SRC( movb (%esi), %dl )
24877-DST( movb %dl, (%edi) )
24878+DST( movb %dl, %es:(%edi) )
24879 6: addl %edx, %eax
24880 adcl $0, %eax
24881 7:
24882 .section .fixup, "ax"
24883 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
24884- movl $-EFAULT, (%ebx)
24885+ movl $-EFAULT, %ss:(%ebx)
24886 # zero the complete destination (computing the rest is too much work)
24887 movl ARGBASE+8(%esp),%edi # dst
24888 movl ARGBASE+12(%esp),%ecx # len
24889@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
24890 rep; stosb
24891 jmp 7b
24892 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24893- movl $-EFAULT, (%ebx)
24894+ movl $-EFAULT, %ss:(%ebx)
24895 jmp 7b
24896 .previous
24897
24898+#ifdef CONFIG_PAX_MEMORY_UDEREF
24899+ pushl_cfi %ss
24900+ popl_cfi %ds
24901+ pushl_cfi %ss
24902+ popl_cfi %es
24903+#endif
24904+
24905 popl_cfi %esi
24906 CFI_RESTORE esi
24907 popl_cfi %edi
24908@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
24909 CFI_RESTORE ebx
24910 ret
24911 CFI_ENDPROC
24912-ENDPROC(csum_partial_copy_generic)
24913+ENDPROC(csum_partial_copy_generic_to_user)
24914
24915 #undef ROUND
24916 #undef ROUND1
24917diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
24918index f2145cf..cea889d 100644
24919--- a/arch/x86/lib/clear_page_64.S
24920+++ b/arch/x86/lib/clear_page_64.S
24921@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
24922 movl $4096/8,%ecx
24923 xorl %eax,%eax
24924 rep stosq
24925+ pax_force_retaddr
24926 ret
24927 CFI_ENDPROC
24928 ENDPROC(clear_page_c)
24929@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
24930 movl $4096,%ecx
24931 xorl %eax,%eax
24932 rep stosb
24933+ pax_force_retaddr
24934 ret
24935 CFI_ENDPROC
24936 ENDPROC(clear_page_c_e)
24937@@ -43,6 +45,7 @@ ENTRY(clear_page)
24938 leaq 64(%rdi),%rdi
24939 jnz .Lloop
24940 nop
24941+ pax_force_retaddr
24942 ret
24943 CFI_ENDPROC
24944 .Lclear_page_end:
24945@@ -58,7 +61,7 @@ ENDPROC(clear_page)
24946
24947 #include <asm/cpufeature.h>
24948
24949- .section .altinstr_replacement,"ax"
24950+ .section .altinstr_replacement,"a"
24951 1: .byte 0xeb /* jmp <disp8> */
24952 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
24953 2: .byte 0xeb /* jmp <disp8> */
24954diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
24955index 1e572c5..2a162cd 100644
24956--- a/arch/x86/lib/cmpxchg16b_emu.S
24957+++ b/arch/x86/lib/cmpxchg16b_emu.S
24958@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
24959
24960 popf
24961 mov $1, %al
24962+ pax_force_retaddr
24963 ret
24964
24965 not_same:
24966 popf
24967 xor %al,%al
24968+ pax_force_retaddr
24969 ret
24970
24971 CFI_ENDPROC
24972diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
24973index 176cca6..1166c50 100644
24974--- a/arch/x86/lib/copy_page_64.S
24975+++ b/arch/x86/lib/copy_page_64.S
24976@@ -9,6 +9,7 @@ copy_page_rep:
24977 CFI_STARTPROC
24978 movl $4096/8, %ecx
24979 rep movsq
24980+ pax_force_retaddr
24981 ret
24982 CFI_ENDPROC
24983 ENDPROC(copy_page_rep)
24984@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
24985
24986 ENTRY(copy_page)
24987 CFI_STARTPROC
24988- subq $2*8, %rsp
24989- CFI_ADJUST_CFA_OFFSET 2*8
24990+ subq $3*8, %rsp
24991+ CFI_ADJUST_CFA_OFFSET 3*8
24992 movq %rbx, (%rsp)
24993 CFI_REL_OFFSET rbx, 0
24994 movq %r12, 1*8(%rsp)
24995 CFI_REL_OFFSET r12, 1*8
24996+ movq %r13, 2*8(%rsp)
24997+ CFI_REL_OFFSET r13, 2*8
24998
24999 movl $(4096/64)-5, %ecx
25000 .p2align 4
25001@@ -36,7 +39,7 @@ ENTRY(copy_page)
25002 movq 0x8*2(%rsi), %rdx
25003 movq 0x8*3(%rsi), %r8
25004 movq 0x8*4(%rsi), %r9
25005- movq 0x8*5(%rsi), %r10
25006+ movq 0x8*5(%rsi), %r13
25007 movq 0x8*6(%rsi), %r11
25008 movq 0x8*7(%rsi), %r12
25009
25010@@ -47,7 +50,7 @@ ENTRY(copy_page)
25011 movq %rdx, 0x8*2(%rdi)
25012 movq %r8, 0x8*3(%rdi)
25013 movq %r9, 0x8*4(%rdi)
25014- movq %r10, 0x8*5(%rdi)
25015+ movq %r13, 0x8*5(%rdi)
25016 movq %r11, 0x8*6(%rdi)
25017 movq %r12, 0x8*7(%rdi)
25018
25019@@ -66,7 +69,7 @@ ENTRY(copy_page)
25020 movq 0x8*2(%rsi), %rdx
25021 movq 0x8*3(%rsi), %r8
25022 movq 0x8*4(%rsi), %r9
25023- movq 0x8*5(%rsi), %r10
25024+ movq 0x8*5(%rsi), %r13
25025 movq 0x8*6(%rsi), %r11
25026 movq 0x8*7(%rsi), %r12
25027
25028@@ -75,7 +78,7 @@ ENTRY(copy_page)
25029 movq %rdx, 0x8*2(%rdi)
25030 movq %r8, 0x8*3(%rdi)
25031 movq %r9, 0x8*4(%rdi)
25032- movq %r10, 0x8*5(%rdi)
25033+ movq %r13, 0x8*5(%rdi)
25034 movq %r11, 0x8*6(%rdi)
25035 movq %r12, 0x8*7(%rdi)
25036
25037@@ -87,8 +90,11 @@ ENTRY(copy_page)
25038 CFI_RESTORE rbx
25039 movq 1*8(%rsp), %r12
25040 CFI_RESTORE r12
25041- addq $2*8, %rsp
25042- CFI_ADJUST_CFA_OFFSET -2*8
25043+ movq 2*8(%rsp), %r13
25044+ CFI_RESTORE r13
25045+ addq $3*8, %rsp
25046+ CFI_ADJUST_CFA_OFFSET -3*8
25047+ pax_force_retaddr
25048 ret
25049 .Lcopy_page_end:
25050 CFI_ENDPROC
25051@@ -99,7 +105,7 @@ ENDPROC(copy_page)
25052
25053 #include <asm/cpufeature.h>
25054
25055- .section .altinstr_replacement,"ax"
25056+ .section .altinstr_replacement,"a"
25057 1: .byte 0xeb /* jmp <disp8> */
25058 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
25059 2:
25060diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
25061index a30ca15..d25fab6 100644
25062--- a/arch/x86/lib/copy_user_64.S
25063+++ b/arch/x86/lib/copy_user_64.S
25064@@ -18,6 +18,7 @@
25065 #include <asm/alternative-asm.h>
25066 #include <asm/asm.h>
25067 #include <asm/smap.h>
25068+#include <asm/pgtable.h>
25069
25070 /*
25071 * By placing feature2 after feature1 in altinstructions section, we logically
25072@@ -31,7 +32,7 @@
25073 .byte 0xe9 /* 32bit jump */
25074 .long \orig-1f /* by default jump to orig */
25075 1:
25076- .section .altinstr_replacement,"ax"
25077+ .section .altinstr_replacement,"a"
25078 2: .byte 0xe9 /* near jump with 32bit immediate */
25079 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
25080 3: .byte 0xe9 /* near jump with 32bit immediate */
25081@@ -70,47 +71,20 @@
25082 #endif
25083 .endm
25084
25085-/* Standard copy_to_user with segment limit checking */
25086-ENTRY(_copy_to_user)
25087- CFI_STARTPROC
25088- GET_THREAD_INFO(%rax)
25089- movq %rdi,%rcx
25090- addq %rdx,%rcx
25091- jc bad_to_user
25092- cmpq TI_addr_limit(%rax),%rcx
25093- ja bad_to_user
25094- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25095- copy_user_generic_unrolled,copy_user_generic_string, \
25096- copy_user_enhanced_fast_string
25097- CFI_ENDPROC
25098-ENDPROC(_copy_to_user)
25099-
25100-/* Standard copy_from_user with segment limit checking */
25101-ENTRY(_copy_from_user)
25102- CFI_STARTPROC
25103- GET_THREAD_INFO(%rax)
25104- movq %rsi,%rcx
25105- addq %rdx,%rcx
25106- jc bad_from_user
25107- cmpq TI_addr_limit(%rax),%rcx
25108- ja bad_from_user
25109- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25110- copy_user_generic_unrolled,copy_user_generic_string, \
25111- copy_user_enhanced_fast_string
25112- CFI_ENDPROC
25113-ENDPROC(_copy_from_user)
25114-
25115 .section .fixup,"ax"
25116 /* must zero dest */
25117 ENTRY(bad_from_user)
25118 bad_from_user:
25119 CFI_STARTPROC
25120+ testl %edx,%edx
25121+ js bad_to_user
25122 movl %edx,%ecx
25123 xorl %eax,%eax
25124 rep
25125 stosb
25126 bad_to_user:
25127 movl %edx,%eax
25128+ pax_force_retaddr
25129 ret
25130 CFI_ENDPROC
25131 ENDPROC(bad_from_user)
25132@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
25133 jz 17f
25134 1: movq (%rsi),%r8
25135 2: movq 1*8(%rsi),%r9
25136-3: movq 2*8(%rsi),%r10
25137+3: movq 2*8(%rsi),%rax
25138 4: movq 3*8(%rsi),%r11
25139 5: movq %r8,(%rdi)
25140 6: movq %r9,1*8(%rdi)
25141-7: movq %r10,2*8(%rdi)
25142+7: movq %rax,2*8(%rdi)
25143 8: movq %r11,3*8(%rdi)
25144 9: movq 4*8(%rsi),%r8
25145 10: movq 5*8(%rsi),%r9
25146-11: movq 6*8(%rsi),%r10
25147+11: movq 6*8(%rsi),%rax
25148 12: movq 7*8(%rsi),%r11
25149 13: movq %r8,4*8(%rdi)
25150 14: movq %r9,5*8(%rdi)
25151-15: movq %r10,6*8(%rdi)
25152+15: movq %rax,6*8(%rdi)
25153 16: movq %r11,7*8(%rdi)
25154 leaq 64(%rsi),%rsi
25155 leaq 64(%rdi),%rdi
25156@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
25157 jnz 21b
25158 23: xor %eax,%eax
25159 ASM_CLAC
25160+ pax_force_retaddr
25161 ret
25162
25163 .section .fixup,"ax"
25164@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
25165 movsb
25166 4: xorl %eax,%eax
25167 ASM_CLAC
25168+ pax_force_retaddr
25169 ret
25170
25171 .section .fixup,"ax"
25172@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
25173 movsb
25174 2: xorl %eax,%eax
25175 ASM_CLAC
25176+ pax_force_retaddr
25177 ret
25178
25179 .section .fixup,"ax"
25180diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
25181index 6a4f43c..f5f9e26 100644
25182--- a/arch/x86/lib/copy_user_nocache_64.S
25183+++ b/arch/x86/lib/copy_user_nocache_64.S
25184@@ -8,6 +8,7 @@
25185
25186 #include <linux/linkage.h>
25187 #include <asm/dwarf2.h>
25188+#include <asm/alternative-asm.h>
25189
25190 #define FIX_ALIGNMENT 1
25191
25192@@ -16,6 +17,7 @@
25193 #include <asm/thread_info.h>
25194 #include <asm/asm.h>
25195 #include <asm/smap.h>
25196+#include <asm/pgtable.h>
25197
25198 .macro ALIGN_DESTINATION
25199 #ifdef FIX_ALIGNMENT
25200@@ -49,6 +51,15 @@
25201 */
25202 ENTRY(__copy_user_nocache)
25203 CFI_STARTPROC
25204+
25205+#ifdef CONFIG_PAX_MEMORY_UDEREF
25206+ mov $PAX_USER_SHADOW_BASE,%rcx
25207+ cmp %rcx,%rsi
25208+ jae 1f
25209+ add %rcx,%rsi
25210+1:
25211+#endif
25212+
25213 ASM_STAC
25214 cmpl $8,%edx
25215 jb 20f /* less then 8 bytes, go to byte copy loop */
25216@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
25217 jz 17f
25218 1: movq (%rsi),%r8
25219 2: movq 1*8(%rsi),%r9
25220-3: movq 2*8(%rsi),%r10
25221+3: movq 2*8(%rsi),%rax
25222 4: movq 3*8(%rsi),%r11
25223 5: movnti %r8,(%rdi)
25224 6: movnti %r9,1*8(%rdi)
25225-7: movnti %r10,2*8(%rdi)
25226+7: movnti %rax,2*8(%rdi)
25227 8: movnti %r11,3*8(%rdi)
25228 9: movq 4*8(%rsi),%r8
25229 10: movq 5*8(%rsi),%r9
25230-11: movq 6*8(%rsi),%r10
25231+11: movq 6*8(%rsi),%rax
25232 12: movq 7*8(%rsi),%r11
25233 13: movnti %r8,4*8(%rdi)
25234 14: movnti %r9,5*8(%rdi)
25235-15: movnti %r10,6*8(%rdi)
25236+15: movnti %rax,6*8(%rdi)
25237 16: movnti %r11,7*8(%rdi)
25238 leaq 64(%rsi),%rsi
25239 leaq 64(%rdi),%rdi
25240@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
25241 23: xorl %eax,%eax
25242 ASM_CLAC
25243 sfence
25244+ pax_force_retaddr
25245 ret
25246
25247 .section .fixup,"ax"
25248diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
25249index 2419d5f..953ee51 100644
25250--- a/arch/x86/lib/csum-copy_64.S
25251+++ b/arch/x86/lib/csum-copy_64.S
25252@@ -9,6 +9,7 @@
25253 #include <asm/dwarf2.h>
25254 #include <asm/errno.h>
25255 #include <asm/asm.h>
25256+#include <asm/alternative-asm.h>
25257
25258 /*
25259 * Checksum copy with exception handling.
25260@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
25261 CFI_RESTORE rbp
25262 addq $7*8, %rsp
25263 CFI_ADJUST_CFA_OFFSET -7*8
25264+ pax_force_retaddr 0, 1
25265 ret
25266 CFI_RESTORE_STATE
25267
25268diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
25269index 25b7ae8..169fafc 100644
25270--- a/arch/x86/lib/csum-wrappers_64.c
25271+++ b/arch/x86/lib/csum-wrappers_64.c
25272@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
25273 len -= 2;
25274 }
25275 }
25276- isum = csum_partial_copy_generic((__force const void *)src,
25277+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
25278 dst, len, isum, errp, NULL);
25279 if (unlikely(*errp))
25280 goto out_err;
25281@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
25282 }
25283
25284 *errp = 0;
25285- return csum_partial_copy_generic(src, (void __force *)dst,
25286+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
25287 len, isum, NULL, errp);
25288 }
25289 EXPORT_SYMBOL(csum_partial_copy_to_user);
25290diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
25291index 156b9c8..b144132 100644
25292--- a/arch/x86/lib/getuser.S
25293+++ b/arch/x86/lib/getuser.S
25294@@ -34,17 +34,40 @@
25295 #include <asm/thread_info.h>
25296 #include <asm/asm.h>
25297 #include <asm/smap.h>
25298+#include <asm/segment.h>
25299+#include <asm/pgtable.h>
25300+#include <asm/alternative-asm.h>
25301+
25302+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25303+#define __copyuser_seg gs;
25304+#else
25305+#define __copyuser_seg
25306+#endif
25307
25308 .text
25309 ENTRY(__get_user_1)
25310 CFI_STARTPROC
25311+
25312+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25313 GET_THREAD_INFO(%_ASM_DX)
25314 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25315 jae bad_get_user
25316 ASM_STAC
25317-1: movzb (%_ASM_AX),%edx
25318+
25319+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25320+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25321+ cmp %_ASM_DX,%_ASM_AX
25322+ jae 1234f
25323+ add %_ASM_DX,%_ASM_AX
25324+1234:
25325+#endif
25326+
25327+#endif
25328+
25329+1: __copyuser_seg movzb (%_ASM_AX),%edx
25330 xor %eax,%eax
25331 ASM_CLAC
25332+ pax_force_retaddr
25333 ret
25334 CFI_ENDPROC
25335 ENDPROC(__get_user_1)
25336@@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
25337 ENTRY(__get_user_2)
25338 CFI_STARTPROC
25339 add $1,%_ASM_AX
25340+
25341+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25342 jc bad_get_user
25343 GET_THREAD_INFO(%_ASM_DX)
25344 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25345 jae bad_get_user
25346 ASM_STAC
25347-2: movzwl -1(%_ASM_AX),%edx
25348+
25349+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25350+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25351+ cmp %_ASM_DX,%_ASM_AX
25352+ jae 1234f
25353+ add %_ASM_DX,%_ASM_AX
25354+1234:
25355+#endif
25356+
25357+#endif
25358+
25359+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
25360 xor %eax,%eax
25361 ASM_CLAC
25362+ pax_force_retaddr
25363 ret
25364 CFI_ENDPROC
25365 ENDPROC(__get_user_2)
25366@@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
25367 ENTRY(__get_user_4)
25368 CFI_STARTPROC
25369 add $3,%_ASM_AX
25370+
25371+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25372 jc bad_get_user
25373 GET_THREAD_INFO(%_ASM_DX)
25374 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25375 jae bad_get_user
25376 ASM_STAC
25377-3: mov -3(%_ASM_AX),%edx
25378+
25379+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25380+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25381+ cmp %_ASM_DX,%_ASM_AX
25382+ jae 1234f
25383+ add %_ASM_DX,%_ASM_AX
25384+1234:
25385+#endif
25386+
25387+#endif
25388+
25389+3: __copyuser_seg mov -3(%_ASM_AX),%edx
25390 xor %eax,%eax
25391 ASM_CLAC
25392+ pax_force_retaddr
25393 ret
25394 CFI_ENDPROC
25395 ENDPROC(__get_user_4)
25396@@ -87,10 +138,20 @@ ENTRY(__get_user_8)
25397 GET_THREAD_INFO(%_ASM_DX)
25398 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25399 jae bad_get_user
25400+
25401+#ifdef CONFIG_PAX_MEMORY_UDEREF
25402+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25403+ cmp %_ASM_DX,%_ASM_AX
25404+ jae 1234f
25405+ add %_ASM_DX,%_ASM_AX
25406+1234:
25407+#endif
25408+
25409 ASM_STAC
25410 4: movq -7(%_ASM_AX),%_ASM_DX
25411 xor %eax,%eax
25412 ASM_CLAC
25413+ pax_force_retaddr
25414 ret
25415 CFI_ENDPROC
25416 ENDPROC(__get_user_8)
25417@@ -101,6 +162,7 @@ bad_get_user:
25418 xor %edx,%edx
25419 mov $(-EFAULT),%_ASM_AX
25420 ASM_CLAC
25421+ pax_force_retaddr
25422 ret
25423 CFI_ENDPROC
25424 END(bad_get_user)
25425diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
25426index 54fcffe..7be149e 100644
25427--- a/arch/x86/lib/insn.c
25428+++ b/arch/x86/lib/insn.c
25429@@ -20,8 +20,10 @@
25430
25431 #ifdef __KERNEL__
25432 #include <linux/string.h>
25433+#include <asm/pgtable_types.h>
25434 #else
25435 #include <string.h>
25436+#define ktla_ktva(addr) addr
25437 #endif
25438 #include <asm/inat.h>
25439 #include <asm/insn.h>
25440@@ -53,8 +55,8 @@
25441 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
25442 {
25443 memset(insn, 0, sizeof(*insn));
25444- insn->kaddr = kaddr;
25445- insn->next_byte = kaddr;
25446+ insn->kaddr = ktla_ktva(kaddr);
25447+ insn->next_byte = ktla_ktva(kaddr);
25448 insn->x86_64 = x86_64 ? 1 : 0;
25449 insn->opnd_bytes = 4;
25450 if (x86_64)
25451diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
25452index 05a95e7..326f2fa 100644
25453--- a/arch/x86/lib/iomap_copy_64.S
25454+++ b/arch/x86/lib/iomap_copy_64.S
25455@@ -17,6 +17,7 @@
25456
25457 #include <linux/linkage.h>
25458 #include <asm/dwarf2.h>
25459+#include <asm/alternative-asm.h>
25460
25461 /*
25462 * override generic version in lib/iomap_copy.c
25463@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
25464 CFI_STARTPROC
25465 movl %edx,%ecx
25466 rep movsd
25467+ pax_force_retaddr
25468 ret
25469 CFI_ENDPROC
25470 ENDPROC(__iowrite32_copy)
25471diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
25472index 1c273be..da9cc0e 100644
25473--- a/arch/x86/lib/memcpy_64.S
25474+++ b/arch/x86/lib/memcpy_64.S
25475@@ -33,6 +33,7 @@
25476 rep movsq
25477 movl %edx, %ecx
25478 rep movsb
25479+ pax_force_retaddr
25480 ret
25481 .Lmemcpy_e:
25482 .previous
25483@@ -49,6 +50,7 @@
25484 movq %rdi, %rax
25485 movq %rdx, %rcx
25486 rep movsb
25487+ pax_force_retaddr
25488 ret
25489 .Lmemcpy_e_e:
25490 .previous
25491@@ -76,13 +78,13 @@ ENTRY(memcpy)
25492 */
25493 movq 0*8(%rsi), %r8
25494 movq 1*8(%rsi), %r9
25495- movq 2*8(%rsi), %r10
25496+ movq 2*8(%rsi), %rcx
25497 movq 3*8(%rsi), %r11
25498 leaq 4*8(%rsi), %rsi
25499
25500 movq %r8, 0*8(%rdi)
25501 movq %r9, 1*8(%rdi)
25502- movq %r10, 2*8(%rdi)
25503+ movq %rcx, 2*8(%rdi)
25504 movq %r11, 3*8(%rdi)
25505 leaq 4*8(%rdi), %rdi
25506 jae .Lcopy_forward_loop
25507@@ -105,12 +107,12 @@ ENTRY(memcpy)
25508 subq $0x20, %rdx
25509 movq -1*8(%rsi), %r8
25510 movq -2*8(%rsi), %r9
25511- movq -3*8(%rsi), %r10
25512+ movq -3*8(%rsi), %rcx
25513 movq -4*8(%rsi), %r11
25514 leaq -4*8(%rsi), %rsi
25515 movq %r8, -1*8(%rdi)
25516 movq %r9, -2*8(%rdi)
25517- movq %r10, -3*8(%rdi)
25518+ movq %rcx, -3*8(%rdi)
25519 movq %r11, -4*8(%rdi)
25520 leaq -4*8(%rdi), %rdi
25521 jae .Lcopy_backward_loop
25522@@ -130,12 +132,13 @@ ENTRY(memcpy)
25523 */
25524 movq 0*8(%rsi), %r8
25525 movq 1*8(%rsi), %r9
25526- movq -2*8(%rsi, %rdx), %r10
25527+ movq -2*8(%rsi, %rdx), %rcx
25528 movq -1*8(%rsi, %rdx), %r11
25529 movq %r8, 0*8(%rdi)
25530 movq %r9, 1*8(%rdi)
25531- movq %r10, -2*8(%rdi, %rdx)
25532+ movq %rcx, -2*8(%rdi, %rdx)
25533 movq %r11, -1*8(%rdi, %rdx)
25534+ pax_force_retaddr
25535 retq
25536 .p2align 4
25537 .Lless_16bytes:
25538@@ -148,6 +151,7 @@ ENTRY(memcpy)
25539 movq -1*8(%rsi, %rdx), %r9
25540 movq %r8, 0*8(%rdi)
25541 movq %r9, -1*8(%rdi, %rdx)
25542+ pax_force_retaddr
25543 retq
25544 .p2align 4
25545 .Lless_8bytes:
25546@@ -161,6 +165,7 @@ ENTRY(memcpy)
25547 movl -4(%rsi, %rdx), %r8d
25548 movl %ecx, (%rdi)
25549 movl %r8d, -4(%rdi, %rdx)
25550+ pax_force_retaddr
25551 retq
25552 .p2align 4
25553 .Lless_3bytes:
25554@@ -179,6 +184,7 @@ ENTRY(memcpy)
25555 movb %cl, (%rdi)
25556
25557 .Lend:
25558+ pax_force_retaddr
25559 retq
25560 CFI_ENDPROC
25561 ENDPROC(memcpy)
25562diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
25563index ee16461..c39c199 100644
25564--- a/arch/x86/lib/memmove_64.S
25565+++ b/arch/x86/lib/memmove_64.S
25566@@ -61,13 +61,13 @@ ENTRY(memmove)
25567 5:
25568 sub $0x20, %rdx
25569 movq 0*8(%rsi), %r11
25570- movq 1*8(%rsi), %r10
25571+ movq 1*8(%rsi), %rcx
25572 movq 2*8(%rsi), %r9
25573 movq 3*8(%rsi), %r8
25574 leaq 4*8(%rsi), %rsi
25575
25576 movq %r11, 0*8(%rdi)
25577- movq %r10, 1*8(%rdi)
25578+ movq %rcx, 1*8(%rdi)
25579 movq %r9, 2*8(%rdi)
25580 movq %r8, 3*8(%rdi)
25581 leaq 4*8(%rdi), %rdi
25582@@ -81,10 +81,10 @@ ENTRY(memmove)
25583 4:
25584 movq %rdx, %rcx
25585 movq -8(%rsi, %rdx), %r11
25586- lea -8(%rdi, %rdx), %r10
25587+ lea -8(%rdi, %rdx), %r9
25588 shrq $3, %rcx
25589 rep movsq
25590- movq %r11, (%r10)
25591+ movq %r11, (%r9)
25592 jmp 13f
25593 .Lmemmove_end_forward:
25594
25595@@ -95,14 +95,14 @@ ENTRY(memmove)
25596 7:
25597 movq %rdx, %rcx
25598 movq (%rsi), %r11
25599- movq %rdi, %r10
25600+ movq %rdi, %r9
25601 leaq -8(%rsi, %rdx), %rsi
25602 leaq -8(%rdi, %rdx), %rdi
25603 shrq $3, %rcx
25604 std
25605 rep movsq
25606 cld
25607- movq %r11, (%r10)
25608+ movq %r11, (%r9)
25609 jmp 13f
25610
25611 /*
25612@@ -127,13 +127,13 @@ ENTRY(memmove)
25613 8:
25614 subq $0x20, %rdx
25615 movq -1*8(%rsi), %r11
25616- movq -2*8(%rsi), %r10
25617+ movq -2*8(%rsi), %rcx
25618 movq -3*8(%rsi), %r9
25619 movq -4*8(%rsi), %r8
25620 leaq -4*8(%rsi), %rsi
25621
25622 movq %r11, -1*8(%rdi)
25623- movq %r10, -2*8(%rdi)
25624+ movq %rcx, -2*8(%rdi)
25625 movq %r9, -3*8(%rdi)
25626 movq %r8, -4*8(%rdi)
25627 leaq -4*8(%rdi), %rdi
25628@@ -151,11 +151,11 @@ ENTRY(memmove)
25629 * Move data from 16 bytes to 31 bytes.
25630 */
25631 movq 0*8(%rsi), %r11
25632- movq 1*8(%rsi), %r10
25633+ movq 1*8(%rsi), %rcx
25634 movq -2*8(%rsi, %rdx), %r9
25635 movq -1*8(%rsi, %rdx), %r8
25636 movq %r11, 0*8(%rdi)
25637- movq %r10, 1*8(%rdi)
25638+ movq %rcx, 1*8(%rdi)
25639 movq %r9, -2*8(%rdi, %rdx)
25640 movq %r8, -1*8(%rdi, %rdx)
25641 jmp 13f
25642@@ -167,9 +167,9 @@ ENTRY(memmove)
25643 * Move data from 8 bytes to 15 bytes.
25644 */
25645 movq 0*8(%rsi), %r11
25646- movq -1*8(%rsi, %rdx), %r10
25647+ movq -1*8(%rsi, %rdx), %r9
25648 movq %r11, 0*8(%rdi)
25649- movq %r10, -1*8(%rdi, %rdx)
25650+ movq %r9, -1*8(%rdi, %rdx)
25651 jmp 13f
25652 10:
25653 cmpq $4, %rdx
25654@@ -178,9 +178,9 @@ ENTRY(memmove)
25655 * Move data from 4 bytes to 7 bytes.
25656 */
25657 movl (%rsi), %r11d
25658- movl -4(%rsi, %rdx), %r10d
25659+ movl -4(%rsi, %rdx), %r9d
25660 movl %r11d, (%rdi)
25661- movl %r10d, -4(%rdi, %rdx)
25662+ movl %r9d, -4(%rdi, %rdx)
25663 jmp 13f
25664 11:
25665 cmp $2, %rdx
25666@@ -189,9 +189,9 @@ ENTRY(memmove)
25667 * Move data from 2 bytes to 3 bytes.
25668 */
25669 movw (%rsi), %r11w
25670- movw -2(%rsi, %rdx), %r10w
25671+ movw -2(%rsi, %rdx), %r9w
25672 movw %r11w, (%rdi)
25673- movw %r10w, -2(%rdi, %rdx)
25674+ movw %r9w, -2(%rdi, %rdx)
25675 jmp 13f
25676 12:
25677 cmp $1, %rdx
25678@@ -202,6 +202,7 @@ ENTRY(memmove)
25679 movb (%rsi), %r11b
25680 movb %r11b, (%rdi)
25681 13:
25682+ pax_force_retaddr
25683 retq
25684 CFI_ENDPROC
25685
25686@@ -210,6 +211,7 @@ ENTRY(memmove)
25687 /* Forward moving data. */
25688 movq %rdx, %rcx
25689 rep movsb
25690+ pax_force_retaddr
25691 retq
25692 .Lmemmove_end_forward_efs:
25693 .previous
25694diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
25695index 2dcb380..963660a 100644
25696--- a/arch/x86/lib/memset_64.S
25697+++ b/arch/x86/lib/memset_64.S
25698@@ -30,6 +30,7 @@
25699 movl %edx,%ecx
25700 rep stosb
25701 movq %r9,%rax
25702+ pax_force_retaddr
25703 ret
25704 .Lmemset_e:
25705 .previous
25706@@ -52,6 +53,7 @@
25707 movq %rdx,%rcx
25708 rep stosb
25709 movq %r9,%rax
25710+ pax_force_retaddr
25711 ret
25712 .Lmemset_e_e:
25713 .previous
25714@@ -59,7 +61,7 @@
25715 ENTRY(memset)
25716 ENTRY(__memset)
25717 CFI_STARTPROC
25718- movq %rdi,%r10
25719+ movq %rdi,%r11
25720
25721 /* expand byte value */
25722 movzbl %sil,%ecx
25723@@ -117,7 +119,8 @@ ENTRY(__memset)
25724 jnz .Lloop_1
25725
25726 .Lende:
25727- movq %r10,%rax
25728+ movq %r11,%rax
25729+ pax_force_retaddr
25730 ret
25731
25732 CFI_RESTORE_STATE
25733diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
25734index c9f2d9b..e7fd2c0 100644
25735--- a/arch/x86/lib/mmx_32.c
25736+++ b/arch/x86/lib/mmx_32.c
25737@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25738 {
25739 void *p;
25740 int i;
25741+ unsigned long cr0;
25742
25743 if (unlikely(in_interrupt()))
25744 return __memcpy(to, from, len);
25745@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25746 kernel_fpu_begin();
25747
25748 __asm__ __volatile__ (
25749- "1: prefetch (%0)\n" /* This set is 28 bytes */
25750- " prefetch 64(%0)\n"
25751- " prefetch 128(%0)\n"
25752- " prefetch 192(%0)\n"
25753- " prefetch 256(%0)\n"
25754+ "1: prefetch (%1)\n" /* This set is 28 bytes */
25755+ " prefetch 64(%1)\n"
25756+ " prefetch 128(%1)\n"
25757+ " prefetch 192(%1)\n"
25758+ " prefetch 256(%1)\n"
25759 "2: \n"
25760 ".section .fixup, \"ax\"\n"
25761- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25762+ "3: \n"
25763+
25764+#ifdef CONFIG_PAX_KERNEXEC
25765+ " movl %%cr0, %0\n"
25766+ " movl %0, %%eax\n"
25767+ " andl $0xFFFEFFFF, %%eax\n"
25768+ " movl %%eax, %%cr0\n"
25769+#endif
25770+
25771+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25772+
25773+#ifdef CONFIG_PAX_KERNEXEC
25774+ " movl %0, %%cr0\n"
25775+#endif
25776+
25777 " jmp 2b\n"
25778 ".previous\n"
25779 _ASM_EXTABLE(1b, 3b)
25780- : : "r" (from));
25781+ : "=&r" (cr0) : "r" (from) : "ax");
25782
25783 for ( ; i > 5; i--) {
25784 __asm__ __volatile__ (
25785- "1: prefetch 320(%0)\n"
25786- "2: movq (%0), %%mm0\n"
25787- " movq 8(%0), %%mm1\n"
25788- " movq 16(%0), %%mm2\n"
25789- " movq 24(%0), %%mm3\n"
25790- " movq %%mm0, (%1)\n"
25791- " movq %%mm1, 8(%1)\n"
25792- " movq %%mm2, 16(%1)\n"
25793- " movq %%mm3, 24(%1)\n"
25794- " movq 32(%0), %%mm0\n"
25795- " movq 40(%0), %%mm1\n"
25796- " movq 48(%0), %%mm2\n"
25797- " movq 56(%0), %%mm3\n"
25798- " movq %%mm0, 32(%1)\n"
25799- " movq %%mm1, 40(%1)\n"
25800- " movq %%mm2, 48(%1)\n"
25801- " movq %%mm3, 56(%1)\n"
25802+ "1: prefetch 320(%1)\n"
25803+ "2: movq (%1), %%mm0\n"
25804+ " movq 8(%1), %%mm1\n"
25805+ " movq 16(%1), %%mm2\n"
25806+ " movq 24(%1), %%mm3\n"
25807+ " movq %%mm0, (%2)\n"
25808+ " movq %%mm1, 8(%2)\n"
25809+ " movq %%mm2, 16(%2)\n"
25810+ " movq %%mm3, 24(%2)\n"
25811+ " movq 32(%1), %%mm0\n"
25812+ " movq 40(%1), %%mm1\n"
25813+ " movq 48(%1), %%mm2\n"
25814+ " movq 56(%1), %%mm3\n"
25815+ " movq %%mm0, 32(%2)\n"
25816+ " movq %%mm1, 40(%2)\n"
25817+ " movq %%mm2, 48(%2)\n"
25818+ " movq %%mm3, 56(%2)\n"
25819 ".section .fixup, \"ax\"\n"
25820- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25821+ "3:\n"
25822+
25823+#ifdef CONFIG_PAX_KERNEXEC
25824+ " movl %%cr0, %0\n"
25825+ " movl %0, %%eax\n"
25826+ " andl $0xFFFEFFFF, %%eax\n"
25827+ " movl %%eax, %%cr0\n"
25828+#endif
25829+
25830+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25831+
25832+#ifdef CONFIG_PAX_KERNEXEC
25833+ " movl %0, %%cr0\n"
25834+#endif
25835+
25836 " jmp 2b\n"
25837 ".previous\n"
25838 _ASM_EXTABLE(1b, 3b)
25839- : : "r" (from), "r" (to) : "memory");
25840+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25841
25842 from += 64;
25843 to += 64;
25844@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
25845 static void fast_copy_page(void *to, void *from)
25846 {
25847 int i;
25848+ unsigned long cr0;
25849
25850 kernel_fpu_begin();
25851
25852@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
25853 * but that is for later. -AV
25854 */
25855 __asm__ __volatile__(
25856- "1: prefetch (%0)\n"
25857- " prefetch 64(%0)\n"
25858- " prefetch 128(%0)\n"
25859- " prefetch 192(%0)\n"
25860- " prefetch 256(%0)\n"
25861+ "1: prefetch (%1)\n"
25862+ " prefetch 64(%1)\n"
25863+ " prefetch 128(%1)\n"
25864+ " prefetch 192(%1)\n"
25865+ " prefetch 256(%1)\n"
25866 "2: \n"
25867 ".section .fixup, \"ax\"\n"
25868- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25869+ "3: \n"
25870+
25871+#ifdef CONFIG_PAX_KERNEXEC
25872+ " movl %%cr0, %0\n"
25873+ " movl %0, %%eax\n"
25874+ " andl $0xFFFEFFFF, %%eax\n"
25875+ " movl %%eax, %%cr0\n"
25876+#endif
25877+
25878+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25879+
25880+#ifdef CONFIG_PAX_KERNEXEC
25881+ " movl %0, %%cr0\n"
25882+#endif
25883+
25884 " jmp 2b\n"
25885 ".previous\n"
25886- _ASM_EXTABLE(1b, 3b) : : "r" (from));
25887+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25888
25889 for (i = 0; i < (4096-320)/64; i++) {
25890 __asm__ __volatile__ (
25891- "1: prefetch 320(%0)\n"
25892- "2: movq (%0), %%mm0\n"
25893- " movntq %%mm0, (%1)\n"
25894- " movq 8(%0), %%mm1\n"
25895- " movntq %%mm1, 8(%1)\n"
25896- " movq 16(%0), %%mm2\n"
25897- " movntq %%mm2, 16(%1)\n"
25898- " movq 24(%0), %%mm3\n"
25899- " movntq %%mm3, 24(%1)\n"
25900- " movq 32(%0), %%mm4\n"
25901- " movntq %%mm4, 32(%1)\n"
25902- " movq 40(%0), %%mm5\n"
25903- " movntq %%mm5, 40(%1)\n"
25904- " movq 48(%0), %%mm6\n"
25905- " movntq %%mm6, 48(%1)\n"
25906- " movq 56(%0), %%mm7\n"
25907- " movntq %%mm7, 56(%1)\n"
25908+ "1: prefetch 320(%1)\n"
25909+ "2: movq (%1), %%mm0\n"
25910+ " movntq %%mm0, (%2)\n"
25911+ " movq 8(%1), %%mm1\n"
25912+ " movntq %%mm1, 8(%2)\n"
25913+ " movq 16(%1), %%mm2\n"
25914+ " movntq %%mm2, 16(%2)\n"
25915+ " movq 24(%1), %%mm3\n"
25916+ " movntq %%mm3, 24(%2)\n"
25917+ " movq 32(%1), %%mm4\n"
25918+ " movntq %%mm4, 32(%2)\n"
25919+ " movq 40(%1), %%mm5\n"
25920+ " movntq %%mm5, 40(%2)\n"
25921+ " movq 48(%1), %%mm6\n"
25922+ " movntq %%mm6, 48(%2)\n"
25923+ " movq 56(%1), %%mm7\n"
25924+ " movntq %%mm7, 56(%2)\n"
25925 ".section .fixup, \"ax\"\n"
25926- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25927+ "3:\n"
25928+
25929+#ifdef CONFIG_PAX_KERNEXEC
25930+ " movl %%cr0, %0\n"
25931+ " movl %0, %%eax\n"
25932+ " andl $0xFFFEFFFF, %%eax\n"
25933+ " movl %%eax, %%cr0\n"
25934+#endif
25935+
25936+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25937+
25938+#ifdef CONFIG_PAX_KERNEXEC
25939+ " movl %0, %%cr0\n"
25940+#endif
25941+
25942 " jmp 2b\n"
25943 ".previous\n"
25944- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
25945+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25946
25947 from += 64;
25948 to += 64;
25949@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
25950 static void fast_copy_page(void *to, void *from)
25951 {
25952 int i;
25953+ unsigned long cr0;
25954
25955 kernel_fpu_begin();
25956
25957 __asm__ __volatile__ (
25958- "1: prefetch (%0)\n"
25959- " prefetch 64(%0)\n"
25960- " prefetch 128(%0)\n"
25961- " prefetch 192(%0)\n"
25962- " prefetch 256(%0)\n"
25963+ "1: prefetch (%1)\n"
25964+ " prefetch 64(%1)\n"
25965+ " prefetch 128(%1)\n"
25966+ " prefetch 192(%1)\n"
25967+ " prefetch 256(%1)\n"
25968 "2: \n"
25969 ".section .fixup, \"ax\"\n"
25970- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25971+ "3: \n"
25972+
25973+#ifdef CONFIG_PAX_KERNEXEC
25974+ " movl %%cr0, %0\n"
25975+ " movl %0, %%eax\n"
25976+ " andl $0xFFFEFFFF, %%eax\n"
25977+ " movl %%eax, %%cr0\n"
25978+#endif
25979+
25980+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25981+
25982+#ifdef CONFIG_PAX_KERNEXEC
25983+ " movl %0, %%cr0\n"
25984+#endif
25985+
25986 " jmp 2b\n"
25987 ".previous\n"
25988- _ASM_EXTABLE(1b, 3b) : : "r" (from));
25989+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25990
25991 for (i = 0; i < 4096/64; i++) {
25992 __asm__ __volatile__ (
25993- "1: prefetch 320(%0)\n"
25994- "2: movq (%0), %%mm0\n"
25995- " movq 8(%0), %%mm1\n"
25996- " movq 16(%0), %%mm2\n"
25997- " movq 24(%0), %%mm3\n"
25998- " movq %%mm0, (%1)\n"
25999- " movq %%mm1, 8(%1)\n"
26000- " movq %%mm2, 16(%1)\n"
26001- " movq %%mm3, 24(%1)\n"
26002- " movq 32(%0), %%mm0\n"
26003- " movq 40(%0), %%mm1\n"
26004- " movq 48(%0), %%mm2\n"
26005- " movq 56(%0), %%mm3\n"
26006- " movq %%mm0, 32(%1)\n"
26007- " movq %%mm1, 40(%1)\n"
26008- " movq %%mm2, 48(%1)\n"
26009- " movq %%mm3, 56(%1)\n"
26010+ "1: prefetch 320(%1)\n"
26011+ "2: movq (%1), %%mm0\n"
26012+ " movq 8(%1), %%mm1\n"
26013+ " movq 16(%1), %%mm2\n"
26014+ " movq 24(%1), %%mm3\n"
26015+ " movq %%mm0, (%2)\n"
26016+ " movq %%mm1, 8(%2)\n"
26017+ " movq %%mm2, 16(%2)\n"
26018+ " movq %%mm3, 24(%2)\n"
26019+ " movq 32(%1), %%mm0\n"
26020+ " movq 40(%1), %%mm1\n"
26021+ " movq 48(%1), %%mm2\n"
26022+ " movq 56(%1), %%mm3\n"
26023+ " movq %%mm0, 32(%2)\n"
26024+ " movq %%mm1, 40(%2)\n"
26025+ " movq %%mm2, 48(%2)\n"
26026+ " movq %%mm3, 56(%2)\n"
26027 ".section .fixup, \"ax\"\n"
26028- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26029+ "3:\n"
26030+
26031+#ifdef CONFIG_PAX_KERNEXEC
26032+ " movl %%cr0, %0\n"
26033+ " movl %0, %%eax\n"
26034+ " andl $0xFFFEFFFF, %%eax\n"
26035+ " movl %%eax, %%cr0\n"
26036+#endif
26037+
26038+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26039+
26040+#ifdef CONFIG_PAX_KERNEXEC
26041+ " movl %0, %%cr0\n"
26042+#endif
26043+
26044 " jmp 2b\n"
26045 ".previous\n"
26046 _ASM_EXTABLE(1b, 3b)
26047- : : "r" (from), "r" (to) : "memory");
26048+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26049
26050 from += 64;
26051 to += 64;
26052diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
26053index f6d13ee..aca5f0b 100644
26054--- a/arch/x86/lib/msr-reg.S
26055+++ b/arch/x86/lib/msr-reg.S
26056@@ -3,6 +3,7 @@
26057 #include <asm/dwarf2.h>
26058 #include <asm/asm.h>
26059 #include <asm/msr.h>
26060+#include <asm/alternative-asm.h>
26061
26062 #ifdef CONFIG_X86_64
26063 /*
26064@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
26065 CFI_STARTPROC
26066 pushq_cfi %rbx
26067 pushq_cfi %rbp
26068- movq %rdi, %r10 /* Save pointer */
26069+ movq %rdi, %r9 /* Save pointer */
26070 xorl %r11d, %r11d /* Return value */
26071 movl (%rdi), %eax
26072 movl 4(%rdi), %ecx
26073@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
26074 movl 28(%rdi), %edi
26075 CFI_REMEMBER_STATE
26076 1: \op
26077-2: movl %eax, (%r10)
26078+2: movl %eax, (%r9)
26079 movl %r11d, %eax /* Return value */
26080- movl %ecx, 4(%r10)
26081- movl %edx, 8(%r10)
26082- movl %ebx, 12(%r10)
26083- movl %ebp, 20(%r10)
26084- movl %esi, 24(%r10)
26085- movl %edi, 28(%r10)
26086+ movl %ecx, 4(%r9)
26087+ movl %edx, 8(%r9)
26088+ movl %ebx, 12(%r9)
26089+ movl %ebp, 20(%r9)
26090+ movl %esi, 24(%r9)
26091+ movl %edi, 28(%r9)
26092 popq_cfi %rbp
26093 popq_cfi %rbx
26094+ pax_force_retaddr
26095 ret
26096 3:
26097 CFI_RESTORE_STATE
26098diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
26099index fc6ba17..04471c5 100644
26100--- a/arch/x86/lib/putuser.S
26101+++ b/arch/x86/lib/putuser.S
26102@@ -16,7 +16,9 @@
26103 #include <asm/errno.h>
26104 #include <asm/asm.h>
26105 #include <asm/smap.h>
26106-
26107+#include <asm/segment.h>
26108+#include <asm/pgtable.h>
26109+#include <asm/alternative-asm.h>
26110
26111 /*
26112 * __put_user_X
26113@@ -30,57 +32,125 @@
26114 * as they get called from within inline assembly.
26115 */
26116
26117-#define ENTER CFI_STARTPROC ; \
26118- GET_THREAD_INFO(%_ASM_BX)
26119-#define EXIT ASM_CLAC ; \
26120- ret ; \
26121+#define ENTER CFI_STARTPROC
26122+#define EXIT ASM_CLAC ; \
26123+ pax_force_retaddr ; \
26124+ ret ; \
26125 CFI_ENDPROC
26126
26127+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26128+#define _DEST %_ASM_CX,%_ASM_BX
26129+#else
26130+#define _DEST %_ASM_CX
26131+#endif
26132+
26133+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26134+#define __copyuser_seg gs;
26135+#else
26136+#define __copyuser_seg
26137+#endif
26138+
26139 .text
26140 ENTRY(__put_user_1)
26141 ENTER
26142+
26143+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26144+ GET_THREAD_INFO(%_ASM_BX)
26145 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
26146 jae bad_put_user
26147 ASM_STAC
26148-1: movb %al,(%_ASM_CX)
26149+
26150+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26151+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26152+ cmp %_ASM_BX,%_ASM_CX
26153+ jb 1234f
26154+ xor %ebx,%ebx
26155+1234:
26156+#endif
26157+
26158+#endif
26159+
26160+1: __copyuser_seg movb %al,(_DEST)
26161 xor %eax,%eax
26162 EXIT
26163 ENDPROC(__put_user_1)
26164
26165 ENTRY(__put_user_2)
26166 ENTER
26167+
26168+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26169+ GET_THREAD_INFO(%_ASM_BX)
26170 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26171 sub $1,%_ASM_BX
26172 cmp %_ASM_BX,%_ASM_CX
26173 jae bad_put_user
26174 ASM_STAC
26175-2: movw %ax,(%_ASM_CX)
26176+
26177+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26178+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26179+ cmp %_ASM_BX,%_ASM_CX
26180+ jb 1234f
26181+ xor %ebx,%ebx
26182+1234:
26183+#endif
26184+
26185+#endif
26186+
26187+2: __copyuser_seg movw %ax,(_DEST)
26188 xor %eax,%eax
26189 EXIT
26190 ENDPROC(__put_user_2)
26191
26192 ENTRY(__put_user_4)
26193 ENTER
26194+
26195+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26196+ GET_THREAD_INFO(%_ASM_BX)
26197 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26198 sub $3,%_ASM_BX
26199 cmp %_ASM_BX,%_ASM_CX
26200 jae bad_put_user
26201 ASM_STAC
26202-3: movl %eax,(%_ASM_CX)
26203+
26204+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26205+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26206+ cmp %_ASM_BX,%_ASM_CX
26207+ jb 1234f
26208+ xor %ebx,%ebx
26209+1234:
26210+#endif
26211+
26212+#endif
26213+
26214+3: __copyuser_seg movl %eax,(_DEST)
26215 xor %eax,%eax
26216 EXIT
26217 ENDPROC(__put_user_4)
26218
26219 ENTRY(__put_user_8)
26220 ENTER
26221+
26222+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26223+ GET_THREAD_INFO(%_ASM_BX)
26224 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26225 sub $7,%_ASM_BX
26226 cmp %_ASM_BX,%_ASM_CX
26227 jae bad_put_user
26228 ASM_STAC
26229-4: mov %_ASM_AX,(%_ASM_CX)
26230+
26231+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26232+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26233+ cmp %_ASM_BX,%_ASM_CX
26234+ jb 1234f
26235+ xor %ebx,%ebx
26236+1234:
26237+#endif
26238+
26239+#endif
26240+
26241+4: __copyuser_seg mov %_ASM_AX,(_DEST)
26242 #ifdef CONFIG_X86_32
26243-5: movl %edx,4(%_ASM_CX)
26244+5: __copyuser_seg movl %edx,4(_DEST)
26245 #endif
26246 xor %eax,%eax
26247 EXIT
26248diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
26249index 1cad221..de671ee 100644
26250--- a/arch/x86/lib/rwlock.S
26251+++ b/arch/x86/lib/rwlock.S
26252@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
26253 FRAME
26254 0: LOCK_PREFIX
26255 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26256+
26257+#ifdef CONFIG_PAX_REFCOUNT
26258+ jno 1234f
26259+ LOCK_PREFIX
26260+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26261+ int $4
26262+1234:
26263+ _ASM_EXTABLE(1234b, 1234b)
26264+#endif
26265+
26266 1: rep; nop
26267 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
26268 jne 1b
26269 LOCK_PREFIX
26270 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26271+
26272+#ifdef CONFIG_PAX_REFCOUNT
26273+ jno 1234f
26274+ LOCK_PREFIX
26275+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26276+ int $4
26277+1234:
26278+ _ASM_EXTABLE(1234b, 1234b)
26279+#endif
26280+
26281 jnz 0b
26282 ENDFRAME
26283+ pax_force_retaddr
26284 ret
26285 CFI_ENDPROC
26286 END(__write_lock_failed)
26287@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
26288 FRAME
26289 0: LOCK_PREFIX
26290 READ_LOCK_SIZE(inc) (%__lock_ptr)
26291+
26292+#ifdef CONFIG_PAX_REFCOUNT
26293+ jno 1234f
26294+ LOCK_PREFIX
26295+ READ_LOCK_SIZE(dec) (%__lock_ptr)
26296+ int $4
26297+1234:
26298+ _ASM_EXTABLE(1234b, 1234b)
26299+#endif
26300+
26301 1: rep; nop
26302 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
26303 js 1b
26304 LOCK_PREFIX
26305 READ_LOCK_SIZE(dec) (%__lock_ptr)
26306+
26307+#ifdef CONFIG_PAX_REFCOUNT
26308+ jno 1234f
26309+ LOCK_PREFIX
26310+ READ_LOCK_SIZE(inc) (%__lock_ptr)
26311+ int $4
26312+1234:
26313+ _ASM_EXTABLE(1234b, 1234b)
26314+#endif
26315+
26316 js 0b
26317 ENDFRAME
26318+ pax_force_retaddr
26319 ret
26320 CFI_ENDPROC
26321 END(__read_lock_failed)
26322diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
26323index 5dff5f0..cadebf4 100644
26324--- a/arch/x86/lib/rwsem.S
26325+++ b/arch/x86/lib/rwsem.S
26326@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
26327 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26328 CFI_RESTORE __ASM_REG(dx)
26329 restore_common_regs
26330+ pax_force_retaddr
26331 ret
26332 CFI_ENDPROC
26333 ENDPROC(call_rwsem_down_read_failed)
26334@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
26335 movq %rax,%rdi
26336 call rwsem_down_write_failed
26337 restore_common_regs
26338+ pax_force_retaddr
26339 ret
26340 CFI_ENDPROC
26341 ENDPROC(call_rwsem_down_write_failed)
26342@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
26343 movq %rax,%rdi
26344 call rwsem_wake
26345 restore_common_regs
26346-1: ret
26347+1: pax_force_retaddr
26348+ ret
26349 CFI_ENDPROC
26350 ENDPROC(call_rwsem_wake)
26351
26352@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
26353 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26354 CFI_RESTORE __ASM_REG(dx)
26355 restore_common_regs
26356+ pax_force_retaddr
26357 ret
26358 CFI_ENDPROC
26359 ENDPROC(call_rwsem_downgrade_wake)
26360diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
26361index a63efd6..ccecad8 100644
26362--- a/arch/x86/lib/thunk_64.S
26363+++ b/arch/x86/lib/thunk_64.S
26364@@ -8,6 +8,7 @@
26365 #include <linux/linkage.h>
26366 #include <asm/dwarf2.h>
26367 #include <asm/calling.h>
26368+#include <asm/alternative-asm.h>
26369
26370 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
26371 .macro THUNK name, func, put_ret_addr_in_rdi=0
26372@@ -41,5 +42,6 @@
26373 SAVE_ARGS
26374 restore:
26375 RESTORE_ARGS
26376+ pax_force_retaddr
26377 ret
26378 CFI_ENDPROC
26379diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
26380index f0312d7..9c39d63 100644
26381--- a/arch/x86/lib/usercopy_32.c
26382+++ b/arch/x86/lib/usercopy_32.c
26383@@ -42,11 +42,13 @@ do { \
26384 int __d0; \
26385 might_fault(); \
26386 __asm__ __volatile__( \
26387+ __COPYUSER_SET_ES \
26388 ASM_STAC "\n" \
26389 "0: rep; stosl\n" \
26390 " movl %2,%0\n" \
26391 "1: rep; stosb\n" \
26392 "2: " ASM_CLAC "\n" \
26393+ __COPYUSER_RESTORE_ES \
26394 ".section .fixup,\"ax\"\n" \
26395 "3: lea 0(%2,%0,4),%0\n" \
26396 " jmp 2b\n" \
26397@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
26398
26399 #ifdef CONFIG_X86_INTEL_USERCOPY
26400 static unsigned long
26401-__copy_user_intel(void __user *to, const void *from, unsigned long size)
26402+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
26403 {
26404 int d0, d1;
26405 __asm__ __volatile__(
26406@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26407 " .align 2,0x90\n"
26408 "3: movl 0(%4), %%eax\n"
26409 "4: movl 4(%4), %%edx\n"
26410- "5: movl %%eax, 0(%3)\n"
26411- "6: movl %%edx, 4(%3)\n"
26412+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
26413+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
26414 "7: movl 8(%4), %%eax\n"
26415 "8: movl 12(%4),%%edx\n"
26416- "9: movl %%eax, 8(%3)\n"
26417- "10: movl %%edx, 12(%3)\n"
26418+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
26419+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
26420 "11: movl 16(%4), %%eax\n"
26421 "12: movl 20(%4), %%edx\n"
26422- "13: movl %%eax, 16(%3)\n"
26423- "14: movl %%edx, 20(%3)\n"
26424+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
26425+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
26426 "15: movl 24(%4), %%eax\n"
26427 "16: movl 28(%4), %%edx\n"
26428- "17: movl %%eax, 24(%3)\n"
26429- "18: movl %%edx, 28(%3)\n"
26430+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
26431+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
26432 "19: movl 32(%4), %%eax\n"
26433 "20: movl 36(%4), %%edx\n"
26434- "21: movl %%eax, 32(%3)\n"
26435- "22: movl %%edx, 36(%3)\n"
26436+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
26437+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
26438 "23: movl 40(%4), %%eax\n"
26439 "24: movl 44(%4), %%edx\n"
26440- "25: movl %%eax, 40(%3)\n"
26441- "26: movl %%edx, 44(%3)\n"
26442+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
26443+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
26444 "27: movl 48(%4), %%eax\n"
26445 "28: movl 52(%4), %%edx\n"
26446- "29: movl %%eax, 48(%3)\n"
26447- "30: movl %%edx, 52(%3)\n"
26448+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
26449+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
26450 "31: movl 56(%4), %%eax\n"
26451 "32: movl 60(%4), %%edx\n"
26452- "33: movl %%eax, 56(%3)\n"
26453- "34: movl %%edx, 60(%3)\n"
26454+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
26455+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
26456 " addl $-64, %0\n"
26457 " addl $64, %4\n"
26458 " addl $64, %3\n"
26459@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26460 " shrl $2, %0\n"
26461 " andl $3, %%eax\n"
26462 " cld\n"
26463+ __COPYUSER_SET_ES
26464 "99: rep; movsl\n"
26465 "36: movl %%eax, %0\n"
26466 "37: rep; movsb\n"
26467 "100:\n"
26468+ __COPYUSER_RESTORE_ES
26469 ".section .fixup,\"ax\"\n"
26470 "101: lea 0(%%eax,%0,4),%0\n"
26471 " jmp 100b\n"
26472@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26473 }
26474
26475 static unsigned long
26476+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
26477+{
26478+ int d0, d1;
26479+ __asm__ __volatile__(
26480+ " .align 2,0x90\n"
26481+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
26482+ " cmpl $67, %0\n"
26483+ " jbe 3f\n"
26484+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
26485+ " .align 2,0x90\n"
26486+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
26487+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
26488+ "5: movl %%eax, 0(%3)\n"
26489+ "6: movl %%edx, 4(%3)\n"
26490+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
26491+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
26492+ "9: movl %%eax, 8(%3)\n"
26493+ "10: movl %%edx, 12(%3)\n"
26494+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
26495+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
26496+ "13: movl %%eax, 16(%3)\n"
26497+ "14: movl %%edx, 20(%3)\n"
26498+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
26499+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
26500+ "17: movl %%eax, 24(%3)\n"
26501+ "18: movl %%edx, 28(%3)\n"
26502+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
26503+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
26504+ "21: movl %%eax, 32(%3)\n"
26505+ "22: movl %%edx, 36(%3)\n"
26506+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
26507+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
26508+ "25: movl %%eax, 40(%3)\n"
26509+ "26: movl %%edx, 44(%3)\n"
26510+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
26511+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
26512+ "29: movl %%eax, 48(%3)\n"
26513+ "30: movl %%edx, 52(%3)\n"
26514+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
26515+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
26516+ "33: movl %%eax, 56(%3)\n"
26517+ "34: movl %%edx, 60(%3)\n"
26518+ " addl $-64, %0\n"
26519+ " addl $64, %4\n"
26520+ " addl $64, %3\n"
26521+ " cmpl $63, %0\n"
26522+ " ja 1b\n"
26523+ "35: movl %0, %%eax\n"
26524+ " shrl $2, %0\n"
26525+ " andl $3, %%eax\n"
26526+ " cld\n"
26527+ "99: rep; "__copyuser_seg" movsl\n"
26528+ "36: movl %%eax, %0\n"
26529+ "37: rep; "__copyuser_seg" movsb\n"
26530+ "100:\n"
26531+ ".section .fixup,\"ax\"\n"
26532+ "101: lea 0(%%eax,%0,4),%0\n"
26533+ " jmp 100b\n"
26534+ ".previous\n"
26535+ _ASM_EXTABLE(1b,100b)
26536+ _ASM_EXTABLE(2b,100b)
26537+ _ASM_EXTABLE(3b,100b)
26538+ _ASM_EXTABLE(4b,100b)
26539+ _ASM_EXTABLE(5b,100b)
26540+ _ASM_EXTABLE(6b,100b)
26541+ _ASM_EXTABLE(7b,100b)
26542+ _ASM_EXTABLE(8b,100b)
26543+ _ASM_EXTABLE(9b,100b)
26544+ _ASM_EXTABLE(10b,100b)
26545+ _ASM_EXTABLE(11b,100b)
26546+ _ASM_EXTABLE(12b,100b)
26547+ _ASM_EXTABLE(13b,100b)
26548+ _ASM_EXTABLE(14b,100b)
26549+ _ASM_EXTABLE(15b,100b)
26550+ _ASM_EXTABLE(16b,100b)
26551+ _ASM_EXTABLE(17b,100b)
26552+ _ASM_EXTABLE(18b,100b)
26553+ _ASM_EXTABLE(19b,100b)
26554+ _ASM_EXTABLE(20b,100b)
26555+ _ASM_EXTABLE(21b,100b)
26556+ _ASM_EXTABLE(22b,100b)
26557+ _ASM_EXTABLE(23b,100b)
26558+ _ASM_EXTABLE(24b,100b)
26559+ _ASM_EXTABLE(25b,100b)
26560+ _ASM_EXTABLE(26b,100b)
26561+ _ASM_EXTABLE(27b,100b)
26562+ _ASM_EXTABLE(28b,100b)
26563+ _ASM_EXTABLE(29b,100b)
26564+ _ASM_EXTABLE(30b,100b)
26565+ _ASM_EXTABLE(31b,100b)
26566+ _ASM_EXTABLE(32b,100b)
26567+ _ASM_EXTABLE(33b,100b)
26568+ _ASM_EXTABLE(34b,100b)
26569+ _ASM_EXTABLE(35b,100b)
26570+ _ASM_EXTABLE(36b,100b)
26571+ _ASM_EXTABLE(37b,100b)
26572+ _ASM_EXTABLE(99b,101b)
26573+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
26574+ : "1"(to), "2"(from), "0"(size)
26575+ : "eax", "edx", "memory");
26576+ return size;
26577+}
26578+
26579+static unsigned long __size_overflow(3)
26580 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26581 {
26582 int d0, d1;
26583 __asm__ __volatile__(
26584 " .align 2,0x90\n"
26585- "0: movl 32(%4), %%eax\n"
26586+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26587 " cmpl $67, %0\n"
26588 " jbe 2f\n"
26589- "1: movl 64(%4), %%eax\n"
26590+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26591 " .align 2,0x90\n"
26592- "2: movl 0(%4), %%eax\n"
26593- "21: movl 4(%4), %%edx\n"
26594+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26595+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26596 " movl %%eax, 0(%3)\n"
26597 " movl %%edx, 4(%3)\n"
26598- "3: movl 8(%4), %%eax\n"
26599- "31: movl 12(%4),%%edx\n"
26600+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26601+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26602 " movl %%eax, 8(%3)\n"
26603 " movl %%edx, 12(%3)\n"
26604- "4: movl 16(%4), %%eax\n"
26605- "41: movl 20(%4), %%edx\n"
26606+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26607+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26608 " movl %%eax, 16(%3)\n"
26609 " movl %%edx, 20(%3)\n"
26610- "10: movl 24(%4), %%eax\n"
26611- "51: movl 28(%4), %%edx\n"
26612+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26613+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26614 " movl %%eax, 24(%3)\n"
26615 " movl %%edx, 28(%3)\n"
26616- "11: movl 32(%4), %%eax\n"
26617- "61: movl 36(%4), %%edx\n"
26618+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26619+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26620 " movl %%eax, 32(%3)\n"
26621 " movl %%edx, 36(%3)\n"
26622- "12: movl 40(%4), %%eax\n"
26623- "71: movl 44(%4), %%edx\n"
26624+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26625+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26626 " movl %%eax, 40(%3)\n"
26627 " movl %%edx, 44(%3)\n"
26628- "13: movl 48(%4), %%eax\n"
26629- "81: movl 52(%4), %%edx\n"
26630+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26631+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26632 " movl %%eax, 48(%3)\n"
26633 " movl %%edx, 52(%3)\n"
26634- "14: movl 56(%4), %%eax\n"
26635- "91: movl 60(%4), %%edx\n"
26636+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26637+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26638 " movl %%eax, 56(%3)\n"
26639 " movl %%edx, 60(%3)\n"
26640 " addl $-64, %0\n"
26641@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26642 " shrl $2, %0\n"
26643 " andl $3, %%eax\n"
26644 " cld\n"
26645- "6: rep; movsl\n"
26646+ "6: rep; "__copyuser_seg" movsl\n"
26647 " movl %%eax,%0\n"
26648- "7: rep; movsb\n"
26649+ "7: rep; "__copyuser_seg" movsb\n"
26650 "8:\n"
26651 ".section .fixup,\"ax\"\n"
26652 "9: lea 0(%%eax,%0,4),%0\n"
26653@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26654 * hyoshiok@miraclelinux.com
26655 */
26656
26657-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26658+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
26659 const void __user *from, unsigned long size)
26660 {
26661 int d0, d1;
26662
26663 __asm__ __volatile__(
26664 " .align 2,0x90\n"
26665- "0: movl 32(%4), %%eax\n"
26666+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26667 " cmpl $67, %0\n"
26668 " jbe 2f\n"
26669- "1: movl 64(%4), %%eax\n"
26670+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26671 " .align 2,0x90\n"
26672- "2: movl 0(%4), %%eax\n"
26673- "21: movl 4(%4), %%edx\n"
26674+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26675+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26676 " movnti %%eax, 0(%3)\n"
26677 " movnti %%edx, 4(%3)\n"
26678- "3: movl 8(%4), %%eax\n"
26679- "31: movl 12(%4),%%edx\n"
26680+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26681+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26682 " movnti %%eax, 8(%3)\n"
26683 " movnti %%edx, 12(%3)\n"
26684- "4: movl 16(%4), %%eax\n"
26685- "41: movl 20(%4), %%edx\n"
26686+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26687+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26688 " movnti %%eax, 16(%3)\n"
26689 " movnti %%edx, 20(%3)\n"
26690- "10: movl 24(%4), %%eax\n"
26691- "51: movl 28(%4), %%edx\n"
26692+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26693+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26694 " movnti %%eax, 24(%3)\n"
26695 " movnti %%edx, 28(%3)\n"
26696- "11: movl 32(%4), %%eax\n"
26697- "61: movl 36(%4), %%edx\n"
26698+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26699+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26700 " movnti %%eax, 32(%3)\n"
26701 " movnti %%edx, 36(%3)\n"
26702- "12: movl 40(%4), %%eax\n"
26703- "71: movl 44(%4), %%edx\n"
26704+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26705+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26706 " movnti %%eax, 40(%3)\n"
26707 " movnti %%edx, 44(%3)\n"
26708- "13: movl 48(%4), %%eax\n"
26709- "81: movl 52(%4), %%edx\n"
26710+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26711+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26712 " movnti %%eax, 48(%3)\n"
26713 " movnti %%edx, 52(%3)\n"
26714- "14: movl 56(%4), %%eax\n"
26715- "91: movl 60(%4), %%edx\n"
26716+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26717+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26718 " movnti %%eax, 56(%3)\n"
26719 " movnti %%edx, 60(%3)\n"
26720 " addl $-64, %0\n"
26721@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26722 " shrl $2, %0\n"
26723 " andl $3, %%eax\n"
26724 " cld\n"
26725- "6: rep; movsl\n"
26726+ "6: rep; "__copyuser_seg" movsl\n"
26727 " movl %%eax,%0\n"
26728- "7: rep; movsb\n"
26729+ "7: rep; "__copyuser_seg" movsb\n"
26730 "8:\n"
26731 ".section .fixup,\"ax\"\n"
26732 "9: lea 0(%%eax,%0,4),%0\n"
26733@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26734 return size;
26735 }
26736
26737-static unsigned long __copy_user_intel_nocache(void *to,
26738+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
26739 const void __user *from, unsigned long size)
26740 {
26741 int d0, d1;
26742
26743 __asm__ __volatile__(
26744 " .align 2,0x90\n"
26745- "0: movl 32(%4), %%eax\n"
26746+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26747 " cmpl $67, %0\n"
26748 " jbe 2f\n"
26749- "1: movl 64(%4), %%eax\n"
26750+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26751 " .align 2,0x90\n"
26752- "2: movl 0(%4), %%eax\n"
26753- "21: movl 4(%4), %%edx\n"
26754+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26755+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26756 " movnti %%eax, 0(%3)\n"
26757 " movnti %%edx, 4(%3)\n"
26758- "3: movl 8(%4), %%eax\n"
26759- "31: movl 12(%4),%%edx\n"
26760+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26761+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26762 " movnti %%eax, 8(%3)\n"
26763 " movnti %%edx, 12(%3)\n"
26764- "4: movl 16(%4), %%eax\n"
26765- "41: movl 20(%4), %%edx\n"
26766+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26767+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26768 " movnti %%eax, 16(%3)\n"
26769 " movnti %%edx, 20(%3)\n"
26770- "10: movl 24(%4), %%eax\n"
26771- "51: movl 28(%4), %%edx\n"
26772+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26773+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26774 " movnti %%eax, 24(%3)\n"
26775 " movnti %%edx, 28(%3)\n"
26776- "11: movl 32(%4), %%eax\n"
26777- "61: movl 36(%4), %%edx\n"
26778+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26779+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26780 " movnti %%eax, 32(%3)\n"
26781 " movnti %%edx, 36(%3)\n"
26782- "12: movl 40(%4), %%eax\n"
26783- "71: movl 44(%4), %%edx\n"
26784+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26785+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26786 " movnti %%eax, 40(%3)\n"
26787 " movnti %%edx, 44(%3)\n"
26788- "13: movl 48(%4), %%eax\n"
26789- "81: movl 52(%4), %%edx\n"
26790+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26791+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26792 " movnti %%eax, 48(%3)\n"
26793 " movnti %%edx, 52(%3)\n"
26794- "14: movl 56(%4), %%eax\n"
26795- "91: movl 60(%4), %%edx\n"
26796+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26797+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26798 " movnti %%eax, 56(%3)\n"
26799 " movnti %%edx, 60(%3)\n"
26800 " addl $-64, %0\n"
26801@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26802 " shrl $2, %0\n"
26803 " andl $3, %%eax\n"
26804 " cld\n"
26805- "6: rep; movsl\n"
26806+ "6: rep; "__copyuser_seg" movsl\n"
26807 " movl %%eax,%0\n"
26808- "7: rep; movsb\n"
26809+ "7: rep; "__copyuser_seg" movsb\n"
26810 "8:\n"
26811 ".section .fixup,\"ax\"\n"
26812 "9: lea 0(%%eax,%0,4),%0\n"
26813@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26814 */
26815 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26816 unsigned long size);
26817-unsigned long __copy_user_intel(void __user *to, const void *from,
26818+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26819+ unsigned long size);
26820+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
26821 unsigned long size);
26822 unsigned long __copy_user_zeroing_intel_nocache(void *to,
26823 const void __user *from, unsigned long size);
26824 #endif /* CONFIG_X86_INTEL_USERCOPY */
26825
26826 /* Generic arbitrary sized copy. */
26827-#define __copy_user(to, from, size) \
26828+#define __copy_user(to, from, size, prefix, set, restore) \
26829 do { \
26830 int __d0, __d1, __d2; \
26831 __asm__ __volatile__( \
26832+ set \
26833 " cmp $7,%0\n" \
26834 " jbe 1f\n" \
26835 " movl %1,%0\n" \
26836 " negl %0\n" \
26837 " andl $7,%0\n" \
26838 " subl %0,%3\n" \
26839- "4: rep; movsb\n" \
26840+ "4: rep; "prefix"movsb\n" \
26841 " movl %3,%0\n" \
26842 " shrl $2,%0\n" \
26843 " andl $3,%3\n" \
26844 " .align 2,0x90\n" \
26845- "0: rep; movsl\n" \
26846+ "0: rep; "prefix"movsl\n" \
26847 " movl %3,%0\n" \
26848- "1: rep; movsb\n" \
26849+ "1: rep; "prefix"movsb\n" \
26850 "2:\n" \
26851+ restore \
26852 ".section .fixup,\"ax\"\n" \
26853 "5: addl %3,%0\n" \
26854 " jmp 2b\n" \
26855@@ -538,14 +650,14 @@ do { \
26856 " negl %0\n" \
26857 " andl $7,%0\n" \
26858 " subl %0,%3\n" \
26859- "4: rep; movsb\n" \
26860+ "4: rep; "__copyuser_seg"movsb\n" \
26861 " movl %3,%0\n" \
26862 " shrl $2,%0\n" \
26863 " andl $3,%3\n" \
26864 " .align 2,0x90\n" \
26865- "0: rep; movsl\n" \
26866+ "0: rep; "__copyuser_seg"movsl\n" \
26867 " movl %3,%0\n" \
26868- "1: rep; movsb\n" \
26869+ "1: rep; "__copyuser_seg"movsb\n" \
26870 "2:\n" \
26871 ".section .fixup,\"ax\"\n" \
26872 "5: addl %3,%0\n" \
26873@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
26874 {
26875 stac();
26876 if (movsl_is_ok(to, from, n))
26877- __copy_user(to, from, n);
26878+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
26879 else
26880- n = __copy_user_intel(to, from, n);
26881+ n = __generic_copy_to_user_intel(to, from, n);
26882 clac();
26883 return n;
26884 }
26885@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
26886 {
26887 stac();
26888 if (movsl_is_ok(to, from, n))
26889- __copy_user(to, from, n);
26890+ __copy_user(to, from, n, __copyuser_seg, "", "");
26891 else
26892- n = __copy_user_intel((void __user *)to,
26893- (const void *)from, n);
26894+ n = __generic_copy_from_user_intel(to, from, n);
26895 clac();
26896 return n;
26897 }
26898@@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
26899 if (n > 64 && cpu_has_xmm2)
26900 n = __copy_user_intel_nocache(to, from, n);
26901 else
26902- __copy_user(to, from, n);
26903+ __copy_user(to, from, n, __copyuser_seg, "", "");
26904 #else
26905- __copy_user(to, from, n);
26906+ __copy_user(to, from, n, __copyuser_seg, "", "");
26907 #endif
26908 clac();
26909 return n;
26910 }
26911 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
26912
26913-/**
26914- * copy_to_user: - Copy a block of data into user space.
26915- * @to: Destination address, in user space.
26916- * @from: Source address, in kernel space.
26917- * @n: Number of bytes to copy.
26918- *
26919- * Context: User context only. This function may sleep.
26920- *
26921- * Copy data from kernel space to user space.
26922- *
26923- * Returns number of bytes that could not be copied.
26924- * On success, this will be zero.
26925- */
26926-unsigned long
26927-copy_to_user(void __user *to, const void *from, unsigned long n)
26928-{
26929- if (access_ok(VERIFY_WRITE, to, n))
26930- n = __copy_to_user(to, from, n);
26931- return n;
26932-}
26933-EXPORT_SYMBOL(copy_to_user);
26934-
26935-/**
26936- * copy_from_user: - Copy a block of data from user space.
26937- * @to: Destination address, in kernel space.
26938- * @from: Source address, in user space.
26939- * @n: Number of bytes to copy.
26940- *
26941- * Context: User context only. This function may sleep.
26942- *
26943- * Copy data from user space to kernel space.
26944- *
26945- * Returns number of bytes that could not be copied.
26946- * On success, this will be zero.
26947- *
26948- * If some data could not be copied, this function will pad the copied
26949- * data to the requested size using zero bytes.
26950- */
26951-unsigned long
26952-_copy_from_user(void *to, const void __user *from, unsigned long n)
26953-{
26954- if (access_ok(VERIFY_READ, from, n))
26955- n = __copy_from_user(to, from, n);
26956- else
26957- memset(to, 0, n);
26958- return n;
26959-}
26960-EXPORT_SYMBOL(_copy_from_user);
26961-
26962 void copy_from_user_overflow(void)
26963 {
26964 WARN(1, "Buffer overflow detected!\n");
26965 }
26966 EXPORT_SYMBOL(copy_from_user_overflow);
26967+
26968+void copy_to_user_overflow(void)
26969+{
26970+ WARN(1, "Buffer overflow detected!\n");
26971+}
26972+EXPORT_SYMBOL(copy_to_user_overflow);
26973+
26974+#ifdef CONFIG_PAX_MEMORY_UDEREF
26975+void __set_fs(mm_segment_t x)
26976+{
26977+ switch (x.seg) {
26978+ case 0:
26979+ loadsegment(gs, 0);
26980+ break;
26981+ case TASK_SIZE_MAX:
26982+ loadsegment(gs, __USER_DS);
26983+ break;
26984+ case -1UL:
26985+ loadsegment(gs, __KERNEL_DS);
26986+ break;
26987+ default:
26988+ BUG();
26989+ }
26990+ return;
26991+}
26992+EXPORT_SYMBOL(__set_fs);
26993+
26994+void set_fs(mm_segment_t x)
26995+{
26996+ current_thread_info()->addr_limit = x;
26997+ __set_fs(x);
26998+}
26999+EXPORT_SYMBOL(set_fs);
27000+#endif
27001diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
27002index 906fea3..ee8a097 100644
27003--- a/arch/x86/lib/usercopy_64.c
27004+++ b/arch/x86/lib/usercopy_64.c
27005@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
27006 _ASM_EXTABLE(0b,3b)
27007 _ASM_EXTABLE(1b,2b)
27008 : [size8] "=&c"(size), [dst] "=&D" (__d0)
27009- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
27010+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
27011 [zero] "r" (0UL), [eight] "r" (8UL));
27012 clac();
27013 return size;
27014@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
27015 }
27016 EXPORT_SYMBOL(clear_user);
27017
27018-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
27019+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
27020 {
27021- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
27022- return copy_user_generic((__force void *)to, (__force void *)from, len);
27023- }
27024- return len;
27025+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
27026+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
27027+ return len;
27028 }
27029 EXPORT_SYMBOL(copy_in_user);
27030
27031@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
27032 * it is not necessary to optimize tail handling.
27033 */
27034 unsigned long
27035-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27036+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
27037 {
27038 char c;
27039 unsigned zero_len;
27040@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27041 clac();
27042 return len;
27043 }
27044+
27045+void copy_from_user_overflow(void)
27046+{
27047+ WARN(1, "Buffer overflow detected!\n");
27048+}
27049+EXPORT_SYMBOL(copy_from_user_overflow);
27050+
27051+void copy_to_user_overflow(void)
27052+{
27053+ WARN(1, "Buffer overflow detected!\n");
27054+}
27055+EXPORT_SYMBOL(copy_to_user_overflow);
27056diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
27057index 903ec1e..c4166b2 100644
27058--- a/arch/x86/mm/extable.c
27059+++ b/arch/x86/mm/extable.c
27060@@ -6,12 +6,24 @@
27061 static inline unsigned long
27062 ex_insn_addr(const struct exception_table_entry *x)
27063 {
27064- return (unsigned long)&x->insn + x->insn;
27065+ unsigned long reloc = 0;
27066+
27067+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27068+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27069+#endif
27070+
27071+ return (unsigned long)&x->insn + x->insn + reloc;
27072 }
27073 static inline unsigned long
27074 ex_fixup_addr(const struct exception_table_entry *x)
27075 {
27076- return (unsigned long)&x->fixup + x->fixup;
27077+ unsigned long reloc = 0;
27078+
27079+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27080+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27081+#endif
27082+
27083+ return (unsigned long)&x->fixup + x->fixup + reloc;
27084 }
27085
27086 int fixup_exception(struct pt_regs *regs)
27087@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
27088 unsigned long new_ip;
27089
27090 #ifdef CONFIG_PNPBIOS
27091- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
27092+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
27093 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
27094 extern u32 pnp_bios_is_utter_crap;
27095 pnp_bios_is_utter_crap = 1;
27096@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
27097 i += 4;
27098 p->fixup -= i;
27099 i += 4;
27100+
27101+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27102+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
27103+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27104+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27105+#endif
27106+
27107 }
27108 }
27109
27110diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
27111index fb674fd..223a693 100644
27112--- a/arch/x86/mm/fault.c
27113+++ b/arch/x86/mm/fault.c
27114@@ -13,12 +13,19 @@
27115 #include <linux/perf_event.h> /* perf_sw_event */
27116 #include <linux/hugetlb.h> /* hstate_index_to_shift */
27117 #include <linux/prefetch.h> /* prefetchw */
27118+#include <linux/unistd.h>
27119+#include <linux/compiler.h>
27120
27121 #include <asm/traps.h> /* dotraplinkage, ... */
27122 #include <asm/pgalloc.h> /* pgd_*(), ... */
27123 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
27124 #include <asm/fixmap.h> /* VSYSCALL_START */
27125 #include <asm/context_tracking.h> /* exception_enter(), ... */
27126+#include <asm/tlbflush.h>
27127+
27128+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27129+#include <asm/stacktrace.h>
27130+#endif
27131
27132 /*
27133 * Page fault error code bits:
27134@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
27135 int ret = 0;
27136
27137 /* kprobe_running() needs smp_processor_id() */
27138- if (kprobes_built_in() && !user_mode_vm(regs)) {
27139+ if (kprobes_built_in() && !user_mode(regs)) {
27140 preempt_disable();
27141 if (kprobe_running() && kprobe_fault_handler(regs, 14))
27142 ret = 1;
27143@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
27144 return !instr_lo || (instr_lo>>1) == 1;
27145 case 0x00:
27146 /* Prefetch instruction is 0x0F0D or 0x0F18 */
27147- if (probe_kernel_address(instr, opcode))
27148+ if (user_mode(regs)) {
27149+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27150+ return 0;
27151+ } else if (probe_kernel_address(instr, opcode))
27152 return 0;
27153
27154 *prefetch = (instr_lo == 0xF) &&
27155@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
27156 while (instr < max_instr) {
27157 unsigned char opcode;
27158
27159- if (probe_kernel_address(instr, opcode))
27160+ if (user_mode(regs)) {
27161+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27162+ break;
27163+ } else if (probe_kernel_address(instr, opcode))
27164 break;
27165
27166 instr++;
27167@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
27168 force_sig_info(si_signo, &info, tsk);
27169 }
27170
27171+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27172+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
27173+#endif
27174+
27175+#ifdef CONFIG_PAX_EMUTRAMP
27176+static int pax_handle_fetch_fault(struct pt_regs *regs);
27177+#endif
27178+
27179+#ifdef CONFIG_PAX_PAGEEXEC
27180+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
27181+{
27182+ pgd_t *pgd;
27183+ pud_t *pud;
27184+ pmd_t *pmd;
27185+
27186+ pgd = pgd_offset(mm, address);
27187+ if (!pgd_present(*pgd))
27188+ return NULL;
27189+ pud = pud_offset(pgd, address);
27190+ if (!pud_present(*pud))
27191+ return NULL;
27192+ pmd = pmd_offset(pud, address);
27193+ if (!pmd_present(*pmd))
27194+ return NULL;
27195+ return pmd;
27196+}
27197+#endif
27198+
27199 DEFINE_SPINLOCK(pgd_lock);
27200 LIST_HEAD(pgd_list);
27201
27202@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
27203 for (address = VMALLOC_START & PMD_MASK;
27204 address >= TASK_SIZE && address < FIXADDR_TOP;
27205 address += PMD_SIZE) {
27206+
27207+#ifdef CONFIG_PAX_PER_CPU_PGD
27208+ unsigned long cpu;
27209+#else
27210 struct page *page;
27211+#endif
27212
27213 spin_lock(&pgd_lock);
27214+
27215+#ifdef CONFIG_PAX_PER_CPU_PGD
27216+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27217+ pgd_t *pgd = get_cpu_pgd(cpu);
27218+ pmd_t *ret;
27219+#else
27220 list_for_each_entry(page, &pgd_list, lru) {
27221+ pgd_t *pgd;
27222 spinlock_t *pgt_lock;
27223 pmd_t *ret;
27224
27225@@ -243,8 +296,14 @@ void vmalloc_sync_all(void)
27226 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27227
27228 spin_lock(pgt_lock);
27229- ret = vmalloc_sync_one(page_address(page), address);
27230+ pgd = page_address(page);
27231+#endif
27232+
27233+ ret = vmalloc_sync_one(pgd, address);
27234+
27235+#ifndef CONFIG_PAX_PER_CPU_PGD
27236 spin_unlock(pgt_lock);
27237+#endif
27238
27239 if (!ret)
27240 break;
27241@@ -278,6 +337,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27242 * an interrupt in the middle of a task switch..
27243 */
27244 pgd_paddr = read_cr3();
27245+
27246+#ifdef CONFIG_PAX_PER_CPU_PGD
27247+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
27248+#endif
27249+
27250 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
27251 if (!pmd_k)
27252 return -1;
27253@@ -373,7 +437,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27254 * happen within a race in page table update. In the later
27255 * case just flush:
27256 */
27257+
27258+#ifdef CONFIG_PAX_PER_CPU_PGD
27259+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
27260+ pgd = pgd_offset_cpu(smp_processor_id(), address);
27261+#else
27262 pgd = pgd_offset(current->active_mm, address);
27263+#endif
27264+
27265 pgd_ref = pgd_offset_k(address);
27266 if (pgd_none(*pgd_ref))
27267 return -1;
27268@@ -541,7 +612,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
27269 static int is_errata100(struct pt_regs *regs, unsigned long address)
27270 {
27271 #ifdef CONFIG_X86_64
27272- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
27273+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
27274 return 1;
27275 #endif
27276 return 0;
27277@@ -568,7 +639,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
27278 }
27279
27280 static const char nx_warning[] = KERN_CRIT
27281-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
27282+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
27283
27284 static void
27285 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27286@@ -577,15 +648,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27287 if (!oops_may_print())
27288 return;
27289
27290- if (error_code & PF_INSTR) {
27291+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
27292 unsigned int level;
27293
27294 pte_t *pte = lookup_address(address, &level);
27295
27296 if (pte && pte_present(*pte) && !pte_exec(*pte))
27297- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
27298+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
27299 }
27300
27301+#ifdef CONFIG_PAX_KERNEXEC
27302+ if (init_mm.start_code <= address && address < init_mm.end_code) {
27303+ if (current->signal->curr_ip)
27304+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
27305+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
27306+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27307+ else
27308+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
27309+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27310+ }
27311+#endif
27312+
27313 printk(KERN_ALERT "BUG: unable to handle kernel ");
27314 if (address < PAGE_SIZE)
27315 printk(KERN_CONT "NULL pointer dereference");
27316@@ -748,6 +831,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
27317 return;
27318 }
27319 #endif
27320+
27321+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27322+ if (pax_is_fetch_fault(regs, error_code, address)) {
27323+
27324+#ifdef CONFIG_PAX_EMUTRAMP
27325+ switch (pax_handle_fetch_fault(regs)) {
27326+ case 2:
27327+ return;
27328+ }
27329+#endif
27330+
27331+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27332+ do_group_exit(SIGKILL);
27333+ }
27334+#endif
27335+
27336 /* Kernel addresses are always protection faults: */
27337 if (address >= TASK_SIZE)
27338 error_code |= PF_PROT;
27339@@ -833,7 +932,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
27340 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
27341 printk(KERN_ERR
27342 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
27343- tsk->comm, tsk->pid, address);
27344+ tsk->comm, task_pid_nr(tsk), address);
27345 code = BUS_MCEERR_AR;
27346 }
27347 #endif
27348@@ -896,6 +995,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
27349 return 1;
27350 }
27351
27352+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27353+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
27354+{
27355+ pte_t *pte;
27356+ pmd_t *pmd;
27357+ spinlock_t *ptl;
27358+ unsigned char pte_mask;
27359+
27360+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
27361+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
27362+ return 0;
27363+
27364+ /* PaX: it's our fault, let's handle it if we can */
27365+
27366+ /* PaX: take a look at read faults before acquiring any locks */
27367+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
27368+ /* instruction fetch attempt from a protected page in user mode */
27369+ up_read(&mm->mmap_sem);
27370+
27371+#ifdef CONFIG_PAX_EMUTRAMP
27372+ switch (pax_handle_fetch_fault(regs)) {
27373+ case 2:
27374+ return 1;
27375+ }
27376+#endif
27377+
27378+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27379+ do_group_exit(SIGKILL);
27380+ }
27381+
27382+ pmd = pax_get_pmd(mm, address);
27383+ if (unlikely(!pmd))
27384+ return 0;
27385+
27386+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
27387+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
27388+ pte_unmap_unlock(pte, ptl);
27389+ return 0;
27390+ }
27391+
27392+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
27393+ /* write attempt to a protected page in user mode */
27394+ pte_unmap_unlock(pte, ptl);
27395+ return 0;
27396+ }
27397+
27398+#ifdef CONFIG_SMP
27399+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
27400+#else
27401+ if (likely(address > get_limit(regs->cs)))
27402+#endif
27403+ {
27404+ set_pte(pte, pte_mkread(*pte));
27405+ __flush_tlb_one(address);
27406+ pte_unmap_unlock(pte, ptl);
27407+ up_read(&mm->mmap_sem);
27408+ return 1;
27409+ }
27410+
27411+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
27412+
27413+ /*
27414+ * PaX: fill DTLB with user rights and retry
27415+ */
27416+ __asm__ __volatile__ (
27417+ "orb %2,(%1)\n"
27418+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
27419+/*
27420+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
27421+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
27422+ * page fault when examined during a TLB load attempt. this is true not only
27423+ * for PTEs holding a non-present entry but also present entries that will
27424+ * raise a page fault (such as those set up by PaX, or the copy-on-write
27425+ * mechanism). in effect it means that we do *not* need to flush the TLBs
27426+ * for our target pages since their PTEs are simply not in the TLBs at all.
27427+
27428+ * the best thing in omitting it is that we gain around 15-20% speed in the
27429+ * fast path of the page fault handler and can get rid of tracing since we
27430+ * can no longer flush unintended entries.
27431+ */
27432+ "invlpg (%0)\n"
27433+#endif
27434+ __copyuser_seg"testb $0,(%0)\n"
27435+ "xorb %3,(%1)\n"
27436+ :
27437+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
27438+ : "memory", "cc");
27439+ pte_unmap_unlock(pte, ptl);
27440+ up_read(&mm->mmap_sem);
27441+ return 1;
27442+}
27443+#endif
27444+
27445 /*
27446 * Handle a spurious fault caused by a stale TLB entry.
27447 *
27448@@ -968,6 +1160,9 @@ int show_unhandled_signals = 1;
27449 static inline int
27450 access_error(unsigned long error_code, struct vm_area_struct *vma)
27451 {
27452+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
27453+ return 1;
27454+
27455 if (error_code & PF_WRITE) {
27456 /* write, present and write, not present: */
27457 if (unlikely(!(vma->vm_flags & VM_WRITE)))
27458@@ -996,7 +1191,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
27459 if (error_code & PF_USER)
27460 return false;
27461
27462- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
27463+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
27464 return false;
27465
27466 return true;
27467@@ -1012,18 +1207,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27468 {
27469 struct vm_area_struct *vma;
27470 struct task_struct *tsk;
27471- unsigned long address;
27472 struct mm_struct *mm;
27473 int fault;
27474 int write = error_code & PF_WRITE;
27475 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
27476 (write ? FAULT_FLAG_WRITE : 0);
27477
27478- tsk = current;
27479- mm = tsk->mm;
27480-
27481 /* Get the faulting address: */
27482- address = read_cr2();
27483+ unsigned long address = read_cr2();
27484+
27485+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27486+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
27487+ if (!search_exception_tables(regs->ip)) {
27488+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27489+ bad_area_nosemaphore(regs, error_code, address);
27490+ return;
27491+ }
27492+ if (address < PAX_USER_SHADOW_BASE) {
27493+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27494+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
27495+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
27496+ } else
27497+ address -= PAX_USER_SHADOW_BASE;
27498+ }
27499+#endif
27500+
27501+ tsk = current;
27502+ mm = tsk->mm;
27503
27504 /*
27505 * Detect and handle instructions that would cause a page fault for
27506@@ -1084,7 +1294,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27507 * User-mode registers count as a user access even for any
27508 * potential system fault or CPU buglet:
27509 */
27510- if (user_mode_vm(regs)) {
27511+ if (user_mode(regs)) {
27512 local_irq_enable();
27513 error_code |= PF_USER;
27514 } else {
27515@@ -1146,6 +1356,11 @@ retry:
27516 might_sleep();
27517 }
27518
27519+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27520+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
27521+ return;
27522+#endif
27523+
27524 vma = find_vma(mm, address);
27525 if (unlikely(!vma)) {
27526 bad_area(regs, error_code, address);
27527@@ -1157,18 +1372,24 @@ retry:
27528 bad_area(regs, error_code, address);
27529 return;
27530 }
27531- if (error_code & PF_USER) {
27532- /*
27533- * Accessing the stack below %sp is always a bug.
27534- * The large cushion allows instructions like enter
27535- * and pusha to work. ("enter $65535, $31" pushes
27536- * 32 pointers and then decrements %sp by 65535.)
27537- */
27538- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
27539- bad_area(regs, error_code, address);
27540- return;
27541- }
27542+ /*
27543+ * Accessing the stack below %sp is always a bug.
27544+ * The large cushion allows instructions like enter
27545+ * and pusha to work. ("enter $65535, $31" pushes
27546+ * 32 pointers and then decrements %sp by 65535.)
27547+ */
27548+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
27549+ bad_area(regs, error_code, address);
27550+ return;
27551 }
27552+
27553+#ifdef CONFIG_PAX_SEGMEXEC
27554+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
27555+ bad_area(regs, error_code, address);
27556+ return;
27557+ }
27558+#endif
27559+
27560 if (unlikely(expand_stack(vma, address))) {
27561 bad_area(regs, error_code, address);
27562 return;
27563@@ -1232,3 +1453,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
27564 __do_page_fault(regs, error_code);
27565 exception_exit(regs);
27566 }
27567+
27568+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27569+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
27570+{
27571+ struct mm_struct *mm = current->mm;
27572+ unsigned long ip = regs->ip;
27573+
27574+ if (v8086_mode(regs))
27575+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
27576+
27577+#ifdef CONFIG_PAX_PAGEEXEC
27578+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
27579+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
27580+ return true;
27581+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
27582+ return true;
27583+ return false;
27584+ }
27585+#endif
27586+
27587+#ifdef CONFIG_PAX_SEGMEXEC
27588+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
27589+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
27590+ return true;
27591+ return false;
27592+ }
27593+#endif
27594+
27595+ return false;
27596+}
27597+#endif
27598+
27599+#ifdef CONFIG_PAX_EMUTRAMP
27600+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
27601+{
27602+ int err;
27603+
27604+ do { /* PaX: libffi trampoline emulation */
27605+ unsigned char mov, jmp;
27606+ unsigned int addr1, addr2;
27607+
27608+#ifdef CONFIG_X86_64
27609+ if ((regs->ip + 9) >> 32)
27610+ break;
27611+#endif
27612+
27613+ err = get_user(mov, (unsigned char __user *)regs->ip);
27614+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27615+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27616+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27617+
27618+ if (err)
27619+ break;
27620+
27621+ if (mov == 0xB8 && jmp == 0xE9) {
27622+ regs->ax = addr1;
27623+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27624+ return 2;
27625+ }
27626+ } while (0);
27627+
27628+ do { /* PaX: gcc trampoline emulation #1 */
27629+ unsigned char mov1, mov2;
27630+ unsigned short jmp;
27631+ unsigned int addr1, addr2;
27632+
27633+#ifdef CONFIG_X86_64
27634+ if ((regs->ip + 11) >> 32)
27635+ break;
27636+#endif
27637+
27638+ err = get_user(mov1, (unsigned char __user *)regs->ip);
27639+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27640+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
27641+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27642+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
27643+
27644+ if (err)
27645+ break;
27646+
27647+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
27648+ regs->cx = addr1;
27649+ regs->ax = addr2;
27650+ regs->ip = addr2;
27651+ return 2;
27652+ }
27653+ } while (0);
27654+
27655+ do { /* PaX: gcc trampoline emulation #2 */
27656+ unsigned char mov, jmp;
27657+ unsigned int addr1, addr2;
27658+
27659+#ifdef CONFIG_X86_64
27660+ if ((regs->ip + 9) >> 32)
27661+ break;
27662+#endif
27663+
27664+ err = get_user(mov, (unsigned char __user *)regs->ip);
27665+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27666+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27667+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27668+
27669+ if (err)
27670+ break;
27671+
27672+ if (mov == 0xB9 && jmp == 0xE9) {
27673+ regs->cx = addr1;
27674+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27675+ return 2;
27676+ }
27677+ } while (0);
27678+
27679+ return 1; /* PaX in action */
27680+}
27681+
27682+#ifdef CONFIG_X86_64
27683+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
27684+{
27685+ int err;
27686+
27687+ do { /* PaX: libffi trampoline emulation */
27688+ unsigned short mov1, mov2, jmp1;
27689+ unsigned char stcclc, jmp2;
27690+ unsigned long addr1, addr2;
27691+
27692+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27693+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27694+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27695+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27696+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
27697+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
27698+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
27699+
27700+ if (err)
27701+ break;
27702+
27703+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27704+ regs->r11 = addr1;
27705+ regs->r10 = addr2;
27706+ if (stcclc == 0xF8)
27707+ regs->flags &= ~X86_EFLAGS_CF;
27708+ else
27709+ regs->flags |= X86_EFLAGS_CF;
27710+ regs->ip = addr1;
27711+ return 2;
27712+ }
27713+ } while (0);
27714+
27715+ do { /* PaX: gcc trampoline emulation #1 */
27716+ unsigned short mov1, mov2, jmp1;
27717+ unsigned char jmp2;
27718+ unsigned int addr1;
27719+ unsigned long addr2;
27720+
27721+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27722+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
27723+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
27724+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
27725+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
27726+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
27727+
27728+ if (err)
27729+ break;
27730+
27731+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27732+ regs->r11 = addr1;
27733+ regs->r10 = addr2;
27734+ regs->ip = addr1;
27735+ return 2;
27736+ }
27737+ } while (0);
27738+
27739+ do { /* PaX: gcc trampoline emulation #2 */
27740+ unsigned short mov1, mov2, jmp1;
27741+ unsigned char jmp2;
27742+ unsigned long addr1, addr2;
27743+
27744+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27745+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27746+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27747+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27748+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
27749+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
27750+
27751+ if (err)
27752+ break;
27753+
27754+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27755+ regs->r11 = addr1;
27756+ regs->r10 = addr2;
27757+ regs->ip = addr1;
27758+ return 2;
27759+ }
27760+ } while (0);
27761+
27762+ return 1; /* PaX in action */
27763+}
27764+#endif
27765+
27766+/*
27767+ * PaX: decide what to do with offenders (regs->ip = fault address)
27768+ *
27769+ * returns 1 when task should be killed
27770+ * 2 when gcc trampoline was detected
27771+ */
27772+static int pax_handle_fetch_fault(struct pt_regs *regs)
27773+{
27774+ if (v8086_mode(regs))
27775+ return 1;
27776+
27777+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
27778+ return 1;
27779+
27780+#ifdef CONFIG_X86_32
27781+ return pax_handle_fetch_fault_32(regs);
27782+#else
27783+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
27784+ return pax_handle_fetch_fault_32(regs);
27785+ else
27786+ return pax_handle_fetch_fault_64(regs);
27787+#endif
27788+}
27789+#endif
27790+
27791+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27792+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27793+{
27794+ long i;
27795+
27796+ printk(KERN_ERR "PAX: bytes at PC: ");
27797+ for (i = 0; i < 20; i++) {
27798+ unsigned char c;
27799+ if (get_user(c, (unsigned char __force_user *)pc+i))
27800+ printk(KERN_CONT "?? ");
27801+ else
27802+ printk(KERN_CONT "%02x ", c);
27803+ }
27804+ printk("\n");
27805+
27806+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27807+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
27808+ unsigned long c;
27809+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
27810+#ifdef CONFIG_X86_32
27811+ printk(KERN_CONT "???????? ");
27812+#else
27813+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27814+ printk(KERN_CONT "???????? ???????? ");
27815+ else
27816+ printk(KERN_CONT "???????????????? ");
27817+#endif
27818+ } else {
27819+#ifdef CONFIG_X86_64
27820+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
27821+ printk(KERN_CONT "%08x ", (unsigned int)c);
27822+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
27823+ } else
27824+#endif
27825+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
27826+ }
27827+ }
27828+ printk("\n");
27829+}
27830+#endif
27831+
27832+/**
27833+ * probe_kernel_write(): safely attempt to write to a location
27834+ * @dst: address to write to
27835+ * @src: pointer to the data that shall be written
27836+ * @size: size of the data chunk
27837+ *
27838+ * Safely write to address @dst from the buffer at @src. If a kernel fault
27839+ * happens, handle that and return -EFAULT.
27840+ */
27841+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
27842+{
27843+ long ret;
27844+ mm_segment_t old_fs = get_fs();
27845+
27846+ set_fs(KERNEL_DS);
27847+ pagefault_disable();
27848+ pax_open_kernel();
27849+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
27850+ pax_close_kernel();
27851+ pagefault_enable();
27852+ set_fs(old_fs);
27853+
27854+ return ret ? -EFAULT : 0;
27855+}
27856diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
27857index dd74e46..7d26398 100644
27858--- a/arch/x86/mm/gup.c
27859+++ b/arch/x86/mm/gup.c
27860@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
27861 addr = start;
27862 len = (unsigned long) nr_pages << PAGE_SHIFT;
27863 end = start + len;
27864- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27865+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27866 (void __user *)start, len)))
27867 return 0;
27868
27869diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
27870index 6f31ee5..8ee4164 100644
27871--- a/arch/x86/mm/highmem_32.c
27872+++ b/arch/x86/mm/highmem_32.c
27873@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
27874 idx = type + KM_TYPE_NR*smp_processor_id();
27875 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27876 BUG_ON(!pte_none(*(kmap_pte-idx)));
27877+
27878+ pax_open_kernel();
27879 set_pte(kmap_pte-idx, mk_pte(page, prot));
27880+ pax_close_kernel();
27881+
27882 arch_flush_lazy_mmu_mode();
27883
27884 return (void *)vaddr;
27885diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
27886index ae1aa71..56316db 100644
27887--- a/arch/x86/mm/hugetlbpage.c
27888+++ b/arch/x86/mm/hugetlbpage.c
27889@@ -279,6 +279,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
27890 info.flags = 0;
27891 info.length = len;
27892 info.low_limit = TASK_UNMAPPED_BASE;
27893+
27894+#ifdef CONFIG_PAX_RANDMMAP
27895+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27896+ info.low_limit += current->mm->delta_mmap;
27897+#endif
27898+
27899 info.high_limit = TASK_SIZE;
27900 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
27901 info.align_offset = 0;
27902@@ -311,6 +317,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
27903 VM_BUG_ON(addr != -ENOMEM);
27904 info.flags = 0;
27905 info.low_limit = TASK_UNMAPPED_BASE;
27906+
27907+#ifdef CONFIG_PAX_RANDMMAP
27908+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27909+ info.low_limit += current->mm->delta_mmap;
27910+#endif
27911+
27912 info.high_limit = TASK_SIZE;
27913 addr = vm_unmapped_area(&info);
27914 }
27915@@ -325,10 +337,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27916 struct hstate *h = hstate_file(file);
27917 struct mm_struct *mm = current->mm;
27918 struct vm_area_struct *vma;
27919+ unsigned long pax_task_size = TASK_SIZE;
27920+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
27921
27922 if (len & ~huge_page_mask(h))
27923 return -EINVAL;
27924- if (len > TASK_SIZE)
27925+
27926+#ifdef CONFIG_PAX_SEGMEXEC
27927+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27928+ pax_task_size = SEGMEXEC_TASK_SIZE;
27929+#endif
27930+
27931+ pax_task_size -= PAGE_SIZE;
27932+
27933+ if (len > pax_task_size)
27934 return -ENOMEM;
27935
27936 if (flags & MAP_FIXED) {
27937@@ -337,11 +359,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27938 return addr;
27939 }
27940
27941+#ifdef CONFIG_PAX_RANDMMAP
27942+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27943+#endif
27944+
27945 if (addr) {
27946 addr = ALIGN(addr, huge_page_size(h));
27947 vma = find_vma(mm, addr);
27948- if (TASK_SIZE - len >= addr &&
27949- (!vma || addr + len <= vma->vm_start))
27950+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27951 return addr;
27952 }
27953 if (mm->get_unmapped_area == arch_get_unmapped_area)
27954diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
27955index d7aea41..0fc945b 100644
27956--- a/arch/x86/mm/init.c
27957+++ b/arch/x86/mm/init.c
27958@@ -4,6 +4,7 @@
27959 #include <linux/swap.h>
27960 #include <linux/memblock.h>
27961 #include <linux/bootmem.h> /* for max_low_pfn */
27962+#include <linux/tboot.h>
27963
27964 #include <asm/cacheflush.h>
27965 #include <asm/e820.h>
27966@@ -16,6 +17,8 @@
27967 #include <asm/tlb.h>
27968 #include <asm/proto.h>
27969 #include <asm/dma.h> /* for MAX_DMA_PFN */
27970+#include <asm/desc.h>
27971+#include <asm/bios_ebda.h>
27972
27973 unsigned long __initdata pgt_buf_start;
27974 unsigned long __meminitdata pgt_buf_end;
27975@@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
27976 {
27977 int i;
27978 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
27979- unsigned long start = 0, good_end;
27980+ unsigned long start = 0x100000, good_end;
27981 phys_addr_t base;
27982
27983 for (i = 0; i < nr_range; i++) {
27984@@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
27985 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
27986 * mmio resources as well as potential bios/acpi data regions.
27987 */
27988+
27989+#ifdef CONFIG_GRKERNSEC_KMEM
27990+static unsigned int ebda_start __read_only;
27991+static unsigned int ebda_end __read_only;
27992+#endif
27993+
27994 int devmem_is_allowed(unsigned long pagenr)
27995 {
27996- if (pagenr < 256)
27997+#ifdef CONFIG_GRKERNSEC_KMEM
27998+ /* allow BDA */
27999+ if (!pagenr)
28000 return 1;
28001+ /* allow EBDA */
28002+ if (pagenr >= ebda_start && pagenr < ebda_end)
28003+ return 1;
28004+ /* if tboot is in use, allow access to its hardcoded serial log range */
28005+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
28006+ return 1;
28007+#else
28008+ if (!pagenr)
28009+ return 1;
28010+#ifdef CONFIG_VM86
28011+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
28012+ return 1;
28013+#endif
28014+#endif
28015+
28016+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
28017+ return 1;
28018+#ifdef CONFIG_GRKERNSEC_KMEM
28019+ /* throw out everything else below 1MB */
28020+ if (pagenr <= 256)
28021+ return 0;
28022+#endif
28023 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
28024 return 0;
28025 if (!page_is_ram(pagenr))
28026@@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
28027 #endif
28028 }
28029
28030+#ifdef CONFIG_GRKERNSEC_KMEM
28031+static inline void gr_init_ebda(void)
28032+{
28033+ unsigned int ebda_addr;
28034+ unsigned int ebda_size = 0;
28035+
28036+ ebda_addr = get_bios_ebda();
28037+ if (ebda_addr) {
28038+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
28039+ ebda_size <<= 10;
28040+ }
28041+ if (ebda_addr && ebda_size) {
28042+ ebda_start = ebda_addr >> PAGE_SHIFT;
28043+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
28044+ } else {
28045+ ebda_start = 0x9f000 >> PAGE_SHIFT;
28046+ ebda_end = 0xa0000 >> PAGE_SHIFT;
28047+ }
28048+}
28049+#else
28050+static inline void gr_init_ebda(void) { }
28051+#endif
28052+
28053 void free_initmem(void)
28054 {
28055+#ifdef CONFIG_PAX_KERNEXEC
28056+#ifdef CONFIG_X86_32
28057+ /* PaX: limit KERNEL_CS to actual size */
28058+ unsigned long addr, limit;
28059+ struct desc_struct d;
28060+ int cpu;
28061+#else
28062+ pgd_t *pgd;
28063+ pud_t *pud;
28064+ pmd_t *pmd;
28065+ unsigned long addr, end;
28066+#endif
28067+#endif
28068+
28069+ gr_init_ebda();
28070+
28071+#ifdef CONFIG_PAX_KERNEXEC
28072+#ifdef CONFIG_X86_32
28073+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
28074+ limit = (limit - 1UL) >> PAGE_SHIFT;
28075+
28076+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
28077+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28078+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
28079+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
28080+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
28081+ }
28082+
28083+ /* PaX: make KERNEL_CS read-only */
28084+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
28085+ if (!paravirt_enabled())
28086+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
28087+/*
28088+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
28089+ pgd = pgd_offset_k(addr);
28090+ pud = pud_offset(pgd, addr);
28091+ pmd = pmd_offset(pud, addr);
28092+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28093+ }
28094+*/
28095+#ifdef CONFIG_X86_PAE
28096+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
28097+/*
28098+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
28099+ pgd = pgd_offset_k(addr);
28100+ pud = pud_offset(pgd, addr);
28101+ pmd = pmd_offset(pud, addr);
28102+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28103+ }
28104+*/
28105+#endif
28106+
28107+#ifdef CONFIG_MODULES
28108+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
28109+#endif
28110+
28111+#else
28112+ /* PaX: make kernel code/rodata read-only, rest non-executable */
28113+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
28114+ pgd = pgd_offset_k(addr);
28115+ pud = pud_offset(pgd, addr);
28116+ pmd = pmd_offset(pud, addr);
28117+ if (!pmd_present(*pmd))
28118+ continue;
28119+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
28120+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28121+ else
28122+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28123+ }
28124+
28125+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
28126+ end = addr + KERNEL_IMAGE_SIZE;
28127+ for (; addr < end; addr += PMD_SIZE) {
28128+ pgd = pgd_offset_k(addr);
28129+ pud = pud_offset(pgd, addr);
28130+ pmd = pmd_offset(pud, addr);
28131+ if (!pmd_present(*pmd))
28132+ continue;
28133+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
28134+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28135+ }
28136+#endif
28137+
28138+ flush_tlb_all();
28139+#endif
28140+
28141 free_init_pages("unused kernel memory",
28142 (unsigned long)(&__init_begin),
28143 (unsigned long)(&__init_end));
28144diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
28145index 745d66b..56bf568 100644
28146--- a/arch/x86/mm/init_32.c
28147+++ b/arch/x86/mm/init_32.c
28148@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
28149 }
28150
28151 /*
28152- * Creates a middle page table and puts a pointer to it in the
28153- * given global directory entry. This only returns the gd entry
28154- * in non-PAE compilation mode, since the middle layer is folded.
28155- */
28156-static pmd_t * __init one_md_table_init(pgd_t *pgd)
28157-{
28158- pud_t *pud;
28159- pmd_t *pmd_table;
28160-
28161-#ifdef CONFIG_X86_PAE
28162- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
28163- if (after_bootmem)
28164- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
28165- else
28166- pmd_table = (pmd_t *)alloc_low_page();
28167- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
28168- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
28169- pud = pud_offset(pgd, 0);
28170- BUG_ON(pmd_table != pmd_offset(pud, 0));
28171-
28172- return pmd_table;
28173- }
28174-#endif
28175- pud = pud_offset(pgd, 0);
28176- pmd_table = pmd_offset(pud, 0);
28177-
28178- return pmd_table;
28179-}
28180-
28181-/*
28182 * Create a page table and place a pointer to it in a middle page
28183 * directory entry:
28184 */
28185@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
28186 page_table = (pte_t *)alloc_low_page();
28187
28188 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
28189+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28190+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
28191+#else
28192 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
28193+#endif
28194 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
28195 }
28196
28197 return pte_offset_kernel(pmd, 0);
28198 }
28199
28200+static pmd_t * __init one_md_table_init(pgd_t *pgd)
28201+{
28202+ pud_t *pud;
28203+ pmd_t *pmd_table;
28204+
28205+ pud = pud_offset(pgd, 0);
28206+ pmd_table = pmd_offset(pud, 0);
28207+
28208+ return pmd_table;
28209+}
28210+
28211 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
28212 {
28213 int pgd_idx = pgd_index(vaddr);
28214@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28215 int pgd_idx, pmd_idx;
28216 unsigned long vaddr;
28217 pgd_t *pgd;
28218+ pud_t *pud;
28219 pmd_t *pmd;
28220 pte_t *pte = NULL;
28221
28222@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28223 pgd = pgd_base + pgd_idx;
28224
28225 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
28226- pmd = one_md_table_init(pgd);
28227- pmd = pmd + pmd_index(vaddr);
28228+ pud = pud_offset(pgd, vaddr);
28229+ pmd = pmd_offset(pud, vaddr);
28230+
28231+#ifdef CONFIG_X86_PAE
28232+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28233+#endif
28234+
28235 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
28236 pmd++, pmd_idx++) {
28237 pte = page_table_kmap_check(one_page_table_init(pmd),
28238@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28239 }
28240 }
28241
28242-static inline int is_kernel_text(unsigned long addr)
28243+static inline int is_kernel_text(unsigned long start, unsigned long end)
28244 {
28245- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
28246- return 1;
28247- return 0;
28248+ if ((start > ktla_ktva((unsigned long)_etext) ||
28249+ end <= ktla_ktva((unsigned long)_stext)) &&
28250+ (start > ktla_ktva((unsigned long)_einittext) ||
28251+ end <= ktla_ktva((unsigned long)_sinittext)) &&
28252+
28253+#ifdef CONFIG_ACPI_SLEEP
28254+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
28255+#endif
28256+
28257+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
28258+ return 0;
28259+ return 1;
28260 }
28261
28262 /*
28263@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
28264 unsigned long last_map_addr = end;
28265 unsigned long start_pfn, end_pfn;
28266 pgd_t *pgd_base = swapper_pg_dir;
28267- int pgd_idx, pmd_idx, pte_ofs;
28268+ unsigned int pgd_idx, pmd_idx, pte_ofs;
28269 unsigned long pfn;
28270 pgd_t *pgd;
28271+ pud_t *pud;
28272 pmd_t *pmd;
28273 pte_t *pte;
28274 unsigned pages_2m, pages_4k;
28275@@ -280,8 +281,13 @@ repeat:
28276 pfn = start_pfn;
28277 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28278 pgd = pgd_base + pgd_idx;
28279- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
28280- pmd = one_md_table_init(pgd);
28281+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
28282+ pud = pud_offset(pgd, 0);
28283+ pmd = pmd_offset(pud, 0);
28284+
28285+#ifdef CONFIG_X86_PAE
28286+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28287+#endif
28288
28289 if (pfn >= end_pfn)
28290 continue;
28291@@ -293,14 +299,13 @@ repeat:
28292 #endif
28293 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
28294 pmd++, pmd_idx++) {
28295- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
28296+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
28297
28298 /*
28299 * Map with big pages if possible, otherwise
28300 * create normal page tables:
28301 */
28302 if (use_pse) {
28303- unsigned int addr2;
28304 pgprot_t prot = PAGE_KERNEL_LARGE;
28305 /*
28306 * first pass will use the same initial
28307@@ -310,11 +315,7 @@ repeat:
28308 __pgprot(PTE_IDENT_ATTR |
28309 _PAGE_PSE);
28310
28311- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
28312- PAGE_OFFSET + PAGE_SIZE-1;
28313-
28314- if (is_kernel_text(addr) ||
28315- is_kernel_text(addr2))
28316+ if (is_kernel_text(address, address + PMD_SIZE))
28317 prot = PAGE_KERNEL_LARGE_EXEC;
28318
28319 pages_2m++;
28320@@ -331,7 +332,7 @@ repeat:
28321 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28322 pte += pte_ofs;
28323 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
28324- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
28325+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
28326 pgprot_t prot = PAGE_KERNEL;
28327 /*
28328 * first pass will use the same initial
28329@@ -339,7 +340,7 @@ repeat:
28330 */
28331 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
28332
28333- if (is_kernel_text(addr))
28334+ if (is_kernel_text(address, address + PAGE_SIZE))
28335 prot = PAGE_KERNEL_EXEC;
28336
28337 pages_4k++;
28338@@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
28339
28340 pud = pud_offset(pgd, va);
28341 pmd = pmd_offset(pud, va);
28342- if (!pmd_present(*pmd))
28343+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
28344 break;
28345
28346 pte = pte_offset_kernel(pmd, va);
28347@@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
28348
28349 static void __init pagetable_init(void)
28350 {
28351- pgd_t *pgd_base = swapper_pg_dir;
28352-
28353- permanent_kmaps_init(pgd_base);
28354+ permanent_kmaps_init(swapper_pg_dir);
28355 }
28356
28357-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28358+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28359 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28360
28361 /* user-defined highmem size */
28362@@ -728,6 +727,12 @@ void __init mem_init(void)
28363
28364 pci_iommu_alloc();
28365
28366+#ifdef CONFIG_PAX_PER_CPU_PGD
28367+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28368+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28369+ KERNEL_PGD_PTRS);
28370+#endif
28371+
28372 #ifdef CONFIG_FLATMEM
28373 BUG_ON(!mem_map);
28374 #endif
28375@@ -754,7 +759,7 @@ void __init mem_init(void)
28376 reservedpages++;
28377
28378 codesize = (unsigned long) &_etext - (unsigned long) &_text;
28379- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
28380+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
28381 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
28382
28383 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
28384@@ -795,10 +800,10 @@ void __init mem_init(void)
28385 ((unsigned long)&__init_end -
28386 (unsigned long)&__init_begin) >> 10,
28387
28388- (unsigned long)&_etext, (unsigned long)&_edata,
28389- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
28390+ (unsigned long)&_sdata, (unsigned long)&_edata,
28391+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
28392
28393- (unsigned long)&_text, (unsigned long)&_etext,
28394+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
28395 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
28396
28397 /*
28398@@ -876,6 +881,7 @@ void set_kernel_text_rw(void)
28399 if (!kernel_set_to_readonly)
28400 return;
28401
28402+ start = ktla_ktva(start);
28403 pr_debug("Set kernel text: %lx - %lx for read write\n",
28404 start, start+size);
28405
28406@@ -890,6 +896,7 @@ void set_kernel_text_ro(void)
28407 if (!kernel_set_to_readonly)
28408 return;
28409
28410+ start = ktla_ktva(start);
28411 pr_debug("Set kernel text: %lx - %lx for read only\n",
28412 start, start+size);
28413
28414@@ -918,6 +925,7 @@ void mark_rodata_ro(void)
28415 unsigned long start = PFN_ALIGN(_text);
28416 unsigned long size = PFN_ALIGN(_etext) - start;
28417
28418+ start = ktla_ktva(start);
28419 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
28420 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
28421 size >> 10);
28422diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
28423index 75c9a6a..498d677 100644
28424--- a/arch/x86/mm/init_64.c
28425+++ b/arch/x86/mm/init_64.c
28426@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
28427 * around without checking the pgd every time.
28428 */
28429
28430-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
28431+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
28432 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28433
28434 int force_personality32;
28435@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28436
28437 for (address = start; address <= end; address += PGDIR_SIZE) {
28438 const pgd_t *pgd_ref = pgd_offset_k(address);
28439+
28440+#ifdef CONFIG_PAX_PER_CPU_PGD
28441+ unsigned long cpu;
28442+#else
28443 struct page *page;
28444+#endif
28445
28446 if (pgd_none(*pgd_ref))
28447 continue;
28448
28449 spin_lock(&pgd_lock);
28450+
28451+#ifdef CONFIG_PAX_PER_CPU_PGD
28452+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28453+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
28454+#else
28455 list_for_each_entry(page, &pgd_list, lru) {
28456 pgd_t *pgd;
28457 spinlock_t *pgt_lock;
28458@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28459 /* the pgt_lock only for Xen */
28460 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
28461 spin_lock(pgt_lock);
28462+#endif
28463
28464 if (pgd_none(*pgd))
28465 set_pgd(pgd, *pgd_ref);
28466@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28467 BUG_ON(pgd_page_vaddr(*pgd)
28468 != pgd_page_vaddr(*pgd_ref));
28469
28470+#ifndef CONFIG_PAX_PER_CPU_PGD
28471 spin_unlock(pgt_lock);
28472+#endif
28473+
28474 }
28475 spin_unlock(&pgd_lock);
28476 }
28477@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
28478 {
28479 if (pgd_none(*pgd)) {
28480 pud_t *pud = (pud_t *)spp_getpage();
28481- pgd_populate(&init_mm, pgd, pud);
28482+ pgd_populate_kernel(&init_mm, pgd, pud);
28483 if (pud != pud_offset(pgd, 0))
28484 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
28485 pud, pud_offset(pgd, 0));
28486@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
28487 {
28488 if (pud_none(*pud)) {
28489 pmd_t *pmd = (pmd_t *) spp_getpage();
28490- pud_populate(&init_mm, pud, pmd);
28491+ pud_populate_kernel(&init_mm, pud, pmd);
28492 if (pmd != pmd_offset(pud, 0))
28493 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
28494 pmd, pmd_offset(pud, 0));
28495@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
28496 pmd = fill_pmd(pud, vaddr);
28497 pte = fill_pte(pmd, vaddr);
28498
28499+ pax_open_kernel();
28500 set_pte(pte, new_pte);
28501+ pax_close_kernel();
28502
28503 /*
28504 * It's enough to flush this one mapping.
28505@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
28506 pgd = pgd_offset_k((unsigned long)__va(phys));
28507 if (pgd_none(*pgd)) {
28508 pud = (pud_t *) spp_getpage();
28509- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
28510- _PAGE_USER));
28511+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
28512 }
28513 pud = pud_offset(pgd, (unsigned long)__va(phys));
28514 if (pud_none(*pud)) {
28515 pmd = (pmd_t *) spp_getpage();
28516- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
28517- _PAGE_USER));
28518+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
28519 }
28520 pmd = pmd_offset(pud, phys);
28521 BUG_ON(!pmd_none(*pmd));
28522@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
28523 if (pfn >= pgt_buf_top)
28524 panic("alloc_low_page: ran out of memory");
28525
28526- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28527+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28528 clear_page(adr);
28529 *phys = pfn * PAGE_SIZE;
28530 return adr;
28531@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
28532
28533 phys = __pa(virt);
28534 left = phys & (PAGE_SIZE - 1);
28535- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28536+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28537 adr = (void *)(((unsigned long)adr) | left);
28538
28539 return adr;
28540@@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
28541 unmap_low_page(pmd);
28542
28543 spin_lock(&init_mm.page_table_lock);
28544- pud_populate(&init_mm, pud, __va(pmd_phys));
28545+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
28546 spin_unlock(&init_mm.page_table_lock);
28547 }
28548 __flush_tlb_all();
28549@@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
28550 unmap_low_page(pud);
28551
28552 spin_lock(&init_mm.page_table_lock);
28553- pgd_populate(&init_mm, pgd, __va(pud_phys));
28554+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
28555 spin_unlock(&init_mm.page_table_lock);
28556 pgd_changed = true;
28557 }
28558@@ -693,6 +707,12 @@ void __init mem_init(void)
28559
28560 pci_iommu_alloc();
28561
28562+#ifdef CONFIG_PAX_PER_CPU_PGD
28563+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28564+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28565+ KERNEL_PGD_PTRS);
28566+#endif
28567+
28568 /* clear_bss() already clear the empty_zero_page */
28569
28570 reservedpages = 0;
28571@@ -856,8 +876,8 @@ int kern_addr_valid(unsigned long addr)
28572 static struct vm_area_struct gate_vma = {
28573 .vm_start = VSYSCALL_START,
28574 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
28575- .vm_page_prot = PAGE_READONLY_EXEC,
28576- .vm_flags = VM_READ | VM_EXEC
28577+ .vm_page_prot = PAGE_READONLY,
28578+ .vm_flags = VM_READ
28579 };
28580
28581 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28582@@ -891,7 +911,7 @@ int in_gate_area_no_mm(unsigned long addr)
28583
28584 const char *arch_vma_name(struct vm_area_struct *vma)
28585 {
28586- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28587+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28588 return "[vdso]";
28589 if (vma == &gate_vma)
28590 return "[vsyscall]";
28591diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
28592index 7b179b4..6bd1777 100644
28593--- a/arch/x86/mm/iomap_32.c
28594+++ b/arch/x86/mm/iomap_32.c
28595@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
28596 type = kmap_atomic_idx_push();
28597 idx = type + KM_TYPE_NR * smp_processor_id();
28598 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28599+
28600+ pax_open_kernel();
28601 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
28602+ pax_close_kernel();
28603+
28604 arch_flush_lazy_mmu_mode();
28605
28606 return (void *)vaddr;
28607diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
28608index 78fe3f1..73b95e2 100644
28609--- a/arch/x86/mm/ioremap.c
28610+++ b/arch/x86/mm/ioremap.c
28611@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
28612 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
28613 int is_ram = page_is_ram(pfn);
28614
28615- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
28616+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
28617 return NULL;
28618 WARN_ON_ONCE(is_ram);
28619 }
28620@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
28621 *
28622 * Caller must ensure there is only one unmapping for the same pointer.
28623 */
28624-void iounmap(volatile void __iomem *addr)
28625+void iounmap(const volatile void __iomem *addr)
28626 {
28627 struct vm_struct *p, *o;
28628
28629@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28630
28631 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
28632 if (page_is_ram(start >> PAGE_SHIFT))
28633+#ifdef CONFIG_HIGHMEM
28634+ if ((start >> PAGE_SHIFT) < max_low_pfn)
28635+#endif
28636 return __va(phys);
28637
28638 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
28639@@ -327,6 +330,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28640 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
28641 {
28642 if (page_is_ram(phys >> PAGE_SHIFT))
28643+#ifdef CONFIG_HIGHMEM
28644+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
28645+#endif
28646 return;
28647
28648 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
28649@@ -344,7 +350,7 @@ static int __init early_ioremap_debug_setup(char *str)
28650 early_param("early_ioremap_debug", early_ioremap_debug_setup);
28651
28652 static __initdata int after_paging_init;
28653-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
28654+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
28655
28656 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
28657 {
28658@@ -381,8 +387,7 @@ void __init early_ioremap_init(void)
28659 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
28660
28661 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
28662- memset(bm_pte, 0, sizeof(bm_pte));
28663- pmd_populate_kernel(&init_mm, pmd, bm_pte);
28664+ pmd_populate_user(&init_mm, pmd, bm_pte);
28665
28666 /*
28667 * The boot-ioremap range spans multiple pmds, for which
28668diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
28669index d87dd6d..bf3fa66 100644
28670--- a/arch/x86/mm/kmemcheck/kmemcheck.c
28671+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
28672@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
28673 * memory (e.g. tracked pages)? For now, we need this to avoid
28674 * invoking kmemcheck for PnP BIOS calls.
28675 */
28676- if (regs->flags & X86_VM_MASK)
28677+ if (v8086_mode(regs))
28678 return false;
28679- if (regs->cs != __KERNEL_CS)
28680+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
28681 return false;
28682
28683 pte = kmemcheck_pte_lookup(address);
28684diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
28685index 845df68..1d8d29f 100644
28686--- a/arch/x86/mm/mmap.c
28687+++ b/arch/x86/mm/mmap.c
28688@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
28689 * Leave an at least ~128 MB hole with possible stack randomization.
28690 */
28691 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
28692-#define MAX_GAP (TASK_SIZE/6*5)
28693+#define MAX_GAP (pax_task_size/6*5)
28694
28695 static int mmap_is_legacy(void)
28696 {
28697@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
28698 return rnd << PAGE_SHIFT;
28699 }
28700
28701-static unsigned long mmap_base(void)
28702+static unsigned long mmap_base(struct mm_struct *mm)
28703 {
28704 unsigned long gap = rlimit(RLIMIT_STACK);
28705+ unsigned long pax_task_size = TASK_SIZE;
28706+
28707+#ifdef CONFIG_PAX_SEGMEXEC
28708+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28709+ pax_task_size = SEGMEXEC_TASK_SIZE;
28710+#endif
28711
28712 if (gap < MIN_GAP)
28713 gap = MIN_GAP;
28714 else if (gap > MAX_GAP)
28715 gap = MAX_GAP;
28716
28717- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
28718+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
28719 }
28720
28721 /*
28722 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
28723 * does, but not when emulating X86_32
28724 */
28725-static unsigned long mmap_legacy_base(void)
28726+static unsigned long mmap_legacy_base(struct mm_struct *mm)
28727 {
28728- if (mmap_is_ia32())
28729+ if (mmap_is_ia32()) {
28730+
28731+#ifdef CONFIG_PAX_SEGMEXEC
28732+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28733+ return SEGMEXEC_TASK_UNMAPPED_BASE;
28734+ else
28735+#endif
28736+
28737 return TASK_UNMAPPED_BASE;
28738- else
28739+ } else
28740 return TASK_UNMAPPED_BASE + mmap_rnd();
28741 }
28742
28743@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
28744 void arch_pick_mmap_layout(struct mm_struct *mm)
28745 {
28746 if (mmap_is_legacy()) {
28747- mm->mmap_base = mmap_legacy_base();
28748+ mm->mmap_base = mmap_legacy_base(mm);
28749+
28750+#ifdef CONFIG_PAX_RANDMMAP
28751+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28752+ mm->mmap_base += mm->delta_mmap;
28753+#endif
28754+
28755 mm->get_unmapped_area = arch_get_unmapped_area;
28756 mm->unmap_area = arch_unmap_area;
28757 } else {
28758- mm->mmap_base = mmap_base();
28759+ mm->mmap_base = mmap_base(mm);
28760+
28761+#ifdef CONFIG_PAX_RANDMMAP
28762+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28763+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
28764+#endif
28765+
28766 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
28767 mm->unmap_area = arch_unmap_area_topdown;
28768 }
28769diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
28770index dc0b727..f612039 100644
28771--- a/arch/x86/mm/mmio-mod.c
28772+++ b/arch/x86/mm/mmio-mod.c
28773@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
28774 break;
28775 default:
28776 {
28777- unsigned char *ip = (unsigned char *)instptr;
28778+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
28779 my_trace->opcode = MMIO_UNKNOWN_OP;
28780 my_trace->width = 0;
28781 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
28782@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
28783 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28784 void __iomem *addr)
28785 {
28786- static atomic_t next_id;
28787+ static atomic_unchecked_t next_id;
28788 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
28789 /* These are page-unaligned. */
28790 struct mmiotrace_map map = {
28791@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28792 .private = trace
28793 },
28794 .phys = offset,
28795- .id = atomic_inc_return(&next_id)
28796+ .id = atomic_inc_return_unchecked(&next_id)
28797 };
28798 map.map_id = trace->id;
28799
28800@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28801 ioremap_trace_core(offset, size, addr);
28802 }
28803
28804-static void iounmap_trace_core(volatile void __iomem *addr)
28805+static void iounmap_trace_core(const volatile void __iomem *addr)
28806 {
28807 struct mmiotrace_map map = {
28808 .phys = 0,
28809@@ -328,7 +328,7 @@ not_enabled:
28810 }
28811 }
28812
28813-void mmiotrace_iounmap(volatile void __iomem *addr)
28814+void mmiotrace_iounmap(const volatile void __iomem *addr)
28815 {
28816 might_sleep();
28817 if (is_enabled()) /* recheck and proper locking in *_core() */
28818diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
28819index 8504f36..5fc68f2 100644
28820--- a/arch/x86/mm/numa.c
28821+++ b/arch/x86/mm/numa.c
28822@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
28823 return true;
28824 }
28825
28826-static int __init numa_register_memblks(struct numa_meminfo *mi)
28827+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
28828 {
28829 unsigned long uninitialized_var(pfn_align);
28830 int i, nid;
28831diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
28832index b008656..773eac2 100644
28833--- a/arch/x86/mm/pageattr-test.c
28834+++ b/arch/x86/mm/pageattr-test.c
28835@@ -36,7 +36,7 @@ enum {
28836
28837 static int pte_testbit(pte_t pte)
28838 {
28839- return pte_flags(pte) & _PAGE_UNUSED1;
28840+ return pte_flags(pte) & _PAGE_CPA_TEST;
28841 }
28842
28843 struct split_state {
28844diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
28845index a718e0d..77419bc 100644
28846--- a/arch/x86/mm/pageattr.c
28847+++ b/arch/x86/mm/pageattr.c
28848@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28849 */
28850 #ifdef CONFIG_PCI_BIOS
28851 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
28852- pgprot_val(forbidden) |= _PAGE_NX;
28853+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28854 #endif
28855
28856 /*
28857@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28858 * Does not cover __inittext since that is gone later on. On
28859 * 64bit we do not enforce !NX on the low mapping
28860 */
28861- if (within(address, (unsigned long)_text, (unsigned long)_etext))
28862- pgprot_val(forbidden) |= _PAGE_NX;
28863+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
28864+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28865
28866+#ifdef CONFIG_DEBUG_RODATA
28867 /*
28868 * The .rodata section needs to be read-only. Using the pfn
28869 * catches all aliases.
28870@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28871 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
28872 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
28873 pgprot_val(forbidden) |= _PAGE_RW;
28874+#endif
28875
28876 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
28877 /*
28878@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28879 }
28880 #endif
28881
28882+#ifdef CONFIG_PAX_KERNEXEC
28883+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
28884+ pgprot_val(forbidden) |= _PAGE_RW;
28885+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28886+ }
28887+#endif
28888+
28889 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
28890
28891 return prot;
28892@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
28893 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
28894 {
28895 /* change init_mm */
28896+ pax_open_kernel();
28897 set_pte_atomic(kpte, pte);
28898+
28899 #ifdef CONFIG_X86_32
28900 if (!SHARED_KERNEL_PMD) {
28901+
28902+#ifdef CONFIG_PAX_PER_CPU_PGD
28903+ unsigned long cpu;
28904+#else
28905 struct page *page;
28906+#endif
28907
28908+#ifdef CONFIG_PAX_PER_CPU_PGD
28909+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28910+ pgd_t *pgd = get_cpu_pgd(cpu);
28911+#else
28912 list_for_each_entry(page, &pgd_list, lru) {
28913- pgd_t *pgd;
28914+ pgd_t *pgd = (pgd_t *)page_address(page);
28915+#endif
28916+
28917 pud_t *pud;
28918 pmd_t *pmd;
28919
28920- pgd = (pgd_t *)page_address(page) + pgd_index(address);
28921+ pgd += pgd_index(address);
28922 pud = pud_offset(pgd, address);
28923 pmd = pmd_offset(pud, address);
28924 set_pte_atomic((pte_t *)pmd, pte);
28925 }
28926 }
28927 #endif
28928+ pax_close_kernel();
28929 }
28930
28931 static int
28932diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
28933index 0eb572e..92f5c1e 100644
28934--- a/arch/x86/mm/pat.c
28935+++ b/arch/x86/mm/pat.c
28936@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
28937
28938 if (!entry) {
28939 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
28940- current->comm, current->pid, start, end - 1);
28941+ current->comm, task_pid_nr(current), start, end - 1);
28942 return -EINVAL;
28943 }
28944
28945@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28946
28947 while (cursor < to) {
28948 if (!devmem_is_allowed(pfn)) {
28949- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
28950- current->comm, from, to - 1);
28951+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
28952+ current->comm, from, to - 1, cursor);
28953 return 0;
28954 }
28955 cursor += PAGE_SIZE;
28956@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
28957 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
28958 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
28959 "for [mem %#010Lx-%#010Lx]\n",
28960- current->comm, current->pid,
28961+ current->comm, task_pid_nr(current),
28962 cattr_name(flags),
28963 base, (unsigned long long)(base + size-1));
28964 return -EINVAL;
28965@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28966 flags = lookup_memtype(paddr);
28967 if (want_flags != flags) {
28968 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
28969- current->comm, current->pid,
28970+ current->comm, task_pid_nr(current),
28971 cattr_name(want_flags),
28972 (unsigned long long)paddr,
28973 (unsigned long long)(paddr + size - 1),
28974@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28975 free_memtype(paddr, paddr + size);
28976 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
28977 " for [mem %#010Lx-%#010Lx], got %s\n",
28978- current->comm, current->pid,
28979+ current->comm, task_pid_nr(current),
28980 cattr_name(want_flags),
28981 (unsigned long long)paddr,
28982 (unsigned long long)(paddr + size - 1),
28983diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
28984index 9f0614d..92ae64a 100644
28985--- a/arch/x86/mm/pf_in.c
28986+++ b/arch/x86/mm/pf_in.c
28987@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
28988 int i;
28989 enum reason_type rv = OTHERS;
28990
28991- p = (unsigned char *)ins_addr;
28992+ p = (unsigned char *)ktla_ktva(ins_addr);
28993 p += skip_prefix(p, &prf);
28994 p += get_opcode(p, &opcode);
28995
28996@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
28997 struct prefix_bits prf;
28998 int i;
28999
29000- p = (unsigned char *)ins_addr;
29001+ p = (unsigned char *)ktla_ktva(ins_addr);
29002 p += skip_prefix(p, &prf);
29003 p += get_opcode(p, &opcode);
29004
29005@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
29006 struct prefix_bits prf;
29007 int i;
29008
29009- p = (unsigned char *)ins_addr;
29010+ p = (unsigned char *)ktla_ktva(ins_addr);
29011 p += skip_prefix(p, &prf);
29012 p += get_opcode(p, &opcode);
29013
29014@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
29015 struct prefix_bits prf;
29016 int i;
29017
29018- p = (unsigned char *)ins_addr;
29019+ p = (unsigned char *)ktla_ktva(ins_addr);
29020 p += skip_prefix(p, &prf);
29021 p += get_opcode(p, &opcode);
29022 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
29023@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
29024 struct prefix_bits prf;
29025 int i;
29026
29027- p = (unsigned char *)ins_addr;
29028+ p = (unsigned char *)ktla_ktva(ins_addr);
29029 p += skip_prefix(p, &prf);
29030 p += get_opcode(p, &opcode);
29031 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
29032diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
29033index e27fbf8..8b56dc9 100644
29034--- a/arch/x86/mm/pgtable.c
29035+++ b/arch/x86/mm/pgtable.c
29036@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
29037 list_del(&page->lru);
29038 }
29039
29040-#define UNSHARED_PTRS_PER_PGD \
29041- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29042+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29043+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
29044
29045+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
29046+{
29047+ unsigned int count = USER_PGD_PTRS;
29048
29049+ while (count--)
29050+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
29051+}
29052+#endif
29053+
29054+#ifdef CONFIG_PAX_PER_CPU_PGD
29055+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
29056+{
29057+ unsigned int count = USER_PGD_PTRS;
29058+
29059+ while (count--) {
29060+ pgd_t pgd;
29061+
29062+#ifdef CONFIG_X86_64
29063+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
29064+#else
29065+ pgd = *src++;
29066+#endif
29067+
29068+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29069+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
29070+#endif
29071+
29072+ *dst++ = pgd;
29073+ }
29074+
29075+}
29076+#endif
29077+
29078+#ifdef CONFIG_X86_64
29079+#define pxd_t pud_t
29080+#define pyd_t pgd_t
29081+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
29082+#define pxd_free(mm, pud) pud_free((mm), (pud))
29083+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
29084+#define pyd_offset(mm, address) pgd_offset((mm), (address))
29085+#define PYD_SIZE PGDIR_SIZE
29086+#else
29087+#define pxd_t pmd_t
29088+#define pyd_t pud_t
29089+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
29090+#define pxd_free(mm, pud) pmd_free((mm), (pud))
29091+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
29092+#define pyd_offset(mm, address) pud_offset((mm), (address))
29093+#define PYD_SIZE PUD_SIZE
29094+#endif
29095+
29096+#ifdef CONFIG_PAX_PER_CPU_PGD
29097+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
29098+static inline void pgd_dtor(pgd_t *pgd) {}
29099+#else
29100 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
29101 {
29102 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
29103@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
29104 pgd_list_del(pgd);
29105 spin_unlock(&pgd_lock);
29106 }
29107+#endif
29108
29109 /*
29110 * List of all pgd's needed for non-PAE so it can invalidate entries
29111@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
29112 * -- nyc
29113 */
29114
29115-#ifdef CONFIG_X86_PAE
29116+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
29117 /*
29118 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
29119 * updating the top-level pagetable entries to guarantee the
29120@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
29121 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
29122 * and initialize the kernel pmds here.
29123 */
29124-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
29125+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29126
29127 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29128 {
29129@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29130 */
29131 flush_tlb_mm(mm);
29132 }
29133+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
29134+#define PREALLOCATED_PXDS USER_PGD_PTRS
29135 #else /* !CONFIG_X86_PAE */
29136
29137 /* No need to prepopulate any pagetable entries in non-PAE modes. */
29138-#define PREALLOCATED_PMDS 0
29139+#define PREALLOCATED_PXDS 0
29140
29141 #endif /* CONFIG_X86_PAE */
29142
29143-static void free_pmds(pmd_t *pmds[])
29144+static void free_pxds(pxd_t *pxds[])
29145 {
29146 int i;
29147
29148- for(i = 0; i < PREALLOCATED_PMDS; i++)
29149- if (pmds[i])
29150- free_page((unsigned long)pmds[i]);
29151+ for(i = 0; i < PREALLOCATED_PXDS; i++)
29152+ if (pxds[i])
29153+ free_page((unsigned long)pxds[i]);
29154 }
29155
29156-static int preallocate_pmds(pmd_t *pmds[])
29157+static int preallocate_pxds(pxd_t *pxds[])
29158 {
29159 int i;
29160 bool failed = false;
29161
29162- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29163- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
29164- if (pmd == NULL)
29165+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29166+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
29167+ if (pxd == NULL)
29168 failed = true;
29169- pmds[i] = pmd;
29170+ pxds[i] = pxd;
29171 }
29172
29173 if (failed) {
29174- free_pmds(pmds);
29175+ free_pxds(pxds);
29176 return -ENOMEM;
29177 }
29178
29179@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
29180 * preallocate which never got a corresponding vma will need to be
29181 * freed manually.
29182 */
29183-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
29184+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
29185 {
29186 int i;
29187
29188- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29189+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29190 pgd_t pgd = pgdp[i];
29191
29192 if (pgd_val(pgd) != 0) {
29193- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
29194+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
29195
29196- pgdp[i] = native_make_pgd(0);
29197+ set_pgd(pgdp + i, native_make_pgd(0));
29198
29199- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
29200- pmd_free(mm, pmd);
29201+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
29202+ pxd_free(mm, pxd);
29203 }
29204 }
29205 }
29206
29207-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
29208+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
29209 {
29210- pud_t *pud;
29211+ pyd_t *pyd;
29212 unsigned long addr;
29213 int i;
29214
29215- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
29216+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
29217 return;
29218
29219- pud = pud_offset(pgd, 0);
29220+#ifdef CONFIG_X86_64
29221+ pyd = pyd_offset(mm, 0L);
29222+#else
29223+ pyd = pyd_offset(pgd, 0L);
29224+#endif
29225
29226- for (addr = i = 0; i < PREALLOCATED_PMDS;
29227- i++, pud++, addr += PUD_SIZE) {
29228- pmd_t *pmd = pmds[i];
29229+ for (addr = i = 0; i < PREALLOCATED_PXDS;
29230+ i++, pyd++, addr += PYD_SIZE) {
29231+ pxd_t *pxd = pxds[i];
29232
29233 if (i >= KERNEL_PGD_BOUNDARY)
29234- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29235- sizeof(pmd_t) * PTRS_PER_PMD);
29236+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29237+ sizeof(pxd_t) * PTRS_PER_PMD);
29238
29239- pud_populate(mm, pud, pmd);
29240+ pyd_populate(mm, pyd, pxd);
29241 }
29242 }
29243
29244 pgd_t *pgd_alloc(struct mm_struct *mm)
29245 {
29246 pgd_t *pgd;
29247- pmd_t *pmds[PREALLOCATED_PMDS];
29248+ pxd_t *pxds[PREALLOCATED_PXDS];
29249
29250 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
29251
29252@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29253
29254 mm->pgd = pgd;
29255
29256- if (preallocate_pmds(pmds) != 0)
29257+ if (preallocate_pxds(pxds) != 0)
29258 goto out_free_pgd;
29259
29260 if (paravirt_pgd_alloc(mm) != 0)
29261- goto out_free_pmds;
29262+ goto out_free_pxds;
29263
29264 /*
29265 * Make sure that pre-populating the pmds is atomic with
29266@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29267 spin_lock(&pgd_lock);
29268
29269 pgd_ctor(mm, pgd);
29270- pgd_prepopulate_pmd(mm, pgd, pmds);
29271+ pgd_prepopulate_pxd(mm, pgd, pxds);
29272
29273 spin_unlock(&pgd_lock);
29274
29275 return pgd;
29276
29277-out_free_pmds:
29278- free_pmds(pmds);
29279+out_free_pxds:
29280+ free_pxds(pxds);
29281 out_free_pgd:
29282 free_page((unsigned long)pgd);
29283 out:
29284@@ -295,7 +356,7 @@ out:
29285
29286 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
29287 {
29288- pgd_mop_up_pmds(mm, pgd);
29289+ pgd_mop_up_pxds(mm, pgd);
29290 pgd_dtor(pgd);
29291 paravirt_pgd_free(mm, pgd);
29292 free_page((unsigned long)pgd);
29293diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
29294index a69bcb8..19068ab 100644
29295--- a/arch/x86/mm/pgtable_32.c
29296+++ b/arch/x86/mm/pgtable_32.c
29297@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
29298 return;
29299 }
29300 pte = pte_offset_kernel(pmd, vaddr);
29301+
29302+ pax_open_kernel();
29303 if (pte_val(pteval))
29304 set_pte_at(&init_mm, vaddr, pte, pteval);
29305 else
29306 pte_clear(&init_mm, vaddr, pte);
29307+ pax_close_kernel();
29308
29309 /*
29310 * It's enough to flush this one mapping.
29311diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
29312index d2e2735..5c6586f 100644
29313--- a/arch/x86/mm/physaddr.c
29314+++ b/arch/x86/mm/physaddr.c
29315@@ -8,7 +8,7 @@
29316
29317 #ifdef CONFIG_X86_64
29318
29319-unsigned long __phys_addr(unsigned long x)
29320+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29321 {
29322 if (x >= __START_KERNEL_map) {
29323 x -= __START_KERNEL_map;
29324@@ -45,7 +45,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
29325 #else
29326
29327 #ifdef CONFIG_DEBUG_VIRTUAL
29328-unsigned long __phys_addr(unsigned long x)
29329+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29330 {
29331 /* VMALLOC_* aren't constants */
29332 VIRTUAL_BUG_ON(x < PAGE_OFFSET);
29333diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
29334index 410531d..0f16030 100644
29335--- a/arch/x86/mm/setup_nx.c
29336+++ b/arch/x86/mm/setup_nx.c
29337@@ -5,8 +5,10 @@
29338 #include <asm/pgtable.h>
29339 #include <asm/proto.h>
29340
29341+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29342 static int disable_nx __cpuinitdata;
29343
29344+#ifndef CONFIG_PAX_PAGEEXEC
29345 /*
29346 * noexec = on|off
29347 *
29348@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
29349 return 0;
29350 }
29351 early_param("noexec", noexec_setup);
29352+#endif
29353+
29354+#endif
29355
29356 void __cpuinit x86_configure_nx(void)
29357 {
29358+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29359 if (cpu_has_nx && !disable_nx)
29360 __supported_pte_mask |= _PAGE_NX;
29361 else
29362+#endif
29363 __supported_pte_mask &= ~_PAGE_NX;
29364 }
29365
29366diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
29367index 13a6b29..c2fff23 100644
29368--- a/arch/x86/mm/tlb.c
29369+++ b/arch/x86/mm/tlb.c
29370@@ -48,7 +48,11 @@ void leave_mm(int cpu)
29371 BUG();
29372 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
29373 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
29374+
29375+#ifndef CONFIG_PAX_PER_CPU_PGD
29376 load_cr3(swapper_pg_dir);
29377+#endif
29378+
29379 }
29380 }
29381 EXPORT_SYMBOL_GPL(leave_mm);
29382diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
29383index 877b9a1..a8ecf42 100644
29384--- a/arch/x86/net/bpf_jit.S
29385+++ b/arch/x86/net/bpf_jit.S
29386@@ -9,6 +9,7 @@
29387 */
29388 #include <linux/linkage.h>
29389 #include <asm/dwarf2.h>
29390+#include <asm/alternative-asm.h>
29391
29392 /*
29393 * Calling convention :
29394@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
29395 jle bpf_slow_path_word
29396 mov (SKBDATA,%rsi),%eax
29397 bswap %eax /* ntohl() */
29398+ pax_force_retaddr
29399 ret
29400
29401 sk_load_half:
29402@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
29403 jle bpf_slow_path_half
29404 movzwl (SKBDATA,%rsi),%eax
29405 rol $8,%ax # ntohs()
29406+ pax_force_retaddr
29407 ret
29408
29409 sk_load_byte:
29410@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
29411 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
29412 jle bpf_slow_path_byte
29413 movzbl (SKBDATA,%rsi),%eax
29414+ pax_force_retaddr
29415 ret
29416
29417 /**
29418@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
29419 movzbl (SKBDATA,%rsi),%ebx
29420 and $15,%bl
29421 shl $2,%bl
29422+ pax_force_retaddr
29423 ret
29424
29425 /* rsi contains offset and can be scratched */
29426@@ -109,6 +114,7 @@ bpf_slow_path_word:
29427 js bpf_error
29428 mov -12(%rbp),%eax
29429 bswap %eax
29430+ pax_force_retaddr
29431 ret
29432
29433 bpf_slow_path_half:
29434@@ -117,12 +123,14 @@ bpf_slow_path_half:
29435 mov -12(%rbp),%ax
29436 rol $8,%ax
29437 movzwl %ax,%eax
29438+ pax_force_retaddr
29439 ret
29440
29441 bpf_slow_path_byte:
29442 bpf_slow_path_common(1)
29443 js bpf_error
29444 movzbl -12(%rbp),%eax
29445+ pax_force_retaddr
29446 ret
29447
29448 bpf_slow_path_byte_msh:
29449@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
29450 and $15,%al
29451 shl $2,%al
29452 xchg %eax,%ebx
29453+ pax_force_retaddr
29454 ret
29455
29456 #define sk_negative_common(SIZE) \
29457@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
29458 sk_negative_common(4)
29459 mov (%rax), %eax
29460 bswap %eax
29461+ pax_force_retaddr
29462 ret
29463
29464 bpf_slow_path_half_neg:
29465@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
29466 mov (%rax),%ax
29467 rol $8,%ax
29468 movzwl %ax,%eax
29469+ pax_force_retaddr
29470 ret
29471
29472 bpf_slow_path_byte_neg:
29473@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
29474 .globl sk_load_byte_negative_offset
29475 sk_negative_common(1)
29476 movzbl (%rax), %eax
29477+ pax_force_retaddr
29478 ret
29479
29480 bpf_slow_path_byte_msh_neg:
29481@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
29482 and $15,%al
29483 shl $2,%al
29484 xchg %eax,%ebx
29485+ pax_force_retaddr
29486 ret
29487
29488 bpf_error:
29489@@ -197,4 +210,5 @@ bpf_error:
29490 xor %eax,%eax
29491 mov -8(%rbp),%rbx
29492 leaveq
29493+ pax_force_retaddr
29494 ret
29495diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
29496index d11a470..3f9adff3 100644
29497--- a/arch/x86/net/bpf_jit_comp.c
29498+++ b/arch/x86/net/bpf_jit_comp.c
29499@@ -12,6 +12,7 @@
29500 #include <linux/netdevice.h>
29501 #include <linux/filter.h>
29502 #include <linux/if_vlan.h>
29503+#include <linux/random.h>
29504
29505 /*
29506 * Conventions :
29507@@ -49,13 +50,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
29508 return ptr + len;
29509 }
29510
29511+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29512+#define MAX_INSTR_CODE_SIZE 96
29513+#else
29514+#define MAX_INSTR_CODE_SIZE 64
29515+#endif
29516+
29517 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
29518
29519 #define EMIT1(b1) EMIT(b1, 1)
29520 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
29521 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
29522 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
29523+
29524+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29525+/* original constant will appear in ecx */
29526+#define DILUTE_CONST_SEQUENCE(_off, _key) \
29527+do { \
29528+ /* mov ecx, randkey */ \
29529+ EMIT1(0xb9); \
29530+ EMIT(_key, 4); \
29531+ /* xor ecx, randkey ^ off */ \
29532+ EMIT2(0x81, 0xf1); \
29533+ EMIT((_key) ^ (_off), 4); \
29534+} while (0)
29535+
29536+#define EMIT1_off32(b1, _off) \
29537+do { \
29538+ switch (b1) { \
29539+ case 0x05: /* add eax, imm32 */ \
29540+ case 0x2d: /* sub eax, imm32 */ \
29541+ case 0x25: /* and eax, imm32 */ \
29542+ case 0x0d: /* or eax, imm32 */ \
29543+ case 0xb8: /* mov eax, imm32 */ \
29544+ case 0x3d: /* cmp eax, imm32 */ \
29545+ case 0xa9: /* test eax, imm32 */ \
29546+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29547+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
29548+ break; \
29549+ case 0xbb: /* mov ebx, imm32 */ \
29550+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29551+ /* mov ebx, ecx */ \
29552+ EMIT2(0x89, 0xcb); \
29553+ break; \
29554+ case 0xbe: /* mov esi, imm32 */ \
29555+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29556+ /* mov esi, ecx */ \
29557+ EMIT2(0x89, 0xce); \
29558+ break; \
29559+ case 0xe9: /* jmp rel imm32 */ \
29560+ EMIT1(b1); \
29561+ EMIT(_off, 4); \
29562+ /* prevent fall-through, we're not called if off = 0 */ \
29563+ EMIT(0xcccccccc, 4); \
29564+ EMIT(0xcccccccc, 4); \
29565+ break; \
29566+ default: \
29567+ EMIT1(b1); \
29568+ EMIT(_off, 4); \
29569+ } \
29570+} while (0)
29571+
29572+#define EMIT2_off32(b1, b2, _off) \
29573+do { \
29574+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
29575+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
29576+ EMIT(randkey, 4); \
29577+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
29578+ EMIT((_off) - randkey, 4); \
29579+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
29580+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29581+ /* imul eax, ecx */ \
29582+ EMIT3(0x0f, 0xaf, 0xc1); \
29583+ } else { \
29584+ EMIT2(b1, b2); \
29585+ EMIT(_off, 4); \
29586+ } \
29587+} while (0)
29588+#else
29589 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
29590+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
29591+#endif
29592
29593 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
29594 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
29595@@ -90,6 +165,24 @@ do { \
29596 #define X86_JBE 0x76
29597 #define X86_JA 0x77
29598
29599+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29600+#define APPEND_FLOW_VERIFY() \
29601+do { \
29602+ /* mov ecx, randkey */ \
29603+ EMIT1(0xb9); \
29604+ EMIT(randkey, 4); \
29605+ /* cmp ecx, randkey */ \
29606+ EMIT2(0x81, 0xf9); \
29607+ EMIT(randkey, 4); \
29608+ /* jz after 8 int 3s */ \
29609+ EMIT2(0x74, 0x08); \
29610+ EMIT(0xcccccccc, 4); \
29611+ EMIT(0xcccccccc, 4); \
29612+} while (0)
29613+#else
29614+#define APPEND_FLOW_VERIFY() do { } while (0)
29615+#endif
29616+
29617 #define EMIT_COND_JMP(op, offset) \
29618 do { \
29619 if (is_near(offset)) \
29620@@ -97,6 +190,7 @@ do { \
29621 else { \
29622 EMIT2(0x0f, op + 0x10); \
29623 EMIT(offset, 4); /* jxx .+off32 */ \
29624+ APPEND_FLOW_VERIFY(); \
29625 } \
29626 } while (0)
29627
29628@@ -121,12 +215,17 @@ static inline void bpf_flush_icache(void *start, void *end)
29629 set_fs(old_fs);
29630 }
29631
29632+struct bpf_jit_work {
29633+ struct work_struct work;
29634+ void *image;
29635+};
29636+
29637 #define CHOOSE_LOAD_FUNC(K, func) \
29638 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
29639
29640 void bpf_jit_compile(struct sk_filter *fp)
29641 {
29642- u8 temp[64];
29643+ u8 temp[MAX_INSTR_CODE_SIZE];
29644 u8 *prog;
29645 unsigned int proglen, oldproglen = 0;
29646 int ilen, i;
29647@@ -139,6 +238,9 @@ void bpf_jit_compile(struct sk_filter *fp)
29648 unsigned int *addrs;
29649 const struct sock_filter *filter = fp->insns;
29650 int flen = fp->len;
29651+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29652+ unsigned int randkey;
29653+#endif
29654
29655 if (!bpf_jit_enable)
29656 return;
29657@@ -147,11 +249,19 @@ void bpf_jit_compile(struct sk_filter *fp)
29658 if (addrs == NULL)
29659 return;
29660
29661+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
29662+ if (!fp->work)
29663+ goto out;
29664+
29665+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29666+ randkey = get_random_int();
29667+#endif
29668+
29669 /* Before first pass, make a rough estimation of addrs[]
29670- * each bpf instruction is translated to less than 64 bytes
29671+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
29672 */
29673 for (proglen = 0, i = 0; i < flen; i++) {
29674- proglen += 64;
29675+ proglen += MAX_INSTR_CODE_SIZE;
29676 addrs[i] = proglen;
29677 }
29678 cleanup_addr = proglen; /* epilogue address */
29679@@ -261,10 +371,8 @@ void bpf_jit_compile(struct sk_filter *fp)
29680 case BPF_S_ALU_MUL_K: /* A *= K */
29681 if (is_imm8(K))
29682 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
29683- else {
29684- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
29685- EMIT(K, 4);
29686- }
29687+ else
29688+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
29689 break;
29690 case BPF_S_ALU_DIV_X: /* A /= X; */
29691 seen |= SEEN_XREG;
29692@@ -304,13 +412,23 @@ void bpf_jit_compile(struct sk_filter *fp)
29693 break;
29694 case BPF_S_ALU_MOD_K: /* A %= K; */
29695 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
29696+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29697+ DILUTE_CONST_SEQUENCE(K, randkey);
29698+#else
29699 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
29700+#endif
29701 EMIT2(0xf7, 0xf1); /* div %ecx */
29702 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
29703 break;
29704 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
29705+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29706+ DILUTE_CONST_SEQUENCE(K, randkey);
29707+ // imul rax, rcx
29708+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
29709+#else
29710 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
29711 EMIT(K, 4);
29712+#endif
29713 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
29714 break;
29715 case BPF_S_ALU_AND_X:
29716@@ -564,8 +682,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
29717 if (is_imm8(K)) {
29718 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
29719 } else {
29720- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
29721- EMIT(K, 4);
29722+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
29723 }
29724 } else {
29725 EMIT2(0x89,0xde); /* mov %ebx,%esi */
29726@@ -648,17 +765,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29727 break;
29728 default:
29729 /* hmm, too complex filter, give up with jit compiler */
29730- goto out;
29731+ goto error;
29732 }
29733 ilen = prog - temp;
29734 if (image) {
29735 if (unlikely(proglen + ilen > oldproglen)) {
29736 pr_err("bpb_jit_compile fatal error\n");
29737- kfree(addrs);
29738- module_free(NULL, image);
29739- return;
29740+ module_free_exec(NULL, image);
29741+ goto error;
29742 }
29743+ pax_open_kernel();
29744 memcpy(image + proglen, temp, ilen);
29745+ pax_close_kernel();
29746 }
29747 proglen += ilen;
29748 addrs[i] = proglen;
29749@@ -679,11 +797,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29750 break;
29751 }
29752 if (proglen == oldproglen) {
29753- image = module_alloc(max_t(unsigned int,
29754- proglen,
29755- sizeof(struct work_struct)));
29756+ image = module_alloc_exec(proglen);
29757 if (!image)
29758- goto out;
29759+ goto error;
29760 }
29761 oldproglen = proglen;
29762 }
29763@@ -699,7 +815,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29764 bpf_flush_icache(image, image + proglen);
29765
29766 fp->bpf_func = (void *)image;
29767- }
29768+ } else
29769+error:
29770+ kfree(fp->work);
29771+
29772 out:
29773 kfree(addrs);
29774 return;
29775@@ -707,18 +826,20 @@ out:
29776
29777 static void jit_free_defer(struct work_struct *arg)
29778 {
29779- module_free(NULL, arg);
29780+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
29781+ kfree(arg);
29782 }
29783
29784 /* run from softirq, we must use a work_struct to call
29785- * module_free() from process context
29786+ * module_free_exec() from process context
29787 */
29788 void bpf_jit_free(struct sk_filter *fp)
29789 {
29790 if (fp->bpf_func != sk_run_filter) {
29791- struct work_struct *work = (struct work_struct *)fp->bpf_func;
29792+ struct work_struct *work = &fp->work->work;
29793
29794 INIT_WORK(work, jit_free_defer);
29795+ fp->work->image = fp->bpf_func;
29796 schedule_work(work);
29797 }
29798 }
29799diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
29800index d6aa6e8..266395a 100644
29801--- a/arch/x86/oprofile/backtrace.c
29802+++ b/arch/x86/oprofile/backtrace.c
29803@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
29804 struct stack_frame_ia32 *fp;
29805 unsigned long bytes;
29806
29807- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29808+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29809 if (bytes != sizeof(bufhead))
29810 return NULL;
29811
29812- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
29813+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
29814
29815 oprofile_add_trace(bufhead[0].return_address);
29816
29817@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
29818 struct stack_frame bufhead[2];
29819 unsigned long bytes;
29820
29821- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29822+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29823 if (bytes != sizeof(bufhead))
29824 return NULL;
29825
29826@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
29827 {
29828 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
29829
29830- if (!user_mode_vm(regs)) {
29831+ if (!user_mode(regs)) {
29832 unsigned long stack = kernel_stack_pointer(regs);
29833 if (depth)
29834 dump_trace(NULL, regs, (unsigned long *)stack, 0,
29835diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
29836index 48768df..ba9143c 100644
29837--- a/arch/x86/oprofile/nmi_int.c
29838+++ b/arch/x86/oprofile/nmi_int.c
29839@@ -23,6 +23,7 @@
29840 #include <asm/nmi.h>
29841 #include <asm/msr.h>
29842 #include <asm/apic.h>
29843+#include <asm/pgtable.h>
29844
29845 #include "op_counter.h"
29846 #include "op_x86_model.h"
29847@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
29848 if (ret)
29849 return ret;
29850
29851- if (!model->num_virt_counters)
29852- model->num_virt_counters = model->num_counters;
29853+ if (!model->num_virt_counters) {
29854+ pax_open_kernel();
29855+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
29856+ pax_close_kernel();
29857+ }
29858
29859 mux_init(ops);
29860
29861diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
29862index b2b9443..be58856 100644
29863--- a/arch/x86/oprofile/op_model_amd.c
29864+++ b/arch/x86/oprofile/op_model_amd.c
29865@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
29866 num_counters = AMD64_NUM_COUNTERS;
29867 }
29868
29869- op_amd_spec.num_counters = num_counters;
29870- op_amd_spec.num_controls = num_counters;
29871- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29872+ pax_open_kernel();
29873+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
29874+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
29875+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29876+ pax_close_kernel();
29877
29878 return 0;
29879 }
29880diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
29881index d90528e..0127e2b 100644
29882--- a/arch/x86/oprofile/op_model_ppro.c
29883+++ b/arch/x86/oprofile/op_model_ppro.c
29884@@ -19,6 +19,7 @@
29885 #include <asm/msr.h>
29886 #include <asm/apic.h>
29887 #include <asm/nmi.h>
29888+#include <asm/pgtable.h>
29889
29890 #include "op_x86_model.h"
29891 #include "op_counter.h"
29892@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
29893
29894 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
29895
29896- op_arch_perfmon_spec.num_counters = num_counters;
29897- op_arch_perfmon_spec.num_controls = num_counters;
29898+ pax_open_kernel();
29899+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
29900+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
29901+ pax_close_kernel();
29902 }
29903
29904 static int arch_perfmon_init(struct oprofile_operations *ignore)
29905diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
29906index 71e8a67..6a313bb 100644
29907--- a/arch/x86/oprofile/op_x86_model.h
29908+++ b/arch/x86/oprofile/op_x86_model.h
29909@@ -52,7 +52,7 @@ struct op_x86_model_spec {
29910 void (*switch_ctrl)(struct op_x86_model_spec const *model,
29911 struct op_msrs const * const msrs);
29912 #endif
29913-};
29914+} __do_const;
29915
29916 struct op_counter_config;
29917
29918diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
29919index e9e6ed5..e47ae67 100644
29920--- a/arch/x86/pci/amd_bus.c
29921+++ b/arch/x86/pci/amd_bus.c
29922@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
29923 return NOTIFY_OK;
29924 }
29925
29926-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
29927+static struct notifier_block amd_cpu_notifier = {
29928 .notifier_call = amd_cpu_notify,
29929 };
29930
29931diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
29932index 372e9b8..e775a6c 100644
29933--- a/arch/x86/pci/irq.c
29934+++ b/arch/x86/pci/irq.c
29935@@ -50,7 +50,7 @@ struct irq_router {
29936 struct irq_router_handler {
29937 u16 vendor;
29938 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
29939-};
29940+} __do_const;
29941
29942 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
29943 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
29944@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
29945 return 0;
29946 }
29947
29948-static __initdata struct irq_router_handler pirq_routers[] = {
29949+static __initconst const struct irq_router_handler pirq_routers[] = {
29950 { PCI_VENDOR_ID_INTEL, intel_router_probe },
29951 { PCI_VENDOR_ID_AL, ali_router_probe },
29952 { PCI_VENDOR_ID_ITE, ite_router_probe },
29953@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
29954 static void __init pirq_find_router(struct irq_router *r)
29955 {
29956 struct irq_routing_table *rt = pirq_table;
29957- struct irq_router_handler *h;
29958+ const struct irq_router_handler *h;
29959
29960 #ifdef CONFIG_PCI_BIOS
29961 if (!rt->signature) {
29962@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
29963 return 0;
29964 }
29965
29966-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
29967+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
29968 {
29969 .callback = fix_broken_hp_bios_irq9,
29970 .ident = "HP Pavilion N5400 Series Laptop",
29971diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
29972index 6eb18c4..20d83de 100644
29973--- a/arch/x86/pci/mrst.c
29974+++ b/arch/x86/pci/mrst.c
29975@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
29976 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
29977 pci_mmcfg_late_init();
29978 pcibios_enable_irq = mrst_pci_irq_enable;
29979- pci_root_ops = pci_mrst_ops;
29980+ pax_open_kernel();
29981+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
29982+ pax_close_kernel();
29983 pci_soc_mode = 1;
29984 /* Continue with standard init */
29985 return 1;
29986diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
29987index c77b24a..c979855 100644
29988--- a/arch/x86/pci/pcbios.c
29989+++ b/arch/x86/pci/pcbios.c
29990@@ -79,7 +79,7 @@ union bios32 {
29991 static struct {
29992 unsigned long address;
29993 unsigned short segment;
29994-} bios32_indirect = { 0, __KERNEL_CS };
29995+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
29996
29997 /*
29998 * Returns the entry point for the given service, NULL on error
29999@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
30000 unsigned long length; /* %ecx */
30001 unsigned long entry; /* %edx */
30002 unsigned long flags;
30003+ struct desc_struct d, *gdt;
30004
30005 local_irq_save(flags);
30006- __asm__("lcall *(%%edi); cld"
30007+
30008+ gdt = get_cpu_gdt_table(smp_processor_id());
30009+
30010+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
30011+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30012+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
30013+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30014+
30015+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
30016 : "=a" (return_code),
30017 "=b" (address),
30018 "=c" (length),
30019 "=d" (entry)
30020 : "0" (service),
30021 "1" (0),
30022- "D" (&bios32_indirect));
30023+ "D" (&bios32_indirect),
30024+ "r"(__PCIBIOS_DS)
30025+ : "memory");
30026+
30027+ pax_open_kernel();
30028+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
30029+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
30030+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
30031+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
30032+ pax_close_kernel();
30033+
30034 local_irq_restore(flags);
30035
30036 switch (return_code) {
30037- case 0:
30038- return address + entry;
30039- case 0x80: /* Not present */
30040- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30041- return 0;
30042- default: /* Shouldn't happen */
30043- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30044- service, return_code);
30045+ case 0: {
30046+ int cpu;
30047+ unsigned char flags;
30048+
30049+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
30050+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
30051+ printk(KERN_WARNING "bios32_service: not valid\n");
30052 return 0;
30053+ }
30054+ address = address + PAGE_OFFSET;
30055+ length += 16UL; /* some BIOSs underreport this... */
30056+ flags = 4;
30057+ if (length >= 64*1024*1024) {
30058+ length >>= PAGE_SHIFT;
30059+ flags |= 8;
30060+ }
30061+
30062+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30063+ gdt = get_cpu_gdt_table(cpu);
30064+ pack_descriptor(&d, address, length, 0x9b, flags);
30065+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30066+ pack_descriptor(&d, address, length, 0x93, flags);
30067+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30068+ }
30069+ return entry;
30070+ }
30071+ case 0x80: /* Not present */
30072+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30073+ return 0;
30074+ default: /* Shouldn't happen */
30075+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30076+ service, return_code);
30077+ return 0;
30078 }
30079 }
30080
30081 static struct {
30082 unsigned long address;
30083 unsigned short segment;
30084-} pci_indirect = { 0, __KERNEL_CS };
30085+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
30086
30087-static int pci_bios_present;
30088+static int pci_bios_present __read_only;
30089
30090 static int check_pcibios(void)
30091 {
30092@@ -131,11 +174,13 @@ static int check_pcibios(void)
30093 unsigned long flags, pcibios_entry;
30094
30095 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
30096- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
30097+ pci_indirect.address = pcibios_entry;
30098
30099 local_irq_save(flags);
30100- __asm__(
30101- "lcall *(%%edi); cld\n\t"
30102+ __asm__("movw %w6, %%ds\n\t"
30103+ "lcall *%%ss:(%%edi); cld\n\t"
30104+ "push %%ss\n\t"
30105+ "pop %%ds\n\t"
30106 "jc 1f\n\t"
30107 "xor %%ah, %%ah\n"
30108 "1:"
30109@@ -144,7 +189,8 @@ static int check_pcibios(void)
30110 "=b" (ebx),
30111 "=c" (ecx)
30112 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
30113- "D" (&pci_indirect)
30114+ "D" (&pci_indirect),
30115+ "r" (__PCIBIOS_DS)
30116 : "memory");
30117 local_irq_restore(flags);
30118
30119@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30120
30121 switch (len) {
30122 case 1:
30123- __asm__("lcall *(%%esi); cld\n\t"
30124+ __asm__("movw %w6, %%ds\n\t"
30125+ "lcall *%%ss:(%%esi); cld\n\t"
30126+ "push %%ss\n\t"
30127+ "pop %%ds\n\t"
30128 "jc 1f\n\t"
30129 "xor %%ah, %%ah\n"
30130 "1:"
30131@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30132 : "1" (PCIBIOS_READ_CONFIG_BYTE),
30133 "b" (bx),
30134 "D" ((long)reg),
30135- "S" (&pci_indirect));
30136+ "S" (&pci_indirect),
30137+ "r" (__PCIBIOS_DS));
30138 /*
30139 * Zero-extend the result beyond 8 bits, do not trust the
30140 * BIOS having done it:
30141@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30142 *value &= 0xff;
30143 break;
30144 case 2:
30145- __asm__("lcall *(%%esi); cld\n\t"
30146+ __asm__("movw %w6, %%ds\n\t"
30147+ "lcall *%%ss:(%%esi); cld\n\t"
30148+ "push %%ss\n\t"
30149+ "pop %%ds\n\t"
30150 "jc 1f\n\t"
30151 "xor %%ah, %%ah\n"
30152 "1:"
30153@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30154 : "1" (PCIBIOS_READ_CONFIG_WORD),
30155 "b" (bx),
30156 "D" ((long)reg),
30157- "S" (&pci_indirect));
30158+ "S" (&pci_indirect),
30159+ "r" (__PCIBIOS_DS));
30160 /*
30161 * Zero-extend the result beyond 16 bits, do not trust the
30162 * BIOS having done it:
30163@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30164 *value &= 0xffff;
30165 break;
30166 case 4:
30167- __asm__("lcall *(%%esi); cld\n\t"
30168+ __asm__("movw %w6, %%ds\n\t"
30169+ "lcall *%%ss:(%%esi); cld\n\t"
30170+ "push %%ss\n\t"
30171+ "pop %%ds\n\t"
30172 "jc 1f\n\t"
30173 "xor %%ah, %%ah\n"
30174 "1:"
30175@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30176 : "1" (PCIBIOS_READ_CONFIG_DWORD),
30177 "b" (bx),
30178 "D" ((long)reg),
30179- "S" (&pci_indirect));
30180+ "S" (&pci_indirect),
30181+ "r" (__PCIBIOS_DS));
30182 break;
30183 }
30184
30185@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30186
30187 switch (len) {
30188 case 1:
30189- __asm__("lcall *(%%esi); cld\n\t"
30190+ __asm__("movw %w6, %%ds\n\t"
30191+ "lcall *%%ss:(%%esi); cld\n\t"
30192+ "push %%ss\n\t"
30193+ "pop %%ds\n\t"
30194 "jc 1f\n\t"
30195 "xor %%ah, %%ah\n"
30196 "1:"
30197@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30198 "c" (value),
30199 "b" (bx),
30200 "D" ((long)reg),
30201- "S" (&pci_indirect));
30202+ "S" (&pci_indirect),
30203+ "r" (__PCIBIOS_DS));
30204 break;
30205 case 2:
30206- __asm__("lcall *(%%esi); cld\n\t"
30207+ __asm__("movw %w6, %%ds\n\t"
30208+ "lcall *%%ss:(%%esi); cld\n\t"
30209+ "push %%ss\n\t"
30210+ "pop %%ds\n\t"
30211 "jc 1f\n\t"
30212 "xor %%ah, %%ah\n"
30213 "1:"
30214@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30215 "c" (value),
30216 "b" (bx),
30217 "D" ((long)reg),
30218- "S" (&pci_indirect));
30219+ "S" (&pci_indirect),
30220+ "r" (__PCIBIOS_DS));
30221 break;
30222 case 4:
30223- __asm__("lcall *(%%esi); cld\n\t"
30224+ __asm__("movw %w6, %%ds\n\t"
30225+ "lcall *%%ss:(%%esi); cld\n\t"
30226+ "push %%ss\n\t"
30227+ "pop %%ds\n\t"
30228 "jc 1f\n\t"
30229 "xor %%ah, %%ah\n"
30230 "1:"
30231@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30232 "c" (value),
30233 "b" (bx),
30234 "D" ((long)reg),
30235- "S" (&pci_indirect));
30236+ "S" (&pci_indirect),
30237+ "r" (__PCIBIOS_DS));
30238 break;
30239 }
30240
30241@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30242
30243 DBG("PCI: Fetching IRQ routing table... ");
30244 __asm__("push %%es\n\t"
30245+ "movw %w8, %%ds\n\t"
30246 "push %%ds\n\t"
30247 "pop %%es\n\t"
30248- "lcall *(%%esi); cld\n\t"
30249+ "lcall *%%ss:(%%esi); cld\n\t"
30250 "pop %%es\n\t"
30251+ "push %%ss\n\t"
30252+ "pop %%ds\n"
30253 "jc 1f\n\t"
30254 "xor %%ah, %%ah\n"
30255 "1:"
30256@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30257 "1" (0),
30258 "D" ((long) &opt),
30259 "S" (&pci_indirect),
30260- "m" (opt)
30261+ "m" (opt),
30262+ "r" (__PCIBIOS_DS)
30263 : "memory");
30264 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
30265 if (ret & 0xff00)
30266@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30267 {
30268 int ret;
30269
30270- __asm__("lcall *(%%esi); cld\n\t"
30271+ __asm__("movw %w5, %%ds\n\t"
30272+ "lcall *%%ss:(%%esi); cld\n\t"
30273+ "push %%ss\n\t"
30274+ "pop %%ds\n"
30275 "jc 1f\n\t"
30276 "xor %%ah, %%ah\n"
30277 "1:"
30278@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30279 : "0" (PCIBIOS_SET_PCI_HW_INT),
30280 "b" ((dev->bus->number << 8) | dev->devfn),
30281 "c" ((irq << 8) | (pin + 10)),
30282- "S" (&pci_indirect));
30283+ "S" (&pci_indirect),
30284+ "r" (__PCIBIOS_DS));
30285 return !(ret & 0xff00);
30286 }
30287 EXPORT_SYMBOL(pcibios_set_irq_routing);
30288diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
30289index 40e4469..1ab536e 100644
30290--- a/arch/x86/platform/efi/efi_32.c
30291+++ b/arch/x86/platform/efi/efi_32.c
30292@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
30293 {
30294 struct desc_ptr gdt_descr;
30295
30296+#ifdef CONFIG_PAX_KERNEXEC
30297+ struct desc_struct d;
30298+#endif
30299+
30300 local_irq_save(efi_rt_eflags);
30301
30302 load_cr3(initial_page_table);
30303 __flush_tlb_all();
30304
30305+#ifdef CONFIG_PAX_KERNEXEC
30306+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
30307+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30308+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
30309+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30310+#endif
30311+
30312 gdt_descr.address = __pa(get_cpu_gdt_table(0));
30313 gdt_descr.size = GDT_SIZE - 1;
30314 load_gdt(&gdt_descr);
30315@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
30316 {
30317 struct desc_ptr gdt_descr;
30318
30319+#ifdef CONFIG_PAX_KERNEXEC
30320+ struct desc_struct d;
30321+
30322+ memset(&d, 0, sizeof d);
30323+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30324+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30325+#endif
30326+
30327 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
30328 gdt_descr.size = GDT_SIZE - 1;
30329 load_gdt(&gdt_descr);
30330diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
30331index fbe66e6..eae5e38 100644
30332--- a/arch/x86/platform/efi/efi_stub_32.S
30333+++ b/arch/x86/platform/efi/efi_stub_32.S
30334@@ -6,7 +6,9 @@
30335 */
30336
30337 #include <linux/linkage.h>
30338+#include <linux/init.h>
30339 #include <asm/page_types.h>
30340+#include <asm/segment.h>
30341
30342 /*
30343 * efi_call_phys(void *, ...) is a function with variable parameters.
30344@@ -20,7 +22,7 @@
30345 * service functions will comply with gcc calling convention, too.
30346 */
30347
30348-.text
30349+__INIT
30350 ENTRY(efi_call_phys)
30351 /*
30352 * 0. The function can only be called in Linux kernel. So CS has been
30353@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
30354 * The mapping of lower virtual memory has been created in prelog and
30355 * epilog.
30356 */
30357- movl $1f, %edx
30358- subl $__PAGE_OFFSET, %edx
30359- jmp *%edx
30360+#ifdef CONFIG_PAX_KERNEXEC
30361+ movl $(__KERNEXEC_EFI_DS), %edx
30362+ mov %edx, %ds
30363+ mov %edx, %es
30364+ mov %edx, %ss
30365+ addl $2f,(1f)
30366+ ljmp *(1f)
30367+
30368+__INITDATA
30369+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
30370+.previous
30371+
30372+2:
30373+ subl $2b,(1b)
30374+#else
30375+ jmp 1f-__PAGE_OFFSET
30376 1:
30377+#endif
30378
30379 /*
30380 * 2. Now on the top of stack is the return
30381@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
30382 * parameter 2, ..., param n. To make things easy, we save the return
30383 * address of efi_call_phys in a global variable.
30384 */
30385- popl %edx
30386- movl %edx, saved_return_addr
30387- /* get the function pointer into ECX*/
30388- popl %ecx
30389- movl %ecx, efi_rt_function_ptr
30390- movl $2f, %edx
30391- subl $__PAGE_OFFSET, %edx
30392- pushl %edx
30393+ popl (saved_return_addr)
30394+ popl (efi_rt_function_ptr)
30395
30396 /*
30397 * 3. Clear PG bit in %CR0.
30398@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
30399 /*
30400 * 5. Call the physical function.
30401 */
30402- jmp *%ecx
30403+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
30404
30405-2:
30406 /*
30407 * 6. After EFI runtime service returns, control will return to
30408 * following instruction. We'd better readjust stack pointer first.
30409@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
30410 movl %cr0, %edx
30411 orl $0x80000000, %edx
30412 movl %edx, %cr0
30413- jmp 1f
30414-1:
30415+
30416 /*
30417 * 8. Now restore the virtual mode from flat mode by
30418 * adding EIP with PAGE_OFFSET.
30419 */
30420- movl $1f, %edx
30421- jmp *%edx
30422+#ifdef CONFIG_PAX_KERNEXEC
30423+ movl $(__KERNEL_DS), %edx
30424+ mov %edx, %ds
30425+ mov %edx, %es
30426+ mov %edx, %ss
30427+ ljmp $(__KERNEL_CS),$1f
30428+#else
30429+ jmp 1f+__PAGE_OFFSET
30430+#endif
30431 1:
30432
30433 /*
30434 * 9. Balance the stack. And because EAX contain the return value,
30435 * we'd better not clobber it.
30436 */
30437- leal efi_rt_function_ptr, %edx
30438- movl (%edx), %ecx
30439- pushl %ecx
30440+ pushl (efi_rt_function_ptr)
30441
30442 /*
30443- * 10. Push the saved return address onto the stack and return.
30444+ * 10. Return to the saved return address.
30445 */
30446- leal saved_return_addr, %edx
30447- movl (%edx), %ecx
30448- pushl %ecx
30449- ret
30450+ jmpl *(saved_return_addr)
30451 ENDPROC(efi_call_phys)
30452 .previous
30453
30454-.data
30455+__INITDATA
30456 saved_return_addr:
30457 .long 0
30458 efi_rt_function_ptr:
30459diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
30460index 4c07cca..2c8427d 100644
30461--- a/arch/x86/platform/efi/efi_stub_64.S
30462+++ b/arch/x86/platform/efi/efi_stub_64.S
30463@@ -7,6 +7,7 @@
30464 */
30465
30466 #include <linux/linkage.h>
30467+#include <asm/alternative-asm.h>
30468
30469 #define SAVE_XMM \
30470 mov %rsp, %rax; \
30471@@ -40,6 +41,7 @@ ENTRY(efi_call0)
30472 call *%rdi
30473 addq $32, %rsp
30474 RESTORE_XMM
30475+ pax_force_retaddr 0, 1
30476 ret
30477 ENDPROC(efi_call0)
30478
30479@@ -50,6 +52,7 @@ ENTRY(efi_call1)
30480 call *%rdi
30481 addq $32, %rsp
30482 RESTORE_XMM
30483+ pax_force_retaddr 0, 1
30484 ret
30485 ENDPROC(efi_call1)
30486
30487@@ -60,6 +63,7 @@ ENTRY(efi_call2)
30488 call *%rdi
30489 addq $32, %rsp
30490 RESTORE_XMM
30491+ pax_force_retaddr 0, 1
30492 ret
30493 ENDPROC(efi_call2)
30494
30495@@ -71,6 +75,7 @@ ENTRY(efi_call3)
30496 call *%rdi
30497 addq $32, %rsp
30498 RESTORE_XMM
30499+ pax_force_retaddr 0, 1
30500 ret
30501 ENDPROC(efi_call3)
30502
30503@@ -83,6 +88,7 @@ ENTRY(efi_call4)
30504 call *%rdi
30505 addq $32, %rsp
30506 RESTORE_XMM
30507+ pax_force_retaddr 0, 1
30508 ret
30509 ENDPROC(efi_call4)
30510
30511@@ -96,6 +102,7 @@ ENTRY(efi_call5)
30512 call *%rdi
30513 addq $48, %rsp
30514 RESTORE_XMM
30515+ pax_force_retaddr 0, 1
30516 ret
30517 ENDPROC(efi_call5)
30518
30519@@ -112,5 +119,6 @@ ENTRY(efi_call6)
30520 call *%rdi
30521 addq $48, %rsp
30522 RESTORE_XMM
30523+ pax_force_retaddr 0, 1
30524 ret
30525 ENDPROC(efi_call6)
30526diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
30527index e31bcd8..f12dc46 100644
30528--- a/arch/x86/platform/mrst/mrst.c
30529+++ b/arch/x86/platform/mrst/mrst.c
30530@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
30531 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
30532 int sfi_mrtc_num;
30533
30534-static void mrst_power_off(void)
30535+static __noreturn void mrst_power_off(void)
30536 {
30537+ BUG();
30538 }
30539
30540-static void mrst_reboot(void)
30541+static __noreturn void mrst_reboot(void)
30542 {
30543 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
30544+ BUG();
30545 }
30546
30547 /* parse all the mtimer info to a static mtimer array */
30548diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
30549index d6ee929..3637cb5 100644
30550--- a/arch/x86/platform/olpc/olpc_dt.c
30551+++ b/arch/x86/platform/olpc/olpc_dt.c
30552@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
30553 return res;
30554 }
30555
30556-static struct of_pdt_ops prom_olpc_ops __initdata = {
30557+static struct of_pdt_ops prom_olpc_ops __initconst = {
30558 .nextprop = olpc_dt_nextprop,
30559 .getproplen = olpc_dt_getproplen,
30560 .getproperty = olpc_dt_getproperty,
30561diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
30562index 3c68768..07e82b8 100644
30563--- a/arch/x86/power/cpu.c
30564+++ b/arch/x86/power/cpu.c
30565@@ -134,7 +134,7 @@ static void do_fpu_end(void)
30566 static void fix_processor_context(void)
30567 {
30568 int cpu = smp_processor_id();
30569- struct tss_struct *t = &per_cpu(init_tss, cpu);
30570+ struct tss_struct *t = init_tss + cpu;
30571
30572 set_tss_desc(cpu, t); /*
30573 * This just modifies memory; should not be
30574@@ -144,8 +144,6 @@ static void fix_processor_context(void)
30575 */
30576
30577 #ifdef CONFIG_X86_64
30578- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
30579-
30580 syscall_init(); /* This sets MSR_*STAR and related */
30581 #endif
30582 load_TR_desc(); /* This does ltr */
30583diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
30584index cbca565..bae7133 100644
30585--- a/arch/x86/realmode/init.c
30586+++ b/arch/x86/realmode/init.c
30587@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
30588 __va(real_mode_header->trampoline_header);
30589
30590 #ifdef CONFIG_X86_32
30591- trampoline_header->start = __pa(startup_32_smp);
30592+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
30593+
30594+#ifdef CONFIG_PAX_KERNEXEC
30595+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
30596+#endif
30597+
30598+ trampoline_header->boot_cs = __BOOT_CS;
30599 trampoline_header->gdt_limit = __BOOT_DS + 7;
30600 trampoline_header->gdt_base = __pa(boot_gdt);
30601 #else
30602diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
30603index 8869287..d577672 100644
30604--- a/arch/x86/realmode/rm/Makefile
30605+++ b/arch/x86/realmode/rm/Makefile
30606@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
30607 $(call cc-option, -fno-unit-at-a-time)) \
30608 $(call cc-option, -fno-stack-protector) \
30609 $(call cc-option, -mpreferred-stack-boundary=2)
30610+ifdef CONSTIFY_PLUGIN
30611+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
30612+endif
30613 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
30614 GCOV_PROFILE := n
30615diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
30616index a28221d..93c40f1 100644
30617--- a/arch/x86/realmode/rm/header.S
30618+++ b/arch/x86/realmode/rm/header.S
30619@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
30620 #endif
30621 /* APM/BIOS reboot */
30622 .long pa_machine_real_restart_asm
30623-#ifdef CONFIG_X86_64
30624+#ifdef CONFIG_X86_32
30625+ .long __KERNEL_CS
30626+#else
30627 .long __KERNEL32_CS
30628 #endif
30629 END(real_mode_header)
30630diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
30631index c1b2791..f9e31c7 100644
30632--- a/arch/x86/realmode/rm/trampoline_32.S
30633+++ b/arch/x86/realmode/rm/trampoline_32.S
30634@@ -25,6 +25,12 @@
30635 #include <asm/page_types.h>
30636 #include "realmode.h"
30637
30638+#ifdef CONFIG_PAX_KERNEXEC
30639+#define ta(X) (X)
30640+#else
30641+#define ta(X) (pa_ ## X)
30642+#endif
30643+
30644 .text
30645 .code16
30646
30647@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
30648
30649 cli # We should be safe anyway
30650
30651- movl tr_start, %eax # where we need to go
30652-
30653 movl $0xA5A5A5A5, trampoline_status
30654 # write marker for master knows we're running
30655
30656@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
30657 movw $1, %dx # protected mode (PE) bit
30658 lmsw %dx # into protected mode
30659
30660- ljmpl $__BOOT_CS, $pa_startup_32
30661+ ljmpl *(trampoline_header)
30662
30663 .section ".text32","ax"
30664 .code32
30665@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
30666 .balign 8
30667 GLOBAL(trampoline_header)
30668 tr_start: .space 4
30669- tr_gdt_pad: .space 2
30670+ tr_boot_cs: .space 2
30671 tr_gdt: .space 6
30672 END(trampoline_header)
30673
30674diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
30675index bb360dc..3e5945f 100644
30676--- a/arch/x86/realmode/rm/trampoline_64.S
30677+++ b/arch/x86/realmode/rm/trampoline_64.S
30678@@ -107,7 +107,7 @@ ENTRY(startup_32)
30679 wrmsr
30680
30681 # Enable paging and in turn activate Long Mode
30682- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
30683+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
30684 movl %eax, %cr0
30685
30686 /*
30687diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
30688index 79d67bd..c7e1b90 100644
30689--- a/arch/x86/tools/relocs.c
30690+++ b/arch/x86/tools/relocs.c
30691@@ -12,10 +12,13 @@
30692 #include <regex.h>
30693 #include <tools/le_byteshift.h>
30694
30695+#include "../../../include/generated/autoconf.h"
30696+
30697 static void die(char *fmt, ...);
30698
30699 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
30700 static Elf32_Ehdr ehdr;
30701+static Elf32_Phdr *phdr;
30702 static unsigned long reloc_count, reloc_idx;
30703 static unsigned long *relocs;
30704 static unsigned long reloc16_count, reloc16_idx;
30705@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
30706 }
30707 }
30708
30709+static void read_phdrs(FILE *fp)
30710+{
30711+ unsigned int i;
30712+
30713+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
30714+ if (!phdr) {
30715+ die("Unable to allocate %d program headers\n",
30716+ ehdr.e_phnum);
30717+ }
30718+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
30719+ die("Seek to %d failed: %s\n",
30720+ ehdr.e_phoff, strerror(errno));
30721+ }
30722+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
30723+ die("Cannot read ELF program headers: %s\n",
30724+ strerror(errno));
30725+ }
30726+ for(i = 0; i < ehdr.e_phnum; i++) {
30727+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
30728+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
30729+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
30730+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
30731+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
30732+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
30733+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
30734+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
30735+ }
30736+
30737+}
30738+
30739 static void read_shdrs(FILE *fp)
30740 {
30741- int i;
30742+ unsigned int i;
30743 Elf32_Shdr shdr;
30744
30745 secs = calloc(ehdr.e_shnum, sizeof(struct section));
30746@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
30747
30748 static void read_strtabs(FILE *fp)
30749 {
30750- int i;
30751+ unsigned int i;
30752 for (i = 0; i < ehdr.e_shnum; i++) {
30753 struct section *sec = &secs[i];
30754 if (sec->shdr.sh_type != SHT_STRTAB) {
30755@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
30756
30757 static void read_symtabs(FILE *fp)
30758 {
30759- int i,j;
30760+ unsigned int i,j;
30761 for (i = 0; i < ehdr.e_shnum; i++) {
30762 struct section *sec = &secs[i];
30763 if (sec->shdr.sh_type != SHT_SYMTAB) {
30764@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
30765 }
30766
30767
30768-static void read_relocs(FILE *fp)
30769+static void read_relocs(FILE *fp, int use_real_mode)
30770 {
30771- int i,j;
30772+ unsigned int i,j;
30773+ uint32_t base;
30774+
30775 for (i = 0; i < ehdr.e_shnum; i++) {
30776 struct section *sec = &secs[i];
30777 if (sec->shdr.sh_type != SHT_REL) {
30778@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
30779 die("Cannot read symbol table: %s\n",
30780 strerror(errno));
30781 }
30782+ base = 0;
30783+
30784+#ifdef CONFIG_X86_32
30785+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
30786+ if (phdr[j].p_type != PT_LOAD )
30787+ continue;
30788+ 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)
30789+ continue;
30790+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
30791+ break;
30792+ }
30793+#endif
30794+
30795 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
30796 Elf32_Rel *rel = &sec->reltab[j];
30797- rel->r_offset = elf32_to_cpu(rel->r_offset);
30798+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
30799 rel->r_info = elf32_to_cpu(rel->r_info);
30800 }
30801 }
30802@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
30803
30804 static void print_absolute_symbols(void)
30805 {
30806- int i;
30807+ unsigned int i;
30808 printf("Absolute symbols\n");
30809 printf(" Num: Value Size Type Bind Visibility Name\n");
30810 for (i = 0; i < ehdr.e_shnum; i++) {
30811 struct section *sec = &secs[i];
30812 char *sym_strtab;
30813- int j;
30814+ unsigned int j;
30815
30816 if (sec->shdr.sh_type != SHT_SYMTAB) {
30817 continue;
30818@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
30819
30820 static void print_absolute_relocs(void)
30821 {
30822- int i, printed = 0;
30823+ unsigned int i, printed = 0;
30824
30825 for (i = 0; i < ehdr.e_shnum; i++) {
30826 struct section *sec = &secs[i];
30827 struct section *sec_applies, *sec_symtab;
30828 char *sym_strtab;
30829 Elf32_Sym *sh_symtab;
30830- int j;
30831+ unsigned int j;
30832 if (sec->shdr.sh_type != SHT_REL) {
30833 continue;
30834 }
30835@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
30836 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30837 int use_real_mode)
30838 {
30839- int i;
30840+ unsigned int i;
30841 /* Walk through the relocations */
30842 for (i = 0; i < ehdr.e_shnum; i++) {
30843 char *sym_strtab;
30844 Elf32_Sym *sh_symtab;
30845 struct section *sec_applies, *sec_symtab;
30846- int j;
30847+ unsigned int j;
30848 struct section *sec = &secs[i];
30849
30850 if (sec->shdr.sh_type != SHT_REL) {
30851@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30852 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
30853 r_type = ELF32_R_TYPE(rel->r_info);
30854
30855+ if (!use_real_mode) {
30856+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
30857+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
30858+ continue;
30859+
30860+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
30861+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
30862+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
30863+ continue;
30864+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
30865+ continue;
30866+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
30867+ continue;
30868+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
30869+ continue;
30870+#endif
30871+ }
30872+
30873 shn_abs = sym->st_shndx == SHN_ABS;
30874
30875 switch (r_type) {
30876@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
30877
30878 static void emit_relocs(int as_text, int use_real_mode)
30879 {
30880- int i;
30881+ unsigned int i;
30882 /* Count how many relocations I have and allocate space for them. */
30883 reloc_count = 0;
30884 walk_relocs(count_reloc, use_real_mode);
30885@@ -808,10 +874,11 @@ int main(int argc, char **argv)
30886 fname, strerror(errno));
30887 }
30888 read_ehdr(fp);
30889+ read_phdrs(fp);
30890 read_shdrs(fp);
30891 read_strtabs(fp);
30892 read_symtabs(fp);
30893- read_relocs(fp);
30894+ read_relocs(fp, use_real_mode);
30895 if (show_absolute_syms) {
30896 print_absolute_symbols();
30897 goto out;
30898diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
30899index fd14be1..e3c79c0 100644
30900--- a/arch/x86/vdso/Makefile
30901+++ b/arch/x86/vdso/Makefile
30902@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
30903 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
30904 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
30905
30906-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
30907+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
30908 GCOV_PROFILE := n
30909
30910 #
30911diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
30912index 0faad64..39ef157 100644
30913--- a/arch/x86/vdso/vdso32-setup.c
30914+++ b/arch/x86/vdso/vdso32-setup.c
30915@@ -25,6 +25,7 @@
30916 #include <asm/tlbflush.h>
30917 #include <asm/vdso.h>
30918 #include <asm/proto.h>
30919+#include <asm/mman.h>
30920
30921 enum {
30922 VDSO_DISABLED = 0,
30923@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
30924 void enable_sep_cpu(void)
30925 {
30926 int cpu = get_cpu();
30927- struct tss_struct *tss = &per_cpu(init_tss, cpu);
30928+ struct tss_struct *tss = init_tss + cpu;
30929
30930 if (!boot_cpu_has(X86_FEATURE_SEP)) {
30931 put_cpu();
30932@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
30933 gate_vma.vm_start = FIXADDR_USER_START;
30934 gate_vma.vm_end = FIXADDR_USER_END;
30935 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
30936- gate_vma.vm_page_prot = __P101;
30937+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
30938
30939 return 0;
30940 }
30941@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30942 if (compat)
30943 addr = VDSO_HIGH_BASE;
30944 else {
30945- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
30946+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
30947 if (IS_ERR_VALUE(addr)) {
30948 ret = addr;
30949 goto up_fail;
30950 }
30951 }
30952
30953- current->mm->context.vdso = (void *)addr;
30954+ current->mm->context.vdso = addr;
30955
30956 if (compat_uses_vma || !compat) {
30957 /*
30958@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30959 }
30960
30961 current_thread_info()->sysenter_return =
30962- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30963+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30964
30965 up_fail:
30966 if (ret)
30967- current->mm->context.vdso = NULL;
30968+ current->mm->context.vdso = 0;
30969
30970 up_write(&mm->mmap_sem);
30971
30972@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
30973
30974 const char *arch_vma_name(struct vm_area_struct *vma)
30975 {
30976- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
30977+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
30978 return "[vdso]";
30979+
30980+#ifdef CONFIG_PAX_SEGMEXEC
30981+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
30982+ return "[vdso]";
30983+#endif
30984+
30985 return NULL;
30986 }
30987
30988@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
30989 * Check to see if the corresponding task was created in compat vdso
30990 * mode.
30991 */
30992- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
30993+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
30994 return &gate_vma;
30995 return NULL;
30996 }
30997diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
30998index 431e875..cbb23f3 100644
30999--- a/arch/x86/vdso/vma.c
31000+++ b/arch/x86/vdso/vma.c
31001@@ -16,8 +16,6 @@
31002 #include <asm/vdso.h>
31003 #include <asm/page.h>
31004
31005-unsigned int __read_mostly vdso_enabled = 1;
31006-
31007 extern char vdso_start[], vdso_end[];
31008 extern unsigned short vdso_sync_cpuid;
31009
31010@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
31011 * unaligned here as a result of stack start randomization.
31012 */
31013 addr = PAGE_ALIGN(addr);
31014- addr = align_vdso_addr(addr);
31015
31016 return addr;
31017 }
31018@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
31019 unsigned size)
31020 {
31021 struct mm_struct *mm = current->mm;
31022- unsigned long addr;
31023+ unsigned long addr = 0;
31024 int ret;
31025
31026- if (!vdso_enabled)
31027- return 0;
31028-
31029 down_write(&mm->mmap_sem);
31030+
31031+#ifdef CONFIG_PAX_RANDMMAP
31032+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31033+#endif
31034+
31035 addr = vdso_addr(mm->start_stack, size);
31036+ addr = align_vdso_addr(addr);
31037 addr = get_unmapped_area(NULL, addr, size, 0, 0);
31038 if (IS_ERR_VALUE(addr)) {
31039 ret = addr;
31040 goto up_fail;
31041 }
31042
31043- current->mm->context.vdso = (void *)addr;
31044+ mm->context.vdso = addr;
31045
31046 ret = install_special_mapping(mm, addr, size,
31047 VM_READ|VM_EXEC|
31048 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
31049 pages);
31050- if (ret) {
31051- current->mm->context.vdso = NULL;
31052- goto up_fail;
31053- }
31054+ if (ret)
31055+ mm->context.vdso = 0;
31056
31057 up_fail:
31058 up_write(&mm->mmap_sem);
31059@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31060 vdsox32_size);
31061 }
31062 #endif
31063-
31064-static __init int vdso_setup(char *s)
31065-{
31066- vdso_enabled = simple_strtoul(s, NULL, 0);
31067- return 0;
31068-}
31069-__setup("vdso=", vdso_setup);
31070diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
31071index 2262003..f229ced 100644
31072--- a/arch/x86/xen/enlighten.c
31073+++ b/arch/x86/xen/enlighten.c
31074@@ -100,8 +100,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
31075
31076 struct shared_info xen_dummy_shared_info;
31077
31078-void *xen_initial_gdt;
31079-
31080 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
31081 __read_mostly int xen_have_vector_callback;
31082 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
31083@@ -496,8 +494,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
31084 {
31085 unsigned long va = dtr->address;
31086 unsigned int size = dtr->size + 1;
31087- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31088- unsigned long frames[pages];
31089+ unsigned long frames[65536 / PAGE_SIZE];
31090 int f;
31091
31092 /*
31093@@ -545,8 +542,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31094 {
31095 unsigned long va = dtr->address;
31096 unsigned int size = dtr->size + 1;
31097- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31098- unsigned long frames[pages];
31099+ unsigned long frames[65536 / PAGE_SIZE];
31100 int f;
31101
31102 /*
31103@@ -939,7 +935,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
31104 return 0;
31105 }
31106
31107-static void set_xen_basic_apic_ops(void)
31108+static void __init set_xen_basic_apic_ops(void)
31109 {
31110 apic->read = xen_apic_read;
31111 apic->write = xen_apic_write;
31112@@ -1245,30 +1241,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
31113 #endif
31114 };
31115
31116-static void xen_reboot(int reason)
31117+static __noreturn void xen_reboot(int reason)
31118 {
31119 struct sched_shutdown r = { .reason = reason };
31120
31121- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
31122- BUG();
31123+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
31124+ BUG();
31125 }
31126
31127-static void xen_restart(char *msg)
31128+static __noreturn void xen_restart(char *msg)
31129 {
31130 xen_reboot(SHUTDOWN_reboot);
31131 }
31132
31133-static void xen_emergency_restart(void)
31134+static __noreturn void xen_emergency_restart(void)
31135 {
31136 xen_reboot(SHUTDOWN_reboot);
31137 }
31138
31139-static void xen_machine_halt(void)
31140+static __noreturn void xen_machine_halt(void)
31141 {
31142 xen_reboot(SHUTDOWN_poweroff);
31143 }
31144
31145-static void xen_machine_power_off(void)
31146+static __noreturn void xen_machine_power_off(void)
31147 {
31148 if (pm_power_off)
31149 pm_power_off();
31150@@ -1370,7 +1366,17 @@ asmlinkage void __init xen_start_kernel(void)
31151 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
31152
31153 /* Work out if we support NX */
31154- x86_configure_nx();
31155+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
31156+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
31157+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
31158+ unsigned l, h;
31159+
31160+ __supported_pte_mask |= _PAGE_NX;
31161+ rdmsr(MSR_EFER, l, h);
31162+ l |= EFER_NX;
31163+ wrmsr(MSR_EFER, l, h);
31164+ }
31165+#endif
31166
31167 xen_setup_features();
31168
31169@@ -1399,14 +1405,7 @@ asmlinkage void __init xen_start_kernel(void)
31170 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
31171 }
31172
31173- machine_ops = xen_machine_ops;
31174-
31175- /*
31176- * The only reliable way to retain the initial address of the
31177- * percpu gdt_page is to remember it here, so we can go and
31178- * mark it RW later, when the initial percpu area is freed.
31179- */
31180- xen_initial_gdt = &per_cpu(gdt_page, 0);
31181+ memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
31182
31183 xen_smp_init();
31184
31185@@ -1598,7 +1597,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
31186 return NOTIFY_OK;
31187 }
31188
31189-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
31190+static struct notifier_block xen_hvm_cpu_notifier = {
31191 .notifier_call = xen_hvm_cpu_notify,
31192 };
31193
31194diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
31195index 01de35c..0bda07b 100644
31196--- a/arch/x86/xen/mmu.c
31197+++ b/arch/x86/xen/mmu.c
31198@@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31199 /* L3_k[510] -> level2_kernel_pgt
31200 * L3_i[511] -> level2_fixmap_pgt */
31201 convert_pfn_mfn(level3_kernel_pgt);
31202+ convert_pfn_mfn(level3_vmalloc_start_pgt);
31203+ convert_pfn_mfn(level3_vmalloc_end_pgt);
31204+ convert_pfn_mfn(level3_vmemmap_pgt);
31205
31206 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
31207 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
31208@@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31209 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
31210 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
31211 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
31212+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
31213+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
31214+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
31215 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
31216 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
31217+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
31218 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
31219 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
31220
31221@@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
31222 pv_mmu_ops.set_pud = xen_set_pud;
31223 #if PAGETABLE_LEVELS == 4
31224 pv_mmu_ops.set_pgd = xen_set_pgd;
31225+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
31226 #endif
31227
31228 /* This will work as long as patching hasn't happened yet
31229@@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
31230 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
31231 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
31232 .set_pgd = xen_set_pgd_hyper,
31233+ .set_pgd_batched = xen_set_pgd_hyper,
31234
31235 .alloc_pud = xen_alloc_pmd_init,
31236 .release_pud = xen_release_pmd_init,
31237diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
31238index 34bc4ce..c34aa24 100644
31239--- a/arch/x86/xen/smp.c
31240+++ b/arch/x86/xen/smp.c
31241@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
31242 {
31243 BUG_ON(smp_processor_id() != 0);
31244 native_smp_prepare_boot_cpu();
31245-
31246- /* We've switched to the "real" per-cpu gdt, so make sure the
31247- old memory can be recycled */
31248- make_lowmem_page_readwrite(xen_initial_gdt);
31249-
31250 xen_filter_cpu_maps();
31251 xen_setup_vcpu_info_placement();
31252 }
31253@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31254 gdt = get_cpu_gdt_table(cpu);
31255
31256 ctxt->flags = VGCF_IN_KERNEL;
31257- ctxt->user_regs.ds = __USER_DS;
31258- ctxt->user_regs.es = __USER_DS;
31259+ ctxt->user_regs.ds = __KERNEL_DS;
31260+ ctxt->user_regs.es = __KERNEL_DS;
31261 ctxt->user_regs.ss = __KERNEL_DS;
31262 #ifdef CONFIG_X86_32
31263 ctxt->user_regs.fs = __KERNEL_PERCPU;
31264- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
31265+ savesegment(gs, ctxt->user_regs.gs);
31266 #else
31267 ctxt->gs_base_kernel = per_cpu_offset(cpu);
31268 #endif
31269@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
31270 int rc;
31271
31272 per_cpu(current_task, cpu) = idle;
31273+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
31274 #ifdef CONFIG_X86_32
31275 irq_ctx_init(cpu);
31276 #else
31277 clear_tsk_thread_flag(idle, TIF_FORK);
31278- per_cpu(kernel_stack, cpu) =
31279- (unsigned long)task_stack_page(idle) -
31280- KERNEL_STACK_OFFSET + THREAD_SIZE;
31281+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
31282 #endif
31283 xen_setup_runstate_info(cpu);
31284 xen_setup_timer(cpu);
31285@@ -630,7 +624,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
31286
31287 void __init xen_smp_init(void)
31288 {
31289- smp_ops = xen_smp_ops;
31290+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
31291 xen_fill_possible_map();
31292 xen_init_spinlocks();
31293 }
31294diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
31295index 33ca6e4..0ded929 100644
31296--- a/arch/x86/xen/xen-asm_32.S
31297+++ b/arch/x86/xen/xen-asm_32.S
31298@@ -84,14 +84,14 @@ ENTRY(xen_iret)
31299 ESP_OFFSET=4 # bytes pushed onto stack
31300
31301 /*
31302- * Store vcpu_info pointer for easy access. Do it this way to
31303- * avoid having to reload %fs
31304+ * Store vcpu_info pointer for easy access.
31305 */
31306 #ifdef CONFIG_SMP
31307- GET_THREAD_INFO(%eax)
31308- movl %ss:TI_cpu(%eax), %eax
31309- movl %ss:__per_cpu_offset(,%eax,4), %eax
31310- mov %ss:xen_vcpu(%eax), %eax
31311+ push %fs
31312+ mov $(__KERNEL_PERCPU), %eax
31313+ mov %eax, %fs
31314+ mov PER_CPU_VAR(xen_vcpu), %eax
31315+ pop %fs
31316 #else
31317 movl %ss:xen_vcpu, %eax
31318 #endif
31319diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
31320index 7faed58..ba4427c 100644
31321--- a/arch/x86/xen/xen-head.S
31322+++ b/arch/x86/xen/xen-head.S
31323@@ -19,6 +19,17 @@ ENTRY(startup_xen)
31324 #ifdef CONFIG_X86_32
31325 mov %esi,xen_start_info
31326 mov $init_thread_union+THREAD_SIZE,%esp
31327+#ifdef CONFIG_SMP
31328+ movl $cpu_gdt_table,%edi
31329+ movl $__per_cpu_load,%eax
31330+ movw %ax,__KERNEL_PERCPU + 2(%edi)
31331+ rorl $16,%eax
31332+ movb %al,__KERNEL_PERCPU + 4(%edi)
31333+ movb %ah,__KERNEL_PERCPU + 7(%edi)
31334+ movl $__per_cpu_end - 1,%eax
31335+ subl $__per_cpu_start,%eax
31336+ movw %ax,__KERNEL_PERCPU + 0(%edi)
31337+#endif
31338 #else
31339 mov %rsi,xen_start_info
31340 mov $init_thread_union+THREAD_SIZE,%rsp
31341diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
31342index a95b417..b6dbd0b 100644
31343--- a/arch/x86/xen/xen-ops.h
31344+++ b/arch/x86/xen/xen-ops.h
31345@@ -10,8 +10,6 @@
31346 extern const char xen_hypervisor_callback[];
31347 extern const char xen_failsafe_callback[];
31348
31349-extern void *xen_initial_gdt;
31350-
31351 struct trap_info;
31352 void xen_copy_trap_info(struct trap_info *traps);
31353
31354diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
31355index 525bd3d..ef888b1 100644
31356--- a/arch/xtensa/variants/dc232b/include/variant/core.h
31357+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
31358@@ -119,9 +119,9 @@
31359 ----------------------------------------------------------------------*/
31360
31361 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
31362-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
31363 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
31364 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
31365+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31366
31367 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
31368 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
31369diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
31370index 2f33760..835e50a 100644
31371--- a/arch/xtensa/variants/fsf/include/variant/core.h
31372+++ b/arch/xtensa/variants/fsf/include/variant/core.h
31373@@ -11,6 +11,7 @@
31374 #ifndef _XTENSA_CORE_H
31375 #define _XTENSA_CORE_H
31376
31377+#include <linux/const.h>
31378
31379 /****************************************************************************
31380 Parameters Useful for Any Code, USER or PRIVILEGED
31381@@ -112,9 +113,9 @@
31382 ----------------------------------------------------------------------*/
31383
31384 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31385-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31386 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31387 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31388+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31389
31390 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
31391 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
31392diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
31393index af00795..2bb8105 100644
31394--- a/arch/xtensa/variants/s6000/include/variant/core.h
31395+++ b/arch/xtensa/variants/s6000/include/variant/core.h
31396@@ -11,6 +11,7 @@
31397 #ifndef _XTENSA_CORE_CONFIGURATION_H
31398 #define _XTENSA_CORE_CONFIGURATION_H
31399
31400+#include <linux/const.h>
31401
31402 /****************************************************************************
31403 Parameters Useful for Any Code, USER or PRIVILEGED
31404@@ -118,9 +119,9 @@
31405 ----------------------------------------------------------------------*/
31406
31407 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31408-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31409 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31410 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31411+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31412
31413 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
31414 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
31415diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
31416index 58916af..eb9dbcf6 100644
31417--- a/block/blk-iopoll.c
31418+++ b/block/blk-iopoll.c
31419@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
31420 }
31421 EXPORT_SYMBOL(blk_iopoll_complete);
31422
31423-static void blk_iopoll_softirq(struct softirq_action *h)
31424+static void blk_iopoll_softirq(void)
31425 {
31426 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
31427 int rearm = 0, budget = blk_iopoll_budget;
31428@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
31429 return NOTIFY_OK;
31430 }
31431
31432-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
31433+static struct notifier_block blk_iopoll_cpu_notifier = {
31434 .notifier_call = blk_iopoll_cpu_notify,
31435 };
31436
31437diff --git a/block/blk-map.c b/block/blk-map.c
31438index 623e1cd..ca1e109 100644
31439--- a/block/blk-map.c
31440+++ b/block/blk-map.c
31441@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
31442 if (!len || !kbuf)
31443 return -EINVAL;
31444
31445- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
31446+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
31447 if (do_copy)
31448 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
31449 else
31450diff --git a/block/blk-softirq.c b/block/blk-softirq.c
31451index 467c8de..f3628c5 100644
31452--- a/block/blk-softirq.c
31453+++ b/block/blk-softirq.c
31454@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
31455 * Softirq action handler - move entries to local list and loop over them
31456 * while passing them to the queue registered handler.
31457 */
31458-static void blk_done_softirq(struct softirq_action *h)
31459+static void blk_done_softirq(void)
31460 {
31461 struct list_head *cpu_list, local_list;
31462
31463@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
31464 return NOTIFY_OK;
31465 }
31466
31467-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
31468+static struct notifier_block blk_cpu_notifier = {
31469 .notifier_call = blk_cpu_notify,
31470 };
31471
31472diff --git a/block/bsg.c b/block/bsg.c
31473index ff64ae3..593560c 100644
31474--- a/block/bsg.c
31475+++ b/block/bsg.c
31476@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
31477 struct sg_io_v4 *hdr, struct bsg_device *bd,
31478 fmode_t has_write_perm)
31479 {
31480+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31481+ unsigned char *cmdptr;
31482+
31483 if (hdr->request_len > BLK_MAX_CDB) {
31484 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
31485 if (!rq->cmd)
31486 return -ENOMEM;
31487- }
31488+ cmdptr = rq->cmd;
31489+ } else
31490+ cmdptr = tmpcmd;
31491
31492- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
31493+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
31494 hdr->request_len))
31495 return -EFAULT;
31496
31497+ if (cmdptr != rq->cmd)
31498+ memcpy(rq->cmd, cmdptr, hdr->request_len);
31499+
31500 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
31501 if (blk_verify_command(rq->cmd, has_write_perm))
31502 return -EPERM;
31503diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
31504index 7c668c8..db3521c 100644
31505--- a/block/compat_ioctl.c
31506+++ b/block/compat_ioctl.c
31507@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
31508 err |= __get_user(f->spec1, &uf->spec1);
31509 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
31510 err |= __get_user(name, &uf->name);
31511- f->name = compat_ptr(name);
31512+ f->name = (void __force_kernel *)compat_ptr(name);
31513 if (err) {
31514 err = -EFAULT;
31515 goto out;
31516diff --git a/block/partitions/efi.c b/block/partitions/efi.c
31517index b62fb88..bdab4c4 100644
31518--- a/block/partitions/efi.c
31519+++ b/block/partitions/efi.c
31520@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
31521 if (!gpt)
31522 return NULL;
31523
31524+ if (!le32_to_cpu(gpt->num_partition_entries))
31525+ return NULL;
31526+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
31527+ if (!pte)
31528+ return NULL;
31529+
31530 count = le32_to_cpu(gpt->num_partition_entries) *
31531 le32_to_cpu(gpt->sizeof_partition_entry);
31532- if (!count)
31533- return NULL;
31534- pte = kzalloc(count, GFP_KERNEL);
31535- if (!pte)
31536- return NULL;
31537-
31538 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
31539 (u8 *) pte,
31540 count) < count) {
31541diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
31542index 9a87daa..fb17486 100644
31543--- a/block/scsi_ioctl.c
31544+++ b/block/scsi_ioctl.c
31545@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
31546 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
31547 struct sg_io_hdr *hdr, fmode_t mode)
31548 {
31549- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
31550+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31551+ unsigned char *cmdptr;
31552+
31553+ if (rq->cmd != rq->__cmd)
31554+ cmdptr = rq->cmd;
31555+ else
31556+ cmdptr = tmpcmd;
31557+
31558+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
31559 return -EFAULT;
31560+
31561+ if (cmdptr != rq->cmd)
31562+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
31563+
31564 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
31565 return -EPERM;
31566
31567@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31568 int err;
31569 unsigned int in_len, out_len, bytes, opcode, cmdlen;
31570 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
31571+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31572+ unsigned char *cmdptr;
31573
31574 if (!sic)
31575 return -EINVAL;
31576@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31577 */
31578 err = -EFAULT;
31579 rq->cmd_len = cmdlen;
31580- if (copy_from_user(rq->cmd, sic->data, cmdlen))
31581+
31582+ if (rq->cmd != rq->__cmd)
31583+ cmdptr = rq->cmd;
31584+ else
31585+ cmdptr = tmpcmd;
31586+
31587+ if (copy_from_user(cmdptr, sic->data, cmdlen))
31588 goto error;
31589
31590+ if (rq->cmd != cmdptr)
31591+ memcpy(rq->cmd, cmdptr, cmdlen);
31592+
31593 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
31594 goto error;
31595
31596diff --git a/crypto/cryptd.c b/crypto/cryptd.c
31597index 7bdd61b..afec999 100644
31598--- a/crypto/cryptd.c
31599+++ b/crypto/cryptd.c
31600@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
31601
31602 struct cryptd_blkcipher_request_ctx {
31603 crypto_completion_t complete;
31604-};
31605+} __no_const;
31606
31607 struct cryptd_hash_ctx {
31608 struct crypto_shash *child;
31609@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
31610
31611 struct cryptd_aead_request_ctx {
31612 crypto_completion_t complete;
31613-};
31614+} __no_const;
31615
31616 static void cryptd_queue_worker(struct work_struct *work);
31617
31618diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
31619index f6d9baf..dfd511f 100644
31620--- a/crypto/crypto_user.c
31621+++ b/crypto/crypto_user.c
31622@@ -30,6 +30,8 @@
31623
31624 #include "internal.h"
31625
31626+#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
31627+
31628 static DEFINE_MUTEX(crypto_cfg_mutex);
31629
31630 /* The crypto netlink socket */
31631@@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
31632 struct crypto_dump_info info;
31633 int err;
31634
31635- if (!p->cru_driver_name)
31636+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31637+ return -EINVAL;
31638+
31639+ if (!p->cru_driver_name[0])
31640 return -EINVAL;
31641
31642 alg = crypto_alg_match(p, 1);
31643@@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31644 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
31645 LIST_HEAD(list);
31646
31647+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31648+ return -EINVAL;
31649+
31650 if (priority && !strlen(p->cru_driver_name))
31651 return -EINVAL;
31652
31653@@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31654 struct crypto_alg *alg;
31655 struct crypto_user_alg *p = nlmsg_data(nlh);
31656
31657+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31658+ return -EINVAL;
31659+
31660 alg = crypto_alg_match(p, 1);
31661 if (!alg)
31662 return -ENOENT;
31663@@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31664 struct crypto_user_alg *p = nlmsg_data(nlh);
31665 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
31666
31667+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31668+ return -EINVAL;
31669+
31670 if (strlen(p->cru_driver_name))
31671 exact = 1;
31672
31673diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
31674index f220d64..d359ad6 100644
31675--- a/drivers/acpi/apei/apei-internal.h
31676+++ b/drivers/acpi/apei/apei-internal.h
31677@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
31678 struct apei_exec_ins_type {
31679 u32 flags;
31680 apei_exec_ins_func_t run;
31681-};
31682+} __do_const;
31683
31684 struct apei_exec_context {
31685 u32 ip;
31686diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
31687index e6defd8..c26a225 100644
31688--- a/drivers/acpi/apei/cper.c
31689+++ b/drivers/acpi/apei/cper.c
31690@@ -38,12 +38,12 @@
31691 */
31692 u64 cper_next_record_id(void)
31693 {
31694- static atomic64_t seq;
31695+ static atomic64_unchecked_t seq;
31696
31697- if (!atomic64_read(&seq))
31698- atomic64_set(&seq, ((u64)get_seconds()) << 32);
31699+ if (!atomic64_read_unchecked(&seq))
31700+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
31701
31702- return atomic64_inc_return(&seq);
31703+ return atomic64_inc_return_unchecked(&seq);
31704 }
31705 EXPORT_SYMBOL_GPL(cper_next_record_id);
31706
31707diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
31708index be60399..778b33e8 100644
31709--- a/drivers/acpi/bgrt.c
31710+++ b/drivers/acpi/bgrt.c
31711@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
31712 return -ENODEV;
31713
31714 sysfs_bin_attr_init(&image_attr);
31715- image_attr.private = bgrt_image;
31716- image_attr.size = bgrt_image_size;
31717+ pax_open_kernel();
31718+ *(void **)&image_attr.private = bgrt_image;
31719+ *(size_t *)&image_attr.size = bgrt_image_size;
31720+ pax_close_kernel();
31721
31722 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
31723 if (!bgrt_kobj)
31724diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
31725index cb96296..b81293b 100644
31726--- a/drivers/acpi/blacklist.c
31727+++ b/drivers/acpi/blacklist.c
31728@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
31729 u32 is_critical_error;
31730 };
31731
31732-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
31733+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
31734
31735 /*
31736 * POLICY: If *anything* doesn't work, put it on the blacklist.
31737@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
31738 return 0;
31739 }
31740
31741-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
31742+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
31743 {
31744 .callback = dmi_disable_osi_vista,
31745 .ident = "Fujitsu Siemens",
31746diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
31747index 7586544..636a2f0 100644
31748--- a/drivers/acpi/ec_sys.c
31749+++ b/drivers/acpi/ec_sys.c
31750@@ -12,6 +12,7 @@
31751 #include <linux/acpi.h>
31752 #include <linux/debugfs.h>
31753 #include <linux/module.h>
31754+#include <linux/uaccess.h>
31755 #include "internal.h"
31756
31757 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
31758@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31759 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
31760 */
31761 unsigned int size = EC_SPACE_SIZE;
31762- u8 *data = (u8 *) buf;
31763+ u8 data;
31764 loff_t init_off = *off;
31765 int err = 0;
31766
31767@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31768 size = count;
31769
31770 while (size) {
31771- err = ec_read(*off, &data[*off - init_off]);
31772+ err = ec_read(*off, &data);
31773 if (err)
31774 return err;
31775+ if (put_user(data, &buf[*off - init_off]))
31776+ return -EFAULT;
31777 *off += 1;
31778 size--;
31779 }
31780@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31781
31782 unsigned int size = count;
31783 loff_t init_off = *off;
31784- u8 *data = (u8 *) buf;
31785 int err = 0;
31786
31787 if (*off >= EC_SPACE_SIZE)
31788@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31789 }
31790
31791 while (size) {
31792- u8 byte_write = data[*off - init_off];
31793+ u8 byte_write;
31794+ if (get_user(byte_write, &buf[*off - init_off]))
31795+ return -EFAULT;
31796 err = ec_write(*off, byte_write);
31797 if (err)
31798 return err;
31799diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
31800index e83311b..142b5cc 100644
31801--- a/drivers/acpi/processor_driver.c
31802+++ b/drivers/acpi/processor_driver.c
31803@@ -558,7 +558,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
31804 return 0;
31805 #endif
31806
31807- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
31808+ BUG_ON(pr->id >= nr_cpu_ids);
31809
31810 /*
31811 * Buggy BIOS check
31812diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
31813index ed9a1cc..f4a354c 100644
31814--- a/drivers/acpi/processor_idle.c
31815+++ b/drivers/acpi/processor_idle.c
31816@@ -1005,7 +1005,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
31817 {
31818 int i, count = CPUIDLE_DRIVER_STATE_START;
31819 struct acpi_processor_cx *cx;
31820- struct cpuidle_state *state;
31821+ cpuidle_state_no_const *state;
31822 struct cpuidle_driver *drv = &acpi_idle_driver;
31823
31824 if (!pr->flags.power_setup_done)
31825diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
31826index ea61ca9..3fdd70d 100644
31827--- a/drivers/acpi/sysfs.c
31828+++ b/drivers/acpi/sysfs.c
31829@@ -420,11 +420,11 @@ static u32 num_counters;
31830 static struct attribute **all_attrs;
31831 static u32 acpi_gpe_count;
31832
31833-static struct attribute_group interrupt_stats_attr_group = {
31834+static attribute_group_no_const interrupt_stats_attr_group = {
31835 .name = "interrupts",
31836 };
31837
31838-static struct kobj_attribute *counter_attrs;
31839+static kobj_attribute_no_const *counter_attrs;
31840
31841 static void delete_gpe_attr_array(void)
31842 {
31843diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
31844index 6cd7805..07facb3 100644
31845--- a/drivers/ata/libahci.c
31846+++ b/drivers/ata/libahci.c
31847@@ -1230,7 +1230,7 @@ int ahci_kick_engine(struct ata_port *ap)
31848 }
31849 EXPORT_SYMBOL_GPL(ahci_kick_engine);
31850
31851-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
31852+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
31853 struct ata_taskfile *tf, int is_cmd, u16 flags,
31854 unsigned long timeout_msec)
31855 {
31856diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
31857index 46cd3f4..0871ad0 100644
31858--- a/drivers/ata/libata-core.c
31859+++ b/drivers/ata/libata-core.c
31860@@ -4780,7 +4780,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
31861 struct ata_port *ap;
31862 unsigned int tag;
31863
31864- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31865+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31866 ap = qc->ap;
31867
31868 qc->flags = 0;
31869@@ -4796,7 +4796,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
31870 struct ata_port *ap;
31871 struct ata_link *link;
31872
31873- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31874+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31875 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
31876 ap = qc->ap;
31877 link = qc->dev->link;
31878@@ -5892,6 +5892,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31879 return;
31880
31881 spin_lock(&lock);
31882+ pax_open_kernel();
31883
31884 for (cur = ops->inherits; cur; cur = cur->inherits) {
31885 void **inherit = (void **)cur;
31886@@ -5905,8 +5906,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31887 if (IS_ERR(*pp))
31888 *pp = NULL;
31889
31890- ops->inherits = NULL;
31891+ *(struct ata_port_operations **)&ops->inherits = NULL;
31892
31893+ pax_close_kernel();
31894 spin_unlock(&lock);
31895 }
31896
31897diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
31898index 405022d..fb70e53 100644
31899--- a/drivers/ata/pata_arasan_cf.c
31900+++ b/drivers/ata/pata_arasan_cf.c
31901@@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
31902 /* Handle platform specific quirks */
31903 if (pdata->quirk) {
31904 if (pdata->quirk & CF_BROKEN_PIO) {
31905- ap->ops->set_piomode = NULL;
31906+ pax_open_kernel();
31907+ *(void **)&ap->ops->set_piomode = NULL;
31908+ pax_close_kernel();
31909 ap->pio_mask = 0;
31910 }
31911 if (pdata->quirk & CF_BROKEN_MWDMA)
31912diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
31913index f9b983a..887b9d8 100644
31914--- a/drivers/atm/adummy.c
31915+++ b/drivers/atm/adummy.c
31916@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
31917 vcc->pop(vcc, skb);
31918 else
31919 dev_kfree_skb_any(skb);
31920- atomic_inc(&vcc->stats->tx);
31921+ atomic_inc_unchecked(&vcc->stats->tx);
31922
31923 return 0;
31924 }
31925diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
31926index 77a7480..05cde58 100644
31927--- a/drivers/atm/ambassador.c
31928+++ b/drivers/atm/ambassador.c
31929@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
31930 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
31931
31932 // VC layer stats
31933- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31934+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31935
31936 // free the descriptor
31937 kfree (tx_descr);
31938@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31939 dump_skb ("<<<", vc, skb);
31940
31941 // VC layer stats
31942- atomic_inc(&atm_vcc->stats->rx);
31943+ atomic_inc_unchecked(&atm_vcc->stats->rx);
31944 __net_timestamp(skb);
31945 // end of our responsibility
31946 atm_vcc->push (atm_vcc, skb);
31947@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31948 } else {
31949 PRINTK (KERN_INFO, "dropped over-size frame");
31950 // should we count this?
31951- atomic_inc(&atm_vcc->stats->rx_drop);
31952+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31953 }
31954
31955 } else {
31956@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
31957 }
31958
31959 if (check_area (skb->data, skb->len)) {
31960- atomic_inc(&atm_vcc->stats->tx_err);
31961+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
31962 return -ENOMEM; // ?
31963 }
31964
31965diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
31966index b22d71c..d6e1049 100644
31967--- a/drivers/atm/atmtcp.c
31968+++ b/drivers/atm/atmtcp.c
31969@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31970 if (vcc->pop) vcc->pop(vcc,skb);
31971 else dev_kfree_skb(skb);
31972 if (dev_data) return 0;
31973- atomic_inc(&vcc->stats->tx_err);
31974+ atomic_inc_unchecked(&vcc->stats->tx_err);
31975 return -ENOLINK;
31976 }
31977 size = skb->len+sizeof(struct atmtcp_hdr);
31978@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31979 if (!new_skb) {
31980 if (vcc->pop) vcc->pop(vcc,skb);
31981 else dev_kfree_skb(skb);
31982- atomic_inc(&vcc->stats->tx_err);
31983+ atomic_inc_unchecked(&vcc->stats->tx_err);
31984 return -ENOBUFS;
31985 }
31986 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
31987@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31988 if (vcc->pop) vcc->pop(vcc,skb);
31989 else dev_kfree_skb(skb);
31990 out_vcc->push(out_vcc,new_skb);
31991- atomic_inc(&vcc->stats->tx);
31992- atomic_inc(&out_vcc->stats->rx);
31993+ atomic_inc_unchecked(&vcc->stats->tx);
31994+ atomic_inc_unchecked(&out_vcc->stats->rx);
31995 return 0;
31996 }
31997
31998@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31999 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
32000 read_unlock(&vcc_sklist_lock);
32001 if (!out_vcc) {
32002- atomic_inc(&vcc->stats->tx_err);
32003+ atomic_inc_unchecked(&vcc->stats->tx_err);
32004 goto done;
32005 }
32006 skb_pull(skb,sizeof(struct atmtcp_hdr));
32007@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32008 __net_timestamp(new_skb);
32009 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
32010 out_vcc->push(out_vcc,new_skb);
32011- atomic_inc(&vcc->stats->tx);
32012- atomic_inc(&out_vcc->stats->rx);
32013+ atomic_inc_unchecked(&vcc->stats->tx);
32014+ atomic_inc_unchecked(&out_vcc->stats->rx);
32015 done:
32016 if (vcc->pop) vcc->pop(vcc,skb);
32017 else dev_kfree_skb(skb);
32018diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
32019index c1eb6fa..4c71be9 100644
32020--- a/drivers/atm/eni.c
32021+++ b/drivers/atm/eni.c
32022@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
32023 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
32024 vcc->dev->number);
32025 length = 0;
32026- atomic_inc(&vcc->stats->rx_err);
32027+ atomic_inc_unchecked(&vcc->stats->rx_err);
32028 }
32029 else {
32030 length = ATM_CELL_SIZE-1; /* no HEC */
32031@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32032 size);
32033 }
32034 eff = length = 0;
32035- atomic_inc(&vcc->stats->rx_err);
32036+ atomic_inc_unchecked(&vcc->stats->rx_err);
32037 }
32038 else {
32039 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
32040@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32041 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
32042 vcc->dev->number,vcc->vci,length,size << 2,descr);
32043 length = eff = 0;
32044- atomic_inc(&vcc->stats->rx_err);
32045+ atomic_inc_unchecked(&vcc->stats->rx_err);
32046 }
32047 }
32048 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
32049@@ -767,7 +767,7 @@ rx_dequeued++;
32050 vcc->push(vcc,skb);
32051 pushed++;
32052 }
32053- atomic_inc(&vcc->stats->rx);
32054+ atomic_inc_unchecked(&vcc->stats->rx);
32055 }
32056 wake_up(&eni_dev->rx_wait);
32057 }
32058@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
32059 PCI_DMA_TODEVICE);
32060 if (vcc->pop) vcc->pop(vcc,skb);
32061 else dev_kfree_skb_irq(skb);
32062- atomic_inc(&vcc->stats->tx);
32063+ atomic_inc_unchecked(&vcc->stats->tx);
32064 wake_up(&eni_dev->tx_wait);
32065 dma_complete++;
32066 }
32067diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
32068index b41c948..a002b17 100644
32069--- a/drivers/atm/firestream.c
32070+++ b/drivers/atm/firestream.c
32071@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
32072 }
32073 }
32074
32075- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32076+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32077
32078 fs_dprintk (FS_DEBUG_TXMEM, "i");
32079 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
32080@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32081 #endif
32082 skb_put (skb, qe->p1 & 0xffff);
32083 ATM_SKB(skb)->vcc = atm_vcc;
32084- atomic_inc(&atm_vcc->stats->rx);
32085+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32086 __net_timestamp(skb);
32087 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
32088 atm_vcc->push (atm_vcc, skb);
32089@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32090 kfree (pe);
32091 }
32092 if (atm_vcc)
32093- atomic_inc(&atm_vcc->stats->rx_drop);
32094+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32095 break;
32096 case 0x1f: /* Reassembly abort: no buffers. */
32097 /* Silently increment error counter. */
32098 if (atm_vcc)
32099- atomic_inc(&atm_vcc->stats->rx_drop);
32100+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32101 break;
32102 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
32103 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
32104diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
32105index 204814e..cede831 100644
32106--- a/drivers/atm/fore200e.c
32107+++ b/drivers/atm/fore200e.c
32108@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
32109 #endif
32110 /* check error condition */
32111 if (*entry->status & STATUS_ERROR)
32112- atomic_inc(&vcc->stats->tx_err);
32113+ atomic_inc_unchecked(&vcc->stats->tx_err);
32114 else
32115- atomic_inc(&vcc->stats->tx);
32116+ atomic_inc_unchecked(&vcc->stats->tx);
32117 }
32118 }
32119
32120@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32121 if (skb == NULL) {
32122 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
32123
32124- atomic_inc(&vcc->stats->rx_drop);
32125+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32126 return -ENOMEM;
32127 }
32128
32129@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32130
32131 dev_kfree_skb_any(skb);
32132
32133- atomic_inc(&vcc->stats->rx_drop);
32134+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32135 return -ENOMEM;
32136 }
32137
32138 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32139
32140 vcc->push(vcc, skb);
32141- atomic_inc(&vcc->stats->rx);
32142+ atomic_inc_unchecked(&vcc->stats->rx);
32143
32144 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32145
32146@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
32147 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
32148 fore200e->atm_dev->number,
32149 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
32150- atomic_inc(&vcc->stats->rx_err);
32151+ atomic_inc_unchecked(&vcc->stats->rx_err);
32152 }
32153 }
32154
32155@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
32156 goto retry_here;
32157 }
32158
32159- atomic_inc(&vcc->stats->tx_err);
32160+ atomic_inc_unchecked(&vcc->stats->tx_err);
32161
32162 fore200e->tx_sat++;
32163 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
32164diff --git a/drivers/atm/he.c b/drivers/atm/he.c
32165index 72b6960..cf9167a 100644
32166--- a/drivers/atm/he.c
32167+++ b/drivers/atm/he.c
32168@@ -1699,7 +1699,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32169
32170 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
32171 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
32172- atomic_inc(&vcc->stats->rx_drop);
32173+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32174 goto return_host_buffers;
32175 }
32176
32177@@ -1726,7 +1726,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32178 RBRQ_LEN_ERR(he_dev->rbrq_head)
32179 ? "LEN_ERR" : "",
32180 vcc->vpi, vcc->vci);
32181- atomic_inc(&vcc->stats->rx_err);
32182+ atomic_inc_unchecked(&vcc->stats->rx_err);
32183 goto return_host_buffers;
32184 }
32185
32186@@ -1778,7 +1778,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32187 vcc->push(vcc, skb);
32188 spin_lock(&he_dev->global_lock);
32189
32190- atomic_inc(&vcc->stats->rx);
32191+ atomic_inc_unchecked(&vcc->stats->rx);
32192
32193 return_host_buffers:
32194 ++pdus_assembled;
32195@@ -2104,7 +2104,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
32196 tpd->vcc->pop(tpd->vcc, tpd->skb);
32197 else
32198 dev_kfree_skb_any(tpd->skb);
32199- atomic_inc(&tpd->vcc->stats->tx_err);
32200+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
32201 }
32202 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
32203 return;
32204@@ -2516,7 +2516,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32205 vcc->pop(vcc, skb);
32206 else
32207 dev_kfree_skb_any(skb);
32208- atomic_inc(&vcc->stats->tx_err);
32209+ atomic_inc_unchecked(&vcc->stats->tx_err);
32210 return -EINVAL;
32211 }
32212
32213@@ -2527,7 +2527,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32214 vcc->pop(vcc, skb);
32215 else
32216 dev_kfree_skb_any(skb);
32217- atomic_inc(&vcc->stats->tx_err);
32218+ atomic_inc_unchecked(&vcc->stats->tx_err);
32219 return -EINVAL;
32220 }
32221 #endif
32222@@ -2539,7 +2539,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32223 vcc->pop(vcc, skb);
32224 else
32225 dev_kfree_skb_any(skb);
32226- atomic_inc(&vcc->stats->tx_err);
32227+ atomic_inc_unchecked(&vcc->stats->tx_err);
32228 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32229 return -ENOMEM;
32230 }
32231@@ -2581,7 +2581,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32232 vcc->pop(vcc, skb);
32233 else
32234 dev_kfree_skb_any(skb);
32235- atomic_inc(&vcc->stats->tx_err);
32236+ atomic_inc_unchecked(&vcc->stats->tx_err);
32237 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32238 return -ENOMEM;
32239 }
32240@@ -2612,7 +2612,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32241 __enqueue_tpd(he_dev, tpd, cid);
32242 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32243
32244- atomic_inc(&vcc->stats->tx);
32245+ atomic_inc_unchecked(&vcc->stats->tx);
32246
32247 return 0;
32248 }
32249diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
32250index 1dc0519..1aadaf7 100644
32251--- a/drivers/atm/horizon.c
32252+++ b/drivers/atm/horizon.c
32253@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
32254 {
32255 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
32256 // VC layer stats
32257- atomic_inc(&vcc->stats->rx);
32258+ atomic_inc_unchecked(&vcc->stats->rx);
32259 __net_timestamp(skb);
32260 // end of our responsibility
32261 vcc->push (vcc, skb);
32262@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
32263 dev->tx_iovec = NULL;
32264
32265 // VC layer stats
32266- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32267+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32268
32269 // free the skb
32270 hrz_kfree_skb (skb);
32271diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
32272index 272f009..a18ba55 100644
32273--- a/drivers/atm/idt77252.c
32274+++ b/drivers/atm/idt77252.c
32275@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
32276 else
32277 dev_kfree_skb(skb);
32278
32279- atomic_inc(&vcc->stats->tx);
32280+ atomic_inc_unchecked(&vcc->stats->tx);
32281 }
32282
32283 atomic_dec(&scq->used);
32284@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32285 if ((sb = dev_alloc_skb(64)) == NULL) {
32286 printk("%s: Can't allocate buffers for aal0.\n",
32287 card->name);
32288- atomic_add(i, &vcc->stats->rx_drop);
32289+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32290 break;
32291 }
32292 if (!atm_charge(vcc, sb->truesize)) {
32293 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
32294 card->name);
32295- atomic_add(i - 1, &vcc->stats->rx_drop);
32296+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
32297 dev_kfree_skb(sb);
32298 break;
32299 }
32300@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32301 ATM_SKB(sb)->vcc = vcc;
32302 __net_timestamp(sb);
32303 vcc->push(vcc, sb);
32304- atomic_inc(&vcc->stats->rx);
32305+ atomic_inc_unchecked(&vcc->stats->rx);
32306
32307 cell += ATM_CELL_PAYLOAD;
32308 }
32309@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32310 "(CDC: %08x)\n",
32311 card->name, len, rpp->len, readl(SAR_REG_CDC));
32312 recycle_rx_pool_skb(card, rpp);
32313- atomic_inc(&vcc->stats->rx_err);
32314+ atomic_inc_unchecked(&vcc->stats->rx_err);
32315 return;
32316 }
32317 if (stat & SAR_RSQE_CRC) {
32318 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
32319 recycle_rx_pool_skb(card, rpp);
32320- atomic_inc(&vcc->stats->rx_err);
32321+ atomic_inc_unchecked(&vcc->stats->rx_err);
32322 return;
32323 }
32324 if (skb_queue_len(&rpp->queue) > 1) {
32325@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32326 RXPRINTK("%s: Can't alloc RX skb.\n",
32327 card->name);
32328 recycle_rx_pool_skb(card, rpp);
32329- atomic_inc(&vcc->stats->rx_err);
32330+ atomic_inc_unchecked(&vcc->stats->rx_err);
32331 return;
32332 }
32333 if (!atm_charge(vcc, skb->truesize)) {
32334@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32335 __net_timestamp(skb);
32336
32337 vcc->push(vcc, skb);
32338- atomic_inc(&vcc->stats->rx);
32339+ atomic_inc_unchecked(&vcc->stats->rx);
32340
32341 return;
32342 }
32343@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32344 __net_timestamp(skb);
32345
32346 vcc->push(vcc, skb);
32347- atomic_inc(&vcc->stats->rx);
32348+ atomic_inc_unchecked(&vcc->stats->rx);
32349
32350 if (skb->truesize > SAR_FB_SIZE_3)
32351 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
32352@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
32353 if (vcc->qos.aal != ATM_AAL0) {
32354 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
32355 card->name, vpi, vci);
32356- atomic_inc(&vcc->stats->rx_drop);
32357+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32358 goto drop;
32359 }
32360
32361 if ((sb = dev_alloc_skb(64)) == NULL) {
32362 printk("%s: Can't allocate buffers for AAL0.\n",
32363 card->name);
32364- atomic_inc(&vcc->stats->rx_err);
32365+ atomic_inc_unchecked(&vcc->stats->rx_err);
32366 goto drop;
32367 }
32368
32369@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
32370 ATM_SKB(sb)->vcc = vcc;
32371 __net_timestamp(sb);
32372 vcc->push(vcc, sb);
32373- atomic_inc(&vcc->stats->rx);
32374+ atomic_inc_unchecked(&vcc->stats->rx);
32375
32376 drop:
32377 skb_pull(queue, 64);
32378@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32379
32380 if (vc == NULL) {
32381 printk("%s: NULL connection in send().\n", card->name);
32382- atomic_inc(&vcc->stats->tx_err);
32383+ atomic_inc_unchecked(&vcc->stats->tx_err);
32384 dev_kfree_skb(skb);
32385 return -EINVAL;
32386 }
32387 if (!test_bit(VCF_TX, &vc->flags)) {
32388 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
32389- atomic_inc(&vcc->stats->tx_err);
32390+ atomic_inc_unchecked(&vcc->stats->tx_err);
32391 dev_kfree_skb(skb);
32392 return -EINVAL;
32393 }
32394@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32395 break;
32396 default:
32397 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
32398- atomic_inc(&vcc->stats->tx_err);
32399+ atomic_inc_unchecked(&vcc->stats->tx_err);
32400 dev_kfree_skb(skb);
32401 return -EINVAL;
32402 }
32403
32404 if (skb_shinfo(skb)->nr_frags != 0) {
32405 printk("%s: No scatter-gather yet.\n", card->name);
32406- atomic_inc(&vcc->stats->tx_err);
32407+ atomic_inc_unchecked(&vcc->stats->tx_err);
32408 dev_kfree_skb(skb);
32409 return -EINVAL;
32410 }
32411@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32412
32413 err = queue_skb(card, vc, skb, oam);
32414 if (err) {
32415- atomic_inc(&vcc->stats->tx_err);
32416+ atomic_inc_unchecked(&vcc->stats->tx_err);
32417 dev_kfree_skb(skb);
32418 return err;
32419 }
32420@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
32421 skb = dev_alloc_skb(64);
32422 if (!skb) {
32423 printk("%s: Out of memory in send_oam().\n", card->name);
32424- atomic_inc(&vcc->stats->tx_err);
32425+ atomic_inc_unchecked(&vcc->stats->tx_err);
32426 return -ENOMEM;
32427 }
32428 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
32429diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
32430index 4217f29..88f547a 100644
32431--- a/drivers/atm/iphase.c
32432+++ b/drivers/atm/iphase.c
32433@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
32434 status = (u_short) (buf_desc_ptr->desc_mode);
32435 if (status & (RX_CER | RX_PTE | RX_OFL))
32436 {
32437- atomic_inc(&vcc->stats->rx_err);
32438+ atomic_inc_unchecked(&vcc->stats->rx_err);
32439 IF_ERR(printk("IA: bad packet, dropping it");)
32440 if (status & RX_CER) {
32441 IF_ERR(printk(" cause: packet CRC error\n");)
32442@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
32443 len = dma_addr - buf_addr;
32444 if (len > iadev->rx_buf_sz) {
32445 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
32446- atomic_inc(&vcc->stats->rx_err);
32447+ atomic_inc_unchecked(&vcc->stats->rx_err);
32448 goto out_free_desc;
32449 }
32450
32451@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32452 ia_vcc = INPH_IA_VCC(vcc);
32453 if (ia_vcc == NULL)
32454 {
32455- atomic_inc(&vcc->stats->rx_err);
32456+ atomic_inc_unchecked(&vcc->stats->rx_err);
32457 atm_return(vcc, skb->truesize);
32458 dev_kfree_skb_any(skb);
32459 goto INCR_DLE;
32460@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32461 if ((length > iadev->rx_buf_sz) || (length >
32462 (skb->len - sizeof(struct cpcs_trailer))))
32463 {
32464- atomic_inc(&vcc->stats->rx_err);
32465+ atomic_inc_unchecked(&vcc->stats->rx_err);
32466 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
32467 length, skb->len);)
32468 atm_return(vcc, skb->truesize);
32469@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32470
32471 IF_RX(printk("rx_dle_intr: skb push");)
32472 vcc->push(vcc,skb);
32473- atomic_inc(&vcc->stats->rx);
32474+ atomic_inc_unchecked(&vcc->stats->rx);
32475 iadev->rx_pkt_cnt++;
32476 }
32477 INCR_DLE:
32478@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
32479 {
32480 struct k_sonet_stats *stats;
32481 stats = &PRIV(_ia_dev[board])->sonet_stats;
32482- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
32483- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
32484- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
32485- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
32486- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
32487- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
32488- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
32489- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
32490- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
32491+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
32492+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
32493+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
32494+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
32495+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
32496+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
32497+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
32498+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
32499+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
32500 }
32501 ia_cmds.status = 0;
32502 break;
32503@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32504 if ((desc == 0) || (desc > iadev->num_tx_desc))
32505 {
32506 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
32507- atomic_inc(&vcc->stats->tx);
32508+ atomic_inc_unchecked(&vcc->stats->tx);
32509 if (vcc->pop)
32510 vcc->pop(vcc, skb);
32511 else
32512@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32513 ATM_DESC(skb) = vcc->vci;
32514 skb_queue_tail(&iadev->tx_dma_q, skb);
32515
32516- atomic_inc(&vcc->stats->tx);
32517+ atomic_inc_unchecked(&vcc->stats->tx);
32518 iadev->tx_pkt_cnt++;
32519 /* Increment transaction counter */
32520 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
32521
32522 #if 0
32523 /* add flow control logic */
32524- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
32525+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
32526 if (iavcc->vc_desc_cnt > 10) {
32527 vcc->tx_quota = vcc->tx_quota * 3 / 4;
32528 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
32529diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
32530index fa7d701..1e404c7 100644
32531--- a/drivers/atm/lanai.c
32532+++ b/drivers/atm/lanai.c
32533@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
32534 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
32535 lanai_endtx(lanai, lvcc);
32536 lanai_free_skb(lvcc->tx.atmvcc, skb);
32537- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
32538+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
32539 }
32540
32541 /* Try to fill the buffer - don't call unless there is backlog */
32542@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
32543 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
32544 __net_timestamp(skb);
32545 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
32546- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
32547+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
32548 out:
32549 lvcc->rx.buf.ptr = end;
32550 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
32551@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32552 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
32553 "vcc %d\n", lanai->number, (unsigned int) s, vci);
32554 lanai->stats.service_rxnotaal5++;
32555- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32556+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32557 return 0;
32558 }
32559 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
32560@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32561 int bytes;
32562 read_unlock(&vcc_sklist_lock);
32563 DPRINTK("got trashed rx pdu on vci %d\n", vci);
32564- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32565+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32566 lvcc->stats.x.aal5.service_trash++;
32567 bytes = (SERVICE_GET_END(s) * 16) -
32568 (((unsigned long) lvcc->rx.buf.ptr) -
32569@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32570 }
32571 if (s & SERVICE_STREAM) {
32572 read_unlock(&vcc_sklist_lock);
32573- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32574+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32575 lvcc->stats.x.aal5.service_stream++;
32576 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
32577 "PDU on VCI %d!\n", lanai->number, vci);
32578@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32579 return 0;
32580 }
32581 DPRINTK("got rx crc error on vci %d\n", vci);
32582- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32583+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32584 lvcc->stats.x.aal5.service_rxcrc++;
32585 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
32586 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
32587diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
32588index ed1d2b7..8cffc1f 100644
32589--- a/drivers/atm/nicstar.c
32590+++ b/drivers/atm/nicstar.c
32591@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32592 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
32593 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
32594 card->index);
32595- atomic_inc(&vcc->stats->tx_err);
32596+ atomic_inc_unchecked(&vcc->stats->tx_err);
32597 dev_kfree_skb_any(skb);
32598 return -EINVAL;
32599 }
32600@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32601 if (!vc->tx) {
32602 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
32603 card->index);
32604- atomic_inc(&vcc->stats->tx_err);
32605+ atomic_inc_unchecked(&vcc->stats->tx_err);
32606 dev_kfree_skb_any(skb);
32607 return -EINVAL;
32608 }
32609@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32610 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
32611 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
32612 card->index);
32613- atomic_inc(&vcc->stats->tx_err);
32614+ atomic_inc_unchecked(&vcc->stats->tx_err);
32615 dev_kfree_skb_any(skb);
32616 return -EINVAL;
32617 }
32618
32619 if (skb_shinfo(skb)->nr_frags != 0) {
32620 printk("nicstar%d: No scatter-gather yet.\n", card->index);
32621- atomic_inc(&vcc->stats->tx_err);
32622+ atomic_inc_unchecked(&vcc->stats->tx_err);
32623 dev_kfree_skb_any(skb);
32624 return -EINVAL;
32625 }
32626@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32627 }
32628
32629 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
32630- atomic_inc(&vcc->stats->tx_err);
32631+ atomic_inc_unchecked(&vcc->stats->tx_err);
32632 dev_kfree_skb_any(skb);
32633 return -EIO;
32634 }
32635- atomic_inc(&vcc->stats->tx);
32636+ atomic_inc_unchecked(&vcc->stats->tx);
32637
32638 return 0;
32639 }
32640@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32641 printk
32642 ("nicstar%d: Can't allocate buffers for aal0.\n",
32643 card->index);
32644- atomic_add(i, &vcc->stats->rx_drop);
32645+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32646 break;
32647 }
32648 if (!atm_charge(vcc, sb->truesize)) {
32649 RXPRINTK
32650 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
32651 card->index);
32652- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32653+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32654 dev_kfree_skb_any(sb);
32655 break;
32656 }
32657@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32658 ATM_SKB(sb)->vcc = vcc;
32659 __net_timestamp(sb);
32660 vcc->push(vcc, sb);
32661- atomic_inc(&vcc->stats->rx);
32662+ atomic_inc_unchecked(&vcc->stats->rx);
32663 cell += ATM_CELL_PAYLOAD;
32664 }
32665
32666@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32667 if (iovb == NULL) {
32668 printk("nicstar%d: Out of iovec buffers.\n",
32669 card->index);
32670- atomic_inc(&vcc->stats->rx_drop);
32671+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32672 recycle_rx_buf(card, skb);
32673 return;
32674 }
32675@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32676 small or large buffer itself. */
32677 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
32678 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
32679- atomic_inc(&vcc->stats->rx_err);
32680+ atomic_inc_unchecked(&vcc->stats->rx_err);
32681 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32682 NS_MAX_IOVECS);
32683 NS_PRV_IOVCNT(iovb) = 0;
32684@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32685 ("nicstar%d: Expected a small buffer, and this is not one.\n",
32686 card->index);
32687 which_list(card, skb);
32688- atomic_inc(&vcc->stats->rx_err);
32689+ atomic_inc_unchecked(&vcc->stats->rx_err);
32690 recycle_rx_buf(card, skb);
32691 vc->rx_iov = NULL;
32692 recycle_iov_buf(card, iovb);
32693@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32694 ("nicstar%d: Expected a large buffer, and this is not one.\n",
32695 card->index);
32696 which_list(card, skb);
32697- atomic_inc(&vcc->stats->rx_err);
32698+ atomic_inc_unchecked(&vcc->stats->rx_err);
32699 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32700 NS_PRV_IOVCNT(iovb));
32701 vc->rx_iov = NULL;
32702@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32703 printk(" - PDU size mismatch.\n");
32704 else
32705 printk(".\n");
32706- atomic_inc(&vcc->stats->rx_err);
32707+ atomic_inc_unchecked(&vcc->stats->rx_err);
32708 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32709 NS_PRV_IOVCNT(iovb));
32710 vc->rx_iov = NULL;
32711@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32712 /* skb points to a small buffer */
32713 if (!atm_charge(vcc, skb->truesize)) {
32714 push_rxbufs(card, skb);
32715- atomic_inc(&vcc->stats->rx_drop);
32716+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32717 } else {
32718 skb_put(skb, len);
32719 dequeue_sm_buf(card, skb);
32720@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32721 ATM_SKB(skb)->vcc = vcc;
32722 __net_timestamp(skb);
32723 vcc->push(vcc, skb);
32724- atomic_inc(&vcc->stats->rx);
32725+ atomic_inc_unchecked(&vcc->stats->rx);
32726 }
32727 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
32728 struct sk_buff *sb;
32729@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32730 if (len <= NS_SMBUFSIZE) {
32731 if (!atm_charge(vcc, sb->truesize)) {
32732 push_rxbufs(card, sb);
32733- atomic_inc(&vcc->stats->rx_drop);
32734+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32735 } else {
32736 skb_put(sb, len);
32737 dequeue_sm_buf(card, sb);
32738@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32739 ATM_SKB(sb)->vcc = vcc;
32740 __net_timestamp(sb);
32741 vcc->push(vcc, sb);
32742- atomic_inc(&vcc->stats->rx);
32743+ atomic_inc_unchecked(&vcc->stats->rx);
32744 }
32745
32746 push_rxbufs(card, skb);
32747@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32748
32749 if (!atm_charge(vcc, skb->truesize)) {
32750 push_rxbufs(card, skb);
32751- atomic_inc(&vcc->stats->rx_drop);
32752+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32753 } else {
32754 dequeue_lg_buf(card, skb);
32755 #ifdef NS_USE_DESTRUCTORS
32756@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32757 ATM_SKB(skb)->vcc = vcc;
32758 __net_timestamp(skb);
32759 vcc->push(vcc, skb);
32760- atomic_inc(&vcc->stats->rx);
32761+ atomic_inc_unchecked(&vcc->stats->rx);
32762 }
32763
32764 push_rxbufs(card, sb);
32765@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32766 printk
32767 ("nicstar%d: Out of huge buffers.\n",
32768 card->index);
32769- atomic_inc(&vcc->stats->rx_drop);
32770+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32771 recycle_iovec_rx_bufs(card,
32772 (struct iovec *)
32773 iovb->data,
32774@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32775 card->hbpool.count++;
32776 } else
32777 dev_kfree_skb_any(hb);
32778- atomic_inc(&vcc->stats->rx_drop);
32779+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32780 } else {
32781 /* Copy the small buffer to the huge buffer */
32782 sb = (struct sk_buff *)iov->iov_base;
32783@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32784 #endif /* NS_USE_DESTRUCTORS */
32785 __net_timestamp(hb);
32786 vcc->push(vcc, hb);
32787- atomic_inc(&vcc->stats->rx);
32788+ atomic_inc_unchecked(&vcc->stats->rx);
32789 }
32790 }
32791
32792diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
32793index 0474a89..06ea4a1 100644
32794--- a/drivers/atm/solos-pci.c
32795+++ b/drivers/atm/solos-pci.c
32796@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
32797 }
32798 atm_charge(vcc, skb->truesize);
32799 vcc->push(vcc, skb);
32800- atomic_inc(&vcc->stats->rx);
32801+ atomic_inc_unchecked(&vcc->stats->rx);
32802 break;
32803
32804 case PKT_STATUS:
32805@@ -1117,7 +1117,7 @@ static uint32_t fpga_tx(struct solos_card *card)
32806 vcc = SKB_CB(oldskb)->vcc;
32807
32808 if (vcc) {
32809- atomic_inc(&vcc->stats->tx);
32810+ atomic_inc_unchecked(&vcc->stats->tx);
32811 solos_pop(vcc, oldskb);
32812 } else {
32813 dev_kfree_skb_irq(oldskb);
32814diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
32815index 0215934..ce9f5b1 100644
32816--- a/drivers/atm/suni.c
32817+++ b/drivers/atm/suni.c
32818@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
32819
32820
32821 #define ADD_LIMITED(s,v) \
32822- atomic_add((v),&stats->s); \
32823- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
32824+ atomic_add_unchecked((v),&stats->s); \
32825+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
32826
32827
32828 static void suni_hz(unsigned long from_timer)
32829diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
32830index 5120a96..e2572bd 100644
32831--- a/drivers/atm/uPD98402.c
32832+++ b/drivers/atm/uPD98402.c
32833@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
32834 struct sonet_stats tmp;
32835 int error = 0;
32836
32837- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32838+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32839 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
32840 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
32841 if (zero && !error) {
32842@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
32843
32844
32845 #define ADD_LIMITED(s,v) \
32846- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
32847- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
32848- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32849+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
32850+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
32851+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32852
32853
32854 static void stat_event(struct atm_dev *dev)
32855@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
32856 if (reason & uPD98402_INT_PFM) stat_event(dev);
32857 if (reason & uPD98402_INT_PCO) {
32858 (void) GET(PCOCR); /* clear interrupt cause */
32859- atomic_add(GET(HECCT),
32860+ atomic_add_unchecked(GET(HECCT),
32861 &PRIV(dev)->sonet_stats.uncorr_hcs);
32862 }
32863 if ((reason & uPD98402_INT_RFO) &&
32864@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
32865 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
32866 uPD98402_INT_LOS),PIMR); /* enable them */
32867 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
32868- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32869- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
32870- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
32871+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32872+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
32873+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
32874 return 0;
32875 }
32876
32877diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
32878index 969c3c2..9b72956 100644
32879--- a/drivers/atm/zatm.c
32880+++ b/drivers/atm/zatm.c
32881@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32882 }
32883 if (!size) {
32884 dev_kfree_skb_irq(skb);
32885- if (vcc) atomic_inc(&vcc->stats->rx_err);
32886+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
32887 continue;
32888 }
32889 if (!atm_charge(vcc,skb->truesize)) {
32890@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32891 skb->len = size;
32892 ATM_SKB(skb)->vcc = vcc;
32893 vcc->push(vcc,skb);
32894- atomic_inc(&vcc->stats->rx);
32895+ atomic_inc_unchecked(&vcc->stats->rx);
32896 }
32897 zout(pos & 0xffff,MTA(mbx));
32898 #if 0 /* probably a stupid idea */
32899@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
32900 skb_queue_head(&zatm_vcc->backlog,skb);
32901 break;
32902 }
32903- atomic_inc(&vcc->stats->tx);
32904+ atomic_inc_unchecked(&vcc->stats->tx);
32905 wake_up(&zatm_vcc->tx_wait);
32906 }
32907
32908diff --git a/drivers/base/bus.c b/drivers/base/bus.c
32909index 6856303..0602d70 100644
32910--- a/drivers/base/bus.c
32911+++ b/drivers/base/bus.c
32912@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
32913 return -EINVAL;
32914
32915 mutex_lock(&subsys->p->mutex);
32916- list_add_tail(&sif->node, &subsys->p->interfaces);
32917+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
32918 if (sif->add_dev) {
32919 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
32920 while ((dev = subsys_dev_iter_next(&iter)))
32921@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
32922 subsys = sif->subsys;
32923
32924 mutex_lock(&subsys->p->mutex);
32925- list_del_init(&sif->node);
32926+ pax_list_del_init((struct list_head *)&sif->node);
32927 if (sif->remove_dev) {
32928 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
32929 while ((dev = subsys_dev_iter_next(&iter)))
32930diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
32931index 17cf7ca..7e553e1 100644
32932--- a/drivers/base/devtmpfs.c
32933+++ b/drivers/base/devtmpfs.c
32934@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
32935 if (!thread)
32936 return 0;
32937
32938- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
32939+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
32940 if (err)
32941 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
32942 else
32943diff --git a/drivers/base/node.c b/drivers/base/node.c
32944index fac124a..66bd4ab 100644
32945--- a/drivers/base/node.c
32946+++ b/drivers/base/node.c
32947@@ -625,7 +625,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
32948 struct node_attr {
32949 struct device_attribute attr;
32950 enum node_states state;
32951-};
32952+} __do_const;
32953
32954 static ssize_t show_node_state(struct device *dev,
32955 struct device_attribute *attr, char *buf)
32956diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
32957index acc3a8d..981c236 100644
32958--- a/drivers/base/power/domain.c
32959+++ b/drivers/base/power/domain.c
32960@@ -1851,7 +1851,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
32961 {
32962 struct cpuidle_driver *cpuidle_drv;
32963 struct gpd_cpu_data *cpu_data;
32964- struct cpuidle_state *idle_state;
32965+ cpuidle_state_no_const *idle_state;
32966 int ret = 0;
32967
32968 if (IS_ERR_OR_NULL(genpd) || state < 0)
32969@@ -1919,7 +1919,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
32970 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
32971 {
32972 struct gpd_cpu_data *cpu_data;
32973- struct cpuidle_state *idle_state;
32974+ cpuidle_state_no_const *idle_state;
32975 int ret = 0;
32976
32977 if (IS_ERR_OR_NULL(genpd))
32978diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
32979index e6ee5e8..98ad7fc 100644
32980--- a/drivers/base/power/wakeup.c
32981+++ b/drivers/base/power/wakeup.c
32982@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
32983 * They need to be modified together atomically, so it's better to use one
32984 * atomic variable to hold them both.
32985 */
32986-static atomic_t combined_event_count = ATOMIC_INIT(0);
32987+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
32988
32989 #define IN_PROGRESS_BITS (sizeof(int) * 4)
32990 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
32991
32992 static void split_counters(unsigned int *cnt, unsigned int *inpr)
32993 {
32994- unsigned int comb = atomic_read(&combined_event_count);
32995+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
32996
32997 *cnt = (comb >> IN_PROGRESS_BITS);
32998 *inpr = comb & MAX_IN_PROGRESS;
32999@@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
33000 ws->start_prevent_time = ws->last_time;
33001
33002 /* Increment the counter of events in progress. */
33003- cec = atomic_inc_return(&combined_event_count);
33004+ cec = atomic_inc_return_unchecked(&combined_event_count);
33005
33006 trace_wakeup_source_activate(ws->name, cec);
33007 }
33008@@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
33009 * Increment the counter of registered wakeup events and decrement the
33010 * couter of wakeup events in progress simultaneously.
33011 */
33012- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
33013+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
33014 trace_wakeup_source_deactivate(ws->name, cec);
33015
33016 split_counters(&cnt, &inpr);
33017diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
33018index e8d11b6..7b1b36f 100644
33019--- a/drivers/base/syscore.c
33020+++ b/drivers/base/syscore.c
33021@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
33022 void register_syscore_ops(struct syscore_ops *ops)
33023 {
33024 mutex_lock(&syscore_ops_lock);
33025- list_add_tail(&ops->node, &syscore_ops_list);
33026+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
33027 mutex_unlock(&syscore_ops_lock);
33028 }
33029 EXPORT_SYMBOL_GPL(register_syscore_ops);
33030@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
33031 void unregister_syscore_ops(struct syscore_ops *ops)
33032 {
33033 mutex_lock(&syscore_ops_lock);
33034- list_del(&ops->node);
33035+ pax_list_del((struct list_head *)&ops->node);
33036 mutex_unlock(&syscore_ops_lock);
33037 }
33038 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
33039diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
33040index ade58bc..867143d 100644
33041--- a/drivers/block/cciss.c
33042+++ b/drivers/block/cciss.c
33043@@ -1196,6 +1196,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
33044 int err;
33045 u32 cp;
33046
33047+ memset(&arg64, 0, sizeof(arg64));
33048+
33049 err = 0;
33050 err |=
33051 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
33052@@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
33053 while (!list_empty(&h->reqQ)) {
33054 c = list_entry(h->reqQ.next, CommandList_struct, list);
33055 /* can't do anything if fifo is full */
33056- if ((h->access.fifo_full(h))) {
33057+ if ((h->access->fifo_full(h))) {
33058 dev_warn(&h->pdev->dev, "fifo full\n");
33059 break;
33060 }
33061@@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
33062 h->Qdepth--;
33063
33064 /* Tell the controller execute command */
33065- h->access.submit_command(h, c);
33066+ h->access->submit_command(h, c);
33067
33068 /* Put job onto the completed Q */
33069 addQ(&h->cmpQ, c);
33070@@ -3441,17 +3443,17 @@ startio:
33071
33072 static inline unsigned long get_next_completion(ctlr_info_t *h)
33073 {
33074- return h->access.command_completed(h);
33075+ return h->access->command_completed(h);
33076 }
33077
33078 static inline int interrupt_pending(ctlr_info_t *h)
33079 {
33080- return h->access.intr_pending(h);
33081+ return h->access->intr_pending(h);
33082 }
33083
33084 static inline long interrupt_not_for_us(ctlr_info_t *h)
33085 {
33086- return ((h->access.intr_pending(h) == 0) ||
33087+ return ((h->access->intr_pending(h) == 0) ||
33088 (h->interrupts_enabled == 0));
33089 }
33090
33091@@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
33092 u32 a;
33093
33094 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
33095- return h->access.command_completed(h);
33096+ return h->access->command_completed(h);
33097
33098 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
33099 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
33100@@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
33101 trans_support & CFGTBL_Trans_use_short_tags);
33102
33103 /* Change the access methods to the performant access methods */
33104- h->access = SA5_performant_access;
33105+ h->access = &SA5_performant_access;
33106 h->transMethod = CFGTBL_Trans_Performant;
33107
33108 return;
33109@@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
33110 if (prod_index < 0)
33111 return -ENODEV;
33112 h->product_name = products[prod_index].product_name;
33113- h->access = *(products[prod_index].access);
33114+ h->access = products[prod_index].access;
33115
33116 if (cciss_board_disabled(h)) {
33117 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
33118@@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
33119 }
33120
33121 /* make sure the board interrupts are off */
33122- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33123+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33124 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
33125 if (rc)
33126 goto clean2;
33127@@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
33128 * fake ones to scoop up any residual completions.
33129 */
33130 spin_lock_irqsave(&h->lock, flags);
33131- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33132+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33133 spin_unlock_irqrestore(&h->lock, flags);
33134 free_irq(h->intr[h->intr_mode], h);
33135 rc = cciss_request_irq(h, cciss_msix_discard_completions,
33136@@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
33137 dev_info(&h->pdev->dev, "Board READY.\n");
33138 dev_info(&h->pdev->dev,
33139 "Waiting for stale completions to drain.\n");
33140- h->access.set_intr_mask(h, CCISS_INTR_ON);
33141+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33142 msleep(10000);
33143- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33144+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33145
33146 rc = controller_reset_failed(h->cfgtable);
33147 if (rc)
33148@@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
33149 cciss_scsi_setup(h);
33150
33151 /* Turn the interrupts on so we can service requests */
33152- h->access.set_intr_mask(h, CCISS_INTR_ON);
33153+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33154
33155 /* Get the firmware version */
33156 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
33157@@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
33158 kfree(flush_buf);
33159 if (return_code != IO_OK)
33160 dev_warn(&h->pdev->dev, "Error flushing cache\n");
33161- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33162+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33163 free_irq(h->intr[h->intr_mode], h);
33164 }
33165
33166diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
33167index 7fda30e..eb5dfe0 100644
33168--- a/drivers/block/cciss.h
33169+++ b/drivers/block/cciss.h
33170@@ -101,7 +101,7 @@ struct ctlr_info
33171 /* information about each logical volume */
33172 drive_info_struct *drv[CISS_MAX_LUN];
33173
33174- struct access_method access;
33175+ struct access_method *access;
33176
33177 /* queue and queue Info */
33178 struct list_head reqQ;
33179diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
33180index 3f08713..56a586a 100644
33181--- a/drivers/block/cpqarray.c
33182+++ b/drivers/block/cpqarray.c
33183@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33184 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
33185 goto Enomem4;
33186 }
33187- hba[i]->access.set_intr_mask(hba[i], 0);
33188+ hba[i]->access->set_intr_mask(hba[i], 0);
33189 if (request_irq(hba[i]->intr, do_ida_intr,
33190 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
33191 {
33192@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33193 add_timer(&hba[i]->timer);
33194
33195 /* Enable IRQ now that spinlock and rate limit timer are set up */
33196- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33197+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33198
33199 for(j=0; j<NWD; j++) {
33200 struct gendisk *disk = ida_gendisk[i][j];
33201@@ -694,7 +694,7 @@ DBGINFO(
33202 for(i=0; i<NR_PRODUCTS; i++) {
33203 if (board_id == products[i].board_id) {
33204 c->product_name = products[i].product_name;
33205- c->access = *(products[i].access);
33206+ c->access = products[i].access;
33207 break;
33208 }
33209 }
33210@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
33211 hba[ctlr]->intr = intr;
33212 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
33213 hba[ctlr]->product_name = products[j].product_name;
33214- hba[ctlr]->access = *(products[j].access);
33215+ hba[ctlr]->access = products[j].access;
33216 hba[ctlr]->ctlr = ctlr;
33217 hba[ctlr]->board_id = board_id;
33218 hba[ctlr]->pci_dev = NULL; /* not PCI */
33219@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
33220
33221 while((c = h->reqQ) != NULL) {
33222 /* Can't do anything if we're busy */
33223- if (h->access.fifo_full(h) == 0)
33224+ if (h->access->fifo_full(h) == 0)
33225 return;
33226
33227 /* Get the first entry from the request Q */
33228@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
33229 h->Qdepth--;
33230
33231 /* Tell the controller to do our bidding */
33232- h->access.submit_command(h, c);
33233+ h->access->submit_command(h, c);
33234
33235 /* Get onto the completion Q */
33236 addQ(&h->cmpQ, c);
33237@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33238 unsigned long flags;
33239 __u32 a,a1;
33240
33241- istat = h->access.intr_pending(h);
33242+ istat = h->access->intr_pending(h);
33243 /* Is this interrupt for us? */
33244 if (istat == 0)
33245 return IRQ_NONE;
33246@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33247 */
33248 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
33249 if (istat & FIFO_NOT_EMPTY) {
33250- while((a = h->access.command_completed(h))) {
33251+ while((a = h->access->command_completed(h))) {
33252 a1 = a; a &= ~3;
33253 if ((c = h->cmpQ) == NULL)
33254 {
33255@@ -1449,11 +1449,11 @@ static int sendcmd(
33256 /*
33257 * Disable interrupt
33258 */
33259- info_p->access.set_intr_mask(info_p, 0);
33260+ info_p->access->set_intr_mask(info_p, 0);
33261 /* Make sure there is room in the command FIFO */
33262 /* Actually it should be completely empty at this time. */
33263 for (i = 200000; i > 0; i--) {
33264- temp = info_p->access.fifo_full(info_p);
33265+ temp = info_p->access->fifo_full(info_p);
33266 if (temp != 0) {
33267 break;
33268 }
33269@@ -1466,7 +1466,7 @@ DBG(
33270 /*
33271 * Send the cmd
33272 */
33273- info_p->access.submit_command(info_p, c);
33274+ info_p->access->submit_command(info_p, c);
33275 complete = pollcomplete(ctlr);
33276
33277 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
33278@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
33279 * we check the new geometry. Then turn interrupts back on when
33280 * we're done.
33281 */
33282- host->access.set_intr_mask(host, 0);
33283+ host->access->set_intr_mask(host, 0);
33284 getgeometry(ctlr);
33285- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
33286+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
33287
33288 for(i=0; i<NWD; i++) {
33289 struct gendisk *disk = ida_gendisk[ctlr][i];
33290@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
33291 /* Wait (up to 2 seconds) for a command to complete */
33292
33293 for (i = 200000; i > 0; i--) {
33294- done = hba[ctlr]->access.command_completed(hba[ctlr]);
33295+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
33296 if (done == 0) {
33297 udelay(10); /* a short fixed delay */
33298 } else
33299diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
33300index be73e9d..7fbf140 100644
33301--- a/drivers/block/cpqarray.h
33302+++ b/drivers/block/cpqarray.h
33303@@ -99,7 +99,7 @@ struct ctlr_info {
33304 drv_info_t drv[NWD];
33305 struct proc_dir_entry *proc;
33306
33307- struct access_method access;
33308+ struct access_method *access;
33309
33310 cmdlist_t *reqQ;
33311 cmdlist_t *cmpQ;
33312diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
33313index 6b51afa..17e1191 100644
33314--- a/drivers/block/drbd/drbd_int.h
33315+++ b/drivers/block/drbd/drbd_int.h
33316@@ -582,7 +582,7 @@ struct drbd_epoch {
33317 struct drbd_tconn *tconn;
33318 struct list_head list;
33319 unsigned int barrier_nr;
33320- atomic_t epoch_size; /* increased on every request added. */
33321+ atomic_unchecked_t epoch_size; /* increased on every request added. */
33322 atomic_t active; /* increased on every req. added, and dec on every finished. */
33323 unsigned long flags;
33324 };
33325@@ -1011,7 +1011,7 @@ struct drbd_conf {
33326 int al_tr_cycle;
33327 int al_tr_pos; /* position of the next transaction in the journal */
33328 wait_queue_head_t seq_wait;
33329- atomic_t packet_seq;
33330+ atomic_unchecked_t packet_seq;
33331 unsigned int peer_seq;
33332 spinlock_t peer_seq_lock;
33333 unsigned int minor;
33334@@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
33335 char __user *uoptval;
33336 int err;
33337
33338- uoptval = (char __user __force *)optval;
33339+ uoptval = (char __force_user *)optval;
33340
33341 set_fs(KERNEL_DS);
33342 if (level == SOL_SOCKET)
33343diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
33344index 8c13eeb..217adee 100644
33345--- a/drivers/block/drbd/drbd_main.c
33346+++ b/drivers/block/drbd/drbd_main.c
33347@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
33348 p->sector = sector;
33349 p->block_id = block_id;
33350 p->blksize = blksize;
33351- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33352+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33353 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
33354 }
33355
33356@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
33357 return -EIO;
33358 p->sector = cpu_to_be64(req->i.sector);
33359 p->block_id = (unsigned long)req;
33360- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33361+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33362 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
33363 if (mdev->state.conn >= C_SYNC_SOURCE &&
33364 mdev->state.conn <= C_PAUSED_SYNC_T)
33365@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
33366 {
33367 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
33368
33369- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
33370- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
33371+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
33372+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
33373 kfree(tconn->current_epoch);
33374
33375 idr_destroy(&tconn->volumes);
33376diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
33377index a9eccfc..f5efe87 100644
33378--- a/drivers/block/drbd/drbd_receiver.c
33379+++ b/drivers/block/drbd/drbd_receiver.c
33380@@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
33381 {
33382 int err;
33383
33384- atomic_set(&mdev->packet_seq, 0);
33385+ atomic_set_unchecked(&mdev->packet_seq, 0);
33386 mdev->peer_seq = 0;
33387
33388 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
33389@@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33390 do {
33391 next_epoch = NULL;
33392
33393- epoch_size = atomic_read(&epoch->epoch_size);
33394+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
33395
33396 switch (ev & ~EV_CLEANUP) {
33397 case EV_PUT:
33398@@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33399 rv = FE_DESTROYED;
33400 } else {
33401 epoch->flags = 0;
33402- atomic_set(&epoch->epoch_size, 0);
33403+ atomic_set_unchecked(&epoch->epoch_size, 0);
33404 /* atomic_set(&epoch->active, 0); is already zero */
33405 if (rv == FE_STILL_LIVE)
33406 rv = FE_RECYCLED;
33407@@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33408 conn_wait_active_ee_empty(tconn);
33409 drbd_flush(tconn);
33410
33411- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33412+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33413 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
33414 if (epoch)
33415 break;
33416@@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33417 }
33418
33419 epoch->flags = 0;
33420- atomic_set(&epoch->epoch_size, 0);
33421+ atomic_set_unchecked(&epoch->epoch_size, 0);
33422 atomic_set(&epoch->active, 0);
33423
33424 spin_lock(&tconn->epoch_lock);
33425- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33426+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33427 list_add(&epoch->list, &tconn->current_epoch->list);
33428 tconn->current_epoch = epoch;
33429 tconn->epochs++;
33430@@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33431
33432 err = wait_for_and_update_peer_seq(mdev, peer_seq);
33433 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
33434- atomic_inc(&tconn->current_epoch->epoch_size);
33435+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
33436 err2 = drbd_drain_block(mdev, pi->size);
33437 if (!err)
33438 err = err2;
33439@@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33440
33441 spin_lock(&tconn->epoch_lock);
33442 peer_req->epoch = tconn->current_epoch;
33443- atomic_inc(&peer_req->epoch->epoch_size);
33444+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
33445 atomic_inc(&peer_req->epoch->active);
33446 spin_unlock(&tconn->epoch_lock);
33447
33448@@ -4346,7 +4346,7 @@ struct data_cmd {
33449 int expect_payload;
33450 size_t pkt_size;
33451 int (*fn)(struct drbd_tconn *, struct packet_info *);
33452-};
33453+} __do_const;
33454
33455 static struct data_cmd drbd_cmd_handler[] = {
33456 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
33457@@ -4466,7 +4466,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
33458 if (!list_empty(&tconn->current_epoch->list))
33459 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
33460 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
33461- atomic_set(&tconn->current_epoch->epoch_size, 0);
33462+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
33463 tconn->send.seen_any_write_yet = false;
33464
33465 conn_info(tconn, "Connection closed\n");
33466@@ -5222,7 +5222,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
33467 struct asender_cmd {
33468 size_t pkt_size;
33469 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
33470-};
33471+} __do_const;
33472
33473 static struct asender_cmd asender_tbl[] = {
33474 [P_PING] = { 0, got_Ping },
33475diff --git a/drivers/block/loop.c b/drivers/block/loop.c
33476index 8bc6d39..f492563 100644
33477--- a/drivers/block/loop.c
33478+++ b/drivers/block/loop.c
33479@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
33480 mm_segment_t old_fs = get_fs();
33481
33482 set_fs(get_ds());
33483- bw = file->f_op->write(file, buf, len, &pos);
33484+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
33485 set_fs(old_fs);
33486 if (likely(bw == len))
33487 return 0;
33488diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
33489index d620b44..587561e 100644
33490--- a/drivers/cdrom/cdrom.c
33491+++ b/drivers/cdrom/cdrom.c
33492@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
33493 ENSURE(reset, CDC_RESET);
33494 ENSURE(generic_packet, CDC_GENERIC_PACKET);
33495 cdi->mc_flags = 0;
33496- cdo->n_minors = 0;
33497 cdi->options = CDO_USE_FFLAGS;
33498
33499 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
33500@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
33501 else
33502 cdi->cdda_method = CDDA_OLD;
33503
33504- if (!cdo->generic_packet)
33505- cdo->generic_packet = cdrom_dummy_generic_packet;
33506+ if (!cdo->generic_packet) {
33507+ pax_open_kernel();
33508+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
33509+ pax_close_kernel();
33510+ }
33511
33512 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
33513 mutex_lock(&cdrom_mutex);
33514@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
33515 if (cdi->exit)
33516 cdi->exit(cdi);
33517
33518- cdi->ops->n_minors--;
33519 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
33520 }
33521
33522diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
33523index d59cdcb..11afddf 100644
33524--- a/drivers/cdrom/gdrom.c
33525+++ b/drivers/cdrom/gdrom.c
33526@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
33527 .audio_ioctl = gdrom_audio_ioctl,
33528 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
33529 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
33530- .n_minors = 1,
33531 };
33532
33533 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
33534diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
33535index 72bedad..8181ce1 100644
33536--- a/drivers/char/Kconfig
33537+++ b/drivers/char/Kconfig
33538@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
33539
33540 config DEVKMEM
33541 bool "/dev/kmem virtual device support"
33542- default y
33543+ default n
33544+ depends on !GRKERNSEC_KMEM
33545 help
33546 Say Y here if you want to support the /dev/kmem device. The
33547 /dev/kmem device is rarely used, but can be used for certain
33548@@ -581,6 +582,7 @@ config DEVPORT
33549 bool
33550 depends on !M68K
33551 depends on ISA || PCI
33552+ depends on !GRKERNSEC_KMEM
33553 default y
33554
33555 source "drivers/s390/char/Kconfig"
33556diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
33557index 2e04433..22afc64 100644
33558--- a/drivers/char/agp/frontend.c
33559+++ b/drivers/char/agp/frontend.c
33560@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33561 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
33562 return -EFAULT;
33563
33564- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
33565+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
33566 return -EFAULT;
33567
33568 client = agp_find_client_by_pid(reserve.pid);
33569diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
33570index 21cb980..f15107c 100644
33571--- a/drivers/char/genrtc.c
33572+++ b/drivers/char/genrtc.c
33573@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
33574 switch (cmd) {
33575
33576 case RTC_PLL_GET:
33577+ memset(&pll, 0, sizeof(pll));
33578 if (get_rtc_pll(&pll))
33579 return -EINVAL;
33580 else
33581diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
33582index fe6d4be..89f32100 100644
33583--- a/drivers/char/hpet.c
33584+++ b/drivers/char/hpet.c
33585@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
33586 }
33587
33588 static int
33589-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
33590+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
33591 struct hpet_info *info)
33592 {
33593 struct hpet_timer __iomem *timer;
33594diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
33595index 053201b0..8335cce 100644
33596--- a/drivers/char/ipmi/ipmi_msghandler.c
33597+++ b/drivers/char/ipmi/ipmi_msghandler.c
33598@@ -420,7 +420,7 @@ struct ipmi_smi {
33599 struct proc_dir_entry *proc_dir;
33600 char proc_dir_name[10];
33601
33602- atomic_t stats[IPMI_NUM_STATS];
33603+ atomic_unchecked_t stats[IPMI_NUM_STATS];
33604
33605 /*
33606 * run_to_completion duplicate of smb_info, smi_info
33607@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
33608
33609
33610 #define ipmi_inc_stat(intf, stat) \
33611- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
33612+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
33613 #define ipmi_get_stat(intf, stat) \
33614- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
33615+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
33616
33617 static int is_lan_addr(struct ipmi_addr *addr)
33618 {
33619@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
33620 INIT_LIST_HEAD(&intf->cmd_rcvrs);
33621 init_waitqueue_head(&intf->waitq);
33622 for (i = 0; i < IPMI_NUM_STATS; i++)
33623- atomic_set(&intf->stats[i], 0);
33624+ atomic_set_unchecked(&intf->stats[i], 0);
33625
33626 intf->proc_dir = NULL;
33627
33628diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
33629index 1c7fdcd..4899100 100644
33630--- a/drivers/char/ipmi/ipmi_si_intf.c
33631+++ b/drivers/char/ipmi/ipmi_si_intf.c
33632@@ -275,7 +275,7 @@ struct smi_info {
33633 unsigned char slave_addr;
33634
33635 /* Counters and things for the proc filesystem. */
33636- atomic_t stats[SI_NUM_STATS];
33637+ atomic_unchecked_t stats[SI_NUM_STATS];
33638
33639 struct task_struct *thread;
33640
33641@@ -284,9 +284,9 @@ struct smi_info {
33642 };
33643
33644 #define smi_inc_stat(smi, stat) \
33645- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
33646+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
33647 #define smi_get_stat(smi, stat) \
33648- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
33649+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
33650
33651 #define SI_MAX_PARMS 4
33652
33653@@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
33654 atomic_set(&new_smi->req_events, 0);
33655 new_smi->run_to_completion = 0;
33656 for (i = 0; i < SI_NUM_STATS; i++)
33657- atomic_set(&new_smi->stats[i], 0);
33658+ atomic_set_unchecked(&new_smi->stats[i], 0);
33659
33660 new_smi->interrupt_disabled = 1;
33661 atomic_set(&new_smi->stop_operation, 0);
33662diff --git a/drivers/char/mem.c b/drivers/char/mem.c
33663index c6fa3bc..4ca3e42 100644
33664--- a/drivers/char/mem.c
33665+++ b/drivers/char/mem.c
33666@@ -18,6 +18,7 @@
33667 #include <linux/raw.h>
33668 #include <linux/tty.h>
33669 #include <linux/capability.h>
33670+#include <linux/security.h>
33671 #include <linux/ptrace.h>
33672 #include <linux/device.h>
33673 #include <linux/highmem.h>
33674@@ -37,6 +38,10 @@
33675
33676 #define DEVPORT_MINOR 4
33677
33678+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33679+extern const struct file_operations grsec_fops;
33680+#endif
33681+
33682 static inline unsigned long size_inside_page(unsigned long start,
33683 unsigned long size)
33684 {
33685@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33686
33687 while (cursor < to) {
33688 if (!devmem_is_allowed(pfn)) {
33689+#ifdef CONFIG_GRKERNSEC_KMEM
33690+ gr_handle_mem_readwrite(from, to);
33691+#else
33692 printk(KERN_INFO
33693 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
33694 current->comm, from, to);
33695+#endif
33696 return 0;
33697 }
33698 cursor += PAGE_SIZE;
33699@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33700 }
33701 return 1;
33702 }
33703+#elif defined(CONFIG_GRKERNSEC_KMEM)
33704+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33705+{
33706+ return 0;
33707+}
33708 #else
33709 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33710 {
33711@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33712
33713 while (count > 0) {
33714 unsigned long remaining;
33715+ char *temp;
33716
33717 sz = size_inside_page(p, count);
33718
33719@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33720 if (!ptr)
33721 return -EFAULT;
33722
33723- remaining = copy_to_user(buf, ptr, sz);
33724+#ifdef CONFIG_PAX_USERCOPY
33725+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
33726+ if (!temp) {
33727+ unxlate_dev_mem_ptr(p, ptr);
33728+ return -ENOMEM;
33729+ }
33730+ memcpy(temp, ptr, sz);
33731+#else
33732+ temp = ptr;
33733+#endif
33734+
33735+ remaining = copy_to_user(buf, temp, sz);
33736+
33737+#ifdef CONFIG_PAX_USERCOPY
33738+ kfree(temp);
33739+#endif
33740+
33741 unxlate_dev_mem_ptr(p, ptr);
33742 if (remaining)
33743 return -EFAULT;
33744@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33745 size_t count, loff_t *ppos)
33746 {
33747 unsigned long p = *ppos;
33748- ssize_t low_count, read, sz;
33749+ ssize_t low_count, read, sz, err = 0;
33750 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
33751- int err = 0;
33752
33753 read = 0;
33754 if (p < (unsigned long) high_memory) {
33755@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33756 }
33757 #endif
33758 while (low_count > 0) {
33759+ char *temp;
33760+
33761 sz = size_inside_page(p, low_count);
33762
33763 /*
33764@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33765 */
33766 kbuf = xlate_dev_kmem_ptr((char *)p);
33767
33768- if (copy_to_user(buf, kbuf, sz))
33769+#ifdef CONFIG_PAX_USERCOPY
33770+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
33771+ if (!temp)
33772+ return -ENOMEM;
33773+ memcpy(temp, kbuf, sz);
33774+#else
33775+ temp = kbuf;
33776+#endif
33777+
33778+ err = copy_to_user(buf, temp, sz);
33779+
33780+#ifdef CONFIG_PAX_USERCOPY
33781+ kfree(temp);
33782+#endif
33783+
33784+ if (err)
33785 return -EFAULT;
33786 buf += sz;
33787 p += sz;
33788@@ -833,6 +880,9 @@ static const struct memdev {
33789 #ifdef CONFIG_CRASH_DUMP
33790 [12] = { "oldmem", 0, &oldmem_fops, NULL },
33791 #endif
33792+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33793+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
33794+#endif
33795 };
33796
33797 static int memory_open(struct inode *inode, struct file *filp)
33798diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
33799index 9df78e2..01ba9ae 100644
33800--- a/drivers/char/nvram.c
33801+++ b/drivers/char/nvram.c
33802@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
33803
33804 spin_unlock_irq(&rtc_lock);
33805
33806- if (copy_to_user(buf, contents, tmp - contents))
33807+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
33808 return -EFAULT;
33809
33810 *ppos = i;
33811diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
33812index b66eaa0..2619d1b 100644
33813--- a/drivers/char/pcmcia/synclink_cs.c
33814+++ b/drivers/char/pcmcia/synclink_cs.c
33815@@ -2348,9 +2348,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
33816
33817 if (debug_level >= DEBUG_LEVEL_INFO)
33818 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
33819- __FILE__,__LINE__, info->device_name, port->count);
33820+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
33821
33822- WARN_ON(!port->count);
33823+ WARN_ON(!atomic_read(&port->count));
33824
33825 if (tty_port_close_start(port, tty, filp) == 0)
33826 goto cleanup;
33827@@ -2368,7 +2368,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
33828 cleanup:
33829 if (debug_level >= DEBUG_LEVEL_INFO)
33830 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
33831- tty->driver->name, port->count);
33832+ tty->driver->name, atomic_read(&port->count));
33833 }
33834
33835 /* Wait until the transmitter is empty.
33836@@ -2510,7 +2510,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
33837
33838 if (debug_level >= DEBUG_LEVEL_INFO)
33839 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
33840- __FILE__,__LINE__,tty->driver->name, port->count);
33841+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
33842
33843 /* If port is closing, signal caller to try again */
33844 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
33845@@ -2530,11 +2530,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
33846 goto cleanup;
33847 }
33848 spin_lock(&port->lock);
33849- port->count++;
33850+ atomic_inc(&port->count);
33851 spin_unlock(&port->lock);
33852 spin_unlock_irqrestore(&info->netlock, flags);
33853
33854- if (port->count == 1) {
33855+ if (atomic_read(&port->count) == 1) {
33856 /* 1st open on this device, init hardware */
33857 retval = startup(info, tty);
33858 if (retval < 0)
33859@@ -3889,7 +3889,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
33860 unsigned short new_crctype;
33861
33862 /* return error if TTY interface open */
33863- if (info->port.count)
33864+ if (atomic_read(&info->port.count))
33865 return -EBUSY;
33866
33867 switch (encoding)
33868@@ -3992,7 +3992,7 @@ static int hdlcdev_open(struct net_device *dev)
33869
33870 /* arbitrate between network and tty opens */
33871 spin_lock_irqsave(&info->netlock, flags);
33872- if (info->port.count != 0 || info->netcount != 0) {
33873+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
33874 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
33875 spin_unlock_irqrestore(&info->netlock, flags);
33876 return -EBUSY;
33877@@ -4081,7 +4081,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
33878 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
33879
33880 /* return error if TTY interface open */
33881- if (info->port.count)
33882+ if (atomic_read(&info->port.count))
33883 return -EBUSY;
33884
33885 if (cmd != SIOCWANDEV)
33886diff --git a/drivers/char/random.c b/drivers/char/random.c
33887index 57d4b15..253207b 100644
33888--- a/drivers/char/random.c
33889+++ b/drivers/char/random.c
33890@@ -272,8 +272,13 @@
33891 /*
33892 * Configuration information
33893 */
33894+#ifdef CONFIG_GRKERNSEC_RANDNET
33895+#define INPUT_POOL_WORDS 512
33896+#define OUTPUT_POOL_WORDS 128
33897+#else
33898 #define INPUT_POOL_WORDS 128
33899 #define OUTPUT_POOL_WORDS 32
33900+#endif
33901 #define SEC_XFER_SIZE 512
33902 #define EXTRACT_SIZE 10
33903
33904@@ -313,10 +318,17 @@ static struct poolinfo {
33905 int poolwords;
33906 int tap1, tap2, tap3, tap4, tap5;
33907 } poolinfo_table[] = {
33908+#ifdef CONFIG_GRKERNSEC_RANDNET
33909+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
33910+ { 512, 411, 308, 208, 104, 1 },
33911+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
33912+ { 128, 103, 76, 51, 25, 1 },
33913+#else
33914 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
33915 { 128, 103, 76, 51, 25, 1 },
33916 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
33917 { 32, 26, 20, 14, 7, 1 },
33918+#endif
33919 #if 0
33920 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
33921 { 2048, 1638, 1231, 819, 411, 1 },
33922@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
33923 input_rotate += i ? 7 : 14;
33924 }
33925
33926- ACCESS_ONCE(r->input_rotate) = input_rotate;
33927- ACCESS_ONCE(r->add_ptr) = i;
33928+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
33929+ ACCESS_ONCE_RW(r->add_ptr) = i;
33930 smp_wmb();
33931
33932 if (out)
33933@@ -1024,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
33934
33935 extract_buf(r, tmp);
33936 i = min_t(int, nbytes, EXTRACT_SIZE);
33937- if (copy_to_user(buf, tmp, i)) {
33938+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
33939 ret = -EFAULT;
33940 break;
33941 }
33942@@ -1360,7 +1372,7 @@ EXPORT_SYMBOL(generate_random_uuid);
33943 #include <linux/sysctl.h>
33944
33945 static int min_read_thresh = 8, min_write_thresh;
33946-static int max_read_thresh = INPUT_POOL_WORDS * 32;
33947+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
33948 static int max_write_thresh = INPUT_POOL_WORDS * 32;
33949 static char sysctl_bootid[16];
33950
33951@@ -1376,7 +1388,7 @@ static char sysctl_bootid[16];
33952 static int proc_do_uuid(ctl_table *table, int write,
33953 void __user *buffer, size_t *lenp, loff_t *ppos)
33954 {
33955- ctl_table fake_table;
33956+ ctl_table_no_const fake_table;
33957 unsigned char buf[64], tmp_uuid[16], *uuid;
33958
33959 uuid = table->data;
33960diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
33961index d780295..b29f3a8 100644
33962--- a/drivers/char/sonypi.c
33963+++ b/drivers/char/sonypi.c
33964@@ -54,6 +54,7 @@
33965
33966 #include <asm/uaccess.h>
33967 #include <asm/io.h>
33968+#include <asm/local.h>
33969
33970 #include <linux/sonypi.h>
33971
33972@@ -490,7 +491,7 @@ static struct sonypi_device {
33973 spinlock_t fifo_lock;
33974 wait_queue_head_t fifo_proc_list;
33975 struct fasync_struct *fifo_async;
33976- int open_count;
33977+ local_t open_count;
33978 int model;
33979 struct input_dev *input_jog_dev;
33980 struct input_dev *input_key_dev;
33981@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
33982 static int sonypi_misc_release(struct inode *inode, struct file *file)
33983 {
33984 mutex_lock(&sonypi_device.lock);
33985- sonypi_device.open_count--;
33986+ local_dec(&sonypi_device.open_count);
33987 mutex_unlock(&sonypi_device.lock);
33988 return 0;
33989 }
33990@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
33991 {
33992 mutex_lock(&sonypi_device.lock);
33993 /* Flush input queue on first open */
33994- if (!sonypi_device.open_count)
33995+ if (!local_read(&sonypi_device.open_count))
33996 kfifo_reset(&sonypi_device.fifo);
33997- sonypi_device.open_count++;
33998+ local_inc(&sonypi_device.open_count);
33999 mutex_unlock(&sonypi_device.lock);
34000
34001 return 0;
34002diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
34003index 93211df..c7805f7 100644
34004--- a/drivers/char/tpm/tpm.c
34005+++ b/drivers/char/tpm/tpm.c
34006@@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
34007 chip->vendor.req_complete_val)
34008 goto out_recv;
34009
34010- if ((status == chip->vendor.req_canceled)) {
34011+ if (status == chip->vendor.req_canceled) {
34012 dev_err(chip->dev, "Operation Canceled\n");
34013 rc = -ECANCELED;
34014 goto out;
34015diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
34016index 56051d0..11cf3b7 100644
34017--- a/drivers/char/tpm/tpm_acpi.c
34018+++ b/drivers/char/tpm/tpm_acpi.c
34019@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
34020 virt = acpi_os_map_memory(start, len);
34021 if (!virt) {
34022 kfree(log->bios_event_log);
34023+ log->bios_event_log = NULL;
34024 printk("%s: ERROR - Unable to map memory\n", __func__);
34025 return -EIO;
34026 }
34027
34028- memcpy_fromio(log->bios_event_log, virt, len);
34029+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
34030
34031 acpi_os_unmap_memory(virt, len);
34032 return 0;
34033diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
34034index 84ddc55..1d32f1e 100644
34035--- a/drivers/char/tpm/tpm_eventlog.c
34036+++ b/drivers/char/tpm/tpm_eventlog.c
34037@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
34038 event = addr;
34039
34040 if ((event->event_type == 0 && event->event_size == 0) ||
34041- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
34042+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
34043 return NULL;
34044
34045 return addr;
34046@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
34047 return NULL;
34048
34049 if ((event->event_type == 0 && event->event_size == 0) ||
34050- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
34051+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
34052 return NULL;
34053
34054 (*pos)++;
34055@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
34056 int i;
34057
34058 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
34059- seq_putc(m, data[i]);
34060+ if (!seq_putc(m, data[i]))
34061+ return -EFAULT;
34062
34063 return 0;
34064 }
34065diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
34066index ee4dbea..69c817b 100644
34067--- a/drivers/char/virtio_console.c
34068+++ b/drivers/char/virtio_console.c
34069@@ -681,7 +681,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
34070 if (to_user) {
34071 ssize_t ret;
34072
34073- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
34074+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
34075 if (ret)
34076 return -EFAULT;
34077 } else {
34078@@ -780,7 +780,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
34079 if (!port_has_data(port) && !port->host_connected)
34080 return 0;
34081
34082- return fill_readbuf(port, ubuf, count, true);
34083+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
34084 }
34085
34086 static int wait_port_writable(struct port *port, bool nonblock)
34087diff --git a/drivers/clocksource/arm_generic.c b/drivers/clocksource/arm_generic.c
34088index 8ae1a61..9c00613 100644
34089--- a/drivers/clocksource/arm_generic.c
34090+++ b/drivers/clocksource/arm_generic.c
34091@@ -181,7 +181,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34092 return NOTIFY_OK;
34093 }
34094
34095-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
34096+static struct notifier_block arch_timer_cpu_nb = {
34097 .notifier_call = arch_timer_cpu_notify,
34098 };
34099
34100diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
34101index 7b0d49d..134fac9 100644
34102--- a/drivers/cpufreq/acpi-cpufreq.c
34103+++ b/drivers/cpufreq/acpi-cpufreq.c
34104@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
34105 return sprintf(buf, "%u\n", boost_enabled);
34106 }
34107
34108-static struct global_attr global_boost = __ATTR(boost, 0644,
34109+static global_attr_no_const global_boost = __ATTR(boost, 0644,
34110 show_global_boost,
34111 store_global_boost);
34112
34113@@ -712,8 +712,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34114 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
34115 per_cpu(acfreq_data, cpu) = data;
34116
34117- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
34118- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34119+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
34120+ pax_open_kernel();
34121+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34122+ pax_close_kernel();
34123+ }
34124
34125 result = acpi_processor_register_performance(data->acpi_data, cpu);
34126 if (result)
34127@@ -835,7 +838,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34128 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
34129 break;
34130 case ACPI_ADR_SPACE_FIXED_HARDWARE:
34131- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34132+ pax_open_kernel();
34133+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34134+ pax_close_kernel();
34135 policy->cur = get_cur_freq_on_cpu(cpu);
34136 break;
34137 default:
34138@@ -846,8 +851,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34139 acpi_processor_notify_smm(THIS_MODULE);
34140
34141 /* Check for APERF/MPERF support in hardware */
34142- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
34143- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34144+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
34145+ pax_open_kernel();
34146+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34147+ pax_close_kernel();
34148+ }
34149
34150 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
34151 for (i = 0; i < perf->state_count; i++)
34152diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
34153index 1f93dbd..305cef1 100644
34154--- a/drivers/cpufreq/cpufreq.c
34155+++ b/drivers/cpufreq/cpufreq.c
34156@@ -1843,7 +1843,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
34157 return NOTIFY_OK;
34158 }
34159
34160-static struct notifier_block __refdata cpufreq_cpu_notifier = {
34161+static struct notifier_block cpufreq_cpu_notifier = {
34162 .notifier_call = cpufreq_cpu_callback,
34163 };
34164
34165@@ -1875,8 +1875,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
34166
34167 pr_debug("trying to register driver %s\n", driver_data->name);
34168
34169- if (driver_data->setpolicy)
34170- driver_data->flags |= CPUFREQ_CONST_LOOPS;
34171+ if (driver_data->setpolicy) {
34172+ pax_open_kernel();
34173+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
34174+ pax_close_kernel();
34175+ }
34176
34177 spin_lock_irqsave(&cpufreq_driver_lock, flags);
34178 if (cpufreq_driver) {
34179diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
34180index 6c5f1d3..c7e2f35e 100644
34181--- a/drivers/cpufreq/cpufreq_governor.c
34182+++ b/drivers/cpufreq/cpufreq_governor.c
34183@@ -243,7 +243,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
34184 * governor, thus we are bound to jiffes/HZ
34185 */
34186 if (dbs_data->governor == GOV_CONSERVATIVE) {
34187- struct cs_ops *ops = dbs_data->gov_ops;
34188+ const struct cs_ops *ops = dbs_data->gov_ops;
34189
34190 cpufreq_register_notifier(ops->notifier_block,
34191 CPUFREQ_TRANSITION_NOTIFIER);
34192@@ -251,7 +251,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
34193 dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO *
34194 jiffies_to_usecs(10);
34195 } else {
34196- struct od_ops *ops = dbs_data->gov_ops;
34197+ const struct od_ops *ops = dbs_data->gov_ops;
34198
34199 od_tuners->io_is_busy = ops->io_busy();
34200 }
34201@@ -268,7 +268,7 @@ second_time:
34202 cs_dbs_info->enable = 1;
34203 cs_dbs_info->requested_freq = policy->cur;
34204 } else {
34205- struct od_ops *ops = dbs_data->gov_ops;
34206+ const struct od_ops *ops = dbs_data->gov_ops;
34207 od_dbs_info->rate_mult = 1;
34208 od_dbs_info->sample_type = OD_NORMAL_SAMPLE;
34209 ops->powersave_bias_init_cpu(cpu);
34210@@ -289,7 +289,7 @@ second_time:
34211 mutex_destroy(&cpu_cdbs->timer_mutex);
34212 dbs_data->enable--;
34213 if (!dbs_data->enable) {
34214- struct cs_ops *ops = dbs_data->gov_ops;
34215+ const struct cs_ops *ops = dbs_data->gov_ops;
34216
34217 sysfs_remove_group(cpufreq_global_kobject,
34218 dbs_data->attr_group);
34219diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
34220index f661654..6c8e638 100644
34221--- a/drivers/cpufreq/cpufreq_governor.h
34222+++ b/drivers/cpufreq/cpufreq_governor.h
34223@@ -142,7 +142,7 @@ struct dbs_data {
34224 void (*gov_check_cpu)(int cpu, unsigned int load);
34225
34226 /* Governor specific ops, see below */
34227- void *gov_ops;
34228+ const void *gov_ops;
34229 };
34230
34231 /* Governor specific ops, will be passed to dbs_data->gov_ops */
34232diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
34233index 9d7732b..0b1a793 100644
34234--- a/drivers/cpufreq/cpufreq_stats.c
34235+++ b/drivers/cpufreq/cpufreq_stats.c
34236@@ -340,7 +340,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
34237 }
34238
34239 /* priority=1 so this will get called before cpufreq_remove_dev */
34240-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
34241+static struct notifier_block cpufreq_stat_cpu_notifier = {
34242 .notifier_call = cpufreq_stat_cpu_callback,
34243 .priority = 1,
34244 };
34245diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
34246index 827629c9..0bc6a03 100644
34247--- a/drivers/cpufreq/p4-clockmod.c
34248+++ b/drivers/cpufreq/p4-clockmod.c
34249@@ -167,10 +167,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34250 case 0x0F: /* Core Duo */
34251 case 0x16: /* Celeron Core */
34252 case 0x1C: /* Atom */
34253- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34254+ pax_open_kernel();
34255+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34256+ pax_close_kernel();
34257 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
34258 case 0x0D: /* Pentium M (Dothan) */
34259- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34260+ pax_open_kernel();
34261+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34262+ pax_close_kernel();
34263 /* fall through */
34264 case 0x09: /* Pentium M (Banias) */
34265 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
34266@@ -182,7 +186,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34267
34268 /* on P-4s, the TSC runs with constant frequency independent whether
34269 * throttling is active or not. */
34270- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34271+ pax_open_kernel();
34272+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34273+ pax_close_kernel();
34274
34275 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
34276 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
34277diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
34278index 3a953d5..f5993f6 100644
34279--- a/drivers/cpufreq/speedstep-centrino.c
34280+++ b/drivers/cpufreq/speedstep-centrino.c
34281@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
34282 !cpu_has(cpu, X86_FEATURE_EST))
34283 return -ENODEV;
34284
34285- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
34286- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34287+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
34288+ pax_open_kernel();
34289+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34290+ pax_close_kernel();
34291+ }
34292
34293 if (policy->cpu != 0)
34294 return -ENODEV;
34295diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
34296index e1f6860..f8de20b 100644
34297--- a/drivers/cpuidle/cpuidle.c
34298+++ b/drivers/cpuidle/cpuidle.c
34299@@ -279,7 +279,7 @@ static int poll_idle(struct cpuidle_device *dev,
34300
34301 static void poll_idle_init(struct cpuidle_driver *drv)
34302 {
34303- struct cpuidle_state *state = &drv->states[0];
34304+ cpuidle_state_no_const *state = &drv->states[0];
34305
34306 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
34307 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
34308diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
34309index ea2f8e7..70ac501 100644
34310--- a/drivers/cpuidle/governor.c
34311+++ b/drivers/cpuidle/governor.c
34312@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
34313 mutex_lock(&cpuidle_lock);
34314 if (__cpuidle_find_governor(gov->name) == NULL) {
34315 ret = 0;
34316- list_add_tail(&gov->governor_list, &cpuidle_governors);
34317+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
34318 if (!cpuidle_curr_governor ||
34319 cpuidle_curr_governor->rating < gov->rating)
34320 cpuidle_switch_governor(gov);
34321@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
34322 new_gov = cpuidle_replace_governor(gov->rating);
34323 cpuidle_switch_governor(new_gov);
34324 }
34325- list_del(&gov->governor_list);
34326+ pax_list_del((struct list_head *)&gov->governor_list);
34327 mutex_unlock(&cpuidle_lock);
34328 }
34329
34330diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
34331index 428754a..8bdf9cc 100644
34332--- a/drivers/cpuidle/sysfs.c
34333+++ b/drivers/cpuidle/sysfs.c
34334@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
34335 NULL
34336 };
34337
34338-static struct attribute_group cpuidle_attr_group = {
34339+static attribute_group_no_const cpuidle_attr_group = {
34340 .attrs = cpuidle_default_attrs,
34341 .name = "cpuidle",
34342 };
34343diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
34344index 3b36797..289c16a 100644
34345--- a/drivers/devfreq/devfreq.c
34346+++ b/drivers/devfreq/devfreq.c
34347@@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
34348 goto err_out;
34349 }
34350
34351- list_add(&governor->node, &devfreq_governor_list);
34352+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
34353
34354 list_for_each_entry(devfreq, &devfreq_list, node) {
34355 int ret = 0;
34356@@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
34357 }
34358 }
34359
34360- list_del(&governor->node);
34361+ pax_list_del((struct list_head *)&governor->node);
34362 err_out:
34363 mutex_unlock(&devfreq_list_lock);
34364
34365diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
34366index b70709b..1d8d02a 100644
34367--- a/drivers/dma/sh/shdma.c
34368+++ b/drivers/dma/sh/shdma.c
34369@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
34370 return ret;
34371 }
34372
34373-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
34374+static struct notifier_block sh_dmae_nmi_notifier = {
34375 .notifier_call = sh_dmae_nmi_handler,
34376
34377 /* Run before NMI debug handler and KGDB */
34378diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
34379index 0ca1ca7..6e6f454 100644
34380--- a/drivers/edac/edac_mc_sysfs.c
34381+++ b/drivers/edac/edac_mc_sysfs.c
34382@@ -148,7 +148,7 @@ static const char *edac_caps[] = {
34383 struct dev_ch_attribute {
34384 struct device_attribute attr;
34385 int channel;
34386-};
34387+} __do_const;
34388
34389 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
34390 struct dev_ch_attribute dev_attr_legacy_##_name = \
34391diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
34392index 0056c4d..23b54d9 100644
34393--- a/drivers/edac/edac_pci_sysfs.c
34394+++ b/drivers/edac/edac_pci_sysfs.c
34395@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
34396 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
34397 static int edac_pci_poll_msec = 1000; /* one second workq period */
34398
34399-static atomic_t pci_parity_count = ATOMIC_INIT(0);
34400-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
34401+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
34402+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
34403
34404 static struct kobject *edac_pci_top_main_kobj;
34405 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
34406@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
34407 void *value;
34408 ssize_t(*show) (void *, char *);
34409 ssize_t(*store) (void *, const char *, size_t);
34410-};
34411+} __do_const;
34412
34413 /* Set of show/store abstract level functions for PCI Parity object */
34414 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
34415@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34416 edac_printk(KERN_CRIT, EDAC_PCI,
34417 "Signaled System Error on %s\n",
34418 pci_name(dev));
34419- atomic_inc(&pci_nonparity_count);
34420+ atomic_inc_unchecked(&pci_nonparity_count);
34421 }
34422
34423 if (status & (PCI_STATUS_PARITY)) {
34424@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34425 "Master Data Parity Error on %s\n",
34426 pci_name(dev));
34427
34428- atomic_inc(&pci_parity_count);
34429+ atomic_inc_unchecked(&pci_parity_count);
34430 }
34431
34432 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34433@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34434 "Detected Parity Error on %s\n",
34435 pci_name(dev));
34436
34437- atomic_inc(&pci_parity_count);
34438+ atomic_inc_unchecked(&pci_parity_count);
34439 }
34440 }
34441
34442@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34443 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
34444 "Signaled System Error on %s\n",
34445 pci_name(dev));
34446- atomic_inc(&pci_nonparity_count);
34447+ atomic_inc_unchecked(&pci_nonparity_count);
34448 }
34449
34450 if (status & (PCI_STATUS_PARITY)) {
34451@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34452 "Master Data Parity Error on "
34453 "%s\n", pci_name(dev));
34454
34455- atomic_inc(&pci_parity_count);
34456+ atomic_inc_unchecked(&pci_parity_count);
34457 }
34458
34459 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34460@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34461 "Detected Parity Error on %s\n",
34462 pci_name(dev));
34463
34464- atomic_inc(&pci_parity_count);
34465+ atomic_inc_unchecked(&pci_parity_count);
34466 }
34467 }
34468 }
34469@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
34470 if (!check_pci_errors)
34471 return;
34472
34473- before_count = atomic_read(&pci_parity_count);
34474+ before_count = atomic_read_unchecked(&pci_parity_count);
34475
34476 /* scan all PCI devices looking for a Parity Error on devices and
34477 * bridges.
34478@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
34479 /* Only if operator has selected panic on PCI Error */
34480 if (edac_pci_get_panic_on_pe()) {
34481 /* If the count is different 'after' from 'before' */
34482- if (before_count != atomic_read(&pci_parity_count))
34483+ if (before_count != atomic_read_unchecked(&pci_parity_count))
34484 panic("EDAC: PCI Parity Error");
34485 }
34486 }
34487diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
34488index 6796799..99e8377 100644
34489--- a/drivers/edac/mce_amd.h
34490+++ b/drivers/edac/mce_amd.h
34491@@ -78,7 +78,7 @@ extern const char * const ii_msgs[];
34492 struct amd_decoder_ops {
34493 bool (*mc0_mce)(u16, u8);
34494 bool (*mc1_mce)(u16, u8);
34495-};
34496+} __no_const;
34497
34498 void amd_report_gart_errors(bool);
34499 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
34500diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
34501index 57ea7f4..789e3c3 100644
34502--- a/drivers/firewire/core-card.c
34503+++ b/drivers/firewire/core-card.c
34504@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
34505
34506 void fw_core_remove_card(struct fw_card *card)
34507 {
34508- struct fw_card_driver dummy_driver = dummy_driver_template;
34509+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
34510
34511 card->driver->update_phy_reg(card, 4,
34512 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
34513diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
34514index f8d2287..5aaf4db 100644
34515--- a/drivers/firewire/core-cdev.c
34516+++ b/drivers/firewire/core-cdev.c
34517@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
34518 int ret;
34519
34520 if ((request->channels == 0 && request->bandwidth == 0) ||
34521- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
34522- request->bandwidth < 0)
34523+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
34524 return -EINVAL;
34525
34526 r = kmalloc(sizeof(*r), GFP_KERNEL);
34527diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
34528index af3e8aa..eb2f227 100644
34529--- a/drivers/firewire/core-device.c
34530+++ b/drivers/firewire/core-device.c
34531@@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
34532 struct config_rom_attribute {
34533 struct device_attribute attr;
34534 u32 key;
34535-};
34536+} __do_const;
34537
34538 static ssize_t show_immediate(struct device *dev,
34539 struct device_attribute *dattr, char *buf)
34540diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
34541index 28a94c7..58da63a 100644
34542--- a/drivers/firewire/core-transaction.c
34543+++ b/drivers/firewire/core-transaction.c
34544@@ -38,6 +38,7 @@
34545 #include <linux/timer.h>
34546 #include <linux/types.h>
34547 #include <linux/workqueue.h>
34548+#include <linux/sched.h>
34549
34550 #include <asm/byteorder.h>
34551
34552diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
34553index 515a42c..5ecf3ba 100644
34554--- a/drivers/firewire/core.h
34555+++ b/drivers/firewire/core.h
34556@@ -111,6 +111,7 @@ struct fw_card_driver {
34557
34558 int (*stop_iso)(struct fw_iso_context *ctx);
34559 };
34560+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
34561
34562 void fw_card_initialize(struct fw_card *card,
34563 const struct fw_card_driver *driver, struct device *device);
34564diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
34565index 94a58a0..f5eba42 100644
34566--- a/drivers/firmware/dmi-id.c
34567+++ b/drivers/firmware/dmi-id.c
34568@@ -16,7 +16,7 @@
34569 struct dmi_device_attribute{
34570 struct device_attribute dev_attr;
34571 int field;
34572-};
34573+} __do_const;
34574 #define to_dmi_dev_attr(_dev_attr) \
34575 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
34576
34577diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
34578index 4cd392d..4b629e1 100644
34579--- a/drivers/firmware/dmi_scan.c
34580+++ b/drivers/firmware/dmi_scan.c
34581@@ -490,11 +490,6 @@ void __init dmi_scan_machine(void)
34582 }
34583 }
34584 else {
34585- /*
34586- * no iounmap() for that ioremap(); it would be a no-op, but
34587- * it's so early in setup that sucker gets confused into doing
34588- * what it shouldn't if we actually call it.
34589- */
34590 p = dmi_ioremap(0xF0000, 0x10000);
34591 if (p == NULL)
34592 goto error;
34593@@ -769,7 +764,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
34594 if (buf == NULL)
34595 return -1;
34596
34597- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
34598+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
34599
34600 iounmap(buf);
34601 return 0;
34602diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
34603index e1d6253..bd00f91 100644
34604--- a/drivers/firmware/efivars.c
34605+++ b/drivers/firmware/efivars.c
34606@@ -138,7 +138,7 @@ struct efivar_attribute {
34607 };
34608
34609 static struct efivars __efivars;
34610-static struct efivar_operations ops;
34611+static efivar_operations_no_const ops __read_only;
34612
34613 #define PSTORE_EFI_ATTRIBUTES \
34614 (EFI_VARIABLE_NON_VOLATILE | \
34615@@ -1787,7 +1787,7 @@ efivar_create_sysfs_entry(struct efivars *efivars,
34616 static int
34617 create_efivars_bin_attributes(struct efivars *efivars)
34618 {
34619- struct bin_attribute *attr;
34620+ bin_attribute_no_const *attr;
34621 int error;
34622
34623 /* new_var */
34624diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
34625index 2a90ba6..07f3733 100644
34626--- a/drivers/firmware/google/memconsole.c
34627+++ b/drivers/firmware/google/memconsole.c
34628@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
34629 if (!found_memconsole())
34630 return -ENODEV;
34631
34632- memconsole_bin_attr.size = memconsole_length;
34633+ pax_open_kernel();
34634+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
34635+ pax_close_kernel();
34636
34637 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
34638
34639diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
34640index 6f2306d..af9476a 100644
34641--- a/drivers/gpio/gpio-ich.c
34642+++ b/drivers/gpio/gpio-ich.c
34643@@ -69,7 +69,7 @@ struct ichx_desc {
34644 /* Some chipsets have quirks, let these use their own request/get */
34645 int (*request)(struct gpio_chip *chip, unsigned offset);
34646 int (*get)(struct gpio_chip *chip, unsigned offset);
34647-};
34648+} __do_const;
34649
34650 static struct {
34651 spinlock_t lock;
34652diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
34653index 9902732..64b62dd 100644
34654--- a/drivers/gpio/gpio-vr41xx.c
34655+++ b/drivers/gpio/gpio-vr41xx.c
34656@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
34657 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
34658 maskl, pendl, maskh, pendh);
34659
34660- atomic_inc(&irq_err_count);
34661+ atomic_inc_unchecked(&irq_err_count);
34662
34663 return -EINVAL;
34664 }
34665diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
34666index 7b2d378..cc947ea 100644
34667--- a/drivers/gpu/drm/drm_crtc_helper.c
34668+++ b/drivers/gpu/drm/drm_crtc_helper.c
34669@@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
34670 struct drm_crtc *tmp;
34671 int crtc_mask = 1;
34672
34673- WARN(!crtc, "checking null crtc?\n");
34674+ BUG_ON(!crtc);
34675
34676 dev = crtc->dev;
34677
34678diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
34679index be174ca..7f38143 100644
34680--- a/drivers/gpu/drm/drm_drv.c
34681+++ b/drivers/gpu/drm/drm_drv.c
34682@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
34683 /**
34684 * Copy and IOCTL return string to user space
34685 */
34686-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
34687+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
34688 {
34689 int len;
34690
34691@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
34692 struct drm_file *file_priv = filp->private_data;
34693 struct drm_device *dev;
34694 struct drm_ioctl_desc *ioctl;
34695- drm_ioctl_t *func;
34696+ drm_ioctl_no_const_t func;
34697 unsigned int nr = DRM_IOCTL_NR(cmd);
34698 int retcode = -EINVAL;
34699 char stack_kdata[128];
34700@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
34701 return -ENODEV;
34702
34703 atomic_inc(&dev->ioctl_count);
34704- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
34705+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
34706 ++file_priv->ioctl_count;
34707
34708 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
34709diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
34710index 133b413..fd68225 100644
34711--- a/drivers/gpu/drm/drm_fops.c
34712+++ b/drivers/gpu/drm/drm_fops.c
34713@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
34714 }
34715
34716 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
34717- atomic_set(&dev->counts[i], 0);
34718+ atomic_set_unchecked(&dev->counts[i], 0);
34719
34720 dev->sigdata.lock = NULL;
34721
34722@@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
34723 if (drm_device_is_unplugged(dev))
34724 return -ENODEV;
34725
34726- if (!dev->open_count++)
34727+ if (local_inc_return(&dev->open_count) == 1)
34728 need_setup = 1;
34729 mutex_lock(&dev->struct_mutex);
34730 old_mapping = dev->dev_mapping;
34731@@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
34732 retcode = drm_open_helper(inode, filp, dev);
34733 if (retcode)
34734 goto err_undo;
34735- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
34736+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
34737 if (need_setup) {
34738 retcode = drm_setup(dev);
34739 if (retcode)
34740@@ -164,7 +164,7 @@ err_undo:
34741 iput(container_of(dev->dev_mapping, struct inode, i_data));
34742 dev->dev_mapping = old_mapping;
34743 mutex_unlock(&dev->struct_mutex);
34744- dev->open_count--;
34745+ local_dec(&dev->open_count);
34746 return retcode;
34747 }
34748 EXPORT_SYMBOL(drm_open);
34749@@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
34750
34751 mutex_lock(&drm_global_mutex);
34752
34753- DRM_DEBUG("open_count = %d\n", dev->open_count);
34754+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
34755
34756 if (dev->driver->preclose)
34757 dev->driver->preclose(dev, file_priv);
34758@@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
34759 * Begin inline drm_release
34760 */
34761
34762- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
34763+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
34764 task_pid_nr(current),
34765 (long)old_encode_dev(file_priv->minor->device),
34766- dev->open_count);
34767+ local_read(&dev->open_count));
34768
34769 /* Release any auth tokens that might point to this file_priv,
34770 (do that under the drm_global_mutex) */
34771@@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
34772 * End inline drm_release
34773 */
34774
34775- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
34776- if (!--dev->open_count) {
34777+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
34778+ if (local_dec_and_test(&dev->open_count)) {
34779 if (atomic_read(&dev->ioctl_count)) {
34780 DRM_ERROR("Device busy: %d\n",
34781 atomic_read(&dev->ioctl_count));
34782diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
34783index f731116..629842c 100644
34784--- a/drivers/gpu/drm/drm_global.c
34785+++ b/drivers/gpu/drm/drm_global.c
34786@@ -36,7 +36,7 @@
34787 struct drm_global_item {
34788 struct mutex mutex;
34789 void *object;
34790- int refcount;
34791+ atomic_t refcount;
34792 };
34793
34794 static struct drm_global_item glob[DRM_GLOBAL_NUM];
34795@@ -49,7 +49,7 @@ void drm_global_init(void)
34796 struct drm_global_item *item = &glob[i];
34797 mutex_init(&item->mutex);
34798 item->object = NULL;
34799- item->refcount = 0;
34800+ atomic_set(&item->refcount, 0);
34801 }
34802 }
34803
34804@@ -59,7 +59,7 @@ void drm_global_release(void)
34805 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
34806 struct drm_global_item *item = &glob[i];
34807 BUG_ON(item->object != NULL);
34808- BUG_ON(item->refcount != 0);
34809+ BUG_ON(atomic_read(&item->refcount) != 0);
34810 }
34811 }
34812
34813@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
34814 void *object;
34815
34816 mutex_lock(&item->mutex);
34817- if (item->refcount == 0) {
34818+ if (atomic_read(&item->refcount) == 0) {
34819 item->object = kzalloc(ref->size, GFP_KERNEL);
34820 if (unlikely(item->object == NULL)) {
34821 ret = -ENOMEM;
34822@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
34823 goto out_err;
34824
34825 }
34826- ++item->refcount;
34827+ atomic_inc(&item->refcount);
34828 ref->object = item->object;
34829 object = item->object;
34830 mutex_unlock(&item->mutex);
34831@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
34832 struct drm_global_item *item = &glob[ref->global_type];
34833
34834 mutex_lock(&item->mutex);
34835- BUG_ON(item->refcount == 0);
34836+ BUG_ON(atomic_read(&item->refcount) == 0);
34837 BUG_ON(ref->object != item->object);
34838- if (--item->refcount == 0) {
34839+ if (atomic_dec_and_test(&item->refcount)) {
34840 ref->release(ref);
34841 item->object = NULL;
34842 }
34843diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
34844index d4b20ce..77a8d41 100644
34845--- a/drivers/gpu/drm/drm_info.c
34846+++ b/drivers/gpu/drm/drm_info.c
34847@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
34848 struct drm_local_map *map;
34849 struct drm_map_list *r_list;
34850
34851- /* Hardcoded from _DRM_FRAME_BUFFER,
34852- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
34853- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
34854- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
34855+ static const char * const types[] = {
34856+ [_DRM_FRAME_BUFFER] = "FB",
34857+ [_DRM_REGISTERS] = "REG",
34858+ [_DRM_SHM] = "SHM",
34859+ [_DRM_AGP] = "AGP",
34860+ [_DRM_SCATTER_GATHER] = "SG",
34861+ [_DRM_CONSISTENT] = "PCI",
34862+ [_DRM_GEM] = "GEM" };
34863 const char *type;
34864 int i;
34865
34866@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
34867 map = r_list->map;
34868 if (!map)
34869 continue;
34870- if (map->type < 0 || map->type > 5)
34871+ if (map->type >= ARRAY_SIZE(types))
34872 type = "??";
34873 else
34874 type = types[map->type];
34875@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
34876 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
34877 vma->vm_flags & VM_LOCKED ? 'l' : '-',
34878 vma->vm_flags & VM_IO ? 'i' : '-',
34879+#ifdef CONFIG_GRKERNSEC_HIDESYM
34880+ 0);
34881+#else
34882 vma->vm_pgoff);
34883+#endif
34884
34885 #if defined(__i386__)
34886 pgprot = pgprot_val(vma->vm_page_prot);
34887diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
34888index 2f4c434..dd12cd2 100644
34889--- a/drivers/gpu/drm/drm_ioc32.c
34890+++ b/drivers/gpu/drm/drm_ioc32.c
34891@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
34892 request = compat_alloc_user_space(nbytes);
34893 if (!access_ok(VERIFY_WRITE, request, nbytes))
34894 return -EFAULT;
34895- list = (struct drm_buf_desc *) (request + 1);
34896+ list = (struct drm_buf_desc __user *) (request + 1);
34897
34898 if (__put_user(count, &request->count)
34899 || __put_user(list, &request->list))
34900@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
34901 request = compat_alloc_user_space(nbytes);
34902 if (!access_ok(VERIFY_WRITE, request, nbytes))
34903 return -EFAULT;
34904- list = (struct drm_buf_pub *) (request + 1);
34905+ list = (struct drm_buf_pub __user *) (request + 1);
34906
34907 if (__put_user(count, &request->count)
34908 || __put_user(list, &request->list))
34909@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
34910 return 0;
34911 }
34912
34913-drm_ioctl_compat_t *drm_compat_ioctls[] = {
34914+drm_ioctl_compat_t drm_compat_ioctls[] = {
34915 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
34916 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
34917 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
34918@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
34919 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34920 {
34921 unsigned int nr = DRM_IOCTL_NR(cmd);
34922- drm_ioctl_compat_t *fn;
34923 int ret;
34924
34925 /* Assume that ioctls without an explicit compat routine will just
34926@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34927 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
34928 return drm_ioctl(filp, cmd, arg);
34929
34930- fn = drm_compat_ioctls[nr];
34931-
34932- if (fn != NULL)
34933- ret = (*fn) (filp, cmd, arg);
34934+ if (drm_compat_ioctls[nr] != NULL)
34935+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
34936 else
34937 ret = drm_ioctl(filp, cmd, arg);
34938
34939diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
34940index e77bd8b..1571b85 100644
34941--- a/drivers/gpu/drm/drm_ioctl.c
34942+++ b/drivers/gpu/drm/drm_ioctl.c
34943@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
34944 stats->data[i].value =
34945 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
34946 else
34947- stats->data[i].value = atomic_read(&dev->counts[i]);
34948+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
34949 stats->data[i].type = dev->types[i];
34950 }
34951
34952diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
34953index d752c96..fe08455 100644
34954--- a/drivers/gpu/drm/drm_lock.c
34955+++ b/drivers/gpu/drm/drm_lock.c
34956@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
34957 if (drm_lock_take(&master->lock, lock->context)) {
34958 master->lock.file_priv = file_priv;
34959 master->lock.lock_time = jiffies;
34960- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
34961+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
34962 break; /* Got lock */
34963 }
34964
34965@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
34966 return -EINVAL;
34967 }
34968
34969- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
34970+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
34971
34972 if (drm_lock_free(&master->lock, lock->context)) {
34973 /* FIXME: Should really bail out here. */
34974diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
34975index 200e104..59facda 100644
34976--- a/drivers/gpu/drm/drm_stub.c
34977+++ b/drivers/gpu/drm/drm_stub.c
34978@@ -516,7 +516,7 @@ void drm_unplug_dev(struct drm_device *dev)
34979
34980 drm_device_set_unplugged(dev);
34981
34982- if (dev->open_count == 0) {
34983+ if (local_read(&dev->open_count) == 0) {
34984 drm_put_dev(dev);
34985 }
34986 mutex_unlock(&drm_global_mutex);
34987diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
34988index 004ecdf..db1f6e0 100644
34989--- a/drivers/gpu/drm/i810/i810_dma.c
34990+++ b/drivers/gpu/drm/i810/i810_dma.c
34991@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
34992 dma->buflist[vertex->idx],
34993 vertex->discard, vertex->used);
34994
34995- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
34996- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
34997+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
34998+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
34999 sarea_priv->last_enqueue = dev_priv->counter - 1;
35000 sarea_priv->last_dispatch = (int)hw_status[5];
35001
35002@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
35003 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
35004 mc->last_render);
35005
35006- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35007- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35008+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35009+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35010 sarea_priv->last_enqueue = dev_priv->counter - 1;
35011 sarea_priv->last_dispatch = (int)hw_status[5];
35012
35013diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
35014index 6e0acad..93c8289 100644
35015--- a/drivers/gpu/drm/i810/i810_drv.h
35016+++ b/drivers/gpu/drm/i810/i810_drv.h
35017@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
35018 int page_flipping;
35019
35020 wait_queue_head_t irq_queue;
35021- atomic_t irq_received;
35022- atomic_t irq_emitted;
35023+ atomic_unchecked_t irq_received;
35024+ atomic_unchecked_t irq_emitted;
35025
35026 int front_offset;
35027 } drm_i810_private_t;
35028diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
35029index 261efc8e..27af8a5 100644
35030--- a/drivers/gpu/drm/i915/i915_debugfs.c
35031+++ b/drivers/gpu/drm/i915/i915_debugfs.c
35032@@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
35033 I915_READ(GTIMR));
35034 }
35035 seq_printf(m, "Interrupts received: %d\n",
35036- atomic_read(&dev_priv->irq_received));
35037+ atomic_read_unchecked(&dev_priv->irq_received));
35038 for_each_ring(ring, dev_priv, i) {
35039 if (IS_GEN6(dev) || IS_GEN7(dev)) {
35040 seq_printf(m,
35041diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
35042index 99daa89..84ebd44 100644
35043--- a/drivers/gpu/drm/i915/i915_dma.c
35044+++ b/drivers/gpu/drm/i915/i915_dma.c
35045@@ -1253,7 +1253,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
35046 bool can_switch;
35047
35048 spin_lock(&dev->count_lock);
35049- can_switch = (dev->open_count == 0);
35050+ can_switch = (local_read(&dev->open_count) == 0);
35051 spin_unlock(&dev->count_lock);
35052 return can_switch;
35053 }
35054diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
35055index 7339a4b..445aaba 100644
35056--- a/drivers/gpu/drm/i915/i915_drv.h
35057+++ b/drivers/gpu/drm/i915/i915_drv.h
35058@@ -656,7 +656,7 @@ typedef struct drm_i915_private {
35059 drm_dma_handle_t *status_page_dmah;
35060 struct resource mch_res;
35061
35062- atomic_t irq_received;
35063+ atomic_unchecked_t irq_received;
35064
35065 /* protects the irq masks */
35066 spinlock_t irq_lock;
35067@@ -1102,7 +1102,7 @@ struct drm_i915_gem_object {
35068 * will be page flipped away on the next vblank. When it
35069 * reaches 0, dev_priv->pending_flip_queue will be woken up.
35070 */
35071- atomic_t pending_flip;
35072+ atomic_unchecked_t pending_flip;
35073 };
35074 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
35075
35076@@ -1633,7 +1633,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
35077 struct drm_i915_private *dev_priv, unsigned port);
35078 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
35079 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
35080-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35081+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35082 {
35083 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
35084 }
35085diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35086index 7adf5a7..e24fb51 100644
35087--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35088+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35089@@ -672,7 +672,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
35090 i915_gem_clflush_object(obj);
35091
35092 if (obj->base.pending_write_domain)
35093- flips |= atomic_read(&obj->pending_flip);
35094+ flips |= atomic_read_unchecked(&obj->pending_flip);
35095
35096 flush_domains |= obj->base.write_domain;
35097 }
35098@@ -703,9 +703,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
35099
35100 static int
35101 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
35102- int count)
35103+ unsigned int count)
35104 {
35105- int i;
35106+ unsigned int i;
35107 int relocs_total = 0;
35108 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
35109
35110@@ -1202,7 +1202,7 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
35111 return -ENOMEM;
35112 }
35113 ret = copy_from_user(exec2_list,
35114- (struct drm_i915_relocation_entry __user *)
35115+ (struct drm_i915_gem_exec_object2 __user *)
35116 (uintptr_t) args->buffers_ptr,
35117 sizeof(*exec2_list) * args->buffer_count);
35118 if (ret != 0) {
35119diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
35120index 3c59584..500f2e9 100644
35121--- a/drivers/gpu/drm/i915/i915_ioc32.c
35122+++ b/drivers/gpu/drm/i915/i915_ioc32.c
35123@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
35124 (unsigned long)request);
35125 }
35126
35127-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35128+static drm_ioctl_compat_t i915_compat_ioctls[] = {
35129 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
35130 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
35131 [DRM_I915_GETPARAM] = compat_i915_getparam,
35132@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35133 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35134 {
35135 unsigned int nr = DRM_IOCTL_NR(cmd);
35136- drm_ioctl_compat_t *fn = NULL;
35137 int ret;
35138
35139 if (nr < DRM_COMMAND_BASE)
35140 return drm_compat_ioctl(filp, cmd, arg);
35141
35142- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
35143- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35144-
35145- if (fn != NULL)
35146+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
35147+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35148 ret = (*fn) (filp, cmd, arg);
35149- else
35150+ } else
35151 ret = drm_ioctl(filp, cmd, arg);
35152
35153 return ret;
35154diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
35155index fe84338..a863190 100644
35156--- a/drivers/gpu/drm/i915/i915_irq.c
35157+++ b/drivers/gpu/drm/i915/i915_irq.c
35158@@ -535,7 +535,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
35159 u32 pipe_stats[I915_MAX_PIPES];
35160 bool blc_event;
35161
35162- atomic_inc(&dev_priv->irq_received);
35163+ atomic_inc_unchecked(&dev_priv->irq_received);
35164
35165 while (true) {
35166 iir = I915_READ(VLV_IIR);
35167@@ -688,7 +688,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
35168 irqreturn_t ret = IRQ_NONE;
35169 int i;
35170
35171- atomic_inc(&dev_priv->irq_received);
35172+ atomic_inc_unchecked(&dev_priv->irq_received);
35173
35174 /* disable master interrupt before clearing iir */
35175 de_ier = I915_READ(DEIER);
35176@@ -760,7 +760,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
35177 int ret = IRQ_NONE;
35178 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
35179
35180- atomic_inc(&dev_priv->irq_received);
35181+ atomic_inc_unchecked(&dev_priv->irq_received);
35182
35183 /* disable master interrupt before clearing iir */
35184 de_ier = I915_READ(DEIER);
35185@@ -1787,7 +1787,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
35186 {
35187 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35188
35189- atomic_set(&dev_priv->irq_received, 0);
35190+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35191
35192 I915_WRITE(HWSTAM, 0xeffe);
35193
35194@@ -1813,7 +1813,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
35195 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35196 int pipe;
35197
35198- atomic_set(&dev_priv->irq_received, 0);
35199+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35200
35201 /* VLV magic */
35202 I915_WRITE(VLV_IMR, 0);
35203@@ -2108,7 +2108,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
35204 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35205 int pipe;
35206
35207- atomic_set(&dev_priv->irq_received, 0);
35208+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35209
35210 for_each_pipe(pipe)
35211 I915_WRITE(PIPESTAT(pipe), 0);
35212@@ -2159,7 +2159,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
35213 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35214 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35215
35216- atomic_inc(&dev_priv->irq_received);
35217+ atomic_inc_unchecked(&dev_priv->irq_received);
35218
35219 iir = I915_READ16(IIR);
35220 if (iir == 0)
35221@@ -2244,7 +2244,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
35222 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35223 int pipe;
35224
35225- atomic_set(&dev_priv->irq_received, 0);
35226+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35227
35228 if (I915_HAS_HOTPLUG(dev)) {
35229 I915_WRITE(PORT_HOTPLUG_EN, 0);
35230@@ -2339,7 +2339,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
35231 };
35232 int pipe, ret = IRQ_NONE;
35233
35234- atomic_inc(&dev_priv->irq_received);
35235+ atomic_inc_unchecked(&dev_priv->irq_received);
35236
35237 iir = I915_READ(IIR);
35238 do {
35239@@ -2465,7 +2465,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
35240 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35241 int pipe;
35242
35243- atomic_set(&dev_priv->irq_received, 0);
35244+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35245
35246 I915_WRITE(PORT_HOTPLUG_EN, 0);
35247 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
35248@@ -2572,7 +2572,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
35249 int irq_received;
35250 int ret = IRQ_NONE, pipe;
35251
35252- atomic_inc(&dev_priv->irq_received);
35253+ atomic_inc_unchecked(&dev_priv->irq_received);
35254
35255 iir = I915_READ(IIR);
35256
35257diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
35258index 80aa1fc..85cfce3 100644
35259--- a/drivers/gpu/drm/i915/intel_display.c
35260+++ b/drivers/gpu/drm/i915/intel_display.c
35261@@ -2255,7 +2255,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
35262
35263 wait_event(dev_priv->pending_flip_queue,
35264 atomic_read(&dev_priv->mm.wedged) ||
35265- atomic_read(&obj->pending_flip) == 0);
35266+ atomic_read_unchecked(&obj->pending_flip) == 0);
35267
35268 /* Big Hammer, we also need to ensure that any pending
35269 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
35270@@ -7122,8 +7122,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
35271
35272 obj = work->old_fb_obj;
35273
35274- atomic_clear_mask(1 << intel_crtc->plane,
35275- &obj->pending_flip.counter);
35276+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
35277 wake_up(&dev_priv->pending_flip_queue);
35278
35279 queue_work(dev_priv->wq, &work->work);
35280@@ -7490,7 +7489,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
35281 /* Block clients from rendering to the new back buffer until
35282 * the flip occurs and the object is no longer visible.
35283 */
35284- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35285+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35286 atomic_inc(&intel_crtc->unpin_work_count);
35287
35288 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
35289@@ -7507,7 +7506,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
35290
35291 cleanup_pending:
35292 atomic_dec(&intel_crtc->unpin_work_count);
35293- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35294+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35295 drm_gem_object_unreference(&work->old_fb_obj->base);
35296 drm_gem_object_unreference(&obj->base);
35297 mutex_unlock(&dev->struct_mutex);
35298@@ -8849,13 +8848,13 @@ struct intel_quirk {
35299 int subsystem_vendor;
35300 int subsystem_device;
35301 void (*hook)(struct drm_device *dev);
35302-};
35303+} __do_const;
35304
35305 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
35306 struct intel_dmi_quirk {
35307 void (*hook)(struct drm_device *dev);
35308 const struct dmi_system_id (*dmi_id_list)[];
35309-};
35310+} __do_const;
35311
35312 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35313 {
35314@@ -8863,18 +8862,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35315 return 1;
35316 }
35317
35318+static const struct dmi_system_id intel_dmi_quirks_table[] = {
35319+ {
35320+ .callback = intel_dmi_reverse_brightness,
35321+ .ident = "NCR Corporation",
35322+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35323+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
35324+ },
35325+ },
35326+ { } /* terminating entry */
35327+};
35328+
35329 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35330 {
35331- .dmi_id_list = &(const struct dmi_system_id[]) {
35332- {
35333- .callback = intel_dmi_reverse_brightness,
35334- .ident = "NCR Corporation",
35335- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35336- DMI_MATCH(DMI_PRODUCT_NAME, ""),
35337- },
35338- },
35339- { } /* terminating entry */
35340- },
35341+ .dmi_id_list = &intel_dmi_quirks_table,
35342 .hook = quirk_invert_brightness,
35343 },
35344 };
35345diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
35346index 54558a0..2d97005 100644
35347--- a/drivers/gpu/drm/mga/mga_drv.h
35348+++ b/drivers/gpu/drm/mga/mga_drv.h
35349@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
35350 u32 clear_cmd;
35351 u32 maccess;
35352
35353- atomic_t vbl_received; /**< Number of vblanks received. */
35354+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
35355 wait_queue_head_t fence_queue;
35356- atomic_t last_fence_retired;
35357+ atomic_unchecked_t last_fence_retired;
35358 u32 next_fence_to_post;
35359
35360 unsigned int fb_cpp;
35361diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
35362index 709e90d..89a1c0d 100644
35363--- a/drivers/gpu/drm/mga/mga_ioc32.c
35364+++ b/drivers/gpu/drm/mga/mga_ioc32.c
35365@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
35366 return 0;
35367 }
35368
35369-drm_ioctl_compat_t *mga_compat_ioctls[] = {
35370+drm_ioctl_compat_t mga_compat_ioctls[] = {
35371 [DRM_MGA_INIT] = compat_mga_init,
35372 [DRM_MGA_GETPARAM] = compat_mga_getparam,
35373 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
35374@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
35375 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35376 {
35377 unsigned int nr = DRM_IOCTL_NR(cmd);
35378- drm_ioctl_compat_t *fn = NULL;
35379 int ret;
35380
35381 if (nr < DRM_COMMAND_BASE)
35382 return drm_compat_ioctl(filp, cmd, arg);
35383
35384- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
35385- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35386-
35387- if (fn != NULL)
35388+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
35389+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35390 ret = (*fn) (filp, cmd, arg);
35391- else
35392+ } else
35393 ret = drm_ioctl(filp, cmd, arg);
35394
35395 return ret;
35396diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
35397index 598c281..60d590e 100644
35398--- a/drivers/gpu/drm/mga/mga_irq.c
35399+++ b/drivers/gpu/drm/mga/mga_irq.c
35400@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
35401 if (crtc != 0)
35402 return 0;
35403
35404- return atomic_read(&dev_priv->vbl_received);
35405+ return atomic_read_unchecked(&dev_priv->vbl_received);
35406 }
35407
35408
35409@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35410 /* VBLANK interrupt */
35411 if (status & MGA_VLINEPEN) {
35412 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
35413- atomic_inc(&dev_priv->vbl_received);
35414+ atomic_inc_unchecked(&dev_priv->vbl_received);
35415 drm_handle_vblank(dev, 0);
35416 handled = 1;
35417 }
35418@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35419 if ((prim_start & ~0x03) != (prim_end & ~0x03))
35420 MGA_WRITE(MGA_PRIMEND, prim_end);
35421
35422- atomic_inc(&dev_priv->last_fence_retired);
35423+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
35424 DRM_WAKEUP(&dev_priv->fence_queue);
35425 handled = 1;
35426 }
35427@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
35428 * using fences.
35429 */
35430 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
35431- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
35432+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
35433 - *sequence) <= (1 << 23)));
35434
35435 *sequence = cur_fence;
35436diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
35437index 865eddf..62c4cc3 100644
35438--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
35439+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
35440@@ -1015,7 +1015,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
35441 struct bit_table {
35442 const char id;
35443 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
35444-};
35445+} __no_const;
35446
35447 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
35448
35449diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
35450index aa89eb9..d45d38b 100644
35451--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
35452+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
35453@@ -80,7 +80,7 @@ struct nouveau_drm {
35454 struct drm_global_reference mem_global_ref;
35455 struct ttm_bo_global_ref bo_global_ref;
35456 struct ttm_bo_device bdev;
35457- atomic_t validate_sequence;
35458+ atomic_unchecked_t validate_sequence;
35459 int (*move)(struct nouveau_channel *,
35460 struct ttm_buffer_object *,
35461 struct ttm_mem_reg *, struct ttm_mem_reg *);
35462diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
35463index cdb83ac..27f0a16 100644
35464--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
35465+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
35466@@ -43,7 +43,7 @@ struct nouveau_fence_priv {
35467 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
35468 struct nouveau_channel *);
35469 u32 (*read)(struct nouveau_channel *);
35470-};
35471+} __no_const;
35472
35473 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
35474
35475diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35476index 8bf695c..9fbc90a 100644
35477--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35478+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35479@@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35480 int trycnt = 0;
35481 int ret, i;
35482
35483- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35484+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35485 retry:
35486 if (++trycnt > 100000) {
35487 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
35488diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35489index 08214bc..9208577 100644
35490--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35491+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35492@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
35493 unsigned long arg)
35494 {
35495 unsigned int nr = DRM_IOCTL_NR(cmd);
35496- drm_ioctl_compat_t *fn = NULL;
35497+ drm_ioctl_compat_t fn = NULL;
35498 int ret;
35499
35500 if (nr < DRM_COMMAND_BASE)
35501diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
35502index 25d3495..d81aaf6 100644
35503--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
35504+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
35505@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
35506 bool can_switch;
35507
35508 spin_lock(&dev->count_lock);
35509- can_switch = (dev->open_count == 0);
35510+ can_switch = (local_read(&dev->open_count) == 0);
35511 spin_unlock(&dev->count_lock);
35512 return can_switch;
35513 }
35514diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
35515index d4660cf..70dbe65 100644
35516--- a/drivers/gpu/drm/r128/r128_cce.c
35517+++ b/drivers/gpu/drm/r128/r128_cce.c
35518@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
35519
35520 /* GH: Simple idle check.
35521 */
35522- atomic_set(&dev_priv->idle_count, 0);
35523+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35524
35525 /* We don't support anything other than bus-mastering ring mode,
35526 * but the ring can be in either AGP or PCI space for the ring
35527diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
35528index 930c71b..499aded 100644
35529--- a/drivers/gpu/drm/r128/r128_drv.h
35530+++ b/drivers/gpu/drm/r128/r128_drv.h
35531@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
35532 int is_pci;
35533 unsigned long cce_buffers_offset;
35534
35535- atomic_t idle_count;
35536+ atomic_unchecked_t idle_count;
35537
35538 int page_flipping;
35539 int current_page;
35540 u32 crtc_offset;
35541 u32 crtc_offset_cntl;
35542
35543- atomic_t vbl_received;
35544+ atomic_unchecked_t vbl_received;
35545
35546 u32 color_fmt;
35547 unsigned int front_offset;
35548diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
35549index a954c54..9cc595c 100644
35550--- a/drivers/gpu/drm/r128/r128_ioc32.c
35551+++ b/drivers/gpu/drm/r128/r128_ioc32.c
35552@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
35553 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
35554 }
35555
35556-drm_ioctl_compat_t *r128_compat_ioctls[] = {
35557+drm_ioctl_compat_t r128_compat_ioctls[] = {
35558 [DRM_R128_INIT] = compat_r128_init,
35559 [DRM_R128_DEPTH] = compat_r128_depth,
35560 [DRM_R128_STIPPLE] = compat_r128_stipple,
35561@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
35562 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35563 {
35564 unsigned int nr = DRM_IOCTL_NR(cmd);
35565- drm_ioctl_compat_t *fn = NULL;
35566 int ret;
35567
35568 if (nr < DRM_COMMAND_BASE)
35569 return drm_compat_ioctl(filp, cmd, arg);
35570
35571- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
35572- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35573-
35574- if (fn != NULL)
35575+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
35576+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35577 ret = (*fn) (filp, cmd, arg);
35578- else
35579+ } else
35580 ret = drm_ioctl(filp, cmd, arg);
35581
35582 return ret;
35583diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
35584index 2ea4f09..d391371 100644
35585--- a/drivers/gpu/drm/r128/r128_irq.c
35586+++ b/drivers/gpu/drm/r128/r128_irq.c
35587@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
35588 if (crtc != 0)
35589 return 0;
35590
35591- return atomic_read(&dev_priv->vbl_received);
35592+ return atomic_read_unchecked(&dev_priv->vbl_received);
35593 }
35594
35595 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35596@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35597 /* VBLANK interrupt */
35598 if (status & R128_CRTC_VBLANK_INT) {
35599 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
35600- atomic_inc(&dev_priv->vbl_received);
35601+ atomic_inc_unchecked(&dev_priv->vbl_received);
35602 drm_handle_vblank(dev, 0);
35603 return IRQ_HANDLED;
35604 }
35605diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
35606index 19bb7e6..de7e2a2 100644
35607--- a/drivers/gpu/drm/r128/r128_state.c
35608+++ b/drivers/gpu/drm/r128/r128_state.c
35609@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
35610
35611 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
35612 {
35613- if (atomic_read(&dev_priv->idle_count) == 0)
35614+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
35615 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
35616 else
35617- atomic_set(&dev_priv->idle_count, 0);
35618+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35619 }
35620
35621 #endif
35622diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
35623index 5a82b6b..9e69c73 100644
35624--- a/drivers/gpu/drm/radeon/mkregtable.c
35625+++ b/drivers/gpu/drm/radeon/mkregtable.c
35626@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
35627 regex_t mask_rex;
35628 regmatch_t match[4];
35629 char buf[1024];
35630- size_t end;
35631+ long end;
35632 int len;
35633 int done = 0;
35634 int r;
35635 unsigned o;
35636 struct offset *offset;
35637 char last_reg_s[10];
35638- int last_reg;
35639+ unsigned long last_reg;
35640
35641 if (regcomp
35642 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
35643diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
35644index 0d6562b..a154330 100644
35645--- a/drivers/gpu/drm/radeon/radeon_device.c
35646+++ b/drivers/gpu/drm/radeon/radeon_device.c
35647@@ -969,7 +969,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
35648 bool can_switch;
35649
35650 spin_lock(&dev->count_lock);
35651- can_switch = (dev->open_count == 0);
35652+ can_switch = (local_read(&dev->open_count) == 0);
35653 spin_unlock(&dev->count_lock);
35654 return can_switch;
35655 }
35656diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
35657index e7fdf16..f4f6490 100644
35658--- a/drivers/gpu/drm/radeon/radeon_drv.h
35659+++ b/drivers/gpu/drm/radeon/radeon_drv.h
35660@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
35661
35662 /* SW interrupt */
35663 wait_queue_head_t swi_queue;
35664- atomic_t swi_emitted;
35665+ atomic_unchecked_t swi_emitted;
35666 int vblank_crtc;
35667 uint32_t irq_enable_reg;
35668 uint32_t r500_disp_irq_reg;
35669diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
35670index c180df8..5fd8186 100644
35671--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
35672+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
35673@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35674 request = compat_alloc_user_space(sizeof(*request));
35675 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
35676 || __put_user(req32.param, &request->param)
35677- || __put_user((void __user *)(unsigned long)req32.value,
35678+ || __put_user((unsigned long)req32.value,
35679 &request->value))
35680 return -EFAULT;
35681
35682@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35683 #define compat_radeon_cp_setparam NULL
35684 #endif /* X86_64 || IA64 */
35685
35686-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35687+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
35688 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
35689 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
35690 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
35691@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35692 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35693 {
35694 unsigned int nr = DRM_IOCTL_NR(cmd);
35695- drm_ioctl_compat_t *fn = NULL;
35696 int ret;
35697
35698 if (nr < DRM_COMMAND_BASE)
35699 return drm_compat_ioctl(filp, cmd, arg);
35700
35701- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
35702- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35703-
35704- if (fn != NULL)
35705+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
35706+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35707 ret = (*fn) (filp, cmd, arg);
35708- else
35709+ } else
35710 ret = drm_ioctl(filp, cmd, arg);
35711
35712 return ret;
35713diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
35714index e771033..a0bc6b3 100644
35715--- a/drivers/gpu/drm/radeon/radeon_irq.c
35716+++ b/drivers/gpu/drm/radeon/radeon_irq.c
35717@@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
35718 unsigned int ret;
35719 RING_LOCALS;
35720
35721- atomic_inc(&dev_priv->swi_emitted);
35722- ret = atomic_read(&dev_priv->swi_emitted);
35723+ atomic_inc_unchecked(&dev_priv->swi_emitted);
35724+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
35725
35726 BEGIN_RING(4);
35727 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
35728@@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
35729 drm_radeon_private_t *dev_priv =
35730 (drm_radeon_private_t *) dev->dev_private;
35731
35732- atomic_set(&dev_priv->swi_emitted, 0);
35733+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
35734 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
35735
35736 dev->max_vblank_count = 0x001fffff;
35737diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
35738index 8e9057b..af6dacb 100644
35739--- a/drivers/gpu/drm/radeon/radeon_state.c
35740+++ b/drivers/gpu/drm/radeon/radeon_state.c
35741@@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
35742 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
35743 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
35744
35745- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35746+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35747 sarea_priv->nbox * sizeof(depth_boxes[0])))
35748 return -EFAULT;
35749
35750@@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
35751 {
35752 drm_radeon_private_t *dev_priv = dev->dev_private;
35753 drm_radeon_getparam_t *param = data;
35754- int value;
35755+ int value = 0;
35756
35757 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
35758
35759diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
35760index 93f760e..8088227 100644
35761--- a/drivers/gpu/drm/radeon/radeon_ttm.c
35762+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
35763@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
35764 man->size = size >> PAGE_SHIFT;
35765 }
35766
35767-static struct vm_operations_struct radeon_ttm_vm_ops;
35768+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
35769 static const struct vm_operations_struct *ttm_vm_ops = NULL;
35770
35771 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
35772@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
35773 }
35774 if (unlikely(ttm_vm_ops == NULL)) {
35775 ttm_vm_ops = vma->vm_ops;
35776+ pax_open_kernel();
35777 radeon_ttm_vm_ops = *ttm_vm_ops;
35778 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
35779+ pax_close_kernel();
35780 }
35781 vma->vm_ops = &radeon_ttm_vm_ops;
35782 return 0;
35783@@ -862,28 +864,33 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
35784 sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
35785 else
35786 sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
35787- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35788- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35789- radeon_mem_types_list[i].driver_features = 0;
35790+ pax_open_kernel();
35791+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35792+ *(void **)&radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35793+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35794 if (i == 0)
35795- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35796+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35797 else
35798- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35799-
35800+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35801+ pax_close_kernel();
35802 }
35803 /* Add ttm page pool to debugfs */
35804 sprintf(radeon_mem_types_names[i], "ttm_page_pool");
35805- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35806- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35807- radeon_mem_types_list[i].driver_features = 0;
35808- radeon_mem_types_list[i++].data = NULL;
35809+ pax_open_kernel();
35810+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35811+ *(void **)&radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35812+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35813+ *(void **)&radeon_mem_types_list[i++].data = NULL;
35814+ pax_close_kernel();
35815 #ifdef CONFIG_SWIOTLB
35816 if (swiotlb_nr_tbl()) {
35817 sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
35818- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35819- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35820- radeon_mem_types_list[i].driver_features = 0;
35821- radeon_mem_types_list[i++].data = NULL;
35822+ pax_open_kernel();
35823+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35824+ *(void **)&radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35825+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35826+ *(void **)&radeon_mem_types_list[i++].data = NULL;
35827+ pax_close_kernel();
35828 }
35829 #endif
35830 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
35831diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
35832index 5706d2a..17aedaa 100644
35833--- a/drivers/gpu/drm/radeon/rs690.c
35834+++ b/drivers/gpu/drm/radeon/rs690.c
35835@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
35836 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
35837 rdev->pm.sideport_bandwidth.full)
35838 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
35839- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
35840+ read_delay_latency.full = dfixed_const(800 * 1000);
35841 read_delay_latency.full = dfixed_div(read_delay_latency,
35842 rdev->pm.igp_sideport_mclk);
35843+ a.full = dfixed_const(370);
35844+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
35845 } else {
35846 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
35847 rdev->pm.k8_bandwidth.full)
35848diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35849index bd2a3b4..122d9ad 100644
35850--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
35851+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35852@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
35853 static int ttm_pool_mm_shrink(struct shrinker *shrink,
35854 struct shrink_control *sc)
35855 {
35856- static atomic_t start_pool = ATOMIC_INIT(0);
35857+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
35858 unsigned i;
35859- unsigned pool_offset = atomic_add_return(1, &start_pool);
35860+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
35861 struct ttm_page_pool *pool;
35862 int shrink_pages = sc->nr_to_scan;
35863
35864diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
35865index 1eb060c..188b1fc 100644
35866--- a/drivers/gpu/drm/udl/udl_fb.c
35867+++ b/drivers/gpu/drm/udl/udl_fb.c
35868@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
35869 fb_deferred_io_cleanup(info);
35870 kfree(info->fbdefio);
35871 info->fbdefio = NULL;
35872- info->fbops->fb_mmap = udl_fb_mmap;
35873 }
35874
35875 pr_warn("released /dev/fb%d user=%d count=%d\n",
35876diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
35877index 893a650..6190d3b 100644
35878--- a/drivers/gpu/drm/via/via_drv.h
35879+++ b/drivers/gpu/drm/via/via_drv.h
35880@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
35881 typedef uint32_t maskarray_t[5];
35882
35883 typedef struct drm_via_irq {
35884- atomic_t irq_received;
35885+ atomic_unchecked_t irq_received;
35886 uint32_t pending_mask;
35887 uint32_t enable_mask;
35888 wait_queue_head_t irq_queue;
35889@@ -75,7 +75,7 @@ typedef struct drm_via_private {
35890 struct timeval last_vblank;
35891 int last_vblank_valid;
35892 unsigned usec_per_vblank;
35893- atomic_t vbl_received;
35894+ atomic_unchecked_t vbl_received;
35895 drm_via_state_t hc_state;
35896 char pci_buf[VIA_PCI_BUF_SIZE];
35897 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
35898diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
35899index ac98964..5dbf512 100644
35900--- a/drivers/gpu/drm/via/via_irq.c
35901+++ b/drivers/gpu/drm/via/via_irq.c
35902@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
35903 if (crtc != 0)
35904 return 0;
35905
35906- return atomic_read(&dev_priv->vbl_received);
35907+ return atomic_read_unchecked(&dev_priv->vbl_received);
35908 }
35909
35910 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35911@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35912
35913 status = VIA_READ(VIA_REG_INTERRUPT);
35914 if (status & VIA_IRQ_VBLANK_PENDING) {
35915- atomic_inc(&dev_priv->vbl_received);
35916- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
35917+ atomic_inc_unchecked(&dev_priv->vbl_received);
35918+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
35919 do_gettimeofday(&cur_vblank);
35920 if (dev_priv->last_vblank_valid) {
35921 dev_priv->usec_per_vblank =
35922@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35923 dev_priv->last_vblank = cur_vblank;
35924 dev_priv->last_vblank_valid = 1;
35925 }
35926- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
35927+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
35928 DRM_DEBUG("US per vblank is: %u\n",
35929 dev_priv->usec_per_vblank);
35930 }
35931@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35932
35933 for (i = 0; i < dev_priv->num_irqs; ++i) {
35934 if (status & cur_irq->pending_mask) {
35935- atomic_inc(&cur_irq->irq_received);
35936+ atomic_inc_unchecked(&cur_irq->irq_received);
35937 DRM_WAKEUP(&cur_irq->irq_queue);
35938 handled = 1;
35939 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
35940@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
35941 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
35942 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
35943 masks[irq][4]));
35944- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
35945+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
35946 } else {
35947 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
35948 (((cur_irq_sequence =
35949- atomic_read(&cur_irq->irq_received)) -
35950+ atomic_read_unchecked(&cur_irq->irq_received)) -
35951 *sequence) <= (1 << 23)));
35952 }
35953 *sequence = cur_irq_sequence;
35954@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
35955 }
35956
35957 for (i = 0; i < dev_priv->num_irqs; ++i) {
35958- atomic_set(&cur_irq->irq_received, 0);
35959+ atomic_set_unchecked(&cur_irq->irq_received, 0);
35960 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
35961 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
35962 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
35963@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
35964 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
35965 case VIA_IRQ_RELATIVE:
35966 irqwait->request.sequence +=
35967- atomic_read(&cur_irq->irq_received);
35968+ atomic_read_unchecked(&cur_irq->irq_received);
35969 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
35970 case VIA_IRQ_ABSOLUTE:
35971 break;
35972diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35973index 13aeda7..4a952d1 100644
35974--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35975+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35976@@ -290,7 +290,7 @@ struct vmw_private {
35977 * Fencing and IRQs.
35978 */
35979
35980- atomic_t marker_seq;
35981+ atomic_unchecked_t marker_seq;
35982 wait_queue_head_t fence_queue;
35983 wait_queue_head_t fifo_queue;
35984 int fence_queue_waiters; /* Protected by hw_mutex */
35985diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35986index 3eb1486..0a47ee9 100644
35987--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35988+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35989@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
35990 (unsigned int) min,
35991 (unsigned int) fifo->capabilities);
35992
35993- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
35994+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
35995 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
35996 vmw_marker_queue_init(&fifo->marker_queue);
35997 return vmw_fifo_send_fence(dev_priv, &dummy);
35998@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
35999 if (reserveable)
36000 iowrite32(bytes, fifo_mem +
36001 SVGA_FIFO_RESERVED);
36002- return fifo_mem + (next_cmd >> 2);
36003+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
36004 } else {
36005 need_bounce = true;
36006 }
36007@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36008
36009 fm = vmw_fifo_reserve(dev_priv, bytes);
36010 if (unlikely(fm == NULL)) {
36011- *seqno = atomic_read(&dev_priv->marker_seq);
36012+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36013 ret = -ENOMEM;
36014 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
36015 false, 3*HZ);
36016@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36017 }
36018
36019 do {
36020- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
36021+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
36022 } while (*seqno == 0);
36023
36024 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
36025diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36026index 4640adb..e1384ed 100644
36027--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36028+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36029@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
36030 * emitted. Then the fence is stale and signaled.
36031 */
36032
36033- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
36034+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
36035 > VMW_FENCE_WRAP);
36036
36037 return ret;
36038@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
36039
36040 if (fifo_idle)
36041 down_read(&fifo_state->rwsem);
36042- signal_seq = atomic_read(&dev_priv->marker_seq);
36043+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
36044 ret = 0;
36045
36046 for (;;) {
36047diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36048index 8a8725c..afed796 100644
36049--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36050+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36051@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
36052 while (!vmw_lag_lt(queue, us)) {
36053 spin_lock(&queue->lock);
36054 if (list_empty(&queue->head))
36055- seqno = atomic_read(&dev_priv->marker_seq);
36056+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36057 else {
36058 marker = list_first_entry(&queue->head,
36059 struct vmw_marker, head);
36060diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
36061index ceb3040..6160c5c 100644
36062--- a/drivers/hid/hid-core.c
36063+++ b/drivers/hid/hid-core.c
36064@@ -2242,7 +2242,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
36065
36066 int hid_add_device(struct hid_device *hdev)
36067 {
36068- static atomic_t id = ATOMIC_INIT(0);
36069+ static atomic_unchecked_t id = ATOMIC_INIT(0);
36070 int ret;
36071
36072 if (WARN_ON(hdev->status & HID_STAT_ADDED))
36073@@ -2276,7 +2276,7 @@ int hid_add_device(struct hid_device *hdev)
36074 /* XXX hack, any other cleaner solution after the driver core
36075 * is converted to allow more than 20 bytes as the device name? */
36076 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
36077- hdev->vendor, hdev->product, atomic_inc_return(&id));
36078+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
36079
36080 hid_debug_register(hdev, dev_name(&hdev->dev));
36081 ret = device_add(&hdev->dev);
36082diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
36083index eec3291..8ed706b 100644
36084--- a/drivers/hid/hid-wiimote-debug.c
36085+++ b/drivers/hid/hid-wiimote-debug.c
36086@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
36087 else if (size == 0)
36088 return -EIO;
36089
36090- if (copy_to_user(u, buf, size))
36091+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
36092 return -EFAULT;
36093
36094 *off += size;
36095diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
36096index 773a2f2..7ce08bc 100644
36097--- a/drivers/hv/channel.c
36098+++ b/drivers/hv/channel.c
36099@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
36100 int ret = 0;
36101 int t;
36102
36103- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
36104- atomic_inc(&vmbus_connection.next_gpadl_handle);
36105+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
36106+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
36107
36108 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
36109 if (ret)
36110diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
36111index 3648f8f..30ef30d 100644
36112--- a/drivers/hv/hv.c
36113+++ b/drivers/hv/hv.c
36114@@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
36115 u64 output_address = (output) ? virt_to_phys(output) : 0;
36116 u32 output_address_hi = output_address >> 32;
36117 u32 output_address_lo = output_address & 0xFFFFFFFF;
36118- void *hypercall_page = hv_context.hypercall_page;
36119+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
36120
36121 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
36122 "=a"(hv_status_lo) : "d" (control_hi),
36123diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
36124index d8d1fad..b91caf7 100644
36125--- a/drivers/hv/hyperv_vmbus.h
36126+++ b/drivers/hv/hyperv_vmbus.h
36127@@ -594,7 +594,7 @@ enum vmbus_connect_state {
36128 struct vmbus_connection {
36129 enum vmbus_connect_state conn_state;
36130
36131- atomic_t next_gpadl_handle;
36132+ atomic_unchecked_t next_gpadl_handle;
36133
36134 /*
36135 * Represents channel interrupts. Each bit position represents a
36136diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
36137index 8e1a9ec..4687821 100644
36138--- a/drivers/hv/vmbus_drv.c
36139+++ b/drivers/hv/vmbus_drv.c
36140@@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
36141 {
36142 int ret = 0;
36143
36144- static atomic_t device_num = ATOMIC_INIT(0);
36145+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
36146
36147 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
36148- atomic_inc_return(&device_num));
36149+ atomic_inc_return_unchecked(&device_num));
36150
36151 child_device_obj->device.bus = &hv_bus;
36152 child_device_obj->device.parent = &hv_acpi_dev->dev;
36153diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
36154index 1672e2a..4a6297c 100644
36155--- a/drivers/hwmon/acpi_power_meter.c
36156+++ b/drivers/hwmon/acpi_power_meter.c
36157@@ -117,7 +117,7 @@ struct sensor_template {
36158 struct device_attribute *devattr,
36159 const char *buf, size_t count);
36160 int index;
36161-};
36162+} __do_const;
36163
36164 /* Averaging interval */
36165 static int update_avg_interval(struct acpi_power_meter_resource *resource)
36166@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
36167 struct sensor_template *attrs)
36168 {
36169 struct device *dev = &resource->acpi_dev->dev;
36170- struct sensor_device_attribute *sensors =
36171+ sensor_device_attribute_no_const *sensors =
36172 &resource->sensors[resource->num_sensors];
36173 int res = 0;
36174
36175diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
36176index b41baff..4953e4d 100644
36177--- a/drivers/hwmon/applesmc.c
36178+++ b/drivers/hwmon/applesmc.c
36179@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
36180 {
36181 struct applesmc_node_group *grp;
36182 struct applesmc_dev_attr *node;
36183- struct attribute *attr;
36184+ attribute_no_const *attr;
36185 int ret, i;
36186
36187 for (grp = groups; grp->format; grp++) {
36188diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
36189index 56dbcfb..9874bf1 100644
36190--- a/drivers/hwmon/asus_atk0110.c
36191+++ b/drivers/hwmon/asus_atk0110.c
36192@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
36193 struct atk_sensor_data {
36194 struct list_head list;
36195 struct atk_data *data;
36196- struct device_attribute label_attr;
36197- struct device_attribute input_attr;
36198- struct device_attribute limit1_attr;
36199- struct device_attribute limit2_attr;
36200+ device_attribute_no_const label_attr;
36201+ device_attribute_no_const input_attr;
36202+ device_attribute_no_const limit1_attr;
36203+ device_attribute_no_const limit2_attr;
36204 char label_attr_name[ATTR_NAME_SIZE];
36205 char input_attr_name[ATTR_NAME_SIZE];
36206 char limit1_attr_name[ATTR_NAME_SIZE];
36207@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
36208 static struct device_attribute atk_name_attr =
36209 __ATTR(name, 0444, atk_name_show, NULL);
36210
36211-static void atk_init_attribute(struct device_attribute *attr, char *name,
36212+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
36213 sysfs_show_func show)
36214 {
36215 sysfs_attr_init(&attr->attr);
36216diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
36217index d64923d..72591e8 100644
36218--- a/drivers/hwmon/coretemp.c
36219+++ b/drivers/hwmon/coretemp.c
36220@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
36221 return NOTIFY_OK;
36222 }
36223
36224-static struct notifier_block coretemp_cpu_notifier __refdata = {
36225+static struct notifier_block coretemp_cpu_notifier = {
36226 .notifier_call = coretemp_cpu_callback,
36227 };
36228
36229diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
36230index a14f634..2916ee2 100644
36231--- a/drivers/hwmon/ibmaem.c
36232+++ b/drivers/hwmon/ibmaem.c
36233@@ -925,7 +925,7 @@ static int aem_register_sensors(struct aem_data *data,
36234 struct aem_rw_sensor_template *rw)
36235 {
36236 struct device *dev = &data->pdev->dev;
36237- struct sensor_device_attribute *sensors = data->sensors;
36238+ sensor_device_attribute_no_const *sensors = data->sensors;
36239 int err;
36240
36241 /* Set up read-only sensors */
36242diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
36243index 7d19b1b..8fdaaac 100644
36244--- a/drivers/hwmon/pmbus/pmbus_core.c
36245+++ b/drivers/hwmon/pmbus/pmbus_core.c
36246@@ -811,7 +811,7 @@ static ssize_t pmbus_show_label(struct device *dev,
36247
36248 #define PMBUS_ADD_ATTR(data, _name, _idx, _mode, _type, _show, _set) \
36249 do { \
36250- struct sensor_device_attribute *a \
36251+ sensor_device_attribute_no_const *a \
36252 = &data->_type##s[data->num_##_type##s].attribute; \
36253 BUG_ON(data->num_attributes >= data->max_attributes); \
36254 sysfs_attr_init(&a->dev_attr.attr); \
36255diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
36256index 8047fed..1e956f0 100644
36257--- a/drivers/hwmon/sht15.c
36258+++ b/drivers/hwmon/sht15.c
36259@@ -169,7 +169,7 @@ struct sht15_data {
36260 int supply_uV;
36261 bool supply_uV_valid;
36262 struct work_struct update_supply_work;
36263- atomic_t interrupt_handled;
36264+ atomic_unchecked_t interrupt_handled;
36265 };
36266
36267 /**
36268@@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
36269 return ret;
36270
36271 gpio_direction_input(data->pdata->gpio_data);
36272- atomic_set(&data->interrupt_handled, 0);
36273+ atomic_set_unchecked(&data->interrupt_handled, 0);
36274
36275 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36276 if (gpio_get_value(data->pdata->gpio_data) == 0) {
36277 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
36278 /* Only relevant if the interrupt hasn't occurred. */
36279- if (!atomic_read(&data->interrupt_handled))
36280+ if (!atomic_read_unchecked(&data->interrupt_handled))
36281 schedule_work(&data->read_work);
36282 }
36283 ret = wait_event_timeout(data->wait_queue,
36284@@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
36285
36286 /* First disable the interrupt */
36287 disable_irq_nosync(irq);
36288- atomic_inc(&data->interrupt_handled);
36289+ atomic_inc_unchecked(&data->interrupt_handled);
36290 /* Then schedule a reading work struct */
36291 if (data->state != SHT15_READING_NOTHING)
36292 schedule_work(&data->read_work);
36293@@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
36294 * If not, then start the interrupt again - care here as could
36295 * have gone low in meantime so verify it hasn't!
36296 */
36297- atomic_set(&data->interrupt_handled, 0);
36298+ atomic_set_unchecked(&data->interrupt_handled, 0);
36299 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36300 /* If still not occurred or another handler was scheduled */
36301 if (gpio_get_value(data->pdata->gpio_data)
36302- || atomic_read(&data->interrupt_handled))
36303+ || atomic_read_unchecked(&data->interrupt_handled))
36304 return;
36305 }
36306
36307diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
36308index 76f157b..9c0db1b 100644
36309--- a/drivers/hwmon/via-cputemp.c
36310+++ b/drivers/hwmon/via-cputemp.c
36311@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
36312 return NOTIFY_OK;
36313 }
36314
36315-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
36316+static struct notifier_block via_cputemp_cpu_notifier = {
36317 .notifier_call = via_cputemp_cpu_callback,
36318 };
36319
36320diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
36321index 378fcb5..5e91fa8 100644
36322--- a/drivers/i2c/busses/i2c-amd756-s4882.c
36323+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
36324@@ -43,7 +43,7 @@
36325 extern struct i2c_adapter amd756_smbus;
36326
36327 static struct i2c_adapter *s4882_adapter;
36328-static struct i2c_algorithm *s4882_algo;
36329+static i2c_algorithm_no_const *s4882_algo;
36330
36331 /* Wrapper access functions for multiplexed SMBus */
36332 static DEFINE_MUTEX(amd756_lock);
36333diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
36334index 29015eb..af2d8e9 100644
36335--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
36336+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
36337@@ -41,7 +41,7 @@
36338 extern struct i2c_adapter *nforce2_smbus;
36339
36340 static struct i2c_adapter *s4985_adapter;
36341-static struct i2c_algorithm *s4985_algo;
36342+static i2c_algorithm_no_const *s4985_algo;
36343
36344 /* Wrapper access functions for multiplexed SMBus */
36345 static DEFINE_MUTEX(nforce2_lock);
36346diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
36347index 8126824..55a2798 100644
36348--- a/drivers/ide/ide-cd.c
36349+++ b/drivers/ide/ide-cd.c
36350@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
36351 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
36352 if ((unsigned long)buf & alignment
36353 || blk_rq_bytes(rq) & q->dma_pad_mask
36354- || object_is_on_stack(buf))
36355+ || object_starts_on_stack(buf))
36356 drive->dma = 0;
36357 }
36358 }
36359diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
36360index 8848f16..f8e6dd8 100644
36361--- a/drivers/iio/industrialio-core.c
36362+++ b/drivers/iio/industrialio-core.c
36363@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
36364 }
36365
36366 static
36367-int __iio_device_attr_init(struct device_attribute *dev_attr,
36368+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
36369 const char *postfix,
36370 struct iio_chan_spec const *chan,
36371 ssize_t (*readfunc)(struct device *dev,
36372diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
36373index 394fea2..c833880 100644
36374--- a/drivers/infiniband/core/cm.c
36375+++ b/drivers/infiniband/core/cm.c
36376@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
36377
36378 struct cm_counter_group {
36379 struct kobject obj;
36380- atomic_long_t counter[CM_ATTR_COUNT];
36381+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
36382 };
36383
36384 struct cm_counter_attribute {
36385@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
36386 struct ib_mad_send_buf *msg = NULL;
36387 int ret;
36388
36389- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36390+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36391 counter[CM_REQ_COUNTER]);
36392
36393 /* Quick state check to discard duplicate REQs. */
36394@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
36395 if (!cm_id_priv)
36396 return;
36397
36398- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36399+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36400 counter[CM_REP_COUNTER]);
36401 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
36402 if (ret)
36403@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
36404 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
36405 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
36406 spin_unlock_irq(&cm_id_priv->lock);
36407- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36408+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36409 counter[CM_RTU_COUNTER]);
36410 goto out;
36411 }
36412@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
36413 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
36414 dreq_msg->local_comm_id);
36415 if (!cm_id_priv) {
36416- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36417+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36418 counter[CM_DREQ_COUNTER]);
36419 cm_issue_drep(work->port, work->mad_recv_wc);
36420 return -EINVAL;
36421@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
36422 case IB_CM_MRA_REP_RCVD:
36423 break;
36424 case IB_CM_TIMEWAIT:
36425- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36426+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36427 counter[CM_DREQ_COUNTER]);
36428 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36429 goto unlock;
36430@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
36431 cm_free_msg(msg);
36432 goto deref;
36433 case IB_CM_DREQ_RCVD:
36434- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36435+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36436 counter[CM_DREQ_COUNTER]);
36437 goto unlock;
36438 default:
36439@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
36440 ib_modify_mad(cm_id_priv->av.port->mad_agent,
36441 cm_id_priv->msg, timeout)) {
36442 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
36443- atomic_long_inc(&work->port->
36444+ atomic_long_inc_unchecked(&work->port->
36445 counter_group[CM_RECV_DUPLICATES].
36446 counter[CM_MRA_COUNTER]);
36447 goto out;
36448@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
36449 break;
36450 case IB_CM_MRA_REQ_RCVD:
36451 case IB_CM_MRA_REP_RCVD:
36452- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36453+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36454 counter[CM_MRA_COUNTER]);
36455 /* fall through */
36456 default:
36457@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
36458 case IB_CM_LAP_IDLE:
36459 break;
36460 case IB_CM_MRA_LAP_SENT:
36461- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36462+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36463 counter[CM_LAP_COUNTER]);
36464 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36465 goto unlock;
36466@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
36467 cm_free_msg(msg);
36468 goto deref;
36469 case IB_CM_LAP_RCVD:
36470- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36471+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36472 counter[CM_LAP_COUNTER]);
36473 goto unlock;
36474 default:
36475@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
36476 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
36477 if (cur_cm_id_priv) {
36478 spin_unlock_irq(&cm.lock);
36479- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36480+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36481 counter[CM_SIDR_REQ_COUNTER]);
36482 goto out; /* Duplicate message. */
36483 }
36484@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
36485 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
36486 msg->retries = 1;
36487
36488- atomic_long_add(1 + msg->retries,
36489+ atomic_long_add_unchecked(1 + msg->retries,
36490 &port->counter_group[CM_XMIT].counter[attr_index]);
36491 if (msg->retries)
36492- atomic_long_add(msg->retries,
36493+ atomic_long_add_unchecked(msg->retries,
36494 &port->counter_group[CM_XMIT_RETRIES].
36495 counter[attr_index]);
36496
36497@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
36498 }
36499
36500 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
36501- atomic_long_inc(&port->counter_group[CM_RECV].
36502+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
36503 counter[attr_id - CM_ATTR_ID_OFFSET]);
36504
36505 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
36506@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
36507 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
36508
36509 return sprintf(buf, "%ld\n",
36510- atomic_long_read(&group->counter[cm_attr->index]));
36511+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
36512 }
36513
36514 static const struct sysfs_ops cm_counter_ops = {
36515diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
36516index 176c8f9..2627b62 100644
36517--- a/drivers/infiniband/core/fmr_pool.c
36518+++ b/drivers/infiniband/core/fmr_pool.c
36519@@ -98,8 +98,8 @@ struct ib_fmr_pool {
36520
36521 struct task_struct *thread;
36522
36523- atomic_t req_ser;
36524- atomic_t flush_ser;
36525+ atomic_unchecked_t req_ser;
36526+ atomic_unchecked_t flush_ser;
36527
36528 wait_queue_head_t force_wait;
36529 };
36530@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36531 struct ib_fmr_pool *pool = pool_ptr;
36532
36533 do {
36534- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
36535+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
36536 ib_fmr_batch_release(pool);
36537
36538- atomic_inc(&pool->flush_ser);
36539+ atomic_inc_unchecked(&pool->flush_ser);
36540 wake_up_interruptible(&pool->force_wait);
36541
36542 if (pool->flush_function)
36543@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36544 }
36545
36546 set_current_state(TASK_INTERRUPTIBLE);
36547- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
36548+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
36549 !kthread_should_stop())
36550 schedule();
36551 __set_current_state(TASK_RUNNING);
36552@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
36553 pool->dirty_watermark = params->dirty_watermark;
36554 pool->dirty_len = 0;
36555 spin_lock_init(&pool->pool_lock);
36556- atomic_set(&pool->req_ser, 0);
36557- atomic_set(&pool->flush_ser, 0);
36558+ atomic_set_unchecked(&pool->req_ser, 0);
36559+ atomic_set_unchecked(&pool->flush_ser, 0);
36560 init_waitqueue_head(&pool->force_wait);
36561
36562 pool->thread = kthread_run(ib_fmr_cleanup_thread,
36563@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
36564 }
36565 spin_unlock_irq(&pool->pool_lock);
36566
36567- serial = atomic_inc_return(&pool->req_ser);
36568+ serial = atomic_inc_return_unchecked(&pool->req_ser);
36569 wake_up_process(pool->thread);
36570
36571 if (wait_event_interruptible(pool->force_wait,
36572- atomic_read(&pool->flush_ser) - serial >= 0))
36573+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
36574 return -EINTR;
36575
36576 return 0;
36577@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
36578 } else {
36579 list_add_tail(&fmr->list, &pool->dirty_list);
36580 if (++pool->dirty_len >= pool->dirty_watermark) {
36581- atomic_inc(&pool->req_ser);
36582+ atomic_inc_unchecked(&pool->req_ser);
36583 wake_up_process(pool->thread);
36584 }
36585 }
36586diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
36587index afd8179..598063f 100644
36588--- a/drivers/infiniband/hw/cxgb4/mem.c
36589+++ b/drivers/infiniband/hw/cxgb4/mem.c
36590@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36591 int err;
36592 struct fw_ri_tpte tpt;
36593 u32 stag_idx;
36594- static atomic_t key;
36595+ static atomic_unchecked_t key;
36596
36597 if (c4iw_fatal_error(rdev))
36598 return -EIO;
36599@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36600 if (rdev->stats.stag.cur > rdev->stats.stag.max)
36601 rdev->stats.stag.max = rdev->stats.stag.cur;
36602 mutex_unlock(&rdev->stats.lock);
36603- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
36604+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
36605 }
36606 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
36607 __func__, stag_state, type, pdid, stag_idx);
36608diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
36609index 79b3dbc..96e5fcc 100644
36610--- a/drivers/infiniband/hw/ipath/ipath_rc.c
36611+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
36612@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36613 struct ib_atomic_eth *ateth;
36614 struct ipath_ack_entry *e;
36615 u64 vaddr;
36616- atomic64_t *maddr;
36617+ atomic64_unchecked_t *maddr;
36618 u64 sdata;
36619 u32 rkey;
36620 u8 next;
36621@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36622 IB_ACCESS_REMOTE_ATOMIC)))
36623 goto nack_acc_unlck;
36624 /* Perform atomic OP and save result. */
36625- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36626+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36627 sdata = be64_to_cpu(ateth->swap_data);
36628 e = &qp->s_ack_queue[qp->r_head_ack_queue];
36629 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
36630- (u64) atomic64_add_return(sdata, maddr) - sdata :
36631+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36632 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36633 be64_to_cpu(ateth->compare_data),
36634 sdata);
36635diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
36636index 1f95bba..9530f87 100644
36637--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
36638+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
36639@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
36640 unsigned long flags;
36641 struct ib_wc wc;
36642 u64 sdata;
36643- atomic64_t *maddr;
36644+ atomic64_unchecked_t *maddr;
36645 enum ib_wc_status send_status;
36646
36647 /*
36648@@ -382,11 +382,11 @@ again:
36649 IB_ACCESS_REMOTE_ATOMIC)))
36650 goto acc_err;
36651 /* Perform atomic OP and save result. */
36652- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36653+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36654 sdata = wqe->wr.wr.atomic.compare_add;
36655 *(u64 *) sqp->s_sge.sge.vaddr =
36656 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
36657- (u64) atomic64_add_return(sdata, maddr) - sdata :
36658+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36659 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36660 sdata, wqe->wr.wr.atomic.swap);
36661 goto send_comp;
36662diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
36663index 9d3e5c1..d9afe4a 100644
36664--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
36665+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
36666@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
36667 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
36668 }
36669
36670-int mthca_QUERY_FW(struct mthca_dev *dev)
36671+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
36672 {
36673 struct mthca_mailbox *mailbox;
36674 u32 *outbox;
36675diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
36676index ed9a989..e0c5871 100644
36677--- a/drivers/infiniband/hw/mthca/mthca_mr.c
36678+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
36679@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
36680 return key;
36681 }
36682
36683-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
36684+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
36685 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
36686 {
36687 struct mthca_mailbox *mailbox;
36688diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
36689index 5b152a3..c1f3e83 100644
36690--- a/drivers/infiniband/hw/nes/nes.c
36691+++ b/drivers/infiniband/hw/nes/nes.c
36692@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
36693 LIST_HEAD(nes_adapter_list);
36694 static LIST_HEAD(nes_dev_list);
36695
36696-atomic_t qps_destroyed;
36697+atomic_unchecked_t qps_destroyed;
36698
36699 static unsigned int ee_flsh_adapter;
36700 static unsigned int sysfs_nonidx_addr;
36701@@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
36702 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
36703 struct nes_adapter *nesadapter = nesdev->nesadapter;
36704
36705- atomic_inc(&qps_destroyed);
36706+ atomic_inc_unchecked(&qps_destroyed);
36707
36708 /* Free the control structures */
36709
36710diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
36711index 33cc589..3bd6538 100644
36712--- a/drivers/infiniband/hw/nes/nes.h
36713+++ b/drivers/infiniband/hw/nes/nes.h
36714@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
36715 extern unsigned int wqm_quanta;
36716 extern struct list_head nes_adapter_list;
36717
36718-extern atomic_t cm_connects;
36719-extern atomic_t cm_accepts;
36720-extern atomic_t cm_disconnects;
36721-extern atomic_t cm_closes;
36722-extern atomic_t cm_connecteds;
36723-extern atomic_t cm_connect_reqs;
36724-extern atomic_t cm_rejects;
36725-extern atomic_t mod_qp_timouts;
36726-extern atomic_t qps_created;
36727-extern atomic_t qps_destroyed;
36728-extern atomic_t sw_qps_destroyed;
36729+extern atomic_unchecked_t cm_connects;
36730+extern atomic_unchecked_t cm_accepts;
36731+extern atomic_unchecked_t cm_disconnects;
36732+extern atomic_unchecked_t cm_closes;
36733+extern atomic_unchecked_t cm_connecteds;
36734+extern atomic_unchecked_t cm_connect_reqs;
36735+extern atomic_unchecked_t cm_rejects;
36736+extern atomic_unchecked_t mod_qp_timouts;
36737+extern atomic_unchecked_t qps_created;
36738+extern atomic_unchecked_t qps_destroyed;
36739+extern atomic_unchecked_t sw_qps_destroyed;
36740 extern u32 mh_detected;
36741 extern u32 mh_pauses_sent;
36742 extern u32 cm_packets_sent;
36743@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
36744 extern u32 cm_packets_received;
36745 extern u32 cm_packets_dropped;
36746 extern u32 cm_packets_retrans;
36747-extern atomic_t cm_listens_created;
36748-extern atomic_t cm_listens_destroyed;
36749+extern atomic_unchecked_t cm_listens_created;
36750+extern atomic_unchecked_t cm_listens_destroyed;
36751 extern u32 cm_backlog_drops;
36752-extern atomic_t cm_loopbacks;
36753-extern atomic_t cm_nodes_created;
36754-extern atomic_t cm_nodes_destroyed;
36755-extern atomic_t cm_accel_dropped_pkts;
36756-extern atomic_t cm_resets_recvd;
36757-extern atomic_t pau_qps_created;
36758-extern atomic_t pau_qps_destroyed;
36759+extern atomic_unchecked_t cm_loopbacks;
36760+extern atomic_unchecked_t cm_nodes_created;
36761+extern atomic_unchecked_t cm_nodes_destroyed;
36762+extern atomic_unchecked_t cm_accel_dropped_pkts;
36763+extern atomic_unchecked_t cm_resets_recvd;
36764+extern atomic_unchecked_t pau_qps_created;
36765+extern atomic_unchecked_t pau_qps_destroyed;
36766
36767 extern u32 int_mod_timer_init;
36768 extern u32 int_mod_cq_depth_256;
36769diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
36770index 22ea67e..dcbe3bc 100644
36771--- a/drivers/infiniband/hw/nes/nes_cm.c
36772+++ b/drivers/infiniband/hw/nes/nes_cm.c
36773@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
36774 u32 cm_packets_retrans;
36775 u32 cm_packets_created;
36776 u32 cm_packets_received;
36777-atomic_t cm_listens_created;
36778-atomic_t cm_listens_destroyed;
36779+atomic_unchecked_t cm_listens_created;
36780+atomic_unchecked_t cm_listens_destroyed;
36781 u32 cm_backlog_drops;
36782-atomic_t cm_loopbacks;
36783-atomic_t cm_nodes_created;
36784-atomic_t cm_nodes_destroyed;
36785-atomic_t cm_accel_dropped_pkts;
36786-atomic_t cm_resets_recvd;
36787+atomic_unchecked_t cm_loopbacks;
36788+atomic_unchecked_t cm_nodes_created;
36789+atomic_unchecked_t cm_nodes_destroyed;
36790+atomic_unchecked_t cm_accel_dropped_pkts;
36791+atomic_unchecked_t cm_resets_recvd;
36792
36793 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
36794 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
36795@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
36796
36797 static struct nes_cm_core *g_cm_core;
36798
36799-atomic_t cm_connects;
36800-atomic_t cm_accepts;
36801-atomic_t cm_disconnects;
36802-atomic_t cm_closes;
36803-atomic_t cm_connecteds;
36804-atomic_t cm_connect_reqs;
36805-atomic_t cm_rejects;
36806+atomic_unchecked_t cm_connects;
36807+atomic_unchecked_t cm_accepts;
36808+atomic_unchecked_t cm_disconnects;
36809+atomic_unchecked_t cm_closes;
36810+atomic_unchecked_t cm_connecteds;
36811+atomic_unchecked_t cm_connect_reqs;
36812+atomic_unchecked_t cm_rejects;
36813
36814 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
36815 {
36816@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
36817 kfree(listener);
36818 listener = NULL;
36819 ret = 0;
36820- atomic_inc(&cm_listens_destroyed);
36821+ atomic_inc_unchecked(&cm_listens_destroyed);
36822 } else {
36823 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
36824 }
36825@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
36826 cm_node->rem_mac);
36827
36828 add_hte_node(cm_core, cm_node);
36829- atomic_inc(&cm_nodes_created);
36830+ atomic_inc_unchecked(&cm_nodes_created);
36831
36832 return cm_node;
36833 }
36834@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
36835 }
36836
36837 atomic_dec(&cm_core->node_cnt);
36838- atomic_inc(&cm_nodes_destroyed);
36839+ atomic_inc_unchecked(&cm_nodes_destroyed);
36840 nesqp = cm_node->nesqp;
36841 if (nesqp) {
36842 nesqp->cm_node = NULL;
36843@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
36844
36845 static void drop_packet(struct sk_buff *skb)
36846 {
36847- atomic_inc(&cm_accel_dropped_pkts);
36848+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
36849 dev_kfree_skb_any(skb);
36850 }
36851
36852@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
36853 {
36854
36855 int reset = 0; /* whether to send reset in case of err.. */
36856- atomic_inc(&cm_resets_recvd);
36857+ atomic_inc_unchecked(&cm_resets_recvd);
36858 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
36859 " refcnt=%d\n", cm_node, cm_node->state,
36860 atomic_read(&cm_node->ref_count));
36861@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
36862 rem_ref_cm_node(cm_node->cm_core, cm_node);
36863 return NULL;
36864 }
36865- atomic_inc(&cm_loopbacks);
36866+ atomic_inc_unchecked(&cm_loopbacks);
36867 loopbackremotenode->loopbackpartner = cm_node;
36868 loopbackremotenode->tcp_cntxt.rcv_wscale =
36869 NES_CM_DEFAULT_RCV_WND_SCALE;
36870@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
36871 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
36872 else {
36873 rem_ref_cm_node(cm_core, cm_node);
36874- atomic_inc(&cm_accel_dropped_pkts);
36875+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
36876 dev_kfree_skb_any(skb);
36877 }
36878 break;
36879@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
36880
36881 if ((cm_id) && (cm_id->event_handler)) {
36882 if (issue_disconn) {
36883- atomic_inc(&cm_disconnects);
36884+ atomic_inc_unchecked(&cm_disconnects);
36885 cm_event.event = IW_CM_EVENT_DISCONNECT;
36886 cm_event.status = disconn_status;
36887 cm_event.local_addr = cm_id->local_addr;
36888@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
36889 }
36890
36891 if (issue_close) {
36892- atomic_inc(&cm_closes);
36893+ atomic_inc_unchecked(&cm_closes);
36894 nes_disconnect(nesqp, 1);
36895
36896 cm_id->provider_data = nesqp;
36897@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
36898
36899 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
36900 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
36901- atomic_inc(&cm_accepts);
36902+ atomic_inc_unchecked(&cm_accepts);
36903
36904 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
36905 netdev_refcnt_read(nesvnic->netdev));
36906@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
36907 struct nes_cm_core *cm_core;
36908 u8 *start_buff;
36909
36910- atomic_inc(&cm_rejects);
36911+ atomic_inc_unchecked(&cm_rejects);
36912 cm_node = (struct nes_cm_node *)cm_id->provider_data;
36913 loopback = cm_node->loopbackpartner;
36914 cm_core = cm_node->cm_core;
36915@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
36916 ntohl(cm_id->local_addr.sin_addr.s_addr),
36917 ntohs(cm_id->local_addr.sin_port));
36918
36919- atomic_inc(&cm_connects);
36920+ atomic_inc_unchecked(&cm_connects);
36921 nesqp->active_conn = 1;
36922
36923 /* cache the cm_id in the qp */
36924@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
36925 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
36926 return err;
36927 }
36928- atomic_inc(&cm_listens_created);
36929+ atomic_inc_unchecked(&cm_listens_created);
36930 }
36931
36932 cm_id->add_ref(cm_id);
36933@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
36934
36935 if (nesqp->destroyed)
36936 return;
36937- atomic_inc(&cm_connecteds);
36938+ atomic_inc_unchecked(&cm_connecteds);
36939 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
36940 " local port 0x%04X. jiffies = %lu.\n",
36941 nesqp->hwqp.qp_id,
36942@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
36943
36944 cm_id->add_ref(cm_id);
36945 ret = cm_id->event_handler(cm_id, &cm_event);
36946- atomic_inc(&cm_closes);
36947+ atomic_inc_unchecked(&cm_closes);
36948 cm_event.event = IW_CM_EVENT_CLOSE;
36949 cm_event.status = 0;
36950 cm_event.provider_data = cm_id->provider_data;
36951@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
36952 return;
36953 cm_id = cm_node->cm_id;
36954
36955- atomic_inc(&cm_connect_reqs);
36956+ atomic_inc_unchecked(&cm_connect_reqs);
36957 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
36958 cm_node, cm_id, jiffies);
36959
36960@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
36961 return;
36962 cm_id = cm_node->cm_id;
36963
36964- atomic_inc(&cm_connect_reqs);
36965+ atomic_inc_unchecked(&cm_connect_reqs);
36966 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
36967 cm_node, cm_id, jiffies);
36968
36969diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
36970index 4166452..fc952c3 100644
36971--- a/drivers/infiniband/hw/nes/nes_mgt.c
36972+++ b/drivers/infiniband/hw/nes/nes_mgt.c
36973@@ -40,8 +40,8 @@
36974 #include "nes.h"
36975 #include "nes_mgt.h"
36976
36977-atomic_t pau_qps_created;
36978-atomic_t pau_qps_destroyed;
36979+atomic_unchecked_t pau_qps_created;
36980+atomic_unchecked_t pau_qps_destroyed;
36981
36982 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
36983 {
36984@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
36985 {
36986 struct sk_buff *skb;
36987 unsigned long flags;
36988- atomic_inc(&pau_qps_destroyed);
36989+ atomic_inc_unchecked(&pau_qps_destroyed);
36990
36991 /* Free packets that have not yet been forwarded */
36992 /* Lock is acquired by skb_dequeue when removing the skb */
36993@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
36994 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
36995 skb_queue_head_init(&nesqp->pau_list);
36996 spin_lock_init(&nesqp->pau_lock);
36997- atomic_inc(&pau_qps_created);
36998+ atomic_inc_unchecked(&pau_qps_created);
36999 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
37000 }
37001
37002diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
37003index 9542e16..a008c40 100644
37004--- a/drivers/infiniband/hw/nes/nes_nic.c
37005+++ b/drivers/infiniband/hw/nes/nes_nic.c
37006@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
37007 target_stat_values[++index] = mh_detected;
37008 target_stat_values[++index] = mh_pauses_sent;
37009 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
37010- target_stat_values[++index] = atomic_read(&cm_connects);
37011- target_stat_values[++index] = atomic_read(&cm_accepts);
37012- target_stat_values[++index] = atomic_read(&cm_disconnects);
37013- target_stat_values[++index] = atomic_read(&cm_connecteds);
37014- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
37015- target_stat_values[++index] = atomic_read(&cm_rejects);
37016- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
37017- target_stat_values[++index] = atomic_read(&qps_created);
37018- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
37019- target_stat_values[++index] = atomic_read(&qps_destroyed);
37020- target_stat_values[++index] = atomic_read(&cm_closes);
37021+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
37022+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
37023+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
37024+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
37025+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
37026+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
37027+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
37028+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
37029+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
37030+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
37031+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
37032 target_stat_values[++index] = cm_packets_sent;
37033 target_stat_values[++index] = cm_packets_bounced;
37034 target_stat_values[++index] = cm_packets_created;
37035 target_stat_values[++index] = cm_packets_received;
37036 target_stat_values[++index] = cm_packets_dropped;
37037 target_stat_values[++index] = cm_packets_retrans;
37038- target_stat_values[++index] = atomic_read(&cm_listens_created);
37039- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
37040+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
37041+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
37042 target_stat_values[++index] = cm_backlog_drops;
37043- target_stat_values[++index] = atomic_read(&cm_loopbacks);
37044- target_stat_values[++index] = atomic_read(&cm_nodes_created);
37045- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
37046- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
37047- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
37048+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
37049+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
37050+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
37051+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
37052+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
37053 target_stat_values[++index] = nesadapter->free_4kpbl;
37054 target_stat_values[++index] = nesadapter->free_256pbl;
37055 target_stat_values[++index] = int_mod_timer_init;
37056 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
37057 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
37058 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
37059- target_stat_values[++index] = atomic_read(&pau_qps_created);
37060- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
37061+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
37062+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
37063 }
37064
37065 /**
37066diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
37067index 07e4fba..685f041 100644
37068--- a/drivers/infiniband/hw/nes/nes_verbs.c
37069+++ b/drivers/infiniband/hw/nes/nes_verbs.c
37070@@ -46,9 +46,9 @@
37071
37072 #include <rdma/ib_umem.h>
37073
37074-atomic_t mod_qp_timouts;
37075-atomic_t qps_created;
37076-atomic_t sw_qps_destroyed;
37077+atomic_unchecked_t mod_qp_timouts;
37078+atomic_unchecked_t qps_created;
37079+atomic_unchecked_t sw_qps_destroyed;
37080
37081 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
37082
37083@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
37084 if (init_attr->create_flags)
37085 return ERR_PTR(-EINVAL);
37086
37087- atomic_inc(&qps_created);
37088+ atomic_inc_unchecked(&qps_created);
37089 switch (init_attr->qp_type) {
37090 case IB_QPT_RC:
37091 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
37092@@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
37093 struct iw_cm_event cm_event;
37094 int ret = 0;
37095
37096- atomic_inc(&sw_qps_destroyed);
37097+ atomic_inc_unchecked(&sw_qps_destroyed);
37098 nesqp->destroyed = 1;
37099
37100 /* Blow away the connection if it exists. */
37101diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
37102index 4d11575..3e890e5 100644
37103--- a/drivers/infiniband/hw/qib/qib.h
37104+++ b/drivers/infiniband/hw/qib/qib.h
37105@@ -51,6 +51,7 @@
37106 #include <linux/completion.h>
37107 #include <linux/kref.h>
37108 #include <linux/sched.h>
37109+#include <linux/slab.h>
37110
37111 #include "qib_common.h"
37112 #include "qib_verbs.h"
37113diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
37114index da739d9..da1c7f4 100644
37115--- a/drivers/input/gameport/gameport.c
37116+++ b/drivers/input/gameport/gameport.c
37117@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
37118 */
37119 static void gameport_init_port(struct gameport *gameport)
37120 {
37121- static atomic_t gameport_no = ATOMIC_INIT(0);
37122+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
37123
37124 __module_get(THIS_MODULE);
37125
37126 mutex_init(&gameport->drv_mutex);
37127 device_initialize(&gameport->dev);
37128 dev_set_name(&gameport->dev, "gameport%lu",
37129- (unsigned long)atomic_inc_return(&gameport_no) - 1);
37130+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
37131 gameport->dev.bus = &gameport_bus;
37132 gameport->dev.release = gameport_release_port;
37133 if (gameport->parent)
37134diff --git a/drivers/input/input.c b/drivers/input/input.c
37135index c044699..174d71a 100644
37136--- a/drivers/input/input.c
37137+++ b/drivers/input/input.c
37138@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
37139 */
37140 int input_register_device(struct input_dev *dev)
37141 {
37142- static atomic_t input_no = ATOMIC_INIT(0);
37143+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
37144 struct input_devres *devres = NULL;
37145 struct input_handler *handler;
37146 unsigned int packet_size;
37147@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
37148 dev->setkeycode = input_default_setkeycode;
37149
37150 dev_set_name(&dev->dev, "input%ld",
37151- (unsigned long) atomic_inc_return(&input_no) - 1);
37152+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
37153
37154 error = device_add(&dev->dev);
37155 if (error)
37156diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
37157index 04c69af..5f92d00 100644
37158--- a/drivers/input/joystick/sidewinder.c
37159+++ b/drivers/input/joystick/sidewinder.c
37160@@ -30,6 +30,7 @@
37161 #include <linux/kernel.h>
37162 #include <linux/module.h>
37163 #include <linux/slab.h>
37164+#include <linux/sched.h>
37165 #include <linux/init.h>
37166 #include <linux/input.h>
37167 #include <linux/gameport.h>
37168diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
37169index d6cbfe9..6225402 100644
37170--- a/drivers/input/joystick/xpad.c
37171+++ b/drivers/input/joystick/xpad.c
37172@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
37173
37174 static int xpad_led_probe(struct usb_xpad *xpad)
37175 {
37176- static atomic_t led_seq = ATOMIC_INIT(0);
37177+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
37178 long led_no;
37179 struct xpad_led *led;
37180 struct led_classdev *led_cdev;
37181@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
37182 if (!led)
37183 return -ENOMEM;
37184
37185- led_no = (long)atomic_inc_return(&led_seq) - 1;
37186+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
37187
37188 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
37189 led->xpad = xpad;
37190diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
37191index fe1df23..5b710f3 100644
37192--- a/drivers/input/mouse/psmouse.h
37193+++ b/drivers/input/mouse/psmouse.h
37194@@ -115,7 +115,7 @@ struct psmouse_attribute {
37195 ssize_t (*set)(struct psmouse *psmouse, void *data,
37196 const char *buf, size_t count);
37197 bool protect;
37198-};
37199+} __do_const;
37200 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
37201
37202 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
37203diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
37204index 4c842c3..590b0bf 100644
37205--- a/drivers/input/mousedev.c
37206+++ b/drivers/input/mousedev.c
37207@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
37208
37209 spin_unlock_irq(&client->packet_lock);
37210
37211- if (copy_to_user(buffer, data, count))
37212+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
37213 return -EFAULT;
37214
37215 return count;
37216diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
37217index 25fc597..558bf3b 100644
37218--- a/drivers/input/serio/serio.c
37219+++ b/drivers/input/serio/serio.c
37220@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
37221 */
37222 static void serio_init_port(struct serio *serio)
37223 {
37224- static atomic_t serio_no = ATOMIC_INIT(0);
37225+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
37226
37227 __module_get(THIS_MODULE);
37228
37229@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
37230 mutex_init(&serio->drv_mutex);
37231 device_initialize(&serio->dev);
37232 dev_set_name(&serio->dev, "serio%ld",
37233- (long)atomic_inc_return(&serio_no) - 1);
37234+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
37235 serio->dev.bus = &serio_bus;
37236 serio->dev.release = serio_release_port;
37237 serio->dev.groups = serio_device_attr_groups;
37238diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
37239index ddbdaca..be18a78 100644
37240--- a/drivers/iommu/iommu.c
37241+++ b/drivers/iommu/iommu.c
37242@@ -554,7 +554,7 @@ static struct notifier_block iommu_bus_nb = {
37243 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
37244 {
37245 bus_register_notifier(bus, &iommu_bus_nb);
37246- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
37247+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
37248 }
37249
37250 /**
37251diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
37252index 89562a8..218999b 100644
37253--- a/drivers/isdn/capi/capi.c
37254+++ b/drivers/isdn/capi/capi.c
37255@@ -81,8 +81,8 @@ struct capiminor {
37256
37257 struct capi20_appl *ap;
37258 u32 ncci;
37259- atomic_t datahandle;
37260- atomic_t msgid;
37261+ atomic_unchecked_t datahandle;
37262+ atomic_unchecked_t msgid;
37263
37264 struct tty_port port;
37265 int ttyinstop;
37266@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
37267 capimsg_setu16(s, 2, mp->ap->applid);
37268 capimsg_setu8 (s, 4, CAPI_DATA_B3);
37269 capimsg_setu8 (s, 5, CAPI_RESP);
37270- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
37271+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
37272 capimsg_setu32(s, 8, mp->ncci);
37273 capimsg_setu16(s, 12, datahandle);
37274 }
37275@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
37276 mp->outbytes -= len;
37277 spin_unlock_bh(&mp->outlock);
37278
37279- datahandle = atomic_inc_return(&mp->datahandle);
37280+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
37281 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
37282 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37283 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37284 capimsg_setu16(skb->data, 2, mp->ap->applid);
37285 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
37286 capimsg_setu8 (skb->data, 5, CAPI_REQ);
37287- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
37288+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
37289 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
37290 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
37291 capimsg_setu16(skb->data, 16, len); /* Data length */
37292diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
37293index 67abf3f..076b3a6 100644
37294--- a/drivers/isdn/gigaset/interface.c
37295+++ b/drivers/isdn/gigaset/interface.c
37296@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
37297 }
37298 tty->driver_data = cs;
37299
37300- ++cs->port.count;
37301+ atomic_inc(&cs->port.count);
37302
37303- if (cs->port.count == 1) {
37304+ if (atomic_read(&cs->port.count) == 1) {
37305 tty_port_tty_set(&cs->port, tty);
37306 tty->low_latency = 1;
37307 }
37308@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
37309
37310 if (!cs->connected)
37311 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
37312- else if (!cs->port.count)
37313+ else if (!atomic_read(&cs->port.count))
37314 dev_warn(cs->dev, "%s: device not opened\n", __func__);
37315- else if (!--cs->port.count)
37316+ else if (!atomic_dec_return(&cs->port.count))
37317 tty_port_tty_set(&cs->port, NULL);
37318
37319 mutex_unlock(&cs->mutex);
37320diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
37321index 821f7ac..28d4030 100644
37322--- a/drivers/isdn/hardware/avm/b1.c
37323+++ b/drivers/isdn/hardware/avm/b1.c
37324@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
37325 }
37326 if (left) {
37327 if (t4file->user) {
37328- if (copy_from_user(buf, dp, left))
37329+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37330 return -EFAULT;
37331 } else {
37332 memcpy(buf, dp, left);
37333@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
37334 }
37335 if (left) {
37336 if (config->user) {
37337- if (copy_from_user(buf, dp, left))
37338+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37339 return -EFAULT;
37340 } else {
37341 memcpy(buf, dp, left);
37342diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
37343index e09dc8a..15e2efb 100644
37344--- a/drivers/isdn/i4l/isdn_tty.c
37345+++ b/drivers/isdn/i4l/isdn_tty.c
37346@@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
37347
37348 #ifdef ISDN_DEBUG_MODEM_OPEN
37349 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
37350- port->count);
37351+ atomic_read(&port->count));
37352 #endif
37353- port->count++;
37354+ atomic_inc(&port->count);
37355 port->tty = tty;
37356 /*
37357 * Start up serial port
37358@@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37359 #endif
37360 return;
37361 }
37362- if ((tty->count == 1) && (port->count != 1)) {
37363+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
37364 /*
37365 * Uh, oh. tty->count is 1, which means that the tty
37366 * structure will be freed. Info->count should always
37367@@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37368 * serial port won't be shutdown.
37369 */
37370 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
37371- "info->count is %d\n", port->count);
37372- port->count = 1;
37373+ "info->count is %d\n", atomic_read(&port->count));
37374+ atomic_set(&port->count, 1);
37375 }
37376- if (--port->count < 0) {
37377+ if (atomic_dec_return(&port->count) < 0) {
37378 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
37379- info->line, port->count);
37380- port->count = 0;
37381+ info->line, atomic_read(&port->count));
37382+ atomic_set(&port->count, 0);
37383 }
37384- if (port->count) {
37385+ if (atomic_read(&port->count)) {
37386 #ifdef ISDN_DEBUG_MODEM_OPEN
37387 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
37388 #endif
37389@@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
37390 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
37391 return;
37392 isdn_tty_shutdown(info);
37393- port->count = 0;
37394+ atomic_set(&port->count, 0);
37395 port->flags &= ~ASYNC_NORMAL_ACTIVE;
37396 port->tty = NULL;
37397 wake_up_interruptible(&port->open_wait);
37398@@ -1975,7 +1975,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
37399 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
37400 modem_info *info = &dev->mdm.info[i];
37401
37402- if (info->port.count == 0)
37403+ if (atomic_read(&info->port.count) == 0)
37404 continue;
37405 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
37406 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
37407diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
37408index e74df7c..03a03ba 100644
37409--- a/drivers/isdn/icn/icn.c
37410+++ b/drivers/isdn/icn/icn.c
37411@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
37412 if (count > len)
37413 count = len;
37414 if (user) {
37415- if (copy_from_user(msg, buf, count))
37416+ if (count > sizeof msg || copy_from_user(msg, buf, count))
37417 return -EFAULT;
37418 } else
37419 memcpy(msg, buf, count);
37420diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
37421index 6a8405d..0bd1c7e 100644
37422--- a/drivers/leds/leds-clevo-mail.c
37423+++ b/drivers/leds/leds-clevo-mail.c
37424@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
37425 * detected as working, but in reality it is not) as low as
37426 * possible.
37427 */
37428-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
37429+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
37430 {
37431 .callback = clevo_mail_led_dmi_callback,
37432 .ident = "Clevo D410J",
37433diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
37434index ec9b287..65c9bf4 100644
37435--- a/drivers/leds/leds-ss4200.c
37436+++ b/drivers/leds/leds-ss4200.c
37437@@ -92,7 +92,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
37438 * detected as working, but in reality it is not) as low as
37439 * possible.
37440 */
37441-static struct dmi_system_id __initdata nas_led_whitelist[] = {
37442+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
37443 {
37444 .callback = ss4200_led_dmi_callback,
37445 .ident = "Intel SS4200-E",
37446diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
37447index a5ebc00..982886f 100644
37448--- a/drivers/lguest/core.c
37449+++ b/drivers/lguest/core.c
37450@@ -92,9 +92,17 @@ static __init int map_switcher(void)
37451 * it's worked so far. The end address needs +1 because __get_vm_area
37452 * allocates an extra guard page, so we need space for that.
37453 */
37454+
37455+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
37456+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37457+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
37458+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37459+#else
37460 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37461 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
37462 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37463+#endif
37464+
37465 if (!switcher_vma) {
37466 err = -ENOMEM;
37467 printk("lguest: could not map switcher pages high\n");
37468@@ -119,7 +127,7 @@ static __init int map_switcher(void)
37469 * Now the Switcher is mapped at the right address, we can't fail!
37470 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
37471 */
37472- memcpy(switcher_vma->addr, start_switcher_text,
37473+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
37474 end_switcher_text - start_switcher_text);
37475
37476 printk(KERN_INFO "lguest: mapped switcher at %p\n",
37477diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
37478index 3b62be16..e33134a 100644
37479--- a/drivers/lguest/page_tables.c
37480+++ b/drivers/lguest/page_tables.c
37481@@ -532,7 +532,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
37482 /*:*/
37483
37484 #ifdef CONFIG_X86_PAE
37485-static void release_pmd(pmd_t *spmd)
37486+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
37487 {
37488 /* If the entry's not present, there's nothing to release. */
37489 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
37490diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
37491index 4af12e1..0e89afe 100644
37492--- a/drivers/lguest/x86/core.c
37493+++ b/drivers/lguest/x86/core.c
37494@@ -59,7 +59,7 @@ static struct {
37495 /* Offset from where switcher.S was compiled to where we've copied it */
37496 static unsigned long switcher_offset(void)
37497 {
37498- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
37499+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
37500 }
37501
37502 /* This cpu's struct lguest_pages. */
37503@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
37504 * These copies are pretty cheap, so we do them unconditionally: */
37505 /* Save the current Host top-level page directory.
37506 */
37507+
37508+#ifdef CONFIG_PAX_PER_CPU_PGD
37509+ pages->state.host_cr3 = read_cr3();
37510+#else
37511 pages->state.host_cr3 = __pa(current->mm->pgd);
37512+#endif
37513+
37514 /*
37515 * Set up the Guest's page tables to see this CPU's pages (and no
37516 * other CPU's pages).
37517@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
37518 * compiled-in switcher code and the high-mapped copy we just made.
37519 */
37520 for (i = 0; i < IDT_ENTRIES; i++)
37521- default_idt_entries[i] += switcher_offset();
37522+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
37523
37524 /*
37525 * Set up the Switcher's per-cpu areas.
37526@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
37527 * it will be undisturbed when we switch. To change %cs and jump we
37528 * need this structure to feed to Intel's "lcall" instruction.
37529 */
37530- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
37531+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
37532 lguest_entry.segment = LGUEST_CS;
37533
37534 /*
37535diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
37536index 40634b0..4f5855e 100644
37537--- a/drivers/lguest/x86/switcher_32.S
37538+++ b/drivers/lguest/x86/switcher_32.S
37539@@ -87,6 +87,7 @@
37540 #include <asm/page.h>
37541 #include <asm/segment.h>
37542 #include <asm/lguest.h>
37543+#include <asm/processor-flags.h>
37544
37545 // We mark the start of the code to copy
37546 // It's placed in .text tho it's never run here
37547@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
37548 // Changes type when we load it: damn Intel!
37549 // For after we switch over our page tables
37550 // That entry will be read-only: we'd crash.
37551+
37552+#ifdef CONFIG_PAX_KERNEXEC
37553+ mov %cr0, %edx
37554+ xor $X86_CR0_WP, %edx
37555+ mov %edx, %cr0
37556+#endif
37557+
37558 movl $(GDT_ENTRY_TSS*8), %edx
37559 ltr %dx
37560
37561@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
37562 // Let's clear it again for our return.
37563 // The GDT descriptor of the Host
37564 // Points to the table after two "size" bytes
37565- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
37566+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
37567 // Clear "used" from type field (byte 5, bit 2)
37568- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
37569+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
37570+
37571+#ifdef CONFIG_PAX_KERNEXEC
37572+ mov %cr0, %eax
37573+ xor $X86_CR0_WP, %eax
37574+ mov %eax, %cr0
37575+#endif
37576
37577 // Once our page table's switched, the Guest is live!
37578 // The Host fades as we run this final step.
37579@@ -295,13 +309,12 @@ deliver_to_host:
37580 // I consulted gcc, and it gave
37581 // These instructions, which I gladly credit:
37582 leal (%edx,%ebx,8), %eax
37583- movzwl (%eax),%edx
37584- movl 4(%eax), %eax
37585- xorw %ax, %ax
37586- orl %eax, %edx
37587+ movl 4(%eax), %edx
37588+ movw (%eax), %dx
37589 // Now the address of the handler's in %edx
37590 // We call it now: its "iret" drops us home.
37591- jmp *%edx
37592+ ljmp $__KERNEL_CS, $1f
37593+1: jmp *%edx
37594
37595 // Every interrupt can come to us here
37596 // But we must truly tell each apart.
37597diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
37598index 7155945..4bcc562 100644
37599--- a/drivers/md/bitmap.c
37600+++ b/drivers/md/bitmap.c
37601@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
37602 chunk_kb ? "KB" : "B");
37603 if (bitmap->storage.file) {
37604 seq_printf(seq, ", file: ");
37605- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
37606+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
37607 }
37608
37609 seq_printf(seq, "\n");
37610diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
37611index eee353d..74504c4 100644
37612--- a/drivers/md/dm-ioctl.c
37613+++ b/drivers/md/dm-ioctl.c
37614@@ -1632,7 +1632,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
37615 cmd == DM_LIST_VERSIONS_CMD)
37616 return 0;
37617
37618- if ((cmd == DM_DEV_CREATE_CMD)) {
37619+ if (cmd == DM_DEV_CREATE_CMD) {
37620 if (!*param->name) {
37621 DMWARN("name not supplied when creating device");
37622 return -EINVAL;
37623diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
37624index 7f24190..0e18099 100644
37625--- a/drivers/md/dm-raid1.c
37626+++ b/drivers/md/dm-raid1.c
37627@@ -40,7 +40,7 @@ enum dm_raid1_error {
37628
37629 struct mirror {
37630 struct mirror_set *ms;
37631- atomic_t error_count;
37632+ atomic_unchecked_t error_count;
37633 unsigned long error_type;
37634 struct dm_dev *dev;
37635 sector_t offset;
37636@@ -183,7 +183,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
37637 struct mirror *m;
37638
37639 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
37640- if (!atomic_read(&m->error_count))
37641+ if (!atomic_read_unchecked(&m->error_count))
37642 return m;
37643
37644 return NULL;
37645@@ -215,7 +215,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
37646 * simple way to tell if a device has encountered
37647 * errors.
37648 */
37649- atomic_inc(&m->error_count);
37650+ atomic_inc_unchecked(&m->error_count);
37651
37652 if (test_and_set_bit(error_type, &m->error_type))
37653 return;
37654@@ -406,7 +406,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
37655 struct mirror *m = get_default_mirror(ms);
37656
37657 do {
37658- if (likely(!atomic_read(&m->error_count)))
37659+ if (likely(!atomic_read_unchecked(&m->error_count)))
37660 return m;
37661
37662 if (m-- == ms->mirror)
37663@@ -420,7 +420,7 @@ static int default_ok(struct mirror *m)
37664 {
37665 struct mirror *default_mirror = get_default_mirror(m->ms);
37666
37667- return !atomic_read(&default_mirror->error_count);
37668+ return !atomic_read_unchecked(&default_mirror->error_count);
37669 }
37670
37671 static int mirror_available(struct mirror_set *ms, struct bio *bio)
37672@@ -557,7 +557,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
37673 */
37674 if (likely(region_in_sync(ms, region, 1)))
37675 m = choose_mirror(ms, bio->bi_sector);
37676- else if (m && atomic_read(&m->error_count))
37677+ else if (m && atomic_read_unchecked(&m->error_count))
37678 m = NULL;
37679
37680 if (likely(m))
37681@@ -924,7 +924,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
37682 }
37683
37684 ms->mirror[mirror].ms = ms;
37685- atomic_set(&(ms->mirror[mirror].error_count), 0);
37686+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
37687 ms->mirror[mirror].error_type = 0;
37688 ms->mirror[mirror].offset = offset;
37689
37690@@ -1337,7 +1337,7 @@ static void mirror_resume(struct dm_target *ti)
37691 */
37692 static char device_status_char(struct mirror *m)
37693 {
37694- if (!atomic_read(&(m->error_count)))
37695+ if (!atomic_read_unchecked(&(m->error_count)))
37696 return 'A';
37697
37698 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
37699diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
37700index aaecefa..23b3026 100644
37701--- a/drivers/md/dm-stripe.c
37702+++ b/drivers/md/dm-stripe.c
37703@@ -20,7 +20,7 @@ struct stripe {
37704 struct dm_dev *dev;
37705 sector_t physical_start;
37706
37707- atomic_t error_count;
37708+ atomic_unchecked_t error_count;
37709 };
37710
37711 struct stripe_c {
37712@@ -184,7 +184,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
37713 kfree(sc);
37714 return r;
37715 }
37716- atomic_set(&(sc->stripe[i].error_count), 0);
37717+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
37718 }
37719
37720 ti->private = sc;
37721@@ -325,7 +325,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
37722 DMEMIT("%d ", sc->stripes);
37723 for (i = 0; i < sc->stripes; i++) {
37724 DMEMIT("%s ", sc->stripe[i].dev->name);
37725- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
37726+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
37727 'D' : 'A';
37728 }
37729 buffer[i] = '\0';
37730@@ -370,8 +370,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
37731 */
37732 for (i = 0; i < sc->stripes; i++)
37733 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
37734- atomic_inc(&(sc->stripe[i].error_count));
37735- if (atomic_read(&(sc->stripe[i].error_count)) <
37736+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
37737+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
37738 DM_IO_ERROR_THRESHOLD)
37739 schedule_work(&sc->trigger_event);
37740 }
37741diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
37742index daf25d0..d74f49f 100644
37743--- a/drivers/md/dm-table.c
37744+++ b/drivers/md/dm-table.c
37745@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
37746 if (!dev_size)
37747 return 0;
37748
37749- if ((start >= dev_size) || (start + len > dev_size)) {
37750+ if ((start >= dev_size) || (len > dev_size - start)) {
37751 DMWARN("%s: %s too small for target: "
37752 "start=%llu, len=%llu, dev_size=%llu",
37753 dm_device_name(ti->table->md), bdevname(bdev, b),
37754diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
37755index 4d6e853..a234157 100644
37756--- a/drivers/md/dm-thin-metadata.c
37757+++ b/drivers/md/dm-thin-metadata.c
37758@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
37759 {
37760 pmd->info.tm = pmd->tm;
37761 pmd->info.levels = 2;
37762- pmd->info.value_type.context = pmd->data_sm;
37763+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
37764 pmd->info.value_type.size = sizeof(__le64);
37765 pmd->info.value_type.inc = data_block_inc;
37766 pmd->info.value_type.dec = data_block_dec;
37767@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
37768
37769 pmd->bl_info.tm = pmd->tm;
37770 pmd->bl_info.levels = 1;
37771- pmd->bl_info.value_type.context = pmd->data_sm;
37772+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
37773 pmd->bl_info.value_type.size = sizeof(__le64);
37774 pmd->bl_info.value_type.inc = data_block_inc;
37775 pmd->bl_info.value_type.dec = data_block_dec;
37776diff --git a/drivers/md/dm.c b/drivers/md/dm.c
37777index 0d8f086..f5a91d5 100644
37778--- a/drivers/md/dm.c
37779+++ b/drivers/md/dm.c
37780@@ -170,9 +170,9 @@ struct mapped_device {
37781 /*
37782 * Event handling.
37783 */
37784- atomic_t event_nr;
37785+ atomic_unchecked_t event_nr;
37786 wait_queue_head_t eventq;
37787- atomic_t uevent_seq;
37788+ atomic_unchecked_t uevent_seq;
37789 struct list_head uevent_list;
37790 spinlock_t uevent_lock; /* Protect access to uevent_list */
37791
37792@@ -1872,8 +1872,8 @@ static struct mapped_device *alloc_dev(int minor)
37793 rwlock_init(&md->map_lock);
37794 atomic_set(&md->holders, 1);
37795 atomic_set(&md->open_count, 0);
37796- atomic_set(&md->event_nr, 0);
37797- atomic_set(&md->uevent_seq, 0);
37798+ atomic_set_unchecked(&md->event_nr, 0);
37799+ atomic_set_unchecked(&md->uevent_seq, 0);
37800 INIT_LIST_HEAD(&md->uevent_list);
37801 spin_lock_init(&md->uevent_lock);
37802
37803@@ -2026,7 +2026,7 @@ static void event_callback(void *context)
37804
37805 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
37806
37807- atomic_inc(&md->event_nr);
37808+ atomic_inc_unchecked(&md->event_nr);
37809 wake_up(&md->eventq);
37810 }
37811
37812@@ -2683,18 +2683,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
37813
37814 uint32_t dm_next_uevent_seq(struct mapped_device *md)
37815 {
37816- return atomic_add_return(1, &md->uevent_seq);
37817+ return atomic_add_return_unchecked(1, &md->uevent_seq);
37818 }
37819
37820 uint32_t dm_get_event_nr(struct mapped_device *md)
37821 {
37822- return atomic_read(&md->event_nr);
37823+ return atomic_read_unchecked(&md->event_nr);
37824 }
37825
37826 int dm_wait_event(struct mapped_device *md, int event_nr)
37827 {
37828 return wait_event_interruptible(md->eventq,
37829- (event_nr != atomic_read(&md->event_nr)));
37830+ (event_nr != atomic_read_unchecked(&md->event_nr)));
37831 }
37832
37833 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
37834diff --git a/drivers/md/md.c b/drivers/md/md.c
37835index f363135..9b38815 100644
37836--- a/drivers/md/md.c
37837+++ b/drivers/md/md.c
37838@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
37839 * start build, activate spare
37840 */
37841 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
37842-static atomic_t md_event_count;
37843+static atomic_unchecked_t md_event_count;
37844 void md_new_event(struct mddev *mddev)
37845 {
37846- atomic_inc(&md_event_count);
37847+ atomic_inc_unchecked(&md_event_count);
37848 wake_up(&md_event_waiters);
37849 }
37850 EXPORT_SYMBOL_GPL(md_new_event);
37851@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
37852 */
37853 static void md_new_event_inintr(struct mddev *mddev)
37854 {
37855- atomic_inc(&md_event_count);
37856+ atomic_inc_unchecked(&md_event_count);
37857 wake_up(&md_event_waiters);
37858 }
37859
37860@@ -1507,7 +1507,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
37861 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
37862 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
37863 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
37864- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
37865+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
37866
37867 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
37868 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
37869@@ -1751,7 +1751,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
37870 else
37871 sb->resync_offset = cpu_to_le64(0);
37872
37873- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
37874+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
37875
37876 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
37877 sb->size = cpu_to_le64(mddev->dev_sectors);
37878@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
37879 static ssize_t
37880 errors_show(struct md_rdev *rdev, char *page)
37881 {
37882- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
37883+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
37884 }
37885
37886 static ssize_t
37887@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
37888 char *e;
37889 unsigned long n = simple_strtoul(buf, &e, 10);
37890 if (*buf && (*e == 0 || *e == '\n')) {
37891- atomic_set(&rdev->corrected_errors, n);
37892+ atomic_set_unchecked(&rdev->corrected_errors, n);
37893 return len;
37894 }
37895 return -EINVAL;
37896@@ -3210,8 +3210,8 @@ int md_rdev_init(struct md_rdev *rdev)
37897 rdev->sb_loaded = 0;
37898 rdev->bb_page = NULL;
37899 atomic_set(&rdev->nr_pending, 0);
37900- atomic_set(&rdev->read_errors, 0);
37901- atomic_set(&rdev->corrected_errors, 0);
37902+ atomic_set_unchecked(&rdev->read_errors, 0);
37903+ atomic_set_unchecked(&rdev->corrected_errors, 0);
37904
37905 INIT_LIST_HEAD(&rdev->same_set);
37906 init_waitqueue_head(&rdev->blocked_wait);
37907@@ -6987,7 +6987,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
37908
37909 spin_unlock(&pers_lock);
37910 seq_printf(seq, "\n");
37911- seq->poll_event = atomic_read(&md_event_count);
37912+ seq->poll_event = atomic_read_unchecked(&md_event_count);
37913 return 0;
37914 }
37915 if (v == (void*)2) {
37916@@ -7090,7 +7090,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
37917 return error;
37918
37919 seq = file->private_data;
37920- seq->poll_event = atomic_read(&md_event_count);
37921+ seq->poll_event = atomic_read_unchecked(&md_event_count);
37922 return error;
37923 }
37924
37925@@ -7104,7 +7104,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
37926 /* always allow read */
37927 mask = POLLIN | POLLRDNORM;
37928
37929- if (seq->poll_event != atomic_read(&md_event_count))
37930+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
37931 mask |= POLLERR | POLLPRI;
37932 return mask;
37933 }
37934@@ -7148,7 +7148,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
37935 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
37936 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
37937 (int)part_stat_read(&disk->part0, sectors[1]) -
37938- atomic_read(&disk->sync_io);
37939+ atomic_read_unchecked(&disk->sync_io);
37940 /* sync IO will cause sync_io to increase before the disk_stats
37941 * as sync_io is counted when a request starts, and
37942 * disk_stats is counted when it completes.
37943diff --git a/drivers/md/md.h b/drivers/md/md.h
37944index eca59c3..7c42285 100644
37945--- a/drivers/md/md.h
37946+++ b/drivers/md/md.h
37947@@ -94,13 +94,13 @@ struct md_rdev {
37948 * only maintained for arrays that
37949 * support hot removal
37950 */
37951- atomic_t read_errors; /* number of consecutive read errors that
37952+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
37953 * we have tried to ignore.
37954 */
37955 struct timespec last_read_error; /* monotonic time since our
37956 * last read error
37957 */
37958- atomic_t corrected_errors; /* number of corrected read errors,
37959+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
37960 * for reporting to userspace and storing
37961 * in superblock.
37962 */
37963@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
37964
37965 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
37966 {
37967- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
37968+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
37969 }
37970
37971 struct md_personality
37972diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
37973index 1cbfc6b..56e1dbb 100644
37974--- a/drivers/md/persistent-data/dm-space-map.h
37975+++ b/drivers/md/persistent-data/dm-space-map.h
37976@@ -60,6 +60,7 @@ struct dm_space_map {
37977 int (*root_size)(struct dm_space_map *sm, size_t *result);
37978 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
37979 };
37980+typedef struct dm_space_map __no_const dm_space_map_no_const;
37981
37982 /*----------------------------------------------------------------*/
37983
37984diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
37985index 75b1f89..00ba344 100644
37986--- a/drivers/md/raid1.c
37987+++ b/drivers/md/raid1.c
37988@@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
37989 if (r1_sync_page_io(rdev, sect, s,
37990 bio->bi_io_vec[idx].bv_page,
37991 READ) != 0)
37992- atomic_add(s, &rdev->corrected_errors);
37993+ atomic_add_unchecked(s, &rdev->corrected_errors);
37994 }
37995 sectors -= s;
37996 sect += s;
37997@@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
37998 test_bit(In_sync, &rdev->flags)) {
37999 if (r1_sync_page_io(rdev, sect, s,
38000 conf->tmppage, READ)) {
38001- atomic_add(s, &rdev->corrected_errors);
38002+ atomic_add_unchecked(s, &rdev->corrected_errors);
38003 printk(KERN_INFO
38004 "md/raid1:%s: read error corrected "
38005 "(%d sectors at %llu on %s)\n",
38006diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
38007index 8d925dc..11d674f 100644
38008--- a/drivers/md/raid10.c
38009+++ b/drivers/md/raid10.c
38010@@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
38011 /* The write handler will notice the lack of
38012 * R10BIO_Uptodate and record any errors etc
38013 */
38014- atomic_add(r10_bio->sectors,
38015+ atomic_add_unchecked(r10_bio->sectors,
38016 &conf->mirrors[d].rdev->corrected_errors);
38017
38018 /* for reconstruct, we always reschedule after a read.
38019@@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38020 {
38021 struct timespec cur_time_mon;
38022 unsigned long hours_since_last;
38023- unsigned int read_errors = atomic_read(&rdev->read_errors);
38024+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
38025
38026 ktime_get_ts(&cur_time_mon);
38027
38028@@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38029 * overflowing the shift of read_errors by hours_since_last.
38030 */
38031 if (hours_since_last >= 8 * sizeof(read_errors))
38032- atomic_set(&rdev->read_errors, 0);
38033+ atomic_set_unchecked(&rdev->read_errors, 0);
38034 else
38035- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
38036+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
38037 }
38038
38039 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
38040@@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38041 return;
38042
38043 check_decay_read_errors(mddev, rdev);
38044- atomic_inc(&rdev->read_errors);
38045- if (atomic_read(&rdev->read_errors) > max_read_errors) {
38046+ atomic_inc_unchecked(&rdev->read_errors);
38047+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
38048 char b[BDEVNAME_SIZE];
38049 bdevname(rdev->bdev, b);
38050
38051@@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38052 "md/raid10:%s: %s: Raid device exceeded "
38053 "read_error threshold [cur %d:max %d]\n",
38054 mdname(mddev), b,
38055- atomic_read(&rdev->read_errors), max_read_errors);
38056+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
38057 printk(KERN_NOTICE
38058 "md/raid10:%s: %s: Failing raid device\n",
38059 mdname(mddev), b);
38060@@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38061 sect +
38062 choose_data_offset(r10_bio, rdev)),
38063 bdevname(rdev->bdev, b));
38064- atomic_add(s, &rdev->corrected_errors);
38065+ atomic_add_unchecked(s, &rdev->corrected_errors);
38066 }
38067
38068 rdev_dec_pending(rdev, mddev);
38069diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
38070index 94ce78e..df99e24 100644
38071--- a/drivers/md/raid5.c
38072+++ b/drivers/md/raid5.c
38073@@ -1800,21 +1800,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
38074 mdname(conf->mddev), STRIPE_SECTORS,
38075 (unsigned long long)s,
38076 bdevname(rdev->bdev, b));
38077- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
38078+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
38079 clear_bit(R5_ReadError, &sh->dev[i].flags);
38080 clear_bit(R5_ReWrite, &sh->dev[i].flags);
38081 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
38082 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
38083
38084- if (atomic_read(&rdev->read_errors))
38085- atomic_set(&rdev->read_errors, 0);
38086+ if (atomic_read_unchecked(&rdev->read_errors))
38087+ atomic_set_unchecked(&rdev->read_errors, 0);
38088 } else {
38089 const char *bdn = bdevname(rdev->bdev, b);
38090 int retry = 0;
38091 int set_bad = 0;
38092
38093 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
38094- atomic_inc(&rdev->read_errors);
38095+ atomic_inc_unchecked(&rdev->read_errors);
38096 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
38097 printk_ratelimited(
38098 KERN_WARNING
38099@@ -1842,7 +1842,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
38100 mdname(conf->mddev),
38101 (unsigned long long)s,
38102 bdn);
38103- } else if (atomic_read(&rdev->read_errors)
38104+ } else if (atomic_read_unchecked(&rdev->read_errors)
38105 > conf->max_nr_stripes)
38106 printk(KERN_WARNING
38107 "md/raid:%s: Too many read errors, failing device %s.\n",
38108diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
38109index d33101a..6b13069 100644
38110--- a/drivers/media/dvb-core/dvbdev.c
38111+++ b/drivers/media/dvb-core/dvbdev.c
38112@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
38113 const struct dvb_device *template, void *priv, int type)
38114 {
38115 struct dvb_device *dvbdev;
38116- struct file_operations *dvbdevfops;
38117+ file_operations_no_const *dvbdevfops;
38118 struct device *clsdev;
38119 int minor;
38120 int id;
38121diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
38122index 404f63a..4796533 100644
38123--- a/drivers/media/dvb-frontends/dib3000.h
38124+++ b/drivers/media/dvb-frontends/dib3000.h
38125@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
38126 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
38127 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
38128 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
38129-};
38130+} __no_const;
38131
38132 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
38133 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
38134diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
38135index 8e9a668..78d6310 100644
38136--- a/drivers/media/platform/omap/omap_vout.c
38137+++ b/drivers/media/platform/omap/omap_vout.c
38138@@ -63,7 +63,6 @@ enum omap_vout_channels {
38139 OMAP_VIDEO2,
38140 };
38141
38142-static struct videobuf_queue_ops video_vbq_ops;
38143 /* Variables configurable through module params*/
38144 static u32 video1_numbuffers = 3;
38145 static u32 video2_numbuffers = 3;
38146@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
38147 {
38148 struct videobuf_queue *q;
38149 struct omap_vout_device *vout = NULL;
38150+ static struct videobuf_queue_ops video_vbq_ops = {
38151+ .buf_setup = omap_vout_buffer_setup,
38152+ .buf_prepare = omap_vout_buffer_prepare,
38153+ .buf_release = omap_vout_buffer_release,
38154+ .buf_queue = omap_vout_buffer_queue,
38155+ };
38156
38157 vout = video_drvdata(file);
38158 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
38159@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
38160 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
38161
38162 q = &vout->vbq;
38163- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
38164- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
38165- video_vbq_ops.buf_release = omap_vout_buffer_release;
38166- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
38167 spin_lock_init(&vout->vbq_lock);
38168
38169 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
38170diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
38171index b671e20..34088b7 100644
38172--- a/drivers/media/platform/s5p-tv/mixer.h
38173+++ b/drivers/media/platform/s5p-tv/mixer.h
38174@@ -155,7 +155,7 @@ struct mxr_layer {
38175 /** layer index (unique identifier) */
38176 int idx;
38177 /** callbacks for layer methods */
38178- struct mxr_layer_ops ops;
38179+ struct mxr_layer_ops *ops;
38180 /** format array */
38181 const struct mxr_format **fmt_array;
38182 /** size of format array */
38183diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38184index b93a21f..2535195 100644
38185--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38186+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38187@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
38188 {
38189 struct mxr_layer *layer;
38190 int ret;
38191- struct mxr_layer_ops ops = {
38192+ static struct mxr_layer_ops ops = {
38193 .release = mxr_graph_layer_release,
38194 .buffer_set = mxr_graph_buffer_set,
38195 .stream_set = mxr_graph_stream_set,
38196diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
38197index 3b1670a..595c939 100644
38198--- a/drivers/media/platform/s5p-tv/mixer_reg.c
38199+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
38200@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
38201 layer->update_buf = next;
38202 }
38203
38204- layer->ops.buffer_set(layer, layer->update_buf);
38205+ layer->ops->buffer_set(layer, layer->update_buf);
38206
38207 if (done && done != layer->shadow_buf)
38208 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
38209diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
38210index 1f3b743..e839271 100644
38211--- a/drivers/media/platform/s5p-tv/mixer_video.c
38212+++ b/drivers/media/platform/s5p-tv/mixer_video.c
38213@@ -208,7 +208,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
38214 layer->geo.src.height = layer->geo.src.full_height;
38215
38216 mxr_geometry_dump(mdev, &layer->geo);
38217- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38218+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38219 mxr_geometry_dump(mdev, &layer->geo);
38220 }
38221
38222@@ -226,7 +226,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
38223 layer->geo.dst.full_width = mbus_fmt.width;
38224 layer->geo.dst.full_height = mbus_fmt.height;
38225 layer->geo.dst.field = mbus_fmt.field;
38226- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38227+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38228
38229 mxr_geometry_dump(mdev, &layer->geo);
38230 }
38231@@ -332,7 +332,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
38232 /* set source size to highest accepted value */
38233 geo->src.full_width = max(geo->dst.full_width, pix->width);
38234 geo->src.full_height = max(geo->dst.full_height, pix->height);
38235- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38236+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38237 mxr_geometry_dump(mdev, &layer->geo);
38238 /* set cropping to total visible screen */
38239 geo->src.width = pix->width;
38240@@ -340,12 +340,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
38241 geo->src.x_offset = 0;
38242 geo->src.y_offset = 0;
38243 /* assure consistency of geometry */
38244- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38245+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38246 mxr_geometry_dump(mdev, &layer->geo);
38247 /* set full size to lowest possible value */
38248 geo->src.full_width = 0;
38249 geo->src.full_height = 0;
38250- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38251+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38252 mxr_geometry_dump(mdev, &layer->geo);
38253
38254 /* returning results */
38255@@ -472,7 +472,7 @@ static int mxr_s_selection(struct file *file, void *fh,
38256 target->width = s->r.width;
38257 target->height = s->r.height;
38258
38259- layer->ops.fix_geometry(layer, stage, s->flags);
38260+ layer->ops->fix_geometry(layer, stage, s->flags);
38261
38262 /* retrieve update selection rectangle */
38263 res.left = target->x_offset;
38264@@ -937,13 +937,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
38265 mxr_output_get(mdev);
38266
38267 mxr_layer_update_output(layer);
38268- layer->ops.format_set(layer);
38269+ layer->ops->format_set(layer);
38270 /* enabling layer in hardware */
38271 spin_lock_irqsave(&layer->enq_slock, flags);
38272 layer->state = MXR_LAYER_STREAMING;
38273 spin_unlock_irqrestore(&layer->enq_slock, flags);
38274
38275- layer->ops.stream_set(layer, MXR_ENABLE);
38276+ layer->ops->stream_set(layer, MXR_ENABLE);
38277 mxr_streamer_get(mdev);
38278
38279 return 0;
38280@@ -1013,7 +1013,7 @@ static int stop_streaming(struct vb2_queue *vq)
38281 spin_unlock_irqrestore(&layer->enq_slock, flags);
38282
38283 /* disabling layer in hardware */
38284- layer->ops.stream_set(layer, MXR_DISABLE);
38285+ layer->ops->stream_set(layer, MXR_DISABLE);
38286 /* remove one streamer */
38287 mxr_streamer_put(mdev);
38288 /* allow changes in output configuration */
38289@@ -1052,8 +1052,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
38290
38291 void mxr_layer_release(struct mxr_layer *layer)
38292 {
38293- if (layer->ops.release)
38294- layer->ops.release(layer);
38295+ if (layer->ops->release)
38296+ layer->ops->release(layer);
38297 }
38298
38299 void mxr_base_layer_release(struct mxr_layer *layer)
38300@@ -1079,7 +1079,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
38301
38302 layer->mdev = mdev;
38303 layer->idx = idx;
38304- layer->ops = *ops;
38305+ layer->ops = ops;
38306
38307 spin_lock_init(&layer->enq_slock);
38308 INIT_LIST_HEAD(&layer->enq_list);
38309diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38310index 3d13a63..da31bf1 100644
38311--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38312+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38313@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
38314 {
38315 struct mxr_layer *layer;
38316 int ret;
38317- struct mxr_layer_ops ops = {
38318+ static struct mxr_layer_ops ops = {
38319 .release = mxr_vp_layer_release,
38320 .buffer_set = mxr_vp_buffer_set,
38321 .stream_set = mxr_vp_stream_set,
38322diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
38323index 643d80a..56bb96b 100644
38324--- a/drivers/media/radio/radio-cadet.c
38325+++ b/drivers/media/radio/radio-cadet.c
38326@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38327 unsigned char readbuf[RDS_BUFFER];
38328 int i = 0;
38329
38330+ if (count > RDS_BUFFER)
38331+ return -EFAULT;
38332 mutex_lock(&dev->lock);
38333 if (dev->rdsstat == 0)
38334 cadet_start_rds(dev);
38335@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38336 while (i < count && dev->rdsin != dev->rdsout)
38337 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
38338
38339- if (i && copy_to_user(data, readbuf, i))
38340+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
38341 i = -EFAULT;
38342 unlock:
38343 mutex_unlock(&dev->lock);
38344diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
38345index 3940bb0..fb3952a 100644
38346--- a/drivers/media/usb/dvb-usb/cxusb.c
38347+++ b/drivers/media/usb/dvb-usb/cxusb.c
38348@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
38349
38350 struct dib0700_adapter_state {
38351 int (*set_param_save) (struct dvb_frontend *);
38352-};
38353+} __no_const;
38354
38355 static int dib7070_set_param_override(struct dvb_frontend *fe)
38356 {
38357diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
38358index 9382895..ac8093c 100644
38359--- a/drivers/media/usb/dvb-usb/dw2102.c
38360+++ b/drivers/media/usb/dvb-usb/dw2102.c
38361@@ -95,7 +95,7 @@ struct su3000_state {
38362
38363 struct s6x0_state {
38364 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
38365-};
38366+} __no_const;
38367
38368 /* debug */
38369 static int dvb_usb_dw2102_debug;
38370diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
38371index aa6e7c7..4cd8061 100644
38372--- a/drivers/media/v4l2-core/v4l2-ioctl.c
38373+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
38374@@ -1923,7 +1923,8 @@ struct v4l2_ioctl_info {
38375 struct file *file, void *fh, void *p);
38376 } u;
38377 void (*debug)(const void *arg, bool write_only);
38378-};
38379+} __do_const;
38380+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
38381
38382 /* This control needs a priority check */
38383 #define INFO_FL_PRIO (1 << 0)
38384@@ -2108,7 +2109,7 @@ static long __video_do_ioctl(struct file *file,
38385 struct video_device *vfd = video_devdata(file);
38386 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
38387 bool write_only = false;
38388- struct v4l2_ioctl_info default_info;
38389+ v4l2_ioctl_info_no_const default_info;
38390 const struct v4l2_ioctl_info *info;
38391 void *fh = file->private_data;
38392 struct v4l2_fh *vfh = NULL;
38393diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c
38394index 29b2172..a7c5b31 100644
38395--- a/drivers/memstick/host/r592.c
38396+++ b/drivers/memstick/host/r592.c
38397@@ -454,7 +454,7 @@ static int r592_transfer_fifo_pio(struct r592_device *dev)
38398 /* Executes one TPC (data is read/written from small or large fifo) */
38399 static void r592_execute_tpc(struct r592_device *dev)
38400 {
38401- bool is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38402+ bool is_write;
38403 int len, error;
38404 u32 status, reg;
38405
38406@@ -463,6 +463,7 @@ static void r592_execute_tpc(struct r592_device *dev)
38407 return;
38408 }
38409
38410+ is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38411 len = dev->req->long_data ?
38412 dev->req->sg.length : dev->req->data_len;
38413
38414diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
38415index fb69baa..3aeea2e 100644
38416--- a/drivers/message/fusion/mptbase.c
38417+++ b/drivers/message/fusion/mptbase.c
38418@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38419 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
38420 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
38421
38422+#ifdef CONFIG_GRKERNSEC_HIDESYM
38423+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
38424+#else
38425 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
38426 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
38427+#endif
38428+
38429 /*
38430 * Rounding UP to nearest 4-kB boundary here...
38431 */
38432@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38433 ioc->facts.GlobalCredits);
38434
38435 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
38436+#ifdef CONFIG_GRKERNSEC_HIDESYM
38437+ NULL, NULL);
38438+#else
38439 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
38440+#endif
38441 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
38442 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
38443 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
38444diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
38445index fa43c39..daeb158 100644
38446--- a/drivers/message/fusion/mptsas.c
38447+++ b/drivers/message/fusion/mptsas.c
38448@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
38449 return 0;
38450 }
38451
38452+static inline void
38453+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38454+{
38455+ if (phy_info->port_details) {
38456+ phy_info->port_details->rphy = rphy;
38457+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38458+ ioc->name, rphy));
38459+ }
38460+
38461+ if (rphy) {
38462+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38463+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38464+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38465+ ioc->name, rphy, rphy->dev.release));
38466+ }
38467+}
38468+
38469 /* no mutex */
38470 static void
38471 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
38472@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
38473 return NULL;
38474 }
38475
38476-static inline void
38477-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38478-{
38479- if (phy_info->port_details) {
38480- phy_info->port_details->rphy = rphy;
38481- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38482- ioc->name, rphy));
38483- }
38484-
38485- if (rphy) {
38486- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38487- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38488- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38489- ioc->name, rphy, rphy->dev.release));
38490- }
38491-}
38492-
38493 static inline struct sas_port *
38494 mptsas_get_port(struct mptsas_phyinfo *phy_info)
38495 {
38496diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
38497index 164afa7..b6b2e74 100644
38498--- a/drivers/message/fusion/mptscsih.c
38499+++ b/drivers/message/fusion/mptscsih.c
38500@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
38501
38502 h = shost_priv(SChost);
38503
38504- if (h) {
38505- if (h->info_kbuf == NULL)
38506- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38507- return h->info_kbuf;
38508- h->info_kbuf[0] = '\0';
38509+ if (!h)
38510+ return NULL;
38511
38512- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38513- h->info_kbuf[size-1] = '\0';
38514- }
38515+ if (h->info_kbuf == NULL)
38516+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38517+ return h->info_kbuf;
38518+ h->info_kbuf[0] = '\0';
38519+
38520+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38521+ h->info_kbuf[size-1] = '\0';
38522
38523 return h->info_kbuf;
38524 }
38525diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
38526index 8001aa6..b137580 100644
38527--- a/drivers/message/i2o/i2o_proc.c
38528+++ b/drivers/message/i2o/i2o_proc.c
38529@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
38530 "Array Controller Device"
38531 };
38532
38533-static char *chtostr(char *tmp, u8 *chars, int n)
38534-{
38535- tmp[0] = 0;
38536- return strncat(tmp, (char *)chars, n);
38537-}
38538-
38539 static int i2o_report_query_status(struct seq_file *seq, int block_status,
38540 char *group)
38541 {
38542@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38543 } *result;
38544
38545 i2o_exec_execute_ddm_table ddm_table;
38546- char tmp[28 + 1];
38547
38548 result = kmalloc(sizeof(*result), GFP_KERNEL);
38549 if (!result)
38550@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38551
38552 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
38553 seq_printf(seq, "%-#8x", ddm_table.module_id);
38554- seq_printf(seq, "%-29s",
38555- chtostr(tmp, ddm_table.module_name_version, 28));
38556+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
38557 seq_printf(seq, "%9d ", ddm_table.data_size);
38558 seq_printf(seq, "%8d", ddm_table.code_size);
38559
38560@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38561
38562 i2o_driver_result_table *result;
38563 i2o_driver_store_table *dst;
38564- char tmp[28 + 1];
38565
38566 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
38567 if (result == NULL)
38568@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38569
38570 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
38571 seq_printf(seq, "%-#8x", dst->module_id);
38572- seq_printf(seq, "%-29s",
38573- chtostr(tmp, dst->module_name_version, 28));
38574- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
38575+ seq_printf(seq, "%-.28s", dst->module_name_version);
38576+ seq_printf(seq, "%-.8s", dst->date);
38577 seq_printf(seq, "%8d ", dst->module_size);
38578 seq_printf(seq, "%8d ", dst->mpb_size);
38579 seq_printf(seq, "0x%04x", dst->module_flags);
38580@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38581 // == (allow) 512d bytes (max)
38582 static u16 *work16 = (u16 *) work32;
38583 int token;
38584- char tmp[16 + 1];
38585
38586 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
38587
38588@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38589 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
38590 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
38591 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
38592- seq_printf(seq, "Vendor info : %s\n",
38593- chtostr(tmp, (u8 *) (work32 + 2), 16));
38594- seq_printf(seq, "Product info : %s\n",
38595- chtostr(tmp, (u8 *) (work32 + 6), 16));
38596- seq_printf(seq, "Description : %s\n",
38597- chtostr(tmp, (u8 *) (work32 + 10), 16));
38598- seq_printf(seq, "Product rev. : %s\n",
38599- chtostr(tmp, (u8 *) (work32 + 14), 8));
38600+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
38601+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
38602+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
38603+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
38604
38605 seq_printf(seq, "Serial number : ");
38606 print_serial_number(seq, (u8 *) (work32 + 16),
38607@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38608 u8 pad[256]; // allow up to 256 byte (max) serial number
38609 } result;
38610
38611- char tmp[24 + 1];
38612-
38613 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
38614
38615 if (token < 0) {
38616@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38617 }
38618
38619 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
38620- seq_printf(seq, "Module name : %s\n",
38621- chtostr(tmp, result.module_name, 24));
38622- seq_printf(seq, "Module revision : %s\n",
38623- chtostr(tmp, result.module_rev, 8));
38624+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
38625+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
38626
38627 seq_printf(seq, "Serial number : ");
38628 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
38629@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38630 u8 instance_number[4];
38631 } result;
38632
38633- char tmp[64 + 1];
38634-
38635 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
38636
38637 if (token < 0) {
38638@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38639 return 0;
38640 }
38641
38642- seq_printf(seq, "Device name : %s\n",
38643- chtostr(tmp, result.device_name, 64));
38644- seq_printf(seq, "Service name : %s\n",
38645- chtostr(tmp, result.service_name, 64));
38646- seq_printf(seq, "Physical name : %s\n",
38647- chtostr(tmp, result.physical_location, 64));
38648- seq_printf(seq, "Instance number : %s\n",
38649- chtostr(tmp, result.instance_number, 4));
38650+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
38651+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
38652+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
38653+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
38654
38655 return 0;
38656 }
38657diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
38658index a8c08f3..155fe3d 100644
38659--- a/drivers/message/i2o/iop.c
38660+++ b/drivers/message/i2o/iop.c
38661@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
38662
38663 spin_lock_irqsave(&c->context_list_lock, flags);
38664
38665- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
38666- atomic_inc(&c->context_list_counter);
38667+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
38668+ atomic_inc_unchecked(&c->context_list_counter);
38669
38670- entry->context = atomic_read(&c->context_list_counter);
38671+ entry->context = atomic_read_unchecked(&c->context_list_counter);
38672
38673 list_add(&entry->list, &c->context_list);
38674
38675@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
38676
38677 #if BITS_PER_LONG == 64
38678 spin_lock_init(&c->context_list_lock);
38679- atomic_set(&c->context_list_counter, 0);
38680+ atomic_set_unchecked(&c->context_list_counter, 0);
38681 INIT_LIST_HEAD(&c->context_list);
38682 #endif
38683
38684diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
38685index 45ece11..8efa218 100644
38686--- a/drivers/mfd/janz-cmodio.c
38687+++ b/drivers/mfd/janz-cmodio.c
38688@@ -13,6 +13,7 @@
38689
38690 #include <linux/kernel.h>
38691 #include <linux/module.h>
38692+#include <linux/slab.h>
38693 #include <linux/init.h>
38694 #include <linux/pci.h>
38695 #include <linux/interrupt.h>
38696diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
38697index a5f9888..1c0ed56 100644
38698--- a/drivers/mfd/twl4030-irq.c
38699+++ b/drivers/mfd/twl4030-irq.c
38700@@ -35,6 +35,7 @@
38701 #include <linux/of.h>
38702 #include <linux/irqdomain.h>
38703 #include <linux/i2c/twl.h>
38704+#include <asm/pgtable.h>
38705
38706 #include "twl-core.h"
38707
38708@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
38709 * Install an irq handler for each of the SIH modules;
38710 * clone dummy irq_chip since PIH can't *do* anything
38711 */
38712- twl4030_irq_chip = dummy_irq_chip;
38713- twl4030_irq_chip.name = "twl4030";
38714+ pax_open_kernel();
38715+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
38716+ *(const char **)&twl4030_irq_chip.name = "twl4030";
38717
38718- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
38719+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
38720+ pax_close_kernel();
38721
38722 for (i = irq_base; i < irq_end; i++) {
38723 irq_set_chip_and_handler(i, &twl4030_irq_chip,
38724diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
38725index 277a8db..0e0b754 100644
38726--- a/drivers/mfd/twl6030-irq.c
38727+++ b/drivers/mfd/twl6030-irq.c
38728@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
38729 * install an irq handler for each of the modules;
38730 * clone dummy irq_chip since PIH can't *do* anything
38731 */
38732- twl6030_irq_chip = dummy_irq_chip;
38733- twl6030_irq_chip.name = "twl6030";
38734- twl6030_irq_chip.irq_set_type = NULL;
38735- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
38736+ pax_open_kernel();
38737+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
38738+ *(const char **)&twl6030_irq_chip.name = "twl6030";
38739+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
38740+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
38741+ pax_close_kernel();
38742
38743 for (i = irq_base; i < irq_end; i++) {
38744 irq_set_chip_and_handler(i, &twl6030_irq_chip,
38745diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
38746index f428d86..274c368 100644
38747--- a/drivers/misc/c2port/core.c
38748+++ b/drivers/misc/c2port/core.c
38749@@ -924,7 +924,9 @@ struct c2port_device *c2port_device_register(char *name,
38750 mutex_init(&c2dev->mutex);
38751
38752 /* Create binary file */
38753- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
38754+ pax_open_kernel();
38755+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
38756+ pax_close_kernel();
38757 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
38758 if (unlikely(ret))
38759 goto error_device_create_bin_file;
38760diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
38761index 3aa9a96..59cf685 100644
38762--- a/drivers/misc/kgdbts.c
38763+++ b/drivers/misc/kgdbts.c
38764@@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
38765 char before[BREAK_INSTR_SIZE];
38766 char after[BREAK_INSTR_SIZE];
38767
38768- probe_kernel_read(before, (char *)kgdbts_break_test,
38769+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
38770 BREAK_INSTR_SIZE);
38771 init_simple_test();
38772 ts.tst = plant_and_detach_test;
38773@@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
38774 /* Activate test with initial breakpoint */
38775 if (!is_early)
38776 kgdb_breakpoint();
38777- probe_kernel_read(after, (char *)kgdbts_break_test,
38778+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
38779 BREAK_INSTR_SIZE);
38780 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
38781 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
38782diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
38783index 4a87e5c..76bdf5c 100644
38784--- a/drivers/misc/lis3lv02d/lis3lv02d.c
38785+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
38786@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
38787 * the lid is closed. This leads to interrupts as soon as a little move
38788 * is done.
38789 */
38790- atomic_inc(&lis3->count);
38791+ atomic_inc_unchecked(&lis3->count);
38792
38793 wake_up_interruptible(&lis3->misc_wait);
38794 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
38795@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
38796 if (lis3->pm_dev)
38797 pm_runtime_get_sync(lis3->pm_dev);
38798
38799- atomic_set(&lis3->count, 0);
38800+ atomic_set_unchecked(&lis3->count, 0);
38801 return 0;
38802 }
38803
38804@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
38805 add_wait_queue(&lis3->misc_wait, &wait);
38806 while (true) {
38807 set_current_state(TASK_INTERRUPTIBLE);
38808- data = atomic_xchg(&lis3->count, 0);
38809+ data = atomic_xchg_unchecked(&lis3->count, 0);
38810 if (data)
38811 break;
38812
38813@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
38814 struct lis3lv02d, miscdev);
38815
38816 poll_wait(file, &lis3->misc_wait, wait);
38817- if (atomic_read(&lis3->count))
38818+ if (atomic_read_unchecked(&lis3->count))
38819 return POLLIN | POLLRDNORM;
38820 return 0;
38821 }
38822diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
38823index c439c82..1f20f57 100644
38824--- a/drivers/misc/lis3lv02d/lis3lv02d.h
38825+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
38826@@ -297,7 +297,7 @@ struct lis3lv02d {
38827 struct input_polled_dev *idev; /* input device */
38828 struct platform_device *pdev; /* platform device */
38829 struct regulator_bulk_data regulators[2];
38830- atomic_t count; /* interrupt count after last read */
38831+ atomic_unchecked_t count; /* interrupt count after last read */
38832 union axis_conversion ac; /* hw -> logical axis */
38833 int mapped_btns[3];
38834
38835diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
38836index 2f30bad..c4c13d0 100644
38837--- a/drivers/misc/sgi-gru/gruhandles.c
38838+++ b/drivers/misc/sgi-gru/gruhandles.c
38839@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
38840 unsigned long nsec;
38841
38842 nsec = CLKS2NSEC(clks);
38843- atomic_long_inc(&mcs_op_statistics[op].count);
38844- atomic_long_add(nsec, &mcs_op_statistics[op].total);
38845+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
38846+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
38847 if (mcs_op_statistics[op].max < nsec)
38848 mcs_op_statistics[op].max = nsec;
38849 }
38850diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
38851index 950dbe9..eeef0f8 100644
38852--- a/drivers/misc/sgi-gru/gruprocfs.c
38853+++ b/drivers/misc/sgi-gru/gruprocfs.c
38854@@ -32,9 +32,9 @@
38855
38856 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
38857
38858-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
38859+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
38860 {
38861- unsigned long val = atomic_long_read(v);
38862+ unsigned long val = atomic_long_read_unchecked(v);
38863
38864 seq_printf(s, "%16lu %s\n", val, id);
38865 }
38866@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
38867
38868 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
38869 for (op = 0; op < mcsop_last; op++) {
38870- count = atomic_long_read(&mcs_op_statistics[op].count);
38871- total = atomic_long_read(&mcs_op_statistics[op].total);
38872+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
38873+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
38874 max = mcs_op_statistics[op].max;
38875 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
38876 count ? total / count : 0, max);
38877diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
38878index 5c3ce24..4915ccb 100644
38879--- a/drivers/misc/sgi-gru/grutables.h
38880+++ b/drivers/misc/sgi-gru/grutables.h
38881@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
38882 * GRU statistics.
38883 */
38884 struct gru_stats_s {
38885- atomic_long_t vdata_alloc;
38886- atomic_long_t vdata_free;
38887- atomic_long_t gts_alloc;
38888- atomic_long_t gts_free;
38889- atomic_long_t gms_alloc;
38890- atomic_long_t gms_free;
38891- atomic_long_t gts_double_allocate;
38892- atomic_long_t assign_context;
38893- atomic_long_t assign_context_failed;
38894- atomic_long_t free_context;
38895- atomic_long_t load_user_context;
38896- atomic_long_t load_kernel_context;
38897- atomic_long_t lock_kernel_context;
38898- atomic_long_t unlock_kernel_context;
38899- atomic_long_t steal_user_context;
38900- atomic_long_t steal_kernel_context;
38901- atomic_long_t steal_context_failed;
38902- atomic_long_t nopfn;
38903- atomic_long_t asid_new;
38904- atomic_long_t asid_next;
38905- atomic_long_t asid_wrap;
38906- atomic_long_t asid_reuse;
38907- atomic_long_t intr;
38908- atomic_long_t intr_cbr;
38909- atomic_long_t intr_tfh;
38910- atomic_long_t intr_spurious;
38911- atomic_long_t intr_mm_lock_failed;
38912- atomic_long_t call_os;
38913- atomic_long_t call_os_wait_queue;
38914- atomic_long_t user_flush_tlb;
38915- atomic_long_t user_unload_context;
38916- atomic_long_t user_exception;
38917- atomic_long_t set_context_option;
38918- atomic_long_t check_context_retarget_intr;
38919- atomic_long_t check_context_unload;
38920- atomic_long_t tlb_dropin;
38921- atomic_long_t tlb_preload_page;
38922- atomic_long_t tlb_dropin_fail_no_asid;
38923- atomic_long_t tlb_dropin_fail_upm;
38924- atomic_long_t tlb_dropin_fail_invalid;
38925- atomic_long_t tlb_dropin_fail_range_active;
38926- atomic_long_t tlb_dropin_fail_idle;
38927- atomic_long_t tlb_dropin_fail_fmm;
38928- atomic_long_t tlb_dropin_fail_no_exception;
38929- atomic_long_t tfh_stale_on_fault;
38930- atomic_long_t mmu_invalidate_range;
38931- atomic_long_t mmu_invalidate_page;
38932- atomic_long_t flush_tlb;
38933- atomic_long_t flush_tlb_gru;
38934- atomic_long_t flush_tlb_gru_tgh;
38935- atomic_long_t flush_tlb_gru_zero_asid;
38936+ atomic_long_unchecked_t vdata_alloc;
38937+ atomic_long_unchecked_t vdata_free;
38938+ atomic_long_unchecked_t gts_alloc;
38939+ atomic_long_unchecked_t gts_free;
38940+ atomic_long_unchecked_t gms_alloc;
38941+ atomic_long_unchecked_t gms_free;
38942+ atomic_long_unchecked_t gts_double_allocate;
38943+ atomic_long_unchecked_t assign_context;
38944+ atomic_long_unchecked_t assign_context_failed;
38945+ atomic_long_unchecked_t free_context;
38946+ atomic_long_unchecked_t load_user_context;
38947+ atomic_long_unchecked_t load_kernel_context;
38948+ atomic_long_unchecked_t lock_kernel_context;
38949+ atomic_long_unchecked_t unlock_kernel_context;
38950+ atomic_long_unchecked_t steal_user_context;
38951+ atomic_long_unchecked_t steal_kernel_context;
38952+ atomic_long_unchecked_t steal_context_failed;
38953+ atomic_long_unchecked_t nopfn;
38954+ atomic_long_unchecked_t asid_new;
38955+ atomic_long_unchecked_t asid_next;
38956+ atomic_long_unchecked_t asid_wrap;
38957+ atomic_long_unchecked_t asid_reuse;
38958+ atomic_long_unchecked_t intr;
38959+ atomic_long_unchecked_t intr_cbr;
38960+ atomic_long_unchecked_t intr_tfh;
38961+ atomic_long_unchecked_t intr_spurious;
38962+ atomic_long_unchecked_t intr_mm_lock_failed;
38963+ atomic_long_unchecked_t call_os;
38964+ atomic_long_unchecked_t call_os_wait_queue;
38965+ atomic_long_unchecked_t user_flush_tlb;
38966+ atomic_long_unchecked_t user_unload_context;
38967+ atomic_long_unchecked_t user_exception;
38968+ atomic_long_unchecked_t set_context_option;
38969+ atomic_long_unchecked_t check_context_retarget_intr;
38970+ atomic_long_unchecked_t check_context_unload;
38971+ atomic_long_unchecked_t tlb_dropin;
38972+ atomic_long_unchecked_t tlb_preload_page;
38973+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
38974+ atomic_long_unchecked_t tlb_dropin_fail_upm;
38975+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
38976+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
38977+ atomic_long_unchecked_t tlb_dropin_fail_idle;
38978+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
38979+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
38980+ atomic_long_unchecked_t tfh_stale_on_fault;
38981+ atomic_long_unchecked_t mmu_invalidate_range;
38982+ atomic_long_unchecked_t mmu_invalidate_page;
38983+ atomic_long_unchecked_t flush_tlb;
38984+ atomic_long_unchecked_t flush_tlb_gru;
38985+ atomic_long_unchecked_t flush_tlb_gru_tgh;
38986+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
38987
38988- atomic_long_t copy_gpa;
38989- atomic_long_t read_gpa;
38990+ atomic_long_unchecked_t copy_gpa;
38991+ atomic_long_unchecked_t read_gpa;
38992
38993- atomic_long_t mesq_receive;
38994- atomic_long_t mesq_receive_none;
38995- atomic_long_t mesq_send;
38996- atomic_long_t mesq_send_failed;
38997- atomic_long_t mesq_noop;
38998- atomic_long_t mesq_send_unexpected_error;
38999- atomic_long_t mesq_send_lb_overflow;
39000- atomic_long_t mesq_send_qlimit_reached;
39001- atomic_long_t mesq_send_amo_nacked;
39002- atomic_long_t mesq_send_put_nacked;
39003- atomic_long_t mesq_page_overflow;
39004- atomic_long_t mesq_qf_locked;
39005- atomic_long_t mesq_qf_noop_not_full;
39006- atomic_long_t mesq_qf_switch_head_failed;
39007- atomic_long_t mesq_qf_unexpected_error;
39008- atomic_long_t mesq_noop_unexpected_error;
39009- atomic_long_t mesq_noop_lb_overflow;
39010- atomic_long_t mesq_noop_qlimit_reached;
39011- atomic_long_t mesq_noop_amo_nacked;
39012- atomic_long_t mesq_noop_put_nacked;
39013- atomic_long_t mesq_noop_page_overflow;
39014+ atomic_long_unchecked_t mesq_receive;
39015+ atomic_long_unchecked_t mesq_receive_none;
39016+ atomic_long_unchecked_t mesq_send;
39017+ atomic_long_unchecked_t mesq_send_failed;
39018+ atomic_long_unchecked_t mesq_noop;
39019+ atomic_long_unchecked_t mesq_send_unexpected_error;
39020+ atomic_long_unchecked_t mesq_send_lb_overflow;
39021+ atomic_long_unchecked_t mesq_send_qlimit_reached;
39022+ atomic_long_unchecked_t mesq_send_amo_nacked;
39023+ atomic_long_unchecked_t mesq_send_put_nacked;
39024+ atomic_long_unchecked_t mesq_page_overflow;
39025+ atomic_long_unchecked_t mesq_qf_locked;
39026+ atomic_long_unchecked_t mesq_qf_noop_not_full;
39027+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
39028+ atomic_long_unchecked_t mesq_qf_unexpected_error;
39029+ atomic_long_unchecked_t mesq_noop_unexpected_error;
39030+ atomic_long_unchecked_t mesq_noop_lb_overflow;
39031+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
39032+ atomic_long_unchecked_t mesq_noop_amo_nacked;
39033+ atomic_long_unchecked_t mesq_noop_put_nacked;
39034+ atomic_long_unchecked_t mesq_noop_page_overflow;
39035
39036 };
39037
39038@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
39039 tghop_invalidate, mcsop_last};
39040
39041 struct mcs_op_statistic {
39042- atomic_long_t count;
39043- atomic_long_t total;
39044+ atomic_long_unchecked_t count;
39045+ atomic_long_unchecked_t total;
39046 unsigned long max;
39047 };
39048
39049@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
39050
39051 #define STAT(id) do { \
39052 if (gru_options & OPT_STATS) \
39053- atomic_long_inc(&gru_stats.id); \
39054+ atomic_long_inc_unchecked(&gru_stats.id); \
39055 } while (0)
39056
39057 #ifdef CONFIG_SGI_GRU_DEBUG
39058diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
39059index c862cd4..0d176fe 100644
39060--- a/drivers/misc/sgi-xp/xp.h
39061+++ b/drivers/misc/sgi-xp/xp.h
39062@@ -288,7 +288,7 @@ struct xpc_interface {
39063 xpc_notify_func, void *);
39064 void (*received) (short, int, void *);
39065 enum xp_retval (*partid_to_nasids) (short, void *);
39066-};
39067+} __no_const;
39068
39069 extern struct xpc_interface xpc_interface;
39070
39071diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
39072index b94d5f7..7f494c5 100644
39073--- a/drivers/misc/sgi-xp/xpc.h
39074+++ b/drivers/misc/sgi-xp/xpc.h
39075@@ -835,6 +835,7 @@ struct xpc_arch_operations {
39076 void (*received_payload) (struct xpc_channel *, void *);
39077 void (*notify_senders_of_disconnect) (struct xpc_channel *);
39078 };
39079+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
39080
39081 /* struct xpc_partition act_state values (for XPC HB) */
39082
39083@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
39084 /* found in xpc_main.c */
39085 extern struct device *xpc_part;
39086 extern struct device *xpc_chan;
39087-extern struct xpc_arch_operations xpc_arch_ops;
39088+extern xpc_arch_operations_no_const xpc_arch_ops;
39089 extern int xpc_disengage_timelimit;
39090 extern int xpc_disengage_timedout;
39091 extern int xpc_activate_IRQ_rcvd;
39092diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
39093index d971817..33bdca5 100644
39094--- a/drivers/misc/sgi-xp/xpc_main.c
39095+++ b/drivers/misc/sgi-xp/xpc_main.c
39096@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
39097 .notifier_call = xpc_system_die,
39098 };
39099
39100-struct xpc_arch_operations xpc_arch_ops;
39101+xpc_arch_operations_no_const xpc_arch_ops;
39102
39103 /*
39104 * Timer function to enforce the timelimit on the partition disengage.
39105@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
39106
39107 if (((die_args->trapnr == X86_TRAP_MF) ||
39108 (die_args->trapnr == X86_TRAP_XF)) &&
39109- !user_mode_vm(die_args->regs))
39110+ !user_mode(die_args->regs))
39111 xpc_die_deactivate();
39112
39113 break;
39114diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
39115index 6d8f701..35b6369 100644
39116--- a/drivers/mmc/core/mmc_ops.c
39117+++ b/drivers/mmc/core/mmc_ops.c
39118@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
39119 void *data_buf;
39120 int is_on_stack;
39121
39122- is_on_stack = object_is_on_stack(buf);
39123+ is_on_stack = object_starts_on_stack(buf);
39124 if (is_on_stack) {
39125 /*
39126 * dma onto stack is unsafe/nonportable, but callers to this
39127diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
39128index 53b8fd9..615b462 100644
39129--- a/drivers/mmc/host/dw_mmc.h
39130+++ b/drivers/mmc/host/dw_mmc.h
39131@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
39132 int (*parse_dt)(struct dw_mci *host);
39133 int (*setup_bus)(struct dw_mci *host,
39134 struct device_node *slot_np, u8 bus_width);
39135-};
39136+} __do_const;
39137 #endif /* _DW_MMC_H_ */
39138diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
39139index 82a8de1..3c56ccb 100644
39140--- a/drivers/mmc/host/sdhci-s3c.c
39141+++ b/drivers/mmc/host/sdhci-s3c.c
39142@@ -721,9 +721,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
39143 * we can use overriding functions instead of default.
39144 */
39145 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
39146- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39147- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39148- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39149+ pax_open_kernel();
39150+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39151+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39152+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39153+ pax_close_kernel();
39154 }
39155
39156 /* It supports additional host capabilities if needed */
39157diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
39158index a4eb8b5..8c0628f 100644
39159--- a/drivers/mtd/devices/doc2000.c
39160+++ b/drivers/mtd/devices/doc2000.c
39161@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
39162
39163 /* The ECC will not be calculated correctly if less than 512 is written */
39164 /* DBB-
39165- if (len != 0x200 && eccbuf)
39166+ if (len != 0x200)
39167 printk(KERN_WARNING
39168 "ECC needs a full sector write (adr: %lx size %lx)\n",
39169 (long) to, (long) len);
39170diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
39171index 0c8bb6b..6f35deb 100644
39172--- a/drivers/mtd/nand/denali.c
39173+++ b/drivers/mtd/nand/denali.c
39174@@ -24,6 +24,7 @@
39175 #include <linux/slab.h>
39176 #include <linux/mtd/mtd.h>
39177 #include <linux/module.h>
39178+#include <linux/slab.h>
39179
39180 #include "denali.h"
39181
39182diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
39183index 51b9d6a..52af9a7 100644
39184--- a/drivers/mtd/nftlmount.c
39185+++ b/drivers/mtd/nftlmount.c
39186@@ -24,6 +24,7 @@
39187 #include <asm/errno.h>
39188 #include <linux/delay.h>
39189 #include <linux/slab.h>
39190+#include <linux/sched.h>
39191 #include <linux/mtd/mtd.h>
39192 #include <linux/mtd/nand.h>
39193 #include <linux/mtd/nftl.h>
39194diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
39195index 8dd6ba5..419cc1d 100644
39196--- a/drivers/mtd/sm_ftl.c
39197+++ b/drivers/mtd/sm_ftl.c
39198@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
39199 #define SM_CIS_VENDOR_OFFSET 0x59
39200 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
39201 {
39202- struct attribute_group *attr_group;
39203+ attribute_group_no_const *attr_group;
39204 struct attribute **attributes;
39205 struct sm_sysfs_attribute *vendor_attribute;
39206
39207diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
39208index 272f81a..c3d767c 100644
39209--- a/drivers/net/bonding/bond_main.c
39210+++ b/drivers/net/bonding/bond_main.c
39211@@ -4860,7 +4860,7 @@ static unsigned int bond_get_num_tx_queues(void)
39212 return tx_queues;
39213 }
39214
39215-static struct rtnl_link_ops bond_link_ops __read_mostly = {
39216+static struct rtnl_link_ops bond_link_ops = {
39217 .kind = "bond",
39218 .priv_size = sizeof(struct bonding),
39219 .setup = bond_setup,
39220diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
39221index 70dba5d..11a0919 100644
39222--- a/drivers/net/ethernet/8390/ax88796.c
39223+++ b/drivers/net/ethernet/8390/ax88796.c
39224@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
39225 if (ax->plat->reg_offsets)
39226 ei_local->reg_offset = ax->plat->reg_offsets;
39227 else {
39228+ resource_size_t _mem_size = mem_size;
39229+ do_div(_mem_size, 0x18);
39230 ei_local->reg_offset = ax->reg_offsets;
39231 for (ret = 0; ret < 0x18; ret++)
39232- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
39233+ ax->reg_offsets[ret] = _mem_size * ret;
39234 }
39235
39236 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
39237diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39238index 0991534..8098e92 100644
39239--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39240+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39241@@ -1094,7 +1094,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
39242 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
39243 {
39244 /* RX_MODE controlling object */
39245- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
39246+ bnx2x_init_rx_mode_obj(bp);
39247
39248 /* multicast configuration controlling object */
39249 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
39250diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39251index 09b625e..15b16fe 100644
39252--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39253+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39254@@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
39255 return rc;
39256 }
39257
39258-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39259- struct bnx2x_rx_mode_obj *o)
39260+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
39261 {
39262 if (CHIP_IS_E1x(bp)) {
39263- o->wait_comp = bnx2x_empty_rx_mode_wait;
39264- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
39265+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
39266+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
39267 } else {
39268- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
39269- o->config_rx_mode = bnx2x_set_rx_mode_e2;
39270+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
39271+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
39272 }
39273 }
39274
39275diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39276index adbd91b..58ec94a 100644
39277--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39278+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39279@@ -1293,8 +1293,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
39280
39281 /********************* RX MODE ****************/
39282
39283-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39284- struct bnx2x_rx_mode_obj *o);
39285+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
39286
39287 /**
39288 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
39289diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
39290index 3ec98f2..b9980e0 100644
39291--- a/drivers/net/ethernet/broadcom/tg3.c
39292+++ b/drivers/net/ethernet/broadcom/tg3.c
39293@@ -14403,8 +14403,10 @@ static void tg3_read_vpd(struct tg3 *tp)
39294 if (j + len > block_end)
39295 goto partno;
39296
39297- memcpy(tp->fw_ver, &vpd_data[j], len);
39298- strncat(tp->fw_ver, " bc ", vpdlen - len - 1);
39299+ if (len >= sizeof(tp->fw_ver))
39300+ len = sizeof(tp->fw_ver) - 1;
39301+ memset(tp->fw_ver, 0, sizeof(tp->fw_ver));
39302+ snprintf(tp->fw_ver, sizeof(tp->fw_ver), "%.*s bc ", len, &vpd_data[j]);
39303 }
39304
39305 partno:
39306diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
39307index d330e81..ce1fb9a 100644
39308--- a/drivers/net/ethernet/broadcom/tg3.h
39309+++ b/drivers/net/ethernet/broadcom/tg3.h
39310@@ -146,6 +146,7 @@
39311 #define CHIPREV_ID_5750_A0 0x4000
39312 #define CHIPREV_ID_5750_A1 0x4001
39313 #define CHIPREV_ID_5750_A3 0x4003
39314+#define CHIPREV_ID_5750_C1 0x4201
39315 #define CHIPREV_ID_5750_C2 0x4202
39316 #define CHIPREV_ID_5752_A0_HW 0x5000
39317 #define CHIPREV_ID_5752_A0 0x6000
39318diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39319index 8cffcdf..aadf043 100644
39320--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39321+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39322@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
39323 */
39324 struct l2t_skb_cb {
39325 arp_failure_handler_func arp_failure_handler;
39326-};
39327+} __no_const;
39328
39329 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
39330
39331diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
39332index 4c83003..2a2a5b9 100644
39333--- a/drivers/net/ethernet/dec/tulip/de4x5.c
39334+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
39335@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39336 for (i=0; i<ETH_ALEN; i++) {
39337 tmp.addr[i] = dev->dev_addr[i];
39338 }
39339- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39340+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39341 break;
39342
39343 case DE4X5_SET_HWADDR: /* Set the hardware address */
39344@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39345 spin_lock_irqsave(&lp->lock, flags);
39346 memcpy(&statbuf, &lp->pktStats, ioc->len);
39347 spin_unlock_irqrestore(&lp->lock, flags);
39348- if (copy_to_user(ioc->data, &statbuf, ioc->len))
39349+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
39350 return -EFAULT;
39351 break;
39352 }
39353diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
39354index 4d6f3c5..6169e60 100644
39355--- a/drivers/net/ethernet/emulex/benet/be_main.c
39356+++ b/drivers/net/ethernet/emulex/benet/be_main.c
39357@@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
39358
39359 if (wrapped)
39360 newacc += 65536;
39361- ACCESS_ONCE(*acc) = newacc;
39362+ ACCESS_ONCE_RW(*acc) = newacc;
39363 }
39364
39365 void be_parse_stats(struct be_adapter *adapter)
39366diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
39367index 74d749e..eefb1bd 100644
39368--- a/drivers/net/ethernet/faraday/ftgmac100.c
39369+++ b/drivers/net/ethernet/faraday/ftgmac100.c
39370@@ -31,6 +31,8 @@
39371 #include <linux/netdevice.h>
39372 #include <linux/phy.h>
39373 #include <linux/platform_device.h>
39374+#include <linux/interrupt.h>
39375+#include <linux/irqreturn.h>
39376 #include <net/ip.h>
39377
39378 #include "ftgmac100.h"
39379diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
39380index b901a01..1ff32ee 100644
39381--- a/drivers/net/ethernet/faraday/ftmac100.c
39382+++ b/drivers/net/ethernet/faraday/ftmac100.c
39383@@ -31,6 +31,8 @@
39384 #include <linux/module.h>
39385 #include <linux/netdevice.h>
39386 #include <linux/platform_device.h>
39387+#include <linux/interrupt.h>
39388+#include <linux/irqreturn.h>
39389
39390 #include "ftmac100.h"
39391
39392diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39393index bb9256a..56d8752 100644
39394--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39395+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39396@@ -806,7 +806,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
39397 }
39398
39399 /* update the base incval used to calculate frequency adjustment */
39400- ACCESS_ONCE(adapter->base_incval) = incval;
39401+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
39402 smp_mb();
39403
39404 /* need lock to prevent incorrect read while modifying cyclecounter */
39405diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39406index fbe5363..266b4e3 100644
39407--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
39408+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39409@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39410 struct __vxge_hw_fifo *fifo;
39411 struct vxge_hw_fifo_config *config;
39412 u32 txdl_size, txdl_per_memblock;
39413- struct vxge_hw_mempool_cbs fifo_mp_callback;
39414+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
39415+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
39416+ };
39417+
39418 struct __vxge_hw_virtualpath *vpath;
39419
39420 if ((vp == NULL) || (attr == NULL)) {
39421@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39422 goto exit;
39423 }
39424
39425- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
39426-
39427 fifo->mempool =
39428 __vxge_hw_mempool_create(vpath->hldev,
39429 fifo->config->memblock_size,
39430diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
39431index 998974f..ecd26db 100644
39432--- a/drivers/net/ethernet/realtek/r8169.c
39433+++ b/drivers/net/ethernet/realtek/r8169.c
39434@@ -741,22 +741,22 @@ struct rtl8169_private {
39435 struct mdio_ops {
39436 void (*write)(struct rtl8169_private *, int, int);
39437 int (*read)(struct rtl8169_private *, int);
39438- } mdio_ops;
39439+ } __no_const mdio_ops;
39440
39441 struct pll_power_ops {
39442 void (*down)(struct rtl8169_private *);
39443 void (*up)(struct rtl8169_private *);
39444- } pll_power_ops;
39445+ } __no_const pll_power_ops;
39446
39447 struct jumbo_ops {
39448 void (*enable)(struct rtl8169_private *);
39449 void (*disable)(struct rtl8169_private *);
39450- } jumbo_ops;
39451+ } __no_const jumbo_ops;
39452
39453 struct csi_ops {
39454 void (*write)(struct rtl8169_private *, int, int);
39455 u32 (*read)(struct rtl8169_private *, int);
39456- } csi_ops;
39457+ } __no_const csi_ops;
39458
39459 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
39460 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
39461diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
39462index 3f93624..cf01144 100644
39463--- a/drivers/net/ethernet/sfc/ptp.c
39464+++ b/drivers/net/ethernet/sfc/ptp.c
39465@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
39466 (u32)((u64)ptp->start.dma_addr >> 32));
39467
39468 /* Clear flag that signals MC ready */
39469- ACCESS_ONCE(*start) = 0;
39470+ ACCESS_ONCE_RW(*start) = 0;
39471 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
39472 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
39473
39474diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39475index 0c74a70..3bc6f68 100644
39476--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39477+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39478@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
39479
39480 writel(value, ioaddr + MMC_CNTRL);
39481
39482- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
39483- MMC_CNTRL, value);
39484+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
39485+// MMC_CNTRL, value);
39486 }
39487
39488 /* To mask all all interrupts.*/
39489diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
39490index e6fe0d8..2b7d752 100644
39491--- a/drivers/net/hyperv/hyperv_net.h
39492+++ b/drivers/net/hyperv/hyperv_net.h
39493@@ -101,7 +101,7 @@ struct rndis_device {
39494
39495 enum rndis_device_state state;
39496 bool link_state;
39497- atomic_t new_req_id;
39498+ atomic_unchecked_t new_req_id;
39499
39500 spinlock_t request_lock;
39501 struct list_head req_list;
39502diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
39503index 2b657d4..9903bc0 100644
39504--- a/drivers/net/hyperv/rndis_filter.c
39505+++ b/drivers/net/hyperv/rndis_filter.c
39506@@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
39507 * template
39508 */
39509 set = &rndis_msg->msg.set_req;
39510- set->req_id = atomic_inc_return(&dev->new_req_id);
39511+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39512
39513 /* Add to the request list */
39514 spin_lock_irqsave(&dev->request_lock, flags);
39515@@ -758,7 +758,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
39516
39517 /* Setup the rndis set */
39518 halt = &request->request_msg.msg.halt_req;
39519- halt->req_id = atomic_inc_return(&dev->new_req_id);
39520+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39521
39522 /* Ignore return since this msg is optional. */
39523 rndis_filter_send_request(dev, request);
39524diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
39525index 1e9cb0b..7839125 100644
39526--- a/drivers/net/ieee802154/fakehard.c
39527+++ b/drivers/net/ieee802154/fakehard.c
39528@@ -386,7 +386,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
39529 phy->transmit_power = 0xbf;
39530
39531 dev->netdev_ops = &fake_ops;
39532- dev->ml_priv = &fake_mlme;
39533+ dev->ml_priv = (void *)&fake_mlme;
39534
39535 priv = netdev_priv(dev);
39536 priv->phy = phy;
39537diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
39538index e5cb723..1fc0461 100644
39539--- a/drivers/net/macvlan.c
39540+++ b/drivers/net/macvlan.c
39541@@ -852,13 +852,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
39542 int macvlan_link_register(struct rtnl_link_ops *ops)
39543 {
39544 /* common fields */
39545- ops->priv_size = sizeof(struct macvlan_dev);
39546- ops->validate = macvlan_validate;
39547- ops->maxtype = IFLA_MACVLAN_MAX;
39548- ops->policy = macvlan_policy;
39549- ops->changelink = macvlan_changelink;
39550- ops->get_size = macvlan_get_size;
39551- ops->fill_info = macvlan_fill_info;
39552+ pax_open_kernel();
39553+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
39554+ *(void **)&ops->validate = macvlan_validate;
39555+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
39556+ *(const void **)&ops->policy = macvlan_policy;
39557+ *(void **)&ops->changelink = macvlan_changelink;
39558+ *(void **)&ops->get_size = macvlan_get_size;
39559+ *(void **)&ops->fill_info = macvlan_fill_info;
39560+ pax_close_kernel();
39561
39562 return rtnl_link_register(ops);
39563 };
39564@@ -914,7 +916,7 @@ static int macvlan_device_event(struct notifier_block *unused,
39565 return NOTIFY_DONE;
39566 }
39567
39568-static struct notifier_block macvlan_notifier_block __read_mostly = {
39569+static struct notifier_block macvlan_notifier_block = {
39570 .notifier_call = macvlan_device_event,
39571 };
39572
39573diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
39574index 0f0f9ce..0ca5819 100644
39575--- a/drivers/net/macvtap.c
39576+++ b/drivers/net/macvtap.c
39577@@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
39578 return NOTIFY_DONE;
39579 }
39580
39581-static struct notifier_block macvtap_notifier_block __read_mostly = {
39582+static struct notifier_block macvtap_notifier_block = {
39583 .notifier_call = macvtap_device_event,
39584 };
39585
39586diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
39587index daec9b0..6428fcb 100644
39588--- a/drivers/net/phy/mdio-bitbang.c
39589+++ b/drivers/net/phy/mdio-bitbang.c
39590@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
39591 struct mdiobb_ctrl *ctrl = bus->priv;
39592
39593 module_put(ctrl->ops->owner);
39594+ mdiobus_unregister(bus);
39595 mdiobus_free(bus);
39596 }
39597 EXPORT_SYMBOL(free_mdio_bitbang);
39598diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
39599index 508570e..f706dc7 100644
39600--- a/drivers/net/ppp/ppp_generic.c
39601+++ b/drivers/net/ppp/ppp_generic.c
39602@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39603 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
39604 struct ppp_stats stats;
39605 struct ppp_comp_stats cstats;
39606- char *vers;
39607
39608 switch (cmd) {
39609 case SIOCGPPPSTATS:
39610@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39611 break;
39612
39613 case SIOCGPPPVER:
39614- vers = PPP_VERSION;
39615- if (copy_to_user(addr, vers, strlen(vers) + 1))
39616+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
39617 break;
39618 err = 0;
39619 break;
39620diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
39621index 8efe47a..a8075c5 100644
39622--- a/drivers/net/team/team.c
39623+++ b/drivers/net/team/team.c
39624@@ -2603,7 +2603,7 @@ static int team_device_event(struct notifier_block *unused,
39625 return NOTIFY_DONE;
39626 }
39627
39628-static struct notifier_block team_notifier_block __read_mostly = {
39629+static struct notifier_block team_notifier_block = {
39630 .notifier_call = team_device_event,
39631 };
39632
39633diff --git a/drivers/net/tun.c b/drivers/net/tun.c
39634index cb95fe5..a5bdab5 100644
39635--- a/drivers/net/tun.c
39636+++ b/drivers/net/tun.c
39637@@ -1838,7 +1838,7 @@ unlock:
39638 }
39639
39640 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
39641- unsigned long arg, int ifreq_len)
39642+ unsigned long arg, size_t ifreq_len)
39643 {
39644 struct tun_file *tfile = file->private_data;
39645 struct tun_struct *tun;
39646@@ -1850,6 +1850,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
39647 int vnet_hdr_sz;
39648 int ret;
39649
39650+ if (ifreq_len > sizeof ifr)
39651+ return -EFAULT;
39652+
39653 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
39654 if (copy_from_user(&ifr, argp, ifreq_len))
39655 return -EFAULT;
39656diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
39657index cd8ccb2..cff5144 100644
39658--- a/drivers/net/usb/hso.c
39659+++ b/drivers/net/usb/hso.c
39660@@ -71,7 +71,7 @@
39661 #include <asm/byteorder.h>
39662 #include <linux/serial_core.h>
39663 #include <linux/serial.h>
39664-
39665+#include <asm/local.h>
39666
39667 #define MOD_AUTHOR "Option Wireless"
39668 #define MOD_DESCRIPTION "USB High Speed Option driver"
39669@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
39670 struct urb *urb;
39671
39672 urb = serial->rx_urb[0];
39673- if (serial->port.count > 0) {
39674+ if (atomic_read(&serial->port.count) > 0) {
39675 count = put_rxbuf_data(urb, serial);
39676 if (count == -1)
39677 return;
39678@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
39679 DUMP1(urb->transfer_buffer, urb->actual_length);
39680
39681 /* Anyone listening? */
39682- if (serial->port.count == 0)
39683+ if (atomic_read(&serial->port.count) == 0)
39684 return;
39685
39686 if (status == 0) {
39687@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39688 tty_port_tty_set(&serial->port, tty);
39689
39690 /* check for port already opened, if not set the termios */
39691- serial->port.count++;
39692- if (serial->port.count == 1) {
39693+ if (atomic_inc_return(&serial->port.count) == 1) {
39694 serial->rx_state = RX_IDLE;
39695 /* Force default termio settings */
39696 _hso_serial_set_termios(tty, NULL);
39697@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39698 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
39699 if (result) {
39700 hso_stop_serial_device(serial->parent);
39701- serial->port.count--;
39702+ atomic_dec(&serial->port.count);
39703 kref_put(&serial->parent->ref, hso_serial_ref_free);
39704 }
39705 } else {
39706@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
39707
39708 /* reset the rts and dtr */
39709 /* do the actual close */
39710- serial->port.count--;
39711+ atomic_dec(&serial->port.count);
39712
39713- if (serial->port.count <= 0) {
39714- serial->port.count = 0;
39715+ if (atomic_read(&serial->port.count) <= 0) {
39716+ atomic_set(&serial->port.count, 0);
39717 tty_port_tty_set(&serial->port, NULL);
39718 if (!usb_gone)
39719 hso_stop_serial_device(serial->parent);
39720@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
39721
39722 /* the actual setup */
39723 spin_lock_irqsave(&serial->serial_lock, flags);
39724- if (serial->port.count)
39725+ if (atomic_read(&serial->port.count))
39726 _hso_serial_set_termios(tty, old);
39727 else
39728 tty->termios = *old;
39729@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
39730 D1("Pending read interrupt on port %d\n", i);
39731 spin_lock(&serial->serial_lock);
39732 if (serial->rx_state == RX_IDLE &&
39733- serial->port.count > 0) {
39734+ atomic_read(&serial->port.count) > 0) {
39735 /* Setup and send a ctrl req read on
39736 * port i */
39737 if (!serial->rx_urb_filled[0]) {
39738@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
39739 /* Start all serial ports */
39740 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
39741 if (serial_table[i] && (serial_table[i]->interface == iface)) {
39742- if (dev2ser(serial_table[i])->port.count) {
39743+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
39744 result =
39745 hso_start_serial_device(serial_table[i], GFP_NOIO);
39746 hso_kick_transmit(dev2ser(serial_table[i]));
39747diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
39748index 6993bfa..9053a34 100644
39749--- a/drivers/net/vxlan.c
39750+++ b/drivers/net/vxlan.c
39751@@ -1428,7 +1428,7 @@ nla_put_failure:
39752 return -EMSGSIZE;
39753 }
39754
39755-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
39756+static struct rtnl_link_ops vxlan_link_ops = {
39757 .kind = "vxlan",
39758 .maxtype = IFLA_VXLAN_MAX,
39759 .policy = vxlan_policy,
39760diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
39761index 77fa428..996b355 100644
39762--- a/drivers/net/wireless/at76c50x-usb.c
39763+++ b/drivers/net/wireless/at76c50x-usb.c
39764@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
39765 }
39766
39767 /* Convert timeout from the DFU status to jiffies */
39768-static inline unsigned long at76_get_timeout(struct dfu_status *s)
39769+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
39770 {
39771 return msecs_to_jiffies((s->poll_timeout[2] << 16)
39772 | (s->poll_timeout[1] << 8)
39773diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39774index 8d78253..bebbb68 100644
39775--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39776+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39777@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39778 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
39779 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
39780
39781- ACCESS_ONCE(ads->ds_link) = i->link;
39782- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
39783+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
39784+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
39785
39786 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
39787 ctl6 = SM(i->keytype, AR_EncrType);
39788@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39789
39790 if ((i->is_first || i->is_last) &&
39791 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
39792- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
39793+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
39794 | set11nTries(i->rates, 1)
39795 | set11nTries(i->rates, 2)
39796 | set11nTries(i->rates, 3)
39797 | (i->dur_update ? AR_DurUpdateEna : 0)
39798 | SM(0, AR_BurstDur);
39799
39800- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
39801+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
39802 | set11nRate(i->rates, 1)
39803 | set11nRate(i->rates, 2)
39804 | set11nRate(i->rates, 3);
39805 } else {
39806- ACCESS_ONCE(ads->ds_ctl2) = 0;
39807- ACCESS_ONCE(ads->ds_ctl3) = 0;
39808+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
39809+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
39810 }
39811
39812 if (!i->is_first) {
39813- ACCESS_ONCE(ads->ds_ctl0) = 0;
39814- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
39815- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
39816+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
39817+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
39818+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
39819 return;
39820 }
39821
39822@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39823 break;
39824 }
39825
39826- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
39827+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
39828 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
39829 | SM(i->txpower, AR_XmitPower)
39830 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
39831@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39832 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
39833 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
39834
39835- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
39836- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
39837+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
39838+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
39839
39840 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
39841 return;
39842
39843- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
39844+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
39845 | set11nPktDurRTSCTS(i->rates, 1);
39846
39847- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
39848+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
39849 | set11nPktDurRTSCTS(i->rates, 3);
39850
39851- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
39852+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
39853 | set11nRateFlags(i->rates, 1)
39854 | set11nRateFlags(i->rates, 2)
39855 | set11nRateFlags(i->rates, 3)
39856diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39857index 301bf72..3f5654f 100644
39858--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39859+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39860@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39861 (i->qcu << AR_TxQcuNum_S) | desc_len;
39862
39863 checksum += val;
39864- ACCESS_ONCE(ads->info) = val;
39865+ ACCESS_ONCE_RW(ads->info) = val;
39866
39867 checksum += i->link;
39868- ACCESS_ONCE(ads->link) = i->link;
39869+ ACCESS_ONCE_RW(ads->link) = i->link;
39870
39871 checksum += i->buf_addr[0];
39872- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
39873+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
39874 checksum += i->buf_addr[1];
39875- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
39876+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
39877 checksum += i->buf_addr[2];
39878- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
39879+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
39880 checksum += i->buf_addr[3];
39881- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
39882+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
39883
39884 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
39885- ACCESS_ONCE(ads->ctl3) = val;
39886+ ACCESS_ONCE_RW(ads->ctl3) = val;
39887 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
39888- ACCESS_ONCE(ads->ctl5) = val;
39889+ ACCESS_ONCE_RW(ads->ctl5) = val;
39890 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
39891- ACCESS_ONCE(ads->ctl7) = val;
39892+ ACCESS_ONCE_RW(ads->ctl7) = val;
39893 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
39894- ACCESS_ONCE(ads->ctl9) = val;
39895+ ACCESS_ONCE_RW(ads->ctl9) = val;
39896
39897 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
39898- ACCESS_ONCE(ads->ctl10) = checksum;
39899+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
39900
39901 if (i->is_first || i->is_last) {
39902- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
39903+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
39904 | set11nTries(i->rates, 1)
39905 | set11nTries(i->rates, 2)
39906 | set11nTries(i->rates, 3)
39907 | (i->dur_update ? AR_DurUpdateEna : 0)
39908 | SM(0, AR_BurstDur);
39909
39910- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
39911+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
39912 | set11nRate(i->rates, 1)
39913 | set11nRate(i->rates, 2)
39914 | set11nRate(i->rates, 3);
39915 } else {
39916- ACCESS_ONCE(ads->ctl13) = 0;
39917- ACCESS_ONCE(ads->ctl14) = 0;
39918+ ACCESS_ONCE_RW(ads->ctl13) = 0;
39919+ ACCESS_ONCE_RW(ads->ctl14) = 0;
39920 }
39921
39922 ads->ctl20 = 0;
39923@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39924
39925 ctl17 = SM(i->keytype, AR_EncrType);
39926 if (!i->is_first) {
39927- ACCESS_ONCE(ads->ctl11) = 0;
39928- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
39929- ACCESS_ONCE(ads->ctl15) = 0;
39930- ACCESS_ONCE(ads->ctl16) = 0;
39931- ACCESS_ONCE(ads->ctl17) = ctl17;
39932- ACCESS_ONCE(ads->ctl18) = 0;
39933- ACCESS_ONCE(ads->ctl19) = 0;
39934+ ACCESS_ONCE_RW(ads->ctl11) = 0;
39935+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
39936+ ACCESS_ONCE_RW(ads->ctl15) = 0;
39937+ ACCESS_ONCE_RW(ads->ctl16) = 0;
39938+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
39939+ ACCESS_ONCE_RW(ads->ctl18) = 0;
39940+ ACCESS_ONCE_RW(ads->ctl19) = 0;
39941 return;
39942 }
39943
39944- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
39945+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
39946 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
39947 | SM(i->txpower, AR_XmitPower)
39948 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
39949@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39950 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
39951 ctl12 |= SM(val, AR_PAPRDChainMask);
39952
39953- ACCESS_ONCE(ads->ctl12) = ctl12;
39954- ACCESS_ONCE(ads->ctl17) = ctl17;
39955+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
39956+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
39957
39958- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
39959+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
39960 | set11nPktDurRTSCTS(i->rates, 1);
39961
39962- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
39963+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
39964 | set11nPktDurRTSCTS(i->rates, 3);
39965
39966- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
39967+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
39968 | set11nRateFlags(i->rates, 1)
39969 | set11nRateFlags(i->rates, 2)
39970 | set11nRateFlags(i->rates, 3)
39971 | SM(i->rtscts_rate, AR_RTSCTSRate);
39972
39973- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
39974+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
39975 }
39976
39977 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
39978diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
39979index 9d26fc5..60d9f14 100644
39980--- a/drivers/net/wireless/ath/ath9k/hw.h
39981+++ b/drivers/net/wireless/ath/ath9k/hw.h
39982@@ -658,7 +658,7 @@ struct ath_hw_private_ops {
39983
39984 /* ANI */
39985 void (*ani_cache_ini_regs)(struct ath_hw *ah);
39986-};
39987+} __no_const;
39988
39989 /**
39990 * struct ath_hw_ops - callbacks used by hardware code and driver code
39991@@ -688,7 +688,7 @@ struct ath_hw_ops {
39992 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
39993 struct ath_hw_antcomb_conf *antconf);
39994 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
39995-};
39996+} __no_const;
39997
39998 struct ath_nf_limits {
39999 s16 max;
40000diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
40001index 3726cd6..b655808 100644
40002--- a/drivers/net/wireless/iwlegacy/3945-mac.c
40003+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
40004@@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
40005 */
40006 if (il3945_mod_params.disable_hw_scan) {
40007 D_INFO("Disabling hw_scan\n");
40008- il3945_mac_ops.hw_scan = NULL;
40009+ pax_open_kernel();
40010+ *(void **)&il3945_mac_ops.hw_scan = NULL;
40011+ pax_close_kernel();
40012 }
40013
40014 D_INFO("*** LOAD DRIVER ***\n");
40015diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40016index 5b9533e..7733880 100644
40017--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40018+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40019@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
40020 {
40021 struct iwl_priv *priv = file->private_data;
40022 char buf[64];
40023- int buf_size;
40024+ size_t buf_size;
40025 u32 offset, len;
40026
40027 memset(buf, 0, sizeof(buf));
40028@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
40029 struct iwl_priv *priv = file->private_data;
40030
40031 char buf[8];
40032- int buf_size;
40033+ size_t buf_size;
40034 u32 reset_flag;
40035
40036 memset(buf, 0, sizeof(buf));
40037@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
40038 {
40039 struct iwl_priv *priv = file->private_data;
40040 char buf[8];
40041- int buf_size;
40042+ size_t buf_size;
40043 int ht40;
40044
40045 memset(buf, 0, sizeof(buf));
40046@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
40047 {
40048 struct iwl_priv *priv = file->private_data;
40049 char buf[8];
40050- int buf_size;
40051+ size_t buf_size;
40052 int value;
40053
40054 memset(buf, 0, sizeof(buf));
40055@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
40056 {
40057 struct iwl_priv *priv = file->private_data;
40058 char buf[8];
40059- int buf_size;
40060+ size_t buf_size;
40061 int clear;
40062
40063 memset(buf, 0, sizeof(buf));
40064@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
40065 {
40066 struct iwl_priv *priv = file->private_data;
40067 char buf[8];
40068- int buf_size;
40069+ size_t buf_size;
40070 int trace;
40071
40072 memset(buf, 0, sizeof(buf));
40073@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
40074 {
40075 struct iwl_priv *priv = file->private_data;
40076 char buf[8];
40077- int buf_size;
40078+ size_t buf_size;
40079 int missed;
40080
40081 memset(buf, 0, sizeof(buf));
40082@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
40083
40084 struct iwl_priv *priv = file->private_data;
40085 char buf[8];
40086- int buf_size;
40087+ size_t buf_size;
40088 int plcp;
40089
40090 memset(buf, 0, sizeof(buf));
40091@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
40092
40093 struct iwl_priv *priv = file->private_data;
40094 char buf[8];
40095- int buf_size;
40096+ size_t buf_size;
40097 int flush;
40098
40099 memset(buf, 0, sizeof(buf));
40100@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
40101
40102 struct iwl_priv *priv = file->private_data;
40103 char buf[8];
40104- int buf_size;
40105+ size_t buf_size;
40106 int rts;
40107
40108 if (!priv->cfg->ht_params)
40109@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
40110 {
40111 struct iwl_priv *priv = file->private_data;
40112 char buf[8];
40113- int buf_size;
40114+ size_t buf_size;
40115
40116 memset(buf, 0, sizeof(buf));
40117 buf_size = min(count, sizeof(buf) - 1);
40118@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
40119 struct iwl_priv *priv = file->private_data;
40120 u32 event_log_flag;
40121 char buf[8];
40122- int buf_size;
40123+ size_t buf_size;
40124
40125 /* check that the interface is up */
40126 if (!iwl_is_ready(priv))
40127@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
40128 struct iwl_priv *priv = file->private_data;
40129 char buf[8];
40130 u32 calib_disabled;
40131- int buf_size;
40132+ size_t buf_size;
40133
40134 memset(buf, 0, sizeof(buf));
40135 buf_size = min(count, sizeof(buf) - 1);
40136diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
40137index 35708b9..31f7754 100644
40138--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
40139+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
40140@@ -1100,7 +1100,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
40141 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
40142
40143 char buf[8];
40144- int buf_size;
40145+ size_t buf_size;
40146 u32 reset_flag;
40147
40148 memset(buf, 0, sizeof(buf));
40149@@ -1121,7 +1121,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
40150 {
40151 struct iwl_trans *trans = file->private_data;
40152 char buf[8];
40153- int buf_size;
40154+ size_t buf_size;
40155 int csr;
40156
40157 memset(buf, 0, sizeof(buf));
40158diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
40159index ff90855..e46d223 100644
40160--- a/drivers/net/wireless/mac80211_hwsim.c
40161+++ b/drivers/net/wireless/mac80211_hwsim.c
40162@@ -2062,25 +2062,19 @@ static int __init init_mac80211_hwsim(void)
40163
40164 if (channels > 1) {
40165 hwsim_if_comb.num_different_channels = channels;
40166- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40167- mac80211_hwsim_ops.cancel_hw_scan =
40168- mac80211_hwsim_cancel_hw_scan;
40169- mac80211_hwsim_ops.sw_scan_start = NULL;
40170- mac80211_hwsim_ops.sw_scan_complete = NULL;
40171- mac80211_hwsim_ops.remain_on_channel =
40172- mac80211_hwsim_roc;
40173- mac80211_hwsim_ops.cancel_remain_on_channel =
40174- mac80211_hwsim_croc;
40175- mac80211_hwsim_ops.add_chanctx =
40176- mac80211_hwsim_add_chanctx;
40177- mac80211_hwsim_ops.remove_chanctx =
40178- mac80211_hwsim_remove_chanctx;
40179- mac80211_hwsim_ops.change_chanctx =
40180- mac80211_hwsim_change_chanctx;
40181- mac80211_hwsim_ops.assign_vif_chanctx =
40182- mac80211_hwsim_assign_vif_chanctx;
40183- mac80211_hwsim_ops.unassign_vif_chanctx =
40184- mac80211_hwsim_unassign_vif_chanctx;
40185+ pax_open_kernel();
40186+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40187+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
40188+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
40189+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
40190+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
40191+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
40192+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
40193+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
40194+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
40195+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
40196+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
40197+ pax_close_kernel();
40198 }
40199
40200 spin_lock_init(&hwsim_radio_lock);
40201diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
40202index abe1d03..fb02c22 100644
40203--- a/drivers/net/wireless/rndis_wlan.c
40204+++ b/drivers/net/wireless/rndis_wlan.c
40205@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
40206
40207 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
40208
40209- if (rts_threshold < 0 || rts_threshold > 2347)
40210+ if (rts_threshold > 2347)
40211 rts_threshold = 2347;
40212
40213 tmp = cpu_to_le32(rts_threshold);
40214diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
40215index 0751b35..246ba3e 100644
40216--- a/drivers/net/wireless/rt2x00/rt2x00.h
40217+++ b/drivers/net/wireless/rt2x00/rt2x00.h
40218@@ -398,7 +398,7 @@ struct rt2x00_intf {
40219 * for hardware which doesn't support hardware
40220 * sequence counting.
40221 */
40222- atomic_t seqno;
40223+ atomic_unchecked_t seqno;
40224 };
40225
40226 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
40227diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
40228index e488b94..14b6a0c 100644
40229--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
40230+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
40231@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
40232 * sequence counter given by mac80211.
40233 */
40234 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
40235- seqno = atomic_add_return(0x10, &intf->seqno);
40236+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
40237 else
40238- seqno = atomic_read(&intf->seqno);
40239+ seqno = atomic_read_unchecked(&intf->seqno);
40240
40241 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
40242 hdr->seq_ctrl |= cpu_to_le16(seqno);
40243diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
40244index e57ee48..541cf6c 100644
40245--- a/drivers/net/wireless/ti/wl1251/sdio.c
40246+++ b/drivers/net/wireless/ti/wl1251/sdio.c
40247@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
40248
40249 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
40250
40251- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40252- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40253+ pax_open_kernel();
40254+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40255+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40256+ pax_close_kernel();
40257
40258 wl1251_info("using dedicated interrupt line");
40259 } else {
40260- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40261- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40262+ pax_open_kernel();
40263+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40264+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40265+ pax_close_kernel();
40266
40267 wl1251_info("using SDIO interrupt");
40268 }
40269diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
40270index e5f5f8f..fdf15b7 100644
40271--- a/drivers/net/wireless/ti/wl12xx/main.c
40272+++ b/drivers/net/wireless/ti/wl12xx/main.c
40273@@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
40274 sizeof(wl->conf.mem));
40275
40276 /* read data preparation is only needed by wl127x */
40277- wl->ops->prepare_read = wl127x_prepare_read;
40278+ pax_open_kernel();
40279+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
40280+ pax_close_kernel();
40281
40282 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
40283 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
40284@@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
40285 sizeof(wl->conf.mem));
40286
40287 /* read data preparation is only needed by wl127x */
40288- wl->ops->prepare_read = wl127x_prepare_read;
40289+ pax_open_kernel();
40290+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
40291+ pax_close_kernel();
40292
40293 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
40294 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
40295diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
40296index 8d8c1f8..e754844 100644
40297--- a/drivers/net/wireless/ti/wl18xx/main.c
40298+++ b/drivers/net/wireless/ti/wl18xx/main.c
40299@@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
40300 }
40301
40302 if (!checksum_param) {
40303- wl18xx_ops.set_rx_csum = NULL;
40304- wl18xx_ops.init_vif = NULL;
40305+ pax_open_kernel();
40306+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
40307+ *(void **)&wl18xx_ops.init_vif = NULL;
40308+ pax_close_kernel();
40309 }
40310
40311 /* Enable 11a Band only if we have 5G antennas */
40312diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
40313index ef2b171..bb513a6 100644
40314--- a/drivers/net/wireless/zd1211rw/zd_usb.c
40315+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
40316@@ -387,7 +387,7 @@ static inline void handle_regs_int(struct urb *urb)
40317 {
40318 struct zd_usb *usb = urb->context;
40319 struct zd_usb_interrupt *intr = &usb->intr;
40320- int len;
40321+ unsigned int len;
40322 u16 int_num;
40323
40324 ZD_ASSERT(in_interrupt());
40325diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
40326index d93b2b6..ae50401 100644
40327--- a/drivers/oprofile/buffer_sync.c
40328+++ b/drivers/oprofile/buffer_sync.c
40329@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
40330 if (cookie == NO_COOKIE)
40331 offset = pc;
40332 if (cookie == INVALID_COOKIE) {
40333- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
40334+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
40335 offset = pc;
40336 }
40337 if (cookie != last_cookie) {
40338@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
40339 /* add userspace sample */
40340
40341 if (!mm) {
40342- atomic_inc(&oprofile_stats.sample_lost_no_mm);
40343+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
40344 return 0;
40345 }
40346
40347 cookie = lookup_dcookie(mm, s->eip, &offset);
40348
40349 if (cookie == INVALID_COOKIE) {
40350- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
40351+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
40352 return 0;
40353 }
40354
40355@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
40356 /* ignore backtraces if failed to add a sample */
40357 if (state == sb_bt_start) {
40358 state = sb_bt_ignore;
40359- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
40360+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
40361 }
40362 }
40363 release_mm(mm);
40364diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
40365index c0cc4e7..44d4e54 100644
40366--- a/drivers/oprofile/event_buffer.c
40367+++ b/drivers/oprofile/event_buffer.c
40368@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
40369 }
40370
40371 if (buffer_pos == buffer_size) {
40372- atomic_inc(&oprofile_stats.event_lost_overflow);
40373+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
40374 return;
40375 }
40376
40377diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
40378index ed2c3ec..deda85a 100644
40379--- a/drivers/oprofile/oprof.c
40380+++ b/drivers/oprofile/oprof.c
40381@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
40382 if (oprofile_ops.switch_events())
40383 return;
40384
40385- atomic_inc(&oprofile_stats.multiplex_counter);
40386+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
40387 start_switch_worker();
40388 }
40389
40390diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
40391index 84a208d..d61b0a1 100644
40392--- a/drivers/oprofile/oprofile_files.c
40393+++ b/drivers/oprofile/oprofile_files.c
40394@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
40395
40396 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
40397
40398-static ssize_t timeout_read(struct file *file, char __user *buf,
40399+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
40400 size_t count, loff_t *offset)
40401 {
40402 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
40403diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
40404index 917d28e..d62d981 100644
40405--- a/drivers/oprofile/oprofile_stats.c
40406+++ b/drivers/oprofile/oprofile_stats.c
40407@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
40408 cpu_buf->sample_invalid_eip = 0;
40409 }
40410
40411- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
40412- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
40413- atomic_set(&oprofile_stats.event_lost_overflow, 0);
40414- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
40415- atomic_set(&oprofile_stats.multiplex_counter, 0);
40416+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
40417+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
40418+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
40419+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
40420+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
40421 }
40422
40423
40424diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
40425index 38b6fc0..b5cbfce 100644
40426--- a/drivers/oprofile/oprofile_stats.h
40427+++ b/drivers/oprofile/oprofile_stats.h
40428@@ -13,11 +13,11 @@
40429 #include <linux/atomic.h>
40430
40431 struct oprofile_stat_struct {
40432- atomic_t sample_lost_no_mm;
40433- atomic_t sample_lost_no_mapping;
40434- atomic_t bt_lost_no_mapping;
40435- atomic_t event_lost_overflow;
40436- atomic_t multiplex_counter;
40437+ atomic_unchecked_t sample_lost_no_mm;
40438+ atomic_unchecked_t sample_lost_no_mapping;
40439+ atomic_unchecked_t bt_lost_no_mapping;
40440+ atomic_unchecked_t event_lost_overflow;
40441+ atomic_unchecked_t multiplex_counter;
40442 };
40443
40444 extern struct oprofile_stat_struct oprofile_stats;
40445diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
40446index 849357c..b83c1e0 100644
40447--- a/drivers/oprofile/oprofilefs.c
40448+++ b/drivers/oprofile/oprofilefs.c
40449@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
40450
40451
40452 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
40453- char const *name, atomic_t *val)
40454+ char const *name, atomic_unchecked_t *val)
40455 {
40456 return __oprofilefs_create_file(sb, root, name,
40457 &atomic_ro_fops, 0444, val);
40458diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
40459index 93404f7..4a313d8 100644
40460--- a/drivers/oprofile/timer_int.c
40461+++ b/drivers/oprofile/timer_int.c
40462@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
40463 return NOTIFY_OK;
40464 }
40465
40466-static struct notifier_block __refdata oprofile_cpu_notifier = {
40467+static struct notifier_block oprofile_cpu_notifier = {
40468 .notifier_call = oprofile_cpu_notify,
40469 };
40470
40471diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
40472index 3f56bc0..707d642 100644
40473--- a/drivers/parport/procfs.c
40474+++ b/drivers/parport/procfs.c
40475@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
40476
40477 *ppos += len;
40478
40479- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
40480+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
40481 }
40482
40483 #ifdef CONFIG_PARPORT_1284
40484@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
40485
40486 *ppos += len;
40487
40488- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
40489+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
40490 }
40491 #endif /* IEEE1284.3 support. */
40492
40493diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
40494index c35e8ad..fc33beb 100644
40495--- a/drivers/pci/hotplug/acpiphp_ibm.c
40496+++ b/drivers/pci/hotplug/acpiphp_ibm.c
40497@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
40498 goto init_cleanup;
40499 }
40500
40501- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
40502+ pax_open_kernel();
40503+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
40504+ pax_close_kernel();
40505 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
40506
40507 return retval;
40508diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
40509index a6a71c4..c91097b 100644
40510--- a/drivers/pci/hotplug/cpcihp_generic.c
40511+++ b/drivers/pci/hotplug/cpcihp_generic.c
40512@@ -73,7 +73,6 @@ static u16 port;
40513 static unsigned int enum_bit;
40514 static u8 enum_mask;
40515
40516-static struct cpci_hp_controller_ops generic_hpc_ops;
40517 static struct cpci_hp_controller generic_hpc;
40518
40519 static int __init validate_parameters(void)
40520@@ -139,6 +138,10 @@ static int query_enum(void)
40521 return ((value & enum_mask) == enum_mask);
40522 }
40523
40524+static struct cpci_hp_controller_ops generic_hpc_ops = {
40525+ .query_enum = query_enum,
40526+};
40527+
40528 static int __init cpcihp_generic_init(void)
40529 {
40530 int status;
40531@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
40532 pci_dev_put(dev);
40533
40534 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
40535- generic_hpc_ops.query_enum = query_enum;
40536 generic_hpc.ops = &generic_hpc_ops;
40537
40538 status = cpci_hp_register_controller(&generic_hpc);
40539diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
40540index 449b4bb..257e2e8 100644
40541--- a/drivers/pci/hotplug/cpcihp_zt5550.c
40542+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
40543@@ -59,7 +59,6 @@
40544 /* local variables */
40545 static bool debug;
40546 static bool poll;
40547-static struct cpci_hp_controller_ops zt5550_hpc_ops;
40548 static struct cpci_hp_controller zt5550_hpc;
40549
40550 /* Primary cPCI bus bridge device */
40551@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
40552 return 0;
40553 }
40554
40555+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
40556+ .query_enum = zt5550_hc_query_enum,
40557+};
40558+
40559 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
40560 {
40561 int status;
40562@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
40563 dbg("returned from zt5550_hc_config");
40564
40565 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
40566- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
40567 zt5550_hpc.ops = &zt5550_hpc_ops;
40568 if(!poll) {
40569 zt5550_hpc.irq = hc_dev->irq;
40570 zt5550_hpc.irq_flags = IRQF_SHARED;
40571 zt5550_hpc.dev_id = hc_dev;
40572
40573- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
40574- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
40575- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
40576+ pax_open_kernel();
40577+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
40578+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
40579+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
40580+ pax_open_kernel();
40581 } else {
40582 info("using ENUM# polling mode");
40583 }
40584diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
40585index 76ba8a1..20ca857 100644
40586--- a/drivers/pci/hotplug/cpqphp_nvram.c
40587+++ b/drivers/pci/hotplug/cpqphp_nvram.c
40588@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
40589
40590 void compaq_nvram_init (void __iomem *rom_start)
40591 {
40592+
40593+#ifndef CONFIG_PAX_KERNEXEC
40594 if (rom_start) {
40595 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
40596 }
40597+#endif
40598+
40599 dbg("int15 entry = %p\n", compaq_int15_entry_point);
40600
40601 /* initialize our int15 lock */
40602diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
40603index 202f4a9..8ee47d0 100644
40604--- a/drivers/pci/hotplug/pci_hotplug_core.c
40605+++ b/drivers/pci/hotplug/pci_hotplug_core.c
40606@@ -448,8 +448,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
40607 return -EINVAL;
40608 }
40609
40610- slot->ops->owner = owner;
40611- slot->ops->mod_name = mod_name;
40612+ pax_open_kernel();
40613+ *(struct module **)&slot->ops->owner = owner;
40614+ *(const char **)&slot->ops->mod_name = mod_name;
40615+ pax_close_kernel();
40616
40617 mutex_lock(&pci_hp_mutex);
40618 /*
40619diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
40620index 939bd1d..a1459c9 100644
40621--- a/drivers/pci/hotplug/pciehp_core.c
40622+++ b/drivers/pci/hotplug/pciehp_core.c
40623@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
40624 struct slot *slot = ctrl->slot;
40625 struct hotplug_slot *hotplug = NULL;
40626 struct hotplug_slot_info *info = NULL;
40627- struct hotplug_slot_ops *ops = NULL;
40628+ hotplug_slot_ops_no_const *ops = NULL;
40629 char name[SLOT_NAME_SIZE];
40630 int retval = -ENOMEM;
40631
40632diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
40633index 9c6e9bb..2916736 100644
40634--- a/drivers/pci/pci-sysfs.c
40635+++ b/drivers/pci/pci-sysfs.c
40636@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
40637 {
40638 /* allocate attribute structure, piggyback attribute name */
40639 int name_len = write_combine ? 13 : 10;
40640- struct bin_attribute *res_attr;
40641+ bin_attribute_no_const *res_attr;
40642 int retval;
40643
40644 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
40645@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
40646 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
40647 {
40648 int retval;
40649- struct bin_attribute *attr;
40650+ bin_attribute_no_const *attr;
40651
40652 /* If the device has VPD, try to expose it in sysfs. */
40653 if (dev->vpd) {
40654@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
40655 {
40656 int retval;
40657 int rom_size = 0;
40658- struct bin_attribute *attr;
40659+ bin_attribute_no_const *attr;
40660
40661 if (!sysfs_initialized)
40662 return -EACCES;
40663diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
40664index e851829..a1a7196 100644
40665--- a/drivers/pci/pci.h
40666+++ b/drivers/pci/pci.h
40667@@ -98,7 +98,7 @@ struct pci_vpd_ops {
40668 struct pci_vpd {
40669 unsigned int len;
40670 const struct pci_vpd_ops *ops;
40671- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
40672+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
40673 };
40674
40675 extern int pci_vpd_pci22_init(struct pci_dev *dev);
40676diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
40677index 8474b6a..ee81993 100644
40678--- a/drivers/pci/pcie/aspm.c
40679+++ b/drivers/pci/pcie/aspm.c
40680@@ -27,9 +27,9 @@
40681 #define MODULE_PARAM_PREFIX "pcie_aspm."
40682
40683 /* Note: those are not register definitions */
40684-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
40685-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
40686-#define ASPM_STATE_L1 (4) /* L1 state */
40687+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
40688+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
40689+#define ASPM_STATE_L1 (4U) /* L1 state */
40690 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
40691 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
40692
40693diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
40694index 6186f03..1a78714 100644
40695--- a/drivers/pci/probe.c
40696+++ b/drivers/pci/probe.c
40697@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
40698 struct pci_bus_region region;
40699 bool bar_too_big = false, bar_disabled = false;
40700
40701- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
40702+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
40703
40704 /* No printks while decoding is disabled! */
40705 if (!dev->mmio_always_on) {
40706diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
40707index 9b8505c..f00870a 100644
40708--- a/drivers/pci/proc.c
40709+++ b/drivers/pci/proc.c
40710@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
40711 static int __init pci_proc_init(void)
40712 {
40713 struct pci_dev *dev = NULL;
40714+
40715+#ifdef CONFIG_GRKERNSEC_PROC_ADD
40716+#ifdef CONFIG_GRKERNSEC_PROC_USER
40717+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
40718+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
40719+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
40720+#endif
40721+#else
40722 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
40723+#endif
40724 proc_create("devices", 0, proc_bus_pci_dir,
40725 &proc_bus_pci_dev_operations);
40726 proc_initialized = 1;
40727diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
40728index 2111dbb..79e434b 100644
40729--- a/drivers/platform/x86/msi-laptop.c
40730+++ b/drivers/platform/x86/msi-laptop.c
40731@@ -820,12 +820,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
40732 int result;
40733
40734 /* allow userland write sysfs file */
40735- dev_attr_bluetooth.store = store_bluetooth;
40736- dev_attr_wlan.store = store_wlan;
40737- dev_attr_threeg.store = store_threeg;
40738- dev_attr_bluetooth.attr.mode |= S_IWUSR;
40739- dev_attr_wlan.attr.mode |= S_IWUSR;
40740- dev_attr_threeg.attr.mode |= S_IWUSR;
40741+ pax_open_kernel();
40742+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
40743+ *(void **)&dev_attr_wlan.store = store_wlan;
40744+ *(void **)&dev_attr_threeg.store = store_threeg;
40745+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
40746+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
40747+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
40748+ pax_close_kernel();
40749
40750 /* disable hardware control by fn key */
40751 result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
40752diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
40753index 0fe987f..6f3d5c3 100644
40754--- a/drivers/platform/x86/sony-laptop.c
40755+++ b/drivers/platform/x86/sony-laptop.c
40756@@ -2356,7 +2356,7 @@ static void sony_nc_lid_resume_cleanup(struct platform_device *pd)
40757 }
40758
40759 /* High speed charging function */
40760-static struct device_attribute *hsc_handle;
40761+static device_attribute_no_const *hsc_handle;
40762
40763 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
40764 struct device_attribute *attr,
40765diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
40766index f946ca7..f25c833 100644
40767--- a/drivers/platform/x86/thinkpad_acpi.c
40768+++ b/drivers/platform/x86/thinkpad_acpi.c
40769@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
40770 return 0;
40771 }
40772
40773-void static hotkey_mask_warn_incomplete_mask(void)
40774+static void hotkey_mask_warn_incomplete_mask(void)
40775 {
40776 /* log only what the user can fix... */
40777 const u32 wantedmask = hotkey_driver_mask &
40778@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
40779 }
40780 }
40781
40782-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40783- struct tp_nvram_state *newn,
40784- const u32 event_mask)
40785-{
40786-
40787 #define TPACPI_COMPARE_KEY(__scancode, __member) \
40788 do { \
40789 if ((event_mask & (1 << __scancode)) && \
40790@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40791 tpacpi_hotkey_send_key(__scancode); \
40792 } while (0)
40793
40794- void issue_volchange(const unsigned int oldvol,
40795- const unsigned int newvol)
40796- {
40797- unsigned int i = oldvol;
40798+static void issue_volchange(const unsigned int oldvol,
40799+ const unsigned int newvol,
40800+ const u32 event_mask)
40801+{
40802+ unsigned int i = oldvol;
40803
40804- while (i > newvol) {
40805- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
40806- i--;
40807- }
40808- while (i < newvol) {
40809- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40810- i++;
40811- }
40812+ while (i > newvol) {
40813+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
40814+ i--;
40815 }
40816+ while (i < newvol) {
40817+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40818+ i++;
40819+ }
40820+}
40821
40822- void issue_brightnesschange(const unsigned int oldbrt,
40823- const unsigned int newbrt)
40824- {
40825- unsigned int i = oldbrt;
40826+static void issue_brightnesschange(const unsigned int oldbrt,
40827+ const unsigned int newbrt,
40828+ const u32 event_mask)
40829+{
40830+ unsigned int i = oldbrt;
40831
40832- while (i > newbrt) {
40833- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
40834- i--;
40835- }
40836- while (i < newbrt) {
40837- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40838- i++;
40839- }
40840+ while (i > newbrt) {
40841+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
40842+ i--;
40843+ }
40844+ while (i < newbrt) {
40845+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40846+ i++;
40847 }
40848+}
40849
40850+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40851+ struct tp_nvram_state *newn,
40852+ const u32 event_mask)
40853+{
40854 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
40855 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
40856 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
40857@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40858 oldn->volume_level != newn->volume_level) {
40859 /* recently muted, or repeated mute keypress, or
40860 * multiple presses ending in mute */
40861- issue_volchange(oldn->volume_level, newn->volume_level);
40862+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
40863 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
40864 }
40865 } else {
40866@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40867 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40868 }
40869 if (oldn->volume_level != newn->volume_level) {
40870- issue_volchange(oldn->volume_level, newn->volume_level);
40871+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
40872 } else if (oldn->volume_toggle != newn->volume_toggle) {
40873 /* repeated vol up/down keypress at end of scale ? */
40874 if (newn->volume_level == 0)
40875@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40876 /* handle brightness */
40877 if (oldn->brightness_level != newn->brightness_level) {
40878 issue_brightnesschange(oldn->brightness_level,
40879- newn->brightness_level);
40880+ newn->brightness_level,
40881+ event_mask);
40882 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
40883 /* repeated key presses that didn't change state */
40884 if (newn->brightness_level == 0)
40885@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40886 && !tp_features.bright_unkfw)
40887 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40888 }
40889+}
40890
40891 #undef TPACPI_COMPARE_KEY
40892 #undef TPACPI_MAY_SEND_KEY
40893-}
40894
40895 /*
40896 * Polling driver
40897diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
40898index 769d265..a3a05ca 100644
40899--- a/drivers/pnp/pnpbios/bioscalls.c
40900+++ b/drivers/pnp/pnpbios/bioscalls.c
40901@@ -58,7 +58,7 @@ do { \
40902 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
40903 } while(0)
40904
40905-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
40906+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
40907 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
40908
40909 /*
40910@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40911
40912 cpu = get_cpu();
40913 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
40914+
40915+ pax_open_kernel();
40916 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
40917+ pax_close_kernel();
40918
40919 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
40920 spin_lock_irqsave(&pnp_bios_lock, flags);
40921@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40922 :"memory");
40923 spin_unlock_irqrestore(&pnp_bios_lock, flags);
40924
40925+ pax_open_kernel();
40926 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
40927+ pax_close_kernel();
40928+
40929 put_cpu();
40930
40931 /* If we get here and this is set then the PnP BIOS faulted on us. */
40932@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
40933 return status;
40934 }
40935
40936-void pnpbios_calls_init(union pnp_bios_install_struct *header)
40937+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
40938 {
40939 int i;
40940
40941@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40942 pnp_bios_callpoint.offset = header->fields.pm16offset;
40943 pnp_bios_callpoint.segment = PNP_CS16;
40944
40945+ pax_open_kernel();
40946+
40947 for_each_possible_cpu(i) {
40948 struct desc_struct *gdt = get_cpu_gdt_table(i);
40949 if (!gdt)
40950@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40951 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
40952 (unsigned long)__va(header->fields.pm16dseg));
40953 }
40954+
40955+ pax_close_kernel();
40956 }
40957diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
40958index 3e6db1c..1fbbdae 100644
40959--- a/drivers/pnp/resource.c
40960+++ b/drivers/pnp/resource.c
40961@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
40962 return 1;
40963
40964 /* check if the resource is valid */
40965- if (*irq < 0 || *irq > 15)
40966+ if (*irq > 15)
40967 return 0;
40968
40969 /* check if the resource is reserved */
40970@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
40971 return 1;
40972
40973 /* check if the resource is valid */
40974- if (*dma < 0 || *dma == 4 || *dma > 7)
40975+ if (*dma == 4 || *dma > 7)
40976 return 0;
40977
40978 /* check if the resource is reserved */
40979diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
40980index 7df7c5f..bd48c47 100644
40981--- a/drivers/power/pda_power.c
40982+++ b/drivers/power/pda_power.c
40983@@ -37,7 +37,11 @@ static int polling;
40984
40985 #ifdef CONFIG_USB_OTG_UTILS
40986 static struct usb_phy *transceiver;
40987-static struct notifier_block otg_nb;
40988+static int otg_handle_notification(struct notifier_block *nb,
40989+ unsigned long event, void *unused);
40990+static struct notifier_block otg_nb = {
40991+ .notifier_call = otg_handle_notification
40992+};
40993 #endif
40994
40995 static struct regulator *ac_draw;
40996@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
40997
40998 #ifdef CONFIG_USB_OTG_UTILS
40999 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
41000- otg_nb.notifier_call = otg_handle_notification;
41001 ret = usb_register_notifier(transceiver, &otg_nb);
41002 if (ret) {
41003 dev_err(dev, "failure to register otg notifier\n");
41004diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
41005index cc439fd..8fa30df 100644
41006--- a/drivers/power/power_supply.h
41007+++ b/drivers/power/power_supply.h
41008@@ -16,12 +16,12 @@ struct power_supply;
41009
41010 #ifdef CONFIG_SYSFS
41011
41012-extern void power_supply_init_attrs(struct device_type *dev_type);
41013+extern void power_supply_init_attrs(void);
41014 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
41015
41016 #else
41017
41018-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
41019+static inline void power_supply_init_attrs(void) {}
41020 #define power_supply_uevent NULL
41021
41022 #endif /* CONFIG_SYSFS */
41023diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
41024index 8a7cfb3..72e6e9b 100644
41025--- a/drivers/power/power_supply_core.c
41026+++ b/drivers/power/power_supply_core.c
41027@@ -24,7 +24,10 @@
41028 struct class *power_supply_class;
41029 EXPORT_SYMBOL_GPL(power_supply_class);
41030
41031-static struct device_type power_supply_dev_type;
41032+extern const struct attribute_group *power_supply_attr_groups[];
41033+static struct device_type power_supply_dev_type = {
41034+ .groups = power_supply_attr_groups,
41035+};
41036
41037 static int __power_supply_changed_work(struct device *dev, void *data)
41038 {
41039@@ -393,7 +396,7 @@ static int __init power_supply_class_init(void)
41040 return PTR_ERR(power_supply_class);
41041
41042 power_supply_class->dev_uevent = power_supply_uevent;
41043- power_supply_init_attrs(&power_supply_dev_type);
41044+ power_supply_init_attrs();
41045
41046 return 0;
41047 }
41048diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
41049index 40fa3b7..d9c2e0e 100644
41050--- a/drivers/power/power_supply_sysfs.c
41051+++ b/drivers/power/power_supply_sysfs.c
41052@@ -229,17 +229,15 @@ static struct attribute_group power_supply_attr_group = {
41053 .is_visible = power_supply_attr_is_visible,
41054 };
41055
41056-static const struct attribute_group *power_supply_attr_groups[] = {
41057+const struct attribute_group *power_supply_attr_groups[] = {
41058 &power_supply_attr_group,
41059 NULL,
41060 };
41061
41062-void power_supply_init_attrs(struct device_type *dev_type)
41063+void power_supply_init_attrs(void)
41064 {
41065 int i;
41066
41067- dev_type->groups = power_supply_attr_groups;
41068-
41069 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
41070 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
41071 }
41072diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
41073index 4d7c635..9860196 100644
41074--- a/drivers/regulator/max8660.c
41075+++ b/drivers/regulator/max8660.c
41076@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
41077 max8660->shadow_regs[MAX8660_OVER1] = 5;
41078 } else {
41079 /* Otherwise devices can be toggled via software */
41080- max8660_dcdc_ops.enable = max8660_dcdc_enable;
41081- max8660_dcdc_ops.disable = max8660_dcdc_disable;
41082+ pax_open_kernel();
41083+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
41084+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
41085+ pax_close_kernel();
41086 }
41087
41088 /*
41089diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
41090index 9a8ea91..c483dd9 100644
41091--- a/drivers/regulator/max8973-regulator.c
41092+++ b/drivers/regulator/max8973-regulator.c
41093@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
41094 if (!pdata->enable_ext_control) {
41095 max->desc.enable_reg = MAX8973_VOUT;
41096 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
41097- max8973_dcdc_ops.enable = regulator_enable_regmap;
41098- max8973_dcdc_ops.disable = regulator_disable_regmap;
41099- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41100+ pax_open_kernel();
41101+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
41102+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
41103+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41104+ pax_close_kernel();
41105 }
41106
41107 max->enable_external_control = pdata->enable_ext_control;
41108diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
41109index 0d84b1f..c2da6ac 100644
41110--- a/drivers/regulator/mc13892-regulator.c
41111+++ b/drivers/regulator/mc13892-regulator.c
41112@@ -540,10 +540,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
41113 }
41114 mc13xxx_unlock(mc13892);
41115
41116- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41117+ pax_open_kernel();
41118+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41119 = mc13892_vcam_set_mode;
41120- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41121+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41122 = mc13892_vcam_get_mode;
41123+ pax_close_kernel();
41124
41125 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
41126 ARRAY_SIZE(mc13892_regulators));
41127diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
41128index 16630aa..6afc992 100644
41129--- a/drivers/rtc/rtc-cmos.c
41130+++ b/drivers/rtc/rtc-cmos.c
41131@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
41132 hpet_rtc_timer_init();
41133
41134 /* export at least the first block of NVRAM */
41135- nvram.size = address_space - NVRAM_OFFSET;
41136+ pax_open_kernel();
41137+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
41138+ pax_close_kernel();
41139 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
41140 if (retval < 0) {
41141 dev_dbg(dev, "can't create nvram file? %d\n", retval);
41142diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
41143index 9a86b4b..3a383dc 100644
41144--- a/drivers/rtc/rtc-dev.c
41145+++ b/drivers/rtc/rtc-dev.c
41146@@ -14,6 +14,7 @@
41147 #include <linux/module.h>
41148 #include <linux/rtc.h>
41149 #include <linux/sched.h>
41150+#include <linux/grsecurity.h>
41151 #include "rtc-core.h"
41152
41153 static dev_t rtc_devt;
41154@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
41155 if (copy_from_user(&tm, uarg, sizeof(tm)))
41156 return -EFAULT;
41157
41158+ gr_log_timechange();
41159+
41160 return rtc_set_time(rtc, &tm);
41161
41162 case RTC_PIE_ON:
41163diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
41164index e0d0ba4..3c65868 100644
41165--- a/drivers/rtc/rtc-ds1307.c
41166+++ b/drivers/rtc/rtc-ds1307.c
41167@@ -106,7 +106,7 @@ struct ds1307 {
41168 u8 offset; /* register's offset */
41169 u8 regs[11];
41170 u16 nvram_offset;
41171- struct bin_attribute *nvram;
41172+ bin_attribute_no_const *nvram;
41173 enum ds_type type;
41174 unsigned long flags;
41175 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
41176diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
41177index 130f29a..6179d03 100644
41178--- a/drivers/rtc/rtc-m48t59.c
41179+++ b/drivers/rtc/rtc-m48t59.c
41180@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
41181 goto out;
41182 }
41183
41184- m48t59_nvram_attr.size = pdata->offset;
41185+ pax_open_kernel();
41186+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
41187+ pax_close_kernel();
41188
41189 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
41190 if (ret) {
41191diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
41192index e693af6..2e525b6 100644
41193--- a/drivers/scsi/bfa/bfa_fcpim.h
41194+++ b/drivers/scsi/bfa/bfa_fcpim.h
41195@@ -36,7 +36,7 @@ struct bfa_iotag_s {
41196
41197 struct bfa_itn_s {
41198 bfa_isr_func_t isr;
41199-};
41200+} __no_const;
41201
41202 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
41203 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
41204diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
41205index 23a90e7..9cf04ee 100644
41206--- a/drivers/scsi/bfa/bfa_ioc.h
41207+++ b/drivers/scsi/bfa/bfa_ioc.h
41208@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
41209 bfa_ioc_disable_cbfn_t disable_cbfn;
41210 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
41211 bfa_ioc_reset_cbfn_t reset_cbfn;
41212-};
41213+} __no_const;
41214
41215 /*
41216 * IOC event notification mechanism.
41217@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
41218 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
41219 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
41220 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
41221-};
41222+} __no_const;
41223
41224 /*
41225 * Queue element to wait for room in request queue. FIFO order is
41226diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
41227index 593085a..47aa999 100644
41228--- a/drivers/scsi/hosts.c
41229+++ b/drivers/scsi/hosts.c
41230@@ -42,7 +42,7 @@
41231 #include "scsi_logging.h"
41232
41233
41234-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41235+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41236
41237
41238 static void scsi_host_cls_release(struct device *dev)
41239@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
41240 * subtract one because we increment first then return, but we need to
41241 * know what the next host number was before increment
41242 */
41243- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
41244+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
41245 shost->dma_channel = 0xff;
41246
41247 /* These three are default values which can be overridden */
41248diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
41249index 4f33806..afd6f60 100644
41250--- a/drivers/scsi/hpsa.c
41251+++ b/drivers/scsi/hpsa.c
41252@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
41253 unsigned long flags;
41254
41255 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
41256- return h->access.command_completed(h, q);
41257+ return h->access->command_completed(h, q);
41258
41259 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
41260 a = rq->head[rq->current_entry];
41261@@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
41262 while (!list_empty(&h->reqQ)) {
41263 c = list_entry(h->reqQ.next, struct CommandList, list);
41264 /* can't do anything if fifo is full */
41265- if ((h->access.fifo_full(h))) {
41266+ if ((h->access->fifo_full(h))) {
41267 dev_warn(&h->pdev->dev, "fifo full\n");
41268 break;
41269 }
41270@@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
41271
41272 /* Tell the controller execute command */
41273 spin_unlock_irqrestore(&h->lock, flags);
41274- h->access.submit_command(h, c);
41275+ h->access->submit_command(h, c);
41276 spin_lock_irqsave(&h->lock, flags);
41277 }
41278 spin_unlock_irqrestore(&h->lock, flags);
41279@@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
41280
41281 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
41282 {
41283- return h->access.command_completed(h, q);
41284+ return h->access->command_completed(h, q);
41285 }
41286
41287 static inline bool interrupt_pending(struct ctlr_info *h)
41288 {
41289- return h->access.intr_pending(h);
41290+ return h->access->intr_pending(h);
41291 }
41292
41293 static inline long interrupt_not_for_us(struct ctlr_info *h)
41294 {
41295- return (h->access.intr_pending(h) == 0) ||
41296+ return (h->access->intr_pending(h) == 0) ||
41297 (h->interrupts_enabled == 0);
41298 }
41299
41300@@ -4316,7 +4316,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
41301 if (prod_index < 0)
41302 return -ENODEV;
41303 h->product_name = products[prod_index].product_name;
41304- h->access = *(products[prod_index].access);
41305+ h->access = products[prod_index].access;
41306
41307 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
41308 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
41309@@ -4598,7 +4598,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
41310
41311 assert_spin_locked(&lockup_detector_lock);
41312 remove_ctlr_from_lockup_detector_list(h);
41313- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41314+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41315 spin_lock_irqsave(&h->lock, flags);
41316 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
41317 spin_unlock_irqrestore(&h->lock, flags);
41318@@ -4775,7 +4775,7 @@ reinit_after_soft_reset:
41319 }
41320
41321 /* make sure the board interrupts are off */
41322- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41323+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41324
41325 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
41326 goto clean2;
41327@@ -4809,7 +4809,7 @@ reinit_after_soft_reset:
41328 * fake ones to scoop up any residual completions.
41329 */
41330 spin_lock_irqsave(&h->lock, flags);
41331- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41332+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41333 spin_unlock_irqrestore(&h->lock, flags);
41334 free_irqs(h);
41335 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
41336@@ -4828,9 +4828,9 @@ reinit_after_soft_reset:
41337 dev_info(&h->pdev->dev, "Board READY.\n");
41338 dev_info(&h->pdev->dev,
41339 "Waiting for stale completions to drain.\n");
41340- h->access.set_intr_mask(h, HPSA_INTR_ON);
41341+ h->access->set_intr_mask(h, HPSA_INTR_ON);
41342 msleep(10000);
41343- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41344+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41345
41346 rc = controller_reset_failed(h->cfgtable);
41347 if (rc)
41348@@ -4851,7 +4851,7 @@ reinit_after_soft_reset:
41349 }
41350
41351 /* Turn the interrupts on so we can service requests */
41352- h->access.set_intr_mask(h, HPSA_INTR_ON);
41353+ h->access->set_intr_mask(h, HPSA_INTR_ON);
41354
41355 hpsa_hba_inquiry(h);
41356 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
41357@@ -4903,7 +4903,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
41358 * To write all data in the battery backed cache to disks
41359 */
41360 hpsa_flush_cache(h);
41361- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41362+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41363 hpsa_free_irqs_and_disable_msix(h);
41364 }
41365
41366@@ -5071,7 +5071,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
41367 return;
41368 }
41369 /* Change the access methods to the performant access methods */
41370- h->access = SA5_performant_access;
41371+ h->access = &SA5_performant_access;
41372 h->transMethod = CFGTBL_Trans_Performant;
41373 }
41374
41375diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
41376index 9816479..c5d4e97 100644
41377--- a/drivers/scsi/hpsa.h
41378+++ b/drivers/scsi/hpsa.h
41379@@ -79,7 +79,7 @@ struct ctlr_info {
41380 unsigned int msix_vector;
41381 unsigned int msi_vector;
41382 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
41383- struct access_method access;
41384+ struct access_method *access;
41385
41386 /* queue and queue Info */
41387 struct list_head reqQ;
41388diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
41389index c772d8d..35c362c 100644
41390--- a/drivers/scsi/libfc/fc_exch.c
41391+++ b/drivers/scsi/libfc/fc_exch.c
41392@@ -100,12 +100,12 @@ struct fc_exch_mgr {
41393 u16 pool_max_index;
41394
41395 struct {
41396- atomic_t no_free_exch;
41397- atomic_t no_free_exch_xid;
41398- atomic_t xid_not_found;
41399- atomic_t xid_busy;
41400- atomic_t seq_not_found;
41401- atomic_t non_bls_resp;
41402+ atomic_unchecked_t no_free_exch;
41403+ atomic_unchecked_t no_free_exch_xid;
41404+ atomic_unchecked_t xid_not_found;
41405+ atomic_unchecked_t xid_busy;
41406+ atomic_unchecked_t seq_not_found;
41407+ atomic_unchecked_t non_bls_resp;
41408 } stats;
41409 };
41410
41411@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
41412 /* allocate memory for exchange */
41413 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
41414 if (!ep) {
41415- atomic_inc(&mp->stats.no_free_exch);
41416+ atomic_inc_unchecked(&mp->stats.no_free_exch);
41417 goto out;
41418 }
41419 memset(ep, 0, sizeof(*ep));
41420@@ -786,7 +786,7 @@ out:
41421 return ep;
41422 err:
41423 spin_unlock_bh(&pool->lock);
41424- atomic_inc(&mp->stats.no_free_exch_xid);
41425+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
41426 mempool_free(ep, mp->ep_pool);
41427 return NULL;
41428 }
41429@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41430 xid = ntohs(fh->fh_ox_id); /* we originated exch */
41431 ep = fc_exch_find(mp, xid);
41432 if (!ep) {
41433- atomic_inc(&mp->stats.xid_not_found);
41434+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41435 reject = FC_RJT_OX_ID;
41436 goto out;
41437 }
41438@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41439 ep = fc_exch_find(mp, xid);
41440 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
41441 if (ep) {
41442- atomic_inc(&mp->stats.xid_busy);
41443+ atomic_inc_unchecked(&mp->stats.xid_busy);
41444 reject = FC_RJT_RX_ID;
41445 goto rel;
41446 }
41447@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41448 }
41449 xid = ep->xid; /* get our XID */
41450 } else if (!ep) {
41451- atomic_inc(&mp->stats.xid_not_found);
41452+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41453 reject = FC_RJT_RX_ID; /* XID not found */
41454 goto out;
41455 }
41456@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41457 } else {
41458 sp = &ep->seq;
41459 if (sp->id != fh->fh_seq_id) {
41460- atomic_inc(&mp->stats.seq_not_found);
41461+ atomic_inc_unchecked(&mp->stats.seq_not_found);
41462 if (f_ctl & FC_FC_END_SEQ) {
41463 /*
41464 * Update sequence_id based on incoming last
41465@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41466
41467 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
41468 if (!ep) {
41469- atomic_inc(&mp->stats.xid_not_found);
41470+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41471 goto out;
41472 }
41473 if (ep->esb_stat & ESB_ST_COMPLETE) {
41474- atomic_inc(&mp->stats.xid_not_found);
41475+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41476 goto rel;
41477 }
41478 if (ep->rxid == FC_XID_UNKNOWN)
41479 ep->rxid = ntohs(fh->fh_rx_id);
41480 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
41481- atomic_inc(&mp->stats.xid_not_found);
41482+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41483 goto rel;
41484 }
41485 if (ep->did != ntoh24(fh->fh_s_id) &&
41486 ep->did != FC_FID_FLOGI) {
41487- atomic_inc(&mp->stats.xid_not_found);
41488+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41489 goto rel;
41490 }
41491 sof = fr_sof(fp);
41492@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41493 sp->ssb_stat |= SSB_ST_RESP;
41494 sp->id = fh->fh_seq_id;
41495 } else if (sp->id != fh->fh_seq_id) {
41496- atomic_inc(&mp->stats.seq_not_found);
41497+ atomic_inc_unchecked(&mp->stats.seq_not_found);
41498 goto rel;
41499 }
41500
41501@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41502 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
41503
41504 if (!sp)
41505- atomic_inc(&mp->stats.xid_not_found);
41506+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41507 else
41508- atomic_inc(&mp->stats.non_bls_resp);
41509+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
41510
41511 fc_frame_free(fp);
41512 }
41513@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
41514
41515 list_for_each_entry(ema, &lport->ema_list, ema_list) {
41516 mp = ema->mp;
41517- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
41518+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
41519 st->fc_no_free_exch_xid +=
41520- atomic_read(&mp->stats.no_free_exch_xid);
41521- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
41522- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
41523- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
41524- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
41525+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
41526+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
41527+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
41528+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
41529+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
41530 }
41531 }
41532 EXPORT_SYMBOL(fc_exch_update_stats);
41533diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
41534index bdb81cd..d3c7c2c 100644
41535--- a/drivers/scsi/libsas/sas_ata.c
41536+++ b/drivers/scsi/libsas/sas_ata.c
41537@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
41538 .postreset = ata_std_postreset,
41539 .error_handler = ata_std_error_handler,
41540 .post_internal_cmd = sas_ata_post_internal,
41541- .qc_defer = ata_std_qc_defer,
41542+ .qc_defer = ata_std_qc_defer,
41543 .qc_prep = ata_noop_qc_prep,
41544 .qc_issue = sas_ata_qc_issue,
41545 .qc_fill_rtf = sas_ata_qc_fill_rtf,
41546diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
41547index df4c13a..a51e90c 100644
41548--- a/drivers/scsi/lpfc/lpfc.h
41549+++ b/drivers/scsi/lpfc/lpfc.h
41550@@ -424,7 +424,7 @@ struct lpfc_vport {
41551 struct dentry *debug_nodelist;
41552 struct dentry *vport_debugfs_root;
41553 struct lpfc_debugfs_trc *disc_trc;
41554- atomic_t disc_trc_cnt;
41555+ atomic_unchecked_t disc_trc_cnt;
41556 #endif
41557 uint8_t stat_data_enabled;
41558 uint8_t stat_data_blocked;
41559@@ -842,8 +842,8 @@ struct lpfc_hba {
41560 struct timer_list fabric_block_timer;
41561 unsigned long bit_flags;
41562 #define FABRIC_COMANDS_BLOCKED 0
41563- atomic_t num_rsrc_err;
41564- atomic_t num_cmd_success;
41565+ atomic_unchecked_t num_rsrc_err;
41566+ atomic_unchecked_t num_cmd_success;
41567 unsigned long last_rsrc_error_time;
41568 unsigned long last_ramp_down_time;
41569 unsigned long last_ramp_up_time;
41570@@ -879,7 +879,7 @@ struct lpfc_hba {
41571
41572 struct dentry *debug_slow_ring_trc;
41573 struct lpfc_debugfs_trc *slow_ring_trc;
41574- atomic_t slow_ring_trc_cnt;
41575+ atomic_unchecked_t slow_ring_trc_cnt;
41576 /* iDiag debugfs sub-directory */
41577 struct dentry *idiag_root;
41578 struct dentry *idiag_pci_cfg;
41579diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
41580index f63f5ff..de29189 100644
41581--- a/drivers/scsi/lpfc/lpfc_debugfs.c
41582+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
41583@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
41584
41585 #include <linux/debugfs.h>
41586
41587-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41588+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41589 static unsigned long lpfc_debugfs_start_time = 0L;
41590
41591 /* iDiag */
41592@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
41593 lpfc_debugfs_enable = 0;
41594
41595 len = 0;
41596- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
41597+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
41598 (lpfc_debugfs_max_disc_trc - 1);
41599 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
41600 dtp = vport->disc_trc + i;
41601@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
41602 lpfc_debugfs_enable = 0;
41603
41604 len = 0;
41605- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
41606+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
41607 (lpfc_debugfs_max_slow_ring_trc - 1);
41608 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
41609 dtp = phba->slow_ring_trc + i;
41610@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
41611 !vport || !vport->disc_trc)
41612 return;
41613
41614- index = atomic_inc_return(&vport->disc_trc_cnt) &
41615+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
41616 (lpfc_debugfs_max_disc_trc - 1);
41617 dtp = vport->disc_trc + index;
41618 dtp->fmt = fmt;
41619 dtp->data1 = data1;
41620 dtp->data2 = data2;
41621 dtp->data3 = data3;
41622- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41623+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41624 dtp->jif = jiffies;
41625 #endif
41626 return;
41627@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
41628 !phba || !phba->slow_ring_trc)
41629 return;
41630
41631- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
41632+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
41633 (lpfc_debugfs_max_slow_ring_trc - 1);
41634 dtp = phba->slow_ring_trc + index;
41635 dtp->fmt = fmt;
41636 dtp->data1 = data1;
41637 dtp->data2 = data2;
41638 dtp->data3 = data3;
41639- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41640+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41641 dtp->jif = jiffies;
41642 #endif
41643 return;
41644@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41645 "slow_ring buffer\n");
41646 goto debug_failed;
41647 }
41648- atomic_set(&phba->slow_ring_trc_cnt, 0);
41649+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
41650 memset(phba->slow_ring_trc, 0,
41651 (sizeof(struct lpfc_debugfs_trc) *
41652 lpfc_debugfs_max_slow_ring_trc));
41653@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41654 "buffer\n");
41655 goto debug_failed;
41656 }
41657- atomic_set(&vport->disc_trc_cnt, 0);
41658+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
41659
41660 snprintf(name, sizeof(name), "discovery_trace");
41661 vport->debug_disc_trc =
41662diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
41663index 89ad558..76956c4 100644
41664--- a/drivers/scsi/lpfc/lpfc_init.c
41665+++ b/drivers/scsi/lpfc/lpfc_init.c
41666@@ -10618,8 +10618,10 @@ lpfc_init(void)
41667 "misc_register returned with status %d", error);
41668
41669 if (lpfc_enable_npiv) {
41670- lpfc_transport_functions.vport_create = lpfc_vport_create;
41671- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41672+ pax_open_kernel();
41673+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
41674+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41675+ pax_close_kernel();
41676 }
41677 lpfc_transport_template =
41678 fc_attach_transport(&lpfc_transport_functions);
41679diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
41680index 60e5a17..ff7a793 100644
41681--- a/drivers/scsi/lpfc/lpfc_scsi.c
41682+++ b/drivers/scsi/lpfc/lpfc_scsi.c
41683@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
41684 uint32_t evt_posted;
41685
41686 spin_lock_irqsave(&phba->hbalock, flags);
41687- atomic_inc(&phba->num_rsrc_err);
41688+ atomic_inc_unchecked(&phba->num_rsrc_err);
41689 phba->last_rsrc_error_time = jiffies;
41690
41691 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
41692@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
41693 unsigned long flags;
41694 struct lpfc_hba *phba = vport->phba;
41695 uint32_t evt_posted;
41696- atomic_inc(&phba->num_cmd_success);
41697+ atomic_inc_unchecked(&phba->num_cmd_success);
41698
41699 if (vport->cfg_lun_queue_depth <= queue_depth)
41700 return;
41701@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41702 unsigned long num_rsrc_err, num_cmd_success;
41703 int i;
41704
41705- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
41706- num_cmd_success = atomic_read(&phba->num_cmd_success);
41707+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
41708+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
41709
41710 /*
41711 * The error and success command counters are global per
41712@@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41713 }
41714 }
41715 lpfc_destroy_vport_work_array(phba, vports);
41716- atomic_set(&phba->num_rsrc_err, 0);
41717- atomic_set(&phba->num_cmd_success, 0);
41718+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
41719+ atomic_set_unchecked(&phba->num_cmd_success, 0);
41720 }
41721
41722 /**
41723@@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
41724 }
41725 }
41726 lpfc_destroy_vport_work_array(phba, vports);
41727- atomic_set(&phba->num_rsrc_err, 0);
41728- atomic_set(&phba->num_cmd_success, 0);
41729+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
41730+ atomic_set_unchecked(&phba->num_cmd_success, 0);
41731 }
41732
41733 /**
41734diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
41735index b46f5e9..c4c4ccb 100644
41736--- a/drivers/scsi/pmcraid.c
41737+++ b/drivers/scsi/pmcraid.c
41738@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
41739 res->scsi_dev = scsi_dev;
41740 scsi_dev->hostdata = res;
41741 res->change_detected = 0;
41742- atomic_set(&res->read_failures, 0);
41743- atomic_set(&res->write_failures, 0);
41744+ atomic_set_unchecked(&res->read_failures, 0);
41745+ atomic_set_unchecked(&res->write_failures, 0);
41746 rc = 0;
41747 }
41748 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
41749@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
41750
41751 /* If this was a SCSI read/write command keep count of errors */
41752 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
41753- atomic_inc(&res->read_failures);
41754+ atomic_inc_unchecked(&res->read_failures);
41755 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
41756- atomic_inc(&res->write_failures);
41757+ atomic_inc_unchecked(&res->write_failures);
41758
41759 if (!RES_IS_GSCSI(res->cfg_entry) &&
41760 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
41761@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
41762 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
41763 * hrrq_id assigned here in queuecommand
41764 */
41765- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
41766+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
41767 pinstance->num_hrrq;
41768 cmd->cmd_done = pmcraid_io_done;
41769
41770@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
41771 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
41772 * hrrq_id assigned here in queuecommand
41773 */
41774- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
41775+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
41776 pinstance->num_hrrq;
41777
41778 if (request_size) {
41779@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
41780
41781 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
41782 /* add resources only after host is added into system */
41783- if (!atomic_read(&pinstance->expose_resources))
41784+ if (!atomic_read_unchecked(&pinstance->expose_resources))
41785 return;
41786
41787 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
41788@@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
41789 init_waitqueue_head(&pinstance->reset_wait_q);
41790
41791 atomic_set(&pinstance->outstanding_cmds, 0);
41792- atomic_set(&pinstance->last_message_id, 0);
41793- atomic_set(&pinstance->expose_resources, 0);
41794+ atomic_set_unchecked(&pinstance->last_message_id, 0);
41795+ atomic_set_unchecked(&pinstance->expose_resources, 0);
41796
41797 INIT_LIST_HEAD(&pinstance->free_res_q);
41798 INIT_LIST_HEAD(&pinstance->used_res_q);
41799@@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
41800 /* Schedule worker thread to handle CCN and take care of adding and
41801 * removing devices to OS
41802 */
41803- atomic_set(&pinstance->expose_resources, 1);
41804+ atomic_set_unchecked(&pinstance->expose_resources, 1);
41805 schedule_work(&pinstance->worker_q);
41806 return rc;
41807
41808diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
41809index e1d150f..6c6df44 100644
41810--- a/drivers/scsi/pmcraid.h
41811+++ b/drivers/scsi/pmcraid.h
41812@@ -748,7 +748,7 @@ struct pmcraid_instance {
41813 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
41814
41815 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
41816- atomic_t last_message_id;
41817+ atomic_unchecked_t last_message_id;
41818
41819 /* configuration table */
41820 struct pmcraid_config_table *cfg_table;
41821@@ -777,7 +777,7 @@ struct pmcraid_instance {
41822 atomic_t outstanding_cmds;
41823
41824 /* should add/delete resources to mid-layer now ?*/
41825- atomic_t expose_resources;
41826+ atomic_unchecked_t expose_resources;
41827
41828
41829
41830@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
41831 struct pmcraid_config_table_entry_ext cfg_entry_ext;
41832 };
41833 struct scsi_device *scsi_dev; /* Link scsi_device structure */
41834- atomic_t read_failures; /* count of failed READ commands */
41835- atomic_t write_failures; /* count of failed WRITE commands */
41836+ atomic_unchecked_t read_failures; /* count of failed READ commands */
41837+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
41838
41839 /* To indicate add/delete/modify during CCN */
41840 u8 change_detected;
41841diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
41842index 83d7984..a27d947 100644
41843--- a/drivers/scsi/qla2xxx/qla_attr.c
41844+++ b/drivers/scsi/qla2xxx/qla_attr.c
41845@@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
41846 return 0;
41847 }
41848
41849-struct fc_function_template qla2xxx_transport_functions = {
41850+fc_function_template_no_const qla2xxx_transport_functions = {
41851
41852 .show_host_node_name = 1,
41853 .show_host_port_name = 1,
41854@@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
41855 .bsg_timeout = qla24xx_bsg_timeout,
41856 };
41857
41858-struct fc_function_template qla2xxx_transport_vport_functions = {
41859+fc_function_template_no_const qla2xxx_transport_vport_functions = {
41860
41861 .show_host_node_name = 1,
41862 .show_host_port_name = 1,
41863diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
41864index 2411d1a..4673766 100644
41865--- a/drivers/scsi/qla2xxx/qla_gbl.h
41866+++ b/drivers/scsi/qla2xxx/qla_gbl.h
41867@@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
41868 struct device_attribute;
41869 extern struct device_attribute *qla2x00_host_attrs[];
41870 struct fc_function_template;
41871-extern struct fc_function_template qla2xxx_transport_functions;
41872-extern struct fc_function_template qla2xxx_transport_vport_functions;
41873+extern fc_function_template_no_const qla2xxx_transport_functions;
41874+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
41875 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
41876 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
41877 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
41878diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
41879index 10d23f8..a7d5d4c 100644
41880--- a/drivers/scsi/qla2xxx/qla_os.c
41881+++ b/drivers/scsi/qla2xxx/qla_os.c
41882@@ -1472,8 +1472,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
41883 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
41884 /* Ok, a 64bit DMA mask is applicable. */
41885 ha->flags.enable_64bit_addressing = 1;
41886- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
41887- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
41888+ pax_open_kernel();
41889+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
41890+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
41891+ pax_close_kernel();
41892 return;
41893 }
41894 }
41895diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
41896index 329d553..f20d31d 100644
41897--- a/drivers/scsi/qla4xxx/ql4_def.h
41898+++ b/drivers/scsi/qla4xxx/ql4_def.h
41899@@ -273,7 +273,7 @@ struct ddb_entry {
41900 * (4000 only) */
41901 atomic_t relogin_timer; /* Max Time to wait for
41902 * relogin to complete */
41903- atomic_t relogin_retry_count; /* Num of times relogin has been
41904+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
41905 * retried */
41906 uint32_t default_time2wait; /* Default Min time between
41907 * relogins (+aens) */
41908diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
41909index 4cec123..7c1329f 100644
41910--- a/drivers/scsi/qla4xxx/ql4_os.c
41911+++ b/drivers/scsi/qla4xxx/ql4_os.c
41912@@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
41913 */
41914 if (!iscsi_is_session_online(cls_sess)) {
41915 /* Reset retry relogin timer */
41916- atomic_inc(&ddb_entry->relogin_retry_count);
41917+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
41918 DEBUG2(ql4_printk(KERN_INFO, ha,
41919 "%s: index[%d] relogin timed out-retrying"
41920 " relogin (%d), retry (%d)\n", __func__,
41921 ddb_entry->fw_ddb_index,
41922- atomic_read(&ddb_entry->relogin_retry_count),
41923+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
41924 ddb_entry->default_time2wait + 4));
41925 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
41926 atomic_set(&ddb_entry->retry_relogin_timer,
41927@@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
41928
41929 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
41930 atomic_set(&ddb_entry->relogin_timer, 0);
41931- atomic_set(&ddb_entry->relogin_retry_count, 0);
41932+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
41933 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
41934 ddb_entry->default_relogin_timeout =
41935 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
41936diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
41937index 2c0d0ec..4e8681a 100644
41938--- a/drivers/scsi/scsi.c
41939+++ b/drivers/scsi/scsi.c
41940@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
41941 unsigned long timeout;
41942 int rtn = 0;
41943
41944- atomic_inc(&cmd->device->iorequest_cnt);
41945+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41946
41947 /* check if the device is still usable */
41948 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
41949diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
41950index f1bf5af..f67e943 100644
41951--- a/drivers/scsi/scsi_lib.c
41952+++ b/drivers/scsi/scsi_lib.c
41953@@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
41954 shost = sdev->host;
41955 scsi_init_cmd_errh(cmd);
41956 cmd->result = DID_NO_CONNECT << 16;
41957- atomic_inc(&cmd->device->iorequest_cnt);
41958+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41959
41960 /*
41961 * SCSI request completion path will do scsi_device_unbusy(),
41962@@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
41963
41964 INIT_LIST_HEAD(&cmd->eh_entry);
41965
41966- atomic_inc(&cmd->device->iodone_cnt);
41967+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
41968 if (cmd->result)
41969- atomic_inc(&cmd->device->ioerr_cnt);
41970+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
41971
41972 disposition = scsi_decide_disposition(cmd);
41973 if (disposition != SUCCESS &&
41974diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
41975index 931a7d9..0c2a754 100644
41976--- a/drivers/scsi/scsi_sysfs.c
41977+++ b/drivers/scsi/scsi_sysfs.c
41978@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
41979 char *buf) \
41980 { \
41981 struct scsi_device *sdev = to_scsi_device(dev); \
41982- unsigned long long count = atomic_read(&sdev->field); \
41983+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
41984 return snprintf(buf, 20, "0x%llx\n", count); \
41985 } \
41986 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
41987diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
41988index 84a1fdf..693b0d6 100644
41989--- a/drivers/scsi/scsi_tgt_lib.c
41990+++ b/drivers/scsi/scsi_tgt_lib.c
41991@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
41992 int err;
41993
41994 dprintk("%lx %u\n", uaddr, len);
41995- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
41996+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
41997 if (err) {
41998 /*
41999 * TODO: need to fixup sg_tablesize, max_segment_size,
42000diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
42001index e894ca7..de9d7660 100644
42002--- a/drivers/scsi/scsi_transport_fc.c
42003+++ b/drivers/scsi/scsi_transport_fc.c
42004@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
42005 * Netlink Infrastructure
42006 */
42007
42008-static atomic_t fc_event_seq;
42009+static atomic_unchecked_t fc_event_seq;
42010
42011 /**
42012 * fc_get_event_number - Obtain the next sequential FC event number
42013@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
42014 u32
42015 fc_get_event_number(void)
42016 {
42017- return atomic_add_return(1, &fc_event_seq);
42018+ return atomic_add_return_unchecked(1, &fc_event_seq);
42019 }
42020 EXPORT_SYMBOL(fc_get_event_number);
42021
42022@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
42023 {
42024 int error;
42025
42026- atomic_set(&fc_event_seq, 0);
42027+ atomic_set_unchecked(&fc_event_seq, 0);
42028
42029 error = transport_class_register(&fc_host_class);
42030 if (error)
42031@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
42032 char *cp;
42033
42034 *val = simple_strtoul(buf, &cp, 0);
42035- if ((*cp && (*cp != '\n')) || (*val < 0))
42036+ if (*cp && (*cp != '\n'))
42037 return -EINVAL;
42038 /*
42039 * Check for overflow; dev_loss_tmo is u32
42040diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
42041index 31969f2..2b348f0 100644
42042--- a/drivers/scsi/scsi_transport_iscsi.c
42043+++ b/drivers/scsi/scsi_transport_iscsi.c
42044@@ -79,7 +79,7 @@ struct iscsi_internal {
42045 struct transport_container session_cont;
42046 };
42047
42048-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
42049+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
42050 static struct workqueue_struct *iscsi_eh_timer_workq;
42051
42052 static DEFINE_IDA(iscsi_sess_ida);
42053@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
42054 int err;
42055
42056 ihost = shost->shost_data;
42057- session->sid = atomic_add_return(1, &iscsi_session_nr);
42058+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
42059
42060 if (target_id == ISCSI_MAX_TARGET) {
42061 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
42062@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
42063 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
42064 ISCSI_TRANSPORT_VERSION);
42065
42066- atomic_set(&iscsi_session_nr, 0);
42067+ atomic_set_unchecked(&iscsi_session_nr, 0);
42068
42069 err = class_register(&iscsi_transport_class);
42070 if (err)
42071diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
42072index f379c7f..e8fc69c 100644
42073--- a/drivers/scsi/scsi_transport_srp.c
42074+++ b/drivers/scsi/scsi_transport_srp.c
42075@@ -33,7 +33,7 @@
42076 #include "scsi_transport_srp_internal.h"
42077
42078 struct srp_host_attrs {
42079- atomic_t next_port_id;
42080+ atomic_unchecked_t next_port_id;
42081 };
42082 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
42083
42084@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
42085 struct Scsi_Host *shost = dev_to_shost(dev);
42086 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
42087
42088- atomic_set(&srp_host->next_port_id, 0);
42089+ atomic_set_unchecked(&srp_host->next_port_id, 0);
42090 return 0;
42091 }
42092
42093@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
42094 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
42095 rport->roles = ids->roles;
42096
42097- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
42098+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
42099 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
42100
42101 transport_setup_device(&rport->dev);
42102diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
42103index 7992635..609faf8 100644
42104--- a/drivers/scsi/sd.c
42105+++ b/drivers/scsi/sd.c
42106@@ -2909,7 +2909,7 @@ static int sd_probe(struct device *dev)
42107 sdkp->disk = gd;
42108 sdkp->index = index;
42109 atomic_set(&sdkp->openers, 0);
42110- atomic_set(&sdkp->device->ioerr_cnt, 0);
42111+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
42112
42113 if (!sdp->request_queue->rq_timeout) {
42114 if (sdp->type != TYPE_MOD)
42115diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
42116index be2c9a6..275525c 100644
42117--- a/drivers/scsi/sg.c
42118+++ b/drivers/scsi/sg.c
42119@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
42120 sdp->disk->disk_name,
42121 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
42122 NULL,
42123- (char *)arg);
42124+ (char __user *)arg);
42125 case BLKTRACESTART:
42126 return blk_trace_startstop(sdp->device->request_queue, 1);
42127 case BLKTRACESTOP:
42128diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
42129index 19ee901..6e8c2ef 100644
42130--- a/drivers/spi/spi.c
42131+++ b/drivers/spi/spi.c
42132@@ -1616,7 +1616,7 @@ int spi_bus_unlock(struct spi_master *master)
42133 EXPORT_SYMBOL_GPL(spi_bus_unlock);
42134
42135 /* portable code must never pass more than 32 bytes */
42136-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
42137+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
42138
42139 static u8 *buf;
42140
42141diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
42142index c7a5f97..71ecd35 100644
42143--- a/drivers/staging/iio/iio_hwmon.c
42144+++ b/drivers/staging/iio/iio_hwmon.c
42145@@ -72,7 +72,7 @@ static void iio_hwmon_free_attrs(struct iio_hwmon_state *st)
42146 static int iio_hwmon_probe(struct platform_device *pdev)
42147 {
42148 struct iio_hwmon_state *st;
42149- struct sensor_device_attribute *a;
42150+ sensor_device_attribute_no_const *a;
42151 int ret, i;
42152 int in_i = 1, temp_i = 1, curr_i = 1;
42153 enum iio_chan_type type;
42154diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
42155index 34afc16..ffe44dd 100644
42156--- a/drivers/staging/octeon/ethernet-rx.c
42157+++ b/drivers/staging/octeon/ethernet-rx.c
42158@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42159 /* Increment RX stats for virtual ports */
42160 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
42161 #ifdef CONFIG_64BIT
42162- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
42163- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
42164+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
42165+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
42166 #else
42167- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
42168- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
42169+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
42170+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
42171 #endif
42172 }
42173 netif_receive_skb(skb);
42174@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42175 dev->name);
42176 */
42177 #ifdef CONFIG_64BIT
42178- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
42179+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42180 #else
42181- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
42182+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
42183 #endif
42184 dev_kfree_skb_irq(skb);
42185 }
42186diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
42187index ef32dc1..a159d68 100644
42188--- a/drivers/staging/octeon/ethernet.c
42189+++ b/drivers/staging/octeon/ethernet.c
42190@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
42191 * since the RX tasklet also increments it.
42192 */
42193 #ifdef CONFIG_64BIT
42194- atomic64_add(rx_status.dropped_packets,
42195- (atomic64_t *)&priv->stats.rx_dropped);
42196+ atomic64_add_unchecked(rx_status.dropped_packets,
42197+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42198 #else
42199- atomic_add(rx_status.dropped_packets,
42200- (atomic_t *)&priv->stats.rx_dropped);
42201+ atomic_add_unchecked(rx_status.dropped_packets,
42202+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
42203 #endif
42204 }
42205
42206diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
42207index a2b7e03..aaf3630 100644
42208--- a/drivers/staging/ramster/tmem.c
42209+++ b/drivers/staging/ramster/tmem.c
42210@@ -50,25 +50,25 @@
42211 * A tmem host implementation must use this function to register callbacks
42212 * for memory allocation.
42213 */
42214-static struct tmem_hostops tmem_hostops;
42215+static struct tmem_hostops *tmem_hostops;
42216
42217 static void tmem_objnode_tree_init(void);
42218
42219 void tmem_register_hostops(struct tmem_hostops *m)
42220 {
42221 tmem_objnode_tree_init();
42222- tmem_hostops = *m;
42223+ tmem_hostops = m;
42224 }
42225
42226 /*
42227 * A tmem host implementation must use this function to register
42228 * callbacks for a page-accessible memory (PAM) implementation.
42229 */
42230-static struct tmem_pamops tmem_pamops;
42231+static struct tmem_pamops *tmem_pamops;
42232
42233 void tmem_register_pamops(struct tmem_pamops *m)
42234 {
42235- tmem_pamops = *m;
42236+ tmem_pamops = m;
42237 }
42238
42239 /*
42240@@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
42241 obj->pampd_count = 0;
42242 #ifdef CONFIG_RAMSTER
42243 if (tmem_pamops.new_obj != NULL)
42244- (*tmem_pamops.new_obj)(obj);
42245+ (tmem_pamops->new_obj)(obj);
42246 #endif
42247 SET_SENTINEL(obj, OBJ);
42248
42249@@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
42250 rbnode = rb_next(rbnode);
42251 tmem_pampd_destroy_all_in_obj(obj, true);
42252 tmem_obj_free(obj, hb);
42253- (*tmem_hostops.obj_free)(obj, pool);
42254+ (tmem_hostops->obj_free)(obj, pool);
42255 }
42256 spin_unlock(&hb->lock);
42257 }
42258@@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
42259 ASSERT_SENTINEL(obj, OBJ);
42260 BUG_ON(obj->pool == NULL);
42261 ASSERT_SENTINEL(obj->pool, POOL);
42262- objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
42263+ objnode = (tmem_hostops->objnode_alloc)(obj->pool);
42264 if (unlikely(objnode == NULL))
42265 goto out;
42266 objnode->obj = obj;
42267@@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
42268 ASSERT_SENTINEL(pool, POOL);
42269 objnode->obj->objnode_count--;
42270 objnode->obj = NULL;
42271- (*tmem_hostops.objnode_free)(objnode, pool);
42272+ (tmem_hostops->objnode_free)(objnode, pool);
42273 }
42274
42275 /*
42276@@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
42277 void *old_pampd = *(void **)slot;
42278 *(void **)slot = new_pampd;
42279 if (!no_free)
42280- (*tmem_pamops.free)(old_pampd, obj->pool,
42281+ (tmem_pamops->free)(old_pampd, obj->pool,
42282 NULL, 0, false);
42283 ret = new_pampd;
42284 }
42285@@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
42286 if (objnode->slots[i]) {
42287 if (ht == 1) {
42288 obj->pampd_count--;
42289- (*tmem_pamops.free)(objnode->slots[i],
42290+ (tmem_pamops->free)(objnode->slots[i],
42291 obj->pool, NULL, 0, true);
42292 objnode->slots[i] = NULL;
42293 continue;
42294@@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
42295 return;
42296 if (obj->objnode_tree_height == 0) {
42297 obj->pampd_count--;
42298- (*tmem_pamops.free)(obj->objnode_tree_root,
42299+ (tmem_pamops->free)(obj->objnode_tree_root,
42300 obj->pool, NULL, 0, true);
42301 } else {
42302 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
42303@@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
42304 obj->objnode_tree_root = NULL;
42305 #ifdef CONFIG_RAMSTER
42306 if (tmem_pamops.free_obj != NULL)
42307- (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
42308+ (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
42309 #endif
42310 }
42311
42312@@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42313 /* if found, is a dup put, flush the old one */
42314 pampd_del = tmem_pampd_delete_from_obj(obj, index);
42315 BUG_ON(pampd_del != pampd);
42316- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
42317+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
42318 if (obj->pampd_count == 0) {
42319 objnew = obj;
42320 objfound = NULL;
42321@@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42322 pampd = NULL;
42323 }
42324 } else {
42325- obj = objnew = (*tmem_hostops.obj_alloc)(pool);
42326+ obj = objnew = (tmem_hostops->obj_alloc)(pool);
42327 if (unlikely(obj == NULL)) {
42328 ret = -ENOMEM;
42329 goto out;
42330@@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42331 if (unlikely(ret == -ENOMEM))
42332 /* may have partially built objnode tree ("stump") */
42333 goto delete_and_free;
42334- (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
42335+ (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
42336 goto out;
42337
42338 delete_and_free:
42339 (void)tmem_pampd_delete_from_obj(obj, index);
42340 if (pampd)
42341- (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
42342+ (tmem_pamops->free)(pampd, pool, NULL, 0, true);
42343 if (objnew) {
42344 tmem_obj_free(objnew, hb);
42345- (*tmem_hostops.obj_free)(objnew, pool);
42346+ (tmem_hostops->obj_free)(objnew, pool);
42347 }
42348 out:
42349 spin_unlock(&hb->lock);
42350@@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
42351 if (pampd != NULL) {
42352 BUG_ON(obj == NULL);
42353 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
42354- (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
42355+ (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
42356 } else if (delete) {
42357 BUG_ON(obj == NULL);
42358 (void)tmem_pampd_delete_from_obj(obj, index);
42359@@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
42360 int ret = 0;
42361
42362 if (!is_ephemeral(pool))
42363- new_pampd = (*tmem_pamops.repatriate_preload)(
42364+ new_pampd = (tmem_pamops->repatriate_preload)(
42365 old_pampd, pool, oidp, index, &intransit);
42366 if (intransit)
42367 ret = -EAGAIN;
42368@@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
42369 /* must release the hb->lock else repatriate can't sleep */
42370 spin_unlock(&hb->lock);
42371 if (!intransit)
42372- ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
42373+ ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
42374 oidp, index, free, data);
42375 if (ret == -EAGAIN) {
42376 /* rare I think, but should cond_resched()??? */
42377@@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
42378 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
42379 /* if we bug here, pamops wasn't properly set up for ramster */
42380 BUG_ON(tmem_pamops.replace_in_obj == NULL);
42381- ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
42382+ ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
42383 out:
42384 spin_unlock(&hb->lock);
42385 return ret;
42386@@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42387 if (free) {
42388 if (obj->pampd_count == 0) {
42389 tmem_obj_free(obj, hb);
42390- (*tmem_hostops.obj_free)(obj, pool);
42391+ (tmem_hostops->obj_free)(obj, pool);
42392 obj = NULL;
42393 }
42394 }
42395 if (free)
42396- ret = (*tmem_pamops.get_data_and_free)(
42397+ ret = (tmem_pamops->get_data_and_free)(
42398 data, sizep, raw, pampd, pool, oidp, index);
42399 else
42400- ret = (*tmem_pamops.get_data)(
42401+ ret = (tmem_pamops->get_data)(
42402 data, sizep, raw, pampd, pool, oidp, index);
42403 if (ret < 0)
42404 goto out;
42405@@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
42406 pampd = tmem_pampd_delete_from_obj(obj, index);
42407 if (pampd == NULL)
42408 goto out;
42409- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
42410+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
42411 if (obj->pampd_count == 0) {
42412 tmem_obj_free(obj, hb);
42413- (*tmem_hostops.obj_free)(obj, pool);
42414+ (tmem_hostops->obj_free)(obj, pool);
42415 }
42416 ret = 0;
42417
42418@@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
42419 goto out;
42420 tmem_pampd_destroy_all_in_obj(obj, false);
42421 tmem_obj_free(obj, hb);
42422- (*tmem_hostops.obj_free)(obj, pool);
42423+ (tmem_hostops->obj_free)(obj, pool);
42424 ret = 0;
42425
42426 out:
42427diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
42428index dc23395..cf7e9b1 100644
42429--- a/drivers/staging/rtl8712/rtl871x_io.h
42430+++ b/drivers/staging/rtl8712/rtl871x_io.h
42431@@ -108,7 +108,7 @@ struct _io_ops {
42432 u8 *pmem);
42433 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
42434 u8 *pmem);
42435-};
42436+} __no_const;
42437
42438 struct io_req {
42439 struct list_head list;
42440diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
42441index 1f5088b..0e59820 100644
42442--- a/drivers/staging/sbe-2t3e3/netdev.c
42443+++ b/drivers/staging/sbe-2t3e3/netdev.c
42444@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42445 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
42446
42447 if (rlen)
42448- if (copy_to_user(data, &resp, rlen))
42449+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
42450 return -EFAULT;
42451
42452 return 0;
42453diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
42454index 5dddc4d..34fcb2f 100644
42455--- a/drivers/staging/usbip/vhci.h
42456+++ b/drivers/staging/usbip/vhci.h
42457@@ -83,7 +83,7 @@ struct vhci_hcd {
42458 unsigned resuming:1;
42459 unsigned long re_timeout;
42460
42461- atomic_t seqnum;
42462+ atomic_unchecked_t seqnum;
42463
42464 /*
42465 * NOTE:
42466diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
42467index c3aa219..bf8b3de 100644
42468--- a/drivers/staging/usbip/vhci_hcd.c
42469+++ b/drivers/staging/usbip/vhci_hcd.c
42470@@ -451,7 +451,7 @@ static void vhci_tx_urb(struct urb *urb)
42471 return;
42472 }
42473
42474- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
42475+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42476 if (priv->seqnum == 0xffff)
42477 dev_info(&urb->dev->dev, "seqnum max\n");
42478
42479@@ -703,7 +703,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
42480 return -ENOMEM;
42481 }
42482
42483- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
42484+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42485 if (unlink->seqnum == 0xffff)
42486 pr_info("seqnum max\n");
42487
42488@@ -907,7 +907,7 @@ static int vhci_start(struct usb_hcd *hcd)
42489 vdev->rhport = rhport;
42490 }
42491
42492- atomic_set(&vhci->seqnum, 0);
42493+ atomic_set_unchecked(&vhci->seqnum, 0);
42494 spin_lock_init(&vhci->lock);
42495
42496 hcd->power_budget = 0; /* no limit */
42497diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
42498index ba5f1c0..11d8122 100644
42499--- a/drivers/staging/usbip/vhci_rx.c
42500+++ b/drivers/staging/usbip/vhci_rx.c
42501@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
42502 if (!urb) {
42503 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
42504 pr_info("max seqnum %d\n",
42505- atomic_read(&the_controller->seqnum));
42506+ atomic_read_unchecked(&the_controller->seqnum));
42507 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
42508 return;
42509 }
42510diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
42511index 5f13890..36a044b 100644
42512--- a/drivers/staging/vt6655/hostap.c
42513+++ b/drivers/staging/vt6655/hostap.c
42514@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
42515 *
42516 */
42517
42518+static net_device_ops_no_const apdev_netdev_ops;
42519+
42520 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42521 {
42522 PSDevice apdev_priv;
42523 struct net_device *dev = pDevice->dev;
42524 int ret;
42525- const struct net_device_ops apdev_netdev_ops = {
42526- .ndo_start_xmit = pDevice->tx_80211,
42527- };
42528
42529 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
42530
42531@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42532 *apdev_priv = *pDevice;
42533 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
42534
42535+ /* only half broken now */
42536+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
42537 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
42538
42539 pDevice->apdev->type = ARPHRD_IEEE80211;
42540diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
42541index 26a7d0e..897b083 100644
42542--- a/drivers/staging/vt6656/hostap.c
42543+++ b/drivers/staging/vt6656/hostap.c
42544@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
42545 *
42546 */
42547
42548+static net_device_ops_no_const apdev_netdev_ops;
42549+
42550 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42551 {
42552 PSDevice apdev_priv;
42553 struct net_device *dev = pDevice->dev;
42554 int ret;
42555- const struct net_device_ops apdev_netdev_ops = {
42556- .ndo_start_xmit = pDevice->tx_80211,
42557- };
42558
42559 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
42560
42561@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42562 *apdev_priv = *pDevice;
42563 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
42564
42565+ /* only half broken now */
42566+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
42567 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
42568
42569 pDevice->apdev->type = ARPHRD_IEEE80211;
42570diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
42571index 56c8e60..1920c63 100644
42572--- a/drivers/staging/zcache/tmem.c
42573+++ b/drivers/staging/zcache/tmem.c
42574@@ -39,7 +39,7 @@
42575 * A tmem host implementation must use this function to register callbacks
42576 * for memory allocation.
42577 */
42578-static struct tmem_hostops tmem_hostops;
42579+static tmem_hostops_no_const tmem_hostops;
42580
42581 static void tmem_objnode_tree_init(void);
42582
42583@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
42584 * A tmem host implementation must use this function to register
42585 * callbacks for a page-accessible memory (PAM) implementation
42586 */
42587-static struct tmem_pamops tmem_pamops;
42588+static tmem_pamops_no_const tmem_pamops;
42589
42590 void tmem_register_pamops(struct tmem_pamops *m)
42591 {
42592diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
42593index 0d4aa82..f7832d4 100644
42594--- a/drivers/staging/zcache/tmem.h
42595+++ b/drivers/staging/zcache/tmem.h
42596@@ -180,6 +180,7 @@ struct tmem_pamops {
42597 void (*new_obj)(struct tmem_obj *);
42598 int (*replace_in_obj)(void *, struct tmem_obj *);
42599 };
42600+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
42601 extern void tmem_register_pamops(struct tmem_pamops *m);
42602
42603 /* memory allocation methods provided by the host implementation */
42604@@ -189,6 +190,7 @@ struct tmem_hostops {
42605 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
42606 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
42607 };
42608+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
42609 extern void tmem_register_hostops(struct tmem_hostops *m);
42610
42611 /* core tmem accessor functions */
42612diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
42613index 96f4981..4daaa7e 100644
42614--- a/drivers/target/target_core_device.c
42615+++ b/drivers/target/target_core_device.c
42616@@ -1370,7 +1370,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
42617 spin_lock_init(&dev->se_port_lock);
42618 spin_lock_init(&dev->se_tmr_lock);
42619 spin_lock_init(&dev->qf_cmd_lock);
42620- atomic_set(&dev->dev_ordered_id, 0);
42621+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
42622 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
42623 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
42624 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
42625diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
42626index bd587b7..173daf3 100644
42627--- a/drivers/target/target_core_transport.c
42628+++ b/drivers/target/target_core_transport.c
42629@@ -1077,7 +1077,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
42630 * Used to determine when ORDERED commands should go from
42631 * Dormant to Active status.
42632 */
42633- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
42634+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
42635 smp_mb__after_atomic_inc();
42636 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
42637 cmd->se_ordered_id, cmd->sam_task_attr,
42638diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
42639index b09c8d1f..c4225c0 100644
42640--- a/drivers/tty/cyclades.c
42641+++ b/drivers/tty/cyclades.c
42642@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
42643 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
42644 info->port.count);
42645 #endif
42646- info->port.count++;
42647+ atomic_inc(&info->port.count);
42648 #ifdef CY_DEBUG_COUNT
42649 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
42650- current->pid, info->port.count);
42651+ current->pid, atomic_read(&info->port.count));
42652 #endif
42653
42654 /*
42655@@ -3991,7 +3991,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
42656 for (j = 0; j < cy_card[i].nports; j++) {
42657 info = &cy_card[i].ports[j];
42658
42659- if (info->port.count) {
42660+ if (atomic_read(&info->port.count)) {
42661 /* XXX is the ldisc num worth this? */
42662 struct tty_struct *tty;
42663 struct tty_ldisc *ld;
42664diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
42665index 13ee53b..418d164 100644
42666--- a/drivers/tty/hvc/hvc_console.c
42667+++ b/drivers/tty/hvc/hvc_console.c
42668@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
42669
42670 spin_lock_irqsave(&hp->port.lock, flags);
42671 /* Check and then increment for fast path open. */
42672- if (hp->port.count++ > 0) {
42673+ if (atomic_inc_return(&hp->port.count) > 1) {
42674 spin_unlock_irqrestore(&hp->port.lock, flags);
42675 hvc_kick();
42676 return 0;
42677@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42678
42679 spin_lock_irqsave(&hp->port.lock, flags);
42680
42681- if (--hp->port.count == 0) {
42682+ if (atomic_dec_return(&hp->port.count) == 0) {
42683 spin_unlock_irqrestore(&hp->port.lock, flags);
42684 /* We are done with the tty pointer now. */
42685 tty_port_tty_set(&hp->port, NULL);
42686@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42687 */
42688 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
42689 } else {
42690- if (hp->port.count < 0)
42691+ if (atomic_read(&hp->port.count) < 0)
42692 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
42693- hp->vtermno, hp->port.count);
42694+ hp->vtermno, atomic_read(&hp->port.count));
42695 spin_unlock_irqrestore(&hp->port.lock, flags);
42696 }
42697 }
42698@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
42699 * open->hangup case this can be called after the final close so prevent
42700 * that from happening for now.
42701 */
42702- if (hp->port.count <= 0) {
42703+ if (atomic_read(&hp->port.count) <= 0) {
42704 spin_unlock_irqrestore(&hp->port.lock, flags);
42705 return;
42706 }
42707
42708- hp->port.count = 0;
42709+ atomic_set(&hp->port.count, 0);
42710 spin_unlock_irqrestore(&hp->port.lock, flags);
42711 tty_port_tty_set(&hp->port, NULL);
42712
42713@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
42714 return -EPIPE;
42715
42716 /* FIXME what's this (unprotected) check for? */
42717- if (hp->port.count <= 0)
42718+ if (atomic_read(&hp->port.count) <= 0)
42719 return -EIO;
42720
42721 spin_lock_irqsave(&hp->lock, flags);
42722diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
42723index 8776357..b2d4afd 100644
42724--- a/drivers/tty/hvc/hvcs.c
42725+++ b/drivers/tty/hvc/hvcs.c
42726@@ -83,6 +83,7 @@
42727 #include <asm/hvcserver.h>
42728 #include <asm/uaccess.h>
42729 #include <asm/vio.h>
42730+#include <asm/local.h>
42731
42732 /*
42733 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
42734@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
42735
42736 spin_lock_irqsave(&hvcsd->lock, flags);
42737
42738- if (hvcsd->port.count > 0) {
42739+ if (atomic_read(&hvcsd->port.count) > 0) {
42740 spin_unlock_irqrestore(&hvcsd->lock, flags);
42741 printk(KERN_INFO "HVCS: vterm state unchanged. "
42742 "The hvcs device node is still in use.\n");
42743@@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
42744 }
42745 }
42746
42747- hvcsd->port.count = 0;
42748+ atomic_set(&hvcsd->port.count, 0);
42749 hvcsd->port.tty = tty;
42750 tty->driver_data = hvcsd;
42751
42752@@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
42753 unsigned long flags;
42754
42755 spin_lock_irqsave(&hvcsd->lock, flags);
42756- hvcsd->port.count++;
42757+ atomic_inc(&hvcsd->port.count);
42758 hvcsd->todo_mask |= HVCS_SCHED_READ;
42759 spin_unlock_irqrestore(&hvcsd->lock, flags);
42760
42761@@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42762 hvcsd = tty->driver_data;
42763
42764 spin_lock_irqsave(&hvcsd->lock, flags);
42765- if (--hvcsd->port.count == 0) {
42766+ if (atomic_dec_and_test(&hvcsd->port.count)) {
42767
42768 vio_disable_interrupts(hvcsd->vdev);
42769
42770@@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42771
42772 free_irq(irq, hvcsd);
42773 return;
42774- } else if (hvcsd->port.count < 0) {
42775+ } else if (atomic_read(&hvcsd->port.count) < 0) {
42776 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
42777 " is missmanaged.\n",
42778- hvcsd->vdev->unit_address, hvcsd->port.count);
42779+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
42780 }
42781
42782 spin_unlock_irqrestore(&hvcsd->lock, flags);
42783@@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42784
42785 spin_lock_irqsave(&hvcsd->lock, flags);
42786 /* Preserve this so that we know how many kref refs to put */
42787- temp_open_count = hvcsd->port.count;
42788+ temp_open_count = atomic_read(&hvcsd->port.count);
42789
42790 /*
42791 * Don't kref put inside the spinlock because the destruction
42792@@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42793 tty->driver_data = NULL;
42794 hvcsd->port.tty = NULL;
42795
42796- hvcsd->port.count = 0;
42797+ atomic_set(&hvcsd->port.count, 0);
42798
42799 /* This will drop any buffered data on the floor which is OK in a hangup
42800 * scenario. */
42801@@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
42802 * the middle of a write operation? This is a crummy place to do this
42803 * but we want to keep it all in the spinlock.
42804 */
42805- if (hvcsd->port.count <= 0) {
42806+ if (atomic_read(&hvcsd->port.count) <= 0) {
42807 spin_unlock_irqrestore(&hvcsd->lock, flags);
42808 return -ENODEV;
42809 }
42810@@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
42811 {
42812 struct hvcs_struct *hvcsd = tty->driver_data;
42813
42814- if (!hvcsd || hvcsd->port.count <= 0)
42815+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
42816 return 0;
42817
42818 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
42819diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
42820index 2cde13d..645d78f 100644
42821--- a/drivers/tty/ipwireless/tty.c
42822+++ b/drivers/tty/ipwireless/tty.c
42823@@ -29,6 +29,7 @@
42824 #include <linux/tty_driver.h>
42825 #include <linux/tty_flip.h>
42826 #include <linux/uaccess.h>
42827+#include <asm/local.h>
42828
42829 #include "tty.h"
42830 #include "network.h"
42831@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
42832 mutex_unlock(&tty->ipw_tty_mutex);
42833 return -ENODEV;
42834 }
42835- if (tty->port.count == 0)
42836+ if (atomic_read(&tty->port.count) == 0)
42837 tty->tx_bytes_queued = 0;
42838
42839- tty->port.count++;
42840+ atomic_inc(&tty->port.count);
42841
42842 tty->port.tty = linux_tty;
42843 linux_tty->driver_data = tty;
42844@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
42845
42846 static void do_ipw_close(struct ipw_tty *tty)
42847 {
42848- tty->port.count--;
42849-
42850- if (tty->port.count == 0) {
42851+ if (atomic_dec_return(&tty->port.count) == 0) {
42852 struct tty_struct *linux_tty = tty->port.tty;
42853
42854 if (linux_tty != NULL) {
42855@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
42856 return;
42857
42858 mutex_lock(&tty->ipw_tty_mutex);
42859- if (tty->port.count == 0) {
42860+ if (atomic_read(&tty->port.count) == 0) {
42861 mutex_unlock(&tty->ipw_tty_mutex);
42862 return;
42863 }
42864@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
42865 return;
42866 }
42867
42868- if (!tty->port.count) {
42869+ if (!atomic_read(&tty->port.count)) {
42870 mutex_unlock(&tty->ipw_tty_mutex);
42871 return;
42872 }
42873@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
42874 return -ENODEV;
42875
42876 mutex_lock(&tty->ipw_tty_mutex);
42877- if (!tty->port.count) {
42878+ if (!atomic_read(&tty->port.count)) {
42879 mutex_unlock(&tty->ipw_tty_mutex);
42880 return -EINVAL;
42881 }
42882@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
42883 if (!tty)
42884 return -ENODEV;
42885
42886- if (!tty->port.count)
42887+ if (!atomic_read(&tty->port.count))
42888 return -EINVAL;
42889
42890 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
42891@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
42892 if (!tty)
42893 return 0;
42894
42895- if (!tty->port.count)
42896+ if (!atomic_read(&tty->port.count))
42897 return 0;
42898
42899 return tty->tx_bytes_queued;
42900@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
42901 if (!tty)
42902 return -ENODEV;
42903
42904- if (!tty->port.count)
42905+ if (!atomic_read(&tty->port.count))
42906 return -EINVAL;
42907
42908 return get_control_lines(tty);
42909@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
42910 if (!tty)
42911 return -ENODEV;
42912
42913- if (!tty->port.count)
42914+ if (!atomic_read(&tty->port.count))
42915 return -EINVAL;
42916
42917 return set_control_lines(tty, set, clear);
42918@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
42919 if (!tty)
42920 return -ENODEV;
42921
42922- if (!tty->port.count)
42923+ if (!atomic_read(&tty->port.count))
42924 return -EINVAL;
42925
42926 /* FIXME: Exactly how is the tty object locked here .. */
42927@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
42928 * are gone */
42929 mutex_lock(&ttyj->ipw_tty_mutex);
42930 }
42931- while (ttyj->port.count)
42932+ while (atomic_read(&ttyj->port.count))
42933 do_ipw_close(ttyj);
42934 ipwireless_disassociate_network_ttys(network,
42935 ttyj->channel_idx);
42936diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
42937index f9d2850..b006f04 100644
42938--- a/drivers/tty/moxa.c
42939+++ b/drivers/tty/moxa.c
42940@@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
42941 }
42942
42943 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
42944- ch->port.count++;
42945+ atomic_inc(&ch->port.count);
42946 tty->driver_data = ch;
42947 tty_port_tty_set(&ch->port, tty);
42948 mutex_lock(&ch->port.mutex);
42949diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
42950index bfd6771..e0d93c4 100644
42951--- a/drivers/tty/n_gsm.c
42952+++ b/drivers/tty/n_gsm.c
42953@@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
42954 spin_lock_init(&dlci->lock);
42955 mutex_init(&dlci->mutex);
42956 dlci->fifo = &dlci->_fifo;
42957- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
42958+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
42959 kfree(dlci);
42960 return NULL;
42961 }
42962@@ -2936,7 +2936,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
42963 struct gsm_dlci *dlci = tty->driver_data;
42964 struct tty_port *port = &dlci->port;
42965
42966- port->count++;
42967+ atomic_inc(&port->count);
42968 dlci_get(dlci);
42969 dlci_get(dlci->gsm->dlci[0]);
42970 mux_get(dlci->gsm);
42971diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
42972index 19083ef..6e34e97 100644
42973--- a/drivers/tty/n_tty.c
42974+++ b/drivers/tty/n_tty.c
42975@@ -2196,6 +2196,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
42976 {
42977 *ops = tty_ldisc_N_TTY;
42978 ops->owner = NULL;
42979- ops->refcount = ops->flags = 0;
42980+ atomic_set(&ops->refcount, 0);
42981+ ops->flags = 0;
42982 }
42983 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
42984diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
42985index ac35c90..c47deac 100644
42986--- a/drivers/tty/pty.c
42987+++ b/drivers/tty/pty.c
42988@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
42989 panic("Couldn't register Unix98 pts driver");
42990
42991 /* Now create the /dev/ptmx special device */
42992+ pax_open_kernel();
42993 tty_default_fops(&ptmx_fops);
42994- ptmx_fops.open = ptmx_open;
42995+ *(void **)&ptmx_fops.open = ptmx_open;
42996+ pax_close_kernel();
42997
42998 cdev_init(&ptmx_cdev, &ptmx_fops);
42999 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
43000diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
43001index e42009a..566a036 100644
43002--- a/drivers/tty/rocket.c
43003+++ b/drivers/tty/rocket.c
43004@@ -925,7 +925,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43005 tty->driver_data = info;
43006 tty_port_tty_set(port, tty);
43007
43008- if (port->count++ == 0) {
43009+ if (atomic_inc_return(&port->count) == 1) {
43010 atomic_inc(&rp_num_ports_open);
43011
43012 #ifdef ROCKET_DEBUG_OPEN
43013@@ -934,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43014 #endif
43015 }
43016 #ifdef ROCKET_DEBUG_OPEN
43017- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
43018+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
43019 #endif
43020
43021 /*
43022@@ -1529,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
43023 spin_unlock_irqrestore(&info->port.lock, flags);
43024 return;
43025 }
43026- if (info->port.count)
43027+ if (atomic_read(&info->port.count))
43028 atomic_dec(&rp_num_ports_open);
43029 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
43030 spin_unlock_irqrestore(&info->port.lock, flags);
43031diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
43032index 1002054..dd644a8 100644
43033--- a/drivers/tty/serial/kgdboc.c
43034+++ b/drivers/tty/serial/kgdboc.c
43035@@ -24,8 +24,9 @@
43036 #define MAX_CONFIG_LEN 40
43037
43038 static struct kgdb_io kgdboc_io_ops;
43039+static struct kgdb_io kgdboc_io_ops_console;
43040
43041-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
43042+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
43043 static int configured = -1;
43044
43045 static char config[MAX_CONFIG_LEN];
43046@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
43047 kgdboc_unregister_kbd();
43048 if (configured == 1)
43049 kgdb_unregister_io_module(&kgdboc_io_ops);
43050+ else if (configured == 2)
43051+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
43052 }
43053
43054 static int configure_kgdboc(void)
43055@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
43056 int err;
43057 char *cptr = config;
43058 struct console *cons;
43059+ int is_console = 0;
43060
43061 err = kgdboc_option_setup(config);
43062 if (err || !strlen(config) || isspace(config[0]))
43063 goto noconfig;
43064
43065 err = -ENODEV;
43066- kgdboc_io_ops.is_console = 0;
43067 kgdb_tty_driver = NULL;
43068
43069 kgdboc_use_kms = 0;
43070@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
43071 int idx;
43072 if (cons->device && cons->device(cons, &idx) == p &&
43073 idx == tty_line) {
43074- kgdboc_io_ops.is_console = 1;
43075+ is_console = 1;
43076 break;
43077 }
43078 cons = cons->next;
43079@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
43080 kgdb_tty_line = tty_line;
43081
43082 do_register:
43083- err = kgdb_register_io_module(&kgdboc_io_ops);
43084+ if (is_console) {
43085+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
43086+ configured = 2;
43087+ } else {
43088+ err = kgdb_register_io_module(&kgdboc_io_ops);
43089+ configured = 1;
43090+ }
43091 if (err)
43092 goto noconfig;
43093
43094@@ -205,8 +214,6 @@ do_register:
43095 if (err)
43096 goto nmi_con_failed;
43097
43098- configured = 1;
43099-
43100 return 0;
43101
43102 nmi_con_failed:
43103@@ -223,7 +230,7 @@ noconfig:
43104 static int __init init_kgdboc(void)
43105 {
43106 /* Already configured? */
43107- if (configured == 1)
43108+ if (configured >= 1)
43109 return 0;
43110
43111 return configure_kgdboc();
43112@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
43113 if (config[len - 1] == '\n')
43114 config[len - 1] = '\0';
43115
43116- if (configured == 1)
43117+ if (configured >= 1)
43118 cleanup_kgdboc();
43119
43120 /* Go and configure with the new params. */
43121@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
43122 .post_exception = kgdboc_post_exp_handler,
43123 };
43124
43125+static struct kgdb_io kgdboc_io_ops_console = {
43126+ .name = "kgdboc",
43127+ .read_char = kgdboc_get_char,
43128+ .write_char = kgdboc_put_char,
43129+ .pre_exception = kgdboc_pre_exp_handler,
43130+ .post_exception = kgdboc_post_exp_handler,
43131+ .is_console = 1
43132+};
43133+
43134 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
43135 /* This is only available if kgdboc is a built in for early debugging */
43136 static int __init kgdboc_early_init(char *opt)
43137diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
43138index e514b3a..c73d614 100644
43139--- a/drivers/tty/serial/samsung.c
43140+++ b/drivers/tty/serial/samsung.c
43141@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
43142 }
43143 }
43144
43145+static int s3c64xx_serial_startup(struct uart_port *port);
43146 static int s3c24xx_serial_startup(struct uart_port *port)
43147 {
43148 struct s3c24xx_uart_port *ourport = to_ourport(port);
43149 int ret;
43150
43151+ /* Startup sequence is different for s3c64xx and higher SoC's */
43152+ if (s3c24xx_serial_has_interrupt_mask(port))
43153+ return s3c64xx_serial_startup(port);
43154+
43155 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
43156 port->mapbase, port->membase);
43157
43158@@ -1122,10 +1127,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
43159 /* setup info for port */
43160 port->dev = &platdev->dev;
43161
43162- /* Startup sequence is different for s3c64xx and higher SoC's */
43163- if (s3c24xx_serial_has_interrupt_mask(port))
43164- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
43165-
43166 port->uartclk = 1;
43167
43168 if (cfg->uart_flags & UPF_CONS_FLOW) {
43169diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
43170index 2c7230a..2104f16 100644
43171--- a/drivers/tty/serial/serial_core.c
43172+++ b/drivers/tty/serial/serial_core.c
43173@@ -1455,7 +1455,7 @@ static void uart_hangup(struct tty_struct *tty)
43174 uart_flush_buffer(tty);
43175 uart_shutdown(tty, state);
43176 spin_lock_irqsave(&port->lock, flags);
43177- port->count = 0;
43178+ atomic_set(&port->count, 0);
43179 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
43180 spin_unlock_irqrestore(&port->lock, flags);
43181 tty_port_tty_set(port, NULL);
43182@@ -1551,7 +1551,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43183 goto end;
43184 }
43185
43186- port->count++;
43187+ atomic_inc(&port->count);
43188 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
43189 retval = -ENXIO;
43190 goto err_dec_count;
43191@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43192 /*
43193 * Make sure the device is in D0 state.
43194 */
43195- if (port->count == 1)
43196+ if (atomic_read(&port->count) == 1)
43197 uart_change_pm(state, 0);
43198
43199 /*
43200@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43201 end:
43202 return retval;
43203 err_dec_count:
43204- port->count--;
43205+ atomic_inc(&port->count);
43206 mutex_unlock(&port->mutex);
43207 goto end;
43208 }
43209diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
43210index 9e071f6..f30ae69 100644
43211--- a/drivers/tty/synclink.c
43212+++ b/drivers/tty/synclink.c
43213@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43214
43215 if (debug_level >= DEBUG_LEVEL_INFO)
43216 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
43217- __FILE__,__LINE__, info->device_name, info->port.count);
43218+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43219
43220 if (tty_port_close_start(&info->port, tty, filp) == 0)
43221 goto cleanup;
43222@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43223 cleanup:
43224 if (debug_level >= DEBUG_LEVEL_INFO)
43225 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
43226- tty->driver->name, info->port.count);
43227+ tty->driver->name, atomic_read(&info->port.count));
43228
43229 } /* end of mgsl_close() */
43230
43231@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
43232
43233 mgsl_flush_buffer(tty);
43234 shutdown(info);
43235-
43236- info->port.count = 0;
43237+
43238+ atomic_set(&info->port.count, 0);
43239 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43240 info->port.tty = NULL;
43241
43242@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43243
43244 if (debug_level >= DEBUG_LEVEL_INFO)
43245 printk("%s(%d):block_til_ready before block on %s count=%d\n",
43246- __FILE__,__LINE__, tty->driver->name, port->count );
43247+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43248
43249 spin_lock_irqsave(&info->irq_spinlock, flags);
43250 if (!tty_hung_up_p(filp)) {
43251 extra_count = true;
43252- port->count--;
43253+ atomic_dec(&port->count);
43254 }
43255 spin_unlock_irqrestore(&info->irq_spinlock, flags);
43256 port->blocked_open++;
43257@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43258
43259 if (debug_level >= DEBUG_LEVEL_INFO)
43260 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
43261- __FILE__,__LINE__, tty->driver->name, port->count );
43262+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43263
43264 tty_unlock(tty);
43265 schedule();
43266@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43267
43268 /* FIXME: Racy on hangup during close wait */
43269 if (extra_count)
43270- port->count++;
43271+ atomic_inc(&port->count);
43272 port->blocked_open--;
43273
43274 if (debug_level >= DEBUG_LEVEL_INFO)
43275 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
43276- __FILE__,__LINE__, tty->driver->name, port->count );
43277+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43278
43279 if (!retval)
43280 port->flags |= ASYNC_NORMAL_ACTIVE;
43281@@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43282
43283 if (debug_level >= DEBUG_LEVEL_INFO)
43284 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
43285- __FILE__,__LINE__,tty->driver->name, info->port.count);
43286+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43287
43288 /* If port is closing, signal caller to try again */
43289 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43290@@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43291 spin_unlock_irqrestore(&info->netlock, flags);
43292 goto cleanup;
43293 }
43294- info->port.count++;
43295+ atomic_inc(&info->port.count);
43296 spin_unlock_irqrestore(&info->netlock, flags);
43297
43298- if (info->port.count == 1) {
43299+ if (atomic_read(&info->port.count) == 1) {
43300 /* 1st open on this device, init hardware */
43301 retval = startup(info);
43302 if (retval < 0)
43303@@ -3451,8 +3451,8 @@ cleanup:
43304 if (retval) {
43305 if (tty->count == 1)
43306 info->port.tty = NULL; /* tty layer will release tty struct */
43307- if(info->port.count)
43308- info->port.count--;
43309+ if (atomic_read(&info->port.count))
43310+ atomic_dec(&info->port.count);
43311 }
43312
43313 return retval;
43314@@ -7662,7 +7662,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43315 unsigned short new_crctype;
43316
43317 /* return error if TTY interface open */
43318- if (info->port.count)
43319+ if (atomic_read(&info->port.count))
43320 return -EBUSY;
43321
43322 switch (encoding)
43323@@ -7757,7 +7757,7 @@ static int hdlcdev_open(struct net_device *dev)
43324
43325 /* arbitrate between network and tty opens */
43326 spin_lock_irqsave(&info->netlock, flags);
43327- if (info->port.count != 0 || info->netcount != 0) {
43328+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43329 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43330 spin_unlock_irqrestore(&info->netlock, flags);
43331 return -EBUSY;
43332@@ -7843,7 +7843,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43333 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43334
43335 /* return error if TTY interface open */
43336- if (info->port.count)
43337+ if (atomic_read(&info->port.count))
43338 return -EBUSY;
43339
43340 if (cmd != SIOCWANDEV)
43341diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
43342index aba1e59..877ac33 100644
43343--- a/drivers/tty/synclink_gt.c
43344+++ b/drivers/tty/synclink_gt.c
43345@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
43346 tty->driver_data = info;
43347 info->port.tty = tty;
43348
43349- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
43350+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
43351
43352 /* If port is closing, signal caller to try again */
43353 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43354@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
43355 mutex_unlock(&info->port.mutex);
43356 goto cleanup;
43357 }
43358- info->port.count++;
43359+ atomic_inc(&info->port.count);
43360 spin_unlock_irqrestore(&info->netlock, flags);
43361
43362- if (info->port.count == 1) {
43363+ if (atomic_read(&info->port.count) == 1) {
43364 /* 1st open on this device, init hardware */
43365 retval = startup(info);
43366 if (retval < 0) {
43367@@ -716,8 +716,8 @@ cleanup:
43368 if (retval) {
43369 if (tty->count == 1)
43370 info->port.tty = NULL; /* tty layer will release tty struct */
43371- if(info->port.count)
43372- info->port.count--;
43373+ if(atomic_read(&info->port.count))
43374+ atomic_dec(&info->port.count);
43375 }
43376
43377 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
43378@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43379
43380 if (sanity_check(info, tty->name, "close"))
43381 return;
43382- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
43383+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
43384
43385 if (tty_port_close_start(&info->port, tty, filp) == 0)
43386 goto cleanup;
43387@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43388 tty_port_close_end(&info->port, tty);
43389 info->port.tty = NULL;
43390 cleanup:
43391- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
43392+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
43393 }
43394
43395 static void hangup(struct tty_struct *tty)
43396@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
43397 shutdown(info);
43398
43399 spin_lock_irqsave(&info->port.lock, flags);
43400- info->port.count = 0;
43401+ atomic_set(&info->port.count, 0);
43402 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43403 info->port.tty = NULL;
43404 spin_unlock_irqrestore(&info->port.lock, flags);
43405@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43406 unsigned short new_crctype;
43407
43408 /* return error if TTY interface open */
43409- if (info->port.count)
43410+ if (atomic_read(&info->port.count))
43411 return -EBUSY;
43412
43413 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
43414@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
43415
43416 /* arbitrate between network and tty opens */
43417 spin_lock_irqsave(&info->netlock, flags);
43418- if (info->port.count != 0 || info->netcount != 0) {
43419+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43420 DBGINFO(("%s hdlc_open busy\n", dev->name));
43421 spin_unlock_irqrestore(&info->netlock, flags);
43422 return -EBUSY;
43423@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43424 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
43425
43426 /* return error if TTY interface open */
43427- if (info->port.count)
43428+ if (atomic_read(&info->port.count))
43429 return -EBUSY;
43430
43431 if (cmd != SIOCWANDEV)
43432@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
43433 if (port == NULL)
43434 continue;
43435 spin_lock(&port->lock);
43436- if ((port->port.count || port->netcount) &&
43437+ if ((atomic_read(&port->port.count) || port->netcount) &&
43438 port->pending_bh && !port->bh_running &&
43439 !port->bh_requested) {
43440 DBGISR(("%s bh queued\n", port->device_name));
43441@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43442 spin_lock_irqsave(&info->lock, flags);
43443 if (!tty_hung_up_p(filp)) {
43444 extra_count = true;
43445- port->count--;
43446+ atomic_dec(&port->count);
43447 }
43448 spin_unlock_irqrestore(&info->lock, flags);
43449 port->blocked_open++;
43450@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43451 remove_wait_queue(&port->open_wait, &wait);
43452
43453 if (extra_count)
43454- port->count++;
43455+ atomic_inc(&port->count);
43456 port->blocked_open--;
43457
43458 if (!retval)
43459diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
43460index fd43fb6..34704ad 100644
43461--- a/drivers/tty/synclinkmp.c
43462+++ b/drivers/tty/synclinkmp.c
43463@@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
43464
43465 if (debug_level >= DEBUG_LEVEL_INFO)
43466 printk("%s(%d):%s open(), old ref count = %d\n",
43467- __FILE__,__LINE__,tty->driver->name, info->port.count);
43468+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43469
43470 /* If port is closing, signal caller to try again */
43471 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43472@@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
43473 spin_unlock_irqrestore(&info->netlock, flags);
43474 goto cleanup;
43475 }
43476- info->port.count++;
43477+ atomic_inc(&info->port.count);
43478 spin_unlock_irqrestore(&info->netlock, flags);
43479
43480- if (info->port.count == 1) {
43481+ if (atomic_read(&info->port.count) == 1) {
43482 /* 1st open on this device, init hardware */
43483 retval = startup(info);
43484 if (retval < 0)
43485@@ -797,8 +797,8 @@ cleanup:
43486 if (retval) {
43487 if (tty->count == 1)
43488 info->port.tty = NULL; /* tty layer will release tty struct */
43489- if(info->port.count)
43490- info->port.count--;
43491+ if(atomic_read(&info->port.count))
43492+ atomic_dec(&info->port.count);
43493 }
43494
43495 return retval;
43496@@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43497
43498 if (debug_level >= DEBUG_LEVEL_INFO)
43499 printk("%s(%d):%s close() entry, count=%d\n",
43500- __FILE__,__LINE__, info->device_name, info->port.count);
43501+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43502
43503 if (tty_port_close_start(&info->port, tty, filp) == 0)
43504 goto cleanup;
43505@@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43506 cleanup:
43507 if (debug_level >= DEBUG_LEVEL_INFO)
43508 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
43509- tty->driver->name, info->port.count);
43510+ tty->driver->name, atomic_read(&info->port.count));
43511 }
43512
43513 /* Called by tty_hangup() when a hangup is signaled.
43514@@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
43515 shutdown(info);
43516
43517 spin_lock_irqsave(&info->port.lock, flags);
43518- info->port.count = 0;
43519+ atomic_set(&info->port.count, 0);
43520 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43521 info->port.tty = NULL;
43522 spin_unlock_irqrestore(&info->port.lock, flags);
43523@@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43524 unsigned short new_crctype;
43525
43526 /* return error if TTY interface open */
43527- if (info->port.count)
43528+ if (atomic_read(&info->port.count))
43529 return -EBUSY;
43530
43531 switch (encoding)
43532@@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
43533
43534 /* arbitrate between network and tty opens */
43535 spin_lock_irqsave(&info->netlock, flags);
43536- if (info->port.count != 0 || info->netcount != 0) {
43537+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43538 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43539 spin_unlock_irqrestore(&info->netlock, flags);
43540 return -EBUSY;
43541@@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43542 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43543
43544 /* return error if TTY interface open */
43545- if (info->port.count)
43546+ if (atomic_read(&info->port.count))
43547 return -EBUSY;
43548
43549 if (cmd != SIOCWANDEV)
43550@@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
43551 * do not request bottom half processing if the
43552 * device is not open in a normal mode.
43553 */
43554- if ( port && (port->port.count || port->netcount) &&
43555+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
43556 port->pending_bh && !port->bh_running &&
43557 !port->bh_requested ) {
43558 if ( debug_level >= DEBUG_LEVEL_ISR )
43559@@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43560
43561 if (debug_level >= DEBUG_LEVEL_INFO)
43562 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
43563- __FILE__,__LINE__, tty->driver->name, port->count );
43564+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43565
43566 spin_lock_irqsave(&info->lock, flags);
43567 if (!tty_hung_up_p(filp)) {
43568 extra_count = true;
43569- port->count--;
43570+ atomic_dec(&port->count);
43571 }
43572 spin_unlock_irqrestore(&info->lock, flags);
43573 port->blocked_open++;
43574@@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43575
43576 if (debug_level >= DEBUG_LEVEL_INFO)
43577 printk("%s(%d):%s block_til_ready() count=%d\n",
43578- __FILE__,__LINE__, tty->driver->name, port->count );
43579+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43580
43581 tty_unlock(tty);
43582 schedule();
43583@@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43584 remove_wait_queue(&port->open_wait, &wait);
43585
43586 if (extra_count)
43587- port->count++;
43588+ atomic_inc(&port->count);
43589 port->blocked_open--;
43590
43591 if (debug_level >= DEBUG_LEVEL_INFO)
43592 printk("%s(%d):%s block_til_ready() after, count=%d\n",
43593- __FILE__,__LINE__, tty->driver->name, port->count );
43594+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43595
43596 if (!retval)
43597 port->flags |= ASYNC_NORMAL_ACTIVE;
43598diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
43599index b3c4a25..723916f 100644
43600--- a/drivers/tty/sysrq.c
43601+++ b/drivers/tty/sysrq.c
43602@@ -867,7 +867,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
43603 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
43604 size_t count, loff_t *ppos)
43605 {
43606- if (count) {
43607+ if (count && capable(CAP_SYS_ADMIN)) {
43608 char c;
43609
43610 if (get_user(c, buf))
43611diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
43612index da9fde8..c07975f 100644
43613--- a/drivers/tty/tty_io.c
43614+++ b/drivers/tty/tty_io.c
43615@@ -3391,7 +3391,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
43616
43617 void tty_default_fops(struct file_operations *fops)
43618 {
43619- *fops = tty_fops;
43620+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
43621 }
43622
43623 /*
43624diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
43625index c578229..45aa9ee 100644
43626--- a/drivers/tty/tty_ldisc.c
43627+++ b/drivers/tty/tty_ldisc.c
43628@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
43629 if (atomic_dec_and_test(&ld->users)) {
43630 struct tty_ldisc_ops *ldo = ld->ops;
43631
43632- ldo->refcount--;
43633+ atomic_dec(&ldo->refcount);
43634 module_put(ldo->owner);
43635 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43636
43637@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
43638 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43639 tty_ldiscs[disc] = new_ldisc;
43640 new_ldisc->num = disc;
43641- new_ldisc->refcount = 0;
43642+ atomic_set(&new_ldisc->refcount, 0);
43643 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43644
43645 return ret;
43646@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
43647 return -EINVAL;
43648
43649 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43650- if (tty_ldiscs[disc]->refcount)
43651+ if (atomic_read(&tty_ldiscs[disc]->refcount))
43652 ret = -EBUSY;
43653 else
43654 tty_ldiscs[disc] = NULL;
43655@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
43656 if (ldops) {
43657 ret = ERR_PTR(-EAGAIN);
43658 if (try_module_get(ldops->owner)) {
43659- ldops->refcount++;
43660+ atomic_inc(&ldops->refcount);
43661 ret = ldops;
43662 }
43663 }
43664@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
43665 unsigned long flags;
43666
43667 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43668- ldops->refcount--;
43669+ atomic_dec(&ldops->refcount);
43670 module_put(ldops->owner);
43671 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43672 }
43673diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
43674index b7ff59d..7c6105e 100644
43675--- a/drivers/tty/tty_port.c
43676+++ b/drivers/tty/tty_port.c
43677@@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
43678 unsigned long flags;
43679
43680 spin_lock_irqsave(&port->lock, flags);
43681- port->count = 0;
43682+ atomic_set(&port->count, 0);
43683 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43684 if (port->tty) {
43685 set_bit(TTY_IO_ERROR, &port->tty->flags);
43686@@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43687 /* The port lock protects the port counts */
43688 spin_lock_irqsave(&port->lock, flags);
43689 if (!tty_hung_up_p(filp))
43690- port->count--;
43691+ atomic_dec(&port->count);
43692 port->blocked_open++;
43693 spin_unlock_irqrestore(&port->lock, flags);
43694
43695@@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43696 we must not mess that up further */
43697 spin_lock_irqsave(&port->lock, flags);
43698 if (!tty_hung_up_p(filp))
43699- port->count++;
43700+ atomic_inc(&port->count);
43701 port->blocked_open--;
43702 if (retval == 0)
43703 port->flags |= ASYNC_NORMAL_ACTIVE;
43704@@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
43705 return 0;
43706 }
43707
43708- if (tty->count == 1 && port->count != 1) {
43709+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
43710 printk(KERN_WARNING
43711 "tty_port_close_start: tty->count = 1 port count = %d.\n",
43712- port->count);
43713- port->count = 1;
43714+ atomic_read(&port->count));
43715+ atomic_set(&port->count, 1);
43716 }
43717- if (--port->count < 0) {
43718+ if (atomic_dec_return(&port->count) < 0) {
43719 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
43720- port->count);
43721- port->count = 0;
43722+ atomic_read(&port->count));
43723+ atomic_set(&port->count, 0);
43724 }
43725
43726- if (port->count) {
43727+ if (atomic_read(&port->count)) {
43728 spin_unlock_irqrestore(&port->lock, flags);
43729 if (port->ops->drop)
43730 port->ops->drop(port);
43731@@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
43732 {
43733 spin_lock_irq(&port->lock);
43734 if (!tty_hung_up_p(filp))
43735- ++port->count;
43736+ atomic_inc(&port->count);
43737 spin_unlock_irq(&port->lock);
43738 tty_port_tty_set(port, tty);
43739
43740diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
43741index 681765b..d3ccdf2 100644
43742--- a/drivers/tty/vt/keyboard.c
43743+++ b/drivers/tty/vt/keyboard.c
43744@@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
43745 kbd->kbdmode == VC_OFF) &&
43746 value != KVAL(K_SAK))
43747 return; /* SAK is allowed even in raw mode */
43748+
43749+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
43750+ {
43751+ void *func = fn_handler[value];
43752+ if (func == fn_show_state || func == fn_show_ptregs ||
43753+ func == fn_show_mem)
43754+ return;
43755+ }
43756+#endif
43757+
43758 fn_handler[value](vc);
43759 }
43760
43761@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43762 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
43763 return -EFAULT;
43764
43765- if (!capable(CAP_SYS_TTY_CONFIG))
43766- perm = 0;
43767-
43768 switch (cmd) {
43769 case KDGKBENT:
43770 /* Ensure another thread doesn't free it under us */
43771@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43772 spin_unlock_irqrestore(&kbd_event_lock, flags);
43773 return put_user(val, &user_kbe->kb_value);
43774 case KDSKBENT:
43775+ if (!capable(CAP_SYS_TTY_CONFIG))
43776+ perm = 0;
43777+
43778 if (!perm)
43779 return -EPERM;
43780 if (!i && v == K_NOSUCHMAP) {
43781@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43782 int i, j, k;
43783 int ret;
43784
43785- if (!capable(CAP_SYS_TTY_CONFIG))
43786- perm = 0;
43787-
43788 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
43789 if (!kbs) {
43790 ret = -ENOMEM;
43791@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43792 kfree(kbs);
43793 return ((p && *p) ? -EOVERFLOW : 0);
43794 case KDSKBSENT:
43795+ if (!capable(CAP_SYS_TTY_CONFIG))
43796+ perm = 0;
43797+
43798 if (!perm) {
43799 ret = -EPERM;
43800 goto reterr;
43801diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
43802index 5110f36..8dc0a74 100644
43803--- a/drivers/uio/uio.c
43804+++ b/drivers/uio/uio.c
43805@@ -25,6 +25,7 @@
43806 #include <linux/kobject.h>
43807 #include <linux/cdev.h>
43808 #include <linux/uio_driver.h>
43809+#include <asm/local.h>
43810
43811 #define UIO_MAX_DEVICES (1U << MINORBITS)
43812
43813@@ -32,10 +33,10 @@ struct uio_device {
43814 struct module *owner;
43815 struct device *dev;
43816 int minor;
43817- atomic_t event;
43818+ atomic_unchecked_t event;
43819 struct fasync_struct *async_queue;
43820 wait_queue_head_t wait;
43821- int vma_count;
43822+ local_t vma_count;
43823 struct uio_info *info;
43824 struct kobject *map_dir;
43825 struct kobject *portio_dir;
43826@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
43827 struct device_attribute *attr, char *buf)
43828 {
43829 struct uio_device *idev = dev_get_drvdata(dev);
43830- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
43831+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
43832 }
43833
43834 static struct device_attribute uio_class_attributes[] = {
43835@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
43836 {
43837 struct uio_device *idev = info->uio_dev;
43838
43839- atomic_inc(&idev->event);
43840+ atomic_inc_unchecked(&idev->event);
43841 wake_up_interruptible(&idev->wait);
43842 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
43843 }
43844@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
43845 }
43846
43847 listener->dev = idev;
43848- listener->event_count = atomic_read(&idev->event);
43849+ listener->event_count = atomic_read_unchecked(&idev->event);
43850 filep->private_data = listener;
43851
43852 if (idev->info->open) {
43853@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
43854 return -EIO;
43855
43856 poll_wait(filep, &idev->wait, wait);
43857- if (listener->event_count != atomic_read(&idev->event))
43858+ if (listener->event_count != atomic_read_unchecked(&idev->event))
43859 return POLLIN | POLLRDNORM;
43860 return 0;
43861 }
43862@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
43863 do {
43864 set_current_state(TASK_INTERRUPTIBLE);
43865
43866- event_count = atomic_read(&idev->event);
43867+ event_count = atomic_read_unchecked(&idev->event);
43868 if (event_count != listener->event_count) {
43869 if (copy_to_user(buf, &event_count, count))
43870 retval = -EFAULT;
43871@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
43872 static void uio_vma_open(struct vm_area_struct *vma)
43873 {
43874 struct uio_device *idev = vma->vm_private_data;
43875- idev->vma_count++;
43876+ local_inc(&idev->vma_count);
43877 }
43878
43879 static void uio_vma_close(struct vm_area_struct *vma)
43880 {
43881 struct uio_device *idev = vma->vm_private_data;
43882- idev->vma_count--;
43883+ local_dec(&idev->vma_count);
43884 }
43885
43886 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
43887@@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
43888 idev->owner = owner;
43889 idev->info = info;
43890 init_waitqueue_head(&idev->wait);
43891- atomic_set(&idev->event, 0);
43892+ atomic_set_unchecked(&idev->event, 0);
43893
43894 ret = uio_get_minor(idev);
43895 if (ret)
43896diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
43897index b7eb86a..36d28af 100644
43898--- a/drivers/usb/atm/cxacru.c
43899+++ b/drivers/usb/atm/cxacru.c
43900@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
43901 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
43902 if (ret < 2)
43903 return -EINVAL;
43904- if (index < 0 || index > 0x7f)
43905+ if (index > 0x7f)
43906 return -EINVAL;
43907 pos += tmp;
43908
43909diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
43910index 35f10bf..6a38a0b 100644
43911--- a/drivers/usb/atm/usbatm.c
43912+++ b/drivers/usb/atm/usbatm.c
43913@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43914 if (printk_ratelimit())
43915 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
43916 __func__, vpi, vci);
43917- atomic_inc(&vcc->stats->rx_err);
43918+ atomic_inc_unchecked(&vcc->stats->rx_err);
43919 return;
43920 }
43921
43922@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43923 if (length > ATM_MAX_AAL5_PDU) {
43924 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
43925 __func__, length, vcc);
43926- atomic_inc(&vcc->stats->rx_err);
43927+ atomic_inc_unchecked(&vcc->stats->rx_err);
43928 goto out;
43929 }
43930
43931@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43932 if (sarb->len < pdu_length) {
43933 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
43934 __func__, pdu_length, sarb->len, vcc);
43935- atomic_inc(&vcc->stats->rx_err);
43936+ atomic_inc_unchecked(&vcc->stats->rx_err);
43937 goto out;
43938 }
43939
43940 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
43941 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
43942 __func__, vcc);
43943- atomic_inc(&vcc->stats->rx_err);
43944+ atomic_inc_unchecked(&vcc->stats->rx_err);
43945 goto out;
43946 }
43947
43948@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43949 if (printk_ratelimit())
43950 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
43951 __func__, length);
43952- atomic_inc(&vcc->stats->rx_drop);
43953+ atomic_inc_unchecked(&vcc->stats->rx_drop);
43954 goto out;
43955 }
43956
43957@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43958
43959 vcc->push(vcc, skb);
43960
43961- atomic_inc(&vcc->stats->rx);
43962+ atomic_inc_unchecked(&vcc->stats->rx);
43963 out:
43964 skb_trim(sarb, 0);
43965 }
43966@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
43967 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
43968
43969 usbatm_pop(vcc, skb);
43970- atomic_inc(&vcc->stats->tx);
43971+ atomic_inc_unchecked(&vcc->stats->tx);
43972
43973 skb = skb_dequeue(&instance->sndqueue);
43974 }
43975@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
43976 if (!left--)
43977 return sprintf(page,
43978 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
43979- atomic_read(&atm_dev->stats.aal5.tx),
43980- atomic_read(&atm_dev->stats.aal5.tx_err),
43981- atomic_read(&atm_dev->stats.aal5.rx),
43982- atomic_read(&atm_dev->stats.aal5.rx_err),
43983- atomic_read(&atm_dev->stats.aal5.rx_drop));
43984+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
43985+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
43986+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
43987+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
43988+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
43989
43990 if (!left--) {
43991 if (instance->disconnected)
43992diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
43993index cbacea9..246cccd 100644
43994--- a/drivers/usb/core/devices.c
43995+++ b/drivers/usb/core/devices.c
43996@@ -126,7 +126,7 @@ static const char format_endpt[] =
43997 * time it gets called.
43998 */
43999 static struct device_connect_event {
44000- atomic_t count;
44001+ atomic_unchecked_t count;
44002 wait_queue_head_t wait;
44003 } device_event = {
44004 .count = ATOMIC_INIT(1),
44005@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
44006
44007 void usbfs_conn_disc_event(void)
44008 {
44009- atomic_add(2, &device_event.count);
44010+ atomic_add_unchecked(2, &device_event.count);
44011 wake_up(&device_event.wait);
44012 }
44013
44014@@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
44015
44016 poll_wait(file, &device_event.wait, wait);
44017
44018- event_count = atomic_read(&device_event.count);
44019+ event_count = atomic_read_unchecked(&device_event.count);
44020 if (file->f_version != event_count) {
44021 file->f_version = event_count;
44022 return POLLIN | POLLRDNORM;
44023diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
44024index 8e64adf..9a33a3c 100644
44025--- a/drivers/usb/core/hcd.c
44026+++ b/drivers/usb/core/hcd.c
44027@@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44028 */
44029 usb_get_urb(urb);
44030 atomic_inc(&urb->use_count);
44031- atomic_inc(&urb->dev->urbnum);
44032+ atomic_inc_unchecked(&urb->dev->urbnum);
44033 usbmon_urb_submit(&hcd->self, urb);
44034
44035 /* NOTE requirements on root-hub callers (usbfs and the hub
44036@@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44037 urb->hcpriv = NULL;
44038 INIT_LIST_HEAD(&urb->urb_list);
44039 atomic_dec(&urb->use_count);
44040- atomic_dec(&urb->dev->urbnum);
44041+ atomic_dec_unchecked(&urb->dev->urbnum);
44042 if (atomic_read(&urb->reject))
44043 wake_up(&usb_kill_urb_queue);
44044 usb_put_urb(urb);
44045diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
44046index 131f736..99004c3 100644
44047--- a/drivers/usb/core/message.c
44048+++ b/drivers/usb/core/message.c
44049@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
44050 * method can wait for it to complete. Since you don't have a handle on the
44051 * URB used, you can't cancel the request.
44052 */
44053-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44054+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44055 __u8 requesttype, __u16 value, __u16 index, void *data,
44056 __u16 size, int timeout)
44057 {
44058diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
44059index 818e4a0..0fc9589 100644
44060--- a/drivers/usb/core/sysfs.c
44061+++ b/drivers/usb/core/sysfs.c
44062@@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
44063 struct usb_device *udev;
44064
44065 udev = to_usb_device(dev);
44066- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
44067+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
44068 }
44069 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
44070
44071diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
44072index f81b925..78d22ec 100644
44073--- a/drivers/usb/core/usb.c
44074+++ b/drivers/usb/core/usb.c
44075@@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
44076 set_dev_node(&dev->dev, dev_to_node(bus->controller));
44077 dev->state = USB_STATE_ATTACHED;
44078 dev->lpm_disable_count = 1;
44079- atomic_set(&dev->urbnum, 0);
44080+ atomic_set_unchecked(&dev->urbnum, 0);
44081
44082 INIT_LIST_HEAD(&dev->ep0.urb_list);
44083 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
44084diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
44085index 5e29dde..eca992f 100644
44086--- a/drivers/usb/early/ehci-dbgp.c
44087+++ b/drivers/usb/early/ehci-dbgp.c
44088@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
44089
44090 #ifdef CONFIG_KGDB
44091 static struct kgdb_io kgdbdbgp_io_ops;
44092-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
44093+static struct kgdb_io kgdbdbgp_io_ops_console;
44094+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
44095 #else
44096 #define dbgp_kgdb_mode (0)
44097 #endif
44098@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
44099 .write_char = kgdbdbgp_write_char,
44100 };
44101
44102+static struct kgdb_io kgdbdbgp_io_ops_console = {
44103+ .name = "kgdbdbgp",
44104+ .read_char = kgdbdbgp_read_char,
44105+ .write_char = kgdbdbgp_write_char,
44106+ .is_console = 1
44107+};
44108+
44109 static int kgdbdbgp_wait_time;
44110
44111 static int __init kgdbdbgp_parse_config(char *str)
44112@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
44113 ptr++;
44114 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
44115 }
44116- kgdb_register_io_module(&kgdbdbgp_io_ops);
44117- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
44118+ if (early_dbgp_console.index != -1)
44119+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
44120+ else
44121+ kgdb_register_io_module(&kgdbdbgp_io_ops);
44122
44123 return 0;
44124 }
44125diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
44126index 598dcc1..032dd4f 100644
44127--- a/drivers/usb/gadget/u_serial.c
44128+++ b/drivers/usb/gadget/u_serial.c
44129@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44130 spin_lock_irq(&port->port_lock);
44131
44132 /* already open? Great. */
44133- if (port->port.count) {
44134+ if (atomic_read(&port->port.count)) {
44135 status = 0;
44136- port->port.count++;
44137+ atomic_inc(&port->port.count);
44138
44139 /* currently opening/closing? wait ... */
44140 } else if (port->openclose) {
44141@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44142 tty->driver_data = port;
44143 port->port.tty = tty;
44144
44145- port->port.count = 1;
44146+ atomic_set(&port->port.count, 1);
44147 port->openclose = false;
44148
44149 /* if connected, start the I/O stream */
44150@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44151
44152 spin_lock_irq(&port->port_lock);
44153
44154- if (port->port.count != 1) {
44155- if (port->port.count == 0)
44156+ if (atomic_read(&port->port.count) != 1) {
44157+ if (atomic_read(&port->port.count) == 0)
44158 WARN_ON(1);
44159 else
44160- --port->port.count;
44161+ atomic_dec(&port->port.count);
44162 goto exit;
44163 }
44164
44165@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44166 * and sleep if necessary
44167 */
44168 port->openclose = true;
44169- port->port.count = 0;
44170+ atomic_set(&port->port.count, 0);
44171
44172 gser = port->port_usb;
44173 if (gser && gser->disconnect)
44174@@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
44175 int cond;
44176
44177 spin_lock_irq(&port->port_lock);
44178- cond = (port->port.count == 0) && !port->openclose;
44179+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
44180 spin_unlock_irq(&port->port_lock);
44181 return cond;
44182 }
44183@@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
44184 /* if it's already open, start I/O ... and notify the serial
44185 * protocol about open/close status (connect/disconnect).
44186 */
44187- if (port->port.count) {
44188+ if (atomic_read(&port->port.count)) {
44189 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
44190 gs_start_io(port);
44191 if (gser->connect)
44192@@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
44193
44194 port->port_usb = NULL;
44195 gser->ioport = NULL;
44196- if (port->port.count > 0 || port->openclose) {
44197+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
44198 wake_up_interruptible(&port->drain_wait);
44199 if (port->port.tty)
44200 tty_hangup(port->port.tty);
44201@@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
44202
44203 /* finally, free any unused/unusable I/O buffers */
44204 spin_lock_irqsave(&port->port_lock, flags);
44205- if (port->port.count == 0 && !port->openclose)
44206+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
44207 gs_buf_free(&port->port_write_buf);
44208 gs_free_requests(gser->out, &port->read_pool, NULL);
44209 gs_free_requests(gser->out, &port->read_queue, NULL);
44210diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
44211index 5f3bcd3..bfca43f 100644
44212--- a/drivers/usb/serial/console.c
44213+++ b/drivers/usb/serial/console.c
44214@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
44215
44216 info->port = port;
44217
44218- ++port->port.count;
44219+ atomic_inc(&port->port.count);
44220 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
44221 if (serial->type->set_termios) {
44222 /*
44223@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
44224 }
44225 /* Now that any required fake tty operations are completed restore
44226 * the tty port count */
44227- --port->port.count;
44228+ atomic_dec(&port->port.count);
44229 /* The console is special in terms of closing the device so
44230 * indicate this port is now acting as a system console. */
44231 port->port.console = 1;
44232@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
44233 free_tty:
44234 kfree(tty);
44235 reset_open_count:
44236- port->port.count = 0;
44237+ atomic_set(&port->port.count, 0);
44238 usb_autopm_put_interface(serial->interface);
44239 error_get_interface:
44240 usb_serial_put(serial);
44241diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
44242index 6c3586a..a94e621 100644
44243--- a/drivers/usb/storage/realtek_cr.c
44244+++ b/drivers/usb/storage/realtek_cr.c
44245@@ -429,7 +429,7 @@ static int rts51x_read_status(struct us_data *us,
44246
44247 buf = kmalloc(len, GFP_NOIO);
44248 if (buf == NULL)
44249- return USB_STOR_TRANSPORT_ERROR;
44250+ return -ENOMEM;
44251
44252 US_DEBUGP("%s, lun = %d\n", __func__, lun);
44253
44254diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
44255index 75f70f0..d467e1a 100644
44256--- a/drivers/usb/storage/usb.h
44257+++ b/drivers/usb/storage/usb.h
44258@@ -63,7 +63,7 @@ struct us_unusual_dev {
44259 __u8 useProtocol;
44260 __u8 useTransport;
44261 int (*initFunction)(struct us_data *);
44262-};
44263+} __do_const;
44264
44265
44266 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
44267diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
44268index d6bea3e..60b250e 100644
44269--- a/drivers/usb/wusbcore/wa-hc.h
44270+++ b/drivers/usb/wusbcore/wa-hc.h
44271@@ -192,7 +192,7 @@ struct wahc {
44272 struct list_head xfer_delayed_list;
44273 spinlock_t xfer_list_lock;
44274 struct work_struct xfer_work;
44275- atomic_t xfer_id_count;
44276+ atomic_unchecked_t xfer_id_count;
44277 };
44278
44279
44280@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
44281 INIT_LIST_HEAD(&wa->xfer_delayed_list);
44282 spin_lock_init(&wa->xfer_list_lock);
44283 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
44284- atomic_set(&wa->xfer_id_count, 1);
44285+ atomic_set_unchecked(&wa->xfer_id_count, 1);
44286 }
44287
44288 /**
44289diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
44290index 57c01ab..8a05959 100644
44291--- a/drivers/usb/wusbcore/wa-xfer.c
44292+++ b/drivers/usb/wusbcore/wa-xfer.c
44293@@ -296,7 +296,7 @@ out:
44294 */
44295 static void wa_xfer_id_init(struct wa_xfer *xfer)
44296 {
44297- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
44298+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
44299 }
44300
44301 /*
44302diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
44303index 8c55011..eed4ae1a 100644
44304--- a/drivers/video/aty/aty128fb.c
44305+++ b/drivers/video/aty/aty128fb.c
44306@@ -149,7 +149,7 @@ enum {
44307 };
44308
44309 /* Must match above enum */
44310-static char * const r128_family[] = {
44311+static const char * const r128_family[] = {
44312 "AGP",
44313 "PCI",
44314 "PRO AGP",
44315diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
44316index 4f27fdc..d3537e6 100644
44317--- a/drivers/video/aty/atyfb_base.c
44318+++ b/drivers/video/aty/atyfb_base.c
44319@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
44320 par->accel_flags = var->accel_flags; /* hack */
44321
44322 if (var->accel_flags) {
44323- info->fbops->fb_sync = atyfb_sync;
44324+ pax_open_kernel();
44325+ *(void **)&info->fbops->fb_sync = atyfb_sync;
44326+ pax_close_kernel();
44327 info->flags &= ~FBINFO_HWACCEL_DISABLED;
44328 } else {
44329- info->fbops->fb_sync = NULL;
44330+ pax_open_kernel();
44331+ *(void **)&info->fbops->fb_sync = NULL;
44332+ pax_close_kernel();
44333 info->flags |= FBINFO_HWACCEL_DISABLED;
44334 }
44335
44336diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
44337index 95ec042..e6affdd 100644
44338--- a/drivers/video/aty/mach64_cursor.c
44339+++ b/drivers/video/aty/mach64_cursor.c
44340@@ -7,6 +7,7 @@
44341 #include <linux/string.h>
44342
44343 #include <asm/io.h>
44344+#include <asm/pgtable.h>
44345
44346 #ifdef __sparc__
44347 #include <asm/fbio.h>
44348@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
44349 info->sprite.buf_align = 16; /* and 64 lines tall. */
44350 info->sprite.flags = FB_PIXMAP_IO;
44351
44352- info->fbops->fb_cursor = atyfb_cursor;
44353+ pax_open_kernel();
44354+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
44355+ pax_close_kernel();
44356
44357 return 0;
44358 }
44359diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
44360index 6c5ed6b..b727c88 100644
44361--- a/drivers/video/backlight/kb3886_bl.c
44362+++ b/drivers/video/backlight/kb3886_bl.c
44363@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
44364 static unsigned long kb3886bl_flags;
44365 #define KB3886BL_SUSPENDED 0x01
44366
44367-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
44368+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
44369 {
44370 .ident = "Sahara Touch-iT",
44371 .matches = {
44372diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
44373index 88cad6b..dd746c7 100644
44374--- a/drivers/video/fb_defio.c
44375+++ b/drivers/video/fb_defio.c
44376@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
44377
44378 BUG_ON(!fbdefio);
44379 mutex_init(&fbdefio->lock);
44380- info->fbops->fb_mmap = fb_deferred_io_mmap;
44381+ pax_open_kernel();
44382+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
44383+ pax_close_kernel();
44384 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
44385 INIT_LIST_HEAD(&fbdefio->pagelist);
44386 if (fbdefio->delay == 0) /* set a default of 1 s */
44387@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
44388 page->mapping = NULL;
44389 }
44390
44391- info->fbops->fb_mmap = NULL;
44392+ *(void **)&info->fbops->fb_mmap = NULL;
44393 mutex_destroy(&fbdefio->lock);
44394 }
44395 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
44396diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
44397index 5c3960d..15cf8fc 100644
44398--- a/drivers/video/fbcmap.c
44399+++ b/drivers/video/fbcmap.c
44400@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
44401 rc = -ENODEV;
44402 goto out;
44403 }
44404- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
44405- !info->fbops->fb_setcmap)) {
44406+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
44407 rc = -EINVAL;
44408 goto out1;
44409 }
44410diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
44411index dc61c12..e29796e 100644
44412--- a/drivers/video/fbmem.c
44413+++ b/drivers/video/fbmem.c
44414@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
44415 image->dx += image->width + 8;
44416 }
44417 } else if (rotate == FB_ROTATE_UD) {
44418- for (x = 0; x < num && image->dx >= 0; x++) {
44419+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
44420 info->fbops->fb_imageblit(info, image);
44421 image->dx -= image->width + 8;
44422 }
44423@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
44424 image->dy += image->height + 8;
44425 }
44426 } else if (rotate == FB_ROTATE_CCW) {
44427- for (x = 0; x < num && image->dy >= 0; x++) {
44428+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
44429 info->fbops->fb_imageblit(info, image);
44430 image->dy -= image->height + 8;
44431 }
44432@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
44433 return -EFAULT;
44434 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
44435 return -EINVAL;
44436- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
44437+ if (con2fb.framebuffer >= FB_MAX)
44438 return -EINVAL;
44439 if (!registered_fb[con2fb.framebuffer])
44440 request_module("fb%d", con2fb.framebuffer);
44441diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
44442index 7672d2e..b56437f 100644
44443--- a/drivers/video/i810/i810_accel.c
44444+++ b/drivers/video/i810/i810_accel.c
44445@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
44446 }
44447 }
44448 printk("ringbuffer lockup!!!\n");
44449+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
44450 i810_report_error(mmio);
44451 par->dev_flags |= LOCKUP;
44452 info->pixmap.scan_align = 1;
44453diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
44454index 3c14e43..eafa544 100644
44455--- a/drivers/video/logo/logo_linux_clut224.ppm
44456+++ b/drivers/video/logo/logo_linux_clut224.ppm
44457@@ -1,1604 +1,1123 @@
44458 P3
44459-# Standard 224-color Linux logo
44460 80 80
44461 255
44462- 0 0 0 0 0 0 0 0 0 0 0 0
44463- 0 0 0 0 0 0 0 0 0 0 0 0
44464- 0 0 0 0 0 0 0 0 0 0 0 0
44465- 0 0 0 0 0 0 0 0 0 0 0 0
44466- 0 0 0 0 0 0 0 0 0 0 0 0
44467- 0 0 0 0 0 0 0 0 0 0 0 0
44468- 0 0 0 0 0 0 0 0 0 0 0 0
44469- 0 0 0 0 0 0 0 0 0 0 0 0
44470- 0 0 0 0 0 0 0 0 0 0 0 0
44471- 6 6 6 6 6 6 10 10 10 10 10 10
44472- 10 10 10 6 6 6 6 6 6 6 6 6
44473- 0 0 0 0 0 0 0 0 0 0 0 0
44474- 0 0 0 0 0 0 0 0 0 0 0 0
44475- 0 0 0 0 0 0 0 0 0 0 0 0
44476- 0 0 0 0 0 0 0 0 0 0 0 0
44477- 0 0 0 0 0 0 0 0 0 0 0 0
44478- 0 0 0 0 0 0 0 0 0 0 0 0
44479- 0 0 0 0 0 0 0 0 0 0 0 0
44480- 0 0 0 0 0 0 0 0 0 0 0 0
44481- 0 0 0 0 0 0 0 0 0 0 0 0
44482- 0 0 0 0 0 0 0 0 0 0 0 0
44483- 0 0 0 0 0 0 0 0 0 0 0 0
44484- 0 0 0 0 0 0 0 0 0 0 0 0
44485- 0 0 0 0 0 0 0 0 0 0 0 0
44486- 0 0 0 0 0 0 0 0 0 0 0 0
44487- 0 0 0 0 0 0 0 0 0 0 0 0
44488- 0 0 0 0 0 0 0 0 0 0 0 0
44489- 0 0 0 0 0 0 0 0 0 0 0 0
44490- 0 0 0 6 6 6 10 10 10 14 14 14
44491- 22 22 22 26 26 26 30 30 30 34 34 34
44492- 30 30 30 30 30 30 26 26 26 18 18 18
44493- 14 14 14 10 10 10 6 6 6 0 0 0
44494- 0 0 0 0 0 0 0 0 0 0 0 0
44495- 0 0 0 0 0 0 0 0 0 0 0 0
44496- 0 0 0 0 0 0 0 0 0 0 0 0
44497- 0 0 0 0 0 0 0 0 0 0 0 0
44498- 0 0 0 0 0 0 0 0 0 0 0 0
44499- 0 0 0 0 0 0 0 0 0 0 0 0
44500- 0 0 0 0 0 0 0 0 0 0 0 0
44501- 0 0 0 0 0 0 0 0 0 0 0 0
44502- 0 0 0 0 0 0 0 0 0 0 0 0
44503- 0 0 0 0 0 1 0 0 1 0 0 0
44504- 0 0 0 0 0 0 0 0 0 0 0 0
44505- 0 0 0 0 0 0 0 0 0 0 0 0
44506- 0 0 0 0 0 0 0 0 0 0 0 0
44507- 0 0 0 0 0 0 0 0 0 0 0 0
44508- 0 0 0 0 0 0 0 0 0 0 0 0
44509- 0 0 0 0 0 0 0 0 0 0 0 0
44510- 6 6 6 14 14 14 26 26 26 42 42 42
44511- 54 54 54 66 66 66 78 78 78 78 78 78
44512- 78 78 78 74 74 74 66 66 66 54 54 54
44513- 42 42 42 26 26 26 18 18 18 10 10 10
44514- 6 6 6 0 0 0 0 0 0 0 0 0
44515- 0 0 0 0 0 0 0 0 0 0 0 0
44516- 0 0 0 0 0 0 0 0 0 0 0 0
44517- 0 0 0 0 0 0 0 0 0 0 0 0
44518- 0 0 0 0 0 0 0 0 0 0 0 0
44519- 0 0 0 0 0 0 0 0 0 0 0 0
44520- 0 0 0 0 0 0 0 0 0 0 0 0
44521- 0 0 0 0 0 0 0 0 0 0 0 0
44522- 0 0 0 0 0 0 0 0 0 0 0 0
44523- 0 0 1 0 0 0 0 0 0 0 0 0
44524- 0 0 0 0 0 0 0 0 0 0 0 0
44525- 0 0 0 0 0 0 0 0 0 0 0 0
44526- 0 0 0 0 0 0 0 0 0 0 0 0
44527- 0 0 0 0 0 0 0 0 0 0 0 0
44528- 0 0 0 0 0 0 0 0 0 0 0 0
44529- 0 0 0 0 0 0 0 0 0 10 10 10
44530- 22 22 22 42 42 42 66 66 66 86 86 86
44531- 66 66 66 38 38 38 38 38 38 22 22 22
44532- 26 26 26 34 34 34 54 54 54 66 66 66
44533- 86 86 86 70 70 70 46 46 46 26 26 26
44534- 14 14 14 6 6 6 0 0 0 0 0 0
44535- 0 0 0 0 0 0 0 0 0 0 0 0
44536- 0 0 0 0 0 0 0 0 0 0 0 0
44537- 0 0 0 0 0 0 0 0 0 0 0 0
44538- 0 0 0 0 0 0 0 0 0 0 0 0
44539- 0 0 0 0 0 0 0 0 0 0 0 0
44540- 0 0 0 0 0 0 0 0 0 0 0 0
44541- 0 0 0 0 0 0 0 0 0 0 0 0
44542- 0 0 0 0 0 0 0 0 0 0 0 0
44543- 0 0 1 0 0 1 0 0 1 0 0 0
44544- 0 0 0 0 0 0 0 0 0 0 0 0
44545- 0 0 0 0 0 0 0 0 0 0 0 0
44546- 0 0 0 0 0 0 0 0 0 0 0 0
44547- 0 0 0 0 0 0 0 0 0 0 0 0
44548- 0 0 0 0 0 0 0 0 0 0 0 0
44549- 0 0 0 0 0 0 10 10 10 26 26 26
44550- 50 50 50 82 82 82 58 58 58 6 6 6
44551- 2 2 6 2 2 6 2 2 6 2 2 6
44552- 2 2 6 2 2 6 2 2 6 2 2 6
44553- 6 6 6 54 54 54 86 86 86 66 66 66
44554- 38 38 38 18 18 18 6 6 6 0 0 0
44555- 0 0 0 0 0 0 0 0 0 0 0 0
44556- 0 0 0 0 0 0 0 0 0 0 0 0
44557- 0 0 0 0 0 0 0 0 0 0 0 0
44558- 0 0 0 0 0 0 0 0 0 0 0 0
44559- 0 0 0 0 0 0 0 0 0 0 0 0
44560- 0 0 0 0 0 0 0 0 0 0 0 0
44561- 0 0 0 0 0 0 0 0 0 0 0 0
44562- 0 0 0 0 0 0 0 0 0 0 0 0
44563- 0 0 0 0 0 0 0 0 0 0 0 0
44564- 0 0 0 0 0 0 0 0 0 0 0 0
44565- 0 0 0 0 0 0 0 0 0 0 0 0
44566- 0 0 0 0 0 0 0 0 0 0 0 0
44567- 0 0 0 0 0 0 0 0 0 0 0 0
44568- 0 0 0 0 0 0 0 0 0 0 0 0
44569- 0 0 0 6 6 6 22 22 22 50 50 50
44570- 78 78 78 34 34 34 2 2 6 2 2 6
44571- 2 2 6 2 2 6 2 2 6 2 2 6
44572- 2 2 6 2 2 6 2 2 6 2 2 6
44573- 2 2 6 2 2 6 6 6 6 70 70 70
44574- 78 78 78 46 46 46 22 22 22 6 6 6
44575- 0 0 0 0 0 0 0 0 0 0 0 0
44576- 0 0 0 0 0 0 0 0 0 0 0 0
44577- 0 0 0 0 0 0 0 0 0 0 0 0
44578- 0 0 0 0 0 0 0 0 0 0 0 0
44579- 0 0 0 0 0 0 0 0 0 0 0 0
44580- 0 0 0 0 0 0 0 0 0 0 0 0
44581- 0 0 0 0 0 0 0 0 0 0 0 0
44582- 0 0 0 0 0 0 0 0 0 0 0 0
44583- 0 0 1 0 0 1 0 0 1 0 0 0
44584- 0 0 0 0 0 0 0 0 0 0 0 0
44585- 0 0 0 0 0 0 0 0 0 0 0 0
44586- 0 0 0 0 0 0 0 0 0 0 0 0
44587- 0 0 0 0 0 0 0 0 0 0 0 0
44588- 0 0 0 0 0 0 0 0 0 0 0 0
44589- 6 6 6 18 18 18 42 42 42 82 82 82
44590- 26 26 26 2 2 6 2 2 6 2 2 6
44591- 2 2 6 2 2 6 2 2 6 2 2 6
44592- 2 2 6 2 2 6 2 2 6 14 14 14
44593- 46 46 46 34 34 34 6 6 6 2 2 6
44594- 42 42 42 78 78 78 42 42 42 18 18 18
44595- 6 6 6 0 0 0 0 0 0 0 0 0
44596- 0 0 0 0 0 0 0 0 0 0 0 0
44597- 0 0 0 0 0 0 0 0 0 0 0 0
44598- 0 0 0 0 0 0 0 0 0 0 0 0
44599- 0 0 0 0 0 0 0 0 0 0 0 0
44600- 0 0 0 0 0 0 0 0 0 0 0 0
44601- 0 0 0 0 0 0 0 0 0 0 0 0
44602- 0 0 0 0 0 0 0 0 0 0 0 0
44603- 0 0 1 0 0 0 0 0 1 0 0 0
44604- 0 0 0 0 0 0 0 0 0 0 0 0
44605- 0 0 0 0 0 0 0 0 0 0 0 0
44606- 0 0 0 0 0 0 0 0 0 0 0 0
44607- 0 0 0 0 0 0 0 0 0 0 0 0
44608- 0 0 0 0 0 0 0 0 0 0 0 0
44609- 10 10 10 30 30 30 66 66 66 58 58 58
44610- 2 2 6 2 2 6 2 2 6 2 2 6
44611- 2 2 6 2 2 6 2 2 6 2 2 6
44612- 2 2 6 2 2 6 2 2 6 26 26 26
44613- 86 86 86 101 101 101 46 46 46 10 10 10
44614- 2 2 6 58 58 58 70 70 70 34 34 34
44615- 10 10 10 0 0 0 0 0 0 0 0 0
44616- 0 0 0 0 0 0 0 0 0 0 0 0
44617- 0 0 0 0 0 0 0 0 0 0 0 0
44618- 0 0 0 0 0 0 0 0 0 0 0 0
44619- 0 0 0 0 0 0 0 0 0 0 0 0
44620- 0 0 0 0 0 0 0 0 0 0 0 0
44621- 0 0 0 0 0 0 0 0 0 0 0 0
44622- 0 0 0 0 0 0 0 0 0 0 0 0
44623- 0 0 1 0 0 1 0 0 1 0 0 0
44624- 0 0 0 0 0 0 0 0 0 0 0 0
44625- 0 0 0 0 0 0 0 0 0 0 0 0
44626- 0 0 0 0 0 0 0 0 0 0 0 0
44627- 0 0 0 0 0 0 0 0 0 0 0 0
44628- 0 0 0 0 0 0 0 0 0 0 0 0
44629- 14 14 14 42 42 42 86 86 86 10 10 10
44630- 2 2 6 2 2 6 2 2 6 2 2 6
44631- 2 2 6 2 2 6 2 2 6 2 2 6
44632- 2 2 6 2 2 6 2 2 6 30 30 30
44633- 94 94 94 94 94 94 58 58 58 26 26 26
44634- 2 2 6 6 6 6 78 78 78 54 54 54
44635- 22 22 22 6 6 6 0 0 0 0 0 0
44636- 0 0 0 0 0 0 0 0 0 0 0 0
44637- 0 0 0 0 0 0 0 0 0 0 0 0
44638- 0 0 0 0 0 0 0 0 0 0 0 0
44639- 0 0 0 0 0 0 0 0 0 0 0 0
44640- 0 0 0 0 0 0 0 0 0 0 0 0
44641- 0 0 0 0 0 0 0 0 0 0 0 0
44642- 0 0 0 0 0 0 0 0 0 0 0 0
44643- 0 0 0 0 0 0 0 0 0 0 0 0
44644- 0 0 0 0 0 0 0 0 0 0 0 0
44645- 0 0 0 0 0 0 0 0 0 0 0 0
44646- 0 0 0 0 0 0 0 0 0 0 0 0
44647- 0 0 0 0 0 0 0 0 0 0 0 0
44648- 0 0 0 0 0 0 0 0 0 6 6 6
44649- 22 22 22 62 62 62 62 62 62 2 2 6
44650- 2 2 6 2 2 6 2 2 6 2 2 6
44651- 2 2 6 2 2 6 2 2 6 2 2 6
44652- 2 2 6 2 2 6 2 2 6 26 26 26
44653- 54 54 54 38 38 38 18 18 18 10 10 10
44654- 2 2 6 2 2 6 34 34 34 82 82 82
44655- 38 38 38 14 14 14 0 0 0 0 0 0
44656- 0 0 0 0 0 0 0 0 0 0 0 0
44657- 0 0 0 0 0 0 0 0 0 0 0 0
44658- 0 0 0 0 0 0 0 0 0 0 0 0
44659- 0 0 0 0 0 0 0 0 0 0 0 0
44660- 0 0 0 0 0 0 0 0 0 0 0 0
44661- 0 0 0 0 0 0 0 0 0 0 0 0
44662- 0 0 0 0 0 0 0 0 0 0 0 0
44663- 0 0 0 0 0 1 0 0 1 0 0 0
44664- 0 0 0 0 0 0 0 0 0 0 0 0
44665- 0 0 0 0 0 0 0 0 0 0 0 0
44666- 0 0 0 0 0 0 0 0 0 0 0 0
44667- 0 0 0 0 0 0 0 0 0 0 0 0
44668- 0 0 0 0 0 0 0 0 0 6 6 6
44669- 30 30 30 78 78 78 30 30 30 2 2 6
44670- 2 2 6 2 2 6 2 2 6 2 2 6
44671- 2 2 6 2 2 6 2 2 6 2 2 6
44672- 2 2 6 2 2 6 2 2 6 10 10 10
44673- 10 10 10 2 2 6 2 2 6 2 2 6
44674- 2 2 6 2 2 6 2 2 6 78 78 78
44675- 50 50 50 18 18 18 6 6 6 0 0 0
44676- 0 0 0 0 0 0 0 0 0 0 0 0
44677- 0 0 0 0 0 0 0 0 0 0 0 0
44678- 0 0 0 0 0 0 0 0 0 0 0 0
44679- 0 0 0 0 0 0 0 0 0 0 0 0
44680- 0 0 0 0 0 0 0 0 0 0 0 0
44681- 0 0 0 0 0 0 0 0 0 0 0 0
44682- 0 0 0 0 0 0 0 0 0 0 0 0
44683- 0 0 1 0 0 0 0 0 0 0 0 0
44684- 0 0 0 0 0 0 0 0 0 0 0 0
44685- 0 0 0 0 0 0 0 0 0 0 0 0
44686- 0 0 0 0 0 0 0 0 0 0 0 0
44687- 0 0 0 0 0 0 0 0 0 0 0 0
44688- 0 0 0 0 0 0 0 0 0 10 10 10
44689- 38 38 38 86 86 86 14 14 14 2 2 6
44690- 2 2 6 2 2 6 2 2 6 2 2 6
44691- 2 2 6 2 2 6 2 2 6 2 2 6
44692- 2 2 6 2 2 6 2 2 6 2 2 6
44693- 2 2 6 2 2 6 2 2 6 2 2 6
44694- 2 2 6 2 2 6 2 2 6 54 54 54
44695- 66 66 66 26 26 26 6 6 6 0 0 0
44696- 0 0 0 0 0 0 0 0 0 0 0 0
44697- 0 0 0 0 0 0 0 0 0 0 0 0
44698- 0 0 0 0 0 0 0 0 0 0 0 0
44699- 0 0 0 0 0 0 0 0 0 0 0 0
44700- 0 0 0 0 0 0 0 0 0 0 0 0
44701- 0 0 0 0 0 0 0 0 0 0 0 0
44702- 0 0 0 0 0 0 0 0 0 0 0 0
44703- 0 0 0 0 0 1 0 0 1 0 0 0
44704- 0 0 0 0 0 0 0 0 0 0 0 0
44705- 0 0 0 0 0 0 0 0 0 0 0 0
44706- 0 0 0 0 0 0 0 0 0 0 0 0
44707- 0 0 0 0 0 0 0 0 0 0 0 0
44708- 0 0 0 0 0 0 0 0 0 14 14 14
44709- 42 42 42 82 82 82 2 2 6 2 2 6
44710- 2 2 6 6 6 6 10 10 10 2 2 6
44711- 2 2 6 2 2 6 2 2 6 2 2 6
44712- 2 2 6 2 2 6 2 2 6 6 6 6
44713- 14 14 14 10 10 10 2 2 6 2 2 6
44714- 2 2 6 2 2 6 2 2 6 18 18 18
44715- 82 82 82 34 34 34 10 10 10 0 0 0
44716- 0 0 0 0 0 0 0 0 0 0 0 0
44717- 0 0 0 0 0 0 0 0 0 0 0 0
44718- 0 0 0 0 0 0 0 0 0 0 0 0
44719- 0 0 0 0 0 0 0 0 0 0 0 0
44720- 0 0 0 0 0 0 0 0 0 0 0 0
44721- 0 0 0 0 0 0 0 0 0 0 0 0
44722- 0 0 0 0 0 0 0 0 0 0 0 0
44723- 0 0 1 0 0 0 0 0 0 0 0 0
44724- 0 0 0 0 0 0 0 0 0 0 0 0
44725- 0 0 0 0 0 0 0 0 0 0 0 0
44726- 0 0 0 0 0 0 0 0 0 0 0 0
44727- 0 0 0 0 0 0 0 0 0 0 0 0
44728- 0 0 0 0 0 0 0 0 0 14 14 14
44729- 46 46 46 86 86 86 2 2 6 2 2 6
44730- 6 6 6 6 6 6 22 22 22 34 34 34
44731- 6 6 6 2 2 6 2 2 6 2 2 6
44732- 2 2 6 2 2 6 18 18 18 34 34 34
44733- 10 10 10 50 50 50 22 22 22 2 2 6
44734- 2 2 6 2 2 6 2 2 6 10 10 10
44735- 86 86 86 42 42 42 14 14 14 0 0 0
44736- 0 0 0 0 0 0 0 0 0 0 0 0
44737- 0 0 0 0 0 0 0 0 0 0 0 0
44738- 0 0 0 0 0 0 0 0 0 0 0 0
44739- 0 0 0 0 0 0 0 0 0 0 0 0
44740- 0 0 0 0 0 0 0 0 0 0 0 0
44741- 0 0 0 0 0 0 0 0 0 0 0 0
44742- 0 0 0 0 0 0 0 0 0 0 0 0
44743- 0 0 1 0 0 1 0 0 1 0 0 0
44744- 0 0 0 0 0 0 0 0 0 0 0 0
44745- 0 0 0 0 0 0 0 0 0 0 0 0
44746- 0 0 0 0 0 0 0 0 0 0 0 0
44747- 0 0 0 0 0 0 0 0 0 0 0 0
44748- 0 0 0 0 0 0 0 0 0 14 14 14
44749- 46 46 46 86 86 86 2 2 6 2 2 6
44750- 38 38 38 116 116 116 94 94 94 22 22 22
44751- 22 22 22 2 2 6 2 2 6 2 2 6
44752- 14 14 14 86 86 86 138 138 138 162 162 162
44753-154 154 154 38 38 38 26 26 26 6 6 6
44754- 2 2 6 2 2 6 2 2 6 2 2 6
44755- 86 86 86 46 46 46 14 14 14 0 0 0
44756- 0 0 0 0 0 0 0 0 0 0 0 0
44757- 0 0 0 0 0 0 0 0 0 0 0 0
44758- 0 0 0 0 0 0 0 0 0 0 0 0
44759- 0 0 0 0 0 0 0 0 0 0 0 0
44760- 0 0 0 0 0 0 0 0 0 0 0 0
44761- 0 0 0 0 0 0 0 0 0 0 0 0
44762- 0 0 0 0 0 0 0 0 0 0 0 0
44763- 0 0 0 0 0 0 0 0 0 0 0 0
44764- 0 0 0 0 0 0 0 0 0 0 0 0
44765- 0 0 0 0 0 0 0 0 0 0 0 0
44766- 0 0 0 0 0 0 0 0 0 0 0 0
44767- 0 0 0 0 0 0 0 0 0 0 0 0
44768- 0 0 0 0 0 0 0 0 0 14 14 14
44769- 46 46 46 86 86 86 2 2 6 14 14 14
44770-134 134 134 198 198 198 195 195 195 116 116 116
44771- 10 10 10 2 2 6 2 2 6 6 6 6
44772-101 98 89 187 187 187 210 210 210 218 218 218
44773-214 214 214 134 134 134 14 14 14 6 6 6
44774- 2 2 6 2 2 6 2 2 6 2 2 6
44775- 86 86 86 50 50 50 18 18 18 6 6 6
44776- 0 0 0 0 0 0 0 0 0 0 0 0
44777- 0 0 0 0 0 0 0 0 0 0 0 0
44778- 0 0 0 0 0 0 0 0 0 0 0 0
44779- 0 0 0 0 0 0 0 0 0 0 0 0
44780- 0 0 0 0 0 0 0 0 0 0 0 0
44781- 0 0 0 0 0 0 0 0 0 0 0 0
44782- 0 0 0 0 0 0 0 0 1 0 0 0
44783- 0 0 1 0 0 1 0 0 1 0 0 0
44784- 0 0 0 0 0 0 0 0 0 0 0 0
44785- 0 0 0 0 0 0 0 0 0 0 0 0
44786- 0 0 0 0 0 0 0 0 0 0 0 0
44787- 0 0 0 0 0 0 0 0 0 0 0 0
44788- 0 0 0 0 0 0 0 0 0 14 14 14
44789- 46 46 46 86 86 86 2 2 6 54 54 54
44790-218 218 218 195 195 195 226 226 226 246 246 246
44791- 58 58 58 2 2 6 2 2 6 30 30 30
44792-210 210 210 253 253 253 174 174 174 123 123 123
44793-221 221 221 234 234 234 74 74 74 2 2 6
44794- 2 2 6 2 2 6 2 2 6 2 2 6
44795- 70 70 70 58 58 58 22 22 22 6 6 6
44796- 0 0 0 0 0 0 0 0 0 0 0 0
44797- 0 0 0 0 0 0 0 0 0 0 0 0
44798- 0 0 0 0 0 0 0 0 0 0 0 0
44799- 0 0 0 0 0 0 0 0 0 0 0 0
44800- 0 0 0 0 0 0 0 0 0 0 0 0
44801- 0 0 0 0 0 0 0 0 0 0 0 0
44802- 0 0 0 0 0 0 0 0 0 0 0 0
44803- 0 0 0 0 0 0 0 0 0 0 0 0
44804- 0 0 0 0 0 0 0 0 0 0 0 0
44805- 0 0 0 0 0 0 0 0 0 0 0 0
44806- 0 0 0 0 0 0 0 0 0 0 0 0
44807- 0 0 0 0 0 0 0 0 0 0 0 0
44808- 0 0 0 0 0 0 0 0 0 14 14 14
44809- 46 46 46 82 82 82 2 2 6 106 106 106
44810-170 170 170 26 26 26 86 86 86 226 226 226
44811-123 123 123 10 10 10 14 14 14 46 46 46
44812-231 231 231 190 190 190 6 6 6 70 70 70
44813- 90 90 90 238 238 238 158 158 158 2 2 6
44814- 2 2 6 2 2 6 2 2 6 2 2 6
44815- 70 70 70 58 58 58 22 22 22 6 6 6
44816- 0 0 0 0 0 0 0 0 0 0 0 0
44817- 0 0 0 0 0 0 0 0 0 0 0 0
44818- 0 0 0 0 0 0 0 0 0 0 0 0
44819- 0 0 0 0 0 0 0 0 0 0 0 0
44820- 0 0 0 0 0 0 0 0 0 0 0 0
44821- 0 0 0 0 0 0 0 0 0 0 0 0
44822- 0 0 0 0 0 0 0 0 1 0 0 0
44823- 0 0 1 0 0 1 0 0 1 0 0 0
44824- 0 0 0 0 0 0 0 0 0 0 0 0
44825- 0 0 0 0 0 0 0 0 0 0 0 0
44826- 0 0 0 0 0 0 0 0 0 0 0 0
44827- 0 0 0 0 0 0 0 0 0 0 0 0
44828- 0 0 0 0 0 0 0 0 0 14 14 14
44829- 42 42 42 86 86 86 6 6 6 116 116 116
44830-106 106 106 6 6 6 70 70 70 149 149 149
44831-128 128 128 18 18 18 38 38 38 54 54 54
44832-221 221 221 106 106 106 2 2 6 14 14 14
44833- 46 46 46 190 190 190 198 198 198 2 2 6
44834- 2 2 6 2 2 6 2 2 6 2 2 6
44835- 74 74 74 62 62 62 22 22 22 6 6 6
44836- 0 0 0 0 0 0 0 0 0 0 0 0
44837- 0 0 0 0 0 0 0 0 0 0 0 0
44838- 0 0 0 0 0 0 0 0 0 0 0 0
44839- 0 0 0 0 0 0 0 0 0 0 0 0
44840- 0 0 0 0 0 0 0 0 0 0 0 0
44841- 0 0 0 0 0 0 0 0 0 0 0 0
44842- 0 0 0 0 0 0 0 0 1 0 0 0
44843- 0 0 1 0 0 0 0 0 1 0 0 0
44844- 0 0 0 0 0 0 0 0 0 0 0 0
44845- 0 0 0 0 0 0 0 0 0 0 0 0
44846- 0 0 0 0 0 0 0 0 0 0 0 0
44847- 0 0 0 0 0 0 0 0 0 0 0 0
44848- 0 0 0 0 0 0 0 0 0 14 14 14
44849- 42 42 42 94 94 94 14 14 14 101 101 101
44850-128 128 128 2 2 6 18 18 18 116 116 116
44851-118 98 46 121 92 8 121 92 8 98 78 10
44852-162 162 162 106 106 106 2 2 6 2 2 6
44853- 2 2 6 195 195 195 195 195 195 6 6 6
44854- 2 2 6 2 2 6 2 2 6 2 2 6
44855- 74 74 74 62 62 62 22 22 22 6 6 6
44856- 0 0 0 0 0 0 0 0 0 0 0 0
44857- 0 0 0 0 0 0 0 0 0 0 0 0
44858- 0 0 0 0 0 0 0 0 0 0 0 0
44859- 0 0 0 0 0 0 0 0 0 0 0 0
44860- 0 0 0 0 0 0 0 0 0 0 0 0
44861- 0 0 0 0 0 0 0 0 0 0 0 0
44862- 0 0 0 0 0 0 0 0 1 0 0 1
44863- 0 0 1 0 0 0 0 0 1 0 0 0
44864- 0 0 0 0 0 0 0 0 0 0 0 0
44865- 0 0 0 0 0 0 0 0 0 0 0 0
44866- 0 0 0 0 0 0 0 0 0 0 0 0
44867- 0 0 0 0 0 0 0 0 0 0 0 0
44868- 0 0 0 0 0 0 0 0 0 10 10 10
44869- 38 38 38 90 90 90 14 14 14 58 58 58
44870-210 210 210 26 26 26 54 38 6 154 114 10
44871-226 170 11 236 186 11 225 175 15 184 144 12
44872-215 174 15 175 146 61 37 26 9 2 2 6
44873- 70 70 70 246 246 246 138 138 138 2 2 6
44874- 2 2 6 2 2 6 2 2 6 2 2 6
44875- 70 70 70 66 66 66 26 26 26 6 6 6
44876- 0 0 0 0 0 0 0 0 0 0 0 0
44877- 0 0 0 0 0 0 0 0 0 0 0 0
44878- 0 0 0 0 0 0 0 0 0 0 0 0
44879- 0 0 0 0 0 0 0 0 0 0 0 0
44880- 0 0 0 0 0 0 0 0 0 0 0 0
44881- 0 0 0 0 0 0 0 0 0 0 0 0
44882- 0 0 0 0 0 0 0 0 0 0 0 0
44883- 0 0 0 0 0 0 0 0 0 0 0 0
44884- 0 0 0 0 0 0 0 0 0 0 0 0
44885- 0 0 0 0 0 0 0 0 0 0 0 0
44886- 0 0 0 0 0 0 0 0 0 0 0 0
44887- 0 0 0 0 0 0 0 0 0 0 0 0
44888- 0 0 0 0 0 0 0 0 0 10 10 10
44889- 38 38 38 86 86 86 14 14 14 10 10 10
44890-195 195 195 188 164 115 192 133 9 225 175 15
44891-239 182 13 234 190 10 232 195 16 232 200 30
44892-245 207 45 241 208 19 232 195 16 184 144 12
44893-218 194 134 211 206 186 42 42 42 2 2 6
44894- 2 2 6 2 2 6 2 2 6 2 2 6
44895- 50 50 50 74 74 74 30 30 30 6 6 6
44896- 0 0 0 0 0 0 0 0 0 0 0 0
44897- 0 0 0 0 0 0 0 0 0 0 0 0
44898- 0 0 0 0 0 0 0 0 0 0 0 0
44899- 0 0 0 0 0 0 0 0 0 0 0 0
44900- 0 0 0 0 0 0 0 0 0 0 0 0
44901- 0 0 0 0 0 0 0 0 0 0 0 0
44902- 0 0 0 0 0 0 0 0 0 0 0 0
44903- 0 0 0 0 0 0 0 0 0 0 0 0
44904- 0 0 0 0 0 0 0 0 0 0 0 0
44905- 0 0 0 0 0 0 0 0 0 0 0 0
44906- 0 0 0 0 0 0 0 0 0 0 0 0
44907- 0 0 0 0 0 0 0 0 0 0 0 0
44908- 0 0 0 0 0 0 0 0 0 10 10 10
44909- 34 34 34 86 86 86 14 14 14 2 2 6
44910-121 87 25 192 133 9 219 162 10 239 182 13
44911-236 186 11 232 195 16 241 208 19 244 214 54
44912-246 218 60 246 218 38 246 215 20 241 208 19
44913-241 208 19 226 184 13 121 87 25 2 2 6
44914- 2 2 6 2 2 6 2 2 6 2 2 6
44915- 50 50 50 82 82 82 34 34 34 10 10 10
44916- 0 0 0 0 0 0 0 0 0 0 0 0
44917- 0 0 0 0 0 0 0 0 0 0 0 0
44918- 0 0 0 0 0 0 0 0 0 0 0 0
44919- 0 0 0 0 0 0 0 0 0 0 0 0
44920- 0 0 0 0 0 0 0 0 0 0 0 0
44921- 0 0 0 0 0 0 0 0 0 0 0 0
44922- 0 0 0 0 0 0 0 0 0 0 0 0
44923- 0 0 0 0 0 0 0 0 0 0 0 0
44924- 0 0 0 0 0 0 0 0 0 0 0 0
44925- 0 0 0 0 0 0 0 0 0 0 0 0
44926- 0 0 0 0 0 0 0 0 0 0 0 0
44927- 0 0 0 0 0 0 0 0 0 0 0 0
44928- 0 0 0 0 0 0 0 0 0 10 10 10
44929- 34 34 34 82 82 82 30 30 30 61 42 6
44930-180 123 7 206 145 10 230 174 11 239 182 13
44931-234 190 10 238 202 15 241 208 19 246 218 74
44932-246 218 38 246 215 20 246 215 20 246 215 20
44933-226 184 13 215 174 15 184 144 12 6 6 6
44934- 2 2 6 2 2 6 2 2 6 2 2 6
44935- 26 26 26 94 94 94 42 42 42 14 14 14
44936- 0 0 0 0 0 0 0 0 0 0 0 0
44937- 0 0 0 0 0 0 0 0 0 0 0 0
44938- 0 0 0 0 0 0 0 0 0 0 0 0
44939- 0 0 0 0 0 0 0 0 0 0 0 0
44940- 0 0 0 0 0 0 0 0 0 0 0 0
44941- 0 0 0 0 0 0 0 0 0 0 0 0
44942- 0 0 0 0 0 0 0 0 0 0 0 0
44943- 0 0 0 0 0 0 0 0 0 0 0 0
44944- 0 0 0 0 0 0 0 0 0 0 0 0
44945- 0 0 0 0 0 0 0 0 0 0 0 0
44946- 0 0 0 0 0 0 0 0 0 0 0 0
44947- 0 0 0 0 0 0 0 0 0 0 0 0
44948- 0 0 0 0 0 0 0 0 0 10 10 10
44949- 30 30 30 78 78 78 50 50 50 104 69 6
44950-192 133 9 216 158 10 236 178 12 236 186 11
44951-232 195 16 241 208 19 244 214 54 245 215 43
44952-246 215 20 246 215 20 241 208 19 198 155 10
44953-200 144 11 216 158 10 156 118 10 2 2 6
44954- 2 2 6 2 2 6 2 2 6 2 2 6
44955- 6 6 6 90 90 90 54 54 54 18 18 18
44956- 6 6 6 0 0 0 0 0 0 0 0 0
44957- 0 0 0 0 0 0 0 0 0 0 0 0
44958- 0 0 0 0 0 0 0 0 0 0 0 0
44959- 0 0 0 0 0 0 0 0 0 0 0 0
44960- 0 0 0 0 0 0 0 0 0 0 0 0
44961- 0 0 0 0 0 0 0 0 0 0 0 0
44962- 0 0 0 0 0 0 0 0 0 0 0 0
44963- 0 0 0 0 0 0 0 0 0 0 0 0
44964- 0 0 0 0 0 0 0 0 0 0 0 0
44965- 0 0 0 0 0 0 0 0 0 0 0 0
44966- 0 0 0 0 0 0 0 0 0 0 0 0
44967- 0 0 0 0 0 0 0 0 0 0 0 0
44968- 0 0 0 0 0 0 0 0 0 10 10 10
44969- 30 30 30 78 78 78 46 46 46 22 22 22
44970-137 92 6 210 162 10 239 182 13 238 190 10
44971-238 202 15 241 208 19 246 215 20 246 215 20
44972-241 208 19 203 166 17 185 133 11 210 150 10
44973-216 158 10 210 150 10 102 78 10 2 2 6
44974- 6 6 6 54 54 54 14 14 14 2 2 6
44975- 2 2 6 62 62 62 74 74 74 30 30 30
44976- 10 10 10 0 0 0 0 0 0 0 0 0
44977- 0 0 0 0 0 0 0 0 0 0 0 0
44978- 0 0 0 0 0 0 0 0 0 0 0 0
44979- 0 0 0 0 0 0 0 0 0 0 0 0
44980- 0 0 0 0 0 0 0 0 0 0 0 0
44981- 0 0 0 0 0 0 0 0 0 0 0 0
44982- 0 0 0 0 0 0 0 0 0 0 0 0
44983- 0 0 0 0 0 0 0 0 0 0 0 0
44984- 0 0 0 0 0 0 0 0 0 0 0 0
44985- 0 0 0 0 0 0 0 0 0 0 0 0
44986- 0 0 0 0 0 0 0 0 0 0 0 0
44987- 0 0 0 0 0 0 0 0 0 0 0 0
44988- 0 0 0 0 0 0 0 0 0 10 10 10
44989- 34 34 34 78 78 78 50 50 50 6 6 6
44990- 94 70 30 139 102 15 190 146 13 226 184 13
44991-232 200 30 232 195 16 215 174 15 190 146 13
44992-168 122 10 192 133 9 210 150 10 213 154 11
44993-202 150 34 182 157 106 101 98 89 2 2 6
44994- 2 2 6 78 78 78 116 116 116 58 58 58
44995- 2 2 6 22 22 22 90 90 90 46 46 46
44996- 18 18 18 6 6 6 0 0 0 0 0 0
44997- 0 0 0 0 0 0 0 0 0 0 0 0
44998- 0 0 0 0 0 0 0 0 0 0 0 0
44999- 0 0 0 0 0 0 0 0 0 0 0 0
45000- 0 0 0 0 0 0 0 0 0 0 0 0
45001- 0 0 0 0 0 0 0 0 0 0 0 0
45002- 0 0 0 0 0 0 0 0 0 0 0 0
45003- 0 0 0 0 0 0 0 0 0 0 0 0
45004- 0 0 0 0 0 0 0 0 0 0 0 0
45005- 0 0 0 0 0 0 0 0 0 0 0 0
45006- 0 0 0 0 0 0 0 0 0 0 0 0
45007- 0 0 0 0 0 0 0 0 0 0 0 0
45008- 0 0 0 0 0 0 0 0 0 10 10 10
45009- 38 38 38 86 86 86 50 50 50 6 6 6
45010-128 128 128 174 154 114 156 107 11 168 122 10
45011-198 155 10 184 144 12 197 138 11 200 144 11
45012-206 145 10 206 145 10 197 138 11 188 164 115
45013-195 195 195 198 198 198 174 174 174 14 14 14
45014- 2 2 6 22 22 22 116 116 116 116 116 116
45015- 22 22 22 2 2 6 74 74 74 70 70 70
45016- 30 30 30 10 10 10 0 0 0 0 0 0
45017- 0 0 0 0 0 0 0 0 0 0 0 0
45018- 0 0 0 0 0 0 0 0 0 0 0 0
45019- 0 0 0 0 0 0 0 0 0 0 0 0
45020- 0 0 0 0 0 0 0 0 0 0 0 0
45021- 0 0 0 0 0 0 0 0 0 0 0 0
45022- 0 0 0 0 0 0 0 0 0 0 0 0
45023- 0 0 0 0 0 0 0 0 0 0 0 0
45024- 0 0 0 0 0 0 0 0 0 0 0 0
45025- 0 0 0 0 0 0 0 0 0 0 0 0
45026- 0 0 0 0 0 0 0 0 0 0 0 0
45027- 0 0 0 0 0 0 0 0 0 0 0 0
45028- 0 0 0 0 0 0 6 6 6 18 18 18
45029- 50 50 50 101 101 101 26 26 26 10 10 10
45030-138 138 138 190 190 190 174 154 114 156 107 11
45031-197 138 11 200 144 11 197 138 11 192 133 9
45032-180 123 7 190 142 34 190 178 144 187 187 187
45033-202 202 202 221 221 221 214 214 214 66 66 66
45034- 2 2 6 2 2 6 50 50 50 62 62 62
45035- 6 6 6 2 2 6 10 10 10 90 90 90
45036- 50 50 50 18 18 18 6 6 6 0 0 0
45037- 0 0 0 0 0 0 0 0 0 0 0 0
45038- 0 0 0 0 0 0 0 0 0 0 0 0
45039- 0 0 0 0 0 0 0 0 0 0 0 0
45040- 0 0 0 0 0 0 0 0 0 0 0 0
45041- 0 0 0 0 0 0 0 0 0 0 0 0
45042- 0 0 0 0 0 0 0 0 0 0 0 0
45043- 0 0 0 0 0 0 0 0 0 0 0 0
45044- 0 0 0 0 0 0 0 0 0 0 0 0
45045- 0 0 0 0 0 0 0 0 0 0 0 0
45046- 0 0 0 0 0 0 0 0 0 0 0 0
45047- 0 0 0 0 0 0 0 0 0 0 0 0
45048- 0 0 0 0 0 0 10 10 10 34 34 34
45049- 74 74 74 74 74 74 2 2 6 6 6 6
45050-144 144 144 198 198 198 190 190 190 178 166 146
45051-154 121 60 156 107 11 156 107 11 168 124 44
45052-174 154 114 187 187 187 190 190 190 210 210 210
45053-246 246 246 253 253 253 253 253 253 182 182 182
45054- 6 6 6 2 2 6 2 2 6 2 2 6
45055- 2 2 6 2 2 6 2 2 6 62 62 62
45056- 74 74 74 34 34 34 14 14 14 0 0 0
45057- 0 0 0 0 0 0 0 0 0 0 0 0
45058- 0 0 0 0 0 0 0 0 0 0 0 0
45059- 0 0 0 0 0 0 0 0 0 0 0 0
45060- 0 0 0 0 0 0 0 0 0 0 0 0
45061- 0 0 0 0 0 0 0 0 0 0 0 0
45062- 0 0 0 0 0 0 0 0 0 0 0 0
45063- 0 0 0 0 0 0 0 0 0 0 0 0
45064- 0 0 0 0 0 0 0 0 0 0 0 0
45065- 0 0 0 0 0 0 0 0 0 0 0 0
45066- 0 0 0 0 0 0 0 0 0 0 0 0
45067- 0 0 0 0 0 0 0 0 0 0 0 0
45068- 0 0 0 10 10 10 22 22 22 54 54 54
45069- 94 94 94 18 18 18 2 2 6 46 46 46
45070-234 234 234 221 221 221 190 190 190 190 190 190
45071-190 190 190 187 187 187 187 187 187 190 190 190
45072-190 190 190 195 195 195 214 214 214 242 242 242
45073-253 253 253 253 253 253 253 253 253 253 253 253
45074- 82 82 82 2 2 6 2 2 6 2 2 6
45075- 2 2 6 2 2 6 2 2 6 14 14 14
45076- 86 86 86 54 54 54 22 22 22 6 6 6
45077- 0 0 0 0 0 0 0 0 0 0 0 0
45078- 0 0 0 0 0 0 0 0 0 0 0 0
45079- 0 0 0 0 0 0 0 0 0 0 0 0
45080- 0 0 0 0 0 0 0 0 0 0 0 0
45081- 0 0 0 0 0 0 0 0 0 0 0 0
45082- 0 0 0 0 0 0 0 0 0 0 0 0
45083- 0 0 0 0 0 0 0 0 0 0 0 0
45084- 0 0 0 0 0 0 0 0 0 0 0 0
45085- 0 0 0 0 0 0 0 0 0 0 0 0
45086- 0 0 0 0 0 0 0 0 0 0 0 0
45087- 0 0 0 0 0 0 0 0 0 0 0 0
45088- 6 6 6 18 18 18 46 46 46 90 90 90
45089- 46 46 46 18 18 18 6 6 6 182 182 182
45090-253 253 253 246 246 246 206 206 206 190 190 190
45091-190 190 190 190 190 190 190 190 190 190 190 190
45092-206 206 206 231 231 231 250 250 250 253 253 253
45093-253 253 253 253 253 253 253 253 253 253 253 253
45094-202 202 202 14 14 14 2 2 6 2 2 6
45095- 2 2 6 2 2 6 2 2 6 2 2 6
45096- 42 42 42 86 86 86 42 42 42 18 18 18
45097- 6 6 6 0 0 0 0 0 0 0 0 0
45098- 0 0 0 0 0 0 0 0 0 0 0 0
45099- 0 0 0 0 0 0 0 0 0 0 0 0
45100- 0 0 0 0 0 0 0 0 0 0 0 0
45101- 0 0 0 0 0 0 0 0 0 0 0 0
45102- 0 0 0 0 0 0 0 0 0 0 0 0
45103- 0 0 0 0 0 0 0 0 0 0 0 0
45104- 0 0 0 0 0 0 0 0 0 0 0 0
45105- 0 0 0 0 0 0 0 0 0 0 0 0
45106- 0 0 0 0 0 0 0 0 0 0 0 0
45107- 0 0 0 0 0 0 0 0 0 6 6 6
45108- 14 14 14 38 38 38 74 74 74 66 66 66
45109- 2 2 6 6 6 6 90 90 90 250 250 250
45110-253 253 253 253 253 253 238 238 238 198 198 198
45111-190 190 190 190 190 190 195 195 195 221 221 221
45112-246 246 246 253 253 253 253 253 253 253 253 253
45113-253 253 253 253 253 253 253 253 253 253 253 253
45114-253 253 253 82 82 82 2 2 6 2 2 6
45115- 2 2 6 2 2 6 2 2 6 2 2 6
45116- 2 2 6 78 78 78 70 70 70 34 34 34
45117- 14 14 14 6 6 6 0 0 0 0 0 0
45118- 0 0 0 0 0 0 0 0 0 0 0 0
45119- 0 0 0 0 0 0 0 0 0 0 0 0
45120- 0 0 0 0 0 0 0 0 0 0 0 0
45121- 0 0 0 0 0 0 0 0 0 0 0 0
45122- 0 0 0 0 0 0 0 0 0 0 0 0
45123- 0 0 0 0 0 0 0 0 0 0 0 0
45124- 0 0 0 0 0 0 0 0 0 0 0 0
45125- 0 0 0 0 0 0 0 0 0 0 0 0
45126- 0 0 0 0 0 0 0 0 0 0 0 0
45127- 0 0 0 0 0 0 0 0 0 14 14 14
45128- 34 34 34 66 66 66 78 78 78 6 6 6
45129- 2 2 6 18 18 18 218 218 218 253 253 253
45130-253 253 253 253 253 253 253 253 253 246 246 246
45131-226 226 226 231 231 231 246 246 246 253 253 253
45132-253 253 253 253 253 253 253 253 253 253 253 253
45133-253 253 253 253 253 253 253 253 253 253 253 253
45134-253 253 253 178 178 178 2 2 6 2 2 6
45135- 2 2 6 2 2 6 2 2 6 2 2 6
45136- 2 2 6 18 18 18 90 90 90 62 62 62
45137- 30 30 30 10 10 10 0 0 0 0 0 0
45138- 0 0 0 0 0 0 0 0 0 0 0 0
45139- 0 0 0 0 0 0 0 0 0 0 0 0
45140- 0 0 0 0 0 0 0 0 0 0 0 0
45141- 0 0 0 0 0 0 0 0 0 0 0 0
45142- 0 0 0 0 0 0 0 0 0 0 0 0
45143- 0 0 0 0 0 0 0 0 0 0 0 0
45144- 0 0 0 0 0 0 0 0 0 0 0 0
45145- 0 0 0 0 0 0 0 0 0 0 0 0
45146- 0 0 0 0 0 0 0 0 0 0 0 0
45147- 0 0 0 0 0 0 10 10 10 26 26 26
45148- 58 58 58 90 90 90 18 18 18 2 2 6
45149- 2 2 6 110 110 110 253 253 253 253 253 253
45150-253 253 253 253 253 253 253 253 253 253 253 253
45151-250 250 250 253 253 253 253 253 253 253 253 253
45152-253 253 253 253 253 253 253 253 253 253 253 253
45153-253 253 253 253 253 253 253 253 253 253 253 253
45154-253 253 253 231 231 231 18 18 18 2 2 6
45155- 2 2 6 2 2 6 2 2 6 2 2 6
45156- 2 2 6 2 2 6 18 18 18 94 94 94
45157- 54 54 54 26 26 26 10 10 10 0 0 0
45158- 0 0 0 0 0 0 0 0 0 0 0 0
45159- 0 0 0 0 0 0 0 0 0 0 0 0
45160- 0 0 0 0 0 0 0 0 0 0 0 0
45161- 0 0 0 0 0 0 0 0 0 0 0 0
45162- 0 0 0 0 0 0 0 0 0 0 0 0
45163- 0 0 0 0 0 0 0 0 0 0 0 0
45164- 0 0 0 0 0 0 0 0 0 0 0 0
45165- 0 0 0 0 0 0 0 0 0 0 0 0
45166- 0 0 0 0 0 0 0 0 0 0 0 0
45167- 0 0 0 6 6 6 22 22 22 50 50 50
45168- 90 90 90 26 26 26 2 2 6 2 2 6
45169- 14 14 14 195 195 195 250 250 250 253 253 253
45170-253 253 253 253 253 253 253 253 253 253 253 253
45171-253 253 253 253 253 253 253 253 253 253 253 253
45172-253 253 253 253 253 253 253 253 253 253 253 253
45173-253 253 253 253 253 253 253 253 253 253 253 253
45174-250 250 250 242 242 242 54 54 54 2 2 6
45175- 2 2 6 2 2 6 2 2 6 2 2 6
45176- 2 2 6 2 2 6 2 2 6 38 38 38
45177- 86 86 86 50 50 50 22 22 22 6 6 6
45178- 0 0 0 0 0 0 0 0 0 0 0 0
45179- 0 0 0 0 0 0 0 0 0 0 0 0
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- 6 6 6 14 14 14 38 38 38 82 82 82
45188- 34 34 34 2 2 6 2 2 6 2 2 6
45189- 42 42 42 195 195 195 246 246 246 253 253 253
45190-253 253 253 253 253 253 253 253 253 250 250 250
45191-242 242 242 242 242 242 250 250 250 253 253 253
45192-253 253 253 253 253 253 253 253 253 253 253 253
45193-253 253 253 250 250 250 246 246 246 238 238 238
45194-226 226 226 231 231 231 101 101 101 6 6 6
45195- 2 2 6 2 2 6 2 2 6 2 2 6
45196- 2 2 6 2 2 6 2 2 6 2 2 6
45197- 38 38 38 82 82 82 42 42 42 14 14 14
45198- 6 6 6 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- 10 10 10 26 26 26 62 62 62 66 66 66
45208- 2 2 6 2 2 6 2 2 6 6 6 6
45209- 70 70 70 170 170 170 206 206 206 234 234 234
45210-246 246 246 250 250 250 250 250 250 238 238 238
45211-226 226 226 231 231 231 238 238 238 250 250 250
45212-250 250 250 250 250 250 246 246 246 231 231 231
45213-214 214 214 206 206 206 202 202 202 202 202 202
45214-198 198 198 202 202 202 182 182 182 18 18 18
45215- 2 2 6 2 2 6 2 2 6 2 2 6
45216- 2 2 6 2 2 6 2 2 6 2 2 6
45217- 2 2 6 62 62 62 66 66 66 30 30 30
45218- 10 10 10 0 0 0 0 0 0 0 0 0
45219- 0 0 0 0 0 0 0 0 0 0 0 0
45220- 0 0 0 0 0 0 0 0 0 0 0 0
45221- 0 0 0 0 0 0 0 0 0 0 0 0
45222- 0 0 0 0 0 0 0 0 0 0 0 0
45223- 0 0 0 0 0 0 0 0 0 0 0 0
45224- 0 0 0 0 0 0 0 0 0 0 0 0
45225- 0 0 0 0 0 0 0 0 0 0 0 0
45226- 0 0 0 0 0 0 0 0 0 0 0 0
45227- 14 14 14 42 42 42 82 82 82 18 18 18
45228- 2 2 6 2 2 6 2 2 6 10 10 10
45229- 94 94 94 182 182 182 218 218 218 242 242 242
45230-250 250 250 253 253 253 253 253 253 250 250 250
45231-234 234 234 253 253 253 253 253 253 253 253 253
45232-253 253 253 253 253 253 253 253 253 246 246 246
45233-238 238 238 226 226 226 210 210 210 202 202 202
45234-195 195 195 195 195 195 210 210 210 158 158 158
45235- 6 6 6 14 14 14 50 50 50 14 14 14
45236- 2 2 6 2 2 6 2 2 6 2 2 6
45237- 2 2 6 6 6 6 86 86 86 46 46 46
45238- 18 18 18 6 6 6 0 0 0 0 0 0
45239- 0 0 0 0 0 0 0 0 0 0 0 0
45240- 0 0 0 0 0 0 0 0 0 0 0 0
45241- 0 0 0 0 0 0 0 0 0 0 0 0
45242- 0 0 0 0 0 0 0 0 0 0 0 0
45243- 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 6 6 6
45247- 22 22 22 54 54 54 70 70 70 2 2 6
45248- 2 2 6 10 10 10 2 2 6 22 22 22
45249-166 166 166 231 231 231 250 250 250 253 253 253
45250-253 253 253 253 253 253 253 253 253 250 250 250
45251-242 242 242 253 253 253 253 253 253 253 253 253
45252-253 253 253 253 253 253 253 253 253 253 253 253
45253-253 253 253 253 253 253 253 253 253 246 246 246
45254-231 231 231 206 206 206 198 198 198 226 226 226
45255- 94 94 94 2 2 6 6 6 6 38 38 38
45256- 30 30 30 2 2 6 2 2 6 2 2 6
45257- 2 2 6 2 2 6 62 62 62 66 66 66
45258- 26 26 26 10 10 10 0 0 0 0 0 0
45259- 0 0 0 0 0 0 0 0 0 0 0 0
45260- 0 0 0 0 0 0 0 0 0 0 0 0
45261- 0 0 0 0 0 0 0 0 0 0 0 0
45262- 0 0 0 0 0 0 0 0 0 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 10 10 10
45267- 30 30 30 74 74 74 50 50 50 2 2 6
45268- 26 26 26 26 26 26 2 2 6 106 106 106
45269-238 238 238 253 253 253 253 253 253 253 253 253
45270-253 253 253 253 253 253 253 253 253 253 253 253
45271-253 253 253 253 253 253 253 253 253 253 253 253
45272-253 253 253 253 253 253 253 253 253 253 253 253
45273-253 253 253 253 253 253 253 253 253 253 253 253
45274-253 253 253 246 246 246 218 218 218 202 202 202
45275-210 210 210 14 14 14 2 2 6 2 2 6
45276- 30 30 30 22 22 22 2 2 6 2 2 6
45277- 2 2 6 2 2 6 18 18 18 86 86 86
45278- 42 42 42 14 14 14 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 14 14 14
45287- 42 42 42 90 90 90 22 22 22 2 2 6
45288- 42 42 42 2 2 6 18 18 18 218 218 218
45289-253 253 253 253 253 253 253 253 253 253 253 253
45290-253 253 253 253 253 253 253 253 253 253 253 253
45291-253 253 253 253 253 253 253 253 253 253 253 253
45292-253 253 253 253 253 253 253 253 253 253 253 253
45293-253 253 253 253 253 253 253 253 253 253 253 253
45294-253 253 253 253 253 253 250 250 250 221 221 221
45295-218 218 218 101 101 101 2 2 6 14 14 14
45296- 18 18 18 38 38 38 10 10 10 2 2 6
45297- 2 2 6 2 2 6 2 2 6 78 78 78
45298- 58 58 58 22 22 22 6 6 6 0 0 0
45299- 0 0 0 0 0 0 0 0 0 0 0 0
45300- 0 0 0 0 0 0 0 0 0 0 0 0
45301- 0 0 0 0 0 0 0 0 0 0 0 0
45302- 0 0 0 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 6 6 6 18 18 18
45307- 54 54 54 82 82 82 2 2 6 26 26 26
45308- 22 22 22 2 2 6 123 123 123 253 253 253
45309-253 253 253 253 253 253 253 253 253 253 253 253
45310-253 253 253 253 253 253 253 253 253 253 253 253
45311-253 253 253 253 253 253 253 253 253 253 253 253
45312-253 253 253 253 253 253 253 253 253 253 253 253
45313-253 253 253 253 253 253 253 253 253 253 253 253
45314-253 253 253 253 253 253 253 253 253 250 250 250
45315-238 238 238 198 198 198 6 6 6 38 38 38
45316- 58 58 58 26 26 26 38 38 38 2 2 6
45317- 2 2 6 2 2 6 2 2 6 46 46 46
45318- 78 78 78 30 30 30 10 10 10 0 0 0
45319- 0 0 0 0 0 0 0 0 0 0 0 0
45320- 0 0 0 0 0 0 0 0 0 0 0 0
45321- 0 0 0 0 0 0 0 0 0 0 0 0
45322- 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 10 10 10 30 30 30
45327- 74 74 74 58 58 58 2 2 6 42 42 42
45328- 2 2 6 22 22 22 231 231 231 253 253 253
45329-253 253 253 253 253 253 253 253 253 253 253 253
45330-253 253 253 253 253 253 253 253 253 250 250 250
45331-253 253 253 253 253 253 253 253 253 253 253 253
45332-253 253 253 253 253 253 253 253 253 253 253 253
45333-253 253 253 253 253 253 253 253 253 253 253 253
45334-253 253 253 253 253 253 253 253 253 253 253 253
45335-253 253 253 246 246 246 46 46 46 38 38 38
45336- 42 42 42 14 14 14 38 38 38 14 14 14
45337- 2 2 6 2 2 6 2 2 6 6 6 6
45338- 86 86 86 46 46 46 14 14 14 0 0 0
45339- 0 0 0 0 0 0 0 0 0 0 0 0
45340- 0 0 0 0 0 0 0 0 0 0 0 0
45341- 0 0 0 0 0 0 0 0 0 0 0 0
45342- 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 6 6 6 14 14 14 42 42 42
45347- 90 90 90 18 18 18 18 18 18 26 26 26
45348- 2 2 6 116 116 116 253 253 253 253 253 253
45349-253 253 253 253 253 253 253 253 253 253 253 253
45350-253 253 253 253 253 253 250 250 250 238 238 238
45351-253 253 253 253 253 253 253 253 253 253 253 253
45352-253 253 253 253 253 253 253 253 253 253 253 253
45353-253 253 253 253 253 253 253 253 253 253 253 253
45354-253 253 253 253 253 253 253 253 253 253 253 253
45355-253 253 253 253 253 253 94 94 94 6 6 6
45356- 2 2 6 2 2 6 10 10 10 34 34 34
45357- 2 2 6 2 2 6 2 2 6 2 2 6
45358- 74 74 74 58 58 58 22 22 22 6 6 6
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 10 10 10 26 26 26 66 66 66
45367- 82 82 82 2 2 6 38 38 38 6 6 6
45368- 14 14 14 210 210 210 253 253 253 253 253 253
45369-253 253 253 253 253 253 253 253 253 253 253 253
45370-253 253 253 253 253 253 246 246 246 242 242 242
45371-253 253 253 253 253 253 253 253 253 253 253 253
45372-253 253 253 253 253 253 253 253 253 253 253 253
45373-253 253 253 253 253 253 253 253 253 253 253 253
45374-253 253 253 253 253 253 253 253 253 253 253 253
45375-253 253 253 253 253 253 144 144 144 2 2 6
45376- 2 2 6 2 2 6 2 2 6 46 46 46
45377- 2 2 6 2 2 6 2 2 6 2 2 6
45378- 42 42 42 74 74 74 30 30 30 10 10 10
45379- 0 0 0 0 0 0 0 0 0 0 0 0
45380- 0 0 0 0 0 0 0 0 0 0 0 0
45381- 0 0 0 0 0 0 0 0 0 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- 6 6 6 14 14 14 42 42 42 90 90 90
45387- 26 26 26 6 6 6 42 42 42 2 2 6
45388- 74 74 74 250 250 250 253 253 253 253 253 253
45389-253 253 253 253 253 253 253 253 253 253 253 253
45390-253 253 253 253 253 253 242 242 242 242 242 242
45391-253 253 253 253 253 253 253 253 253 253 253 253
45392-253 253 253 253 253 253 253 253 253 253 253 253
45393-253 253 253 253 253 253 253 253 253 253 253 253
45394-253 253 253 253 253 253 253 253 253 253 253 253
45395-253 253 253 253 253 253 182 182 182 2 2 6
45396- 2 2 6 2 2 6 2 2 6 46 46 46
45397- 2 2 6 2 2 6 2 2 6 2 2 6
45398- 10 10 10 86 86 86 38 38 38 10 10 10
45399- 0 0 0 0 0 0 0 0 0 0 0 0
45400- 0 0 0 0 0 0 0 0 0 0 0 0
45401- 0 0 0 0 0 0 0 0 0 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- 10 10 10 26 26 26 66 66 66 82 82 82
45407- 2 2 6 22 22 22 18 18 18 2 2 6
45408-149 149 149 253 253 253 253 253 253 253 253 253
45409-253 253 253 253 253 253 253 253 253 253 253 253
45410-253 253 253 253 253 253 234 234 234 242 242 242
45411-253 253 253 253 253 253 253 253 253 253 253 253
45412-253 253 253 253 253 253 253 253 253 253 253 253
45413-253 253 253 253 253 253 253 253 253 253 253 253
45414-253 253 253 253 253 253 253 253 253 253 253 253
45415-253 253 253 253 253 253 206 206 206 2 2 6
45416- 2 2 6 2 2 6 2 2 6 38 38 38
45417- 2 2 6 2 2 6 2 2 6 2 2 6
45418- 6 6 6 86 86 86 46 46 46 14 14 14
45419- 0 0 0 0 0 0 0 0 0 0 0 0
45420- 0 0 0 0 0 0 0 0 0 0 0 0
45421- 0 0 0 0 0 0 0 0 0 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 6 6 6
45426- 18 18 18 46 46 46 86 86 86 18 18 18
45427- 2 2 6 34 34 34 10 10 10 6 6 6
45428-210 210 210 253 253 253 253 253 253 253 253 253
45429-253 253 253 253 253 253 253 253 253 253 253 253
45430-253 253 253 253 253 253 234 234 234 242 242 242
45431-253 253 253 253 253 253 253 253 253 253 253 253
45432-253 253 253 253 253 253 253 253 253 253 253 253
45433-253 253 253 253 253 253 253 253 253 253 253 253
45434-253 253 253 253 253 253 253 253 253 253 253 253
45435-253 253 253 253 253 253 221 221 221 6 6 6
45436- 2 2 6 2 2 6 6 6 6 30 30 30
45437- 2 2 6 2 2 6 2 2 6 2 2 6
45438- 2 2 6 82 82 82 54 54 54 18 18 18
45439- 6 6 6 0 0 0 0 0 0 0 0 0
45440- 0 0 0 0 0 0 0 0 0 0 0 0
45441- 0 0 0 0 0 0 0 0 0 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 10 10 10
45446- 26 26 26 66 66 66 62 62 62 2 2 6
45447- 2 2 6 38 38 38 10 10 10 26 26 26
45448-238 238 238 253 253 253 253 253 253 253 253 253
45449-253 253 253 253 253 253 253 253 253 253 253 253
45450-253 253 253 253 253 253 231 231 231 238 238 238
45451-253 253 253 253 253 253 253 253 253 253 253 253
45452-253 253 253 253 253 253 253 253 253 253 253 253
45453-253 253 253 253 253 253 253 253 253 253 253 253
45454-253 253 253 253 253 253 253 253 253 253 253 253
45455-253 253 253 253 253 253 231 231 231 6 6 6
45456- 2 2 6 2 2 6 10 10 10 30 30 30
45457- 2 2 6 2 2 6 2 2 6 2 2 6
45458- 2 2 6 66 66 66 58 58 58 22 22 22
45459- 6 6 6 0 0 0 0 0 0 0 0 0
45460- 0 0 0 0 0 0 0 0 0 0 0 0
45461- 0 0 0 0 0 0 0 0 0 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 10 10 10
45466- 38 38 38 78 78 78 6 6 6 2 2 6
45467- 2 2 6 46 46 46 14 14 14 42 42 42
45468-246 246 246 253 253 253 253 253 253 253 253 253
45469-253 253 253 253 253 253 253 253 253 253 253 253
45470-253 253 253 253 253 253 231 231 231 242 242 242
45471-253 253 253 253 253 253 253 253 253 253 253 253
45472-253 253 253 253 253 253 253 253 253 253 253 253
45473-253 253 253 253 253 253 253 253 253 253 253 253
45474-253 253 253 253 253 253 253 253 253 253 253 253
45475-253 253 253 253 253 253 234 234 234 10 10 10
45476- 2 2 6 2 2 6 22 22 22 14 14 14
45477- 2 2 6 2 2 6 2 2 6 2 2 6
45478- 2 2 6 66 66 66 62 62 62 22 22 22
45479- 6 6 6 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 6 6 6 18 18 18
45486- 50 50 50 74 74 74 2 2 6 2 2 6
45487- 14 14 14 70 70 70 34 34 34 62 62 62
45488-250 250 250 253 253 253 253 253 253 253 253 253
45489-253 253 253 253 253 253 253 253 253 253 253 253
45490-253 253 253 253 253 253 231 231 231 246 246 246
45491-253 253 253 253 253 253 253 253 253 253 253 253
45492-253 253 253 253 253 253 253 253 253 253 253 253
45493-253 253 253 253 253 253 253 253 253 253 253 253
45494-253 253 253 253 253 253 253 253 253 253 253 253
45495-253 253 253 253 253 253 234 234 234 14 14 14
45496- 2 2 6 2 2 6 30 30 30 2 2 6
45497- 2 2 6 2 2 6 2 2 6 2 2 6
45498- 2 2 6 66 66 66 62 62 62 22 22 22
45499- 6 6 6 0 0 0 0 0 0 0 0 0
45500- 0 0 0 0 0 0 0 0 0 0 0 0
45501- 0 0 0 0 0 0 0 0 0 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 6 6 6 18 18 18
45506- 54 54 54 62 62 62 2 2 6 2 2 6
45507- 2 2 6 30 30 30 46 46 46 70 70 70
45508-250 250 250 253 253 253 253 253 253 253 253 253
45509-253 253 253 253 253 253 253 253 253 253 253 253
45510-253 253 253 253 253 253 231 231 231 246 246 246
45511-253 253 253 253 253 253 253 253 253 253 253 253
45512-253 253 253 253 253 253 253 253 253 253 253 253
45513-253 253 253 253 253 253 253 253 253 253 253 253
45514-253 253 253 253 253 253 253 253 253 253 253 253
45515-253 253 253 253 253 253 226 226 226 10 10 10
45516- 2 2 6 6 6 6 30 30 30 2 2 6
45517- 2 2 6 2 2 6 2 2 6 2 2 6
45518- 2 2 6 66 66 66 58 58 58 22 22 22
45519- 6 6 6 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 6 6 6 22 22 22
45526- 58 58 58 62 62 62 2 2 6 2 2 6
45527- 2 2 6 2 2 6 30 30 30 78 78 78
45528-250 250 250 253 253 253 253 253 253 253 253 253
45529-253 253 253 253 253 253 253 253 253 253 253 253
45530-253 253 253 253 253 253 231 231 231 246 246 246
45531-253 253 253 253 253 253 253 253 253 253 253 253
45532-253 253 253 253 253 253 253 253 253 253 253 253
45533-253 253 253 253 253 253 253 253 253 253 253 253
45534-253 253 253 253 253 253 253 253 253 253 253 253
45535-253 253 253 253 253 253 206 206 206 2 2 6
45536- 22 22 22 34 34 34 18 14 6 22 22 22
45537- 26 26 26 18 18 18 6 6 6 2 2 6
45538- 2 2 6 82 82 82 54 54 54 18 18 18
45539- 6 6 6 0 0 0 0 0 0 0 0 0
45540- 0 0 0 0 0 0 0 0 0 0 0 0
45541- 0 0 0 0 0 0 0 0 0 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 6 6 6 26 26 26
45546- 62 62 62 106 106 106 74 54 14 185 133 11
45547-210 162 10 121 92 8 6 6 6 62 62 62
45548-238 238 238 253 253 253 253 253 253 253 253 253
45549-253 253 253 253 253 253 253 253 253 253 253 253
45550-253 253 253 253 253 253 231 231 231 246 246 246
45551-253 253 253 253 253 253 253 253 253 253 253 253
45552-253 253 253 253 253 253 253 253 253 253 253 253
45553-253 253 253 253 253 253 253 253 253 253 253 253
45554-253 253 253 253 253 253 253 253 253 253 253 253
45555-253 253 253 253 253 253 158 158 158 18 18 18
45556- 14 14 14 2 2 6 2 2 6 2 2 6
45557- 6 6 6 18 18 18 66 66 66 38 38 38
45558- 6 6 6 94 94 94 50 50 50 18 18 18
45559- 6 6 6 0 0 0 0 0 0 0 0 0
45560- 0 0 0 0 0 0 0 0 0 0 0 0
45561- 0 0 0 0 0 0 0 0 0 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 6 6 6
45565- 10 10 10 10 10 10 18 18 18 38 38 38
45566- 78 78 78 142 134 106 216 158 10 242 186 14
45567-246 190 14 246 190 14 156 118 10 10 10 10
45568- 90 90 90 238 238 238 253 253 253 253 253 253
45569-253 253 253 253 253 253 253 253 253 253 253 253
45570-253 253 253 253 253 253 231 231 231 250 250 250
45571-253 253 253 253 253 253 253 253 253 253 253 253
45572-253 253 253 253 253 253 253 253 253 253 253 253
45573-253 253 253 253 253 253 253 253 253 253 253 253
45574-253 253 253 253 253 253 253 253 253 246 230 190
45575-238 204 91 238 204 91 181 142 44 37 26 9
45576- 2 2 6 2 2 6 2 2 6 2 2 6
45577- 2 2 6 2 2 6 38 38 38 46 46 46
45578- 26 26 26 106 106 106 54 54 54 18 18 18
45579- 6 6 6 0 0 0 0 0 0 0 0 0
45580- 0 0 0 0 0 0 0 0 0 0 0 0
45581- 0 0 0 0 0 0 0 0 0 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 6 6 6 14 14 14 22 22 22
45585- 30 30 30 38 38 38 50 50 50 70 70 70
45586-106 106 106 190 142 34 226 170 11 242 186 14
45587-246 190 14 246 190 14 246 190 14 154 114 10
45588- 6 6 6 74 74 74 226 226 226 253 253 253
45589-253 253 253 253 253 253 253 253 253 253 253 253
45590-253 253 253 253 253 253 231 231 231 250 250 250
45591-253 253 253 253 253 253 253 253 253 253 253 253
45592-253 253 253 253 253 253 253 253 253 253 253 253
45593-253 253 253 253 253 253 253 253 253 253 253 253
45594-253 253 253 253 253 253 253 253 253 228 184 62
45595-241 196 14 241 208 19 232 195 16 38 30 10
45596- 2 2 6 2 2 6 2 2 6 2 2 6
45597- 2 2 6 6 6 6 30 30 30 26 26 26
45598-203 166 17 154 142 90 66 66 66 26 26 26
45599- 6 6 6 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- 6 6 6 18 18 18 38 38 38 58 58 58
45605- 78 78 78 86 86 86 101 101 101 123 123 123
45606-175 146 61 210 150 10 234 174 13 246 186 14
45607-246 190 14 246 190 14 246 190 14 238 190 10
45608-102 78 10 2 2 6 46 46 46 198 198 198
45609-253 253 253 253 253 253 253 253 253 253 253 253
45610-253 253 253 253 253 253 234 234 234 242 242 242
45611-253 253 253 253 253 253 253 253 253 253 253 253
45612-253 253 253 253 253 253 253 253 253 253 253 253
45613-253 253 253 253 253 253 253 253 253 253 253 253
45614-253 253 253 253 253 253 253 253 253 224 178 62
45615-242 186 14 241 196 14 210 166 10 22 18 6
45616- 2 2 6 2 2 6 2 2 6 2 2 6
45617- 2 2 6 2 2 6 6 6 6 121 92 8
45618-238 202 15 232 195 16 82 82 82 34 34 34
45619- 10 10 10 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- 14 14 14 38 38 38 70 70 70 154 122 46
45625-190 142 34 200 144 11 197 138 11 197 138 11
45626-213 154 11 226 170 11 242 186 14 246 190 14
45627-246 190 14 246 190 14 246 190 14 246 190 14
45628-225 175 15 46 32 6 2 2 6 22 22 22
45629-158 158 158 250 250 250 253 253 253 253 253 253
45630-253 253 253 253 253 253 253 253 253 253 253 253
45631-253 253 253 253 253 253 253 253 253 253 253 253
45632-253 253 253 253 253 253 253 253 253 253 253 253
45633-253 253 253 253 253 253 253 253 253 253 253 253
45634-253 253 253 250 250 250 242 242 242 224 178 62
45635-239 182 13 236 186 11 213 154 11 46 32 6
45636- 2 2 6 2 2 6 2 2 6 2 2 6
45637- 2 2 6 2 2 6 61 42 6 225 175 15
45638-238 190 10 236 186 11 112 100 78 42 42 42
45639- 14 14 14 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 6 6 6
45644- 22 22 22 54 54 54 154 122 46 213 154 11
45645-226 170 11 230 174 11 226 170 11 226 170 11
45646-236 178 12 242 186 14 246 190 14 246 190 14
45647-246 190 14 246 190 14 246 190 14 246 190 14
45648-241 196 14 184 144 12 10 10 10 2 2 6
45649- 6 6 6 116 116 116 242 242 242 253 253 253
45650-253 253 253 253 253 253 253 253 253 253 253 253
45651-253 253 253 253 253 253 253 253 253 253 253 253
45652-253 253 253 253 253 253 253 253 253 253 253 253
45653-253 253 253 253 253 253 253 253 253 253 253 253
45654-253 253 253 231 231 231 198 198 198 214 170 54
45655-236 178 12 236 178 12 210 150 10 137 92 6
45656- 18 14 6 2 2 6 2 2 6 2 2 6
45657- 6 6 6 70 47 6 200 144 11 236 178 12
45658-239 182 13 239 182 13 124 112 88 58 58 58
45659- 22 22 22 6 6 6 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 10 10 10
45664- 30 30 30 70 70 70 180 133 36 226 170 11
45665-239 182 13 242 186 14 242 186 14 246 186 14
45666-246 190 14 246 190 14 246 190 14 246 190 14
45667-246 190 14 246 190 14 246 190 14 246 190 14
45668-246 190 14 232 195 16 98 70 6 2 2 6
45669- 2 2 6 2 2 6 66 66 66 221 221 221
45670-253 253 253 253 253 253 253 253 253 253 253 253
45671-253 253 253 253 253 253 253 253 253 253 253 253
45672-253 253 253 253 253 253 253 253 253 253 253 253
45673-253 253 253 253 253 253 253 253 253 253 253 253
45674-253 253 253 206 206 206 198 198 198 214 166 58
45675-230 174 11 230 174 11 216 158 10 192 133 9
45676-163 110 8 116 81 8 102 78 10 116 81 8
45677-167 114 7 197 138 11 226 170 11 239 182 13
45678-242 186 14 242 186 14 162 146 94 78 78 78
45679- 34 34 34 14 14 14 6 6 6 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 6 6 6
45684- 30 30 30 78 78 78 190 142 34 226 170 11
45685-239 182 13 246 190 14 246 190 14 246 190 14
45686-246 190 14 246 190 14 246 190 14 246 190 14
45687-246 190 14 246 190 14 246 190 14 246 190 14
45688-246 190 14 241 196 14 203 166 17 22 18 6
45689- 2 2 6 2 2 6 2 2 6 38 38 38
45690-218 218 218 253 253 253 253 253 253 253 253 253
45691-253 253 253 253 253 253 253 253 253 253 253 253
45692-253 253 253 253 253 253 253 253 253 253 253 253
45693-253 253 253 253 253 253 253 253 253 253 253 253
45694-250 250 250 206 206 206 198 198 198 202 162 69
45695-226 170 11 236 178 12 224 166 10 210 150 10
45696-200 144 11 197 138 11 192 133 9 197 138 11
45697-210 150 10 226 170 11 242 186 14 246 190 14
45698-246 190 14 246 186 14 225 175 15 124 112 88
45699- 62 62 62 30 30 30 14 14 14 6 6 6
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 10 10 10
45704- 30 30 30 78 78 78 174 135 50 224 166 10
45705-239 182 13 246 190 14 246 190 14 246 190 14
45706-246 190 14 246 190 14 246 190 14 246 190 14
45707-246 190 14 246 190 14 246 190 14 246 190 14
45708-246 190 14 246 190 14 241 196 14 139 102 15
45709- 2 2 6 2 2 6 2 2 6 2 2 6
45710- 78 78 78 250 250 250 253 253 253 253 253 253
45711-253 253 253 253 253 253 253 253 253 253 253 253
45712-253 253 253 253 253 253 253 253 253 253 253 253
45713-253 253 253 253 253 253 253 253 253 253 253 253
45714-250 250 250 214 214 214 198 198 198 190 150 46
45715-219 162 10 236 178 12 234 174 13 224 166 10
45716-216 158 10 213 154 11 213 154 11 216 158 10
45717-226 170 11 239 182 13 246 190 14 246 190 14
45718-246 190 14 246 190 14 242 186 14 206 162 42
45719-101 101 101 58 58 58 30 30 30 14 14 14
45720- 6 6 6 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 10 10 10
45724- 30 30 30 74 74 74 174 135 50 216 158 10
45725-236 178 12 246 190 14 246 190 14 246 190 14
45726-246 190 14 246 190 14 246 190 14 246 190 14
45727-246 190 14 246 190 14 246 190 14 246 190 14
45728-246 190 14 246 190 14 241 196 14 226 184 13
45729- 61 42 6 2 2 6 2 2 6 2 2 6
45730- 22 22 22 238 238 238 253 253 253 253 253 253
45731-253 253 253 253 253 253 253 253 253 253 253 253
45732-253 253 253 253 253 253 253 253 253 253 253 253
45733-253 253 253 253 253 253 253 253 253 253 253 253
45734-253 253 253 226 226 226 187 187 187 180 133 36
45735-216 158 10 236 178 12 239 182 13 236 178 12
45736-230 174 11 226 170 11 226 170 11 230 174 11
45737-236 178 12 242 186 14 246 190 14 246 190 14
45738-246 190 14 246 190 14 246 186 14 239 182 13
45739-206 162 42 106 106 106 66 66 66 34 34 34
45740- 14 14 14 6 6 6 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 6 6 6
45744- 26 26 26 70 70 70 163 133 67 213 154 11
45745-236 178 12 246 190 14 246 190 14 246 190 14
45746-246 190 14 246 190 14 246 190 14 246 190 14
45747-246 190 14 246 190 14 246 190 14 246 190 14
45748-246 190 14 246 190 14 246 190 14 241 196 14
45749-190 146 13 18 14 6 2 2 6 2 2 6
45750- 46 46 46 246 246 246 253 253 253 253 253 253
45751-253 253 253 253 253 253 253 253 253 253 253 253
45752-253 253 253 253 253 253 253 253 253 253 253 253
45753-253 253 253 253 253 253 253 253 253 253 253 253
45754-253 253 253 221 221 221 86 86 86 156 107 11
45755-216 158 10 236 178 12 242 186 14 246 186 14
45756-242 186 14 239 182 13 239 182 13 242 186 14
45757-242 186 14 246 186 14 246 190 14 246 190 14
45758-246 190 14 246 190 14 246 190 14 246 190 14
45759-242 186 14 225 175 15 142 122 72 66 66 66
45760- 30 30 30 10 10 10 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 6 6 6
45764- 26 26 26 70 70 70 163 133 67 210 150 10
45765-236 178 12 246 190 14 246 190 14 246 190 14
45766-246 190 14 246 190 14 246 190 14 246 190 14
45767-246 190 14 246 190 14 246 190 14 246 190 14
45768-246 190 14 246 190 14 246 190 14 246 190 14
45769-232 195 16 121 92 8 34 34 34 106 106 106
45770-221 221 221 253 253 253 253 253 253 253 253 253
45771-253 253 253 253 253 253 253 253 253 253 253 253
45772-253 253 253 253 253 253 253 253 253 253 253 253
45773-253 253 253 253 253 253 253 253 253 253 253 253
45774-242 242 242 82 82 82 18 14 6 163 110 8
45775-216 158 10 236 178 12 242 186 14 246 190 14
45776-246 190 14 246 190 14 246 190 14 246 190 14
45777-246 190 14 246 190 14 246 190 14 246 190 14
45778-246 190 14 246 190 14 246 190 14 246 190 14
45779-246 190 14 246 190 14 242 186 14 163 133 67
45780- 46 46 46 18 18 18 6 6 6 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 10 10 10
45784- 30 30 30 78 78 78 163 133 67 210 150 10
45785-236 178 12 246 186 14 246 190 14 246 190 14
45786-246 190 14 246 190 14 246 190 14 246 190 14
45787-246 190 14 246 190 14 246 190 14 246 190 14
45788-246 190 14 246 190 14 246 190 14 246 190 14
45789-241 196 14 215 174 15 190 178 144 253 253 253
45790-253 253 253 253 253 253 253 253 253 253 253 253
45791-253 253 253 253 253 253 253 253 253 253 253 253
45792-253 253 253 253 253 253 253 253 253 253 253 253
45793-253 253 253 253 253 253 253 253 253 218 218 218
45794- 58 58 58 2 2 6 22 18 6 167 114 7
45795-216 158 10 236 178 12 246 186 14 246 190 14
45796-246 190 14 246 190 14 246 190 14 246 190 14
45797-246 190 14 246 190 14 246 190 14 246 190 14
45798-246 190 14 246 190 14 246 190 14 246 190 14
45799-246 190 14 246 186 14 242 186 14 190 150 46
45800- 54 54 54 22 22 22 6 6 6 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 14 14 14
45804- 38 38 38 86 86 86 180 133 36 213 154 11
45805-236 178 12 246 186 14 246 190 14 246 190 14
45806-246 190 14 246 190 14 246 190 14 246 190 14
45807-246 190 14 246 190 14 246 190 14 246 190 14
45808-246 190 14 246 190 14 246 190 14 246 190 14
45809-246 190 14 232 195 16 190 146 13 214 214 214
45810-253 253 253 253 253 253 253 253 253 253 253 253
45811-253 253 253 253 253 253 253 253 253 253 253 253
45812-253 253 253 253 253 253 253 253 253 253 253 253
45813-253 253 253 250 250 250 170 170 170 26 26 26
45814- 2 2 6 2 2 6 37 26 9 163 110 8
45815-219 162 10 239 182 13 246 186 14 246 190 14
45816-246 190 14 246 190 14 246 190 14 246 190 14
45817-246 190 14 246 190 14 246 190 14 246 190 14
45818-246 190 14 246 190 14 246 190 14 246 190 14
45819-246 186 14 236 178 12 224 166 10 142 122 72
45820- 46 46 46 18 18 18 6 6 6 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 6 6 6 18 18 18
45824- 50 50 50 109 106 95 192 133 9 224 166 10
45825-242 186 14 246 190 14 246 190 14 246 190 14
45826-246 190 14 246 190 14 246 190 14 246 190 14
45827-246 190 14 246 190 14 246 190 14 246 190 14
45828-246 190 14 246 190 14 246 190 14 246 190 14
45829-242 186 14 226 184 13 210 162 10 142 110 46
45830-226 226 226 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 253 253 253 253 253 253 253 253 253
45833-198 198 198 66 66 66 2 2 6 2 2 6
45834- 2 2 6 2 2 6 50 34 6 156 107 11
45835-219 162 10 239 182 13 246 186 14 246 190 14
45836-246 190 14 246 190 14 246 190 14 246 190 14
45837-246 190 14 246 190 14 246 190 14 246 190 14
45838-246 190 14 246 190 14 246 190 14 242 186 14
45839-234 174 13 213 154 11 154 122 46 66 66 66
45840- 30 30 30 10 10 10 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 6 6 6 22 22 22
45844- 58 58 58 154 121 60 206 145 10 234 174 13
45845-242 186 14 246 186 14 246 190 14 246 190 14
45846-246 190 14 246 190 14 246 190 14 246 190 14
45847-246 190 14 246 190 14 246 190 14 246 190 14
45848-246 190 14 246 190 14 246 190 14 246 190 14
45849-246 186 14 236 178 12 210 162 10 163 110 8
45850- 61 42 6 138 138 138 218 218 218 250 250 250
45851-253 253 253 253 253 253 253 253 253 250 250 250
45852-242 242 242 210 210 210 144 144 144 66 66 66
45853- 6 6 6 2 2 6 2 2 6 2 2 6
45854- 2 2 6 2 2 6 61 42 6 163 110 8
45855-216 158 10 236 178 12 246 190 14 246 190 14
45856-246 190 14 246 190 14 246 190 14 246 190 14
45857-246 190 14 246 190 14 246 190 14 246 190 14
45858-246 190 14 239 182 13 230 174 11 216 158 10
45859-190 142 34 124 112 88 70 70 70 38 38 38
45860- 18 18 18 6 6 6 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 6 6 6 22 22 22
45864- 62 62 62 168 124 44 206 145 10 224 166 10
45865-236 178 12 239 182 13 242 186 14 242 186 14
45866-246 186 14 246 190 14 246 190 14 246 190 14
45867-246 190 14 246 190 14 246 190 14 246 190 14
45868-246 190 14 246 190 14 246 190 14 246 190 14
45869-246 190 14 236 178 12 216 158 10 175 118 6
45870- 80 54 7 2 2 6 6 6 6 30 30 30
45871- 54 54 54 62 62 62 50 50 50 38 38 38
45872- 14 14 14 2 2 6 2 2 6 2 2 6
45873- 2 2 6 2 2 6 2 2 6 2 2 6
45874- 2 2 6 6 6 6 80 54 7 167 114 7
45875-213 154 11 236 178 12 246 190 14 246 190 14
45876-246 190 14 246 190 14 246 190 14 246 190 14
45877-246 190 14 242 186 14 239 182 13 239 182 13
45878-230 174 11 210 150 10 174 135 50 124 112 88
45879- 82 82 82 54 54 54 34 34 34 18 18 18
45880- 6 6 6 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 6 6 6 18 18 18
45884- 50 50 50 158 118 36 192 133 9 200 144 11
45885-216 158 10 219 162 10 224 166 10 226 170 11
45886-230 174 11 236 178 12 239 182 13 239 182 13
45887-242 186 14 246 186 14 246 190 14 246 190 14
45888-246 190 14 246 190 14 246 190 14 246 190 14
45889-246 186 14 230 174 11 210 150 10 163 110 8
45890-104 69 6 10 10 10 2 2 6 2 2 6
45891- 2 2 6 2 2 6 2 2 6 2 2 6
45892- 2 2 6 2 2 6 2 2 6 2 2 6
45893- 2 2 6 2 2 6 2 2 6 2 2 6
45894- 2 2 6 6 6 6 91 60 6 167 114 7
45895-206 145 10 230 174 11 242 186 14 246 190 14
45896-246 190 14 246 190 14 246 186 14 242 186 14
45897-239 182 13 230 174 11 224 166 10 213 154 11
45898-180 133 36 124 112 88 86 86 86 58 58 58
45899- 38 38 38 22 22 22 10 10 10 6 6 6
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 14 14 14
45904- 34 34 34 70 70 70 138 110 50 158 118 36
45905-167 114 7 180 123 7 192 133 9 197 138 11
45906-200 144 11 206 145 10 213 154 11 219 162 10
45907-224 166 10 230 174 11 239 182 13 242 186 14
45908-246 186 14 246 186 14 246 186 14 246 186 14
45909-239 182 13 216 158 10 185 133 11 152 99 6
45910-104 69 6 18 14 6 2 2 6 2 2 6
45911- 2 2 6 2 2 6 2 2 6 2 2 6
45912- 2 2 6 2 2 6 2 2 6 2 2 6
45913- 2 2 6 2 2 6 2 2 6 2 2 6
45914- 2 2 6 6 6 6 80 54 7 152 99 6
45915-192 133 9 219 162 10 236 178 12 239 182 13
45916-246 186 14 242 186 14 239 182 13 236 178 12
45917-224 166 10 206 145 10 192 133 9 154 121 60
45918- 94 94 94 62 62 62 42 42 42 22 22 22
45919- 14 14 14 6 6 6 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 6 6 6
45924- 18 18 18 34 34 34 58 58 58 78 78 78
45925-101 98 89 124 112 88 142 110 46 156 107 11
45926-163 110 8 167 114 7 175 118 6 180 123 7
45927-185 133 11 197 138 11 210 150 10 219 162 10
45928-226 170 11 236 178 12 236 178 12 234 174 13
45929-219 162 10 197 138 11 163 110 8 130 83 6
45930- 91 60 6 10 10 10 2 2 6 2 2 6
45931- 18 18 18 38 38 38 38 38 38 38 38 38
45932- 38 38 38 38 38 38 38 38 38 38 38 38
45933- 38 38 38 38 38 38 26 26 26 2 2 6
45934- 2 2 6 6 6 6 70 47 6 137 92 6
45935-175 118 6 200 144 11 219 162 10 230 174 11
45936-234 174 13 230 174 11 219 162 10 210 150 10
45937-192 133 9 163 110 8 124 112 88 82 82 82
45938- 50 50 50 30 30 30 14 14 14 6 6 6
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- 6 6 6 14 14 14 22 22 22 34 34 34
45945- 42 42 42 58 58 58 74 74 74 86 86 86
45946-101 98 89 122 102 70 130 98 46 121 87 25
45947-137 92 6 152 99 6 163 110 8 180 123 7
45948-185 133 11 197 138 11 206 145 10 200 144 11
45949-180 123 7 156 107 11 130 83 6 104 69 6
45950- 50 34 6 54 54 54 110 110 110 101 98 89
45951- 86 86 86 82 82 82 78 78 78 78 78 78
45952- 78 78 78 78 78 78 78 78 78 78 78 78
45953- 78 78 78 82 82 82 86 86 86 94 94 94
45954-106 106 106 101 101 101 86 66 34 124 80 6
45955-156 107 11 180 123 7 192 133 9 200 144 11
45956-206 145 10 200 144 11 192 133 9 175 118 6
45957-139 102 15 109 106 95 70 70 70 42 42 42
45958- 22 22 22 10 10 10 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 6 6 6 10 10 10
45965- 14 14 14 22 22 22 30 30 30 38 38 38
45966- 50 50 50 62 62 62 74 74 74 90 90 90
45967-101 98 89 112 100 78 121 87 25 124 80 6
45968-137 92 6 152 99 6 152 99 6 152 99 6
45969-138 86 6 124 80 6 98 70 6 86 66 30
45970-101 98 89 82 82 82 58 58 58 46 46 46
45971- 38 38 38 34 34 34 34 34 34 34 34 34
45972- 34 34 34 34 34 34 34 34 34 34 34 34
45973- 34 34 34 34 34 34 38 38 38 42 42 42
45974- 54 54 54 82 82 82 94 86 76 91 60 6
45975-134 86 6 156 107 11 167 114 7 175 118 6
45976-175 118 6 167 114 7 152 99 6 121 87 25
45977-101 98 89 62 62 62 34 34 34 18 18 18
45978- 6 6 6 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 0 0 0
45985- 0 0 0 6 6 6 6 6 6 10 10 10
45986- 18 18 18 22 22 22 30 30 30 42 42 42
45987- 50 50 50 66 66 66 86 86 86 101 98 89
45988-106 86 58 98 70 6 104 69 6 104 69 6
45989-104 69 6 91 60 6 82 62 34 90 90 90
45990- 62 62 62 38 38 38 22 22 22 14 14 14
45991- 10 10 10 10 10 10 10 10 10 10 10 10
45992- 10 10 10 10 10 10 6 6 6 10 10 10
45993- 10 10 10 10 10 10 10 10 10 14 14 14
45994- 22 22 22 42 42 42 70 70 70 89 81 66
45995- 80 54 7 104 69 6 124 80 6 137 92 6
45996-134 86 6 116 81 8 100 82 52 86 86 86
45997- 58 58 58 30 30 30 14 14 14 6 6 6
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 0 0 0
46005- 0 0 0 0 0 0 0 0 0 0 0 0
46006- 0 0 0 6 6 6 10 10 10 14 14 14
46007- 18 18 18 26 26 26 38 38 38 54 54 54
46008- 70 70 70 86 86 86 94 86 76 89 81 66
46009- 89 81 66 86 86 86 74 74 74 50 50 50
46010- 30 30 30 14 14 14 6 6 6 0 0 0
46011- 0 0 0 0 0 0 0 0 0 0 0 0
46012- 0 0 0 0 0 0 0 0 0 0 0 0
46013- 0 0 0 0 0 0 0 0 0 0 0 0
46014- 6 6 6 18 18 18 34 34 34 58 58 58
46015- 82 82 82 89 81 66 89 81 66 89 81 66
46016- 94 86 66 94 86 76 74 74 74 50 50 50
46017- 26 26 26 14 14 14 6 6 6 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 0 0 0 0 0 0
46025- 0 0 0 0 0 0 0 0 0 0 0 0
46026- 0 0 0 0 0 0 0 0 0 0 0 0
46027- 6 6 6 6 6 6 14 14 14 18 18 18
46028- 30 30 30 38 38 38 46 46 46 54 54 54
46029- 50 50 50 42 42 42 30 30 30 18 18 18
46030- 10 10 10 0 0 0 0 0 0 0 0 0
46031- 0 0 0 0 0 0 0 0 0 0 0 0
46032- 0 0 0 0 0 0 0 0 0 0 0 0
46033- 0 0 0 0 0 0 0 0 0 0 0 0
46034- 0 0 0 6 6 6 14 14 14 26 26 26
46035- 38 38 38 50 50 50 58 58 58 58 58 58
46036- 54 54 54 42 42 42 30 30 30 18 18 18
46037- 10 10 10 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 0 0 0 0 0 0
46045- 0 0 0 0 0 0 0 0 0 0 0 0
46046- 0 0 0 0 0 0 0 0 0 0 0 0
46047- 0 0 0 0 0 0 0 0 0 6 6 6
46048- 6 6 6 10 10 10 14 14 14 18 18 18
46049- 18 18 18 14 14 14 10 10 10 6 6 6
46050- 0 0 0 0 0 0 0 0 0 0 0 0
46051- 0 0 0 0 0 0 0 0 0 0 0 0
46052- 0 0 0 0 0 0 0 0 0 0 0 0
46053- 0 0 0 0 0 0 0 0 0 0 0 0
46054- 0 0 0 0 0 0 0 0 0 6 6 6
46055- 14 14 14 18 18 18 22 22 22 22 22 22
46056- 18 18 18 14 14 14 10 10 10 6 6 6
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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46063+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46064+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46066+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46075+4 4 4 4 4 4
46076+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46077+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46078+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46080+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46083+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46088+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46089+4 4 4 4 4 4
46090+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46091+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46092+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46093+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46094+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46097+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46099+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46102+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46103+4 4 4 4 4 4
46104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46105+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46106+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46111+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46116+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46117+4 4 4 4 4 4
46118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46119+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46120+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46125+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46126+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46127+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46130+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46131+4 4 4 4 4 4
46132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46133+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46134+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46139+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46144+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46145+4 4 4 4 4 4
46146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46148+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46150+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
46151+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
46152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46155+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
46156+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46157+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
46158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46159+4 4 4 4 4 4
46160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46161+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46162+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46164+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
46165+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
46166+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46167+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46169+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
46170+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
46171+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
46172+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46173+4 4 4 4 4 4
46174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46175+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46178+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
46179+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
46180+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46181+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46183+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
46184+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
46185+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
46186+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
46187+4 4 4 4 4 4
46188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46189+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46191+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
46192+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
46193+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
46194+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
46195+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46196+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46197+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
46198+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
46199+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
46200+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
46201+4 4 4 4 4 4
46202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46205+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
46206+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
46207+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
46208+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
46209+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46210+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
46211+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
46212+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
46213+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
46214+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
46215+4 4 4 4 4 4
46216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46219+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
46220+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
46221+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
46222+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
46223+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46224+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
46225+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
46226+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
46227+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
46228+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
46229+4 4 4 4 4 4
46230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46232+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
46233+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
46234+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
46235+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
46236+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
46237+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
46238+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
46239+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
46240+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
46241+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
46242+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
46243+4 4 4 4 4 4
46244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46246+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
46247+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
46248+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
46249+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
46250+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
46251+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
46252+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
46253+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
46254+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
46255+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
46256+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
46257+4 4 4 4 4 4
46258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46260+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
46261+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
46262+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
46263+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
46264+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
46265+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
46266+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
46267+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
46268+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
46269+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
46270+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46271+4 4 4 4 4 4
46272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46274+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
46275+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
46276+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
46277+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
46278+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
46279+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
46280+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
46281+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
46282+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
46283+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
46284+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
46285+4 4 4 4 4 4
46286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46287+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
46288+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
46289+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
46290+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
46291+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
46292+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
46293+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
46294+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
46295+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
46296+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
46297+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
46298+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
46299+4 4 4 4 4 4
46300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46301+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
46302+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
46303+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
46304+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
46305+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
46306+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
46307+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
46308+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
46309+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
46310+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
46311+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
46312+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
46313+0 0 0 4 4 4
46314+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46315+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
46316+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
46317+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
46318+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
46319+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
46320+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
46321+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
46322+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
46323+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
46324+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
46325+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
46326+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
46327+2 0 0 0 0 0
46328+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
46329+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
46330+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
46331+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
46332+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
46333+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
46334+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
46335+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
46336+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
46337+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
46338+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
46339+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
46340+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
46341+37 38 37 0 0 0
46342+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
46343+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
46344+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
46345+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
46346+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
46347+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
46348+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
46349+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
46350+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
46351+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
46352+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
46353+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
46354+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
46355+85 115 134 4 0 0
46356+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
46357+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
46358+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
46359+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
46360+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
46361+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
46362+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
46363+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
46364+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
46365+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
46366+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
46367+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
46368+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
46369+60 73 81 4 0 0
46370+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
46371+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
46372+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
46373+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
46374+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
46375+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
46376+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
46377+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
46378+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
46379+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
46380+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
46381+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
46382+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
46383+16 19 21 4 0 0
46384+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
46385+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
46386+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
46387+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
46388+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
46389+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
46390+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
46391+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
46392+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
46393+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
46394+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
46395+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
46396+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
46397+4 0 0 4 3 3
46398+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
46399+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
46400+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
46401+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
46402+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
46403+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
46404+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
46405+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
46406+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
46407+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
46408+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
46409+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
46410+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
46411+3 2 2 4 4 4
46412+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
46413+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
46414+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
46415+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
46416+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
46417+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
46418+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
46419+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
46420+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
46421+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
46422+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
46423+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
46424+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
46425+4 4 4 4 4 4
46426+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
46427+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
46428+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
46429+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
46430+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
46431+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
46432+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
46433+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
46434+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
46435+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
46436+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
46437+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
46438+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
46439+4 4 4 4 4 4
46440+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
46441+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
46442+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
46443+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
46444+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
46445+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
46446+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
46447+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
46448+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
46449+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
46450+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
46451+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
46452+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
46453+5 5 5 5 5 5
46454+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
46455+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
46456+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
46457+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
46458+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
46459+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46460+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
46461+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
46462+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
46463+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
46464+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
46465+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
46466+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
46467+5 5 5 4 4 4
46468+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
46469+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
46470+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
46471+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
46472+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46473+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
46474+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
46475+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
46476+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
46477+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
46478+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
46479+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
46480+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46481+4 4 4 4 4 4
46482+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
46483+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
46484+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
46485+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
46486+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
46487+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46488+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46489+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
46490+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
46491+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
46492+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
46493+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
46494+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46495+4 4 4 4 4 4
46496+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
46497+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
46498+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
46499+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
46500+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46501+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
46502+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
46503+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
46504+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
46505+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
46506+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
46507+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46508+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46509+4 4 4 4 4 4
46510+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
46511+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
46512+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
46513+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
46514+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46515+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46516+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46517+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
46518+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
46519+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
46520+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
46521+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46522+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46523+4 4 4 4 4 4
46524+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
46525+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
46526+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
46527+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
46528+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46529+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
46530+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
46531+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
46532+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
46533+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
46534+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46535+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46536+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46537+4 4 4 4 4 4
46538+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
46539+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
46540+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
46541+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
46542+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46543+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
46544+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
46545+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
46546+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
46547+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
46548+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
46549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46551+4 4 4 4 4 4
46552+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
46553+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
46554+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
46555+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
46556+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46557+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
46558+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
46559+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
46560+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
46561+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
46562+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
46563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46564+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46565+4 4 4 4 4 4
46566+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
46567+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
46568+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
46569+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
46570+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
46571+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
46572+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
46573+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
46574+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
46575+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
46576+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46579+4 4 4 4 4 4
46580+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
46581+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
46582+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
46583+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46584+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46585+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
46586+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
46587+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
46588+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
46589+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
46590+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46593+4 4 4 4 4 4
46594+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
46595+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
46596+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46597+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
46598+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46599+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
46600+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
46601+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
46602+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
46603+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
46604+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46607+4 4 4 4 4 4
46608+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
46609+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
46610+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46611+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46612+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46613+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
46614+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
46615+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
46616+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46617+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46618+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46621+4 4 4 4 4 4
46622+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46623+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
46624+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46625+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
46626+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
46627+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
46628+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
46629+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
46630+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46631+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46632+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46635+4 4 4 4 4 4
46636+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46637+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
46638+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46639+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
46640+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46641+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
46642+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
46643+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
46644+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46645+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46646+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46649+4 4 4 4 4 4
46650+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
46651+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
46652+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46653+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
46654+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
46655+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
46656+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
46657+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
46658+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46659+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46660+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46663+4 4 4 4 4 4
46664+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
46665+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
46666+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46667+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
46668+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
46669+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
46670+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
46671+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
46672+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46673+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46674+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46677+4 4 4 4 4 4
46678+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46679+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
46680+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46681+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
46682+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
46683+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
46684+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
46685+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
46686+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46687+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46688+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46691+4 4 4 4 4 4
46692+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
46693+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
46694+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46695+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
46696+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
46697+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
46698+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
46699+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
46700+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
46701+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46702+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46705+4 4 4 4 4 4
46706+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46707+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
46708+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
46709+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
46710+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
46711+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
46712+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
46713+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
46714+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46715+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46716+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46719+4 4 4 4 4 4
46720+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46721+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
46722+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46723+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
46724+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
46725+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
46726+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
46727+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
46728+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46729+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46730+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46733+4 4 4 4 4 4
46734+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46735+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
46736+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
46737+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
46738+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
46739+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
46740+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46741+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
46742+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46743+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46744+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46747+4 4 4 4 4 4
46748+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46749+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
46750+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
46751+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46752+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
46753+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
46754+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46755+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
46756+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46757+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46758+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46761+4 4 4 4 4 4
46762+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46763+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
46764+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
46765+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
46766+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
46767+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
46768+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
46769+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
46770+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
46771+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46772+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46775+4 4 4 4 4 4
46776+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46777+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
46778+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
46779+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
46780+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
46781+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
46782+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
46783+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
46784+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
46785+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46786+0 0 0 3 3 3 5 5 5 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
46790+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
46791+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
46792+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
46793+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
46794+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46795+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
46796+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
46797+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
46798+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
46799+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46800+0 0 0 3 3 3 5 5 5 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
46804+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46805+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
46806+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
46807+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
46808+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
46809+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
46810+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
46811+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
46812+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
46813+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46814+0 0 0 3 3 3 5 5 5 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
46818+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
46819+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
46820+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
46821+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
46822+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
46823+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
46824+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
46825+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
46826+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
46827+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
46828+0 0 0 3 3 3 5 5 5 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
46832+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
46833+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
46834+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
46835+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
46836+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
46837+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
46838+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
46839+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
46840+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
46841+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
46842+0 0 0 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
46846+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
46847+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
46848+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
46849+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
46850+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
46851+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
46852+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46853+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
46854+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
46855+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
46856+4 3 3 5 5 5 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
46860+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
46861+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
46862+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
46863+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
46864+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
46865+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
46866+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
46867+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
46868+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
46869+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
46870+5 5 5 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
46874+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
46875+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
46876+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
46877+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
46878+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
46879+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
46880+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
46881+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
46882+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
46883+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
46884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46887+4 4 4 4 4 4
46888+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46889+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
46890+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
46891+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
46892+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
46893+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
46894+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
46895+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
46896+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
46897+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
46898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46901+4 4 4 4 4 4
46902+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
46903+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
46904+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
46905+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
46906+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
46907+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
46908+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
46909+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
46910+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
46911+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
46912+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46914+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46915+4 4 4 4 4 4
46916+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
46917+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
46918+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
46919+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
46920+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
46921+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
46922+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
46923+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
46924+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
46925+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46926+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46928+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46929+4 4 4 4 4 4
46930+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
46931+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46932+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
46933+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
46934+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
46935+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
46936+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
46937+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
46938+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
46939+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46941+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46942+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46943+4 4 4 4 4 4
46944+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
46945+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
46946+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
46947+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
46948+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
46949+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
46950+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
46951+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
46952+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
46953+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46954+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46955+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46956+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46957+4 4 4 4 4 4
46958+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
46959+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
46960+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
46961+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
46962+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
46963+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
46964+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
46965+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
46966+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46967+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46968+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46969+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46970+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46971+4 4 4 4 4 4
46972+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
46973+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
46974+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
46975+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
46976+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
46977+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
46978+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
46979+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
46980+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46981+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46984+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46985+4 4 4 4 4 4
46986+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
46987+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
46988+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
46989+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
46990+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
46991+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
46992+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
46993+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
46994+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46995+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46999+4 4 4 4 4 4
47000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47001+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
47002+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47003+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
47004+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
47005+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
47006+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
47007+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
47008+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47013+4 4 4 4 4 4
47014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47015+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
47016+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
47017+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
47018+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
47019+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
47020+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
47021+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
47022+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47023+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47027+4 4 4 4 4 4
47028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47029+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47030+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
47031+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47032+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
47033+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
47034+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
47035+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47036+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47037+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47041+4 4 4 4 4 4
47042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47044+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47045+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
47046+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
47047+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
47048+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
47049+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47050+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47052+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47055+4 4 4 4 4 4
47056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47059+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47060+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
47061+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
47062+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
47063+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47064+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47066+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47069+4 4 4 4 4 4
47070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47073+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47074+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47075+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
47076+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
47077+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47078+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47080+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47083+4 4 4 4 4 4
47084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47087+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47088+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47089+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47090+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
47091+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47092+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47093+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47094+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47097+4 4 4 4 4 4
47098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47099+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47101+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
47102+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
47103+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
47104+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
47105+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47106+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47111+4 4 4 4 4 4
47112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47116+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
47117+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47118+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47119+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47120+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47125+4 4 4 4 4 4
47126+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47127+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47130+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
47131+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
47132+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
47133+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47134+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47139+4 4 4 4 4 4
47140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47144+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
47145+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
47146+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47148+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47153+4 4 4 4 4 4
47154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47158+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
47159+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
47160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47161+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47162+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47167+4 4 4 4 4 4
47168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47172+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47173+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
47174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47175+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47181+4 4 4 4 4 4
47182diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
47183index fe92eed..106e085 100644
47184--- a/drivers/video/mb862xx/mb862xxfb_accel.c
47185+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
47186@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
47187 struct mb862xxfb_par *par = info->par;
47188
47189 if (info->var.bits_per_pixel == 32) {
47190- info->fbops->fb_fillrect = cfb_fillrect;
47191- info->fbops->fb_copyarea = cfb_copyarea;
47192- info->fbops->fb_imageblit = cfb_imageblit;
47193+ pax_open_kernel();
47194+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47195+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47196+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47197+ pax_close_kernel();
47198 } else {
47199 outreg(disp, GC_L0EM, 3);
47200- info->fbops->fb_fillrect = mb86290fb_fillrect;
47201- info->fbops->fb_copyarea = mb86290fb_copyarea;
47202- info->fbops->fb_imageblit = mb86290fb_imageblit;
47203+ pax_open_kernel();
47204+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
47205+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
47206+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
47207+ pax_close_kernel();
47208 }
47209 outreg(draw, GDC_REG_DRAW_BASE, 0);
47210 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
47211diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
47212index ff22871..b129bed 100644
47213--- a/drivers/video/nvidia/nvidia.c
47214+++ b/drivers/video/nvidia/nvidia.c
47215@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
47216 info->fix.line_length = (info->var.xres_virtual *
47217 info->var.bits_per_pixel) >> 3;
47218 if (info->var.accel_flags) {
47219- info->fbops->fb_imageblit = nvidiafb_imageblit;
47220- info->fbops->fb_fillrect = nvidiafb_fillrect;
47221- info->fbops->fb_copyarea = nvidiafb_copyarea;
47222- info->fbops->fb_sync = nvidiafb_sync;
47223+ pax_open_kernel();
47224+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
47225+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
47226+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
47227+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
47228+ pax_close_kernel();
47229 info->pixmap.scan_align = 4;
47230 info->flags &= ~FBINFO_HWACCEL_DISABLED;
47231 info->flags |= FBINFO_READS_FAST;
47232 NVResetGraphics(info);
47233 } else {
47234- info->fbops->fb_imageblit = cfb_imageblit;
47235- info->fbops->fb_fillrect = cfb_fillrect;
47236- info->fbops->fb_copyarea = cfb_copyarea;
47237- info->fbops->fb_sync = NULL;
47238+ pax_open_kernel();
47239+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47240+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47241+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47242+ *(void **)&info->fbops->fb_sync = NULL;
47243+ pax_close_kernel();
47244 info->pixmap.scan_align = 1;
47245 info->flags |= FBINFO_HWACCEL_DISABLED;
47246 info->flags &= ~FBINFO_READS_FAST;
47247@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
47248 info->pixmap.size = 8 * 1024;
47249 info->pixmap.flags = FB_PIXMAP_SYSTEM;
47250
47251- if (!hwcur)
47252- info->fbops->fb_cursor = NULL;
47253+ if (!hwcur) {
47254+ pax_open_kernel();
47255+ *(void **)&info->fbops->fb_cursor = NULL;
47256+ pax_close_kernel();
47257+ }
47258
47259 info->var.accel_flags = (!noaccel);
47260
47261diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
47262index 76d9053..dec2bfd 100644
47263--- a/drivers/video/s1d13xxxfb.c
47264+++ b/drivers/video/s1d13xxxfb.c
47265@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
47266
47267 switch(prod_id) {
47268 case S1D13506_PROD_ID: /* activate acceleration */
47269- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47270- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47271+ pax_open_kernel();
47272+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47273+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47274+ pax_close_kernel();
47275 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
47276 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
47277 break;
47278diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
47279index 97bd662..39fab85 100644
47280--- a/drivers/video/smscufx.c
47281+++ b/drivers/video/smscufx.c
47282@@ -1171,7 +1171,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
47283 fb_deferred_io_cleanup(info);
47284 kfree(info->fbdefio);
47285 info->fbdefio = NULL;
47286- info->fbops->fb_mmap = ufx_ops_mmap;
47287+ pax_open_kernel();
47288+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
47289+ pax_close_kernel();
47290 }
47291
47292 pr_debug("released /dev/fb%d user=%d count=%d",
47293diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
47294index 86d449e..8e04dc5 100644
47295--- a/drivers/video/udlfb.c
47296+++ b/drivers/video/udlfb.c
47297@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
47298 dlfb_urb_completion(urb);
47299
47300 error:
47301- atomic_add(bytes_sent, &dev->bytes_sent);
47302- atomic_add(bytes_identical, &dev->bytes_identical);
47303- atomic_add(width*height*2, &dev->bytes_rendered);
47304+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47305+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47306+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
47307 end_cycles = get_cycles();
47308- atomic_add(((unsigned int) ((end_cycles - start_cycles)
47309+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
47310 >> 10)), /* Kcycles */
47311 &dev->cpu_kcycles_used);
47312
47313@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
47314 dlfb_urb_completion(urb);
47315
47316 error:
47317- atomic_add(bytes_sent, &dev->bytes_sent);
47318- atomic_add(bytes_identical, &dev->bytes_identical);
47319- atomic_add(bytes_rendered, &dev->bytes_rendered);
47320+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47321+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47322+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
47323 end_cycles = get_cycles();
47324- atomic_add(((unsigned int) ((end_cycles - start_cycles)
47325+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
47326 >> 10)), /* Kcycles */
47327 &dev->cpu_kcycles_used);
47328 }
47329@@ -989,7 +989,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
47330 fb_deferred_io_cleanup(info);
47331 kfree(info->fbdefio);
47332 info->fbdefio = NULL;
47333- info->fbops->fb_mmap = dlfb_ops_mmap;
47334+ pax_open_kernel();
47335+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
47336+ pax_close_kernel();
47337 }
47338
47339 pr_warn("released /dev/fb%d user=%d count=%d\n",
47340@@ -1372,7 +1374,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
47341 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47342 struct dlfb_data *dev = fb_info->par;
47343 return snprintf(buf, PAGE_SIZE, "%u\n",
47344- atomic_read(&dev->bytes_rendered));
47345+ atomic_read_unchecked(&dev->bytes_rendered));
47346 }
47347
47348 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
47349@@ -1380,7 +1382,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
47350 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47351 struct dlfb_data *dev = fb_info->par;
47352 return snprintf(buf, PAGE_SIZE, "%u\n",
47353- atomic_read(&dev->bytes_identical));
47354+ atomic_read_unchecked(&dev->bytes_identical));
47355 }
47356
47357 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
47358@@ -1388,7 +1390,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
47359 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47360 struct dlfb_data *dev = fb_info->par;
47361 return snprintf(buf, PAGE_SIZE, "%u\n",
47362- atomic_read(&dev->bytes_sent));
47363+ atomic_read_unchecked(&dev->bytes_sent));
47364 }
47365
47366 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
47367@@ -1396,7 +1398,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
47368 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47369 struct dlfb_data *dev = fb_info->par;
47370 return snprintf(buf, PAGE_SIZE, "%u\n",
47371- atomic_read(&dev->cpu_kcycles_used));
47372+ atomic_read_unchecked(&dev->cpu_kcycles_used));
47373 }
47374
47375 static ssize_t edid_show(
47376@@ -1456,10 +1458,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
47377 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47378 struct dlfb_data *dev = fb_info->par;
47379
47380- atomic_set(&dev->bytes_rendered, 0);
47381- atomic_set(&dev->bytes_identical, 0);
47382- atomic_set(&dev->bytes_sent, 0);
47383- atomic_set(&dev->cpu_kcycles_used, 0);
47384+ atomic_set_unchecked(&dev->bytes_rendered, 0);
47385+ atomic_set_unchecked(&dev->bytes_identical, 0);
47386+ atomic_set_unchecked(&dev->bytes_sent, 0);
47387+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
47388
47389 return count;
47390 }
47391diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
47392index b75db01..ad2f34a 100644
47393--- a/drivers/video/uvesafb.c
47394+++ b/drivers/video/uvesafb.c
47395@@ -19,6 +19,7 @@
47396 #include <linux/io.h>
47397 #include <linux/mutex.h>
47398 #include <linux/slab.h>
47399+#include <linux/moduleloader.h>
47400 #include <video/edid.h>
47401 #include <video/uvesafb.h>
47402 #ifdef CONFIG_X86
47403@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
47404 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
47405 par->pmi_setpal = par->ypan = 0;
47406 } else {
47407+
47408+#ifdef CONFIG_PAX_KERNEXEC
47409+#ifdef CONFIG_MODULES
47410+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
47411+#endif
47412+ if (!par->pmi_code) {
47413+ par->pmi_setpal = par->ypan = 0;
47414+ return 0;
47415+ }
47416+#endif
47417+
47418 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
47419 + task->t.regs.edi);
47420+
47421+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47422+ pax_open_kernel();
47423+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
47424+ pax_close_kernel();
47425+
47426+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
47427+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
47428+#else
47429 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
47430 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
47431+#endif
47432+
47433 printk(KERN_INFO "uvesafb: protected mode interface info at "
47434 "%04x:%04x\n",
47435 (u16)task->t.regs.es, (u16)task->t.regs.edi);
47436@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
47437 par->ypan = ypan;
47438
47439 if (par->pmi_setpal || par->ypan) {
47440+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
47441 if (__supported_pte_mask & _PAGE_NX) {
47442 par->pmi_setpal = par->ypan = 0;
47443 printk(KERN_WARNING "uvesafb: NX protection is actively."
47444 "We have better not to use the PMI.\n");
47445- } else {
47446+ } else
47447+#endif
47448 uvesafb_vbe_getpmi(task, par);
47449- }
47450 }
47451 #else
47452 /* The protected mode interface is not available on non-x86. */
47453@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
47454 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
47455
47456 /* Disable blanking if the user requested so. */
47457- if (!blank)
47458- info->fbops->fb_blank = NULL;
47459+ if (!blank) {
47460+ pax_open_kernel();
47461+ *(void **)&info->fbops->fb_blank = NULL;
47462+ pax_close_kernel();
47463+ }
47464
47465 /*
47466 * Find out how much IO memory is required for the mode with
47467@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
47468 info->flags = FBINFO_FLAG_DEFAULT |
47469 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
47470
47471- if (!par->ypan)
47472- info->fbops->fb_pan_display = NULL;
47473+ if (!par->ypan) {
47474+ pax_open_kernel();
47475+ *(void **)&info->fbops->fb_pan_display = NULL;
47476+ pax_close_kernel();
47477+ }
47478 }
47479
47480 static void uvesafb_init_mtrr(struct fb_info *info)
47481@@ -1836,6 +1866,11 @@ out:
47482 if (par->vbe_modes)
47483 kfree(par->vbe_modes);
47484
47485+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47486+ if (par->pmi_code)
47487+ module_free_exec(NULL, par->pmi_code);
47488+#endif
47489+
47490 framebuffer_release(info);
47491 return err;
47492 }
47493@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
47494 kfree(par->vbe_state_orig);
47495 if (par->vbe_state_saved)
47496 kfree(par->vbe_state_saved);
47497+
47498+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47499+ if (par->pmi_code)
47500+ module_free_exec(NULL, par->pmi_code);
47501+#endif
47502+
47503 }
47504
47505 framebuffer_release(info);
47506diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
47507index 501b340..d80aa17 100644
47508--- a/drivers/video/vesafb.c
47509+++ b/drivers/video/vesafb.c
47510@@ -9,6 +9,7 @@
47511 */
47512
47513 #include <linux/module.h>
47514+#include <linux/moduleloader.h>
47515 #include <linux/kernel.h>
47516 #include <linux/errno.h>
47517 #include <linux/string.h>
47518@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
47519 static int vram_total __initdata; /* Set total amount of memory */
47520 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
47521 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
47522-static void (*pmi_start)(void) __read_mostly;
47523-static void (*pmi_pal) (void) __read_mostly;
47524+static void (*pmi_start)(void) __read_only;
47525+static void (*pmi_pal) (void) __read_only;
47526 static int depth __read_mostly;
47527 static int vga_compat __read_mostly;
47528 /* --------------------------------------------------------------------- */
47529@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
47530 unsigned int size_vmode;
47531 unsigned int size_remap;
47532 unsigned int size_total;
47533+ void *pmi_code = NULL;
47534
47535 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
47536 return -ENODEV;
47537@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
47538 size_remap = size_total;
47539 vesafb_fix.smem_len = size_remap;
47540
47541-#ifndef __i386__
47542- screen_info.vesapm_seg = 0;
47543-#endif
47544-
47545 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
47546 printk(KERN_WARNING
47547 "vesafb: cannot reserve video memory at 0x%lx\n",
47548@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
47549 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
47550 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
47551
47552+#ifdef __i386__
47553+
47554+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47555+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
47556+ if (!pmi_code)
47557+#elif !defined(CONFIG_PAX_KERNEXEC)
47558+ if (0)
47559+#endif
47560+
47561+#endif
47562+ screen_info.vesapm_seg = 0;
47563+
47564 if (screen_info.vesapm_seg) {
47565- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
47566- screen_info.vesapm_seg,screen_info.vesapm_off);
47567+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
47568+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
47569 }
47570
47571 if (screen_info.vesapm_seg < 0xc000)
47572@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
47573
47574 if (ypan || pmi_setpal) {
47575 unsigned short *pmi_base;
47576+
47577 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
47578- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
47579- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
47580+
47581+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47582+ pax_open_kernel();
47583+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
47584+#else
47585+ pmi_code = pmi_base;
47586+#endif
47587+
47588+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
47589+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
47590+
47591+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47592+ pmi_start = ktva_ktla(pmi_start);
47593+ pmi_pal = ktva_ktla(pmi_pal);
47594+ pax_close_kernel();
47595+#endif
47596+
47597 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
47598 if (pmi_base[3]) {
47599 printk(KERN_INFO "vesafb: pmi: ports = ");
47600@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47601 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
47602 (ypan ? FBINFO_HWACCEL_YPAN : 0);
47603
47604- if (!ypan)
47605- info->fbops->fb_pan_display = NULL;
47606+ if (!ypan) {
47607+ pax_open_kernel();
47608+ *(void **)&info->fbops->fb_pan_display = NULL;
47609+ pax_close_kernel();
47610+ }
47611
47612 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
47613 err = -ENOMEM;
47614@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47615 info->node, info->fix.id);
47616 return 0;
47617 err:
47618+
47619+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47620+ module_free_exec(NULL, pmi_code);
47621+#endif
47622+
47623 if (info->screen_base)
47624 iounmap(info->screen_base);
47625 framebuffer_release(info);
47626diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
47627index 88714ae..16c2e11 100644
47628--- a/drivers/video/via/via_clock.h
47629+++ b/drivers/video/via/via_clock.h
47630@@ -56,7 +56,7 @@ struct via_clock {
47631
47632 void (*set_engine_pll_state)(u8 state);
47633 void (*set_engine_pll)(struct via_pll_config config);
47634-};
47635+} __no_const;
47636
47637
47638 static inline u32 get_pll_internal_frequency(u32 ref_freq,
47639diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
47640index fef20db..d28b1ab 100644
47641--- a/drivers/xen/xenfs/xenstored.c
47642+++ b/drivers/xen/xenfs/xenstored.c
47643@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
47644 static int xsd_kva_open(struct inode *inode, struct file *file)
47645 {
47646 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
47647+#ifdef CONFIG_GRKERNSEC_HIDESYM
47648+ NULL);
47649+#else
47650 xen_store_interface);
47651+#endif
47652+
47653 if (!file->private_data)
47654 return -ENOMEM;
47655 return 0;
47656diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
47657index 890bed5..17ae73e 100644
47658--- a/fs/9p/vfs_inode.c
47659+++ b/fs/9p/vfs_inode.c
47660@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
47661 void
47662 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47663 {
47664- char *s = nd_get_link(nd);
47665+ const char *s = nd_get_link(nd);
47666
47667 p9_debug(P9_DEBUG_VFS, " %s %s\n",
47668 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
47669diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
47670index 0efd152..b5802ad 100644
47671--- a/fs/Kconfig.binfmt
47672+++ b/fs/Kconfig.binfmt
47673@@ -89,7 +89,7 @@ config HAVE_AOUT
47674
47675 config BINFMT_AOUT
47676 tristate "Kernel support for a.out and ECOFF binaries"
47677- depends on HAVE_AOUT
47678+ depends on HAVE_AOUT && BROKEN
47679 ---help---
47680 A.out (Assembler.OUTput) is a set of formats for libraries and
47681 executables used in the earliest versions of UNIX. Linux used
47682diff --git a/fs/aio.c b/fs/aio.c
47683index 71f613c..9d01f1f 100644
47684--- a/fs/aio.c
47685+++ b/fs/aio.c
47686@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
47687 size += sizeof(struct io_event) * nr_events;
47688 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
47689
47690- if (nr_pages < 0)
47691+ if (nr_pages <= 0)
47692 return -EINVAL;
47693
47694 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
47695@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
47696 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47697 {
47698 ssize_t ret;
47699+ struct iovec iovstack;
47700
47701 #ifdef CONFIG_COMPAT
47702 if (compat)
47703 ret = compat_rw_copy_check_uvector(type,
47704 (struct compat_iovec __user *)kiocb->ki_buf,
47705- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47706+ kiocb->ki_nbytes, 1, &iovstack,
47707 &kiocb->ki_iovec);
47708 else
47709 #endif
47710 ret = rw_copy_check_uvector(type,
47711 (struct iovec __user *)kiocb->ki_buf,
47712- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47713+ kiocb->ki_nbytes, 1, &iovstack,
47714 &kiocb->ki_iovec);
47715 if (ret < 0)
47716 goto out;
47717@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47718 if (ret < 0)
47719 goto out;
47720
47721+ if (kiocb->ki_iovec == &iovstack) {
47722+ kiocb->ki_inline_vec = iovstack;
47723+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
47724+ }
47725 kiocb->ki_nr_segs = kiocb->ki_nbytes;
47726 kiocb->ki_cur_seg = 0;
47727 /* ki_nbytes/left now reflect bytes instead of segs */
47728diff --git a/fs/attr.c b/fs/attr.c
47729index 1449adb..a2038c2 100644
47730--- a/fs/attr.c
47731+++ b/fs/attr.c
47732@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
47733 unsigned long limit;
47734
47735 limit = rlimit(RLIMIT_FSIZE);
47736+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
47737 if (limit != RLIM_INFINITY && offset > limit)
47738 goto out_sig;
47739 if (offset > inode->i_sb->s_maxbytes)
47740diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
47741index 03bc1d3..6205356 100644
47742--- a/fs/autofs4/waitq.c
47743+++ b/fs/autofs4/waitq.c
47744@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
47745 {
47746 unsigned long sigpipe, flags;
47747 mm_segment_t fs;
47748- const char *data = (const char *)addr;
47749+ const char __user *data = (const char __force_user *)addr;
47750 ssize_t wr = 0;
47751
47752 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
47753@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
47754 return 1;
47755 }
47756
47757+#ifdef CONFIG_GRKERNSEC_HIDESYM
47758+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
47759+#endif
47760+
47761 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47762 enum autofs_notify notify)
47763 {
47764@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47765
47766 /* If this is a direct mount request create a dummy name */
47767 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
47768+#ifdef CONFIG_GRKERNSEC_HIDESYM
47769+ /* this name does get written to userland via autofs4_write() */
47770+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
47771+#else
47772 qstr.len = sprintf(name, "%p", dentry);
47773+#endif
47774 else {
47775 qstr.len = autofs4_getpath(sbi, dentry, &name);
47776 if (!qstr.len) {
47777diff --git a/fs/befs/endian.h b/fs/befs/endian.h
47778index 2722387..c8dd2a7 100644
47779--- a/fs/befs/endian.h
47780+++ b/fs/befs/endian.h
47781@@ -11,7 +11,7 @@
47782
47783 #include <asm/byteorder.h>
47784
47785-static inline u64
47786+static inline u64 __intentional_overflow(-1)
47787 fs64_to_cpu(const struct super_block *sb, fs64 n)
47788 {
47789 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
47790@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
47791 return (__force fs64)cpu_to_be64(n);
47792 }
47793
47794-static inline u32
47795+static inline u32 __intentional_overflow(-1)
47796 fs32_to_cpu(const struct super_block *sb, fs32 n)
47797 {
47798 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
47799diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
47800index 2b3bda8..6a2d4be 100644
47801--- a/fs/befs/linuxvfs.c
47802+++ b/fs/befs/linuxvfs.c
47803@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47804 {
47805 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
47806 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
47807- char *link = nd_get_link(nd);
47808+ const char *link = nd_get_link(nd);
47809 if (!IS_ERR(link))
47810 kfree(link);
47811 }
47812diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
47813index 6043567..16a9239 100644
47814--- a/fs/binfmt_aout.c
47815+++ b/fs/binfmt_aout.c
47816@@ -16,6 +16,7 @@
47817 #include <linux/string.h>
47818 #include <linux/fs.h>
47819 #include <linux/file.h>
47820+#include <linux/security.h>
47821 #include <linux/stat.h>
47822 #include <linux/fcntl.h>
47823 #include <linux/ptrace.h>
47824@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
47825 #endif
47826 # define START_STACK(u) ((void __user *)u.start_stack)
47827
47828+ memset(&dump, 0, sizeof(dump));
47829+
47830 fs = get_fs();
47831 set_fs(KERNEL_DS);
47832 has_dumped = 1;
47833@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
47834
47835 /* If the size of the dump file exceeds the rlimit, then see what would happen
47836 if we wrote the stack, but not the data area. */
47837+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
47838 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
47839 dump.u_dsize = 0;
47840
47841 /* Make sure we have enough room to write the stack and data areas. */
47842+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
47843 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
47844 dump.u_ssize = 0;
47845
47846@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
47847 rlim = rlimit(RLIMIT_DATA);
47848 if (rlim >= RLIM_INFINITY)
47849 rlim = ~0;
47850+
47851+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
47852 if (ex.a_data + ex.a_bss > rlim)
47853 return -ENOMEM;
47854
47855@@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
47856
47857 install_exec_creds(bprm);
47858
47859+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47860+ current->mm->pax_flags = 0UL;
47861+#endif
47862+
47863+#ifdef CONFIG_PAX_PAGEEXEC
47864+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
47865+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
47866+
47867+#ifdef CONFIG_PAX_EMUTRAMP
47868+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
47869+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
47870+#endif
47871+
47872+#ifdef CONFIG_PAX_MPROTECT
47873+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
47874+ current->mm->pax_flags |= MF_PAX_MPROTECT;
47875+#endif
47876+
47877+ }
47878+#endif
47879+
47880 if (N_MAGIC(ex) == OMAGIC) {
47881 unsigned long text_addr, map_size;
47882 loff_t pos;
47883@@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
47884 }
47885
47886 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
47887- PROT_READ | PROT_WRITE | PROT_EXEC,
47888+ PROT_READ | PROT_WRITE,
47889 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
47890 fd_offset + ex.a_text);
47891 if (error != N_DATADDR(ex)) {
47892diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
47893index 0c42cdb..b62581e9 100644
47894--- a/fs/binfmt_elf.c
47895+++ b/fs/binfmt_elf.c
47896@@ -33,6 +33,7 @@
47897 #include <linux/elf.h>
47898 #include <linux/utsname.h>
47899 #include <linux/coredump.h>
47900+#include <linux/xattr.h>
47901 #include <asm/uaccess.h>
47902 #include <asm/param.h>
47903 #include <asm/page.h>
47904@@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
47905 #define elf_core_dump NULL
47906 #endif
47907
47908+#ifdef CONFIG_PAX_MPROTECT
47909+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
47910+#endif
47911+
47912 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
47913 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
47914 #else
47915@@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
47916 .load_binary = load_elf_binary,
47917 .load_shlib = load_elf_library,
47918 .core_dump = elf_core_dump,
47919+
47920+#ifdef CONFIG_PAX_MPROTECT
47921+ .handle_mprotect= elf_handle_mprotect,
47922+#endif
47923+
47924 .min_coredump = ELF_EXEC_PAGESIZE,
47925 };
47926
47927@@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
47928
47929 static int set_brk(unsigned long start, unsigned long end)
47930 {
47931+ unsigned long e = end;
47932+
47933 start = ELF_PAGEALIGN(start);
47934 end = ELF_PAGEALIGN(end);
47935 if (end > start) {
47936@@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
47937 if (BAD_ADDR(addr))
47938 return addr;
47939 }
47940- current->mm->start_brk = current->mm->brk = end;
47941+ current->mm->start_brk = current->mm->brk = e;
47942 return 0;
47943 }
47944
47945@@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47946 elf_addr_t __user *u_rand_bytes;
47947 const char *k_platform = ELF_PLATFORM;
47948 const char *k_base_platform = ELF_BASE_PLATFORM;
47949- unsigned char k_rand_bytes[16];
47950+ u32 k_rand_bytes[4];
47951 int items;
47952 elf_addr_t *elf_info;
47953 int ei_index = 0;
47954 const struct cred *cred = current_cred();
47955 struct vm_area_struct *vma;
47956+ unsigned long saved_auxv[AT_VECTOR_SIZE];
47957
47958 /*
47959 * In some cases (e.g. Hyper-Threading), we want to avoid L1
47960@@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47961 * Generate 16 random bytes for userspace PRNG seeding.
47962 */
47963 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
47964- u_rand_bytes = (elf_addr_t __user *)
47965- STACK_ALLOC(p, sizeof(k_rand_bytes));
47966+ srandom32(k_rand_bytes[0] ^ random32());
47967+ srandom32(k_rand_bytes[1] ^ random32());
47968+ srandom32(k_rand_bytes[2] ^ random32());
47969+ srandom32(k_rand_bytes[3] ^ random32());
47970+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
47971+ u_rand_bytes = (elf_addr_t __user *) p;
47972 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
47973 return -EFAULT;
47974
47975@@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47976 return -EFAULT;
47977 current->mm->env_end = p;
47978
47979+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
47980+
47981 /* Put the elf_info on the stack in the right place. */
47982 sp = (elf_addr_t __user *)envp + 1;
47983- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
47984+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
47985 return -EFAULT;
47986 return 0;
47987 }
47988@@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
47989 an ELF header */
47990
47991 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47992- struct file *interpreter, unsigned long *interp_map_addr,
47993- unsigned long no_base)
47994+ struct file *interpreter, unsigned long no_base)
47995 {
47996 struct elf_phdr *elf_phdata;
47997 struct elf_phdr *eppnt;
47998- unsigned long load_addr = 0;
47999+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
48000 int load_addr_set = 0;
48001 unsigned long last_bss = 0, elf_bss = 0;
48002- unsigned long error = ~0UL;
48003+ unsigned long error = -EINVAL;
48004 unsigned long total_size;
48005 int retval, i, size;
48006
48007@@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48008 goto out_close;
48009 }
48010
48011+#ifdef CONFIG_PAX_SEGMEXEC
48012+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
48013+ pax_task_size = SEGMEXEC_TASK_SIZE;
48014+#endif
48015+
48016 eppnt = elf_phdata;
48017 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
48018 if (eppnt->p_type == PT_LOAD) {
48019@@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48020 map_addr = elf_map(interpreter, load_addr + vaddr,
48021 eppnt, elf_prot, elf_type, total_size);
48022 total_size = 0;
48023- if (!*interp_map_addr)
48024- *interp_map_addr = map_addr;
48025 error = map_addr;
48026 if (BAD_ADDR(map_addr))
48027 goto out_close;
48028@@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48029 k = load_addr + eppnt->p_vaddr;
48030 if (BAD_ADDR(k) ||
48031 eppnt->p_filesz > eppnt->p_memsz ||
48032- eppnt->p_memsz > TASK_SIZE ||
48033- TASK_SIZE - eppnt->p_memsz < k) {
48034+ eppnt->p_memsz > pax_task_size ||
48035+ pax_task_size - eppnt->p_memsz < k) {
48036 error = -ENOMEM;
48037 goto out_close;
48038 }
48039@@ -530,6 +551,315 @@ out:
48040 return error;
48041 }
48042
48043+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48044+#ifdef CONFIG_PAX_SOFTMODE
48045+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
48046+{
48047+ unsigned long pax_flags = 0UL;
48048+
48049+#ifdef CONFIG_PAX_PAGEEXEC
48050+ if (elf_phdata->p_flags & PF_PAGEEXEC)
48051+ pax_flags |= MF_PAX_PAGEEXEC;
48052+#endif
48053+
48054+#ifdef CONFIG_PAX_SEGMEXEC
48055+ if (elf_phdata->p_flags & PF_SEGMEXEC)
48056+ pax_flags |= MF_PAX_SEGMEXEC;
48057+#endif
48058+
48059+#ifdef CONFIG_PAX_EMUTRAMP
48060+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48061+ pax_flags |= MF_PAX_EMUTRAMP;
48062+#endif
48063+
48064+#ifdef CONFIG_PAX_MPROTECT
48065+ if (elf_phdata->p_flags & PF_MPROTECT)
48066+ pax_flags |= MF_PAX_MPROTECT;
48067+#endif
48068+
48069+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48070+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
48071+ pax_flags |= MF_PAX_RANDMMAP;
48072+#endif
48073+
48074+ return pax_flags;
48075+}
48076+#endif
48077+
48078+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
48079+{
48080+ unsigned long pax_flags = 0UL;
48081+
48082+#ifdef CONFIG_PAX_PAGEEXEC
48083+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
48084+ pax_flags |= MF_PAX_PAGEEXEC;
48085+#endif
48086+
48087+#ifdef CONFIG_PAX_SEGMEXEC
48088+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
48089+ pax_flags |= MF_PAX_SEGMEXEC;
48090+#endif
48091+
48092+#ifdef CONFIG_PAX_EMUTRAMP
48093+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
48094+ pax_flags |= MF_PAX_EMUTRAMP;
48095+#endif
48096+
48097+#ifdef CONFIG_PAX_MPROTECT
48098+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
48099+ pax_flags |= MF_PAX_MPROTECT;
48100+#endif
48101+
48102+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48103+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
48104+ pax_flags |= MF_PAX_RANDMMAP;
48105+#endif
48106+
48107+ return pax_flags;
48108+}
48109+#endif
48110+
48111+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48112+#ifdef CONFIG_PAX_SOFTMODE
48113+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
48114+{
48115+ unsigned long pax_flags = 0UL;
48116+
48117+#ifdef CONFIG_PAX_PAGEEXEC
48118+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
48119+ pax_flags |= MF_PAX_PAGEEXEC;
48120+#endif
48121+
48122+#ifdef CONFIG_PAX_SEGMEXEC
48123+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
48124+ pax_flags |= MF_PAX_SEGMEXEC;
48125+#endif
48126+
48127+#ifdef CONFIG_PAX_EMUTRAMP
48128+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
48129+ pax_flags |= MF_PAX_EMUTRAMP;
48130+#endif
48131+
48132+#ifdef CONFIG_PAX_MPROTECT
48133+ if (pax_flags_softmode & MF_PAX_MPROTECT)
48134+ pax_flags |= MF_PAX_MPROTECT;
48135+#endif
48136+
48137+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48138+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
48139+ pax_flags |= MF_PAX_RANDMMAP;
48140+#endif
48141+
48142+ return pax_flags;
48143+}
48144+#endif
48145+
48146+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
48147+{
48148+ unsigned long pax_flags = 0UL;
48149+
48150+#ifdef CONFIG_PAX_PAGEEXEC
48151+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
48152+ pax_flags |= MF_PAX_PAGEEXEC;
48153+#endif
48154+
48155+#ifdef CONFIG_PAX_SEGMEXEC
48156+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
48157+ pax_flags |= MF_PAX_SEGMEXEC;
48158+#endif
48159+
48160+#ifdef CONFIG_PAX_EMUTRAMP
48161+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
48162+ pax_flags |= MF_PAX_EMUTRAMP;
48163+#endif
48164+
48165+#ifdef CONFIG_PAX_MPROTECT
48166+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
48167+ pax_flags |= MF_PAX_MPROTECT;
48168+#endif
48169+
48170+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48171+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
48172+ pax_flags |= MF_PAX_RANDMMAP;
48173+#endif
48174+
48175+ return pax_flags;
48176+}
48177+#endif
48178+
48179+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48180+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
48181+{
48182+ unsigned long pax_flags = 0UL;
48183+
48184+#ifdef CONFIG_PAX_EI_PAX
48185+
48186+#ifdef CONFIG_PAX_PAGEEXEC
48187+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
48188+ pax_flags |= MF_PAX_PAGEEXEC;
48189+#endif
48190+
48191+#ifdef CONFIG_PAX_SEGMEXEC
48192+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
48193+ pax_flags |= MF_PAX_SEGMEXEC;
48194+#endif
48195+
48196+#ifdef CONFIG_PAX_EMUTRAMP
48197+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
48198+ pax_flags |= MF_PAX_EMUTRAMP;
48199+#endif
48200+
48201+#ifdef CONFIG_PAX_MPROTECT
48202+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
48203+ pax_flags |= MF_PAX_MPROTECT;
48204+#endif
48205+
48206+#ifdef CONFIG_PAX_ASLR
48207+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
48208+ pax_flags |= MF_PAX_RANDMMAP;
48209+#endif
48210+
48211+#else
48212+
48213+#ifdef CONFIG_PAX_PAGEEXEC
48214+ pax_flags |= MF_PAX_PAGEEXEC;
48215+#endif
48216+
48217+#ifdef CONFIG_PAX_SEGMEXEC
48218+ pax_flags |= MF_PAX_SEGMEXEC;
48219+#endif
48220+
48221+#ifdef CONFIG_PAX_MPROTECT
48222+ pax_flags |= MF_PAX_MPROTECT;
48223+#endif
48224+
48225+#ifdef CONFIG_PAX_RANDMMAP
48226+ if (randomize_va_space)
48227+ pax_flags |= MF_PAX_RANDMMAP;
48228+#endif
48229+
48230+#endif
48231+
48232+ return pax_flags;
48233+}
48234+
48235+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
48236+{
48237+
48238+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48239+ unsigned long i;
48240+
48241+ for (i = 0UL; i < elf_ex->e_phnum; i++)
48242+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
48243+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
48244+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
48245+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
48246+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
48247+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
48248+ return ~0UL;
48249+
48250+#ifdef CONFIG_PAX_SOFTMODE
48251+ if (pax_softmode)
48252+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
48253+ else
48254+#endif
48255+
48256+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
48257+ break;
48258+ }
48259+#endif
48260+
48261+ return ~0UL;
48262+}
48263+
48264+static unsigned long pax_parse_xattr_pax(struct file * const file)
48265+{
48266+
48267+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48268+ ssize_t xattr_size, i;
48269+ unsigned char xattr_value[5];
48270+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
48271+
48272+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
48273+ if (xattr_size <= 0 || xattr_size > 5)
48274+ return ~0UL;
48275+
48276+ for (i = 0; i < xattr_size; i++)
48277+ switch (xattr_value[i]) {
48278+ default:
48279+ return ~0UL;
48280+
48281+#define parse_flag(option1, option2, flag) \
48282+ case option1: \
48283+ if (pax_flags_hardmode & MF_PAX_##flag) \
48284+ return ~0UL; \
48285+ pax_flags_hardmode |= MF_PAX_##flag; \
48286+ break; \
48287+ case option2: \
48288+ if (pax_flags_softmode & MF_PAX_##flag) \
48289+ return ~0UL; \
48290+ pax_flags_softmode |= MF_PAX_##flag; \
48291+ break;
48292+
48293+ parse_flag('p', 'P', PAGEEXEC);
48294+ parse_flag('e', 'E', EMUTRAMP);
48295+ parse_flag('m', 'M', MPROTECT);
48296+ parse_flag('r', 'R', RANDMMAP);
48297+ parse_flag('s', 'S', SEGMEXEC);
48298+
48299+#undef parse_flag
48300+ }
48301+
48302+ if (pax_flags_hardmode & pax_flags_softmode)
48303+ return ~0UL;
48304+
48305+#ifdef CONFIG_PAX_SOFTMODE
48306+ if (pax_softmode)
48307+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
48308+ else
48309+#endif
48310+
48311+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
48312+#else
48313+ return ~0UL;
48314+#endif
48315+
48316+}
48317+
48318+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
48319+{
48320+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
48321+
48322+ pax_flags = pax_parse_ei_pax(elf_ex);
48323+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
48324+ xattr_pax_flags = pax_parse_xattr_pax(file);
48325+
48326+ if (pt_pax_flags == ~0UL)
48327+ pt_pax_flags = xattr_pax_flags;
48328+ else if (xattr_pax_flags == ~0UL)
48329+ xattr_pax_flags = pt_pax_flags;
48330+ if (pt_pax_flags != xattr_pax_flags)
48331+ return -EINVAL;
48332+ if (pt_pax_flags != ~0UL)
48333+ pax_flags = pt_pax_flags;
48334+
48335+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
48336+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48337+ if ((__supported_pte_mask & _PAGE_NX))
48338+ pax_flags &= ~MF_PAX_SEGMEXEC;
48339+ else
48340+ pax_flags &= ~MF_PAX_PAGEEXEC;
48341+ }
48342+#endif
48343+
48344+ if (0 > pax_check_flags(&pax_flags))
48345+ return -EINVAL;
48346+
48347+ current->mm->pax_flags = pax_flags;
48348+ return 0;
48349+}
48350+#endif
48351+
48352 /*
48353 * These are the functions used to load ELF style executables and shared
48354 * libraries. There is no binary dependent code anywhere else.
48355@@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
48356 {
48357 unsigned int random_variable = 0;
48358
48359+#ifdef CONFIG_PAX_RANDUSTACK
48360+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
48361+ return stack_top - current->mm->delta_stack;
48362+#endif
48363+
48364 if ((current->flags & PF_RANDOMIZE) &&
48365 !(current->personality & ADDR_NO_RANDOMIZE)) {
48366 random_variable = get_random_int() & STACK_RND_MASK;
48367@@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
48368 unsigned long load_addr = 0, load_bias = 0;
48369 int load_addr_set = 0;
48370 char * elf_interpreter = NULL;
48371- unsigned long error;
48372+ unsigned long error = 0;
48373 struct elf_phdr *elf_ppnt, *elf_phdata;
48374 unsigned long elf_bss, elf_brk;
48375 int retval, i;
48376@@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
48377 unsigned long start_code, end_code, start_data, end_data;
48378 unsigned long reloc_func_desc __maybe_unused = 0;
48379 int executable_stack = EXSTACK_DEFAULT;
48380- unsigned long def_flags = 0;
48381 struct pt_regs *regs = current_pt_regs();
48382 struct {
48383 struct elfhdr elf_ex;
48384 struct elfhdr interp_elf_ex;
48385 } *loc;
48386+ unsigned long pax_task_size = TASK_SIZE;
48387
48388 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
48389 if (!loc) {
48390@@ -715,11 +1050,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
48391 goto out_free_dentry;
48392
48393 /* OK, This is the point of no return */
48394- current->mm->def_flags = def_flags;
48395+
48396+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48397+ current->mm->pax_flags = 0UL;
48398+#endif
48399+
48400+#ifdef CONFIG_PAX_DLRESOLVE
48401+ current->mm->call_dl_resolve = 0UL;
48402+#endif
48403+
48404+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
48405+ current->mm->call_syscall = 0UL;
48406+#endif
48407+
48408+#ifdef CONFIG_PAX_ASLR
48409+ current->mm->delta_mmap = 0UL;
48410+ current->mm->delta_stack = 0UL;
48411+#endif
48412+
48413+ current->mm->def_flags = 0;
48414+
48415+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48416+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
48417+ send_sig(SIGKILL, current, 0);
48418+ goto out_free_dentry;
48419+ }
48420+#endif
48421+
48422+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
48423+ pax_set_initial_flags(bprm);
48424+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
48425+ if (pax_set_initial_flags_func)
48426+ (pax_set_initial_flags_func)(bprm);
48427+#endif
48428+
48429+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48430+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
48431+ current->mm->context.user_cs_limit = PAGE_SIZE;
48432+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
48433+ }
48434+#endif
48435+
48436+#ifdef CONFIG_PAX_SEGMEXEC
48437+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
48438+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
48439+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
48440+ pax_task_size = SEGMEXEC_TASK_SIZE;
48441+ current->mm->def_flags |= VM_NOHUGEPAGE;
48442+ }
48443+#endif
48444+
48445+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
48446+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48447+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
48448+ put_cpu();
48449+ }
48450+#endif
48451
48452 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
48453 may depend on the personality. */
48454 SET_PERSONALITY(loc->elf_ex);
48455+
48456+#ifdef CONFIG_PAX_ASLR
48457+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
48458+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
48459+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
48460+ }
48461+#endif
48462+
48463+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
48464+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48465+ executable_stack = EXSTACK_DISABLE_X;
48466+ current->personality &= ~READ_IMPLIES_EXEC;
48467+ } else
48468+#endif
48469+
48470 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
48471 current->personality |= READ_IMPLIES_EXEC;
48472
48473@@ -810,6 +1215,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
48474 #else
48475 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
48476 #endif
48477+
48478+#ifdef CONFIG_PAX_RANDMMAP
48479+ /* PaX: randomize base address at the default exe base if requested */
48480+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
48481+#ifdef CONFIG_SPARC64
48482+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
48483+#else
48484+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
48485+#endif
48486+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
48487+ elf_flags |= MAP_FIXED;
48488+ }
48489+#endif
48490+
48491 }
48492
48493 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
48494@@ -842,9 +1261,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
48495 * allowed task size. Note that p_filesz must always be
48496 * <= p_memsz so it is only necessary to check p_memsz.
48497 */
48498- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48499- elf_ppnt->p_memsz > TASK_SIZE ||
48500- TASK_SIZE - elf_ppnt->p_memsz < k) {
48501+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48502+ elf_ppnt->p_memsz > pax_task_size ||
48503+ pax_task_size - elf_ppnt->p_memsz < k) {
48504 /* set_brk can never work. Avoid overflows. */
48505 send_sig(SIGKILL, current, 0);
48506 retval = -EINVAL;
48507@@ -883,17 +1302,44 @@ static int load_elf_binary(struct linux_binprm *bprm)
48508 goto out_free_dentry;
48509 }
48510 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
48511- send_sig(SIGSEGV, current, 0);
48512- retval = -EFAULT; /* Nobody gets to see this, but.. */
48513- goto out_free_dentry;
48514+ /*
48515+ * This bss-zeroing can fail if the ELF
48516+ * file specifies odd protections. So
48517+ * we don't check the return value
48518+ */
48519 }
48520
48521+#ifdef CONFIG_PAX_RANDMMAP
48522+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
48523+ unsigned long start, size, flags, vm_flags;
48524+
48525+ start = ELF_PAGEALIGN(elf_brk);
48526+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
48527+ flags = MAP_FIXED | MAP_PRIVATE;
48528+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
48529+
48530+ down_write(&current->mm->mmap_sem);
48531+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
48532+ retval = -ENOMEM;
48533+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
48534+// if (current->personality & ADDR_NO_RANDOMIZE)
48535+// vm_flags |= VM_READ | VM_MAYREAD;
48536+ start = mmap_region(NULL, start, PAGE_ALIGN(size), flags, vm_flags, 0);
48537+ retval = IS_ERR_VALUE(start) ? start : 0;
48538+ }
48539+ up_write(&current->mm->mmap_sem);
48540+ if (retval == 0)
48541+ retval = set_brk(start + size, start + size + PAGE_SIZE);
48542+ if (retval < 0) {
48543+ send_sig(SIGKILL, current, 0);
48544+ goto out_free_dentry;
48545+ }
48546+ }
48547+#endif
48548+
48549 if (elf_interpreter) {
48550- unsigned long interp_map_addr = 0;
48551-
48552 elf_entry = load_elf_interp(&loc->interp_elf_ex,
48553 interpreter,
48554- &interp_map_addr,
48555 load_bias);
48556 if (!IS_ERR((void *)elf_entry)) {
48557 /*
48558@@ -1115,7 +1561,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
48559 * Decide what to dump of a segment, part, all or none.
48560 */
48561 static unsigned long vma_dump_size(struct vm_area_struct *vma,
48562- unsigned long mm_flags)
48563+ unsigned long mm_flags, long signr)
48564 {
48565 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
48566
48567@@ -1152,7 +1598,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
48568 if (vma->vm_file == NULL)
48569 return 0;
48570
48571- if (FILTER(MAPPED_PRIVATE))
48572+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
48573 goto whole;
48574
48575 /*
48576@@ -1374,9 +1820,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
48577 {
48578 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
48579 int i = 0;
48580- do
48581+ do {
48582 i += 2;
48583- while (auxv[i - 2] != AT_NULL);
48584+ } while (auxv[i - 2] != AT_NULL);
48585 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
48586 }
48587
48588@@ -2006,14 +2452,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
48589 }
48590
48591 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
48592- unsigned long mm_flags)
48593+ struct coredump_params *cprm)
48594 {
48595 struct vm_area_struct *vma;
48596 size_t size = 0;
48597
48598 for (vma = first_vma(current, gate_vma); vma != NULL;
48599 vma = next_vma(vma, gate_vma))
48600- size += vma_dump_size(vma, mm_flags);
48601+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48602 return size;
48603 }
48604
48605@@ -2107,7 +2553,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48606
48607 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
48608
48609- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
48610+ offset += elf_core_vma_data_size(gate_vma, cprm);
48611 offset += elf_core_extra_data_size();
48612 e_shoff = offset;
48613
48614@@ -2121,10 +2567,12 @@ static int elf_core_dump(struct coredump_params *cprm)
48615 offset = dataoff;
48616
48617 size += sizeof(*elf);
48618+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48619 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
48620 goto end_coredump;
48621
48622 size += sizeof(*phdr4note);
48623+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48624 if (size > cprm->limit
48625 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
48626 goto end_coredump;
48627@@ -2138,7 +2586,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48628 phdr.p_offset = offset;
48629 phdr.p_vaddr = vma->vm_start;
48630 phdr.p_paddr = 0;
48631- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
48632+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48633 phdr.p_memsz = vma->vm_end - vma->vm_start;
48634 offset += phdr.p_filesz;
48635 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
48636@@ -2149,6 +2597,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48637 phdr.p_align = ELF_EXEC_PAGESIZE;
48638
48639 size += sizeof(phdr);
48640+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48641 if (size > cprm->limit
48642 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
48643 goto end_coredump;
48644@@ -2173,7 +2622,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48645 unsigned long addr;
48646 unsigned long end;
48647
48648- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
48649+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48650
48651 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
48652 struct page *page;
48653@@ -2182,6 +2631,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48654 page = get_dump_page(addr);
48655 if (page) {
48656 void *kaddr = kmap(page);
48657+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
48658 stop = ((size += PAGE_SIZE) > cprm->limit) ||
48659 !dump_write(cprm->file, kaddr,
48660 PAGE_SIZE);
48661@@ -2199,6 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48662
48663 if (e_phnum == PN_XNUM) {
48664 size += sizeof(*shdr4extnum);
48665+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48666 if (size > cprm->limit
48667 || !dump_write(cprm->file, shdr4extnum,
48668 sizeof(*shdr4extnum)))
48669@@ -2219,6 +2670,97 @@ out:
48670
48671 #endif /* CONFIG_ELF_CORE */
48672
48673+#ifdef CONFIG_PAX_MPROTECT
48674+/* PaX: non-PIC ELF libraries need relocations on their executable segments
48675+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
48676+ * we'll remove VM_MAYWRITE for good on RELRO segments.
48677+ *
48678+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
48679+ * basis because we want to allow the common case and not the special ones.
48680+ */
48681+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
48682+{
48683+ struct elfhdr elf_h;
48684+ struct elf_phdr elf_p;
48685+ unsigned long i;
48686+ unsigned long oldflags;
48687+ bool is_textrel_rw, is_textrel_rx, is_relro;
48688+
48689+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
48690+ return;
48691+
48692+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
48693+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
48694+
48695+#ifdef CONFIG_PAX_ELFRELOCS
48696+ /* possible TEXTREL */
48697+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
48698+ 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);
48699+#else
48700+ is_textrel_rw = false;
48701+ is_textrel_rx = false;
48702+#endif
48703+
48704+ /* possible RELRO */
48705+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
48706+
48707+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
48708+ return;
48709+
48710+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
48711+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
48712+
48713+#ifdef CONFIG_PAX_ETEXECRELOCS
48714+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48715+#else
48716+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
48717+#endif
48718+
48719+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48720+ !elf_check_arch(&elf_h) ||
48721+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
48722+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
48723+ return;
48724+
48725+ for (i = 0UL; i < elf_h.e_phnum; i++) {
48726+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
48727+ return;
48728+ switch (elf_p.p_type) {
48729+ case PT_DYNAMIC:
48730+ if (!is_textrel_rw && !is_textrel_rx)
48731+ continue;
48732+ i = 0UL;
48733+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
48734+ elf_dyn dyn;
48735+
48736+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
48737+ return;
48738+ if (dyn.d_tag == DT_NULL)
48739+ return;
48740+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
48741+ gr_log_textrel(vma);
48742+ if (is_textrel_rw)
48743+ vma->vm_flags |= VM_MAYWRITE;
48744+ else
48745+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
48746+ vma->vm_flags &= ~VM_MAYWRITE;
48747+ return;
48748+ }
48749+ i++;
48750+ }
48751+ return;
48752+
48753+ case PT_GNU_RELRO:
48754+ if (!is_relro)
48755+ continue;
48756+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
48757+ vma->vm_flags &= ~VM_MAYWRITE;
48758+ return;
48759+ }
48760+ }
48761+}
48762+#endif
48763+
48764 static int __init init_elf_binfmt(void)
48765 {
48766 register_binfmt(&elf_format);
48767diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
48768index b563719..3868998 100644
48769--- a/fs/binfmt_flat.c
48770+++ b/fs/binfmt_flat.c
48771@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
48772 realdatastart = (unsigned long) -ENOMEM;
48773 printk("Unable to allocate RAM for process data, errno %d\n",
48774 (int)-realdatastart);
48775+ down_write(&current->mm->mmap_sem);
48776 vm_munmap(textpos, text_len);
48777+ up_write(&current->mm->mmap_sem);
48778 ret = realdatastart;
48779 goto err;
48780 }
48781@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48782 }
48783 if (IS_ERR_VALUE(result)) {
48784 printk("Unable to read data+bss, errno %d\n", (int)-result);
48785+ down_write(&current->mm->mmap_sem);
48786 vm_munmap(textpos, text_len);
48787 vm_munmap(realdatastart, len);
48788+ up_write(&current->mm->mmap_sem);
48789 ret = result;
48790 goto err;
48791 }
48792@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48793 }
48794 if (IS_ERR_VALUE(result)) {
48795 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
48796+ down_write(&current->mm->mmap_sem);
48797 vm_munmap(textpos, text_len + data_len + extra +
48798 MAX_SHARED_LIBS * sizeof(unsigned long));
48799+ up_write(&current->mm->mmap_sem);
48800 ret = result;
48801 goto err;
48802 }
48803diff --git a/fs/bio.c b/fs/bio.c
48804index b96fc6c..431d628 100644
48805--- a/fs/bio.c
48806+++ b/fs/bio.c
48807@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
48808 /*
48809 * Overflow, abort
48810 */
48811- if (end < start)
48812+ if (end < start || end - start > INT_MAX - nr_pages)
48813 return ERR_PTR(-EINVAL);
48814
48815 nr_pages += end - start;
48816@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
48817 /*
48818 * Overflow, abort
48819 */
48820- if (end < start)
48821+ if (end < start || end - start > INT_MAX - nr_pages)
48822 return ERR_PTR(-EINVAL);
48823
48824 nr_pages += end - start;
48825@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
48826 const int read = bio_data_dir(bio) == READ;
48827 struct bio_map_data *bmd = bio->bi_private;
48828 int i;
48829- char *p = bmd->sgvecs[0].iov_base;
48830+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
48831
48832 __bio_for_each_segment(bvec, bio, i, 0) {
48833 char *addr = page_address(bvec->bv_page);
48834diff --git a/fs/block_dev.c b/fs/block_dev.c
48835index 78edf76..da14f3f 100644
48836--- a/fs/block_dev.c
48837+++ b/fs/block_dev.c
48838@@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
48839 else if (bdev->bd_contains == bdev)
48840 return true; /* is a whole device which isn't held */
48841
48842- else if (whole->bd_holder == bd_may_claim)
48843+ else if (whole->bd_holder == (void *)bd_may_claim)
48844 return true; /* is a partition of a device that is being partitioned */
48845 else if (whole->bd_holder != NULL)
48846 return false; /* is a partition of a held device */
48847diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
48848index eea5da7..88fead70 100644
48849--- a/fs/btrfs/ctree.c
48850+++ b/fs/btrfs/ctree.c
48851@@ -1033,9 +1033,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
48852 free_extent_buffer(buf);
48853 add_root_to_dirty_list(root);
48854 } else {
48855- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
48856- parent_start = parent->start;
48857- else
48858+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
48859+ if (parent)
48860+ parent_start = parent->start;
48861+ else
48862+ parent_start = 0;
48863+ } else
48864 parent_start = 0;
48865
48866 WARN_ON(trans->transid != btrfs_header_generation(parent));
48867diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
48868index 659ea81..0f63c1a 100644
48869--- a/fs/btrfs/inode.c
48870+++ b/fs/btrfs/inode.c
48871@@ -7300,7 +7300,7 @@ fail:
48872 return -ENOMEM;
48873 }
48874
48875-static int btrfs_getattr(struct vfsmount *mnt,
48876+int btrfs_getattr(struct vfsmount *mnt,
48877 struct dentry *dentry, struct kstat *stat)
48878 {
48879 struct inode *inode = dentry->d_inode;
48880@@ -7314,6 +7314,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
48881 return 0;
48882 }
48883
48884+EXPORT_SYMBOL(btrfs_getattr);
48885+
48886+dev_t get_btrfs_dev_from_inode(struct inode *inode)
48887+{
48888+ return BTRFS_I(inode)->root->anon_dev;
48889+}
48890+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
48891+
48892 /*
48893 * If a file is moved, it will inherit the cow and compression flags of the new
48894 * directory.
48895diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
48896index 338f259..b657640 100644
48897--- a/fs/btrfs/ioctl.c
48898+++ b/fs/btrfs/ioctl.c
48899@@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48900 for (i = 0; i < num_types; i++) {
48901 struct btrfs_space_info *tmp;
48902
48903+ /* Don't copy in more than we allocated */
48904 if (!slot_count)
48905 break;
48906
48907+ slot_count--;
48908+
48909 info = NULL;
48910 rcu_read_lock();
48911 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
48912@@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48913 memcpy(dest, &space, sizeof(space));
48914 dest++;
48915 space_args.total_spaces++;
48916- slot_count--;
48917 }
48918- if (!slot_count)
48919- break;
48920 }
48921 up_read(&info->groups_sem);
48922 }
48923diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
48924index 300e09a..9fe4539 100644
48925--- a/fs/btrfs/relocation.c
48926+++ b/fs/btrfs/relocation.c
48927@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
48928 }
48929 spin_unlock(&rc->reloc_root_tree.lock);
48930
48931- BUG_ON((struct btrfs_root *)node->data != root);
48932+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
48933
48934 if (!del) {
48935 spin_lock(&rc->reloc_root_tree.lock);
48936diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
48937index d8982e9..29a85fa 100644
48938--- a/fs/btrfs/super.c
48939+++ b/fs/btrfs/super.c
48940@@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
48941 function, line, errstr);
48942 return;
48943 }
48944- ACCESS_ONCE(trans->transaction->aborted) = errno;
48945+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
48946 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
48947 }
48948 /*
48949diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
48950index 622f469..e8d2d55 100644
48951--- a/fs/cachefiles/bind.c
48952+++ b/fs/cachefiles/bind.c
48953@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
48954 args);
48955
48956 /* start by checking things over */
48957- ASSERT(cache->fstop_percent >= 0 &&
48958- cache->fstop_percent < cache->fcull_percent &&
48959+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
48960 cache->fcull_percent < cache->frun_percent &&
48961 cache->frun_percent < 100);
48962
48963- ASSERT(cache->bstop_percent >= 0 &&
48964- cache->bstop_percent < cache->bcull_percent &&
48965+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
48966 cache->bcull_percent < cache->brun_percent &&
48967 cache->brun_percent < 100);
48968
48969diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
48970index 0a1467b..6a53245 100644
48971--- a/fs/cachefiles/daemon.c
48972+++ b/fs/cachefiles/daemon.c
48973@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
48974 if (n > buflen)
48975 return -EMSGSIZE;
48976
48977- if (copy_to_user(_buffer, buffer, n) != 0)
48978+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
48979 return -EFAULT;
48980
48981 return n;
48982@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
48983 if (test_bit(CACHEFILES_DEAD, &cache->flags))
48984 return -EIO;
48985
48986- if (datalen < 0 || datalen > PAGE_SIZE - 1)
48987+ if (datalen > PAGE_SIZE - 1)
48988 return -EOPNOTSUPP;
48989
48990 /* drag the command string into the kernel so we can parse it */
48991@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
48992 if (args[0] != '%' || args[1] != '\0')
48993 return -EINVAL;
48994
48995- if (fstop < 0 || fstop >= cache->fcull_percent)
48996+ if (fstop >= cache->fcull_percent)
48997 return cachefiles_daemon_range_error(cache, args);
48998
48999 cache->fstop_percent = fstop;
49000@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
49001 if (args[0] != '%' || args[1] != '\0')
49002 return -EINVAL;
49003
49004- if (bstop < 0 || bstop >= cache->bcull_percent)
49005+ if (bstop >= cache->bcull_percent)
49006 return cachefiles_daemon_range_error(cache, args);
49007
49008 cache->bstop_percent = bstop;
49009diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
49010index 4938251..7e01445 100644
49011--- a/fs/cachefiles/internal.h
49012+++ b/fs/cachefiles/internal.h
49013@@ -59,7 +59,7 @@ struct cachefiles_cache {
49014 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
49015 struct rb_root active_nodes; /* active nodes (can't be culled) */
49016 rwlock_t active_lock; /* lock for active_nodes */
49017- atomic_t gravecounter; /* graveyard uniquifier */
49018+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
49019 unsigned frun_percent; /* when to stop culling (% files) */
49020 unsigned fcull_percent; /* when to start culling (% files) */
49021 unsigned fstop_percent; /* when to stop allocating (% files) */
49022@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
49023 * proc.c
49024 */
49025 #ifdef CONFIG_CACHEFILES_HISTOGRAM
49026-extern atomic_t cachefiles_lookup_histogram[HZ];
49027-extern atomic_t cachefiles_mkdir_histogram[HZ];
49028-extern atomic_t cachefiles_create_histogram[HZ];
49029+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49030+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49031+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
49032
49033 extern int __init cachefiles_proc_init(void);
49034 extern void cachefiles_proc_cleanup(void);
49035 static inline
49036-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
49037+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
49038 {
49039 unsigned long jif = jiffies - start_jif;
49040 if (jif >= HZ)
49041 jif = HZ - 1;
49042- atomic_inc(&histogram[jif]);
49043+ atomic_inc_unchecked(&histogram[jif]);
49044 }
49045
49046 #else
49047diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
49048index 8c01c5fc..15f982e 100644
49049--- a/fs/cachefiles/namei.c
49050+++ b/fs/cachefiles/namei.c
49051@@ -317,7 +317,7 @@ try_again:
49052 /* first step is to make up a grave dentry in the graveyard */
49053 sprintf(nbuffer, "%08x%08x",
49054 (uint32_t) get_seconds(),
49055- (uint32_t) atomic_inc_return(&cache->gravecounter));
49056+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
49057
49058 /* do the multiway lock magic */
49059 trap = lock_rename(cache->graveyard, dir);
49060diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
49061index eccd339..4c1d995 100644
49062--- a/fs/cachefiles/proc.c
49063+++ b/fs/cachefiles/proc.c
49064@@ -14,9 +14,9 @@
49065 #include <linux/seq_file.h>
49066 #include "internal.h"
49067
49068-atomic_t cachefiles_lookup_histogram[HZ];
49069-atomic_t cachefiles_mkdir_histogram[HZ];
49070-atomic_t cachefiles_create_histogram[HZ];
49071+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49072+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49073+atomic_unchecked_t cachefiles_create_histogram[HZ];
49074
49075 /*
49076 * display the latency histogram
49077@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
49078 return 0;
49079 default:
49080 index = (unsigned long) v - 3;
49081- x = atomic_read(&cachefiles_lookup_histogram[index]);
49082- y = atomic_read(&cachefiles_mkdir_histogram[index]);
49083- z = atomic_read(&cachefiles_create_histogram[index]);
49084+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
49085+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
49086+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
49087 if (x == 0 && y == 0 && z == 0)
49088 return 0;
49089
49090diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
49091index 4809922..aab2c39 100644
49092--- a/fs/cachefiles/rdwr.c
49093+++ b/fs/cachefiles/rdwr.c
49094@@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
49095 old_fs = get_fs();
49096 set_fs(KERNEL_DS);
49097 ret = file->f_op->write(
49098- file, (const void __user *) data, len, &pos);
49099+ file, (const void __force_user *) data, len, &pos);
49100 set_fs(old_fs);
49101 kunmap(page);
49102 if (ret != len)
49103diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
49104index 8c1aabe..bbf856a 100644
49105--- a/fs/ceph/dir.c
49106+++ b/fs/ceph/dir.c
49107@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
49108 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
49109 struct ceph_mds_client *mdsc = fsc->mdsc;
49110 unsigned frag = fpos_frag(filp->f_pos);
49111- int off = fpos_off(filp->f_pos);
49112+ unsigned int off = fpos_off(filp->f_pos);
49113 int err;
49114 u32 ftype;
49115 struct ceph_mds_reply_info_parsed *rinfo;
49116diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
49117index d9ea6ed..1e6c8ac 100644
49118--- a/fs/cifs/cifs_debug.c
49119+++ b/fs/cifs/cifs_debug.c
49120@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49121
49122 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
49123 #ifdef CONFIG_CIFS_STATS2
49124- atomic_set(&totBufAllocCount, 0);
49125- atomic_set(&totSmBufAllocCount, 0);
49126+ atomic_set_unchecked(&totBufAllocCount, 0);
49127+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49128 #endif /* CONFIG_CIFS_STATS2 */
49129 spin_lock(&cifs_tcp_ses_lock);
49130 list_for_each(tmp1, &cifs_tcp_ses_list) {
49131@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49132 tcon = list_entry(tmp3,
49133 struct cifs_tcon,
49134 tcon_list);
49135- atomic_set(&tcon->num_smbs_sent, 0);
49136+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
49137 if (server->ops->clear_stats)
49138 server->ops->clear_stats(tcon);
49139 }
49140@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49141 smBufAllocCount.counter, cifs_min_small);
49142 #ifdef CONFIG_CIFS_STATS2
49143 seq_printf(m, "Total Large %d Small %d Allocations\n",
49144- atomic_read(&totBufAllocCount),
49145- atomic_read(&totSmBufAllocCount));
49146+ atomic_read_unchecked(&totBufAllocCount),
49147+ atomic_read_unchecked(&totSmBufAllocCount));
49148 #endif /* CONFIG_CIFS_STATS2 */
49149
49150 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
49151@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49152 if (tcon->need_reconnect)
49153 seq_puts(m, "\tDISCONNECTED ");
49154 seq_printf(m, "\nSMBs: %d",
49155- atomic_read(&tcon->num_smbs_sent));
49156+ atomic_read_unchecked(&tcon->num_smbs_sent));
49157 if (server->ops->print_stats)
49158 server->ops->print_stats(m, tcon);
49159 }
49160diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
49161index b9db388..9a73d6d 100644
49162--- a/fs/cifs/cifsfs.c
49163+++ b/fs/cifs/cifsfs.c
49164@@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
49165 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
49166 cifs_req_cachep = kmem_cache_create("cifs_request",
49167 CIFSMaxBufSize + max_hdr_size, 0,
49168- SLAB_HWCACHE_ALIGN, NULL);
49169+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
49170 if (cifs_req_cachep == NULL)
49171 return -ENOMEM;
49172
49173@@ -1053,7 +1053,7 @@ cifs_init_request_bufs(void)
49174 efficient to alloc 1 per page off the slab compared to 17K (5page)
49175 alloc of large cifs buffers even when page debugging is on */
49176 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
49177- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
49178+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
49179 NULL);
49180 if (cifs_sm_req_cachep == NULL) {
49181 mempool_destroy(cifs_req_poolp);
49182@@ -1138,8 +1138,8 @@ init_cifs(void)
49183 atomic_set(&bufAllocCount, 0);
49184 atomic_set(&smBufAllocCount, 0);
49185 #ifdef CONFIG_CIFS_STATS2
49186- atomic_set(&totBufAllocCount, 0);
49187- atomic_set(&totSmBufAllocCount, 0);
49188+ atomic_set_unchecked(&totBufAllocCount, 0);
49189+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49190 #endif /* CONFIG_CIFS_STATS2 */
49191
49192 atomic_set(&midCount, 0);
49193diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
49194index e6899ce..d6b2920 100644
49195--- a/fs/cifs/cifsglob.h
49196+++ b/fs/cifs/cifsglob.h
49197@@ -751,35 +751,35 @@ struct cifs_tcon {
49198 __u16 Flags; /* optional support bits */
49199 enum statusEnum tidStatus;
49200 #ifdef CONFIG_CIFS_STATS
49201- atomic_t num_smbs_sent;
49202+ atomic_unchecked_t num_smbs_sent;
49203 union {
49204 struct {
49205- atomic_t num_writes;
49206- atomic_t num_reads;
49207- atomic_t num_flushes;
49208- atomic_t num_oplock_brks;
49209- atomic_t num_opens;
49210- atomic_t num_closes;
49211- atomic_t num_deletes;
49212- atomic_t num_mkdirs;
49213- atomic_t num_posixopens;
49214- atomic_t num_posixmkdirs;
49215- atomic_t num_rmdirs;
49216- atomic_t num_renames;
49217- atomic_t num_t2renames;
49218- atomic_t num_ffirst;
49219- atomic_t num_fnext;
49220- atomic_t num_fclose;
49221- atomic_t num_hardlinks;
49222- atomic_t num_symlinks;
49223- atomic_t num_locks;
49224- atomic_t num_acl_get;
49225- atomic_t num_acl_set;
49226+ atomic_unchecked_t num_writes;
49227+ atomic_unchecked_t num_reads;
49228+ atomic_unchecked_t num_flushes;
49229+ atomic_unchecked_t num_oplock_brks;
49230+ atomic_unchecked_t num_opens;
49231+ atomic_unchecked_t num_closes;
49232+ atomic_unchecked_t num_deletes;
49233+ atomic_unchecked_t num_mkdirs;
49234+ atomic_unchecked_t num_posixopens;
49235+ atomic_unchecked_t num_posixmkdirs;
49236+ atomic_unchecked_t num_rmdirs;
49237+ atomic_unchecked_t num_renames;
49238+ atomic_unchecked_t num_t2renames;
49239+ atomic_unchecked_t num_ffirst;
49240+ atomic_unchecked_t num_fnext;
49241+ atomic_unchecked_t num_fclose;
49242+ atomic_unchecked_t num_hardlinks;
49243+ atomic_unchecked_t num_symlinks;
49244+ atomic_unchecked_t num_locks;
49245+ atomic_unchecked_t num_acl_get;
49246+ atomic_unchecked_t num_acl_set;
49247 } cifs_stats;
49248 #ifdef CONFIG_CIFS_SMB2
49249 struct {
49250- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49251- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49252+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49253+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49254 } smb2_stats;
49255 #endif /* CONFIG_CIFS_SMB2 */
49256 } stats;
49257@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
49258 }
49259
49260 #ifdef CONFIG_CIFS_STATS
49261-#define cifs_stats_inc atomic_inc
49262+#define cifs_stats_inc atomic_inc_unchecked
49263
49264 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
49265 unsigned int bytes)
49266@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
49267 /* Various Debug counters */
49268 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
49269 #ifdef CONFIG_CIFS_STATS2
49270-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
49271-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
49272+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
49273+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
49274 #endif
49275 GLOBAL_EXTERN atomic_t smBufAllocCount;
49276 GLOBAL_EXTERN atomic_t midCount;
49277diff --git a/fs/cifs/link.c b/fs/cifs/link.c
49278index 51dc2fb..1e12a33 100644
49279--- a/fs/cifs/link.c
49280+++ b/fs/cifs/link.c
49281@@ -616,7 +616,7 @@ symlink_exit:
49282
49283 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
49284 {
49285- char *p = nd_get_link(nd);
49286+ const char *p = nd_get_link(nd);
49287 if (!IS_ERR(p))
49288 kfree(p);
49289 }
49290diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
49291index 3a00c0d..42d901c 100644
49292--- a/fs/cifs/misc.c
49293+++ b/fs/cifs/misc.c
49294@@ -169,7 +169,7 @@ cifs_buf_get(void)
49295 memset(ret_buf, 0, buf_size + 3);
49296 atomic_inc(&bufAllocCount);
49297 #ifdef CONFIG_CIFS_STATS2
49298- atomic_inc(&totBufAllocCount);
49299+ atomic_inc_unchecked(&totBufAllocCount);
49300 #endif /* CONFIG_CIFS_STATS2 */
49301 }
49302
49303@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
49304 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
49305 atomic_inc(&smBufAllocCount);
49306 #ifdef CONFIG_CIFS_STATS2
49307- atomic_inc(&totSmBufAllocCount);
49308+ atomic_inc_unchecked(&totSmBufAllocCount);
49309 #endif /* CONFIG_CIFS_STATS2 */
49310
49311 }
49312diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
49313index 47bc5a8..10decbe 100644
49314--- a/fs/cifs/smb1ops.c
49315+++ b/fs/cifs/smb1ops.c
49316@@ -586,27 +586,27 @@ static void
49317 cifs_clear_stats(struct cifs_tcon *tcon)
49318 {
49319 #ifdef CONFIG_CIFS_STATS
49320- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
49321- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
49322- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
49323- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
49324- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
49325- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
49326- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
49327- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
49328- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
49329- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
49330- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
49331- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
49332- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
49333- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
49334- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
49335- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
49336- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
49337- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
49338- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
49339- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
49340- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
49341+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
49342+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
49343+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
49344+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
49345+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
49346+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
49347+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
49348+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
49349+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
49350+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
49351+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
49352+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
49353+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
49354+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
49355+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
49356+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
49357+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
49358+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
49359+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
49360+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
49361+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
49362 #endif
49363 }
49364
49365@@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
49366 {
49367 #ifdef CONFIG_CIFS_STATS
49368 seq_printf(m, " Oplocks breaks: %d",
49369- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
49370+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
49371 seq_printf(m, "\nReads: %d Bytes: %llu",
49372- atomic_read(&tcon->stats.cifs_stats.num_reads),
49373+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
49374 (long long)(tcon->bytes_read));
49375 seq_printf(m, "\nWrites: %d Bytes: %llu",
49376- atomic_read(&tcon->stats.cifs_stats.num_writes),
49377+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
49378 (long long)(tcon->bytes_written));
49379 seq_printf(m, "\nFlushes: %d",
49380- atomic_read(&tcon->stats.cifs_stats.num_flushes));
49381+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
49382 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
49383- atomic_read(&tcon->stats.cifs_stats.num_locks),
49384- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
49385- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
49386+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
49387+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
49388+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
49389 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
49390- atomic_read(&tcon->stats.cifs_stats.num_opens),
49391- atomic_read(&tcon->stats.cifs_stats.num_closes),
49392- atomic_read(&tcon->stats.cifs_stats.num_deletes));
49393+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
49394+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
49395+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
49396 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
49397- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
49398- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
49399+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
49400+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
49401 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
49402- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
49403- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
49404+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
49405+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
49406 seq_printf(m, "\nRenames: %d T2 Renames %d",
49407- atomic_read(&tcon->stats.cifs_stats.num_renames),
49408- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
49409+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
49410+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
49411 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
49412- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
49413- atomic_read(&tcon->stats.cifs_stats.num_fnext),
49414- atomic_read(&tcon->stats.cifs_stats.num_fclose));
49415+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
49416+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
49417+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
49418 #endif
49419 }
49420
49421diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
49422index bceffe7..cd1ae59 100644
49423--- a/fs/cifs/smb2ops.c
49424+++ b/fs/cifs/smb2ops.c
49425@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
49426 #ifdef CONFIG_CIFS_STATS
49427 int i;
49428 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
49429- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
49430- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
49431+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
49432+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
49433 }
49434 #endif
49435 }
49436@@ -284,66 +284,66 @@ static void
49437 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
49438 {
49439 #ifdef CONFIG_CIFS_STATS
49440- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
49441- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
49442+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
49443+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
49444 seq_printf(m, "\nNegotiates: %d sent %d failed",
49445- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
49446- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
49447+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
49448+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
49449 seq_printf(m, "\nSessionSetups: %d sent %d failed",
49450- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
49451- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
49452+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
49453+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
49454 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
49455 seq_printf(m, "\nLogoffs: %d sent %d failed",
49456- atomic_read(&sent[SMB2_LOGOFF_HE]),
49457- atomic_read(&failed[SMB2_LOGOFF_HE]));
49458+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
49459+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
49460 seq_printf(m, "\nTreeConnects: %d sent %d failed",
49461- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
49462- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
49463+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
49464+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
49465 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
49466- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
49467- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
49468+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
49469+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
49470 seq_printf(m, "\nCreates: %d sent %d failed",
49471- atomic_read(&sent[SMB2_CREATE_HE]),
49472- atomic_read(&failed[SMB2_CREATE_HE]));
49473+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
49474+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
49475 seq_printf(m, "\nCloses: %d sent %d failed",
49476- atomic_read(&sent[SMB2_CLOSE_HE]),
49477- atomic_read(&failed[SMB2_CLOSE_HE]));
49478+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
49479+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
49480 seq_printf(m, "\nFlushes: %d sent %d failed",
49481- atomic_read(&sent[SMB2_FLUSH_HE]),
49482- atomic_read(&failed[SMB2_FLUSH_HE]));
49483+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
49484+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
49485 seq_printf(m, "\nReads: %d sent %d failed",
49486- atomic_read(&sent[SMB2_READ_HE]),
49487- atomic_read(&failed[SMB2_READ_HE]));
49488+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
49489+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
49490 seq_printf(m, "\nWrites: %d sent %d failed",
49491- atomic_read(&sent[SMB2_WRITE_HE]),
49492- atomic_read(&failed[SMB2_WRITE_HE]));
49493+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
49494+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
49495 seq_printf(m, "\nLocks: %d sent %d failed",
49496- atomic_read(&sent[SMB2_LOCK_HE]),
49497- atomic_read(&failed[SMB2_LOCK_HE]));
49498+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
49499+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
49500 seq_printf(m, "\nIOCTLs: %d sent %d failed",
49501- atomic_read(&sent[SMB2_IOCTL_HE]),
49502- atomic_read(&failed[SMB2_IOCTL_HE]));
49503+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
49504+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
49505 seq_printf(m, "\nCancels: %d sent %d failed",
49506- atomic_read(&sent[SMB2_CANCEL_HE]),
49507- atomic_read(&failed[SMB2_CANCEL_HE]));
49508+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
49509+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
49510 seq_printf(m, "\nEchos: %d sent %d failed",
49511- atomic_read(&sent[SMB2_ECHO_HE]),
49512- atomic_read(&failed[SMB2_ECHO_HE]));
49513+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
49514+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
49515 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
49516- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
49517- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
49518+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
49519+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
49520 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
49521- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
49522- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
49523+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
49524+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
49525 seq_printf(m, "\nQueryInfos: %d sent %d failed",
49526- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
49527- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
49528+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
49529+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
49530 seq_printf(m, "\nSetInfos: %d sent %d failed",
49531- atomic_read(&sent[SMB2_SET_INFO_HE]),
49532- atomic_read(&failed[SMB2_SET_INFO_HE]));
49533+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
49534+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
49535 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
49536- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
49537- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
49538+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
49539+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
49540 #endif
49541 }
49542
49543diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
49544index 41d9d07..dbb4772 100644
49545--- a/fs/cifs/smb2pdu.c
49546+++ b/fs/cifs/smb2pdu.c
49547@@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
49548 default:
49549 cERROR(1, "info level %u isn't supported",
49550 srch_inf->info_level);
49551- rc = -EINVAL;
49552- goto qdir_exit;
49553+ return -EINVAL;
49554 }
49555
49556 req->FileIndex = cpu_to_le32(index);
49557diff --git a/fs/coda/cache.c b/fs/coda/cache.c
49558index 958ae0e..505c9d0 100644
49559--- a/fs/coda/cache.c
49560+++ b/fs/coda/cache.c
49561@@ -24,7 +24,7 @@
49562 #include "coda_linux.h"
49563 #include "coda_cache.h"
49564
49565-static atomic_t permission_epoch = ATOMIC_INIT(0);
49566+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
49567
49568 /* replace or extend an acl cache hit */
49569 void coda_cache_enter(struct inode *inode, int mask)
49570@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
49571 struct coda_inode_info *cii = ITOC(inode);
49572
49573 spin_lock(&cii->c_lock);
49574- cii->c_cached_epoch = atomic_read(&permission_epoch);
49575+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
49576 if (cii->c_uid != current_fsuid()) {
49577 cii->c_uid = current_fsuid();
49578 cii->c_cached_perm = mask;
49579@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
49580 {
49581 struct coda_inode_info *cii = ITOC(inode);
49582 spin_lock(&cii->c_lock);
49583- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
49584+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
49585 spin_unlock(&cii->c_lock);
49586 }
49587
49588 /* remove all acl caches */
49589 void coda_cache_clear_all(struct super_block *sb)
49590 {
49591- atomic_inc(&permission_epoch);
49592+ atomic_inc_unchecked(&permission_epoch);
49593 }
49594
49595
49596@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
49597 spin_lock(&cii->c_lock);
49598 hit = (mask & cii->c_cached_perm) == mask &&
49599 cii->c_uid == current_fsuid() &&
49600- cii->c_cached_epoch == atomic_read(&permission_epoch);
49601+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
49602 spin_unlock(&cii->c_lock);
49603
49604 return hit;
49605diff --git a/fs/compat.c b/fs/compat.c
49606index a06dcbc..dacb6d3 100644
49607--- a/fs/compat.c
49608+++ b/fs/compat.c
49609@@ -54,7 +54,7 @@
49610 #include <asm/ioctls.h>
49611 #include "internal.h"
49612
49613-int compat_log = 1;
49614+int compat_log = 0;
49615
49616 int compat_printk(const char *fmt, ...)
49617 {
49618@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
49619
49620 set_fs(KERNEL_DS);
49621 /* The __user pointer cast is valid because of the set_fs() */
49622- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
49623+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
49624 set_fs(oldfs);
49625 /* truncating is ok because it's a user address */
49626 if (!ret)
49627@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
49628 goto out;
49629
49630 ret = -EINVAL;
49631- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
49632+ if (nr_segs > UIO_MAXIOV)
49633 goto out;
49634 if (nr_segs > fast_segs) {
49635 ret = -ENOMEM;
49636@@ -835,6 +835,7 @@ struct compat_old_linux_dirent {
49637
49638 struct compat_readdir_callback {
49639 struct compat_old_linux_dirent __user *dirent;
49640+ struct file * file;
49641 int result;
49642 };
49643
49644@@ -852,6 +853,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
49645 buf->result = -EOVERFLOW;
49646 return -EOVERFLOW;
49647 }
49648+
49649+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49650+ return 0;
49651+
49652 buf->result++;
49653 dirent = buf->dirent;
49654 if (!access_ok(VERIFY_WRITE, dirent,
49655@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
49656
49657 buf.result = 0;
49658 buf.dirent = dirent;
49659+ buf.file = f.file;
49660
49661 error = vfs_readdir(f.file, compat_fillonedir, &buf);
49662 if (buf.result)
49663@@ -901,6 +907,7 @@ struct compat_linux_dirent {
49664 struct compat_getdents_callback {
49665 struct compat_linux_dirent __user *current_dir;
49666 struct compat_linux_dirent __user *previous;
49667+ struct file * file;
49668 int count;
49669 int error;
49670 };
49671@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
49672 buf->error = -EOVERFLOW;
49673 return -EOVERFLOW;
49674 }
49675+
49676+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49677+ return 0;
49678+
49679 dirent = buf->previous;
49680 if (dirent) {
49681 if (__put_user(offset, &dirent->d_off))
49682@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49683 buf.previous = NULL;
49684 buf.count = count;
49685 buf.error = 0;
49686+ buf.file = f.file;
49687
49688 error = vfs_readdir(f.file, compat_filldir, &buf);
49689 if (error >= 0)
49690@@ -987,6 +999,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49691 struct compat_getdents_callback64 {
49692 struct linux_dirent64 __user *current_dir;
49693 struct linux_dirent64 __user *previous;
49694+ struct file * file;
49695 int count;
49696 int error;
49697 };
49698@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
49699 buf->error = -EINVAL; /* only used if we fail.. */
49700 if (reclen > buf->count)
49701 return -EINVAL;
49702+
49703+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49704+ return 0;
49705+
49706 dirent = buf->previous;
49707
49708 if (dirent) {
49709@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
49710 buf.previous = NULL;
49711 buf.count = count;
49712 buf.error = 0;
49713+ buf.file = f.file;
49714
49715 error = vfs_readdir(f.file, compat_filldir64, &buf);
49716 if (error >= 0)
49717 error = buf.error;
49718 lastdirent = buf.previous;
49719 if (lastdirent) {
49720- typeof(lastdirent->d_off) d_off = f.file->f_pos;
49721+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
49722 if (__put_user_unaligned(d_off, &lastdirent->d_off))
49723 error = -EFAULT;
49724 else
49725diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
49726index a81147e..20bf2b5 100644
49727--- a/fs/compat_binfmt_elf.c
49728+++ b/fs/compat_binfmt_elf.c
49729@@ -30,11 +30,13 @@
49730 #undef elf_phdr
49731 #undef elf_shdr
49732 #undef elf_note
49733+#undef elf_dyn
49734 #undef elf_addr_t
49735 #define elfhdr elf32_hdr
49736 #define elf_phdr elf32_phdr
49737 #define elf_shdr elf32_shdr
49738 #define elf_note elf32_note
49739+#define elf_dyn Elf32_Dyn
49740 #define elf_addr_t Elf32_Addr
49741
49742 /*
49743diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
49744index e2f57a0..3c78771 100644
49745--- a/fs/compat_ioctl.c
49746+++ b/fs/compat_ioctl.c
49747@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
49748 return -EFAULT;
49749 if (__get_user(udata, &ss32->iomem_base))
49750 return -EFAULT;
49751- ss.iomem_base = compat_ptr(udata);
49752+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
49753 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
49754 __get_user(ss.port_high, &ss32->port_high))
49755 return -EFAULT;
49756@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
49757 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
49758 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
49759 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
49760- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49761+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49762 return -EFAULT;
49763
49764 return ioctl_preallocate(file, p);
49765@@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
49766 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
49767 {
49768 unsigned int a, b;
49769- a = *(unsigned int *)p;
49770- b = *(unsigned int *)q;
49771+ a = *(const unsigned int *)p;
49772+ b = *(const unsigned int *)q;
49773 if (a > b)
49774 return 1;
49775 if (a < b)
49776diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
49777index 712b10f..c33c4ca 100644
49778--- a/fs/configfs/dir.c
49779+++ b/fs/configfs/dir.c
49780@@ -1037,10 +1037,11 @@ static int configfs_dump(struct configfs_dirent *sd, int level)
49781 static int configfs_depend_prep(struct dentry *origin,
49782 struct config_item *target)
49783 {
49784- struct configfs_dirent *child_sd, *sd = origin->d_fsdata;
49785+ struct configfs_dirent *child_sd, *sd;
49786 int ret = 0;
49787
49788- BUG_ON(!origin || !sd);
49789+ BUG_ON(!origin || !origin->d_fsdata);
49790+ sd = origin->d_fsdata;
49791
49792 if (sd->s_element == target) /* Boo-yah */
49793 goto out;
49794@@ -1564,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49795 }
49796 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
49797 struct configfs_dirent *next;
49798- const char * name;
49799+ const unsigned char * name;
49800+ char d_name[sizeof(next->s_dentry->d_iname)];
49801 int len;
49802 struct inode *inode = NULL;
49803
49804@@ -1574,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49805 continue;
49806
49807 name = configfs_get_name(next);
49808- len = strlen(name);
49809+ if (next->s_dentry && name == next->s_dentry->d_iname) {
49810+ len = next->s_dentry->d_name.len;
49811+ memcpy(d_name, name, len);
49812+ name = d_name;
49813+ } else
49814+ len = strlen(name);
49815
49816 /*
49817 * We'll have a dentry and an inode for
49818diff --git a/fs/coredump.c b/fs/coredump.c
49819index 1774932..5812106 100644
49820--- a/fs/coredump.c
49821+++ b/fs/coredump.c
49822@@ -52,7 +52,7 @@ struct core_name {
49823 char *corename;
49824 int used, size;
49825 };
49826-static atomic_t call_count = ATOMIC_INIT(1);
49827+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
49828
49829 /* The maximal length of core_pattern is also specified in sysctl.c */
49830
49831@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
49832 {
49833 char *old_corename = cn->corename;
49834
49835- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
49836+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
49837 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
49838
49839 if (!cn->corename) {
49840@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
49841 int pid_in_pattern = 0;
49842 int err = 0;
49843
49844- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
49845+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
49846 cn->corename = kmalloc(cn->size, GFP_KERNEL);
49847 cn->used = 0;
49848
49849@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
49850 pipe = file->f_path.dentry->d_inode->i_pipe;
49851
49852 pipe_lock(pipe);
49853- pipe->readers++;
49854- pipe->writers--;
49855+ atomic_inc(&pipe->readers);
49856+ atomic_dec(&pipe->writers);
49857
49858- while ((pipe->readers > 1) && (!signal_pending(current))) {
49859+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
49860 wake_up_interruptible_sync(&pipe->wait);
49861 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49862 pipe_wait(pipe);
49863 }
49864
49865- pipe->readers--;
49866- pipe->writers++;
49867+ atomic_dec(&pipe->readers);
49868+ atomic_inc(&pipe->writers);
49869 pipe_unlock(pipe);
49870
49871 }
49872@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
49873 int ispipe;
49874 struct files_struct *displaced;
49875 bool need_nonrelative = false;
49876- static atomic_t core_dump_count = ATOMIC_INIT(0);
49877+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
49878+ long signr = siginfo->si_signo;
49879 struct coredump_params cprm = {
49880 .siginfo = siginfo,
49881 .regs = signal_pt_regs(),
49882@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
49883 .mm_flags = mm->flags,
49884 };
49885
49886- audit_core_dumps(siginfo->si_signo);
49887+ audit_core_dumps(signr);
49888+
49889+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
49890+ gr_handle_brute_attach(cprm.mm_flags);
49891
49892 binfmt = mm->binfmt;
49893 if (!binfmt || !binfmt->core_dump)
49894@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
49895 need_nonrelative = true;
49896 }
49897
49898- retval = coredump_wait(siginfo->si_signo, &core_state);
49899+ retval = coredump_wait(signr, &core_state);
49900 if (retval < 0)
49901 goto fail_creds;
49902
49903@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
49904 }
49905 cprm.limit = RLIM_INFINITY;
49906
49907- dump_count = atomic_inc_return(&core_dump_count);
49908+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
49909 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
49910 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
49911 task_tgid_vnr(current), current->comm);
49912@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
49913 } else {
49914 struct inode *inode;
49915
49916+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
49917+
49918 if (cprm.limit < binfmt->min_coredump)
49919 goto fail_unlock;
49920
49921@@ -640,7 +646,7 @@ close_fail:
49922 filp_close(cprm.file, NULL);
49923 fail_dropcount:
49924 if (ispipe)
49925- atomic_dec(&core_dump_count);
49926+ atomic_dec_unchecked(&core_dump_count);
49927 fail_unlock:
49928 kfree(cn.corename);
49929 fail_corename:
49930@@ -659,7 +665,7 @@ fail:
49931 */
49932 int dump_write(struct file *file, const void *addr, int nr)
49933 {
49934- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
49935+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
49936 }
49937 EXPORT_SYMBOL(dump_write);
49938
49939diff --git a/fs/dcache.c b/fs/dcache.c
49940index 19153a0..5b71101 100644
49941--- a/fs/dcache.c
49942+++ b/fs/dcache.c
49943@@ -2552,7 +2552,6 @@ static int prepend_path(const struct path *path,
49944 bool slash = false;
49945 int error = 0;
49946
49947- br_read_lock(&vfsmount_lock);
49948 while (dentry != root->dentry || vfsmnt != root->mnt) {
49949 struct dentry * parent;
49950
49951@@ -2582,8 +2581,6 @@ static int prepend_path(const struct path *path,
49952 if (!error && !slash)
49953 error = prepend(buffer, buflen, "/", 1);
49954
49955-out:
49956- br_read_unlock(&vfsmount_lock);
49957 return error;
49958
49959 global_root:
49960@@ -2600,7 +2597,7 @@ global_root:
49961 error = prepend(buffer, buflen, "/", 1);
49962 if (!error)
49963 error = is_mounted(vfsmnt) ? 1 : 2;
49964- goto out;
49965+ return error;
49966 }
49967
49968 /**
49969@@ -2627,9 +2624,11 @@ char *__d_path(const struct path *path,
49970 int error;
49971
49972 prepend(&res, &buflen, "\0", 1);
49973+ br_read_lock(&vfsmount_lock);
49974 write_seqlock(&rename_lock);
49975 error = prepend_path(path, root, &res, &buflen);
49976 write_sequnlock(&rename_lock);
49977+ br_read_unlock(&vfsmount_lock);
49978
49979 if (error < 0)
49980 return ERR_PTR(error);
49981@@ -2646,9 +2645,11 @@ char *d_absolute_path(const struct path *path,
49982 int error;
49983
49984 prepend(&res, &buflen, "\0", 1);
49985+ br_read_lock(&vfsmount_lock);
49986 write_seqlock(&rename_lock);
49987 error = prepend_path(path, &root, &res, &buflen);
49988 write_sequnlock(&rename_lock);
49989+ br_read_unlock(&vfsmount_lock);
49990
49991 if (error > 1)
49992 error = -EINVAL;
49993@@ -2712,11 +2713,13 @@ char *d_path(const struct path *path, char *buf, int buflen)
49994 return path->dentry->d_op->d_dname(path->dentry, buf, buflen);
49995
49996 get_fs_root(current->fs, &root);
49997+ br_read_lock(&vfsmount_lock);
49998 write_seqlock(&rename_lock);
49999 error = path_with_deleted(path, &root, &res, &buflen);
50000+ write_sequnlock(&rename_lock);
50001+ br_read_unlock(&vfsmount_lock);
50002 if (error < 0)
50003 res = ERR_PTR(error);
50004- write_sequnlock(&rename_lock);
50005 path_put(&root);
50006 return res;
50007 }
50008@@ -2871,6 +2874,7 @@ SYSCALL_DEFINE2(getcwd, char __user *, buf, unsigned long, size)
50009 get_fs_root_and_pwd(current->fs, &root, &pwd);
50010
50011 error = -ENOENT;
50012+ br_read_lock(&vfsmount_lock);
50013 write_seqlock(&rename_lock);
50014 if (!d_unlinked(pwd.dentry)) {
50015 unsigned long len;
50016@@ -2880,6 +2884,7 @@ SYSCALL_DEFINE2(getcwd, char __user *, buf, unsigned long, size)
50017 prepend(&cwd, &buflen, "\0", 1);
50018 error = prepend_path(&pwd, &root, &cwd, &buflen);
50019 write_sequnlock(&rename_lock);
50020+ br_read_unlock(&vfsmount_lock);
50021
50022 if (error < 0)
50023 goto out;
50024@@ -2900,6 +2905,7 @@ SYSCALL_DEFINE2(getcwd, char __user *, buf, unsigned long, size)
50025 }
50026 } else {
50027 write_sequnlock(&rename_lock);
50028+ br_read_unlock(&vfsmount_lock);
50029 }
50030
50031 out:
50032@@ -3133,7 +3139,7 @@ void __init vfs_caches_init(unsigned long mempages)
50033 mempages -= reserve;
50034
50035 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
50036- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
50037+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
50038
50039 dcache_init();
50040 inode_init();
50041diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
50042index a5f12b7..4ee8a6f 100644
50043--- a/fs/debugfs/inode.c
50044+++ b/fs/debugfs/inode.c
50045@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
50046 */
50047 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
50048 {
50049+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50050+ return __create_file(name, S_IFDIR | S_IRWXU,
50051+#else
50052 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
50053+#endif
50054 parent, NULL, NULL);
50055 }
50056 EXPORT_SYMBOL_GPL(debugfs_create_dir);
50057diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
50058index cc7709e..7e7211f 100644
50059--- a/fs/ecryptfs/inode.c
50060+++ b/fs/ecryptfs/inode.c
50061@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
50062 old_fs = get_fs();
50063 set_fs(get_ds());
50064 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
50065- (char __user *)lower_buf,
50066+ (char __force_user *)lower_buf,
50067 PATH_MAX);
50068 set_fs(old_fs);
50069 if (rc < 0)
50070@@ -706,7 +706,7 @@ out:
50071 static void
50072 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
50073 {
50074- char *buf = nd_get_link(nd);
50075+ const char *buf = nd_get_link(nd);
50076 if (!IS_ERR(buf)) {
50077 /* Free the char* */
50078 kfree(buf);
50079diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
50080index 412e6ed..4292d22 100644
50081--- a/fs/ecryptfs/miscdev.c
50082+++ b/fs/ecryptfs/miscdev.c
50083@@ -315,7 +315,7 @@ check_list:
50084 goto out_unlock_msg_ctx;
50085 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
50086 if (msg_ctx->msg) {
50087- if (copy_to_user(&buf[i], packet_length, packet_length_size))
50088+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
50089 goto out_unlock_msg_ctx;
50090 i += packet_length_size;
50091 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
50092diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
50093index b2a34a1..162fa69 100644
50094--- a/fs/ecryptfs/read_write.c
50095+++ b/fs/ecryptfs/read_write.c
50096@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
50097 return -EIO;
50098 fs_save = get_fs();
50099 set_fs(get_ds());
50100- rc = vfs_write(lower_file, data, size, &offset);
50101+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
50102 set_fs(fs_save);
50103 mark_inode_dirty_sync(ecryptfs_inode);
50104 return rc;
50105@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
50106 return -EIO;
50107 fs_save = get_fs();
50108 set_fs(get_ds());
50109- rc = vfs_read(lower_file, data, size, &offset);
50110+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
50111 set_fs(fs_save);
50112 return rc;
50113 }
50114diff --git a/fs/exec.c b/fs/exec.c
50115index 20df02c..1b1d946 100644
50116--- a/fs/exec.c
50117+++ b/fs/exec.c
50118@@ -55,6 +55,17 @@
50119 #include <linux/pipe_fs_i.h>
50120 #include <linux/oom.h>
50121 #include <linux/compat.h>
50122+#include <linux/random.h>
50123+#include <linux/seq_file.h>
50124+#include <linux/coredump.h>
50125+#include <linux/mman.h>
50126+
50127+#ifdef CONFIG_PAX_REFCOUNT
50128+#include <linux/kallsyms.h>
50129+#include <linux/kdebug.h>
50130+#endif
50131+
50132+#include <trace/events/fs.h>
50133
50134 #include <asm/uaccess.h>
50135 #include <asm/mmu_context.h>
50136@@ -66,6 +77,18 @@
50137
50138 #include <trace/events/sched.h>
50139
50140+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
50141+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
50142+{
50143+ 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");
50144+}
50145+#endif
50146+
50147+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
50148+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
50149+EXPORT_SYMBOL(pax_set_initial_flags_func);
50150+#endif
50151+
50152 int suid_dumpable = 0;
50153
50154 static LIST_HEAD(formats);
50155@@ -75,8 +98,8 @@ void __register_binfmt(struct linux_binfmt * fmt, int insert)
50156 {
50157 BUG_ON(!fmt);
50158 write_lock(&binfmt_lock);
50159- insert ? list_add(&fmt->lh, &formats) :
50160- list_add_tail(&fmt->lh, &formats);
50161+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
50162+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
50163 write_unlock(&binfmt_lock);
50164 }
50165
50166@@ -85,7 +108,7 @@ EXPORT_SYMBOL(__register_binfmt);
50167 void unregister_binfmt(struct linux_binfmt * fmt)
50168 {
50169 write_lock(&binfmt_lock);
50170- list_del(&fmt->lh);
50171+ pax_list_del((struct list_head *)&fmt->lh);
50172 write_unlock(&binfmt_lock);
50173 }
50174
50175@@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50176 int write)
50177 {
50178 struct page *page;
50179- int ret;
50180
50181-#ifdef CONFIG_STACK_GROWSUP
50182- if (write) {
50183- ret = expand_downwards(bprm->vma, pos);
50184- if (ret < 0)
50185- return NULL;
50186- }
50187-#endif
50188- ret = get_user_pages(current, bprm->mm, pos,
50189- 1, write, 1, &page, NULL);
50190- if (ret <= 0)
50191+ if (0 > expand_downwards(bprm->vma, pos))
50192+ return NULL;
50193+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
50194 return NULL;
50195
50196 if (write) {
50197@@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50198 if (size <= ARG_MAX)
50199 return page;
50200
50201+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50202+ // only allow 512KB for argv+env on suid/sgid binaries
50203+ // to prevent easy ASLR exhaustion
50204+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
50205+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
50206+ (size > (512 * 1024))) {
50207+ put_page(page);
50208+ return NULL;
50209+ }
50210+#endif
50211+
50212 /*
50213 * Limit to 1/4-th the stack size for the argv+env strings.
50214 * This ensures that:
50215@@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50216 vma->vm_end = STACK_TOP_MAX;
50217 vma->vm_start = vma->vm_end - PAGE_SIZE;
50218 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
50219+
50220+#ifdef CONFIG_PAX_SEGMEXEC
50221+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
50222+#endif
50223+
50224 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
50225 INIT_LIST_HEAD(&vma->anon_vma_chain);
50226
50227@@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50228 mm->stack_vm = mm->total_vm = 1;
50229 up_write(&mm->mmap_sem);
50230 bprm->p = vma->vm_end - sizeof(void *);
50231+
50232+#ifdef CONFIG_PAX_RANDUSTACK
50233+ if (randomize_va_space)
50234+ bprm->p ^= random32() & ~PAGE_MASK;
50235+#endif
50236+
50237 return 0;
50238 err:
50239 up_write(&mm->mmap_sem);
50240@@ -396,7 +433,7 @@ struct user_arg_ptr {
50241 } ptr;
50242 };
50243
50244-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50245+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50246 {
50247 const char __user *native;
50248
50249@@ -405,14 +442,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50250 compat_uptr_t compat;
50251
50252 if (get_user(compat, argv.ptr.compat + nr))
50253- return ERR_PTR(-EFAULT);
50254+ return (const char __force_user *)ERR_PTR(-EFAULT);
50255
50256 return compat_ptr(compat);
50257 }
50258 #endif
50259
50260 if (get_user(native, argv.ptr.native + nr))
50261- return ERR_PTR(-EFAULT);
50262+ return (const char __force_user *)ERR_PTR(-EFAULT);
50263
50264 return native;
50265 }
50266@@ -431,7 +468,7 @@ static int count(struct user_arg_ptr argv, int max)
50267 if (!p)
50268 break;
50269
50270- if (IS_ERR(p))
50271+ if (IS_ERR((const char __force_kernel *)p))
50272 return -EFAULT;
50273
50274 if (i >= max)
50275@@ -466,7 +503,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
50276
50277 ret = -EFAULT;
50278 str = get_user_arg_ptr(argv, argc);
50279- if (IS_ERR(str))
50280+ if (IS_ERR((const char __force_kernel *)str))
50281 goto out;
50282
50283 len = strnlen_user(str, MAX_ARG_STRLEN);
50284@@ -548,7 +585,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
50285 int r;
50286 mm_segment_t oldfs = get_fs();
50287 struct user_arg_ptr argv = {
50288- .ptr.native = (const char __user *const __user *)__argv,
50289+ .ptr.native = (const char __force_user *const __force_user *)__argv,
50290 };
50291
50292 set_fs(KERNEL_DS);
50293@@ -583,7 +620,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50294 unsigned long new_end = old_end - shift;
50295 struct mmu_gather tlb;
50296
50297- BUG_ON(new_start > new_end);
50298+ if (new_start >= new_end || new_start < mmap_min_addr)
50299+ return -ENOMEM;
50300
50301 /*
50302 * ensure there are no vmas between where we want to go
50303@@ -592,6 +630,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50304 if (vma != find_vma(mm, new_start))
50305 return -EFAULT;
50306
50307+#ifdef CONFIG_PAX_SEGMEXEC
50308+ BUG_ON(pax_find_mirror_vma(vma));
50309+#endif
50310+
50311 /*
50312 * cover the whole range: [new_start, old_end)
50313 */
50314@@ -672,10 +714,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50315 stack_top = arch_align_stack(stack_top);
50316 stack_top = PAGE_ALIGN(stack_top);
50317
50318- if (unlikely(stack_top < mmap_min_addr) ||
50319- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
50320- return -ENOMEM;
50321-
50322 stack_shift = vma->vm_end - stack_top;
50323
50324 bprm->p -= stack_shift;
50325@@ -687,8 +725,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
50326 bprm->exec -= stack_shift;
50327
50328 down_write(&mm->mmap_sem);
50329+
50330+ /* Move stack pages down in memory. */
50331+ if (stack_shift) {
50332+ ret = shift_arg_pages(vma, stack_shift);
50333+ if (ret)
50334+ goto out_unlock;
50335+ }
50336+
50337 vm_flags = VM_STACK_FLAGS;
50338
50339+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50340+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
50341+ vm_flags &= ~VM_EXEC;
50342+
50343+#ifdef CONFIG_PAX_MPROTECT
50344+ if (mm->pax_flags & MF_PAX_MPROTECT)
50345+ vm_flags &= ~VM_MAYEXEC;
50346+#endif
50347+
50348+ }
50349+#endif
50350+
50351 /*
50352 * Adjust stack execute permissions; explicitly enable for
50353 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
50354@@ -707,13 +765,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50355 goto out_unlock;
50356 BUG_ON(prev != vma);
50357
50358- /* Move stack pages down in memory. */
50359- if (stack_shift) {
50360- ret = shift_arg_pages(vma, stack_shift);
50361- if (ret)
50362- goto out_unlock;
50363- }
50364-
50365 /* mprotect_fixup is overkill to remove the temporary stack flags */
50366 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
50367
50368@@ -737,6 +788,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
50369 #endif
50370 current->mm->start_stack = bprm->p;
50371 ret = expand_stack(vma, stack_base);
50372+
50373+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
50374+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
50375+ unsigned long size, flags, vm_flags;
50376+
50377+ size = STACK_TOP - vma->vm_end;
50378+ flags = MAP_FIXED | MAP_PRIVATE;
50379+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
50380+
50381+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
50382+
50383+#ifdef CONFIG_X86
50384+ if (!ret) {
50385+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
50386+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), flags, vm_flags, 0);
50387+ }
50388+#endif
50389+
50390+ }
50391+#endif
50392+
50393 if (ret)
50394 ret = -EFAULT;
50395
50396@@ -772,6 +844,8 @@ struct file *open_exec(const char *name)
50397
50398 fsnotify_open(file);
50399
50400+ trace_open_exec(name);
50401+
50402 err = deny_write_access(file);
50403 if (err)
50404 goto exit;
50405@@ -795,7 +869,7 @@ int kernel_read(struct file *file, loff_t offset,
50406 old_fs = get_fs();
50407 set_fs(get_ds());
50408 /* The cast to a user pointer is valid due to the set_fs() */
50409- result = vfs_read(file, (void __user *)addr, count, &pos);
50410+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
50411 set_fs(old_fs);
50412 return result;
50413 }
50414@@ -1247,7 +1321,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
50415 }
50416 rcu_read_unlock();
50417
50418- if (p->fs->users > n_fs) {
50419+ if (atomic_read(&p->fs->users) > n_fs) {
50420 bprm->unsafe |= LSM_UNSAFE_SHARE;
50421 } else {
50422 res = -EAGAIN;
50423@@ -1447,6 +1521,31 @@ int search_binary_handler(struct linux_binprm *bprm)
50424
50425 EXPORT_SYMBOL(search_binary_handler);
50426
50427+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50428+static DEFINE_PER_CPU(u64, exec_counter);
50429+static int __init init_exec_counters(void)
50430+{
50431+ unsigned int cpu;
50432+
50433+ for_each_possible_cpu(cpu) {
50434+ per_cpu(exec_counter, cpu) = (u64)cpu;
50435+ }
50436+
50437+ return 0;
50438+}
50439+early_initcall(init_exec_counters);
50440+static inline void increment_exec_counter(void)
50441+{
50442+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
50443+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
50444+}
50445+#else
50446+static inline void increment_exec_counter(void) {}
50447+#endif
50448+
50449+extern void gr_handle_exec_args(struct linux_binprm *bprm,
50450+ struct user_arg_ptr argv);
50451+
50452 /*
50453 * sys_execve() executes a new program.
50454 */
50455@@ -1454,6 +1553,11 @@ static int do_execve_common(const char *filename,
50456 struct user_arg_ptr argv,
50457 struct user_arg_ptr envp)
50458 {
50459+#ifdef CONFIG_GRKERNSEC
50460+ struct file *old_exec_file;
50461+ struct acl_subject_label *old_acl;
50462+ struct rlimit old_rlim[RLIM_NLIMITS];
50463+#endif
50464 struct linux_binprm *bprm;
50465 struct file *file;
50466 struct files_struct *displaced;
50467@@ -1461,6 +1565,8 @@ static int do_execve_common(const char *filename,
50468 int retval;
50469 const struct cred *cred = current_cred();
50470
50471+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
50472+
50473 /*
50474 * We move the actual failure in case of RLIMIT_NPROC excess from
50475 * set*uid() to execve() because too many poorly written programs
50476@@ -1501,12 +1607,27 @@ static int do_execve_common(const char *filename,
50477 if (IS_ERR(file))
50478 goto out_unmark;
50479
50480+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
50481+ retval = -EPERM;
50482+ goto out_file;
50483+ }
50484+
50485 sched_exec();
50486
50487 bprm->file = file;
50488 bprm->filename = filename;
50489 bprm->interp = filename;
50490
50491+ if (gr_process_user_ban()) {
50492+ retval = -EPERM;
50493+ goto out_file;
50494+ }
50495+
50496+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
50497+ retval = -EACCES;
50498+ goto out_file;
50499+ }
50500+
50501 retval = bprm_mm_init(bprm);
50502 if (retval)
50503 goto out_file;
50504@@ -1523,24 +1644,65 @@ static int do_execve_common(const char *filename,
50505 if (retval < 0)
50506 goto out;
50507
50508+#ifdef CONFIG_GRKERNSEC
50509+ old_acl = current->acl;
50510+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
50511+ old_exec_file = current->exec_file;
50512+ get_file(file);
50513+ current->exec_file = file;
50514+#endif
50515+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50516+ /* limit suid stack to 8MB
50517+ * we saved the old limits above and will restore them if this exec fails
50518+ */
50519+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
50520+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
50521+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
50522+#endif
50523+
50524+ if (!gr_tpe_allow(file)) {
50525+ retval = -EACCES;
50526+ goto out_fail;
50527+ }
50528+
50529+ if (gr_check_crash_exec(file)) {
50530+ retval = -EACCES;
50531+ goto out_fail;
50532+ }
50533+
50534+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
50535+ bprm->unsafe);
50536+ if (retval < 0)
50537+ goto out_fail;
50538+
50539 retval = copy_strings_kernel(1, &bprm->filename, bprm);
50540 if (retval < 0)
50541- goto out;
50542+ goto out_fail;
50543
50544 bprm->exec = bprm->p;
50545 retval = copy_strings(bprm->envc, envp, bprm);
50546 if (retval < 0)
50547- goto out;
50548+ goto out_fail;
50549
50550 retval = copy_strings(bprm->argc, argv, bprm);
50551 if (retval < 0)
50552- goto out;
50553+ goto out_fail;
50554+
50555+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
50556+
50557+ gr_handle_exec_args(bprm, argv);
50558
50559 retval = search_binary_handler(bprm);
50560 if (retval < 0)
50561- goto out;
50562+ goto out_fail;
50563+#ifdef CONFIG_GRKERNSEC
50564+ if (old_exec_file)
50565+ fput(old_exec_file);
50566+#endif
50567
50568 /* execve succeeded */
50569+
50570+ increment_exec_counter();
50571 current->fs->in_exec = 0;
50572 current->in_execve = 0;
50573 acct_update_integrals(current);
50574@@ -1549,6 +1711,14 @@ static int do_execve_common(const char *filename,
50575 put_files_struct(displaced);
50576 return retval;
50577
50578+out_fail:
50579+#ifdef CONFIG_GRKERNSEC
50580+ current->acl = old_acl;
50581+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
50582+ fput(current->exec_file);
50583+ current->exec_file = old_exec_file;
50584+#endif
50585+
50586 out:
50587 if (bprm->mm) {
50588 acct_arg_size(bprm, 0);
50589@@ -1697,3 +1867,253 @@ asmlinkage long compat_sys_execve(const char __user * filename,
50590 return error;
50591 }
50592 #endif
50593+
50594+int pax_check_flags(unsigned long *flags)
50595+{
50596+ int retval = 0;
50597+
50598+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
50599+ if (*flags & MF_PAX_SEGMEXEC)
50600+ {
50601+ *flags &= ~MF_PAX_SEGMEXEC;
50602+ retval = -EINVAL;
50603+ }
50604+#endif
50605+
50606+ if ((*flags & MF_PAX_PAGEEXEC)
50607+
50608+#ifdef CONFIG_PAX_PAGEEXEC
50609+ && (*flags & MF_PAX_SEGMEXEC)
50610+#endif
50611+
50612+ )
50613+ {
50614+ *flags &= ~MF_PAX_PAGEEXEC;
50615+ retval = -EINVAL;
50616+ }
50617+
50618+ if ((*flags & MF_PAX_MPROTECT)
50619+
50620+#ifdef CONFIG_PAX_MPROTECT
50621+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50622+#endif
50623+
50624+ )
50625+ {
50626+ *flags &= ~MF_PAX_MPROTECT;
50627+ retval = -EINVAL;
50628+ }
50629+
50630+ if ((*flags & MF_PAX_EMUTRAMP)
50631+
50632+#ifdef CONFIG_PAX_EMUTRAMP
50633+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50634+#endif
50635+
50636+ )
50637+ {
50638+ *flags &= ~MF_PAX_EMUTRAMP;
50639+ retval = -EINVAL;
50640+ }
50641+
50642+ return retval;
50643+}
50644+
50645+EXPORT_SYMBOL(pax_check_flags);
50646+
50647+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50648+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
50649+{
50650+ struct task_struct *tsk = current;
50651+ struct mm_struct *mm = current->mm;
50652+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
50653+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
50654+ char *path_exec = NULL;
50655+ char *path_fault = NULL;
50656+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
50657+ siginfo_t info = { };
50658+
50659+ if (buffer_exec && buffer_fault) {
50660+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
50661+
50662+ down_read(&mm->mmap_sem);
50663+ vma = mm->mmap;
50664+ while (vma && (!vma_exec || !vma_fault)) {
50665+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
50666+ vma_exec = vma;
50667+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
50668+ vma_fault = vma;
50669+ vma = vma->vm_next;
50670+ }
50671+ if (vma_exec) {
50672+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
50673+ if (IS_ERR(path_exec))
50674+ path_exec = "<path too long>";
50675+ else {
50676+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
50677+ if (path_exec) {
50678+ *path_exec = 0;
50679+ path_exec = buffer_exec;
50680+ } else
50681+ path_exec = "<path too long>";
50682+ }
50683+ }
50684+ if (vma_fault) {
50685+ start = vma_fault->vm_start;
50686+ end = vma_fault->vm_end;
50687+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
50688+ if (vma_fault->vm_file) {
50689+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
50690+ if (IS_ERR(path_fault))
50691+ path_fault = "<path too long>";
50692+ else {
50693+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
50694+ if (path_fault) {
50695+ *path_fault = 0;
50696+ path_fault = buffer_fault;
50697+ } else
50698+ path_fault = "<path too long>";
50699+ }
50700+ } else
50701+ path_fault = "<anonymous mapping>";
50702+ }
50703+ up_read(&mm->mmap_sem);
50704+ }
50705+ if (tsk->signal->curr_ip)
50706+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
50707+ else
50708+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
50709+ 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),
50710+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
50711+ free_page((unsigned long)buffer_exec);
50712+ free_page((unsigned long)buffer_fault);
50713+ pax_report_insns(regs, pc, sp);
50714+ info.si_signo = SIGKILL;
50715+ info.si_errno = 0;
50716+ info.si_code = SI_KERNEL;
50717+ info.si_pid = 0;
50718+ info.si_uid = 0;
50719+ do_coredump(&info);
50720+}
50721+#endif
50722+
50723+#ifdef CONFIG_PAX_REFCOUNT
50724+void pax_report_refcount_overflow(struct pt_regs *regs)
50725+{
50726+ if (current->signal->curr_ip)
50727+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
50728+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
50729+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
50730+ else
50731+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
50732+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
50733+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
50734+ show_regs(regs);
50735+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
50736+}
50737+#endif
50738+
50739+#ifdef CONFIG_PAX_USERCOPY
50740+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
50741+static noinline int check_stack_object(const void *obj, unsigned long len)
50742+{
50743+ const void * const stack = task_stack_page(current);
50744+ const void * const stackend = stack + THREAD_SIZE;
50745+
50746+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50747+ const void *frame = NULL;
50748+ const void *oldframe;
50749+#endif
50750+
50751+ if (obj + len < obj)
50752+ return -1;
50753+
50754+ if (obj + len <= stack || stackend <= obj)
50755+ return 0;
50756+
50757+ if (obj < stack || stackend < obj + len)
50758+ return -1;
50759+
50760+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50761+ oldframe = __builtin_frame_address(1);
50762+ if (oldframe)
50763+ frame = __builtin_frame_address(2);
50764+ /*
50765+ low ----------------------------------------------> high
50766+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
50767+ ^----------------^
50768+ allow copies only within here
50769+ */
50770+ while (stack <= frame && frame < stackend) {
50771+ /* if obj + len extends past the last frame, this
50772+ check won't pass and the next frame will be 0,
50773+ causing us to bail out and correctly report
50774+ the copy as invalid
50775+ */
50776+ if (obj + len <= frame)
50777+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
50778+ oldframe = frame;
50779+ frame = *(const void * const *)frame;
50780+ }
50781+ return -1;
50782+#else
50783+ return 1;
50784+#endif
50785+}
50786+
50787+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
50788+{
50789+ if (current->signal->curr_ip)
50790+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50791+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
50792+ else
50793+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50794+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
50795+ dump_stack();
50796+ gr_handle_kernel_exploit();
50797+ do_group_exit(SIGKILL);
50798+}
50799+#endif
50800+
50801+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
50802+{
50803+
50804+#ifdef CONFIG_PAX_USERCOPY
50805+ const char *type;
50806+
50807+ if (!n)
50808+ return;
50809+
50810+ type = check_heap_object(ptr, n);
50811+ if (!type) {
50812+ if (check_stack_object(ptr, n) != -1)
50813+ return;
50814+ type = "<process stack>";
50815+ }
50816+
50817+ pax_report_usercopy(ptr, n, to_user, type);
50818+#endif
50819+
50820+}
50821+EXPORT_SYMBOL(__check_object_size);
50822+
50823+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
50824+void pax_track_stack(void)
50825+{
50826+ unsigned long sp = (unsigned long)&sp;
50827+ if (sp < current_thread_info()->lowest_stack &&
50828+ sp > (unsigned long)task_stack_page(current))
50829+ current_thread_info()->lowest_stack = sp;
50830+}
50831+EXPORT_SYMBOL(pax_track_stack);
50832+#endif
50833+
50834+#ifdef CONFIG_PAX_SIZE_OVERFLOW
50835+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
50836+{
50837+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
50838+ dump_stack();
50839+ do_group_exit(SIGKILL);
50840+}
50841+EXPORT_SYMBOL(report_size_overflow);
50842+#endif
50843diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
50844index 2616d0e..2ffdec9 100644
50845--- a/fs/ext2/balloc.c
50846+++ b/fs/ext2/balloc.c
50847@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
50848
50849 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50850 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50851- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50852+ if (free_blocks < root_blocks + 1 &&
50853 !uid_eq(sbi->s_resuid, current_fsuid()) &&
50854 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50855- !in_group_p (sbi->s_resgid))) {
50856+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50857 return 0;
50858 }
50859 return 1;
50860diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
50861index 22548f5..41521d8 100644
50862--- a/fs/ext3/balloc.c
50863+++ b/fs/ext3/balloc.c
50864@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
50865
50866 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50867 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50868- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50869+ if (free_blocks < root_blocks + 1 &&
50870 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
50871 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50872- !in_group_p (sbi->s_resgid))) {
50873+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50874 return 0;
50875 }
50876 return 1;
50877diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
50878index 92e68b3..115d987 100644
50879--- a/fs/ext4/balloc.c
50880+++ b/fs/ext4/balloc.c
50881@@ -505,8 +505,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
50882 /* Hm, nope. Are (enough) root reserved clusters available? */
50883 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
50884 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
50885- capable(CAP_SYS_RESOURCE) ||
50886- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
50887+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
50888+ capable_nolog(CAP_SYS_RESOURCE)) {
50889
50890 if (free_clusters >= (nclusters + dirty_clusters))
50891 return 1;
50892diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
50893index bbcd6a0..2824592 100644
50894--- a/fs/ext4/ext4.h
50895+++ b/fs/ext4/ext4.h
50896@@ -1265,19 +1265,19 @@ struct ext4_sb_info {
50897 unsigned long s_mb_last_start;
50898
50899 /* stats for buddy allocator */
50900- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
50901- atomic_t s_bal_success; /* we found long enough chunks */
50902- atomic_t s_bal_allocated; /* in blocks */
50903- atomic_t s_bal_ex_scanned; /* total extents scanned */
50904- atomic_t s_bal_goals; /* goal hits */
50905- atomic_t s_bal_breaks; /* too long searches */
50906- atomic_t s_bal_2orders; /* 2^order hits */
50907+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
50908+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
50909+ atomic_unchecked_t s_bal_allocated; /* in blocks */
50910+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
50911+ atomic_unchecked_t s_bal_goals; /* goal hits */
50912+ atomic_unchecked_t s_bal_breaks; /* too long searches */
50913+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
50914 spinlock_t s_bal_lock;
50915 unsigned long s_mb_buddies_generated;
50916 unsigned long long s_mb_generation_time;
50917- atomic_t s_mb_lost_chunks;
50918- atomic_t s_mb_preallocated;
50919- atomic_t s_mb_discarded;
50920+ atomic_unchecked_t s_mb_lost_chunks;
50921+ atomic_unchecked_t s_mb_preallocated;
50922+ atomic_unchecked_t s_mb_discarded;
50923 atomic_t s_lock_busy;
50924
50925 /* locality groups */
50926diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
50927index 82f8c2d..ce7c889 100644
50928--- a/fs/ext4/mballoc.c
50929+++ b/fs/ext4/mballoc.c
50930@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
50931 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
50932
50933 if (EXT4_SB(sb)->s_mb_stats)
50934- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
50935+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
50936
50937 break;
50938 }
50939@@ -2044,7 +2044,7 @@ repeat:
50940 ac->ac_status = AC_STATUS_CONTINUE;
50941 ac->ac_flags |= EXT4_MB_HINT_FIRST;
50942 cr = 3;
50943- atomic_inc(&sbi->s_mb_lost_chunks);
50944+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
50945 goto repeat;
50946 }
50947 }
50948@@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
50949 if (sbi->s_mb_stats) {
50950 ext4_msg(sb, KERN_INFO,
50951 "mballoc: %u blocks %u reqs (%u success)",
50952- atomic_read(&sbi->s_bal_allocated),
50953- atomic_read(&sbi->s_bal_reqs),
50954- atomic_read(&sbi->s_bal_success));
50955+ atomic_read_unchecked(&sbi->s_bal_allocated),
50956+ atomic_read_unchecked(&sbi->s_bal_reqs),
50957+ atomic_read_unchecked(&sbi->s_bal_success));
50958 ext4_msg(sb, KERN_INFO,
50959 "mballoc: %u extents scanned, %u goal hits, "
50960 "%u 2^N hits, %u breaks, %u lost",
50961- atomic_read(&sbi->s_bal_ex_scanned),
50962- atomic_read(&sbi->s_bal_goals),
50963- atomic_read(&sbi->s_bal_2orders),
50964- atomic_read(&sbi->s_bal_breaks),
50965- atomic_read(&sbi->s_mb_lost_chunks));
50966+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
50967+ atomic_read_unchecked(&sbi->s_bal_goals),
50968+ atomic_read_unchecked(&sbi->s_bal_2orders),
50969+ atomic_read_unchecked(&sbi->s_bal_breaks),
50970+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
50971 ext4_msg(sb, KERN_INFO,
50972 "mballoc: %lu generated and it took %Lu",
50973 sbi->s_mb_buddies_generated,
50974 sbi->s_mb_generation_time);
50975 ext4_msg(sb, KERN_INFO,
50976 "mballoc: %u preallocated, %u discarded",
50977- atomic_read(&sbi->s_mb_preallocated),
50978- atomic_read(&sbi->s_mb_discarded));
50979+ atomic_read_unchecked(&sbi->s_mb_preallocated),
50980+ atomic_read_unchecked(&sbi->s_mb_discarded));
50981 }
50982
50983 free_percpu(sbi->s_locality_groups);
50984@@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
50985 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
50986
50987 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
50988- atomic_inc(&sbi->s_bal_reqs);
50989- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50990+ atomic_inc_unchecked(&sbi->s_bal_reqs);
50991+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50992 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
50993- atomic_inc(&sbi->s_bal_success);
50994- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
50995+ atomic_inc_unchecked(&sbi->s_bal_success);
50996+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
50997 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
50998 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
50999- atomic_inc(&sbi->s_bal_goals);
51000+ atomic_inc_unchecked(&sbi->s_bal_goals);
51001 if (ac->ac_found > sbi->s_mb_max_to_scan)
51002- atomic_inc(&sbi->s_bal_breaks);
51003+ atomic_inc_unchecked(&sbi->s_bal_breaks);
51004 }
51005
51006 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
51007@@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
51008 trace_ext4_mb_new_inode_pa(ac, pa);
51009
51010 ext4_mb_use_inode_pa(ac, pa);
51011- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
51012+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
51013
51014 ei = EXT4_I(ac->ac_inode);
51015 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51016@@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
51017 trace_ext4_mb_new_group_pa(ac, pa);
51018
51019 ext4_mb_use_group_pa(ac, pa);
51020- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51021+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51022
51023 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51024 lg = ac->ac_lg;
51025@@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
51026 * from the bitmap and continue.
51027 */
51028 }
51029- atomic_add(free, &sbi->s_mb_discarded);
51030+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
51031
51032 return err;
51033 }
51034@@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
51035 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
51036 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
51037 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
51038- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51039+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51040 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
51041
51042 return 0;
51043diff --git a/fs/ext4/super.c b/fs/ext4/super.c
51044index 24c767d..893aa55 100644
51045--- a/fs/ext4/super.c
51046+++ b/fs/ext4/super.c
51047@@ -2429,7 +2429,7 @@ struct ext4_attr {
51048 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
51049 const char *, size_t);
51050 int offset;
51051-};
51052+} __do_const;
51053
51054 static int parse_strtoul(const char *buf,
51055 unsigned long max, unsigned long *value)
51056diff --git a/fs/fcntl.c b/fs/fcntl.c
51057index 71a600a..20d87b1 100644
51058--- a/fs/fcntl.c
51059+++ b/fs/fcntl.c
51060@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
51061 if (err)
51062 return err;
51063
51064+ if (gr_handle_chroot_fowner(pid, type))
51065+ return -ENOENT;
51066+ if (gr_check_protected_task_fowner(pid, type))
51067+ return -EACCES;
51068+
51069 f_modown(filp, pid, type, force);
51070 return 0;
51071 }
51072diff --git a/fs/fhandle.c b/fs/fhandle.c
51073index 999ff5c..41f4109 100644
51074--- a/fs/fhandle.c
51075+++ b/fs/fhandle.c
51076@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
51077 } else
51078 retval = 0;
51079 /* copy the mount id */
51080- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
51081- sizeof(*mnt_id)) ||
51082+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
51083 copy_to_user(ufh, handle,
51084 sizeof(struct file_handle) + handle_bytes))
51085 retval = -EFAULT;
51086diff --git a/fs/fifo.c b/fs/fifo.c
51087index cf6f434..3d7942c 100644
51088--- a/fs/fifo.c
51089+++ b/fs/fifo.c
51090@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
51091 */
51092 filp->f_op = &read_pipefifo_fops;
51093 pipe->r_counter++;
51094- if (pipe->readers++ == 0)
51095+ if (atomic_inc_return(&pipe->readers) == 1)
51096 wake_up_partner(inode);
51097
51098- if (!pipe->writers) {
51099+ if (!atomic_read(&pipe->writers)) {
51100 if ((filp->f_flags & O_NONBLOCK)) {
51101 /* suppress POLLHUP until we have
51102 * seen a writer */
51103@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
51104 * errno=ENXIO when there is no process reading the FIFO.
51105 */
51106 ret = -ENXIO;
51107- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
51108+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
51109 goto err;
51110
51111 filp->f_op = &write_pipefifo_fops;
51112 pipe->w_counter++;
51113- if (!pipe->writers++)
51114+ if (atomic_inc_return(&pipe->writers) == 1)
51115 wake_up_partner(inode);
51116
51117- if (!pipe->readers) {
51118+ if (!atomic_read(&pipe->readers)) {
51119 if (wait_for_partner(inode, &pipe->r_counter))
51120 goto err_wr;
51121 }
51122@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
51123 */
51124 filp->f_op = &rdwr_pipefifo_fops;
51125
51126- pipe->readers++;
51127- pipe->writers++;
51128+ atomic_inc(&pipe->readers);
51129+ atomic_inc(&pipe->writers);
51130 pipe->r_counter++;
51131 pipe->w_counter++;
51132- if (pipe->readers == 1 || pipe->writers == 1)
51133+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
51134 wake_up_partner(inode);
51135 break;
51136
51137@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
51138 return 0;
51139
51140 err_rd:
51141- if (!--pipe->readers)
51142+ if (atomic_dec_and_test(&pipe->readers))
51143 wake_up_interruptible(&pipe->wait);
51144 ret = -ERESTARTSYS;
51145 goto err;
51146
51147 err_wr:
51148- if (!--pipe->writers)
51149+ if (atomic_dec_and_test(&pipe->writers))
51150 wake_up_interruptible(&pipe->wait);
51151 ret = -ERESTARTSYS;
51152 goto err;
51153
51154 err:
51155- if (!pipe->readers && !pipe->writers)
51156+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
51157 free_pipe_info(inode);
51158
51159 err_nocleanup:
51160diff --git a/fs/file.c b/fs/file.c
51161index 2b3570b..c57924b 100644
51162--- a/fs/file.c
51163+++ b/fs/file.c
51164@@ -16,6 +16,7 @@
51165 #include <linux/slab.h>
51166 #include <linux/vmalloc.h>
51167 #include <linux/file.h>
51168+#include <linux/security.h>
51169 #include <linux/fdtable.h>
51170 #include <linux/bitops.h>
51171 #include <linux/interrupt.h>
51172@@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
51173 if (!file)
51174 return __close_fd(files, fd);
51175
51176+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
51177 if (fd >= rlimit(RLIMIT_NOFILE))
51178 return -EBADF;
51179
51180@@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
51181 if (unlikely(oldfd == newfd))
51182 return -EINVAL;
51183
51184+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
51185 if (newfd >= rlimit(RLIMIT_NOFILE))
51186 return -EBADF;
51187
51188@@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
51189 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
51190 {
51191 int err;
51192+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
51193 if (from >= rlimit(RLIMIT_NOFILE))
51194 return -EINVAL;
51195 err = alloc_fd(from, flags);
51196diff --git a/fs/filesystems.c b/fs/filesystems.c
51197index da165f6..3671bdb 100644
51198--- a/fs/filesystems.c
51199+++ b/fs/filesystems.c
51200@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
51201 int len = dot ? dot - name : strlen(name);
51202
51203 fs = __get_fs_type(name, len);
51204+
51205+#ifdef CONFIG_GRKERNSEC_MODHARDEN
51206+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
51207+#else
51208 if (!fs && (request_module("%.*s", len, name) == 0))
51209+#endif
51210 fs = __get_fs_type(name, len);
51211
51212 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
51213diff --git a/fs/fs_struct.c b/fs/fs_struct.c
51214index fe6ca58..65318cf 100644
51215--- a/fs/fs_struct.c
51216+++ b/fs/fs_struct.c
51217@@ -4,6 +4,7 @@
51218 #include <linux/path.h>
51219 #include <linux/slab.h>
51220 #include <linux/fs_struct.h>
51221+#include <linux/grsecurity.h>
51222 #include "internal.h"
51223
51224 /*
51225@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
51226 write_seqcount_begin(&fs->seq);
51227 old_root = fs->root;
51228 fs->root = *path;
51229+ gr_set_chroot_entries(current, path);
51230 write_seqcount_end(&fs->seq);
51231 spin_unlock(&fs->lock);
51232 if (old_root.dentry)
51233@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
51234 return 1;
51235 }
51236
51237+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
51238+{
51239+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
51240+ return 0;
51241+ *p = *new;
51242+
51243+ /* This function is only called from pivot_root(). Leave our
51244+ gr_chroot_dentry and is_chrooted flags as-is, so that a
51245+ pivoted root isn't treated as a chroot
51246+ */
51247+ //gr_set_chroot_entries(task, new);
51248+
51249+ return 1;
51250+}
51251+
51252 void chroot_fs_refs(struct path *old_root, struct path *new_root)
51253 {
51254 struct task_struct *g, *p;
51255@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
51256 int hits = 0;
51257 spin_lock(&fs->lock);
51258 write_seqcount_begin(&fs->seq);
51259- hits += replace_path(&fs->root, old_root, new_root);
51260+ hits += replace_root_path(p, &fs->root, old_root, new_root);
51261 hits += replace_path(&fs->pwd, old_root, new_root);
51262 write_seqcount_end(&fs->seq);
51263 while (hits--) {
51264@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
51265 task_lock(tsk);
51266 spin_lock(&fs->lock);
51267 tsk->fs = NULL;
51268- kill = !--fs->users;
51269+ gr_clear_chroot_entries(tsk);
51270+ kill = !atomic_dec_return(&fs->users);
51271 spin_unlock(&fs->lock);
51272 task_unlock(tsk);
51273 if (kill)
51274@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51275 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
51276 /* We don't need to lock fs - think why ;-) */
51277 if (fs) {
51278- fs->users = 1;
51279+ atomic_set(&fs->users, 1);
51280 fs->in_exec = 0;
51281 spin_lock_init(&fs->lock);
51282 seqcount_init(&fs->seq);
51283@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51284 spin_lock(&old->lock);
51285 fs->root = old->root;
51286 path_get(&fs->root);
51287+ /* instead of calling gr_set_chroot_entries here,
51288+ we call it from every caller of this function
51289+ */
51290 fs->pwd = old->pwd;
51291 path_get(&fs->pwd);
51292 spin_unlock(&old->lock);
51293@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
51294
51295 task_lock(current);
51296 spin_lock(&fs->lock);
51297- kill = !--fs->users;
51298+ kill = !atomic_dec_return(&fs->users);
51299 current->fs = new_fs;
51300+ gr_set_chroot_entries(current, &new_fs->root);
51301 spin_unlock(&fs->lock);
51302 task_unlock(current);
51303
51304@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
51305
51306 int current_umask(void)
51307 {
51308- return current->fs->umask;
51309+ return current->fs->umask | gr_acl_umask();
51310 }
51311 EXPORT_SYMBOL(current_umask);
51312
51313 /* to be mentioned only in INIT_TASK */
51314 struct fs_struct init_fs = {
51315- .users = 1,
51316+ .users = ATOMIC_INIT(1),
51317 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
51318 .seq = SEQCNT_ZERO,
51319 .umask = 0022,
51320diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
51321index 8dcb114..b1072e2 100644
51322--- a/fs/fscache/cookie.c
51323+++ b/fs/fscache/cookie.c
51324@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
51325 parent ? (char *) parent->def->name : "<no-parent>",
51326 def->name, netfs_data);
51327
51328- fscache_stat(&fscache_n_acquires);
51329+ fscache_stat_unchecked(&fscache_n_acquires);
51330
51331 /* if there's no parent cookie, then we don't create one here either */
51332 if (!parent) {
51333- fscache_stat(&fscache_n_acquires_null);
51334+ fscache_stat_unchecked(&fscache_n_acquires_null);
51335 _leave(" [no parent]");
51336 return NULL;
51337 }
51338@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
51339 /* allocate and initialise a cookie */
51340 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
51341 if (!cookie) {
51342- fscache_stat(&fscache_n_acquires_oom);
51343+ fscache_stat_unchecked(&fscache_n_acquires_oom);
51344 _leave(" [ENOMEM]");
51345 return NULL;
51346 }
51347@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51348
51349 switch (cookie->def->type) {
51350 case FSCACHE_COOKIE_TYPE_INDEX:
51351- fscache_stat(&fscache_n_cookie_index);
51352+ fscache_stat_unchecked(&fscache_n_cookie_index);
51353 break;
51354 case FSCACHE_COOKIE_TYPE_DATAFILE:
51355- fscache_stat(&fscache_n_cookie_data);
51356+ fscache_stat_unchecked(&fscache_n_cookie_data);
51357 break;
51358 default:
51359- fscache_stat(&fscache_n_cookie_special);
51360+ fscache_stat_unchecked(&fscache_n_cookie_special);
51361 break;
51362 }
51363
51364@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51365 if (fscache_acquire_non_index_cookie(cookie) < 0) {
51366 atomic_dec(&parent->n_children);
51367 __fscache_cookie_put(cookie);
51368- fscache_stat(&fscache_n_acquires_nobufs);
51369+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
51370 _leave(" = NULL");
51371 return NULL;
51372 }
51373 }
51374
51375- fscache_stat(&fscache_n_acquires_ok);
51376+ fscache_stat_unchecked(&fscache_n_acquires_ok);
51377 _leave(" = %p", cookie);
51378 return cookie;
51379 }
51380@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
51381 cache = fscache_select_cache_for_object(cookie->parent);
51382 if (!cache) {
51383 up_read(&fscache_addremove_sem);
51384- fscache_stat(&fscache_n_acquires_no_cache);
51385+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
51386 _leave(" = -ENOMEDIUM [no cache]");
51387 return -ENOMEDIUM;
51388 }
51389@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
51390 object = cache->ops->alloc_object(cache, cookie);
51391 fscache_stat_d(&fscache_n_cop_alloc_object);
51392 if (IS_ERR(object)) {
51393- fscache_stat(&fscache_n_object_no_alloc);
51394+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
51395 ret = PTR_ERR(object);
51396 goto error;
51397 }
51398
51399- fscache_stat(&fscache_n_object_alloc);
51400+ fscache_stat_unchecked(&fscache_n_object_alloc);
51401
51402 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
51403
51404@@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
51405
51406 _enter("{%s}", cookie->def->name);
51407
51408- fscache_stat(&fscache_n_invalidates);
51409+ fscache_stat_unchecked(&fscache_n_invalidates);
51410
51411 /* Only permit invalidation of data files. Invalidating an index will
51412 * require the caller to release all its attachments to the tree rooted
51413@@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
51414 struct fscache_object *object;
51415 struct hlist_node *_p;
51416
51417- fscache_stat(&fscache_n_updates);
51418+ fscache_stat_unchecked(&fscache_n_updates);
51419
51420 if (!cookie) {
51421- fscache_stat(&fscache_n_updates_null);
51422+ fscache_stat_unchecked(&fscache_n_updates_null);
51423 _leave(" [no cookie]");
51424 return;
51425 }
51426@@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
51427 struct fscache_object *object;
51428 unsigned long event;
51429
51430- fscache_stat(&fscache_n_relinquishes);
51431+ fscache_stat_unchecked(&fscache_n_relinquishes);
51432 if (retire)
51433- fscache_stat(&fscache_n_relinquishes_retire);
51434+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
51435
51436 if (!cookie) {
51437- fscache_stat(&fscache_n_relinquishes_null);
51438+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
51439 _leave(" [no cookie]");
51440 return;
51441 }
51442@@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
51443
51444 /* wait for the cookie to finish being instantiated (or to fail) */
51445 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
51446- fscache_stat(&fscache_n_relinquishes_waitcrt);
51447+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
51448 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
51449 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
51450 }
51451diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
51452index ee38fef..0a326d4 100644
51453--- a/fs/fscache/internal.h
51454+++ b/fs/fscache/internal.h
51455@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
51456 * stats.c
51457 */
51458 #ifdef CONFIG_FSCACHE_STATS
51459-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
51460-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
51461+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
51462+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
51463
51464-extern atomic_t fscache_n_op_pend;
51465-extern atomic_t fscache_n_op_run;
51466-extern atomic_t fscache_n_op_enqueue;
51467-extern atomic_t fscache_n_op_deferred_release;
51468-extern atomic_t fscache_n_op_release;
51469-extern atomic_t fscache_n_op_gc;
51470-extern atomic_t fscache_n_op_cancelled;
51471-extern atomic_t fscache_n_op_rejected;
51472+extern atomic_unchecked_t fscache_n_op_pend;
51473+extern atomic_unchecked_t fscache_n_op_run;
51474+extern atomic_unchecked_t fscache_n_op_enqueue;
51475+extern atomic_unchecked_t fscache_n_op_deferred_release;
51476+extern atomic_unchecked_t fscache_n_op_release;
51477+extern atomic_unchecked_t fscache_n_op_gc;
51478+extern atomic_unchecked_t fscache_n_op_cancelled;
51479+extern atomic_unchecked_t fscache_n_op_rejected;
51480
51481-extern atomic_t fscache_n_attr_changed;
51482-extern atomic_t fscache_n_attr_changed_ok;
51483-extern atomic_t fscache_n_attr_changed_nobufs;
51484-extern atomic_t fscache_n_attr_changed_nomem;
51485-extern atomic_t fscache_n_attr_changed_calls;
51486+extern atomic_unchecked_t fscache_n_attr_changed;
51487+extern atomic_unchecked_t fscache_n_attr_changed_ok;
51488+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
51489+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
51490+extern atomic_unchecked_t fscache_n_attr_changed_calls;
51491
51492-extern atomic_t fscache_n_allocs;
51493-extern atomic_t fscache_n_allocs_ok;
51494-extern atomic_t fscache_n_allocs_wait;
51495-extern atomic_t fscache_n_allocs_nobufs;
51496-extern atomic_t fscache_n_allocs_intr;
51497-extern atomic_t fscache_n_allocs_object_dead;
51498-extern atomic_t fscache_n_alloc_ops;
51499-extern atomic_t fscache_n_alloc_op_waits;
51500+extern atomic_unchecked_t fscache_n_allocs;
51501+extern atomic_unchecked_t fscache_n_allocs_ok;
51502+extern atomic_unchecked_t fscache_n_allocs_wait;
51503+extern atomic_unchecked_t fscache_n_allocs_nobufs;
51504+extern atomic_unchecked_t fscache_n_allocs_intr;
51505+extern atomic_unchecked_t fscache_n_allocs_object_dead;
51506+extern atomic_unchecked_t fscache_n_alloc_ops;
51507+extern atomic_unchecked_t fscache_n_alloc_op_waits;
51508
51509-extern atomic_t fscache_n_retrievals;
51510-extern atomic_t fscache_n_retrievals_ok;
51511-extern atomic_t fscache_n_retrievals_wait;
51512-extern atomic_t fscache_n_retrievals_nodata;
51513-extern atomic_t fscache_n_retrievals_nobufs;
51514-extern atomic_t fscache_n_retrievals_intr;
51515-extern atomic_t fscache_n_retrievals_nomem;
51516-extern atomic_t fscache_n_retrievals_object_dead;
51517-extern atomic_t fscache_n_retrieval_ops;
51518-extern atomic_t fscache_n_retrieval_op_waits;
51519+extern atomic_unchecked_t fscache_n_retrievals;
51520+extern atomic_unchecked_t fscache_n_retrievals_ok;
51521+extern atomic_unchecked_t fscache_n_retrievals_wait;
51522+extern atomic_unchecked_t fscache_n_retrievals_nodata;
51523+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
51524+extern atomic_unchecked_t fscache_n_retrievals_intr;
51525+extern atomic_unchecked_t fscache_n_retrievals_nomem;
51526+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
51527+extern atomic_unchecked_t fscache_n_retrieval_ops;
51528+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
51529
51530-extern atomic_t fscache_n_stores;
51531-extern atomic_t fscache_n_stores_ok;
51532-extern atomic_t fscache_n_stores_again;
51533-extern atomic_t fscache_n_stores_nobufs;
51534-extern atomic_t fscache_n_stores_oom;
51535-extern atomic_t fscache_n_store_ops;
51536-extern atomic_t fscache_n_store_calls;
51537-extern atomic_t fscache_n_store_pages;
51538-extern atomic_t fscache_n_store_radix_deletes;
51539-extern atomic_t fscache_n_store_pages_over_limit;
51540+extern atomic_unchecked_t fscache_n_stores;
51541+extern atomic_unchecked_t fscache_n_stores_ok;
51542+extern atomic_unchecked_t fscache_n_stores_again;
51543+extern atomic_unchecked_t fscache_n_stores_nobufs;
51544+extern atomic_unchecked_t fscache_n_stores_oom;
51545+extern atomic_unchecked_t fscache_n_store_ops;
51546+extern atomic_unchecked_t fscache_n_store_calls;
51547+extern atomic_unchecked_t fscache_n_store_pages;
51548+extern atomic_unchecked_t fscache_n_store_radix_deletes;
51549+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
51550
51551-extern atomic_t fscache_n_store_vmscan_not_storing;
51552-extern atomic_t fscache_n_store_vmscan_gone;
51553-extern atomic_t fscache_n_store_vmscan_busy;
51554-extern atomic_t fscache_n_store_vmscan_cancelled;
51555-extern atomic_t fscache_n_store_vmscan_wait;
51556+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
51557+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
51558+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
51559+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
51560+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
51561
51562-extern atomic_t fscache_n_marks;
51563-extern atomic_t fscache_n_uncaches;
51564+extern atomic_unchecked_t fscache_n_marks;
51565+extern atomic_unchecked_t fscache_n_uncaches;
51566
51567-extern atomic_t fscache_n_acquires;
51568-extern atomic_t fscache_n_acquires_null;
51569-extern atomic_t fscache_n_acquires_no_cache;
51570-extern atomic_t fscache_n_acquires_ok;
51571-extern atomic_t fscache_n_acquires_nobufs;
51572-extern atomic_t fscache_n_acquires_oom;
51573+extern atomic_unchecked_t fscache_n_acquires;
51574+extern atomic_unchecked_t fscache_n_acquires_null;
51575+extern atomic_unchecked_t fscache_n_acquires_no_cache;
51576+extern atomic_unchecked_t fscache_n_acquires_ok;
51577+extern atomic_unchecked_t fscache_n_acquires_nobufs;
51578+extern atomic_unchecked_t fscache_n_acquires_oom;
51579
51580-extern atomic_t fscache_n_invalidates;
51581-extern atomic_t fscache_n_invalidates_run;
51582+extern atomic_unchecked_t fscache_n_invalidates;
51583+extern atomic_unchecked_t fscache_n_invalidates_run;
51584
51585-extern atomic_t fscache_n_updates;
51586-extern atomic_t fscache_n_updates_null;
51587-extern atomic_t fscache_n_updates_run;
51588+extern atomic_unchecked_t fscache_n_updates;
51589+extern atomic_unchecked_t fscache_n_updates_null;
51590+extern atomic_unchecked_t fscache_n_updates_run;
51591
51592-extern atomic_t fscache_n_relinquishes;
51593-extern atomic_t fscache_n_relinquishes_null;
51594-extern atomic_t fscache_n_relinquishes_waitcrt;
51595-extern atomic_t fscache_n_relinquishes_retire;
51596+extern atomic_unchecked_t fscache_n_relinquishes;
51597+extern atomic_unchecked_t fscache_n_relinquishes_null;
51598+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
51599+extern atomic_unchecked_t fscache_n_relinquishes_retire;
51600
51601-extern atomic_t fscache_n_cookie_index;
51602-extern atomic_t fscache_n_cookie_data;
51603-extern atomic_t fscache_n_cookie_special;
51604+extern atomic_unchecked_t fscache_n_cookie_index;
51605+extern atomic_unchecked_t fscache_n_cookie_data;
51606+extern atomic_unchecked_t fscache_n_cookie_special;
51607
51608-extern atomic_t fscache_n_object_alloc;
51609-extern atomic_t fscache_n_object_no_alloc;
51610-extern atomic_t fscache_n_object_lookups;
51611-extern atomic_t fscache_n_object_lookups_negative;
51612-extern atomic_t fscache_n_object_lookups_positive;
51613-extern atomic_t fscache_n_object_lookups_timed_out;
51614-extern atomic_t fscache_n_object_created;
51615-extern atomic_t fscache_n_object_avail;
51616-extern atomic_t fscache_n_object_dead;
51617+extern atomic_unchecked_t fscache_n_object_alloc;
51618+extern atomic_unchecked_t fscache_n_object_no_alloc;
51619+extern atomic_unchecked_t fscache_n_object_lookups;
51620+extern atomic_unchecked_t fscache_n_object_lookups_negative;
51621+extern atomic_unchecked_t fscache_n_object_lookups_positive;
51622+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
51623+extern atomic_unchecked_t fscache_n_object_created;
51624+extern atomic_unchecked_t fscache_n_object_avail;
51625+extern atomic_unchecked_t fscache_n_object_dead;
51626
51627-extern atomic_t fscache_n_checkaux_none;
51628-extern atomic_t fscache_n_checkaux_okay;
51629-extern atomic_t fscache_n_checkaux_update;
51630-extern atomic_t fscache_n_checkaux_obsolete;
51631+extern atomic_unchecked_t fscache_n_checkaux_none;
51632+extern atomic_unchecked_t fscache_n_checkaux_okay;
51633+extern atomic_unchecked_t fscache_n_checkaux_update;
51634+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
51635
51636 extern atomic_t fscache_n_cop_alloc_object;
51637 extern atomic_t fscache_n_cop_lookup_object;
51638@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
51639 atomic_inc(stat);
51640 }
51641
51642+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
51643+{
51644+ atomic_inc_unchecked(stat);
51645+}
51646+
51647 static inline void fscache_stat_d(atomic_t *stat)
51648 {
51649 atomic_dec(stat);
51650@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
51651
51652 #define __fscache_stat(stat) (NULL)
51653 #define fscache_stat(stat) do {} while (0)
51654+#define fscache_stat_unchecked(stat) do {} while (0)
51655 #define fscache_stat_d(stat) do {} while (0)
51656 #endif
51657
51658diff --git a/fs/fscache/object.c b/fs/fscache/object.c
51659index 50d41c1..10ee117 100644
51660--- a/fs/fscache/object.c
51661+++ b/fs/fscache/object.c
51662@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51663 /* Invalidate an object on disk */
51664 case FSCACHE_OBJECT_INVALIDATING:
51665 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
51666- fscache_stat(&fscache_n_invalidates_run);
51667+ fscache_stat_unchecked(&fscache_n_invalidates_run);
51668 fscache_stat(&fscache_n_cop_invalidate_object);
51669 fscache_invalidate_object(object);
51670 fscache_stat_d(&fscache_n_cop_invalidate_object);
51671@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51672 /* update the object metadata on disk */
51673 case FSCACHE_OBJECT_UPDATING:
51674 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
51675- fscache_stat(&fscache_n_updates_run);
51676+ fscache_stat_unchecked(&fscache_n_updates_run);
51677 fscache_stat(&fscache_n_cop_update_object);
51678 object->cache->ops->update_object(object);
51679 fscache_stat_d(&fscache_n_cop_update_object);
51680@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51681 spin_lock(&object->lock);
51682 object->state = FSCACHE_OBJECT_DEAD;
51683 spin_unlock(&object->lock);
51684- fscache_stat(&fscache_n_object_dead);
51685+ fscache_stat_unchecked(&fscache_n_object_dead);
51686 goto terminal_transit;
51687
51688 /* handle the parent cache of this object being withdrawn from
51689@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51690 spin_lock(&object->lock);
51691 object->state = FSCACHE_OBJECT_DEAD;
51692 spin_unlock(&object->lock);
51693- fscache_stat(&fscache_n_object_dead);
51694+ fscache_stat_unchecked(&fscache_n_object_dead);
51695 goto terminal_transit;
51696
51697 /* complain about the object being woken up once it is
51698@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51699 parent->cookie->def->name, cookie->def->name,
51700 object->cache->tag->name);
51701
51702- fscache_stat(&fscache_n_object_lookups);
51703+ fscache_stat_unchecked(&fscache_n_object_lookups);
51704 fscache_stat(&fscache_n_cop_lookup_object);
51705 ret = object->cache->ops->lookup_object(object);
51706 fscache_stat_d(&fscache_n_cop_lookup_object);
51707@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51708 if (ret == -ETIMEDOUT) {
51709 /* probably stuck behind another object, so move this one to
51710 * the back of the queue */
51711- fscache_stat(&fscache_n_object_lookups_timed_out);
51712+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
51713 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51714 }
51715
51716@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
51717
51718 spin_lock(&object->lock);
51719 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51720- fscache_stat(&fscache_n_object_lookups_negative);
51721+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
51722
51723 /* transit here to allow write requests to begin stacking up
51724 * and read requests to begin returning ENODATA */
51725@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
51726 * result, in which case there may be data available */
51727 spin_lock(&object->lock);
51728 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51729- fscache_stat(&fscache_n_object_lookups_positive);
51730+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
51731
51732 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
51733
51734@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
51735 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51736 } else {
51737 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
51738- fscache_stat(&fscache_n_object_created);
51739+ fscache_stat_unchecked(&fscache_n_object_created);
51740
51741 object->state = FSCACHE_OBJECT_AVAILABLE;
51742 spin_unlock(&object->lock);
51743@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
51744 fscache_enqueue_dependents(object);
51745
51746 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
51747- fscache_stat(&fscache_n_object_avail);
51748+ fscache_stat_unchecked(&fscache_n_object_avail);
51749
51750 _leave("");
51751 }
51752@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51753 enum fscache_checkaux result;
51754
51755 if (!object->cookie->def->check_aux) {
51756- fscache_stat(&fscache_n_checkaux_none);
51757+ fscache_stat_unchecked(&fscache_n_checkaux_none);
51758 return FSCACHE_CHECKAUX_OKAY;
51759 }
51760
51761@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51762 switch (result) {
51763 /* entry okay as is */
51764 case FSCACHE_CHECKAUX_OKAY:
51765- fscache_stat(&fscache_n_checkaux_okay);
51766+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
51767 break;
51768
51769 /* entry requires update */
51770 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
51771- fscache_stat(&fscache_n_checkaux_update);
51772+ fscache_stat_unchecked(&fscache_n_checkaux_update);
51773 break;
51774
51775 /* entry requires deletion */
51776 case FSCACHE_CHECKAUX_OBSOLETE:
51777- fscache_stat(&fscache_n_checkaux_obsolete);
51778+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
51779 break;
51780
51781 default:
51782diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
51783index 762a9ec..2023284 100644
51784--- a/fs/fscache/operation.c
51785+++ b/fs/fscache/operation.c
51786@@ -17,7 +17,7 @@
51787 #include <linux/slab.h>
51788 #include "internal.h"
51789
51790-atomic_t fscache_op_debug_id;
51791+atomic_unchecked_t fscache_op_debug_id;
51792 EXPORT_SYMBOL(fscache_op_debug_id);
51793
51794 /**
51795@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
51796 ASSERTCMP(atomic_read(&op->usage), >, 0);
51797 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
51798
51799- fscache_stat(&fscache_n_op_enqueue);
51800+ fscache_stat_unchecked(&fscache_n_op_enqueue);
51801 switch (op->flags & FSCACHE_OP_TYPE) {
51802 case FSCACHE_OP_ASYNC:
51803 _debug("queue async");
51804@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
51805 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
51806 if (op->processor)
51807 fscache_enqueue_operation(op);
51808- fscache_stat(&fscache_n_op_run);
51809+ fscache_stat_unchecked(&fscache_n_op_run);
51810 }
51811
51812 /*
51813@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51814 if (object->n_in_progress > 0) {
51815 atomic_inc(&op->usage);
51816 list_add_tail(&op->pend_link, &object->pending_ops);
51817- fscache_stat(&fscache_n_op_pend);
51818+ fscache_stat_unchecked(&fscache_n_op_pend);
51819 } else if (!list_empty(&object->pending_ops)) {
51820 atomic_inc(&op->usage);
51821 list_add_tail(&op->pend_link, &object->pending_ops);
51822- fscache_stat(&fscache_n_op_pend);
51823+ fscache_stat_unchecked(&fscache_n_op_pend);
51824 fscache_start_operations(object);
51825 } else {
51826 ASSERTCMP(object->n_in_progress, ==, 0);
51827@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51828 object->n_exclusive++; /* reads and writes must wait */
51829 atomic_inc(&op->usage);
51830 list_add_tail(&op->pend_link, &object->pending_ops);
51831- fscache_stat(&fscache_n_op_pend);
51832+ fscache_stat_unchecked(&fscache_n_op_pend);
51833 ret = 0;
51834 } else {
51835 /* If we're in any other state, there must have been an I/O
51836@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
51837 if (object->n_exclusive > 0) {
51838 atomic_inc(&op->usage);
51839 list_add_tail(&op->pend_link, &object->pending_ops);
51840- fscache_stat(&fscache_n_op_pend);
51841+ fscache_stat_unchecked(&fscache_n_op_pend);
51842 } else if (!list_empty(&object->pending_ops)) {
51843 atomic_inc(&op->usage);
51844 list_add_tail(&op->pend_link, &object->pending_ops);
51845- fscache_stat(&fscache_n_op_pend);
51846+ fscache_stat_unchecked(&fscache_n_op_pend);
51847 fscache_start_operations(object);
51848 } else {
51849 ASSERTCMP(object->n_exclusive, ==, 0);
51850@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
51851 object->n_ops++;
51852 atomic_inc(&op->usage);
51853 list_add_tail(&op->pend_link, &object->pending_ops);
51854- fscache_stat(&fscache_n_op_pend);
51855+ fscache_stat_unchecked(&fscache_n_op_pend);
51856 ret = 0;
51857 } else if (object->state == FSCACHE_OBJECT_DYING ||
51858 object->state == FSCACHE_OBJECT_LC_DYING ||
51859 object->state == FSCACHE_OBJECT_WITHDRAWING) {
51860- fscache_stat(&fscache_n_op_rejected);
51861+ fscache_stat_unchecked(&fscache_n_op_rejected);
51862 op->state = FSCACHE_OP_ST_CANCELLED;
51863 ret = -ENOBUFS;
51864 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
51865@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
51866 ret = -EBUSY;
51867 if (op->state == FSCACHE_OP_ST_PENDING) {
51868 ASSERT(!list_empty(&op->pend_link));
51869- fscache_stat(&fscache_n_op_cancelled);
51870+ fscache_stat_unchecked(&fscache_n_op_cancelled);
51871 list_del_init(&op->pend_link);
51872 if (do_cancel)
51873 do_cancel(op);
51874@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
51875 while (!list_empty(&object->pending_ops)) {
51876 op = list_entry(object->pending_ops.next,
51877 struct fscache_operation, pend_link);
51878- fscache_stat(&fscache_n_op_cancelled);
51879+ fscache_stat_unchecked(&fscache_n_op_cancelled);
51880 list_del_init(&op->pend_link);
51881
51882 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
51883@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
51884 op->state, ==, FSCACHE_OP_ST_CANCELLED);
51885 op->state = FSCACHE_OP_ST_DEAD;
51886
51887- fscache_stat(&fscache_n_op_release);
51888+ fscache_stat_unchecked(&fscache_n_op_release);
51889
51890 if (op->release) {
51891 op->release(op);
51892@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
51893 * lock, and defer it otherwise */
51894 if (!spin_trylock(&object->lock)) {
51895 _debug("defer put");
51896- fscache_stat(&fscache_n_op_deferred_release);
51897+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
51898
51899 cache = object->cache;
51900 spin_lock(&cache->op_gc_list_lock);
51901@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
51902
51903 _debug("GC DEFERRED REL OBJ%x OP%x",
51904 object->debug_id, op->debug_id);
51905- fscache_stat(&fscache_n_op_gc);
51906+ fscache_stat_unchecked(&fscache_n_op_gc);
51907
51908 ASSERTCMP(atomic_read(&op->usage), ==, 0);
51909 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
51910diff --git a/fs/fscache/page.c b/fs/fscache/page.c
51911index ff000e5..c44ec6d 100644
51912--- a/fs/fscache/page.c
51913+++ b/fs/fscache/page.c
51914@@ -61,7 +61,7 @@ try_again:
51915 val = radix_tree_lookup(&cookie->stores, page->index);
51916 if (!val) {
51917 rcu_read_unlock();
51918- fscache_stat(&fscache_n_store_vmscan_not_storing);
51919+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
51920 __fscache_uncache_page(cookie, page);
51921 return true;
51922 }
51923@@ -91,11 +91,11 @@ try_again:
51924 spin_unlock(&cookie->stores_lock);
51925
51926 if (xpage) {
51927- fscache_stat(&fscache_n_store_vmscan_cancelled);
51928- fscache_stat(&fscache_n_store_radix_deletes);
51929+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
51930+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51931 ASSERTCMP(xpage, ==, page);
51932 } else {
51933- fscache_stat(&fscache_n_store_vmscan_gone);
51934+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
51935 }
51936
51937 wake_up_bit(&cookie->flags, 0);
51938@@ -110,11 +110,11 @@ page_busy:
51939 * sleeping on memory allocation, so we may need to impose a timeout
51940 * too. */
51941 if (!(gfp & __GFP_WAIT)) {
51942- fscache_stat(&fscache_n_store_vmscan_busy);
51943+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
51944 return false;
51945 }
51946
51947- fscache_stat(&fscache_n_store_vmscan_wait);
51948+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
51949 __fscache_wait_on_page_write(cookie, page);
51950 gfp &= ~__GFP_WAIT;
51951 goto try_again;
51952@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
51953 FSCACHE_COOKIE_STORING_TAG);
51954 if (!radix_tree_tag_get(&cookie->stores, page->index,
51955 FSCACHE_COOKIE_PENDING_TAG)) {
51956- fscache_stat(&fscache_n_store_radix_deletes);
51957+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51958 xpage = radix_tree_delete(&cookie->stores, page->index);
51959 }
51960 spin_unlock(&cookie->stores_lock);
51961@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
51962
51963 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
51964
51965- fscache_stat(&fscache_n_attr_changed_calls);
51966+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
51967
51968 if (fscache_object_is_active(object)) {
51969 fscache_stat(&fscache_n_cop_attr_changed);
51970@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51971
51972 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51973
51974- fscache_stat(&fscache_n_attr_changed);
51975+ fscache_stat_unchecked(&fscache_n_attr_changed);
51976
51977 op = kzalloc(sizeof(*op), GFP_KERNEL);
51978 if (!op) {
51979- fscache_stat(&fscache_n_attr_changed_nomem);
51980+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
51981 _leave(" = -ENOMEM");
51982 return -ENOMEM;
51983 }
51984@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51985 if (fscache_submit_exclusive_op(object, op) < 0)
51986 goto nobufs;
51987 spin_unlock(&cookie->lock);
51988- fscache_stat(&fscache_n_attr_changed_ok);
51989+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
51990 fscache_put_operation(op);
51991 _leave(" = 0");
51992 return 0;
51993@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51994 nobufs:
51995 spin_unlock(&cookie->lock);
51996 kfree(op);
51997- fscache_stat(&fscache_n_attr_changed_nobufs);
51998+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
51999 _leave(" = %d", -ENOBUFS);
52000 return -ENOBUFS;
52001 }
52002@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
52003 /* allocate a retrieval operation and attempt to submit it */
52004 op = kzalloc(sizeof(*op), GFP_NOIO);
52005 if (!op) {
52006- fscache_stat(&fscache_n_retrievals_nomem);
52007+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52008 return NULL;
52009 }
52010
52011@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
52012 return 0;
52013 }
52014
52015- fscache_stat(&fscache_n_retrievals_wait);
52016+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
52017
52018 jif = jiffies;
52019 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
52020 fscache_wait_bit_interruptible,
52021 TASK_INTERRUPTIBLE) != 0) {
52022- fscache_stat(&fscache_n_retrievals_intr);
52023+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52024 _leave(" = -ERESTARTSYS");
52025 return -ERESTARTSYS;
52026 }
52027@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
52028 */
52029 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52030 struct fscache_retrieval *op,
52031- atomic_t *stat_op_waits,
52032- atomic_t *stat_object_dead)
52033+ atomic_unchecked_t *stat_op_waits,
52034+ atomic_unchecked_t *stat_object_dead)
52035 {
52036 int ret;
52037
52038@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52039 goto check_if_dead;
52040
52041 _debug(">>> WT");
52042- fscache_stat(stat_op_waits);
52043+ fscache_stat_unchecked(stat_op_waits);
52044 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
52045 fscache_wait_bit_interruptible,
52046 TASK_INTERRUPTIBLE) != 0) {
52047@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52048
52049 check_if_dead:
52050 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
52051- fscache_stat(stat_object_dead);
52052+ fscache_stat_unchecked(stat_object_dead);
52053 _leave(" = -ENOBUFS [cancelled]");
52054 return -ENOBUFS;
52055 }
52056 if (unlikely(fscache_object_is_dead(object))) {
52057 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
52058 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
52059- fscache_stat(stat_object_dead);
52060+ fscache_stat_unchecked(stat_object_dead);
52061 return -ENOBUFS;
52062 }
52063 return 0;
52064@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52065
52066 _enter("%p,%p,,,", cookie, page);
52067
52068- fscache_stat(&fscache_n_retrievals);
52069+ fscache_stat_unchecked(&fscache_n_retrievals);
52070
52071 if (hlist_empty(&cookie->backing_objects))
52072 goto nobufs;
52073@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52074 goto nobufs_unlock_dec;
52075 spin_unlock(&cookie->lock);
52076
52077- fscache_stat(&fscache_n_retrieval_ops);
52078+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52079
52080 /* pin the netfs read context in case we need to do the actual netfs
52081 * read because we've encountered a cache read failure */
52082@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52083
52084 error:
52085 if (ret == -ENOMEM)
52086- fscache_stat(&fscache_n_retrievals_nomem);
52087+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52088 else if (ret == -ERESTARTSYS)
52089- fscache_stat(&fscache_n_retrievals_intr);
52090+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52091 else if (ret == -ENODATA)
52092- fscache_stat(&fscache_n_retrievals_nodata);
52093+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52094 else if (ret < 0)
52095- fscache_stat(&fscache_n_retrievals_nobufs);
52096+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52097 else
52098- fscache_stat(&fscache_n_retrievals_ok);
52099+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52100
52101 fscache_put_retrieval(op);
52102 _leave(" = %d", ret);
52103@@ -467,7 +467,7 @@ nobufs_unlock:
52104 spin_unlock(&cookie->lock);
52105 kfree(op);
52106 nobufs:
52107- fscache_stat(&fscache_n_retrievals_nobufs);
52108+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52109 _leave(" = -ENOBUFS");
52110 return -ENOBUFS;
52111 }
52112@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52113
52114 _enter("%p,,%d,,,", cookie, *nr_pages);
52115
52116- fscache_stat(&fscache_n_retrievals);
52117+ fscache_stat_unchecked(&fscache_n_retrievals);
52118
52119 if (hlist_empty(&cookie->backing_objects))
52120 goto nobufs;
52121@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52122 goto nobufs_unlock_dec;
52123 spin_unlock(&cookie->lock);
52124
52125- fscache_stat(&fscache_n_retrieval_ops);
52126+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52127
52128 /* pin the netfs read context in case we need to do the actual netfs
52129 * read because we've encountered a cache read failure */
52130@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52131
52132 error:
52133 if (ret == -ENOMEM)
52134- fscache_stat(&fscache_n_retrievals_nomem);
52135+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52136 else if (ret == -ERESTARTSYS)
52137- fscache_stat(&fscache_n_retrievals_intr);
52138+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52139 else if (ret == -ENODATA)
52140- fscache_stat(&fscache_n_retrievals_nodata);
52141+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52142 else if (ret < 0)
52143- fscache_stat(&fscache_n_retrievals_nobufs);
52144+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52145 else
52146- fscache_stat(&fscache_n_retrievals_ok);
52147+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52148
52149 fscache_put_retrieval(op);
52150 _leave(" = %d", ret);
52151@@ -591,7 +591,7 @@ nobufs_unlock:
52152 spin_unlock(&cookie->lock);
52153 kfree(op);
52154 nobufs:
52155- fscache_stat(&fscache_n_retrievals_nobufs);
52156+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52157 _leave(" = -ENOBUFS");
52158 return -ENOBUFS;
52159 }
52160@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52161
52162 _enter("%p,%p,,,", cookie, page);
52163
52164- fscache_stat(&fscache_n_allocs);
52165+ fscache_stat_unchecked(&fscache_n_allocs);
52166
52167 if (hlist_empty(&cookie->backing_objects))
52168 goto nobufs;
52169@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52170 goto nobufs_unlock;
52171 spin_unlock(&cookie->lock);
52172
52173- fscache_stat(&fscache_n_alloc_ops);
52174+ fscache_stat_unchecked(&fscache_n_alloc_ops);
52175
52176 ret = fscache_wait_for_retrieval_activation(
52177 object, op,
52178@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52179
52180 error:
52181 if (ret == -ERESTARTSYS)
52182- fscache_stat(&fscache_n_allocs_intr);
52183+ fscache_stat_unchecked(&fscache_n_allocs_intr);
52184 else if (ret < 0)
52185- fscache_stat(&fscache_n_allocs_nobufs);
52186+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52187 else
52188- fscache_stat(&fscache_n_allocs_ok);
52189+ fscache_stat_unchecked(&fscache_n_allocs_ok);
52190
52191 fscache_put_retrieval(op);
52192 _leave(" = %d", ret);
52193@@ -677,7 +677,7 @@ nobufs_unlock:
52194 spin_unlock(&cookie->lock);
52195 kfree(op);
52196 nobufs:
52197- fscache_stat(&fscache_n_allocs_nobufs);
52198+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52199 _leave(" = -ENOBUFS");
52200 return -ENOBUFS;
52201 }
52202@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52203
52204 spin_lock(&cookie->stores_lock);
52205
52206- fscache_stat(&fscache_n_store_calls);
52207+ fscache_stat_unchecked(&fscache_n_store_calls);
52208
52209 /* find a page to store */
52210 page = NULL;
52211@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52212 page = results[0];
52213 _debug("gang %d [%lx]", n, page->index);
52214 if (page->index > op->store_limit) {
52215- fscache_stat(&fscache_n_store_pages_over_limit);
52216+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
52217 goto superseded;
52218 }
52219
52220@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52221 spin_unlock(&cookie->stores_lock);
52222 spin_unlock(&object->lock);
52223
52224- fscache_stat(&fscache_n_store_pages);
52225+ fscache_stat_unchecked(&fscache_n_store_pages);
52226 fscache_stat(&fscache_n_cop_write_page);
52227 ret = object->cache->ops->write_page(op, page);
52228 fscache_stat_d(&fscache_n_cop_write_page);
52229@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52230 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52231 ASSERT(PageFsCache(page));
52232
52233- fscache_stat(&fscache_n_stores);
52234+ fscache_stat_unchecked(&fscache_n_stores);
52235
52236 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
52237 _leave(" = -ENOBUFS [invalidating]");
52238@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52239 spin_unlock(&cookie->stores_lock);
52240 spin_unlock(&object->lock);
52241
52242- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
52243+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
52244 op->store_limit = object->store_limit;
52245
52246 if (fscache_submit_op(object, &op->op) < 0)
52247@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52248
52249 spin_unlock(&cookie->lock);
52250 radix_tree_preload_end();
52251- fscache_stat(&fscache_n_store_ops);
52252- fscache_stat(&fscache_n_stores_ok);
52253+ fscache_stat_unchecked(&fscache_n_store_ops);
52254+ fscache_stat_unchecked(&fscache_n_stores_ok);
52255
52256 /* the work queue now carries its own ref on the object */
52257 fscache_put_operation(&op->op);
52258@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52259 return 0;
52260
52261 already_queued:
52262- fscache_stat(&fscache_n_stores_again);
52263+ fscache_stat_unchecked(&fscache_n_stores_again);
52264 already_pending:
52265 spin_unlock(&cookie->stores_lock);
52266 spin_unlock(&object->lock);
52267 spin_unlock(&cookie->lock);
52268 radix_tree_preload_end();
52269 kfree(op);
52270- fscache_stat(&fscache_n_stores_ok);
52271+ fscache_stat_unchecked(&fscache_n_stores_ok);
52272 _leave(" = 0");
52273 return 0;
52274
52275@@ -959,14 +959,14 @@ nobufs:
52276 spin_unlock(&cookie->lock);
52277 radix_tree_preload_end();
52278 kfree(op);
52279- fscache_stat(&fscache_n_stores_nobufs);
52280+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
52281 _leave(" = -ENOBUFS");
52282 return -ENOBUFS;
52283
52284 nomem_free:
52285 kfree(op);
52286 nomem:
52287- fscache_stat(&fscache_n_stores_oom);
52288+ fscache_stat_unchecked(&fscache_n_stores_oom);
52289 _leave(" = -ENOMEM");
52290 return -ENOMEM;
52291 }
52292@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
52293 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52294 ASSERTCMP(page, !=, NULL);
52295
52296- fscache_stat(&fscache_n_uncaches);
52297+ fscache_stat_unchecked(&fscache_n_uncaches);
52298
52299 /* cache withdrawal may beat us to it */
52300 if (!PageFsCache(page))
52301@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
52302 struct fscache_cookie *cookie = op->op.object->cookie;
52303
52304 #ifdef CONFIG_FSCACHE_STATS
52305- atomic_inc(&fscache_n_marks);
52306+ atomic_inc_unchecked(&fscache_n_marks);
52307 #endif
52308
52309 _debug("- mark %p{%lx}", page, page->index);
52310diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
52311index 8179e8b..5072cc7 100644
52312--- a/fs/fscache/stats.c
52313+++ b/fs/fscache/stats.c
52314@@ -18,99 +18,99 @@
52315 /*
52316 * operation counters
52317 */
52318-atomic_t fscache_n_op_pend;
52319-atomic_t fscache_n_op_run;
52320-atomic_t fscache_n_op_enqueue;
52321-atomic_t fscache_n_op_requeue;
52322-atomic_t fscache_n_op_deferred_release;
52323-atomic_t fscache_n_op_release;
52324-atomic_t fscache_n_op_gc;
52325-atomic_t fscache_n_op_cancelled;
52326-atomic_t fscache_n_op_rejected;
52327+atomic_unchecked_t fscache_n_op_pend;
52328+atomic_unchecked_t fscache_n_op_run;
52329+atomic_unchecked_t fscache_n_op_enqueue;
52330+atomic_unchecked_t fscache_n_op_requeue;
52331+atomic_unchecked_t fscache_n_op_deferred_release;
52332+atomic_unchecked_t fscache_n_op_release;
52333+atomic_unchecked_t fscache_n_op_gc;
52334+atomic_unchecked_t fscache_n_op_cancelled;
52335+atomic_unchecked_t fscache_n_op_rejected;
52336
52337-atomic_t fscache_n_attr_changed;
52338-atomic_t fscache_n_attr_changed_ok;
52339-atomic_t fscache_n_attr_changed_nobufs;
52340-atomic_t fscache_n_attr_changed_nomem;
52341-atomic_t fscache_n_attr_changed_calls;
52342+atomic_unchecked_t fscache_n_attr_changed;
52343+atomic_unchecked_t fscache_n_attr_changed_ok;
52344+atomic_unchecked_t fscache_n_attr_changed_nobufs;
52345+atomic_unchecked_t fscache_n_attr_changed_nomem;
52346+atomic_unchecked_t fscache_n_attr_changed_calls;
52347
52348-atomic_t fscache_n_allocs;
52349-atomic_t fscache_n_allocs_ok;
52350-atomic_t fscache_n_allocs_wait;
52351-atomic_t fscache_n_allocs_nobufs;
52352-atomic_t fscache_n_allocs_intr;
52353-atomic_t fscache_n_allocs_object_dead;
52354-atomic_t fscache_n_alloc_ops;
52355-atomic_t fscache_n_alloc_op_waits;
52356+atomic_unchecked_t fscache_n_allocs;
52357+atomic_unchecked_t fscache_n_allocs_ok;
52358+atomic_unchecked_t fscache_n_allocs_wait;
52359+atomic_unchecked_t fscache_n_allocs_nobufs;
52360+atomic_unchecked_t fscache_n_allocs_intr;
52361+atomic_unchecked_t fscache_n_allocs_object_dead;
52362+atomic_unchecked_t fscache_n_alloc_ops;
52363+atomic_unchecked_t fscache_n_alloc_op_waits;
52364
52365-atomic_t fscache_n_retrievals;
52366-atomic_t fscache_n_retrievals_ok;
52367-atomic_t fscache_n_retrievals_wait;
52368-atomic_t fscache_n_retrievals_nodata;
52369-atomic_t fscache_n_retrievals_nobufs;
52370-atomic_t fscache_n_retrievals_intr;
52371-atomic_t fscache_n_retrievals_nomem;
52372-atomic_t fscache_n_retrievals_object_dead;
52373-atomic_t fscache_n_retrieval_ops;
52374-atomic_t fscache_n_retrieval_op_waits;
52375+atomic_unchecked_t fscache_n_retrievals;
52376+atomic_unchecked_t fscache_n_retrievals_ok;
52377+atomic_unchecked_t fscache_n_retrievals_wait;
52378+atomic_unchecked_t fscache_n_retrievals_nodata;
52379+atomic_unchecked_t fscache_n_retrievals_nobufs;
52380+atomic_unchecked_t fscache_n_retrievals_intr;
52381+atomic_unchecked_t fscache_n_retrievals_nomem;
52382+atomic_unchecked_t fscache_n_retrievals_object_dead;
52383+atomic_unchecked_t fscache_n_retrieval_ops;
52384+atomic_unchecked_t fscache_n_retrieval_op_waits;
52385
52386-atomic_t fscache_n_stores;
52387-atomic_t fscache_n_stores_ok;
52388-atomic_t fscache_n_stores_again;
52389-atomic_t fscache_n_stores_nobufs;
52390-atomic_t fscache_n_stores_oom;
52391-atomic_t fscache_n_store_ops;
52392-atomic_t fscache_n_store_calls;
52393-atomic_t fscache_n_store_pages;
52394-atomic_t fscache_n_store_radix_deletes;
52395-atomic_t fscache_n_store_pages_over_limit;
52396+atomic_unchecked_t fscache_n_stores;
52397+atomic_unchecked_t fscache_n_stores_ok;
52398+atomic_unchecked_t fscache_n_stores_again;
52399+atomic_unchecked_t fscache_n_stores_nobufs;
52400+atomic_unchecked_t fscache_n_stores_oom;
52401+atomic_unchecked_t fscache_n_store_ops;
52402+atomic_unchecked_t fscache_n_store_calls;
52403+atomic_unchecked_t fscache_n_store_pages;
52404+atomic_unchecked_t fscache_n_store_radix_deletes;
52405+atomic_unchecked_t fscache_n_store_pages_over_limit;
52406
52407-atomic_t fscache_n_store_vmscan_not_storing;
52408-atomic_t fscache_n_store_vmscan_gone;
52409-atomic_t fscache_n_store_vmscan_busy;
52410-atomic_t fscache_n_store_vmscan_cancelled;
52411-atomic_t fscache_n_store_vmscan_wait;
52412+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52413+atomic_unchecked_t fscache_n_store_vmscan_gone;
52414+atomic_unchecked_t fscache_n_store_vmscan_busy;
52415+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52416+atomic_unchecked_t fscache_n_store_vmscan_wait;
52417
52418-atomic_t fscache_n_marks;
52419-atomic_t fscache_n_uncaches;
52420+atomic_unchecked_t fscache_n_marks;
52421+atomic_unchecked_t fscache_n_uncaches;
52422
52423-atomic_t fscache_n_acquires;
52424-atomic_t fscache_n_acquires_null;
52425-atomic_t fscache_n_acquires_no_cache;
52426-atomic_t fscache_n_acquires_ok;
52427-atomic_t fscache_n_acquires_nobufs;
52428-atomic_t fscache_n_acquires_oom;
52429+atomic_unchecked_t fscache_n_acquires;
52430+atomic_unchecked_t fscache_n_acquires_null;
52431+atomic_unchecked_t fscache_n_acquires_no_cache;
52432+atomic_unchecked_t fscache_n_acquires_ok;
52433+atomic_unchecked_t fscache_n_acquires_nobufs;
52434+atomic_unchecked_t fscache_n_acquires_oom;
52435
52436-atomic_t fscache_n_invalidates;
52437-atomic_t fscache_n_invalidates_run;
52438+atomic_unchecked_t fscache_n_invalidates;
52439+atomic_unchecked_t fscache_n_invalidates_run;
52440
52441-atomic_t fscache_n_updates;
52442-atomic_t fscache_n_updates_null;
52443-atomic_t fscache_n_updates_run;
52444+atomic_unchecked_t fscache_n_updates;
52445+atomic_unchecked_t fscache_n_updates_null;
52446+atomic_unchecked_t fscache_n_updates_run;
52447
52448-atomic_t fscache_n_relinquishes;
52449-atomic_t fscache_n_relinquishes_null;
52450-atomic_t fscache_n_relinquishes_waitcrt;
52451-atomic_t fscache_n_relinquishes_retire;
52452+atomic_unchecked_t fscache_n_relinquishes;
52453+atomic_unchecked_t fscache_n_relinquishes_null;
52454+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
52455+atomic_unchecked_t fscache_n_relinquishes_retire;
52456
52457-atomic_t fscache_n_cookie_index;
52458-atomic_t fscache_n_cookie_data;
52459-atomic_t fscache_n_cookie_special;
52460+atomic_unchecked_t fscache_n_cookie_index;
52461+atomic_unchecked_t fscache_n_cookie_data;
52462+atomic_unchecked_t fscache_n_cookie_special;
52463
52464-atomic_t fscache_n_object_alloc;
52465-atomic_t fscache_n_object_no_alloc;
52466-atomic_t fscache_n_object_lookups;
52467-atomic_t fscache_n_object_lookups_negative;
52468-atomic_t fscache_n_object_lookups_positive;
52469-atomic_t fscache_n_object_lookups_timed_out;
52470-atomic_t fscache_n_object_created;
52471-atomic_t fscache_n_object_avail;
52472-atomic_t fscache_n_object_dead;
52473+atomic_unchecked_t fscache_n_object_alloc;
52474+atomic_unchecked_t fscache_n_object_no_alloc;
52475+atomic_unchecked_t fscache_n_object_lookups;
52476+atomic_unchecked_t fscache_n_object_lookups_negative;
52477+atomic_unchecked_t fscache_n_object_lookups_positive;
52478+atomic_unchecked_t fscache_n_object_lookups_timed_out;
52479+atomic_unchecked_t fscache_n_object_created;
52480+atomic_unchecked_t fscache_n_object_avail;
52481+atomic_unchecked_t fscache_n_object_dead;
52482
52483-atomic_t fscache_n_checkaux_none;
52484-atomic_t fscache_n_checkaux_okay;
52485-atomic_t fscache_n_checkaux_update;
52486-atomic_t fscache_n_checkaux_obsolete;
52487+atomic_unchecked_t fscache_n_checkaux_none;
52488+atomic_unchecked_t fscache_n_checkaux_okay;
52489+atomic_unchecked_t fscache_n_checkaux_update;
52490+atomic_unchecked_t fscache_n_checkaux_obsolete;
52491
52492 atomic_t fscache_n_cop_alloc_object;
52493 atomic_t fscache_n_cop_lookup_object;
52494@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
52495 seq_puts(m, "FS-Cache statistics\n");
52496
52497 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
52498- atomic_read(&fscache_n_cookie_index),
52499- atomic_read(&fscache_n_cookie_data),
52500- atomic_read(&fscache_n_cookie_special));
52501+ atomic_read_unchecked(&fscache_n_cookie_index),
52502+ atomic_read_unchecked(&fscache_n_cookie_data),
52503+ atomic_read_unchecked(&fscache_n_cookie_special));
52504
52505 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
52506- atomic_read(&fscache_n_object_alloc),
52507- atomic_read(&fscache_n_object_no_alloc),
52508- atomic_read(&fscache_n_object_avail),
52509- atomic_read(&fscache_n_object_dead));
52510+ atomic_read_unchecked(&fscache_n_object_alloc),
52511+ atomic_read_unchecked(&fscache_n_object_no_alloc),
52512+ atomic_read_unchecked(&fscache_n_object_avail),
52513+ atomic_read_unchecked(&fscache_n_object_dead));
52514 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
52515- atomic_read(&fscache_n_checkaux_none),
52516- atomic_read(&fscache_n_checkaux_okay),
52517- atomic_read(&fscache_n_checkaux_update),
52518- atomic_read(&fscache_n_checkaux_obsolete));
52519+ atomic_read_unchecked(&fscache_n_checkaux_none),
52520+ atomic_read_unchecked(&fscache_n_checkaux_okay),
52521+ atomic_read_unchecked(&fscache_n_checkaux_update),
52522+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
52523
52524 seq_printf(m, "Pages : mrk=%u unc=%u\n",
52525- atomic_read(&fscache_n_marks),
52526- atomic_read(&fscache_n_uncaches));
52527+ atomic_read_unchecked(&fscache_n_marks),
52528+ atomic_read_unchecked(&fscache_n_uncaches));
52529
52530 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
52531 " oom=%u\n",
52532- atomic_read(&fscache_n_acquires),
52533- atomic_read(&fscache_n_acquires_null),
52534- atomic_read(&fscache_n_acquires_no_cache),
52535- atomic_read(&fscache_n_acquires_ok),
52536- atomic_read(&fscache_n_acquires_nobufs),
52537- atomic_read(&fscache_n_acquires_oom));
52538+ atomic_read_unchecked(&fscache_n_acquires),
52539+ atomic_read_unchecked(&fscache_n_acquires_null),
52540+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
52541+ atomic_read_unchecked(&fscache_n_acquires_ok),
52542+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
52543+ atomic_read_unchecked(&fscache_n_acquires_oom));
52544
52545 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
52546- atomic_read(&fscache_n_object_lookups),
52547- atomic_read(&fscache_n_object_lookups_negative),
52548- atomic_read(&fscache_n_object_lookups_positive),
52549- atomic_read(&fscache_n_object_created),
52550- atomic_read(&fscache_n_object_lookups_timed_out));
52551+ atomic_read_unchecked(&fscache_n_object_lookups),
52552+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
52553+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
52554+ atomic_read_unchecked(&fscache_n_object_created),
52555+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
52556
52557 seq_printf(m, "Invals : n=%u run=%u\n",
52558- atomic_read(&fscache_n_invalidates),
52559- atomic_read(&fscache_n_invalidates_run));
52560+ atomic_read_unchecked(&fscache_n_invalidates),
52561+ atomic_read_unchecked(&fscache_n_invalidates_run));
52562
52563 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
52564- atomic_read(&fscache_n_updates),
52565- atomic_read(&fscache_n_updates_null),
52566- atomic_read(&fscache_n_updates_run));
52567+ atomic_read_unchecked(&fscache_n_updates),
52568+ atomic_read_unchecked(&fscache_n_updates_null),
52569+ atomic_read_unchecked(&fscache_n_updates_run));
52570
52571 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
52572- atomic_read(&fscache_n_relinquishes),
52573- atomic_read(&fscache_n_relinquishes_null),
52574- atomic_read(&fscache_n_relinquishes_waitcrt),
52575- atomic_read(&fscache_n_relinquishes_retire));
52576+ atomic_read_unchecked(&fscache_n_relinquishes),
52577+ atomic_read_unchecked(&fscache_n_relinquishes_null),
52578+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
52579+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
52580
52581 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
52582- atomic_read(&fscache_n_attr_changed),
52583- atomic_read(&fscache_n_attr_changed_ok),
52584- atomic_read(&fscache_n_attr_changed_nobufs),
52585- atomic_read(&fscache_n_attr_changed_nomem),
52586- atomic_read(&fscache_n_attr_changed_calls));
52587+ atomic_read_unchecked(&fscache_n_attr_changed),
52588+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
52589+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
52590+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
52591+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
52592
52593 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
52594- atomic_read(&fscache_n_allocs),
52595- atomic_read(&fscache_n_allocs_ok),
52596- atomic_read(&fscache_n_allocs_wait),
52597- atomic_read(&fscache_n_allocs_nobufs),
52598- atomic_read(&fscache_n_allocs_intr));
52599+ atomic_read_unchecked(&fscache_n_allocs),
52600+ atomic_read_unchecked(&fscache_n_allocs_ok),
52601+ atomic_read_unchecked(&fscache_n_allocs_wait),
52602+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
52603+ atomic_read_unchecked(&fscache_n_allocs_intr));
52604 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
52605- atomic_read(&fscache_n_alloc_ops),
52606- atomic_read(&fscache_n_alloc_op_waits),
52607- atomic_read(&fscache_n_allocs_object_dead));
52608+ atomic_read_unchecked(&fscache_n_alloc_ops),
52609+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
52610+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
52611
52612 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
52613 " int=%u oom=%u\n",
52614- atomic_read(&fscache_n_retrievals),
52615- atomic_read(&fscache_n_retrievals_ok),
52616- atomic_read(&fscache_n_retrievals_wait),
52617- atomic_read(&fscache_n_retrievals_nodata),
52618- atomic_read(&fscache_n_retrievals_nobufs),
52619- atomic_read(&fscache_n_retrievals_intr),
52620- atomic_read(&fscache_n_retrievals_nomem));
52621+ atomic_read_unchecked(&fscache_n_retrievals),
52622+ atomic_read_unchecked(&fscache_n_retrievals_ok),
52623+ atomic_read_unchecked(&fscache_n_retrievals_wait),
52624+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
52625+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
52626+ atomic_read_unchecked(&fscache_n_retrievals_intr),
52627+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
52628 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
52629- atomic_read(&fscache_n_retrieval_ops),
52630- atomic_read(&fscache_n_retrieval_op_waits),
52631- atomic_read(&fscache_n_retrievals_object_dead));
52632+ atomic_read_unchecked(&fscache_n_retrieval_ops),
52633+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
52634+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
52635
52636 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
52637- atomic_read(&fscache_n_stores),
52638- atomic_read(&fscache_n_stores_ok),
52639- atomic_read(&fscache_n_stores_again),
52640- atomic_read(&fscache_n_stores_nobufs),
52641- atomic_read(&fscache_n_stores_oom));
52642+ atomic_read_unchecked(&fscache_n_stores),
52643+ atomic_read_unchecked(&fscache_n_stores_ok),
52644+ atomic_read_unchecked(&fscache_n_stores_again),
52645+ atomic_read_unchecked(&fscache_n_stores_nobufs),
52646+ atomic_read_unchecked(&fscache_n_stores_oom));
52647 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
52648- atomic_read(&fscache_n_store_ops),
52649- atomic_read(&fscache_n_store_calls),
52650- atomic_read(&fscache_n_store_pages),
52651- atomic_read(&fscache_n_store_radix_deletes),
52652- atomic_read(&fscache_n_store_pages_over_limit));
52653+ atomic_read_unchecked(&fscache_n_store_ops),
52654+ atomic_read_unchecked(&fscache_n_store_calls),
52655+ atomic_read_unchecked(&fscache_n_store_pages),
52656+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
52657+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
52658
52659 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
52660- atomic_read(&fscache_n_store_vmscan_not_storing),
52661- atomic_read(&fscache_n_store_vmscan_gone),
52662- atomic_read(&fscache_n_store_vmscan_busy),
52663- atomic_read(&fscache_n_store_vmscan_cancelled),
52664- atomic_read(&fscache_n_store_vmscan_wait));
52665+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
52666+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
52667+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
52668+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
52669+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
52670
52671 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
52672- atomic_read(&fscache_n_op_pend),
52673- atomic_read(&fscache_n_op_run),
52674- atomic_read(&fscache_n_op_enqueue),
52675- atomic_read(&fscache_n_op_cancelled),
52676- atomic_read(&fscache_n_op_rejected));
52677+ atomic_read_unchecked(&fscache_n_op_pend),
52678+ atomic_read_unchecked(&fscache_n_op_run),
52679+ atomic_read_unchecked(&fscache_n_op_enqueue),
52680+ atomic_read_unchecked(&fscache_n_op_cancelled),
52681+ atomic_read_unchecked(&fscache_n_op_rejected));
52682 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
52683- atomic_read(&fscache_n_op_deferred_release),
52684- atomic_read(&fscache_n_op_release),
52685- atomic_read(&fscache_n_op_gc));
52686+ atomic_read_unchecked(&fscache_n_op_deferred_release),
52687+ atomic_read_unchecked(&fscache_n_op_release),
52688+ atomic_read_unchecked(&fscache_n_op_gc));
52689
52690 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
52691 atomic_read(&fscache_n_cop_alloc_object),
52692diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
52693index e397b67..b0d8709 100644
52694--- a/fs/fuse/cuse.c
52695+++ b/fs/fuse/cuse.c
52696@@ -593,10 +593,12 @@ static int __init cuse_init(void)
52697 INIT_LIST_HEAD(&cuse_conntbl[i]);
52698
52699 /* inherit and extend fuse_dev_operations */
52700- cuse_channel_fops = fuse_dev_operations;
52701- cuse_channel_fops.owner = THIS_MODULE;
52702- cuse_channel_fops.open = cuse_channel_open;
52703- cuse_channel_fops.release = cuse_channel_release;
52704+ pax_open_kernel();
52705+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
52706+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
52707+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
52708+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
52709+ pax_close_kernel();
52710
52711 cuse_class = class_create(THIS_MODULE, "cuse");
52712 if (IS_ERR(cuse_class))
52713diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
52714index e83351a..41e3c9c 100644
52715--- a/fs/fuse/dev.c
52716+++ b/fs/fuse/dev.c
52717@@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
52718 ret = 0;
52719 pipe_lock(pipe);
52720
52721- if (!pipe->readers) {
52722+ if (!atomic_read(&pipe->readers)) {
52723 send_sig(SIGPIPE, current, 0);
52724 if (!ret)
52725 ret = -EPIPE;
52726diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
52727index 315e1f8..91f890c 100644
52728--- a/fs/fuse/dir.c
52729+++ b/fs/fuse/dir.c
52730@@ -1233,7 +1233,7 @@ static char *read_link(struct dentry *dentry)
52731 return link;
52732 }
52733
52734-static void free_link(char *link)
52735+static void free_link(const char *link)
52736 {
52737 if (!IS_ERR(link))
52738 free_page((unsigned long) link);
52739diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
52740index 2b6f569..fcb4d1f 100644
52741--- a/fs/gfs2/inode.c
52742+++ b/fs/gfs2/inode.c
52743@@ -1499,7 +1499,7 @@ out:
52744
52745 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52746 {
52747- char *s = nd_get_link(nd);
52748+ const char *s = nd_get_link(nd);
52749 if (!IS_ERR(s))
52750 kfree(s);
52751 }
52752diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
52753index 78bde32..767e906 100644
52754--- a/fs/hugetlbfs/inode.c
52755+++ b/fs/hugetlbfs/inode.c
52756@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52757 struct mm_struct *mm = current->mm;
52758 struct vm_area_struct *vma;
52759 struct hstate *h = hstate_file(file);
52760+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
52761 struct vm_unmapped_area_info info;
52762
52763 if (len & ~huge_page_mask(h))
52764@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52765 return addr;
52766 }
52767
52768+#ifdef CONFIG_PAX_RANDMMAP
52769+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
52770+#endif
52771+
52772 if (addr) {
52773 addr = ALIGN(addr, huge_page_size(h));
52774 vma = find_vma(mm, addr);
52775- if (TASK_SIZE - len >= addr &&
52776- (!vma || addr + len <= vma->vm_start))
52777+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
52778 return addr;
52779 }
52780
52781 info.flags = 0;
52782 info.length = len;
52783 info.low_limit = TASK_UNMAPPED_BASE;
52784+
52785+#ifdef CONFIG_PAX_RANDMMAP
52786+ if (mm->pax_flags & MF_PAX_RANDMMAP)
52787+ info.low_limit += mm->delta_mmap;
52788+#endif
52789+
52790 info.high_limit = TASK_SIZE;
52791 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
52792 info.align_offset = 0;
52793@@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
52794 .kill_sb = kill_litter_super,
52795 };
52796
52797-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52798+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52799
52800 static int can_do_hugetlb_shm(void)
52801 {
52802diff --git a/fs/inode.c b/fs/inode.c
52803index 14084b7..29af1d9 100644
52804--- a/fs/inode.c
52805+++ b/fs/inode.c
52806@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
52807
52808 #ifdef CONFIG_SMP
52809 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
52810- static atomic_t shared_last_ino;
52811- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
52812+ static atomic_unchecked_t shared_last_ino;
52813+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
52814
52815 res = next - LAST_INO_BATCH;
52816 }
52817diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
52818index 4a6cf28..d3a29d3 100644
52819--- a/fs/jffs2/erase.c
52820+++ b/fs/jffs2/erase.c
52821@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
52822 struct jffs2_unknown_node marker = {
52823 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
52824 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52825- .totlen = cpu_to_je32(c->cleanmarker_size)
52826+ .totlen = cpu_to_je32(c->cleanmarker_size),
52827+ .hdr_crc = cpu_to_je32(0)
52828 };
52829
52830 jffs2_prealloc_raw_node_refs(c, jeb, 1);
52831diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
52832index a6597d6..41b30ec 100644
52833--- a/fs/jffs2/wbuf.c
52834+++ b/fs/jffs2/wbuf.c
52835@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
52836 {
52837 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
52838 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52839- .totlen = constant_cpu_to_je32(8)
52840+ .totlen = constant_cpu_to_je32(8),
52841+ .hdr_crc = constant_cpu_to_je32(0)
52842 };
52843
52844 /*
52845diff --git a/fs/jfs/super.c b/fs/jfs/super.c
52846index 1a543be..a4e1363 100644
52847--- a/fs/jfs/super.c
52848+++ b/fs/jfs/super.c
52849@@ -225,7 +225,7 @@ static const match_table_t tokens = {
52850 static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52851 int *flag)
52852 {
52853- void *nls_map = (void *)-1; /* -1: no change; NULL: none */
52854+ const void *nls_map = (const void *)-1; /* -1: no change; NULL: none */
52855 char *p;
52856 struct jfs_sb_info *sbi = JFS_SBI(sb);
52857
52858@@ -253,7 +253,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52859 /* Don't do anything ;-) */
52860 break;
52861 case Opt_iocharset:
52862- if (nls_map && nls_map != (void *) -1)
52863+ if (nls_map && nls_map != (const void *) -1)
52864 unload_nls(nls_map);
52865 if (!strcmp(args[0].from, "none"))
52866 nls_map = NULL;
52867@@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
52868
52869 jfs_inode_cachep =
52870 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
52871- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
52872+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
52873 init_once);
52874 if (jfs_inode_cachep == NULL)
52875 return -ENOMEM;
52876diff --git a/fs/libfs.c b/fs/libfs.c
52877index 916da8c..1588998 100644
52878--- a/fs/libfs.c
52879+++ b/fs/libfs.c
52880@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52881
52882 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
52883 struct dentry *next;
52884+ char d_name[sizeof(next->d_iname)];
52885+ const unsigned char *name;
52886+
52887 next = list_entry(p, struct dentry, d_u.d_child);
52888 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
52889 if (!simple_positive(next)) {
52890@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52891
52892 spin_unlock(&next->d_lock);
52893 spin_unlock(&dentry->d_lock);
52894- if (filldir(dirent, next->d_name.name,
52895+ name = next->d_name.name;
52896+ if (name == next->d_iname) {
52897+ memcpy(d_name, name, next->d_name.len);
52898+ name = d_name;
52899+ }
52900+ if (filldir(dirent, name,
52901 next->d_name.len, filp->f_pos,
52902 next->d_inode->i_ino,
52903 dt_type(next->d_inode)) < 0)
52904diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
52905index 52e5120..808936e 100644
52906--- a/fs/lockd/clntproc.c
52907+++ b/fs/lockd/clntproc.c
52908@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
52909 /*
52910 * Cookie counter for NLM requests
52911 */
52912-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
52913+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
52914
52915 void nlmclnt_next_cookie(struct nlm_cookie *c)
52916 {
52917- u32 cookie = atomic_inc_return(&nlm_cookie);
52918+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
52919
52920 memcpy(c->data, &cookie, 4);
52921 c->len=4;
52922diff --git a/fs/locks.c b/fs/locks.c
52923index a94e331..060bce3 100644
52924--- a/fs/locks.c
52925+++ b/fs/locks.c
52926@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
52927 return;
52928
52929 if (filp->f_op && filp->f_op->flock) {
52930- struct file_lock fl = {
52931+ struct file_lock flock = {
52932 .fl_pid = current->tgid,
52933 .fl_file = filp,
52934 .fl_flags = FL_FLOCK,
52935 .fl_type = F_UNLCK,
52936 .fl_end = OFFSET_MAX,
52937 };
52938- filp->f_op->flock(filp, F_SETLKW, &fl);
52939- if (fl.fl_ops && fl.fl_ops->fl_release_private)
52940- fl.fl_ops->fl_release_private(&fl);
52941+ filp->f_op->flock(filp, F_SETLKW, &flock);
52942+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
52943+ flock.fl_ops->fl_release_private(&flock);
52944 }
52945
52946 lock_flocks();
52947diff --git a/fs/namei.c b/fs/namei.c
52948index ec97aef..e67718d 100644
52949--- a/fs/namei.c
52950+++ b/fs/namei.c
52951@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
52952 if (ret != -EACCES)
52953 return ret;
52954
52955+#ifdef CONFIG_GRKERNSEC
52956+ /* we'll block if we have to log due to a denied capability use */
52957+ if (mask & MAY_NOT_BLOCK)
52958+ return -ECHILD;
52959+#endif
52960+
52961 if (S_ISDIR(inode->i_mode)) {
52962 /* DACs are overridable for directories */
52963- if (inode_capable(inode, CAP_DAC_OVERRIDE))
52964- return 0;
52965 if (!(mask & MAY_WRITE))
52966- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52967+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52968+ inode_capable(inode, CAP_DAC_READ_SEARCH))
52969 return 0;
52970+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
52971+ return 0;
52972 return -EACCES;
52973 }
52974 /*
52975+ * Searching includes executable on directories, else just read.
52976+ */
52977+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52978+ if (mask == MAY_READ)
52979+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52980+ inode_capable(inode, CAP_DAC_READ_SEARCH))
52981+ return 0;
52982+
52983+ /*
52984 * Read/write DACs are always overridable.
52985 * Executable DACs are overridable when there is
52986 * at least one exec bit set.
52987@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
52988 if (inode_capable(inode, CAP_DAC_OVERRIDE))
52989 return 0;
52990
52991- /*
52992- * Searching includes executable on directories, else just read.
52993- */
52994- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52995- if (mask == MAY_READ)
52996- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52997- return 0;
52998-
52999 return -EACCES;
53000 }
53001
53002@@ -824,7 +832,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53003 {
53004 struct dentry *dentry = link->dentry;
53005 int error;
53006- char *s;
53007+ const char *s;
53008
53009 BUG_ON(nd->flags & LOOKUP_RCU);
53010
53011@@ -845,6 +853,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53012 if (error)
53013 goto out_put_nd_path;
53014
53015+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
53016+ dentry->d_inode, dentry, nd->path.mnt)) {
53017+ error = -EACCES;
53018+ goto out_put_nd_path;
53019+ }
53020+
53021 nd->last_type = LAST_BIND;
53022 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
53023 error = PTR_ERR(*p);
53024@@ -1594,6 +1608,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
53025 break;
53026 res = walk_component(nd, path, &nd->last,
53027 nd->last_type, LOOKUP_FOLLOW);
53028+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
53029+ res = -EACCES;
53030 put_link(nd, &link, cookie);
53031 } while (res > 0);
53032
53033@@ -1692,7 +1708,7 @@ EXPORT_SYMBOL(full_name_hash);
53034 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
53035 {
53036 unsigned long a, b, adata, bdata, mask, hash, len;
53037- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53038+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53039
53040 hash = a = 0;
53041 len = -sizeof(unsigned long);
53042@@ -1977,6 +1993,8 @@ static int path_lookupat(int dfd, const char *name,
53043 if (err)
53044 break;
53045 err = lookup_last(nd, &path);
53046+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
53047+ err = -EACCES;
53048 put_link(nd, &link, cookie);
53049 }
53050 }
53051@@ -1984,6 +2002,13 @@ static int path_lookupat(int dfd, const char *name,
53052 if (!err)
53053 err = complete_walk(nd);
53054
53055+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
53056+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53057+ path_put(&nd->path);
53058+ err = -ENOENT;
53059+ }
53060+ }
53061+
53062 if (!err && nd->flags & LOOKUP_DIRECTORY) {
53063 if (!nd->inode->i_op->lookup) {
53064 path_put(&nd->path);
53065@@ -2011,8 +2036,15 @@ static int filename_lookup(int dfd, struct filename *name,
53066 retval = path_lookupat(dfd, name->name,
53067 flags | LOOKUP_REVAL, nd);
53068
53069- if (likely(!retval))
53070+ if (likely(!retval)) {
53071 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
53072+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
53073+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
53074+ path_put(&nd->path);
53075+ return -ENOENT;
53076+ }
53077+ }
53078+ }
53079 return retval;
53080 }
53081
53082@@ -2390,6 +2422,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
53083 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
53084 return -EPERM;
53085
53086+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
53087+ return -EPERM;
53088+ if (gr_handle_rawio(inode))
53089+ return -EPERM;
53090+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
53091+ return -EACCES;
53092+
53093 return 0;
53094 }
53095
53096@@ -2611,7 +2650,7 @@ looked_up:
53097 * cleared otherwise prior to returning.
53098 */
53099 static int lookup_open(struct nameidata *nd, struct path *path,
53100- struct file *file,
53101+ struct path *link, struct file *file,
53102 const struct open_flags *op,
53103 bool got_write, int *opened)
53104 {
53105@@ -2646,6 +2685,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53106 /* Negative dentry, just create the file */
53107 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
53108 umode_t mode = op->mode;
53109+
53110+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
53111+ error = -EACCES;
53112+ goto out_dput;
53113+ }
53114+
53115+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
53116+ error = -EACCES;
53117+ goto out_dput;
53118+ }
53119+
53120 if (!IS_POSIXACL(dir->d_inode))
53121 mode &= ~current_umask();
53122 /*
53123@@ -2667,6 +2717,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53124 nd->flags & LOOKUP_EXCL);
53125 if (error)
53126 goto out_dput;
53127+ else
53128+ gr_handle_create(dentry, nd->path.mnt);
53129 }
53130 out_no_open:
53131 path->dentry = dentry;
53132@@ -2681,7 +2733,7 @@ out_dput:
53133 /*
53134 * Handle the last step of open()
53135 */
53136-static int do_last(struct nameidata *nd, struct path *path,
53137+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
53138 struct file *file, const struct open_flags *op,
53139 int *opened, struct filename *name)
53140 {
53141@@ -2710,16 +2762,32 @@ static int do_last(struct nameidata *nd, struct path *path,
53142 error = complete_walk(nd);
53143 if (error)
53144 return error;
53145+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53146+ error = -ENOENT;
53147+ goto out;
53148+ }
53149 audit_inode(name, nd->path.dentry, 0);
53150 if (open_flag & O_CREAT) {
53151 error = -EISDIR;
53152 goto out;
53153 }
53154+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53155+ error = -EACCES;
53156+ goto out;
53157+ }
53158 goto finish_open;
53159 case LAST_BIND:
53160 error = complete_walk(nd);
53161 if (error)
53162 return error;
53163+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
53164+ error = -ENOENT;
53165+ goto out;
53166+ }
53167+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53168+ error = -EACCES;
53169+ goto out;
53170+ }
53171 audit_inode(name, dir, 0);
53172 goto finish_open;
53173 }
53174@@ -2768,7 +2836,7 @@ retry_lookup:
53175 */
53176 }
53177 mutex_lock(&dir->d_inode->i_mutex);
53178- error = lookup_open(nd, path, file, op, got_write, opened);
53179+ error = lookup_open(nd, path, link, file, op, got_write, opened);
53180 mutex_unlock(&dir->d_inode->i_mutex);
53181
53182 if (error <= 0) {
53183@@ -2792,11 +2860,28 @@ retry_lookup:
53184 goto finish_open_created;
53185 }
53186
53187+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
53188+ error = -ENOENT;
53189+ goto exit_dput;
53190+ }
53191+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
53192+ error = -EACCES;
53193+ goto exit_dput;
53194+ }
53195+
53196 /*
53197 * create/update audit record if it already exists.
53198 */
53199- if (path->dentry->d_inode)
53200+ if (path->dentry->d_inode) {
53201+ /* only check if O_CREAT is specified, all other checks need to go
53202+ into may_open */
53203+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
53204+ error = -EACCES;
53205+ goto exit_dput;
53206+ }
53207+
53208 audit_inode(name, path->dentry, 0);
53209+ }
53210
53211 /*
53212 * If atomic_open() acquired write access it is dropped now due to
53213@@ -2837,6 +2922,11 @@ finish_lookup:
53214 }
53215 }
53216 BUG_ON(inode != path->dentry->d_inode);
53217+ /* if we're resolving a symlink to another symlink */
53218+ if (link && gr_handle_symlink_owner(link, inode)) {
53219+ error = -EACCES;
53220+ goto out;
53221+ }
53222 return 1;
53223 }
53224
53225@@ -2846,7 +2936,6 @@ finish_lookup:
53226 save_parent.dentry = nd->path.dentry;
53227 save_parent.mnt = mntget(path->mnt);
53228 nd->path.dentry = path->dentry;
53229-
53230 }
53231 nd->inode = inode;
53232 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
53233@@ -2855,6 +2944,16 @@ finish_lookup:
53234 path_put(&save_parent);
53235 return error;
53236 }
53237+
53238+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53239+ error = -ENOENT;
53240+ goto out;
53241+ }
53242+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53243+ error = -EACCES;
53244+ goto out;
53245+ }
53246+
53247 error = -EISDIR;
53248 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
53249 goto out;
53250@@ -2953,7 +3052,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53251 if (unlikely(error))
53252 goto out;
53253
53254- error = do_last(nd, &path, file, op, &opened, pathname);
53255+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
53256 while (unlikely(error > 0)) { /* trailing symlink */
53257 struct path link = path;
53258 void *cookie;
53259@@ -2971,7 +3070,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53260 error = follow_link(&link, nd, &cookie);
53261 if (unlikely(error))
53262 break;
53263- error = do_last(nd, &path, file, op, &opened, pathname);
53264+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
53265 put_link(nd, &link, cookie);
53266 }
53267 out:
53268@@ -3071,8 +3170,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
53269 goto unlock;
53270
53271 error = -EEXIST;
53272- if (dentry->d_inode)
53273+ if (dentry->d_inode) {
53274+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
53275+ error = -ENOENT;
53276+ }
53277 goto fail;
53278+ }
53279 /*
53280 * Special case - lookup gave negative, but... we had foo/bar/
53281 * From the vfs_mknod() POV we just have a negative dentry -
53282@@ -3124,6 +3227,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
53283 }
53284 EXPORT_SYMBOL(user_path_create);
53285
53286+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
53287+{
53288+ struct filename *tmp = getname(pathname);
53289+ struct dentry *res;
53290+ if (IS_ERR(tmp))
53291+ return ERR_CAST(tmp);
53292+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
53293+ if (IS_ERR(res))
53294+ putname(tmp);
53295+ else
53296+ *to = tmp;
53297+ return res;
53298+}
53299+
53300 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
53301 {
53302 int error = may_create(dir, dentry);
53303@@ -3186,6 +3303,17 @@ retry:
53304
53305 if (!IS_POSIXACL(path.dentry->d_inode))
53306 mode &= ~current_umask();
53307+
53308+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
53309+ error = -EPERM;
53310+ goto out;
53311+ }
53312+
53313+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
53314+ error = -EACCES;
53315+ goto out;
53316+ }
53317+
53318 error = security_path_mknod(&path, dentry, mode, dev);
53319 if (error)
53320 goto out;
53321@@ -3202,6 +3330,8 @@ retry:
53322 break;
53323 }
53324 out:
53325+ if (!error)
53326+ gr_handle_create(dentry, path.mnt);
53327 done_path_create(&path, dentry);
53328 if (retry_estale(error, lookup_flags)) {
53329 lookup_flags |= LOOKUP_REVAL;
53330@@ -3254,9 +3384,16 @@ retry:
53331
53332 if (!IS_POSIXACL(path.dentry->d_inode))
53333 mode &= ~current_umask();
53334+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
53335+ error = -EACCES;
53336+ goto out;
53337+ }
53338 error = security_path_mkdir(&path, dentry, mode);
53339 if (!error)
53340 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
53341+ if (!error)
53342+ gr_handle_create(dentry, path.mnt);
53343+out:
53344 done_path_create(&path, dentry);
53345 if (retry_estale(error, lookup_flags)) {
53346 lookup_flags |= LOOKUP_REVAL;
53347@@ -3337,6 +3474,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
53348 struct filename *name;
53349 struct dentry *dentry;
53350 struct nameidata nd;
53351+ ino_t saved_ino = 0;
53352+ dev_t saved_dev = 0;
53353 unsigned int lookup_flags = 0;
53354 retry:
53355 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53356@@ -3369,10 +3508,21 @@ retry:
53357 error = -ENOENT;
53358 goto exit3;
53359 }
53360+
53361+ saved_ino = dentry->d_inode->i_ino;
53362+ saved_dev = gr_get_dev_from_dentry(dentry);
53363+
53364+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
53365+ error = -EACCES;
53366+ goto exit3;
53367+ }
53368+
53369 error = security_path_rmdir(&nd.path, dentry);
53370 if (error)
53371 goto exit3;
53372 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
53373+ if (!error && (saved_dev || saved_ino))
53374+ gr_handle_delete(saved_ino, saved_dev);
53375 exit3:
53376 dput(dentry);
53377 exit2:
53378@@ -3438,6 +3588,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
53379 struct dentry *dentry;
53380 struct nameidata nd;
53381 struct inode *inode = NULL;
53382+ ino_t saved_ino = 0;
53383+ dev_t saved_dev = 0;
53384 unsigned int lookup_flags = 0;
53385 retry:
53386 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53387@@ -3464,10 +3616,22 @@ retry:
53388 if (!inode)
53389 goto slashes;
53390 ihold(inode);
53391+
53392+ if (inode->i_nlink <= 1) {
53393+ saved_ino = inode->i_ino;
53394+ saved_dev = gr_get_dev_from_dentry(dentry);
53395+ }
53396+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
53397+ error = -EACCES;
53398+ goto exit2;
53399+ }
53400+
53401 error = security_path_unlink(&nd.path, dentry);
53402 if (error)
53403 goto exit2;
53404 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
53405+ if (!error && (saved_ino || saved_dev))
53406+ gr_handle_delete(saved_ino, saved_dev);
53407 exit2:
53408 dput(dentry);
53409 }
53410@@ -3545,9 +3709,17 @@ retry:
53411 if (IS_ERR(dentry))
53412 goto out_putname;
53413
53414+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
53415+ error = -EACCES;
53416+ goto out;
53417+ }
53418+
53419 error = security_path_symlink(&path, dentry, from->name);
53420 if (!error)
53421 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
53422+ if (!error)
53423+ gr_handle_create(dentry, path.mnt);
53424+out:
53425 done_path_create(&path, dentry);
53426 if (retry_estale(error, lookup_flags)) {
53427 lookup_flags |= LOOKUP_REVAL;
53428@@ -3621,6 +3793,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
53429 {
53430 struct dentry *new_dentry;
53431 struct path old_path, new_path;
53432+ struct filename *to = NULL;
53433 int how = 0;
53434 int error;
53435
53436@@ -3644,7 +3817,7 @@ retry:
53437 if (error)
53438 return error;
53439
53440- new_dentry = user_path_create(newdfd, newname, &new_path,
53441+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
53442 (how & LOOKUP_REVAL));
53443 error = PTR_ERR(new_dentry);
53444 if (IS_ERR(new_dentry))
53445@@ -3656,11 +3829,28 @@ retry:
53446 error = may_linkat(&old_path);
53447 if (unlikely(error))
53448 goto out_dput;
53449+
53450+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
53451+ old_path.dentry->d_inode,
53452+ old_path.dentry->d_inode->i_mode, to)) {
53453+ error = -EACCES;
53454+ goto out_dput;
53455+ }
53456+
53457+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
53458+ old_path.dentry, old_path.mnt, to)) {
53459+ error = -EACCES;
53460+ goto out_dput;
53461+ }
53462+
53463 error = security_path_link(old_path.dentry, &new_path, new_dentry);
53464 if (error)
53465 goto out_dput;
53466 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
53467+ if (!error)
53468+ gr_handle_create(new_dentry, new_path.mnt);
53469 out_dput:
53470+ putname(to);
53471 done_path_create(&new_path, new_dentry);
53472 if (retry_estale(error, how)) {
53473 how |= LOOKUP_REVAL;
53474@@ -3906,12 +4096,21 @@ retry:
53475 if (new_dentry == trap)
53476 goto exit5;
53477
53478+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
53479+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
53480+ to);
53481+ if (error)
53482+ goto exit5;
53483+
53484 error = security_path_rename(&oldnd.path, old_dentry,
53485 &newnd.path, new_dentry);
53486 if (error)
53487 goto exit5;
53488 error = vfs_rename(old_dir->d_inode, old_dentry,
53489 new_dir->d_inode, new_dentry);
53490+ if (!error)
53491+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
53492+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
53493 exit5:
53494 dput(new_dentry);
53495 exit4:
53496@@ -3943,6 +4142,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
53497
53498 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
53499 {
53500+ char tmpbuf[64];
53501+ const char *newlink;
53502 int len;
53503
53504 len = PTR_ERR(link);
53505@@ -3952,7 +4153,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
53506 len = strlen(link);
53507 if (len > (unsigned) buflen)
53508 len = buflen;
53509- if (copy_to_user(buffer, link, len))
53510+
53511+ if (len < sizeof(tmpbuf)) {
53512+ memcpy(tmpbuf, link, len);
53513+ newlink = tmpbuf;
53514+ } else
53515+ newlink = link;
53516+
53517+ if (copy_to_user(buffer, newlink, len))
53518 len = -EFAULT;
53519 out:
53520 return len;
53521diff --git a/fs/namespace.c b/fs/namespace.c
53522index a51054f..f9b53e5 100644
53523--- a/fs/namespace.c
53524+++ b/fs/namespace.c
53525@@ -1215,6 +1215,9 @@ static int do_umount(struct mount *mnt, int flags)
53526 if (!(sb->s_flags & MS_RDONLY))
53527 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
53528 up_write(&sb->s_umount);
53529+
53530+ gr_log_remount(mnt->mnt_devname, retval);
53531+
53532 return retval;
53533 }
53534
53535@@ -1234,6 +1237,9 @@ static int do_umount(struct mount *mnt, int flags)
53536 br_write_unlock(&vfsmount_lock);
53537 up_write(&namespace_sem);
53538 release_mounts(&umount_list);
53539+
53540+ gr_log_unmount(mnt->mnt_devname, retval);
53541+
53542 return retval;
53543 }
53544
53545@@ -2287,6 +2293,16 @@ long do_mount(const char *dev_name, const char *dir_name,
53546 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
53547 MS_STRICTATIME);
53548
53549+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
53550+ retval = -EPERM;
53551+ goto dput_out;
53552+ }
53553+
53554+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
53555+ retval = -EPERM;
53556+ goto dput_out;
53557+ }
53558+
53559 if (flags & MS_REMOUNT)
53560 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
53561 data_page);
53562@@ -2301,6 +2317,9 @@ long do_mount(const char *dev_name, const char *dir_name,
53563 dev_name, data_page);
53564 dput_out:
53565 path_put(&path);
53566+
53567+ gr_log_mount(dev_name, dir_name, retval);
53568+
53569 return retval;
53570 }
53571
53572@@ -2587,6 +2606,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
53573 if (error)
53574 goto out2;
53575
53576+ if (gr_handle_chroot_pivot()) {
53577+ error = -EPERM;
53578+ goto out2;
53579+ }
53580+
53581 get_fs_root(current->fs, &root);
53582 error = lock_mount(&old);
53583 if (error)
53584@@ -2790,7 +2814,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
53585 !nsown_capable(CAP_SYS_ADMIN))
53586 return -EPERM;
53587
53588- if (fs->users != 1)
53589+ if (atomic_read(&fs->users) != 1)
53590 return -EINVAL;
53591
53592 get_mnt_ns(mnt_ns);
53593diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
53594index 59461c9..b17c57e 100644
53595--- a/fs/nfs/callback_xdr.c
53596+++ b/fs/nfs/callback_xdr.c
53597@@ -51,7 +51,7 @@ struct callback_op {
53598 callback_decode_arg_t decode_args;
53599 callback_encode_res_t encode_res;
53600 long res_maxsize;
53601-};
53602+} __do_const;
53603
53604 static struct callback_op callback_ops[];
53605
53606diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
53607index ebeb94c..ff35337 100644
53608--- a/fs/nfs/inode.c
53609+++ b/fs/nfs/inode.c
53610@@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
53611 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
53612 }
53613
53614-static atomic_long_t nfs_attr_generation_counter;
53615+static atomic_long_unchecked_t nfs_attr_generation_counter;
53616
53617 static unsigned long nfs_read_attr_generation_counter(void)
53618 {
53619- return atomic_long_read(&nfs_attr_generation_counter);
53620+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
53621 }
53622
53623 unsigned long nfs_inc_attr_generation_counter(void)
53624 {
53625- return atomic_long_inc_return(&nfs_attr_generation_counter);
53626+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
53627 }
53628
53629 void nfs_fattr_init(struct nfs_fattr *fattr)
53630diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
53631index 9d1c5db..1e13db8 100644
53632--- a/fs/nfsd/nfs4proc.c
53633+++ b/fs/nfsd/nfs4proc.c
53634@@ -1097,7 +1097,7 @@ struct nfsd4_operation {
53635 nfsd4op_rsize op_rsize_bop;
53636 stateid_getter op_get_currentstateid;
53637 stateid_setter op_set_currentstateid;
53638-};
53639+} __do_const;
53640
53641 static struct nfsd4_operation nfsd4_ops[];
53642
53643diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
53644index 0dc1158..32ac0e8 100644
53645--- a/fs/nfsd/nfs4xdr.c
53646+++ b/fs/nfsd/nfs4xdr.c
53647@@ -264,7 +264,7 @@ nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval,
53648 iattr->ia_valid |= ATTR_SIZE;
53649 }
53650 if (bmval[0] & FATTR4_WORD0_ACL) {
53651- int nace;
53652+ u32 nace;
53653 struct nfs4_ace *ace;
53654
53655 READ_BUF(4); len += 4;
53656@@ -1456,7 +1456,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
53657
53658 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
53659
53660-static nfsd4_dec nfsd4_dec_ops[] = {
53661+static const nfsd4_dec nfsd4_dec_ops[] = {
53662 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53663 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53664 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53665@@ -1496,7 +1496,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
53666 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
53667 };
53668
53669-static nfsd4_dec nfsd41_dec_ops[] = {
53670+static const nfsd4_dec nfsd41_dec_ops[] = {
53671 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53672 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53673 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53674@@ -1558,7 +1558,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
53675 };
53676
53677 struct nfsd4_minorversion_ops {
53678- nfsd4_dec *decoders;
53679+ const nfsd4_dec *decoders;
53680 int nops;
53681 };
53682
53683diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
53684index 69c6413..c0408d2 100644
53685--- a/fs/nfsd/vfs.c
53686+++ b/fs/nfsd/vfs.c
53687@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53688 } else {
53689 oldfs = get_fs();
53690 set_fs(KERNEL_DS);
53691- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
53692+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
53693 set_fs(oldfs);
53694 }
53695
53696@@ -1026,7 +1026,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53697
53698 /* Write the data. */
53699 oldfs = get_fs(); set_fs(KERNEL_DS);
53700- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
53701+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
53702 set_fs(oldfs);
53703 if (host_err < 0)
53704 goto out_nfserr;
53705@@ -1572,7 +1572,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
53706 */
53707
53708 oldfs = get_fs(); set_fs(KERNEL_DS);
53709- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
53710+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
53711 set_fs(oldfs);
53712
53713 if (host_err < 0)
53714diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
53715index fea6bd5..8ee9d81 100644
53716--- a/fs/nls/nls_base.c
53717+++ b/fs/nls/nls_base.c
53718@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
53719
53720 int register_nls(struct nls_table * nls)
53721 {
53722- struct nls_table ** tmp = &tables;
53723+ struct nls_table *tmp = tables;
53724
53725 if (nls->next)
53726 return -EBUSY;
53727
53728 spin_lock(&nls_lock);
53729- while (*tmp) {
53730- if (nls == *tmp) {
53731+ while (tmp) {
53732+ if (nls == tmp) {
53733 spin_unlock(&nls_lock);
53734 return -EBUSY;
53735 }
53736- tmp = &(*tmp)->next;
53737+ tmp = tmp->next;
53738 }
53739- nls->next = tables;
53740+ pax_open_kernel();
53741+ *(struct nls_table **)&nls->next = tables;
53742+ pax_close_kernel();
53743 tables = nls;
53744 spin_unlock(&nls_lock);
53745 return 0;
53746@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
53747
53748 int unregister_nls(struct nls_table * nls)
53749 {
53750- struct nls_table ** tmp = &tables;
53751+ struct nls_table * const * tmp = &tables;
53752
53753 spin_lock(&nls_lock);
53754 while (*tmp) {
53755 if (nls == *tmp) {
53756- *tmp = nls->next;
53757+ pax_open_kernel();
53758+ *(struct nls_table **)tmp = nls->next;
53759+ pax_close_kernel();
53760 spin_unlock(&nls_lock);
53761 return 0;
53762 }
53763diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
53764index 7424929..35f6be5 100644
53765--- a/fs/nls/nls_euc-jp.c
53766+++ b/fs/nls/nls_euc-jp.c
53767@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
53768 p_nls = load_nls("cp932");
53769
53770 if (p_nls) {
53771- table.charset2upper = p_nls->charset2upper;
53772- table.charset2lower = p_nls->charset2lower;
53773+ pax_open_kernel();
53774+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53775+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53776+ pax_close_kernel();
53777 return register_nls(&table);
53778 }
53779
53780diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
53781index e7bc1d7..06bd4bb 100644
53782--- a/fs/nls/nls_koi8-ru.c
53783+++ b/fs/nls/nls_koi8-ru.c
53784@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
53785 p_nls = load_nls("koi8-u");
53786
53787 if (p_nls) {
53788- table.charset2upper = p_nls->charset2upper;
53789- table.charset2lower = p_nls->charset2lower;
53790+ pax_open_kernel();
53791+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53792+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53793+ pax_close_kernel();
53794 return register_nls(&table);
53795 }
53796
53797diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
53798index 9ff4a5e..deb1f0f 100644
53799--- a/fs/notify/fanotify/fanotify_user.c
53800+++ b/fs/notify/fanotify/fanotify_user.c
53801@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
53802
53803 fd = fanotify_event_metadata.fd;
53804 ret = -EFAULT;
53805- if (copy_to_user(buf, &fanotify_event_metadata,
53806- fanotify_event_metadata.event_len))
53807+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
53808+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
53809 goto out_close_fd;
53810
53811 ret = prepare_for_access_response(group, event, fd);
53812diff --git a/fs/notify/notification.c b/fs/notify/notification.c
53813index 7b51b05..5ea5ef6 100644
53814--- a/fs/notify/notification.c
53815+++ b/fs/notify/notification.c
53816@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
53817 * get set to 0 so it will never get 'freed'
53818 */
53819 static struct fsnotify_event *q_overflow_event;
53820-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53821+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53822
53823 /**
53824 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
53825@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53826 */
53827 u32 fsnotify_get_cookie(void)
53828 {
53829- return atomic_inc_return(&fsnotify_sync_cookie);
53830+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
53831 }
53832 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
53833
53834diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
53835index 99e3610..02c1068 100644
53836--- a/fs/ntfs/dir.c
53837+++ b/fs/ntfs/dir.c
53838@@ -1329,7 +1329,7 @@ find_next_index_buffer:
53839 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
53840 ~(s64)(ndir->itype.index.block_size - 1)));
53841 /* Bounds checks. */
53842- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53843+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53844 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
53845 "inode 0x%lx or driver bug.", vdir->i_ino);
53846 goto err_out;
53847diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
53848index 5b2d4f0..c6de396 100644
53849--- a/fs/ntfs/file.c
53850+++ b/fs/ntfs/file.c
53851@@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
53852 #endif /* NTFS_RW */
53853 };
53854
53855-const struct file_operations ntfs_empty_file_ops = {};
53856+const struct file_operations ntfs_empty_file_ops __read_only;
53857
53858-const struct inode_operations ntfs_empty_inode_ops = {};
53859+const struct inode_operations ntfs_empty_inode_ops __read_only;
53860diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
53861index a9f78c7..ed8a381 100644
53862--- a/fs/ocfs2/localalloc.c
53863+++ b/fs/ocfs2/localalloc.c
53864@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
53865 goto bail;
53866 }
53867
53868- atomic_inc(&osb->alloc_stats.moves);
53869+ atomic_inc_unchecked(&osb->alloc_stats.moves);
53870
53871 bail:
53872 if (handle)
53873diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
53874index d355e6e..578d905 100644
53875--- a/fs/ocfs2/ocfs2.h
53876+++ b/fs/ocfs2/ocfs2.h
53877@@ -235,11 +235,11 @@ enum ocfs2_vol_state
53878
53879 struct ocfs2_alloc_stats
53880 {
53881- atomic_t moves;
53882- atomic_t local_data;
53883- atomic_t bitmap_data;
53884- atomic_t bg_allocs;
53885- atomic_t bg_extends;
53886+ atomic_unchecked_t moves;
53887+ atomic_unchecked_t local_data;
53888+ atomic_unchecked_t bitmap_data;
53889+ atomic_unchecked_t bg_allocs;
53890+ atomic_unchecked_t bg_extends;
53891 };
53892
53893 enum ocfs2_local_alloc_state
53894diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
53895index b7e74b5..19c6536 100644
53896--- a/fs/ocfs2/suballoc.c
53897+++ b/fs/ocfs2/suballoc.c
53898@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
53899 mlog_errno(status);
53900 goto bail;
53901 }
53902- atomic_inc(&osb->alloc_stats.bg_extends);
53903+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
53904
53905 /* You should never ask for this much metadata */
53906 BUG_ON(bits_wanted >
53907@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
53908 mlog_errno(status);
53909 goto bail;
53910 }
53911- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53912+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53913
53914 *suballoc_loc = res.sr_bg_blkno;
53915 *suballoc_bit_start = res.sr_bit_offset;
53916@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
53917 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
53918 res->sr_bits);
53919
53920- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53921+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53922
53923 BUG_ON(res->sr_bits != 1);
53924
53925@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
53926 mlog_errno(status);
53927 goto bail;
53928 }
53929- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53930+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53931
53932 BUG_ON(res.sr_bits != 1);
53933
53934@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53935 cluster_start,
53936 num_clusters);
53937 if (!status)
53938- atomic_inc(&osb->alloc_stats.local_data);
53939+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
53940 } else {
53941 if (min_clusters > (osb->bitmap_cpg - 1)) {
53942 /* The only paths asking for contiguousness
53943@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53944 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
53945 res.sr_bg_blkno,
53946 res.sr_bit_offset);
53947- atomic_inc(&osb->alloc_stats.bitmap_data);
53948+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
53949 *num_clusters = res.sr_bits;
53950 }
53951 }
53952diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
53953index 0e91ec2..f4b3fc6 100644
53954--- a/fs/ocfs2/super.c
53955+++ b/fs/ocfs2/super.c
53956@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
53957 "%10s => GlobalAllocs: %d LocalAllocs: %d "
53958 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
53959 "Stats",
53960- atomic_read(&osb->alloc_stats.bitmap_data),
53961- atomic_read(&osb->alloc_stats.local_data),
53962- atomic_read(&osb->alloc_stats.bg_allocs),
53963- atomic_read(&osb->alloc_stats.moves),
53964- atomic_read(&osb->alloc_stats.bg_extends));
53965+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
53966+ atomic_read_unchecked(&osb->alloc_stats.local_data),
53967+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
53968+ atomic_read_unchecked(&osb->alloc_stats.moves),
53969+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
53970
53971 out += snprintf(buf + out, len - out,
53972 "%10s => State: %u Descriptor: %llu Size: %u bits "
53973@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
53974 spin_lock_init(&osb->osb_xattr_lock);
53975 ocfs2_init_steal_slots(osb);
53976
53977- atomic_set(&osb->alloc_stats.moves, 0);
53978- atomic_set(&osb->alloc_stats.local_data, 0);
53979- atomic_set(&osb->alloc_stats.bitmap_data, 0);
53980- atomic_set(&osb->alloc_stats.bg_allocs, 0);
53981- atomic_set(&osb->alloc_stats.bg_extends, 0);
53982+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
53983+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
53984+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
53985+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
53986+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
53987
53988 /* Copy the blockcheck stats from the superblock probe */
53989 osb->osb_ecc_stats = *stats;
53990diff --git a/fs/open.c b/fs/open.c
53991index 9b33c0c..2ffcca2 100644
53992--- a/fs/open.c
53993+++ b/fs/open.c
53994@@ -31,6 +31,8 @@
53995 #include <linux/ima.h>
53996 #include <linux/dnotify.h>
53997
53998+#define CREATE_TRACE_POINTS
53999+#include <trace/events/fs.h>
54000 #include "internal.h"
54001
54002 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
54003@@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
54004 error = locks_verify_truncate(inode, NULL, length);
54005 if (!error)
54006 error = security_path_truncate(path);
54007+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
54008+ error = -EACCES;
54009 if (!error)
54010 error = do_truncate(path->dentry, length, 0, NULL);
54011
54012@@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
54013 error = locks_verify_truncate(inode, f.file, length);
54014 if (!error)
54015 error = security_path_truncate(&f.file->f_path);
54016+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
54017+ error = -EACCES;
54018 if (!error)
54019 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
54020 sb_end_write(inode->i_sb);
54021@@ -373,6 +379,9 @@ retry:
54022 if (__mnt_is_readonly(path.mnt))
54023 res = -EROFS;
54024
54025+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
54026+ res = -EACCES;
54027+
54028 out_path_release:
54029 path_put(&path);
54030 if (retry_estale(res, lookup_flags)) {
54031@@ -404,6 +413,8 @@ retry:
54032 if (error)
54033 goto dput_and_out;
54034
54035+ gr_log_chdir(path.dentry, path.mnt);
54036+
54037 set_fs_pwd(current->fs, &path);
54038
54039 dput_and_out:
54040@@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
54041 goto out_putf;
54042
54043 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
54044+
54045+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
54046+ error = -EPERM;
54047+
54048+ if (!error)
54049+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
54050+
54051 if (!error)
54052 set_fs_pwd(current->fs, &f.file->f_path);
54053 out_putf:
54054@@ -462,7 +480,13 @@ retry:
54055 if (error)
54056 goto dput_and_out;
54057
54058+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
54059+ goto dput_and_out;
54060+
54061 set_fs_root(current->fs, &path);
54062+
54063+ gr_handle_chroot_chdir(&path);
54064+
54065 error = 0;
54066 dput_and_out:
54067 path_put(&path);
54068@@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
54069 if (error)
54070 return error;
54071 mutex_lock(&inode->i_mutex);
54072+
54073+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
54074+ error = -EACCES;
54075+ goto out_unlock;
54076+ }
54077+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
54078+ error = -EACCES;
54079+ goto out_unlock;
54080+ }
54081+
54082 error = security_path_chmod(path, mode);
54083 if (error)
54084 goto out_unlock;
54085@@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
54086 uid = make_kuid(current_user_ns(), user);
54087 gid = make_kgid(current_user_ns(), group);
54088
54089+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
54090+ return -EACCES;
54091+
54092 newattrs.ia_valid = ATTR_CTIME;
54093 if (user != (uid_t) -1) {
54094 if (!uid_valid(uid))
54095@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
54096 } else {
54097 fsnotify_open(f);
54098 fd_install(fd, f);
54099+ trace_do_sys_open(tmp->name, flags, mode);
54100 }
54101 }
54102 putname(tmp);
54103diff --git a/fs/pipe.c b/fs/pipe.c
54104index 8e2e73f..1ef1048 100644
54105--- a/fs/pipe.c
54106+++ b/fs/pipe.c
54107@@ -438,9 +438,9 @@ redo:
54108 }
54109 if (bufs) /* More to do? */
54110 continue;
54111- if (!pipe->writers)
54112+ if (!atomic_read(&pipe->writers))
54113 break;
54114- if (!pipe->waiting_writers) {
54115+ if (!atomic_read(&pipe->waiting_writers)) {
54116 /* syscall merging: Usually we must not sleep
54117 * if O_NONBLOCK is set, or if we got some data.
54118 * But if a writer sleeps in kernel space, then
54119@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
54120 mutex_lock(&inode->i_mutex);
54121 pipe = inode->i_pipe;
54122
54123- if (!pipe->readers) {
54124+ if (!atomic_read(&pipe->readers)) {
54125 send_sig(SIGPIPE, current, 0);
54126 ret = -EPIPE;
54127 goto out;
54128@@ -553,7 +553,7 @@ redo1:
54129 for (;;) {
54130 int bufs;
54131
54132- if (!pipe->readers) {
54133+ if (!atomic_read(&pipe->readers)) {
54134 send_sig(SIGPIPE, current, 0);
54135 if (!ret)
54136 ret = -EPIPE;
54137@@ -644,9 +644,9 @@ redo2:
54138 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54139 do_wakeup = 0;
54140 }
54141- pipe->waiting_writers++;
54142+ atomic_inc(&pipe->waiting_writers);
54143 pipe_wait(pipe);
54144- pipe->waiting_writers--;
54145+ atomic_dec(&pipe->waiting_writers);
54146 }
54147 out:
54148 mutex_unlock(&inode->i_mutex);
54149@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54150 mask = 0;
54151 if (filp->f_mode & FMODE_READ) {
54152 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
54153- if (!pipe->writers && filp->f_version != pipe->w_counter)
54154+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
54155 mask |= POLLHUP;
54156 }
54157
54158@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54159 * Most Unices do not set POLLERR for FIFOs but on Linux they
54160 * behave exactly like pipes for poll().
54161 */
54162- if (!pipe->readers)
54163+ if (!atomic_read(&pipe->readers))
54164 mask |= POLLERR;
54165 }
54166
54167@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
54168
54169 mutex_lock(&inode->i_mutex);
54170 pipe = inode->i_pipe;
54171- pipe->readers -= decr;
54172- pipe->writers -= decw;
54173+ atomic_sub(decr, &pipe->readers);
54174+ atomic_sub(decw, &pipe->writers);
54175
54176- if (!pipe->readers && !pipe->writers) {
54177+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
54178 free_pipe_info(inode);
54179 } else {
54180 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
54181@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
54182
54183 if (inode->i_pipe) {
54184 ret = 0;
54185- inode->i_pipe->readers++;
54186+ atomic_inc(&inode->i_pipe->readers);
54187 }
54188
54189 mutex_unlock(&inode->i_mutex);
54190@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
54191
54192 if (inode->i_pipe) {
54193 ret = 0;
54194- inode->i_pipe->writers++;
54195+ atomic_inc(&inode->i_pipe->writers);
54196 }
54197
54198 mutex_unlock(&inode->i_mutex);
54199@@ -871,9 +871,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
54200 if (inode->i_pipe) {
54201 ret = 0;
54202 if (filp->f_mode & FMODE_READ)
54203- inode->i_pipe->readers++;
54204+ atomic_inc(&inode->i_pipe->readers);
54205 if (filp->f_mode & FMODE_WRITE)
54206- inode->i_pipe->writers++;
54207+ atomic_inc(&inode->i_pipe->writers);
54208 }
54209
54210 mutex_unlock(&inode->i_mutex);
54211@@ -965,7 +965,7 @@ void free_pipe_info(struct inode *inode)
54212 inode->i_pipe = NULL;
54213 }
54214
54215-static struct vfsmount *pipe_mnt __read_mostly;
54216+struct vfsmount *pipe_mnt __read_mostly;
54217
54218 /*
54219 * pipefs_dname() is called from d_path().
54220@@ -995,7 +995,8 @@ static struct inode * get_pipe_inode(void)
54221 goto fail_iput;
54222 inode->i_pipe = pipe;
54223
54224- pipe->readers = pipe->writers = 1;
54225+ atomic_set(&pipe->readers, 1);
54226+ atomic_set(&pipe->writers, 1);
54227 inode->i_fop = &rdwr_pipefifo_fops;
54228
54229 /*
54230diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
54231index 15af622..0e9f4467 100644
54232--- a/fs/proc/Kconfig
54233+++ b/fs/proc/Kconfig
54234@@ -30,12 +30,12 @@ config PROC_FS
54235
54236 config PROC_KCORE
54237 bool "/proc/kcore support" if !ARM
54238- depends on PROC_FS && MMU
54239+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
54240
54241 config PROC_VMCORE
54242 bool "/proc/vmcore support"
54243- depends on PROC_FS && CRASH_DUMP
54244- default y
54245+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
54246+ default n
54247 help
54248 Exports the dump image of crashed kernel in ELF format.
54249
54250@@ -59,8 +59,8 @@ config PROC_SYSCTL
54251 limited in memory.
54252
54253 config PROC_PAGE_MONITOR
54254- default y
54255- depends on PROC_FS && MMU
54256+ default n
54257+ depends on PROC_FS && MMU && !GRKERNSEC
54258 bool "Enable /proc page monitoring" if EXPERT
54259 help
54260 Various /proc files exist to monitor process memory utilization:
54261diff --git a/fs/proc/array.c b/fs/proc/array.c
54262index 6a91e6f..e54dbc14 100644
54263--- a/fs/proc/array.c
54264+++ b/fs/proc/array.c
54265@@ -60,6 +60,7 @@
54266 #include <linux/tty.h>
54267 #include <linux/string.h>
54268 #include <linux/mman.h>
54269+#include <linux/grsecurity.h>
54270 #include <linux/proc_fs.h>
54271 #include <linux/ioport.h>
54272 #include <linux/uaccess.h>
54273@@ -362,6 +363,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
54274 seq_putc(m, '\n');
54275 }
54276
54277+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54278+static inline void task_pax(struct seq_file *m, struct task_struct *p)
54279+{
54280+ if (p->mm)
54281+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
54282+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
54283+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
54284+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
54285+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
54286+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
54287+ else
54288+ seq_printf(m, "PaX:\t-----\n");
54289+}
54290+#endif
54291+
54292 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54293 struct pid *pid, struct task_struct *task)
54294 {
54295@@ -380,9 +396,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54296 task_cpus_allowed(m, task);
54297 cpuset_task_status_allowed(m, task);
54298 task_context_switch_counts(m, task);
54299+
54300+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54301+ task_pax(m, task);
54302+#endif
54303+
54304+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
54305+ task_grsec_rbac(m, task);
54306+#endif
54307+
54308 return 0;
54309 }
54310
54311+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54312+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54313+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
54314+ _mm->pax_flags & MF_PAX_SEGMEXEC))
54315+#endif
54316+
54317 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54318 struct pid *pid, struct task_struct *task, int whole)
54319 {
54320@@ -404,6 +435,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54321 char tcomm[sizeof(task->comm)];
54322 unsigned long flags;
54323
54324+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54325+ if (current->exec_id != m->exec_id) {
54326+ gr_log_badprocpid("stat");
54327+ return 0;
54328+ }
54329+#endif
54330+
54331 state = *get_task_state(task);
54332 vsize = eip = esp = 0;
54333 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
54334@@ -475,6 +513,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54335 gtime = task->gtime;
54336 }
54337
54338+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54339+ if (PAX_RAND_FLAGS(mm)) {
54340+ eip = 0;
54341+ esp = 0;
54342+ wchan = 0;
54343+ }
54344+#endif
54345+#ifdef CONFIG_GRKERNSEC_HIDESYM
54346+ wchan = 0;
54347+ eip =0;
54348+ esp =0;
54349+#endif
54350+
54351 /* scale priority and nice values from timeslices to -20..20 */
54352 /* to make it look like a "normal" Unix priority/nice value */
54353 priority = task_prio(task);
54354@@ -511,9 +562,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54355 seq_put_decimal_ull(m, ' ', vsize);
54356 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
54357 seq_put_decimal_ull(m, ' ', rsslim);
54358+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54359+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
54360+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
54361+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
54362+#else
54363 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
54364 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
54365 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
54366+#endif
54367 seq_put_decimal_ull(m, ' ', esp);
54368 seq_put_decimal_ull(m, ' ', eip);
54369 /* The signal information here is obsolete.
54370@@ -535,7 +592,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54371 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
54372 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
54373
54374- if (mm && permitted) {
54375+ if (mm && permitted
54376+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54377+ && !PAX_RAND_FLAGS(mm)
54378+#endif
54379+ ) {
54380 seq_put_decimal_ull(m, ' ', mm->start_data);
54381 seq_put_decimal_ull(m, ' ', mm->end_data);
54382 seq_put_decimal_ull(m, ' ', mm->start_brk);
54383@@ -573,8 +634,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54384 struct pid *pid, struct task_struct *task)
54385 {
54386 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
54387- struct mm_struct *mm = get_task_mm(task);
54388+ struct mm_struct *mm;
54389
54390+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54391+ if (current->exec_id != m->exec_id) {
54392+ gr_log_badprocpid("statm");
54393+ return 0;
54394+ }
54395+#endif
54396+ mm = get_task_mm(task);
54397 if (mm) {
54398 size = task_statm(mm, &shared, &text, &data, &resident);
54399 mmput(mm);
54400@@ -597,6 +665,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54401 return 0;
54402 }
54403
54404+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54405+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
54406+{
54407+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
54408+}
54409+#endif
54410+
54411 #ifdef CONFIG_CHECKPOINT_RESTORE
54412 static struct pid *
54413 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
54414diff --git a/fs/proc/base.c b/fs/proc/base.c
54415index 9b43ff77..ba3e990 100644
54416--- a/fs/proc/base.c
54417+++ b/fs/proc/base.c
54418@@ -111,6 +111,14 @@ struct pid_entry {
54419 union proc_op op;
54420 };
54421
54422+struct getdents_callback {
54423+ struct linux_dirent __user * current_dir;
54424+ struct linux_dirent __user * previous;
54425+ struct file * file;
54426+ int count;
54427+ int error;
54428+};
54429+
54430 #define NOD(NAME, MODE, IOP, FOP, OP) { \
54431 .name = (NAME), \
54432 .len = sizeof(NAME) - 1, \
54433@@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
54434 if (!mm->arg_end)
54435 goto out_mm; /* Shh! No looking before we're done */
54436
54437+ if (gr_acl_handle_procpidmem(task))
54438+ goto out_mm;
54439+
54440 len = mm->arg_end - mm->arg_start;
54441
54442 if (len > PAGE_SIZE)
54443@@ -235,12 +246,28 @@ out:
54444 return res;
54445 }
54446
54447+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54448+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54449+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
54450+ _mm->pax_flags & MF_PAX_SEGMEXEC))
54451+#endif
54452+
54453 static int proc_pid_auxv(struct task_struct *task, char *buffer)
54454 {
54455 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
54456 int res = PTR_ERR(mm);
54457 if (mm && !IS_ERR(mm)) {
54458 unsigned int nwords = 0;
54459+
54460+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54461+ /* allow if we're currently ptracing this task */
54462+ if (PAX_RAND_FLAGS(mm) &&
54463+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
54464+ mmput(mm);
54465+ return 0;
54466+ }
54467+#endif
54468+
54469 do {
54470 nwords += 2;
54471 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
54472@@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
54473 }
54474
54475
54476-#ifdef CONFIG_KALLSYMS
54477+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54478 /*
54479 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
54480 * Returns the resolved symbol. If that fails, simply return the address.
54481@@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
54482 mutex_unlock(&task->signal->cred_guard_mutex);
54483 }
54484
54485-#ifdef CONFIG_STACKTRACE
54486+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54487
54488 #define MAX_STACK_TRACE_DEPTH 64
54489
54490@@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
54491 return count;
54492 }
54493
54494-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54495+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54496 static int proc_pid_syscall(struct task_struct *task, char *buffer)
54497 {
54498 long nr;
54499@@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
54500 /************************************************************************/
54501
54502 /* permission checks */
54503-static int proc_fd_access_allowed(struct inode *inode)
54504+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
54505 {
54506 struct task_struct *task;
54507 int allowed = 0;
54508@@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
54509 */
54510 task = get_proc_task(inode);
54511 if (task) {
54512- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
54513+ if (log)
54514+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
54515+ else
54516+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
54517 put_task_struct(task);
54518 }
54519 return allowed;
54520@@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
54521 struct task_struct *task,
54522 int hide_pid_min)
54523 {
54524+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54525+ return false;
54526+
54527+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54528+ rcu_read_lock();
54529+ {
54530+ const struct cred *tmpcred = current_cred();
54531+ const struct cred *cred = __task_cred(task);
54532+
54533+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
54534+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54535+ || in_group_p(grsec_proc_gid)
54536+#endif
54537+ ) {
54538+ rcu_read_unlock();
54539+ return true;
54540+ }
54541+ }
54542+ rcu_read_unlock();
54543+
54544+ if (!pid->hide_pid)
54545+ return false;
54546+#endif
54547+
54548 if (pid->hide_pid < hide_pid_min)
54549 return true;
54550 if (in_group_p(pid->pid_gid))
54551 return true;
54552+
54553 return ptrace_may_access(task, PTRACE_MODE_READ);
54554 }
54555
54556@@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
54557 put_task_struct(task);
54558
54559 if (!has_perms) {
54560+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54561+ {
54562+#else
54563 if (pid->hide_pid == 2) {
54564+#endif
54565 /*
54566 * Let's make getdents(), stat(), and open()
54567 * consistent with each other. If a process
54568@@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54569 if (!task)
54570 return -ESRCH;
54571
54572+ if (gr_acl_handle_procpidmem(task)) {
54573+ put_task_struct(task);
54574+ return -EPERM;
54575+ }
54576+
54577 mm = mm_access(task, mode);
54578 put_task_struct(task);
54579
54580@@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54581
54582 file->private_data = mm;
54583
54584+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54585+ file->f_version = current->exec_id;
54586+#endif
54587+
54588 return 0;
54589 }
54590
54591@@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
54592 ssize_t copied;
54593 char *page;
54594
54595+#ifdef CONFIG_GRKERNSEC
54596+ if (write)
54597+ return -EPERM;
54598+#endif
54599+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54600+ if (file->f_version != current->exec_id) {
54601+ gr_log_badprocpid("mem");
54602+ return 0;
54603+ }
54604+#endif
54605+
54606 if (!mm)
54607 return 0;
54608
54609@@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
54610 if (!mm)
54611 return 0;
54612
54613+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54614+ if (file->f_version != current->exec_id) {
54615+ gr_log_badprocpid("environ");
54616+ return 0;
54617+ }
54618+#endif
54619+
54620 page = (char *)__get_free_page(GFP_TEMPORARY);
54621 if (!page)
54622 return -ENOMEM;
54623@@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
54624 int error = -EACCES;
54625
54626 /* Are we allowed to snoop on the tasks file descriptors? */
54627- if (!proc_fd_access_allowed(inode))
54628+ if (!proc_fd_access_allowed(inode, 0))
54629 goto out;
54630
54631 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54632@@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
54633 struct path path;
54634
54635 /* Are we allowed to snoop on the tasks file descriptors? */
54636- if (!proc_fd_access_allowed(inode))
54637- goto out;
54638+ /* logging this is needed for learning on chromium to work properly,
54639+ but we don't want to flood the logs from 'ps' which does a readlink
54640+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
54641+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
54642+ */
54643+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
54644+ if (!proc_fd_access_allowed(inode,0))
54645+ goto out;
54646+ } else {
54647+ if (!proc_fd_access_allowed(inode,1))
54648+ goto out;
54649+ }
54650
54651 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54652 if (error)
54653@@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
54654 rcu_read_lock();
54655 cred = __task_cred(task);
54656 inode->i_uid = cred->euid;
54657+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54658+ inode->i_gid = grsec_proc_gid;
54659+#else
54660 inode->i_gid = cred->egid;
54661+#endif
54662 rcu_read_unlock();
54663 }
54664 security_task_to_inode(task, inode);
54665@@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
54666 return -ENOENT;
54667 }
54668 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54669+#ifdef CONFIG_GRKERNSEC_PROC_USER
54670+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54671+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54672+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54673+#endif
54674 task_dumpable(task)) {
54675 cred = __task_cred(task);
54676 stat->uid = cred->euid;
54677+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54678+ stat->gid = grsec_proc_gid;
54679+#else
54680 stat->gid = cred->egid;
54681+#endif
54682 }
54683 }
54684 rcu_read_unlock();
54685@@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
54686
54687 if (task) {
54688 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54689+#ifdef CONFIG_GRKERNSEC_PROC_USER
54690+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54691+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54692+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54693+#endif
54694 task_dumpable(task)) {
54695 rcu_read_lock();
54696 cred = __task_cred(task);
54697 inode->i_uid = cred->euid;
54698+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54699+ inode->i_gid = grsec_proc_gid;
54700+#else
54701 inode->i_gid = cred->egid;
54702+#endif
54703 rcu_read_unlock();
54704 } else {
54705 inode->i_uid = GLOBAL_ROOT_UID;
54706@@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
54707 if (!task)
54708 goto out_no_task;
54709
54710+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54711+ goto out;
54712+
54713 /*
54714 * Yes, it does not scale. And it should not. Don't add
54715 * new entries into /proc/<tgid>/ without very good reasons.
54716@@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
54717 if (!task)
54718 goto out_no_task;
54719
54720+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54721+ goto out;
54722+
54723 ret = 0;
54724 i = filp->f_pos;
54725 switch (i) {
54726@@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
54727 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
54728 #endif
54729 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54730-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54731+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54732 INF("syscall", S_IRUGO, proc_pid_syscall),
54733 #endif
54734 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54735@@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
54736 #ifdef CONFIG_SECURITY
54737 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54738 #endif
54739-#ifdef CONFIG_KALLSYMS
54740+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54741 INF("wchan", S_IRUGO, proc_pid_wchan),
54742 #endif
54743-#ifdef CONFIG_STACKTRACE
54744+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54745 ONE("stack", S_IRUGO, proc_pid_stack),
54746 #endif
54747 #ifdef CONFIG_SCHEDSTATS
54748@@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
54749 #ifdef CONFIG_HARDWALL
54750 INF("hardwall", S_IRUGO, proc_pid_hardwall),
54751 #endif
54752+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54753+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
54754+#endif
54755 #ifdef CONFIG_USER_NS
54756 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
54757 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
54758@@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
54759 if (!inode)
54760 goto out;
54761
54762+#ifdef CONFIG_GRKERNSEC_PROC_USER
54763+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
54764+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54765+ inode->i_gid = grsec_proc_gid;
54766+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
54767+#else
54768 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
54769+#endif
54770 inode->i_op = &proc_tgid_base_inode_operations;
54771 inode->i_fop = &proc_tgid_base_operations;
54772 inode->i_flags|=S_IMMUTABLE;
54773@@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
54774 if (!task)
54775 goto out;
54776
54777+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54778+ goto out_put_task;
54779+
54780 result = proc_pid_instantiate(dir, dentry, task, NULL);
54781+out_put_task:
54782 put_task_struct(task);
54783 out:
54784 return result;
54785@@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
54786 static int fake_filldir(void *buf, const char *name, int namelen,
54787 loff_t offset, u64 ino, unsigned d_type)
54788 {
54789+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
54790+ __buf->error = -EINVAL;
54791 return 0;
54792 }
54793
54794@@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
54795 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
54796 #endif
54797 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54798-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54799+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54800 INF("syscall", S_IRUGO, proc_pid_syscall),
54801 #endif
54802 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54803@@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
54804 #ifdef CONFIG_SECURITY
54805 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54806 #endif
54807-#ifdef CONFIG_KALLSYMS
54808+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54809 INF("wchan", S_IRUGO, proc_pid_wchan),
54810 #endif
54811-#ifdef CONFIG_STACKTRACE
54812+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54813 ONE("stack", S_IRUGO, proc_pid_stack),
54814 #endif
54815 #ifdef CONFIG_SCHEDSTATS
54816diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
54817index 82676e3..5f8518a 100644
54818--- a/fs/proc/cmdline.c
54819+++ b/fs/proc/cmdline.c
54820@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
54821
54822 static int __init proc_cmdline_init(void)
54823 {
54824+#ifdef CONFIG_GRKERNSEC_PROC_ADD
54825+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
54826+#else
54827 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
54828+#endif
54829 return 0;
54830 }
54831 module_init(proc_cmdline_init);
54832diff --git a/fs/proc/devices.c b/fs/proc/devices.c
54833index b143471..bb105e5 100644
54834--- a/fs/proc/devices.c
54835+++ b/fs/proc/devices.c
54836@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
54837
54838 static int __init proc_devices_init(void)
54839 {
54840+#ifdef CONFIG_GRKERNSEC_PROC_ADD
54841+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
54842+#else
54843 proc_create("devices", 0, NULL, &proc_devinfo_operations);
54844+#endif
54845 return 0;
54846 }
54847 module_init(proc_devices_init);
54848diff --git a/fs/proc/fd.c b/fs/proc/fd.c
54849index d7a4a28..0201742 100644
54850--- a/fs/proc/fd.c
54851+++ b/fs/proc/fd.c
54852@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
54853 if (!task)
54854 return -ENOENT;
54855
54856- files = get_files_struct(task);
54857+ if (!gr_acl_handle_procpidmem(task))
54858+ files = get_files_struct(task);
54859 put_task_struct(task);
54860
54861 if (files) {
54862@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
54863 */
54864 int proc_fd_permission(struct inode *inode, int mask)
54865 {
54866+ struct task_struct *task;
54867 int rv = generic_permission(inode, mask);
54868- if (rv == 0)
54869- return 0;
54870+
54871 if (task_pid(current) == proc_pid(inode))
54872 rv = 0;
54873+
54874+ task = get_proc_task(inode);
54875+ if (task == NULL)
54876+ return rv;
54877+
54878+ if (gr_acl_handle_procpidmem(task))
54879+ rv = -EACCES;
54880+
54881+ put_task_struct(task);
54882+
54883 return rv;
54884 }
54885
54886diff --git a/fs/proc/inode.c b/fs/proc/inode.c
54887index 0ac1e1b..0497e58 100644
54888--- a/fs/proc/inode.c
54889+++ b/fs/proc/inode.c
54890@@ -21,11 +21,17 @@
54891 #include <linux/seq_file.h>
54892 #include <linux/slab.h>
54893 #include <linux/mount.h>
54894+#include <linux/grsecurity.h>
54895
54896 #include <asm/uaccess.h>
54897
54898 #include "internal.h"
54899
54900+#ifdef CONFIG_PROC_SYSCTL
54901+extern const struct inode_operations proc_sys_inode_operations;
54902+extern const struct inode_operations proc_sys_dir_operations;
54903+#endif
54904+
54905 static void proc_evict_inode(struct inode *inode)
54906 {
54907 struct proc_dir_entry *de;
54908@@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
54909 ns = PROC_I(inode)->ns;
54910 if (ns_ops && ns)
54911 ns_ops->put(ns);
54912+
54913+#ifdef CONFIG_PROC_SYSCTL
54914+ if (inode->i_op == &proc_sys_inode_operations ||
54915+ inode->i_op == &proc_sys_dir_operations)
54916+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
54917+#endif
54918+
54919 }
54920
54921 static struct kmem_cache * proc_inode_cachep;
54922@@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
54923 if (de->mode) {
54924 inode->i_mode = de->mode;
54925 inode->i_uid = de->uid;
54926+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54927+ inode->i_gid = grsec_proc_gid;
54928+#else
54929 inode->i_gid = de->gid;
54930+#endif
54931 }
54932 if (de->size)
54933 inode->i_size = de->size;
54934diff --git a/fs/proc/internal.h b/fs/proc/internal.h
54935index 252544c..04395b9 100644
54936--- a/fs/proc/internal.h
54937+++ b/fs/proc/internal.h
54938@@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54939 struct pid *pid, struct task_struct *task);
54940 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54941 struct pid *pid, struct task_struct *task);
54942+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54943+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
54944+#endif
54945 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
54946
54947 extern const struct file_operations proc_tid_children_operations;
54948diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
54949index e96d4f1..8b116ed 100644
54950--- a/fs/proc/kcore.c
54951+++ b/fs/proc/kcore.c
54952@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54953 * the addresses in the elf_phdr on our list.
54954 */
54955 start = kc_offset_to_vaddr(*fpos - elf_buflen);
54956- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
54957+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
54958+ if (tsz > buflen)
54959 tsz = buflen;
54960-
54961+
54962 while (buflen) {
54963 struct kcore_list *m;
54964
54965@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54966 kfree(elf_buf);
54967 } else {
54968 if (kern_addr_valid(start)) {
54969- unsigned long n;
54970+ char *elf_buf;
54971+ mm_segment_t oldfs;
54972
54973- n = copy_to_user(buffer, (char *)start, tsz);
54974- /*
54975- * We cannot distinguish between fault on source
54976- * and fault on destination. When this happens
54977- * we clear too and hope it will trigger the
54978- * EFAULT again.
54979- */
54980- if (n) {
54981- if (clear_user(buffer + tsz - n,
54982- n))
54983+ elf_buf = kmalloc(tsz, GFP_KERNEL);
54984+ if (!elf_buf)
54985+ return -ENOMEM;
54986+ oldfs = get_fs();
54987+ set_fs(KERNEL_DS);
54988+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
54989+ set_fs(oldfs);
54990+ if (copy_to_user(buffer, elf_buf, tsz)) {
54991+ kfree(elf_buf);
54992 return -EFAULT;
54993+ }
54994 }
54995+ set_fs(oldfs);
54996+ kfree(elf_buf);
54997 } else {
54998 if (clear_user(buffer, tsz))
54999 return -EFAULT;
55000@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55001
55002 static int open_kcore(struct inode *inode, struct file *filp)
55003 {
55004+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
55005+ return -EPERM;
55006+#endif
55007 if (!capable(CAP_SYS_RAWIO))
55008 return -EPERM;
55009 if (kcore_need_update)
55010diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
55011index 80e4645..53e5fcf 100644
55012--- a/fs/proc/meminfo.c
55013+++ b/fs/proc/meminfo.c
55014@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
55015 vmi.used >> 10,
55016 vmi.largest_chunk >> 10
55017 #ifdef CONFIG_MEMORY_FAILURE
55018- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
55019+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
55020 #endif
55021 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
55022 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
55023diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
55024index b1822dd..df622cb 100644
55025--- a/fs/proc/nommu.c
55026+++ b/fs/proc/nommu.c
55027@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
55028 if (len < 1)
55029 len = 1;
55030 seq_printf(m, "%*c", len, ' ');
55031- seq_path(m, &file->f_path, "");
55032+ seq_path(m, &file->f_path, "\n\\");
55033 }
55034
55035 seq_putc(m, '\n');
55036diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
55037index fe72cd0..21b52ff 100644
55038--- a/fs/proc/proc_net.c
55039+++ b/fs/proc/proc_net.c
55040@@ -23,6 +23,7 @@
55041 #include <linux/nsproxy.h>
55042 #include <net/net_namespace.h>
55043 #include <linux/seq_file.h>
55044+#include <linux/grsecurity.h>
55045
55046 #include "internal.h"
55047
55048@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
55049 struct task_struct *task;
55050 struct nsproxy *ns;
55051 struct net *net = NULL;
55052+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55053+ const struct cred *cred = current_cred();
55054+#endif
55055+
55056+#ifdef CONFIG_GRKERNSEC_PROC_USER
55057+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
55058+ return net;
55059+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55060+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
55061+ return net;
55062+#endif
55063
55064 rcu_read_lock();
55065 task = pid_task(proc_pid(dir), PIDTYPE_PID);
55066diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
55067index 1827d88..43b0279 100644
55068--- a/fs/proc/proc_sysctl.c
55069+++ b/fs/proc/proc_sysctl.c
55070@@ -12,11 +12,15 @@
55071 #include <linux/module.h>
55072 #include "internal.h"
55073
55074+extern int gr_handle_chroot_sysctl(const int op);
55075+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
55076+ const int op);
55077+
55078 static const struct dentry_operations proc_sys_dentry_operations;
55079 static const struct file_operations proc_sys_file_operations;
55080-static const struct inode_operations proc_sys_inode_operations;
55081+const struct inode_operations proc_sys_inode_operations;
55082 static const struct file_operations proc_sys_dir_file_operations;
55083-static const struct inode_operations proc_sys_dir_operations;
55084+const struct inode_operations proc_sys_dir_operations;
55085
55086 void proc_sys_poll_notify(struct ctl_table_poll *poll)
55087 {
55088@@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
55089
55090 err = NULL;
55091 d_set_d_op(dentry, &proc_sys_dentry_operations);
55092+
55093+ gr_handle_proc_create(dentry, inode);
55094+
55095 d_add(dentry, inode);
55096
55097 out:
55098@@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55099 struct inode *inode = filp->f_path.dentry->d_inode;
55100 struct ctl_table_header *head = grab_header(inode);
55101 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
55102+ int op = write ? MAY_WRITE : MAY_READ;
55103 ssize_t error;
55104 size_t res;
55105
55106@@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55107 * and won't be until we finish.
55108 */
55109 error = -EPERM;
55110- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
55111+ if (sysctl_perm(head, table, op))
55112 goto out;
55113
55114 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
55115@@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55116 if (!table->proc_handler)
55117 goto out;
55118
55119+#ifdef CONFIG_GRKERNSEC
55120+ error = -EPERM;
55121+ if (gr_handle_chroot_sysctl(op))
55122+ goto out;
55123+ dget(filp->f_path.dentry);
55124+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
55125+ dput(filp->f_path.dentry);
55126+ goto out;
55127+ }
55128+ dput(filp->f_path.dentry);
55129+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
55130+ goto out;
55131+ if (write && !capable(CAP_SYS_ADMIN))
55132+ goto out;
55133+#endif
55134+
55135 /* careful: calling conventions are nasty here */
55136 res = count;
55137 error = table->proc_handler(table, write, buf, &res, ppos);
55138@@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
55139 return -ENOMEM;
55140 } else {
55141 d_set_d_op(child, &proc_sys_dentry_operations);
55142+
55143+ gr_handle_proc_create(child, inode);
55144+
55145 d_add(child, inode);
55146 }
55147 } else {
55148@@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
55149 if ((*pos)++ < file->f_pos)
55150 return 0;
55151
55152+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
55153+ return 0;
55154+
55155 if (unlikely(S_ISLNK(table->mode)))
55156 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
55157 else
55158@@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
55159 if (IS_ERR(head))
55160 return PTR_ERR(head);
55161
55162+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
55163+ return -ENOENT;
55164+
55165 generic_fillattr(inode, stat);
55166 if (table)
55167 stat->mode = (stat->mode & S_IFMT) | table->mode;
55168@@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
55169 .llseek = generic_file_llseek,
55170 };
55171
55172-static const struct inode_operations proc_sys_inode_operations = {
55173+const struct inode_operations proc_sys_inode_operations = {
55174 .permission = proc_sys_permission,
55175 .setattr = proc_sys_setattr,
55176 .getattr = proc_sys_getattr,
55177 };
55178
55179-static const struct inode_operations proc_sys_dir_operations = {
55180+const struct inode_operations proc_sys_dir_operations = {
55181 .lookup = proc_sys_lookup,
55182 .permission = proc_sys_permission,
55183 .setattr = proc_sys_setattr,
55184@@ -854,7 +887,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
55185 static struct ctl_dir *new_dir(struct ctl_table_set *set,
55186 const char *name, int namelen)
55187 {
55188- struct ctl_table *table;
55189+ ctl_table_no_const *table;
55190 struct ctl_dir *new;
55191 struct ctl_node *node;
55192 char *new_name;
55193@@ -866,7 +899,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
55194 return NULL;
55195
55196 node = (struct ctl_node *)(new + 1);
55197- table = (struct ctl_table *)(node + 1);
55198+ table = (ctl_table_no_const *)(node + 1);
55199 new_name = (char *)(table + 2);
55200 memcpy(new_name, name, namelen);
55201 new_name[namelen] = '\0';
55202@@ -1035,7 +1068,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
55203 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
55204 struct ctl_table_root *link_root)
55205 {
55206- struct ctl_table *link_table, *entry, *link;
55207+ ctl_table_no_const *link_table, *link;
55208+ struct ctl_table *entry;
55209 struct ctl_table_header *links;
55210 struct ctl_node *node;
55211 char *link_name;
55212@@ -1058,7 +1092,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
55213 return NULL;
55214
55215 node = (struct ctl_node *)(links + 1);
55216- link_table = (struct ctl_table *)(node + nr_entries);
55217+ link_table = (ctl_table_no_const *)(node + nr_entries);
55218 link_name = (char *)&link_table[nr_entries + 1];
55219
55220 for (link = link_table, entry = table; entry->procname; link++, entry++) {
55221@@ -1306,8 +1340,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55222 struct ctl_table_header ***subheader, struct ctl_table_set *set,
55223 struct ctl_table *table)
55224 {
55225- struct ctl_table *ctl_table_arg = NULL;
55226- struct ctl_table *entry, *files;
55227+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
55228+ struct ctl_table *entry;
55229 int nr_files = 0;
55230 int nr_dirs = 0;
55231 int err = -ENOMEM;
55232@@ -1319,10 +1353,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55233 nr_files++;
55234 }
55235
55236- files = table;
55237 /* If there are mixed files and directories we need a new table */
55238 if (nr_dirs && nr_files) {
55239- struct ctl_table *new;
55240+ ctl_table_no_const *new;
55241 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
55242 GFP_KERNEL);
55243 if (!files)
55244@@ -1340,7 +1373,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55245 /* Register everything except a directory full of subdirectories */
55246 if (nr_files || !nr_dirs) {
55247 struct ctl_table_header *header;
55248- header = __register_sysctl_table(set, path, files);
55249+ header = __register_sysctl_table(set, path, files ? files : table);
55250 if (!header) {
55251 kfree(ctl_table_arg);
55252 goto out;
55253diff --git a/fs/proc/root.c b/fs/proc/root.c
55254index c6e9fac..a740964 100644
55255--- a/fs/proc/root.c
55256+++ b/fs/proc/root.c
55257@@ -176,7 +176,15 @@ void __init proc_root_init(void)
55258 #ifdef CONFIG_PROC_DEVICETREE
55259 proc_device_tree_init();
55260 #endif
55261+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55262+#ifdef CONFIG_GRKERNSEC_PROC_USER
55263+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
55264+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55265+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
55266+#endif
55267+#else
55268 proc_mkdir("bus", NULL);
55269+#endif
55270 proc_sys_init();
55271 }
55272
55273diff --git a/fs/proc/self.c b/fs/proc/self.c
55274index aa5cc3b..c91a5d0 100644
55275--- a/fs/proc/self.c
55276+++ b/fs/proc/self.c
55277@@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
55278 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
55279 void *cookie)
55280 {
55281- char *s = nd_get_link(nd);
55282+ const char *s = nd_get_link(nd);
55283 if (!IS_ERR(s))
55284 kfree(s);
55285 }
55286diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
55287index ca5ce7f..02c1cf0 100644
55288--- a/fs/proc/task_mmu.c
55289+++ b/fs/proc/task_mmu.c
55290@@ -11,12 +11,19 @@
55291 #include <linux/rmap.h>
55292 #include <linux/swap.h>
55293 #include <linux/swapops.h>
55294+#include <linux/grsecurity.h>
55295
55296 #include <asm/elf.h>
55297 #include <asm/uaccess.h>
55298 #include <asm/tlbflush.h>
55299 #include "internal.h"
55300
55301+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55302+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55303+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55304+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55305+#endif
55306+
55307 void task_mem(struct seq_file *m, struct mm_struct *mm)
55308 {
55309 unsigned long data, text, lib, swap;
55310@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55311 "VmExe:\t%8lu kB\n"
55312 "VmLib:\t%8lu kB\n"
55313 "VmPTE:\t%8lu kB\n"
55314- "VmSwap:\t%8lu kB\n",
55315- hiwater_vm << (PAGE_SHIFT-10),
55316+ "VmSwap:\t%8lu kB\n"
55317+
55318+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55319+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
55320+#endif
55321+
55322+ ,hiwater_vm << (PAGE_SHIFT-10),
55323 total_vm << (PAGE_SHIFT-10),
55324 mm->locked_vm << (PAGE_SHIFT-10),
55325 mm->pinned_vm << (PAGE_SHIFT-10),
55326@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55327 data << (PAGE_SHIFT-10),
55328 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
55329 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
55330- swap << (PAGE_SHIFT-10));
55331+ swap << (PAGE_SHIFT-10)
55332+
55333+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55334+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55335+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
55336+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
55337+#else
55338+ , mm->context.user_cs_base
55339+ , mm->context.user_cs_limit
55340+#endif
55341+#endif
55342+
55343+ );
55344 }
55345
55346 unsigned long task_vsize(struct mm_struct *mm)
55347@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55348 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
55349 }
55350
55351- /* We don't show the stack guard page in /proc/maps */
55352+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55353+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
55354+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
55355+#else
55356 start = vma->vm_start;
55357- if (stack_guard_page_start(vma, start))
55358- start += PAGE_SIZE;
55359 end = vma->vm_end;
55360- if (stack_guard_page_end(vma, end))
55361- end -= PAGE_SIZE;
55362+#endif
55363
55364 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
55365 start,
55366@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55367 flags & VM_WRITE ? 'w' : '-',
55368 flags & VM_EXEC ? 'x' : '-',
55369 flags & VM_MAYSHARE ? 's' : 'p',
55370+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55371+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
55372+#else
55373 pgoff,
55374+#endif
55375 MAJOR(dev), MINOR(dev), ino, &len);
55376
55377 /*
55378@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55379 */
55380 if (file) {
55381 pad_len_spaces(m, len);
55382- seq_path(m, &file->f_path, "\n");
55383+ seq_path(m, &file->f_path, "\n\\");
55384 goto done;
55385 }
55386
55387@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55388 * Thread stack in /proc/PID/task/TID/maps or
55389 * the main process stack.
55390 */
55391- if (!is_pid || (vma->vm_start <= mm->start_stack &&
55392- vma->vm_end >= mm->start_stack)) {
55393+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
55394+ (vma->vm_start <= mm->start_stack &&
55395+ vma->vm_end >= mm->start_stack)) {
55396 name = "[stack]";
55397 } else {
55398 /* Thread stack in /proc/PID/maps */
55399@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
55400 struct proc_maps_private *priv = m->private;
55401 struct task_struct *task = priv->task;
55402
55403+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55404+ if (current->exec_id != m->exec_id) {
55405+ gr_log_badprocpid("maps");
55406+ return 0;
55407+ }
55408+#endif
55409+
55410 show_map_vma(m, vma, is_pid);
55411
55412 if (m->count < m->size) /* vma is copied successfully */
55413@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
55414 .private = &mss,
55415 };
55416
55417+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55418+ if (current->exec_id != m->exec_id) {
55419+ gr_log_badprocpid("smaps");
55420+ return 0;
55421+ }
55422+#endif
55423 memset(&mss, 0, sizeof mss);
55424- mss.vma = vma;
55425- /* mmap_sem is held in m_start */
55426- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
55427- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
55428-
55429+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55430+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
55431+#endif
55432+ mss.vma = vma;
55433+ /* mmap_sem is held in m_start */
55434+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
55435+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
55436+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55437+ }
55438+#endif
55439 show_map_vma(m, vma, is_pid);
55440
55441 seq_printf(m,
55442@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
55443 "KernelPageSize: %8lu kB\n"
55444 "MMUPageSize: %8lu kB\n"
55445 "Locked: %8lu kB\n",
55446+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55447+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
55448+#else
55449 (vma->vm_end - vma->vm_start) >> 10,
55450+#endif
55451 mss.resident >> 10,
55452 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
55453 mss.shared_clean >> 10,
55454@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
55455 int n;
55456 char buffer[50];
55457
55458+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55459+ if (current->exec_id != m->exec_id) {
55460+ gr_log_badprocpid("numa_maps");
55461+ return 0;
55462+ }
55463+#endif
55464+
55465 if (!mm)
55466 return 0;
55467
55468@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
55469 mpol_to_str(buffer, sizeof(buffer), pol);
55470 mpol_cond_put(pol);
55471
55472+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55473+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
55474+#else
55475 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
55476+#endif
55477
55478 if (file) {
55479 seq_printf(m, " file=");
55480- seq_path(m, &file->f_path, "\n\t= ");
55481+ seq_path(m, &file->f_path, "\n\t\\= ");
55482 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
55483 seq_printf(m, " heap");
55484 } else {
55485diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
55486index 1ccfa53..0848f95 100644
55487--- a/fs/proc/task_nommu.c
55488+++ b/fs/proc/task_nommu.c
55489@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55490 else
55491 bytes += kobjsize(mm);
55492
55493- if (current->fs && current->fs->users > 1)
55494+ if (current->fs && atomic_read(&current->fs->users) > 1)
55495 sbytes += kobjsize(current->fs);
55496 else
55497 bytes += kobjsize(current->fs);
55498@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
55499
55500 if (file) {
55501 pad_len_spaces(m, len);
55502- seq_path(m, &file->f_path, "");
55503+ seq_path(m, &file->f_path, "\n\\");
55504 } else if (mm) {
55505 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
55506
55507diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
55508index b00fcc9..e0c6381 100644
55509--- a/fs/qnx6/qnx6.h
55510+++ b/fs/qnx6/qnx6.h
55511@@ -74,7 +74,7 @@ enum {
55512 BYTESEX_BE,
55513 };
55514
55515-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
55516+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
55517 {
55518 if (sbi->s_bytesex == BYTESEX_LE)
55519 return le64_to_cpu((__force __le64)n);
55520@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
55521 return (__force __fs64)cpu_to_be64(n);
55522 }
55523
55524-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
55525+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
55526 {
55527 if (sbi->s_bytesex == BYTESEX_LE)
55528 return le32_to_cpu((__force __le32)n);
55529diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
55530index 16e8abb..2dcf914 100644
55531--- a/fs/quota/netlink.c
55532+++ b/fs/quota/netlink.c
55533@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
55534 void quota_send_warning(struct kqid qid, dev_t dev,
55535 const char warntype)
55536 {
55537- static atomic_t seq;
55538+ static atomic_unchecked_t seq;
55539 struct sk_buff *skb;
55540 void *msg_head;
55541 int ret;
55542@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
55543 "VFS: Not enough memory to send quota warning.\n");
55544 return;
55545 }
55546- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
55547+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
55548 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
55549 if (!msg_head) {
55550 printk(KERN_ERR
55551diff --git a/fs/readdir.c b/fs/readdir.c
55552index 5e69ef5..e5d9099 100644
55553--- a/fs/readdir.c
55554+++ b/fs/readdir.c
55555@@ -17,6 +17,7 @@
55556 #include <linux/security.h>
55557 #include <linux/syscalls.h>
55558 #include <linux/unistd.h>
55559+#include <linux/namei.h>
55560
55561 #include <asm/uaccess.h>
55562
55563@@ -67,6 +68,7 @@ struct old_linux_dirent {
55564
55565 struct readdir_callback {
55566 struct old_linux_dirent __user * dirent;
55567+ struct file * file;
55568 int result;
55569 };
55570
55571@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
55572 buf->result = -EOVERFLOW;
55573 return -EOVERFLOW;
55574 }
55575+
55576+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55577+ return 0;
55578+
55579 buf->result++;
55580 dirent = buf->dirent;
55581 if (!access_ok(VERIFY_WRITE, dirent,
55582@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
55583
55584 buf.result = 0;
55585 buf.dirent = dirent;
55586+ buf.file = f.file;
55587
55588 error = vfs_readdir(f.file, fillonedir, &buf);
55589 if (buf.result)
55590@@ -139,6 +146,7 @@ struct linux_dirent {
55591 struct getdents_callback {
55592 struct linux_dirent __user * current_dir;
55593 struct linux_dirent __user * previous;
55594+ struct file * file;
55595 int count;
55596 int error;
55597 };
55598@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
55599 buf->error = -EOVERFLOW;
55600 return -EOVERFLOW;
55601 }
55602+
55603+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55604+ return 0;
55605+
55606 dirent = buf->previous;
55607 if (dirent) {
55608 if (__put_user(offset, &dirent->d_off))
55609@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55610 buf.previous = NULL;
55611 buf.count = count;
55612 buf.error = 0;
55613+ buf.file = f.file;
55614
55615 error = vfs_readdir(f.file, filldir, &buf);
55616 if (error >= 0)
55617@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55618 struct getdents_callback64 {
55619 struct linux_dirent64 __user * current_dir;
55620 struct linux_dirent64 __user * previous;
55621+ struct file *file;
55622 int count;
55623 int error;
55624 };
55625@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
55626 buf->error = -EINVAL; /* only used if we fail.. */
55627 if (reclen > buf->count)
55628 return -EINVAL;
55629+
55630+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55631+ return 0;
55632+
55633 dirent = buf->previous;
55634 if (dirent) {
55635 if (__put_user(offset, &dirent->d_off))
55636@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55637
55638 buf.current_dir = dirent;
55639 buf.previous = NULL;
55640+ buf.file = f.file;
55641 buf.count = count;
55642 buf.error = 0;
55643
55644@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55645 error = buf.error;
55646 lastdirent = buf.previous;
55647 if (lastdirent) {
55648- typeof(lastdirent->d_off) d_off = f.file->f_pos;
55649+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
55650 if (__put_user(d_off, &lastdirent->d_off))
55651 error = -EFAULT;
55652 else
55653diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
55654index 2b7882b..1c5ef48 100644
55655--- a/fs/reiserfs/do_balan.c
55656+++ b/fs/reiserfs/do_balan.c
55657@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
55658 return;
55659 }
55660
55661- atomic_inc(&(fs_generation(tb->tb_sb)));
55662+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
55663 do_balance_starts(tb);
55664
55665 /* balance leaf returns 0 except if combining L R and S into
55666diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
55667index e60e870..f40ac16 100644
55668--- a/fs/reiserfs/procfs.c
55669+++ b/fs/reiserfs/procfs.c
55670@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
55671 "SMALL_TAILS " : "NO_TAILS ",
55672 replay_only(sb) ? "REPLAY_ONLY " : "",
55673 convert_reiserfs(sb) ? "CONV " : "",
55674- atomic_read(&r->s_generation_counter),
55675+ atomic_read_unchecked(&r->s_generation_counter),
55676 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
55677 SF(s_do_balance), SF(s_unneeded_left_neighbor),
55678 SF(s_good_search_by_key_reada), SF(s_bmaps),
55679diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
55680index 157e474..65a6114 100644
55681--- a/fs/reiserfs/reiserfs.h
55682+++ b/fs/reiserfs/reiserfs.h
55683@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
55684 /* Comment? -Hans */
55685 wait_queue_head_t s_wait;
55686 /* To be obsoleted soon by per buffer seals.. -Hans */
55687- atomic_t s_generation_counter; // increased by one every time the
55688+ atomic_unchecked_t s_generation_counter; // increased by one every time the
55689 // tree gets re-balanced
55690 unsigned long s_properties; /* File system properties. Currently holds
55691 on-disk FS format */
55692@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
55693 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
55694
55695 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
55696-#define get_generation(s) atomic_read (&fs_generation(s))
55697+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
55698 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
55699 #define __fs_changed(gen,s) (gen != get_generation (s))
55700 #define fs_changed(gen,s) \
55701diff --git a/fs/select.c b/fs/select.c
55702index 2ef72d9..f213b17 100644
55703--- a/fs/select.c
55704+++ b/fs/select.c
55705@@ -20,6 +20,7 @@
55706 #include <linux/export.h>
55707 #include <linux/slab.h>
55708 #include <linux/poll.h>
55709+#include <linux/security.h>
55710 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
55711 #include <linux/file.h>
55712 #include <linux/fdtable.h>
55713@@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
55714 struct poll_list *walk = head;
55715 unsigned long todo = nfds;
55716
55717+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
55718 if (nfds > rlimit(RLIMIT_NOFILE))
55719 return -EINVAL;
55720
55721diff --git a/fs/seq_file.c b/fs/seq_file.c
55722index f2bc3df..239d4f6 100644
55723--- a/fs/seq_file.c
55724+++ b/fs/seq_file.c
55725@@ -10,6 +10,7 @@
55726 #include <linux/seq_file.h>
55727 #include <linux/slab.h>
55728 #include <linux/cred.h>
55729+#include <linux/sched.h>
55730
55731 #include <asm/uaccess.h>
55732 #include <asm/page.h>
55733@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
55734 #ifdef CONFIG_USER_NS
55735 p->user_ns = file->f_cred->user_ns;
55736 #endif
55737+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55738+ p->exec_id = current->exec_id;
55739+#endif
55740
55741 /*
55742 * Wrappers around seq_open(e.g. swaps_open) need to be
55743@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55744 return 0;
55745 }
55746 if (!m->buf) {
55747- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55748+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55749 if (!m->buf)
55750 return -ENOMEM;
55751 }
55752@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55753 Eoverflow:
55754 m->op->stop(m, p);
55755 kfree(m->buf);
55756- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55757+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55758 return !m->buf ? -ENOMEM : -EAGAIN;
55759 }
55760
55761@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55762
55763 /* grab buffer if we didn't have one */
55764 if (!m->buf) {
55765- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55766+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55767 if (!m->buf)
55768 goto Enomem;
55769 }
55770@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55771 goto Fill;
55772 m->op->stop(m, p);
55773 kfree(m->buf);
55774- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55775+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55776 if (!m->buf)
55777 goto Enomem;
55778 m->count = 0;
55779@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
55780 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
55781 void *data)
55782 {
55783- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
55784+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
55785 int res = -ENOMEM;
55786
55787 if (op) {
55788diff --git a/fs/splice.c b/fs/splice.c
55789index 6909d89..5b2e8f9 100644
55790--- a/fs/splice.c
55791+++ b/fs/splice.c
55792@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55793 pipe_lock(pipe);
55794
55795 for (;;) {
55796- if (!pipe->readers) {
55797+ if (!atomic_read(&pipe->readers)) {
55798 send_sig(SIGPIPE, current, 0);
55799 if (!ret)
55800 ret = -EPIPE;
55801@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55802 do_wakeup = 0;
55803 }
55804
55805- pipe->waiting_writers++;
55806+ atomic_inc(&pipe->waiting_writers);
55807 pipe_wait(pipe);
55808- pipe->waiting_writers--;
55809+ atomic_dec(&pipe->waiting_writers);
55810 }
55811
55812 pipe_unlock(pipe);
55813@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
55814 old_fs = get_fs();
55815 set_fs(get_ds());
55816 /* The cast to a user pointer is valid due to the set_fs() */
55817- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
55818+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
55819 set_fs(old_fs);
55820
55821 return res;
55822@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
55823 old_fs = get_fs();
55824 set_fs(get_ds());
55825 /* The cast to a user pointer is valid due to the set_fs() */
55826- res = vfs_write(file, (const char __user *)buf, count, &pos);
55827+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
55828 set_fs(old_fs);
55829
55830 return res;
55831@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
55832 goto err;
55833
55834 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
55835- vec[i].iov_base = (void __user *) page_address(page);
55836+ vec[i].iov_base = (void __force_user *) page_address(page);
55837 vec[i].iov_len = this_len;
55838 spd.pages[i] = page;
55839 spd.nr_pages++;
55840@@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
55841 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
55842 {
55843 while (!pipe->nrbufs) {
55844- if (!pipe->writers)
55845+ if (!atomic_read(&pipe->writers))
55846 return 0;
55847
55848- if (!pipe->waiting_writers && sd->num_spliced)
55849+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
55850 return 0;
55851
55852 if (sd->flags & SPLICE_F_NONBLOCK)
55853@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
55854 * out of the pipe right after the splice_to_pipe(). So set
55855 * PIPE_READERS appropriately.
55856 */
55857- pipe->readers = 1;
55858+ atomic_set(&pipe->readers, 1);
55859
55860 current->splice_pipe = pipe;
55861 }
55862@@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55863 ret = -ERESTARTSYS;
55864 break;
55865 }
55866- if (!pipe->writers)
55867+ if (!atomic_read(&pipe->writers))
55868 break;
55869- if (!pipe->waiting_writers) {
55870+ if (!atomic_read(&pipe->waiting_writers)) {
55871 if (flags & SPLICE_F_NONBLOCK) {
55872 ret = -EAGAIN;
55873 break;
55874@@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55875 pipe_lock(pipe);
55876
55877 while (pipe->nrbufs >= pipe->buffers) {
55878- if (!pipe->readers) {
55879+ if (!atomic_read(&pipe->readers)) {
55880 send_sig(SIGPIPE, current, 0);
55881 ret = -EPIPE;
55882 break;
55883@@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55884 ret = -ERESTARTSYS;
55885 break;
55886 }
55887- pipe->waiting_writers++;
55888+ atomic_inc(&pipe->waiting_writers);
55889 pipe_wait(pipe);
55890- pipe->waiting_writers--;
55891+ atomic_dec(&pipe->waiting_writers);
55892 }
55893
55894 pipe_unlock(pipe);
55895@@ -1823,14 +1823,14 @@ retry:
55896 pipe_double_lock(ipipe, opipe);
55897
55898 do {
55899- if (!opipe->readers) {
55900+ if (!atomic_read(&opipe->readers)) {
55901 send_sig(SIGPIPE, current, 0);
55902 if (!ret)
55903 ret = -EPIPE;
55904 break;
55905 }
55906
55907- if (!ipipe->nrbufs && !ipipe->writers)
55908+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
55909 break;
55910
55911 /*
55912@@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55913 pipe_double_lock(ipipe, opipe);
55914
55915 do {
55916- if (!opipe->readers) {
55917+ if (!atomic_read(&opipe->readers)) {
55918 send_sig(SIGPIPE, current, 0);
55919 if (!ret)
55920 ret = -EPIPE;
55921@@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55922 * return EAGAIN if we have the potential of some data in the
55923 * future, otherwise just return 0
55924 */
55925- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
55926+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
55927 ret = -EAGAIN;
55928
55929 pipe_unlock(ipipe);
55930diff --git a/fs/stat.c b/fs/stat.c
55931index 14f4545..9b7f55b 100644
55932--- a/fs/stat.c
55933+++ b/fs/stat.c
55934@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
55935 stat->gid = inode->i_gid;
55936 stat->rdev = inode->i_rdev;
55937 stat->size = i_size_read(inode);
55938- stat->atime = inode->i_atime;
55939- stat->mtime = inode->i_mtime;
55940+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55941+ stat->atime = inode->i_ctime;
55942+ stat->mtime = inode->i_ctime;
55943+ } else {
55944+ stat->atime = inode->i_atime;
55945+ stat->mtime = inode->i_mtime;
55946+ }
55947 stat->ctime = inode->i_ctime;
55948 stat->blksize = (1 << inode->i_blkbits);
55949 stat->blocks = inode->i_blocks;
55950@@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55951 if (retval)
55952 return retval;
55953
55954- if (inode->i_op->getattr)
55955- return inode->i_op->getattr(mnt, dentry, stat);
55956+ if (inode->i_op->getattr) {
55957+ retval = inode->i_op->getattr(mnt, dentry, stat);
55958+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55959+ stat->atime = stat->ctime;
55960+ stat->mtime = stat->ctime;
55961+ }
55962+ return retval;
55963+ }
55964
55965 generic_fillattr(inode, stat);
55966 return 0;
55967diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
55968index 2fbdff6..5530a61 100644
55969--- a/fs/sysfs/dir.c
55970+++ b/fs/sysfs/dir.c
55971@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
55972 struct sysfs_dirent *sd;
55973 int rc;
55974
55975+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
55976+ const char *parent_name = parent_sd->s_name;
55977+
55978+ mode = S_IFDIR | S_IRWXU;
55979+
55980+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
55981+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
55982+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
55983+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
55984+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
55985+#endif
55986+
55987 /* allocate */
55988 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
55989 if (!sd)
55990diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
55991index 602f56d..6853db8 100644
55992--- a/fs/sysfs/file.c
55993+++ b/fs/sysfs/file.c
55994@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
55995
55996 struct sysfs_open_dirent {
55997 atomic_t refcnt;
55998- atomic_t event;
55999+ atomic_unchecked_t event;
56000 wait_queue_head_t poll;
56001 struct list_head buffers; /* goes through sysfs_buffer.list */
56002 };
56003@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
56004 if (!sysfs_get_active(attr_sd))
56005 return -ENODEV;
56006
56007- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
56008+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
56009 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
56010
56011 sysfs_put_active(attr_sd);
56012@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
56013 return -ENOMEM;
56014
56015 atomic_set(&new_od->refcnt, 0);
56016- atomic_set(&new_od->event, 1);
56017+ atomic_set_unchecked(&new_od->event, 1);
56018 init_waitqueue_head(&new_od->poll);
56019 INIT_LIST_HEAD(&new_od->buffers);
56020 goto retry;
56021@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
56022
56023 sysfs_put_active(attr_sd);
56024
56025- if (buffer->event != atomic_read(&od->event))
56026+ if (buffer->event != atomic_read_unchecked(&od->event))
56027 goto trigger;
56028
56029 return DEFAULT_POLLMASK;
56030@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
56031
56032 od = sd->s_attr.open;
56033 if (od) {
56034- atomic_inc(&od->event);
56035+ atomic_inc_unchecked(&od->event);
56036 wake_up_interruptible(&od->poll);
56037 }
56038
56039diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
56040index 3c9eb56..9dea5be 100644
56041--- a/fs/sysfs/symlink.c
56042+++ b/fs/sysfs/symlink.c
56043@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56044
56045 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
56046 {
56047- char *page = nd_get_link(nd);
56048+ const char *page = nd_get_link(nd);
56049 if (!IS_ERR(page))
56050 free_page((unsigned long)page);
56051 }
56052diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
56053index 69d4889..a810bd4 100644
56054--- a/fs/sysv/sysv.h
56055+++ b/fs/sysv/sysv.h
56056@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
56057 #endif
56058 }
56059
56060-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56061+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56062 {
56063 if (sbi->s_bytesex == BYTESEX_PDP)
56064 return PDP_swab((__force __u32)n);
56065diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
56066index e18b988..f1d4ad0f 100644
56067--- a/fs/ubifs/io.c
56068+++ b/fs/ubifs/io.c
56069@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
56070 return err;
56071 }
56072
56073-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56074+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56075 {
56076 int err;
56077
56078diff --git a/fs/udf/misc.c b/fs/udf/misc.c
56079index c175b4d..8f36a16 100644
56080--- a/fs/udf/misc.c
56081+++ b/fs/udf/misc.c
56082@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
56083
56084 u8 udf_tag_checksum(const struct tag *t)
56085 {
56086- u8 *data = (u8 *)t;
56087+ const u8 *data = (const u8 *)t;
56088 u8 checksum = 0;
56089 int i;
56090 for (i = 0; i < sizeof(struct tag); ++i)
56091diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
56092index 8d974c4..b82f6ec 100644
56093--- a/fs/ufs/swab.h
56094+++ b/fs/ufs/swab.h
56095@@ -22,7 +22,7 @@ enum {
56096 BYTESEX_BE
56097 };
56098
56099-static inline u64
56100+static inline u64 __intentional_overflow(-1)
56101 fs64_to_cpu(struct super_block *sbp, __fs64 n)
56102 {
56103 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56104@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
56105 return (__force __fs64)cpu_to_be64(n);
56106 }
56107
56108-static inline u32
56109+static inline u32 __intentional_overflow(-1)
56110 fs32_to_cpu(struct super_block *sbp, __fs32 n)
56111 {
56112 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56113diff --git a/fs/utimes.c b/fs/utimes.c
56114index f4fb7ec..3fe03c0 100644
56115--- a/fs/utimes.c
56116+++ b/fs/utimes.c
56117@@ -1,6 +1,7 @@
56118 #include <linux/compiler.h>
56119 #include <linux/file.h>
56120 #include <linux/fs.h>
56121+#include <linux/security.h>
56122 #include <linux/linkage.h>
56123 #include <linux/mount.h>
56124 #include <linux/namei.h>
56125@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
56126 goto mnt_drop_write_and_out;
56127 }
56128 }
56129+
56130+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
56131+ error = -EACCES;
56132+ goto mnt_drop_write_and_out;
56133+ }
56134+
56135 mutex_lock(&inode->i_mutex);
56136 error = notify_change(path->dentry, &newattrs);
56137 mutex_unlock(&inode->i_mutex);
56138diff --git a/fs/xattr.c b/fs/xattr.c
56139index 3377dff..4feded6 100644
56140--- a/fs/xattr.c
56141+++ b/fs/xattr.c
56142@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
56143 * Extended attribute SET operations
56144 */
56145 static long
56146-setxattr(struct dentry *d, const char __user *name, const void __user *value,
56147+setxattr(struct path *path, const char __user *name, const void __user *value,
56148 size_t size, int flags)
56149 {
56150 int error;
56151@@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
56152 posix_acl_fix_xattr_from_user(kvalue, size);
56153 }
56154
56155- error = vfs_setxattr(d, kname, kvalue, size, flags);
56156+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
56157+ error = -EACCES;
56158+ goto out;
56159+ }
56160+
56161+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
56162 out:
56163 if (vvalue)
56164 vfree(vvalue);
56165@@ -377,7 +382,7 @@ retry:
56166 return error;
56167 error = mnt_want_write(path.mnt);
56168 if (!error) {
56169- error = setxattr(path.dentry, name, value, size, flags);
56170+ error = setxattr(&path, name, value, size, flags);
56171 mnt_drop_write(path.mnt);
56172 }
56173 path_put(&path);
56174@@ -401,7 +406,7 @@ retry:
56175 return error;
56176 error = mnt_want_write(path.mnt);
56177 if (!error) {
56178- error = setxattr(path.dentry, name, value, size, flags);
56179+ error = setxattr(&path, name, value, size, flags);
56180 mnt_drop_write(path.mnt);
56181 }
56182 path_put(&path);
56183@@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
56184 const void __user *,value, size_t, size, int, flags)
56185 {
56186 struct fd f = fdget(fd);
56187- struct dentry *dentry;
56188 int error = -EBADF;
56189
56190 if (!f.file)
56191 return error;
56192- dentry = f.file->f_path.dentry;
56193- audit_inode(NULL, dentry, 0);
56194+ audit_inode(NULL, f.file->f_path.dentry, 0);
56195 error = mnt_want_write_file(f.file);
56196 if (!error) {
56197- error = setxattr(dentry, name, value, size, flags);
56198+ error = setxattr(&f.file->f_path, name, value, size, flags);
56199 mnt_drop_write_file(f.file);
56200 }
56201 fdput(f);
56202diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
56203index 9fbea87..6b19972 100644
56204--- a/fs/xattr_acl.c
56205+++ b/fs/xattr_acl.c
56206@@ -76,8 +76,8 @@ struct posix_acl *
56207 posix_acl_from_xattr(struct user_namespace *user_ns,
56208 const void *value, size_t size)
56209 {
56210- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
56211- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
56212+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
56213+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
56214 int count;
56215 struct posix_acl *acl;
56216 struct posix_acl_entry *acl_e;
56217diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
56218index 572a858..12a9b0d 100644
56219--- a/fs/xfs/xfs_bmap.c
56220+++ b/fs/xfs/xfs_bmap.c
56221@@ -192,7 +192,7 @@ xfs_bmap_validate_ret(
56222 int nmap,
56223 int ret_nmap);
56224 #else
56225-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
56226+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
56227 #endif /* DEBUG */
56228
56229 STATIC int
56230diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
56231index 1b9fc3e..e1bdde0 100644
56232--- a/fs/xfs/xfs_dir2_sf.c
56233+++ b/fs/xfs/xfs_dir2_sf.c
56234@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
56235 }
56236
56237 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
56238- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
56239+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
56240+ char name[sfep->namelen];
56241+ memcpy(name, sfep->name, sfep->namelen);
56242+ if (filldir(dirent, name, sfep->namelen,
56243+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
56244+ *offset = off & 0x7fffffff;
56245+ return 0;
56246+ }
56247+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
56248 off & 0x7fffffff, ino, DT_UNKNOWN)) {
56249 *offset = off & 0x7fffffff;
56250 return 0;
56251diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
56252index c1c3ef8..0952438 100644
56253--- a/fs/xfs/xfs_ioctl.c
56254+++ b/fs/xfs/xfs_ioctl.c
56255@@ -127,7 +127,7 @@ xfs_find_handle(
56256 }
56257
56258 error = -EFAULT;
56259- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
56260+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
56261 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
56262 goto out_put;
56263
56264diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
56265index d82efaa..0904a8e 100644
56266--- a/fs/xfs/xfs_iops.c
56267+++ b/fs/xfs/xfs_iops.c
56268@@ -395,7 +395,7 @@ xfs_vn_put_link(
56269 struct nameidata *nd,
56270 void *p)
56271 {
56272- char *s = nd_get_link(nd);
56273+ const char *s = nd_get_link(nd);
56274
56275 if (!IS_ERR(s))
56276 kfree(s);
56277diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
56278new file mode 100644
56279index 0000000..92247e4
56280--- /dev/null
56281+++ b/grsecurity/Kconfig
56282@@ -0,0 +1,1021 @@
56283+#
56284+# grecurity configuration
56285+#
56286+menu "Memory Protections"
56287+depends on GRKERNSEC
56288+
56289+config GRKERNSEC_KMEM
56290+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
56291+ default y if GRKERNSEC_CONFIG_AUTO
56292+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
56293+ help
56294+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
56295+ be written to or read from to modify or leak the contents of the running
56296+ kernel. /dev/port will also not be allowed to be opened and support
56297+ for /dev/cpu/*/msr will be removed. If you have module
56298+ support disabled, enabling this will close up five ways that are
56299+ currently used to insert malicious code into the running kernel.
56300+
56301+ Even with all these features enabled, we still highly recommend that
56302+ you use the RBAC system, as it is still possible for an attacker to
56303+ modify the running kernel through privileged I/O granted by ioperm/iopl.
56304+
56305+ If you are not using XFree86, you may be able to stop this additional
56306+ case by enabling the 'Disable privileged I/O' option. Though nothing
56307+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
56308+ but only to video memory, which is the only writing we allow in this
56309+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
56310+ not be allowed to mprotect it with PROT_WRITE later.
56311+ Enabling this feature will prevent the "cpupower" and "powertop" tools
56312+ from working.
56313+
56314+ It is highly recommended that you say Y here if you meet all the
56315+ conditions above.
56316+
56317+config GRKERNSEC_VM86
56318+ bool "Restrict VM86 mode"
56319+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56320+ depends on X86_32
56321+
56322+ help
56323+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
56324+ make use of a special execution mode on 32bit x86 processors called
56325+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
56326+ video cards and will still work with this option enabled. The purpose
56327+ of the option is to prevent exploitation of emulation errors in
56328+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
56329+ Nearly all users should be able to enable this option.
56330+
56331+config GRKERNSEC_IO
56332+ bool "Disable privileged I/O"
56333+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56334+ depends on X86
56335+ select RTC_CLASS
56336+ select RTC_INTF_DEV
56337+ select RTC_DRV_CMOS
56338+
56339+ help
56340+ If you say Y here, all ioperm and iopl calls will return an error.
56341+ Ioperm and iopl can be used to modify the running kernel.
56342+ Unfortunately, some programs need this access to operate properly,
56343+ the most notable of which are XFree86 and hwclock. hwclock can be
56344+ remedied by having RTC support in the kernel, so real-time
56345+ clock support is enabled if this option is enabled, to ensure
56346+ that hwclock operates correctly. XFree86 still will not
56347+ operate correctly with this option enabled, so DO NOT CHOOSE Y
56348+ IF YOU USE XFree86. If you use XFree86 and you still want to
56349+ protect your kernel against modification, use the RBAC system.
56350+
56351+config GRKERNSEC_JIT_HARDEN
56352+ bool "Harden BPF JIT against spray attacks"
56353+ default y if GRKERNSEC_CONFIG_AUTO
56354+ depends on BPF_JIT
56355+ help
56356+ If you say Y here, the native code generated by the kernel's Berkeley
56357+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
56358+ attacks that attempt to fit attacker-beneficial instructions in
56359+ 32bit immediate fields of JIT-generated native instructions. The
56360+ attacker will generally aim to cause an unintended instruction sequence
56361+ of JIT-generated native code to execute by jumping into the middle of
56362+ a generated instruction. This feature effectively randomizes the 32bit
56363+ immediate constants present in the generated code to thwart such attacks.
56364+
56365+ If you're using KERNEXEC, it's recommended that you enable this option
56366+ to supplement the hardening of the kernel.
56367+
56368+config GRKERNSEC_RAND_THREADSTACK
56369+ bool "Insert random gaps between thread stacks"
56370+ default y if GRKERNSEC_CONFIG_AUTO
56371+ depends on PAX_RANDMMAP && !PPC
56372+ help
56373+ If you say Y here, a random-sized gap will be enforced between allocated
56374+ thread stacks. Glibc's NPTL and other threading libraries that
56375+ pass MAP_STACK to the kernel for thread stack allocation are supported.
56376+ The implementation currently provides 8 bits of entropy for the gap.
56377+
56378+ Many distributions do not compile threaded remote services with the
56379+ -fstack-check argument to GCC, causing the variable-sized stack-based
56380+ allocator, alloca(), to not probe the stack on allocation. This
56381+ permits an unbounded alloca() to skip over any guard page and potentially
56382+ modify another thread's stack reliably. An enforced random gap
56383+ reduces the reliability of such an attack and increases the chance
56384+ that such a read/write to another thread's stack instead lands in
56385+ an unmapped area, causing a crash and triggering grsecurity's
56386+ anti-bruteforcing logic.
56387+
56388+config GRKERNSEC_PROC_MEMMAP
56389+ bool "Harden ASLR against information leaks and entropy reduction"
56390+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
56391+ depends on PAX_NOEXEC || PAX_ASLR
56392+ help
56393+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
56394+ give no information about the addresses of its mappings if
56395+ PaX features that rely on random addresses are enabled on the task.
56396+ In addition to sanitizing this information and disabling other
56397+ dangerous sources of information, this option causes reads of sensitive
56398+ /proc/<pid> entries where the file descriptor was opened in a different
56399+ task than the one performing the read. Such attempts are logged.
56400+ This option also limits argv/env strings for suid/sgid binaries
56401+ to 512KB to prevent a complete exhaustion of the stack entropy provided
56402+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
56403+ binaries to prevent alternative mmap layouts from being abused.
56404+
56405+ If you use PaX it is essential that you say Y here as it closes up
56406+ several holes that make full ASLR useless locally.
56407+
56408+config GRKERNSEC_BRUTE
56409+ bool "Deter exploit bruteforcing"
56410+ default y if GRKERNSEC_CONFIG_AUTO
56411+ help
56412+ If you say Y here, attempts to bruteforce exploits against forking
56413+ daemons such as apache or sshd, as well as against suid/sgid binaries
56414+ will be deterred. When a child of a forking daemon is killed by PaX
56415+ or crashes due to an illegal instruction or other suspicious signal,
56416+ the parent process will be delayed 30 seconds upon every subsequent
56417+ fork until the administrator is able to assess the situation and
56418+ restart the daemon.
56419+ In the suid/sgid case, the attempt is logged, the user has all their
56420+ processes terminated, and they are prevented from executing any further
56421+ processes for 15 minutes.
56422+ It is recommended that you also enable signal logging in the auditing
56423+ section so that logs are generated when a process triggers a suspicious
56424+ signal.
56425+ If the sysctl option is enabled, a sysctl option with name
56426+ "deter_bruteforce" is created.
56427+
56428+
56429+config GRKERNSEC_MODHARDEN
56430+ bool "Harden module auto-loading"
56431+ default y if GRKERNSEC_CONFIG_AUTO
56432+ depends on MODULES
56433+ help
56434+ If you say Y here, module auto-loading in response to use of some
56435+ feature implemented by an unloaded module will be restricted to
56436+ root users. Enabling this option helps defend against attacks
56437+ by unprivileged users who abuse the auto-loading behavior to
56438+ cause a vulnerable module to load that is then exploited.
56439+
56440+ If this option prevents a legitimate use of auto-loading for a
56441+ non-root user, the administrator can execute modprobe manually
56442+ with the exact name of the module mentioned in the alert log.
56443+ Alternatively, the administrator can add the module to the list
56444+ of modules loaded at boot by modifying init scripts.
56445+
56446+ Modification of init scripts will most likely be needed on
56447+ Ubuntu servers with encrypted home directory support enabled,
56448+ as the first non-root user logging in will cause the ecb(aes),
56449+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
56450+
56451+config GRKERNSEC_HIDESYM
56452+ bool "Hide kernel symbols"
56453+ default y if GRKERNSEC_CONFIG_AUTO
56454+ select PAX_USERCOPY_SLABS
56455+ help
56456+ If you say Y here, getting information on loaded modules, and
56457+ displaying all kernel symbols through a syscall will be restricted
56458+ to users with CAP_SYS_MODULE. For software compatibility reasons,
56459+ /proc/kallsyms will be restricted to the root user. The RBAC
56460+ system can hide that entry even from root.
56461+
56462+ This option also prevents leaking of kernel addresses through
56463+ several /proc entries.
56464+
56465+ Note that this option is only effective provided the following
56466+ conditions are met:
56467+ 1) The kernel using grsecurity is not precompiled by some distribution
56468+ 2) You have also enabled GRKERNSEC_DMESG
56469+ 3) You are using the RBAC system and hiding other files such as your
56470+ kernel image and System.map. Alternatively, enabling this option
56471+ causes the permissions on /boot, /lib/modules, and the kernel
56472+ source directory to change at compile time to prevent
56473+ reading by non-root users.
56474+ If the above conditions are met, this option will aid in providing a
56475+ useful protection against local kernel exploitation of overflows
56476+ and arbitrary read/write vulnerabilities.
56477+
56478+config GRKERNSEC_KERN_LOCKOUT
56479+ bool "Active kernel exploit response"
56480+ default y if GRKERNSEC_CONFIG_AUTO
56481+ depends on X86 || ARM || PPC || SPARC
56482+ help
56483+ If you say Y here, when a PaX alert is triggered due to suspicious
56484+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
56485+ or an OOPS occurs due to bad memory accesses, instead of just
56486+ terminating the offending process (and potentially allowing
56487+ a subsequent exploit from the same user), we will take one of two
56488+ actions:
56489+ If the user was root, we will panic the system
56490+ If the user was non-root, we will log the attempt, terminate
56491+ all processes owned by the user, then prevent them from creating
56492+ any new processes until the system is restarted
56493+ This deters repeated kernel exploitation/bruteforcing attempts
56494+ and is useful for later forensics.
56495+
56496+endmenu
56497+menu "Role Based Access Control Options"
56498+depends on GRKERNSEC
56499+
56500+config GRKERNSEC_RBAC_DEBUG
56501+ bool
56502+
56503+config GRKERNSEC_NO_RBAC
56504+ bool "Disable RBAC system"
56505+ help
56506+ If you say Y here, the /dev/grsec device will be removed from the kernel,
56507+ preventing the RBAC system from being enabled. You should only say Y
56508+ here if you have no intention of using the RBAC system, so as to prevent
56509+ an attacker with root access from misusing the RBAC system to hide files
56510+ and processes when loadable module support and /dev/[k]mem have been
56511+ locked down.
56512+
56513+config GRKERNSEC_ACL_HIDEKERN
56514+ bool "Hide kernel processes"
56515+ help
56516+ If you say Y here, all kernel threads will be hidden to all
56517+ processes but those whose subject has the "view hidden processes"
56518+ flag.
56519+
56520+config GRKERNSEC_ACL_MAXTRIES
56521+ int "Maximum tries before password lockout"
56522+ default 3
56523+ help
56524+ This option enforces the maximum number of times a user can attempt
56525+ to authorize themselves with the grsecurity RBAC system before being
56526+ denied the ability to attempt authorization again for a specified time.
56527+ The lower the number, the harder it will be to brute-force a password.
56528+
56529+config GRKERNSEC_ACL_TIMEOUT
56530+ int "Time to wait after max password tries, in seconds"
56531+ default 30
56532+ help
56533+ This option specifies the time the user must wait after attempting to
56534+ authorize to the RBAC system with the maximum number of invalid
56535+ passwords. The higher the number, the harder it will be to brute-force
56536+ a password.
56537+
56538+endmenu
56539+menu "Filesystem Protections"
56540+depends on GRKERNSEC
56541+
56542+config GRKERNSEC_PROC
56543+ bool "Proc restrictions"
56544+ default y if GRKERNSEC_CONFIG_AUTO
56545+ help
56546+ If you say Y here, the permissions of the /proc filesystem
56547+ will be altered to enhance system security and privacy. You MUST
56548+ choose either a user only restriction or a user and group restriction.
56549+ Depending upon the option you choose, you can either restrict users to
56550+ see only the processes they themselves run, or choose a group that can
56551+ view all processes and files normally restricted to root if you choose
56552+ the "restrict to user only" option. NOTE: If you're running identd or
56553+ ntpd as a non-root user, you will have to run it as the group you
56554+ specify here.
56555+
56556+config GRKERNSEC_PROC_USER
56557+ bool "Restrict /proc to user only"
56558+ depends on GRKERNSEC_PROC
56559+ help
56560+ If you say Y here, non-root users will only be able to view their own
56561+ processes, and restricts them from viewing network-related information,
56562+ and viewing kernel symbol and module information.
56563+
56564+config GRKERNSEC_PROC_USERGROUP
56565+ bool "Allow special group"
56566+ default y if GRKERNSEC_CONFIG_AUTO
56567+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
56568+ help
56569+ If you say Y here, you will be able to select a group that will be
56570+ able to view all processes and network-related information. If you've
56571+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
56572+ remain hidden. This option is useful if you want to run identd as
56573+ a non-root user. The group you select may also be chosen at boot time
56574+ via "grsec_proc_gid=" on the kernel commandline.
56575+
56576+config GRKERNSEC_PROC_GID
56577+ int "GID for special group"
56578+ depends on GRKERNSEC_PROC_USERGROUP
56579+ default 1001
56580+
56581+config GRKERNSEC_PROC_ADD
56582+ bool "Additional restrictions"
56583+ default y if GRKERNSEC_CONFIG_AUTO
56584+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
56585+ help
56586+ If you say Y here, additional restrictions will be placed on
56587+ /proc that keep normal users from viewing device information and
56588+ slabinfo information that could be useful for exploits.
56589+
56590+config GRKERNSEC_LINK
56591+ bool "Linking restrictions"
56592+ default y if GRKERNSEC_CONFIG_AUTO
56593+ help
56594+ If you say Y here, /tmp race exploits will be prevented, since users
56595+ will no longer be able to follow symlinks owned by other users in
56596+ world-writable +t directories (e.g. /tmp), unless the owner of the
56597+ symlink is the owner of the directory. users will also not be
56598+ able to hardlink to files they do not own. If the sysctl option is
56599+ enabled, a sysctl option with name "linking_restrictions" is created.
56600+
56601+config GRKERNSEC_SYMLINKOWN
56602+ bool "Kernel-enforced SymlinksIfOwnerMatch"
56603+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
56604+ help
56605+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
56606+ that prevents it from being used as a security feature. As Apache
56607+ verifies the symlink by performing a stat() against the target of
56608+ the symlink before it is followed, an attacker can setup a symlink
56609+ to point to a same-owned file, then replace the symlink with one
56610+ that targets another user's file just after Apache "validates" the
56611+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
56612+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
56613+ will be in place for the group you specify. If the sysctl option
56614+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
56615+ created.
56616+
56617+config GRKERNSEC_SYMLINKOWN_GID
56618+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
56619+ depends on GRKERNSEC_SYMLINKOWN
56620+ default 1006
56621+ help
56622+ Setting this GID determines what group kernel-enforced
56623+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
56624+ is enabled, a sysctl option with name "symlinkown_gid" is created.
56625+
56626+config GRKERNSEC_FIFO
56627+ bool "FIFO restrictions"
56628+ default y if GRKERNSEC_CONFIG_AUTO
56629+ help
56630+ If you say Y here, users will not be able to write to FIFOs they don't
56631+ own in world-writable +t directories (e.g. /tmp), unless the owner of
56632+ the FIFO is the same owner of the directory it's held in. If the sysctl
56633+ option is enabled, a sysctl option with name "fifo_restrictions" is
56634+ created.
56635+
56636+config GRKERNSEC_SYSFS_RESTRICT
56637+ bool "Sysfs/debugfs restriction"
56638+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56639+ depends on SYSFS
56640+ help
56641+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
56642+ any filesystem normally mounted under it (e.g. debugfs) will be
56643+ mostly accessible only by root. These filesystems generally provide access
56644+ to hardware and debug information that isn't appropriate for unprivileged
56645+ users of the system. Sysfs and debugfs have also become a large source
56646+ of new vulnerabilities, ranging from infoleaks to local compromise.
56647+ There has been very little oversight with an eye toward security involved
56648+ in adding new exporters of information to these filesystems, so their
56649+ use is discouraged.
56650+ For reasons of compatibility, a few directories have been whitelisted
56651+ for access by non-root users:
56652+ /sys/fs/selinux
56653+ /sys/fs/fuse
56654+ /sys/devices/system/cpu
56655+
56656+config GRKERNSEC_ROFS
56657+ bool "Runtime read-only mount protection"
56658+ help
56659+ If you say Y here, a sysctl option with name "romount_protect" will
56660+ be created. By setting this option to 1 at runtime, filesystems
56661+ will be protected in the following ways:
56662+ * No new writable mounts will be allowed
56663+ * Existing read-only mounts won't be able to be remounted read/write
56664+ * Write operations will be denied on all block devices
56665+ This option acts independently of grsec_lock: once it is set to 1,
56666+ it cannot be turned off. Therefore, please be mindful of the resulting
56667+ behavior if this option is enabled in an init script on a read-only
56668+ filesystem. This feature is mainly intended for secure embedded systems.
56669+
56670+config GRKERNSEC_DEVICE_SIDECHANNEL
56671+ bool "Eliminate stat/notify-based device sidechannels"
56672+ default y if GRKERNSEC_CONFIG_AUTO
56673+ help
56674+ If you say Y here, timing analyses on block or character
56675+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
56676+ will be thwarted for unprivileged users. If a process without
56677+ CAP_MKNOD stats such a device, the last access and last modify times
56678+ will match the device's create time. No access or modify events
56679+ will be triggered through inotify/dnotify/fanotify for such devices.
56680+ This feature will prevent attacks that may at a minimum
56681+ allow an attacker to determine the administrator's password length.
56682+
56683+config GRKERNSEC_CHROOT
56684+ bool "Chroot jail restrictions"
56685+ default y if GRKERNSEC_CONFIG_AUTO
56686+ help
56687+ If you say Y here, you will be able to choose several options that will
56688+ make breaking out of a chrooted jail much more difficult. If you
56689+ encounter no software incompatibilities with the following options, it
56690+ is recommended that you enable each one.
56691+
56692+config GRKERNSEC_CHROOT_MOUNT
56693+ bool "Deny mounts"
56694+ default y if GRKERNSEC_CONFIG_AUTO
56695+ depends on GRKERNSEC_CHROOT
56696+ help
56697+ If you say Y here, processes inside a chroot will not be able to
56698+ mount or remount filesystems. If the sysctl option is enabled, a
56699+ sysctl option with name "chroot_deny_mount" is created.
56700+
56701+config GRKERNSEC_CHROOT_DOUBLE
56702+ bool "Deny double-chroots"
56703+ default y if GRKERNSEC_CONFIG_AUTO
56704+ depends on GRKERNSEC_CHROOT
56705+ help
56706+ If you say Y here, processes inside a chroot will not be able to chroot
56707+ again outside the chroot. This is a widely used method of breaking
56708+ out of a chroot jail and should not be allowed. If the sysctl
56709+ option is enabled, a sysctl option with name
56710+ "chroot_deny_chroot" is created.
56711+
56712+config GRKERNSEC_CHROOT_PIVOT
56713+ bool "Deny pivot_root in chroot"
56714+ default y if GRKERNSEC_CONFIG_AUTO
56715+ depends on GRKERNSEC_CHROOT
56716+ help
56717+ If you say Y here, processes inside a chroot will not be able to use
56718+ a function called pivot_root() that was introduced in Linux 2.3.41. It
56719+ works similar to chroot in that it changes the root filesystem. This
56720+ function could be misused in a chrooted process to attempt to break out
56721+ of the chroot, and therefore should not be allowed. If the sysctl
56722+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
56723+ created.
56724+
56725+config GRKERNSEC_CHROOT_CHDIR
56726+ bool "Enforce chdir(\"/\") on all chroots"
56727+ default y if GRKERNSEC_CONFIG_AUTO
56728+ depends on GRKERNSEC_CHROOT
56729+ help
56730+ If you say Y here, the current working directory of all newly-chrooted
56731+ applications will be set to the the root directory of the chroot.
56732+ The man page on chroot(2) states:
56733+ Note that this call does not change the current working
56734+ directory, so that `.' can be outside the tree rooted at
56735+ `/'. In particular, the super-user can escape from a
56736+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
56737+
56738+ It is recommended that you say Y here, since it's not known to break
56739+ any software. If the sysctl option is enabled, a sysctl option with
56740+ name "chroot_enforce_chdir" is created.
56741+
56742+config GRKERNSEC_CHROOT_CHMOD
56743+ bool "Deny (f)chmod +s"
56744+ default y if GRKERNSEC_CONFIG_AUTO
56745+ depends on GRKERNSEC_CHROOT
56746+ help
56747+ If you say Y here, processes inside a chroot will not be able to chmod
56748+ or fchmod files to make them have suid or sgid bits. This protects
56749+ against another published method of breaking a chroot. If the sysctl
56750+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
56751+ created.
56752+
56753+config GRKERNSEC_CHROOT_FCHDIR
56754+ bool "Deny fchdir out of chroot"
56755+ default y if GRKERNSEC_CONFIG_AUTO
56756+ depends on GRKERNSEC_CHROOT
56757+ help
56758+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
56759+ to a file descriptor of the chrooting process that points to a directory
56760+ outside the filesystem will be stopped. If the sysctl option
56761+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
56762+
56763+config GRKERNSEC_CHROOT_MKNOD
56764+ bool "Deny mknod"
56765+ default y if GRKERNSEC_CONFIG_AUTO
56766+ depends on GRKERNSEC_CHROOT
56767+ help
56768+ If you say Y here, processes inside a chroot will not be allowed to
56769+ mknod. The problem with using mknod inside a chroot is that it
56770+ would allow an attacker to create a device entry that is the same
56771+ as one on the physical root of your system, which could range from
56772+ anything from the console device to a device for your harddrive (which
56773+ they could then use to wipe the drive or steal data). It is recommended
56774+ that you say Y here, unless you run into software incompatibilities.
56775+ If the sysctl option is enabled, a sysctl option with name
56776+ "chroot_deny_mknod" is created.
56777+
56778+config GRKERNSEC_CHROOT_SHMAT
56779+ bool "Deny shmat() out of chroot"
56780+ default y if GRKERNSEC_CONFIG_AUTO
56781+ depends on GRKERNSEC_CHROOT
56782+ help
56783+ If you say Y here, processes inside a chroot will not be able to attach
56784+ to shared memory segments that were created outside of the chroot jail.
56785+ It is recommended that you say Y here. If the sysctl option is enabled,
56786+ a sysctl option with name "chroot_deny_shmat" is created.
56787+
56788+config GRKERNSEC_CHROOT_UNIX
56789+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
56790+ default y if GRKERNSEC_CONFIG_AUTO
56791+ depends on GRKERNSEC_CHROOT
56792+ help
56793+ If you say Y here, processes inside a chroot will not be able to
56794+ connect to abstract (meaning not belonging to a filesystem) Unix
56795+ domain sockets that were bound outside of a chroot. It is recommended
56796+ that you say Y here. If the sysctl option is enabled, a sysctl option
56797+ with name "chroot_deny_unix" is created.
56798+
56799+config GRKERNSEC_CHROOT_FINDTASK
56800+ bool "Protect outside processes"
56801+ default y if GRKERNSEC_CONFIG_AUTO
56802+ depends on GRKERNSEC_CHROOT
56803+ help
56804+ If you say Y here, processes inside a chroot will not be able to
56805+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
56806+ getsid, or view any process outside of the chroot. If the sysctl
56807+ option is enabled, a sysctl option with name "chroot_findtask" is
56808+ created.
56809+
56810+config GRKERNSEC_CHROOT_NICE
56811+ bool "Restrict priority changes"
56812+ default y if GRKERNSEC_CONFIG_AUTO
56813+ depends on GRKERNSEC_CHROOT
56814+ help
56815+ If you say Y here, processes inside a chroot will not be able to raise
56816+ the priority of processes in the chroot, or alter the priority of
56817+ processes outside the chroot. This provides more security than simply
56818+ removing CAP_SYS_NICE from the process' capability set. If the
56819+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
56820+ is created.
56821+
56822+config GRKERNSEC_CHROOT_SYSCTL
56823+ bool "Deny sysctl writes"
56824+ default y if GRKERNSEC_CONFIG_AUTO
56825+ depends on GRKERNSEC_CHROOT
56826+ help
56827+ If you say Y here, an attacker in a chroot will not be able to
56828+ write to sysctl entries, either by sysctl(2) or through a /proc
56829+ interface. It is strongly recommended that you say Y here. If the
56830+ sysctl option is enabled, a sysctl option with name
56831+ "chroot_deny_sysctl" is created.
56832+
56833+config GRKERNSEC_CHROOT_CAPS
56834+ bool "Capability restrictions"
56835+ default y if GRKERNSEC_CONFIG_AUTO
56836+ depends on GRKERNSEC_CHROOT
56837+ help
56838+ If you say Y here, the capabilities on all processes within a
56839+ chroot jail will be lowered to stop module insertion, raw i/o,
56840+ system and net admin tasks, rebooting the system, modifying immutable
56841+ files, modifying IPC owned by another, and changing the system time.
56842+ This is left an option because it can break some apps. Disable this
56843+ if your chrooted apps are having problems performing those kinds of
56844+ tasks. If the sysctl option is enabled, a sysctl option with
56845+ name "chroot_caps" is created.
56846+
56847+endmenu
56848+menu "Kernel Auditing"
56849+depends on GRKERNSEC
56850+
56851+config GRKERNSEC_AUDIT_GROUP
56852+ bool "Single group for auditing"
56853+ help
56854+ If you say Y here, the exec and chdir logging features will only operate
56855+ on a group you specify. This option is recommended if you only want to
56856+ watch certain users instead of having a large amount of logs from the
56857+ entire system. If the sysctl option is enabled, a sysctl option with
56858+ name "audit_group" is created.
56859+
56860+config GRKERNSEC_AUDIT_GID
56861+ int "GID for auditing"
56862+ depends on GRKERNSEC_AUDIT_GROUP
56863+ default 1007
56864+
56865+config GRKERNSEC_EXECLOG
56866+ bool "Exec logging"
56867+ help
56868+ If you say Y here, all execve() calls will be logged (since the
56869+ other exec*() calls are frontends to execve(), all execution
56870+ will be logged). Useful for shell-servers that like to keep track
56871+ of their users. If the sysctl option is enabled, a sysctl option with
56872+ name "exec_logging" is created.
56873+ WARNING: This option when enabled will produce a LOT of logs, especially
56874+ on an active system.
56875+
56876+config GRKERNSEC_RESLOG
56877+ bool "Resource logging"
56878+ default y if GRKERNSEC_CONFIG_AUTO
56879+ help
56880+ If you say Y here, all attempts to overstep resource limits will
56881+ be logged with the resource name, the requested size, and the current
56882+ limit. It is highly recommended that you say Y here. If the sysctl
56883+ option is enabled, a sysctl option with name "resource_logging" is
56884+ created. If the RBAC system is enabled, the sysctl value is ignored.
56885+
56886+config GRKERNSEC_CHROOT_EXECLOG
56887+ bool "Log execs within chroot"
56888+ help
56889+ If you say Y here, all executions inside a chroot jail will be logged
56890+ to syslog. This can cause a large amount of logs if certain
56891+ applications (eg. djb's daemontools) are installed on the system, and
56892+ is therefore left as an option. If the sysctl option is enabled, a
56893+ sysctl option with name "chroot_execlog" is created.
56894+
56895+config GRKERNSEC_AUDIT_PTRACE
56896+ bool "Ptrace logging"
56897+ help
56898+ If you say Y here, all attempts to attach to a process via ptrace
56899+ will be logged. If the sysctl option is enabled, a sysctl option
56900+ with name "audit_ptrace" is created.
56901+
56902+config GRKERNSEC_AUDIT_CHDIR
56903+ bool "Chdir logging"
56904+ help
56905+ If you say Y here, all chdir() calls will be logged. If the sysctl
56906+ option is enabled, a sysctl option with name "audit_chdir" is created.
56907+
56908+config GRKERNSEC_AUDIT_MOUNT
56909+ bool "(Un)Mount logging"
56910+ help
56911+ If you say Y here, all mounts and unmounts will be logged. If the
56912+ sysctl option is enabled, a sysctl option with name "audit_mount" is
56913+ created.
56914+
56915+config GRKERNSEC_SIGNAL
56916+ bool "Signal logging"
56917+ default y if GRKERNSEC_CONFIG_AUTO
56918+ help
56919+ If you say Y here, certain important signals will be logged, such as
56920+ SIGSEGV, which will as a result inform you of when a error in a program
56921+ occurred, which in some cases could mean a possible exploit attempt.
56922+ If the sysctl option is enabled, a sysctl option with name
56923+ "signal_logging" is created.
56924+
56925+config GRKERNSEC_FORKFAIL
56926+ bool "Fork failure logging"
56927+ help
56928+ If you say Y here, all failed fork() attempts will be logged.
56929+ This could suggest a fork bomb, or someone attempting to overstep
56930+ their process limit. If the sysctl option is enabled, a sysctl option
56931+ with name "forkfail_logging" is created.
56932+
56933+config GRKERNSEC_TIME
56934+ bool "Time change logging"
56935+ default y if GRKERNSEC_CONFIG_AUTO
56936+ help
56937+ If you say Y here, any changes of the system clock will be logged.
56938+ If the sysctl option is enabled, a sysctl option with name
56939+ "timechange_logging" is created.
56940+
56941+config GRKERNSEC_PROC_IPADDR
56942+ bool "/proc/<pid>/ipaddr support"
56943+ default y if GRKERNSEC_CONFIG_AUTO
56944+ help
56945+ If you say Y here, a new entry will be added to each /proc/<pid>
56946+ directory that contains the IP address of the person using the task.
56947+ The IP is carried across local TCP and AF_UNIX stream sockets.
56948+ This information can be useful for IDS/IPSes to perform remote response
56949+ to a local attack. The entry is readable by only the owner of the
56950+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
56951+ the RBAC system), and thus does not create privacy concerns.
56952+
56953+config GRKERNSEC_RWXMAP_LOG
56954+ bool 'Denied RWX mmap/mprotect logging'
56955+ default y if GRKERNSEC_CONFIG_AUTO
56956+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
56957+ help
56958+ If you say Y here, calls to mmap() and mprotect() with explicit
56959+ usage of PROT_WRITE and PROT_EXEC together will be logged when
56960+ denied by the PAX_MPROTECT feature. If the sysctl option is
56961+ enabled, a sysctl option with name "rwxmap_logging" is created.
56962+
56963+config GRKERNSEC_AUDIT_TEXTREL
56964+ bool 'ELF text relocations logging (READ HELP)'
56965+ depends on PAX_MPROTECT
56966+ help
56967+ If you say Y here, text relocations will be logged with the filename
56968+ of the offending library or binary. The purpose of the feature is
56969+ to help Linux distribution developers get rid of libraries and
56970+ binaries that need text relocations which hinder the future progress
56971+ of PaX. Only Linux distribution developers should say Y here, and
56972+ never on a production machine, as this option creates an information
56973+ leak that could aid an attacker in defeating the randomization of
56974+ a single memory region. If the sysctl option is enabled, a sysctl
56975+ option with name "audit_textrel" is created.
56976+
56977+endmenu
56978+
56979+menu "Executable Protections"
56980+depends on GRKERNSEC
56981+
56982+config GRKERNSEC_DMESG
56983+ bool "Dmesg(8) restriction"
56984+ default y if GRKERNSEC_CONFIG_AUTO
56985+ help
56986+ If you say Y here, non-root users will not be able to use dmesg(8)
56987+ to view the contents of the kernel's circular log buffer.
56988+ The kernel's log buffer often contains kernel addresses and other
56989+ identifying information useful to an attacker in fingerprinting a
56990+ system for a targeted exploit.
56991+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
56992+ created.
56993+
56994+config GRKERNSEC_HARDEN_PTRACE
56995+ bool "Deter ptrace-based process snooping"
56996+ default y if GRKERNSEC_CONFIG_AUTO
56997+ help
56998+ If you say Y here, TTY sniffers and other malicious monitoring
56999+ programs implemented through ptrace will be defeated. If you
57000+ have been using the RBAC system, this option has already been
57001+ enabled for several years for all users, with the ability to make
57002+ fine-grained exceptions.
57003+
57004+ This option only affects the ability of non-root users to ptrace
57005+ processes that are not a descendent of the ptracing process.
57006+ This means that strace ./binary and gdb ./binary will still work,
57007+ but attaching to arbitrary processes will not. If the sysctl
57008+ option is enabled, a sysctl option with name "harden_ptrace" is
57009+ created.
57010+
57011+config GRKERNSEC_PTRACE_READEXEC
57012+ bool "Require read access to ptrace sensitive binaries"
57013+ default y if GRKERNSEC_CONFIG_AUTO
57014+ help
57015+ If you say Y here, unprivileged users will not be able to ptrace unreadable
57016+ binaries. This option is useful in environments that
57017+ remove the read bits (e.g. file mode 4711) from suid binaries to
57018+ prevent infoleaking of their contents. This option adds
57019+ consistency to the use of that file mode, as the binary could normally
57020+ be read out when run without privileges while ptracing.
57021+
57022+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
57023+ is created.
57024+
57025+config GRKERNSEC_SETXID
57026+ bool "Enforce consistent multithreaded privileges"
57027+ default y if GRKERNSEC_CONFIG_AUTO
57028+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
57029+ help
57030+ If you say Y here, a change from a root uid to a non-root uid
57031+ in a multithreaded application will cause the resulting uids,
57032+ gids, supplementary groups, and capabilities in that thread
57033+ to be propagated to the other threads of the process. In most
57034+ cases this is unnecessary, as glibc will emulate this behavior
57035+ on behalf of the application. Other libcs do not act in the
57036+ same way, allowing the other threads of the process to continue
57037+ running with root privileges. If the sysctl option is enabled,
57038+ a sysctl option with name "consistent_setxid" is created.
57039+
57040+config GRKERNSEC_TPE
57041+ bool "Trusted Path Execution (TPE)"
57042+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57043+ help
57044+ If you say Y here, you will be able to choose a gid to add to the
57045+ supplementary groups of users you want to mark as "untrusted."
57046+ These users will not be able to execute any files that are not in
57047+ root-owned directories writable only by root. If the sysctl option
57048+ is enabled, a sysctl option with name "tpe" is created.
57049+
57050+config GRKERNSEC_TPE_ALL
57051+ bool "Partially restrict all non-root users"
57052+ depends on GRKERNSEC_TPE
57053+ help
57054+ If you say Y here, all non-root users will be covered under
57055+ a weaker TPE restriction. This is separate from, and in addition to,
57056+ the main TPE options that you have selected elsewhere. Thus, if a
57057+ "trusted" GID is chosen, this restriction applies to even that GID.
57058+ Under this restriction, all non-root users will only be allowed to
57059+ execute files in directories they own that are not group or
57060+ world-writable, or in directories owned by root and writable only by
57061+ root. If the sysctl option is enabled, a sysctl option with name
57062+ "tpe_restrict_all" is created.
57063+
57064+config GRKERNSEC_TPE_INVERT
57065+ bool "Invert GID option"
57066+ depends on GRKERNSEC_TPE
57067+ help
57068+ If you say Y here, the group you specify in the TPE configuration will
57069+ decide what group TPE restrictions will be *disabled* for. This
57070+ option is useful if you want TPE restrictions to be applied to most
57071+ users on the system. If the sysctl option is enabled, a sysctl option
57072+ with name "tpe_invert" is created. Unlike other sysctl options, this
57073+ entry will default to on for backward-compatibility.
57074+
57075+config GRKERNSEC_TPE_GID
57076+ int
57077+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
57078+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
57079+
57080+config GRKERNSEC_TPE_UNTRUSTED_GID
57081+ int "GID for TPE-untrusted users"
57082+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
57083+ default 1005
57084+ help
57085+ Setting this GID determines what group TPE restrictions will be
57086+ *enabled* for. If the sysctl option is enabled, a sysctl option
57087+ with name "tpe_gid" is created.
57088+
57089+config GRKERNSEC_TPE_TRUSTED_GID
57090+ int "GID for TPE-trusted users"
57091+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
57092+ default 1005
57093+ help
57094+ Setting this GID determines what group TPE restrictions will be
57095+ *disabled* for. If the sysctl option is enabled, a sysctl option
57096+ with name "tpe_gid" is created.
57097+
57098+endmenu
57099+menu "Network Protections"
57100+depends on GRKERNSEC
57101+
57102+config GRKERNSEC_RANDNET
57103+ bool "Larger entropy pools"
57104+ default y if GRKERNSEC_CONFIG_AUTO
57105+ help
57106+ If you say Y here, the entropy pools used for many features of Linux
57107+ and grsecurity will be doubled in size. Since several grsecurity
57108+ features use additional randomness, it is recommended that you say Y
57109+ here. Saying Y here has a similar effect as modifying
57110+ /proc/sys/kernel/random/poolsize.
57111+
57112+config GRKERNSEC_BLACKHOLE
57113+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
57114+ default y if GRKERNSEC_CONFIG_AUTO
57115+ depends on NET
57116+ help
57117+ If you say Y here, neither TCP resets nor ICMP
57118+ destination-unreachable packets will be sent in response to packets
57119+ sent to ports for which no associated listening process exists.
57120+ This feature supports both IPV4 and IPV6 and exempts the
57121+ loopback interface from blackholing. Enabling this feature
57122+ makes a host more resilient to DoS attacks and reduces network
57123+ visibility against scanners.
57124+
57125+ The blackhole feature as-implemented is equivalent to the FreeBSD
57126+ blackhole feature, as it prevents RST responses to all packets, not
57127+ just SYNs. Under most application behavior this causes no
57128+ problems, but applications (like haproxy) may not close certain
57129+ connections in a way that cleanly terminates them on the remote
57130+ end, leaving the remote host in LAST_ACK state. Because of this
57131+ side-effect and to prevent intentional LAST_ACK DoSes, this
57132+ feature also adds automatic mitigation against such attacks.
57133+ The mitigation drastically reduces the amount of time a socket
57134+ can spend in LAST_ACK state. If you're using haproxy and not
57135+ all servers it connects to have this option enabled, consider
57136+ disabling this feature on the haproxy host.
57137+
57138+ If the sysctl option is enabled, two sysctl options with names
57139+ "ip_blackhole" and "lastack_retries" will be created.
57140+ While "ip_blackhole" takes the standard zero/non-zero on/off
57141+ toggle, "lastack_retries" uses the same kinds of values as
57142+ "tcp_retries1" and "tcp_retries2". The default value of 4
57143+ prevents a socket from lasting more than 45 seconds in LAST_ACK
57144+ state.
57145+
57146+config GRKERNSEC_NO_SIMULT_CONNECT
57147+ bool "Disable TCP Simultaneous Connect"
57148+ default y if GRKERNSEC_CONFIG_AUTO
57149+ depends on NET
57150+ help
57151+ If you say Y here, a feature by Willy Tarreau will be enabled that
57152+ removes a weakness in Linux's strict implementation of TCP that
57153+ allows two clients to connect to each other without either entering
57154+ a listening state. The weakness allows an attacker to easily prevent
57155+ a client from connecting to a known server provided the source port
57156+ for the connection is guessed correctly.
57157+
57158+ As the weakness could be used to prevent an antivirus or IPS from
57159+ fetching updates, or prevent an SSL gateway from fetching a CRL,
57160+ it should be eliminated by enabling this option. Though Linux is
57161+ one of few operating systems supporting simultaneous connect, it
57162+ has no legitimate use in practice and is rarely supported by firewalls.
57163+
57164+config GRKERNSEC_SOCKET
57165+ bool "Socket restrictions"
57166+ depends on NET
57167+ help
57168+ If you say Y here, you will be able to choose from several options.
57169+ If you assign a GID on your system and add it to the supplementary
57170+ groups of users you want to restrict socket access to, this patch
57171+ will perform up to three things, based on the option(s) you choose.
57172+
57173+config GRKERNSEC_SOCKET_ALL
57174+ bool "Deny any sockets to group"
57175+ depends on GRKERNSEC_SOCKET
57176+ help
57177+ If you say Y here, you will be able to choose a GID of whose users will
57178+ be unable to connect to other hosts from your machine or run server
57179+ applications from your machine. If the sysctl option is enabled, a
57180+ sysctl option with name "socket_all" is created.
57181+
57182+config GRKERNSEC_SOCKET_ALL_GID
57183+ int "GID to deny all sockets for"
57184+ depends on GRKERNSEC_SOCKET_ALL
57185+ default 1004
57186+ help
57187+ Here you can choose the GID to disable socket access for. Remember to
57188+ add the users you want socket access disabled for to the GID
57189+ specified here. If the sysctl option is enabled, a sysctl option
57190+ with name "socket_all_gid" is created.
57191+
57192+config GRKERNSEC_SOCKET_CLIENT
57193+ bool "Deny client sockets to group"
57194+ depends on GRKERNSEC_SOCKET
57195+ help
57196+ If you say Y here, you will be able to choose a GID of whose users will
57197+ be unable to connect to other hosts from your machine, but will be
57198+ able to run servers. If this option is enabled, all users in the group
57199+ you specify will have to use passive mode when initiating ftp transfers
57200+ from the shell on your machine. If the sysctl option is enabled, a
57201+ sysctl option with name "socket_client" is created.
57202+
57203+config GRKERNSEC_SOCKET_CLIENT_GID
57204+ int "GID to deny client sockets for"
57205+ depends on GRKERNSEC_SOCKET_CLIENT
57206+ default 1003
57207+ help
57208+ Here you can choose the GID to disable client socket access for.
57209+ Remember to add the users you want client socket access disabled for to
57210+ the GID specified here. If the sysctl option is enabled, a sysctl
57211+ option with name "socket_client_gid" is created.
57212+
57213+config GRKERNSEC_SOCKET_SERVER
57214+ bool "Deny server sockets to group"
57215+ depends on GRKERNSEC_SOCKET
57216+ help
57217+ If you say Y here, you will be able to choose a GID of whose users will
57218+ be unable to run server applications from your machine. If the sysctl
57219+ option is enabled, a sysctl option with name "socket_server" is created.
57220+
57221+config GRKERNSEC_SOCKET_SERVER_GID
57222+ int "GID to deny server sockets for"
57223+ depends on GRKERNSEC_SOCKET_SERVER
57224+ default 1002
57225+ help
57226+ Here you can choose the GID to disable server socket access for.
57227+ Remember to add the users you want server socket access disabled for to
57228+ the GID specified here. If the sysctl option is enabled, a sysctl
57229+ option with name "socket_server_gid" is created.
57230+
57231+endmenu
57232+menu "Sysctl Support"
57233+depends on GRKERNSEC && SYSCTL
57234+
57235+config GRKERNSEC_SYSCTL
57236+ bool "Sysctl support"
57237+ default y if GRKERNSEC_CONFIG_AUTO
57238+ help
57239+ If you say Y here, you will be able to change the options that
57240+ grsecurity runs with at bootup, without having to recompile your
57241+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
57242+ to enable (1) or disable (0) various features. All the sysctl entries
57243+ are mutable until the "grsec_lock" entry is set to a non-zero value.
57244+ All features enabled in the kernel configuration are disabled at boot
57245+ if you do not say Y to the "Turn on features by default" option.
57246+ All options should be set at startup, and the grsec_lock entry should
57247+ be set to a non-zero value after all the options are set.
57248+ *THIS IS EXTREMELY IMPORTANT*
57249+
57250+config GRKERNSEC_SYSCTL_DISTRO
57251+ bool "Extra sysctl support for distro makers (READ HELP)"
57252+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
57253+ help
57254+ If you say Y here, additional sysctl options will be created
57255+ for features that affect processes running as root. Therefore,
57256+ it is critical when using this option that the grsec_lock entry be
57257+ enabled after boot. Only distros with prebuilt kernel packages
57258+ with this option enabled that can ensure grsec_lock is enabled
57259+ after boot should use this option.
57260+ *Failure to set grsec_lock after boot makes all grsec features
57261+ this option covers useless*
57262+
57263+ Currently this option creates the following sysctl entries:
57264+ "Disable Privileged I/O": "disable_priv_io"
57265+
57266+config GRKERNSEC_SYSCTL_ON
57267+ bool "Turn on features by default"
57268+ default y if GRKERNSEC_CONFIG_AUTO
57269+ depends on GRKERNSEC_SYSCTL
57270+ help
57271+ If you say Y here, instead of having all features enabled in the
57272+ kernel configuration disabled at boot time, the features will be
57273+ enabled at boot time. It is recommended you say Y here unless
57274+ there is some reason you would want all sysctl-tunable features to
57275+ be disabled by default. As mentioned elsewhere, it is important
57276+ to enable the grsec_lock entry once you have finished modifying
57277+ the sysctl entries.
57278+
57279+endmenu
57280+menu "Logging Options"
57281+depends on GRKERNSEC
57282+
57283+config GRKERNSEC_FLOODTIME
57284+ int "Seconds in between log messages (minimum)"
57285+ default 10
57286+ help
57287+ This option allows you to enforce the number of seconds between
57288+ grsecurity log messages. The default should be suitable for most
57289+ people, however, if you choose to change it, choose a value small enough
57290+ to allow informative logs to be produced, but large enough to
57291+ prevent flooding.
57292+
57293+config GRKERNSEC_FLOODBURST
57294+ int "Number of messages in a burst (maximum)"
57295+ default 6
57296+ help
57297+ This option allows you to choose the maximum number of messages allowed
57298+ within the flood time interval you chose in a separate option. The
57299+ default should be suitable for most people, however if you find that
57300+ many of your logs are being interpreted as flooding, you may want to
57301+ raise this value.
57302+
57303+endmenu
57304diff --git a/grsecurity/Makefile b/grsecurity/Makefile
57305new file mode 100644
57306index 0000000..1b9afa9
57307--- /dev/null
57308+++ b/grsecurity/Makefile
57309@@ -0,0 +1,38 @@
57310+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
57311+# during 2001-2009 it has been completely redesigned by Brad Spengler
57312+# into an RBAC system
57313+#
57314+# All code in this directory and various hooks inserted throughout the kernel
57315+# are copyright Brad Spengler - Open Source Security, Inc., and released
57316+# under the GPL v2 or higher
57317+
57318+KBUILD_CFLAGS += -Werror
57319+
57320+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
57321+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
57322+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
57323+
57324+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
57325+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
57326+ gracl_learn.o grsec_log.o
57327+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
57328+
57329+ifdef CONFIG_NET
57330+obj-y += grsec_sock.o
57331+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
57332+endif
57333+
57334+ifndef CONFIG_GRKERNSEC
57335+obj-y += grsec_disabled.o
57336+endif
57337+
57338+ifdef CONFIG_GRKERNSEC_HIDESYM
57339+extra-y := grsec_hidesym.o
57340+$(obj)/grsec_hidesym.o:
57341+ @-chmod -f 500 /boot
57342+ @-chmod -f 500 /lib/modules
57343+ @-chmod -f 500 /lib64/modules
57344+ @-chmod -f 500 /lib32/modules
57345+ @-chmod -f 700 .
57346+ @echo ' grsec: protected kernel image paths'
57347+endif
57348diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
57349new file mode 100644
57350index 0000000..d0e7b38
57351--- /dev/null
57352+++ b/grsecurity/gracl.c
57353@@ -0,0 +1,4071 @@
57354+#include <linux/kernel.h>
57355+#include <linux/module.h>
57356+#include <linux/sched.h>
57357+#include <linux/mm.h>
57358+#include <linux/file.h>
57359+#include <linux/fs.h>
57360+#include <linux/namei.h>
57361+#include <linux/mount.h>
57362+#include <linux/tty.h>
57363+#include <linux/proc_fs.h>
57364+#include <linux/lglock.h>
57365+#include <linux/slab.h>
57366+#include <linux/vmalloc.h>
57367+#include <linux/types.h>
57368+#include <linux/sysctl.h>
57369+#include <linux/netdevice.h>
57370+#include <linux/ptrace.h>
57371+#include <linux/gracl.h>
57372+#include <linux/gralloc.h>
57373+#include <linux/security.h>
57374+#include <linux/grinternal.h>
57375+#include <linux/pid_namespace.h>
57376+#include <linux/stop_machine.h>
57377+#include <linux/fdtable.h>
57378+#include <linux/percpu.h>
57379+#include <linux/lglock.h>
57380+#include <linux/hugetlb.h>
57381+#include <linux/posix-timers.h>
57382+#include "../fs/mount.h"
57383+
57384+#include <asm/uaccess.h>
57385+#include <asm/errno.h>
57386+#include <asm/mman.h>
57387+
57388+extern struct lglock vfsmount_lock;
57389+
57390+static struct acl_role_db acl_role_set;
57391+static struct name_db name_set;
57392+static struct inodev_db inodev_set;
57393+
57394+/* for keeping track of userspace pointers used for subjects, so we
57395+ can share references in the kernel as well
57396+*/
57397+
57398+static struct path real_root;
57399+
57400+static struct acl_subj_map_db subj_map_set;
57401+
57402+static struct acl_role_label *default_role;
57403+
57404+static struct acl_role_label *role_list;
57405+
57406+static u16 acl_sp_role_value;
57407+
57408+extern char *gr_shared_page[4];
57409+static DEFINE_MUTEX(gr_dev_mutex);
57410+DEFINE_RWLOCK(gr_inode_lock);
57411+
57412+struct gr_arg *gr_usermode;
57413+
57414+static unsigned int gr_status __read_only = GR_STATUS_INIT;
57415+
57416+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
57417+extern void gr_clear_learn_entries(void);
57418+
57419+unsigned char *gr_system_salt;
57420+unsigned char *gr_system_sum;
57421+
57422+static struct sprole_pw **acl_special_roles = NULL;
57423+static __u16 num_sprole_pws = 0;
57424+
57425+static struct acl_role_label *kernel_role = NULL;
57426+
57427+static unsigned int gr_auth_attempts = 0;
57428+static unsigned long gr_auth_expires = 0UL;
57429+
57430+#ifdef CONFIG_NET
57431+extern struct vfsmount *sock_mnt;
57432+#endif
57433+
57434+extern struct vfsmount *pipe_mnt;
57435+extern struct vfsmount *shm_mnt;
57436+
57437+#ifdef CONFIG_HUGETLBFS
57438+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57439+#endif
57440+
57441+static struct acl_object_label *fakefs_obj_rw;
57442+static struct acl_object_label *fakefs_obj_rwx;
57443+
57444+extern int gr_init_uidset(void);
57445+extern void gr_free_uidset(void);
57446+extern void gr_remove_uid(uid_t uid);
57447+extern int gr_find_uid(uid_t uid);
57448+
57449+__inline__ int
57450+gr_acl_is_enabled(void)
57451+{
57452+ return (gr_status & GR_READY);
57453+}
57454+
57455+#ifdef CONFIG_BTRFS_FS
57456+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57457+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57458+#endif
57459+
57460+static inline dev_t __get_dev(const struct dentry *dentry)
57461+{
57462+#ifdef CONFIG_BTRFS_FS
57463+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57464+ return get_btrfs_dev_from_inode(dentry->d_inode);
57465+ else
57466+#endif
57467+ return dentry->d_inode->i_sb->s_dev;
57468+}
57469+
57470+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57471+{
57472+ return __get_dev(dentry);
57473+}
57474+
57475+static char gr_task_roletype_to_char(struct task_struct *task)
57476+{
57477+ switch (task->role->roletype &
57478+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
57479+ GR_ROLE_SPECIAL)) {
57480+ case GR_ROLE_DEFAULT:
57481+ return 'D';
57482+ case GR_ROLE_USER:
57483+ return 'U';
57484+ case GR_ROLE_GROUP:
57485+ return 'G';
57486+ case GR_ROLE_SPECIAL:
57487+ return 'S';
57488+ }
57489+
57490+ return 'X';
57491+}
57492+
57493+char gr_roletype_to_char(void)
57494+{
57495+ return gr_task_roletype_to_char(current);
57496+}
57497+
57498+__inline__ int
57499+gr_acl_tpe_check(void)
57500+{
57501+ if (unlikely(!(gr_status & GR_READY)))
57502+ return 0;
57503+ if (current->role->roletype & GR_ROLE_TPE)
57504+ return 1;
57505+ else
57506+ return 0;
57507+}
57508+
57509+int
57510+gr_handle_rawio(const struct inode *inode)
57511+{
57512+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57513+ if (inode && S_ISBLK(inode->i_mode) &&
57514+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57515+ !capable(CAP_SYS_RAWIO))
57516+ return 1;
57517+#endif
57518+ return 0;
57519+}
57520+
57521+static int
57522+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
57523+{
57524+ if (likely(lena != lenb))
57525+ return 0;
57526+
57527+ return !memcmp(a, b, lena);
57528+}
57529+
57530+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
57531+{
57532+ *buflen -= namelen;
57533+ if (*buflen < 0)
57534+ return -ENAMETOOLONG;
57535+ *buffer -= namelen;
57536+ memcpy(*buffer, str, namelen);
57537+ return 0;
57538+}
57539+
57540+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
57541+{
57542+ return prepend(buffer, buflen, name->name, name->len);
57543+}
57544+
57545+static int prepend_path(const struct path *path, struct path *root,
57546+ char **buffer, int *buflen)
57547+{
57548+ struct dentry *dentry = path->dentry;
57549+ struct vfsmount *vfsmnt = path->mnt;
57550+ struct mount *mnt = real_mount(vfsmnt);
57551+ bool slash = false;
57552+ int error = 0;
57553+
57554+ while (dentry != root->dentry || vfsmnt != root->mnt) {
57555+ struct dentry * parent;
57556+
57557+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
57558+ /* Global root? */
57559+ if (!mnt_has_parent(mnt)) {
57560+ goto out;
57561+ }
57562+ dentry = mnt->mnt_mountpoint;
57563+ mnt = mnt->mnt_parent;
57564+ vfsmnt = &mnt->mnt;
57565+ continue;
57566+ }
57567+ parent = dentry->d_parent;
57568+ prefetch(parent);
57569+ spin_lock(&dentry->d_lock);
57570+ error = prepend_name(buffer, buflen, &dentry->d_name);
57571+ spin_unlock(&dentry->d_lock);
57572+ if (!error)
57573+ error = prepend(buffer, buflen, "/", 1);
57574+ if (error)
57575+ break;
57576+
57577+ slash = true;
57578+ dentry = parent;
57579+ }
57580+
57581+out:
57582+ if (!error && !slash)
57583+ error = prepend(buffer, buflen, "/", 1);
57584+
57585+ return error;
57586+}
57587+
57588+/* this must be called with vfsmount_lock and rename_lock held */
57589+
57590+static char *__our_d_path(const struct path *path, struct path *root,
57591+ char *buf, int buflen)
57592+{
57593+ char *res = buf + buflen;
57594+ int error;
57595+
57596+ prepend(&res, &buflen, "\0", 1);
57597+ error = prepend_path(path, root, &res, &buflen);
57598+ if (error)
57599+ return ERR_PTR(error);
57600+
57601+ return res;
57602+}
57603+
57604+static char *
57605+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
57606+{
57607+ char *retval;
57608+
57609+ retval = __our_d_path(path, root, buf, buflen);
57610+ if (unlikely(IS_ERR(retval)))
57611+ retval = strcpy(buf, "<path too long>");
57612+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
57613+ retval[1] = '\0';
57614+
57615+ return retval;
57616+}
57617+
57618+static char *
57619+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
57620+ char *buf, int buflen)
57621+{
57622+ struct path path;
57623+ char *res;
57624+
57625+ path.dentry = (struct dentry *)dentry;
57626+ path.mnt = (struct vfsmount *)vfsmnt;
57627+
57628+ /* we can use real_root.dentry, real_root.mnt, because this is only called
57629+ by the RBAC system */
57630+ res = gen_full_path(&path, &real_root, buf, buflen);
57631+
57632+ return res;
57633+}
57634+
57635+static char *
57636+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
57637+ char *buf, int buflen)
57638+{
57639+ char *res;
57640+ struct path path;
57641+ struct path root;
57642+ struct task_struct *reaper = init_pid_ns.child_reaper;
57643+
57644+ path.dentry = (struct dentry *)dentry;
57645+ path.mnt = (struct vfsmount *)vfsmnt;
57646+
57647+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
57648+ get_fs_root(reaper->fs, &root);
57649+
57650+ br_read_lock(&vfsmount_lock);
57651+ write_seqlock(&rename_lock);
57652+ res = gen_full_path(&path, &root, buf, buflen);
57653+ write_sequnlock(&rename_lock);
57654+ br_read_unlock(&vfsmount_lock);
57655+
57656+ path_put(&root);
57657+ return res;
57658+}
57659+
57660+static char *
57661+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57662+{
57663+ char *ret;
57664+ br_read_lock(&vfsmount_lock);
57665+ write_seqlock(&rename_lock);
57666+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57667+ PAGE_SIZE);
57668+ write_sequnlock(&rename_lock);
57669+ br_read_unlock(&vfsmount_lock);
57670+ return ret;
57671+}
57672+
57673+static char *
57674+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57675+{
57676+ char *ret;
57677+ char *buf;
57678+ int buflen;
57679+
57680+ br_read_lock(&vfsmount_lock);
57681+ write_seqlock(&rename_lock);
57682+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
57683+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
57684+ buflen = (int)(ret - buf);
57685+ if (buflen >= 5)
57686+ prepend(&ret, &buflen, "/proc", 5);
57687+ else
57688+ ret = strcpy(buf, "<path too long>");
57689+ write_sequnlock(&rename_lock);
57690+ br_read_unlock(&vfsmount_lock);
57691+ return ret;
57692+}
57693+
57694+char *
57695+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
57696+{
57697+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57698+ PAGE_SIZE);
57699+}
57700+
57701+char *
57702+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
57703+{
57704+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57705+ PAGE_SIZE);
57706+}
57707+
57708+char *
57709+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
57710+{
57711+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
57712+ PAGE_SIZE);
57713+}
57714+
57715+char *
57716+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
57717+{
57718+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
57719+ PAGE_SIZE);
57720+}
57721+
57722+char *
57723+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
57724+{
57725+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
57726+ PAGE_SIZE);
57727+}
57728+
57729+__inline__ __u32
57730+to_gr_audit(const __u32 reqmode)
57731+{
57732+ /* masks off auditable permission flags, then shifts them to create
57733+ auditing flags, and adds the special case of append auditing if
57734+ we're requesting write */
57735+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
57736+}
57737+
57738+struct acl_subject_label *
57739+lookup_subject_map(const struct acl_subject_label *userp)
57740+{
57741+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
57742+ struct subject_map *match;
57743+
57744+ match = subj_map_set.s_hash[index];
57745+
57746+ while (match && match->user != userp)
57747+ match = match->next;
57748+
57749+ if (match != NULL)
57750+ return match->kernel;
57751+ else
57752+ return NULL;
57753+}
57754+
57755+static void
57756+insert_subj_map_entry(struct subject_map *subjmap)
57757+{
57758+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
57759+ struct subject_map **curr;
57760+
57761+ subjmap->prev = NULL;
57762+
57763+ curr = &subj_map_set.s_hash[index];
57764+ if (*curr != NULL)
57765+ (*curr)->prev = subjmap;
57766+
57767+ subjmap->next = *curr;
57768+ *curr = subjmap;
57769+
57770+ return;
57771+}
57772+
57773+static struct acl_role_label *
57774+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
57775+ const gid_t gid)
57776+{
57777+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
57778+ struct acl_role_label *match;
57779+ struct role_allowed_ip *ipp;
57780+ unsigned int x;
57781+ u32 curr_ip = task->signal->curr_ip;
57782+
57783+ task->signal->saved_ip = curr_ip;
57784+
57785+ match = acl_role_set.r_hash[index];
57786+
57787+ while (match) {
57788+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
57789+ for (x = 0; x < match->domain_child_num; x++) {
57790+ if (match->domain_children[x] == uid)
57791+ goto found;
57792+ }
57793+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
57794+ break;
57795+ match = match->next;
57796+ }
57797+found:
57798+ if (match == NULL) {
57799+ try_group:
57800+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
57801+ match = acl_role_set.r_hash[index];
57802+
57803+ while (match) {
57804+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
57805+ for (x = 0; x < match->domain_child_num; x++) {
57806+ if (match->domain_children[x] == gid)
57807+ goto found2;
57808+ }
57809+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
57810+ break;
57811+ match = match->next;
57812+ }
57813+found2:
57814+ if (match == NULL)
57815+ match = default_role;
57816+ if (match->allowed_ips == NULL)
57817+ return match;
57818+ else {
57819+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57820+ if (likely
57821+ ((ntohl(curr_ip) & ipp->netmask) ==
57822+ (ntohl(ipp->addr) & ipp->netmask)))
57823+ return match;
57824+ }
57825+ match = default_role;
57826+ }
57827+ } else if (match->allowed_ips == NULL) {
57828+ return match;
57829+ } else {
57830+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57831+ if (likely
57832+ ((ntohl(curr_ip) & ipp->netmask) ==
57833+ (ntohl(ipp->addr) & ipp->netmask)))
57834+ return match;
57835+ }
57836+ goto try_group;
57837+ }
57838+
57839+ return match;
57840+}
57841+
57842+struct acl_subject_label *
57843+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
57844+ const struct acl_role_label *role)
57845+{
57846+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57847+ struct acl_subject_label *match;
57848+
57849+ match = role->subj_hash[index];
57850+
57851+ while (match && (match->inode != ino || match->device != dev ||
57852+ (match->mode & GR_DELETED))) {
57853+ match = match->next;
57854+ }
57855+
57856+ if (match && !(match->mode & GR_DELETED))
57857+ return match;
57858+ else
57859+ return NULL;
57860+}
57861+
57862+struct acl_subject_label *
57863+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
57864+ const struct acl_role_label *role)
57865+{
57866+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57867+ struct acl_subject_label *match;
57868+
57869+ match = role->subj_hash[index];
57870+
57871+ while (match && (match->inode != ino || match->device != dev ||
57872+ !(match->mode & GR_DELETED))) {
57873+ match = match->next;
57874+ }
57875+
57876+ if (match && (match->mode & GR_DELETED))
57877+ return match;
57878+ else
57879+ return NULL;
57880+}
57881+
57882+static struct acl_object_label *
57883+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
57884+ const struct acl_subject_label *subj)
57885+{
57886+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57887+ struct acl_object_label *match;
57888+
57889+ match = subj->obj_hash[index];
57890+
57891+ while (match && (match->inode != ino || match->device != dev ||
57892+ (match->mode & GR_DELETED))) {
57893+ match = match->next;
57894+ }
57895+
57896+ if (match && !(match->mode & GR_DELETED))
57897+ return match;
57898+ else
57899+ return NULL;
57900+}
57901+
57902+static struct acl_object_label *
57903+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
57904+ const struct acl_subject_label *subj)
57905+{
57906+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57907+ struct acl_object_label *match;
57908+
57909+ match = subj->obj_hash[index];
57910+
57911+ while (match && (match->inode != ino || match->device != dev ||
57912+ !(match->mode & GR_DELETED))) {
57913+ match = match->next;
57914+ }
57915+
57916+ if (match && (match->mode & GR_DELETED))
57917+ return match;
57918+
57919+ match = subj->obj_hash[index];
57920+
57921+ while (match && (match->inode != ino || match->device != dev ||
57922+ (match->mode & GR_DELETED))) {
57923+ match = match->next;
57924+ }
57925+
57926+ if (match && !(match->mode & GR_DELETED))
57927+ return match;
57928+ else
57929+ return NULL;
57930+}
57931+
57932+static struct name_entry *
57933+lookup_name_entry(const char *name)
57934+{
57935+ unsigned int len = strlen(name);
57936+ unsigned int key = full_name_hash(name, len);
57937+ unsigned int index = key % name_set.n_size;
57938+ struct name_entry *match;
57939+
57940+ match = name_set.n_hash[index];
57941+
57942+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
57943+ match = match->next;
57944+
57945+ return match;
57946+}
57947+
57948+static struct name_entry *
57949+lookup_name_entry_create(const char *name)
57950+{
57951+ unsigned int len = strlen(name);
57952+ unsigned int key = full_name_hash(name, len);
57953+ unsigned int index = key % name_set.n_size;
57954+ struct name_entry *match;
57955+
57956+ match = name_set.n_hash[index];
57957+
57958+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57959+ !match->deleted))
57960+ match = match->next;
57961+
57962+ if (match && match->deleted)
57963+ return match;
57964+
57965+ match = name_set.n_hash[index];
57966+
57967+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57968+ match->deleted))
57969+ match = match->next;
57970+
57971+ if (match && !match->deleted)
57972+ return match;
57973+ else
57974+ return NULL;
57975+}
57976+
57977+static struct inodev_entry *
57978+lookup_inodev_entry(const ino_t ino, const dev_t dev)
57979+{
57980+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
57981+ struct inodev_entry *match;
57982+
57983+ match = inodev_set.i_hash[index];
57984+
57985+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
57986+ match = match->next;
57987+
57988+ return match;
57989+}
57990+
57991+static void
57992+insert_inodev_entry(struct inodev_entry *entry)
57993+{
57994+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
57995+ inodev_set.i_size);
57996+ struct inodev_entry **curr;
57997+
57998+ entry->prev = NULL;
57999+
58000+ curr = &inodev_set.i_hash[index];
58001+ if (*curr != NULL)
58002+ (*curr)->prev = entry;
58003+
58004+ entry->next = *curr;
58005+ *curr = entry;
58006+
58007+ return;
58008+}
58009+
58010+static void
58011+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
58012+{
58013+ unsigned int index =
58014+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
58015+ struct acl_role_label **curr;
58016+ struct acl_role_label *tmp, *tmp2;
58017+
58018+ curr = &acl_role_set.r_hash[index];
58019+
58020+ /* simple case, slot is empty, just set it to our role */
58021+ if (*curr == NULL) {
58022+ *curr = role;
58023+ } else {
58024+ /* example:
58025+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
58026+ 2 -> 3
58027+ */
58028+ /* first check to see if we can already be reached via this slot */
58029+ tmp = *curr;
58030+ while (tmp && tmp != role)
58031+ tmp = tmp->next;
58032+ if (tmp == role) {
58033+ /* we don't need to add ourselves to this slot's chain */
58034+ return;
58035+ }
58036+ /* we need to add ourselves to this chain, two cases */
58037+ if (role->next == NULL) {
58038+ /* simple case, append the current chain to our role */
58039+ role->next = *curr;
58040+ *curr = role;
58041+ } else {
58042+ /* 1 -> 2 -> 3 -> 4
58043+ 2 -> 3 -> 4
58044+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
58045+ */
58046+ /* trickier case: walk our role's chain until we find
58047+ the role for the start of the current slot's chain */
58048+ tmp = role;
58049+ tmp2 = *curr;
58050+ while (tmp->next && tmp->next != tmp2)
58051+ tmp = tmp->next;
58052+ if (tmp->next == tmp2) {
58053+ /* from example above, we found 3, so just
58054+ replace this slot's chain with ours */
58055+ *curr = role;
58056+ } else {
58057+ /* we didn't find a subset of our role's chain
58058+ in the current slot's chain, so append their
58059+ chain to ours, and set us as the first role in
58060+ the slot's chain
58061+
58062+ we could fold this case with the case above,
58063+ but making it explicit for clarity
58064+ */
58065+ tmp->next = tmp2;
58066+ *curr = role;
58067+ }
58068+ }
58069+ }
58070+
58071+ return;
58072+}
58073+
58074+static void
58075+insert_acl_role_label(struct acl_role_label *role)
58076+{
58077+ int i;
58078+
58079+ if (role_list == NULL) {
58080+ role_list = role;
58081+ role->prev = NULL;
58082+ } else {
58083+ role->prev = role_list;
58084+ role_list = role;
58085+ }
58086+
58087+ /* used for hash chains */
58088+ role->next = NULL;
58089+
58090+ if (role->roletype & GR_ROLE_DOMAIN) {
58091+ for (i = 0; i < role->domain_child_num; i++)
58092+ __insert_acl_role_label(role, role->domain_children[i]);
58093+ } else
58094+ __insert_acl_role_label(role, role->uidgid);
58095+}
58096+
58097+static int
58098+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
58099+{
58100+ struct name_entry **curr, *nentry;
58101+ struct inodev_entry *ientry;
58102+ unsigned int len = strlen(name);
58103+ unsigned int key = full_name_hash(name, len);
58104+ unsigned int index = key % name_set.n_size;
58105+
58106+ curr = &name_set.n_hash[index];
58107+
58108+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
58109+ curr = &((*curr)->next);
58110+
58111+ if (*curr != NULL)
58112+ return 1;
58113+
58114+ nentry = acl_alloc(sizeof (struct name_entry));
58115+ if (nentry == NULL)
58116+ return 0;
58117+ ientry = acl_alloc(sizeof (struct inodev_entry));
58118+ if (ientry == NULL)
58119+ return 0;
58120+ ientry->nentry = nentry;
58121+
58122+ nentry->key = key;
58123+ nentry->name = name;
58124+ nentry->inode = inode;
58125+ nentry->device = device;
58126+ nentry->len = len;
58127+ nentry->deleted = deleted;
58128+
58129+ nentry->prev = NULL;
58130+ curr = &name_set.n_hash[index];
58131+ if (*curr != NULL)
58132+ (*curr)->prev = nentry;
58133+ nentry->next = *curr;
58134+ *curr = nentry;
58135+
58136+ /* insert us into the table searchable by inode/dev */
58137+ insert_inodev_entry(ientry);
58138+
58139+ return 1;
58140+}
58141+
58142+static void
58143+insert_acl_obj_label(struct acl_object_label *obj,
58144+ struct acl_subject_label *subj)
58145+{
58146+ unsigned int index =
58147+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
58148+ struct acl_object_label **curr;
58149+
58150+
58151+ obj->prev = NULL;
58152+
58153+ curr = &subj->obj_hash[index];
58154+ if (*curr != NULL)
58155+ (*curr)->prev = obj;
58156+
58157+ obj->next = *curr;
58158+ *curr = obj;
58159+
58160+ return;
58161+}
58162+
58163+static void
58164+insert_acl_subj_label(struct acl_subject_label *obj,
58165+ struct acl_role_label *role)
58166+{
58167+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
58168+ struct acl_subject_label **curr;
58169+
58170+ obj->prev = NULL;
58171+
58172+ curr = &role->subj_hash[index];
58173+ if (*curr != NULL)
58174+ (*curr)->prev = obj;
58175+
58176+ obj->next = *curr;
58177+ *curr = obj;
58178+
58179+ return;
58180+}
58181+
58182+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
58183+
58184+static void *
58185+create_table(__u32 * len, int elementsize)
58186+{
58187+ unsigned int table_sizes[] = {
58188+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
58189+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
58190+ 4194301, 8388593, 16777213, 33554393, 67108859
58191+ };
58192+ void *newtable = NULL;
58193+ unsigned int pwr = 0;
58194+
58195+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
58196+ table_sizes[pwr] <= *len)
58197+ pwr++;
58198+
58199+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
58200+ return newtable;
58201+
58202+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
58203+ newtable =
58204+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
58205+ else
58206+ newtable = vmalloc(table_sizes[pwr] * elementsize);
58207+
58208+ *len = table_sizes[pwr];
58209+
58210+ return newtable;
58211+}
58212+
58213+static int
58214+init_variables(const struct gr_arg *arg)
58215+{
58216+ struct task_struct *reaper = init_pid_ns.child_reaper;
58217+ unsigned int stacksize;
58218+
58219+ subj_map_set.s_size = arg->role_db.num_subjects;
58220+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
58221+ name_set.n_size = arg->role_db.num_objects;
58222+ inodev_set.i_size = arg->role_db.num_objects;
58223+
58224+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
58225+ !name_set.n_size || !inodev_set.i_size)
58226+ return 1;
58227+
58228+ if (!gr_init_uidset())
58229+ return 1;
58230+
58231+ /* set up the stack that holds allocation info */
58232+
58233+ stacksize = arg->role_db.num_pointers + 5;
58234+
58235+ if (!acl_alloc_stack_init(stacksize))
58236+ return 1;
58237+
58238+ /* grab reference for the real root dentry and vfsmount */
58239+ get_fs_root(reaper->fs, &real_root);
58240+
58241+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58242+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
58243+#endif
58244+
58245+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
58246+ if (fakefs_obj_rw == NULL)
58247+ return 1;
58248+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
58249+
58250+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
58251+ if (fakefs_obj_rwx == NULL)
58252+ return 1;
58253+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
58254+
58255+ subj_map_set.s_hash =
58256+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
58257+ acl_role_set.r_hash =
58258+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
58259+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
58260+ inodev_set.i_hash =
58261+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
58262+
58263+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
58264+ !name_set.n_hash || !inodev_set.i_hash)
58265+ return 1;
58266+
58267+ memset(subj_map_set.s_hash, 0,
58268+ sizeof(struct subject_map *) * subj_map_set.s_size);
58269+ memset(acl_role_set.r_hash, 0,
58270+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
58271+ memset(name_set.n_hash, 0,
58272+ sizeof (struct name_entry *) * name_set.n_size);
58273+ memset(inodev_set.i_hash, 0,
58274+ sizeof (struct inodev_entry *) * inodev_set.i_size);
58275+
58276+ return 0;
58277+}
58278+
58279+/* free information not needed after startup
58280+ currently contains user->kernel pointer mappings for subjects
58281+*/
58282+
58283+static void
58284+free_init_variables(void)
58285+{
58286+ __u32 i;
58287+
58288+ if (subj_map_set.s_hash) {
58289+ for (i = 0; i < subj_map_set.s_size; i++) {
58290+ if (subj_map_set.s_hash[i]) {
58291+ kfree(subj_map_set.s_hash[i]);
58292+ subj_map_set.s_hash[i] = NULL;
58293+ }
58294+ }
58295+
58296+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
58297+ PAGE_SIZE)
58298+ kfree(subj_map_set.s_hash);
58299+ else
58300+ vfree(subj_map_set.s_hash);
58301+ }
58302+
58303+ return;
58304+}
58305+
58306+static void
58307+free_variables(void)
58308+{
58309+ struct acl_subject_label *s;
58310+ struct acl_role_label *r;
58311+ struct task_struct *task, *task2;
58312+ unsigned int x;
58313+
58314+ gr_clear_learn_entries();
58315+
58316+ read_lock(&tasklist_lock);
58317+ do_each_thread(task2, task) {
58318+ task->acl_sp_role = 0;
58319+ task->acl_role_id = 0;
58320+ task->acl = NULL;
58321+ task->role = NULL;
58322+ } while_each_thread(task2, task);
58323+ read_unlock(&tasklist_lock);
58324+
58325+ /* release the reference to the real root dentry and vfsmount */
58326+ path_put(&real_root);
58327+ memset(&real_root, 0, sizeof(real_root));
58328+
58329+ /* free all object hash tables */
58330+
58331+ FOR_EACH_ROLE_START(r)
58332+ if (r->subj_hash == NULL)
58333+ goto next_role;
58334+ FOR_EACH_SUBJECT_START(r, s, x)
58335+ if (s->obj_hash == NULL)
58336+ break;
58337+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
58338+ kfree(s->obj_hash);
58339+ else
58340+ vfree(s->obj_hash);
58341+ FOR_EACH_SUBJECT_END(s, x)
58342+ FOR_EACH_NESTED_SUBJECT_START(r, s)
58343+ if (s->obj_hash == NULL)
58344+ break;
58345+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
58346+ kfree(s->obj_hash);
58347+ else
58348+ vfree(s->obj_hash);
58349+ FOR_EACH_NESTED_SUBJECT_END(s)
58350+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
58351+ kfree(r->subj_hash);
58352+ else
58353+ vfree(r->subj_hash);
58354+ r->subj_hash = NULL;
58355+next_role:
58356+ FOR_EACH_ROLE_END(r)
58357+
58358+ acl_free_all();
58359+
58360+ if (acl_role_set.r_hash) {
58361+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
58362+ PAGE_SIZE)
58363+ kfree(acl_role_set.r_hash);
58364+ else
58365+ vfree(acl_role_set.r_hash);
58366+ }
58367+ if (name_set.n_hash) {
58368+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
58369+ PAGE_SIZE)
58370+ kfree(name_set.n_hash);
58371+ else
58372+ vfree(name_set.n_hash);
58373+ }
58374+
58375+ if (inodev_set.i_hash) {
58376+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
58377+ PAGE_SIZE)
58378+ kfree(inodev_set.i_hash);
58379+ else
58380+ vfree(inodev_set.i_hash);
58381+ }
58382+
58383+ gr_free_uidset();
58384+
58385+ memset(&name_set, 0, sizeof (struct name_db));
58386+ memset(&inodev_set, 0, sizeof (struct inodev_db));
58387+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
58388+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
58389+
58390+ default_role = NULL;
58391+ kernel_role = NULL;
58392+ role_list = NULL;
58393+
58394+ return;
58395+}
58396+
58397+static __u32
58398+count_user_objs(struct acl_object_label *userp)
58399+{
58400+ struct acl_object_label o_tmp;
58401+ __u32 num = 0;
58402+
58403+ while (userp) {
58404+ if (copy_from_user(&o_tmp, userp,
58405+ sizeof (struct acl_object_label)))
58406+ break;
58407+
58408+ userp = o_tmp.prev;
58409+ num++;
58410+ }
58411+
58412+ return num;
58413+}
58414+
58415+static struct acl_subject_label *
58416+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
58417+
58418+static int
58419+copy_user_glob(struct acl_object_label *obj)
58420+{
58421+ struct acl_object_label *g_tmp, **guser;
58422+ unsigned int len;
58423+ char *tmp;
58424+
58425+ if (obj->globbed == NULL)
58426+ return 0;
58427+
58428+ guser = &obj->globbed;
58429+ while (*guser) {
58430+ g_tmp = (struct acl_object_label *)
58431+ acl_alloc(sizeof (struct acl_object_label));
58432+ if (g_tmp == NULL)
58433+ return -ENOMEM;
58434+
58435+ if (copy_from_user(g_tmp, *guser,
58436+ sizeof (struct acl_object_label)))
58437+ return -EFAULT;
58438+
58439+ len = strnlen_user(g_tmp->filename, PATH_MAX);
58440+
58441+ if (!len || len >= PATH_MAX)
58442+ return -EINVAL;
58443+
58444+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58445+ return -ENOMEM;
58446+
58447+ if (copy_from_user(tmp, g_tmp->filename, len))
58448+ return -EFAULT;
58449+ tmp[len-1] = '\0';
58450+ g_tmp->filename = tmp;
58451+
58452+ *guser = g_tmp;
58453+ guser = &(g_tmp->next);
58454+ }
58455+
58456+ return 0;
58457+}
58458+
58459+static int
58460+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
58461+ struct acl_role_label *role)
58462+{
58463+ struct acl_object_label *o_tmp;
58464+ unsigned int len;
58465+ int ret;
58466+ char *tmp;
58467+
58468+ while (userp) {
58469+ if ((o_tmp = (struct acl_object_label *)
58470+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
58471+ return -ENOMEM;
58472+
58473+ if (copy_from_user(o_tmp, userp,
58474+ sizeof (struct acl_object_label)))
58475+ return -EFAULT;
58476+
58477+ userp = o_tmp->prev;
58478+
58479+ len = strnlen_user(o_tmp->filename, PATH_MAX);
58480+
58481+ if (!len || len >= PATH_MAX)
58482+ return -EINVAL;
58483+
58484+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58485+ return -ENOMEM;
58486+
58487+ if (copy_from_user(tmp, o_tmp->filename, len))
58488+ return -EFAULT;
58489+ tmp[len-1] = '\0';
58490+ o_tmp->filename = tmp;
58491+
58492+ insert_acl_obj_label(o_tmp, subj);
58493+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
58494+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
58495+ return -ENOMEM;
58496+
58497+ ret = copy_user_glob(o_tmp);
58498+ if (ret)
58499+ return ret;
58500+
58501+ if (o_tmp->nested) {
58502+ int already_copied;
58503+
58504+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
58505+ if (IS_ERR(o_tmp->nested))
58506+ return PTR_ERR(o_tmp->nested);
58507+
58508+ /* insert into nested subject list if we haven't copied this one yet
58509+ to prevent duplicate entries */
58510+ if (!already_copied) {
58511+ o_tmp->nested->next = role->hash->first;
58512+ role->hash->first = o_tmp->nested;
58513+ }
58514+ }
58515+ }
58516+
58517+ return 0;
58518+}
58519+
58520+static __u32
58521+count_user_subjs(struct acl_subject_label *userp)
58522+{
58523+ struct acl_subject_label s_tmp;
58524+ __u32 num = 0;
58525+
58526+ while (userp) {
58527+ if (copy_from_user(&s_tmp, userp,
58528+ sizeof (struct acl_subject_label)))
58529+ break;
58530+
58531+ userp = s_tmp.prev;
58532+ }
58533+
58534+ return num;
58535+}
58536+
58537+static int
58538+copy_user_allowedips(struct acl_role_label *rolep)
58539+{
58540+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
58541+
58542+ ruserip = rolep->allowed_ips;
58543+
58544+ while (ruserip) {
58545+ rlast = rtmp;
58546+
58547+ if ((rtmp = (struct role_allowed_ip *)
58548+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
58549+ return -ENOMEM;
58550+
58551+ if (copy_from_user(rtmp, ruserip,
58552+ sizeof (struct role_allowed_ip)))
58553+ return -EFAULT;
58554+
58555+ ruserip = rtmp->prev;
58556+
58557+ if (!rlast) {
58558+ rtmp->prev = NULL;
58559+ rolep->allowed_ips = rtmp;
58560+ } else {
58561+ rlast->next = rtmp;
58562+ rtmp->prev = rlast;
58563+ }
58564+
58565+ if (!ruserip)
58566+ rtmp->next = NULL;
58567+ }
58568+
58569+ return 0;
58570+}
58571+
58572+static int
58573+copy_user_transitions(struct acl_role_label *rolep)
58574+{
58575+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
58576+
58577+ unsigned int len;
58578+ char *tmp;
58579+
58580+ rusertp = rolep->transitions;
58581+
58582+ while (rusertp) {
58583+ rlast = rtmp;
58584+
58585+ if ((rtmp = (struct role_transition *)
58586+ acl_alloc(sizeof (struct role_transition))) == NULL)
58587+ return -ENOMEM;
58588+
58589+ if (copy_from_user(rtmp, rusertp,
58590+ sizeof (struct role_transition)))
58591+ return -EFAULT;
58592+
58593+ rusertp = rtmp->prev;
58594+
58595+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
58596+
58597+ if (!len || len >= GR_SPROLE_LEN)
58598+ return -EINVAL;
58599+
58600+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58601+ return -ENOMEM;
58602+
58603+ if (copy_from_user(tmp, rtmp->rolename, len))
58604+ return -EFAULT;
58605+ tmp[len-1] = '\0';
58606+ rtmp->rolename = tmp;
58607+
58608+ if (!rlast) {
58609+ rtmp->prev = NULL;
58610+ rolep->transitions = rtmp;
58611+ } else {
58612+ rlast->next = rtmp;
58613+ rtmp->prev = rlast;
58614+ }
58615+
58616+ if (!rusertp)
58617+ rtmp->next = NULL;
58618+ }
58619+
58620+ return 0;
58621+}
58622+
58623+static struct acl_subject_label *
58624+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
58625+{
58626+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
58627+ unsigned int len;
58628+ char *tmp;
58629+ __u32 num_objs;
58630+ struct acl_ip_label **i_tmp, *i_utmp2;
58631+ struct gr_hash_struct ghash;
58632+ struct subject_map *subjmap;
58633+ unsigned int i_num;
58634+ int err;
58635+
58636+ if (already_copied != NULL)
58637+ *already_copied = 0;
58638+
58639+ s_tmp = lookup_subject_map(userp);
58640+
58641+ /* we've already copied this subject into the kernel, just return
58642+ the reference to it, and don't copy it over again
58643+ */
58644+ if (s_tmp) {
58645+ if (already_copied != NULL)
58646+ *already_copied = 1;
58647+ return(s_tmp);
58648+ }
58649+
58650+ if ((s_tmp = (struct acl_subject_label *)
58651+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
58652+ return ERR_PTR(-ENOMEM);
58653+
58654+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
58655+ if (subjmap == NULL)
58656+ return ERR_PTR(-ENOMEM);
58657+
58658+ subjmap->user = userp;
58659+ subjmap->kernel = s_tmp;
58660+ insert_subj_map_entry(subjmap);
58661+
58662+ if (copy_from_user(s_tmp, userp,
58663+ sizeof (struct acl_subject_label)))
58664+ return ERR_PTR(-EFAULT);
58665+
58666+ len = strnlen_user(s_tmp->filename, PATH_MAX);
58667+
58668+ if (!len || len >= PATH_MAX)
58669+ return ERR_PTR(-EINVAL);
58670+
58671+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58672+ return ERR_PTR(-ENOMEM);
58673+
58674+ if (copy_from_user(tmp, s_tmp->filename, len))
58675+ return ERR_PTR(-EFAULT);
58676+ tmp[len-1] = '\0';
58677+ s_tmp->filename = tmp;
58678+
58679+ if (!strcmp(s_tmp->filename, "/"))
58680+ role->root_label = s_tmp;
58681+
58682+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
58683+ return ERR_PTR(-EFAULT);
58684+
58685+ /* copy user and group transition tables */
58686+
58687+ if (s_tmp->user_trans_num) {
58688+ uid_t *uidlist;
58689+
58690+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
58691+ if (uidlist == NULL)
58692+ return ERR_PTR(-ENOMEM);
58693+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
58694+ return ERR_PTR(-EFAULT);
58695+
58696+ s_tmp->user_transitions = uidlist;
58697+ }
58698+
58699+ if (s_tmp->group_trans_num) {
58700+ gid_t *gidlist;
58701+
58702+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
58703+ if (gidlist == NULL)
58704+ return ERR_PTR(-ENOMEM);
58705+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
58706+ return ERR_PTR(-EFAULT);
58707+
58708+ s_tmp->group_transitions = gidlist;
58709+ }
58710+
58711+ /* set up object hash table */
58712+ num_objs = count_user_objs(ghash.first);
58713+
58714+ s_tmp->obj_hash_size = num_objs;
58715+ s_tmp->obj_hash =
58716+ (struct acl_object_label **)
58717+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
58718+
58719+ if (!s_tmp->obj_hash)
58720+ return ERR_PTR(-ENOMEM);
58721+
58722+ memset(s_tmp->obj_hash, 0,
58723+ s_tmp->obj_hash_size *
58724+ sizeof (struct acl_object_label *));
58725+
58726+ /* add in objects */
58727+ err = copy_user_objs(ghash.first, s_tmp, role);
58728+
58729+ if (err)
58730+ return ERR_PTR(err);
58731+
58732+ /* set pointer for parent subject */
58733+ if (s_tmp->parent_subject) {
58734+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
58735+
58736+ if (IS_ERR(s_tmp2))
58737+ return s_tmp2;
58738+
58739+ s_tmp->parent_subject = s_tmp2;
58740+ }
58741+
58742+ /* add in ip acls */
58743+
58744+ if (!s_tmp->ip_num) {
58745+ s_tmp->ips = NULL;
58746+ goto insert;
58747+ }
58748+
58749+ i_tmp =
58750+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
58751+ sizeof (struct acl_ip_label *));
58752+
58753+ if (!i_tmp)
58754+ return ERR_PTR(-ENOMEM);
58755+
58756+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
58757+ *(i_tmp + i_num) =
58758+ (struct acl_ip_label *)
58759+ acl_alloc(sizeof (struct acl_ip_label));
58760+ if (!*(i_tmp + i_num))
58761+ return ERR_PTR(-ENOMEM);
58762+
58763+ if (copy_from_user
58764+ (&i_utmp2, s_tmp->ips + i_num,
58765+ sizeof (struct acl_ip_label *)))
58766+ return ERR_PTR(-EFAULT);
58767+
58768+ if (copy_from_user
58769+ (*(i_tmp + i_num), i_utmp2,
58770+ sizeof (struct acl_ip_label)))
58771+ return ERR_PTR(-EFAULT);
58772+
58773+ if ((*(i_tmp + i_num))->iface == NULL)
58774+ continue;
58775+
58776+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
58777+ if (!len || len >= IFNAMSIZ)
58778+ return ERR_PTR(-EINVAL);
58779+ tmp = acl_alloc(len);
58780+ if (tmp == NULL)
58781+ return ERR_PTR(-ENOMEM);
58782+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
58783+ return ERR_PTR(-EFAULT);
58784+ (*(i_tmp + i_num))->iface = tmp;
58785+ }
58786+
58787+ s_tmp->ips = i_tmp;
58788+
58789+insert:
58790+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
58791+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
58792+ return ERR_PTR(-ENOMEM);
58793+
58794+ return s_tmp;
58795+}
58796+
58797+static int
58798+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
58799+{
58800+ struct acl_subject_label s_pre;
58801+ struct acl_subject_label * ret;
58802+ int err;
58803+
58804+ while (userp) {
58805+ if (copy_from_user(&s_pre, userp,
58806+ sizeof (struct acl_subject_label)))
58807+ return -EFAULT;
58808+
58809+ ret = do_copy_user_subj(userp, role, NULL);
58810+
58811+ err = PTR_ERR(ret);
58812+ if (IS_ERR(ret))
58813+ return err;
58814+
58815+ insert_acl_subj_label(ret, role);
58816+
58817+ userp = s_pre.prev;
58818+ }
58819+
58820+ return 0;
58821+}
58822+
58823+static int
58824+copy_user_acl(struct gr_arg *arg)
58825+{
58826+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
58827+ struct acl_subject_label *subj_list;
58828+ struct sprole_pw *sptmp;
58829+ struct gr_hash_struct *ghash;
58830+ uid_t *domainlist;
58831+ unsigned int r_num;
58832+ unsigned int len;
58833+ char *tmp;
58834+ int err = 0;
58835+ __u16 i;
58836+ __u32 num_subjs;
58837+
58838+ /* we need a default and kernel role */
58839+ if (arg->role_db.num_roles < 2)
58840+ return -EINVAL;
58841+
58842+ /* copy special role authentication info from userspace */
58843+
58844+ num_sprole_pws = arg->num_sprole_pws;
58845+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
58846+
58847+ if (!acl_special_roles && num_sprole_pws)
58848+ return -ENOMEM;
58849+
58850+ for (i = 0; i < num_sprole_pws; i++) {
58851+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
58852+ if (!sptmp)
58853+ return -ENOMEM;
58854+ if (copy_from_user(sptmp, arg->sprole_pws + i,
58855+ sizeof (struct sprole_pw)))
58856+ return -EFAULT;
58857+
58858+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
58859+
58860+ if (!len || len >= GR_SPROLE_LEN)
58861+ return -EINVAL;
58862+
58863+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58864+ return -ENOMEM;
58865+
58866+ if (copy_from_user(tmp, sptmp->rolename, len))
58867+ return -EFAULT;
58868+
58869+ tmp[len-1] = '\0';
58870+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58871+ printk(KERN_ALERT "Copying special role %s\n", tmp);
58872+#endif
58873+ sptmp->rolename = tmp;
58874+ acl_special_roles[i] = sptmp;
58875+ }
58876+
58877+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
58878+
58879+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
58880+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
58881+
58882+ if (!r_tmp)
58883+ return -ENOMEM;
58884+
58885+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
58886+ sizeof (struct acl_role_label *)))
58887+ return -EFAULT;
58888+
58889+ if (copy_from_user(r_tmp, r_utmp2,
58890+ sizeof (struct acl_role_label)))
58891+ return -EFAULT;
58892+
58893+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
58894+
58895+ if (!len || len >= PATH_MAX)
58896+ return -EINVAL;
58897+
58898+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58899+ return -ENOMEM;
58900+
58901+ if (copy_from_user(tmp, r_tmp->rolename, len))
58902+ return -EFAULT;
58903+
58904+ tmp[len-1] = '\0';
58905+ r_tmp->rolename = tmp;
58906+
58907+ if (!strcmp(r_tmp->rolename, "default")
58908+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
58909+ default_role = r_tmp;
58910+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
58911+ kernel_role = r_tmp;
58912+ }
58913+
58914+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
58915+ return -ENOMEM;
58916+
58917+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
58918+ return -EFAULT;
58919+
58920+ r_tmp->hash = ghash;
58921+
58922+ num_subjs = count_user_subjs(r_tmp->hash->first);
58923+
58924+ r_tmp->subj_hash_size = num_subjs;
58925+ r_tmp->subj_hash =
58926+ (struct acl_subject_label **)
58927+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
58928+
58929+ if (!r_tmp->subj_hash)
58930+ return -ENOMEM;
58931+
58932+ err = copy_user_allowedips(r_tmp);
58933+ if (err)
58934+ return err;
58935+
58936+ /* copy domain info */
58937+ if (r_tmp->domain_children != NULL) {
58938+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
58939+ if (domainlist == NULL)
58940+ return -ENOMEM;
58941+
58942+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
58943+ return -EFAULT;
58944+
58945+ r_tmp->domain_children = domainlist;
58946+ }
58947+
58948+ err = copy_user_transitions(r_tmp);
58949+ if (err)
58950+ return err;
58951+
58952+ memset(r_tmp->subj_hash, 0,
58953+ r_tmp->subj_hash_size *
58954+ sizeof (struct acl_subject_label *));
58955+
58956+ /* acquire the list of subjects, then NULL out
58957+ the list prior to parsing the subjects for this role,
58958+ as during this parsing the list is replaced with a list
58959+ of *nested* subjects for the role
58960+ */
58961+ subj_list = r_tmp->hash->first;
58962+
58963+ /* set nested subject list to null */
58964+ r_tmp->hash->first = NULL;
58965+
58966+ err = copy_user_subjs(subj_list, r_tmp);
58967+
58968+ if (err)
58969+ return err;
58970+
58971+ insert_acl_role_label(r_tmp);
58972+ }
58973+
58974+ if (default_role == NULL || kernel_role == NULL)
58975+ return -EINVAL;
58976+
58977+ return err;
58978+}
58979+
58980+static int
58981+gracl_init(struct gr_arg *args)
58982+{
58983+ int error = 0;
58984+
58985+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
58986+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
58987+
58988+ if (init_variables(args)) {
58989+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
58990+ error = -ENOMEM;
58991+ free_variables();
58992+ goto out;
58993+ }
58994+
58995+ error = copy_user_acl(args);
58996+ free_init_variables();
58997+ if (error) {
58998+ free_variables();
58999+ goto out;
59000+ }
59001+
59002+ if ((error = gr_set_acls(0))) {
59003+ free_variables();
59004+ goto out;
59005+ }
59006+
59007+ pax_open_kernel();
59008+ gr_status |= GR_READY;
59009+ pax_close_kernel();
59010+
59011+ out:
59012+ return error;
59013+}
59014+
59015+/* derived from glibc fnmatch() 0: match, 1: no match*/
59016+
59017+static int
59018+glob_match(const char *p, const char *n)
59019+{
59020+ char c;
59021+
59022+ while ((c = *p++) != '\0') {
59023+ switch (c) {
59024+ case '?':
59025+ if (*n == '\0')
59026+ return 1;
59027+ else if (*n == '/')
59028+ return 1;
59029+ break;
59030+ case '\\':
59031+ if (*n != c)
59032+ return 1;
59033+ break;
59034+ case '*':
59035+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
59036+ if (*n == '/')
59037+ return 1;
59038+ else if (c == '?') {
59039+ if (*n == '\0')
59040+ return 1;
59041+ else
59042+ ++n;
59043+ }
59044+ }
59045+ if (c == '\0') {
59046+ return 0;
59047+ } else {
59048+ const char *endp;
59049+
59050+ if ((endp = strchr(n, '/')) == NULL)
59051+ endp = n + strlen(n);
59052+
59053+ if (c == '[') {
59054+ for (--p; n < endp; ++n)
59055+ if (!glob_match(p, n))
59056+ return 0;
59057+ } else if (c == '/') {
59058+ while (*n != '\0' && *n != '/')
59059+ ++n;
59060+ if (*n == '/' && !glob_match(p, n + 1))
59061+ return 0;
59062+ } else {
59063+ for (--p; n < endp; ++n)
59064+ if (*n == c && !glob_match(p, n))
59065+ return 0;
59066+ }
59067+
59068+ return 1;
59069+ }
59070+ case '[':
59071+ {
59072+ int not;
59073+ char cold;
59074+
59075+ if (*n == '\0' || *n == '/')
59076+ return 1;
59077+
59078+ not = (*p == '!' || *p == '^');
59079+ if (not)
59080+ ++p;
59081+
59082+ c = *p++;
59083+ for (;;) {
59084+ unsigned char fn = (unsigned char)*n;
59085+
59086+ if (c == '\0')
59087+ return 1;
59088+ else {
59089+ if (c == fn)
59090+ goto matched;
59091+ cold = c;
59092+ c = *p++;
59093+
59094+ if (c == '-' && *p != ']') {
59095+ unsigned char cend = *p++;
59096+
59097+ if (cend == '\0')
59098+ return 1;
59099+
59100+ if (cold <= fn && fn <= cend)
59101+ goto matched;
59102+
59103+ c = *p++;
59104+ }
59105+ }
59106+
59107+ if (c == ']')
59108+ break;
59109+ }
59110+ if (!not)
59111+ return 1;
59112+ break;
59113+ matched:
59114+ while (c != ']') {
59115+ if (c == '\0')
59116+ return 1;
59117+
59118+ c = *p++;
59119+ }
59120+ if (not)
59121+ return 1;
59122+ }
59123+ break;
59124+ default:
59125+ if (c != *n)
59126+ return 1;
59127+ }
59128+
59129+ ++n;
59130+ }
59131+
59132+ if (*n == '\0')
59133+ return 0;
59134+
59135+ if (*n == '/')
59136+ return 0;
59137+
59138+ return 1;
59139+}
59140+
59141+static struct acl_object_label *
59142+chk_glob_label(struct acl_object_label *globbed,
59143+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
59144+{
59145+ struct acl_object_label *tmp;
59146+
59147+ if (*path == NULL)
59148+ *path = gr_to_filename_nolock(dentry, mnt);
59149+
59150+ tmp = globbed;
59151+
59152+ while (tmp) {
59153+ if (!glob_match(tmp->filename, *path))
59154+ return tmp;
59155+ tmp = tmp->next;
59156+ }
59157+
59158+ return NULL;
59159+}
59160+
59161+static struct acl_object_label *
59162+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
59163+ const ino_t curr_ino, const dev_t curr_dev,
59164+ const struct acl_subject_label *subj, char **path, const int checkglob)
59165+{
59166+ struct acl_subject_label *tmpsubj;
59167+ struct acl_object_label *retval;
59168+ struct acl_object_label *retval2;
59169+
59170+ tmpsubj = (struct acl_subject_label *) subj;
59171+ read_lock(&gr_inode_lock);
59172+ do {
59173+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
59174+ if (retval) {
59175+ if (checkglob && retval->globbed) {
59176+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
59177+ if (retval2)
59178+ retval = retval2;
59179+ }
59180+ break;
59181+ }
59182+ } while ((tmpsubj = tmpsubj->parent_subject));
59183+ read_unlock(&gr_inode_lock);
59184+
59185+ return retval;
59186+}
59187+
59188+static __inline__ struct acl_object_label *
59189+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
59190+ struct dentry *curr_dentry,
59191+ const struct acl_subject_label *subj, char **path, const int checkglob)
59192+{
59193+ int newglob = checkglob;
59194+ ino_t inode;
59195+ dev_t device;
59196+
59197+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
59198+ as we don't want a / * rule to match instead of the / object
59199+ don't do this for create lookups that call this function though, since they're looking up
59200+ on the parent and thus need globbing checks on all paths
59201+ */
59202+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
59203+ newglob = GR_NO_GLOB;
59204+
59205+ spin_lock(&curr_dentry->d_lock);
59206+ inode = curr_dentry->d_inode->i_ino;
59207+ device = __get_dev(curr_dentry);
59208+ spin_unlock(&curr_dentry->d_lock);
59209+
59210+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
59211+}
59212+
59213+#ifdef CONFIG_HUGETLBFS
59214+static inline bool
59215+is_hugetlbfs_mnt(const struct vfsmount *mnt)
59216+{
59217+ int i;
59218+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
59219+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
59220+ return true;
59221+ }
59222+
59223+ return false;
59224+}
59225+#endif
59226+
59227+static struct acl_object_label *
59228+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59229+ const struct acl_subject_label *subj, char *path, const int checkglob)
59230+{
59231+ struct dentry *dentry = (struct dentry *) l_dentry;
59232+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
59233+ struct mount *real_mnt = real_mount(mnt);
59234+ struct acl_object_label *retval;
59235+ struct dentry *parent;
59236+
59237+ br_read_lock(&vfsmount_lock);
59238+ write_seqlock(&rename_lock);
59239+
59240+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
59241+#ifdef CONFIG_NET
59242+ mnt == sock_mnt ||
59243+#endif
59244+#ifdef CONFIG_HUGETLBFS
59245+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
59246+#endif
59247+ /* ignore Eric Biederman */
59248+ IS_PRIVATE(l_dentry->d_inode))) {
59249+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
59250+ goto out;
59251+ }
59252+
59253+ for (;;) {
59254+ if (dentry == real_root.dentry && mnt == real_root.mnt)
59255+ break;
59256+
59257+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
59258+ if (!mnt_has_parent(real_mnt))
59259+ break;
59260+
59261+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59262+ if (retval != NULL)
59263+ goto out;
59264+
59265+ dentry = real_mnt->mnt_mountpoint;
59266+ real_mnt = real_mnt->mnt_parent;
59267+ mnt = &real_mnt->mnt;
59268+ continue;
59269+ }
59270+
59271+ parent = dentry->d_parent;
59272+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59273+ if (retval != NULL)
59274+ goto out;
59275+
59276+ dentry = parent;
59277+ }
59278+
59279+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59280+
59281+ /* real_root is pinned so we don't have to hold a reference */
59282+ if (retval == NULL)
59283+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
59284+out:
59285+ write_sequnlock(&rename_lock);
59286+ br_read_unlock(&vfsmount_lock);
59287+
59288+ BUG_ON(retval == NULL);
59289+
59290+ return retval;
59291+}
59292+
59293+static __inline__ struct acl_object_label *
59294+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59295+ const struct acl_subject_label *subj)
59296+{
59297+ char *path = NULL;
59298+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
59299+}
59300+
59301+static __inline__ struct acl_object_label *
59302+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59303+ const struct acl_subject_label *subj)
59304+{
59305+ char *path = NULL;
59306+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
59307+}
59308+
59309+static __inline__ struct acl_object_label *
59310+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59311+ const struct acl_subject_label *subj, char *path)
59312+{
59313+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
59314+}
59315+
59316+static struct acl_subject_label *
59317+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59318+ const struct acl_role_label *role)
59319+{
59320+ struct dentry *dentry = (struct dentry *) l_dentry;
59321+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
59322+ struct mount *real_mnt = real_mount(mnt);
59323+ struct acl_subject_label *retval;
59324+ struct dentry *parent;
59325+
59326+ br_read_lock(&vfsmount_lock);
59327+ write_seqlock(&rename_lock);
59328+
59329+ for (;;) {
59330+ if (dentry == real_root.dentry && mnt == real_root.mnt)
59331+ break;
59332+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
59333+ if (!mnt_has_parent(real_mnt))
59334+ break;
59335+
59336+ spin_lock(&dentry->d_lock);
59337+ read_lock(&gr_inode_lock);
59338+ retval =
59339+ lookup_acl_subj_label(dentry->d_inode->i_ino,
59340+ __get_dev(dentry), role);
59341+ read_unlock(&gr_inode_lock);
59342+ spin_unlock(&dentry->d_lock);
59343+ if (retval != NULL)
59344+ goto out;
59345+
59346+ dentry = real_mnt->mnt_mountpoint;
59347+ real_mnt = real_mnt->mnt_parent;
59348+ mnt = &real_mnt->mnt;
59349+ continue;
59350+ }
59351+
59352+ spin_lock(&dentry->d_lock);
59353+ read_lock(&gr_inode_lock);
59354+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
59355+ __get_dev(dentry), role);
59356+ read_unlock(&gr_inode_lock);
59357+ parent = dentry->d_parent;
59358+ spin_unlock(&dentry->d_lock);
59359+
59360+ if (retval != NULL)
59361+ goto out;
59362+
59363+ dentry = parent;
59364+ }
59365+
59366+ spin_lock(&dentry->d_lock);
59367+ read_lock(&gr_inode_lock);
59368+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
59369+ __get_dev(dentry), role);
59370+ read_unlock(&gr_inode_lock);
59371+ spin_unlock(&dentry->d_lock);
59372+
59373+ if (unlikely(retval == NULL)) {
59374+ /* real_root is pinned, we don't need to hold a reference */
59375+ read_lock(&gr_inode_lock);
59376+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
59377+ __get_dev(real_root.dentry), role);
59378+ read_unlock(&gr_inode_lock);
59379+ }
59380+out:
59381+ write_sequnlock(&rename_lock);
59382+ br_read_unlock(&vfsmount_lock);
59383+
59384+ BUG_ON(retval == NULL);
59385+
59386+ return retval;
59387+}
59388+
59389+static void
59390+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
59391+{
59392+ struct task_struct *task = current;
59393+ const struct cred *cred = current_cred();
59394+
59395+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
59396+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59397+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59398+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
59399+
59400+ return;
59401+}
59402+
59403+static void
59404+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
59405+{
59406+ struct task_struct *task = current;
59407+ const struct cred *cred = current_cred();
59408+
59409+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
59410+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59411+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59412+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
59413+
59414+ return;
59415+}
59416+
59417+static void
59418+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
59419+{
59420+ struct task_struct *task = current;
59421+ const struct cred *cred = current_cred();
59422+
59423+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
59424+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59425+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59426+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
59427+
59428+ return;
59429+}
59430+
59431+__u32
59432+gr_search_file(const struct dentry * dentry, const __u32 mode,
59433+ const struct vfsmount * mnt)
59434+{
59435+ __u32 retval = mode;
59436+ struct acl_subject_label *curracl;
59437+ struct acl_object_label *currobj;
59438+
59439+ if (unlikely(!(gr_status & GR_READY)))
59440+ return (mode & ~GR_AUDITS);
59441+
59442+ curracl = current->acl;
59443+
59444+ currobj = chk_obj_label(dentry, mnt, curracl);
59445+ retval = currobj->mode & mode;
59446+
59447+ /* if we're opening a specified transfer file for writing
59448+ (e.g. /dev/initctl), then transfer our role to init
59449+ */
59450+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
59451+ current->role->roletype & GR_ROLE_PERSIST)) {
59452+ struct task_struct *task = init_pid_ns.child_reaper;
59453+
59454+ if (task->role != current->role) {
59455+ task->acl_sp_role = 0;
59456+ task->acl_role_id = current->acl_role_id;
59457+ task->role = current->role;
59458+ rcu_read_lock();
59459+ read_lock(&grsec_exec_file_lock);
59460+ gr_apply_subject_to_task(task);
59461+ read_unlock(&grsec_exec_file_lock);
59462+ rcu_read_unlock();
59463+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
59464+ }
59465+ }
59466+
59467+ if (unlikely
59468+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
59469+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
59470+ __u32 new_mode = mode;
59471+
59472+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
59473+
59474+ retval = new_mode;
59475+
59476+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
59477+ new_mode |= GR_INHERIT;
59478+
59479+ if (!(mode & GR_NOLEARN))
59480+ gr_log_learn(dentry, mnt, new_mode);
59481+ }
59482+
59483+ return retval;
59484+}
59485+
59486+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
59487+ const struct dentry *parent,
59488+ const struct vfsmount *mnt)
59489+{
59490+ struct name_entry *match;
59491+ struct acl_object_label *matchpo;
59492+ struct acl_subject_label *curracl;
59493+ char *path;
59494+
59495+ if (unlikely(!(gr_status & GR_READY)))
59496+ return NULL;
59497+
59498+ preempt_disable();
59499+ path = gr_to_filename_rbac(new_dentry, mnt);
59500+ match = lookup_name_entry_create(path);
59501+
59502+ curracl = current->acl;
59503+
59504+ if (match) {
59505+ read_lock(&gr_inode_lock);
59506+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
59507+ read_unlock(&gr_inode_lock);
59508+
59509+ if (matchpo) {
59510+ preempt_enable();
59511+ return matchpo;
59512+ }
59513+ }
59514+
59515+ // lookup parent
59516+
59517+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
59518+
59519+ preempt_enable();
59520+ return matchpo;
59521+}
59522+
59523+__u32
59524+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
59525+ const struct vfsmount * mnt, const __u32 mode)
59526+{
59527+ struct acl_object_label *matchpo;
59528+ __u32 retval;
59529+
59530+ if (unlikely(!(gr_status & GR_READY)))
59531+ return (mode & ~GR_AUDITS);
59532+
59533+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
59534+
59535+ retval = matchpo->mode & mode;
59536+
59537+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
59538+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
59539+ __u32 new_mode = mode;
59540+
59541+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
59542+
59543+ gr_log_learn(new_dentry, mnt, new_mode);
59544+ return new_mode;
59545+ }
59546+
59547+ return retval;
59548+}
59549+
59550+__u32
59551+gr_check_link(const struct dentry * new_dentry,
59552+ const struct dentry * parent_dentry,
59553+ const struct vfsmount * parent_mnt,
59554+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
59555+{
59556+ struct acl_object_label *obj;
59557+ __u32 oldmode, newmode;
59558+ __u32 needmode;
59559+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
59560+ GR_DELETE | GR_INHERIT;
59561+
59562+ if (unlikely(!(gr_status & GR_READY)))
59563+ return (GR_CREATE | GR_LINK);
59564+
59565+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
59566+ oldmode = obj->mode;
59567+
59568+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
59569+ newmode = obj->mode;
59570+
59571+ needmode = newmode & checkmodes;
59572+
59573+ // old name for hardlink must have at least the permissions of the new name
59574+ if ((oldmode & needmode) != needmode)
59575+ goto bad;
59576+
59577+ // if old name had restrictions/auditing, make sure the new name does as well
59578+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
59579+
59580+ // don't allow hardlinking of suid/sgid/fcapped files without permission
59581+ if (is_privileged_binary(old_dentry))
59582+ needmode |= GR_SETID;
59583+
59584+ if ((newmode & needmode) != needmode)
59585+ goto bad;
59586+
59587+ // enforce minimum permissions
59588+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
59589+ return newmode;
59590+bad:
59591+ needmode = oldmode;
59592+ if (is_privileged_binary(old_dentry))
59593+ needmode |= GR_SETID;
59594+
59595+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
59596+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
59597+ return (GR_CREATE | GR_LINK);
59598+ } else if (newmode & GR_SUPPRESS)
59599+ return GR_SUPPRESS;
59600+ else
59601+ return 0;
59602+}
59603+
59604+int
59605+gr_check_hidden_task(const struct task_struct *task)
59606+{
59607+ if (unlikely(!(gr_status & GR_READY)))
59608+ return 0;
59609+
59610+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
59611+ return 1;
59612+
59613+ return 0;
59614+}
59615+
59616+int
59617+gr_check_protected_task(const struct task_struct *task)
59618+{
59619+ if (unlikely(!(gr_status & GR_READY) || !task))
59620+ return 0;
59621+
59622+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
59623+ task->acl != current->acl)
59624+ return 1;
59625+
59626+ return 0;
59627+}
59628+
59629+int
59630+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59631+{
59632+ struct task_struct *p;
59633+ int ret = 0;
59634+
59635+ if (unlikely(!(gr_status & GR_READY) || !pid))
59636+ return ret;
59637+
59638+ read_lock(&tasklist_lock);
59639+ do_each_pid_task(pid, type, p) {
59640+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
59641+ p->acl != current->acl) {
59642+ ret = 1;
59643+ goto out;
59644+ }
59645+ } while_each_pid_task(pid, type, p);
59646+out:
59647+ read_unlock(&tasklist_lock);
59648+
59649+ return ret;
59650+}
59651+
59652+void
59653+gr_copy_label(struct task_struct *tsk)
59654+{
59655+ tsk->signal->used_accept = 0;
59656+ tsk->acl_sp_role = 0;
59657+ tsk->acl_role_id = current->acl_role_id;
59658+ tsk->acl = current->acl;
59659+ tsk->role = current->role;
59660+ tsk->signal->curr_ip = current->signal->curr_ip;
59661+ tsk->signal->saved_ip = current->signal->saved_ip;
59662+ if (current->exec_file)
59663+ get_file(current->exec_file);
59664+ tsk->exec_file = current->exec_file;
59665+ tsk->is_writable = current->is_writable;
59666+ if (unlikely(current->signal->used_accept)) {
59667+ current->signal->curr_ip = 0;
59668+ current->signal->saved_ip = 0;
59669+ }
59670+
59671+ return;
59672+}
59673+
59674+static void
59675+gr_set_proc_res(struct task_struct *task)
59676+{
59677+ struct acl_subject_label *proc;
59678+ unsigned short i;
59679+
59680+ proc = task->acl;
59681+
59682+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
59683+ return;
59684+
59685+ for (i = 0; i < RLIM_NLIMITS; i++) {
59686+ if (!(proc->resmask & (1 << i)))
59687+ continue;
59688+
59689+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
59690+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
59691+
59692+ if (i == RLIMIT_CPU)
59693+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
59694+ }
59695+
59696+ return;
59697+}
59698+
59699+extern int __gr_process_user_ban(struct user_struct *user);
59700+
59701+int
59702+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
59703+{
59704+ unsigned int i;
59705+ __u16 num;
59706+ uid_t *uidlist;
59707+ uid_t curuid;
59708+ int realok = 0;
59709+ int effectiveok = 0;
59710+ int fsok = 0;
59711+ uid_t globalreal, globaleffective, globalfs;
59712+
59713+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59714+ struct user_struct *user;
59715+
59716+ if (!uid_valid(real))
59717+ goto skipit;
59718+
59719+ /* find user based on global namespace */
59720+
59721+ globalreal = GR_GLOBAL_UID(real);
59722+
59723+ user = find_user(make_kuid(&init_user_ns, globalreal));
59724+ if (user == NULL)
59725+ goto skipit;
59726+
59727+ if (__gr_process_user_ban(user)) {
59728+ /* for find_user */
59729+ free_uid(user);
59730+ return 1;
59731+ }
59732+
59733+ /* for find_user */
59734+ free_uid(user);
59735+
59736+skipit:
59737+#endif
59738+
59739+ if (unlikely(!(gr_status & GR_READY)))
59740+ return 0;
59741+
59742+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59743+ gr_log_learn_uid_change(real, effective, fs);
59744+
59745+ num = current->acl->user_trans_num;
59746+ uidlist = current->acl->user_transitions;
59747+
59748+ if (uidlist == NULL)
59749+ return 0;
59750+
59751+ if (!uid_valid(real)) {
59752+ realok = 1;
59753+ globalreal = (uid_t)-1;
59754+ } else {
59755+ globalreal = GR_GLOBAL_UID(real);
59756+ }
59757+ if (!uid_valid(effective)) {
59758+ effectiveok = 1;
59759+ globaleffective = (uid_t)-1;
59760+ } else {
59761+ globaleffective = GR_GLOBAL_UID(effective);
59762+ }
59763+ if (!uid_valid(fs)) {
59764+ fsok = 1;
59765+ globalfs = (uid_t)-1;
59766+ } else {
59767+ globalfs = GR_GLOBAL_UID(fs);
59768+ }
59769+
59770+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
59771+ for (i = 0; i < num; i++) {
59772+ curuid = uidlist[i];
59773+ if (globalreal == curuid)
59774+ realok = 1;
59775+ if (globaleffective == curuid)
59776+ effectiveok = 1;
59777+ if (globalfs == curuid)
59778+ fsok = 1;
59779+ }
59780+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
59781+ for (i = 0; i < num; i++) {
59782+ curuid = uidlist[i];
59783+ if (globalreal == curuid)
59784+ break;
59785+ if (globaleffective == curuid)
59786+ break;
59787+ if (globalfs == curuid)
59788+ break;
59789+ }
59790+ /* not in deny list */
59791+ if (i == num) {
59792+ realok = 1;
59793+ effectiveok = 1;
59794+ fsok = 1;
59795+ }
59796+ }
59797+
59798+ if (realok && effectiveok && fsok)
59799+ return 0;
59800+ else {
59801+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59802+ return 1;
59803+ }
59804+}
59805+
59806+int
59807+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
59808+{
59809+ unsigned int i;
59810+ __u16 num;
59811+ gid_t *gidlist;
59812+ gid_t curgid;
59813+ int realok = 0;
59814+ int effectiveok = 0;
59815+ int fsok = 0;
59816+ gid_t globalreal, globaleffective, globalfs;
59817+
59818+ if (unlikely(!(gr_status & GR_READY)))
59819+ return 0;
59820+
59821+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59822+ gr_log_learn_gid_change(real, effective, fs);
59823+
59824+ num = current->acl->group_trans_num;
59825+ gidlist = current->acl->group_transitions;
59826+
59827+ if (gidlist == NULL)
59828+ return 0;
59829+
59830+ if (!gid_valid(real)) {
59831+ realok = 1;
59832+ globalreal = (gid_t)-1;
59833+ } else {
59834+ globalreal = GR_GLOBAL_GID(real);
59835+ }
59836+ if (!gid_valid(effective)) {
59837+ effectiveok = 1;
59838+ globaleffective = (gid_t)-1;
59839+ } else {
59840+ globaleffective = GR_GLOBAL_GID(effective);
59841+ }
59842+ if (!gid_valid(fs)) {
59843+ fsok = 1;
59844+ globalfs = (gid_t)-1;
59845+ } else {
59846+ globalfs = GR_GLOBAL_GID(fs);
59847+ }
59848+
59849+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
59850+ for (i = 0; i < num; i++) {
59851+ curgid = gidlist[i];
59852+ if (globalreal == curgid)
59853+ realok = 1;
59854+ if (globaleffective == curgid)
59855+ effectiveok = 1;
59856+ if (globalfs == curgid)
59857+ fsok = 1;
59858+ }
59859+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
59860+ for (i = 0; i < num; i++) {
59861+ curgid = gidlist[i];
59862+ if (globalreal == curgid)
59863+ break;
59864+ if (globaleffective == curgid)
59865+ break;
59866+ if (globalfs == curgid)
59867+ break;
59868+ }
59869+ /* not in deny list */
59870+ if (i == num) {
59871+ realok = 1;
59872+ effectiveok = 1;
59873+ fsok = 1;
59874+ }
59875+ }
59876+
59877+ if (realok && effectiveok && fsok)
59878+ return 0;
59879+ else {
59880+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59881+ return 1;
59882+ }
59883+}
59884+
59885+extern int gr_acl_is_capable(const int cap);
59886+
59887+void
59888+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
59889+{
59890+ struct acl_role_label *role = task->role;
59891+ struct acl_subject_label *subj = NULL;
59892+ struct acl_object_label *obj;
59893+ struct file *filp;
59894+ uid_t uid;
59895+ gid_t gid;
59896+
59897+ if (unlikely(!(gr_status & GR_READY)))
59898+ return;
59899+
59900+ uid = GR_GLOBAL_UID(kuid);
59901+ gid = GR_GLOBAL_GID(kgid);
59902+
59903+ filp = task->exec_file;
59904+
59905+ /* kernel process, we'll give them the kernel role */
59906+ if (unlikely(!filp)) {
59907+ task->role = kernel_role;
59908+ task->acl = kernel_role->root_label;
59909+ return;
59910+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
59911+ role = lookup_acl_role_label(task, uid, gid);
59912+
59913+ /* don't change the role if we're not a privileged process */
59914+ if (role && task->role != role &&
59915+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
59916+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
59917+ return;
59918+
59919+ /* perform subject lookup in possibly new role
59920+ we can use this result below in the case where role == task->role
59921+ */
59922+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
59923+
59924+ /* if we changed uid/gid, but result in the same role
59925+ and are using inheritance, don't lose the inherited subject
59926+ if current subject is other than what normal lookup
59927+ would result in, we arrived via inheritance, don't
59928+ lose subject
59929+ */
59930+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
59931+ (subj == task->acl)))
59932+ task->acl = subj;
59933+
59934+ task->role = role;
59935+
59936+ task->is_writable = 0;
59937+
59938+ /* ignore additional mmap checks for processes that are writable
59939+ by the default ACL */
59940+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59941+ if (unlikely(obj->mode & GR_WRITE))
59942+ task->is_writable = 1;
59943+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
59944+ if (unlikely(obj->mode & GR_WRITE))
59945+ task->is_writable = 1;
59946+
59947+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59948+ 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);
59949+#endif
59950+
59951+ gr_set_proc_res(task);
59952+
59953+ return;
59954+}
59955+
59956+int
59957+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59958+ const int unsafe_flags)
59959+{
59960+ struct task_struct *task = current;
59961+ struct acl_subject_label *newacl;
59962+ struct acl_object_label *obj;
59963+ __u32 retmode;
59964+
59965+ if (unlikely(!(gr_status & GR_READY)))
59966+ return 0;
59967+
59968+ newacl = chk_subj_label(dentry, mnt, task->role);
59969+
59970+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
59971+ did an exec
59972+ */
59973+ rcu_read_lock();
59974+ read_lock(&tasklist_lock);
59975+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
59976+ (task->parent->acl->mode & GR_POVERRIDE))) {
59977+ read_unlock(&tasklist_lock);
59978+ rcu_read_unlock();
59979+ goto skip_check;
59980+ }
59981+ read_unlock(&tasklist_lock);
59982+ rcu_read_unlock();
59983+
59984+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
59985+ !(task->role->roletype & GR_ROLE_GOD) &&
59986+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
59987+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
59988+ if (unsafe_flags & LSM_UNSAFE_SHARE)
59989+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
59990+ else
59991+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
59992+ return -EACCES;
59993+ }
59994+
59995+skip_check:
59996+
59997+ obj = chk_obj_label(dentry, mnt, task->acl);
59998+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
59999+
60000+ if (!(task->acl->mode & GR_INHERITLEARN) &&
60001+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
60002+ if (obj->nested)
60003+ task->acl = obj->nested;
60004+ else
60005+ task->acl = newacl;
60006+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
60007+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
60008+
60009+ task->is_writable = 0;
60010+
60011+ /* ignore additional mmap checks for processes that are writable
60012+ by the default ACL */
60013+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
60014+ if (unlikely(obj->mode & GR_WRITE))
60015+ task->is_writable = 1;
60016+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
60017+ if (unlikely(obj->mode & GR_WRITE))
60018+ task->is_writable = 1;
60019+
60020+ gr_set_proc_res(task);
60021+
60022+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60023+ 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);
60024+#endif
60025+ return 0;
60026+}
60027+
60028+/* always called with valid inodev ptr */
60029+static void
60030+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
60031+{
60032+ struct acl_object_label *matchpo;
60033+ struct acl_subject_label *matchps;
60034+ struct acl_subject_label *subj;
60035+ struct acl_role_label *role;
60036+ unsigned int x;
60037+
60038+ FOR_EACH_ROLE_START(role)
60039+ FOR_EACH_SUBJECT_START(role, subj, x)
60040+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60041+ matchpo->mode |= GR_DELETED;
60042+ FOR_EACH_SUBJECT_END(subj,x)
60043+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
60044+ /* nested subjects aren't in the role's subj_hash table */
60045+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60046+ matchpo->mode |= GR_DELETED;
60047+ FOR_EACH_NESTED_SUBJECT_END(subj)
60048+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
60049+ matchps->mode |= GR_DELETED;
60050+ FOR_EACH_ROLE_END(role)
60051+
60052+ inodev->nentry->deleted = 1;
60053+
60054+ return;
60055+}
60056+
60057+void
60058+gr_handle_delete(const ino_t ino, const dev_t dev)
60059+{
60060+ struct inodev_entry *inodev;
60061+
60062+ if (unlikely(!(gr_status & GR_READY)))
60063+ return;
60064+
60065+ write_lock(&gr_inode_lock);
60066+ inodev = lookup_inodev_entry(ino, dev);
60067+ if (inodev != NULL)
60068+ do_handle_delete(inodev, ino, dev);
60069+ write_unlock(&gr_inode_lock);
60070+
60071+ return;
60072+}
60073+
60074+static void
60075+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
60076+ const ino_t newinode, const dev_t newdevice,
60077+ struct acl_subject_label *subj)
60078+{
60079+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
60080+ struct acl_object_label *match;
60081+
60082+ match = subj->obj_hash[index];
60083+
60084+ while (match && (match->inode != oldinode ||
60085+ match->device != olddevice ||
60086+ !(match->mode & GR_DELETED)))
60087+ match = match->next;
60088+
60089+ if (match && (match->inode == oldinode)
60090+ && (match->device == olddevice)
60091+ && (match->mode & GR_DELETED)) {
60092+ if (match->prev == NULL) {
60093+ subj->obj_hash[index] = match->next;
60094+ if (match->next != NULL)
60095+ match->next->prev = NULL;
60096+ } else {
60097+ match->prev->next = match->next;
60098+ if (match->next != NULL)
60099+ match->next->prev = match->prev;
60100+ }
60101+ match->prev = NULL;
60102+ match->next = NULL;
60103+ match->inode = newinode;
60104+ match->device = newdevice;
60105+ match->mode &= ~GR_DELETED;
60106+
60107+ insert_acl_obj_label(match, subj);
60108+ }
60109+
60110+ return;
60111+}
60112+
60113+static void
60114+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
60115+ const ino_t newinode, const dev_t newdevice,
60116+ struct acl_role_label *role)
60117+{
60118+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
60119+ struct acl_subject_label *match;
60120+
60121+ match = role->subj_hash[index];
60122+
60123+ while (match && (match->inode != oldinode ||
60124+ match->device != olddevice ||
60125+ !(match->mode & GR_DELETED)))
60126+ match = match->next;
60127+
60128+ if (match && (match->inode == oldinode)
60129+ && (match->device == olddevice)
60130+ && (match->mode & GR_DELETED)) {
60131+ if (match->prev == NULL) {
60132+ role->subj_hash[index] = match->next;
60133+ if (match->next != NULL)
60134+ match->next->prev = NULL;
60135+ } else {
60136+ match->prev->next = match->next;
60137+ if (match->next != NULL)
60138+ match->next->prev = match->prev;
60139+ }
60140+ match->prev = NULL;
60141+ match->next = NULL;
60142+ match->inode = newinode;
60143+ match->device = newdevice;
60144+ match->mode &= ~GR_DELETED;
60145+
60146+ insert_acl_subj_label(match, role);
60147+ }
60148+
60149+ return;
60150+}
60151+
60152+static void
60153+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
60154+ const ino_t newinode, const dev_t newdevice)
60155+{
60156+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
60157+ struct inodev_entry *match;
60158+
60159+ match = inodev_set.i_hash[index];
60160+
60161+ while (match && (match->nentry->inode != oldinode ||
60162+ match->nentry->device != olddevice || !match->nentry->deleted))
60163+ match = match->next;
60164+
60165+ if (match && (match->nentry->inode == oldinode)
60166+ && (match->nentry->device == olddevice) &&
60167+ match->nentry->deleted) {
60168+ if (match->prev == NULL) {
60169+ inodev_set.i_hash[index] = match->next;
60170+ if (match->next != NULL)
60171+ match->next->prev = NULL;
60172+ } else {
60173+ match->prev->next = match->next;
60174+ if (match->next != NULL)
60175+ match->next->prev = match->prev;
60176+ }
60177+ match->prev = NULL;
60178+ match->next = NULL;
60179+ match->nentry->inode = newinode;
60180+ match->nentry->device = newdevice;
60181+ match->nentry->deleted = 0;
60182+
60183+ insert_inodev_entry(match);
60184+ }
60185+
60186+ return;
60187+}
60188+
60189+static void
60190+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
60191+{
60192+ struct acl_subject_label *subj;
60193+ struct acl_role_label *role;
60194+ unsigned int x;
60195+
60196+ FOR_EACH_ROLE_START(role)
60197+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
60198+
60199+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
60200+ if ((subj->inode == ino) && (subj->device == dev)) {
60201+ subj->inode = ino;
60202+ subj->device = dev;
60203+ }
60204+ /* nested subjects aren't in the role's subj_hash table */
60205+ update_acl_obj_label(matchn->inode, matchn->device,
60206+ ino, dev, subj);
60207+ FOR_EACH_NESTED_SUBJECT_END(subj)
60208+ FOR_EACH_SUBJECT_START(role, subj, x)
60209+ update_acl_obj_label(matchn->inode, matchn->device,
60210+ ino, dev, subj);
60211+ FOR_EACH_SUBJECT_END(subj,x)
60212+ FOR_EACH_ROLE_END(role)
60213+
60214+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
60215+
60216+ return;
60217+}
60218+
60219+static void
60220+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
60221+ const struct vfsmount *mnt)
60222+{
60223+ ino_t ino = dentry->d_inode->i_ino;
60224+ dev_t dev = __get_dev(dentry);
60225+
60226+ __do_handle_create(matchn, ino, dev);
60227+
60228+ return;
60229+}
60230+
60231+void
60232+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
60233+{
60234+ struct name_entry *matchn;
60235+
60236+ if (unlikely(!(gr_status & GR_READY)))
60237+ return;
60238+
60239+ preempt_disable();
60240+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
60241+
60242+ if (unlikely((unsigned long)matchn)) {
60243+ write_lock(&gr_inode_lock);
60244+ do_handle_create(matchn, dentry, mnt);
60245+ write_unlock(&gr_inode_lock);
60246+ }
60247+ preempt_enable();
60248+
60249+ return;
60250+}
60251+
60252+void
60253+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
60254+{
60255+ struct name_entry *matchn;
60256+
60257+ if (unlikely(!(gr_status & GR_READY)))
60258+ return;
60259+
60260+ preempt_disable();
60261+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
60262+
60263+ if (unlikely((unsigned long)matchn)) {
60264+ write_lock(&gr_inode_lock);
60265+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
60266+ write_unlock(&gr_inode_lock);
60267+ }
60268+ preempt_enable();
60269+
60270+ return;
60271+}
60272+
60273+void
60274+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
60275+ struct dentry *old_dentry,
60276+ struct dentry *new_dentry,
60277+ struct vfsmount *mnt, const __u8 replace)
60278+{
60279+ struct name_entry *matchn;
60280+ struct inodev_entry *inodev;
60281+ struct inode *inode = new_dentry->d_inode;
60282+ ino_t old_ino = old_dentry->d_inode->i_ino;
60283+ dev_t old_dev = __get_dev(old_dentry);
60284+
60285+ /* vfs_rename swaps the name and parent link for old_dentry and
60286+ new_dentry
60287+ at this point, old_dentry has the new name, parent link, and inode
60288+ for the renamed file
60289+ if a file is being replaced by a rename, new_dentry has the inode
60290+ and name for the replaced file
60291+ */
60292+
60293+ if (unlikely(!(gr_status & GR_READY)))
60294+ return;
60295+
60296+ preempt_disable();
60297+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
60298+
60299+ /* we wouldn't have to check d_inode if it weren't for
60300+ NFS silly-renaming
60301+ */
60302+
60303+ write_lock(&gr_inode_lock);
60304+ if (unlikely(replace && inode)) {
60305+ ino_t new_ino = inode->i_ino;
60306+ dev_t new_dev = __get_dev(new_dentry);
60307+
60308+ inodev = lookup_inodev_entry(new_ino, new_dev);
60309+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
60310+ do_handle_delete(inodev, new_ino, new_dev);
60311+ }
60312+
60313+ inodev = lookup_inodev_entry(old_ino, old_dev);
60314+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
60315+ do_handle_delete(inodev, old_ino, old_dev);
60316+
60317+ if (unlikely((unsigned long)matchn))
60318+ do_handle_create(matchn, old_dentry, mnt);
60319+
60320+ write_unlock(&gr_inode_lock);
60321+ preempt_enable();
60322+
60323+ return;
60324+}
60325+
60326+static int
60327+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
60328+ unsigned char **sum)
60329+{
60330+ struct acl_role_label *r;
60331+ struct role_allowed_ip *ipp;
60332+ struct role_transition *trans;
60333+ unsigned int i;
60334+ int found = 0;
60335+ u32 curr_ip = current->signal->curr_ip;
60336+
60337+ current->signal->saved_ip = curr_ip;
60338+
60339+ /* check transition table */
60340+
60341+ for (trans = current->role->transitions; trans; trans = trans->next) {
60342+ if (!strcmp(rolename, trans->rolename)) {
60343+ found = 1;
60344+ break;
60345+ }
60346+ }
60347+
60348+ if (!found)
60349+ return 0;
60350+
60351+ /* handle special roles that do not require authentication
60352+ and check ip */
60353+
60354+ FOR_EACH_ROLE_START(r)
60355+ if (!strcmp(rolename, r->rolename) &&
60356+ (r->roletype & GR_ROLE_SPECIAL)) {
60357+ found = 0;
60358+ if (r->allowed_ips != NULL) {
60359+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
60360+ if ((ntohl(curr_ip) & ipp->netmask) ==
60361+ (ntohl(ipp->addr) & ipp->netmask))
60362+ found = 1;
60363+ }
60364+ } else
60365+ found = 2;
60366+ if (!found)
60367+ return 0;
60368+
60369+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
60370+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
60371+ *salt = NULL;
60372+ *sum = NULL;
60373+ return 1;
60374+ }
60375+ }
60376+ FOR_EACH_ROLE_END(r)
60377+
60378+ for (i = 0; i < num_sprole_pws; i++) {
60379+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
60380+ *salt = acl_special_roles[i]->salt;
60381+ *sum = acl_special_roles[i]->sum;
60382+ return 1;
60383+ }
60384+ }
60385+
60386+ return 0;
60387+}
60388+
60389+static void
60390+assign_special_role(char *rolename)
60391+{
60392+ struct acl_object_label *obj;
60393+ struct acl_role_label *r;
60394+ struct acl_role_label *assigned = NULL;
60395+ struct task_struct *tsk;
60396+ struct file *filp;
60397+
60398+ FOR_EACH_ROLE_START(r)
60399+ if (!strcmp(rolename, r->rolename) &&
60400+ (r->roletype & GR_ROLE_SPECIAL)) {
60401+ assigned = r;
60402+ break;
60403+ }
60404+ FOR_EACH_ROLE_END(r)
60405+
60406+ if (!assigned)
60407+ return;
60408+
60409+ read_lock(&tasklist_lock);
60410+ read_lock(&grsec_exec_file_lock);
60411+
60412+ tsk = current->real_parent;
60413+ if (tsk == NULL)
60414+ goto out_unlock;
60415+
60416+ filp = tsk->exec_file;
60417+ if (filp == NULL)
60418+ goto out_unlock;
60419+
60420+ tsk->is_writable = 0;
60421+
60422+ tsk->acl_sp_role = 1;
60423+ tsk->acl_role_id = ++acl_sp_role_value;
60424+ tsk->role = assigned;
60425+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
60426+
60427+ /* ignore additional mmap checks for processes that are writable
60428+ by the default ACL */
60429+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60430+ if (unlikely(obj->mode & GR_WRITE))
60431+ tsk->is_writable = 1;
60432+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
60433+ if (unlikely(obj->mode & GR_WRITE))
60434+ tsk->is_writable = 1;
60435+
60436+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60437+ 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));
60438+#endif
60439+
60440+out_unlock:
60441+ read_unlock(&grsec_exec_file_lock);
60442+ read_unlock(&tasklist_lock);
60443+ return;
60444+}
60445+
60446+int gr_check_secure_terminal(struct task_struct *task)
60447+{
60448+ struct task_struct *p, *p2, *p3;
60449+ struct files_struct *files;
60450+ struct fdtable *fdt;
60451+ struct file *our_file = NULL, *file;
60452+ int i;
60453+
60454+ if (task->signal->tty == NULL)
60455+ return 1;
60456+
60457+ files = get_files_struct(task);
60458+ if (files != NULL) {
60459+ rcu_read_lock();
60460+ fdt = files_fdtable(files);
60461+ for (i=0; i < fdt->max_fds; i++) {
60462+ file = fcheck_files(files, i);
60463+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
60464+ get_file(file);
60465+ our_file = file;
60466+ }
60467+ }
60468+ rcu_read_unlock();
60469+ put_files_struct(files);
60470+ }
60471+
60472+ if (our_file == NULL)
60473+ return 1;
60474+
60475+ read_lock(&tasklist_lock);
60476+ do_each_thread(p2, p) {
60477+ files = get_files_struct(p);
60478+ if (files == NULL ||
60479+ (p->signal && p->signal->tty == task->signal->tty)) {
60480+ if (files != NULL)
60481+ put_files_struct(files);
60482+ continue;
60483+ }
60484+ rcu_read_lock();
60485+ fdt = files_fdtable(files);
60486+ for (i=0; i < fdt->max_fds; i++) {
60487+ file = fcheck_files(files, i);
60488+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
60489+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
60490+ p3 = task;
60491+ while (task_pid_nr(p3) > 0) {
60492+ if (p3 == p)
60493+ break;
60494+ p3 = p3->real_parent;
60495+ }
60496+ if (p3 == p)
60497+ break;
60498+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
60499+ gr_handle_alertkill(p);
60500+ rcu_read_unlock();
60501+ put_files_struct(files);
60502+ read_unlock(&tasklist_lock);
60503+ fput(our_file);
60504+ return 0;
60505+ }
60506+ }
60507+ rcu_read_unlock();
60508+ put_files_struct(files);
60509+ } while_each_thread(p2, p);
60510+ read_unlock(&tasklist_lock);
60511+
60512+ fput(our_file);
60513+ return 1;
60514+}
60515+
60516+static int gr_rbac_disable(void *unused)
60517+{
60518+ pax_open_kernel();
60519+ gr_status &= ~GR_READY;
60520+ pax_close_kernel();
60521+
60522+ return 0;
60523+}
60524+
60525+ssize_t
60526+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
60527+{
60528+ struct gr_arg_wrapper uwrap;
60529+ unsigned char *sprole_salt = NULL;
60530+ unsigned char *sprole_sum = NULL;
60531+ int error = sizeof (struct gr_arg_wrapper);
60532+ int error2 = 0;
60533+
60534+ mutex_lock(&gr_dev_mutex);
60535+
60536+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
60537+ error = -EPERM;
60538+ goto out;
60539+ }
60540+
60541+ if (count != sizeof (struct gr_arg_wrapper)) {
60542+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
60543+ error = -EINVAL;
60544+ goto out;
60545+ }
60546+
60547+
60548+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
60549+ gr_auth_expires = 0;
60550+ gr_auth_attempts = 0;
60551+ }
60552+
60553+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
60554+ error = -EFAULT;
60555+ goto out;
60556+ }
60557+
60558+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
60559+ error = -EINVAL;
60560+ goto out;
60561+ }
60562+
60563+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
60564+ error = -EFAULT;
60565+ goto out;
60566+ }
60567+
60568+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
60569+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
60570+ time_after(gr_auth_expires, get_seconds())) {
60571+ error = -EBUSY;
60572+ goto out;
60573+ }
60574+
60575+ /* if non-root trying to do anything other than use a special role,
60576+ do not attempt authentication, do not count towards authentication
60577+ locking
60578+ */
60579+
60580+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
60581+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
60582+ gr_is_global_nonroot(current_uid())) {
60583+ error = -EPERM;
60584+ goto out;
60585+ }
60586+
60587+ /* ensure pw and special role name are null terminated */
60588+
60589+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
60590+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
60591+
60592+ /* Okay.
60593+ * We have our enough of the argument structure..(we have yet
60594+ * to copy_from_user the tables themselves) . Copy the tables
60595+ * only if we need them, i.e. for loading operations. */
60596+
60597+ switch (gr_usermode->mode) {
60598+ case GR_STATUS:
60599+ if (gr_status & GR_READY) {
60600+ error = 1;
60601+ if (!gr_check_secure_terminal(current))
60602+ error = 3;
60603+ } else
60604+ error = 2;
60605+ goto out;
60606+ case GR_SHUTDOWN:
60607+ if ((gr_status & GR_READY)
60608+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60609+ stop_machine(gr_rbac_disable, NULL, NULL);
60610+ free_variables();
60611+ memset(gr_usermode, 0, sizeof (struct gr_arg));
60612+ memset(gr_system_salt, 0, GR_SALT_LEN);
60613+ memset(gr_system_sum, 0, GR_SHA_LEN);
60614+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
60615+ } else if (gr_status & GR_READY) {
60616+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
60617+ error = -EPERM;
60618+ } else {
60619+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
60620+ error = -EAGAIN;
60621+ }
60622+ break;
60623+ case GR_ENABLE:
60624+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
60625+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
60626+ else {
60627+ if (gr_status & GR_READY)
60628+ error = -EAGAIN;
60629+ else
60630+ error = error2;
60631+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
60632+ }
60633+ break;
60634+ case GR_RELOAD:
60635+ if (!(gr_status & GR_READY)) {
60636+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
60637+ error = -EAGAIN;
60638+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60639+ stop_machine(gr_rbac_disable, NULL, NULL);
60640+ free_variables();
60641+ error2 = gracl_init(gr_usermode);
60642+ if (!error2)
60643+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
60644+ else {
60645+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
60646+ error = error2;
60647+ }
60648+ } else {
60649+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
60650+ error = -EPERM;
60651+ }
60652+ break;
60653+ case GR_SEGVMOD:
60654+ if (unlikely(!(gr_status & GR_READY))) {
60655+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
60656+ error = -EAGAIN;
60657+ break;
60658+ }
60659+
60660+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60661+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
60662+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
60663+ struct acl_subject_label *segvacl;
60664+ segvacl =
60665+ lookup_acl_subj_label(gr_usermode->segv_inode,
60666+ gr_usermode->segv_device,
60667+ current->role);
60668+ if (segvacl) {
60669+ segvacl->crashes = 0;
60670+ segvacl->expires = 0;
60671+ }
60672+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
60673+ gr_remove_uid(gr_usermode->segv_uid);
60674+ }
60675+ } else {
60676+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
60677+ error = -EPERM;
60678+ }
60679+ break;
60680+ case GR_SPROLE:
60681+ case GR_SPROLEPAM:
60682+ if (unlikely(!(gr_status & GR_READY))) {
60683+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
60684+ error = -EAGAIN;
60685+ break;
60686+ }
60687+
60688+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
60689+ current->role->expires = 0;
60690+ current->role->auth_attempts = 0;
60691+ }
60692+
60693+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
60694+ time_after(current->role->expires, get_seconds())) {
60695+ error = -EBUSY;
60696+ goto out;
60697+ }
60698+
60699+ if (lookup_special_role_auth
60700+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
60701+ && ((!sprole_salt && !sprole_sum)
60702+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
60703+ char *p = "";
60704+ assign_special_role(gr_usermode->sp_role);
60705+ read_lock(&tasklist_lock);
60706+ if (current->real_parent)
60707+ p = current->real_parent->role->rolename;
60708+ read_unlock(&tasklist_lock);
60709+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
60710+ p, acl_sp_role_value);
60711+ } else {
60712+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
60713+ error = -EPERM;
60714+ if(!(current->role->auth_attempts++))
60715+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
60716+
60717+ goto out;
60718+ }
60719+ break;
60720+ case GR_UNSPROLE:
60721+ if (unlikely(!(gr_status & GR_READY))) {
60722+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
60723+ error = -EAGAIN;
60724+ break;
60725+ }
60726+
60727+ if (current->role->roletype & GR_ROLE_SPECIAL) {
60728+ char *p = "";
60729+ int i = 0;
60730+
60731+ read_lock(&tasklist_lock);
60732+ if (current->real_parent) {
60733+ p = current->real_parent->role->rolename;
60734+ i = current->real_parent->acl_role_id;
60735+ }
60736+ read_unlock(&tasklist_lock);
60737+
60738+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
60739+ gr_set_acls(1);
60740+ } else {
60741+ error = -EPERM;
60742+ goto out;
60743+ }
60744+ break;
60745+ default:
60746+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
60747+ error = -EINVAL;
60748+ break;
60749+ }
60750+
60751+ if (error != -EPERM)
60752+ goto out;
60753+
60754+ if(!(gr_auth_attempts++))
60755+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
60756+
60757+ out:
60758+ mutex_unlock(&gr_dev_mutex);
60759+ return error;
60760+}
60761+
60762+/* must be called with
60763+ rcu_read_lock();
60764+ read_lock(&tasklist_lock);
60765+ read_lock(&grsec_exec_file_lock);
60766+*/
60767+int gr_apply_subject_to_task(struct task_struct *task)
60768+{
60769+ struct acl_object_label *obj;
60770+ char *tmpname;
60771+ struct acl_subject_label *tmpsubj;
60772+ struct file *filp;
60773+ struct name_entry *nmatch;
60774+
60775+ filp = task->exec_file;
60776+ if (filp == NULL)
60777+ return 0;
60778+
60779+ /* the following is to apply the correct subject
60780+ on binaries running when the RBAC system
60781+ is enabled, when the binaries have been
60782+ replaced or deleted since their execution
60783+ -----
60784+ when the RBAC system starts, the inode/dev
60785+ from exec_file will be one the RBAC system
60786+ is unaware of. It only knows the inode/dev
60787+ of the present file on disk, or the absence
60788+ of it.
60789+ */
60790+ preempt_disable();
60791+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
60792+
60793+ nmatch = lookup_name_entry(tmpname);
60794+ preempt_enable();
60795+ tmpsubj = NULL;
60796+ if (nmatch) {
60797+ if (nmatch->deleted)
60798+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
60799+ else
60800+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
60801+ if (tmpsubj != NULL)
60802+ task->acl = tmpsubj;
60803+ }
60804+ if (tmpsubj == NULL)
60805+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
60806+ task->role);
60807+ if (task->acl) {
60808+ task->is_writable = 0;
60809+ /* ignore additional mmap checks for processes that are writable
60810+ by the default ACL */
60811+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60812+ if (unlikely(obj->mode & GR_WRITE))
60813+ task->is_writable = 1;
60814+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60815+ if (unlikely(obj->mode & GR_WRITE))
60816+ task->is_writable = 1;
60817+
60818+ gr_set_proc_res(task);
60819+
60820+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60821+ 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);
60822+#endif
60823+ } else {
60824+ return 1;
60825+ }
60826+
60827+ return 0;
60828+}
60829+
60830+int
60831+gr_set_acls(const int type)
60832+{
60833+ struct task_struct *task, *task2;
60834+ struct acl_role_label *role = current->role;
60835+ __u16 acl_role_id = current->acl_role_id;
60836+ const struct cred *cred;
60837+ int ret;
60838+
60839+ rcu_read_lock();
60840+ read_lock(&tasklist_lock);
60841+ read_lock(&grsec_exec_file_lock);
60842+ do_each_thread(task2, task) {
60843+ /* check to see if we're called from the exit handler,
60844+ if so, only replace ACLs that have inherited the admin
60845+ ACL */
60846+
60847+ if (type && (task->role != role ||
60848+ task->acl_role_id != acl_role_id))
60849+ continue;
60850+
60851+ task->acl_role_id = 0;
60852+ task->acl_sp_role = 0;
60853+
60854+ if (task->exec_file) {
60855+ cred = __task_cred(task);
60856+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
60857+ ret = gr_apply_subject_to_task(task);
60858+ if (ret) {
60859+ read_unlock(&grsec_exec_file_lock);
60860+ read_unlock(&tasklist_lock);
60861+ rcu_read_unlock();
60862+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
60863+ return ret;
60864+ }
60865+ } else {
60866+ // it's a kernel process
60867+ task->role = kernel_role;
60868+ task->acl = kernel_role->root_label;
60869+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
60870+ task->acl->mode &= ~GR_PROCFIND;
60871+#endif
60872+ }
60873+ } while_each_thread(task2, task);
60874+ read_unlock(&grsec_exec_file_lock);
60875+ read_unlock(&tasklist_lock);
60876+ rcu_read_unlock();
60877+
60878+ return 0;
60879+}
60880+
60881+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
60882+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
60883+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
60884+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
60885+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
60886+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
60887+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
60888+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
60889+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
60890+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
60891+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
60892+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
60893+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
60894+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
60895+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
60896+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
60897+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
60898+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
60899+};
60900+
60901+void
60902+gr_learn_resource(const struct task_struct *task,
60903+ const int res, const unsigned long wanted, const int gt)
60904+{
60905+ struct acl_subject_label *acl;
60906+ const struct cred *cred;
60907+
60908+ if (unlikely((gr_status & GR_READY) &&
60909+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
60910+ goto skip_reslog;
60911+
60912+ gr_log_resource(task, res, wanted, gt);
60913+skip_reslog:
60914+
60915+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
60916+ return;
60917+
60918+ acl = task->acl;
60919+
60920+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
60921+ !(acl->resmask & (1 << (unsigned short) res))))
60922+ return;
60923+
60924+ if (wanted >= acl->res[res].rlim_cur) {
60925+ unsigned long res_add;
60926+
60927+ res_add = wanted + res_learn_bumps[res];
60928+
60929+ acl->res[res].rlim_cur = res_add;
60930+
60931+ if (wanted > acl->res[res].rlim_max)
60932+ acl->res[res].rlim_max = res_add;
60933+
60934+ /* only log the subject filename, since resource logging is supported for
60935+ single-subject learning only */
60936+ rcu_read_lock();
60937+ cred = __task_cred(task);
60938+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
60939+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
60940+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
60941+ "", (unsigned long) res, &task->signal->saved_ip);
60942+ rcu_read_unlock();
60943+ }
60944+
60945+ return;
60946+}
60947+EXPORT_SYMBOL(gr_learn_resource);
60948+#endif
60949+
60950+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
60951+void
60952+pax_set_initial_flags(struct linux_binprm *bprm)
60953+{
60954+ struct task_struct *task = current;
60955+ struct acl_subject_label *proc;
60956+ unsigned long flags;
60957+
60958+ if (unlikely(!(gr_status & GR_READY)))
60959+ return;
60960+
60961+ flags = pax_get_flags(task);
60962+
60963+ proc = task->acl;
60964+
60965+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
60966+ flags &= ~MF_PAX_PAGEEXEC;
60967+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
60968+ flags &= ~MF_PAX_SEGMEXEC;
60969+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
60970+ flags &= ~MF_PAX_RANDMMAP;
60971+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
60972+ flags &= ~MF_PAX_EMUTRAMP;
60973+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
60974+ flags &= ~MF_PAX_MPROTECT;
60975+
60976+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
60977+ flags |= MF_PAX_PAGEEXEC;
60978+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
60979+ flags |= MF_PAX_SEGMEXEC;
60980+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
60981+ flags |= MF_PAX_RANDMMAP;
60982+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
60983+ flags |= MF_PAX_EMUTRAMP;
60984+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
60985+ flags |= MF_PAX_MPROTECT;
60986+
60987+ pax_set_flags(task, flags);
60988+
60989+ return;
60990+}
60991+#endif
60992+
60993+int
60994+gr_handle_proc_ptrace(struct task_struct *task)
60995+{
60996+ struct file *filp;
60997+ struct task_struct *tmp = task;
60998+ struct task_struct *curtemp = current;
60999+ __u32 retmode;
61000+
61001+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61002+ if (unlikely(!(gr_status & GR_READY)))
61003+ return 0;
61004+#endif
61005+
61006+ read_lock(&tasklist_lock);
61007+ read_lock(&grsec_exec_file_lock);
61008+ filp = task->exec_file;
61009+
61010+ while (task_pid_nr(tmp) > 0) {
61011+ if (tmp == curtemp)
61012+ break;
61013+ tmp = tmp->real_parent;
61014+ }
61015+
61016+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61017+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
61018+ read_unlock(&grsec_exec_file_lock);
61019+ read_unlock(&tasklist_lock);
61020+ return 1;
61021+ }
61022+
61023+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61024+ if (!(gr_status & GR_READY)) {
61025+ read_unlock(&grsec_exec_file_lock);
61026+ read_unlock(&tasklist_lock);
61027+ return 0;
61028+ }
61029+#endif
61030+
61031+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
61032+ read_unlock(&grsec_exec_file_lock);
61033+ read_unlock(&tasklist_lock);
61034+
61035+ if (retmode & GR_NOPTRACE)
61036+ return 1;
61037+
61038+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
61039+ && (current->acl != task->acl || (current->acl != current->role->root_label
61040+ && task_pid_nr(current) != task_pid_nr(task))))
61041+ return 1;
61042+
61043+ return 0;
61044+}
61045+
61046+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
61047+{
61048+ if (unlikely(!(gr_status & GR_READY)))
61049+ return;
61050+
61051+ if (!(current->role->roletype & GR_ROLE_GOD))
61052+ return;
61053+
61054+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
61055+ p->role->rolename, gr_task_roletype_to_char(p),
61056+ p->acl->filename);
61057+}
61058+
61059+int
61060+gr_handle_ptrace(struct task_struct *task, const long request)
61061+{
61062+ struct task_struct *tmp = task;
61063+ struct task_struct *curtemp = current;
61064+ __u32 retmode;
61065+
61066+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61067+ if (unlikely(!(gr_status & GR_READY)))
61068+ return 0;
61069+#endif
61070+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
61071+ read_lock(&tasklist_lock);
61072+ while (task_pid_nr(tmp) > 0) {
61073+ if (tmp == curtemp)
61074+ break;
61075+ tmp = tmp->real_parent;
61076+ }
61077+
61078+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61079+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
61080+ read_unlock(&tasklist_lock);
61081+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61082+ return 1;
61083+ }
61084+ read_unlock(&tasklist_lock);
61085+ }
61086+
61087+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61088+ if (!(gr_status & GR_READY))
61089+ return 0;
61090+#endif
61091+
61092+ read_lock(&grsec_exec_file_lock);
61093+ if (unlikely(!task->exec_file)) {
61094+ read_unlock(&grsec_exec_file_lock);
61095+ return 0;
61096+ }
61097+
61098+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
61099+ read_unlock(&grsec_exec_file_lock);
61100+
61101+ if (retmode & GR_NOPTRACE) {
61102+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61103+ return 1;
61104+ }
61105+
61106+ if (retmode & GR_PTRACERD) {
61107+ switch (request) {
61108+ case PTRACE_SEIZE:
61109+ case PTRACE_POKETEXT:
61110+ case PTRACE_POKEDATA:
61111+ case PTRACE_POKEUSR:
61112+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
61113+ case PTRACE_SETREGS:
61114+ case PTRACE_SETFPREGS:
61115+#endif
61116+#ifdef CONFIG_X86
61117+ case PTRACE_SETFPXREGS:
61118+#endif
61119+#ifdef CONFIG_ALTIVEC
61120+ case PTRACE_SETVRREGS:
61121+#endif
61122+ return 1;
61123+ default:
61124+ return 0;
61125+ }
61126+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
61127+ !(current->role->roletype & GR_ROLE_GOD) &&
61128+ (current->acl != task->acl)) {
61129+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61130+ return 1;
61131+ }
61132+
61133+ return 0;
61134+}
61135+
61136+static int is_writable_mmap(const struct file *filp)
61137+{
61138+ struct task_struct *task = current;
61139+ struct acl_object_label *obj, *obj2;
61140+
61141+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
61142+ !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))) {
61143+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61144+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
61145+ task->role->root_label);
61146+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
61147+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
61148+ return 1;
61149+ }
61150+ }
61151+ return 0;
61152+}
61153+
61154+int
61155+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
61156+{
61157+ __u32 mode;
61158+
61159+ if (unlikely(!file || !(prot & PROT_EXEC)))
61160+ return 1;
61161+
61162+ if (is_writable_mmap(file))
61163+ return 0;
61164+
61165+ mode =
61166+ gr_search_file(file->f_path.dentry,
61167+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
61168+ file->f_path.mnt);
61169+
61170+ if (!gr_tpe_allow(file))
61171+ return 0;
61172+
61173+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
61174+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61175+ return 0;
61176+ } else if (unlikely(!(mode & GR_EXEC))) {
61177+ return 0;
61178+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
61179+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61180+ return 1;
61181+ }
61182+
61183+ return 1;
61184+}
61185+
61186+int
61187+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
61188+{
61189+ __u32 mode;
61190+
61191+ if (unlikely(!file || !(prot & PROT_EXEC)))
61192+ return 1;
61193+
61194+ if (is_writable_mmap(file))
61195+ return 0;
61196+
61197+ mode =
61198+ gr_search_file(file->f_path.dentry,
61199+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
61200+ file->f_path.mnt);
61201+
61202+ if (!gr_tpe_allow(file))
61203+ return 0;
61204+
61205+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
61206+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61207+ return 0;
61208+ } else if (unlikely(!(mode & GR_EXEC))) {
61209+ return 0;
61210+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
61211+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61212+ return 1;
61213+ }
61214+
61215+ return 1;
61216+}
61217+
61218+void
61219+gr_acl_handle_psacct(struct task_struct *task, const long code)
61220+{
61221+ unsigned long runtime;
61222+ unsigned long cputime;
61223+ unsigned int wday, cday;
61224+ __u8 whr, chr;
61225+ __u8 wmin, cmin;
61226+ __u8 wsec, csec;
61227+ struct timespec timeval;
61228+
61229+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
61230+ !(task->acl->mode & GR_PROCACCT)))
61231+ return;
61232+
61233+ do_posix_clock_monotonic_gettime(&timeval);
61234+ runtime = timeval.tv_sec - task->start_time.tv_sec;
61235+ wday = runtime / (3600 * 24);
61236+ runtime -= wday * (3600 * 24);
61237+ whr = runtime / 3600;
61238+ runtime -= whr * 3600;
61239+ wmin = runtime / 60;
61240+ runtime -= wmin * 60;
61241+ wsec = runtime;
61242+
61243+ cputime = (task->utime + task->stime) / HZ;
61244+ cday = cputime / (3600 * 24);
61245+ cputime -= cday * (3600 * 24);
61246+ chr = cputime / 3600;
61247+ cputime -= chr * 3600;
61248+ cmin = cputime / 60;
61249+ cputime -= cmin * 60;
61250+ csec = cputime;
61251+
61252+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
61253+
61254+ return;
61255+}
61256+
61257+void gr_set_kernel_label(struct task_struct *task)
61258+{
61259+ if (gr_status & GR_READY) {
61260+ task->role = kernel_role;
61261+ task->acl = kernel_role->root_label;
61262+ }
61263+ return;
61264+}
61265+
61266+#ifdef CONFIG_TASKSTATS
61267+int gr_is_taskstats_denied(int pid)
61268+{
61269+ struct task_struct *task;
61270+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61271+ const struct cred *cred;
61272+#endif
61273+ int ret = 0;
61274+
61275+ /* restrict taskstats viewing to un-chrooted root users
61276+ who have the 'view' subject flag if the RBAC system is enabled
61277+ */
61278+
61279+ rcu_read_lock();
61280+ read_lock(&tasklist_lock);
61281+ task = find_task_by_vpid(pid);
61282+ if (task) {
61283+#ifdef CONFIG_GRKERNSEC_CHROOT
61284+ if (proc_is_chrooted(task))
61285+ ret = -EACCES;
61286+#endif
61287+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61288+ cred = __task_cred(task);
61289+#ifdef CONFIG_GRKERNSEC_PROC_USER
61290+ if (gr_is_global_nonroot(cred->uid))
61291+ ret = -EACCES;
61292+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61293+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
61294+ ret = -EACCES;
61295+#endif
61296+#endif
61297+ if (gr_status & GR_READY) {
61298+ if (!(task->acl->mode & GR_VIEW))
61299+ ret = -EACCES;
61300+ }
61301+ } else
61302+ ret = -ENOENT;
61303+
61304+ read_unlock(&tasklist_lock);
61305+ rcu_read_unlock();
61306+
61307+ return ret;
61308+}
61309+#endif
61310+
61311+/* AUXV entries are filled via a descendant of search_binary_handler
61312+ after we've already applied the subject for the target
61313+*/
61314+int gr_acl_enable_at_secure(void)
61315+{
61316+ if (unlikely(!(gr_status & GR_READY)))
61317+ return 0;
61318+
61319+ if (current->acl->mode & GR_ATSECURE)
61320+ return 1;
61321+
61322+ return 0;
61323+}
61324+
61325+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
61326+{
61327+ struct task_struct *task = current;
61328+ struct dentry *dentry = file->f_path.dentry;
61329+ struct vfsmount *mnt = file->f_path.mnt;
61330+ struct acl_object_label *obj, *tmp;
61331+ struct acl_subject_label *subj;
61332+ unsigned int bufsize;
61333+ int is_not_root;
61334+ char *path;
61335+ dev_t dev = __get_dev(dentry);
61336+
61337+ if (unlikely(!(gr_status & GR_READY)))
61338+ return 1;
61339+
61340+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
61341+ return 1;
61342+
61343+ /* ignore Eric Biederman */
61344+ if (IS_PRIVATE(dentry->d_inode))
61345+ return 1;
61346+
61347+ subj = task->acl;
61348+ read_lock(&gr_inode_lock);
61349+ do {
61350+ obj = lookup_acl_obj_label(ino, dev, subj);
61351+ if (obj != NULL) {
61352+ read_unlock(&gr_inode_lock);
61353+ return (obj->mode & GR_FIND) ? 1 : 0;
61354+ }
61355+ } while ((subj = subj->parent_subject));
61356+ read_unlock(&gr_inode_lock);
61357+
61358+ /* this is purely an optimization since we're looking for an object
61359+ for the directory we're doing a readdir on
61360+ if it's possible for any globbed object to match the entry we're
61361+ filling into the directory, then the object we find here will be
61362+ an anchor point with attached globbed objects
61363+ */
61364+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
61365+ if (obj->globbed == NULL)
61366+ return (obj->mode & GR_FIND) ? 1 : 0;
61367+
61368+ is_not_root = ((obj->filename[0] == '/') &&
61369+ (obj->filename[1] == '\0')) ? 0 : 1;
61370+ bufsize = PAGE_SIZE - namelen - is_not_root;
61371+
61372+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
61373+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
61374+ return 1;
61375+
61376+ preempt_disable();
61377+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
61378+ bufsize);
61379+
61380+ bufsize = strlen(path);
61381+
61382+ /* if base is "/", don't append an additional slash */
61383+ if (is_not_root)
61384+ *(path + bufsize) = '/';
61385+ memcpy(path + bufsize + is_not_root, name, namelen);
61386+ *(path + bufsize + namelen + is_not_root) = '\0';
61387+
61388+ tmp = obj->globbed;
61389+ while (tmp) {
61390+ if (!glob_match(tmp->filename, path)) {
61391+ preempt_enable();
61392+ return (tmp->mode & GR_FIND) ? 1 : 0;
61393+ }
61394+ tmp = tmp->next;
61395+ }
61396+ preempt_enable();
61397+ return (obj->mode & GR_FIND) ? 1 : 0;
61398+}
61399+
61400+void gr_put_exec_file(struct task_struct *task)
61401+{
61402+ struct file *filp;
61403+
61404+ write_lock(&grsec_exec_file_lock);
61405+ filp = task->exec_file;
61406+ task->exec_file = NULL;
61407+ write_unlock(&grsec_exec_file_lock);
61408+
61409+ if (filp)
61410+ fput(filp);
61411+
61412+ return;
61413+}
61414+
61415+
61416+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
61417+EXPORT_SYMBOL(gr_acl_is_enabled);
61418+#endif
61419+EXPORT_SYMBOL(gr_set_kernel_label);
61420+#ifdef CONFIG_SECURITY
61421+EXPORT_SYMBOL(gr_check_user_change);
61422+EXPORT_SYMBOL(gr_check_group_change);
61423+#endif
61424+
61425diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
61426new file mode 100644
61427index 0000000..34fefda
61428--- /dev/null
61429+++ b/grsecurity/gracl_alloc.c
61430@@ -0,0 +1,105 @@
61431+#include <linux/kernel.h>
61432+#include <linux/mm.h>
61433+#include <linux/slab.h>
61434+#include <linux/vmalloc.h>
61435+#include <linux/gracl.h>
61436+#include <linux/grsecurity.h>
61437+
61438+static unsigned long alloc_stack_next = 1;
61439+static unsigned long alloc_stack_size = 1;
61440+static void **alloc_stack;
61441+
61442+static __inline__ int
61443+alloc_pop(void)
61444+{
61445+ if (alloc_stack_next == 1)
61446+ return 0;
61447+
61448+ kfree(alloc_stack[alloc_stack_next - 2]);
61449+
61450+ alloc_stack_next--;
61451+
61452+ return 1;
61453+}
61454+
61455+static __inline__ int
61456+alloc_push(void *buf)
61457+{
61458+ if (alloc_stack_next >= alloc_stack_size)
61459+ return 1;
61460+
61461+ alloc_stack[alloc_stack_next - 1] = buf;
61462+
61463+ alloc_stack_next++;
61464+
61465+ return 0;
61466+}
61467+
61468+void *
61469+acl_alloc(unsigned long len)
61470+{
61471+ void *ret = NULL;
61472+
61473+ if (!len || len > PAGE_SIZE)
61474+ goto out;
61475+
61476+ ret = kmalloc(len, GFP_KERNEL);
61477+
61478+ if (ret) {
61479+ if (alloc_push(ret)) {
61480+ kfree(ret);
61481+ ret = NULL;
61482+ }
61483+ }
61484+
61485+out:
61486+ return ret;
61487+}
61488+
61489+void *
61490+acl_alloc_num(unsigned long num, unsigned long len)
61491+{
61492+ if (!len || (num > (PAGE_SIZE / len)))
61493+ return NULL;
61494+
61495+ return acl_alloc(num * len);
61496+}
61497+
61498+void
61499+acl_free_all(void)
61500+{
61501+ if (gr_acl_is_enabled() || !alloc_stack)
61502+ return;
61503+
61504+ while (alloc_pop()) ;
61505+
61506+ if (alloc_stack) {
61507+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
61508+ kfree(alloc_stack);
61509+ else
61510+ vfree(alloc_stack);
61511+ }
61512+
61513+ alloc_stack = NULL;
61514+ alloc_stack_size = 1;
61515+ alloc_stack_next = 1;
61516+
61517+ return;
61518+}
61519+
61520+int
61521+acl_alloc_stack_init(unsigned long size)
61522+{
61523+ if ((size * sizeof (void *)) <= PAGE_SIZE)
61524+ alloc_stack =
61525+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
61526+ else
61527+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
61528+
61529+ alloc_stack_size = size;
61530+
61531+ if (!alloc_stack)
61532+ return 0;
61533+ else
61534+ return 1;
61535+}
61536diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
61537new file mode 100644
61538index 0000000..bdd51ea
61539--- /dev/null
61540+++ b/grsecurity/gracl_cap.c
61541@@ -0,0 +1,110 @@
61542+#include <linux/kernel.h>
61543+#include <linux/module.h>
61544+#include <linux/sched.h>
61545+#include <linux/gracl.h>
61546+#include <linux/grsecurity.h>
61547+#include <linux/grinternal.h>
61548+
61549+extern const char *captab_log[];
61550+extern int captab_log_entries;
61551+
61552+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
61553+{
61554+ struct acl_subject_label *curracl;
61555+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
61556+ kernel_cap_t cap_audit = __cap_empty_set;
61557+
61558+ if (!gr_acl_is_enabled())
61559+ return 1;
61560+
61561+ curracl = task->acl;
61562+
61563+ cap_drop = curracl->cap_lower;
61564+ cap_mask = curracl->cap_mask;
61565+ cap_audit = curracl->cap_invert_audit;
61566+
61567+ while ((curracl = curracl->parent_subject)) {
61568+ /* if the cap isn't specified in the current computed mask but is specified in the
61569+ current level subject, and is lowered in the current level subject, then add
61570+ it to the set of dropped capabilities
61571+ otherwise, add the current level subject's mask to the current computed mask
61572+ */
61573+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
61574+ cap_raise(cap_mask, cap);
61575+ if (cap_raised(curracl->cap_lower, cap))
61576+ cap_raise(cap_drop, cap);
61577+ if (cap_raised(curracl->cap_invert_audit, cap))
61578+ cap_raise(cap_audit, cap);
61579+ }
61580+ }
61581+
61582+ if (!cap_raised(cap_drop, cap)) {
61583+ if (cap_raised(cap_audit, cap))
61584+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
61585+ return 1;
61586+ }
61587+
61588+ curracl = task->acl;
61589+
61590+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
61591+ && cap_raised(cred->cap_effective, cap)) {
61592+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
61593+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
61594+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
61595+ gr_to_filename(task->exec_file->f_path.dentry,
61596+ task->exec_file->f_path.mnt) : curracl->filename,
61597+ curracl->filename, 0UL,
61598+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
61599+ return 1;
61600+ }
61601+
61602+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
61603+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
61604+
61605+ return 0;
61606+}
61607+
61608+int
61609+gr_acl_is_capable(const int cap)
61610+{
61611+ return gr_task_acl_is_capable(current, current_cred(), cap);
61612+}
61613+
61614+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
61615+{
61616+ struct acl_subject_label *curracl;
61617+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
61618+
61619+ if (!gr_acl_is_enabled())
61620+ return 1;
61621+
61622+ curracl = task->acl;
61623+
61624+ cap_drop = curracl->cap_lower;
61625+ cap_mask = curracl->cap_mask;
61626+
61627+ while ((curracl = curracl->parent_subject)) {
61628+ /* if the cap isn't specified in the current computed mask but is specified in the
61629+ current level subject, and is lowered in the current level subject, then add
61630+ it to the set of dropped capabilities
61631+ otherwise, add the current level subject's mask to the current computed mask
61632+ */
61633+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
61634+ cap_raise(cap_mask, cap);
61635+ if (cap_raised(curracl->cap_lower, cap))
61636+ cap_raise(cap_drop, cap);
61637+ }
61638+ }
61639+
61640+ if (!cap_raised(cap_drop, cap))
61641+ return 1;
61642+
61643+ return 0;
61644+}
61645+
61646+int
61647+gr_acl_is_capable_nolog(const int cap)
61648+{
61649+ return gr_task_acl_is_capable_nolog(current, cap);
61650+}
61651+
61652diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
61653new file mode 100644
61654index 0000000..a340c17
61655--- /dev/null
61656+++ b/grsecurity/gracl_fs.c
61657@@ -0,0 +1,431 @@
61658+#include <linux/kernel.h>
61659+#include <linux/sched.h>
61660+#include <linux/types.h>
61661+#include <linux/fs.h>
61662+#include <linux/file.h>
61663+#include <linux/stat.h>
61664+#include <linux/grsecurity.h>
61665+#include <linux/grinternal.h>
61666+#include <linux/gracl.h>
61667+
61668+umode_t
61669+gr_acl_umask(void)
61670+{
61671+ if (unlikely(!gr_acl_is_enabled()))
61672+ return 0;
61673+
61674+ return current->role->umask;
61675+}
61676+
61677+__u32
61678+gr_acl_handle_hidden_file(const struct dentry * dentry,
61679+ const struct vfsmount * mnt)
61680+{
61681+ __u32 mode;
61682+
61683+ if (unlikely(!dentry->d_inode))
61684+ return GR_FIND;
61685+
61686+ mode =
61687+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
61688+
61689+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
61690+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61691+ return mode;
61692+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
61693+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61694+ return 0;
61695+ } else if (unlikely(!(mode & GR_FIND)))
61696+ return 0;
61697+
61698+ return GR_FIND;
61699+}
61700+
61701+__u32
61702+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
61703+ int acc_mode)
61704+{
61705+ __u32 reqmode = GR_FIND;
61706+ __u32 mode;
61707+
61708+ if (unlikely(!dentry->d_inode))
61709+ return reqmode;
61710+
61711+ if (acc_mode & MAY_APPEND)
61712+ reqmode |= GR_APPEND;
61713+ else if (acc_mode & MAY_WRITE)
61714+ reqmode |= GR_WRITE;
61715+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
61716+ reqmode |= GR_READ;
61717+
61718+ mode =
61719+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
61720+ mnt);
61721+
61722+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61723+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61724+ reqmode & GR_READ ? " reading" : "",
61725+ reqmode & GR_WRITE ? " writing" : reqmode &
61726+ GR_APPEND ? " appending" : "");
61727+ return reqmode;
61728+ } else
61729+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61730+ {
61731+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61732+ reqmode & GR_READ ? " reading" : "",
61733+ reqmode & GR_WRITE ? " writing" : reqmode &
61734+ GR_APPEND ? " appending" : "");
61735+ return 0;
61736+ } else if (unlikely((mode & reqmode) != reqmode))
61737+ return 0;
61738+
61739+ return reqmode;
61740+}
61741+
61742+__u32
61743+gr_acl_handle_creat(const struct dentry * dentry,
61744+ const struct dentry * p_dentry,
61745+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
61746+ const int imode)
61747+{
61748+ __u32 reqmode = GR_WRITE | GR_CREATE;
61749+ __u32 mode;
61750+
61751+ if (acc_mode & MAY_APPEND)
61752+ reqmode |= GR_APPEND;
61753+ // if a directory was required or the directory already exists, then
61754+ // don't count this open as a read
61755+ if ((acc_mode & MAY_READ) &&
61756+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
61757+ reqmode |= GR_READ;
61758+ if ((open_flags & O_CREAT) &&
61759+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
61760+ reqmode |= GR_SETID;
61761+
61762+ mode =
61763+ gr_check_create(dentry, p_dentry, p_mnt,
61764+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
61765+
61766+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61767+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
61768+ reqmode & GR_READ ? " reading" : "",
61769+ reqmode & GR_WRITE ? " writing" : reqmode &
61770+ GR_APPEND ? " appending" : "");
61771+ return reqmode;
61772+ } else
61773+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61774+ {
61775+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
61776+ reqmode & GR_READ ? " reading" : "",
61777+ reqmode & GR_WRITE ? " writing" : reqmode &
61778+ GR_APPEND ? " appending" : "");
61779+ return 0;
61780+ } else if (unlikely((mode & reqmode) != reqmode))
61781+ return 0;
61782+
61783+ return reqmode;
61784+}
61785+
61786+__u32
61787+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
61788+ const int fmode)
61789+{
61790+ __u32 mode, reqmode = GR_FIND;
61791+
61792+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
61793+ reqmode |= GR_EXEC;
61794+ if (fmode & S_IWOTH)
61795+ reqmode |= GR_WRITE;
61796+ if (fmode & S_IROTH)
61797+ reqmode |= GR_READ;
61798+
61799+ mode =
61800+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
61801+ mnt);
61802+
61803+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61804+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61805+ reqmode & GR_READ ? " reading" : "",
61806+ reqmode & GR_WRITE ? " writing" : "",
61807+ reqmode & GR_EXEC ? " executing" : "");
61808+ return reqmode;
61809+ } else
61810+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61811+ {
61812+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61813+ reqmode & GR_READ ? " reading" : "",
61814+ reqmode & GR_WRITE ? " writing" : "",
61815+ reqmode & GR_EXEC ? " executing" : "");
61816+ return 0;
61817+ } else if (unlikely((mode & reqmode) != reqmode))
61818+ return 0;
61819+
61820+ return reqmode;
61821+}
61822+
61823+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
61824+{
61825+ __u32 mode;
61826+
61827+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
61828+
61829+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61830+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
61831+ return mode;
61832+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61833+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
61834+ return 0;
61835+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
61836+ return 0;
61837+
61838+ return (reqmode);
61839+}
61840+
61841+__u32
61842+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
61843+{
61844+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
61845+}
61846+
61847+__u32
61848+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
61849+{
61850+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
61851+}
61852+
61853+__u32
61854+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
61855+{
61856+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
61857+}
61858+
61859+__u32
61860+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
61861+{
61862+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
61863+}
61864+
61865+__u32
61866+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
61867+ umode_t *modeptr)
61868+{
61869+ umode_t mode;
61870+
61871+ *modeptr &= ~gr_acl_umask();
61872+ mode = *modeptr;
61873+
61874+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
61875+ return 1;
61876+
61877+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
61878+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
61879+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
61880+ GR_CHMOD_ACL_MSG);
61881+ } else {
61882+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
61883+ }
61884+}
61885+
61886+__u32
61887+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
61888+{
61889+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
61890+}
61891+
61892+__u32
61893+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
61894+{
61895+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
61896+}
61897+
61898+__u32
61899+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
61900+{
61901+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
61902+}
61903+
61904+__u32
61905+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
61906+{
61907+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
61908+ GR_UNIXCONNECT_ACL_MSG);
61909+}
61910+
61911+/* hardlinks require at minimum create and link permission,
61912+ any additional privilege required is based on the
61913+ privilege of the file being linked to
61914+*/
61915+__u32
61916+gr_acl_handle_link(const struct dentry * new_dentry,
61917+ const struct dentry * parent_dentry,
61918+ const struct vfsmount * parent_mnt,
61919+ const struct dentry * old_dentry,
61920+ const struct vfsmount * old_mnt, const struct filename *to)
61921+{
61922+ __u32 mode;
61923+ __u32 needmode = GR_CREATE | GR_LINK;
61924+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
61925+
61926+ mode =
61927+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
61928+ old_mnt);
61929+
61930+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
61931+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61932+ return mode;
61933+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61934+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61935+ return 0;
61936+ } else if (unlikely((mode & needmode) != needmode))
61937+ return 0;
61938+
61939+ return 1;
61940+}
61941+
61942+__u32
61943+gr_acl_handle_symlink(const struct dentry * new_dentry,
61944+ const struct dentry * parent_dentry,
61945+ const struct vfsmount * parent_mnt, const struct filename *from)
61946+{
61947+ __u32 needmode = GR_WRITE | GR_CREATE;
61948+ __u32 mode;
61949+
61950+ mode =
61951+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
61952+ GR_CREATE | GR_AUDIT_CREATE |
61953+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
61954+
61955+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
61956+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61957+ return mode;
61958+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61959+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61960+ return 0;
61961+ } else if (unlikely((mode & needmode) != needmode))
61962+ return 0;
61963+
61964+ return (GR_WRITE | GR_CREATE);
61965+}
61966+
61967+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)
61968+{
61969+ __u32 mode;
61970+
61971+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
61972+
61973+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61974+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
61975+ return mode;
61976+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61977+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
61978+ return 0;
61979+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
61980+ return 0;
61981+
61982+ return (reqmode);
61983+}
61984+
61985+__u32
61986+gr_acl_handle_mknod(const struct dentry * new_dentry,
61987+ const struct dentry * parent_dentry,
61988+ const struct vfsmount * parent_mnt,
61989+ const int mode)
61990+{
61991+ __u32 reqmode = GR_WRITE | GR_CREATE;
61992+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
61993+ reqmode |= GR_SETID;
61994+
61995+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
61996+ reqmode, GR_MKNOD_ACL_MSG);
61997+}
61998+
61999+__u32
62000+gr_acl_handle_mkdir(const struct dentry *new_dentry,
62001+ const struct dentry *parent_dentry,
62002+ const struct vfsmount *parent_mnt)
62003+{
62004+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62005+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
62006+}
62007+
62008+#define RENAME_CHECK_SUCCESS(old, new) \
62009+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
62010+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
62011+
62012+int
62013+gr_acl_handle_rename(struct dentry *new_dentry,
62014+ struct dentry *parent_dentry,
62015+ const struct vfsmount *parent_mnt,
62016+ struct dentry *old_dentry,
62017+ struct inode *old_parent_inode,
62018+ struct vfsmount *old_mnt, const struct filename *newname)
62019+{
62020+ __u32 comp1, comp2;
62021+ int error = 0;
62022+
62023+ if (unlikely(!gr_acl_is_enabled()))
62024+ return 0;
62025+
62026+ if (!new_dentry->d_inode) {
62027+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
62028+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
62029+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
62030+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
62031+ GR_DELETE | GR_AUDIT_DELETE |
62032+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62033+ GR_SUPPRESS, old_mnt);
62034+ } else {
62035+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
62036+ GR_CREATE | GR_DELETE |
62037+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
62038+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62039+ GR_SUPPRESS, parent_mnt);
62040+ comp2 =
62041+ gr_search_file(old_dentry,
62042+ GR_READ | GR_WRITE | GR_AUDIT_READ |
62043+ GR_DELETE | GR_AUDIT_DELETE |
62044+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
62045+ }
62046+
62047+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
62048+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
62049+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62050+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
62051+ && !(comp2 & GR_SUPPRESS)) {
62052+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62053+ error = -EACCES;
62054+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
62055+ error = -EACCES;
62056+
62057+ return error;
62058+}
62059+
62060+void
62061+gr_acl_handle_exit(void)
62062+{
62063+ u16 id;
62064+ char *rolename;
62065+
62066+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
62067+ !(current->role->roletype & GR_ROLE_PERSIST))) {
62068+ id = current->acl_role_id;
62069+ rolename = current->role->rolename;
62070+ gr_set_acls(1);
62071+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
62072+ }
62073+
62074+ gr_put_exec_file(current);
62075+ return;
62076+}
62077+
62078+int
62079+gr_acl_handle_procpidmem(const struct task_struct *task)
62080+{
62081+ if (unlikely(!gr_acl_is_enabled()))
62082+ return 0;
62083+
62084+ if (task != current && task->acl->mode & GR_PROTPROCFD)
62085+ return -EACCES;
62086+
62087+ return 0;
62088+}
62089diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
62090new file mode 100644
62091index 0000000..4699807
62092--- /dev/null
62093+++ b/grsecurity/gracl_ip.c
62094@@ -0,0 +1,384 @@
62095+#include <linux/kernel.h>
62096+#include <asm/uaccess.h>
62097+#include <asm/errno.h>
62098+#include <net/sock.h>
62099+#include <linux/file.h>
62100+#include <linux/fs.h>
62101+#include <linux/net.h>
62102+#include <linux/in.h>
62103+#include <linux/skbuff.h>
62104+#include <linux/ip.h>
62105+#include <linux/udp.h>
62106+#include <linux/types.h>
62107+#include <linux/sched.h>
62108+#include <linux/netdevice.h>
62109+#include <linux/inetdevice.h>
62110+#include <linux/gracl.h>
62111+#include <linux/grsecurity.h>
62112+#include <linux/grinternal.h>
62113+
62114+#define GR_BIND 0x01
62115+#define GR_CONNECT 0x02
62116+#define GR_INVERT 0x04
62117+#define GR_BINDOVERRIDE 0x08
62118+#define GR_CONNECTOVERRIDE 0x10
62119+#define GR_SOCK_FAMILY 0x20
62120+
62121+static const char * gr_protocols[IPPROTO_MAX] = {
62122+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
62123+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
62124+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
62125+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
62126+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
62127+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
62128+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
62129+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
62130+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
62131+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
62132+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
62133+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
62134+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
62135+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
62136+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
62137+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
62138+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
62139+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
62140+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
62141+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
62142+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
62143+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
62144+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
62145+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
62146+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
62147+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
62148+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
62149+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
62150+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
62151+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
62152+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
62153+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
62154+ };
62155+
62156+static const char * gr_socktypes[SOCK_MAX] = {
62157+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
62158+ "unknown:7", "unknown:8", "unknown:9", "packet"
62159+ };
62160+
62161+static const char * gr_sockfamilies[AF_MAX+1] = {
62162+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
62163+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
62164+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
62165+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
62166+ };
62167+
62168+const char *
62169+gr_proto_to_name(unsigned char proto)
62170+{
62171+ return gr_protocols[proto];
62172+}
62173+
62174+const char *
62175+gr_socktype_to_name(unsigned char type)
62176+{
62177+ return gr_socktypes[type];
62178+}
62179+
62180+const char *
62181+gr_sockfamily_to_name(unsigned char family)
62182+{
62183+ return gr_sockfamilies[family];
62184+}
62185+
62186+int
62187+gr_search_socket(const int domain, const int type, const int protocol)
62188+{
62189+ struct acl_subject_label *curr;
62190+ const struct cred *cred = current_cred();
62191+
62192+ if (unlikely(!gr_acl_is_enabled()))
62193+ goto exit;
62194+
62195+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
62196+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
62197+ goto exit; // let the kernel handle it
62198+
62199+ curr = current->acl;
62200+
62201+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
62202+ /* the family is allowed, if this is PF_INET allow it only if
62203+ the extra sock type/protocol checks pass */
62204+ if (domain == PF_INET)
62205+ goto inet_check;
62206+ goto exit;
62207+ } else {
62208+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62209+ __u32 fakeip = 0;
62210+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62211+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62212+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62213+ gr_to_filename(current->exec_file->f_path.dentry,
62214+ current->exec_file->f_path.mnt) :
62215+ curr->filename, curr->filename,
62216+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
62217+ &current->signal->saved_ip);
62218+ goto exit;
62219+ }
62220+ goto exit_fail;
62221+ }
62222+
62223+inet_check:
62224+ /* the rest of this checking is for IPv4 only */
62225+ if (!curr->ips)
62226+ goto exit;
62227+
62228+ if ((curr->ip_type & (1 << type)) &&
62229+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
62230+ goto exit;
62231+
62232+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62233+ /* we don't place acls on raw sockets , and sometimes
62234+ dgram/ip sockets are opened for ioctl and not
62235+ bind/connect, so we'll fake a bind learn log */
62236+ if (type == SOCK_RAW || type == SOCK_PACKET) {
62237+ __u32 fakeip = 0;
62238+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62239+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62240+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62241+ gr_to_filename(current->exec_file->f_path.dentry,
62242+ current->exec_file->f_path.mnt) :
62243+ curr->filename, curr->filename,
62244+ &fakeip, 0, type,
62245+ protocol, GR_CONNECT, &current->signal->saved_ip);
62246+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
62247+ __u32 fakeip = 0;
62248+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62249+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62250+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62251+ gr_to_filename(current->exec_file->f_path.dentry,
62252+ current->exec_file->f_path.mnt) :
62253+ curr->filename, curr->filename,
62254+ &fakeip, 0, type,
62255+ protocol, GR_BIND, &current->signal->saved_ip);
62256+ }
62257+ /* we'll log when they use connect or bind */
62258+ goto exit;
62259+ }
62260+
62261+exit_fail:
62262+ if (domain == PF_INET)
62263+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
62264+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
62265+ else
62266+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
62267+ gr_socktype_to_name(type), protocol);
62268+
62269+ return 0;
62270+exit:
62271+ return 1;
62272+}
62273+
62274+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)
62275+{
62276+ if ((ip->mode & mode) &&
62277+ (ip_port >= ip->low) &&
62278+ (ip_port <= ip->high) &&
62279+ ((ntohl(ip_addr) & our_netmask) ==
62280+ (ntohl(our_addr) & our_netmask))
62281+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
62282+ && (ip->type & (1 << type))) {
62283+ if (ip->mode & GR_INVERT)
62284+ return 2; // specifically denied
62285+ else
62286+ return 1; // allowed
62287+ }
62288+
62289+ return 0; // not specifically allowed, may continue parsing
62290+}
62291+
62292+static int
62293+gr_search_connectbind(const int full_mode, struct sock *sk,
62294+ struct sockaddr_in *addr, const int type)
62295+{
62296+ char iface[IFNAMSIZ] = {0};
62297+ struct acl_subject_label *curr;
62298+ struct acl_ip_label *ip;
62299+ struct inet_sock *isk;
62300+ struct net_device *dev;
62301+ struct in_device *idev;
62302+ unsigned long i;
62303+ int ret;
62304+ int mode = full_mode & (GR_BIND | GR_CONNECT);
62305+ __u32 ip_addr = 0;
62306+ __u32 our_addr;
62307+ __u32 our_netmask;
62308+ char *p;
62309+ __u16 ip_port = 0;
62310+ const struct cred *cred = current_cred();
62311+
62312+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
62313+ return 0;
62314+
62315+ curr = current->acl;
62316+ isk = inet_sk(sk);
62317+
62318+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
62319+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
62320+ addr->sin_addr.s_addr = curr->inaddr_any_override;
62321+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
62322+ struct sockaddr_in saddr;
62323+ int err;
62324+
62325+ saddr.sin_family = AF_INET;
62326+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
62327+ saddr.sin_port = isk->inet_sport;
62328+
62329+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
62330+ if (err)
62331+ return err;
62332+
62333+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
62334+ if (err)
62335+ return err;
62336+ }
62337+
62338+ if (!curr->ips)
62339+ return 0;
62340+
62341+ ip_addr = addr->sin_addr.s_addr;
62342+ ip_port = ntohs(addr->sin_port);
62343+
62344+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62345+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62346+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62347+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62348+ gr_to_filename(current->exec_file->f_path.dentry,
62349+ current->exec_file->f_path.mnt) :
62350+ curr->filename, curr->filename,
62351+ &ip_addr, ip_port, type,
62352+ sk->sk_protocol, mode, &current->signal->saved_ip);
62353+ return 0;
62354+ }
62355+
62356+ for (i = 0; i < curr->ip_num; i++) {
62357+ ip = *(curr->ips + i);
62358+ if (ip->iface != NULL) {
62359+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
62360+ p = strchr(iface, ':');
62361+ if (p != NULL)
62362+ *p = '\0';
62363+ dev = dev_get_by_name(sock_net(sk), iface);
62364+ if (dev == NULL)
62365+ continue;
62366+ idev = in_dev_get(dev);
62367+ if (idev == NULL) {
62368+ dev_put(dev);
62369+ continue;
62370+ }
62371+ rcu_read_lock();
62372+ for_ifa(idev) {
62373+ if (!strcmp(ip->iface, ifa->ifa_label)) {
62374+ our_addr = ifa->ifa_address;
62375+ our_netmask = 0xffffffff;
62376+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
62377+ if (ret == 1) {
62378+ rcu_read_unlock();
62379+ in_dev_put(idev);
62380+ dev_put(dev);
62381+ return 0;
62382+ } else if (ret == 2) {
62383+ rcu_read_unlock();
62384+ in_dev_put(idev);
62385+ dev_put(dev);
62386+ goto denied;
62387+ }
62388+ }
62389+ } endfor_ifa(idev);
62390+ rcu_read_unlock();
62391+ in_dev_put(idev);
62392+ dev_put(dev);
62393+ } else {
62394+ our_addr = ip->addr;
62395+ our_netmask = ip->netmask;
62396+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
62397+ if (ret == 1)
62398+ return 0;
62399+ else if (ret == 2)
62400+ goto denied;
62401+ }
62402+ }
62403+
62404+denied:
62405+ if (mode == GR_BIND)
62406+ 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));
62407+ else if (mode == GR_CONNECT)
62408+ 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));
62409+
62410+ return -EACCES;
62411+}
62412+
62413+int
62414+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
62415+{
62416+ /* always allow disconnection of dgram sockets with connect */
62417+ if (addr->sin_family == AF_UNSPEC)
62418+ return 0;
62419+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
62420+}
62421+
62422+int
62423+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
62424+{
62425+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
62426+}
62427+
62428+int gr_search_listen(struct socket *sock)
62429+{
62430+ struct sock *sk = sock->sk;
62431+ struct sockaddr_in addr;
62432+
62433+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
62434+ addr.sin_port = inet_sk(sk)->inet_sport;
62435+
62436+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
62437+}
62438+
62439+int gr_search_accept(struct socket *sock)
62440+{
62441+ struct sock *sk = sock->sk;
62442+ struct sockaddr_in addr;
62443+
62444+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
62445+ addr.sin_port = inet_sk(sk)->inet_sport;
62446+
62447+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
62448+}
62449+
62450+int
62451+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
62452+{
62453+ if (addr)
62454+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
62455+ else {
62456+ struct sockaddr_in sin;
62457+ const struct inet_sock *inet = inet_sk(sk);
62458+
62459+ sin.sin_addr.s_addr = inet->inet_daddr;
62460+ sin.sin_port = inet->inet_dport;
62461+
62462+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
62463+ }
62464+}
62465+
62466+int
62467+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
62468+{
62469+ struct sockaddr_in sin;
62470+
62471+ if (unlikely(skb->len < sizeof (struct udphdr)))
62472+ return 0; // skip this packet
62473+
62474+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
62475+ sin.sin_port = udp_hdr(skb)->source;
62476+
62477+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
62478+}
62479diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
62480new file mode 100644
62481index 0000000..25f54ef
62482--- /dev/null
62483+++ b/grsecurity/gracl_learn.c
62484@@ -0,0 +1,207 @@
62485+#include <linux/kernel.h>
62486+#include <linux/mm.h>
62487+#include <linux/sched.h>
62488+#include <linux/poll.h>
62489+#include <linux/string.h>
62490+#include <linux/file.h>
62491+#include <linux/types.h>
62492+#include <linux/vmalloc.h>
62493+#include <linux/grinternal.h>
62494+
62495+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
62496+ size_t count, loff_t *ppos);
62497+extern int gr_acl_is_enabled(void);
62498+
62499+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
62500+static int gr_learn_attached;
62501+
62502+/* use a 512k buffer */
62503+#define LEARN_BUFFER_SIZE (512 * 1024)
62504+
62505+static DEFINE_SPINLOCK(gr_learn_lock);
62506+static DEFINE_MUTEX(gr_learn_user_mutex);
62507+
62508+/* we need to maintain two buffers, so that the kernel context of grlearn
62509+ uses a semaphore around the userspace copying, and the other kernel contexts
62510+ use a spinlock when copying into the buffer, since they cannot sleep
62511+*/
62512+static char *learn_buffer;
62513+static char *learn_buffer_user;
62514+static int learn_buffer_len;
62515+static int learn_buffer_user_len;
62516+
62517+static ssize_t
62518+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
62519+{
62520+ DECLARE_WAITQUEUE(wait, current);
62521+ ssize_t retval = 0;
62522+
62523+ add_wait_queue(&learn_wait, &wait);
62524+ set_current_state(TASK_INTERRUPTIBLE);
62525+ do {
62526+ mutex_lock(&gr_learn_user_mutex);
62527+ spin_lock(&gr_learn_lock);
62528+ if (learn_buffer_len)
62529+ break;
62530+ spin_unlock(&gr_learn_lock);
62531+ mutex_unlock(&gr_learn_user_mutex);
62532+ if (file->f_flags & O_NONBLOCK) {
62533+ retval = -EAGAIN;
62534+ goto out;
62535+ }
62536+ if (signal_pending(current)) {
62537+ retval = -ERESTARTSYS;
62538+ goto out;
62539+ }
62540+
62541+ schedule();
62542+ } while (1);
62543+
62544+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
62545+ learn_buffer_user_len = learn_buffer_len;
62546+ retval = learn_buffer_len;
62547+ learn_buffer_len = 0;
62548+
62549+ spin_unlock(&gr_learn_lock);
62550+
62551+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
62552+ retval = -EFAULT;
62553+
62554+ mutex_unlock(&gr_learn_user_mutex);
62555+out:
62556+ set_current_state(TASK_RUNNING);
62557+ remove_wait_queue(&learn_wait, &wait);
62558+ return retval;
62559+}
62560+
62561+static unsigned int
62562+poll_learn(struct file * file, poll_table * wait)
62563+{
62564+ poll_wait(file, &learn_wait, wait);
62565+
62566+ if (learn_buffer_len)
62567+ return (POLLIN | POLLRDNORM);
62568+
62569+ return 0;
62570+}
62571+
62572+void
62573+gr_clear_learn_entries(void)
62574+{
62575+ char *tmp;
62576+
62577+ mutex_lock(&gr_learn_user_mutex);
62578+ spin_lock(&gr_learn_lock);
62579+ tmp = learn_buffer;
62580+ learn_buffer = NULL;
62581+ spin_unlock(&gr_learn_lock);
62582+ if (tmp)
62583+ vfree(tmp);
62584+ if (learn_buffer_user != NULL) {
62585+ vfree(learn_buffer_user);
62586+ learn_buffer_user = NULL;
62587+ }
62588+ learn_buffer_len = 0;
62589+ mutex_unlock(&gr_learn_user_mutex);
62590+
62591+ return;
62592+}
62593+
62594+void
62595+gr_add_learn_entry(const char *fmt, ...)
62596+{
62597+ va_list args;
62598+ unsigned int len;
62599+
62600+ if (!gr_learn_attached)
62601+ return;
62602+
62603+ spin_lock(&gr_learn_lock);
62604+
62605+ /* leave a gap at the end so we know when it's "full" but don't have to
62606+ compute the exact length of the string we're trying to append
62607+ */
62608+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
62609+ spin_unlock(&gr_learn_lock);
62610+ wake_up_interruptible(&learn_wait);
62611+ return;
62612+ }
62613+ if (learn_buffer == NULL) {
62614+ spin_unlock(&gr_learn_lock);
62615+ return;
62616+ }
62617+
62618+ va_start(args, fmt);
62619+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
62620+ va_end(args);
62621+
62622+ learn_buffer_len += len + 1;
62623+
62624+ spin_unlock(&gr_learn_lock);
62625+ wake_up_interruptible(&learn_wait);
62626+
62627+ return;
62628+}
62629+
62630+static int
62631+open_learn(struct inode *inode, struct file *file)
62632+{
62633+ if (file->f_mode & FMODE_READ && gr_learn_attached)
62634+ return -EBUSY;
62635+ if (file->f_mode & FMODE_READ) {
62636+ int retval = 0;
62637+ mutex_lock(&gr_learn_user_mutex);
62638+ if (learn_buffer == NULL)
62639+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
62640+ if (learn_buffer_user == NULL)
62641+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
62642+ if (learn_buffer == NULL) {
62643+ retval = -ENOMEM;
62644+ goto out_error;
62645+ }
62646+ if (learn_buffer_user == NULL) {
62647+ retval = -ENOMEM;
62648+ goto out_error;
62649+ }
62650+ learn_buffer_len = 0;
62651+ learn_buffer_user_len = 0;
62652+ gr_learn_attached = 1;
62653+out_error:
62654+ mutex_unlock(&gr_learn_user_mutex);
62655+ return retval;
62656+ }
62657+ return 0;
62658+}
62659+
62660+static int
62661+close_learn(struct inode *inode, struct file *file)
62662+{
62663+ if (file->f_mode & FMODE_READ) {
62664+ char *tmp = NULL;
62665+ mutex_lock(&gr_learn_user_mutex);
62666+ spin_lock(&gr_learn_lock);
62667+ tmp = learn_buffer;
62668+ learn_buffer = NULL;
62669+ spin_unlock(&gr_learn_lock);
62670+ if (tmp)
62671+ vfree(tmp);
62672+ if (learn_buffer_user != NULL) {
62673+ vfree(learn_buffer_user);
62674+ learn_buffer_user = NULL;
62675+ }
62676+ learn_buffer_len = 0;
62677+ learn_buffer_user_len = 0;
62678+ gr_learn_attached = 0;
62679+ mutex_unlock(&gr_learn_user_mutex);
62680+ }
62681+
62682+ return 0;
62683+}
62684+
62685+const struct file_operations grsec_fops = {
62686+ .read = read_learn,
62687+ .write = write_grsec_handler,
62688+ .open = open_learn,
62689+ .release = close_learn,
62690+ .poll = poll_learn,
62691+};
62692diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
62693new file mode 100644
62694index 0000000..39645c9
62695--- /dev/null
62696+++ b/grsecurity/gracl_res.c
62697@@ -0,0 +1,68 @@
62698+#include <linux/kernel.h>
62699+#include <linux/sched.h>
62700+#include <linux/gracl.h>
62701+#include <linux/grinternal.h>
62702+
62703+static const char *restab_log[] = {
62704+ [RLIMIT_CPU] = "RLIMIT_CPU",
62705+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
62706+ [RLIMIT_DATA] = "RLIMIT_DATA",
62707+ [RLIMIT_STACK] = "RLIMIT_STACK",
62708+ [RLIMIT_CORE] = "RLIMIT_CORE",
62709+ [RLIMIT_RSS] = "RLIMIT_RSS",
62710+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
62711+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
62712+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
62713+ [RLIMIT_AS] = "RLIMIT_AS",
62714+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
62715+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
62716+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
62717+ [RLIMIT_NICE] = "RLIMIT_NICE",
62718+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
62719+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
62720+ [GR_CRASH_RES] = "RLIMIT_CRASH"
62721+};
62722+
62723+void
62724+gr_log_resource(const struct task_struct *task,
62725+ const int res, const unsigned long wanted, const int gt)
62726+{
62727+ const struct cred *cred;
62728+ unsigned long rlim;
62729+
62730+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
62731+ return;
62732+
62733+ // not yet supported resource
62734+ if (unlikely(!restab_log[res]))
62735+ return;
62736+
62737+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
62738+ rlim = task_rlimit_max(task, res);
62739+ else
62740+ rlim = task_rlimit(task, res);
62741+
62742+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
62743+ return;
62744+
62745+ rcu_read_lock();
62746+ cred = __task_cred(task);
62747+
62748+ if (res == RLIMIT_NPROC &&
62749+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
62750+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
62751+ goto out_rcu_unlock;
62752+ else if (res == RLIMIT_MEMLOCK &&
62753+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
62754+ goto out_rcu_unlock;
62755+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
62756+ goto out_rcu_unlock;
62757+ rcu_read_unlock();
62758+
62759+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
62760+
62761+ return;
62762+out_rcu_unlock:
62763+ rcu_read_unlock();
62764+ return;
62765+}
62766diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
62767new file mode 100644
62768index 0000000..8c8fc9d
62769--- /dev/null
62770+++ b/grsecurity/gracl_segv.c
62771@@ -0,0 +1,303 @@
62772+#include <linux/kernel.h>
62773+#include <linux/mm.h>
62774+#include <asm/uaccess.h>
62775+#include <asm/errno.h>
62776+#include <asm/mman.h>
62777+#include <net/sock.h>
62778+#include <linux/file.h>
62779+#include <linux/fs.h>
62780+#include <linux/net.h>
62781+#include <linux/in.h>
62782+#include <linux/slab.h>
62783+#include <linux/types.h>
62784+#include <linux/sched.h>
62785+#include <linux/timer.h>
62786+#include <linux/gracl.h>
62787+#include <linux/grsecurity.h>
62788+#include <linux/grinternal.h>
62789+
62790+static struct crash_uid *uid_set;
62791+static unsigned short uid_used;
62792+static DEFINE_SPINLOCK(gr_uid_lock);
62793+extern rwlock_t gr_inode_lock;
62794+extern struct acl_subject_label *
62795+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
62796+ struct acl_role_label *role);
62797+
62798+#ifdef CONFIG_BTRFS_FS
62799+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
62800+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
62801+#endif
62802+
62803+static inline dev_t __get_dev(const struct dentry *dentry)
62804+{
62805+#ifdef CONFIG_BTRFS_FS
62806+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
62807+ return get_btrfs_dev_from_inode(dentry->d_inode);
62808+ else
62809+#endif
62810+ return dentry->d_inode->i_sb->s_dev;
62811+}
62812+
62813+int
62814+gr_init_uidset(void)
62815+{
62816+ uid_set =
62817+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
62818+ uid_used = 0;
62819+
62820+ return uid_set ? 1 : 0;
62821+}
62822+
62823+void
62824+gr_free_uidset(void)
62825+{
62826+ if (uid_set)
62827+ kfree(uid_set);
62828+
62829+ return;
62830+}
62831+
62832+int
62833+gr_find_uid(const uid_t uid)
62834+{
62835+ struct crash_uid *tmp = uid_set;
62836+ uid_t buid;
62837+ int low = 0, high = uid_used - 1, mid;
62838+
62839+ while (high >= low) {
62840+ mid = (low + high) >> 1;
62841+ buid = tmp[mid].uid;
62842+ if (buid == uid)
62843+ return mid;
62844+ if (buid > uid)
62845+ high = mid - 1;
62846+ if (buid < uid)
62847+ low = mid + 1;
62848+ }
62849+
62850+ return -1;
62851+}
62852+
62853+static __inline__ void
62854+gr_insertsort(void)
62855+{
62856+ unsigned short i, j;
62857+ struct crash_uid index;
62858+
62859+ for (i = 1; i < uid_used; i++) {
62860+ index = uid_set[i];
62861+ j = i;
62862+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
62863+ uid_set[j] = uid_set[j - 1];
62864+ j--;
62865+ }
62866+ uid_set[j] = index;
62867+ }
62868+
62869+ return;
62870+}
62871+
62872+static __inline__ void
62873+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
62874+{
62875+ int loc;
62876+ uid_t uid = GR_GLOBAL_UID(kuid);
62877+
62878+ if (uid_used == GR_UIDTABLE_MAX)
62879+ return;
62880+
62881+ loc = gr_find_uid(uid);
62882+
62883+ if (loc >= 0) {
62884+ uid_set[loc].expires = expires;
62885+ return;
62886+ }
62887+
62888+ uid_set[uid_used].uid = uid;
62889+ uid_set[uid_used].expires = expires;
62890+ uid_used++;
62891+
62892+ gr_insertsort();
62893+
62894+ return;
62895+}
62896+
62897+void
62898+gr_remove_uid(const unsigned short loc)
62899+{
62900+ unsigned short i;
62901+
62902+ for (i = loc + 1; i < uid_used; i++)
62903+ uid_set[i - 1] = uid_set[i];
62904+
62905+ uid_used--;
62906+
62907+ return;
62908+}
62909+
62910+int
62911+gr_check_crash_uid(const kuid_t kuid)
62912+{
62913+ int loc;
62914+ int ret = 0;
62915+ uid_t uid;
62916+
62917+ if (unlikely(!gr_acl_is_enabled()))
62918+ return 0;
62919+
62920+ uid = GR_GLOBAL_UID(kuid);
62921+
62922+ spin_lock(&gr_uid_lock);
62923+ loc = gr_find_uid(uid);
62924+
62925+ if (loc < 0)
62926+ goto out_unlock;
62927+
62928+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
62929+ gr_remove_uid(loc);
62930+ else
62931+ ret = 1;
62932+
62933+out_unlock:
62934+ spin_unlock(&gr_uid_lock);
62935+ return ret;
62936+}
62937+
62938+static __inline__ int
62939+proc_is_setxid(const struct cred *cred)
62940+{
62941+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
62942+ !uid_eq(cred->uid, cred->fsuid))
62943+ return 1;
62944+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
62945+ !gid_eq(cred->gid, cred->fsgid))
62946+ return 1;
62947+
62948+ return 0;
62949+}
62950+
62951+extern int gr_fake_force_sig(int sig, struct task_struct *t);
62952+
62953+void
62954+gr_handle_crash(struct task_struct *task, const int sig)
62955+{
62956+ struct acl_subject_label *curr;
62957+ struct task_struct *tsk, *tsk2;
62958+ const struct cred *cred;
62959+ const struct cred *cred2;
62960+
62961+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
62962+ return;
62963+
62964+ if (unlikely(!gr_acl_is_enabled()))
62965+ return;
62966+
62967+ curr = task->acl;
62968+
62969+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
62970+ return;
62971+
62972+ if (time_before_eq(curr->expires, get_seconds())) {
62973+ curr->expires = 0;
62974+ curr->crashes = 0;
62975+ }
62976+
62977+ curr->crashes++;
62978+
62979+ if (!curr->expires)
62980+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
62981+
62982+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
62983+ time_after(curr->expires, get_seconds())) {
62984+ rcu_read_lock();
62985+ cred = __task_cred(task);
62986+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
62987+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
62988+ spin_lock(&gr_uid_lock);
62989+ gr_insert_uid(cred->uid, curr->expires);
62990+ spin_unlock(&gr_uid_lock);
62991+ curr->expires = 0;
62992+ curr->crashes = 0;
62993+ read_lock(&tasklist_lock);
62994+ do_each_thread(tsk2, tsk) {
62995+ cred2 = __task_cred(tsk);
62996+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
62997+ gr_fake_force_sig(SIGKILL, tsk);
62998+ } while_each_thread(tsk2, tsk);
62999+ read_unlock(&tasklist_lock);
63000+ } else {
63001+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63002+ read_lock(&tasklist_lock);
63003+ read_lock(&grsec_exec_file_lock);
63004+ do_each_thread(tsk2, tsk) {
63005+ if (likely(tsk != task)) {
63006+ // if this thread has the same subject as the one that triggered
63007+ // RES_CRASH and it's the same binary, kill it
63008+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
63009+ gr_fake_force_sig(SIGKILL, tsk);
63010+ }
63011+ } while_each_thread(tsk2, tsk);
63012+ read_unlock(&grsec_exec_file_lock);
63013+ read_unlock(&tasklist_lock);
63014+ }
63015+ rcu_read_unlock();
63016+ }
63017+
63018+ return;
63019+}
63020+
63021+int
63022+gr_check_crash_exec(const struct file *filp)
63023+{
63024+ struct acl_subject_label *curr;
63025+
63026+ if (unlikely(!gr_acl_is_enabled()))
63027+ return 0;
63028+
63029+ read_lock(&gr_inode_lock);
63030+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
63031+ __get_dev(filp->f_path.dentry),
63032+ current->role);
63033+ read_unlock(&gr_inode_lock);
63034+
63035+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
63036+ (!curr->crashes && !curr->expires))
63037+ return 0;
63038+
63039+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63040+ time_after(curr->expires, get_seconds()))
63041+ return 1;
63042+ else if (time_before_eq(curr->expires, get_seconds())) {
63043+ curr->crashes = 0;
63044+ curr->expires = 0;
63045+ }
63046+
63047+ return 0;
63048+}
63049+
63050+void
63051+gr_handle_alertkill(struct task_struct *task)
63052+{
63053+ struct acl_subject_label *curracl;
63054+ __u32 curr_ip;
63055+ struct task_struct *p, *p2;
63056+
63057+ if (unlikely(!gr_acl_is_enabled()))
63058+ return;
63059+
63060+ curracl = task->acl;
63061+ curr_ip = task->signal->curr_ip;
63062+
63063+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
63064+ read_lock(&tasklist_lock);
63065+ do_each_thread(p2, p) {
63066+ if (p->signal->curr_ip == curr_ip)
63067+ gr_fake_force_sig(SIGKILL, p);
63068+ } while_each_thread(p2, p);
63069+ read_unlock(&tasklist_lock);
63070+ } else if (curracl->mode & GR_KILLPROC)
63071+ gr_fake_force_sig(SIGKILL, task);
63072+
63073+ return;
63074+}
63075diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
63076new file mode 100644
63077index 0000000..98011b0
63078--- /dev/null
63079+++ b/grsecurity/gracl_shm.c
63080@@ -0,0 +1,40 @@
63081+#include <linux/kernel.h>
63082+#include <linux/mm.h>
63083+#include <linux/sched.h>
63084+#include <linux/file.h>
63085+#include <linux/ipc.h>
63086+#include <linux/gracl.h>
63087+#include <linux/grsecurity.h>
63088+#include <linux/grinternal.h>
63089+
63090+int
63091+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63092+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
63093+{
63094+ struct task_struct *task;
63095+
63096+ if (!gr_acl_is_enabled())
63097+ return 1;
63098+
63099+ rcu_read_lock();
63100+ read_lock(&tasklist_lock);
63101+
63102+ task = find_task_by_vpid(shm_cprid);
63103+
63104+ if (unlikely(!task))
63105+ task = find_task_by_vpid(shm_lapid);
63106+
63107+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
63108+ (task_pid_nr(task) == shm_lapid)) &&
63109+ (task->acl->mode & GR_PROTSHM) &&
63110+ (task->acl != current->acl))) {
63111+ read_unlock(&tasklist_lock);
63112+ rcu_read_unlock();
63113+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
63114+ return 0;
63115+ }
63116+ read_unlock(&tasklist_lock);
63117+ rcu_read_unlock();
63118+
63119+ return 1;
63120+}
63121diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
63122new file mode 100644
63123index 0000000..bc0be01
63124--- /dev/null
63125+++ b/grsecurity/grsec_chdir.c
63126@@ -0,0 +1,19 @@
63127+#include <linux/kernel.h>
63128+#include <linux/sched.h>
63129+#include <linux/fs.h>
63130+#include <linux/file.h>
63131+#include <linux/grsecurity.h>
63132+#include <linux/grinternal.h>
63133+
63134+void
63135+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
63136+{
63137+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
63138+ if ((grsec_enable_chdir && grsec_enable_group &&
63139+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
63140+ !grsec_enable_group)) {
63141+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
63142+ }
63143+#endif
63144+ return;
63145+}
63146diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
63147new file mode 100644
63148index 0000000..6d2de57
63149--- /dev/null
63150+++ b/grsecurity/grsec_chroot.c
63151@@ -0,0 +1,357 @@
63152+#include <linux/kernel.h>
63153+#include <linux/module.h>
63154+#include <linux/sched.h>
63155+#include <linux/file.h>
63156+#include <linux/fs.h>
63157+#include <linux/mount.h>
63158+#include <linux/types.h>
63159+#include "../fs/mount.h"
63160+#include <linux/grsecurity.h>
63161+#include <linux/grinternal.h>
63162+
63163+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
63164+{
63165+#ifdef CONFIG_GRKERNSEC
63166+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
63167+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
63168+ task->gr_is_chrooted = 1;
63169+ else
63170+ task->gr_is_chrooted = 0;
63171+
63172+ task->gr_chroot_dentry = path->dentry;
63173+#endif
63174+ return;
63175+}
63176+
63177+void gr_clear_chroot_entries(struct task_struct *task)
63178+{
63179+#ifdef CONFIG_GRKERNSEC
63180+ task->gr_is_chrooted = 0;
63181+ task->gr_chroot_dentry = NULL;
63182+#endif
63183+ return;
63184+}
63185+
63186+int
63187+gr_handle_chroot_unix(const pid_t pid)
63188+{
63189+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
63190+ struct task_struct *p;
63191+
63192+ if (unlikely(!grsec_enable_chroot_unix))
63193+ return 1;
63194+
63195+ if (likely(!proc_is_chrooted(current)))
63196+ return 1;
63197+
63198+ rcu_read_lock();
63199+ read_lock(&tasklist_lock);
63200+ p = find_task_by_vpid_unrestricted(pid);
63201+ if (unlikely(p && !have_same_root(current, p))) {
63202+ read_unlock(&tasklist_lock);
63203+ rcu_read_unlock();
63204+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
63205+ return 0;
63206+ }
63207+ read_unlock(&tasklist_lock);
63208+ rcu_read_unlock();
63209+#endif
63210+ return 1;
63211+}
63212+
63213+int
63214+gr_handle_chroot_nice(void)
63215+{
63216+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63217+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
63218+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
63219+ return -EPERM;
63220+ }
63221+#endif
63222+ return 0;
63223+}
63224+
63225+int
63226+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
63227+{
63228+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63229+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
63230+ && proc_is_chrooted(current)) {
63231+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
63232+ return -EACCES;
63233+ }
63234+#endif
63235+ return 0;
63236+}
63237+
63238+int
63239+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
63240+{
63241+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63242+ struct task_struct *p;
63243+ int ret = 0;
63244+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
63245+ return ret;
63246+
63247+ read_lock(&tasklist_lock);
63248+ do_each_pid_task(pid, type, p) {
63249+ if (!have_same_root(current, p)) {
63250+ ret = 1;
63251+ goto out;
63252+ }
63253+ } while_each_pid_task(pid, type, p);
63254+out:
63255+ read_unlock(&tasklist_lock);
63256+ return ret;
63257+#endif
63258+ return 0;
63259+}
63260+
63261+int
63262+gr_pid_is_chrooted(struct task_struct *p)
63263+{
63264+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63265+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
63266+ return 0;
63267+
63268+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
63269+ !have_same_root(current, p)) {
63270+ return 1;
63271+ }
63272+#endif
63273+ return 0;
63274+}
63275+
63276+EXPORT_SYMBOL(gr_pid_is_chrooted);
63277+
63278+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
63279+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
63280+{
63281+ struct path path, currentroot;
63282+ int ret = 0;
63283+
63284+ path.dentry = (struct dentry *)u_dentry;
63285+ path.mnt = (struct vfsmount *)u_mnt;
63286+ get_fs_root(current->fs, &currentroot);
63287+ if (path_is_under(&path, &currentroot))
63288+ ret = 1;
63289+ path_put(&currentroot);
63290+
63291+ return ret;
63292+}
63293+#endif
63294+
63295+int
63296+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
63297+{
63298+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
63299+ if (!grsec_enable_chroot_fchdir)
63300+ return 1;
63301+
63302+ if (!proc_is_chrooted(current))
63303+ return 1;
63304+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
63305+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
63306+ return 0;
63307+ }
63308+#endif
63309+ return 1;
63310+}
63311+
63312+int
63313+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63314+ const time_t shm_createtime)
63315+{
63316+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
63317+ struct task_struct *p;
63318+ time_t starttime;
63319+
63320+ if (unlikely(!grsec_enable_chroot_shmat))
63321+ return 1;
63322+
63323+ if (likely(!proc_is_chrooted(current)))
63324+ return 1;
63325+
63326+ rcu_read_lock();
63327+ read_lock(&tasklist_lock);
63328+
63329+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
63330+ starttime = p->start_time.tv_sec;
63331+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
63332+ if (have_same_root(current, p)) {
63333+ goto allow;
63334+ } else {
63335+ read_unlock(&tasklist_lock);
63336+ rcu_read_unlock();
63337+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
63338+ return 0;
63339+ }
63340+ }
63341+ /* creator exited, pid reuse, fall through to next check */
63342+ }
63343+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
63344+ if (unlikely(!have_same_root(current, p))) {
63345+ read_unlock(&tasklist_lock);
63346+ rcu_read_unlock();
63347+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
63348+ return 0;
63349+ }
63350+ }
63351+
63352+allow:
63353+ read_unlock(&tasklist_lock);
63354+ rcu_read_unlock();
63355+#endif
63356+ return 1;
63357+}
63358+
63359+void
63360+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
63361+{
63362+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
63363+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
63364+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
63365+#endif
63366+ return;
63367+}
63368+
63369+int
63370+gr_handle_chroot_mknod(const struct dentry *dentry,
63371+ const struct vfsmount *mnt, const int mode)
63372+{
63373+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
63374+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
63375+ proc_is_chrooted(current)) {
63376+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
63377+ return -EPERM;
63378+ }
63379+#endif
63380+ return 0;
63381+}
63382+
63383+int
63384+gr_handle_chroot_mount(const struct dentry *dentry,
63385+ const struct vfsmount *mnt, const char *dev_name)
63386+{
63387+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
63388+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
63389+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
63390+ return -EPERM;
63391+ }
63392+#endif
63393+ return 0;
63394+}
63395+
63396+int
63397+gr_handle_chroot_pivot(void)
63398+{
63399+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
63400+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
63401+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
63402+ return -EPERM;
63403+ }
63404+#endif
63405+ return 0;
63406+}
63407+
63408+int
63409+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
63410+{
63411+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
63412+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
63413+ !gr_is_outside_chroot(dentry, mnt)) {
63414+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
63415+ return -EPERM;
63416+ }
63417+#endif
63418+ return 0;
63419+}
63420+
63421+extern const char *captab_log[];
63422+extern int captab_log_entries;
63423+
63424+int
63425+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
63426+{
63427+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63428+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
63429+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
63430+ if (cap_raised(chroot_caps, cap)) {
63431+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
63432+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
63433+ }
63434+ return 0;
63435+ }
63436+ }
63437+#endif
63438+ return 1;
63439+}
63440+
63441+int
63442+gr_chroot_is_capable(const int cap)
63443+{
63444+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63445+ return gr_task_chroot_is_capable(current, current_cred(), cap);
63446+#endif
63447+ return 1;
63448+}
63449+
63450+int
63451+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
63452+{
63453+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63454+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
63455+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
63456+ if (cap_raised(chroot_caps, cap)) {
63457+ return 0;
63458+ }
63459+ }
63460+#endif
63461+ return 1;
63462+}
63463+
63464+int
63465+gr_chroot_is_capable_nolog(const int cap)
63466+{
63467+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63468+ return gr_task_chroot_is_capable_nolog(current, cap);
63469+#endif
63470+ return 1;
63471+}
63472+
63473+int
63474+gr_handle_chroot_sysctl(const int op)
63475+{
63476+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
63477+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
63478+ proc_is_chrooted(current))
63479+ return -EACCES;
63480+#endif
63481+ return 0;
63482+}
63483+
63484+void
63485+gr_handle_chroot_chdir(struct path *path)
63486+{
63487+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
63488+ if (grsec_enable_chroot_chdir)
63489+ set_fs_pwd(current->fs, path);
63490+#endif
63491+ return;
63492+}
63493+
63494+int
63495+gr_handle_chroot_chmod(const struct dentry *dentry,
63496+ const struct vfsmount *mnt, const int mode)
63497+{
63498+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
63499+ /* allow chmod +s on directories, but not files */
63500+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
63501+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
63502+ proc_is_chrooted(current)) {
63503+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
63504+ return -EPERM;
63505+ }
63506+#endif
63507+ return 0;
63508+}
63509diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
63510new file mode 100644
63511index 0000000..207d409
63512--- /dev/null
63513+++ b/grsecurity/grsec_disabled.c
63514@@ -0,0 +1,434 @@
63515+#include <linux/kernel.h>
63516+#include <linux/module.h>
63517+#include <linux/sched.h>
63518+#include <linux/file.h>
63519+#include <linux/fs.h>
63520+#include <linux/kdev_t.h>
63521+#include <linux/net.h>
63522+#include <linux/in.h>
63523+#include <linux/ip.h>
63524+#include <linux/skbuff.h>
63525+#include <linux/sysctl.h>
63526+
63527+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63528+void
63529+pax_set_initial_flags(struct linux_binprm *bprm)
63530+{
63531+ return;
63532+}
63533+#endif
63534+
63535+#ifdef CONFIG_SYSCTL
63536+__u32
63537+gr_handle_sysctl(const struct ctl_table * table, const int op)
63538+{
63539+ return 0;
63540+}
63541+#endif
63542+
63543+#ifdef CONFIG_TASKSTATS
63544+int gr_is_taskstats_denied(int pid)
63545+{
63546+ return 0;
63547+}
63548+#endif
63549+
63550+int
63551+gr_acl_is_enabled(void)
63552+{
63553+ return 0;
63554+}
63555+
63556+void
63557+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
63558+{
63559+ return;
63560+}
63561+
63562+int
63563+gr_handle_rawio(const struct inode *inode)
63564+{
63565+ return 0;
63566+}
63567+
63568+void
63569+gr_acl_handle_psacct(struct task_struct *task, const long code)
63570+{
63571+ return;
63572+}
63573+
63574+int
63575+gr_handle_ptrace(struct task_struct *task, const long request)
63576+{
63577+ return 0;
63578+}
63579+
63580+int
63581+gr_handle_proc_ptrace(struct task_struct *task)
63582+{
63583+ return 0;
63584+}
63585+
63586+int
63587+gr_set_acls(const int type)
63588+{
63589+ return 0;
63590+}
63591+
63592+int
63593+gr_check_hidden_task(const struct task_struct *tsk)
63594+{
63595+ return 0;
63596+}
63597+
63598+int
63599+gr_check_protected_task(const struct task_struct *task)
63600+{
63601+ return 0;
63602+}
63603+
63604+int
63605+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
63606+{
63607+ return 0;
63608+}
63609+
63610+void
63611+gr_copy_label(struct task_struct *tsk)
63612+{
63613+ return;
63614+}
63615+
63616+void
63617+gr_set_pax_flags(struct task_struct *task)
63618+{
63619+ return;
63620+}
63621+
63622+int
63623+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
63624+ const int unsafe_share)
63625+{
63626+ return 0;
63627+}
63628+
63629+void
63630+gr_handle_delete(const ino_t ino, const dev_t dev)
63631+{
63632+ return;
63633+}
63634+
63635+void
63636+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
63637+{
63638+ return;
63639+}
63640+
63641+void
63642+gr_handle_crash(struct task_struct *task, const int sig)
63643+{
63644+ return;
63645+}
63646+
63647+int
63648+gr_check_crash_exec(const struct file *filp)
63649+{
63650+ return 0;
63651+}
63652+
63653+int
63654+gr_check_crash_uid(const kuid_t uid)
63655+{
63656+ return 0;
63657+}
63658+
63659+void
63660+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63661+ struct dentry *old_dentry,
63662+ struct dentry *new_dentry,
63663+ struct vfsmount *mnt, const __u8 replace)
63664+{
63665+ return;
63666+}
63667+
63668+int
63669+gr_search_socket(const int family, const int type, const int protocol)
63670+{
63671+ return 1;
63672+}
63673+
63674+int
63675+gr_search_connectbind(const int mode, const struct socket *sock,
63676+ const struct sockaddr_in *addr)
63677+{
63678+ return 0;
63679+}
63680+
63681+void
63682+gr_handle_alertkill(struct task_struct *task)
63683+{
63684+ return;
63685+}
63686+
63687+__u32
63688+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
63689+{
63690+ return 1;
63691+}
63692+
63693+__u32
63694+gr_acl_handle_hidden_file(const struct dentry * dentry,
63695+ const struct vfsmount * mnt)
63696+{
63697+ return 1;
63698+}
63699+
63700+__u32
63701+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
63702+ int acc_mode)
63703+{
63704+ return 1;
63705+}
63706+
63707+__u32
63708+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
63709+{
63710+ return 1;
63711+}
63712+
63713+__u32
63714+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
63715+{
63716+ return 1;
63717+}
63718+
63719+int
63720+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
63721+ unsigned int *vm_flags)
63722+{
63723+ return 1;
63724+}
63725+
63726+__u32
63727+gr_acl_handle_truncate(const struct dentry * dentry,
63728+ const struct vfsmount * mnt)
63729+{
63730+ return 1;
63731+}
63732+
63733+__u32
63734+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
63735+{
63736+ return 1;
63737+}
63738+
63739+__u32
63740+gr_acl_handle_access(const struct dentry * dentry,
63741+ const struct vfsmount * mnt, const int fmode)
63742+{
63743+ return 1;
63744+}
63745+
63746+__u32
63747+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
63748+ umode_t *mode)
63749+{
63750+ return 1;
63751+}
63752+
63753+__u32
63754+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
63755+{
63756+ return 1;
63757+}
63758+
63759+__u32
63760+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
63761+{
63762+ return 1;
63763+}
63764+
63765+void
63766+grsecurity_init(void)
63767+{
63768+ return;
63769+}
63770+
63771+umode_t gr_acl_umask(void)
63772+{
63773+ return 0;
63774+}
63775+
63776+__u32
63777+gr_acl_handle_mknod(const struct dentry * new_dentry,
63778+ const struct dentry * parent_dentry,
63779+ const struct vfsmount * parent_mnt,
63780+ const int mode)
63781+{
63782+ return 1;
63783+}
63784+
63785+__u32
63786+gr_acl_handle_mkdir(const struct dentry * new_dentry,
63787+ const struct dentry * parent_dentry,
63788+ const struct vfsmount * parent_mnt)
63789+{
63790+ return 1;
63791+}
63792+
63793+__u32
63794+gr_acl_handle_symlink(const struct dentry * new_dentry,
63795+ const struct dentry * parent_dentry,
63796+ const struct vfsmount * parent_mnt, const struct filename *from)
63797+{
63798+ return 1;
63799+}
63800+
63801+__u32
63802+gr_acl_handle_link(const struct dentry * new_dentry,
63803+ const struct dentry * parent_dentry,
63804+ const struct vfsmount * parent_mnt,
63805+ const struct dentry * old_dentry,
63806+ const struct vfsmount * old_mnt, const struct filename *to)
63807+{
63808+ return 1;
63809+}
63810+
63811+int
63812+gr_acl_handle_rename(const struct dentry *new_dentry,
63813+ const struct dentry *parent_dentry,
63814+ const struct vfsmount *parent_mnt,
63815+ const struct dentry *old_dentry,
63816+ const struct inode *old_parent_inode,
63817+ const struct vfsmount *old_mnt, const struct filename *newname)
63818+{
63819+ return 0;
63820+}
63821+
63822+int
63823+gr_acl_handle_filldir(const struct file *file, const char *name,
63824+ const int namelen, const ino_t ino)
63825+{
63826+ return 1;
63827+}
63828+
63829+int
63830+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63831+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
63832+{
63833+ return 1;
63834+}
63835+
63836+int
63837+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
63838+{
63839+ return 0;
63840+}
63841+
63842+int
63843+gr_search_accept(const struct socket *sock)
63844+{
63845+ return 0;
63846+}
63847+
63848+int
63849+gr_search_listen(const struct socket *sock)
63850+{
63851+ return 0;
63852+}
63853+
63854+int
63855+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
63856+{
63857+ return 0;
63858+}
63859+
63860+__u32
63861+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
63862+{
63863+ return 1;
63864+}
63865+
63866+__u32
63867+gr_acl_handle_creat(const struct dentry * dentry,
63868+ const struct dentry * p_dentry,
63869+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
63870+ const int imode)
63871+{
63872+ return 1;
63873+}
63874+
63875+void
63876+gr_acl_handle_exit(void)
63877+{
63878+ return;
63879+}
63880+
63881+int
63882+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
63883+{
63884+ return 1;
63885+}
63886+
63887+void
63888+gr_set_role_label(const kuid_t uid, const kgid_t gid)
63889+{
63890+ return;
63891+}
63892+
63893+int
63894+gr_acl_handle_procpidmem(const struct task_struct *task)
63895+{
63896+ return 0;
63897+}
63898+
63899+int
63900+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
63901+{
63902+ return 0;
63903+}
63904+
63905+int
63906+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
63907+{
63908+ return 0;
63909+}
63910+
63911+void
63912+gr_set_kernel_label(struct task_struct *task)
63913+{
63914+ return;
63915+}
63916+
63917+int
63918+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
63919+{
63920+ return 0;
63921+}
63922+
63923+int
63924+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
63925+{
63926+ return 0;
63927+}
63928+
63929+int gr_acl_enable_at_secure(void)
63930+{
63931+ return 0;
63932+}
63933+
63934+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
63935+{
63936+ return dentry->d_inode->i_sb->s_dev;
63937+}
63938+
63939+void gr_put_exec_file(struct task_struct *task)
63940+{
63941+ return;
63942+}
63943+
63944+EXPORT_SYMBOL(gr_set_kernel_label);
63945+#ifdef CONFIG_SECURITY
63946+EXPORT_SYMBOL(gr_check_user_change);
63947+EXPORT_SYMBOL(gr_check_group_change);
63948+#endif
63949diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
63950new file mode 100644
63951index 0000000..387032b
63952--- /dev/null
63953+++ b/grsecurity/grsec_exec.c
63954@@ -0,0 +1,187 @@
63955+#include <linux/kernel.h>
63956+#include <linux/sched.h>
63957+#include <linux/file.h>
63958+#include <linux/binfmts.h>
63959+#include <linux/fs.h>
63960+#include <linux/types.h>
63961+#include <linux/grdefs.h>
63962+#include <linux/grsecurity.h>
63963+#include <linux/grinternal.h>
63964+#include <linux/capability.h>
63965+#include <linux/module.h>
63966+#include <linux/compat.h>
63967+
63968+#include <asm/uaccess.h>
63969+
63970+#ifdef CONFIG_GRKERNSEC_EXECLOG
63971+static char gr_exec_arg_buf[132];
63972+static DEFINE_MUTEX(gr_exec_arg_mutex);
63973+#endif
63974+
63975+struct user_arg_ptr {
63976+#ifdef CONFIG_COMPAT
63977+ bool is_compat;
63978+#endif
63979+ union {
63980+ const char __user *const __user *native;
63981+#ifdef CONFIG_COMPAT
63982+ const compat_uptr_t __user *compat;
63983+#endif
63984+ } ptr;
63985+};
63986+
63987+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
63988+
63989+void
63990+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
63991+{
63992+#ifdef CONFIG_GRKERNSEC_EXECLOG
63993+ char *grarg = gr_exec_arg_buf;
63994+ unsigned int i, x, execlen = 0;
63995+ char c;
63996+
63997+ if (!((grsec_enable_execlog && grsec_enable_group &&
63998+ in_group_p(grsec_audit_gid))
63999+ || (grsec_enable_execlog && !grsec_enable_group)))
64000+ return;
64001+
64002+ mutex_lock(&gr_exec_arg_mutex);
64003+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
64004+
64005+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
64006+ const char __user *p;
64007+ unsigned int len;
64008+
64009+ p = get_user_arg_ptr(argv, i);
64010+ if (IS_ERR(p))
64011+ goto log;
64012+
64013+ len = strnlen_user(p, 128 - execlen);
64014+ if (len > 128 - execlen)
64015+ len = 128 - execlen;
64016+ else if (len > 0)
64017+ len--;
64018+ if (copy_from_user(grarg + execlen, p, len))
64019+ goto log;
64020+
64021+ /* rewrite unprintable characters */
64022+ for (x = 0; x < len; x++) {
64023+ c = *(grarg + execlen + x);
64024+ if (c < 32 || c > 126)
64025+ *(grarg + execlen + x) = ' ';
64026+ }
64027+
64028+ execlen += len;
64029+ *(grarg + execlen) = ' ';
64030+ *(grarg + execlen + 1) = '\0';
64031+ execlen++;
64032+ }
64033+
64034+ log:
64035+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
64036+ bprm->file->f_path.mnt, grarg);
64037+ mutex_unlock(&gr_exec_arg_mutex);
64038+#endif
64039+ return;
64040+}
64041+
64042+#ifdef CONFIG_GRKERNSEC
64043+extern int gr_acl_is_capable(const int cap);
64044+extern int gr_acl_is_capable_nolog(const int cap);
64045+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64046+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
64047+extern int gr_chroot_is_capable(const int cap);
64048+extern int gr_chroot_is_capable_nolog(const int cap);
64049+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64050+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
64051+#endif
64052+
64053+const char *captab_log[] = {
64054+ "CAP_CHOWN",
64055+ "CAP_DAC_OVERRIDE",
64056+ "CAP_DAC_READ_SEARCH",
64057+ "CAP_FOWNER",
64058+ "CAP_FSETID",
64059+ "CAP_KILL",
64060+ "CAP_SETGID",
64061+ "CAP_SETUID",
64062+ "CAP_SETPCAP",
64063+ "CAP_LINUX_IMMUTABLE",
64064+ "CAP_NET_BIND_SERVICE",
64065+ "CAP_NET_BROADCAST",
64066+ "CAP_NET_ADMIN",
64067+ "CAP_NET_RAW",
64068+ "CAP_IPC_LOCK",
64069+ "CAP_IPC_OWNER",
64070+ "CAP_SYS_MODULE",
64071+ "CAP_SYS_RAWIO",
64072+ "CAP_SYS_CHROOT",
64073+ "CAP_SYS_PTRACE",
64074+ "CAP_SYS_PACCT",
64075+ "CAP_SYS_ADMIN",
64076+ "CAP_SYS_BOOT",
64077+ "CAP_SYS_NICE",
64078+ "CAP_SYS_RESOURCE",
64079+ "CAP_SYS_TIME",
64080+ "CAP_SYS_TTY_CONFIG",
64081+ "CAP_MKNOD",
64082+ "CAP_LEASE",
64083+ "CAP_AUDIT_WRITE",
64084+ "CAP_AUDIT_CONTROL",
64085+ "CAP_SETFCAP",
64086+ "CAP_MAC_OVERRIDE",
64087+ "CAP_MAC_ADMIN",
64088+ "CAP_SYSLOG",
64089+ "CAP_WAKE_ALARM"
64090+};
64091+
64092+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
64093+
64094+int gr_is_capable(const int cap)
64095+{
64096+#ifdef CONFIG_GRKERNSEC
64097+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
64098+ return 1;
64099+ return 0;
64100+#else
64101+ return 1;
64102+#endif
64103+}
64104+
64105+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64106+{
64107+#ifdef CONFIG_GRKERNSEC
64108+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
64109+ return 1;
64110+ return 0;
64111+#else
64112+ return 1;
64113+#endif
64114+}
64115+
64116+int gr_is_capable_nolog(const int cap)
64117+{
64118+#ifdef CONFIG_GRKERNSEC
64119+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
64120+ return 1;
64121+ return 0;
64122+#else
64123+ return 1;
64124+#endif
64125+}
64126+
64127+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
64128+{
64129+#ifdef CONFIG_GRKERNSEC
64130+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
64131+ return 1;
64132+ return 0;
64133+#else
64134+ return 1;
64135+#endif
64136+}
64137+
64138+EXPORT_SYMBOL(gr_is_capable);
64139+EXPORT_SYMBOL(gr_is_capable_nolog);
64140+EXPORT_SYMBOL(gr_task_is_capable);
64141+EXPORT_SYMBOL(gr_task_is_capable_nolog);
64142diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
64143new file mode 100644
64144index 0000000..06cc6ea
64145--- /dev/null
64146+++ b/grsecurity/grsec_fifo.c
64147@@ -0,0 +1,24 @@
64148+#include <linux/kernel.h>
64149+#include <linux/sched.h>
64150+#include <linux/fs.h>
64151+#include <linux/file.h>
64152+#include <linux/grinternal.h>
64153+
64154+int
64155+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
64156+ const struct dentry *dir, const int flag, const int acc_mode)
64157+{
64158+#ifdef CONFIG_GRKERNSEC_FIFO
64159+ const struct cred *cred = current_cred();
64160+
64161+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
64162+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
64163+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
64164+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
64165+ if (!inode_permission(dentry->d_inode, acc_mode))
64166+ 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));
64167+ return -EACCES;
64168+ }
64169+#endif
64170+ return 0;
64171+}
64172diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
64173new file mode 100644
64174index 0000000..8ca18bf
64175--- /dev/null
64176+++ b/grsecurity/grsec_fork.c
64177@@ -0,0 +1,23 @@
64178+#include <linux/kernel.h>
64179+#include <linux/sched.h>
64180+#include <linux/grsecurity.h>
64181+#include <linux/grinternal.h>
64182+#include <linux/errno.h>
64183+
64184+void
64185+gr_log_forkfail(const int retval)
64186+{
64187+#ifdef CONFIG_GRKERNSEC_FORKFAIL
64188+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
64189+ switch (retval) {
64190+ case -EAGAIN:
64191+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
64192+ break;
64193+ case -ENOMEM:
64194+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
64195+ break;
64196+ }
64197+ }
64198+#endif
64199+ return;
64200+}
64201diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
64202new file mode 100644
64203index 0000000..a862e9f
64204--- /dev/null
64205+++ b/grsecurity/grsec_init.c
64206@@ -0,0 +1,283 @@
64207+#include <linux/kernel.h>
64208+#include <linux/sched.h>
64209+#include <linux/mm.h>
64210+#include <linux/gracl.h>
64211+#include <linux/slab.h>
64212+#include <linux/vmalloc.h>
64213+#include <linux/percpu.h>
64214+#include <linux/module.h>
64215+
64216+int grsec_enable_ptrace_readexec;
64217+int grsec_enable_setxid;
64218+int grsec_enable_symlinkown;
64219+kgid_t grsec_symlinkown_gid;
64220+int grsec_enable_brute;
64221+int grsec_enable_link;
64222+int grsec_enable_dmesg;
64223+int grsec_enable_harden_ptrace;
64224+int grsec_enable_fifo;
64225+int grsec_enable_execlog;
64226+int grsec_enable_signal;
64227+int grsec_enable_forkfail;
64228+int grsec_enable_audit_ptrace;
64229+int grsec_enable_time;
64230+int grsec_enable_audit_textrel;
64231+int grsec_enable_group;
64232+kgid_t grsec_audit_gid;
64233+int grsec_enable_chdir;
64234+int grsec_enable_mount;
64235+int grsec_enable_rofs;
64236+int grsec_enable_chroot_findtask;
64237+int grsec_enable_chroot_mount;
64238+int grsec_enable_chroot_shmat;
64239+int grsec_enable_chroot_fchdir;
64240+int grsec_enable_chroot_double;
64241+int grsec_enable_chroot_pivot;
64242+int grsec_enable_chroot_chdir;
64243+int grsec_enable_chroot_chmod;
64244+int grsec_enable_chroot_mknod;
64245+int grsec_enable_chroot_nice;
64246+int grsec_enable_chroot_execlog;
64247+int grsec_enable_chroot_caps;
64248+int grsec_enable_chroot_sysctl;
64249+int grsec_enable_chroot_unix;
64250+int grsec_enable_tpe;
64251+kgid_t grsec_tpe_gid;
64252+int grsec_enable_blackhole;
64253+#ifdef CONFIG_IPV6_MODULE
64254+EXPORT_SYMBOL(grsec_enable_blackhole);
64255+#endif
64256+int grsec_lastack_retries;
64257+int grsec_enable_tpe_all;
64258+int grsec_enable_tpe_invert;
64259+int grsec_enable_socket_all;
64260+kgid_t grsec_socket_all_gid;
64261+int grsec_enable_socket_client;
64262+kgid_t grsec_socket_client_gid;
64263+int grsec_enable_socket_server;
64264+kgid_t grsec_socket_server_gid;
64265+int grsec_resource_logging;
64266+int grsec_disable_privio;
64267+int grsec_enable_log_rwxmaps;
64268+int grsec_lock;
64269+
64270+DEFINE_SPINLOCK(grsec_alert_lock);
64271+unsigned long grsec_alert_wtime = 0;
64272+unsigned long grsec_alert_fyet = 0;
64273+
64274+DEFINE_SPINLOCK(grsec_audit_lock);
64275+
64276+DEFINE_RWLOCK(grsec_exec_file_lock);
64277+
64278+char *gr_shared_page[4];
64279+
64280+char *gr_alert_log_fmt;
64281+char *gr_audit_log_fmt;
64282+char *gr_alert_log_buf;
64283+char *gr_audit_log_buf;
64284+
64285+extern struct gr_arg *gr_usermode;
64286+extern unsigned char *gr_system_salt;
64287+extern unsigned char *gr_system_sum;
64288+
64289+void __init
64290+grsecurity_init(void)
64291+{
64292+ int j;
64293+ /* create the per-cpu shared pages */
64294+
64295+#ifdef CONFIG_X86
64296+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
64297+#endif
64298+
64299+ for (j = 0; j < 4; j++) {
64300+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
64301+ if (gr_shared_page[j] == NULL) {
64302+ panic("Unable to allocate grsecurity shared page");
64303+ return;
64304+ }
64305+ }
64306+
64307+ /* allocate log buffers */
64308+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
64309+ if (!gr_alert_log_fmt) {
64310+ panic("Unable to allocate grsecurity alert log format buffer");
64311+ return;
64312+ }
64313+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
64314+ if (!gr_audit_log_fmt) {
64315+ panic("Unable to allocate grsecurity audit log format buffer");
64316+ return;
64317+ }
64318+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
64319+ if (!gr_alert_log_buf) {
64320+ panic("Unable to allocate grsecurity alert log buffer");
64321+ return;
64322+ }
64323+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
64324+ if (!gr_audit_log_buf) {
64325+ panic("Unable to allocate grsecurity audit log buffer");
64326+ return;
64327+ }
64328+
64329+ /* allocate memory for authentication structure */
64330+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
64331+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
64332+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
64333+
64334+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
64335+ panic("Unable to allocate grsecurity authentication structure");
64336+ return;
64337+ }
64338+
64339+
64340+#ifdef CONFIG_GRKERNSEC_IO
64341+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
64342+ grsec_disable_privio = 1;
64343+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
64344+ grsec_disable_privio = 1;
64345+#else
64346+ grsec_disable_privio = 0;
64347+#endif
64348+#endif
64349+
64350+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
64351+ /* for backward compatibility, tpe_invert always defaults to on if
64352+ enabled in the kernel
64353+ */
64354+ grsec_enable_tpe_invert = 1;
64355+#endif
64356+
64357+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
64358+#ifndef CONFIG_GRKERNSEC_SYSCTL
64359+ grsec_lock = 1;
64360+#endif
64361+
64362+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64363+ grsec_enable_audit_textrel = 1;
64364+#endif
64365+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64366+ grsec_enable_log_rwxmaps = 1;
64367+#endif
64368+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
64369+ grsec_enable_group = 1;
64370+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
64371+#endif
64372+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
64373+ grsec_enable_ptrace_readexec = 1;
64374+#endif
64375+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
64376+ grsec_enable_chdir = 1;
64377+#endif
64378+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
64379+ grsec_enable_harden_ptrace = 1;
64380+#endif
64381+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64382+ grsec_enable_mount = 1;
64383+#endif
64384+#ifdef CONFIG_GRKERNSEC_LINK
64385+ grsec_enable_link = 1;
64386+#endif
64387+#ifdef CONFIG_GRKERNSEC_BRUTE
64388+ grsec_enable_brute = 1;
64389+#endif
64390+#ifdef CONFIG_GRKERNSEC_DMESG
64391+ grsec_enable_dmesg = 1;
64392+#endif
64393+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
64394+ grsec_enable_blackhole = 1;
64395+ grsec_lastack_retries = 4;
64396+#endif
64397+#ifdef CONFIG_GRKERNSEC_FIFO
64398+ grsec_enable_fifo = 1;
64399+#endif
64400+#ifdef CONFIG_GRKERNSEC_EXECLOG
64401+ grsec_enable_execlog = 1;
64402+#endif
64403+#ifdef CONFIG_GRKERNSEC_SETXID
64404+ grsec_enable_setxid = 1;
64405+#endif
64406+#ifdef CONFIG_GRKERNSEC_SIGNAL
64407+ grsec_enable_signal = 1;
64408+#endif
64409+#ifdef CONFIG_GRKERNSEC_FORKFAIL
64410+ grsec_enable_forkfail = 1;
64411+#endif
64412+#ifdef CONFIG_GRKERNSEC_TIME
64413+ grsec_enable_time = 1;
64414+#endif
64415+#ifdef CONFIG_GRKERNSEC_RESLOG
64416+ grsec_resource_logging = 1;
64417+#endif
64418+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64419+ grsec_enable_chroot_findtask = 1;
64420+#endif
64421+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64422+ grsec_enable_chroot_unix = 1;
64423+#endif
64424+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64425+ grsec_enable_chroot_mount = 1;
64426+#endif
64427+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64428+ grsec_enable_chroot_fchdir = 1;
64429+#endif
64430+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64431+ grsec_enable_chroot_shmat = 1;
64432+#endif
64433+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64434+ grsec_enable_audit_ptrace = 1;
64435+#endif
64436+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64437+ grsec_enable_chroot_double = 1;
64438+#endif
64439+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64440+ grsec_enable_chroot_pivot = 1;
64441+#endif
64442+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64443+ grsec_enable_chroot_chdir = 1;
64444+#endif
64445+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
64446+ grsec_enable_chroot_chmod = 1;
64447+#endif
64448+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64449+ grsec_enable_chroot_mknod = 1;
64450+#endif
64451+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64452+ grsec_enable_chroot_nice = 1;
64453+#endif
64454+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64455+ grsec_enable_chroot_execlog = 1;
64456+#endif
64457+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64458+ grsec_enable_chroot_caps = 1;
64459+#endif
64460+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
64461+ grsec_enable_chroot_sysctl = 1;
64462+#endif
64463+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
64464+ grsec_enable_symlinkown = 1;
64465+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
64466+#endif
64467+#ifdef CONFIG_GRKERNSEC_TPE
64468+ grsec_enable_tpe = 1;
64469+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
64470+#ifdef CONFIG_GRKERNSEC_TPE_ALL
64471+ grsec_enable_tpe_all = 1;
64472+#endif
64473+#endif
64474+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
64475+ grsec_enable_socket_all = 1;
64476+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
64477+#endif
64478+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
64479+ grsec_enable_socket_client = 1;
64480+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
64481+#endif
64482+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64483+ grsec_enable_socket_server = 1;
64484+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
64485+#endif
64486+#endif
64487+
64488+ return;
64489+}
64490diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
64491new file mode 100644
64492index 0000000..5e05e20
64493--- /dev/null
64494+++ b/grsecurity/grsec_link.c
64495@@ -0,0 +1,58 @@
64496+#include <linux/kernel.h>
64497+#include <linux/sched.h>
64498+#include <linux/fs.h>
64499+#include <linux/file.h>
64500+#include <linux/grinternal.h>
64501+
64502+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
64503+{
64504+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
64505+ const struct inode *link_inode = link->dentry->d_inode;
64506+
64507+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
64508+ /* ignore root-owned links, e.g. /proc/self */
64509+ gr_is_global_nonroot(link_inode->i_uid) && target &&
64510+ !uid_eq(link_inode->i_uid, target->i_uid)) {
64511+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
64512+ return 1;
64513+ }
64514+#endif
64515+ return 0;
64516+}
64517+
64518+int
64519+gr_handle_follow_link(const struct inode *parent,
64520+ const struct inode *inode,
64521+ const struct dentry *dentry, const struct vfsmount *mnt)
64522+{
64523+#ifdef CONFIG_GRKERNSEC_LINK
64524+ const struct cred *cred = current_cred();
64525+
64526+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
64527+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
64528+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
64529+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
64530+ return -EACCES;
64531+ }
64532+#endif
64533+ return 0;
64534+}
64535+
64536+int
64537+gr_handle_hardlink(const struct dentry *dentry,
64538+ const struct vfsmount *mnt,
64539+ struct inode *inode, const int mode, const struct filename *to)
64540+{
64541+#ifdef CONFIG_GRKERNSEC_LINK
64542+ const struct cred *cred = current_cred();
64543+
64544+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
64545+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
64546+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
64547+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
64548+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
64549+ return -EPERM;
64550+ }
64551+#endif
64552+ return 0;
64553+}
64554diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
64555new file mode 100644
64556index 0000000..7c06085
64557--- /dev/null
64558+++ b/grsecurity/grsec_log.c
64559@@ -0,0 +1,326 @@
64560+#include <linux/kernel.h>
64561+#include <linux/sched.h>
64562+#include <linux/file.h>
64563+#include <linux/tty.h>
64564+#include <linux/fs.h>
64565+#include <linux/grinternal.h>
64566+
64567+#ifdef CONFIG_TREE_PREEMPT_RCU
64568+#define DISABLE_PREEMPT() preempt_disable()
64569+#define ENABLE_PREEMPT() preempt_enable()
64570+#else
64571+#define DISABLE_PREEMPT()
64572+#define ENABLE_PREEMPT()
64573+#endif
64574+
64575+#define BEGIN_LOCKS(x) \
64576+ DISABLE_PREEMPT(); \
64577+ rcu_read_lock(); \
64578+ read_lock(&tasklist_lock); \
64579+ read_lock(&grsec_exec_file_lock); \
64580+ if (x != GR_DO_AUDIT) \
64581+ spin_lock(&grsec_alert_lock); \
64582+ else \
64583+ spin_lock(&grsec_audit_lock)
64584+
64585+#define END_LOCKS(x) \
64586+ if (x != GR_DO_AUDIT) \
64587+ spin_unlock(&grsec_alert_lock); \
64588+ else \
64589+ spin_unlock(&grsec_audit_lock); \
64590+ read_unlock(&grsec_exec_file_lock); \
64591+ read_unlock(&tasklist_lock); \
64592+ rcu_read_unlock(); \
64593+ ENABLE_PREEMPT(); \
64594+ if (x == GR_DONT_AUDIT) \
64595+ gr_handle_alertkill(current)
64596+
64597+enum {
64598+ FLOODING,
64599+ NO_FLOODING
64600+};
64601+
64602+extern char *gr_alert_log_fmt;
64603+extern char *gr_audit_log_fmt;
64604+extern char *gr_alert_log_buf;
64605+extern char *gr_audit_log_buf;
64606+
64607+static int gr_log_start(int audit)
64608+{
64609+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
64610+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
64611+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64612+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
64613+ unsigned long curr_secs = get_seconds();
64614+
64615+ if (audit == GR_DO_AUDIT)
64616+ goto set_fmt;
64617+
64618+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
64619+ grsec_alert_wtime = curr_secs;
64620+ grsec_alert_fyet = 0;
64621+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
64622+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
64623+ grsec_alert_fyet++;
64624+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
64625+ grsec_alert_wtime = curr_secs;
64626+ grsec_alert_fyet++;
64627+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
64628+ return FLOODING;
64629+ }
64630+ else return FLOODING;
64631+
64632+set_fmt:
64633+#endif
64634+ memset(buf, 0, PAGE_SIZE);
64635+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
64636+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
64637+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
64638+ } else if (current->signal->curr_ip) {
64639+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
64640+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
64641+ } else if (gr_acl_is_enabled()) {
64642+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
64643+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
64644+ } else {
64645+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
64646+ strcpy(buf, fmt);
64647+ }
64648+
64649+ return NO_FLOODING;
64650+}
64651+
64652+static void gr_log_middle(int audit, const char *msg, va_list ap)
64653+ __attribute__ ((format (printf, 2, 0)));
64654+
64655+static void gr_log_middle(int audit, const char *msg, va_list ap)
64656+{
64657+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64658+ unsigned int len = strlen(buf);
64659+
64660+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
64661+
64662+ return;
64663+}
64664+
64665+static void gr_log_middle_varargs(int audit, const char *msg, ...)
64666+ __attribute__ ((format (printf, 2, 3)));
64667+
64668+static void gr_log_middle_varargs(int audit, const char *msg, ...)
64669+{
64670+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64671+ unsigned int len = strlen(buf);
64672+ va_list ap;
64673+
64674+ va_start(ap, msg);
64675+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
64676+ va_end(ap);
64677+
64678+ return;
64679+}
64680+
64681+static void gr_log_end(int audit, int append_default)
64682+{
64683+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64684+ if (append_default) {
64685+ struct task_struct *task = current;
64686+ struct task_struct *parent = task->real_parent;
64687+ const struct cred *cred = __task_cred(task);
64688+ const struct cred *pcred = __task_cred(parent);
64689+ unsigned int len = strlen(buf);
64690+
64691+ 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));
64692+ }
64693+
64694+ printk("%s\n", buf);
64695+
64696+ return;
64697+}
64698+
64699+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
64700+{
64701+ int logtype;
64702+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
64703+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
64704+ void *voidptr = NULL;
64705+ int num1 = 0, num2 = 0;
64706+ unsigned long ulong1 = 0, ulong2 = 0;
64707+ struct dentry *dentry = NULL;
64708+ struct vfsmount *mnt = NULL;
64709+ struct file *file = NULL;
64710+ struct task_struct *task = NULL;
64711+ const struct cred *cred, *pcred;
64712+ va_list ap;
64713+
64714+ BEGIN_LOCKS(audit);
64715+ logtype = gr_log_start(audit);
64716+ if (logtype == FLOODING) {
64717+ END_LOCKS(audit);
64718+ return;
64719+ }
64720+ va_start(ap, argtypes);
64721+ switch (argtypes) {
64722+ case GR_TTYSNIFF:
64723+ task = va_arg(ap, struct task_struct *);
64724+ 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));
64725+ break;
64726+ case GR_SYSCTL_HIDDEN:
64727+ str1 = va_arg(ap, char *);
64728+ gr_log_middle_varargs(audit, msg, result, str1);
64729+ break;
64730+ case GR_RBAC:
64731+ dentry = va_arg(ap, struct dentry *);
64732+ mnt = va_arg(ap, struct vfsmount *);
64733+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
64734+ break;
64735+ case GR_RBAC_STR:
64736+ dentry = va_arg(ap, struct dentry *);
64737+ mnt = va_arg(ap, struct vfsmount *);
64738+ str1 = va_arg(ap, char *);
64739+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
64740+ break;
64741+ case GR_STR_RBAC:
64742+ str1 = va_arg(ap, char *);
64743+ dentry = va_arg(ap, struct dentry *);
64744+ mnt = va_arg(ap, struct vfsmount *);
64745+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
64746+ break;
64747+ case GR_RBAC_MODE2:
64748+ dentry = va_arg(ap, struct dentry *);
64749+ mnt = va_arg(ap, struct vfsmount *);
64750+ str1 = va_arg(ap, char *);
64751+ str2 = va_arg(ap, char *);
64752+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
64753+ break;
64754+ case GR_RBAC_MODE3:
64755+ dentry = va_arg(ap, struct dentry *);
64756+ mnt = va_arg(ap, struct vfsmount *);
64757+ str1 = va_arg(ap, char *);
64758+ str2 = va_arg(ap, char *);
64759+ str3 = va_arg(ap, char *);
64760+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
64761+ break;
64762+ case GR_FILENAME:
64763+ dentry = va_arg(ap, struct dentry *);
64764+ mnt = va_arg(ap, struct vfsmount *);
64765+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
64766+ break;
64767+ case GR_STR_FILENAME:
64768+ str1 = va_arg(ap, char *);
64769+ dentry = va_arg(ap, struct dentry *);
64770+ mnt = va_arg(ap, struct vfsmount *);
64771+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
64772+ break;
64773+ case GR_FILENAME_STR:
64774+ dentry = va_arg(ap, struct dentry *);
64775+ mnt = va_arg(ap, struct vfsmount *);
64776+ str1 = va_arg(ap, char *);
64777+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
64778+ break;
64779+ case GR_FILENAME_TWO_INT:
64780+ dentry = va_arg(ap, struct dentry *);
64781+ mnt = va_arg(ap, struct vfsmount *);
64782+ num1 = va_arg(ap, int);
64783+ num2 = va_arg(ap, int);
64784+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
64785+ break;
64786+ case GR_FILENAME_TWO_INT_STR:
64787+ dentry = va_arg(ap, struct dentry *);
64788+ mnt = va_arg(ap, struct vfsmount *);
64789+ num1 = va_arg(ap, int);
64790+ num2 = va_arg(ap, int);
64791+ str1 = va_arg(ap, char *);
64792+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
64793+ break;
64794+ case GR_TEXTREL:
64795+ file = va_arg(ap, struct file *);
64796+ ulong1 = va_arg(ap, unsigned long);
64797+ ulong2 = va_arg(ap, unsigned long);
64798+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
64799+ break;
64800+ case GR_PTRACE:
64801+ task = va_arg(ap, struct task_struct *);
64802+ 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));
64803+ break;
64804+ case GR_RESOURCE:
64805+ task = va_arg(ap, struct task_struct *);
64806+ cred = __task_cred(task);
64807+ pcred = __task_cred(task->real_parent);
64808+ ulong1 = va_arg(ap, unsigned long);
64809+ str1 = va_arg(ap, char *);
64810+ ulong2 = va_arg(ap, unsigned long);
64811+ 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));
64812+ break;
64813+ case GR_CAP:
64814+ task = va_arg(ap, struct task_struct *);
64815+ cred = __task_cred(task);
64816+ pcred = __task_cred(task->real_parent);
64817+ str1 = va_arg(ap, char *);
64818+ 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));
64819+ break;
64820+ case GR_SIG:
64821+ str1 = va_arg(ap, char *);
64822+ voidptr = va_arg(ap, void *);
64823+ gr_log_middle_varargs(audit, msg, str1, voidptr);
64824+ break;
64825+ case GR_SIG2:
64826+ task = va_arg(ap, struct task_struct *);
64827+ cred = __task_cred(task);
64828+ pcred = __task_cred(task->real_parent);
64829+ num1 = va_arg(ap, int);
64830+ 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));
64831+ break;
64832+ case GR_CRASH1:
64833+ task = va_arg(ap, struct task_struct *);
64834+ cred = __task_cred(task);
64835+ pcred = __task_cred(task->real_parent);
64836+ ulong1 = va_arg(ap, unsigned long);
64837+ 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);
64838+ break;
64839+ case GR_CRASH2:
64840+ task = va_arg(ap, struct task_struct *);
64841+ cred = __task_cred(task);
64842+ pcred = __task_cred(task->real_parent);
64843+ ulong1 = va_arg(ap, unsigned long);
64844+ 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);
64845+ break;
64846+ case GR_RWXMAP:
64847+ file = va_arg(ap, struct file *);
64848+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
64849+ break;
64850+ case GR_PSACCT:
64851+ {
64852+ unsigned int wday, cday;
64853+ __u8 whr, chr;
64854+ __u8 wmin, cmin;
64855+ __u8 wsec, csec;
64856+ char cur_tty[64] = { 0 };
64857+ char parent_tty[64] = { 0 };
64858+
64859+ task = va_arg(ap, struct task_struct *);
64860+ wday = va_arg(ap, unsigned int);
64861+ cday = va_arg(ap, unsigned int);
64862+ whr = va_arg(ap, int);
64863+ chr = va_arg(ap, int);
64864+ wmin = va_arg(ap, int);
64865+ cmin = va_arg(ap, int);
64866+ wsec = va_arg(ap, int);
64867+ csec = va_arg(ap, int);
64868+ ulong1 = va_arg(ap, unsigned long);
64869+ cred = __task_cred(task);
64870+ pcred = __task_cred(task->real_parent);
64871+
64872+ 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));
64873+ }
64874+ break;
64875+ default:
64876+ gr_log_middle(audit, msg, ap);
64877+ }
64878+ va_end(ap);
64879+ // these don't need DEFAULTSECARGS printed on the end
64880+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
64881+ gr_log_end(audit, 0);
64882+ else
64883+ gr_log_end(audit, 1);
64884+ END_LOCKS(audit);
64885+}
64886diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
64887new file mode 100644
64888index 0000000..f536303
64889--- /dev/null
64890+++ b/grsecurity/grsec_mem.c
64891@@ -0,0 +1,40 @@
64892+#include <linux/kernel.h>
64893+#include <linux/sched.h>
64894+#include <linux/mm.h>
64895+#include <linux/mman.h>
64896+#include <linux/grinternal.h>
64897+
64898+void
64899+gr_handle_ioperm(void)
64900+{
64901+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
64902+ return;
64903+}
64904+
64905+void
64906+gr_handle_iopl(void)
64907+{
64908+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
64909+ return;
64910+}
64911+
64912+void
64913+gr_handle_mem_readwrite(u64 from, u64 to)
64914+{
64915+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
64916+ return;
64917+}
64918+
64919+void
64920+gr_handle_vm86(void)
64921+{
64922+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
64923+ return;
64924+}
64925+
64926+void
64927+gr_log_badprocpid(const char *entry)
64928+{
64929+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
64930+ return;
64931+}
64932diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
64933new file mode 100644
64934index 0000000..2131422
64935--- /dev/null
64936+++ b/grsecurity/grsec_mount.c
64937@@ -0,0 +1,62 @@
64938+#include <linux/kernel.h>
64939+#include <linux/sched.h>
64940+#include <linux/mount.h>
64941+#include <linux/grsecurity.h>
64942+#include <linux/grinternal.h>
64943+
64944+void
64945+gr_log_remount(const char *devname, const int retval)
64946+{
64947+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64948+ if (grsec_enable_mount && (retval >= 0))
64949+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
64950+#endif
64951+ return;
64952+}
64953+
64954+void
64955+gr_log_unmount(const char *devname, const int retval)
64956+{
64957+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64958+ if (grsec_enable_mount && (retval >= 0))
64959+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
64960+#endif
64961+ return;
64962+}
64963+
64964+void
64965+gr_log_mount(const char *from, const char *to, const int retval)
64966+{
64967+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64968+ if (grsec_enable_mount && (retval >= 0))
64969+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
64970+#endif
64971+ return;
64972+}
64973+
64974+int
64975+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
64976+{
64977+#ifdef CONFIG_GRKERNSEC_ROFS
64978+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
64979+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
64980+ return -EPERM;
64981+ } else
64982+ return 0;
64983+#endif
64984+ return 0;
64985+}
64986+
64987+int
64988+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
64989+{
64990+#ifdef CONFIG_GRKERNSEC_ROFS
64991+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
64992+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
64993+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
64994+ return -EPERM;
64995+ } else
64996+ return 0;
64997+#endif
64998+ return 0;
64999+}
65000diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
65001new file mode 100644
65002index 0000000..a3b12a0
65003--- /dev/null
65004+++ b/grsecurity/grsec_pax.c
65005@@ -0,0 +1,36 @@
65006+#include <linux/kernel.h>
65007+#include <linux/sched.h>
65008+#include <linux/mm.h>
65009+#include <linux/file.h>
65010+#include <linux/grinternal.h>
65011+#include <linux/grsecurity.h>
65012+
65013+void
65014+gr_log_textrel(struct vm_area_struct * vma)
65015+{
65016+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65017+ if (grsec_enable_audit_textrel)
65018+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
65019+#endif
65020+ return;
65021+}
65022+
65023+void
65024+gr_log_rwxmmap(struct file *file)
65025+{
65026+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65027+ if (grsec_enable_log_rwxmaps)
65028+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
65029+#endif
65030+ return;
65031+}
65032+
65033+void
65034+gr_log_rwxmprotect(struct file *file)
65035+{
65036+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65037+ if (grsec_enable_log_rwxmaps)
65038+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
65039+#endif
65040+ return;
65041+}
65042diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
65043new file mode 100644
65044index 0000000..f7f29aa
65045--- /dev/null
65046+++ b/grsecurity/grsec_ptrace.c
65047@@ -0,0 +1,30 @@
65048+#include <linux/kernel.h>
65049+#include <linux/sched.h>
65050+#include <linux/grinternal.h>
65051+#include <linux/security.h>
65052+
65053+void
65054+gr_audit_ptrace(struct task_struct *task)
65055+{
65056+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65057+ if (grsec_enable_audit_ptrace)
65058+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
65059+#endif
65060+ return;
65061+}
65062+
65063+int
65064+gr_ptrace_readexec(struct file *file, int unsafe_flags)
65065+{
65066+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65067+ const struct dentry *dentry = file->f_path.dentry;
65068+ const struct vfsmount *mnt = file->f_path.mnt;
65069+
65070+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
65071+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
65072+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
65073+ return -EACCES;
65074+ }
65075+#endif
65076+ return 0;
65077+}
65078diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
65079new file mode 100644
65080index 0000000..e09715a
65081--- /dev/null
65082+++ b/grsecurity/grsec_sig.c
65083@@ -0,0 +1,222 @@
65084+#include <linux/kernel.h>
65085+#include <linux/sched.h>
65086+#include <linux/delay.h>
65087+#include <linux/grsecurity.h>
65088+#include <linux/grinternal.h>
65089+#include <linux/hardirq.h>
65090+
65091+char *signames[] = {
65092+ [SIGSEGV] = "Segmentation fault",
65093+ [SIGILL] = "Illegal instruction",
65094+ [SIGABRT] = "Abort",
65095+ [SIGBUS] = "Invalid alignment/Bus error"
65096+};
65097+
65098+void
65099+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
65100+{
65101+#ifdef CONFIG_GRKERNSEC_SIGNAL
65102+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
65103+ (sig == SIGABRT) || (sig == SIGBUS))) {
65104+ if (task_pid_nr(t) == task_pid_nr(current)) {
65105+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
65106+ } else {
65107+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
65108+ }
65109+ }
65110+#endif
65111+ return;
65112+}
65113+
65114+int
65115+gr_handle_signal(const struct task_struct *p, const int sig)
65116+{
65117+#ifdef CONFIG_GRKERNSEC
65118+ /* ignore the 0 signal for protected task checks */
65119+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
65120+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
65121+ return -EPERM;
65122+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
65123+ return -EPERM;
65124+ }
65125+#endif
65126+ return 0;
65127+}
65128+
65129+#ifdef CONFIG_GRKERNSEC
65130+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
65131+
65132+int gr_fake_force_sig(int sig, struct task_struct *t)
65133+{
65134+ unsigned long int flags;
65135+ int ret, blocked, ignored;
65136+ struct k_sigaction *action;
65137+
65138+ spin_lock_irqsave(&t->sighand->siglock, flags);
65139+ action = &t->sighand->action[sig-1];
65140+ ignored = action->sa.sa_handler == SIG_IGN;
65141+ blocked = sigismember(&t->blocked, sig);
65142+ if (blocked || ignored) {
65143+ action->sa.sa_handler = SIG_DFL;
65144+ if (blocked) {
65145+ sigdelset(&t->blocked, sig);
65146+ recalc_sigpending_and_wake(t);
65147+ }
65148+ }
65149+ if (action->sa.sa_handler == SIG_DFL)
65150+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
65151+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
65152+
65153+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
65154+
65155+ return ret;
65156+}
65157+#endif
65158+
65159+#ifdef CONFIG_GRKERNSEC_BRUTE
65160+#define GR_USER_BAN_TIME (15 * 60)
65161+#define GR_DAEMON_BRUTE_TIME (30 * 60)
65162+
65163+static int __get_dumpable(unsigned long mm_flags)
65164+{
65165+ int ret;
65166+
65167+ ret = mm_flags & MMF_DUMPABLE_MASK;
65168+ return (ret >= 2) ? 2 : ret;
65169+}
65170+#endif
65171+
65172+void gr_handle_brute_attach(unsigned long mm_flags)
65173+{
65174+#ifdef CONFIG_GRKERNSEC_BRUTE
65175+ struct task_struct *p = current;
65176+ kuid_t uid = GLOBAL_ROOT_UID;
65177+ int daemon = 0;
65178+
65179+ if (!grsec_enable_brute)
65180+ return;
65181+
65182+ rcu_read_lock();
65183+ read_lock(&tasklist_lock);
65184+ read_lock(&grsec_exec_file_lock);
65185+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
65186+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
65187+ p->real_parent->brute = 1;
65188+ daemon = 1;
65189+ } else {
65190+ const struct cred *cred = __task_cred(p), *cred2;
65191+ struct task_struct *tsk, *tsk2;
65192+
65193+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
65194+ struct user_struct *user;
65195+
65196+ uid = cred->uid;
65197+
65198+ /* this is put upon execution past expiration */
65199+ user = find_user(uid);
65200+ if (user == NULL)
65201+ goto unlock;
65202+ user->banned = 1;
65203+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
65204+ if (user->ban_expires == ~0UL)
65205+ user->ban_expires--;
65206+
65207+ do_each_thread(tsk2, tsk) {
65208+ cred2 = __task_cred(tsk);
65209+ if (tsk != p && uid_eq(cred2->uid, uid))
65210+ gr_fake_force_sig(SIGKILL, tsk);
65211+ } while_each_thread(tsk2, tsk);
65212+ }
65213+ }
65214+unlock:
65215+ read_unlock(&grsec_exec_file_lock);
65216+ read_unlock(&tasklist_lock);
65217+ rcu_read_unlock();
65218+
65219+ if (gr_is_global_nonroot(uid))
65220+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
65221+ GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
65222+ else if (daemon)
65223+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
65224+
65225+#endif
65226+ return;
65227+}
65228+
65229+void gr_handle_brute_check(void)
65230+{
65231+#ifdef CONFIG_GRKERNSEC_BRUTE
65232+ struct task_struct *p = current;
65233+
65234+ if (unlikely(p->brute)) {
65235+ if (!grsec_enable_brute)
65236+ p->brute = 0;
65237+ else if (time_before(get_seconds(), p->brute_expires))
65238+ msleep(30 * 1000);
65239+ }
65240+#endif
65241+ return;
65242+}
65243+
65244+void gr_handle_kernel_exploit(void)
65245+{
65246+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
65247+ const struct cred *cred;
65248+ struct task_struct *tsk, *tsk2;
65249+ struct user_struct *user;
65250+ kuid_t uid;
65251+
65252+ if (in_irq() || in_serving_softirq() || in_nmi())
65253+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
65254+
65255+ uid = current_uid();
65256+
65257+ if (gr_is_global_root(uid))
65258+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
65259+ else {
65260+ /* kill all the processes of this user, hold a reference
65261+ to their creds struct, and prevent them from creating
65262+ another process until system reset
65263+ */
65264+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
65265+ GR_GLOBAL_UID(uid));
65266+ /* we intentionally leak this ref */
65267+ user = get_uid(current->cred->user);
65268+ if (user) {
65269+ user->banned = 1;
65270+ user->ban_expires = ~0UL;
65271+ }
65272+
65273+ read_lock(&tasklist_lock);
65274+ do_each_thread(tsk2, tsk) {
65275+ cred = __task_cred(tsk);
65276+ if (uid_eq(cred->uid, uid))
65277+ gr_fake_force_sig(SIGKILL, tsk);
65278+ } while_each_thread(tsk2, tsk);
65279+ read_unlock(&tasklist_lock);
65280+ }
65281+#endif
65282+}
65283+
65284+int __gr_process_user_ban(struct user_struct *user)
65285+{
65286+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65287+ if (unlikely(user->banned)) {
65288+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
65289+ user->banned = 0;
65290+ user->ban_expires = 0;
65291+ free_uid(user);
65292+ } else
65293+ return -EPERM;
65294+ }
65295+#endif
65296+ return 0;
65297+}
65298+
65299+int gr_process_user_ban(void)
65300+{
65301+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65302+ return __gr_process_user_ban(current->cred->user);
65303+#endif
65304+ return 0;
65305+}
65306diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
65307new file mode 100644
65308index 0000000..4030d57
65309--- /dev/null
65310+++ b/grsecurity/grsec_sock.c
65311@@ -0,0 +1,244 @@
65312+#include <linux/kernel.h>
65313+#include <linux/module.h>
65314+#include <linux/sched.h>
65315+#include <linux/file.h>
65316+#include <linux/net.h>
65317+#include <linux/in.h>
65318+#include <linux/ip.h>
65319+#include <net/sock.h>
65320+#include <net/inet_sock.h>
65321+#include <linux/grsecurity.h>
65322+#include <linux/grinternal.h>
65323+#include <linux/gracl.h>
65324+
65325+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
65326+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
65327+
65328+EXPORT_SYMBOL(gr_search_udp_recvmsg);
65329+EXPORT_SYMBOL(gr_search_udp_sendmsg);
65330+
65331+#ifdef CONFIG_UNIX_MODULE
65332+EXPORT_SYMBOL(gr_acl_handle_unix);
65333+EXPORT_SYMBOL(gr_acl_handle_mknod);
65334+EXPORT_SYMBOL(gr_handle_chroot_unix);
65335+EXPORT_SYMBOL(gr_handle_create);
65336+#endif
65337+
65338+#ifdef CONFIG_GRKERNSEC
65339+#define gr_conn_table_size 32749
65340+struct conn_table_entry {
65341+ struct conn_table_entry *next;
65342+ struct signal_struct *sig;
65343+};
65344+
65345+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
65346+DEFINE_SPINLOCK(gr_conn_table_lock);
65347+
65348+extern const char * gr_socktype_to_name(unsigned char type);
65349+extern const char * gr_proto_to_name(unsigned char proto);
65350+extern const char * gr_sockfamily_to_name(unsigned char family);
65351+
65352+static __inline__ int
65353+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
65354+{
65355+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
65356+}
65357+
65358+static __inline__ int
65359+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
65360+ __u16 sport, __u16 dport)
65361+{
65362+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
65363+ sig->gr_sport == sport && sig->gr_dport == dport))
65364+ return 1;
65365+ else
65366+ return 0;
65367+}
65368+
65369+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
65370+{
65371+ struct conn_table_entry **match;
65372+ unsigned int index;
65373+
65374+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
65375+ sig->gr_sport, sig->gr_dport,
65376+ gr_conn_table_size);
65377+
65378+ newent->sig = sig;
65379+
65380+ match = &gr_conn_table[index];
65381+ newent->next = *match;
65382+ *match = newent;
65383+
65384+ return;
65385+}
65386+
65387+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
65388+{
65389+ struct conn_table_entry *match, *last = NULL;
65390+ unsigned int index;
65391+
65392+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
65393+ sig->gr_sport, sig->gr_dport,
65394+ gr_conn_table_size);
65395+
65396+ match = gr_conn_table[index];
65397+ while (match && !conn_match(match->sig,
65398+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
65399+ sig->gr_dport)) {
65400+ last = match;
65401+ match = match->next;
65402+ }
65403+
65404+ if (match) {
65405+ if (last)
65406+ last->next = match->next;
65407+ else
65408+ gr_conn_table[index] = NULL;
65409+ kfree(match);
65410+ }
65411+
65412+ return;
65413+}
65414+
65415+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
65416+ __u16 sport, __u16 dport)
65417+{
65418+ struct conn_table_entry *match;
65419+ unsigned int index;
65420+
65421+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
65422+
65423+ match = gr_conn_table[index];
65424+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
65425+ match = match->next;
65426+
65427+ if (match)
65428+ return match->sig;
65429+ else
65430+ return NULL;
65431+}
65432+
65433+#endif
65434+
65435+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
65436+{
65437+#ifdef CONFIG_GRKERNSEC
65438+ struct signal_struct *sig = task->signal;
65439+ struct conn_table_entry *newent;
65440+
65441+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
65442+ if (newent == NULL)
65443+ return;
65444+ /* no bh lock needed since we are called with bh disabled */
65445+ spin_lock(&gr_conn_table_lock);
65446+ gr_del_task_from_ip_table_nolock(sig);
65447+ sig->gr_saddr = inet->inet_rcv_saddr;
65448+ sig->gr_daddr = inet->inet_daddr;
65449+ sig->gr_sport = inet->inet_sport;
65450+ sig->gr_dport = inet->inet_dport;
65451+ gr_add_to_task_ip_table_nolock(sig, newent);
65452+ spin_unlock(&gr_conn_table_lock);
65453+#endif
65454+ return;
65455+}
65456+
65457+void gr_del_task_from_ip_table(struct task_struct *task)
65458+{
65459+#ifdef CONFIG_GRKERNSEC
65460+ spin_lock_bh(&gr_conn_table_lock);
65461+ gr_del_task_from_ip_table_nolock(task->signal);
65462+ spin_unlock_bh(&gr_conn_table_lock);
65463+#endif
65464+ return;
65465+}
65466+
65467+void
65468+gr_attach_curr_ip(const struct sock *sk)
65469+{
65470+#ifdef CONFIG_GRKERNSEC
65471+ struct signal_struct *p, *set;
65472+ const struct inet_sock *inet = inet_sk(sk);
65473+
65474+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
65475+ return;
65476+
65477+ set = current->signal;
65478+
65479+ spin_lock_bh(&gr_conn_table_lock);
65480+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
65481+ inet->inet_dport, inet->inet_sport);
65482+ if (unlikely(p != NULL)) {
65483+ set->curr_ip = p->curr_ip;
65484+ set->used_accept = 1;
65485+ gr_del_task_from_ip_table_nolock(p);
65486+ spin_unlock_bh(&gr_conn_table_lock);
65487+ return;
65488+ }
65489+ spin_unlock_bh(&gr_conn_table_lock);
65490+
65491+ set->curr_ip = inet->inet_daddr;
65492+ set->used_accept = 1;
65493+#endif
65494+ return;
65495+}
65496+
65497+int
65498+gr_handle_sock_all(const int family, const int type, const int protocol)
65499+{
65500+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65501+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
65502+ (family != AF_UNIX)) {
65503+ if (family == AF_INET)
65504+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
65505+ else
65506+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
65507+ return -EACCES;
65508+ }
65509+#endif
65510+ return 0;
65511+}
65512+
65513+int
65514+gr_handle_sock_server(const struct sockaddr *sck)
65515+{
65516+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65517+ if (grsec_enable_socket_server &&
65518+ in_group_p(grsec_socket_server_gid) &&
65519+ sck && (sck->sa_family != AF_UNIX) &&
65520+ (sck->sa_family != AF_LOCAL)) {
65521+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
65522+ return -EACCES;
65523+ }
65524+#endif
65525+ return 0;
65526+}
65527+
65528+int
65529+gr_handle_sock_server_other(const struct sock *sck)
65530+{
65531+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65532+ if (grsec_enable_socket_server &&
65533+ in_group_p(grsec_socket_server_gid) &&
65534+ sck && (sck->sk_family != AF_UNIX) &&
65535+ (sck->sk_family != AF_LOCAL)) {
65536+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
65537+ return -EACCES;
65538+ }
65539+#endif
65540+ return 0;
65541+}
65542+
65543+int
65544+gr_handle_sock_client(const struct sockaddr *sck)
65545+{
65546+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65547+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
65548+ sck && (sck->sa_family != AF_UNIX) &&
65549+ (sck->sa_family != AF_LOCAL)) {
65550+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
65551+ return -EACCES;
65552+ }
65553+#endif
65554+ return 0;
65555+}
65556diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
65557new file mode 100644
65558index 0000000..f55ef0f
65559--- /dev/null
65560+++ b/grsecurity/grsec_sysctl.c
65561@@ -0,0 +1,469 @@
65562+#include <linux/kernel.h>
65563+#include <linux/sched.h>
65564+#include <linux/sysctl.h>
65565+#include <linux/grsecurity.h>
65566+#include <linux/grinternal.h>
65567+
65568+int
65569+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
65570+{
65571+#ifdef CONFIG_GRKERNSEC_SYSCTL
65572+ if (dirname == NULL || name == NULL)
65573+ return 0;
65574+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
65575+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
65576+ return -EACCES;
65577+ }
65578+#endif
65579+ return 0;
65580+}
65581+
65582+#ifdef CONFIG_GRKERNSEC_ROFS
65583+static int __maybe_unused one = 1;
65584+#endif
65585+
65586+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
65587+struct ctl_table grsecurity_table[] = {
65588+#ifdef CONFIG_GRKERNSEC_SYSCTL
65589+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
65590+#ifdef CONFIG_GRKERNSEC_IO
65591+ {
65592+ .procname = "disable_priv_io",
65593+ .data = &grsec_disable_privio,
65594+ .maxlen = sizeof(int),
65595+ .mode = 0600,
65596+ .proc_handler = &proc_dointvec,
65597+ },
65598+#endif
65599+#endif
65600+#ifdef CONFIG_GRKERNSEC_LINK
65601+ {
65602+ .procname = "linking_restrictions",
65603+ .data = &grsec_enable_link,
65604+ .maxlen = sizeof(int),
65605+ .mode = 0600,
65606+ .proc_handler = &proc_dointvec,
65607+ },
65608+#endif
65609+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65610+ {
65611+ .procname = "enforce_symlinksifowner",
65612+ .data = &grsec_enable_symlinkown,
65613+ .maxlen = sizeof(int),
65614+ .mode = 0600,
65615+ .proc_handler = &proc_dointvec,
65616+ },
65617+ {
65618+ .procname = "symlinkown_gid",
65619+ .data = &grsec_symlinkown_gid,
65620+ .maxlen = sizeof(int),
65621+ .mode = 0600,
65622+ .proc_handler = &proc_dointvec,
65623+ },
65624+#endif
65625+#ifdef CONFIG_GRKERNSEC_BRUTE
65626+ {
65627+ .procname = "deter_bruteforce",
65628+ .data = &grsec_enable_brute,
65629+ .maxlen = sizeof(int),
65630+ .mode = 0600,
65631+ .proc_handler = &proc_dointvec,
65632+ },
65633+#endif
65634+#ifdef CONFIG_GRKERNSEC_FIFO
65635+ {
65636+ .procname = "fifo_restrictions",
65637+ .data = &grsec_enable_fifo,
65638+ .maxlen = sizeof(int),
65639+ .mode = 0600,
65640+ .proc_handler = &proc_dointvec,
65641+ },
65642+#endif
65643+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65644+ {
65645+ .procname = "ptrace_readexec",
65646+ .data = &grsec_enable_ptrace_readexec,
65647+ .maxlen = sizeof(int),
65648+ .mode = 0600,
65649+ .proc_handler = &proc_dointvec,
65650+ },
65651+#endif
65652+#ifdef CONFIG_GRKERNSEC_SETXID
65653+ {
65654+ .procname = "consistent_setxid",
65655+ .data = &grsec_enable_setxid,
65656+ .maxlen = sizeof(int),
65657+ .mode = 0600,
65658+ .proc_handler = &proc_dointvec,
65659+ },
65660+#endif
65661+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65662+ {
65663+ .procname = "ip_blackhole",
65664+ .data = &grsec_enable_blackhole,
65665+ .maxlen = sizeof(int),
65666+ .mode = 0600,
65667+ .proc_handler = &proc_dointvec,
65668+ },
65669+ {
65670+ .procname = "lastack_retries",
65671+ .data = &grsec_lastack_retries,
65672+ .maxlen = sizeof(int),
65673+ .mode = 0600,
65674+ .proc_handler = &proc_dointvec,
65675+ },
65676+#endif
65677+#ifdef CONFIG_GRKERNSEC_EXECLOG
65678+ {
65679+ .procname = "exec_logging",
65680+ .data = &grsec_enable_execlog,
65681+ .maxlen = sizeof(int),
65682+ .mode = 0600,
65683+ .proc_handler = &proc_dointvec,
65684+ },
65685+#endif
65686+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65687+ {
65688+ .procname = "rwxmap_logging",
65689+ .data = &grsec_enable_log_rwxmaps,
65690+ .maxlen = sizeof(int),
65691+ .mode = 0600,
65692+ .proc_handler = &proc_dointvec,
65693+ },
65694+#endif
65695+#ifdef CONFIG_GRKERNSEC_SIGNAL
65696+ {
65697+ .procname = "signal_logging",
65698+ .data = &grsec_enable_signal,
65699+ .maxlen = sizeof(int),
65700+ .mode = 0600,
65701+ .proc_handler = &proc_dointvec,
65702+ },
65703+#endif
65704+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65705+ {
65706+ .procname = "forkfail_logging",
65707+ .data = &grsec_enable_forkfail,
65708+ .maxlen = sizeof(int),
65709+ .mode = 0600,
65710+ .proc_handler = &proc_dointvec,
65711+ },
65712+#endif
65713+#ifdef CONFIG_GRKERNSEC_TIME
65714+ {
65715+ .procname = "timechange_logging",
65716+ .data = &grsec_enable_time,
65717+ .maxlen = sizeof(int),
65718+ .mode = 0600,
65719+ .proc_handler = &proc_dointvec,
65720+ },
65721+#endif
65722+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65723+ {
65724+ .procname = "chroot_deny_shmat",
65725+ .data = &grsec_enable_chroot_shmat,
65726+ .maxlen = sizeof(int),
65727+ .mode = 0600,
65728+ .proc_handler = &proc_dointvec,
65729+ },
65730+#endif
65731+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65732+ {
65733+ .procname = "chroot_deny_unix",
65734+ .data = &grsec_enable_chroot_unix,
65735+ .maxlen = sizeof(int),
65736+ .mode = 0600,
65737+ .proc_handler = &proc_dointvec,
65738+ },
65739+#endif
65740+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65741+ {
65742+ .procname = "chroot_deny_mount",
65743+ .data = &grsec_enable_chroot_mount,
65744+ .maxlen = sizeof(int),
65745+ .mode = 0600,
65746+ .proc_handler = &proc_dointvec,
65747+ },
65748+#endif
65749+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65750+ {
65751+ .procname = "chroot_deny_fchdir",
65752+ .data = &grsec_enable_chroot_fchdir,
65753+ .maxlen = sizeof(int),
65754+ .mode = 0600,
65755+ .proc_handler = &proc_dointvec,
65756+ },
65757+#endif
65758+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65759+ {
65760+ .procname = "chroot_deny_chroot",
65761+ .data = &grsec_enable_chroot_double,
65762+ .maxlen = sizeof(int),
65763+ .mode = 0600,
65764+ .proc_handler = &proc_dointvec,
65765+ },
65766+#endif
65767+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65768+ {
65769+ .procname = "chroot_deny_pivot",
65770+ .data = &grsec_enable_chroot_pivot,
65771+ .maxlen = sizeof(int),
65772+ .mode = 0600,
65773+ .proc_handler = &proc_dointvec,
65774+ },
65775+#endif
65776+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65777+ {
65778+ .procname = "chroot_enforce_chdir",
65779+ .data = &grsec_enable_chroot_chdir,
65780+ .maxlen = sizeof(int),
65781+ .mode = 0600,
65782+ .proc_handler = &proc_dointvec,
65783+ },
65784+#endif
65785+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65786+ {
65787+ .procname = "chroot_deny_chmod",
65788+ .data = &grsec_enable_chroot_chmod,
65789+ .maxlen = sizeof(int),
65790+ .mode = 0600,
65791+ .proc_handler = &proc_dointvec,
65792+ },
65793+#endif
65794+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65795+ {
65796+ .procname = "chroot_deny_mknod",
65797+ .data = &grsec_enable_chroot_mknod,
65798+ .maxlen = sizeof(int),
65799+ .mode = 0600,
65800+ .proc_handler = &proc_dointvec,
65801+ },
65802+#endif
65803+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65804+ {
65805+ .procname = "chroot_restrict_nice",
65806+ .data = &grsec_enable_chroot_nice,
65807+ .maxlen = sizeof(int),
65808+ .mode = 0600,
65809+ .proc_handler = &proc_dointvec,
65810+ },
65811+#endif
65812+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65813+ {
65814+ .procname = "chroot_execlog",
65815+ .data = &grsec_enable_chroot_execlog,
65816+ .maxlen = sizeof(int),
65817+ .mode = 0600,
65818+ .proc_handler = &proc_dointvec,
65819+ },
65820+#endif
65821+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65822+ {
65823+ .procname = "chroot_caps",
65824+ .data = &grsec_enable_chroot_caps,
65825+ .maxlen = sizeof(int),
65826+ .mode = 0600,
65827+ .proc_handler = &proc_dointvec,
65828+ },
65829+#endif
65830+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65831+ {
65832+ .procname = "chroot_deny_sysctl",
65833+ .data = &grsec_enable_chroot_sysctl,
65834+ .maxlen = sizeof(int),
65835+ .mode = 0600,
65836+ .proc_handler = &proc_dointvec,
65837+ },
65838+#endif
65839+#ifdef CONFIG_GRKERNSEC_TPE
65840+ {
65841+ .procname = "tpe",
65842+ .data = &grsec_enable_tpe,
65843+ .maxlen = sizeof(int),
65844+ .mode = 0600,
65845+ .proc_handler = &proc_dointvec,
65846+ },
65847+ {
65848+ .procname = "tpe_gid",
65849+ .data = &grsec_tpe_gid,
65850+ .maxlen = sizeof(int),
65851+ .mode = 0600,
65852+ .proc_handler = &proc_dointvec,
65853+ },
65854+#endif
65855+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65856+ {
65857+ .procname = "tpe_invert",
65858+ .data = &grsec_enable_tpe_invert,
65859+ .maxlen = sizeof(int),
65860+ .mode = 0600,
65861+ .proc_handler = &proc_dointvec,
65862+ },
65863+#endif
65864+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65865+ {
65866+ .procname = "tpe_restrict_all",
65867+ .data = &grsec_enable_tpe_all,
65868+ .maxlen = sizeof(int),
65869+ .mode = 0600,
65870+ .proc_handler = &proc_dointvec,
65871+ },
65872+#endif
65873+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65874+ {
65875+ .procname = "socket_all",
65876+ .data = &grsec_enable_socket_all,
65877+ .maxlen = sizeof(int),
65878+ .mode = 0600,
65879+ .proc_handler = &proc_dointvec,
65880+ },
65881+ {
65882+ .procname = "socket_all_gid",
65883+ .data = &grsec_socket_all_gid,
65884+ .maxlen = sizeof(int),
65885+ .mode = 0600,
65886+ .proc_handler = &proc_dointvec,
65887+ },
65888+#endif
65889+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65890+ {
65891+ .procname = "socket_client",
65892+ .data = &grsec_enable_socket_client,
65893+ .maxlen = sizeof(int),
65894+ .mode = 0600,
65895+ .proc_handler = &proc_dointvec,
65896+ },
65897+ {
65898+ .procname = "socket_client_gid",
65899+ .data = &grsec_socket_client_gid,
65900+ .maxlen = sizeof(int),
65901+ .mode = 0600,
65902+ .proc_handler = &proc_dointvec,
65903+ },
65904+#endif
65905+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65906+ {
65907+ .procname = "socket_server",
65908+ .data = &grsec_enable_socket_server,
65909+ .maxlen = sizeof(int),
65910+ .mode = 0600,
65911+ .proc_handler = &proc_dointvec,
65912+ },
65913+ {
65914+ .procname = "socket_server_gid",
65915+ .data = &grsec_socket_server_gid,
65916+ .maxlen = sizeof(int),
65917+ .mode = 0600,
65918+ .proc_handler = &proc_dointvec,
65919+ },
65920+#endif
65921+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65922+ {
65923+ .procname = "audit_group",
65924+ .data = &grsec_enable_group,
65925+ .maxlen = sizeof(int),
65926+ .mode = 0600,
65927+ .proc_handler = &proc_dointvec,
65928+ },
65929+ {
65930+ .procname = "audit_gid",
65931+ .data = &grsec_audit_gid,
65932+ .maxlen = sizeof(int),
65933+ .mode = 0600,
65934+ .proc_handler = &proc_dointvec,
65935+ },
65936+#endif
65937+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65938+ {
65939+ .procname = "audit_chdir",
65940+ .data = &grsec_enable_chdir,
65941+ .maxlen = sizeof(int),
65942+ .mode = 0600,
65943+ .proc_handler = &proc_dointvec,
65944+ },
65945+#endif
65946+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65947+ {
65948+ .procname = "audit_mount",
65949+ .data = &grsec_enable_mount,
65950+ .maxlen = sizeof(int),
65951+ .mode = 0600,
65952+ .proc_handler = &proc_dointvec,
65953+ },
65954+#endif
65955+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65956+ {
65957+ .procname = "audit_textrel",
65958+ .data = &grsec_enable_audit_textrel,
65959+ .maxlen = sizeof(int),
65960+ .mode = 0600,
65961+ .proc_handler = &proc_dointvec,
65962+ },
65963+#endif
65964+#ifdef CONFIG_GRKERNSEC_DMESG
65965+ {
65966+ .procname = "dmesg",
65967+ .data = &grsec_enable_dmesg,
65968+ .maxlen = sizeof(int),
65969+ .mode = 0600,
65970+ .proc_handler = &proc_dointvec,
65971+ },
65972+#endif
65973+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65974+ {
65975+ .procname = "chroot_findtask",
65976+ .data = &grsec_enable_chroot_findtask,
65977+ .maxlen = sizeof(int),
65978+ .mode = 0600,
65979+ .proc_handler = &proc_dointvec,
65980+ },
65981+#endif
65982+#ifdef CONFIG_GRKERNSEC_RESLOG
65983+ {
65984+ .procname = "resource_logging",
65985+ .data = &grsec_resource_logging,
65986+ .maxlen = sizeof(int),
65987+ .mode = 0600,
65988+ .proc_handler = &proc_dointvec,
65989+ },
65990+#endif
65991+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65992+ {
65993+ .procname = "audit_ptrace",
65994+ .data = &grsec_enable_audit_ptrace,
65995+ .maxlen = sizeof(int),
65996+ .mode = 0600,
65997+ .proc_handler = &proc_dointvec,
65998+ },
65999+#endif
66000+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
66001+ {
66002+ .procname = "harden_ptrace",
66003+ .data = &grsec_enable_harden_ptrace,
66004+ .maxlen = sizeof(int),
66005+ .mode = 0600,
66006+ .proc_handler = &proc_dointvec,
66007+ },
66008+#endif
66009+ {
66010+ .procname = "grsec_lock",
66011+ .data = &grsec_lock,
66012+ .maxlen = sizeof(int),
66013+ .mode = 0600,
66014+ .proc_handler = &proc_dointvec,
66015+ },
66016+#endif
66017+#ifdef CONFIG_GRKERNSEC_ROFS
66018+ {
66019+ .procname = "romount_protect",
66020+ .data = &grsec_enable_rofs,
66021+ .maxlen = sizeof(int),
66022+ .mode = 0600,
66023+ .proc_handler = &proc_dointvec_minmax,
66024+ .extra1 = &one,
66025+ .extra2 = &one,
66026+ },
66027+#endif
66028+ { }
66029+};
66030+#endif
66031diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
66032new file mode 100644
66033index 0000000..0dc13c3
66034--- /dev/null
66035+++ b/grsecurity/grsec_time.c
66036@@ -0,0 +1,16 @@
66037+#include <linux/kernel.h>
66038+#include <linux/sched.h>
66039+#include <linux/grinternal.h>
66040+#include <linux/module.h>
66041+
66042+void
66043+gr_log_timechange(void)
66044+{
66045+#ifdef CONFIG_GRKERNSEC_TIME
66046+ if (grsec_enable_time)
66047+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
66048+#endif
66049+ return;
66050+}
66051+
66052+EXPORT_SYMBOL(gr_log_timechange);
66053diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
66054new file mode 100644
66055index 0000000..ee57dcf
66056--- /dev/null
66057+++ b/grsecurity/grsec_tpe.c
66058@@ -0,0 +1,73 @@
66059+#include <linux/kernel.h>
66060+#include <linux/sched.h>
66061+#include <linux/file.h>
66062+#include <linux/fs.h>
66063+#include <linux/grinternal.h>
66064+
66065+extern int gr_acl_tpe_check(void);
66066+
66067+int
66068+gr_tpe_allow(const struct file *file)
66069+{
66070+#ifdef CONFIG_GRKERNSEC
66071+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
66072+ const struct cred *cred = current_cred();
66073+ char *msg = NULL;
66074+ char *msg2 = NULL;
66075+
66076+ // never restrict root
66077+ if (gr_is_global_root(cred->uid))
66078+ return 1;
66079+
66080+ if (grsec_enable_tpe) {
66081+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
66082+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
66083+ msg = "not being in trusted group";
66084+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
66085+ msg = "being in untrusted group";
66086+#else
66087+ if (in_group_p(grsec_tpe_gid))
66088+ msg = "being in untrusted group";
66089+#endif
66090+ }
66091+ if (!msg && gr_acl_tpe_check())
66092+ msg = "being in untrusted role";
66093+
66094+ // not in any affected group/role
66095+ if (!msg)
66096+ goto next_check;
66097+
66098+ if (gr_is_global_nonroot(inode->i_uid))
66099+ msg2 = "file in non-root-owned directory";
66100+ else if (inode->i_mode & S_IWOTH)
66101+ msg2 = "file in world-writable directory";
66102+ else if (inode->i_mode & S_IWGRP)
66103+ msg2 = "file in group-writable directory";
66104+
66105+ if (msg && msg2) {
66106+ char fullmsg[70] = {0};
66107+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
66108+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
66109+ return 0;
66110+ }
66111+ msg = NULL;
66112+next_check:
66113+#ifdef CONFIG_GRKERNSEC_TPE_ALL
66114+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
66115+ return 1;
66116+
66117+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
66118+ msg = "directory not owned by user";
66119+ else if (inode->i_mode & S_IWOTH)
66120+ msg = "file in world-writable directory";
66121+ else if (inode->i_mode & S_IWGRP)
66122+ msg = "file in group-writable directory";
66123+
66124+ if (msg) {
66125+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
66126+ return 0;
66127+ }
66128+#endif
66129+#endif
66130+ return 1;
66131+}
66132diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
66133new file mode 100644
66134index 0000000..9f7b1ac
66135--- /dev/null
66136+++ b/grsecurity/grsum.c
66137@@ -0,0 +1,61 @@
66138+#include <linux/err.h>
66139+#include <linux/kernel.h>
66140+#include <linux/sched.h>
66141+#include <linux/mm.h>
66142+#include <linux/scatterlist.h>
66143+#include <linux/crypto.h>
66144+#include <linux/gracl.h>
66145+
66146+
66147+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
66148+#error "crypto and sha256 must be built into the kernel"
66149+#endif
66150+
66151+int
66152+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
66153+{
66154+ char *p;
66155+ struct crypto_hash *tfm;
66156+ struct hash_desc desc;
66157+ struct scatterlist sg;
66158+ unsigned char temp_sum[GR_SHA_LEN];
66159+ volatile int retval = 0;
66160+ volatile int dummy = 0;
66161+ unsigned int i;
66162+
66163+ sg_init_table(&sg, 1);
66164+
66165+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
66166+ if (IS_ERR(tfm)) {
66167+ /* should never happen, since sha256 should be built in */
66168+ return 1;
66169+ }
66170+
66171+ desc.tfm = tfm;
66172+ desc.flags = 0;
66173+
66174+ crypto_hash_init(&desc);
66175+
66176+ p = salt;
66177+ sg_set_buf(&sg, p, GR_SALT_LEN);
66178+ crypto_hash_update(&desc, &sg, sg.length);
66179+
66180+ p = entry->pw;
66181+ sg_set_buf(&sg, p, strlen(p));
66182+
66183+ crypto_hash_update(&desc, &sg, sg.length);
66184+
66185+ crypto_hash_final(&desc, temp_sum);
66186+
66187+ memset(entry->pw, 0, GR_PW_LEN);
66188+
66189+ for (i = 0; i < GR_SHA_LEN; i++)
66190+ if (sum[i] != temp_sum[i])
66191+ retval = 1;
66192+ else
66193+ dummy = 1; // waste a cycle
66194+
66195+ crypto_free_hash(tfm);
66196+
66197+ return retval;
66198+}
66199diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
66200index 77ff547..181834f 100644
66201--- a/include/asm-generic/4level-fixup.h
66202+++ b/include/asm-generic/4level-fixup.h
66203@@ -13,8 +13,10 @@
66204 #define pmd_alloc(mm, pud, address) \
66205 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
66206 NULL: pmd_offset(pud, address))
66207+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
66208
66209 #define pud_alloc(mm, pgd, address) (pgd)
66210+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
66211 #define pud_offset(pgd, start) (pgd)
66212 #define pud_none(pud) 0
66213 #define pud_bad(pud) 0
66214diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
66215index b7babf0..04ad282 100644
66216--- a/include/asm-generic/atomic-long.h
66217+++ b/include/asm-generic/atomic-long.h
66218@@ -22,6 +22,12 @@
66219
66220 typedef atomic64_t atomic_long_t;
66221
66222+#ifdef CONFIG_PAX_REFCOUNT
66223+typedef atomic64_unchecked_t atomic_long_unchecked_t;
66224+#else
66225+typedef atomic64_t atomic_long_unchecked_t;
66226+#endif
66227+
66228 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
66229
66230 static inline long atomic_long_read(atomic_long_t *l)
66231@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
66232 return (long)atomic64_read(v);
66233 }
66234
66235+#ifdef CONFIG_PAX_REFCOUNT
66236+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
66237+{
66238+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66239+
66240+ return (long)atomic64_read_unchecked(v);
66241+}
66242+#endif
66243+
66244 static inline void atomic_long_set(atomic_long_t *l, long i)
66245 {
66246 atomic64_t *v = (atomic64_t *)l;
66247@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
66248 atomic64_set(v, i);
66249 }
66250
66251+#ifdef CONFIG_PAX_REFCOUNT
66252+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
66253+{
66254+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66255+
66256+ atomic64_set_unchecked(v, i);
66257+}
66258+#endif
66259+
66260 static inline void atomic_long_inc(atomic_long_t *l)
66261 {
66262 atomic64_t *v = (atomic64_t *)l;
66263@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
66264 atomic64_inc(v);
66265 }
66266
66267+#ifdef CONFIG_PAX_REFCOUNT
66268+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
66269+{
66270+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66271+
66272+ atomic64_inc_unchecked(v);
66273+}
66274+#endif
66275+
66276 static inline void atomic_long_dec(atomic_long_t *l)
66277 {
66278 atomic64_t *v = (atomic64_t *)l;
66279@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
66280 atomic64_dec(v);
66281 }
66282
66283+#ifdef CONFIG_PAX_REFCOUNT
66284+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
66285+{
66286+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66287+
66288+ atomic64_dec_unchecked(v);
66289+}
66290+#endif
66291+
66292 static inline void atomic_long_add(long i, atomic_long_t *l)
66293 {
66294 atomic64_t *v = (atomic64_t *)l;
66295@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
66296 atomic64_add(i, v);
66297 }
66298
66299+#ifdef CONFIG_PAX_REFCOUNT
66300+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
66301+{
66302+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66303+
66304+ atomic64_add_unchecked(i, v);
66305+}
66306+#endif
66307+
66308 static inline void atomic_long_sub(long i, atomic_long_t *l)
66309 {
66310 atomic64_t *v = (atomic64_t *)l;
66311@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
66312 atomic64_sub(i, v);
66313 }
66314
66315+#ifdef CONFIG_PAX_REFCOUNT
66316+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
66317+{
66318+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66319+
66320+ atomic64_sub_unchecked(i, v);
66321+}
66322+#endif
66323+
66324 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
66325 {
66326 atomic64_t *v = (atomic64_t *)l;
66327@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
66328 return (long)atomic64_add_return(i, v);
66329 }
66330
66331+#ifdef CONFIG_PAX_REFCOUNT
66332+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
66333+{
66334+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66335+
66336+ return (long)atomic64_add_return_unchecked(i, v);
66337+}
66338+#endif
66339+
66340 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
66341 {
66342 atomic64_t *v = (atomic64_t *)l;
66343@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
66344 return (long)atomic64_inc_return(v);
66345 }
66346
66347+#ifdef CONFIG_PAX_REFCOUNT
66348+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
66349+{
66350+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66351+
66352+ return (long)atomic64_inc_return_unchecked(v);
66353+}
66354+#endif
66355+
66356 static inline long atomic_long_dec_return(atomic_long_t *l)
66357 {
66358 atomic64_t *v = (atomic64_t *)l;
66359@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
66360
66361 typedef atomic_t atomic_long_t;
66362
66363+#ifdef CONFIG_PAX_REFCOUNT
66364+typedef atomic_unchecked_t atomic_long_unchecked_t;
66365+#else
66366+typedef atomic_t atomic_long_unchecked_t;
66367+#endif
66368+
66369 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
66370 static inline long atomic_long_read(atomic_long_t *l)
66371 {
66372@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
66373 return (long)atomic_read(v);
66374 }
66375
66376+#ifdef CONFIG_PAX_REFCOUNT
66377+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
66378+{
66379+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66380+
66381+ return (long)atomic_read_unchecked(v);
66382+}
66383+#endif
66384+
66385 static inline void atomic_long_set(atomic_long_t *l, long i)
66386 {
66387 atomic_t *v = (atomic_t *)l;
66388@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
66389 atomic_set(v, i);
66390 }
66391
66392+#ifdef CONFIG_PAX_REFCOUNT
66393+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
66394+{
66395+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66396+
66397+ atomic_set_unchecked(v, i);
66398+}
66399+#endif
66400+
66401 static inline void atomic_long_inc(atomic_long_t *l)
66402 {
66403 atomic_t *v = (atomic_t *)l;
66404@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
66405 atomic_inc(v);
66406 }
66407
66408+#ifdef CONFIG_PAX_REFCOUNT
66409+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
66410+{
66411+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66412+
66413+ atomic_inc_unchecked(v);
66414+}
66415+#endif
66416+
66417 static inline void atomic_long_dec(atomic_long_t *l)
66418 {
66419 atomic_t *v = (atomic_t *)l;
66420@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
66421 atomic_dec(v);
66422 }
66423
66424+#ifdef CONFIG_PAX_REFCOUNT
66425+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
66426+{
66427+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66428+
66429+ atomic_dec_unchecked(v);
66430+}
66431+#endif
66432+
66433 static inline void atomic_long_add(long i, atomic_long_t *l)
66434 {
66435 atomic_t *v = (atomic_t *)l;
66436@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
66437 atomic_add(i, v);
66438 }
66439
66440+#ifdef CONFIG_PAX_REFCOUNT
66441+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
66442+{
66443+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66444+
66445+ atomic_add_unchecked(i, v);
66446+}
66447+#endif
66448+
66449 static inline void atomic_long_sub(long i, atomic_long_t *l)
66450 {
66451 atomic_t *v = (atomic_t *)l;
66452@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
66453 atomic_sub(i, v);
66454 }
66455
66456+#ifdef CONFIG_PAX_REFCOUNT
66457+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
66458+{
66459+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66460+
66461+ atomic_sub_unchecked(i, v);
66462+}
66463+#endif
66464+
66465 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
66466 {
66467 atomic_t *v = (atomic_t *)l;
66468@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
66469 return (long)atomic_add_return(i, v);
66470 }
66471
66472+#ifdef CONFIG_PAX_REFCOUNT
66473+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
66474+{
66475+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66476+
66477+ return (long)atomic_add_return_unchecked(i, v);
66478+}
66479+
66480+#endif
66481+
66482 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
66483 {
66484 atomic_t *v = (atomic_t *)l;
66485@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
66486 return (long)atomic_inc_return(v);
66487 }
66488
66489+#ifdef CONFIG_PAX_REFCOUNT
66490+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
66491+{
66492+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66493+
66494+ return (long)atomic_inc_return_unchecked(v);
66495+}
66496+#endif
66497+
66498 static inline long atomic_long_dec_return(atomic_long_t *l)
66499 {
66500 atomic_t *v = (atomic_t *)l;
66501@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
66502
66503 #endif /* BITS_PER_LONG == 64 */
66504
66505+#ifdef CONFIG_PAX_REFCOUNT
66506+static inline void pax_refcount_needs_these_functions(void)
66507+{
66508+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
66509+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
66510+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
66511+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
66512+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
66513+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
66514+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
66515+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
66516+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
66517+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
66518+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
66519+#ifdef CONFIG_X86
66520+ atomic_clear_mask_unchecked(0, NULL);
66521+ atomic_set_mask_unchecked(0, NULL);
66522+#endif
66523+
66524+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
66525+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
66526+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
66527+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
66528+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
66529+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
66530+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
66531+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
66532+}
66533+#else
66534+#define atomic_read_unchecked(v) atomic_read(v)
66535+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
66536+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
66537+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
66538+#define atomic_inc_unchecked(v) atomic_inc(v)
66539+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
66540+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
66541+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
66542+#define atomic_dec_unchecked(v) atomic_dec(v)
66543+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
66544+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
66545+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
66546+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
66547+
66548+#define atomic_long_read_unchecked(v) atomic_long_read(v)
66549+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
66550+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
66551+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
66552+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
66553+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
66554+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
66555+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
66556+#endif
66557+
66558 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
66559diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
66560index 1ced641..c896ee8 100644
66561--- a/include/asm-generic/atomic.h
66562+++ b/include/asm-generic/atomic.h
66563@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
66564 * Atomically clears the bits set in @mask from @v
66565 */
66566 #ifndef atomic_clear_mask
66567-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
66568+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
66569 {
66570 unsigned long flags;
66571
66572diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
66573index b18ce4f..2ee2843 100644
66574--- a/include/asm-generic/atomic64.h
66575+++ b/include/asm-generic/atomic64.h
66576@@ -16,6 +16,8 @@ typedef struct {
66577 long long counter;
66578 } atomic64_t;
66579
66580+typedef atomic64_t atomic64_unchecked_t;
66581+
66582 #define ATOMIC64_INIT(i) { (i) }
66583
66584 extern long long atomic64_read(const atomic64_t *v);
66585@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
66586 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
66587 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
66588
66589+#define atomic64_read_unchecked(v) atomic64_read(v)
66590+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
66591+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
66592+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
66593+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
66594+#define atomic64_inc_unchecked(v) atomic64_inc(v)
66595+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
66596+#define atomic64_dec_unchecked(v) atomic64_dec(v)
66597+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
66598+
66599 #endif /* _ASM_GENERIC_ATOMIC64_H */
66600diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
66601index 1bfcfe5..e04c5c9 100644
66602--- a/include/asm-generic/cache.h
66603+++ b/include/asm-generic/cache.h
66604@@ -6,7 +6,7 @@
66605 * cache lines need to provide their own cache.h.
66606 */
66607
66608-#define L1_CACHE_SHIFT 5
66609-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
66610+#define L1_CACHE_SHIFT 5UL
66611+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
66612
66613 #endif /* __ASM_GENERIC_CACHE_H */
66614diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
66615index 0d68a1e..b74a761 100644
66616--- a/include/asm-generic/emergency-restart.h
66617+++ b/include/asm-generic/emergency-restart.h
66618@@ -1,7 +1,7 @@
66619 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
66620 #define _ASM_GENERIC_EMERGENCY_RESTART_H
66621
66622-static inline void machine_emergency_restart(void)
66623+static inline __noreturn void machine_emergency_restart(void)
66624 {
66625 machine_restart(NULL);
66626 }
66627diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
66628index 90f99c7..00ce236 100644
66629--- a/include/asm-generic/kmap_types.h
66630+++ b/include/asm-generic/kmap_types.h
66631@@ -2,9 +2,9 @@
66632 #define _ASM_GENERIC_KMAP_TYPES_H
66633
66634 #ifdef __WITH_KM_FENCE
66635-# define KM_TYPE_NR 41
66636+# define KM_TYPE_NR 42
66637 #else
66638-# define KM_TYPE_NR 20
66639+# define KM_TYPE_NR 21
66640 #endif
66641
66642 #endif
66643diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
66644index 9ceb03b..62b0b8f 100644
66645--- a/include/asm-generic/local.h
66646+++ b/include/asm-generic/local.h
66647@@ -23,24 +23,37 @@ typedef struct
66648 atomic_long_t a;
66649 } local_t;
66650
66651+typedef struct {
66652+ atomic_long_unchecked_t a;
66653+} local_unchecked_t;
66654+
66655 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
66656
66657 #define local_read(l) atomic_long_read(&(l)->a)
66658+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
66659 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
66660+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
66661 #define local_inc(l) atomic_long_inc(&(l)->a)
66662+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
66663 #define local_dec(l) atomic_long_dec(&(l)->a)
66664+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
66665 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
66666+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
66667 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
66668+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
66669
66670 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
66671 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
66672 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
66673 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
66674 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
66675+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
66676 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
66677 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
66678+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
66679
66680 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66681+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66682 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
66683 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
66684 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
66685diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
66686index 725612b..9cc513a 100644
66687--- a/include/asm-generic/pgtable-nopmd.h
66688+++ b/include/asm-generic/pgtable-nopmd.h
66689@@ -1,14 +1,19 @@
66690 #ifndef _PGTABLE_NOPMD_H
66691 #define _PGTABLE_NOPMD_H
66692
66693-#ifndef __ASSEMBLY__
66694-
66695 #include <asm-generic/pgtable-nopud.h>
66696
66697-struct mm_struct;
66698-
66699 #define __PAGETABLE_PMD_FOLDED
66700
66701+#define PMD_SHIFT PUD_SHIFT
66702+#define PTRS_PER_PMD 1
66703+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
66704+#define PMD_MASK (~(PMD_SIZE-1))
66705+
66706+#ifndef __ASSEMBLY__
66707+
66708+struct mm_struct;
66709+
66710 /*
66711 * Having the pmd type consist of a pud gets the size right, and allows
66712 * us to conceptually access the pud entry that this pmd is folded into
66713@@ -16,11 +21,6 @@ struct mm_struct;
66714 */
66715 typedef struct { pud_t pud; } pmd_t;
66716
66717-#define PMD_SHIFT PUD_SHIFT
66718-#define PTRS_PER_PMD 1
66719-#define PMD_SIZE (1UL << PMD_SHIFT)
66720-#define PMD_MASK (~(PMD_SIZE-1))
66721-
66722 /*
66723 * The "pud_xxx()" functions here are trivial for a folded two-level
66724 * setup: the pmd is never bad, and a pmd always exists (as it's folded
66725diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
66726index 810431d..0ec4804f 100644
66727--- a/include/asm-generic/pgtable-nopud.h
66728+++ b/include/asm-generic/pgtable-nopud.h
66729@@ -1,10 +1,15 @@
66730 #ifndef _PGTABLE_NOPUD_H
66731 #define _PGTABLE_NOPUD_H
66732
66733-#ifndef __ASSEMBLY__
66734-
66735 #define __PAGETABLE_PUD_FOLDED
66736
66737+#define PUD_SHIFT PGDIR_SHIFT
66738+#define PTRS_PER_PUD 1
66739+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
66740+#define PUD_MASK (~(PUD_SIZE-1))
66741+
66742+#ifndef __ASSEMBLY__
66743+
66744 /*
66745 * Having the pud type consist of a pgd gets the size right, and allows
66746 * us to conceptually access the pgd entry that this pud is folded into
66747@@ -12,11 +17,6 @@
66748 */
66749 typedef struct { pgd_t pgd; } pud_t;
66750
66751-#define PUD_SHIFT PGDIR_SHIFT
66752-#define PTRS_PER_PUD 1
66753-#define PUD_SIZE (1UL << PUD_SHIFT)
66754-#define PUD_MASK (~(PUD_SIZE-1))
66755-
66756 /*
66757 * The "pgd_xxx()" functions here are trivial for a folded two-level
66758 * setup: the pud is never bad, and a pud always exists (as it's folded
66759@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
66760 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
66761
66762 #define pgd_populate(mm, pgd, pud) do { } while (0)
66763+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
66764 /*
66765 * (puds are folded into pgds so this doesn't get actually called,
66766 * but the define is needed for a generic inline function.)
66767diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
66768index 5cf680a..4b74d62 100644
66769--- a/include/asm-generic/pgtable.h
66770+++ b/include/asm-generic/pgtable.h
66771@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
66772 }
66773 #endif /* CONFIG_NUMA_BALANCING */
66774
66775+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
66776+static inline unsigned long pax_open_kernel(void) { return 0; }
66777+#endif
66778+
66779+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
66780+static inline unsigned long pax_close_kernel(void) { return 0; }
66781+#endif
66782+
66783 #endif /* CONFIG_MMU */
66784
66785 #endif /* !__ASSEMBLY__ */
66786diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
66787index d1ea7ce..b1ebf2a 100644
66788--- a/include/asm-generic/vmlinux.lds.h
66789+++ b/include/asm-generic/vmlinux.lds.h
66790@@ -218,6 +218,7 @@
66791 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
66792 VMLINUX_SYMBOL(__start_rodata) = .; \
66793 *(.rodata) *(.rodata.*) \
66794+ *(.data..read_only) \
66795 *(__vermagic) /* Kernel version magic */ \
66796 . = ALIGN(8); \
66797 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
66798@@ -725,17 +726,18 @@
66799 * section in the linker script will go there too. @phdr should have
66800 * a leading colon.
66801 *
66802- * Note that this macros defines __per_cpu_load as an absolute symbol.
66803+ * Note that this macros defines per_cpu_load as an absolute symbol.
66804 * If there is no need to put the percpu section at a predetermined
66805 * address, use PERCPU_SECTION.
66806 */
66807 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
66808- VMLINUX_SYMBOL(__per_cpu_load) = .; \
66809- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
66810+ per_cpu_load = .; \
66811+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
66812 - LOAD_OFFSET) { \
66813+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
66814 PERCPU_INPUT(cacheline) \
66815 } phdr \
66816- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
66817+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
66818
66819 /**
66820 * PERCPU_SECTION - define output section for percpu area, simple version
66821diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
66822index 418d270..bfd2794 100644
66823--- a/include/crypto/algapi.h
66824+++ b/include/crypto/algapi.h
66825@@ -34,7 +34,7 @@ struct crypto_type {
66826 unsigned int maskclear;
66827 unsigned int maskset;
66828 unsigned int tfmsize;
66829-};
66830+} __do_const;
66831
66832 struct crypto_instance {
66833 struct crypto_alg alg;
66834diff --git a/include/drm/drmP.h b/include/drm/drmP.h
66835index fad21c9..ab858bc 100644
66836--- a/include/drm/drmP.h
66837+++ b/include/drm/drmP.h
66838@@ -72,6 +72,7 @@
66839 #include <linux/workqueue.h>
66840 #include <linux/poll.h>
66841 #include <asm/pgalloc.h>
66842+#include <asm/local.h>
66843 #include <drm/drm.h>
66844 #include <drm/drm_sarea.h>
66845
66846@@ -293,10 +294,12 @@ do { \
66847 * \param cmd command.
66848 * \param arg argument.
66849 */
66850-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
66851+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
66852+ struct drm_file *file_priv);
66853+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
66854 struct drm_file *file_priv);
66855
66856-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66857+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
66858 unsigned long arg);
66859
66860 #define DRM_IOCTL_NR(n) _IOC_NR(n)
66861@@ -311,9 +314,9 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66862 struct drm_ioctl_desc {
66863 unsigned int cmd;
66864 int flags;
66865- drm_ioctl_t *func;
66866+ drm_ioctl_t func;
66867 unsigned int cmd_drv;
66868-};
66869+} __do_const;
66870
66871 /**
66872 * Creates a driver or general drm_ioctl_desc array entry for the given
66873@@ -995,7 +998,7 @@ struct drm_info_list {
66874 int (*show)(struct seq_file*, void*); /** show callback */
66875 u32 driver_features; /**< Required driver features for this entry */
66876 void *data;
66877-};
66878+} __do_const;
66879
66880 /**
66881 * debugfs node structure. This structure represents a debugfs file.
66882@@ -1068,7 +1071,7 @@ struct drm_device {
66883
66884 /** \name Usage Counters */
66885 /*@{ */
66886- int open_count; /**< Outstanding files open */
66887+ local_t open_count; /**< Outstanding files open */
66888 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
66889 atomic_t vma_count; /**< Outstanding vma areas open */
66890 int buf_use; /**< Buffers in use -- cannot alloc */
66891@@ -1079,7 +1082,7 @@ struct drm_device {
66892 /*@{ */
66893 unsigned long counters;
66894 enum drm_stat_type types[15];
66895- atomic_t counts[15];
66896+ atomic_unchecked_t counts[15];
66897 /*@} */
66898
66899 struct list_head filelist;
66900diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
66901index f43d556..94d9343 100644
66902--- a/include/drm/drm_crtc_helper.h
66903+++ b/include/drm/drm_crtc_helper.h
66904@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
66905 struct drm_connector *connector);
66906 /* disable encoder when not in use - more explicit than dpms off */
66907 void (*disable)(struct drm_encoder *encoder);
66908-};
66909+} __no_const;
66910
66911 /**
66912 * drm_connector_helper_funcs - helper operations for connectors
66913diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
66914index 72dcbe8..8db58d7 100644
66915--- a/include/drm/ttm/ttm_memory.h
66916+++ b/include/drm/ttm/ttm_memory.h
66917@@ -48,7 +48,7 @@
66918
66919 struct ttm_mem_shrink {
66920 int (*do_shrink) (struct ttm_mem_shrink *);
66921-};
66922+} __no_const;
66923
66924 /**
66925 * struct ttm_mem_global - Global memory accounting structure.
66926diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
66927index 4b840e8..155d235 100644
66928--- a/include/keys/asymmetric-subtype.h
66929+++ b/include/keys/asymmetric-subtype.h
66930@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
66931 /* Verify the signature on a key of this subtype (optional) */
66932 int (*verify_signature)(const struct key *key,
66933 const struct public_key_signature *sig);
66934-};
66935+} __do_const;
66936
66937 /**
66938 * asymmetric_key_subtype - Get the subtype from an asymmetric key
66939diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
66940index c1da539..1dcec55 100644
66941--- a/include/linux/atmdev.h
66942+++ b/include/linux/atmdev.h
66943@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
66944 #endif
66945
66946 struct k_atm_aal_stats {
66947-#define __HANDLE_ITEM(i) atomic_t i
66948+#define __HANDLE_ITEM(i) atomic_unchecked_t i
66949 __AAL_STAT_ITEMS
66950 #undef __HANDLE_ITEM
66951 };
66952@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
66953 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
66954 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
66955 struct module *owner;
66956-};
66957+} __do_const ;
66958
66959 struct atmphy_ops {
66960 int (*start)(struct atm_dev *dev);
66961diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
66962index 0530b98..96a8ac0 100644
66963--- a/include/linux/binfmts.h
66964+++ b/include/linux/binfmts.h
66965@@ -73,8 +73,9 @@ struct linux_binfmt {
66966 int (*load_binary)(struct linux_binprm *);
66967 int (*load_shlib)(struct file *);
66968 int (*core_dump)(struct coredump_params *cprm);
66969+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
66970 unsigned long min_coredump; /* minimal dump size */
66971-};
66972+} __do_const;
66973
66974 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
66975
66976diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
66977index f94bc83..62b9cfe 100644
66978--- a/include/linux/blkdev.h
66979+++ b/include/linux/blkdev.h
66980@@ -1498,7 +1498,7 @@ struct block_device_operations {
66981 /* this callback is with swap_lock and sometimes page table lock held */
66982 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
66983 struct module *owner;
66984-};
66985+} __do_const;
66986
66987 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
66988 unsigned long);
66989diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
66990index 7c2e030..b72475d 100644
66991--- a/include/linux/blktrace_api.h
66992+++ b/include/linux/blktrace_api.h
66993@@ -23,7 +23,7 @@ struct blk_trace {
66994 struct dentry *dir;
66995 struct dentry *dropped_file;
66996 struct dentry *msg_file;
66997- atomic_t dropped;
66998+ atomic_unchecked_t dropped;
66999 };
67000
67001 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
67002diff --git a/include/linux/cache.h b/include/linux/cache.h
67003index 4c57065..4307975 100644
67004--- a/include/linux/cache.h
67005+++ b/include/linux/cache.h
67006@@ -16,6 +16,10 @@
67007 #define __read_mostly
67008 #endif
67009
67010+#ifndef __read_only
67011+#define __read_only __read_mostly
67012+#endif
67013+
67014 #ifndef ____cacheline_aligned
67015 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
67016 #endif
67017diff --git a/include/linux/capability.h b/include/linux/capability.h
67018index 98503b7..cc36d18 100644
67019--- a/include/linux/capability.h
67020+++ b/include/linux/capability.h
67021@@ -211,8 +211,13 @@ extern bool capable(int cap);
67022 extern bool ns_capable(struct user_namespace *ns, int cap);
67023 extern bool nsown_capable(int cap);
67024 extern bool inode_capable(const struct inode *inode, int cap);
67025+extern bool capable_nolog(int cap);
67026+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
67027+extern bool inode_capable_nolog(const struct inode *inode, int cap);
67028
67029 /* audit system wants to get cap info from files as well */
67030 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
67031
67032+extern int is_privileged_binary(const struct dentry *dentry);
67033+
67034 #endif /* !_LINUX_CAPABILITY_H */
67035diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
67036index 8609d57..86e4d79 100644
67037--- a/include/linux/cdrom.h
67038+++ b/include/linux/cdrom.h
67039@@ -87,7 +87,6 @@ struct cdrom_device_ops {
67040
67041 /* driver specifications */
67042 const int capability; /* capability flags */
67043- int n_minors; /* number of active minor devices */
67044 /* handle uniform packets for scsi type devices (scsi,atapi) */
67045 int (*generic_packet) (struct cdrom_device_info *,
67046 struct packet_command *);
67047diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
67048index 42e55de..1cd0e66 100644
67049--- a/include/linux/cleancache.h
67050+++ b/include/linux/cleancache.h
67051@@ -31,7 +31,7 @@ struct cleancache_ops {
67052 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
67053 void (*invalidate_inode)(int, struct cleancache_filekey);
67054 void (*invalidate_fs)(int);
67055-};
67056+} __no_const;
67057
67058 extern struct cleancache_ops
67059 cleancache_register_ops(struct cleancache_ops *ops);
67060diff --git a/include/linux/compat.h b/include/linux/compat.h
67061index dec7e2d..45db13f 100644
67062--- a/include/linux/compat.h
67063+++ b/include/linux/compat.h
67064@@ -311,14 +311,14 @@ long compat_sys_msgsnd(int first, int second, int third, void __user *uptr);
67065 long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
67066 int version, void __user *uptr);
67067 long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
67068- void __user *uptr);
67069+ void __user *uptr) __intentional_overflow(0);
67070 #else
67071 long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
67072 long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp,
67073 compat_ssize_t msgsz, int msgflg);
67074 long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp,
67075 compat_ssize_t msgsz, long msgtyp, int msgflg);
67076-long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
67077+long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
67078 #endif
67079 long compat_sys_msgctl(int first, int second, void __user *uptr);
67080 long compat_sys_shmctl(int first, int second, void __user *uptr);
67081@@ -414,7 +414,7 @@ extern int compat_ptrace_request(struct task_struct *child,
67082 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
67083 compat_ulong_t addr, compat_ulong_t data);
67084 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
67085- compat_long_t addr, compat_long_t data);
67086+ compat_ulong_t addr, compat_ulong_t data);
67087
67088 /*
67089 * epoll (fs/eventpoll.c) compat bits follow ...
67090diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
67091index 662fd1b..e801992 100644
67092--- a/include/linux/compiler-gcc4.h
67093+++ b/include/linux/compiler-gcc4.h
67094@@ -34,6 +34,21 @@
67095 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
67096
67097 #if __GNUC_MINOR__ >= 5
67098+
67099+#ifdef CONSTIFY_PLUGIN
67100+#define __no_const __attribute__((no_const))
67101+#define __do_const __attribute__((do_const))
67102+#endif
67103+
67104+#ifdef SIZE_OVERFLOW_PLUGIN
67105+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
67106+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
67107+#endif
67108+
67109+#ifdef LATENT_ENTROPY_PLUGIN
67110+#define __latent_entropy __attribute__((latent_entropy))
67111+#endif
67112+
67113 /*
67114 * Mark a position in code as unreachable. This can be used to
67115 * suppress control flow warnings after asm blocks that transfer
67116@@ -49,6 +64,11 @@
67117 #define __noclone __attribute__((__noclone__))
67118
67119 #endif
67120+
67121+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
67122+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
67123+#define __bos0(ptr) __bos((ptr), 0)
67124+#define __bos1(ptr) __bos((ptr), 1)
67125 #endif
67126
67127 #if __GNUC_MINOR__ >= 6
67128diff --git a/include/linux/compiler.h b/include/linux/compiler.h
67129index dd852b7..1ad5fba 100644
67130--- a/include/linux/compiler.h
67131+++ b/include/linux/compiler.h
67132@@ -5,11 +5,14 @@
67133
67134 #ifdef __CHECKER__
67135 # define __user __attribute__((noderef, address_space(1)))
67136+# define __force_user __force __user
67137 # define __kernel __attribute__((address_space(0)))
67138+# define __force_kernel __force __kernel
67139 # define __safe __attribute__((safe))
67140 # define __force __attribute__((force))
67141 # define __nocast __attribute__((nocast))
67142 # define __iomem __attribute__((noderef, address_space(2)))
67143+# define __force_iomem __force __iomem
67144 # define __must_hold(x) __attribute__((context(x,1,1)))
67145 # define __acquires(x) __attribute__((context(x,0,1)))
67146 # define __releases(x) __attribute__((context(x,1,0)))
67147@@ -17,20 +20,37 @@
67148 # define __release(x) __context__(x,-1)
67149 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
67150 # define __percpu __attribute__((noderef, address_space(3)))
67151+# define __force_percpu __force __percpu
67152 #ifdef CONFIG_SPARSE_RCU_POINTER
67153 # define __rcu __attribute__((noderef, address_space(4)))
67154+# define __force_rcu __force __rcu
67155 #else
67156 # define __rcu
67157+# define __force_rcu
67158 #endif
67159 extern void __chk_user_ptr(const volatile void __user *);
67160 extern void __chk_io_ptr(const volatile void __iomem *);
67161 #else
67162-# define __user
67163-# define __kernel
67164+# ifdef CHECKER_PLUGIN
67165+//# define __user
67166+//# define __force_user
67167+//# define __kernel
67168+//# define __force_kernel
67169+# else
67170+# ifdef STRUCTLEAK_PLUGIN
67171+# define __user __attribute__((user))
67172+# else
67173+# define __user
67174+# endif
67175+# define __force_user
67176+# define __kernel
67177+# define __force_kernel
67178+# endif
67179 # define __safe
67180 # define __force
67181 # define __nocast
67182 # define __iomem
67183+# define __force_iomem
67184 # define __chk_user_ptr(x) (void)0
67185 # define __chk_io_ptr(x) (void)0
67186 # define __builtin_warning(x, y...) (1)
67187@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
67188 # define __release(x) (void)0
67189 # define __cond_lock(x,c) (c)
67190 # define __percpu
67191+# define __force_percpu
67192 # define __rcu
67193+# define __force_rcu
67194 #endif
67195
67196 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
67197@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67198 # define __attribute_const__ /* unimplemented */
67199 #endif
67200
67201+#ifndef __no_const
67202+# define __no_const
67203+#endif
67204+
67205+#ifndef __do_const
67206+# define __do_const
67207+#endif
67208+
67209+#ifndef __size_overflow
67210+# define __size_overflow(...)
67211+#endif
67212+
67213+#ifndef __intentional_overflow
67214+# define __intentional_overflow(...)
67215+#endif
67216+
67217+#ifndef __latent_entropy
67218+# define __latent_entropy
67219+#endif
67220+
67221 /*
67222 * Tell gcc if a function is cold. The compiler will assume any path
67223 * directly leading to the call is unlikely.
67224@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67225 #define __cold
67226 #endif
67227
67228+#ifndef __alloc_size
67229+#define __alloc_size(...)
67230+#endif
67231+
67232+#ifndef __bos
67233+#define __bos(ptr, arg)
67234+#endif
67235+
67236+#ifndef __bos0
67237+#define __bos0(ptr)
67238+#endif
67239+
67240+#ifndef __bos1
67241+#define __bos1(ptr)
67242+#endif
67243+
67244 /* Simple shorthand for a section definition */
67245 #ifndef __section
67246 # define __section(S) __attribute__ ((__section__(#S)))
67247@@ -323,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67248 * use is to mediate communication between process-level code and irq/NMI
67249 * handlers, all running on the same CPU.
67250 */
67251-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
67252+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
67253+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
67254
67255 #endif /* __LINUX_COMPILER_H */
67256diff --git a/include/linux/completion.h b/include/linux/completion.h
67257index 51494e6..0fd1b61 100644
67258--- a/include/linux/completion.h
67259+++ b/include/linux/completion.h
67260@@ -78,13 +78,13 @@ static inline void init_completion(struct completion *x)
67261
67262 extern void wait_for_completion(struct completion *);
67263 extern int wait_for_completion_interruptible(struct completion *x);
67264-extern int wait_for_completion_killable(struct completion *x);
67265+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
67266 extern unsigned long wait_for_completion_timeout(struct completion *x,
67267 unsigned long timeout);
67268 extern long wait_for_completion_interruptible_timeout(
67269- struct completion *x, unsigned long timeout);
67270+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
67271 extern long wait_for_completion_killable_timeout(
67272- struct completion *x, unsigned long timeout);
67273+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
67274 extern bool try_wait_for_completion(struct completion *x);
67275 extern bool completion_done(struct completion *x);
67276
67277diff --git a/include/linux/configfs.h b/include/linux/configfs.h
67278index 34025df..d94bbbc 100644
67279--- a/include/linux/configfs.h
67280+++ b/include/linux/configfs.h
67281@@ -125,7 +125,7 @@ struct configfs_attribute {
67282 const char *ca_name;
67283 struct module *ca_owner;
67284 umode_t ca_mode;
67285-};
67286+} __do_const;
67287
67288 /*
67289 * Users often need to create attribute structures for their configurable
67290diff --git a/include/linux/cpu.h b/include/linux/cpu.h
67291index ce7a074..01ab8ac 100644
67292--- a/include/linux/cpu.h
67293+++ b/include/linux/cpu.h
67294@@ -115,7 +115,7 @@ enum {
67295 /* Need to know about CPUs going up/down? */
67296 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
67297 #define cpu_notifier(fn, pri) { \
67298- static struct notifier_block fn##_nb __cpuinitdata = \
67299+ static struct notifier_block fn##_nb = \
67300 { .notifier_call = fn, .priority = pri }; \
67301 register_cpu_notifier(&fn##_nb); \
67302 }
67303diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
67304index a55b88e..fba90c5 100644
67305--- a/include/linux/cpufreq.h
67306+++ b/include/linux/cpufreq.h
67307@@ -240,7 +240,7 @@ struct cpufreq_driver {
67308 int (*suspend) (struct cpufreq_policy *policy);
67309 int (*resume) (struct cpufreq_policy *policy);
67310 struct freq_attr **attr;
67311-};
67312+} __do_const;
67313
67314 /* flags */
67315
67316@@ -299,6 +299,7 @@ struct global_attr {
67317 ssize_t (*store)(struct kobject *a, struct attribute *b,
67318 const char *c, size_t count);
67319 };
67320+typedef struct global_attr __no_const global_attr_no_const;
67321
67322 #define define_one_global_ro(_name) \
67323 static struct global_attr _name = \
67324diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
67325index 24cd1037..20a63aae 100644
67326--- a/include/linux/cpuidle.h
67327+++ b/include/linux/cpuidle.h
67328@@ -54,7 +54,8 @@ struct cpuidle_state {
67329 int index);
67330
67331 int (*enter_dead) (struct cpuidle_device *dev, int index);
67332-};
67333+} __do_const;
67334+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
67335
67336 /* Idle State Flags */
67337 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
67338@@ -216,7 +217,7 @@ struct cpuidle_governor {
67339 void (*reflect) (struct cpuidle_device *dev, int index);
67340
67341 struct module *owner;
67342-};
67343+} __do_const;
67344
67345 #ifdef CONFIG_CPU_IDLE
67346
67347diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
67348index 0325602..5e9feff 100644
67349--- a/include/linux/cpumask.h
67350+++ b/include/linux/cpumask.h
67351@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
67352 }
67353
67354 /* Valid inputs for n are -1 and 0. */
67355-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67356+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
67357 {
67358 return n+1;
67359 }
67360
67361-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67362+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
67363 {
67364 return n+1;
67365 }
67366
67367-static inline unsigned int cpumask_next_and(int n,
67368+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
67369 const struct cpumask *srcp,
67370 const struct cpumask *andp)
67371 {
67372@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
67373 *
67374 * Returns >= nr_cpu_ids if no further cpus set.
67375 */
67376-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67377+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
67378 {
67379 /* -1 is a legal arg here. */
67380 if (n != -1)
67381@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67382 *
67383 * Returns >= nr_cpu_ids if no further cpus unset.
67384 */
67385-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67386+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
67387 {
67388 /* -1 is a legal arg here. */
67389 if (n != -1)
67390@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67391 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
67392 }
67393
67394-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
67395+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
67396 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
67397
67398 /**
67399diff --git a/include/linux/cred.h b/include/linux/cred.h
67400index 04421e8..6bce4ef 100644
67401--- a/include/linux/cred.h
67402+++ b/include/linux/cred.h
67403@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
67404 static inline void validate_process_creds(void)
67405 {
67406 }
67407+static inline void validate_task_creds(struct task_struct *task)
67408+{
67409+}
67410 #endif
67411
67412 /**
67413diff --git a/include/linux/crypto.h b/include/linux/crypto.h
67414index b92eadf..b4ecdc1 100644
67415--- a/include/linux/crypto.h
67416+++ b/include/linux/crypto.h
67417@@ -373,7 +373,7 @@ struct cipher_tfm {
67418 const u8 *key, unsigned int keylen);
67419 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
67420 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
67421-};
67422+} __no_const;
67423
67424 struct hash_tfm {
67425 int (*init)(struct hash_desc *desc);
67426@@ -394,13 +394,13 @@ struct compress_tfm {
67427 int (*cot_decompress)(struct crypto_tfm *tfm,
67428 const u8 *src, unsigned int slen,
67429 u8 *dst, unsigned int *dlen);
67430-};
67431+} __no_const;
67432
67433 struct rng_tfm {
67434 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
67435 unsigned int dlen);
67436 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
67437-};
67438+} __no_const;
67439
67440 #define crt_ablkcipher crt_u.ablkcipher
67441 #define crt_aead crt_u.aead
67442diff --git a/include/linux/ctype.h b/include/linux/ctype.h
67443index 8acfe31..6ffccd63 100644
67444--- a/include/linux/ctype.h
67445+++ b/include/linux/ctype.h
67446@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
67447 * Fast implementation of tolower() for internal usage. Do not use in your
67448 * code.
67449 */
67450-static inline char _tolower(const char c)
67451+static inline unsigned char _tolower(const unsigned char c)
67452 {
67453 return c | 0x20;
67454 }
67455diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
67456index 7925bf0..d5143d2 100644
67457--- a/include/linux/decompress/mm.h
67458+++ b/include/linux/decompress/mm.h
67459@@ -77,7 +77,7 @@ static void free(void *where)
67460 * warnings when not needed (indeed large_malloc / large_free are not
67461 * needed by inflate */
67462
67463-#define malloc(a) kmalloc(a, GFP_KERNEL)
67464+#define malloc(a) kmalloc((a), GFP_KERNEL)
67465 #define free(a) kfree(a)
67466
67467 #define large_malloc(a) vmalloc(a)
67468diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
67469index e83ef39..33e0eb3 100644
67470--- a/include/linux/devfreq.h
67471+++ b/include/linux/devfreq.h
67472@@ -114,7 +114,7 @@ struct devfreq_governor {
67473 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
67474 int (*event_handler)(struct devfreq *devfreq,
67475 unsigned int event, void *data);
67476-};
67477+} __do_const;
67478
67479 /**
67480 * struct devfreq - Device devfreq structure
67481diff --git a/include/linux/device.h b/include/linux/device.h
67482index 43dcda9..7a1fb65 100644
67483--- a/include/linux/device.h
67484+++ b/include/linux/device.h
67485@@ -294,7 +294,7 @@ struct subsys_interface {
67486 struct list_head node;
67487 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
67488 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
67489-};
67490+} __do_const;
67491
67492 int subsys_interface_register(struct subsys_interface *sif);
67493 void subsys_interface_unregister(struct subsys_interface *sif);
67494@@ -474,7 +474,7 @@ struct device_type {
67495 void (*release)(struct device *dev);
67496
67497 const struct dev_pm_ops *pm;
67498-};
67499+} __do_const;
67500
67501 /* interface for exporting device attributes */
67502 struct device_attribute {
67503@@ -484,11 +484,12 @@ struct device_attribute {
67504 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
67505 const char *buf, size_t count);
67506 };
67507+typedef struct device_attribute __no_const device_attribute_no_const;
67508
67509 struct dev_ext_attribute {
67510 struct device_attribute attr;
67511 void *var;
67512-};
67513+} __do_const;
67514
67515 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
67516 char *buf);
67517diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
67518index 94af418..b1ca7a2 100644
67519--- a/include/linux/dma-mapping.h
67520+++ b/include/linux/dma-mapping.h
67521@@ -54,7 +54,7 @@ struct dma_map_ops {
67522 u64 (*get_required_mask)(struct device *dev);
67523 #endif
67524 int is_phys;
67525-};
67526+} __do_const;
67527
67528 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
67529
67530diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
67531index d3201e4..8281e63 100644
67532--- a/include/linux/dmaengine.h
67533+++ b/include/linux/dmaengine.h
67534@@ -1018,9 +1018,9 @@ struct dma_pinned_list {
67535 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
67536 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
67537
67538-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
67539+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
67540 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
67541-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
67542+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
67543 struct dma_pinned_list *pinned_list, struct page *page,
67544 unsigned int offset, size_t len);
67545
67546diff --git a/include/linux/efi.h b/include/linux/efi.h
67547index 7a9498a..155713d 100644
67548--- a/include/linux/efi.h
67549+++ b/include/linux/efi.h
67550@@ -733,6 +733,7 @@ struct efivar_operations {
67551 efi_set_variable_t *set_variable;
67552 efi_query_variable_info_t *query_variable_info;
67553 };
67554+typedef struct efivar_operations __no_const efivar_operations_no_const;
67555
67556 struct efivars {
67557 /*
67558diff --git a/include/linux/elf.h b/include/linux/elf.h
67559index 8c9048e..16a4665 100644
67560--- a/include/linux/elf.h
67561+++ b/include/linux/elf.h
67562@@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
67563 #define elf_note elf32_note
67564 #define elf_addr_t Elf32_Off
67565 #define Elf_Half Elf32_Half
67566+#define elf_dyn Elf32_Dyn
67567
67568 #else
67569
67570@@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
67571 #define elf_note elf64_note
67572 #define elf_addr_t Elf64_Off
67573 #define Elf_Half Elf64_Half
67574+#define elf_dyn Elf64_Dyn
67575
67576 #endif
67577
67578diff --git a/include/linux/err.h b/include/linux/err.h
67579index f2edce2..cc2082c 100644
67580--- a/include/linux/err.h
67581+++ b/include/linux/err.h
67582@@ -19,12 +19,12 @@
67583
67584 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
67585
67586-static inline void * __must_check ERR_PTR(long error)
67587+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
67588 {
67589 return (void *) error;
67590 }
67591
67592-static inline long __must_check PTR_ERR(const void *ptr)
67593+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
67594 {
67595 return (long) ptr;
67596 }
67597diff --git a/include/linux/extcon.h b/include/linux/extcon.h
67598index fcb51c8..bdafcf6 100644
67599--- a/include/linux/extcon.h
67600+++ b/include/linux/extcon.h
67601@@ -134,7 +134,7 @@ struct extcon_dev {
67602 /* /sys/class/extcon/.../mutually_exclusive/... */
67603 struct attribute_group attr_g_muex;
67604 struct attribute **attrs_muex;
67605- struct device_attribute *d_attrs_muex;
67606+ device_attribute_no_const *d_attrs_muex;
67607 };
67608
67609 /**
67610diff --git a/include/linux/fb.h b/include/linux/fb.h
67611index c7a9571..02eeffe 100644
67612--- a/include/linux/fb.h
67613+++ b/include/linux/fb.h
67614@@ -302,7 +302,7 @@ struct fb_ops {
67615 /* called at KDB enter and leave time to prepare the console */
67616 int (*fb_debug_enter)(struct fb_info *info);
67617 int (*fb_debug_leave)(struct fb_info *info);
67618-};
67619+} __do_const;
67620
67621 #ifdef CONFIG_FB_TILEBLITTING
67622 #define FB_TILE_CURSOR_NONE 0
67623diff --git a/include/linux/filter.h b/include/linux/filter.h
67624index c45eabc..baa0be5 100644
67625--- a/include/linux/filter.h
67626+++ b/include/linux/filter.h
67627@@ -20,6 +20,7 @@ struct compat_sock_fprog {
67628
67629 struct sk_buff;
67630 struct sock;
67631+struct bpf_jit_work;
67632
67633 struct sk_filter
67634 {
67635@@ -27,6 +28,9 @@ struct sk_filter
67636 unsigned int len; /* Number of filter blocks */
67637 unsigned int (*bpf_func)(const struct sk_buff *skb,
67638 const struct sock_filter *filter);
67639+#ifdef CONFIG_BPF_JIT
67640+ struct bpf_jit_work *work;
67641+#endif
67642 struct rcu_head rcu;
67643 struct sock_filter insns[0];
67644 };
67645diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
67646index 3044254..9767f41 100644
67647--- a/include/linux/frontswap.h
67648+++ b/include/linux/frontswap.h
67649@@ -11,7 +11,7 @@ struct frontswap_ops {
67650 int (*load)(unsigned, pgoff_t, struct page *);
67651 void (*invalidate_page)(unsigned, pgoff_t);
67652 void (*invalidate_area)(unsigned);
67653-};
67654+} __no_const;
67655
67656 extern bool frontswap_enabled;
67657 extern struct frontswap_ops
67658diff --git a/include/linux/fs.h b/include/linux/fs.h
67659index 7617ee0..b575199 100644
67660--- a/include/linux/fs.h
67661+++ b/include/linux/fs.h
67662@@ -1541,7 +1541,8 @@ struct file_operations {
67663 long (*fallocate)(struct file *file, int mode, loff_t offset,
67664 loff_t len);
67665 int (*show_fdinfo)(struct seq_file *m, struct file *f);
67666-};
67667+} __do_const;
67668+typedef struct file_operations __no_const file_operations_no_const;
67669
67670 struct inode_operations {
67671 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
67672@@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
67673 inode->i_flags |= S_NOSEC;
67674 }
67675
67676+static inline bool is_sidechannel_device(const struct inode *inode)
67677+{
67678+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
67679+ umode_t mode = inode->i_mode;
67680+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
67681+#else
67682+ return false;
67683+#endif
67684+}
67685+
67686 #endif /* _LINUX_FS_H */
67687diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
67688index d0ae3a8..0244b34 100644
67689--- a/include/linux/fs_struct.h
67690+++ b/include/linux/fs_struct.h
67691@@ -6,7 +6,7 @@
67692 #include <linux/seqlock.h>
67693
67694 struct fs_struct {
67695- int users;
67696+ atomic_t users;
67697 spinlock_t lock;
67698 seqcount_t seq;
67699 int umask;
67700diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
67701index 5dfa0aa..6acf322 100644
67702--- a/include/linux/fscache-cache.h
67703+++ b/include/linux/fscache-cache.h
67704@@ -112,7 +112,7 @@ struct fscache_operation {
67705 fscache_operation_release_t release;
67706 };
67707
67708-extern atomic_t fscache_op_debug_id;
67709+extern atomic_unchecked_t fscache_op_debug_id;
67710 extern void fscache_op_work_func(struct work_struct *work);
67711
67712 extern void fscache_enqueue_operation(struct fscache_operation *);
67713@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
67714 INIT_WORK(&op->work, fscache_op_work_func);
67715 atomic_set(&op->usage, 1);
67716 op->state = FSCACHE_OP_ST_INITIALISED;
67717- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
67718+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
67719 op->processor = processor;
67720 op->release = release;
67721 INIT_LIST_HEAD(&op->pend_link);
67722diff --git a/include/linux/fscache.h b/include/linux/fscache.h
67723index 7a08623..4c07b0f 100644
67724--- a/include/linux/fscache.h
67725+++ b/include/linux/fscache.h
67726@@ -152,7 +152,7 @@ struct fscache_cookie_def {
67727 * - this is mandatory for any object that may have data
67728 */
67729 void (*now_uncached)(void *cookie_netfs_data);
67730-};
67731+} __do_const;
67732
67733 /*
67734 * fscache cached network filesystem type
67735diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
67736index 0fbfb46..508eb0d 100644
67737--- a/include/linux/fsnotify.h
67738+++ b/include/linux/fsnotify.h
67739@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
67740 struct inode *inode = path->dentry->d_inode;
67741 __u32 mask = FS_ACCESS;
67742
67743+ if (is_sidechannel_device(inode))
67744+ return;
67745+
67746 if (S_ISDIR(inode->i_mode))
67747 mask |= FS_ISDIR;
67748
67749@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
67750 struct inode *inode = path->dentry->d_inode;
67751 __u32 mask = FS_MODIFY;
67752
67753+ if (is_sidechannel_device(inode))
67754+ return;
67755+
67756 if (S_ISDIR(inode->i_mode))
67757 mask |= FS_ISDIR;
67758
67759@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
67760 */
67761 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
67762 {
67763- return kstrdup(name, GFP_KERNEL);
67764+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
67765 }
67766
67767 /*
67768diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
67769index a3d4895..ddd2a50 100644
67770--- a/include/linux/ftrace_event.h
67771+++ b/include/linux/ftrace_event.h
67772@@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
67773 extern int trace_add_event_call(struct ftrace_event_call *call);
67774 extern void trace_remove_event_call(struct ftrace_event_call *call);
67775
67776-#define is_signed_type(type) (((type)(-1)) < 0)
67777+#define is_signed_type(type) (((type)(-1)) < (type)1)
67778
67779 int trace_set_clr_event(const char *system, const char *event, int set);
67780
67781diff --git a/include/linux/genhd.h b/include/linux/genhd.h
67782index 79b8bba..86b539e 100644
67783--- a/include/linux/genhd.h
67784+++ b/include/linux/genhd.h
67785@@ -194,7 +194,7 @@ struct gendisk {
67786 struct kobject *slave_dir;
67787
67788 struct timer_rand_state *random;
67789- atomic_t sync_io; /* RAID */
67790+ atomic_unchecked_t sync_io; /* RAID */
67791 struct disk_events *ev;
67792 #ifdef CONFIG_BLK_DEV_INTEGRITY
67793 struct blk_integrity *integrity;
67794diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
67795index 023bc34..b02b46a 100644
67796--- a/include/linux/genl_magic_func.h
67797+++ b/include/linux/genl_magic_func.h
67798@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
67799 },
67800
67801 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
67802-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
67803+static struct genl_ops ZZZ_genl_ops[] = {
67804 #include GENL_MAGIC_INCLUDE_FILE
67805 };
67806
67807diff --git a/include/linux/gfp.h b/include/linux/gfp.h
67808index 0f615eb..5c3832f 100644
67809--- a/include/linux/gfp.h
67810+++ b/include/linux/gfp.h
67811@@ -35,6 +35,13 @@ struct vm_area_struct;
67812 #define ___GFP_NO_KSWAPD 0x400000u
67813 #define ___GFP_OTHER_NODE 0x800000u
67814 #define ___GFP_WRITE 0x1000000u
67815+
67816+#ifdef CONFIG_PAX_USERCOPY_SLABS
67817+#define ___GFP_USERCOPY 0x2000000u
67818+#else
67819+#define ___GFP_USERCOPY 0
67820+#endif
67821+
67822 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
67823
67824 /*
67825@@ -92,6 +99,7 @@ struct vm_area_struct;
67826 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
67827 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
67828 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
67829+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
67830
67831 /*
67832 * This may seem redundant, but it's a way of annotating false positives vs.
67833@@ -99,7 +107,7 @@ struct vm_area_struct;
67834 */
67835 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
67836
67837-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
67838+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
67839 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
67840
67841 /* This equals 0, but use constants in case they ever change */
67842@@ -153,6 +161,8 @@ struct vm_area_struct;
67843 /* 4GB DMA on some platforms */
67844 #define GFP_DMA32 __GFP_DMA32
67845
67846+#define GFP_USERCOPY __GFP_USERCOPY
67847+
67848 /* Convert GFP flags to their corresponding migrate type */
67849 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
67850 {
67851diff --git a/include/linux/gracl.h b/include/linux/gracl.h
67852new file mode 100644
67853index 0000000..ebe6d72
67854--- /dev/null
67855+++ b/include/linux/gracl.h
67856@@ -0,0 +1,319 @@
67857+#ifndef GR_ACL_H
67858+#define GR_ACL_H
67859+
67860+#include <linux/grdefs.h>
67861+#include <linux/resource.h>
67862+#include <linux/capability.h>
67863+#include <linux/dcache.h>
67864+#include <asm/resource.h>
67865+
67866+/* Major status information */
67867+
67868+#define GR_VERSION "grsecurity 2.9.1"
67869+#define GRSECURITY_VERSION 0x2901
67870+
67871+enum {
67872+ GR_SHUTDOWN = 0,
67873+ GR_ENABLE = 1,
67874+ GR_SPROLE = 2,
67875+ GR_RELOAD = 3,
67876+ GR_SEGVMOD = 4,
67877+ GR_STATUS = 5,
67878+ GR_UNSPROLE = 6,
67879+ GR_PASSSET = 7,
67880+ GR_SPROLEPAM = 8,
67881+};
67882+
67883+/* Password setup definitions
67884+ * kernel/grhash.c */
67885+enum {
67886+ GR_PW_LEN = 128,
67887+ GR_SALT_LEN = 16,
67888+ GR_SHA_LEN = 32,
67889+};
67890+
67891+enum {
67892+ GR_SPROLE_LEN = 64,
67893+};
67894+
67895+enum {
67896+ GR_NO_GLOB = 0,
67897+ GR_REG_GLOB,
67898+ GR_CREATE_GLOB
67899+};
67900+
67901+#define GR_NLIMITS 32
67902+
67903+/* Begin Data Structures */
67904+
67905+struct sprole_pw {
67906+ unsigned char *rolename;
67907+ unsigned char salt[GR_SALT_LEN];
67908+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
67909+};
67910+
67911+struct name_entry {
67912+ __u32 key;
67913+ ino_t inode;
67914+ dev_t device;
67915+ char *name;
67916+ __u16 len;
67917+ __u8 deleted;
67918+ struct name_entry *prev;
67919+ struct name_entry *next;
67920+};
67921+
67922+struct inodev_entry {
67923+ struct name_entry *nentry;
67924+ struct inodev_entry *prev;
67925+ struct inodev_entry *next;
67926+};
67927+
67928+struct acl_role_db {
67929+ struct acl_role_label **r_hash;
67930+ __u32 r_size;
67931+};
67932+
67933+struct inodev_db {
67934+ struct inodev_entry **i_hash;
67935+ __u32 i_size;
67936+};
67937+
67938+struct name_db {
67939+ struct name_entry **n_hash;
67940+ __u32 n_size;
67941+};
67942+
67943+struct crash_uid {
67944+ uid_t uid;
67945+ unsigned long expires;
67946+};
67947+
67948+struct gr_hash_struct {
67949+ void **table;
67950+ void **nametable;
67951+ void *first;
67952+ __u32 table_size;
67953+ __u32 used_size;
67954+ int type;
67955+};
67956+
67957+/* Userspace Grsecurity ACL data structures */
67958+
67959+struct acl_subject_label {
67960+ char *filename;
67961+ ino_t inode;
67962+ dev_t device;
67963+ __u32 mode;
67964+ kernel_cap_t cap_mask;
67965+ kernel_cap_t cap_lower;
67966+ kernel_cap_t cap_invert_audit;
67967+
67968+ struct rlimit res[GR_NLIMITS];
67969+ __u32 resmask;
67970+
67971+ __u8 user_trans_type;
67972+ __u8 group_trans_type;
67973+ uid_t *user_transitions;
67974+ gid_t *group_transitions;
67975+ __u16 user_trans_num;
67976+ __u16 group_trans_num;
67977+
67978+ __u32 sock_families[2];
67979+ __u32 ip_proto[8];
67980+ __u32 ip_type;
67981+ struct acl_ip_label **ips;
67982+ __u32 ip_num;
67983+ __u32 inaddr_any_override;
67984+
67985+ __u32 crashes;
67986+ unsigned long expires;
67987+
67988+ struct acl_subject_label *parent_subject;
67989+ struct gr_hash_struct *hash;
67990+ struct acl_subject_label *prev;
67991+ struct acl_subject_label *next;
67992+
67993+ struct acl_object_label **obj_hash;
67994+ __u32 obj_hash_size;
67995+ __u16 pax_flags;
67996+};
67997+
67998+struct role_allowed_ip {
67999+ __u32 addr;
68000+ __u32 netmask;
68001+
68002+ struct role_allowed_ip *prev;
68003+ struct role_allowed_ip *next;
68004+};
68005+
68006+struct role_transition {
68007+ char *rolename;
68008+
68009+ struct role_transition *prev;
68010+ struct role_transition *next;
68011+};
68012+
68013+struct acl_role_label {
68014+ char *rolename;
68015+ uid_t uidgid;
68016+ __u16 roletype;
68017+
68018+ __u16 auth_attempts;
68019+ unsigned long expires;
68020+
68021+ struct acl_subject_label *root_label;
68022+ struct gr_hash_struct *hash;
68023+
68024+ struct acl_role_label *prev;
68025+ struct acl_role_label *next;
68026+
68027+ struct role_transition *transitions;
68028+ struct role_allowed_ip *allowed_ips;
68029+ uid_t *domain_children;
68030+ __u16 domain_child_num;
68031+
68032+ umode_t umask;
68033+
68034+ struct acl_subject_label **subj_hash;
68035+ __u32 subj_hash_size;
68036+};
68037+
68038+struct user_acl_role_db {
68039+ struct acl_role_label **r_table;
68040+ __u32 num_pointers; /* Number of allocations to track */
68041+ __u32 num_roles; /* Number of roles */
68042+ __u32 num_domain_children; /* Number of domain children */
68043+ __u32 num_subjects; /* Number of subjects */
68044+ __u32 num_objects; /* Number of objects */
68045+};
68046+
68047+struct acl_object_label {
68048+ char *filename;
68049+ ino_t inode;
68050+ dev_t device;
68051+ __u32 mode;
68052+
68053+ struct acl_subject_label *nested;
68054+ struct acl_object_label *globbed;
68055+
68056+ /* next two structures not used */
68057+
68058+ struct acl_object_label *prev;
68059+ struct acl_object_label *next;
68060+};
68061+
68062+struct acl_ip_label {
68063+ char *iface;
68064+ __u32 addr;
68065+ __u32 netmask;
68066+ __u16 low, high;
68067+ __u8 mode;
68068+ __u32 type;
68069+ __u32 proto[8];
68070+
68071+ /* next two structures not used */
68072+
68073+ struct acl_ip_label *prev;
68074+ struct acl_ip_label *next;
68075+};
68076+
68077+struct gr_arg {
68078+ struct user_acl_role_db role_db;
68079+ unsigned char pw[GR_PW_LEN];
68080+ unsigned char salt[GR_SALT_LEN];
68081+ unsigned char sum[GR_SHA_LEN];
68082+ unsigned char sp_role[GR_SPROLE_LEN];
68083+ struct sprole_pw *sprole_pws;
68084+ dev_t segv_device;
68085+ ino_t segv_inode;
68086+ uid_t segv_uid;
68087+ __u16 num_sprole_pws;
68088+ __u16 mode;
68089+};
68090+
68091+struct gr_arg_wrapper {
68092+ struct gr_arg *arg;
68093+ __u32 version;
68094+ __u32 size;
68095+};
68096+
68097+struct subject_map {
68098+ struct acl_subject_label *user;
68099+ struct acl_subject_label *kernel;
68100+ struct subject_map *prev;
68101+ struct subject_map *next;
68102+};
68103+
68104+struct acl_subj_map_db {
68105+ struct subject_map **s_hash;
68106+ __u32 s_size;
68107+};
68108+
68109+/* End Data Structures Section */
68110+
68111+/* Hash functions generated by empirical testing by Brad Spengler
68112+ Makes good use of the low bits of the inode. Generally 0-1 times
68113+ in loop for successful match. 0-3 for unsuccessful match.
68114+ Shift/add algorithm with modulus of table size and an XOR*/
68115+
68116+static __inline__ unsigned int
68117+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
68118+{
68119+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
68120+}
68121+
68122+ static __inline__ unsigned int
68123+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
68124+{
68125+ return ((const unsigned long)userp % sz);
68126+}
68127+
68128+static __inline__ unsigned int
68129+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
68130+{
68131+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
68132+}
68133+
68134+static __inline__ unsigned int
68135+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
68136+{
68137+ return full_name_hash((const unsigned char *)name, len) % sz;
68138+}
68139+
68140+#define FOR_EACH_ROLE_START(role) \
68141+ role = role_list; \
68142+ while (role) {
68143+
68144+#define FOR_EACH_ROLE_END(role) \
68145+ role = role->prev; \
68146+ }
68147+
68148+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
68149+ subj = NULL; \
68150+ iter = 0; \
68151+ while (iter < role->subj_hash_size) { \
68152+ if (subj == NULL) \
68153+ subj = role->subj_hash[iter]; \
68154+ if (subj == NULL) { \
68155+ iter++; \
68156+ continue; \
68157+ }
68158+
68159+#define FOR_EACH_SUBJECT_END(subj,iter) \
68160+ subj = subj->next; \
68161+ if (subj == NULL) \
68162+ iter++; \
68163+ }
68164+
68165+
68166+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
68167+ subj = role->hash->first; \
68168+ while (subj != NULL) {
68169+
68170+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
68171+ subj = subj->next; \
68172+ }
68173+
68174+#endif
68175+
68176diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
68177new file mode 100644
68178index 0000000..323ecf2
68179--- /dev/null
68180+++ b/include/linux/gralloc.h
68181@@ -0,0 +1,9 @@
68182+#ifndef __GRALLOC_H
68183+#define __GRALLOC_H
68184+
68185+void acl_free_all(void);
68186+int acl_alloc_stack_init(unsigned long size);
68187+void *acl_alloc(unsigned long len);
68188+void *acl_alloc_num(unsigned long num, unsigned long len);
68189+
68190+#endif
68191diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
68192new file mode 100644
68193index 0000000..be66033
68194--- /dev/null
68195+++ b/include/linux/grdefs.h
68196@@ -0,0 +1,140 @@
68197+#ifndef GRDEFS_H
68198+#define GRDEFS_H
68199+
68200+/* Begin grsecurity status declarations */
68201+
68202+enum {
68203+ GR_READY = 0x01,
68204+ GR_STATUS_INIT = 0x00 // disabled state
68205+};
68206+
68207+/* Begin ACL declarations */
68208+
68209+/* Role flags */
68210+
68211+enum {
68212+ GR_ROLE_USER = 0x0001,
68213+ GR_ROLE_GROUP = 0x0002,
68214+ GR_ROLE_DEFAULT = 0x0004,
68215+ GR_ROLE_SPECIAL = 0x0008,
68216+ GR_ROLE_AUTH = 0x0010,
68217+ GR_ROLE_NOPW = 0x0020,
68218+ GR_ROLE_GOD = 0x0040,
68219+ GR_ROLE_LEARN = 0x0080,
68220+ GR_ROLE_TPE = 0x0100,
68221+ GR_ROLE_DOMAIN = 0x0200,
68222+ GR_ROLE_PAM = 0x0400,
68223+ GR_ROLE_PERSIST = 0x0800
68224+};
68225+
68226+/* ACL Subject and Object mode flags */
68227+enum {
68228+ GR_DELETED = 0x80000000
68229+};
68230+
68231+/* ACL Object-only mode flags */
68232+enum {
68233+ GR_READ = 0x00000001,
68234+ GR_APPEND = 0x00000002,
68235+ GR_WRITE = 0x00000004,
68236+ GR_EXEC = 0x00000008,
68237+ GR_FIND = 0x00000010,
68238+ GR_INHERIT = 0x00000020,
68239+ GR_SETID = 0x00000040,
68240+ GR_CREATE = 0x00000080,
68241+ GR_DELETE = 0x00000100,
68242+ GR_LINK = 0x00000200,
68243+ GR_AUDIT_READ = 0x00000400,
68244+ GR_AUDIT_APPEND = 0x00000800,
68245+ GR_AUDIT_WRITE = 0x00001000,
68246+ GR_AUDIT_EXEC = 0x00002000,
68247+ GR_AUDIT_FIND = 0x00004000,
68248+ GR_AUDIT_INHERIT= 0x00008000,
68249+ GR_AUDIT_SETID = 0x00010000,
68250+ GR_AUDIT_CREATE = 0x00020000,
68251+ GR_AUDIT_DELETE = 0x00040000,
68252+ GR_AUDIT_LINK = 0x00080000,
68253+ GR_PTRACERD = 0x00100000,
68254+ GR_NOPTRACE = 0x00200000,
68255+ GR_SUPPRESS = 0x00400000,
68256+ GR_NOLEARN = 0x00800000,
68257+ GR_INIT_TRANSFER= 0x01000000
68258+};
68259+
68260+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
68261+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
68262+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
68263+
68264+/* ACL subject-only mode flags */
68265+enum {
68266+ GR_KILL = 0x00000001,
68267+ GR_VIEW = 0x00000002,
68268+ GR_PROTECTED = 0x00000004,
68269+ GR_LEARN = 0x00000008,
68270+ GR_OVERRIDE = 0x00000010,
68271+ /* just a placeholder, this mode is only used in userspace */
68272+ GR_DUMMY = 0x00000020,
68273+ GR_PROTSHM = 0x00000040,
68274+ GR_KILLPROC = 0x00000080,
68275+ GR_KILLIPPROC = 0x00000100,
68276+ /* just a placeholder, this mode is only used in userspace */
68277+ GR_NOTROJAN = 0x00000200,
68278+ GR_PROTPROCFD = 0x00000400,
68279+ GR_PROCACCT = 0x00000800,
68280+ GR_RELAXPTRACE = 0x00001000,
68281+ //GR_NESTED = 0x00002000,
68282+ GR_INHERITLEARN = 0x00004000,
68283+ GR_PROCFIND = 0x00008000,
68284+ GR_POVERRIDE = 0x00010000,
68285+ GR_KERNELAUTH = 0x00020000,
68286+ GR_ATSECURE = 0x00040000,
68287+ GR_SHMEXEC = 0x00080000
68288+};
68289+
68290+enum {
68291+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
68292+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
68293+ GR_PAX_ENABLE_MPROTECT = 0x0004,
68294+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
68295+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
68296+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
68297+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
68298+ GR_PAX_DISABLE_MPROTECT = 0x0400,
68299+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
68300+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
68301+};
68302+
68303+enum {
68304+ GR_ID_USER = 0x01,
68305+ GR_ID_GROUP = 0x02,
68306+};
68307+
68308+enum {
68309+ GR_ID_ALLOW = 0x01,
68310+ GR_ID_DENY = 0x02,
68311+};
68312+
68313+#define GR_CRASH_RES 31
68314+#define GR_UIDTABLE_MAX 500
68315+
68316+/* begin resource learning section */
68317+enum {
68318+ GR_RLIM_CPU_BUMP = 60,
68319+ GR_RLIM_FSIZE_BUMP = 50000,
68320+ GR_RLIM_DATA_BUMP = 10000,
68321+ GR_RLIM_STACK_BUMP = 1000,
68322+ GR_RLIM_CORE_BUMP = 10000,
68323+ GR_RLIM_RSS_BUMP = 500000,
68324+ GR_RLIM_NPROC_BUMP = 1,
68325+ GR_RLIM_NOFILE_BUMP = 5,
68326+ GR_RLIM_MEMLOCK_BUMP = 50000,
68327+ GR_RLIM_AS_BUMP = 500000,
68328+ GR_RLIM_LOCKS_BUMP = 2,
68329+ GR_RLIM_SIGPENDING_BUMP = 5,
68330+ GR_RLIM_MSGQUEUE_BUMP = 10000,
68331+ GR_RLIM_NICE_BUMP = 1,
68332+ GR_RLIM_RTPRIO_BUMP = 1,
68333+ GR_RLIM_RTTIME_BUMP = 1000000
68334+};
68335+
68336+#endif
68337diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
68338new file mode 100644
68339index 0000000..9bb6662
68340--- /dev/null
68341+++ b/include/linux/grinternal.h
68342@@ -0,0 +1,215 @@
68343+#ifndef __GRINTERNAL_H
68344+#define __GRINTERNAL_H
68345+
68346+#ifdef CONFIG_GRKERNSEC
68347+
68348+#include <linux/fs.h>
68349+#include <linux/mnt_namespace.h>
68350+#include <linux/nsproxy.h>
68351+#include <linux/gracl.h>
68352+#include <linux/grdefs.h>
68353+#include <linux/grmsg.h>
68354+
68355+void gr_add_learn_entry(const char *fmt, ...)
68356+ __attribute__ ((format (printf, 1, 2)));
68357+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
68358+ const struct vfsmount *mnt);
68359+__u32 gr_check_create(const struct dentry *new_dentry,
68360+ const struct dentry *parent,
68361+ const struct vfsmount *mnt, const __u32 mode);
68362+int gr_check_protected_task(const struct task_struct *task);
68363+__u32 to_gr_audit(const __u32 reqmode);
68364+int gr_set_acls(const int type);
68365+int gr_apply_subject_to_task(struct task_struct *task);
68366+int gr_acl_is_enabled(void);
68367+char gr_roletype_to_char(void);
68368+
68369+void gr_handle_alertkill(struct task_struct *task);
68370+char *gr_to_filename(const struct dentry *dentry,
68371+ const struct vfsmount *mnt);
68372+char *gr_to_filename1(const struct dentry *dentry,
68373+ const struct vfsmount *mnt);
68374+char *gr_to_filename2(const struct dentry *dentry,
68375+ const struct vfsmount *mnt);
68376+char *gr_to_filename3(const struct dentry *dentry,
68377+ const struct vfsmount *mnt);
68378+
68379+extern int grsec_enable_ptrace_readexec;
68380+extern int grsec_enable_harden_ptrace;
68381+extern int grsec_enable_link;
68382+extern int grsec_enable_fifo;
68383+extern int grsec_enable_execve;
68384+extern int grsec_enable_shm;
68385+extern int grsec_enable_execlog;
68386+extern int grsec_enable_signal;
68387+extern int grsec_enable_audit_ptrace;
68388+extern int grsec_enable_forkfail;
68389+extern int grsec_enable_time;
68390+extern int grsec_enable_rofs;
68391+extern int grsec_enable_chroot_shmat;
68392+extern int grsec_enable_chroot_mount;
68393+extern int grsec_enable_chroot_double;
68394+extern int grsec_enable_chroot_pivot;
68395+extern int grsec_enable_chroot_chdir;
68396+extern int grsec_enable_chroot_chmod;
68397+extern int grsec_enable_chroot_mknod;
68398+extern int grsec_enable_chroot_fchdir;
68399+extern int grsec_enable_chroot_nice;
68400+extern int grsec_enable_chroot_execlog;
68401+extern int grsec_enable_chroot_caps;
68402+extern int grsec_enable_chroot_sysctl;
68403+extern int grsec_enable_chroot_unix;
68404+extern int grsec_enable_symlinkown;
68405+extern kgid_t grsec_symlinkown_gid;
68406+extern int grsec_enable_tpe;
68407+extern kgid_t grsec_tpe_gid;
68408+extern int grsec_enable_tpe_all;
68409+extern int grsec_enable_tpe_invert;
68410+extern int grsec_enable_socket_all;
68411+extern kgid_t grsec_socket_all_gid;
68412+extern int grsec_enable_socket_client;
68413+extern kgid_t grsec_socket_client_gid;
68414+extern int grsec_enable_socket_server;
68415+extern kgid_t grsec_socket_server_gid;
68416+extern kgid_t grsec_audit_gid;
68417+extern int grsec_enable_group;
68418+extern int grsec_enable_audit_textrel;
68419+extern int grsec_enable_log_rwxmaps;
68420+extern int grsec_enable_mount;
68421+extern int grsec_enable_chdir;
68422+extern int grsec_resource_logging;
68423+extern int grsec_enable_blackhole;
68424+extern int grsec_lastack_retries;
68425+extern int grsec_enable_brute;
68426+extern int grsec_lock;
68427+
68428+extern spinlock_t grsec_alert_lock;
68429+extern unsigned long grsec_alert_wtime;
68430+extern unsigned long grsec_alert_fyet;
68431+
68432+extern spinlock_t grsec_audit_lock;
68433+
68434+extern rwlock_t grsec_exec_file_lock;
68435+
68436+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
68437+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
68438+ (tsk)->exec_file->f_vfsmnt) : "/")
68439+
68440+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
68441+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
68442+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
68443+
68444+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
68445+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
68446+ (tsk)->exec_file->f_vfsmnt) : "/")
68447+
68448+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
68449+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
68450+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
68451+
68452+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
68453+
68454+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
68455+
68456+#define GR_CHROOT_CAPS {{ \
68457+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
68458+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
68459+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
68460+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
68461+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
68462+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
68463+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
68464+
68465+#define security_learn(normal_msg,args...) \
68466+({ \
68467+ read_lock(&grsec_exec_file_lock); \
68468+ gr_add_learn_entry(normal_msg "\n", ## args); \
68469+ read_unlock(&grsec_exec_file_lock); \
68470+})
68471+
68472+enum {
68473+ GR_DO_AUDIT,
68474+ GR_DONT_AUDIT,
68475+ /* used for non-audit messages that we shouldn't kill the task on */
68476+ GR_DONT_AUDIT_GOOD
68477+};
68478+
68479+enum {
68480+ GR_TTYSNIFF,
68481+ GR_RBAC,
68482+ GR_RBAC_STR,
68483+ GR_STR_RBAC,
68484+ GR_RBAC_MODE2,
68485+ GR_RBAC_MODE3,
68486+ GR_FILENAME,
68487+ GR_SYSCTL_HIDDEN,
68488+ GR_NOARGS,
68489+ GR_ONE_INT,
68490+ GR_ONE_INT_TWO_STR,
68491+ GR_ONE_STR,
68492+ GR_STR_INT,
68493+ GR_TWO_STR_INT,
68494+ GR_TWO_INT,
68495+ GR_TWO_U64,
68496+ GR_THREE_INT,
68497+ GR_FIVE_INT_TWO_STR,
68498+ GR_TWO_STR,
68499+ GR_THREE_STR,
68500+ GR_FOUR_STR,
68501+ GR_STR_FILENAME,
68502+ GR_FILENAME_STR,
68503+ GR_FILENAME_TWO_INT,
68504+ GR_FILENAME_TWO_INT_STR,
68505+ GR_TEXTREL,
68506+ GR_PTRACE,
68507+ GR_RESOURCE,
68508+ GR_CAP,
68509+ GR_SIG,
68510+ GR_SIG2,
68511+ GR_CRASH1,
68512+ GR_CRASH2,
68513+ GR_PSACCT,
68514+ GR_RWXMAP
68515+};
68516+
68517+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
68518+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
68519+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
68520+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
68521+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
68522+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
68523+#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)
68524+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
68525+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
68526+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
68527+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
68528+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
68529+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
68530+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
68531+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
68532+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
68533+#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)
68534+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
68535+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
68536+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
68537+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
68538+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
68539+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
68540+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
68541+#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)
68542+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
68543+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
68544+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
68545+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
68546+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
68547+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
68548+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
68549+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
68550+#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)
68551+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
68552+
68553+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
68554+
68555+#endif
68556+
68557+#endif
68558diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
68559new file mode 100644
68560index 0000000..2bd4c8d
68561--- /dev/null
68562+++ b/include/linux/grmsg.h
68563@@ -0,0 +1,111 @@
68564+#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"
68565+#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"
68566+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
68567+#define GR_STOPMOD_MSG "denied modification of module state by "
68568+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
68569+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
68570+#define GR_IOPERM_MSG "denied use of ioperm() by "
68571+#define GR_IOPL_MSG "denied use of iopl() by "
68572+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
68573+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
68574+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
68575+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
68576+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
68577+#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"
68578+#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"
68579+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
68580+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
68581+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
68582+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
68583+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
68584+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
68585+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
68586+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
68587+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
68588+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
68589+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
68590+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
68591+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
68592+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
68593+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
68594+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
68595+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
68596+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
68597+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
68598+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
68599+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
68600+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
68601+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
68602+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
68603+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
68604+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
68605+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
68606+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
68607+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
68608+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
68609+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
68610+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
68611+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
68612+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
68613+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
68614+#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"
68615+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
68616+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
68617+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
68618+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
68619+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
68620+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
68621+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
68622+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
68623+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
68624+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
68625+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
68626+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
68627+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
68628+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
68629+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
68630+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
68631+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
68632+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
68633+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
68634+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
68635+#define GR_FAILFORK_MSG "failed fork with errno %s by "
68636+#define GR_NICE_CHROOT_MSG "denied priority change by "
68637+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
68638+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
68639+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
68640+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
68641+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
68642+#define GR_TIME_MSG "time set by "
68643+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
68644+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
68645+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
68646+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
68647+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
68648+#define GR_BIND_MSG "denied bind() by "
68649+#define GR_CONNECT_MSG "denied connect() by "
68650+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
68651+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
68652+#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"
68653+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
68654+#define GR_CAP_ACL_MSG "use of %s denied for "
68655+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
68656+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
68657+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
68658+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
68659+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
68660+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
68661+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
68662+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
68663+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
68664+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
68665+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
68666+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
68667+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
68668+#define GR_VM86_MSG "denied use of vm86 by "
68669+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
68670+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
68671+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
68672+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
68673+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
68674+#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 "
68675diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
68676new file mode 100644
68677index 0000000..8da63a4
68678--- /dev/null
68679+++ b/include/linux/grsecurity.h
68680@@ -0,0 +1,242 @@
68681+#ifndef GR_SECURITY_H
68682+#define GR_SECURITY_H
68683+#include <linux/fs.h>
68684+#include <linux/fs_struct.h>
68685+#include <linux/binfmts.h>
68686+#include <linux/gracl.h>
68687+
68688+/* notify of brain-dead configs */
68689+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68690+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
68691+#endif
68692+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
68693+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
68694+#endif
68695+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
68696+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
68697+#endif
68698+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
68699+#error "CONFIG_PAX enabled, but no PaX options are enabled."
68700+#endif
68701+
68702+void gr_handle_brute_attach(unsigned long mm_flags);
68703+void gr_handle_brute_check(void);
68704+void gr_handle_kernel_exploit(void);
68705+int gr_process_user_ban(void);
68706+
68707+char gr_roletype_to_char(void);
68708+
68709+int gr_acl_enable_at_secure(void);
68710+
68711+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
68712+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
68713+
68714+void gr_del_task_from_ip_table(struct task_struct *p);
68715+
68716+int gr_pid_is_chrooted(struct task_struct *p);
68717+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
68718+int gr_handle_chroot_nice(void);
68719+int gr_handle_chroot_sysctl(const int op);
68720+int gr_handle_chroot_setpriority(struct task_struct *p,
68721+ const int niceval);
68722+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
68723+int gr_handle_chroot_chroot(const struct dentry *dentry,
68724+ const struct vfsmount *mnt);
68725+void gr_handle_chroot_chdir(struct path *path);
68726+int gr_handle_chroot_chmod(const struct dentry *dentry,
68727+ const struct vfsmount *mnt, const int mode);
68728+int gr_handle_chroot_mknod(const struct dentry *dentry,
68729+ const struct vfsmount *mnt, const int mode);
68730+int gr_handle_chroot_mount(const struct dentry *dentry,
68731+ const struct vfsmount *mnt,
68732+ const char *dev_name);
68733+int gr_handle_chroot_pivot(void);
68734+int gr_handle_chroot_unix(const pid_t pid);
68735+
68736+int gr_handle_rawio(const struct inode *inode);
68737+
68738+void gr_handle_ioperm(void);
68739+void gr_handle_iopl(void);
68740+
68741+umode_t gr_acl_umask(void);
68742+
68743+int gr_tpe_allow(const struct file *file);
68744+
68745+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
68746+void gr_clear_chroot_entries(struct task_struct *task);
68747+
68748+void gr_log_forkfail(const int retval);
68749+void gr_log_timechange(void);
68750+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
68751+void gr_log_chdir(const struct dentry *dentry,
68752+ const struct vfsmount *mnt);
68753+void gr_log_chroot_exec(const struct dentry *dentry,
68754+ const struct vfsmount *mnt);
68755+void gr_log_remount(const char *devname, const int retval);
68756+void gr_log_unmount(const char *devname, const int retval);
68757+void gr_log_mount(const char *from, const char *to, const int retval);
68758+void gr_log_textrel(struct vm_area_struct *vma);
68759+void gr_log_rwxmmap(struct file *file);
68760+void gr_log_rwxmprotect(struct file *file);
68761+
68762+int gr_handle_follow_link(const struct inode *parent,
68763+ const struct inode *inode,
68764+ const struct dentry *dentry,
68765+ const struct vfsmount *mnt);
68766+int gr_handle_fifo(const struct dentry *dentry,
68767+ const struct vfsmount *mnt,
68768+ const struct dentry *dir, const int flag,
68769+ const int acc_mode);
68770+int gr_handle_hardlink(const struct dentry *dentry,
68771+ const struct vfsmount *mnt,
68772+ struct inode *inode,
68773+ const int mode, const struct filename *to);
68774+
68775+int gr_is_capable(const int cap);
68776+int gr_is_capable_nolog(const int cap);
68777+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
68778+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
68779+
68780+void gr_copy_label(struct task_struct *tsk);
68781+void gr_handle_crash(struct task_struct *task, const int sig);
68782+int gr_handle_signal(const struct task_struct *p, const int sig);
68783+int gr_check_crash_uid(const kuid_t uid);
68784+int gr_check_protected_task(const struct task_struct *task);
68785+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
68786+int gr_acl_handle_mmap(const struct file *file,
68787+ const unsigned long prot);
68788+int gr_acl_handle_mprotect(const struct file *file,
68789+ const unsigned long prot);
68790+int gr_check_hidden_task(const struct task_struct *tsk);
68791+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
68792+ const struct vfsmount *mnt);
68793+__u32 gr_acl_handle_utime(const struct dentry *dentry,
68794+ const struct vfsmount *mnt);
68795+__u32 gr_acl_handle_access(const struct dentry *dentry,
68796+ const struct vfsmount *mnt, const int fmode);
68797+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
68798+ const struct vfsmount *mnt, umode_t *mode);
68799+__u32 gr_acl_handle_chown(const struct dentry *dentry,
68800+ const struct vfsmount *mnt);
68801+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
68802+ const struct vfsmount *mnt);
68803+int gr_handle_ptrace(struct task_struct *task, const long request);
68804+int gr_handle_proc_ptrace(struct task_struct *task);
68805+__u32 gr_acl_handle_execve(const struct dentry *dentry,
68806+ const struct vfsmount *mnt);
68807+int gr_check_crash_exec(const struct file *filp);
68808+int gr_acl_is_enabled(void);
68809+void gr_set_kernel_label(struct task_struct *task);
68810+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
68811+ const kgid_t gid);
68812+int gr_set_proc_label(const struct dentry *dentry,
68813+ const struct vfsmount *mnt,
68814+ const int unsafe_flags);
68815+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
68816+ const struct vfsmount *mnt);
68817+__u32 gr_acl_handle_open(const struct dentry *dentry,
68818+ const struct vfsmount *mnt, int acc_mode);
68819+__u32 gr_acl_handle_creat(const struct dentry *dentry,
68820+ const struct dentry *p_dentry,
68821+ const struct vfsmount *p_mnt,
68822+ int open_flags, int acc_mode, const int imode);
68823+void gr_handle_create(const struct dentry *dentry,
68824+ const struct vfsmount *mnt);
68825+void gr_handle_proc_create(const struct dentry *dentry,
68826+ const struct inode *inode);
68827+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
68828+ const struct dentry *parent_dentry,
68829+ const struct vfsmount *parent_mnt,
68830+ const int mode);
68831+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
68832+ const struct dentry *parent_dentry,
68833+ const struct vfsmount *parent_mnt);
68834+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
68835+ const struct vfsmount *mnt);
68836+void gr_handle_delete(const ino_t ino, const dev_t dev);
68837+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
68838+ const struct vfsmount *mnt);
68839+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
68840+ const struct dentry *parent_dentry,
68841+ const struct vfsmount *parent_mnt,
68842+ const struct filename *from);
68843+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
68844+ const struct dentry *parent_dentry,
68845+ const struct vfsmount *parent_mnt,
68846+ const struct dentry *old_dentry,
68847+ const struct vfsmount *old_mnt, const struct filename *to);
68848+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
68849+int gr_acl_handle_rename(struct dentry *new_dentry,
68850+ struct dentry *parent_dentry,
68851+ const struct vfsmount *parent_mnt,
68852+ struct dentry *old_dentry,
68853+ struct inode *old_parent_inode,
68854+ struct vfsmount *old_mnt, const struct filename *newname);
68855+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68856+ struct dentry *old_dentry,
68857+ struct dentry *new_dentry,
68858+ struct vfsmount *mnt, const __u8 replace);
68859+__u32 gr_check_link(const struct dentry *new_dentry,
68860+ const struct dentry *parent_dentry,
68861+ const struct vfsmount *parent_mnt,
68862+ const struct dentry *old_dentry,
68863+ const struct vfsmount *old_mnt);
68864+int gr_acl_handle_filldir(const struct file *file, const char *name,
68865+ const unsigned int namelen, const ino_t ino);
68866+
68867+__u32 gr_acl_handle_unix(const struct dentry *dentry,
68868+ const struct vfsmount *mnt);
68869+void gr_acl_handle_exit(void);
68870+void gr_acl_handle_psacct(struct task_struct *task, const long code);
68871+int gr_acl_handle_procpidmem(const struct task_struct *task);
68872+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
68873+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
68874+void gr_audit_ptrace(struct task_struct *task);
68875+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
68876+void gr_put_exec_file(struct task_struct *task);
68877+
68878+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
68879+
68880+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
68881+extern void gr_learn_resource(const struct task_struct *task, const int res,
68882+ const unsigned long wanted, const int gt);
68883+#else
68884+static inline void gr_learn_resource(const struct task_struct *task, const int res,
68885+ const unsigned long wanted, const int gt)
68886+{
68887+}
68888+#endif
68889+
68890+#ifdef CONFIG_GRKERNSEC_RESLOG
68891+extern void gr_log_resource(const struct task_struct *task, const int res,
68892+ const unsigned long wanted, const int gt);
68893+#else
68894+static inline void gr_log_resource(const struct task_struct *task, const int res,
68895+ const unsigned long wanted, const int gt)
68896+{
68897+}
68898+#endif
68899+
68900+#ifdef CONFIG_GRKERNSEC
68901+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
68902+void gr_handle_vm86(void);
68903+void gr_handle_mem_readwrite(u64 from, u64 to);
68904+
68905+void gr_log_badprocpid(const char *entry);
68906+
68907+extern int grsec_enable_dmesg;
68908+extern int grsec_disable_privio;
68909+
68910+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68911+extern kgid_t grsec_proc_gid;
68912+#endif
68913+
68914+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68915+extern int grsec_enable_chroot_findtask;
68916+#endif
68917+#ifdef CONFIG_GRKERNSEC_SETXID
68918+extern int grsec_enable_setxid;
68919+#endif
68920+#endif
68921+
68922+#endif
68923diff --git a/include/linux/grsock.h b/include/linux/grsock.h
68924new file mode 100644
68925index 0000000..e7ffaaf
68926--- /dev/null
68927+++ b/include/linux/grsock.h
68928@@ -0,0 +1,19 @@
68929+#ifndef __GRSOCK_H
68930+#define __GRSOCK_H
68931+
68932+extern void gr_attach_curr_ip(const struct sock *sk);
68933+extern int gr_handle_sock_all(const int family, const int type,
68934+ const int protocol);
68935+extern int gr_handle_sock_server(const struct sockaddr *sck);
68936+extern int gr_handle_sock_server_other(const struct sock *sck);
68937+extern int gr_handle_sock_client(const struct sockaddr *sck);
68938+extern int gr_search_connect(struct socket * sock,
68939+ struct sockaddr_in * addr);
68940+extern int gr_search_bind(struct socket * sock,
68941+ struct sockaddr_in * addr);
68942+extern int gr_search_listen(struct socket * sock);
68943+extern int gr_search_accept(struct socket * sock);
68944+extern int gr_search_socket(const int domain, const int type,
68945+ const int protocol);
68946+
68947+#endif
68948diff --git a/include/linux/highmem.h b/include/linux/highmem.h
68949index ef788b5..ac41b7b 100644
68950--- a/include/linux/highmem.h
68951+++ b/include/linux/highmem.h
68952@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
68953 kunmap_atomic(kaddr);
68954 }
68955
68956+static inline void sanitize_highpage(struct page *page)
68957+{
68958+ void *kaddr;
68959+ unsigned long flags;
68960+
68961+ local_irq_save(flags);
68962+ kaddr = kmap_atomic(page);
68963+ clear_page(kaddr);
68964+ kunmap_atomic(kaddr);
68965+ local_irq_restore(flags);
68966+}
68967+
68968 static inline void zero_user_segments(struct page *page,
68969 unsigned start1, unsigned end1,
68970 unsigned start2, unsigned end2)
68971diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
68972index 1c7b89a..7f52502 100644
68973--- a/include/linux/hwmon-sysfs.h
68974+++ b/include/linux/hwmon-sysfs.h
68975@@ -25,7 +25,8 @@
68976 struct sensor_device_attribute{
68977 struct device_attribute dev_attr;
68978 int index;
68979-};
68980+} __do_const;
68981+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
68982 #define to_sensor_dev_attr(_dev_attr) \
68983 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
68984
68985@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
68986 struct device_attribute dev_attr;
68987 u8 index;
68988 u8 nr;
68989-};
68990+} __do_const;
68991 #define to_sensor_dev_attr_2(_dev_attr) \
68992 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
68993
68994diff --git a/include/linux/i2c.h b/include/linux/i2c.h
68995index d0c4db7..61b3577 100644
68996--- a/include/linux/i2c.h
68997+++ b/include/linux/i2c.h
68998@@ -369,6 +369,7 @@ struct i2c_algorithm {
68999 /* To determine what the adapter supports */
69000 u32 (*functionality) (struct i2c_adapter *);
69001 };
69002+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
69003
69004 /*
69005 * i2c_adapter is the structure used to identify a physical i2c bus along
69006diff --git a/include/linux/i2o.h b/include/linux/i2o.h
69007index d23c3c2..eb63c81 100644
69008--- a/include/linux/i2o.h
69009+++ b/include/linux/i2o.h
69010@@ -565,7 +565,7 @@ struct i2o_controller {
69011 struct i2o_device *exec; /* Executive */
69012 #if BITS_PER_LONG == 64
69013 spinlock_t context_list_lock; /* lock for context_list */
69014- atomic_t context_list_counter; /* needed for unique contexts */
69015+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
69016 struct list_head context_list; /* list of context id's
69017 and pointers */
69018 #endif
69019diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
69020index aff7ad8..3942bbd 100644
69021--- a/include/linux/if_pppox.h
69022+++ b/include/linux/if_pppox.h
69023@@ -76,7 +76,7 @@ struct pppox_proto {
69024 int (*ioctl)(struct socket *sock, unsigned int cmd,
69025 unsigned long arg);
69026 struct module *owner;
69027-};
69028+} __do_const;
69029
69030 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
69031 extern void unregister_pppox_proto(int proto_num);
69032diff --git a/include/linux/init.h b/include/linux/init.h
69033index 10ed4f4..8e8490d 100644
69034--- a/include/linux/init.h
69035+++ b/include/linux/init.h
69036@@ -39,9 +39,36 @@
69037 * Also note, that this data cannot be "const".
69038 */
69039
69040+#ifdef MODULE
69041+#define add_init_latent_entropy
69042+#define add_devinit_latent_entropy
69043+#define add_cpuinit_latent_entropy
69044+#define add_meminit_latent_entropy
69045+#else
69046+#define add_init_latent_entropy __latent_entropy
69047+
69048+#ifdef CONFIG_HOTPLUG
69049+#define add_devinit_latent_entropy
69050+#else
69051+#define add_devinit_latent_entropy __latent_entropy
69052+#endif
69053+
69054+#ifdef CONFIG_HOTPLUG_CPU
69055+#define add_cpuinit_latent_entropy
69056+#else
69057+#define add_cpuinit_latent_entropy __latent_entropy
69058+#endif
69059+
69060+#ifdef CONFIG_MEMORY_HOTPLUG
69061+#define add_meminit_latent_entropy
69062+#else
69063+#define add_meminit_latent_entropy __latent_entropy
69064+#endif
69065+#endif
69066+
69067 /* These are for everybody (although not all archs will actually
69068 discard it in modules) */
69069-#define __init __section(.init.text) __cold notrace
69070+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
69071 #define __initdata __section(.init.data)
69072 #define __initconst __constsection(.init.rodata)
69073 #define __exitdata __section(.exit.data)
69074@@ -94,7 +121,7 @@
69075 #define __exit __section(.exit.text) __exitused __cold notrace
69076
69077 /* Used for HOTPLUG_CPU */
69078-#define __cpuinit __section(.cpuinit.text) __cold notrace
69079+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
69080 #define __cpuinitdata __section(.cpuinit.data)
69081 #define __cpuinitconst __constsection(.cpuinit.rodata)
69082 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
69083@@ -102,7 +129,7 @@
69084 #define __cpuexitconst __constsection(.cpuexit.rodata)
69085
69086 /* Used for MEMORY_HOTPLUG */
69087-#define __meminit __section(.meminit.text) __cold notrace
69088+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
69089 #define __meminitdata __section(.meminit.data)
69090 #define __meminitconst __constsection(.meminit.rodata)
69091 #define __memexit __section(.memexit.text) __exitused __cold notrace
69092diff --git a/include/linux/init_task.h b/include/linux/init_task.h
69093index 6d087c5..401cab8 100644
69094--- a/include/linux/init_task.h
69095+++ b/include/linux/init_task.h
69096@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
69097
69098 #define INIT_TASK_COMM "swapper"
69099
69100+#ifdef CONFIG_X86
69101+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
69102+#else
69103+#define INIT_TASK_THREAD_INFO
69104+#endif
69105+
69106 /*
69107 * INIT_TASK is used to set up the first task table, touch at
69108 * your own risk!. Base=0, limit=0x1fffff (=2MB)
69109@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
69110 RCU_POINTER_INITIALIZER(cred, &init_cred), \
69111 .comm = INIT_TASK_COMM, \
69112 .thread = INIT_THREAD, \
69113+ INIT_TASK_THREAD_INFO \
69114 .fs = &init_fs, \
69115 .files = &init_files, \
69116 .signal = &init_signals, \
69117diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
69118index 5fa5afe..ac55b25 100644
69119--- a/include/linux/interrupt.h
69120+++ b/include/linux/interrupt.h
69121@@ -430,7 +430,7 @@ enum
69122 /* map softirq index to softirq name. update 'softirq_to_name' in
69123 * kernel/softirq.c when adding a new softirq.
69124 */
69125-extern char *softirq_to_name[NR_SOFTIRQS];
69126+extern const char * const softirq_to_name[NR_SOFTIRQS];
69127
69128 /* softirq mask and active fields moved to irq_cpustat_t in
69129 * asm/hardirq.h to get better cache usage. KAO
69130@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
69131
69132 struct softirq_action
69133 {
69134- void (*action)(struct softirq_action *);
69135-};
69136+ void (*action)(void);
69137+} __no_const;
69138
69139 asmlinkage void do_softirq(void);
69140 asmlinkage void __do_softirq(void);
69141-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
69142+extern void open_softirq(int nr, void (*action)(void));
69143 extern void softirq_init(void);
69144 extern void __raise_softirq_irqoff(unsigned int nr);
69145
69146diff --git a/include/linux/iommu.h b/include/linux/iommu.h
69147index f3b99e1..9b73cee 100644
69148--- a/include/linux/iommu.h
69149+++ b/include/linux/iommu.h
69150@@ -101,7 +101,7 @@ struct iommu_ops {
69151 int (*domain_set_attr)(struct iommu_domain *domain,
69152 enum iommu_attr attr, void *data);
69153 unsigned long pgsize_bitmap;
69154-};
69155+} __do_const;
69156
69157 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
69158 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
69159diff --git a/include/linux/irq.h b/include/linux/irq.h
69160index fdf2c4a..5332486 100644
69161--- a/include/linux/irq.h
69162+++ b/include/linux/irq.h
69163@@ -328,7 +328,8 @@ struct irq_chip {
69164 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
69165
69166 unsigned long flags;
69167-};
69168+} __do_const;
69169+typedef struct irq_chip __no_const irq_chip_no_const;
69170
69171 /*
69172 * irq_chip specific flags
69173diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
69174index 6883e19..06992b1 100644
69175--- a/include/linux/kallsyms.h
69176+++ b/include/linux/kallsyms.h
69177@@ -15,7 +15,8 @@
69178
69179 struct module;
69180
69181-#ifdef CONFIG_KALLSYMS
69182+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
69183+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
69184 /* Lookup the address for a symbol. Returns 0 if not found. */
69185 unsigned long kallsyms_lookup_name(const char *name);
69186
69187@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
69188 /* Stupid that this does nothing, but I didn't create this mess. */
69189 #define __print_symbol(fmt, addr)
69190 #endif /*CONFIG_KALLSYMS*/
69191+#else /* when included by kallsyms.c, vsnprintf.c, or
69192+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
69193+extern void __print_symbol(const char *fmt, unsigned long address);
69194+extern int sprint_backtrace(char *buffer, unsigned long address);
69195+extern int sprint_symbol(char *buffer, unsigned long address);
69196+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
69197+const char *kallsyms_lookup(unsigned long addr,
69198+ unsigned long *symbolsize,
69199+ unsigned long *offset,
69200+ char **modname, char *namebuf);
69201+#endif
69202
69203 /* This macro allows us to keep printk typechecking */
69204 static __printf(1, 2)
69205diff --git a/include/linux/key-type.h b/include/linux/key-type.h
69206index 518a53a..5e28358 100644
69207--- a/include/linux/key-type.h
69208+++ b/include/linux/key-type.h
69209@@ -125,7 +125,7 @@ struct key_type {
69210 /* internal fields */
69211 struct list_head link; /* link in types list */
69212 struct lock_class_key lock_class; /* key->sem lock class */
69213-};
69214+} __do_const;
69215
69216 extern struct key_type key_type_keyring;
69217
69218diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
69219index 4dff0c6..1ca9b72 100644
69220--- a/include/linux/kgdb.h
69221+++ b/include/linux/kgdb.h
69222@@ -53,7 +53,7 @@ extern int kgdb_connected;
69223 extern int kgdb_io_module_registered;
69224
69225 extern atomic_t kgdb_setting_breakpoint;
69226-extern atomic_t kgdb_cpu_doing_single_step;
69227+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
69228
69229 extern struct task_struct *kgdb_usethread;
69230 extern struct task_struct *kgdb_contthread;
69231@@ -255,7 +255,7 @@ struct kgdb_arch {
69232 void (*correct_hw_break)(void);
69233
69234 void (*enable_nmi)(bool on);
69235-};
69236+} __do_const;
69237
69238 /**
69239 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
69240@@ -280,7 +280,7 @@ struct kgdb_io {
69241 void (*pre_exception) (void);
69242 void (*post_exception) (void);
69243 int is_console;
69244-};
69245+} __do_const;
69246
69247 extern struct kgdb_arch arch_kgdb_ops;
69248
69249diff --git a/include/linux/kmod.h b/include/linux/kmod.h
69250index 5398d58..5883a34 100644
69251--- a/include/linux/kmod.h
69252+++ b/include/linux/kmod.h
69253@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
69254 * usually useless though. */
69255 extern __printf(2, 3)
69256 int __request_module(bool wait, const char *name, ...);
69257+extern __printf(3, 4)
69258+int ___request_module(bool wait, char *param_name, const char *name, ...);
69259 #define request_module(mod...) __request_module(true, mod)
69260 #define request_module_nowait(mod...) __request_module(false, mod)
69261 #define try_then_request_module(x, mod...) \
69262diff --git a/include/linux/kobject.h b/include/linux/kobject.h
69263index 939b112..ed6ed51 100644
69264--- a/include/linux/kobject.h
69265+++ b/include/linux/kobject.h
69266@@ -111,7 +111,7 @@ struct kobj_type {
69267 struct attribute **default_attrs;
69268 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
69269 const void *(*namespace)(struct kobject *kobj);
69270-};
69271+} __do_const;
69272
69273 struct kobj_uevent_env {
69274 char *envp[UEVENT_NUM_ENVP];
69275@@ -134,6 +134,7 @@ struct kobj_attribute {
69276 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
69277 const char *buf, size_t count);
69278 };
69279+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
69280
69281 extern const struct sysfs_ops kobj_sysfs_ops;
69282
69283diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
69284index f66b065..c2c29b4 100644
69285--- a/include/linux/kobject_ns.h
69286+++ b/include/linux/kobject_ns.h
69287@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
69288 const void *(*netlink_ns)(struct sock *sk);
69289 const void *(*initial_ns)(void);
69290 void (*drop_ns)(void *);
69291-};
69292+} __do_const;
69293
69294 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
69295 int kobj_ns_type_registered(enum kobj_ns_type type);
69296diff --git a/include/linux/kref.h b/include/linux/kref.h
69297index 4972e6e..de4d19b 100644
69298--- a/include/linux/kref.h
69299+++ b/include/linux/kref.h
69300@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
69301 static inline int kref_sub(struct kref *kref, unsigned int count,
69302 void (*release)(struct kref *kref))
69303 {
69304- WARN_ON(release == NULL);
69305+ BUG_ON(release == NULL);
69306
69307 if (atomic_sub_and_test((int) count, &kref->refcount)) {
69308 release(kref);
69309diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
69310index 2c497ab..afe32f5 100644
69311--- a/include/linux/kvm_host.h
69312+++ b/include/linux/kvm_host.h
69313@@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
69314 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
69315 void vcpu_put(struct kvm_vcpu *vcpu);
69316
69317-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
69318+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
69319 struct module *module);
69320 void kvm_exit(void);
69321
69322@@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
69323 struct kvm_guest_debug *dbg);
69324 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
69325
69326-int kvm_arch_init(void *opaque);
69327+int kvm_arch_init(const void *opaque);
69328 void kvm_arch_exit(void);
69329
69330 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
69331diff --git a/include/linux/libata.h b/include/linux/libata.h
69332index 649e5f8..ead5194 100644
69333--- a/include/linux/libata.h
69334+++ b/include/linux/libata.h
69335@@ -915,7 +915,7 @@ struct ata_port_operations {
69336 * fields must be pointers.
69337 */
69338 const struct ata_port_operations *inherits;
69339-};
69340+} __do_const;
69341
69342 struct ata_port_info {
69343 unsigned long flags;
69344diff --git a/include/linux/list.h b/include/linux/list.h
69345index cc6d2aa..c10ee83 100644
69346--- a/include/linux/list.h
69347+++ b/include/linux/list.h
69348@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
69349 extern void list_del(struct list_head *entry);
69350 #endif
69351
69352+extern void __pax_list_add(struct list_head *new,
69353+ struct list_head *prev,
69354+ struct list_head *next);
69355+static inline void pax_list_add(struct list_head *new, struct list_head *head)
69356+{
69357+ __pax_list_add(new, head, head->next);
69358+}
69359+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
69360+{
69361+ __pax_list_add(new, head->prev, head);
69362+}
69363+extern void pax_list_del(struct list_head *entry);
69364+
69365 /**
69366 * list_replace - replace old entry by new one
69367 * @old : the element to be replaced
69368@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
69369 INIT_LIST_HEAD(entry);
69370 }
69371
69372+extern void pax_list_del_init(struct list_head *entry);
69373+
69374 /**
69375 * list_move - delete from one list and add as another's head
69376 * @list: the entry to move
69377diff --git a/include/linux/math64.h b/include/linux/math64.h
69378index b8ba855..0148090 100644
69379--- a/include/linux/math64.h
69380+++ b/include/linux/math64.h
69381@@ -14,7 +14,7 @@
69382 * This is commonly provided by 32bit archs to provide an optimized 64bit
69383 * divide.
69384 */
69385-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69386+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69387 {
69388 *remainder = dividend % divisor;
69389 return dividend / divisor;
69390@@ -50,7 +50,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
69391 #define div64_long(x,y) div_s64((x),(y))
69392
69393 #ifndef div_u64_rem
69394-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69395+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69396 {
69397 *remainder = do_div(dividend, divisor);
69398 return dividend;
69399@@ -79,7 +79,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
69400 * divide.
69401 */
69402 #ifndef div_u64
69403-static inline u64 div_u64(u64 dividend, u32 divisor)
69404+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
69405 {
69406 u32 remainder;
69407 return div_u64_rem(dividend, divisor, &remainder);
69408diff --git a/include/linux/mm.h b/include/linux/mm.h
69409index 66e2f7c..a398fb2 100644
69410--- a/include/linux/mm.h
69411+++ b/include/linux/mm.h
69412@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
69413 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
69414 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
69415 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
69416+
69417+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
69418+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
69419+#endif
69420+
69421 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
69422
69423 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
69424@@ -231,6 +236,7 @@ struct vm_operations_struct {
69425 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
69426 unsigned long size, pgoff_t pgoff);
69427 };
69428+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
69429
69430 struct mmu_gather;
69431 struct inode;
69432@@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
69433 int set_page_dirty_lock(struct page *page);
69434 int clear_page_dirty_for_io(struct page *page);
69435
69436-/* Is the vma a continuation of the stack vma above it? */
69437-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
69438-{
69439- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
69440-}
69441-
69442-static inline int stack_guard_page_start(struct vm_area_struct *vma,
69443- unsigned long addr)
69444-{
69445- return (vma->vm_flags & VM_GROWSDOWN) &&
69446- (vma->vm_start == addr) &&
69447- !vma_growsdown(vma->vm_prev, addr);
69448-}
69449-
69450-/* Is the vma a continuation of the stack vma below it? */
69451-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
69452-{
69453- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
69454-}
69455-
69456-static inline int stack_guard_page_end(struct vm_area_struct *vma,
69457- unsigned long addr)
69458-{
69459- return (vma->vm_flags & VM_GROWSUP) &&
69460- (vma->vm_end == addr) &&
69461- !vma_growsup(vma->vm_next, addr);
69462-}
69463-
69464 extern pid_t
69465 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
69466
69467@@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
69468 }
69469 #endif
69470
69471+#ifdef CONFIG_MMU
69472+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
69473+#else
69474+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
69475+{
69476+ return __pgprot(0);
69477+}
69478+#endif
69479+
69480 int vma_wants_writenotify(struct vm_area_struct *vma);
69481
69482 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
69483@@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
69484 {
69485 return 0;
69486 }
69487+
69488+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
69489+ unsigned long address)
69490+{
69491+ return 0;
69492+}
69493 #else
69494 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
69495+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
69496 #endif
69497
69498 #ifdef __PAGETABLE_PMD_FOLDED
69499@@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
69500 {
69501 return 0;
69502 }
69503+
69504+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
69505+ unsigned long address)
69506+{
69507+ return 0;
69508+}
69509 #else
69510 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
69511+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
69512 #endif
69513
69514 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
69515@@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
69516 NULL: pud_offset(pgd, address);
69517 }
69518
69519+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
69520+{
69521+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
69522+ NULL: pud_offset(pgd, address);
69523+}
69524+
69525 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
69526 {
69527 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
69528 NULL: pmd_offset(pud, address);
69529 }
69530+
69531+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
69532+{
69533+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
69534+ NULL: pmd_offset(pud, address);
69535+}
69536 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
69537
69538 #if USE_SPLIT_PTLOCKS
69539@@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
69540 unsigned long, unsigned long,
69541 unsigned long, unsigned long);
69542 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
69543+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
69544
69545 /* These take the mm semaphore themselves */
69546 extern unsigned long vm_brk(unsigned long, unsigned long);
69547@@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
69548 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
69549 struct vm_area_struct **pprev);
69550
69551+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
69552+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
69553+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
69554+
69555 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
69556 NULL if none. Assume start_addr < end_addr. */
69557 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
69558@@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
69559 return vma;
69560 }
69561
69562-#ifdef CONFIG_MMU
69563-pgprot_t vm_get_page_prot(unsigned long vm_flags);
69564-#else
69565-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
69566-{
69567- return __pgprot(0);
69568-}
69569-#endif
69570-
69571 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
69572 unsigned long change_prot_numa(struct vm_area_struct *vma,
69573 unsigned long start, unsigned long end);
69574@@ -1649,6 +1658,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
69575 static inline void vm_stat_account(struct mm_struct *mm,
69576 unsigned long flags, struct file *file, long pages)
69577 {
69578+
69579+#ifdef CONFIG_PAX_RANDMMAP
69580+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
69581+#endif
69582+
69583 mm->total_vm += pages;
69584 }
69585 #endif /* CONFIG_PROC_FS */
69586@@ -1721,7 +1735,7 @@ extern int unpoison_memory(unsigned long pfn);
69587 extern int sysctl_memory_failure_early_kill;
69588 extern int sysctl_memory_failure_recovery;
69589 extern void shake_page(struct page *p, int access);
69590-extern atomic_long_t mce_bad_pages;
69591+extern atomic_long_unchecked_t mce_bad_pages;
69592 extern int soft_offline_page(struct page *page, int flags);
69593
69594 extern void dump_page(struct page *page);
69595@@ -1752,5 +1766,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
69596 static inline bool page_is_guard(struct page *page) { return false; }
69597 #endif /* CONFIG_DEBUG_PAGEALLOC */
69598
69599+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
69600+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
69601+#else
69602+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
69603+#endif
69604+
69605 #endif /* __KERNEL__ */
69606 #endif /* _LINUX_MM_H */
69607diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
69608index f8f5162..3aaf20f 100644
69609--- a/include/linux/mm_types.h
69610+++ b/include/linux/mm_types.h
69611@@ -288,6 +288,8 @@ struct vm_area_struct {
69612 #ifdef CONFIG_NUMA
69613 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
69614 #endif
69615+
69616+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
69617 };
69618
69619 struct core_thread {
69620@@ -436,6 +438,24 @@ struct mm_struct {
69621 int first_nid;
69622 #endif
69623 struct uprobes_state uprobes_state;
69624+
69625+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
69626+ unsigned long pax_flags;
69627+#endif
69628+
69629+#ifdef CONFIG_PAX_DLRESOLVE
69630+ unsigned long call_dl_resolve;
69631+#endif
69632+
69633+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
69634+ unsigned long call_syscall;
69635+#endif
69636+
69637+#ifdef CONFIG_PAX_ASLR
69638+ unsigned long delta_mmap; /* randomized offset */
69639+ unsigned long delta_stack; /* randomized offset */
69640+#endif
69641+
69642 };
69643
69644 /* first nid will either be a valid NID or one of these values */
69645diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
69646index c5d5278..f0b68c8 100644
69647--- a/include/linux/mmiotrace.h
69648+++ b/include/linux/mmiotrace.h
69649@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
69650 /* Called from ioremap.c */
69651 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
69652 void __iomem *addr);
69653-extern void mmiotrace_iounmap(volatile void __iomem *addr);
69654+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
69655
69656 /* For anyone to insert markers. Remember trailing newline. */
69657 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
69658@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
69659 {
69660 }
69661
69662-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
69663+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
69664 {
69665 }
69666
69667diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
69668index 73b64a3..6562925 100644
69669--- a/include/linux/mmzone.h
69670+++ b/include/linux/mmzone.h
69671@@ -412,7 +412,7 @@ struct zone {
69672 unsigned long flags; /* zone flags, see below */
69673
69674 /* Zone statistics */
69675- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
69676+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
69677
69678 /*
69679 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
69680diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
69681index fed3def..c933f99 100644
69682--- a/include/linux/mod_devicetable.h
69683+++ b/include/linux/mod_devicetable.h
69684@@ -12,7 +12,7 @@
69685 typedef unsigned long kernel_ulong_t;
69686 #endif
69687
69688-#define PCI_ANY_ID (~0)
69689+#define PCI_ANY_ID ((__u16)~0)
69690
69691 struct pci_device_id {
69692 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
69693@@ -139,7 +139,7 @@ struct usb_device_id {
69694 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
69695 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
69696
69697-#define HID_ANY_ID (~0)
69698+#define HID_ANY_ID (~0U)
69699 #define HID_BUS_ANY 0xffff
69700 #define HID_GROUP_ANY 0x0000
69701
69702@@ -498,7 +498,7 @@ struct dmi_system_id {
69703 const char *ident;
69704 struct dmi_strmatch matches[4];
69705 void *driver_data;
69706-};
69707+} __do_const;
69708 /*
69709 * struct dmi_device_id appears during expansion of
69710 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
69711diff --git a/include/linux/module.h b/include/linux/module.h
69712index 1375ee3..ced8177 100644
69713--- a/include/linux/module.h
69714+++ b/include/linux/module.h
69715@@ -17,9 +17,11 @@
69716 #include <linux/moduleparam.h>
69717 #include <linux/tracepoint.h>
69718 #include <linux/export.h>
69719+#include <linux/fs.h>
69720
69721 #include <linux/percpu.h>
69722 #include <asm/module.h>
69723+#include <asm/pgtable.h>
69724
69725 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
69726 #define MODULE_SIG_STRING "~Module signature appended~\n"
69727@@ -54,12 +56,13 @@ struct module_attribute {
69728 int (*test)(struct module *);
69729 void (*free)(struct module *);
69730 };
69731+typedef struct module_attribute __no_const module_attribute_no_const;
69732
69733 struct module_version_attribute {
69734 struct module_attribute mattr;
69735 const char *module_name;
69736 const char *version;
69737-} __attribute__ ((__aligned__(sizeof(void *))));
69738+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
69739
69740 extern ssize_t __modver_version_show(struct module_attribute *,
69741 struct module_kobject *, char *);
69742@@ -232,7 +235,7 @@ struct module
69743
69744 /* Sysfs stuff. */
69745 struct module_kobject mkobj;
69746- struct module_attribute *modinfo_attrs;
69747+ module_attribute_no_const *modinfo_attrs;
69748 const char *version;
69749 const char *srcversion;
69750 struct kobject *holders_dir;
69751@@ -281,19 +284,16 @@ struct module
69752 int (*init)(void);
69753
69754 /* If this is non-NULL, vfree after init() returns */
69755- void *module_init;
69756+ void *module_init_rx, *module_init_rw;
69757
69758 /* Here is the actual code + data, vfree'd on unload. */
69759- void *module_core;
69760+ void *module_core_rx, *module_core_rw;
69761
69762 /* Here are the sizes of the init and core sections */
69763- unsigned int init_size, core_size;
69764+ unsigned int init_size_rw, core_size_rw;
69765
69766 /* The size of the executable code in each section. */
69767- unsigned int init_text_size, core_text_size;
69768-
69769- /* Size of RO sections of the module (text+rodata) */
69770- unsigned int init_ro_size, core_ro_size;
69771+ unsigned int init_size_rx, core_size_rx;
69772
69773 /* Arch-specific module values */
69774 struct mod_arch_specific arch;
69775@@ -349,6 +349,10 @@ struct module
69776 #ifdef CONFIG_EVENT_TRACING
69777 struct ftrace_event_call **trace_events;
69778 unsigned int num_trace_events;
69779+ struct file_operations trace_id;
69780+ struct file_operations trace_enable;
69781+ struct file_operations trace_format;
69782+ struct file_operations trace_filter;
69783 #endif
69784 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
69785 unsigned int num_ftrace_callsites;
69786@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
69787 bool is_module_percpu_address(unsigned long addr);
69788 bool is_module_text_address(unsigned long addr);
69789
69790+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
69791+{
69792+
69793+#ifdef CONFIG_PAX_KERNEXEC
69794+ if (ktla_ktva(addr) >= (unsigned long)start &&
69795+ ktla_ktva(addr) < (unsigned long)start + size)
69796+ return 1;
69797+#endif
69798+
69799+ return ((void *)addr >= start && (void *)addr < start + size);
69800+}
69801+
69802+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
69803+{
69804+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
69805+}
69806+
69807+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
69808+{
69809+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
69810+}
69811+
69812+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
69813+{
69814+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
69815+}
69816+
69817+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
69818+{
69819+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
69820+}
69821+
69822 static inline int within_module_core(unsigned long addr, struct module *mod)
69823 {
69824- return (unsigned long)mod->module_core <= addr &&
69825- addr < (unsigned long)mod->module_core + mod->core_size;
69826+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
69827 }
69828
69829 static inline int within_module_init(unsigned long addr, struct module *mod)
69830 {
69831- return (unsigned long)mod->module_init <= addr &&
69832- addr < (unsigned long)mod->module_init + mod->init_size;
69833+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
69834 }
69835
69836 /* Search for module by name: must hold module_mutex. */
69837diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
69838index 560ca53..ef621ef 100644
69839--- a/include/linux/moduleloader.h
69840+++ b/include/linux/moduleloader.h
69841@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
69842 sections. Returns NULL on failure. */
69843 void *module_alloc(unsigned long size);
69844
69845+#ifdef CONFIG_PAX_KERNEXEC
69846+void *module_alloc_exec(unsigned long size);
69847+#else
69848+#define module_alloc_exec(x) module_alloc(x)
69849+#endif
69850+
69851 /* Free memory returned from module_alloc. */
69852 void module_free(struct module *mod, void *module_region);
69853
69854+#ifdef CONFIG_PAX_KERNEXEC
69855+void module_free_exec(struct module *mod, void *module_region);
69856+#else
69857+#define module_free_exec(x, y) module_free((x), (y))
69858+#endif
69859+
69860 /*
69861 * Apply the given relocation to the (simplified) ELF. Return -error
69862 * or 0.
69863@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
69864 unsigned int relsec,
69865 struct module *me)
69866 {
69867+#ifdef CONFIG_MODULES
69868 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
69869+#endif
69870 return -ENOEXEC;
69871 }
69872 #endif
69873@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
69874 unsigned int relsec,
69875 struct module *me)
69876 {
69877+#ifdef CONFIG_MODULES
69878 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
69879+#endif
69880 return -ENOEXEC;
69881 }
69882 #endif
69883diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
69884index 137b419..fe663ec 100644
69885--- a/include/linux/moduleparam.h
69886+++ b/include/linux/moduleparam.h
69887@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
69888 * @len is usually just sizeof(string).
69889 */
69890 #define module_param_string(name, string, len, perm) \
69891- static const struct kparam_string __param_string_##name \
69892+ static const struct kparam_string __param_string_##name __used \
69893 = { len, string }; \
69894 __module_param_call(MODULE_PARAM_PREFIX, name, \
69895 &param_ops_string, \
69896@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
69897 */
69898 #define module_param_array_named(name, array, type, nump, perm) \
69899 param_check_##type(name, &(array)[0]); \
69900- static const struct kparam_array __param_arr_##name \
69901+ static const struct kparam_array __param_arr_##name __used \
69902 = { .max = ARRAY_SIZE(array), .num = nump, \
69903 .ops = &param_ops_##type, \
69904 .elemsize = sizeof(array[0]), .elem = array }; \
69905diff --git a/include/linux/namei.h b/include/linux/namei.h
69906index 5a5ff57..5ae5070 100644
69907--- a/include/linux/namei.h
69908+++ b/include/linux/namei.h
69909@@ -19,7 +19,7 @@ struct nameidata {
69910 unsigned seq;
69911 int last_type;
69912 unsigned depth;
69913- char *saved_names[MAX_NESTED_LINKS + 1];
69914+ const char *saved_names[MAX_NESTED_LINKS + 1];
69915 };
69916
69917 /*
69918@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
69919
69920 extern void nd_jump_link(struct nameidata *nd, struct path *path);
69921
69922-static inline void nd_set_link(struct nameidata *nd, char *path)
69923+static inline void nd_set_link(struct nameidata *nd, const char *path)
69924 {
69925 nd->saved_names[nd->depth] = path;
69926 }
69927
69928-static inline char *nd_get_link(struct nameidata *nd)
69929+static inline const char *nd_get_link(const struct nameidata *nd)
69930 {
69931 return nd->saved_names[nd->depth];
69932 }
69933diff --git a/include/linux/net.h b/include/linux/net.h
69934index aa16731..514b875 100644
69935--- a/include/linux/net.h
69936+++ b/include/linux/net.h
69937@@ -183,7 +183,7 @@ struct net_proto_family {
69938 int (*create)(struct net *net, struct socket *sock,
69939 int protocol, int kern);
69940 struct module *owner;
69941-};
69942+} __do_const;
69943
69944 struct iovec;
69945 struct kvec;
69946diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
69947index 9ef07d0..130a5d9 100644
69948--- a/include/linux/netdevice.h
69949+++ b/include/linux/netdevice.h
69950@@ -1012,6 +1012,7 @@ struct net_device_ops {
69951 u32 pid, u32 seq,
69952 struct net_device *dev);
69953 };
69954+typedef struct net_device_ops __no_const net_device_ops_no_const;
69955
69956 /*
69957 * The DEVICE structure.
69958@@ -1078,7 +1079,7 @@ struct net_device {
69959 int iflink;
69960
69961 struct net_device_stats stats;
69962- atomic_long_t rx_dropped; /* dropped packets by core network
69963+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
69964 * Do not use this in drivers.
69965 */
69966
69967diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
69968index ee14284..bc65d63 100644
69969--- a/include/linux/netfilter.h
69970+++ b/include/linux/netfilter.h
69971@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
69972 #endif
69973 /* Use the module struct to lock set/get code in place */
69974 struct module *owner;
69975-};
69976+} __do_const;
69977
69978 /* Function to register/unregister hook points. */
69979 int nf_register_hook(struct nf_hook_ops *reg);
69980diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
69981index 7958e84..ed74d7a 100644
69982--- a/include/linux/netfilter/ipset/ip_set.h
69983+++ b/include/linux/netfilter/ipset/ip_set.h
69984@@ -98,7 +98,7 @@ struct ip_set_type_variant {
69985 /* Return true if "b" set is the same as "a"
69986 * according to the create set parameters */
69987 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
69988-};
69989+} __do_const;
69990
69991 /* The core set type structure */
69992 struct ip_set_type {
69993diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
69994index 4966dde..7d8ce06 100644
69995--- a/include/linux/netfilter/nfnetlink.h
69996+++ b/include/linux/netfilter/nfnetlink.h
69997@@ -16,7 +16,7 @@ struct nfnl_callback {
69998 const struct nlattr * const cda[]);
69999 const struct nla_policy *policy; /* netlink attribute policy */
70000 const u_int16_t attr_count; /* number of nlattr's */
70001-};
70002+} __do_const;
70003
70004 struct nfnetlink_subsystem {
70005 const char *name;
70006diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
70007new file mode 100644
70008index 0000000..33f4af8
70009--- /dev/null
70010+++ b/include/linux/netfilter/xt_gradm.h
70011@@ -0,0 +1,9 @@
70012+#ifndef _LINUX_NETFILTER_XT_GRADM_H
70013+#define _LINUX_NETFILTER_XT_GRADM_H 1
70014+
70015+struct xt_gradm_mtinfo {
70016+ __u16 flags;
70017+ __u16 invflags;
70018+};
70019+
70020+#endif
70021diff --git a/include/linux/nls.h b/include/linux/nls.h
70022index 5dc635f..35f5e11 100644
70023--- a/include/linux/nls.h
70024+++ b/include/linux/nls.h
70025@@ -31,7 +31,7 @@ struct nls_table {
70026 const unsigned char *charset2upper;
70027 struct module *owner;
70028 struct nls_table *next;
70029-};
70030+} __do_const;
70031
70032 /* this value hold the maximum octet of charset */
70033 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
70034diff --git a/include/linux/notifier.h b/include/linux/notifier.h
70035index d65746e..62e72c2 100644
70036--- a/include/linux/notifier.h
70037+++ b/include/linux/notifier.h
70038@@ -51,7 +51,8 @@ struct notifier_block {
70039 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
70040 struct notifier_block __rcu *next;
70041 int priority;
70042-};
70043+} __do_const;
70044+typedef struct notifier_block __no_const notifier_block_no_const;
70045
70046 struct atomic_notifier_head {
70047 spinlock_t lock;
70048diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
70049index a4c5624..79d6d88 100644
70050--- a/include/linux/oprofile.h
70051+++ b/include/linux/oprofile.h
70052@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
70053 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
70054 char const * name, ulong * val);
70055
70056-/** Create a file for read-only access to an atomic_t. */
70057+/** Create a file for read-only access to an atomic_unchecked_t. */
70058 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
70059- char const * name, atomic_t * val);
70060+ char const * name, atomic_unchecked_t * val);
70061
70062 /** create a directory */
70063 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
70064diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
70065index 45fc162..01a4068 100644
70066--- a/include/linux/pci_hotplug.h
70067+++ b/include/linux/pci_hotplug.h
70068@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
70069 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
70070 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
70071 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
70072-};
70073+} __do_const;
70074+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
70075
70076 /**
70077 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
70078diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
70079index a280650..2b67b91 100644
70080--- a/include/linux/perf_event.h
70081+++ b/include/linux/perf_event.h
70082@@ -328,8 +328,8 @@ struct perf_event {
70083
70084 enum perf_event_active_state state;
70085 unsigned int attach_state;
70086- local64_t count;
70087- atomic64_t child_count;
70088+ local64_t count; /* PaX: fix it one day */
70089+ atomic64_unchecked_t child_count;
70090
70091 /*
70092 * These are the total time in nanoseconds that the event
70093@@ -380,8 +380,8 @@ struct perf_event {
70094 * These accumulate total time (in nanoseconds) that children
70095 * events have been enabled and running, respectively.
70096 */
70097- atomic64_t child_total_time_enabled;
70098- atomic64_t child_total_time_running;
70099+ atomic64_unchecked_t child_total_time_enabled;
70100+ atomic64_unchecked_t child_total_time_running;
70101
70102 /*
70103 * Protect attach/detach and child_list:
70104@@ -807,7 +807,7 @@ static inline void perf_restore_debug_store(void) { }
70105 */
70106 #define perf_cpu_notifier(fn) \
70107 do { \
70108- static struct notifier_block fn##_nb __cpuinitdata = \
70109+ static struct notifier_block fn##_nb = \
70110 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
70111 unsigned long cpu = smp_processor_id(); \
70112 unsigned long flags; \
70113diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
70114index ad1a427..6419649 100644
70115--- a/include/linux/pipe_fs_i.h
70116+++ b/include/linux/pipe_fs_i.h
70117@@ -45,9 +45,9 @@ struct pipe_buffer {
70118 struct pipe_inode_info {
70119 wait_queue_head_t wait;
70120 unsigned int nrbufs, curbuf, buffers;
70121- unsigned int readers;
70122- unsigned int writers;
70123- unsigned int waiting_writers;
70124+ atomic_t readers;
70125+ atomic_t writers;
70126+ atomic_t waiting_writers;
70127 unsigned int r_counter;
70128 unsigned int w_counter;
70129 struct page *tmp_page;
70130diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
70131index 5f28cae..3d23723 100644
70132--- a/include/linux/platform_data/usb-ehci-s5p.h
70133+++ b/include/linux/platform_data/usb-ehci-s5p.h
70134@@ -14,7 +14,7 @@
70135 struct s5p_ehci_platdata {
70136 int (*phy_init)(struct platform_device *pdev, int type);
70137 int (*phy_exit)(struct platform_device *pdev, int type);
70138-};
70139+} __no_const;
70140
70141 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
70142
70143diff --git a/include/linux/platform_data/usb-exynos.h b/include/linux/platform_data/usb-exynos.h
70144index c256c59..8ea94c7 100644
70145--- a/include/linux/platform_data/usb-exynos.h
70146+++ b/include/linux/platform_data/usb-exynos.h
70147@@ -14,7 +14,7 @@
70148 struct exynos4_ohci_platdata {
70149 int (*phy_init)(struct platform_device *pdev, int type);
70150 int (*phy_exit)(struct platform_device *pdev, int type);
70151-};
70152+} __no_const;
70153
70154 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
70155
70156diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
70157index 7c1d252..c5c773e 100644
70158--- a/include/linux/pm_domain.h
70159+++ b/include/linux/pm_domain.h
70160@@ -48,7 +48,7 @@ struct gpd_dev_ops {
70161
70162 struct gpd_cpu_data {
70163 unsigned int saved_exit_latency;
70164- struct cpuidle_state *idle_state;
70165+ cpuidle_state_no_const *idle_state;
70166 };
70167
70168 struct generic_pm_domain {
70169diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
70170index f271860..6b3bec5 100644
70171--- a/include/linux/pm_runtime.h
70172+++ b/include/linux/pm_runtime.h
70173@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
70174
70175 static inline void pm_runtime_mark_last_busy(struct device *dev)
70176 {
70177- ACCESS_ONCE(dev->power.last_busy) = jiffies;
70178+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
70179 }
70180
70181 #else /* !CONFIG_PM_RUNTIME */
70182diff --git a/include/linux/pnp.h b/include/linux/pnp.h
70183index 195aafc..49a7bc2 100644
70184--- a/include/linux/pnp.h
70185+++ b/include/linux/pnp.h
70186@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
70187 struct pnp_fixup {
70188 char id[7];
70189 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
70190-};
70191+} __do_const;
70192
70193 /* config parameters */
70194 #define PNP_CONFIG_NORMAL 0x0001
70195diff --git a/include/linux/poison.h b/include/linux/poison.h
70196index 2110a81..13a11bb 100644
70197--- a/include/linux/poison.h
70198+++ b/include/linux/poison.h
70199@@ -19,8 +19,8 @@
70200 * under normal circumstances, used to verify that nobody uses
70201 * non-initialized list entries.
70202 */
70203-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
70204-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
70205+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
70206+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
70207
70208 /********** include/linux/timer.h **********/
70209 /*
70210diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
70211index c0f44c2..1572583 100644
70212--- a/include/linux/power/smartreflex.h
70213+++ b/include/linux/power/smartreflex.h
70214@@ -238,7 +238,7 @@ struct omap_sr_class_data {
70215 int (*notify)(struct omap_sr *sr, u32 status);
70216 u8 notify_flags;
70217 u8 class_type;
70218-};
70219+} __do_const;
70220
70221 /**
70222 * struct omap_sr_nvalue_table - Smartreflex n-target value info
70223diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
70224index 4ea1d37..80f4b33 100644
70225--- a/include/linux/ppp-comp.h
70226+++ b/include/linux/ppp-comp.h
70227@@ -84,7 +84,7 @@ struct compressor {
70228 struct module *owner;
70229 /* Extra skb space needed by the compressor algorithm */
70230 unsigned int comp_extra;
70231-};
70232+} __do_const;
70233
70234 /*
70235 * The return value from decompress routine is the length of the
70236diff --git a/include/linux/printk.h b/include/linux/printk.h
70237index 9afc01e..92c32e8 100644
70238--- a/include/linux/printk.h
70239+++ b/include/linux/printk.h
70240@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
70241 extern int printk_needs_cpu(int cpu);
70242 extern void printk_tick(void);
70243
70244+extern int kptr_restrict;
70245+
70246 #ifdef CONFIG_PRINTK
70247 asmlinkage __printf(5, 0)
70248 int vprintk_emit(int facility, int level,
70249@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
70250
70251 extern int printk_delay_msec;
70252 extern int dmesg_restrict;
70253-extern int kptr_restrict;
70254
70255 void log_buf_kexec_setup(void);
70256 void __init setup_log_buf(int early);
70257diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
70258index 32676b3..e46f2c0 100644
70259--- a/include/linux/proc_fs.h
70260+++ b/include/linux/proc_fs.h
70261@@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
70262 return proc_create_data(name, mode, parent, proc_fops, NULL);
70263 }
70264
70265+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
70266+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
70267+{
70268+#ifdef CONFIG_GRKERNSEC_PROC_USER
70269+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
70270+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70271+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
70272+#else
70273+ return proc_create_data(name, mode, parent, proc_fops, NULL);
70274+#endif
70275+}
70276+
70277 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
70278 umode_t mode, struct proc_dir_entry *base,
70279 read_proc_t *read_proc, void * data)
70280@@ -268,7 +280,7 @@ struct proc_ns_operations {
70281 void (*put)(void *ns);
70282 int (*install)(struct nsproxy *nsproxy, void *ns);
70283 unsigned int (*inum)(void *ns);
70284-};
70285+} __do_const;
70286 extern const struct proc_ns_operations netns_operations;
70287 extern const struct proc_ns_operations utsns_operations;
70288 extern const struct proc_ns_operations ipcns_operations;
70289diff --git a/include/linux/random.h b/include/linux/random.h
70290index d984608..d6f0042 100644
70291--- a/include/linux/random.h
70292+++ b/include/linux/random.h
70293@@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
70294 u32 prandom_u32_state(struct rnd_state *);
70295 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
70296
70297+static inline unsigned long pax_get_random_long(void)
70298+{
70299+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
70300+}
70301+
70302 /*
70303 * Handle minimum values for seeds
70304 */
70305diff --git a/include/linux/rculist.h b/include/linux/rculist.h
70306index c92dd28..08f4eab 100644
70307--- a/include/linux/rculist.h
70308+++ b/include/linux/rculist.h
70309@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
70310 struct list_head *prev, struct list_head *next);
70311 #endif
70312
70313+extern void __pax_list_add_rcu(struct list_head *new,
70314+ struct list_head *prev, struct list_head *next);
70315+
70316 /**
70317 * list_add_rcu - add a new entry to rcu-protected list
70318 * @new: new entry to be added
70319@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
70320 __list_add_rcu(new, head, head->next);
70321 }
70322
70323+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
70324+{
70325+ __pax_list_add_rcu(new, head, head->next);
70326+}
70327+
70328 /**
70329 * list_add_tail_rcu - add a new entry to rcu-protected list
70330 * @new: new entry to be added
70331@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
70332 __list_add_rcu(new, head->prev, head);
70333 }
70334
70335+static inline void pax_list_add_tail_rcu(struct list_head *new,
70336+ struct list_head *head)
70337+{
70338+ __pax_list_add_rcu(new, head->prev, head);
70339+}
70340+
70341 /**
70342 * list_del_rcu - deletes entry from list without re-initialization
70343 * @entry: the element to delete from the list.
70344@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
70345 entry->prev = LIST_POISON2;
70346 }
70347
70348+extern void pax_list_del_rcu(struct list_head *entry);
70349+
70350 /**
70351 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
70352 * @n: the element to delete from the hash list.
70353diff --git a/include/linux/reboot.h b/include/linux/reboot.h
70354index 23b3630..e1bc12b 100644
70355--- a/include/linux/reboot.h
70356+++ b/include/linux/reboot.h
70357@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
70358 * Architecture-specific implementations of sys_reboot commands.
70359 */
70360
70361-extern void machine_restart(char *cmd);
70362-extern void machine_halt(void);
70363-extern void machine_power_off(void);
70364+extern void machine_restart(char *cmd) __noreturn;
70365+extern void machine_halt(void) __noreturn;
70366+extern void machine_power_off(void) __noreturn;
70367
70368 extern void machine_shutdown(void);
70369 struct pt_regs;
70370@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
70371 */
70372
70373 extern void kernel_restart_prepare(char *cmd);
70374-extern void kernel_restart(char *cmd);
70375-extern void kernel_halt(void);
70376-extern void kernel_power_off(void);
70377+extern void kernel_restart(char *cmd) __noreturn;
70378+extern void kernel_halt(void) __noreturn;
70379+extern void kernel_power_off(void) __noreturn;
70380
70381 extern int C_A_D; /* for sysctl */
70382 void ctrl_alt_del(void);
70383@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
70384 * Emergency restart, callable from an interrupt handler.
70385 */
70386
70387-extern void emergency_restart(void);
70388+extern void emergency_restart(void) __noreturn;
70389 #include <asm/emergency-restart.h>
70390
70391 #endif /* _LINUX_REBOOT_H */
70392diff --git a/include/linux/regset.h b/include/linux/regset.h
70393index 8e0c9fe..ac4d221 100644
70394--- a/include/linux/regset.h
70395+++ b/include/linux/regset.h
70396@@ -161,7 +161,8 @@ struct user_regset {
70397 unsigned int align;
70398 unsigned int bias;
70399 unsigned int core_note_type;
70400-};
70401+} __do_const;
70402+typedef struct user_regset __no_const user_regset_no_const;
70403
70404 /**
70405 * struct user_regset_view - available regsets
70406diff --git a/include/linux/relay.h b/include/linux/relay.h
70407index 91cacc3..b55ff74 100644
70408--- a/include/linux/relay.h
70409+++ b/include/linux/relay.h
70410@@ -160,7 +160,7 @@ struct rchan_callbacks
70411 * The callback should return 0 if successful, negative if not.
70412 */
70413 int (*remove_buf_file)(struct dentry *dentry);
70414-};
70415+} __no_const;
70416
70417 /*
70418 * CONFIG_RELAY kernel API, kernel/relay.c
70419diff --git a/include/linux/rio.h b/include/linux/rio.h
70420index a3e7842..d973ca6 100644
70421--- a/include/linux/rio.h
70422+++ b/include/linux/rio.h
70423@@ -339,7 +339,7 @@ struct rio_ops {
70424 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
70425 u64 rstart, u32 size, u32 flags);
70426 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
70427-};
70428+} __no_const;
70429
70430 #define RIO_RESOURCE_MEM 0x00000100
70431 #define RIO_RESOURCE_DOORBELL 0x00000200
70432diff --git a/include/linux/rmap.h b/include/linux/rmap.h
70433index c20635c..2f5def4 100644
70434--- a/include/linux/rmap.h
70435+++ b/include/linux/rmap.h
70436@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
70437 void anon_vma_init(void); /* create anon_vma_cachep */
70438 int anon_vma_prepare(struct vm_area_struct *);
70439 void unlink_anon_vmas(struct vm_area_struct *);
70440-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
70441-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
70442+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
70443+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
70444
70445 static inline void anon_vma_merge(struct vm_area_struct *vma,
70446 struct vm_area_struct *next)
70447diff --git a/include/linux/sched.h b/include/linux/sched.h
70448index d211247..eac6c2c 100644
70449--- a/include/linux/sched.h
70450+++ b/include/linux/sched.h
70451@@ -61,6 +61,7 @@ struct bio_list;
70452 struct fs_struct;
70453 struct perf_event_context;
70454 struct blk_plug;
70455+struct linux_binprm;
70456
70457 /*
70458 * List of flags we want to share for kernel threads,
70459@@ -327,7 +328,7 @@ extern char __sched_text_start[], __sched_text_end[];
70460 extern int in_sched_functions(unsigned long addr);
70461
70462 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
70463-extern signed long schedule_timeout(signed long timeout);
70464+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
70465 extern signed long schedule_timeout_interruptible(signed long timeout);
70466 extern signed long schedule_timeout_killable(signed long timeout);
70467 extern signed long schedule_timeout_uninterruptible(signed long timeout);
70468@@ -354,10 +355,23 @@ struct user_namespace;
70469 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
70470
70471 extern int sysctl_max_map_count;
70472+extern unsigned long sysctl_heap_stack_gap;
70473
70474 #include <linux/aio.h>
70475
70476 #ifdef CONFIG_MMU
70477+
70478+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
70479+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
70480+#else
70481+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
70482+{
70483+ return 0;
70484+}
70485+#endif
70486+
70487+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
70488+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
70489 extern void arch_pick_mmap_layout(struct mm_struct *mm);
70490 extern unsigned long
70491 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
70492@@ -639,6 +653,17 @@ struct signal_struct {
70493 #ifdef CONFIG_TASKSTATS
70494 struct taskstats *stats;
70495 #endif
70496+
70497+#ifdef CONFIG_GRKERNSEC
70498+ u32 curr_ip;
70499+ u32 saved_ip;
70500+ u32 gr_saddr;
70501+ u32 gr_daddr;
70502+ u16 gr_sport;
70503+ u16 gr_dport;
70504+ u8 used_accept:1;
70505+#endif
70506+
70507 #ifdef CONFIG_AUDIT
70508 unsigned audit_tty;
70509 struct tty_audit_buf *tty_audit_buf;
70510@@ -717,6 +742,11 @@ struct user_struct {
70511 struct key *session_keyring; /* UID's default session keyring */
70512 #endif
70513
70514+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
70515+ unsigned int banned;
70516+ unsigned long ban_expires;
70517+#endif
70518+
70519 /* Hash table maintenance information */
70520 struct hlist_node uidhash_node;
70521 kuid_t uid;
70522@@ -1116,7 +1146,7 @@ struct sched_class {
70523 #ifdef CONFIG_FAIR_GROUP_SCHED
70524 void (*task_move_group) (struct task_struct *p, int on_rq);
70525 #endif
70526-};
70527+} __do_const;
70528
70529 struct load_weight {
70530 unsigned long weight, inv_weight;
70531@@ -1360,8 +1390,8 @@ struct task_struct {
70532 struct list_head thread_group;
70533
70534 struct completion *vfork_done; /* for vfork() */
70535- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
70536- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
70537+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
70538+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
70539
70540 cputime_t utime, stime, utimescaled, stimescaled;
70541 cputime_t gtime;
70542@@ -1377,11 +1407,6 @@ struct task_struct {
70543 struct task_cputime cputime_expires;
70544 struct list_head cpu_timers[3];
70545
70546-/* process credentials */
70547- const struct cred __rcu *real_cred; /* objective and real subjective task
70548- * credentials (COW) */
70549- const struct cred __rcu *cred; /* effective (overridable) subjective task
70550- * credentials (COW) */
70551 char comm[TASK_COMM_LEN]; /* executable name excluding path
70552 - access with [gs]et_task_comm (which lock
70553 it with task_lock())
70554@@ -1398,6 +1423,10 @@ struct task_struct {
70555 #endif
70556 /* CPU-specific state of this task */
70557 struct thread_struct thread;
70558+/* thread_info moved to task_struct */
70559+#ifdef CONFIG_X86
70560+ struct thread_info tinfo;
70561+#endif
70562 /* filesystem information */
70563 struct fs_struct *fs;
70564 /* open file information */
70565@@ -1471,6 +1500,10 @@ struct task_struct {
70566 gfp_t lockdep_reclaim_gfp;
70567 #endif
70568
70569+/* process credentials */
70570+ const struct cred __rcu *real_cred; /* objective and real subjective task
70571+ * credentials (COW) */
70572+
70573 /* journalling filesystem info */
70574 void *journal_info;
70575
70576@@ -1509,6 +1542,10 @@ struct task_struct {
70577 /* cg_list protected by css_set_lock and tsk->alloc_lock */
70578 struct list_head cg_list;
70579 #endif
70580+
70581+ const struct cred __rcu *cred; /* effective (overridable) subjective task
70582+ * credentials (COW) */
70583+
70584 #ifdef CONFIG_FUTEX
70585 struct robust_list_head __user *robust_list;
70586 #ifdef CONFIG_COMPAT
70587@@ -1605,8 +1642,74 @@ struct task_struct {
70588 #ifdef CONFIG_UPROBES
70589 struct uprobe_task *utask;
70590 #endif
70591+
70592+#ifdef CONFIG_GRKERNSEC
70593+ /* grsecurity */
70594+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70595+ u64 exec_id;
70596+#endif
70597+#ifdef CONFIG_GRKERNSEC_SETXID
70598+ const struct cred *delayed_cred;
70599+#endif
70600+ struct dentry *gr_chroot_dentry;
70601+ struct acl_subject_label *acl;
70602+ struct acl_role_label *role;
70603+ struct file *exec_file;
70604+ unsigned long brute_expires;
70605+ u16 acl_role_id;
70606+ /* is this the task that authenticated to the special role */
70607+ u8 acl_sp_role;
70608+ u8 is_writable;
70609+ u8 brute;
70610+ u8 gr_is_chrooted;
70611+#endif
70612+
70613 };
70614
70615+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
70616+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
70617+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
70618+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
70619+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
70620+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
70621+
70622+#ifdef CONFIG_PAX_SOFTMODE
70623+extern int pax_softmode;
70624+#endif
70625+
70626+extern int pax_check_flags(unsigned long *);
70627+
70628+/* if tsk != current then task_lock must be held on it */
70629+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
70630+static inline unsigned long pax_get_flags(struct task_struct *tsk)
70631+{
70632+ if (likely(tsk->mm))
70633+ return tsk->mm->pax_flags;
70634+ else
70635+ return 0UL;
70636+}
70637+
70638+/* if tsk != current then task_lock must be held on it */
70639+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
70640+{
70641+ if (likely(tsk->mm)) {
70642+ tsk->mm->pax_flags = flags;
70643+ return 0;
70644+ }
70645+ return -EINVAL;
70646+}
70647+#endif
70648+
70649+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
70650+extern void pax_set_initial_flags(struct linux_binprm *bprm);
70651+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
70652+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
70653+#endif
70654+
70655+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
70656+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
70657+extern void pax_report_refcount_overflow(struct pt_regs *regs);
70658+
70659 /* Future-safe accessor for struct task_struct's cpus_allowed. */
70660 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
70661
70662@@ -1696,7 +1799,7 @@ struct pid_namespace;
70663 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
70664 struct pid_namespace *ns);
70665
70666-static inline pid_t task_pid_nr(struct task_struct *tsk)
70667+static inline pid_t task_pid_nr(const struct task_struct *tsk)
70668 {
70669 return tsk->pid;
70670 }
70671@@ -2155,7 +2258,9 @@ void yield(void);
70672 extern struct exec_domain default_exec_domain;
70673
70674 union thread_union {
70675+#ifndef CONFIG_X86
70676 struct thread_info thread_info;
70677+#endif
70678 unsigned long stack[THREAD_SIZE/sizeof(long)];
70679 };
70680
70681@@ -2188,6 +2293,7 @@ extern struct pid_namespace init_pid_ns;
70682 */
70683
70684 extern struct task_struct *find_task_by_vpid(pid_t nr);
70685+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
70686 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
70687 struct pid_namespace *ns);
70688
70689@@ -2344,7 +2450,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
70690 extern void exit_itimers(struct signal_struct *);
70691 extern void flush_itimer_signals(void);
70692
70693-extern void do_group_exit(int);
70694+extern __noreturn void do_group_exit(int);
70695
70696 extern int allow_signal(int);
70697 extern int disallow_signal(int);
70698@@ -2545,9 +2651,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
70699
70700 #endif
70701
70702-static inline int object_is_on_stack(void *obj)
70703+static inline int object_starts_on_stack(void *obj)
70704 {
70705- void *stack = task_stack_page(current);
70706+ const void *stack = task_stack_page(current);
70707
70708 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
70709 }
70710diff --git a/include/linux/security.h b/include/linux/security.h
70711index eee7478..290f7ba 100644
70712--- a/include/linux/security.h
70713+++ b/include/linux/security.h
70714@@ -26,6 +26,7 @@
70715 #include <linux/capability.h>
70716 #include <linux/slab.h>
70717 #include <linux/err.h>
70718+#include <linux/grsecurity.h>
70719
70720 struct linux_binprm;
70721 struct cred;
70722diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
70723index 68a04a3..866e6a1 100644
70724--- a/include/linux/seq_file.h
70725+++ b/include/linux/seq_file.h
70726@@ -26,6 +26,9 @@ struct seq_file {
70727 struct mutex lock;
70728 const struct seq_operations *op;
70729 int poll_event;
70730+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70731+ u64 exec_id;
70732+#endif
70733 #ifdef CONFIG_USER_NS
70734 struct user_namespace *user_ns;
70735 #endif
70736@@ -38,6 +41,7 @@ struct seq_operations {
70737 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
70738 int (*show) (struct seq_file *m, void *v);
70739 };
70740+typedef struct seq_operations __no_const seq_operations_no_const;
70741
70742 #define SEQ_SKIP 1
70743
70744diff --git a/include/linux/shm.h b/include/linux/shm.h
70745index 429c199..4d42e38 100644
70746--- a/include/linux/shm.h
70747+++ b/include/linux/shm.h
70748@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
70749
70750 /* The task created the shm object. NULL if the task is dead. */
70751 struct task_struct *shm_creator;
70752+#ifdef CONFIG_GRKERNSEC
70753+ time_t shm_createtime;
70754+ pid_t shm_lapid;
70755+#endif
70756 };
70757
70758 /* shm_mode upper byte flags */
70759diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
70760index 98399e2..6e225e9 100644
70761--- a/include/linux/skbuff.h
70762+++ b/include/linux/skbuff.h
70763@@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
70764 extern struct sk_buff *__alloc_skb(unsigned int size,
70765 gfp_t priority, int flags, int node);
70766 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
70767-static inline struct sk_buff *alloc_skb(unsigned int size,
70768+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
70769 gfp_t priority)
70770 {
70771 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
70772@@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
70773 */
70774 static inline int skb_queue_empty(const struct sk_buff_head *list)
70775 {
70776- return list->next == (struct sk_buff *)list;
70777+ return list->next == (const struct sk_buff *)list;
70778 }
70779
70780 /**
70781@@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
70782 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
70783 const struct sk_buff *skb)
70784 {
70785- return skb->next == (struct sk_buff *)list;
70786+ return skb->next == (const struct sk_buff *)list;
70787 }
70788
70789 /**
70790@@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
70791 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
70792 const struct sk_buff *skb)
70793 {
70794- return skb->prev == (struct sk_buff *)list;
70795+ return skb->prev == (const struct sk_buff *)list;
70796 }
70797
70798 /**
70799@@ -1727,7 +1727,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
70800 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
70801 */
70802 #ifndef NET_SKB_PAD
70803-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
70804+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
70805 #endif
70806
70807 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
70808@@ -2305,7 +2305,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
70809 int noblock, int *err);
70810 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
70811 struct poll_table_struct *wait);
70812-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
70813+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
70814 int offset, struct iovec *to,
70815 int size);
70816 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
70817diff --git a/include/linux/slab.h b/include/linux/slab.h
70818index 5d168d7..720bff3 100644
70819--- a/include/linux/slab.h
70820+++ b/include/linux/slab.h
70821@@ -12,13 +12,20 @@
70822 #include <linux/gfp.h>
70823 #include <linux/types.h>
70824 #include <linux/workqueue.h>
70825-
70826+#include <linux/err.h>
70827
70828 /*
70829 * Flags to pass to kmem_cache_create().
70830 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
70831 */
70832 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
70833+
70834+#ifdef CONFIG_PAX_USERCOPY_SLABS
70835+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
70836+#else
70837+#define SLAB_USERCOPY 0x00000000UL
70838+#endif
70839+
70840 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
70841 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
70842 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
70843@@ -89,10 +96,13 @@
70844 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
70845 * Both make kfree a no-op.
70846 */
70847-#define ZERO_SIZE_PTR ((void *)16)
70848+#define ZERO_SIZE_PTR \
70849+({ \
70850+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
70851+ (void *)(-MAX_ERRNO-1L); \
70852+})
70853
70854-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
70855- (unsigned long)ZERO_SIZE_PTR)
70856+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
70857
70858 /*
70859 * Common fields provided in kmem_cache by all slab allocators
70860@@ -112,7 +122,7 @@ struct kmem_cache {
70861 unsigned int align; /* Alignment as calculated */
70862 unsigned long flags; /* Active flags on the slab */
70863 const char *name; /* Slab name for sysfs */
70864- int refcount; /* Use counter */
70865+ atomic_t refcount; /* Use counter */
70866 void (*ctor)(void *); /* Called on object slot creation */
70867 struct list_head list; /* List of all slab caches on the system */
70868 };
70869@@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
70870 void kfree(const void *);
70871 void kzfree(const void *);
70872 size_t ksize(const void *);
70873+const char *check_heap_object(const void *ptr, unsigned long n);
70874+bool is_usercopy_object(const void *ptr);
70875
70876 /*
70877 * Allocator specific definitions. These are mainly used to establish optimized
70878@@ -311,6 +323,7 @@ size_t ksize(const void *);
70879 * for general use, and so are not documented here. For a full list of
70880 * potential flags, always refer to linux/gfp.h.
70881 */
70882+
70883 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
70884 {
70885 if (size != 0 && n > SIZE_MAX / size)
70886@@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
70887 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
70888 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
70889 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
70890-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
70891+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
70892 #define kmalloc_track_caller(size, flags) \
70893 __kmalloc_track_caller(size, flags, _RET_IP_)
70894 #else
70895@@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
70896 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
70897 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
70898 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
70899-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
70900+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
70901 #define kmalloc_node_track_caller(size, flags, node) \
70902 __kmalloc_node_track_caller(size, flags, node, \
70903 _RET_IP_)
70904diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
70905index 8bb6e0e..8eb0dbe 100644
70906--- a/include/linux/slab_def.h
70907+++ b/include/linux/slab_def.h
70908@@ -52,7 +52,7 @@ struct kmem_cache {
70909 /* 4) cache creation/removal */
70910 const char *name;
70911 struct list_head list;
70912- int refcount;
70913+ atomic_t refcount;
70914 int object_size;
70915 int align;
70916
70917@@ -68,10 +68,10 @@ struct kmem_cache {
70918 unsigned long node_allocs;
70919 unsigned long node_frees;
70920 unsigned long node_overflow;
70921- atomic_t allochit;
70922- atomic_t allocmiss;
70923- atomic_t freehit;
70924- atomic_t freemiss;
70925+ atomic_unchecked_t allochit;
70926+ atomic_unchecked_t allocmiss;
70927+ atomic_unchecked_t freehit;
70928+ atomic_unchecked_t freemiss;
70929
70930 /*
70931 * If debugging is enabled, then the allocator can add additional
70932@@ -111,11 +111,16 @@ struct cache_sizes {
70933 #ifdef CONFIG_ZONE_DMA
70934 struct kmem_cache *cs_dmacachep;
70935 #endif
70936+
70937+#ifdef CONFIG_PAX_USERCOPY_SLABS
70938+ struct kmem_cache *cs_usercopycachep;
70939+#endif
70940+
70941 };
70942 extern struct cache_sizes malloc_sizes[];
70943
70944 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
70945-void *__kmalloc(size_t size, gfp_t flags);
70946+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
70947
70948 #ifdef CONFIG_TRACING
70949 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
70950@@ -152,6 +157,13 @@ found:
70951 cachep = malloc_sizes[i].cs_dmacachep;
70952 else
70953 #endif
70954+
70955+#ifdef CONFIG_PAX_USERCOPY_SLABS
70956+ if (flags & GFP_USERCOPY)
70957+ cachep = malloc_sizes[i].cs_usercopycachep;
70958+ else
70959+#endif
70960+
70961 cachep = malloc_sizes[i].cs_cachep;
70962
70963 ret = kmem_cache_alloc_trace(cachep, flags, size);
70964@@ -162,7 +174,7 @@ found:
70965 }
70966
70967 #ifdef CONFIG_NUMA
70968-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
70969+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70970 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
70971
70972 #ifdef CONFIG_TRACING
70973@@ -205,6 +217,13 @@ found:
70974 cachep = malloc_sizes[i].cs_dmacachep;
70975 else
70976 #endif
70977+
70978+#ifdef CONFIG_PAX_USERCOPY_SLABS
70979+ if (flags & GFP_USERCOPY)
70980+ cachep = malloc_sizes[i].cs_usercopycachep;
70981+ else
70982+#endif
70983+
70984 cachep = malloc_sizes[i].cs_cachep;
70985
70986 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
70987diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
70988index f28e14a..7831211 100644
70989--- a/include/linux/slob_def.h
70990+++ b/include/linux/slob_def.h
70991@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
70992 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
70993 }
70994
70995-void *__kmalloc_node(size_t size, gfp_t flags, int node);
70996+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70997
70998 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
70999 {
71000@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
71001 return __kmalloc_node(size, flags, NUMA_NO_NODE);
71002 }
71003
71004-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
71005+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
71006 {
71007 return kmalloc(size, flags);
71008 }
71009diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
71010index 9db4825..ed42fb5 100644
71011--- a/include/linux/slub_def.h
71012+++ b/include/linux/slub_def.h
71013@@ -91,7 +91,7 @@ struct kmem_cache {
71014 struct kmem_cache_order_objects max;
71015 struct kmem_cache_order_objects min;
71016 gfp_t allocflags; /* gfp flags to use on each alloc */
71017- int refcount; /* Refcount for slab cache destroy */
71018+ atomic_t refcount; /* Refcount for slab cache destroy */
71019 void (*ctor)(void *);
71020 int inuse; /* Offset to metadata */
71021 int align; /* Alignment */
71022@@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
71023 * Sorry that the following has to be that ugly but some versions of GCC
71024 * have trouble with constant propagation and loops.
71025 */
71026-static __always_inline int kmalloc_index(size_t size)
71027+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
71028 {
71029 if (!size)
71030 return 0;
71031@@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
71032 }
71033
71034 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
71035-void *__kmalloc(size_t size, gfp_t flags);
71036+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
71037
71038 static __always_inline void *
71039 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
71040@@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
71041 }
71042 #endif
71043
71044-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
71045+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
71046 {
71047 unsigned int order = get_order(size);
71048 return kmalloc_order_trace(size, flags, order);
71049@@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
71050 }
71051
71052 #ifdef CONFIG_NUMA
71053-void *__kmalloc_node(size_t size, gfp_t flags, int node);
71054+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71055 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
71056
71057 #ifdef CONFIG_TRACING
71058diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
71059index e8d702e..0a56eb4 100644
71060--- a/include/linux/sock_diag.h
71061+++ b/include/linux/sock_diag.h
71062@@ -10,7 +10,7 @@ struct sock;
71063 struct sock_diag_handler {
71064 __u8 family;
71065 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
71066-};
71067+} __do_const;
71068
71069 int sock_diag_register(const struct sock_diag_handler *h);
71070 void sock_diag_unregister(const struct sock_diag_handler *h);
71071diff --git a/include/linux/sonet.h b/include/linux/sonet.h
71072index 680f9a3..f13aeb0 100644
71073--- a/include/linux/sonet.h
71074+++ b/include/linux/sonet.h
71075@@ -7,7 +7,7 @@
71076 #include <uapi/linux/sonet.h>
71077
71078 struct k_sonet_stats {
71079-#define __HANDLE_ITEM(i) atomic_t i
71080+#define __HANDLE_ITEM(i) atomic_unchecked_t i
71081 __SONET_ITEMS
71082 #undef __HANDLE_ITEM
71083 };
71084diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
71085index 34206b8..3db7f1c 100644
71086--- a/include/linux/sunrpc/clnt.h
71087+++ b/include/linux/sunrpc/clnt.h
71088@@ -96,7 +96,7 @@ struct rpc_procinfo {
71089 unsigned int p_timer; /* Which RTT timer to use */
71090 u32 p_statidx; /* Which procedure to account */
71091 const char * p_name; /* name of procedure */
71092-};
71093+} __do_const;
71094
71095 #ifdef __KERNEL__
71096
71097@@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
71098 {
71099 switch (sap->sa_family) {
71100 case AF_INET:
71101- return ntohs(((struct sockaddr_in *)sap)->sin_port);
71102+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
71103 case AF_INET6:
71104- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
71105+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
71106 }
71107 return 0;
71108 }
71109@@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
71110 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
71111 const struct sockaddr *src)
71112 {
71113- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
71114+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
71115 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
71116
71117 dsin->sin_family = ssin->sin_family;
71118@@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
71119 if (sa->sa_family != AF_INET6)
71120 return 0;
71121
71122- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
71123+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
71124 }
71125
71126 #endif /* __KERNEL__ */
71127diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
71128index 676ddf5..4c519a1 100644
71129--- a/include/linux/sunrpc/svc.h
71130+++ b/include/linux/sunrpc/svc.h
71131@@ -410,7 +410,7 @@ struct svc_procedure {
71132 unsigned int pc_count; /* call count */
71133 unsigned int pc_cachetype; /* cache info (NFS) */
71134 unsigned int pc_xdrressize; /* maximum size of XDR reply */
71135-};
71136+} __do_const;
71137
71138 /*
71139 * Function prototypes.
71140diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
71141index 0b8e3e6..33e0a01 100644
71142--- a/include/linux/sunrpc/svc_rdma.h
71143+++ b/include/linux/sunrpc/svc_rdma.h
71144@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
71145 extern unsigned int svcrdma_max_requests;
71146 extern unsigned int svcrdma_max_req_size;
71147
71148-extern atomic_t rdma_stat_recv;
71149-extern atomic_t rdma_stat_read;
71150-extern atomic_t rdma_stat_write;
71151-extern atomic_t rdma_stat_sq_starve;
71152-extern atomic_t rdma_stat_rq_starve;
71153-extern atomic_t rdma_stat_rq_poll;
71154-extern atomic_t rdma_stat_rq_prod;
71155-extern atomic_t rdma_stat_sq_poll;
71156-extern atomic_t rdma_stat_sq_prod;
71157+extern atomic_unchecked_t rdma_stat_recv;
71158+extern atomic_unchecked_t rdma_stat_read;
71159+extern atomic_unchecked_t rdma_stat_write;
71160+extern atomic_unchecked_t rdma_stat_sq_starve;
71161+extern atomic_unchecked_t rdma_stat_rq_starve;
71162+extern atomic_unchecked_t rdma_stat_rq_poll;
71163+extern atomic_unchecked_t rdma_stat_rq_prod;
71164+extern atomic_unchecked_t rdma_stat_sq_poll;
71165+extern atomic_unchecked_t rdma_stat_sq_prod;
71166
71167 #define RPCRDMA_VERSION 1
71168
71169diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
71170index dd74084a..7f509d5 100644
71171--- a/include/linux/sunrpc/svcauth.h
71172+++ b/include/linux/sunrpc/svcauth.h
71173@@ -109,7 +109,7 @@ struct auth_ops {
71174 int (*release)(struct svc_rqst *rq);
71175 void (*domain_release)(struct auth_domain *);
71176 int (*set_client)(struct svc_rqst *rq);
71177-};
71178+} __do_const;
71179
71180 #define SVC_GARBAGE 1
71181 #define SVC_SYSERR 2
71182diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
71183index 071d62c..4ccc7ac 100644
71184--- a/include/linux/swiotlb.h
71185+++ b/include/linux/swiotlb.h
71186@@ -59,7 +59,8 @@ extern void
71187
71188 extern void
71189 swiotlb_free_coherent(struct device *hwdev, size_t size,
71190- void *vaddr, dma_addr_t dma_handle);
71191+ void *vaddr, dma_addr_t dma_handle,
71192+ struct dma_attrs *attrs);
71193
71194 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
71195 unsigned long offset, size_t size,
71196diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
71197index 45e2db2..1635156a 100644
71198--- a/include/linux/syscalls.h
71199+++ b/include/linux/syscalls.h
71200@@ -615,7 +615,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
71201 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
71202 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
71203 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
71204- struct sockaddr __user *, int);
71205+ struct sockaddr __user *, int) __intentional_overflow(0);
71206 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
71207 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
71208 unsigned int vlen, unsigned flags);
71209diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
71210index 27b3b0b..e093dd9 100644
71211--- a/include/linux/syscore_ops.h
71212+++ b/include/linux/syscore_ops.h
71213@@ -16,7 +16,7 @@ struct syscore_ops {
71214 int (*suspend)(void);
71215 void (*resume)(void);
71216 void (*shutdown)(void);
71217-};
71218+} __do_const;
71219
71220 extern void register_syscore_ops(struct syscore_ops *ops);
71221 extern void unregister_syscore_ops(struct syscore_ops *ops);
71222diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
71223index 14a8ff2..af52bad 100644
71224--- a/include/linux/sysctl.h
71225+++ b/include/linux/sysctl.h
71226@@ -34,13 +34,13 @@ struct ctl_table_root;
71227 struct ctl_table_header;
71228 struct ctl_dir;
71229
71230-typedef struct ctl_table ctl_table;
71231-
71232 typedef int proc_handler (struct ctl_table *ctl, int write,
71233 void __user *buffer, size_t *lenp, loff_t *ppos);
71234
71235 extern int proc_dostring(struct ctl_table *, int,
71236 void __user *, size_t *, loff_t *);
71237+extern int proc_dostring_modpriv(struct ctl_table *, int,
71238+ void __user *, size_t *, loff_t *);
71239 extern int proc_dointvec(struct ctl_table *, int,
71240 void __user *, size_t *, loff_t *);
71241 extern int proc_dointvec_minmax(struct ctl_table *, int,
71242@@ -115,7 +115,9 @@ struct ctl_table
71243 struct ctl_table_poll *poll;
71244 void *extra1;
71245 void *extra2;
71246-};
71247+} __do_const;
71248+typedef struct ctl_table __no_const ctl_table_no_const;
71249+typedef struct ctl_table ctl_table;
71250
71251 struct ctl_node {
71252 struct rb_node node;
71253diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
71254index 381f06d..dc16cc7 100644
71255--- a/include/linux/sysfs.h
71256+++ b/include/linux/sysfs.h
71257@@ -31,7 +31,8 @@ struct attribute {
71258 struct lock_class_key *key;
71259 struct lock_class_key skey;
71260 #endif
71261-};
71262+} __do_const;
71263+typedef struct attribute __no_const attribute_no_const;
71264
71265 /**
71266 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
71267@@ -59,8 +60,8 @@ struct attribute_group {
71268 umode_t (*is_visible)(struct kobject *,
71269 struct attribute *, int);
71270 struct attribute **attrs;
71271-};
71272-
71273+} __do_const;
71274+typedef struct attribute_group __no_const attribute_group_no_const;
71275
71276
71277 /**
71278@@ -107,7 +108,8 @@ struct bin_attribute {
71279 char *, loff_t, size_t);
71280 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
71281 struct vm_area_struct *vma);
71282-};
71283+} __do_const;
71284+typedef struct bin_attribute __no_const bin_attribute_no_const;
71285
71286 /**
71287 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
71288diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
71289index 7faf933..9b85a0c 100644
71290--- a/include/linux/sysrq.h
71291+++ b/include/linux/sysrq.h
71292@@ -16,6 +16,7 @@
71293
71294 #include <linux/errno.h>
71295 #include <linux/types.h>
71296+#include <linux/compiler.h>
71297
71298 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
71299 #define SYSRQ_DEFAULT_ENABLE 1
71300@@ -36,7 +37,7 @@ struct sysrq_key_op {
71301 char *help_msg;
71302 char *action_msg;
71303 int enable_mask;
71304-};
71305+} __do_const;
71306
71307 #ifdef CONFIG_MAGIC_SYSRQ
71308
71309diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
71310index e7e0473..7989295 100644
71311--- a/include/linux/thread_info.h
71312+++ b/include/linux/thread_info.h
71313@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
71314 #error "no set_restore_sigmask() provided and default one won't work"
71315 #endif
71316
71317+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
71318+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
71319+{
71320+#ifndef CONFIG_PAX_USERCOPY_DEBUG
71321+ if (!__builtin_constant_p(n))
71322+#endif
71323+ __check_object_size(ptr, n, to_user);
71324+}
71325+
71326 #endif /* __KERNEL__ */
71327
71328 #endif /* _LINUX_THREAD_INFO_H */
71329diff --git a/include/linux/tty.h b/include/linux/tty.h
71330index 8db1b56..c16a040 100644
71331--- a/include/linux/tty.h
71332+++ b/include/linux/tty.h
71333@@ -194,7 +194,7 @@ struct tty_port {
71334 const struct tty_port_operations *ops; /* Port operations */
71335 spinlock_t lock; /* Lock protecting tty field */
71336 int blocked_open; /* Waiting to open */
71337- int count; /* Usage count */
71338+ atomic_t count; /* Usage count */
71339 wait_queue_head_t open_wait; /* Open waiters */
71340 wait_queue_head_t close_wait; /* Close waiters */
71341 wait_queue_head_t delta_msr_wait; /* Modem status change */
71342@@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
71343 struct tty_struct *tty, struct file *filp);
71344 static inline int tty_port_users(struct tty_port *port)
71345 {
71346- return port->count + port->blocked_open;
71347+ return atomic_read(&port->count) + port->blocked_open;
71348 }
71349
71350 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
71351diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
71352index dd976cf..e272742 100644
71353--- a/include/linux/tty_driver.h
71354+++ b/include/linux/tty_driver.h
71355@@ -284,7 +284,7 @@ struct tty_operations {
71356 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
71357 #endif
71358 const struct file_operations *proc_fops;
71359-};
71360+} __do_const;
71361
71362 struct tty_driver {
71363 int magic; /* magic number for this structure */
71364diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
71365index fb79dd8d..07d4773 100644
71366--- a/include/linux/tty_ldisc.h
71367+++ b/include/linux/tty_ldisc.h
71368@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
71369
71370 struct module *owner;
71371
71372- int refcount;
71373+ atomic_t refcount;
71374 };
71375
71376 struct tty_ldisc {
71377diff --git a/include/linux/types.h b/include/linux/types.h
71378index 4d118ba..c3ee9bf 100644
71379--- a/include/linux/types.h
71380+++ b/include/linux/types.h
71381@@ -176,10 +176,26 @@ typedef struct {
71382 int counter;
71383 } atomic_t;
71384
71385+#ifdef CONFIG_PAX_REFCOUNT
71386+typedef struct {
71387+ int counter;
71388+} atomic_unchecked_t;
71389+#else
71390+typedef atomic_t atomic_unchecked_t;
71391+#endif
71392+
71393 #ifdef CONFIG_64BIT
71394 typedef struct {
71395 long counter;
71396 } atomic64_t;
71397+
71398+#ifdef CONFIG_PAX_REFCOUNT
71399+typedef struct {
71400+ long counter;
71401+} atomic64_unchecked_t;
71402+#else
71403+typedef atomic64_t atomic64_unchecked_t;
71404+#endif
71405 #endif
71406
71407 struct list_head {
71408diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
71409index 5ca0951..ab496a5 100644
71410--- a/include/linux/uaccess.h
71411+++ b/include/linux/uaccess.h
71412@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
71413 long ret; \
71414 mm_segment_t old_fs = get_fs(); \
71415 \
71416- set_fs(KERNEL_DS); \
71417 pagefault_disable(); \
71418- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
71419- pagefault_enable(); \
71420+ set_fs(KERNEL_DS); \
71421+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
71422 set_fs(old_fs); \
71423+ pagefault_enable(); \
71424 ret; \
71425 })
71426
71427diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
71428index 8e522cbc..aa8572d 100644
71429--- a/include/linux/uidgid.h
71430+++ b/include/linux/uidgid.h
71431@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
71432
71433 #endif /* CONFIG_USER_NS */
71434
71435+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
71436+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
71437+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
71438+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
71439+
71440 #endif /* _LINUX_UIDGID_H */
71441diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
71442index 99c1b4d..562e6f3 100644
71443--- a/include/linux/unaligned/access_ok.h
71444+++ b/include/linux/unaligned/access_ok.h
71445@@ -4,34 +4,34 @@
71446 #include <linux/kernel.h>
71447 #include <asm/byteorder.h>
71448
71449-static inline u16 get_unaligned_le16(const void *p)
71450+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
71451 {
71452- return le16_to_cpup((__le16 *)p);
71453+ return le16_to_cpup((const __le16 *)p);
71454 }
71455
71456-static inline u32 get_unaligned_le32(const void *p)
71457+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
71458 {
71459- return le32_to_cpup((__le32 *)p);
71460+ return le32_to_cpup((const __le32 *)p);
71461 }
71462
71463-static inline u64 get_unaligned_le64(const void *p)
71464+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
71465 {
71466- return le64_to_cpup((__le64 *)p);
71467+ return le64_to_cpup((const __le64 *)p);
71468 }
71469
71470-static inline u16 get_unaligned_be16(const void *p)
71471+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
71472 {
71473- return be16_to_cpup((__be16 *)p);
71474+ return be16_to_cpup((const __be16 *)p);
71475 }
71476
71477-static inline u32 get_unaligned_be32(const void *p)
71478+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
71479 {
71480- return be32_to_cpup((__be32 *)p);
71481+ return be32_to_cpup((const __be32 *)p);
71482 }
71483
71484-static inline u64 get_unaligned_be64(const void *p)
71485+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
71486 {
71487- return be64_to_cpup((__be64 *)p);
71488+ return be64_to_cpup((const __be64 *)p);
71489 }
71490
71491 static inline void put_unaligned_le16(u16 val, void *p)
71492diff --git a/include/linux/usb.h b/include/linux/usb.h
71493index 4d22d0f..8d0e8f8 100644
71494--- a/include/linux/usb.h
71495+++ b/include/linux/usb.h
71496@@ -554,7 +554,7 @@ struct usb_device {
71497 int maxchild;
71498
71499 u32 quirks;
71500- atomic_t urbnum;
71501+ atomic_unchecked_t urbnum;
71502
71503 unsigned long active_duration;
71504
71505@@ -1604,7 +1604,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
71506
71507 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
71508 __u8 request, __u8 requesttype, __u16 value, __u16 index,
71509- void *data, __u16 size, int timeout);
71510+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
71511 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
71512 void *data, int len, int *actual_length, int timeout);
71513 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
71514diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
71515index c5d36c6..108f4f9 100644
71516--- a/include/linux/usb/renesas_usbhs.h
71517+++ b/include/linux/usb/renesas_usbhs.h
71518@@ -39,7 +39,7 @@ enum {
71519 */
71520 struct renesas_usbhs_driver_callback {
71521 int (*notify_hotplug)(struct platform_device *pdev);
71522-};
71523+} __no_const;
71524
71525 /*
71526 * callback functions for platform
71527diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
71528index b9bd2e6..4ce0093 100644
71529--- a/include/linux/user_namespace.h
71530+++ b/include/linux/user_namespace.h
71531@@ -21,7 +21,7 @@ struct user_namespace {
71532 struct uid_gid_map uid_map;
71533 struct uid_gid_map gid_map;
71534 struct uid_gid_map projid_map;
71535- struct kref kref;
71536+ atomic_t count;
71537 struct user_namespace *parent;
71538 kuid_t owner;
71539 kgid_t group;
71540@@ -35,18 +35,18 @@ extern struct user_namespace init_user_ns;
71541 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
71542 {
71543 if (ns)
71544- kref_get(&ns->kref);
71545+ atomic_inc(&ns->count);
71546 return ns;
71547 }
71548
71549 extern int create_user_ns(struct cred *new);
71550 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
71551-extern void free_user_ns(struct kref *kref);
71552+extern void free_user_ns(struct user_namespace *ns);
71553
71554 static inline void put_user_ns(struct user_namespace *ns)
71555 {
71556- if (ns)
71557- kref_put(&ns->kref, free_user_ns);
71558+ if (ns && atomic_dec_and_test(&ns->count))
71559+ free_user_ns(ns);
71560 }
71561
71562 struct seq_operations;
71563diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
71564index 6f8fbcf..8259001 100644
71565--- a/include/linux/vermagic.h
71566+++ b/include/linux/vermagic.h
71567@@ -25,9 +25,35 @@
71568 #define MODULE_ARCH_VERMAGIC ""
71569 #endif
71570
71571+#ifdef CONFIG_PAX_REFCOUNT
71572+#define MODULE_PAX_REFCOUNT "REFCOUNT "
71573+#else
71574+#define MODULE_PAX_REFCOUNT ""
71575+#endif
71576+
71577+#ifdef CONSTIFY_PLUGIN
71578+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
71579+#else
71580+#define MODULE_CONSTIFY_PLUGIN ""
71581+#endif
71582+
71583+#ifdef STACKLEAK_PLUGIN
71584+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
71585+#else
71586+#define MODULE_STACKLEAK_PLUGIN ""
71587+#endif
71588+
71589+#ifdef CONFIG_GRKERNSEC
71590+#define MODULE_GRSEC "GRSEC "
71591+#else
71592+#define MODULE_GRSEC ""
71593+#endif
71594+
71595 #define VERMAGIC_STRING \
71596 UTS_RELEASE " " \
71597 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
71598 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
71599- MODULE_ARCH_VERMAGIC
71600+ MODULE_ARCH_VERMAGIC \
71601+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
71602+ MODULE_GRSEC
71603
71604diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
71605index 6071e91..ca6a489 100644
71606--- a/include/linux/vmalloc.h
71607+++ b/include/linux/vmalloc.h
71608@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
71609 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
71610 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
71611 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
71612+
71613+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
71614+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
71615+#endif
71616+
71617 /* bits [20..32] reserved for arch specific ioremap internals */
71618
71619 /*
71620@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
71621 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
71622 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
71623 unsigned long start, unsigned long end, gfp_t gfp_mask,
71624- pgprot_t prot, int node, const void *caller);
71625+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
71626 extern void vfree(const void *addr);
71627
71628 extern void *vmap(struct page **pages, unsigned int count,
71629@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
71630 extern void free_vm_area(struct vm_struct *area);
71631
71632 /* for /dev/kmem */
71633-extern long vread(char *buf, char *addr, unsigned long count);
71634-extern long vwrite(char *buf, char *addr, unsigned long count);
71635+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
71636+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
71637
71638 /*
71639 * Internals. Dont't use..
71640diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
71641index a13291f..af51fa3 100644
71642--- a/include/linux/vmstat.h
71643+++ b/include/linux/vmstat.h
71644@@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
71645 /*
71646 * Zone based page accounting with per cpu differentials.
71647 */
71648-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
71649+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
71650
71651 static inline void zone_page_state_add(long x, struct zone *zone,
71652 enum zone_stat_item item)
71653 {
71654- atomic_long_add(x, &zone->vm_stat[item]);
71655- atomic_long_add(x, &vm_stat[item]);
71656+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
71657+ atomic_long_add_unchecked(x, &vm_stat[item]);
71658 }
71659
71660 static inline unsigned long global_page_state(enum zone_stat_item item)
71661 {
71662- long x = atomic_long_read(&vm_stat[item]);
71663+ long x = atomic_long_read_unchecked(&vm_stat[item]);
71664 #ifdef CONFIG_SMP
71665 if (x < 0)
71666 x = 0;
71667@@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
71668 static inline unsigned long zone_page_state(struct zone *zone,
71669 enum zone_stat_item item)
71670 {
71671- long x = atomic_long_read(&zone->vm_stat[item]);
71672+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
71673 #ifdef CONFIG_SMP
71674 if (x < 0)
71675 x = 0;
71676@@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
71677 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
71678 enum zone_stat_item item)
71679 {
71680- long x = atomic_long_read(&zone->vm_stat[item]);
71681+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
71682
71683 #ifdef CONFIG_SMP
71684 int cpu;
71685@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
71686
71687 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
71688 {
71689- atomic_long_inc(&zone->vm_stat[item]);
71690- atomic_long_inc(&vm_stat[item]);
71691+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
71692+ atomic_long_inc_unchecked(&vm_stat[item]);
71693 }
71694
71695 static inline void __inc_zone_page_state(struct page *page,
71696@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
71697
71698 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
71699 {
71700- atomic_long_dec(&zone->vm_stat[item]);
71701- atomic_long_dec(&vm_stat[item]);
71702+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
71703+ atomic_long_dec_unchecked(&vm_stat[item]);
71704 }
71705
71706 static inline void __dec_zone_page_state(struct page *page,
71707diff --git a/include/linux/xattr.h b/include/linux/xattr.h
71708index fdbafc6..b7ffd47 100644
71709--- a/include/linux/xattr.h
71710+++ b/include/linux/xattr.h
71711@@ -28,7 +28,7 @@ struct xattr_handler {
71712 size_t size, int handler_flags);
71713 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
71714 size_t size, int flags, int handler_flags);
71715-};
71716+} __do_const;
71717
71718 struct xattr {
71719 char *name;
71720diff --git a/include/linux/zlib.h b/include/linux/zlib.h
71721index 9c5a6b4..09c9438 100644
71722--- a/include/linux/zlib.h
71723+++ b/include/linux/zlib.h
71724@@ -31,6 +31,7 @@
71725 #define _ZLIB_H
71726
71727 #include <linux/zconf.h>
71728+#include <linux/compiler.h>
71729
71730 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
71731 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
71732@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
71733
71734 /* basic functions */
71735
71736-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
71737+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
71738 /*
71739 Returns the number of bytes that needs to be allocated for a per-
71740 stream workspace with the specified parameters. A pointer to this
71741diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
71742index 95d1c91..6798cca 100644
71743--- a/include/media/v4l2-dev.h
71744+++ b/include/media/v4l2-dev.h
71745@@ -76,7 +76,7 @@ struct v4l2_file_operations {
71746 int (*mmap) (struct file *, struct vm_area_struct *);
71747 int (*open) (struct file *);
71748 int (*release) (struct file *);
71749-};
71750+} __do_const;
71751
71752 /*
71753 * Newer version of video_device, handled by videodev2.c
71754diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
71755index 4118ad1..cb7e25f 100644
71756--- a/include/media/v4l2-ioctl.h
71757+++ b/include/media/v4l2-ioctl.h
71758@@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
71759 bool valid_prio, int cmd, void *arg);
71760 };
71761
71762-
71763 /* v4l debugging and diagnostics */
71764
71765 /* Debug bitmask flags to be used on V4L2 */
71766diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
71767index adcbb20..62c2559 100644
71768--- a/include/net/9p/transport.h
71769+++ b/include/net/9p/transport.h
71770@@ -57,7 +57,7 @@ struct p9_trans_module {
71771 int (*cancel) (struct p9_client *, struct p9_req_t *req);
71772 int (*zc_request)(struct p9_client *, struct p9_req_t *,
71773 char *, char *, int , int, int, int);
71774-};
71775+} __do_const;
71776
71777 void v9fs_register_trans(struct p9_trans_module *m);
71778 void v9fs_unregister_trans(struct p9_trans_module *m);
71779diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
71780index 7588ef4..e62d35f 100644
71781--- a/include/net/bluetooth/l2cap.h
71782+++ b/include/net/bluetooth/l2cap.h
71783@@ -552,7 +552,7 @@ struct l2cap_ops {
71784 void (*defer) (struct l2cap_chan *chan);
71785 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
71786 unsigned long len, int nb);
71787-};
71788+} __do_const;
71789
71790 struct l2cap_conn {
71791 struct hci_conn *hcon;
71792diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
71793index 9e5425b..8136ffc 100644
71794--- a/include/net/caif/cfctrl.h
71795+++ b/include/net/caif/cfctrl.h
71796@@ -52,7 +52,7 @@ struct cfctrl_rsp {
71797 void (*radioset_rsp)(void);
71798 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
71799 struct cflayer *client_layer);
71800-};
71801+} __no_const;
71802
71803 /* Link Setup Parameters for CAIF-Links. */
71804 struct cfctrl_link_param {
71805@@ -101,8 +101,8 @@ struct cfctrl_request_info {
71806 struct cfctrl {
71807 struct cfsrvl serv;
71808 struct cfctrl_rsp res;
71809- atomic_t req_seq_no;
71810- atomic_t rsp_seq_no;
71811+ atomic_unchecked_t req_seq_no;
71812+ atomic_unchecked_t rsp_seq_no;
71813 struct list_head list;
71814 /* Protects from simultaneous access to first_req list */
71815 spinlock_t info_list_lock;
71816diff --git a/include/net/flow.h b/include/net/flow.h
71817index 628e11b..4c475df 100644
71818--- a/include/net/flow.h
71819+++ b/include/net/flow.h
71820@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
71821
71822 extern void flow_cache_flush(void);
71823 extern void flow_cache_flush_deferred(void);
71824-extern atomic_t flow_cache_genid;
71825+extern atomic_unchecked_t flow_cache_genid;
71826
71827 #endif
71828diff --git a/include/net/genetlink.h b/include/net/genetlink.h
71829index bdfbe68..4402ebe 100644
71830--- a/include/net/genetlink.h
71831+++ b/include/net/genetlink.h
71832@@ -118,7 +118,7 @@ struct genl_ops {
71833 struct netlink_callback *cb);
71834 int (*done)(struct netlink_callback *cb);
71835 struct list_head ops_list;
71836-};
71837+} __do_const;
71838
71839 extern int genl_register_family(struct genl_family *family);
71840 extern int genl_register_family_with_ops(struct genl_family *family,
71841diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
71842index e5062c9..48a9a4b 100644
71843--- a/include/net/gro_cells.h
71844+++ b/include/net/gro_cells.h
71845@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
71846 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
71847
71848 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
71849- atomic_long_inc(&dev->rx_dropped);
71850+ atomic_long_inc_unchecked(&dev->rx_dropped);
71851 kfree_skb(skb);
71852 return;
71853 }
71854@@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
71855 int i;
71856
71857 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
71858- gcells->cells = kcalloc(sizeof(struct gro_cell),
71859- gcells->gro_cells_mask + 1,
71860+ gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
71861+ sizeof(struct gro_cell),
71862 GFP_KERNEL);
71863 if (!gcells->cells)
71864 return -ENOMEM;
71865diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
71866index 1832927..ce39aea 100644
71867--- a/include/net/inet_connection_sock.h
71868+++ b/include/net/inet_connection_sock.h
71869@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
71870 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
71871 int (*bind_conflict)(const struct sock *sk,
71872 const struct inet_bind_bucket *tb, bool relax);
71873-};
71874+} __do_const;
71875
71876 /** inet_connection_sock - INET connection oriented sock
71877 *
71878diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
71879index 53f464d..ba76aaa 100644
71880--- a/include/net/inetpeer.h
71881+++ b/include/net/inetpeer.h
71882@@ -47,8 +47,8 @@ struct inet_peer {
71883 */
71884 union {
71885 struct {
71886- atomic_t rid; /* Frag reception counter */
71887- atomic_t ip_id_count; /* IP ID for the next packet */
71888+ atomic_unchecked_t rid; /* Frag reception counter */
71889+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
71890 };
71891 struct rcu_head rcu;
71892 struct inet_peer *gc_next;
71893@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
71894 more++;
71895 inet_peer_refcheck(p);
71896 do {
71897- old = atomic_read(&p->ip_id_count);
71898+ old = atomic_read_unchecked(&p->ip_id_count);
71899 new = old + more;
71900 if (!new)
71901 new = 1;
71902- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
71903+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
71904 return new;
71905 }
71906
71907diff --git a/include/net/ip.h b/include/net/ip.h
71908index a68f838..74518ab 100644
71909--- a/include/net/ip.h
71910+++ b/include/net/ip.h
71911@@ -202,7 +202,7 @@ extern struct local_ports {
71912 } sysctl_local_ports;
71913 extern void inet_get_local_port_range(int *low, int *high);
71914
71915-extern unsigned long *sysctl_local_reserved_ports;
71916+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
71917 static inline int inet_is_reserved_local_port(int port)
71918 {
71919 return test_bit(port, sysctl_local_reserved_ports);
71920diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
71921index e49db91..76a81de 100644
71922--- a/include/net/ip_fib.h
71923+++ b/include/net/ip_fib.h
71924@@ -167,7 +167,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
71925
71926 #define FIB_RES_SADDR(net, res) \
71927 ((FIB_RES_NH(res).nh_saddr_genid == \
71928- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
71929+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
71930 FIB_RES_NH(res).nh_saddr : \
71931 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
71932 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
71933diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
71934index 68c69d5..bdab192 100644
71935--- a/include/net/ip_vs.h
71936+++ b/include/net/ip_vs.h
71937@@ -599,7 +599,7 @@ struct ip_vs_conn {
71938 struct ip_vs_conn *control; /* Master control connection */
71939 atomic_t n_control; /* Number of controlled ones */
71940 struct ip_vs_dest *dest; /* real server */
71941- atomic_t in_pkts; /* incoming packet counter */
71942+ atomic_unchecked_t in_pkts; /* incoming packet counter */
71943
71944 /* packet transmitter for different forwarding methods. If it
71945 mangles the packet, it must return NF_DROP or better NF_STOLEN,
71946@@ -737,7 +737,7 @@ struct ip_vs_dest {
71947 __be16 port; /* port number of the server */
71948 union nf_inet_addr addr; /* IP address of the server */
71949 volatile unsigned int flags; /* dest status flags */
71950- atomic_t conn_flags; /* flags to copy to conn */
71951+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
71952 atomic_t weight; /* server weight */
71953
71954 atomic_t refcnt; /* reference counter */
71955@@ -980,11 +980,11 @@ struct netns_ipvs {
71956 /* ip_vs_lblc */
71957 int sysctl_lblc_expiration;
71958 struct ctl_table_header *lblc_ctl_header;
71959- struct ctl_table *lblc_ctl_table;
71960+ ctl_table_no_const *lblc_ctl_table;
71961 /* ip_vs_lblcr */
71962 int sysctl_lblcr_expiration;
71963 struct ctl_table_header *lblcr_ctl_header;
71964- struct ctl_table *lblcr_ctl_table;
71965+ ctl_table_no_const *lblcr_ctl_table;
71966 /* ip_vs_est */
71967 struct list_head est_list; /* estimator list */
71968 spinlock_t est_lock;
71969diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
71970index 80ffde3..968b0f4 100644
71971--- a/include/net/irda/ircomm_tty.h
71972+++ b/include/net/irda/ircomm_tty.h
71973@@ -35,6 +35,7 @@
71974 #include <linux/termios.h>
71975 #include <linux/timer.h>
71976 #include <linux/tty.h> /* struct tty_struct */
71977+#include <asm/local.h>
71978
71979 #include <net/irda/irias_object.h>
71980 #include <net/irda/ircomm_core.h>
71981diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
71982index cc7c197..9f2da2a 100644
71983--- a/include/net/iucv/af_iucv.h
71984+++ b/include/net/iucv/af_iucv.h
71985@@ -141,7 +141,7 @@ struct iucv_sock {
71986 struct iucv_sock_list {
71987 struct hlist_head head;
71988 rwlock_t lock;
71989- atomic_t autobind_name;
71990+ atomic_unchecked_t autobind_name;
71991 };
71992
71993 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
71994diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
71995index df83f69..9b640b8 100644
71996--- a/include/net/llc_c_ac.h
71997+++ b/include/net/llc_c_ac.h
71998@@ -87,7 +87,7 @@
71999 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
72000 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
72001
72002-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
72003+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
72004
72005 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
72006 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
72007diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
72008index 6ca3113..f8026dd 100644
72009--- a/include/net/llc_c_ev.h
72010+++ b/include/net/llc_c_ev.h
72011@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
72012 return (struct llc_conn_state_ev *)skb->cb;
72013 }
72014
72015-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
72016-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
72017+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
72018+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
72019
72020 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
72021 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
72022diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
72023index 0e79cfb..f46db31 100644
72024--- a/include/net/llc_c_st.h
72025+++ b/include/net/llc_c_st.h
72026@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
72027 u8 next_state;
72028 llc_conn_ev_qfyr_t *ev_qualifiers;
72029 llc_conn_action_t *ev_actions;
72030-};
72031+} __do_const;
72032
72033 struct llc_conn_state {
72034 u8 current_state;
72035diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
72036index 37a3bbd..55a4241 100644
72037--- a/include/net/llc_s_ac.h
72038+++ b/include/net/llc_s_ac.h
72039@@ -23,7 +23,7 @@
72040 #define SAP_ACT_TEST_IND 9
72041
72042 /* All action functions must look like this */
72043-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
72044+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
72045
72046 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
72047 struct sk_buff *skb);
72048diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
72049index 567c681..cd73ac0 100644
72050--- a/include/net/llc_s_st.h
72051+++ b/include/net/llc_s_st.h
72052@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
72053 llc_sap_ev_t ev;
72054 u8 next_state;
72055 llc_sap_action_t *ev_actions;
72056-};
72057+} __do_const;
72058
72059 struct llc_sap_state {
72060 u8 curr_state;
72061diff --git a/include/net/mac80211.h b/include/net/mac80211.h
72062index ee50c5e..1bc3b1a 100644
72063--- a/include/net/mac80211.h
72064+++ b/include/net/mac80211.h
72065@@ -3996,7 +3996,7 @@ struct rate_control_ops {
72066 void (*add_sta_debugfs)(void *priv, void *priv_sta,
72067 struct dentry *dir);
72068 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
72069-};
72070+} __do_const;
72071
72072 static inline int rate_supported(struct ieee80211_sta *sta,
72073 enum ieee80211_band band,
72074diff --git a/include/net/neighbour.h b/include/net/neighbour.h
72075index 0dab173..1b76af0 100644
72076--- a/include/net/neighbour.h
72077+++ b/include/net/neighbour.h
72078@@ -123,7 +123,7 @@ struct neigh_ops {
72079 void (*error_report)(struct neighbour *, struct sk_buff *);
72080 int (*output)(struct neighbour *, struct sk_buff *);
72081 int (*connected_output)(struct neighbour *, struct sk_buff *);
72082-};
72083+} __do_const;
72084
72085 struct pneigh_entry {
72086 struct pneigh_entry *next;
72087diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
72088index de644bc..dfbcc4c 100644
72089--- a/include/net/net_namespace.h
72090+++ b/include/net/net_namespace.h
72091@@ -115,7 +115,7 @@ struct net {
72092 #endif
72093 struct netns_ipvs *ipvs;
72094 struct sock *diag_nlsk;
72095- atomic_t rt_genid;
72096+ atomic_unchecked_t rt_genid;
72097 };
72098
72099 /*
72100@@ -272,7 +272,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
72101 #define __net_init __init
72102 #define __net_exit __exit_refok
72103 #define __net_initdata __initdata
72104+#ifdef CONSTIFY_PLUGIN
72105 #define __net_initconst __initconst
72106+#else
72107+#define __net_initconst __initdata
72108+#endif
72109 #endif
72110
72111 struct pernet_operations {
72112@@ -282,7 +286,7 @@ struct pernet_operations {
72113 void (*exit_batch)(struct list_head *net_exit_list);
72114 int *id;
72115 size_t size;
72116-};
72117+} __do_const;
72118
72119 /*
72120 * Use these carefully. If you implement a network device and it
72121@@ -330,12 +334,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
72122
72123 static inline int rt_genid(struct net *net)
72124 {
72125- return atomic_read(&net->rt_genid);
72126+ return atomic_read_unchecked(&net->rt_genid);
72127 }
72128
72129 static inline void rt_genid_bump(struct net *net)
72130 {
72131- atomic_inc(&net->rt_genid);
72132+ atomic_inc_unchecked(&net->rt_genid);
72133 }
72134
72135 #endif /* __NET_NET_NAMESPACE_H */
72136diff --git a/include/net/netdma.h b/include/net/netdma.h
72137index 8ba8ce2..99b7fff 100644
72138--- a/include/net/netdma.h
72139+++ b/include/net/netdma.h
72140@@ -24,7 +24,7 @@
72141 #include <linux/dmaengine.h>
72142 #include <linux/skbuff.h>
72143
72144-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
72145+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
72146 struct sk_buff *skb, int offset, struct iovec *to,
72147 size_t len, struct dma_pinned_list *pinned_list);
72148
72149diff --git a/include/net/netlink.h b/include/net/netlink.h
72150index 9690b0f..87aded7 100644
72151--- a/include/net/netlink.h
72152+++ b/include/net/netlink.h
72153@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
72154 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
72155 {
72156 if (mark)
72157- skb_trim(skb, (unsigned char *) mark - skb->data);
72158+ skb_trim(skb, (const unsigned char *) mark - skb->data);
72159 }
72160
72161 /**
72162diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
72163index 923cb20..deae816 100644
72164--- a/include/net/netns/conntrack.h
72165+++ b/include/net/netns/conntrack.h
72166@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
72167 struct nf_proto_net {
72168 #ifdef CONFIG_SYSCTL
72169 struct ctl_table_header *ctl_table_header;
72170- struct ctl_table *ctl_table;
72171+ ctl_table_no_const *ctl_table;
72172 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
72173 struct ctl_table_header *ctl_compat_header;
72174- struct ctl_table *ctl_compat_table;
72175+ ctl_table_no_const *ctl_compat_table;
72176 #endif
72177 #endif
72178 unsigned int users;
72179@@ -58,7 +58,7 @@ struct nf_ip_net {
72180 struct nf_icmp_net icmpv6;
72181 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
72182 struct ctl_table_header *ctl_table_header;
72183- struct ctl_table *ctl_table;
72184+ ctl_table_no_const *ctl_table;
72185 #endif
72186 };
72187
72188diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
72189index 2ae2b83..dbdc85e 100644
72190--- a/include/net/netns/ipv4.h
72191+++ b/include/net/netns/ipv4.h
72192@@ -64,7 +64,7 @@ struct netns_ipv4 {
72193 kgid_t sysctl_ping_group_range[2];
72194 long sysctl_tcp_mem[3];
72195
72196- atomic_t dev_addr_genid;
72197+ atomic_unchecked_t dev_addr_genid;
72198
72199 #ifdef CONFIG_IP_MROUTE
72200 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
72201diff --git a/include/net/protocol.h b/include/net/protocol.h
72202index 047c047..b9dad15 100644
72203--- a/include/net/protocol.h
72204+++ b/include/net/protocol.h
72205@@ -44,7 +44,7 @@ struct net_protocol {
72206 void (*err_handler)(struct sk_buff *skb, u32 info);
72207 unsigned int no_policy:1,
72208 netns_ok:1;
72209-};
72210+} __do_const;
72211
72212 #if IS_ENABLED(CONFIG_IPV6)
72213 struct inet6_protocol {
72214@@ -57,7 +57,7 @@ struct inet6_protocol {
72215 u8 type, u8 code, int offset,
72216 __be32 info);
72217 unsigned int flags; /* INET6_PROTO_xxx */
72218-};
72219+} __do_const;
72220
72221 #define INET6_PROTO_NOPOLICY 0x1
72222 #define INET6_PROTO_FINAL 0x2
72223diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
72224index 5a15fab..d799ea7 100644
72225--- a/include/net/rtnetlink.h
72226+++ b/include/net/rtnetlink.h
72227@@ -81,7 +81,7 @@ struct rtnl_link_ops {
72228 const struct net_device *dev);
72229 unsigned int (*get_num_tx_queues)(void);
72230 unsigned int (*get_num_rx_queues)(void);
72231-};
72232+} __do_const;
72233
72234 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
72235 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
72236diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
72237index 7fdf298..197e9f7 100644
72238--- a/include/net/sctp/sctp.h
72239+++ b/include/net/sctp/sctp.h
72240@@ -330,9 +330,9 @@ do { \
72241
72242 #else /* SCTP_DEBUG */
72243
72244-#define SCTP_DEBUG_PRINTK(whatever...)
72245-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
72246-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
72247+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
72248+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
72249+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
72250 #define SCTP_ENABLE_DEBUG
72251 #define SCTP_DISABLE_DEBUG
72252 #define SCTP_ASSERT(expr, str, func)
72253diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
72254index 2a82d13..62a31c2 100644
72255--- a/include/net/sctp/sm.h
72256+++ b/include/net/sctp/sm.h
72257@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
72258 typedef struct {
72259 sctp_state_fn_t *fn;
72260 const char *name;
72261-} sctp_sm_table_entry_t;
72262+} __do_const sctp_sm_table_entry_t;
72263
72264 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
72265 * currently in use.
72266@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
72267 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
72268
72269 /* Extern declarations for major data structures. */
72270-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
72271+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
72272
72273
72274 /* Get the size of a DATA chunk payload. */
72275diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
72276index fdeb85a..1329d95 100644
72277--- a/include/net/sctp/structs.h
72278+++ b/include/net/sctp/structs.h
72279@@ -517,7 +517,7 @@ struct sctp_pf {
72280 struct sctp_association *asoc);
72281 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
72282 struct sctp_af *af;
72283-};
72284+} __do_const;
72285
72286
72287 /* Structure to track chunk fragments that have been acked, but peer
72288diff --git a/include/net/sock.h b/include/net/sock.h
72289index 25afaa0..8bb0070 100644
72290--- a/include/net/sock.h
72291+++ b/include/net/sock.h
72292@@ -322,7 +322,7 @@ struct sock {
72293 #ifdef CONFIG_RPS
72294 __u32 sk_rxhash;
72295 #endif
72296- atomic_t sk_drops;
72297+ atomic_unchecked_t sk_drops;
72298 int sk_rcvbuf;
72299
72300 struct sk_filter __rcu *sk_filter;
72301@@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
72302 }
72303
72304 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
72305- char __user *from, char *to,
72306+ char __user *from, unsigned char *to,
72307 int copy, int offset)
72308 {
72309 if (skb->ip_summed == CHECKSUM_NONE) {
72310@@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
72311 }
72312 }
72313
72314-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
72315+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
72316
72317 /**
72318 * sk_page_frag - return an appropriate page_frag
72319diff --git a/include/net/tcp.h b/include/net/tcp.h
72320index aed42c7..43890c6 100644
72321--- a/include/net/tcp.h
72322+++ b/include/net/tcp.h
72323@@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
72324 extern void tcp_xmit_retransmit_queue(struct sock *);
72325 extern void tcp_simple_retransmit(struct sock *);
72326 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
72327-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
72328+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
72329
72330 extern void tcp_send_probe0(struct sock *);
72331 extern void tcp_send_partial(struct sock *);
72332@@ -701,8 +701,8 @@ struct tcp_skb_cb {
72333 struct inet6_skb_parm h6;
72334 #endif
72335 } header; /* For incoming frames */
72336- __u32 seq; /* Starting sequence number */
72337- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
72338+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
72339+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
72340 __u32 when; /* used to compute rtt's */
72341 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
72342
72343@@ -716,7 +716,7 @@ struct tcp_skb_cb {
72344
72345 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
72346 /* 1 byte hole */
72347- __u32 ack_seq; /* Sequence number ACK'd */
72348+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
72349 };
72350
72351 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
72352diff --git a/include/net/xfrm.h b/include/net/xfrm.h
72353index 63445ed..d6fc34f 100644
72354--- a/include/net/xfrm.h
72355+++ b/include/net/xfrm.h
72356@@ -304,7 +304,7 @@ struct xfrm_policy_afinfo {
72357 struct net_device *dev,
72358 const struct flowi *fl);
72359 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
72360-};
72361+} __do_const;
72362
72363 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
72364 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
72365@@ -340,7 +340,7 @@ struct xfrm_state_afinfo {
72366 struct sk_buff *skb);
72367 int (*transport_finish)(struct sk_buff *skb,
72368 int async);
72369-};
72370+} __do_const;
72371
72372 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
72373 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
72374@@ -423,7 +423,7 @@ struct xfrm_mode {
72375 struct module *owner;
72376 unsigned int encap;
72377 int flags;
72378-};
72379+} __do_const;
72380
72381 /* Flags for xfrm_mode. */
72382 enum {
72383@@ -514,7 +514,7 @@ struct xfrm_policy {
72384 struct timer_list timer;
72385
72386 struct flow_cache_object flo;
72387- atomic_t genid;
72388+ atomic_unchecked_t genid;
72389 u32 priority;
72390 u32 index;
72391 struct xfrm_mark mark;
72392diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
72393index 1a046b1..ee0bef0 100644
72394--- a/include/rdma/iw_cm.h
72395+++ b/include/rdma/iw_cm.h
72396@@ -122,7 +122,7 @@ struct iw_cm_verbs {
72397 int backlog);
72398
72399 int (*destroy_listen)(struct iw_cm_id *cm_id);
72400-};
72401+} __no_const;
72402
72403 /**
72404 * iw_create_cm_id - Create an IW CM identifier.
72405diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
72406index 399162b..b337f1a 100644
72407--- a/include/scsi/libfc.h
72408+++ b/include/scsi/libfc.h
72409@@ -762,6 +762,7 @@ struct libfc_function_template {
72410 */
72411 void (*disc_stop_final) (struct fc_lport *);
72412 };
72413+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
72414
72415 /**
72416 * struct fc_disc - Discovery context
72417@@ -866,7 +867,7 @@ struct fc_lport {
72418 struct fc_vport *vport;
72419
72420 /* Operational Information */
72421- struct libfc_function_template tt;
72422+ libfc_function_template_no_const tt;
72423 u8 link_up;
72424 u8 qfull;
72425 enum fc_lport_state state;
72426diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
72427index e65c62e..aa2e5a2 100644
72428--- a/include/scsi/scsi_device.h
72429+++ b/include/scsi/scsi_device.h
72430@@ -170,9 +170,9 @@ struct scsi_device {
72431 unsigned int max_device_blocked; /* what device_blocked counts down from */
72432 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
72433
72434- atomic_t iorequest_cnt;
72435- atomic_t iodone_cnt;
72436- atomic_t ioerr_cnt;
72437+ atomic_unchecked_t iorequest_cnt;
72438+ atomic_unchecked_t iodone_cnt;
72439+ atomic_unchecked_t ioerr_cnt;
72440
72441 struct device sdev_gendev,
72442 sdev_dev;
72443diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
72444index b797e8f..8e2c3aa 100644
72445--- a/include/scsi/scsi_transport_fc.h
72446+++ b/include/scsi/scsi_transport_fc.h
72447@@ -751,7 +751,8 @@ struct fc_function_template {
72448 unsigned long show_host_system_hostname:1;
72449
72450 unsigned long disable_target_scan:1;
72451-};
72452+} __do_const;
72453+typedef struct fc_function_template __no_const fc_function_template_no_const;
72454
72455
72456 /**
72457diff --git a/include/sound/soc.h b/include/sound/soc.h
72458index bc56738..a4be132 100644
72459--- a/include/sound/soc.h
72460+++ b/include/sound/soc.h
72461@@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
72462 /* probe ordering - for components with runtime dependencies */
72463 int probe_order;
72464 int remove_order;
72465-};
72466+} __do_const;
72467
72468 /* SoC platform interface */
72469 struct snd_soc_platform_driver {
72470@@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
72471 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
72472 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
72473 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
72474-};
72475+} __do_const;
72476
72477 struct snd_soc_platform {
72478 const char *name;
72479diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
72480index 663e34a..91b306a 100644
72481--- a/include/target/target_core_base.h
72482+++ b/include/target/target_core_base.h
72483@@ -654,7 +654,7 @@ struct se_device {
72484 spinlock_t stats_lock;
72485 /* Active commands on this virtual SE device */
72486 atomic_t simple_cmds;
72487- atomic_t dev_ordered_id;
72488+ atomic_unchecked_t dev_ordered_id;
72489 atomic_t dev_ordered_sync;
72490 atomic_t dev_qf_count;
72491 int export_count;
72492diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
72493new file mode 100644
72494index 0000000..fb634b7
72495--- /dev/null
72496+++ b/include/trace/events/fs.h
72497@@ -0,0 +1,53 @@
72498+#undef TRACE_SYSTEM
72499+#define TRACE_SYSTEM fs
72500+
72501+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
72502+#define _TRACE_FS_H
72503+
72504+#include <linux/fs.h>
72505+#include <linux/tracepoint.h>
72506+
72507+TRACE_EVENT(do_sys_open,
72508+
72509+ TP_PROTO(const char *filename, int flags, int mode),
72510+
72511+ TP_ARGS(filename, flags, mode),
72512+
72513+ TP_STRUCT__entry(
72514+ __string( filename, filename )
72515+ __field( int, flags )
72516+ __field( int, mode )
72517+ ),
72518+
72519+ TP_fast_assign(
72520+ __assign_str(filename, filename);
72521+ __entry->flags = flags;
72522+ __entry->mode = mode;
72523+ ),
72524+
72525+ TP_printk("\"%s\" %x %o",
72526+ __get_str(filename), __entry->flags, __entry->mode)
72527+);
72528+
72529+TRACE_EVENT(open_exec,
72530+
72531+ TP_PROTO(const char *filename),
72532+
72533+ TP_ARGS(filename),
72534+
72535+ TP_STRUCT__entry(
72536+ __string( filename, filename )
72537+ ),
72538+
72539+ TP_fast_assign(
72540+ __assign_str(filename, filename);
72541+ ),
72542+
72543+ TP_printk("\"%s\"",
72544+ __get_str(filename))
72545+);
72546+
72547+#endif /* _TRACE_FS_H */
72548+
72549+/* This part must be outside protection */
72550+#include <trace/define_trace.h>
72551diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
72552index 1c09820..7f5ec79 100644
72553--- a/include/trace/events/irq.h
72554+++ b/include/trace/events/irq.h
72555@@ -36,7 +36,7 @@ struct softirq_action;
72556 */
72557 TRACE_EVENT(irq_handler_entry,
72558
72559- TP_PROTO(int irq, struct irqaction *action),
72560+ TP_PROTO(int irq, const struct irqaction *action),
72561
72562 TP_ARGS(irq, action),
72563
72564@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
72565 */
72566 TRACE_EVENT(irq_handler_exit,
72567
72568- TP_PROTO(int irq, struct irqaction *action, int ret),
72569+ TP_PROTO(int irq, const struct irqaction *action, int ret),
72570
72571 TP_ARGS(irq, action, ret),
72572
72573diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
72574index 7caf44c..23c6f27 100644
72575--- a/include/uapi/linux/a.out.h
72576+++ b/include/uapi/linux/a.out.h
72577@@ -39,6 +39,14 @@ enum machine_type {
72578 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
72579 };
72580
72581+/* Constants for the N_FLAGS field */
72582+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
72583+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
72584+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
72585+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
72586+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
72587+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
72588+
72589 #if !defined (N_MAGIC)
72590 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
72591 #endif
72592diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
72593index d876736..ccce5c0 100644
72594--- a/include/uapi/linux/byteorder/little_endian.h
72595+++ b/include/uapi/linux/byteorder/little_endian.h
72596@@ -42,51 +42,51 @@
72597
72598 static inline __le64 __cpu_to_le64p(const __u64 *p)
72599 {
72600- return (__force __le64)*p;
72601+ return (__force const __le64)*p;
72602 }
72603-static inline __u64 __le64_to_cpup(const __le64 *p)
72604+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
72605 {
72606- return (__force __u64)*p;
72607+ return (__force const __u64)*p;
72608 }
72609 static inline __le32 __cpu_to_le32p(const __u32 *p)
72610 {
72611- return (__force __le32)*p;
72612+ return (__force const __le32)*p;
72613 }
72614 static inline __u32 __le32_to_cpup(const __le32 *p)
72615 {
72616- return (__force __u32)*p;
72617+ return (__force const __u32)*p;
72618 }
72619 static inline __le16 __cpu_to_le16p(const __u16 *p)
72620 {
72621- return (__force __le16)*p;
72622+ return (__force const __le16)*p;
72623 }
72624 static inline __u16 __le16_to_cpup(const __le16 *p)
72625 {
72626- return (__force __u16)*p;
72627+ return (__force const __u16)*p;
72628 }
72629 static inline __be64 __cpu_to_be64p(const __u64 *p)
72630 {
72631- return (__force __be64)__swab64p(p);
72632+ return (__force const __be64)__swab64p(p);
72633 }
72634 static inline __u64 __be64_to_cpup(const __be64 *p)
72635 {
72636- return __swab64p((__u64 *)p);
72637+ return __swab64p((const __u64 *)p);
72638 }
72639 static inline __be32 __cpu_to_be32p(const __u32 *p)
72640 {
72641- return (__force __be32)__swab32p(p);
72642+ return (__force const __be32)__swab32p(p);
72643 }
72644-static inline __u32 __be32_to_cpup(const __be32 *p)
72645+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
72646 {
72647- return __swab32p((__u32 *)p);
72648+ return __swab32p((const __u32 *)p);
72649 }
72650 static inline __be16 __cpu_to_be16p(const __u16 *p)
72651 {
72652- return (__force __be16)__swab16p(p);
72653+ return (__force const __be16)__swab16p(p);
72654 }
72655 static inline __u16 __be16_to_cpup(const __be16 *p)
72656 {
72657- return __swab16p((__u16 *)p);
72658+ return __swab16p((const __u16 *)p);
72659 }
72660 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
72661 #define __le64_to_cpus(x) do { (void)(x); } while (0)
72662diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
72663index 126a817..d522bd1 100644
72664--- a/include/uapi/linux/elf.h
72665+++ b/include/uapi/linux/elf.h
72666@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
72667 #define PT_GNU_EH_FRAME 0x6474e550
72668
72669 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
72670+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
72671+
72672+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
72673+
72674+/* Constants for the e_flags field */
72675+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
72676+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
72677+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
72678+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
72679+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
72680+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
72681
72682 /*
72683 * Extended Numbering
72684@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
72685 #define DT_DEBUG 21
72686 #define DT_TEXTREL 22
72687 #define DT_JMPREL 23
72688+#define DT_FLAGS 30
72689+ #define DF_TEXTREL 0x00000004
72690 #define DT_ENCODING 32
72691 #define OLD_DT_LOOS 0x60000000
72692 #define DT_LOOS 0x6000000d
72693@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
72694 #define PF_W 0x2
72695 #define PF_X 0x1
72696
72697+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
72698+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
72699+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
72700+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
72701+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
72702+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
72703+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
72704+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
72705+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
72706+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
72707+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
72708+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
72709+
72710 typedef struct elf32_phdr{
72711 Elf32_Word p_type;
72712 Elf32_Off p_offset;
72713@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
72714 #define EI_OSABI 7
72715 #define EI_PAD 8
72716
72717+#define EI_PAX 14
72718+
72719 #define ELFMAG0 0x7f /* EI_MAG */
72720 #define ELFMAG1 'E'
72721 #define ELFMAG2 'L'
72722diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
72723index aa169c4..6a2771d 100644
72724--- a/include/uapi/linux/personality.h
72725+++ b/include/uapi/linux/personality.h
72726@@ -30,6 +30,7 @@ enum {
72727 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
72728 ADDR_NO_RANDOMIZE | \
72729 ADDR_COMPAT_LAYOUT | \
72730+ ADDR_LIMIT_3GB | \
72731 MMAP_PAGE_ZERO)
72732
72733 /*
72734diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
72735index 7530e74..e714828 100644
72736--- a/include/uapi/linux/screen_info.h
72737+++ b/include/uapi/linux/screen_info.h
72738@@ -43,7 +43,8 @@ struct screen_info {
72739 __u16 pages; /* 0x32 */
72740 __u16 vesa_attributes; /* 0x34 */
72741 __u32 capabilities; /* 0x36 */
72742- __u8 _reserved[6]; /* 0x3a */
72743+ __u16 vesapm_size; /* 0x3a */
72744+ __u8 _reserved[4]; /* 0x3c */
72745 } __attribute__((packed));
72746
72747 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
72748diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
72749index 0e011eb..82681b1 100644
72750--- a/include/uapi/linux/swab.h
72751+++ b/include/uapi/linux/swab.h
72752@@ -43,7 +43,7 @@
72753 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
72754 */
72755
72756-static inline __attribute_const__ __u16 __fswab16(__u16 val)
72757+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
72758 {
72759 #ifdef __HAVE_BUILTIN_BSWAP16__
72760 return __builtin_bswap16(val);
72761@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
72762 #endif
72763 }
72764
72765-static inline __attribute_const__ __u32 __fswab32(__u32 val)
72766+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
72767 {
72768 #ifdef __HAVE_BUILTIN_BSWAP32__
72769 return __builtin_bswap32(val);
72770@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
72771 #endif
72772 }
72773
72774-static inline __attribute_const__ __u64 __fswab64(__u64 val)
72775+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
72776 {
72777 #ifdef __HAVE_BUILTIN_BSWAP64__
72778 return __builtin_bswap64(val);
72779diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
72780index 6d67213..8dab561 100644
72781--- a/include/uapi/linux/sysctl.h
72782+++ b/include/uapi/linux/sysctl.h
72783@@ -155,7 +155,11 @@ enum
72784 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
72785 };
72786
72787-
72788+#ifdef CONFIG_PAX_SOFTMODE
72789+enum {
72790+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
72791+};
72792+#endif
72793
72794 /* CTL_VM names: */
72795 enum
72796diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
72797index 26607bd..588b65f 100644
72798--- a/include/uapi/linux/xattr.h
72799+++ b/include/uapi/linux/xattr.h
72800@@ -60,5 +60,9 @@
72801 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
72802 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
72803
72804+/* User namespace */
72805+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
72806+#define XATTR_PAX_FLAGS_SUFFIX "flags"
72807+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
72808
72809 #endif /* _UAPI_LINUX_XATTR_H */
72810diff --git a/include/video/udlfb.h b/include/video/udlfb.h
72811index f9466fa..f4e2b81 100644
72812--- a/include/video/udlfb.h
72813+++ b/include/video/udlfb.h
72814@@ -53,10 +53,10 @@ struct dlfb_data {
72815 u32 pseudo_palette[256];
72816 int blank_mode; /*one of FB_BLANK_ */
72817 /* blit-only rendering path metrics, exposed through sysfs */
72818- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
72819- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
72820- atomic_t bytes_sent; /* to usb, after compression including overhead */
72821- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
72822+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
72823+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
72824+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
72825+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
72826 };
72827
72828 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
72829diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
72830index 0993a22..32ba2fe 100644
72831--- a/include/video/uvesafb.h
72832+++ b/include/video/uvesafb.h
72833@@ -177,6 +177,7 @@ struct uvesafb_par {
72834 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
72835 u8 pmi_setpal; /* PMI for palette changes */
72836 u16 *pmi_base; /* protected mode interface location */
72837+ u8 *pmi_code; /* protected mode code location */
72838 void *pmi_start;
72839 void *pmi_pal;
72840 u8 *vbe_state_orig; /*
72841diff --git a/init/Kconfig b/init/Kconfig
72842index be8b7f5..1eeca9b 100644
72843--- a/init/Kconfig
72844+++ b/init/Kconfig
72845@@ -990,6 +990,7 @@ endif # CGROUPS
72846
72847 config CHECKPOINT_RESTORE
72848 bool "Checkpoint/restore support" if EXPERT
72849+ depends on !GRKERNSEC
72850 default n
72851 help
72852 Enables additional kernel features in a sake of checkpoint/restore.
72853@@ -1468,7 +1469,7 @@ config SLUB_DEBUG
72854
72855 config COMPAT_BRK
72856 bool "Disable heap randomization"
72857- default y
72858+ default n
72859 help
72860 Randomizing heap placement makes heap exploits harder, but it
72861 also breaks ancient binaries (including anything libc5 based).
72862@@ -1711,7 +1712,7 @@ config INIT_ALL_POSSIBLE
72863 config STOP_MACHINE
72864 bool
72865 default y
72866- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
72867+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
72868 help
72869 Need stop_machine() primitive.
72870
72871diff --git a/init/Makefile b/init/Makefile
72872index 7bc47ee..6da2dc7 100644
72873--- a/init/Makefile
72874+++ b/init/Makefile
72875@@ -2,6 +2,9 @@
72876 # Makefile for the linux kernel.
72877 #
72878
72879+ccflags-y := $(GCC_PLUGINS_CFLAGS)
72880+asflags-y := $(GCC_PLUGINS_AFLAGS)
72881+
72882 obj-y := main.o version.o mounts.o
72883 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
72884 obj-y += noinitramfs.o
72885diff --git a/init/do_mounts.c b/init/do_mounts.c
72886index 1d1b634..a1c810f 100644
72887--- a/init/do_mounts.c
72888+++ b/init/do_mounts.c
72889@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
72890 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
72891 {
72892 struct super_block *s;
72893- int err = sys_mount(name, "/root", fs, flags, data);
72894+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
72895 if (err)
72896 return err;
72897
72898- sys_chdir("/root");
72899+ sys_chdir((const char __force_user *)"/root");
72900 s = current->fs->pwd.dentry->d_sb;
72901 ROOT_DEV = s->s_dev;
72902 printk(KERN_INFO
72903@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
72904 va_start(args, fmt);
72905 vsprintf(buf, fmt, args);
72906 va_end(args);
72907- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
72908+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
72909 if (fd >= 0) {
72910 sys_ioctl(fd, FDEJECT, 0);
72911 sys_close(fd);
72912 }
72913 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
72914- fd = sys_open("/dev/console", O_RDWR, 0);
72915+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
72916 if (fd >= 0) {
72917 sys_ioctl(fd, TCGETS, (long)&termios);
72918 termios.c_lflag &= ~ICANON;
72919 sys_ioctl(fd, TCSETSF, (long)&termios);
72920- sys_read(fd, &c, 1);
72921+ sys_read(fd, (char __user *)&c, 1);
72922 termios.c_lflag |= ICANON;
72923 sys_ioctl(fd, TCSETSF, (long)&termios);
72924 sys_close(fd);
72925@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
72926 mount_root();
72927 out:
72928 devtmpfs_mount("dev");
72929- sys_mount(".", "/", NULL, MS_MOVE, NULL);
72930- sys_chroot(".");
72931+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
72932+ sys_chroot((const char __force_user *)".");
72933 }
72934diff --git a/init/do_mounts.h b/init/do_mounts.h
72935index f5b978a..69dbfe8 100644
72936--- a/init/do_mounts.h
72937+++ b/init/do_mounts.h
72938@@ -15,15 +15,15 @@ extern int root_mountflags;
72939
72940 static inline int create_dev(char *name, dev_t dev)
72941 {
72942- sys_unlink(name);
72943- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
72944+ sys_unlink((char __force_user *)name);
72945+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
72946 }
72947
72948 #if BITS_PER_LONG == 32
72949 static inline u32 bstat(char *name)
72950 {
72951 struct stat64 stat;
72952- if (sys_stat64(name, &stat) != 0)
72953+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
72954 return 0;
72955 if (!S_ISBLK(stat.st_mode))
72956 return 0;
72957@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
72958 static inline u32 bstat(char *name)
72959 {
72960 struct stat stat;
72961- if (sys_newstat(name, &stat) != 0)
72962+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
72963 return 0;
72964 if (!S_ISBLK(stat.st_mode))
72965 return 0;
72966diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
72967index f9acf71..1e19144 100644
72968--- a/init/do_mounts_initrd.c
72969+++ b/init/do_mounts_initrd.c
72970@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
72971 create_dev("/dev/root.old", Root_RAM0);
72972 /* mount initrd on rootfs' /root */
72973 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
72974- sys_mkdir("/old", 0700);
72975- sys_chdir("/old");
72976+ sys_mkdir((const char __force_user *)"/old", 0700);
72977+ sys_chdir((const char __force_user *)"/old");
72978
72979 /*
72980 * In case that a resume from disk is carried out by linuxrc or one of
72981@@ -73,31 +73,31 @@ static void __init handle_initrd(void)
72982 current->flags &= ~PF_FREEZER_SKIP;
72983
72984 /* move initrd to rootfs' /old */
72985- sys_mount("..", ".", NULL, MS_MOVE, NULL);
72986+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
72987 /* switch root and cwd back to / of rootfs */
72988- sys_chroot("..");
72989+ sys_chroot((const char __force_user *)"..");
72990
72991 if (new_decode_dev(real_root_dev) == Root_RAM0) {
72992- sys_chdir("/old");
72993+ sys_chdir((const char __force_user *)"/old");
72994 return;
72995 }
72996
72997- sys_chdir("/");
72998+ sys_chdir((const char __force_user *)"/");
72999 ROOT_DEV = new_decode_dev(real_root_dev);
73000 mount_root();
73001
73002 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
73003- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
73004+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
73005 if (!error)
73006 printk("okay\n");
73007 else {
73008- int fd = sys_open("/dev/root.old", O_RDWR, 0);
73009+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
73010 if (error == -ENOENT)
73011 printk("/initrd does not exist. Ignored.\n");
73012 else
73013 printk("failed\n");
73014 printk(KERN_NOTICE "Unmounting old root\n");
73015- sys_umount("/old", MNT_DETACH);
73016+ sys_umount((char __force_user *)"/old", MNT_DETACH);
73017 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
73018 if (fd < 0) {
73019 error = fd;
73020@@ -120,11 +120,11 @@ int __init initrd_load(void)
73021 * mounted in the normal path.
73022 */
73023 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
73024- sys_unlink("/initrd.image");
73025+ sys_unlink((const char __force_user *)"/initrd.image");
73026 handle_initrd();
73027 return 1;
73028 }
73029 }
73030- sys_unlink("/initrd.image");
73031+ sys_unlink((const char __force_user *)"/initrd.image");
73032 return 0;
73033 }
73034diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
73035index 8cb6db5..d729f50 100644
73036--- a/init/do_mounts_md.c
73037+++ b/init/do_mounts_md.c
73038@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
73039 partitioned ? "_d" : "", minor,
73040 md_setup_args[ent].device_names);
73041
73042- fd = sys_open(name, 0, 0);
73043+ fd = sys_open((char __force_user *)name, 0, 0);
73044 if (fd < 0) {
73045 printk(KERN_ERR "md: open failed - cannot start "
73046 "array %s\n", name);
73047@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
73048 * array without it
73049 */
73050 sys_close(fd);
73051- fd = sys_open(name, 0, 0);
73052+ fd = sys_open((char __force_user *)name, 0, 0);
73053 sys_ioctl(fd, BLKRRPART, 0);
73054 }
73055 sys_close(fd);
73056@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
73057
73058 wait_for_device_probe();
73059
73060- fd = sys_open("/dev/md0", 0, 0);
73061+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
73062 if (fd >= 0) {
73063 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
73064 sys_close(fd);
73065diff --git a/init/init_task.c b/init/init_task.c
73066index 8b2f399..f0797c9 100644
73067--- a/init/init_task.c
73068+++ b/init/init_task.c
73069@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
73070 * Initial thread structure. Alignment of this is handled by a special
73071 * linker map entry.
73072 */
73073+#ifdef CONFIG_X86
73074+union thread_union init_thread_union __init_task_data;
73075+#else
73076 union thread_union init_thread_union __init_task_data =
73077 { INIT_THREAD_INFO(init_task) };
73078+#endif
73079diff --git a/init/initramfs.c b/init/initramfs.c
73080index 84c6bf1..8899338 100644
73081--- a/init/initramfs.c
73082+++ b/init/initramfs.c
73083@@ -84,7 +84,7 @@ static void __init free_hash(void)
73084 }
73085 }
73086
73087-static long __init do_utime(char *filename, time_t mtime)
73088+static long __init do_utime(char __force_user *filename, time_t mtime)
73089 {
73090 struct timespec t[2];
73091
73092@@ -119,7 +119,7 @@ static void __init dir_utime(void)
73093 struct dir_entry *de, *tmp;
73094 list_for_each_entry_safe(de, tmp, &dir_list, list) {
73095 list_del(&de->list);
73096- do_utime(de->name, de->mtime);
73097+ do_utime((char __force_user *)de->name, de->mtime);
73098 kfree(de->name);
73099 kfree(de);
73100 }
73101@@ -281,7 +281,7 @@ static int __init maybe_link(void)
73102 if (nlink >= 2) {
73103 char *old = find_link(major, minor, ino, mode, collected);
73104 if (old)
73105- return (sys_link(old, collected) < 0) ? -1 : 1;
73106+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
73107 }
73108 return 0;
73109 }
73110@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
73111 {
73112 struct stat st;
73113
73114- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
73115+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
73116 if (S_ISDIR(st.st_mode))
73117- sys_rmdir(path);
73118+ sys_rmdir((char __force_user *)path);
73119 else
73120- sys_unlink(path);
73121+ sys_unlink((char __force_user *)path);
73122 }
73123 }
73124
73125@@ -315,7 +315,7 @@ static int __init do_name(void)
73126 int openflags = O_WRONLY|O_CREAT;
73127 if (ml != 1)
73128 openflags |= O_TRUNC;
73129- wfd = sys_open(collected, openflags, mode);
73130+ wfd = sys_open((char __force_user *)collected, openflags, mode);
73131
73132 if (wfd >= 0) {
73133 sys_fchown(wfd, uid, gid);
73134@@ -327,17 +327,17 @@ static int __init do_name(void)
73135 }
73136 }
73137 } else if (S_ISDIR(mode)) {
73138- sys_mkdir(collected, mode);
73139- sys_chown(collected, uid, gid);
73140- sys_chmod(collected, mode);
73141+ sys_mkdir((char __force_user *)collected, mode);
73142+ sys_chown((char __force_user *)collected, uid, gid);
73143+ sys_chmod((char __force_user *)collected, mode);
73144 dir_add(collected, mtime);
73145 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
73146 S_ISFIFO(mode) || S_ISSOCK(mode)) {
73147 if (maybe_link() == 0) {
73148- sys_mknod(collected, mode, rdev);
73149- sys_chown(collected, uid, gid);
73150- sys_chmod(collected, mode);
73151- do_utime(collected, mtime);
73152+ sys_mknod((char __force_user *)collected, mode, rdev);
73153+ sys_chown((char __force_user *)collected, uid, gid);
73154+ sys_chmod((char __force_user *)collected, mode);
73155+ do_utime((char __force_user *)collected, mtime);
73156 }
73157 }
73158 return 0;
73159@@ -346,15 +346,15 @@ static int __init do_name(void)
73160 static int __init do_copy(void)
73161 {
73162 if (count >= body_len) {
73163- sys_write(wfd, victim, body_len);
73164+ sys_write(wfd, (char __force_user *)victim, body_len);
73165 sys_close(wfd);
73166- do_utime(vcollected, mtime);
73167+ do_utime((char __force_user *)vcollected, mtime);
73168 kfree(vcollected);
73169 eat(body_len);
73170 state = SkipIt;
73171 return 0;
73172 } else {
73173- sys_write(wfd, victim, count);
73174+ sys_write(wfd, (char __force_user *)victim, count);
73175 body_len -= count;
73176 eat(count);
73177 return 1;
73178@@ -365,9 +365,9 @@ static int __init do_symlink(void)
73179 {
73180 collected[N_ALIGN(name_len) + body_len] = '\0';
73181 clean_path(collected, 0);
73182- sys_symlink(collected + N_ALIGN(name_len), collected);
73183- sys_lchown(collected, uid, gid);
73184- do_utime(collected, mtime);
73185+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
73186+ sys_lchown((char __force_user *)collected, uid, gid);
73187+ do_utime((char __force_user *)collected, mtime);
73188 state = SkipIt;
73189 next_state = Reset;
73190 return 0;
73191diff --git a/init/main.c b/init/main.c
73192index cee4b5c..360e10a 100644
73193--- a/init/main.c
73194+++ b/init/main.c
73195@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
73196 extern void tc_init(void);
73197 #endif
73198
73199+extern void grsecurity_init(void);
73200+
73201 /*
73202 * Debug helper: via this flag we know that we are in 'early bootup code'
73203 * where only the boot processor is running with IRQ disabled. This means
73204@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
73205
73206 __setup("reset_devices", set_reset_devices);
73207
73208+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
73209+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
73210+static int __init setup_grsec_proc_gid(char *str)
73211+{
73212+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
73213+ return 1;
73214+}
73215+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
73216+#endif
73217+
73218+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
73219+extern char pax_enter_kernel_user[];
73220+extern char pax_exit_kernel_user[];
73221+extern pgdval_t clone_pgd_mask;
73222+#endif
73223+
73224+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
73225+static int __init setup_pax_nouderef(char *str)
73226+{
73227+#ifdef CONFIG_X86_32
73228+ unsigned int cpu;
73229+ struct desc_struct *gdt;
73230+
73231+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
73232+ gdt = get_cpu_gdt_table(cpu);
73233+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
73234+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
73235+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
73236+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
73237+ }
73238+ loadsegment(ds, __KERNEL_DS);
73239+ loadsegment(es, __KERNEL_DS);
73240+ loadsegment(ss, __KERNEL_DS);
73241+#else
73242+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
73243+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
73244+ clone_pgd_mask = ~(pgdval_t)0UL;
73245+#endif
73246+
73247+ return 0;
73248+}
73249+early_param("pax_nouderef", setup_pax_nouderef);
73250+#endif
73251+
73252+#ifdef CONFIG_PAX_SOFTMODE
73253+int pax_softmode;
73254+
73255+static int __init setup_pax_softmode(char *str)
73256+{
73257+ get_option(&str, &pax_softmode);
73258+ return 1;
73259+}
73260+__setup("pax_softmode=", setup_pax_softmode);
73261+#endif
73262+
73263 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
73264 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
73265 static const char *panic_later, *panic_param;
73266@@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
73267 {
73268 int count = preempt_count();
73269 int ret;
73270+ const char *msg1 = "", *msg2 = "";
73271
73272 if (initcall_debug)
73273 ret = do_one_initcall_debug(fn);
73274@@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
73275 sprintf(msgbuf, "error code %d ", ret);
73276
73277 if (preempt_count() != count) {
73278- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
73279+ msg1 = " preemption imbalance";
73280 preempt_count() = count;
73281 }
73282 if (irqs_disabled()) {
73283- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
73284+ msg2 = " disabled interrupts";
73285 local_irq_enable();
73286 }
73287- if (msgbuf[0]) {
73288- printk("initcall %pF returned with %s\n", fn, msgbuf);
73289+ if (msgbuf[0] || *msg1 || *msg2) {
73290+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
73291 }
73292
73293 return ret;
73294@@ -755,8 +813,14 @@ static void __init do_initcall_level(int level)
73295 level, level,
73296 &repair_env_string);
73297
73298- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
73299+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
73300 do_one_initcall(*fn);
73301+
73302+#ifdef LATENT_ENTROPY_PLUGIN
73303+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
73304+#endif
73305+
73306+ }
73307 }
73308
73309 static void __init do_initcalls(void)
73310@@ -790,8 +854,14 @@ static void __init do_pre_smp_initcalls(void)
73311 {
73312 initcall_t *fn;
73313
73314- for (fn = __initcall_start; fn < __initcall0_start; fn++)
73315+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
73316 do_one_initcall(*fn);
73317+
73318+#ifdef LATENT_ENTROPY_PLUGIN
73319+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
73320+#endif
73321+
73322+ }
73323 }
73324
73325 static int run_init_process(const char *init_filename)
73326@@ -877,7 +947,7 @@ static noinline void __init kernel_init_freeable(void)
73327 do_basic_setup();
73328
73329 /* Open the /dev/console on the rootfs, this should never fail */
73330- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
73331+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
73332 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
73333
73334 (void) sys_dup(0);
73335@@ -890,11 +960,13 @@ static noinline void __init kernel_init_freeable(void)
73336 if (!ramdisk_execute_command)
73337 ramdisk_execute_command = "/init";
73338
73339- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
73340+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
73341 ramdisk_execute_command = NULL;
73342 prepare_namespace();
73343 }
73344
73345+ grsecurity_init();
73346+
73347 /*
73348 * Ok, we have completed the initial bootup, and
73349 * we're essentially up and running. Get rid of the
73350diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
73351index 130dfec..cc88451 100644
73352--- a/ipc/ipc_sysctl.c
73353+++ b/ipc/ipc_sysctl.c
73354@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
73355 static int proc_ipc_dointvec(ctl_table *table, int write,
73356 void __user *buffer, size_t *lenp, loff_t *ppos)
73357 {
73358- struct ctl_table ipc_table;
73359+ ctl_table_no_const ipc_table;
73360
73361 memcpy(&ipc_table, table, sizeof(ipc_table));
73362 ipc_table.data = get_ipc(table);
73363@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
73364 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
73365 void __user *buffer, size_t *lenp, loff_t *ppos)
73366 {
73367- struct ctl_table ipc_table;
73368+ ctl_table_no_const ipc_table;
73369
73370 memcpy(&ipc_table, table, sizeof(ipc_table));
73371 ipc_table.data = get_ipc(table);
73372@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
73373 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
73374 void __user *buffer, size_t *lenp, loff_t *ppos)
73375 {
73376- struct ctl_table ipc_table;
73377+ ctl_table_no_const ipc_table;
73378 size_t lenp_bef = *lenp;
73379 int rc;
73380
73381@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
73382 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
73383 void __user *buffer, size_t *lenp, loff_t *ppos)
73384 {
73385- struct ctl_table ipc_table;
73386+ ctl_table_no_const ipc_table;
73387 memcpy(&ipc_table, table, sizeof(ipc_table));
73388 ipc_table.data = get_ipc(table);
73389
73390@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
73391 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
73392 void __user *buffer, size_t *lenp, loff_t *ppos)
73393 {
73394- struct ctl_table ipc_table;
73395+ ctl_table_no_const ipc_table;
73396 size_t lenp_bef = *lenp;
73397 int oldval;
73398 int rc;
73399diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
73400index 383d638..943fdbb 100644
73401--- a/ipc/mq_sysctl.c
73402+++ b/ipc/mq_sysctl.c
73403@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
73404 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
73405 void __user *buffer, size_t *lenp, loff_t *ppos)
73406 {
73407- struct ctl_table mq_table;
73408+ ctl_table_no_const mq_table;
73409 memcpy(&mq_table, table, sizeof(mq_table));
73410 mq_table.data = get_mq(table);
73411
73412diff --git a/ipc/mqueue.c b/ipc/mqueue.c
73413index 6ebfbf5..c750fff 100644
73414--- a/ipc/mqueue.c
73415+++ b/ipc/mqueue.c
73416@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
73417 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
73418 info->attr.mq_msgsize);
73419
73420+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
73421 spin_lock(&mq_lock);
73422 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
73423 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
73424diff --git a/ipc/msg.c b/ipc/msg.c
73425index 31cd1bf..362ea07 100644
73426--- a/ipc/msg.c
73427+++ b/ipc/msg.c
73428@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
73429 return security_msg_queue_associate(msq, msgflg);
73430 }
73431
73432+static struct ipc_ops msg_ops = {
73433+ .getnew = newque,
73434+ .associate = msg_security,
73435+ .more_checks = NULL
73436+};
73437+
73438 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
73439 {
73440 struct ipc_namespace *ns;
73441- struct ipc_ops msg_ops;
73442 struct ipc_params msg_params;
73443
73444 ns = current->nsproxy->ipc_ns;
73445
73446- msg_ops.getnew = newque;
73447- msg_ops.associate = msg_security;
73448- msg_ops.more_checks = NULL;
73449-
73450 msg_params.key = key;
73451 msg_params.flg = msgflg;
73452
73453diff --git a/ipc/sem.c b/ipc/sem.c
73454index 58d31f1..cce7a55 100644
73455--- a/ipc/sem.c
73456+++ b/ipc/sem.c
73457@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
73458 return 0;
73459 }
73460
73461+static struct ipc_ops sem_ops = {
73462+ .getnew = newary,
73463+ .associate = sem_security,
73464+ .more_checks = sem_more_checks
73465+};
73466+
73467 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
73468 {
73469 struct ipc_namespace *ns;
73470- struct ipc_ops sem_ops;
73471 struct ipc_params sem_params;
73472
73473 ns = current->nsproxy->ipc_ns;
73474@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
73475 if (nsems < 0 || nsems > ns->sc_semmsl)
73476 return -EINVAL;
73477
73478- sem_ops.getnew = newary;
73479- sem_ops.associate = sem_security;
73480- sem_ops.more_checks = sem_more_checks;
73481-
73482 sem_params.key = key;
73483 sem_params.flg = semflg;
73484 sem_params.u.nsems = nsems;
73485diff --git a/ipc/shm.c b/ipc/shm.c
73486index 4fa6d8f..55cff14 100644
73487--- a/ipc/shm.c
73488+++ b/ipc/shm.c
73489@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
73490 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
73491 #endif
73492
73493+#ifdef CONFIG_GRKERNSEC
73494+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73495+ const time_t shm_createtime, const kuid_t cuid,
73496+ const int shmid);
73497+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73498+ const time_t shm_createtime);
73499+#endif
73500+
73501 void shm_init_ns(struct ipc_namespace *ns)
73502 {
73503 ns->shm_ctlmax = SHMMAX;
73504@@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
73505 shp->shm_lprid = 0;
73506 shp->shm_atim = shp->shm_dtim = 0;
73507 shp->shm_ctim = get_seconds();
73508+#ifdef CONFIG_GRKERNSEC
73509+ {
73510+ struct timespec timeval;
73511+ do_posix_clock_monotonic_gettime(&timeval);
73512+
73513+ shp->shm_createtime = timeval.tv_sec;
73514+ }
73515+#endif
73516 shp->shm_segsz = size;
73517 shp->shm_nattch = 0;
73518 shp->shm_file = file;
73519@@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
73520 return 0;
73521 }
73522
73523+static struct ipc_ops shm_ops = {
73524+ .getnew = newseg,
73525+ .associate = shm_security,
73526+ .more_checks = shm_more_checks
73527+};
73528+
73529 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
73530 {
73531 struct ipc_namespace *ns;
73532- struct ipc_ops shm_ops;
73533 struct ipc_params shm_params;
73534
73535 ns = current->nsproxy->ipc_ns;
73536
73537- shm_ops.getnew = newseg;
73538- shm_ops.associate = shm_security;
73539- shm_ops.more_checks = shm_more_checks;
73540-
73541 shm_params.key = key;
73542 shm_params.flg = shmflg;
73543 shm_params.u.size = size;
73544@@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
73545 f_mode = FMODE_READ | FMODE_WRITE;
73546 }
73547 if (shmflg & SHM_EXEC) {
73548+
73549+#ifdef CONFIG_PAX_MPROTECT
73550+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
73551+ goto out;
73552+#endif
73553+
73554 prot |= PROT_EXEC;
73555 acc_mode |= S_IXUGO;
73556 }
73557@@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
73558 if (err)
73559 goto out_unlock;
73560
73561+#ifdef CONFIG_GRKERNSEC
73562+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
73563+ shp->shm_perm.cuid, shmid) ||
73564+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
73565+ err = -EACCES;
73566+ goto out_unlock;
73567+ }
73568+#endif
73569+
73570 path = shp->shm_file->f_path;
73571 path_get(&path);
73572 shp->shm_nattch++;
73573+#ifdef CONFIG_GRKERNSEC
73574+ shp->shm_lapid = current->pid;
73575+#endif
73576 size = i_size_read(path.dentry->d_inode);
73577 shm_unlock(shp);
73578
73579diff --git a/kernel/acct.c b/kernel/acct.c
73580index 051e071..15e0920 100644
73581--- a/kernel/acct.c
73582+++ b/kernel/acct.c
73583@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
73584 */
73585 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
73586 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
73587- file->f_op->write(file, (char *)&ac,
73588+ file->f_op->write(file, (char __force_user *)&ac,
73589 sizeof(acct_t), &file->f_pos);
73590 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
73591 set_fs(fs);
73592diff --git a/kernel/audit.c b/kernel/audit.c
73593index d596e53..dbef3c3 100644
73594--- a/kernel/audit.c
73595+++ b/kernel/audit.c
73596@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
73597 3) suppressed due to audit_rate_limit
73598 4) suppressed due to audit_backlog_limit
73599 */
73600-static atomic_t audit_lost = ATOMIC_INIT(0);
73601+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
73602
73603 /* The netlink socket. */
73604 static struct sock *audit_sock;
73605@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
73606 unsigned long now;
73607 int print;
73608
73609- atomic_inc(&audit_lost);
73610+ atomic_inc_unchecked(&audit_lost);
73611
73612 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
73613
73614@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
73615 printk(KERN_WARNING
73616 "audit: audit_lost=%d audit_rate_limit=%d "
73617 "audit_backlog_limit=%d\n",
73618- atomic_read(&audit_lost),
73619+ atomic_read_unchecked(&audit_lost),
73620 audit_rate_limit,
73621 audit_backlog_limit);
73622 audit_panic(message);
73623@@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
73624 status_set.pid = audit_pid;
73625 status_set.rate_limit = audit_rate_limit;
73626 status_set.backlog_limit = audit_backlog_limit;
73627- status_set.lost = atomic_read(&audit_lost);
73628+ status_set.lost = atomic_read_unchecked(&audit_lost);
73629 status_set.backlog = skb_queue_len(&audit_skb_queue);
73630 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
73631 &status_set, sizeof(status_set));
73632diff --git a/kernel/auditsc.c b/kernel/auditsc.c
73633index a371f85..da826c1 100644
73634--- a/kernel/auditsc.c
73635+++ b/kernel/auditsc.c
73636@@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
73637 }
73638
73639 /* global counter which is incremented every time something logs in */
73640-static atomic_t session_id = ATOMIC_INIT(0);
73641+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
73642
73643 /**
73644 * audit_set_loginuid - set current task's audit_context loginuid
73645@@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
73646 return -EPERM;
73647 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
73648
73649- sessionid = atomic_inc_return(&session_id);
73650+ sessionid = atomic_inc_return_unchecked(&session_id);
73651 if (context && context->in_syscall) {
73652 struct audit_buffer *ab;
73653
73654diff --git a/kernel/capability.c b/kernel/capability.c
73655index 493d972..f87dfbd 100644
73656--- a/kernel/capability.c
73657+++ b/kernel/capability.c
73658@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
73659 * before modification is attempted and the application
73660 * fails.
73661 */
73662+ if (tocopy > ARRAY_SIZE(kdata))
73663+ return -EFAULT;
73664+
73665 if (copy_to_user(dataptr, kdata, tocopy
73666 * sizeof(struct __user_cap_data_struct))) {
73667 return -EFAULT;
73668@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
73669 int ret;
73670
73671 rcu_read_lock();
73672- ret = security_capable(__task_cred(t), ns, cap);
73673+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
73674+ gr_task_is_capable(t, __task_cred(t), cap);
73675 rcu_read_unlock();
73676
73677- return (ret == 0);
73678+ return ret;
73679 }
73680
73681 /**
73682@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
73683 int ret;
73684
73685 rcu_read_lock();
73686- ret = security_capable_noaudit(__task_cred(t), ns, cap);
73687+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
73688 rcu_read_unlock();
73689
73690- return (ret == 0);
73691+ return ret;
73692 }
73693
73694 /**
73695@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
73696 BUG();
73697 }
73698
73699- if (security_capable(current_cred(), ns, cap) == 0) {
73700+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
73701 current->flags |= PF_SUPERPRIV;
73702 return true;
73703 }
73704@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
73705 }
73706 EXPORT_SYMBOL(ns_capable);
73707
73708+bool ns_capable_nolog(struct user_namespace *ns, int cap)
73709+{
73710+ if (unlikely(!cap_valid(cap))) {
73711+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
73712+ BUG();
73713+ }
73714+
73715+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
73716+ current->flags |= PF_SUPERPRIV;
73717+ return true;
73718+ }
73719+ return false;
73720+}
73721+EXPORT_SYMBOL(ns_capable_nolog);
73722+
73723 /**
73724 * capable - Determine if the current task has a superior capability in effect
73725 * @cap: The capability to be tested for
73726@@ -408,6 +427,12 @@ bool capable(int cap)
73727 }
73728 EXPORT_SYMBOL(capable);
73729
73730+bool capable_nolog(int cap)
73731+{
73732+ return ns_capable_nolog(&init_user_ns, cap);
73733+}
73734+EXPORT_SYMBOL(capable_nolog);
73735+
73736 /**
73737 * nsown_capable - Check superior capability to one's own user_ns
73738 * @cap: The capability in question
73739@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
73740
73741 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
73742 }
73743+
73744+bool inode_capable_nolog(const struct inode *inode, int cap)
73745+{
73746+ struct user_namespace *ns = current_user_ns();
73747+
73748+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
73749+}
73750diff --git a/kernel/cgroup.c b/kernel/cgroup.c
73751index 1e23664..570a83d 100644
73752--- a/kernel/cgroup.c
73753+++ b/kernel/cgroup.c
73754@@ -5543,7 +5543,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
73755 struct css_set *cg = link->cg;
73756 struct task_struct *task;
73757 int count = 0;
73758- seq_printf(seq, "css_set %p\n", cg);
73759+ seq_printf(seq, "css_set %pK\n", cg);
73760 list_for_each_entry(task, &cg->tasks, cg_list) {
73761 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
73762 seq_puts(seq, " ...\n");
73763diff --git a/kernel/compat.c b/kernel/compat.c
73764index 36700e9..73d770c 100644
73765--- a/kernel/compat.c
73766+++ b/kernel/compat.c
73767@@ -13,6 +13,7 @@
73768
73769 #include <linux/linkage.h>
73770 #include <linux/compat.h>
73771+#include <linux/module.h>
73772 #include <linux/errno.h>
73773 #include <linux/time.h>
73774 #include <linux/signal.h>
73775@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
73776 mm_segment_t oldfs;
73777 long ret;
73778
73779- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
73780+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
73781 oldfs = get_fs();
73782 set_fs(KERNEL_DS);
73783 ret = hrtimer_nanosleep_restart(restart);
73784@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
73785 oldfs = get_fs();
73786 set_fs(KERNEL_DS);
73787 ret = hrtimer_nanosleep(&tu,
73788- rmtp ? (struct timespec __user *)&rmt : NULL,
73789+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
73790 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
73791 set_fs(oldfs);
73792
73793@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
73794 mm_segment_t old_fs = get_fs();
73795
73796 set_fs(KERNEL_DS);
73797- ret = sys_sigpending((old_sigset_t __user *) &s);
73798+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
73799 set_fs(old_fs);
73800 if (ret == 0)
73801 ret = put_user(s, set);
73802@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
73803 mm_segment_t old_fs = get_fs();
73804
73805 set_fs(KERNEL_DS);
73806- ret = sys_old_getrlimit(resource, &r);
73807+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
73808 set_fs(old_fs);
73809
73810 if (!ret) {
73811@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
73812 mm_segment_t old_fs = get_fs();
73813
73814 set_fs(KERNEL_DS);
73815- ret = sys_getrusage(who, (struct rusage __user *) &r);
73816+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
73817 set_fs(old_fs);
73818
73819 if (ret)
73820@@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
73821 set_fs (KERNEL_DS);
73822 ret = sys_wait4(pid,
73823 (stat_addr ?
73824- (unsigned int __user *) &status : NULL),
73825- options, (struct rusage __user *) &r);
73826+ (unsigned int __force_user *) &status : NULL),
73827+ options, (struct rusage __force_user *) &r);
73828 set_fs (old_fs);
73829
73830 if (ret > 0) {
73831@@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
73832 memset(&info, 0, sizeof(info));
73833
73834 set_fs(KERNEL_DS);
73835- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
73836- uru ? (struct rusage __user *)&ru : NULL);
73837+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
73838+ uru ? (struct rusage __force_user *)&ru : NULL);
73839 set_fs(old_fs);
73840
73841 if ((ret < 0) || (info.si_signo == 0))
73842@@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
73843 oldfs = get_fs();
73844 set_fs(KERNEL_DS);
73845 err = sys_timer_settime(timer_id, flags,
73846- (struct itimerspec __user *) &newts,
73847- (struct itimerspec __user *) &oldts);
73848+ (struct itimerspec __force_user *) &newts,
73849+ (struct itimerspec __force_user *) &oldts);
73850 set_fs(oldfs);
73851 if (!err && old && put_compat_itimerspec(old, &oldts))
73852 return -EFAULT;
73853@@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
73854 oldfs = get_fs();
73855 set_fs(KERNEL_DS);
73856 err = sys_timer_gettime(timer_id,
73857- (struct itimerspec __user *) &ts);
73858+ (struct itimerspec __force_user *) &ts);
73859 set_fs(oldfs);
73860 if (!err && put_compat_itimerspec(setting, &ts))
73861 return -EFAULT;
73862@@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
73863 oldfs = get_fs();
73864 set_fs(KERNEL_DS);
73865 err = sys_clock_settime(which_clock,
73866- (struct timespec __user *) &ts);
73867+ (struct timespec __force_user *) &ts);
73868 set_fs(oldfs);
73869 return err;
73870 }
73871@@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
73872 oldfs = get_fs();
73873 set_fs(KERNEL_DS);
73874 err = sys_clock_gettime(which_clock,
73875- (struct timespec __user *) &ts);
73876+ (struct timespec __force_user *) &ts);
73877 set_fs(oldfs);
73878 if (!err && put_compat_timespec(&ts, tp))
73879 return -EFAULT;
73880@@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
73881
73882 oldfs = get_fs();
73883 set_fs(KERNEL_DS);
73884- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
73885+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
73886 set_fs(oldfs);
73887
73888 err = compat_put_timex(utp, &txc);
73889@@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
73890 oldfs = get_fs();
73891 set_fs(KERNEL_DS);
73892 err = sys_clock_getres(which_clock,
73893- (struct timespec __user *) &ts);
73894+ (struct timespec __force_user *) &ts);
73895 set_fs(oldfs);
73896 if (!err && tp && put_compat_timespec(&ts, tp))
73897 return -EFAULT;
73898@@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
73899 long err;
73900 mm_segment_t oldfs;
73901 struct timespec tu;
73902- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
73903+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
73904
73905- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
73906+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
73907 oldfs = get_fs();
73908 set_fs(KERNEL_DS);
73909 err = clock_nanosleep_restart(restart);
73910@@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
73911 oldfs = get_fs();
73912 set_fs(KERNEL_DS);
73913 err = sys_clock_nanosleep(which_clock, flags,
73914- (struct timespec __user *) &in,
73915- (struct timespec __user *) &out);
73916+ (struct timespec __force_user *) &in,
73917+ (struct timespec __force_user *) &out);
73918 set_fs(oldfs);
73919
73920 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
73921diff --git a/kernel/configs.c b/kernel/configs.c
73922index 42e8fa0..9e7406b 100644
73923--- a/kernel/configs.c
73924+++ b/kernel/configs.c
73925@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
73926 struct proc_dir_entry *entry;
73927
73928 /* create the current config file */
73929+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
73930+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
73931+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
73932+ &ikconfig_file_ops);
73933+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
73934+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
73935+ &ikconfig_file_ops);
73936+#endif
73937+#else
73938 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
73939 &ikconfig_file_ops);
73940+#endif
73941+
73942 if (!entry)
73943 return -ENOMEM;
73944
73945diff --git a/kernel/cred.c b/kernel/cred.c
73946index e0573a4..3874e41 100644
73947--- a/kernel/cred.c
73948+++ b/kernel/cred.c
73949@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
73950 validate_creds(cred);
73951 alter_cred_subscribers(cred, -1);
73952 put_cred(cred);
73953+
73954+#ifdef CONFIG_GRKERNSEC_SETXID
73955+ cred = (struct cred *) tsk->delayed_cred;
73956+ if (cred != NULL) {
73957+ tsk->delayed_cred = NULL;
73958+ validate_creds(cred);
73959+ alter_cred_subscribers(cred, -1);
73960+ put_cred(cred);
73961+ }
73962+#endif
73963 }
73964
73965 /**
73966@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
73967 * Always returns 0 thus allowing this function to be tail-called at the end
73968 * of, say, sys_setgid().
73969 */
73970-int commit_creds(struct cred *new)
73971+static int __commit_creds(struct cred *new)
73972 {
73973 struct task_struct *task = current;
73974 const struct cred *old = task->real_cred;
73975@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
73976
73977 get_cred(new); /* we will require a ref for the subj creds too */
73978
73979+ gr_set_role_label(task, new->uid, new->gid);
73980+
73981 /* dumpability changes */
73982 if (!uid_eq(old->euid, new->euid) ||
73983 !gid_eq(old->egid, new->egid) ||
73984@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
73985 put_cred(old);
73986 return 0;
73987 }
73988+#ifdef CONFIG_GRKERNSEC_SETXID
73989+extern int set_user(struct cred *new);
73990+
73991+void gr_delayed_cred_worker(void)
73992+{
73993+ const struct cred *new = current->delayed_cred;
73994+ struct cred *ncred;
73995+
73996+ current->delayed_cred = NULL;
73997+
73998+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
73999+ // from doing get_cred on it when queueing this
74000+ put_cred(new);
74001+ return;
74002+ } else if (new == NULL)
74003+ return;
74004+
74005+ ncred = prepare_creds();
74006+ if (!ncred)
74007+ goto die;
74008+ // uids
74009+ ncred->uid = new->uid;
74010+ ncred->euid = new->euid;
74011+ ncred->suid = new->suid;
74012+ ncred->fsuid = new->fsuid;
74013+ // gids
74014+ ncred->gid = new->gid;
74015+ ncred->egid = new->egid;
74016+ ncred->sgid = new->sgid;
74017+ ncred->fsgid = new->fsgid;
74018+ // groups
74019+ if (set_groups(ncred, new->group_info) < 0) {
74020+ abort_creds(ncred);
74021+ goto die;
74022+ }
74023+ // caps
74024+ ncred->securebits = new->securebits;
74025+ ncred->cap_inheritable = new->cap_inheritable;
74026+ ncred->cap_permitted = new->cap_permitted;
74027+ ncred->cap_effective = new->cap_effective;
74028+ ncred->cap_bset = new->cap_bset;
74029+
74030+ if (set_user(ncred)) {
74031+ abort_creds(ncred);
74032+ goto die;
74033+ }
74034+
74035+ // from doing get_cred on it when queueing this
74036+ put_cred(new);
74037+
74038+ __commit_creds(ncred);
74039+ return;
74040+die:
74041+ // from doing get_cred on it when queueing this
74042+ put_cred(new);
74043+ do_group_exit(SIGKILL);
74044+}
74045+#endif
74046+
74047+int commit_creds(struct cred *new)
74048+{
74049+#ifdef CONFIG_GRKERNSEC_SETXID
74050+ int ret;
74051+ int schedule_it = 0;
74052+ struct task_struct *t;
74053+
74054+ /* we won't get called with tasklist_lock held for writing
74055+ and interrupts disabled as the cred struct in that case is
74056+ init_cred
74057+ */
74058+ if (grsec_enable_setxid && !current_is_single_threaded() &&
74059+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
74060+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
74061+ schedule_it = 1;
74062+ }
74063+ ret = __commit_creds(new);
74064+ if (schedule_it) {
74065+ rcu_read_lock();
74066+ read_lock(&tasklist_lock);
74067+ for (t = next_thread(current); t != current;
74068+ t = next_thread(t)) {
74069+ if (t->delayed_cred == NULL) {
74070+ t->delayed_cred = get_cred(new);
74071+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
74072+ set_tsk_need_resched(t);
74073+ }
74074+ }
74075+ read_unlock(&tasklist_lock);
74076+ rcu_read_unlock();
74077+ }
74078+ return ret;
74079+#else
74080+ return __commit_creds(new);
74081+#endif
74082+}
74083+
74084 EXPORT_SYMBOL(commit_creds);
74085
74086 /**
74087diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
74088index 9a61738..c5c8f3a 100644
74089--- a/kernel/debug/debug_core.c
74090+++ b/kernel/debug/debug_core.c
74091@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
74092 */
74093 static atomic_t masters_in_kgdb;
74094 static atomic_t slaves_in_kgdb;
74095-static atomic_t kgdb_break_tasklet_var;
74096+static atomic_unchecked_t kgdb_break_tasklet_var;
74097 atomic_t kgdb_setting_breakpoint;
74098
74099 struct task_struct *kgdb_usethread;
74100@@ -132,7 +132,7 @@ int kgdb_single_step;
74101 static pid_t kgdb_sstep_pid;
74102
74103 /* to keep track of the CPU which is doing the single stepping*/
74104-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
74105+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
74106
74107 /*
74108 * If you are debugging a problem where roundup (the collection of
74109@@ -540,7 +540,7 @@ return_normal:
74110 * kernel will only try for the value of sstep_tries before
74111 * giving up and continuing on.
74112 */
74113- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
74114+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
74115 (kgdb_info[cpu].task &&
74116 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
74117 atomic_set(&kgdb_active, -1);
74118@@ -634,8 +634,8 @@ cpu_master_loop:
74119 }
74120
74121 kgdb_restore:
74122- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
74123- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
74124+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
74125+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
74126 if (kgdb_info[sstep_cpu].task)
74127 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
74128 else
74129@@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
74130 static void kgdb_tasklet_bpt(unsigned long ing)
74131 {
74132 kgdb_breakpoint();
74133- atomic_set(&kgdb_break_tasklet_var, 0);
74134+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
74135 }
74136
74137 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
74138
74139 void kgdb_schedule_breakpoint(void)
74140 {
74141- if (atomic_read(&kgdb_break_tasklet_var) ||
74142+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
74143 atomic_read(&kgdb_active) != -1 ||
74144 atomic_read(&kgdb_setting_breakpoint))
74145 return;
74146- atomic_inc(&kgdb_break_tasklet_var);
74147+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
74148 tasklet_schedule(&kgdb_tasklet_breakpoint);
74149 }
74150 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
74151diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
74152index 8875254..7cf4928 100644
74153--- a/kernel/debug/kdb/kdb_main.c
74154+++ b/kernel/debug/kdb/kdb_main.c
74155@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
74156 continue;
74157
74158 kdb_printf("%-20s%8u 0x%p ", mod->name,
74159- mod->core_size, (void *)mod);
74160+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
74161 #ifdef CONFIG_MODULE_UNLOAD
74162 kdb_printf("%4ld ", module_refcount(mod));
74163 #endif
74164@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
74165 kdb_printf(" (Loading)");
74166 else
74167 kdb_printf(" (Live)");
74168- kdb_printf(" 0x%p", mod->module_core);
74169+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
74170
74171 #ifdef CONFIG_MODULE_UNLOAD
74172 {
74173diff --git a/kernel/events/core.c b/kernel/events/core.c
74174index 7b6646a..3cb1135 100644
74175--- a/kernel/events/core.c
74176+++ b/kernel/events/core.c
74177@@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
74178 return 0;
74179 }
74180
74181-static atomic64_t perf_event_id;
74182+static atomic64_unchecked_t perf_event_id;
74183
74184 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
74185 enum event_type_t event_type);
74186@@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
74187
74188 static inline u64 perf_event_count(struct perf_event *event)
74189 {
74190- return local64_read(&event->count) + atomic64_read(&event->child_count);
74191+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
74192 }
74193
74194 static u64 perf_event_read(struct perf_event *event)
74195@@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
74196 mutex_lock(&event->child_mutex);
74197 total += perf_event_read(event);
74198 *enabled += event->total_time_enabled +
74199- atomic64_read(&event->child_total_time_enabled);
74200+ atomic64_read_unchecked(&event->child_total_time_enabled);
74201 *running += event->total_time_running +
74202- atomic64_read(&event->child_total_time_running);
74203+ atomic64_read_unchecked(&event->child_total_time_running);
74204
74205 list_for_each_entry(child, &event->child_list, child_list) {
74206 total += perf_event_read(child);
74207@@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
74208 userpg->offset -= local64_read(&event->hw.prev_count);
74209
74210 userpg->time_enabled = enabled +
74211- atomic64_read(&event->child_total_time_enabled);
74212+ atomic64_read_unchecked(&event->child_total_time_enabled);
74213
74214 userpg->time_running = running +
74215- atomic64_read(&event->child_total_time_running);
74216+ atomic64_read_unchecked(&event->child_total_time_running);
74217
74218 arch_perf_update_userpage(userpg, now);
74219
74220@@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
74221 values[n++] = perf_event_count(event);
74222 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
74223 values[n++] = enabled +
74224- atomic64_read(&event->child_total_time_enabled);
74225+ atomic64_read_unchecked(&event->child_total_time_enabled);
74226 }
74227 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
74228 values[n++] = running +
74229- atomic64_read(&event->child_total_time_running);
74230+ atomic64_read_unchecked(&event->child_total_time_running);
74231 }
74232 if (read_format & PERF_FORMAT_ID)
74233 values[n++] = primary_event_id(event);
74234@@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
74235 * need to add enough zero bytes after the string to handle
74236 * the 64bit alignment we do later.
74237 */
74238- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
74239+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
74240 if (!buf) {
74241 name = strncpy(tmp, "//enomem", sizeof(tmp));
74242 goto got_name;
74243 }
74244- name = d_path(&file->f_path, buf, PATH_MAX);
74245+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
74246 if (IS_ERR(name)) {
74247 name = strncpy(tmp, "//toolong", sizeof(tmp));
74248 goto got_name;
74249@@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
74250 event->parent = parent_event;
74251
74252 event->ns = get_pid_ns(task_active_pid_ns(current));
74253- event->id = atomic64_inc_return(&perf_event_id);
74254+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
74255
74256 event->state = PERF_EVENT_STATE_INACTIVE;
74257
74258@@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
74259 /*
74260 * Add back the child's count to the parent's count:
74261 */
74262- atomic64_add(child_val, &parent_event->child_count);
74263- atomic64_add(child_event->total_time_enabled,
74264+ atomic64_add_unchecked(child_val, &parent_event->child_count);
74265+ atomic64_add_unchecked(child_event->total_time_enabled,
74266 &parent_event->child_total_time_enabled);
74267- atomic64_add(child_event->total_time_running,
74268+ atomic64_add_unchecked(child_event->total_time_running,
74269 &parent_event->child_total_time_running);
74270
74271 /*
74272diff --git a/kernel/exit.c b/kernel/exit.c
74273index b4df219..f13c02d 100644
74274--- a/kernel/exit.c
74275+++ b/kernel/exit.c
74276@@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
74277 struct task_struct *leader;
74278 int zap_leader;
74279 repeat:
74280+#ifdef CONFIG_NET
74281+ gr_del_task_from_ip_table(p);
74282+#endif
74283+
74284 /* don't need to get the RCU readlock here - the process is dead and
74285 * can't be modifying its own credentials. But shut RCU-lockdep up */
74286 rcu_read_lock();
74287@@ -338,7 +342,7 @@ int allow_signal(int sig)
74288 * know it'll be handled, so that they don't get converted to
74289 * SIGKILL or just silently dropped.
74290 */
74291- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
74292+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
74293 recalc_sigpending();
74294 spin_unlock_irq(&current->sighand->siglock);
74295 return 0;
74296@@ -708,6 +712,8 @@ void do_exit(long code)
74297 struct task_struct *tsk = current;
74298 int group_dead;
74299
74300+ set_fs(USER_DS);
74301+
74302 profile_task_exit(tsk);
74303
74304 WARN_ON(blk_needs_flush_plug(tsk));
74305@@ -724,7 +730,6 @@ void do_exit(long code)
74306 * mm_release()->clear_child_tid() from writing to a user-controlled
74307 * kernel address.
74308 */
74309- set_fs(USER_DS);
74310
74311 ptrace_event(PTRACE_EVENT_EXIT, code);
74312
74313@@ -783,6 +788,9 @@ void do_exit(long code)
74314 tsk->exit_code = code;
74315 taskstats_exit(tsk, group_dead);
74316
74317+ gr_acl_handle_psacct(tsk, code);
74318+ gr_acl_handle_exit();
74319+
74320 exit_mm(tsk);
74321
74322 if (group_dead)
74323@@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
74324 * Take down every thread in the group. This is called by fatal signals
74325 * as well as by sys_exit_group (below).
74326 */
74327-void
74328+__noreturn void
74329 do_group_exit(int exit_code)
74330 {
74331 struct signal_struct *sig = current->signal;
74332diff --git a/kernel/fork.c b/kernel/fork.c
74333index 5630e52..0cee608 100644
74334--- a/kernel/fork.c
74335+++ b/kernel/fork.c
74336@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
74337 *stackend = STACK_END_MAGIC; /* for overflow detection */
74338
74339 #ifdef CONFIG_CC_STACKPROTECTOR
74340- tsk->stack_canary = get_random_int();
74341+ tsk->stack_canary = pax_get_random_long();
74342 #endif
74343
74344 /*
74345@@ -344,13 +344,81 @@ free_tsk:
74346 }
74347
74348 #ifdef CONFIG_MMU
74349+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
74350+{
74351+ struct vm_area_struct *tmp;
74352+ unsigned long charge;
74353+ struct mempolicy *pol;
74354+ struct file *file;
74355+
74356+ charge = 0;
74357+ if (mpnt->vm_flags & VM_ACCOUNT) {
74358+ unsigned long len = vma_pages(mpnt);
74359+
74360+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
74361+ goto fail_nomem;
74362+ charge = len;
74363+ }
74364+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74365+ if (!tmp)
74366+ goto fail_nomem;
74367+ *tmp = *mpnt;
74368+ tmp->vm_mm = mm;
74369+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
74370+ pol = mpol_dup(vma_policy(mpnt));
74371+ if (IS_ERR(pol))
74372+ goto fail_nomem_policy;
74373+ vma_set_policy(tmp, pol);
74374+ if (anon_vma_fork(tmp, mpnt))
74375+ goto fail_nomem_anon_vma_fork;
74376+ tmp->vm_flags &= ~VM_LOCKED;
74377+ tmp->vm_next = tmp->vm_prev = NULL;
74378+ tmp->vm_mirror = NULL;
74379+ file = tmp->vm_file;
74380+ if (file) {
74381+ struct inode *inode = file->f_path.dentry->d_inode;
74382+ struct address_space *mapping = file->f_mapping;
74383+
74384+ get_file(file);
74385+ if (tmp->vm_flags & VM_DENYWRITE)
74386+ atomic_dec(&inode->i_writecount);
74387+ mutex_lock(&mapping->i_mmap_mutex);
74388+ if (tmp->vm_flags & VM_SHARED)
74389+ mapping->i_mmap_writable++;
74390+ flush_dcache_mmap_lock(mapping);
74391+ /* insert tmp into the share list, just after mpnt */
74392+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
74393+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
74394+ else
74395+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
74396+ flush_dcache_mmap_unlock(mapping);
74397+ mutex_unlock(&mapping->i_mmap_mutex);
74398+ }
74399+
74400+ /*
74401+ * Clear hugetlb-related page reserves for children. This only
74402+ * affects MAP_PRIVATE mappings. Faults generated by the child
74403+ * are not guaranteed to succeed, even if read-only
74404+ */
74405+ if (is_vm_hugetlb_page(tmp))
74406+ reset_vma_resv_huge_pages(tmp);
74407+
74408+ return tmp;
74409+
74410+fail_nomem_anon_vma_fork:
74411+ mpol_put(pol);
74412+fail_nomem_policy:
74413+ kmem_cache_free(vm_area_cachep, tmp);
74414+fail_nomem:
74415+ vm_unacct_memory(charge);
74416+ return NULL;
74417+}
74418+
74419 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74420 {
74421 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
74422 struct rb_node **rb_link, *rb_parent;
74423 int retval;
74424- unsigned long charge;
74425- struct mempolicy *pol;
74426
74427 uprobe_start_dup_mmap();
74428 down_write(&oldmm->mmap_sem);
74429@@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74430 mm->locked_vm = 0;
74431 mm->mmap = NULL;
74432 mm->mmap_cache = NULL;
74433- mm->free_area_cache = oldmm->mmap_base;
74434- mm->cached_hole_size = ~0UL;
74435+ mm->free_area_cache = oldmm->free_area_cache;
74436+ mm->cached_hole_size = oldmm->cached_hole_size;
74437 mm->map_count = 0;
74438 cpumask_clear(mm_cpumask(mm));
74439 mm->mm_rb = RB_ROOT;
74440@@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74441
74442 prev = NULL;
74443 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
74444- struct file *file;
74445-
74446 if (mpnt->vm_flags & VM_DONTCOPY) {
74447 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
74448 -vma_pages(mpnt));
74449 continue;
74450 }
74451- charge = 0;
74452- if (mpnt->vm_flags & VM_ACCOUNT) {
74453- unsigned long len = vma_pages(mpnt);
74454-
74455- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
74456- goto fail_nomem;
74457- charge = len;
74458- }
74459- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74460- if (!tmp)
74461- goto fail_nomem;
74462- *tmp = *mpnt;
74463- INIT_LIST_HEAD(&tmp->anon_vma_chain);
74464- pol = mpol_dup(vma_policy(mpnt));
74465- retval = PTR_ERR(pol);
74466- if (IS_ERR(pol))
74467- goto fail_nomem_policy;
74468- vma_set_policy(tmp, pol);
74469- tmp->vm_mm = mm;
74470- if (anon_vma_fork(tmp, mpnt))
74471- goto fail_nomem_anon_vma_fork;
74472- tmp->vm_flags &= ~VM_LOCKED;
74473- tmp->vm_next = tmp->vm_prev = NULL;
74474- file = tmp->vm_file;
74475- if (file) {
74476- struct inode *inode = file->f_path.dentry->d_inode;
74477- struct address_space *mapping = file->f_mapping;
74478-
74479- get_file(file);
74480- if (tmp->vm_flags & VM_DENYWRITE)
74481- atomic_dec(&inode->i_writecount);
74482- mutex_lock(&mapping->i_mmap_mutex);
74483- if (tmp->vm_flags & VM_SHARED)
74484- mapping->i_mmap_writable++;
74485- flush_dcache_mmap_lock(mapping);
74486- /* insert tmp into the share list, just after mpnt */
74487- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
74488- vma_nonlinear_insert(tmp,
74489- &mapping->i_mmap_nonlinear);
74490- else
74491- vma_interval_tree_insert_after(tmp, mpnt,
74492- &mapping->i_mmap);
74493- flush_dcache_mmap_unlock(mapping);
74494- mutex_unlock(&mapping->i_mmap_mutex);
74495+ tmp = dup_vma(mm, oldmm, mpnt);
74496+ if (!tmp) {
74497+ retval = -ENOMEM;
74498+ goto out;
74499 }
74500
74501 /*
74502@@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74503 if (retval)
74504 goto out;
74505 }
74506+
74507+#ifdef CONFIG_PAX_SEGMEXEC
74508+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
74509+ struct vm_area_struct *mpnt_m;
74510+
74511+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
74512+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
74513+
74514+ if (!mpnt->vm_mirror)
74515+ continue;
74516+
74517+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
74518+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
74519+ mpnt->vm_mirror = mpnt_m;
74520+ } else {
74521+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
74522+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
74523+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
74524+ mpnt->vm_mirror->vm_mirror = mpnt;
74525+ }
74526+ }
74527+ BUG_ON(mpnt_m);
74528+ }
74529+#endif
74530+
74531 /* a new mm has just been created */
74532 arch_dup_mmap(oldmm, mm);
74533 retval = 0;
74534@@ -472,14 +523,6 @@ out:
74535 up_write(&oldmm->mmap_sem);
74536 uprobe_end_dup_mmap();
74537 return retval;
74538-fail_nomem_anon_vma_fork:
74539- mpol_put(pol);
74540-fail_nomem_policy:
74541- kmem_cache_free(vm_area_cachep, tmp);
74542-fail_nomem:
74543- retval = -ENOMEM;
74544- vm_unacct_memory(charge);
74545- goto out;
74546 }
74547
74548 static inline int mm_alloc_pgd(struct mm_struct *mm)
74549@@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
74550 return ERR_PTR(err);
74551
74552 mm = get_task_mm(task);
74553- if (mm && mm != current->mm &&
74554- !ptrace_may_access(task, mode)) {
74555+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
74556+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
74557 mmput(mm);
74558 mm = ERR_PTR(-EACCES);
74559 }
74560@@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
74561 spin_unlock(&fs->lock);
74562 return -EAGAIN;
74563 }
74564- fs->users++;
74565+ atomic_inc(&fs->users);
74566 spin_unlock(&fs->lock);
74567 return 0;
74568 }
74569 tsk->fs = copy_fs_struct(fs);
74570 if (!tsk->fs)
74571 return -ENOMEM;
74572+ /* Carry through gr_chroot_dentry and is_chrooted instead
74573+ of recomputing it here. Already copied when the task struct
74574+ is duplicated. This allows pivot_root to not be treated as
74575+ a chroot
74576+ */
74577+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
74578+
74579 return 0;
74580 }
74581
74582@@ -1196,6 +1246,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
74583 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
74584 #endif
74585 retval = -EAGAIN;
74586+
74587+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
74588+
74589 if (atomic_read(&p->real_cred->user->processes) >=
74590 task_rlimit(p, RLIMIT_NPROC)) {
74591 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
74592@@ -1435,6 +1488,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
74593 goto bad_fork_free_pid;
74594 }
74595
74596+ /* synchronizes with gr_set_acls()
74597+ we need to call this past the point of no return for fork()
74598+ */
74599+ gr_copy_label(p);
74600+
74601 if (clone_flags & CLONE_THREAD) {
74602 current->signal->nr_threads++;
74603 atomic_inc(&current->signal->live);
74604@@ -1518,6 +1576,8 @@ bad_fork_cleanup_count:
74605 bad_fork_free:
74606 free_task(p);
74607 fork_out:
74608+ gr_log_forkfail(retval);
74609+
74610 return ERR_PTR(retval);
74611 }
74612
74613@@ -1568,6 +1628,23 @@ long do_fork(unsigned long clone_flags,
74614 return -EINVAL;
74615 }
74616
74617+#ifdef CONFIG_GRKERNSEC
74618+ if (clone_flags & CLONE_NEWUSER) {
74619+ /*
74620+ * This doesn't really inspire confidence:
74621+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
74622+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
74623+ * Increases kernel attack surface in areas developers
74624+ * previously cared little about ("low importance due
74625+ * to requiring "root" capability")
74626+ * To be removed when this code receives *proper* review
74627+ */
74628+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
74629+ !capable(CAP_SETGID))
74630+ return -EPERM;
74631+ }
74632+#endif
74633+
74634 /*
74635 * Determine whether and which event to report to ptracer. When
74636 * called from kernel_thread or CLONE_UNTRACED is explicitly
74637@@ -1602,6 +1679,8 @@ long do_fork(unsigned long clone_flags,
74638 if (clone_flags & CLONE_PARENT_SETTID)
74639 put_user(nr, parent_tidptr);
74640
74641+ gr_handle_brute_check();
74642+
74643 if (clone_flags & CLONE_VFORK) {
74644 p->vfork_done = &vfork;
74645 init_completion(&vfork);
74646@@ -1755,7 +1834,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
74647 return 0;
74648
74649 /* don't need lock here; in the worst case we'll do useless copy */
74650- if (fs->users == 1)
74651+ if (atomic_read(&fs->users) == 1)
74652 return 0;
74653
74654 *new_fsp = copy_fs_struct(fs);
74655@@ -1869,7 +1948,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
74656 fs = current->fs;
74657 spin_lock(&fs->lock);
74658 current->fs = new_fs;
74659- if (--fs->users)
74660+ gr_set_chroot_entries(current, &current->fs->root);
74661+ if (atomic_dec_return(&fs->users))
74662 new_fs = NULL;
74663 else
74664 new_fs = fs;
74665diff --git a/kernel/futex.c b/kernel/futex.c
74666index 8879430..31696f1 100644
74667--- a/kernel/futex.c
74668+++ b/kernel/futex.c
74669@@ -54,6 +54,7 @@
74670 #include <linux/mount.h>
74671 #include <linux/pagemap.h>
74672 #include <linux/syscalls.h>
74673+#include <linux/ptrace.h>
74674 #include <linux/signal.h>
74675 #include <linux/export.h>
74676 #include <linux/magic.h>
74677@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
74678 struct page *page, *page_head;
74679 int err, ro = 0;
74680
74681+#ifdef CONFIG_PAX_SEGMEXEC
74682+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
74683+ return -EFAULT;
74684+#endif
74685+
74686 /*
74687 * The futex address must be "naturally" aligned.
74688 */
74689@@ -2731,6 +2737,7 @@ static int __init futex_init(void)
74690 {
74691 u32 curval;
74692 int i;
74693+ mm_segment_t oldfs;
74694
74695 /*
74696 * This will fail and we want it. Some arch implementations do
74697@@ -2742,8 +2749,11 @@ static int __init futex_init(void)
74698 * implementation, the non-functional ones will return
74699 * -ENOSYS.
74700 */
74701+ oldfs = get_fs();
74702+ set_fs(USER_DS);
74703 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
74704 futex_cmpxchg_enabled = 1;
74705+ set_fs(oldfs);
74706
74707 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
74708 plist_head_init(&futex_queues[i].chain);
74709diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
74710index a9642d5..51eb98c 100644
74711--- a/kernel/futex_compat.c
74712+++ b/kernel/futex_compat.c
74713@@ -31,7 +31,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
74714 return 0;
74715 }
74716
74717-static void __user *futex_uaddr(struct robust_list __user *entry,
74718+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
74719 compat_long_t futex_offset)
74720 {
74721 compat_uptr_t base = ptr_to_compat(entry);
74722diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
74723index 9b22d03..6295b62 100644
74724--- a/kernel/gcov/base.c
74725+++ b/kernel/gcov/base.c
74726@@ -102,11 +102,6 @@ void gcov_enable_events(void)
74727 }
74728
74729 #ifdef CONFIG_MODULES
74730-static inline int within(void *addr, void *start, unsigned long size)
74731-{
74732- return ((addr >= start) && (addr < start + size));
74733-}
74734-
74735 /* Update list and generate events when modules are unloaded. */
74736 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
74737 void *data)
74738@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
74739 prev = NULL;
74740 /* Remove entries located in module from linked list. */
74741 for (info = gcov_info_head; info; info = info->next) {
74742- if (within(info, mod->module_core, mod->core_size)) {
74743+ if (within_module_core_rw((unsigned long)info, mod)) {
74744 if (prev)
74745 prev->next = info->next;
74746 else
74747diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
74748index cdd5607..c3fc919 100644
74749--- a/kernel/hrtimer.c
74750+++ b/kernel/hrtimer.c
74751@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
74752 local_irq_restore(flags);
74753 }
74754
74755-static void run_hrtimer_softirq(struct softirq_action *h)
74756+static void run_hrtimer_softirq(void)
74757 {
74758 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
74759
74760@@ -1751,7 +1751,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
74761 return NOTIFY_OK;
74762 }
74763
74764-static struct notifier_block __cpuinitdata hrtimers_nb = {
74765+static struct notifier_block hrtimers_nb = {
74766 .notifier_call = hrtimer_cpu_notify,
74767 };
74768
74769diff --git a/kernel/jump_label.c b/kernel/jump_label.c
74770index 60f48fa..7f3a770 100644
74771--- a/kernel/jump_label.c
74772+++ b/kernel/jump_label.c
74773@@ -13,6 +13,7 @@
74774 #include <linux/sort.h>
74775 #include <linux/err.h>
74776 #include <linux/static_key.h>
74777+#include <linux/mm.h>
74778
74779 #ifdef HAVE_JUMP_LABEL
74780
74781@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
74782
74783 size = (((unsigned long)stop - (unsigned long)start)
74784 / sizeof(struct jump_entry));
74785+ pax_open_kernel();
74786 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
74787+ pax_close_kernel();
74788 }
74789
74790 static void jump_label_update(struct static_key *key, int enable);
74791@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
74792 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
74793 struct jump_entry *iter;
74794
74795+ pax_open_kernel();
74796 for (iter = iter_start; iter < iter_stop; iter++) {
74797 if (within_module_init(iter->code, mod))
74798 iter->code = 0;
74799 }
74800+ pax_close_kernel();
74801 }
74802
74803 static int
74804diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
74805index 2169fee..706ccca 100644
74806--- a/kernel/kallsyms.c
74807+++ b/kernel/kallsyms.c
74808@@ -11,6 +11,9 @@
74809 * Changed the compression method from stem compression to "table lookup"
74810 * compression (see scripts/kallsyms.c for a more complete description)
74811 */
74812+#ifdef CONFIG_GRKERNSEC_HIDESYM
74813+#define __INCLUDED_BY_HIDESYM 1
74814+#endif
74815 #include <linux/kallsyms.h>
74816 #include <linux/module.h>
74817 #include <linux/init.h>
74818@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
74819
74820 static inline int is_kernel_inittext(unsigned long addr)
74821 {
74822+ if (system_state != SYSTEM_BOOTING)
74823+ return 0;
74824+
74825 if (addr >= (unsigned long)_sinittext
74826 && addr <= (unsigned long)_einittext)
74827 return 1;
74828 return 0;
74829 }
74830
74831+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74832+#ifdef CONFIG_MODULES
74833+static inline int is_module_text(unsigned long addr)
74834+{
74835+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
74836+ return 1;
74837+
74838+ addr = ktla_ktva(addr);
74839+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
74840+}
74841+#else
74842+static inline int is_module_text(unsigned long addr)
74843+{
74844+ return 0;
74845+}
74846+#endif
74847+#endif
74848+
74849 static inline int is_kernel_text(unsigned long addr)
74850 {
74851 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
74852@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
74853
74854 static inline int is_kernel(unsigned long addr)
74855 {
74856+
74857+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74858+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
74859+ return 1;
74860+
74861+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
74862+#else
74863 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
74864+#endif
74865+
74866 return 1;
74867 return in_gate_area_no_mm(addr);
74868 }
74869
74870 static int is_ksym_addr(unsigned long addr)
74871 {
74872+
74873+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74874+ if (is_module_text(addr))
74875+ return 0;
74876+#endif
74877+
74878 if (all_var)
74879 return is_kernel(addr);
74880
74881@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
74882
74883 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
74884 {
74885- iter->name[0] = '\0';
74886 iter->nameoff = get_symbol_offset(new_pos);
74887 iter->pos = new_pos;
74888 }
74889@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
74890 {
74891 struct kallsym_iter *iter = m->private;
74892
74893+#ifdef CONFIG_GRKERNSEC_HIDESYM
74894+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
74895+ return 0;
74896+#endif
74897+
74898 /* Some debugging symbols have no name. Ignore them. */
74899 if (!iter->name[0])
74900 return 0;
74901@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
74902 */
74903 type = iter->exported ? toupper(iter->type) :
74904 tolower(iter->type);
74905+
74906 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
74907 type, iter->name, iter->module_name);
74908 } else
74909@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
74910 struct kallsym_iter *iter;
74911 int ret;
74912
74913- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
74914+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
74915 if (!iter)
74916 return -ENOMEM;
74917 reset_iter(iter, 0);
74918diff --git a/kernel/kcmp.c b/kernel/kcmp.c
74919index e30ac0f..3528cac 100644
74920--- a/kernel/kcmp.c
74921+++ b/kernel/kcmp.c
74922@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
74923 struct task_struct *task1, *task2;
74924 int ret;
74925
74926+#ifdef CONFIG_GRKERNSEC
74927+ return -ENOSYS;
74928+#endif
74929+
74930 rcu_read_lock();
74931
74932 /*
74933diff --git a/kernel/kexec.c b/kernel/kexec.c
74934index 5e4bd78..00c5b91 100644
74935--- a/kernel/kexec.c
74936+++ b/kernel/kexec.c
74937@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
74938 unsigned long flags)
74939 {
74940 struct compat_kexec_segment in;
74941- struct kexec_segment out, __user *ksegments;
74942+ struct kexec_segment out;
74943+ struct kexec_segment __user *ksegments;
74944 unsigned long i, result;
74945
74946 /* Don't allow clients that don't understand the native
74947diff --git a/kernel/kmod.c b/kernel/kmod.c
74948index 0023a87..9c0c068 100644
74949--- a/kernel/kmod.c
74950+++ b/kernel/kmod.c
74951@@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
74952 kfree(info->argv);
74953 }
74954
74955-static int call_modprobe(char *module_name, int wait)
74956+static int call_modprobe(char *module_name, char *module_param, int wait)
74957 {
74958 static char *envp[] = {
74959 "HOME=/",
74960@@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
74961 NULL
74962 };
74963
74964- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
74965+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
74966 if (!argv)
74967 goto out;
74968
74969@@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
74970 argv[1] = "-q";
74971 argv[2] = "--";
74972 argv[3] = module_name; /* check free_modprobe_argv() */
74973- argv[4] = NULL;
74974+ argv[4] = module_param;
74975+ argv[5] = NULL;
74976
74977 return call_usermodehelper_fns(modprobe_path, argv, envp,
74978 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
74979@@ -120,9 +121,8 @@ out:
74980 * If module auto-loading support is disabled then this function
74981 * becomes a no-operation.
74982 */
74983-int __request_module(bool wait, const char *fmt, ...)
74984+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
74985 {
74986- va_list args;
74987 char module_name[MODULE_NAME_LEN];
74988 unsigned int max_modprobes;
74989 int ret;
74990@@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
74991 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
74992 static int kmod_loop_msg;
74993
74994- va_start(args, fmt);
74995- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
74996- va_end(args);
74997+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
74998 if (ret >= MODULE_NAME_LEN)
74999 return -ENAMETOOLONG;
75000
75001@@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
75002 if (ret)
75003 return ret;
75004
75005+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75006+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
75007+ /* hack to workaround consolekit/udisks stupidity */
75008+ read_lock(&tasklist_lock);
75009+ if (!strcmp(current->comm, "mount") &&
75010+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
75011+ read_unlock(&tasklist_lock);
75012+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
75013+ return -EPERM;
75014+ }
75015+ read_unlock(&tasklist_lock);
75016+ }
75017+#endif
75018+
75019 /* If modprobe needs a service that is in a module, we get a recursive
75020 * loop. Limit the number of running kmod threads to max_threads/2 or
75021 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
75022@@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
75023
75024 trace_module_request(module_name, wait, _RET_IP_);
75025
75026- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
75027+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
75028
75029 atomic_dec(&kmod_concurrent);
75030 return ret;
75031 }
75032+
75033+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
75034+{
75035+ va_list args;
75036+ int ret;
75037+
75038+ va_start(args, fmt);
75039+ ret = ____request_module(wait, module_param, fmt, args);
75040+ va_end(args);
75041+
75042+ return ret;
75043+}
75044+
75045+int __request_module(bool wait, const char *fmt, ...)
75046+{
75047+ va_list args;
75048+ int ret;
75049+
75050+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75051+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
75052+ char module_param[MODULE_NAME_LEN];
75053+
75054+ memset(module_param, 0, sizeof(module_param));
75055+
75056+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
75057+
75058+ va_start(args, fmt);
75059+ ret = ____request_module(wait, module_param, fmt, args);
75060+ va_end(args);
75061+
75062+ return ret;
75063+ }
75064+#endif
75065+
75066+ va_start(args, fmt);
75067+ ret = ____request_module(wait, NULL, fmt, args);
75068+ va_end(args);
75069+
75070+ return ret;
75071+}
75072+
75073 EXPORT_SYMBOL(__request_module);
75074 #endif /* CONFIG_MODULES */
75075
75076@@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
75077 *
75078 * Thus the __user pointer cast is valid here.
75079 */
75080- sys_wait4(pid, (int __user *)&ret, 0, NULL);
75081+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
75082
75083 /*
75084 * If ret is 0, either ____call_usermodehelper failed and the
75085@@ -635,7 +688,7 @@ EXPORT_SYMBOL(call_usermodehelper_fns);
75086 static int proc_cap_handler(struct ctl_table *table, int write,
75087 void __user *buffer, size_t *lenp, loff_t *ppos)
75088 {
75089- struct ctl_table t;
75090+ ctl_table_no_const t;
75091 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
75092 kernel_cap_t new_cap;
75093 int err, i;
75094diff --git a/kernel/kprobes.c b/kernel/kprobes.c
75095index 098f396..fe85ff1 100644
75096--- a/kernel/kprobes.c
75097+++ b/kernel/kprobes.c
75098@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
75099 * kernel image and loaded module images reside. This is required
75100 * so x86_64 can correctly handle the %rip-relative fixups.
75101 */
75102- kip->insns = module_alloc(PAGE_SIZE);
75103+ kip->insns = module_alloc_exec(PAGE_SIZE);
75104 if (!kip->insns) {
75105 kfree(kip);
75106 return NULL;
75107@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
75108 */
75109 if (!list_is_singular(&kip->list)) {
75110 list_del(&kip->list);
75111- module_free(NULL, kip->insns);
75112+ module_free_exec(NULL, kip->insns);
75113 kfree(kip);
75114 }
75115 return 1;
75116@@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
75117 {
75118 int i, err = 0;
75119 unsigned long offset = 0, size = 0;
75120- char *modname, namebuf[128];
75121+ char *modname, namebuf[KSYM_NAME_LEN];
75122 const char *symbol_name;
75123 void *addr;
75124 struct kprobe_blackpoint *kb;
75125@@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
75126 kprobe_type = "k";
75127
75128 if (sym)
75129- seq_printf(pi, "%p %s %s+0x%x %s ",
75130+ seq_printf(pi, "%pK %s %s+0x%x %s ",
75131 p->addr, kprobe_type, sym, offset,
75132 (modname ? modname : " "));
75133 else
75134- seq_printf(pi, "%p %s %p ",
75135+ seq_printf(pi, "%pK %s %pK ",
75136 p->addr, kprobe_type, p->addr);
75137
75138 if (!pp)
75139@@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
75140 const char *sym = NULL;
75141 unsigned int i = *(loff_t *) v;
75142 unsigned long offset = 0;
75143- char *modname, namebuf[128];
75144+ char *modname, namebuf[KSYM_NAME_LEN];
75145
75146 head = &kprobe_table[i];
75147 preempt_disable();
75148diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
75149index 6ada93c..dce7d5d 100644
75150--- a/kernel/ksysfs.c
75151+++ b/kernel/ksysfs.c
75152@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
75153 {
75154 if (count+1 > UEVENT_HELPER_PATH_LEN)
75155 return -ENOENT;
75156+ if (!capable(CAP_SYS_ADMIN))
75157+ return -EPERM;
75158 memcpy(uevent_helper, buf, count);
75159 uevent_helper[count] = '\0';
75160 if (count && uevent_helper[count-1] == '\n')
75161@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
75162 return count;
75163 }
75164
75165-static struct bin_attribute notes_attr = {
75166+static bin_attribute_no_const notes_attr __read_only = {
75167 .attr = {
75168 .name = "notes",
75169 .mode = S_IRUGO,
75170diff --git a/kernel/lockdep.c b/kernel/lockdep.c
75171index 7981e5b..7f2105c 100644
75172--- a/kernel/lockdep.c
75173+++ b/kernel/lockdep.c
75174@@ -590,6 +590,10 @@ static int static_obj(void *obj)
75175 end = (unsigned long) &_end,
75176 addr = (unsigned long) obj;
75177
75178+#ifdef CONFIG_PAX_KERNEXEC
75179+ start = ktla_ktva(start);
75180+#endif
75181+
75182 /*
75183 * static variable?
75184 */
75185@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
75186 if (!static_obj(lock->key)) {
75187 debug_locks_off();
75188 printk("INFO: trying to register non-static key.\n");
75189+ printk("lock:%pS key:%pS.\n", lock, lock->key);
75190 printk("the code is fine but needs lockdep annotation.\n");
75191 printk("turning off the locking correctness validator.\n");
75192 dump_stack();
75193@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
75194 if (!class)
75195 return 0;
75196 }
75197- atomic_inc((atomic_t *)&class->ops);
75198+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
75199 if (very_verbose(class)) {
75200 printk("\nacquire class [%p] %s", class->key, class->name);
75201 if (class->name_version > 1)
75202diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
75203index b2c71c5..7b88d63 100644
75204--- a/kernel/lockdep_proc.c
75205+++ b/kernel/lockdep_proc.c
75206@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
75207 return 0;
75208 }
75209
75210- seq_printf(m, "%p", class->key);
75211+ seq_printf(m, "%pK", class->key);
75212 #ifdef CONFIG_DEBUG_LOCKDEP
75213 seq_printf(m, " OPS:%8ld", class->ops);
75214 #endif
75215@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
75216
75217 list_for_each_entry(entry, &class->locks_after, entry) {
75218 if (entry->distance == 1) {
75219- seq_printf(m, " -> [%p] ", entry->class->key);
75220+ seq_printf(m, " -> [%pK] ", entry->class->key);
75221 print_name(m, entry->class);
75222 seq_puts(m, "\n");
75223 }
75224@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
75225 if (!class->key)
75226 continue;
75227
75228- seq_printf(m, "[%p] ", class->key);
75229+ seq_printf(m, "[%pK] ", class->key);
75230 print_name(m, class);
75231 seq_puts(m, "\n");
75232 }
75233@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
75234 if (!i)
75235 seq_line(m, '-', 40-namelen, namelen);
75236
75237- snprintf(ip, sizeof(ip), "[<%p>]",
75238+ snprintf(ip, sizeof(ip), "[<%pK>]",
75239 (void *)class->contention_point[i]);
75240 seq_printf(m, "%40s %14lu %29s %pS\n",
75241 name, stats->contention_point[i],
75242@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
75243 if (!i)
75244 seq_line(m, '-', 40-namelen, namelen);
75245
75246- snprintf(ip, sizeof(ip), "[<%p>]",
75247+ snprintf(ip, sizeof(ip), "[<%pK>]",
75248 (void *)class->contending_point[i]);
75249 seq_printf(m, "%40s %14lu %29s %pS\n",
75250 name, stats->contending_point[i],
75251diff --git a/kernel/module.c b/kernel/module.c
75252index eab0827..f488603 100644
75253--- a/kernel/module.c
75254+++ b/kernel/module.c
75255@@ -61,6 +61,7 @@
75256 #include <linux/pfn.h>
75257 #include <linux/bsearch.h>
75258 #include <linux/fips.h>
75259+#include <linux/grsecurity.h>
75260 #include <uapi/linux/module.h>
75261 #include "module-internal.h"
75262
75263@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
75264
75265 /* Bounds of module allocation, for speeding __module_address.
75266 * Protected by module_mutex. */
75267-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
75268+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
75269+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
75270
75271 int register_module_notifier(struct notifier_block * nb)
75272 {
75273@@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
75274 return true;
75275
75276 list_for_each_entry_rcu(mod, &modules, list) {
75277- struct symsearch arr[] = {
75278+ struct symsearch modarr[] = {
75279 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
75280 NOT_GPL_ONLY, false },
75281 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
75282@@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
75283 if (mod->state == MODULE_STATE_UNFORMED)
75284 continue;
75285
75286- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
75287+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
75288 return true;
75289 }
75290 return false;
75291@@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
75292 static int percpu_modalloc(struct module *mod,
75293 unsigned long size, unsigned long align)
75294 {
75295- if (align > PAGE_SIZE) {
75296+ if (align-1 >= PAGE_SIZE) {
75297 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
75298 mod->name, align, PAGE_SIZE);
75299 align = PAGE_SIZE;
75300@@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
75301 static ssize_t show_coresize(struct module_attribute *mattr,
75302 struct module_kobject *mk, char *buffer)
75303 {
75304- return sprintf(buffer, "%u\n", mk->mod->core_size);
75305+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
75306 }
75307
75308 static struct module_attribute modinfo_coresize =
75309@@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
75310 static ssize_t show_initsize(struct module_attribute *mattr,
75311 struct module_kobject *mk, char *buffer)
75312 {
75313- return sprintf(buffer, "%u\n", mk->mod->init_size);
75314+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
75315 }
75316
75317 static struct module_attribute modinfo_initsize =
75318@@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
75319 */
75320 #ifdef CONFIG_SYSFS
75321
75322-#ifdef CONFIG_KALLSYMS
75323+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
75324 static inline bool sect_empty(const Elf_Shdr *sect)
75325 {
75326 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
75327@@ -1451,7 +1453,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
75328 {
75329 unsigned int notes, loaded, i;
75330 struct module_notes_attrs *notes_attrs;
75331- struct bin_attribute *nattr;
75332+ bin_attribute_no_const *nattr;
75333
75334 /* failed to create section attributes, so can't create notes */
75335 if (!mod->sect_attrs)
75336@@ -1563,7 +1565,7 @@ static void del_usage_links(struct module *mod)
75337 static int module_add_modinfo_attrs(struct module *mod)
75338 {
75339 struct module_attribute *attr;
75340- struct module_attribute *temp_attr;
75341+ module_attribute_no_const *temp_attr;
75342 int error = 0;
75343 int i;
75344
75345@@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
75346
75347 static void unset_module_core_ro_nx(struct module *mod)
75348 {
75349- set_page_attributes(mod->module_core + mod->core_text_size,
75350- mod->module_core + mod->core_size,
75351+ set_page_attributes(mod->module_core_rw,
75352+ mod->module_core_rw + mod->core_size_rw,
75353 set_memory_x);
75354- set_page_attributes(mod->module_core,
75355- mod->module_core + mod->core_ro_size,
75356+ set_page_attributes(mod->module_core_rx,
75357+ mod->module_core_rx + mod->core_size_rx,
75358 set_memory_rw);
75359 }
75360
75361 static void unset_module_init_ro_nx(struct module *mod)
75362 {
75363- set_page_attributes(mod->module_init + mod->init_text_size,
75364- mod->module_init + mod->init_size,
75365+ set_page_attributes(mod->module_init_rw,
75366+ mod->module_init_rw + mod->init_size_rw,
75367 set_memory_x);
75368- set_page_attributes(mod->module_init,
75369- mod->module_init + mod->init_ro_size,
75370+ set_page_attributes(mod->module_init_rx,
75371+ mod->module_init_rx + mod->init_size_rx,
75372 set_memory_rw);
75373 }
75374
75375@@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
75376 list_for_each_entry_rcu(mod, &modules, list) {
75377 if (mod->state == MODULE_STATE_UNFORMED)
75378 continue;
75379- if ((mod->module_core) && (mod->core_text_size)) {
75380- set_page_attributes(mod->module_core,
75381- mod->module_core + mod->core_text_size,
75382+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
75383+ set_page_attributes(mod->module_core_rx,
75384+ mod->module_core_rx + mod->core_size_rx,
75385 set_memory_rw);
75386 }
75387- if ((mod->module_init) && (mod->init_text_size)) {
75388- set_page_attributes(mod->module_init,
75389- mod->module_init + mod->init_text_size,
75390+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
75391+ set_page_attributes(mod->module_init_rx,
75392+ mod->module_init_rx + mod->init_size_rx,
75393 set_memory_rw);
75394 }
75395 }
75396@@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
75397 list_for_each_entry_rcu(mod, &modules, list) {
75398 if (mod->state == MODULE_STATE_UNFORMED)
75399 continue;
75400- if ((mod->module_core) && (mod->core_text_size)) {
75401- set_page_attributes(mod->module_core,
75402- mod->module_core + mod->core_text_size,
75403+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
75404+ set_page_attributes(mod->module_core_rx,
75405+ mod->module_core_rx + mod->core_size_rx,
75406 set_memory_ro);
75407 }
75408- if ((mod->module_init) && (mod->init_text_size)) {
75409- set_page_attributes(mod->module_init,
75410- mod->module_init + mod->init_text_size,
75411+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
75412+ set_page_attributes(mod->module_init_rx,
75413+ mod->module_init_rx + mod->init_size_rx,
75414 set_memory_ro);
75415 }
75416 }
75417@@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
75418
75419 /* This may be NULL, but that's OK */
75420 unset_module_init_ro_nx(mod);
75421- module_free(mod, mod->module_init);
75422+ module_free(mod, mod->module_init_rw);
75423+ module_free_exec(mod, mod->module_init_rx);
75424 kfree(mod->args);
75425 percpu_modfree(mod);
75426
75427 /* Free lock-classes: */
75428- lockdep_free_key_range(mod->module_core, mod->core_size);
75429+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
75430+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
75431
75432 /* Finally, free the core (containing the module structure) */
75433 unset_module_core_ro_nx(mod);
75434- module_free(mod, mod->module_core);
75435+ module_free_exec(mod, mod->module_core_rx);
75436+ module_free(mod, mod->module_core_rw);
75437
75438 #ifdef CONFIG_MPU
75439 update_protections(current->mm);
75440@@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
75441 int ret = 0;
75442 const struct kernel_symbol *ksym;
75443
75444+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75445+ int is_fs_load = 0;
75446+ int register_filesystem_found = 0;
75447+ char *p;
75448+
75449+ p = strstr(mod->args, "grsec_modharden_fs");
75450+ if (p) {
75451+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
75452+ /* copy \0 as well */
75453+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
75454+ is_fs_load = 1;
75455+ }
75456+#endif
75457+
75458 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
75459 const char *name = info->strtab + sym[i].st_name;
75460
75461+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75462+ /* it's a real shame this will never get ripped and copied
75463+ upstream! ;(
75464+ */
75465+ if (is_fs_load && !strcmp(name, "register_filesystem"))
75466+ register_filesystem_found = 1;
75467+#endif
75468+
75469 switch (sym[i].st_shndx) {
75470 case SHN_COMMON:
75471 /* We compiled with -fno-common. These are not
75472@@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
75473 ksym = resolve_symbol_wait(mod, info, name);
75474 /* Ok if resolved. */
75475 if (ksym && !IS_ERR(ksym)) {
75476+ pax_open_kernel();
75477 sym[i].st_value = ksym->value;
75478+ pax_close_kernel();
75479 break;
75480 }
75481
75482@@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
75483 secbase = (unsigned long)mod_percpu(mod);
75484 else
75485 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
75486+ pax_open_kernel();
75487 sym[i].st_value += secbase;
75488+ pax_close_kernel();
75489 break;
75490 }
75491 }
75492
75493+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75494+ if (is_fs_load && !register_filesystem_found) {
75495+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
75496+ ret = -EPERM;
75497+ }
75498+#endif
75499+
75500 return ret;
75501 }
75502
75503@@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
75504 || s->sh_entsize != ~0UL
75505 || strstarts(sname, ".init"))
75506 continue;
75507- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
75508+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
75509+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
75510+ else
75511+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
75512 pr_debug("\t%s\n", sname);
75513 }
75514- switch (m) {
75515- case 0: /* executable */
75516- mod->core_size = debug_align(mod->core_size);
75517- mod->core_text_size = mod->core_size;
75518- break;
75519- case 1: /* RO: text and ro-data */
75520- mod->core_size = debug_align(mod->core_size);
75521- mod->core_ro_size = mod->core_size;
75522- break;
75523- case 3: /* whole core */
75524- mod->core_size = debug_align(mod->core_size);
75525- break;
75526- }
75527 }
75528
75529 pr_debug("Init section allocation order:\n");
75530@@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
75531 || s->sh_entsize != ~0UL
75532 || !strstarts(sname, ".init"))
75533 continue;
75534- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
75535- | INIT_OFFSET_MASK);
75536+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
75537+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
75538+ else
75539+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
75540+ s->sh_entsize |= INIT_OFFSET_MASK;
75541 pr_debug("\t%s\n", sname);
75542 }
75543- switch (m) {
75544- case 0: /* executable */
75545- mod->init_size = debug_align(mod->init_size);
75546- mod->init_text_size = mod->init_size;
75547- break;
75548- case 1: /* RO: text and ro-data */
75549- mod->init_size = debug_align(mod->init_size);
75550- mod->init_ro_size = mod->init_size;
75551- break;
75552- case 3: /* whole init */
75553- mod->init_size = debug_align(mod->init_size);
75554- break;
75555- }
75556 }
75557 }
75558
75559@@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
75560
75561 /* Put symbol section at end of init part of module. */
75562 symsect->sh_flags |= SHF_ALLOC;
75563- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
75564+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
75565 info->index.sym) | INIT_OFFSET_MASK;
75566 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
75567
75568@@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
75569 }
75570
75571 /* Append room for core symbols at end of core part. */
75572- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
75573- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
75574- mod->core_size += strtab_size;
75575+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
75576+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
75577+ mod->core_size_rx += strtab_size;
75578
75579 /* Put string table section at end of init part of module. */
75580 strsect->sh_flags |= SHF_ALLOC;
75581- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
75582+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
75583 info->index.str) | INIT_OFFSET_MASK;
75584 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
75585 }
75586@@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
75587 /* Make sure we get permanent strtab: don't use info->strtab. */
75588 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
75589
75590+ pax_open_kernel();
75591+
75592 /* Set types up while we still have access to sections. */
75593 for (i = 0; i < mod->num_symtab; i++)
75594 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
75595
75596- mod->core_symtab = dst = mod->module_core + info->symoffs;
75597- mod->core_strtab = s = mod->module_core + info->stroffs;
75598+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
75599+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
75600 src = mod->symtab;
75601 for (ndst = i = 0; i < mod->num_symtab; i++) {
75602 if (i == 0 ||
75603@@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
75604 }
75605 }
75606 mod->core_num_syms = ndst;
75607+
75608+ pax_close_kernel();
75609 }
75610 #else
75611 static inline void layout_symtab(struct module *mod, struct load_info *info)
75612@@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
75613 return vmalloc_exec(size);
75614 }
75615
75616-static void *module_alloc_update_bounds(unsigned long size)
75617+static void *module_alloc_update_bounds_rw(unsigned long size)
75618 {
75619 void *ret = module_alloc(size);
75620
75621 if (ret) {
75622 mutex_lock(&module_mutex);
75623 /* Update module bounds. */
75624- if ((unsigned long)ret < module_addr_min)
75625- module_addr_min = (unsigned long)ret;
75626- if ((unsigned long)ret + size > module_addr_max)
75627- module_addr_max = (unsigned long)ret + size;
75628+ if ((unsigned long)ret < module_addr_min_rw)
75629+ module_addr_min_rw = (unsigned long)ret;
75630+ if ((unsigned long)ret + size > module_addr_max_rw)
75631+ module_addr_max_rw = (unsigned long)ret + size;
75632+ mutex_unlock(&module_mutex);
75633+ }
75634+ return ret;
75635+}
75636+
75637+static void *module_alloc_update_bounds_rx(unsigned long size)
75638+{
75639+ void *ret = module_alloc_exec(size);
75640+
75641+ if (ret) {
75642+ mutex_lock(&module_mutex);
75643+ /* Update module bounds. */
75644+ if ((unsigned long)ret < module_addr_min_rx)
75645+ module_addr_min_rx = (unsigned long)ret;
75646+ if ((unsigned long)ret + size > module_addr_max_rx)
75647+ module_addr_max_rx = (unsigned long)ret + size;
75648 mutex_unlock(&module_mutex);
75649 }
75650 return ret;
75651@@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
75652 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
75653 {
75654 const char *modmagic = get_modinfo(info, "vermagic");
75655+ const char *license = get_modinfo(info, "license");
75656 int err;
75657
75658+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
75659+ if (!license || !license_is_gpl_compatible(license))
75660+ return -ENOEXEC;
75661+#endif
75662+
75663 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
75664 modmagic = NULL;
75665
75666@@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
75667 }
75668
75669 /* Set up license info based on the info section */
75670- set_license(mod, get_modinfo(info, "license"));
75671+ set_license(mod, license);
75672
75673 return 0;
75674 }
75675@@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
75676 void *ptr;
75677
75678 /* Do the allocs. */
75679- ptr = module_alloc_update_bounds(mod->core_size);
75680+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
75681 /*
75682 * The pointer to this block is stored in the module structure
75683 * which is inside the block. Just mark it as not being a
75684@@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
75685 if (!ptr)
75686 return -ENOMEM;
75687
75688- memset(ptr, 0, mod->core_size);
75689- mod->module_core = ptr;
75690+ memset(ptr, 0, mod->core_size_rw);
75691+ mod->module_core_rw = ptr;
75692
75693- if (mod->init_size) {
75694- ptr = module_alloc_update_bounds(mod->init_size);
75695+ if (mod->init_size_rw) {
75696+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
75697 /*
75698 * The pointer to this block is stored in the module structure
75699 * which is inside the block. This block doesn't need to be
75700@@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
75701 */
75702 kmemleak_ignore(ptr);
75703 if (!ptr) {
75704- module_free(mod, mod->module_core);
75705+ module_free(mod, mod->module_core_rw);
75706 return -ENOMEM;
75707 }
75708- memset(ptr, 0, mod->init_size);
75709- mod->module_init = ptr;
75710+ memset(ptr, 0, mod->init_size_rw);
75711+ mod->module_init_rw = ptr;
75712 } else
75713- mod->module_init = NULL;
75714+ mod->module_init_rw = NULL;
75715+
75716+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
75717+ kmemleak_not_leak(ptr);
75718+ if (!ptr) {
75719+ if (mod->module_init_rw)
75720+ module_free(mod, mod->module_init_rw);
75721+ module_free(mod, mod->module_core_rw);
75722+ return -ENOMEM;
75723+ }
75724+
75725+ pax_open_kernel();
75726+ memset(ptr, 0, mod->core_size_rx);
75727+ pax_close_kernel();
75728+ mod->module_core_rx = ptr;
75729+
75730+ if (mod->init_size_rx) {
75731+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
75732+ kmemleak_ignore(ptr);
75733+ if (!ptr && mod->init_size_rx) {
75734+ module_free_exec(mod, mod->module_core_rx);
75735+ if (mod->module_init_rw)
75736+ module_free(mod, mod->module_init_rw);
75737+ module_free(mod, mod->module_core_rw);
75738+ return -ENOMEM;
75739+ }
75740+
75741+ pax_open_kernel();
75742+ memset(ptr, 0, mod->init_size_rx);
75743+ pax_close_kernel();
75744+ mod->module_init_rx = ptr;
75745+ } else
75746+ mod->module_init_rx = NULL;
75747
75748 /* Transfer each section which specifies SHF_ALLOC */
75749 pr_debug("final section addresses:\n");
75750@@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
75751 if (!(shdr->sh_flags & SHF_ALLOC))
75752 continue;
75753
75754- if (shdr->sh_entsize & INIT_OFFSET_MASK)
75755- dest = mod->module_init
75756- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
75757- else
75758- dest = mod->module_core + shdr->sh_entsize;
75759+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
75760+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
75761+ dest = mod->module_init_rw
75762+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
75763+ else
75764+ dest = mod->module_init_rx
75765+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
75766+ } else {
75767+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
75768+ dest = mod->module_core_rw + shdr->sh_entsize;
75769+ else
75770+ dest = mod->module_core_rx + shdr->sh_entsize;
75771+ }
75772+
75773+ if (shdr->sh_type != SHT_NOBITS) {
75774+
75775+#ifdef CONFIG_PAX_KERNEXEC
75776+#ifdef CONFIG_X86_64
75777+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
75778+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
75779+#endif
75780+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
75781+ pax_open_kernel();
75782+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
75783+ pax_close_kernel();
75784+ } else
75785+#endif
75786
75787- if (shdr->sh_type != SHT_NOBITS)
75788 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
75789+ }
75790 /* Update sh_addr to point to copy in image. */
75791- shdr->sh_addr = (unsigned long)dest;
75792+
75793+#ifdef CONFIG_PAX_KERNEXEC
75794+ if (shdr->sh_flags & SHF_EXECINSTR)
75795+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
75796+ else
75797+#endif
75798+
75799+ shdr->sh_addr = (unsigned long)dest;
75800 pr_debug("\t0x%lx %s\n",
75801 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
75802 }
75803@@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
75804 * Do it before processing of module parameters, so the module
75805 * can provide parameter accessor functions of its own.
75806 */
75807- if (mod->module_init)
75808- flush_icache_range((unsigned long)mod->module_init,
75809- (unsigned long)mod->module_init
75810- + mod->init_size);
75811- flush_icache_range((unsigned long)mod->module_core,
75812- (unsigned long)mod->module_core + mod->core_size);
75813+ if (mod->module_init_rx)
75814+ flush_icache_range((unsigned long)mod->module_init_rx,
75815+ (unsigned long)mod->module_init_rx
75816+ + mod->init_size_rx);
75817+ flush_icache_range((unsigned long)mod->module_core_rx,
75818+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
75819
75820 set_fs(old_fs);
75821 }
75822@@ -2983,8 +3088,10 @@ out:
75823 static void module_deallocate(struct module *mod, struct load_info *info)
75824 {
75825 percpu_modfree(mod);
75826- module_free(mod, mod->module_init);
75827- module_free(mod, mod->module_core);
75828+ module_free_exec(mod, mod->module_init_rx);
75829+ module_free_exec(mod, mod->module_core_rx);
75830+ module_free(mod, mod->module_init_rw);
75831+ module_free(mod, mod->module_core_rw);
75832 }
75833
75834 int __weak module_finalize(const Elf_Ehdr *hdr,
75835@@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
75836 static int post_relocation(struct module *mod, const struct load_info *info)
75837 {
75838 /* Sort exception table now relocations are done. */
75839+ pax_open_kernel();
75840 sort_extable(mod->extable, mod->extable + mod->num_exentries);
75841+ pax_close_kernel();
75842
75843 /* Copy relocated percpu area over. */
75844 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
75845@@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
75846 MODULE_STATE_COMING, mod);
75847
75848 /* Set RO and NX regions for core */
75849- set_section_ro_nx(mod->module_core,
75850- mod->core_text_size,
75851- mod->core_ro_size,
75852- mod->core_size);
75853+ set_section_ro_nx(mod->module_core_rx,
75854+ mod->core_size_rx,
75855+ mod->core_size_rx,
75856+ mod->core_size_rx);
75857
75858 /* Set RO and NX regions for init */
75859- set_section_ro_nx(mod->module_init,
75860- mod->init_text_size,
75861- mod->init_ro_size,
75862- mod->init_size);
75863+ set_section_ro_nx(mod->module_init_rx,
75864+ mod->init_size_rx,
75865+ mod->init_size_rx,
75866+ mod->init_size_rx);
75867
75868 do_mod_ctors(mod);
75869 /* Start the module */
75870@@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
75871 mod->strtab = mod->core_strtab;
75872 #endif
75873 unset_module_init_ro_nx(mod);
75874- module_free(mod, mod->module_init);
75875- mod->module_init = NULL;
75876- mod->init_size = 0;
75877- mod->init_ro_size = 0;
75878- mod->init_text_size = 0;
75879+ module_free(mod, mod->module_init_rw);
75880+ module_free_exec(mod, mod->module_init_rx);
75881+ mod->module_init_rw = NULL;
75882+ mod->module_init_rx = NULL;
75883+ mod->init_size_rw = 0;
75884+ mod->init_size_rx = 0;
75885 mutex_unlock(&module_mutex);
75886 wake_up_all(&module_wq);
75887
75888@@ -3209,9 +3319,38 @@ again:
75889 if (err)
75890 goto free_unload;
75891
75892+ /* Now copy in args */
75893+ mod->args = strndup_user(uargs, ~0UL >> 1);
75894+ if (IS_ERR(mod->args)) {
75895+ err = PTR_ERR(mod->args);
75896+ goto free_unload;
75897+ }
75898+
75899 /* Set up MODINFO_ATTR fields */
75900 setup_modinfo(mod, info);
75901
75902+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75903+ {
75904+ char *p, *p2;
75905+
75906+ if (strstr(mod->args, "grsec_modharden_netdev")) {
75907+ 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);
75908+ err = -EPERM;
75909+ goto free_modinfo;
75910+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
75911+ p += sizeof("grsec_modharden_normal") - 1;
75912+ p2 = strstr(p, "_");
75913+ if (p2) {
75914+ *p2 = '\0';
75915+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
75916+ *p2 = '_';
75917+ }
75918+ err = -EPERM;
75919+ goto free_modinfo;
75920+ }
75921+ }
75922+#endif
75923+
75924 /* Fix up syms, so that st_value is a pointer to location. */
75925 err = simplify_symbols(mod, info);
75926 if (err < 0)
75927@@ -3227,13 +3366,6 @@ again:
75928
75929 flush_module_icache(mod);
75930
75931- /* Now copy in args */
75932- mod->args = strndup_user(uargs, ~0UL >> 1);
75933- if (IS_ERR(mod->args)) {
75934- err = PTR_ERR(mod->args);
75935- goto free_arch_cleanup;
75936- }
75937-
75938 dynamic_debug_setup(info->debug, info->num_debug);
75939
75940 mutex_lock(&module_mutex);
75941@@ -3278,11 +3410,10 @@ again:
75942 mutex_unlock(&module_mutex);
75943 dynamic_debug_remove(info->debug);
75944 synchronize_sched();
75945- kfree(mod->args);
75946- free_arch_cleanup:
75947 module_arch_cleanup(mod);
75948 free_modinfo:
75949 free_modinfo(mod);
75950+ kfree(mod->args);
75951 free_unload:
75952 module_unload_free(mod);
75953 unlink_mod:
75954@@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
75955 unsigned long nextval;
75956
75957 /* At worse, next value is at end of module */
75958- if (within_module_init(addr, mod))
75959- nextval = (unsigned long)mod->module_init+mod->init_text_size;
75960+ if (within_module_init_rx(addr, mod))
75961+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
75962+ else if (within_module_init_rw(addr, mod))
75963+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
75964+ else if (within_module_core_rx(addr, mod))
75965+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
75966+ else if (within_module_core_rw(addr, mod))
75967+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
75968 else
75969- nextval = (unsigned long)mod->module_core+mod->core_text_size;
75970+ return NULL;
75971
75972 /* Scan for closest preceding symbol, and next symbol. (ELF
75973 starts real symbols at 1). */
75974@@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
75975 return 0;
75976
75977 seq_printf(m, "%s %u",
75978- mod->name, mod->init_size + mod->core_size);
75979+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
75980 print_unload_info(m, mod);
75981
75982 /* Informative for users. */
75983@@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
75984 mod->state == MODULE_STATE_COMING ? "Loading":
75985 "Live");
75986 /* Used by oprofile and other similar tools. */
75987- seq_printf(m, " 0x%pK", mod->module_core);
75988+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
75989
75990 /* Taints info */
75991 if (mod->taints)
75992@@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
75993
75994 static int __init proc_modules_init(void)
75995 {
75996+#ifndef CONFIG_GRKERNSEC_HIDESYM
75997+#ifdef CONFIG_GRKERNSEC_PROC_USER
75998+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
75999+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76000+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
76001+#else
76002 proc_create("modules", 0, NULL, &proc_modules_operations);
76003+#endif
76004+#else
76005+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
76006+#endif
76007 return 0;
76008 }
76009 module_init(proc_modules_init);
76010@@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
76011 {
76012 struct module *mod;
76013
76014- if (addr < module_addr_min || addr > module_addr_max)
76015+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
76016+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
76017 return NULL;
76018
76019 list_for_each_entry_rcu(mod, &modules, list) {
76020 if (mod->state == MODULE_STATE_UNFORMED)
76021 continue;
76022- if (within_module_core(addr, mod)
76023- || within_module_init(addr, mod))
76024+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
76025 return mod;
76026 }
76027 return NULL;
76028@@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
76029 */
76030 struct module *__module_text_address(unsigned long addr)
76031 {
76032- struct module *mod = __module_address(addr);
76033+ struct module *mod;
76034+
76035+#ifdef CONFIG_X86_32
76036+ addr = ktla_ktva(addr);
76037+#endif
76038+
76039+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
76040+ return NULL;
76041+
76042+ mod = __module_address(addr);
76043+
76044 if (mod) {
76045 /* Make sure it's within the text section. */
76046- if (!within(addr, mod->module_init, mod->init_text_size)
76047- && !within(addr, mod->module_core, mod->core_text_size))
76048+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
76049 mod = NULL;
76050 }
76051 return mod;
76052diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
76053index 7e3443f..b2a1e6b 100644
76054--- a/kernel/mutex-debug.c
76055+++ b/kernel/mutex-debug.c
76056@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
76057 }
76058
76059 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
76060- struct thread_info *ti)
76061+ struct task_struct *task)
76062 {
76063 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
76064
76065 /* Mark the current thread as blocked on the lock: */
76066- ti->task->blocked_on = waiter;
76067+ task->blocked_on = waiter;
76068 }
76069
76070 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
76071- struct thread_info *ti)
76072+ struct task_struct *task)
76073 {
76074 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
76075- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
76076- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
76077- ti->task->blocked_on = NULL;
76078+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
76079+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
76080+ task->blocked_on = NULL;
76081
76082 list_del_init(&waiter->list);
76083 waiter->task = NULL;
76084diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
76085index 0799fd3..d06ae3b 100644
76086--- a/kernel/mutex-debug.h
76087+++ b/kernel/mutex-debug.h
76088@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
76089 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
76090 extern void debug_mutex_add_waiter(struct mutex *lock,
76091 struct mutex_waiter *waiter,
76092- struct thread_info *ti);
76093+ struct task_struct *task);
76094 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
76095- struct thread_info *ti);
76096+ struct task_struct *task);
76097 extern void debug_mutex_unlock(struct mutex *lock);
76098 extern void debug_mutex_init(struct mutex *lock, const char *name,
76099 struct lock_class_key *key);
76100diff --git a/kernel/mutex.c b/kernel/mutex.c
76101index a307cc9..27fd2e9 100644
76102--- a/kernel/mutex.c
76103+++ b/kernel/mutex.c
76104@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
76105 spin_lock_mutex(&lock->wait_lock, flags);
76106
76107 debug_mutex_lock_common(lock, &waiter);
76108- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
76109+ debug_mutex_add_waiter(lock, &waiter, task);
76110
76111 /* add waiting tasks to the end of the waitqueue (FIFO): */
76112 list_add_tail(&waiter.list, &lock->wait_list);
76113@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
76114 * TASK_UNINTERRUPTIBLE case.)
76115 */
76116 if (unlikely(signal_pending_state(state, task))) {
76117- mutex_remove_waiter(lock, &waiter,
76118- task_thread_info(task));
76119+ mutex_remove_waiter(lock, &waiter, task);
76120 mutex_release(&lock->dep_map, 1, ip);
76121 spin_unlock_mutex(&lock->wait_lock, flags);
76122
76123@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
76124 done:
76125 lock_acquired(&lock->dep_map, ip);
76126 /* got the lock - rejoice! */
76127- mutex_remove_waiter(lock, &waiter, current_thread_info());
76128+ mutex_remove_waiter(lock, &waiter, task);
76129 mutex_set_owner(lock);
76130
76131 /* set it to 0 if there are no waiters left: */
76132diff --git a/kernel/notifier.c b/kernel/notifier.c
76133index 2d5cc4c..d9ea600 100644
76134--- a/kernel/notifier.c
76135+++ b/kernel/notifier.c
76136@@ -5,6 +5,7 @@
76137 #include <linux/rcupdate.h>
76138 #include <linux/vmalloc.h>
76139 #include <linux/reboot.h>
76140+#include <linux/mm.h>
76141
76142 /*
76143 * Notifier list for kernel code which wants to be called
76144@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
76145 while ((*nl) != NULL) {
76146 if (n->priority > (*nl)->priority)
76147 break;
76148- nl = &((*nl)->next);
76149+ nl = (struct notifier_block **)&((*nl)->next);
76150 }
76151- n->next = *nl;
76152+ pax_open_kernel();
76153+ *(const void **)&n->next = *nl;
76154 rcu_assign_pointer(*nl, n);
76155+ pax_close_kernel();
76156 return 0;
76157 }
76158
76159@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
76160 return 0;
76161 if (n->priority > (*nl)->priority)
76162 break;
76163- nl = &((*nl)->next);
76164+ nl = (struct notifier_block **)&((*nl)->next);
76165 }
76166- n->next = *nl;
76167+ pax_open_kernel();
76168+ *(const void **)&n->next = *nl;
76169 rcu_assign_pointer(*nl, n);
76170+ pax_close_kernel();
76171 return 0;
76172 }
76173
76174@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
76175 {
76176 while ((*nl) != NULL) {
76177 if ((*nl) == n) {
76178+ pax_open_kernel();
76179 rcu_assign_pointer(*nl, n->next);
76180+ pax_close_kernel();
76181 return 0;
76182 }
76183- nl = &((*nl)->next);
76184+ nl = (struct notifier_block **)&((*nl)->next);
76185 }
76186 return -ENOENT;
76187 }
76188diff --git a/kernel/panic.c b/kernel/panic.c
76189index e1b2822..5edc1d9 100644
76190--- a/kernel/panic.c
76191+++ b/kernel/panic.c
76192@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
76193 const char *board;
76194
76195 printk(KERN_WARNING "------------[ cut here ]------------\n");
76196- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
76197+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
76198 board = dmi_get_system_info(DMI_PRODUCT_NAME);
76199 if (board)
76200 printk(KERN_WARNING "Hardware name: %s\n", board);
76201@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
76202 */
76203 void __stack_chk_fail(void)
76204 {
76205- panic("stack-protector: Kernel stack is corrupted in: %p\n",
76206+ dump_stack();
76207+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
76208 __builtin_return_address(0));
76209 }
76210 EXPORT_SYMBOL(__stack_chk_fail);
76211diff --git a/kernel/pid.c b/kernel/pid.c
76212index f2c6a68..4922d97 100644
76213--- a/kernel/pid.c
76214+++ b/kernel/pid.c
76215@@ -33,6 +33,7 @@
76216 #include <linux/rculist.h>
76217 #include <linux/bootmem.h>
76218 #include <linux/hash.h>
76219+#include <linux/security.h>
76220 #include <linux/pid_namespace.h>
76221 #include <linux/init_task.h>
76222 #include <linux/syscalls.h>
76223@@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
76224
76225 int pid_max = PID_MAX_DEFAULT;
76226
76227-#define RESERVED_PIDS 300
76228+#define RESERVED_PIDS 500
76229
76230 int pid_max_min = RESERVED_PIDS + 1;
76231 int pid_max_max = PID_MAX_LIMIT;
76232@@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
76233 */
76234 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
76235 {
76236+ struct task_struct *task;
76237+
76238 rcu_lockdep_assert(rcu_read_lock_held(),
76239 "find_task_by_pid_ns() needs rcu_read_lock()"
76240 " protection");
76241- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
76242+
76243+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
76244+
76245+ if (gr_pid_is_chrooted(task))
76246+ return NULL;
76247+
76248+ return task;
76249 }
76250
76251 struct task_struct *find_task_by_vpid(pid_t vnr)
76252@@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
76253 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
76254 }
76255
76256+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
76257+{
76258+ rcu_lockdep_assert(rcu_read_lock_held(),
76259+ "find_task_by_pid_ns() needs rcu_read_lock()"
76260+ " protection");
76261+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
76262+}
76263+
76264 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
76265 {
76266 struct pid *pid;
76267diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
76268index c1c3dc1..bbeaf31 100644
76269--- a/kernel/pid_namespace.c
76270+++ b/kernel/pid_namespace.c
76271@@ -248,7 +248,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
76272 void __user *buffer, size_t *lenp, loff_t *ppos)
76273 {
76274 struct pid_namespace *pid_ns = task_active_pid_ns(current);
76275- struct ctl_table tmp = *table;
76276+ ctl_table_no_const tmp = *table;
76277
76278 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
76279 return -EPERM;
76280diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
76281index 942ca27..111e609 100644
76282--- a/kernel/posix-cpu-timers.c
76283+++ b/kernel/posix-cpu-timers.c
76284@@ -1576,14 +1576,14 @@ struct k_clock clock_posix_cpu = {
76285
76286 static __init int init_posix_cpu_timers(void)
76287 {
76288- struct k_clock process = {
76289+ static struct k_clock process = {
76290 .clock_getres = process_cpu_clock_getres,
76291 .clock_get = process_cpu_clock_get,
76292 .timer_create = process_cpu_timer_create,
76293 .nsleep = process_cpu_nsleep,
76294 .nsleep_restart = process_cpu_nsleep_restart,
76295 };
76296- struct k_clock thread = {
76297+ static struct k_clock thread = {
76298 .clock_getres = thread_cpu_clock_getres,
76299 .clock_get = thread_cpu_clock_get,
76300 .timer_create = thread_cpu_timer_create,
76301diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
76302index e885be1..380fe76 100644
76303--- a/kernel/posix-timers.c
76304+++ b/kernel/posix-timers.c
76305@@ -43,6 +43,7 @@
76306 #include <linux/idr.h>
76307 #include <linux/posix-clock.h>
76308 #include <linux/posix-timers.h>
76309+#include <linux/grsecurity.h>
76310 #include <linux/syscalls.h>
76311 #include <linux/wait.h>
76312 #include <linux/workqueue.h>
76313@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
76314 * which we beg off on and pass to do_sys_settimeofday().
76315 */
76316
76317-static struct k_clock posix_clocks[MAX_CLOCKS];
76318+static struct k_clock *posix_clocks[MAX_CLOCKS];
76319
76320 /*
76321 * These ones are defined below.
76322@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
76323 */
76324 static __init int init_posix_timers(void)
76325 {
76326- struct k_clock clock_realtime = {
76327+ static struct k_clock clock_realtime = {
76328 .clock_getres = hrtimer_get_res,
76329 .clock_get = posix_clock_realtime_get,
76330 .clock_set = posix_clock_realtime_set,
76331@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
76332 .timer_get = common_timer_get,
76333 .timer_del = common_timer_del,
76334 };
76335- struct k_clock clock_monotonic = {
76336+ static struct k_clock clock_monotonic = {
76337 .clock_getres = hrtimer_get_res,
76338 .clock_get = posix_ktime_get_ts,
76339 .nsleep = common_nsleep,
76340@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
76341 .timer_get = common_timer_get,
76342 .timer_del = common_timer_del,
76343 };
76344- struct k_clock clock_monotonic_raw = {
76345+ static struct k_clock clock_monotonic_raw = {
76346 .clock_getres = hrtimer_get_res,
76347 .clock_get = posix_get_monotonic_raw,
76348 };
76349- struct k_clock clock_realtime_coarse = {
76350+ static struct k_clock clock_realtime_coarse = {
76351 .clock_getres = posix_get_coarse_res,
76352 .clock_get = posix_get_realtime_coarse,
76353 };
76354- struct k_clock clock_monotonic_coarse = {
76355+ static struct k_clock clock_monotonic_coarse = {
76356 .clock_getres = posix_get_coarse_res,
76357 .clock_get = posix_get_monotonic_coarse,
76358 };
76359- struct k_clock clock_boottime = {
76360+ static struct k_clock clock_boottime = {
76361 .clock_getres = hrtimer_get_res,
76362 .clock_get = posix_get_boottime,
76363 .nsleep = common_nsleep,
76364@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
76365 return;
76366 }
76367
76368- posix_clocks[clock_id] = *new_clock;
76369+ posix_clocks[clock_id] = new_clock;
76370 }
76371 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
76372
76373@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
76374 return (id & CLOCKFD_MASK) == CLOCKFD ?
76375 &clock_posix_dynamic : &clock_posix_cpu;
76376
76377- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
76378+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
76379 return NULL;
76380- return &posix_clocks[id];
76381+ return posix_clocks[id];
76382 }
76383
76384 static int common_timer_create(struct k_itimer *new_timer)
76385@@ -966,6 +967,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
76386 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
76387 return -EFAULT;
76388
76389+ /* only the CLOCK_REALTIME clock can be set, all other clocks
76390+ have their clock_set fptr set to a nosettime dummy function
76391+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
76392+ call common_clock_set, which calls do_sys_settimeofday, which
76393+ we hook
76394+ */
76395+
76396 return kc->clock_set(which_clock, &new_tp);
76397 }
76398
76399diff --git a/kernel/power/process.c b/kernel/power/process.c
76400index d5a258b..4271191 100644
76401--- a/kernel/power/process.c
76402+++ b/kernel/power/process.c
76403@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
76404 u64 elapsed_csecs64;
76405 unsigned int elapsed_csecs;
76406 bool wakeup = false;
76407+ bool timedout = false;
76408
76409 do_gettimeofday(&start);
76410
76411@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
76412
76413 while (true) {
76414 todo = 0;
76415+ if (time_after(jiffies, end_time))
76416+ timedout = true;
76417 read_lock(&tasklist_lock);
76418 do_each_thread(g, p) {
76419 if (p == current || !freeze_task(p))
76420 continue;
76421
76422- if (!freezer_should_skip(p))
76423+ if (!freezer_should_skip(p)) {
76424 todo++;
76425+ if (timedout) {
76426+ printk(KERN_ERR "Task refusing to freeze:\n");
76427+ sched_show_task(p);
76428+ }
76429+ }
76430 } while_each_thread(g, p);
76431 read_unlock(&tasklist_lock);
76432
76433@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
76434 todo += wq_busy;
76435 }
76436
76437- if (!todo || time_after(jiffies, end_time))
76438+ if (!todo || timedout)
76439 break;
76440
76441 if (pm_wakeup_pending()) {
76442diff --git a/kernel/printk.c b/kernel/printk.c
76443index 267ce78..2487112 100644
76444--- a/kernel/printk.c
76445+++ b/kernel/printk.c
76446@@ -609,11 +609,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
76447 return ret;
76448 }
76449
76450+static int check_syslog_permissions(int type, bool from_file);
76451+
76452 static int devkmsg_open(struct inode *inode, struct file *file)
76453 {
76454 struct devkmsg_user *user;
76455 int err;
76456
76457+ err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
76458+ if (err)
76459+ return err;
76460+
76461 /* write-only does not need any file context */
76462 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
76463 return 0;
76464@@ -822,7 +828,7 @@ static int syslog_action_restricted(int type)
76465 if (dmesg_restrict)
76466 return 1;
76467 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
76468- return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
76469+ return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
76470 }
76471
76472 static int check_syslog_permissions(int type, bool from_file)
76473@@ -834,6 +840,11 @@ static int check_syslog_permissions(int type, bool from_file)
76474 if (from_file && type != SYSLOG_ACTION_OPEN)
76475 return 0;
76476
76477+#ifdef CONFIG_GRKERNSEC_DMESG
76478+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
76479+ return -EPERM;
76480+#endif
76481+
76482 if (syslog_action_restricted(type)) {
76483 if (capable(CAP_SYSLOG))
76484 return 0;
76485diff --git a/kernel/profile.c b/kernel/profile.c
76486index 1f39181..86093471 100644
76487--- a/kernel/profile.c
76488+++ b/kernel/profile.c
76489@@ -40,7 +40,7 @@ struct profile_hit {
76490 /* Oprofile timer tick hook */
76491 static int (*timer_hook)(struct pt_regs *) __read_mostly;
76492
76493-static atomic_t *prof_buffer;
76494+static atomic_unchecked_t *prof_buffer;
76495 static unsigned long prof_len, prof_shift;
76496
76497 int prof_on __read_mostly;
76498@@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
76499 hits[i].pc = 0;
76500 continue;
76501 }
76502- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
76503+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
76504 hits[i].hits = hits[i].pc = 0;
76505 }
76506 }
76507@@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
76508 * Add the current hit(s) and flush the write-queue out
76509 * to the global buffer:
76510 */
76511- atomic_add(nr_hits, &prof_buffer[pc]);
76512+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
76513 for (i = 0; i < NR_PROFILE_HIT; ++i) {
76514- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
76515+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
76516 hits[i].pc = hits[i].hits = 0;
76517 }
76518 out:
76519@@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
76520 {
76521 unsigned long pc;
76522 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
76523- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
76524+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
76525 }
76526 #endif /* !CONFIG_SMP */
76527
76528@@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
76529 return -EFAULT;
76530 buf++; p++; count--; read++;
76531 }
76532- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
76533+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
76534 if (copy_to_user(buf, (void *)pnt, count))
76535 return -EFAULT;
76536 read += count;
76537@@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
76538 }
76539 #endif
76540 profile_discard_flip_buffers();
76541- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
76542+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
76543 return count;
76544 }
76545
76546diff --git a/kernel/ptrace.c b/kernel/ptrace.c
76547index 6cbeaae..cfe7ff0 100644
76548--- a/kernel/ptrace.c
76549+++ b/kernel/ptrace.c
76550@@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
76551 if (seize)
76552 flags |= PT_SEIZED;
76553 rcu_read_lock();
76554- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
76555+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
76556 flags |= PT_PTRACE_CAP;
76557 rcu_read_unlock();
76558 task->ptrace = flags;
76559@@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
76560 break;
76561 return -EIO;
76562 }
76563- if (copy_to_user(dst, buf, retval))
76564+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
76565 return -EFAULT;
76566 copied += retval;
76567 src += retval;
76568@@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
76569 bool seized = child->ptrace & PT_SEIZED;
76570 int ret = -EIO;
76571 siginfo_t siginfo, *si;
76572- void __user *datavp = (void __user *) data;
76573+ void __user *datavp = (__force void __user *) data;
76574 unsigned long __user *datalp = datavp;
76575 unsigned long flags;
76576
76577@@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
76578 goto out;
76579 }
76580
76581+ if (gr_handle_ptrace(child, request)) {
76582+ ret = -EPERM;
76583+ goto out_put_task_struct;
76584+ }
76585+
76586 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
76587 ret = ptrace_attach(child, request, addr, data);
76588 /*
76589 * Some architectures need to do book-keeping after
76590 * a ptrace attach.
76591 */
76592- if (!ret)
76593+ if (!ret) {
76594 arch_ptrace_attach(child);
76595+ gr_audit_ptrace(child);
76596+ }
76597 goto out_put_task_struct;
76598 }
76599
76600@@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
76601 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
76602 if (copied != sizeof(tmp))
76603 return -EIO;
76604- return put_user(tmp, (unsigned long __user *)data);
76605+ return put_user(tmp, (__force unsigned long __user *)data);
76606 }
76607
76608 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
76609@@ -1051,7 +1058,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
76610 }
76611
76612 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
76613- compat_long_t addr, compat_long_t data)
76614+ compat_ulong_t addr, compat_ulong_t data)
76615 {
76616 struct task_struct *child;
76617 long ret;
76618@@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
76619 goto out;
76620 }
76621
76622+ if (gr_handle_ptrace(child, request)) {
76623+ ret = -EPERM;
76624+ goto out_put_task_struct;
76625+ }
76626+
76627 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
76628 ret = ptrace_attach(child, request, addr, data);
76629 /*
76630 * Some architectures need to do book-keeping after
76631 * a ptrace attach.
76632 */
76633- if (!ret)
76634+ if (!ret) {
76635 arch_ptrace_attach(child);
76636+ gr_audit_ptrace(child);
76637+ }
76638 goto out_put_task_struct;
76639 }
76640
76641diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
76642index e7dce58..ad0d7b7 100644
76643--- a/kernel/rcutiny.c
76644+++ b/kernel/rcutiny.c
76645@@ -46,7 +46,7 @@
76646 struct rcu_ctrlblk;
76647 static void invoke_rcu_callbacks(void);
76648 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
76649-static void rcu_process_callbacks(struct softirq_action *unused);
76650+static void rcu_process_callbacks(void);
76651 static void __call_rcu(struct rcu_head *head,
76652 void (*func)(struct rcu_head *rcu),
76653 struct rcu_ctrlblk *rcp);
76654@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
76655 rcu_is_callbacks_kthread()));
76656 }
76657
76658-static void rcu_process_callbacks(struct softirq_action *unused)
76659+static void rcu_process_callbacks(void)
76660 {
76661 __rcu_process_callbacks(&rcu_sched_ctrlblk);
76662 __rcu_process_callbacks(&rcu_bh_ctrlblk);
76663diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
76664index f85016a..91cb03b 100644
76665--- a/kernel/rcutiny_plugin.h
76666+++ b/kernel/rcutiny_plugin.h
76667@@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
76668 have_rcu_kthread_work = morework;
76669 local_irq_restore(flags);
76670 if (work)
76671- rcu_process_callbacks(NULL);
76672+ rcu_process_callbacks();
76673 schedule_timeout_interruptible(1); /* Leave CPU for others. */
76674 }
76675
76676diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
76677index 31dea01..ad91ffb 100644
76678--- a/kernel/rcutorture.c
76679+++ b/kernel/rcutorture.c
76680@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
76681 { 0 };
76682 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
76683 { 0 };
76684-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
76685-static atomic_t n_rcu_torture_alloc;
76686-static atomic_t n_rcu_torture_alloc_fail;
76687-static atomic_t n_rcu_torture_free;
76688-static atomic_t n_rcu_torture_mberror;
76689-static atomic_t n_rcu_torture_error;
76690+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
76691+static atomic_unchecked_t n_rcu_torture_alloc;
76692+static atomic_unchecked_t n_rcu_torture_alloc_fail;
76693+static atomic_unchecked_t n_rcu_torture_free;
76694+static atomic_unchecked_t n_rcu_torture_mberror;
76695+static atomic_unchecked_t n_rcu_torture_error;
76696 static long n_rcu_torture_barrier_error;
76697 static long n_rcu_torture_boost_ktrerror;
76698 static long n_rcu_torture_boost_rterror;
76699@@ -272,11 +272,11 @@ rcu_torture_alloc(void)
76700
76701 spin_lock_bh(&rcu_torture_lock);
76702 if (list_empty(&rcu_torture_freelist)) {
76703- atomic_inc(&n_rcu_torture_alloc_fail);
76704+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
76705 spin_unlock_bh(&rcu_torture_lock);
76706 return NULL;
76707 }
76708- atomic_inc(&n_rcu_torture_alloc);
76709+ atomic_inc_unchecked(&n_rcu_torture_alloc);
76710 p = rcu_torture_freelist.next;
76711 list_del_init(p);
76712 spin_unlock_bh(&rcu_torture_lock);
76713@@ -289,7 +289,7 @@ rcu_torture_alloc(void)
76714 static void
76715 rcu_torture_free(struct rcu_torture *p)
76716 {
76717- atomic_inc(&n_rcu_torture_free);
76718+ atomic_inc_unchecked(&n_rcu_torture_free);
76719 spin_lock_bh(&rcu_torture_lock);
76720 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
76721 spin_unlock_bh(&rcu_torture_lock);
76722@@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
76723 i = rp->rtort_pipe_count;
76724 if (i > RCU_TORTURE_PIPE_LEN)
76725 i = RCU_TORTURE_PIPE_LEN;
76726- atomic_inc(&rcu_torture_wcount[i]);
76727+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
76728 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
76729 rp->rtort_mbtest = 0;
76730 rcu_torture_free(rp);
76731@@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
76732 i = rp->rtort_pipe_count;
76733 if (i > RCU_TORTURE_PIPE_LEN)
76734 i = RCU_TORTURE_PIPE_LEN;
76735- atomic_inc(&rcu_torture_wcount[i]);
76736+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
76737 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
76738 rp->rtort_mbtest = 0;
76739 list_del(&rp->rtort_free);
76740@@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
76741 i = old_rp->rtort_pipe_count;
76742 if (i > RCU_TORTURE_PIPE_LEN)
76743 i = RCU_TORTURE_PIPE_LEN;
76744- atomic_inc(&rcu_torture_wcount[i]);
76745+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
76746 old_rp->rtort_pipe_count++;
76747 cur_ops->deferred_free(old_rp);
76748 }
76749@@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
76750 }
76751 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
76752 if (p->rtort_mbtest == 0)
76753- atomic_inc(&n_rcu_torture_mberror);
76754+ atomic_inc_unchecked(&n_rcu_torture_mberror);
76755 spin_lock(&rand_lock);
76756 cur_ops->read_delay(&rand);
76757 n_rcu_torture_timers++;
76758@@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
76759 }
76760 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
76761 if (p->rtort_mbtest == 0)
76762- atomic_inc(&n_rcu_torture_mberror);
76763+ atomic_inc_unchecked(&n_rcu_torture_mberror);
76764 cur_ops->read_delay(&rand);
76765 preempt_disable();
76766 pipe_count = p->rtort_pipe_count;
76767@@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
76768 rcu_torture_current,
76769 rcu_torture_current_version,
76770 list_empty(&rcu_torture_freelist),
76771- atomic_read(&n_rcu_torture_alloc),
76772- atomic_read(&n_rcu_torture_alloc_fail),
76773- atomic_read(&n_rcu_torture_free));
76774+ atomic_read_unchecked(&n_rcu_torture_alloc),
76775+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
76776+ atomic_read_unchecked(&n_rcu_torture_free));
76777 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
76778- atomic_read(&n_rcu_torture_mberror),
76779+ atomic_read_unchecked(&n_rcu_torture_mberror),
76780 n_rcu_torture_boost_ktrerror,
76781 n_rcu_torture_boost_rterror);
76782 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
76783@@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
76784 n_barrier_attempts,
76785 n_rcu_torture_barrier_error);
76786 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
76787- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
76788+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
76789 n_rcu_torture_barrier_error != 0 ||
76790 n_rcu_torture_boost_ktrerror != 0 ||
76791 n_rcu_torture_boost_rterror != 0 ||
76792 n_rcu_torture_boost_failure != 0 ||
76793 i > 1) {
76794 cnt += sprintf(&page[cnt], "!!! ");
76795- atomic_inc(&n_rcu_torture_error);
76796+ atomic_inc_unchecked(&n_rcu_torture_error);
76797 WARN_ON_ONCE(1);
76798 }
76799 cnt += sprintf(&page[cnt], "Reader Pipe: ");
76800@@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
76801 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
76802 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
76803 cnt += sprintf(&page[cnt], " %d",
76804- atomic_read(&rcu_torture_wcount[i]));
76805+ atomic_read_unchecked(&rcu_torture_wcount[i]));
76806 }
76807 cnt += sprintf(&page[cnt], "\n");
76808 if (cur_ops->stats)
76809@@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
76810
76811 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
76812
76813- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
76814+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
76815 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
76816 else if (n_online_successes != n_online_attempts ||
76817 n_offline_successes != n_offline_attempts)
76818@@ -1989,18 +1989,18 @@ rcu_torture_init(void)
76819
76820 rcu_torture_current = NULL;
76821 rcu_torture_current_version = 0;
76822- atomic_set(&n_rcu_torture_alloc, 0);
76823- atomic_set(&n_rcu_torture_alloc_fail, 0);
76824- atomic_set(&n_rcu_torture_free, 0);
76825- atomic_set(&n_rcu_torture_mberror, 0);
76826- atomic_set(&n_rcu_torture_error, 0);
76827+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
76828+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
76829+ atomic_set_unchecked(&n_rcu_torture_free, 0);
76830+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
76831+ atomic_set_unchecked(&n_rcu_torture_error, 0);
76832 n_rcu_torture_barrier_error = 0;
76833 n_rcu_torture_boost_ktrerror = 0;
76834 n_rcu_torture_boost_rterror = 0;
76835 n_rcu_torture_boost_failure = 0;
76836 n_rcu_torture_boosts = 0;
76837 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
76838- atomic_set(&rcu_torture_wcount[i], 0);
76839+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
76840 for_each_possible_cpu(cpu) {
76841 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
76842 per_cpu(rcu_torture_count, cpu)[i] = 0;
76843diff --git a/kernel/rcutree.c b/kernel/rcutree.c
76844index e441b77..dd54f17 100644
76845--- a/kernel/rcutree.c
76846+++ b/kernel/rcutree.c
76847@@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
76848 rcu_prepare_for_idle(smp_processor_id());
76849 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
76850 smp_mb__before_atomic_inc(); /* See above. */
76851- atomic_inc(&rdtp->dynticks);
76852+ atomic_inc_unchecked(&rdtp->dynticks);
76853 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
76854- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
76855+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
76856
76857 /*
76858 * It is illegal to enter an extended quiescent state while
76859@@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
76860 int user)
76861 {
76862 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
76863- atomic_inc(&rdtp->dynticks);
76864+ atomic_inc_unchecked(&rdtp->dynticks);
76865 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
76866 smp_mb__after_atomic_inc(); /* See above. */
76867- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
76868+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
76869 rcu_cleanup_after_idle(smp_processor_id());
76870 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
76871 if (!user && !is_idle_task(current)) {
76872@@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
76873 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
76874
76875 if (rdtp->dynticks_nmi_nesting == 0 &&
76876- (atomic_read(&rdtp->dynticks) & 0x1))
76877+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
76878 return;
76879 rdtp->dynticks_nmi_nesting++;
76880 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
76881- atomic_inc(&rdtp->dynticks);
76882+ atomic_inc_unchecked(&rdtp->dynticks);
76883 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
76884 smp_mb__after_atomic_inc(); /* See above. */
76885- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
76886+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
76887 }
76888
76889 /**
76890@@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
76891 return;
76892 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
76893 smp_mb__before_atomic_inc(); /* See above. */
76894- atomic_inc(&rdtp->dynticks);
76895+ atomic_inc_unchecked(&rdtp->dynticks);
76896 smp_mb__after_atomic_inc(); /* Force delay to next write. */
76897- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
76898+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
76899 }
76900
76901 /**
76902@@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
76903 int ret;
76904
76905 preempt_disable();
76906- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
76907+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
76908 preempt_enable();
76909 return ret;
76910 }
76911@@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
76912 */
76913 static int dyntick_save_progress_counter(struct rcu_data *rdp)
76914 {
76915- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
76916+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
76917 return (rdp->dynticks_snap & 0x1) == 0;
76918 }
76919
76920@@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
76921 unsigned int curr;
76922 unsigned int snap;
76923
76924- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
76925+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
76926 snap = (unsigned int)rdp->dynticks_snap;
76927
76928 /*
76929@@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
76930 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
76931 */
76932 if (till_stall_check < 3) {
76933- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
76934+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
76935 till_stall_check = 3;
76936 } else if (till_stall_check > 300) {
76937- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
76938+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
76939 till_stall_check = 300;
76940 }
76941 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
76942@@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
76943 rsp->qlen += rdp->qlen;
76944 rdp->n_cbs_orphaned += rdp->qlen;
76945 rdp->qlen_lazy = 0;
76946- ACCESS_ONCE(rdp->qlen) = 0;
76947+ ACCESS_ONCE_RW(rdp->qlen) = 0;
76948 }
76949
76950 /*
76951@@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
76952 }
76953 smp_mb(); /* List handling before counting for rcu_barrier(). */
76954 rdp->qlen_lazy -= count_lazy;
76955- ACCESS_ONCE(rdp->qlen) -= count;
76956+ ACCESS_ONCE_RW(rdp->qlen) -= count;
76957 rdp->n_cbs_invoked += count;
76958
76959 /* Reinstate batch limit if we have worked down the excess. */
76960@@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
76961 /*
76962 * Do RCU core processing for the current CPU.
76963 */
76964-static void rcu_process_callbacks(struct softirq_action *unused)
76965+static void rcu_process_callbacks(void)
76966 {
76967 struct rcu_state *rsp;
76968
76969@@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
76970 local_irq_restore(flags);
76971 return;
76972 }
76973- ACCESS_ONCE(rdp->qlen)++;
76974+ ACCESS_ONCE_RW(rdp->qlen)++;
76975 if (lazy)
76976 rdp->qlen_lazy++;
76977 else
76978@@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
76979 * counter wrap on a 32-bit system. Quite a few more CPUs would of
76980 * course be required on a 64-bit system.
76981 */
76982- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
76983+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
76984 (ulong)atomic_long_read(&rsp->expedited_done) +
76985 ULONG_MAX / 8)) {
76986 synchronize_sched();
76987- atomic_long_inc(&rsp->expedited_wrap);
76988+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
76989 return;
76990 }
76991
76992@@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
76993 * Take a ticket. Note that atomic_inc_return() implies a
76994 * full memory barrier.
76995 */
76996- snap = atomic_long_inc_return(&rsp->expedited_start);
76997+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
76998 firstsnap = snap;
76999 get_online_cpus();
77000 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
77001@@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
77002 synchronize_sched_expedited_cpu_stop,
77003 NULL) == -EAGAIN) {
77004 put_online_cpus();
77005- atomic_long_inc(&rsp->expedited_tryfail);
77006+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
77007
77008 /* Check to see if someone else did our work for us. */
77009 s = atomic_long_read(&rsp->expedited_done);
77010 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
77011 /* ensure test happens before caller kfree */
77012 smp_mb__before_atomic_inc(); /* ^^^ */
77013- atomic_long_inc(&rsp->expedited_workdone1);
77014+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
77015 return;
77016 }
77017
77018@@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
77019 udelay(trycount * num_online_cpus());
77020 } else {
77021 wait_rcu_gp(call_rcu_sched);
77022- atomic_long_inc(&rsp->expedited_normal);
77023+ atomic_long_inc_unchecked(&rsp->expedited_normal);
77024 return;
77025 }
77026
77027@@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
77028 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
77029 /* ensure test happens before caller kfree */
77030 smp_mb__before_atomic_inc(); /* ^^^ */
77031- atomic_long_inc(&rsp->expedited_workdone2);
77032+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
77033 return;
77034 }
77035
77036@@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
77037 * period works for us.
77038 */
77039 get_online_cpus();
77040- snap = atomic_long_read(&rsp->expedited_start);
77041+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
77042 smp_mb(); /* ensure read is before try_stop_cpus(). */
77043 }
77044- atomic_long_inc(&rsp->expedited_stoppedcpus);
77045+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
77046
77047 /*
77048 * Everyone up to our most recent fetch is covered by our grace
77049@@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
77050 * than we did already did their update.
77051 */
77052 do {
77053- atomic_long_inc(&rsp->expedited_done_tries);
77054+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
77055 s = atomic_long_read(&rsp->expedited_done);
77056 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
77057 /* ensure test happens before caller kfree */
77058 smp_mb__before_atomic_inc(); /* ^^^ */
77059- atomic_long_inc(&rsp->expedited_done_lost);
77060+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
77061 break;
77062 }
77063 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
77064- atomic_long_inc(&rsp->expedited_done_exit);
77065+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
77066
77067 put_online_cpus();
77068 }
77069@@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
77070 * ACCESS_ONCE() to prevent the compiler from speculating
77071 * the increment to precede the early-exit check.
77072 */
77073- ACCESS_ONCE(rsp->n_barrier_done)++;
77074+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
77075 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
77076 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
77077 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
77078@@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
77079
77080 /* Increment ->n_barrier_done to prevent duplicate work. */
77081 smp_mb(); /* Keep increment after above mechanism. */
77082- ACCESS_ONCE(rsp->n_barrier_done)++;
77083+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
77084 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
77085 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
77086 smp_mb(); /* Keep increment before caller's subsequent code. */
77087@@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
77088 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
77089 init_callback_list(rdp);
77090 rdp->qlen_lazy = 0;
77091- ACCESS_ONCE(rdp->qlen) = 0;
77092+ ACCESS_ONCE_RW(rdp->qlen) = 0;
77093 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
77094 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
77095- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
77096+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
77097 #ifdef CONFIG_RCU_USER_QS
77098 WARN_ON_ONCE(rdp->dynticks->in_user);
77099 #endif
77100@@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
77101 rdp->blimit = blimit;
77102 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
77103 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
77104- atomic_set(&rdp->dynticks->dynticks,
77105- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
77106+ atomic_set_unchecked(&rdp->dynticks->dynticks,
77107+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
77108 rcu_prepare_for_idle_init(cpu);
77109 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
77110
77111diff --git a/kernel/rcutree.h b/kernel/rcutree.h
77112index 4b69291..704c92e 100644
77113--- a/kernel/rcutree.h
77114+++ b/kernel/rcutree.h
77115@@ -86,7 +86,7 @@ struct rcu_dynticks {
77116 long long dynticks_nesting; /* Track irq/process nesting level. */
77117 /* Process level is worth LLONG_MAX/2. */
77118 int dynticks_nmi_nesting; /* Track NMI nesting level. */
77119- atomic_t dynticks; /* Even value for idle, else odd. */
77120+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
77121 #ifdef CONFIG_RCU_FAST_NO_HZ
77122 int dyntick_drain; /* Prepare-for-idle state variable. */
77123 unsigned long dyntick_holdoff;
77124@@ -423,17 +423,17 @@ struct rcu_state {
77125 /* _rcu_barrier(). */
77126 /* End of fields guarded by barrier_mutex. */
77127
77128- atomic_long_t expedited_start; /* Starting ticket. */
77129- atomic_long_t expedited_done; /* Done ticket. */
77130- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
77131- atomic_long_t expedited_tryfail; /* # acquisition failures. */
77132- atomic_long_t expedited_workdone1; /* # done by others #1. */
77133- atomic_long_t expedited_workdone2; /* # done by others #2. */
77134- atomic_long_t expedited_normal; /* # fallbacks to normal. */
77135- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
77136- atomic_long_t expedited_done_tries; /* # tries to update _done. */
77137- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
77138- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
77139+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
77140+ atomic_long_t expedited_done; /* Done ticket. */
77141+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
77142+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
77143+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
77144+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
77145+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
77146+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
77147+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
77148+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
77149+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
77150
77151 unsigned long jiffies_force_qs; /* Time at which to invoke */
77152 /* force_quiescent_state(). */
77153diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
77154index c1cc7e1..f62e436 100644
77155--- a/kernel/rcutree_plugin.h
77156+++ b/kernel/rcutree_plugin.h
77157@@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
77158
77159 /* Clean up and exit. */
77160 smp_mb(); /* ensure expedited GP seen before counter increment. */
77161- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
77162+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
77163 unlock_mb_ret:
77164 mutex_unlock(&sync_rcu_preempt_exp_mutex);
77165 mb_ret:
77166@@ -1440,7 +1440,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
77167 free_cpumask_var(cm);
77168 }
77169
77170-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
77171+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
77172 .store = &rcu_cpu_kthread_task,
77173 .thread_should_run = rcu_cpu_kthread_should_run,
77174 .thread_fn = rcu_cpu_kthread,
77175@@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
77176 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
77177 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
77178 cpu, ticks_value, ticks_title,
77179- atomic_read(&rdtp->dynticks) & 0xfff,
77180+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
77181 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
77182 fast_no_hz);
77183 }
77184@@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
77185
77186 /* Enqueue the callback on the nocb list and update counts. */
77187 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
77188- ACCESS_ONCE(*old_rhpp) = rhp;
77189+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
77190 atomic_long_add(rhcount, &rdp->nocb_q_count);
77191 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
77192
77193@@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
77194 * Extract queued callbacks, update counts, and wait
77195 * for a grace period to elapse.
77196 */
77197- ACCESS_ONCE(rdp->nocb_head) = NULL;
77198+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
77199 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
77200 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
77201 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
77202- ACCESS_ONCE(rdp->nocb_p_count) += c;
77203- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
77204+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
77205+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
77206 wait_rcu_gp(rdp->rsp->call_remote);
77207
77208 /* Each pass through the following loop invokes a callback. */
77209@@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
77210 list = next;
77211 }
77212 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
77213- ACCESS_ONCE(rdp->nocb_p_count) -= c;
77214- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
77215+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
77216+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
77217 rdp->n_nocbs_invoked += c;
77218 }
77219 return 0;
77220@@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
77221 rdp = per_cpu_ptr(rsp->rda, cpu);
77222 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
77223 BUG_ON(IS_ERR(t));
77224- ACCESS_ONCE(rdp->nocb_kthread) = t;
77225+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
77226 }
77227 }
77228
77229diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
77230index 0d095dc..1985b19 100644
77231--- a/kernel/rcutree_trace.c
77232+++ b/kernel/rcutree_trace.c
77233@@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
77234 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
77235 rdp->passed_quiesce, rdp->qs_pending);
77236 seq_printf(m, " dt=%d/%llx/%d df=%lu",
77237- atomic_read(&rdp->dynticks->dynticks),
77238+ atomic_read_unchecked(&rdp->dynticks->dynticks),
77239 rdp->dynticks->dynticks_nesting,
77240 rdp->dynticks->dynticks_nmi_nesting,
77241 rdp->dynticks_fqs);
77242@@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
77243 struct rcu_state *rsp = (struct rcu_state *)m->private;
77244
77245 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",
77246- atomic_long_read(&rsp->expedited_start),
77247+ atomic_long_read_unchecked(&rsp->expedited_start),
77248 atomic_long_read(&rsp->expedited_done),
77249- atomic_long_read(&rsp->expedited_wrap),
77250- atomic_long_read(&rsp->expedited_tryfail),
77251- atomic_long_read(&rsp->expedited_workdone1),
77252- atomic_long_read(&rsp->expedited_workdone2),
77253- atomic_long_read(&rsp->expedited_normal),
77254- atomic_long_read(&rsp->expedited_stoppedcpus),
77255- atomic_long_read(&rsp->expedited_done_tries),
77256- atomic_long_read(&rsp->expedited_done_lost),
77257- atomic_long_read(&rsp->expedited_done_exit));
77258+ atomic_long_read_unchecked(&rsp->expedited_wrap),
77259+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
77260+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
77261+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
77262+ atomic_long_read_unchecked(&rsp->expedited_normal),
77263+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
77264+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
77265+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
77266+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
77267 return 0;
77268 }
77269
77270diff --git a/kernel/resource.c b/kernel/resource.c
77271index 73f35d4..4684fc4 100644
77272--- a/kernel/resource.c
77273+++ b/kernel/resource.c
77274@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
77275
77276 static int __init ioresources_init(void)
77277 {
77278+#ifdef CONFIG_GRKERNSEC_PROC_ADD
77279+#ifdef CONFIG_GRKERNSEC_PROC_USER
77280+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
77281+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
77282+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77283+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
77284+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
77285+#endif
77286+#else
77287 proc_create("ioports", 0, NULL, &proc_ioports_operations);
77288 proc_create("iomem", 0, NULL, &proc_iomem_operations);
77289+#endif
77290 return 0;
77291 }
77292 __initcall(ioresources_init);
77293diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
77294index 98ec494..4241d6d 100644
77295--- a/kernel/rtmutex-tester.c
77296+++ b/kernel/rtmutex-tester.c
77297@@ -20,7 +20,7 @@
77298 #define MAX_RT_TEST_MUTEXES 8
77299
77300 static spinlock_t rttest_lock;
77301-static atomic_t rttest_event;
77302+static atomic_unchecked_t rttest_event;
77303
77304 struct test_thread_data {
77305 int opcode;
77306@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77307
77308 case RTTEST_LOCKCONT:
77309 td->mutexes[td->opdata] = 1;
77310- td->event = atomic_add_return(1, &rttest_event);
77311+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77312 return 0;
77313
77314 case RTTEST_RESET:
77315@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77316 return 0;
77317
77318 case RTTEST_RESETEVENT:
77319- atomic_set(&rttest_event, 0);
77320+ atomic_set_unchecked(&rttest_event, 0);
77321 return 0;
77322
77323 default:
77324@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77325 return ret;
77326
77327 td->mutexes[id] = 1;
77328- td->event = atomic_add_return(1, &rttest_event);
77329+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77330 rt_mutex_lock(&mutexes[id]);
77331- td->event = atomic_add_return(1, &rttest_event);
77332+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77333 td->mutexes[id] = 4;
77334 return 0;
77335
77336@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77337 return ret;
77338
77339 td->mutexes[id] = 1;
77340- td->event = atomic_add_return(1, &rttest_event);
77341+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77342 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
77343- td->event = atomic_add_return(1, &rttest_event);
77344+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77345 td->mutexes[id] = ret ? 0 : 4;
77346 return ret ? -EINTR : 0;
77347
77348@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77349 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
77350 return ret;
77351
77352- td->event = atomic_add_return(1, &rttest_event);
77353+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77354 rt_mutex_unlock(&mutexes[id]);
77355- td->event = atomic_add_return(1, &rttest_event);
77356+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77357 td->mutexes[id] = 0;
77358 return 0;
77359
77360@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
77361 break;
77362
77363 td->mutexes[dat] = 2;
77364- td->event = atomic_add_return(1, &rttest_event);
77365+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77366 break;
77367
77368 default:
77369@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
77370 return;
77371
77372 td->mutexes[dat] = 3;
77373- td->event = atomic_add_return(1, &rttest_event);
77374+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77375 break;
77376
77377 case RTTEST_LOCKNOWAIT:
77378@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
77379 return;
77380
77381 td->mutexes[dat] = 1;
77382- td->event = atomic_add_return(1, &rttest_event);
77383+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77384 return;
77385
77386 default:
77387diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
77388index 0984a21..939f183 100644
77389--- a/kernel/sched/auto_group.c
77390+++ b/kernel/sched/auto_group.c
77391@@ -11,7 +11,7 @@
77392
77393 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
77394 static struct autogroup autogroup_default;
77395-static atomic_t autogroup_seq_nr;
77396+static atomic_unchecked_t autogroup_seq_nr;
77397
77398 void __init autogroup_init(struct task_struct *init_task)
77399 {
77400@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
77401
77402 kref_init(&ag->kref);
77403 init_rwsem(&ag->lock);
77404- ag->id = atomic_inc_return(&autogroup_seq_nr);
77405+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
77406 ag->tg = tg;
77407 #ifdef CONFIG_RT_GROUP_SCHED
77408 /*
77409diff --git a/kernel/sched/core.c b/kernel/sched/core.c
77410index 26058d0..e315889 100644
77411--- a/kernel/sched/core.c
77412+++ b/kernel/sched/core.c
77413@@ -3367,7 +3367,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
77414 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
77415 * positive (at least 1, or number of jiffies left till timeout) if completed.
77416 */
77417-long __sched
77418+long __sched __intentional_overflow(-1)
77419 wait_for_completion_interruptible_timeout(struct completion *x,
77420 unsigned long timeout)
77421 {
77422@@ -3384,7 +3384,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
77423 *
77424 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
77425 */
77426-int __sched wait_for_completion_killable(struct completion *x)
77427+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
77428 {
77429 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
77430 if (t == -ERESTARTSYS)
77431@@ -3405,7 +3405,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
77432 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
77433 * positive (at least 1, or number of jiffies left till timeout) if completed.
77434 */
77435-long __sched
77436+long __sched __intentional_overflow(-1)
77437 wait_for_completion_killable_timeout(struct completion *x,
77438 unsigned long timeout)
77439 {
77440@@ -3631,6 +3631,8 @@ int can_nice(const struct task_struct *p, const int nice)
77441 /* convert nice value [19,-20] to rlimit style value [1,40] */
77442 int nice_rlim = 20 - nice;
77443
77444+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
77445+
77446 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
77447 capable(CAP_SYS_NICE));
77448 }
77449@@ -3664,7 +3666,8 @@ SYSCALL_DEFINE1(nice, int, increment)
77450 if (nice > 19)
77451 nice = 19;
77452
77453- if (increment < 0 && !can_nice(current, nice))
77454+ if (increment < 0 && (!can_nice(current, nice) ||
77455+ gr_handle_chroot_nice()))
77456 return -EPERM;
77457
77458 retval = security_task_setnice(current, nice);
77459@@ -3818,6 +3821,7 @@ recheck:
77460 unsigned long rlim_rtprio =
77461 task_rlimit(p, RLIMIT_RTPRIO);
77462
77463+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
77464 /* can't set/change the rt policy */
77465 if (policy != p->policy && !rlim_rtprio)
77466 return -EPERM;
77467@@ -4901,7 +4905,7 @@ static void migrate_tasks(unsigned int dead_cpu)
77468
77469 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
77470
77471-static struct ctl_table sd_ctl_dir[] = {
77472+static ctl_table_no_const sd_ctl_dir[] __read_only = {
77473 {
77474 .procname = "sched_domain",
77475 .mode = 0555,
77476@@ -4918,17 +4922,17 @@ static struct ctl_table sd_ctl_root[] = {
77477 {}
77478 };
77479
77480-static struct ctl_table *sd_alloc_ctl_entry(int n)
77481+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
77482 {
77483- struct ctl_table *entry =
77484+ ctl_table_no_const *entry =
77485 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
77486
77487 return entry;
77488 }
77489
77490-static void sd_free_ctl_entry(struct ctl_table **tablep)
77491+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
77492 {
77493- struct ctl_table *entry;
77494+ ctl_table_no_const *entry;
77495
77496 /*
77497 * In the intermediate directories, both the child directory and
77498@@ -4936,22 +4940,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
77499 * will always be set. In the lowest directory the names are
77500 * static strings and all have proc handlers.
77501 */
77502- for (entry = *tablep; entry->mode; entry++) {
77503- if (entry->child)
77504- sd_free_ctl_entry(&entry->child);
77505+ for (entry = tablep; entry->mode; entry++) {
77506+ if (entry->child) {
77507+ sd_free_ctl_entry(entry->child);
77508+ pax_open_kernel();
77509+ entry->child = NULL;
77510+ pax_close_kernel();
77511+ }
77512 if (entry->proc_handler == NULL)
77513 kfree(entry->procname);
77514 }
77515
77516- kfree(*tablep);
77517- *tablep = NULL;
77518+ kfree(tablep);
77519 }
77520
77521 static int min_load_idx = 0;
77522 static int max_load_idx = CPU_LOAD_IDX_MAX;
77523
77524 static void
77525-set_table_entry(struct ctl_table *entry,
77526+set_table_entry(ctl_table_no_const *entry,
77527 const char *procname, void *data, int maxlen,
77528 umode_t mode, proc_handler *proc_handler,
77529 bool load_idx)
77530@@ -4971,7 +4978,7 @@ set_table_entry(struct ctl_table *entry,
77531 static struct ctl_table *
77532 sd_alloc_ctl_domain_table(struct sched_domain *sd)
77533 {
77534- struct ctl_table *table = sd_alloc_ctl_entry(13);
77535+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
77536
77537 if (table == NULL)
77538 return NULL;
77539@@ -5006,9 +5013,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
77540 return table;
77541 }
77542
77543-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
77544+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
77545 {
77546- struct ctl_table *entry, *table;
77547+ ctl_table_no_const *entry, *table;
77548 struct sched_domain *sd;
77549 int domain_num = 0, i;
77550 char buf[32];
77551@@ -5035,11 +5042,13 @@ static struct ctl_table_header *sd_sysctl_header;
77552 static void register_sched_domain_sysctl(void)
77553 {
77554 int i, cpu_num = num_possible_cpus();
77555- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
77556+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
77557 char buf[32];
77558
77559 WARN_ON(sd_ctl_dir[0].child);
77560+ pax_open_kernel();
77561 sd_ctl_dir[0].child = entry;
77562+ pax_close_kernel();
77563
77564 if (entry == NULL)
77565 return;
77566@@ -5062,8 +5071,12 @@ static void unregister_sched_domain_sysctl(void)
77567 if (sd_sysctl_header)
77568 unregister_sysctl_table(sd_sysctl_header);
77569 sd_sysctl_header = NULL;
77570- if (sd_ctl_dir[0].child)
77571- sd_free_ctl_entry(&sd_ctl_dir[0].child);
77572+ if (sd_ctl_dir[0].child) {
77573+ sd_free_ctl_entry(sd_ctl_dir[0].child);
77574+ pax_open_kernel();
77575+ sd_ctl_dir[0].child = NULL;
77576+ pax_close_kernel();
77577+ }
77578 }
77579 #else
77580 static void register_sched_domain_sysctl(void)
77581@@ -5162,7 +5175,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
77582 * happens before everything else. This has to be lower priority than
77583 * the notifier in the perf_event subsystem, though.
77584 */
77585-static struct notifier_block __cpuinitdata migration_notifier = {
77586+static struct notifier_block migration_notifier = {
77587 .notifier_call = migration_call,
77588 .priority = CPU_PRI_MIGRATION,
77589 };
77590diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
77591index 81fa536..6ccf96a 100644
77592--- a/kernel/sched/fair.c
77593+++ b/kernel/sched/fair.c
77594@@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
77595
77596 static void reset_ptenuma_scan(struct task_struct *p)
77597 {
77598- ACCESS_ONCE(p->mm->numa_scan_seq)++;
77599+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
77600 p->mm->numa_scan_offset = 0;
77601 }
77602
77603@@ -3254,25 +3254,18 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
77604 */
77605 static int select_idle_sibling(struct task_struct *p, int target)
77606 {
77607- int cpu = smp_processor_id();
77608- int prev_cpu = task_cpu(p);
77609 struct sched_domain *sd;
77610 struct sched_group *sg;
77611- int i;
77612+ int i = task_cpu(p);
77613
77614- /*
77615- * If the task is going to be woken-up on this cpu and if it is
77616- * already idle, then it is the right target.
77617- */
77618- if (target == cpu && idle_cpu(cpu))
77619- return cpu;
77620+ if (idle_cpu(target))
77621+ return target;
77622
77623 /*
77624- * If the task is going to be woken-up on the cpu where it previously
77625- * ran and if it is currently idle, then it the right target.
77626+ * If the prevous cpu is cache affine and idle, don't be stupid.
77627 */
77628- if (target == prev_cpu && idle_cpu(prev_cpu))
77629- return prev_cpu;
77630+ if (i != target && cpus_share_cache(i, target) && idle_cpu(i))
77631+ return i;
77632
77633 /*
77634 * Otherwise, iterate the domains and find an elegible idle cpu.
77635@@ -3286,7 +3279,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
77636 goto next;
77637
77638 for_each_cpu(i, sched_group_cpus(sg)) {
77639- if (!idle_cpu(i))
77640+ if (i == target || !idle_cpu(i))
77641 goto next;
77642 }
77643
77644@@ -5663,7 +5656,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
77645 * run_rebalance_domains is triggered when needed from the scheduler tick.
77646 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
77647 */
77648-static void run_rebalance_domains(struct softirq_action *h)
77649+static void run_rebalance_domains(void)
77650 {
77651 int this_cpu = smp_processor_id();
77652 struct rq *this_rq = cpu_rq(this_cpu);
77653diff --git a/kernel/signal.c b/kernel/signal.c
77654index 7591ccc..8988390 100644
77655--- a/kernel/signal.c
77656+++ b/kernel/signal.c
77657@@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
77658
77659 int print_fatal_signals __read_mostly;
77660
77661-static void __user *sig_handler(struct task_struct *t, int sig)
77662+static __sighandler_t sig_handler(struct task_struct *t, int sig)
77663 {
77664 return t->sighand->action[sig - 1].sa.sa_handler;
77665 }
77666
77667-static int sig_handler_ignored(void __user *handler, int sig)
77668+static int sig_handler_ignored(__sighandler_t handler, int sig)
77669 {
77670 /* Is it explicitly or implicitly ignored? */
77671 return handler == SIG_IGN ||
77672@@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
77673
77674 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
77675 {
77676- void __user *handler;
77677+ __sighandler_t handler;
77678
77679 handler = sig_handler(t, sig);
77680
77681@@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
77682 atomic_inc(&user->sigpending);
77683 rcu_read_unlock();
77684
77685+ if (!override_rlimit)
77686+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
77687+
77688 if (override_rlimit ||
77689 atomic_read(&user->sigpending) <=
77690 task_rlimit(t, RLIMIT_SIGPENDING)) {
77691@@ -495,7 +498,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
77692
77693 int unhandled_signal(struct task_struct *tsk, int sig)
77694 {
77695- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
77696+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
77697 if (is_global_init(tsk))
77698 return 1;
77699 if (handler != SIG_IGN && handler != SIG_DFL)
77700@@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
77701 }
77702 }
77703
77704+ /* allow glibc communication via tgkill to other threads in our
77705+ thread group */
77706+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
77707+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
77708+ && gr_handle_signal(t, sig))
77709+ return -EPERM;
77710+
77711 return security_task_kill(t, info, sig, 0);
77712 }
77713
77714@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
77715 return send_signal(sig, info, p, 1);
77716 }
77717
77718-static int
77719+int
77720 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
77721 {
77722 return send_signal(sig, info, t, 0);
77723@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
77724 unsigned long int flags;
77725 int ret, blocked, ignored;
77726 struct k_sigaction *action;
77727+ int is_unhandled = 0;
77728
77729 spin_lock_irqsave(&t->sighand->siglock, flags);
77730 action = &t->sighand->action[sig-1];
77731@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
77732 }
77733 if (action->sa.sa_handler == SIG_DFL)
77734 t->signal->flags &= ~SIGNAL_UNKILLABLE;
77735+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
77736+ is_unhandled = 1;
77737 ret = specific_send_sig_info(sig, info, t);
77738 spin_unlock_irqrestore(&t->sighand->siglock, flags);
77739
77740+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
77741+ normal operation */
77742+ if (is_unhandled) {
77743+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
77744+ gr_handle_crash(t, sig);
77745+ }
77746+
77747 return ret;
77748 }
77749
77750@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
77751 ret = check_kill_permission(sig, info, p);
77752 rcu_read_unlock();
77753
77754- if (!ret && sig)
77755+ if (!ret && sig) {
77756 ret = do_send_sig_info(sig, info, p, true);
77757+ if (!ret)
77758+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
77759+ }
77760
77761 return ret;
77762 }
77763@@ -2855,7 +2878,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
77764 int error = -ESRCH;
77765
77766 rcu_read_lock();
77767- p = find_task_by_vpid(pid);
77768+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77769+ /* allow glibc communication via tgkill to other threads in our
77770+ thread group */
77771+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
77772+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
77773+ p = find_task_by_vpid_unrestricted(pid);
77774+ else
77775+#endif
77776+ p = find_task_by_vpid(pid);
77777 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
77778 error = check_kill_permission(sig, info, p);
77779 /*
77780@@ -3138,8 +3169,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
77781 }
77782 seg = get_fs();
77783 set_fs(KERNEL_DS);
77784- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
77785- (stack_t __force __user *) &uoss,
77786+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
77787+ (stack_t __force_user *) &uoss,
77788 compat_user_stack_pointer());
77789 set_fs(seg);
77790 if (ret >= 0 && uoss_ptr) {
77791diff --git a/kernel/smp.c b/kernel/smp.c
77792index 69f38bd..77bbf12 100644
77793--- a/kernel/smp.c
77794+++ b/kernel/smp.c
77795@@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
77796 return NOTIFY_OK;
77797 }
77798
77799-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
77800+static struct notifier_block hotplug_cfd_notifier = {
77801 .notifier_call = hotplug_cfd,
77802 };
77803
77804diff --git a/kernel/smpboot.c b/kernel/smpboot.c
77805index d6c5fc0..530560c 100644
77806--- a/kernel/smpboot.c
77807+++ b/kernel/smpboot.c
77808@@ -275,7 +275,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
77809 }
77810 smpboot_unpark_thread(plug_thread, cpu);
77811 }
77812- list_add(&plug_thread->list, &hotplug_threads);
77813+ pax_list_add(&plug_thread->list, &hotplug_threads);
77814 out:
77815 mutex_unlock(&smpboot_threads_lock);
77816 return ret;
77817@@ -292,7 +292,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
77818 {
77819 get_online_cpus();
77820 mutex_lock(&smpboot_threads_lock);
77821- list_del(&plug_thread->list);
77822+ pax_list_del(&plug_thread->list);
77823 smpboot_destroy_threads(plug_thread);
77824 mutex_unlock(&smpboot_threads_lock);
77825 put_online_cpus();
77826diff --git a/kernel/softirq.c b/kernel/softirq.c
77827index ed567ba..e71dabf 100644
77828--- a/kernel/softirq.c
77829+++ b/kernel/softirq.c
77830@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
77831 EXPORT_SYMBOL(irq_stat);
77832 #endif
77833
77834-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
77835+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
77836
77837 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
77838
77839-char *softirq_to_name[NR_SOFTIRQS] = {
77840+const char * const softirq_to_name[NR_SOFTIRQS] = {
77841 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
77842 "TASKLET", "SCHED", "HRTIMER", "RCU"
77843 };
77844@@ -244,7 +244,7 @@ restart:
77845 kstat_incr_softirqs_this_cpu(vec_nr);
77846
77847 trace_softirq_entry(vec_nr);
77848- h->action(h);
77849+ h->action();
77850 trace_softirq_exit(vec_nr);
77851 if (unlikely(prev_count != preempt_count())) {
77852 printk(KERN_ERR "huh, entered softirq %u %s %p"
77853@@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
77854 or_softirq_pending(1UL << nr);
77855 }
77856
77857-void open_softirq(int nr, void (*action)(struct softirq_action *))
77858+void __init open_softirq(int nr, void (*action)(void))
77859 {
77860 softirq_vec[nr].action = action;
77861 }
77862@@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
77863
77864 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
77865
77866-static void tasklet_action(struct softirq_action *a)
77867+static void tasklet_action(void)
77868 {
77869 struct tasklet_struct *list;
77870
77871@@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
77872 }
77873 }
77874
77875-static void tasklet_hi_action(struct softirq_action *a)
77876+static void tasklet_hi_action(void)
77877 {
77878 struct tasklet_struct *list;
77879
77880@@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
77881 return NOTIFY_OK;
77882 }
77883
77884-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
77885+static struct notifier_block remote_softirq_cpu_notifier = {
77886 .notifier_call = remote_softirq_cpu_notify,
77887 };
77888
77889@@ -835,11 +835,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
77890 return NOTIFY_OK;
77891 }
77892
77893-static struct notifier_block __cpuinitdata cpu_nfb = {
77894+static struct notifier_block cpu_nfb = {
77895 .notifier_call = cpu_callback
77896 };
77897
77898-static struct smp_hotplug_thread softirq_threads = {
77899+static struct smp_hotplug_thread softirq_threads __read_only = {
77900 .store = &ksoftirqd,
77901 .thread_should_run = ksoftirqd_should_run,
77902 .thread_fn = run_ksoftirqd,
77903diff --git a/kernel/srcu.c b/kernel/srcu.c
77904index 2b85982..d52ab26 100644
77905--- a/kernel/srcu.c
77906+++ b/kernel/srcu.c
77907@@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
77908 preempt_disable();
77909 idx = rcu_dereference_index_check(sp->completed,
77910 rcu_read_lock_sched_held()) & 0x1;
77911- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
77912+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
77913 smp_mb(); /* B */ /* Avoid leaking the critical section. */
77914- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
77915+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
77916 preempt_enable();
77917 return idx;
77918 }
77919@@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
77920 {
77921 preempt_disable();
77922 smp_mb(); /* C */ /* Avoid leaking the critical section. */
77923- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
77924+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
77925 preempt_enable();
77926 }
77927 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
77928diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
77929index 2f194e9..2c05ea9 100644
77930--- a/kernel/stop_machine.c
77931+++ b/kernel/stop_machine.c
77932@@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
77933 * cpu notifiers. It currently shares the same priority as sched
77934 * migration_notifier.
77935 */
77936-static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
77937+static struct notifier_block cpu_stop_cpu_notifier = {
77938 .notifier_call = cpu_stop_cpu_callback,
77939 .priority = 10,
77940 };
77941diff --git a/kernel/sys.c b/kernel/sys.c
77942index 265b376..4e42ef5 100644
77943--- a/kernel/sys.c
77944+++ b/kernel/sys.c
77945@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
77946 error = -EACCES;
77947 goto out;
77948 }
77949+
77950+ if (gr_handle_chroot_setpriority(p, niceval)) {
77951+ error = -EACCES;
77952+ goto out;
77953+ }
77954+
77955 no_nice = security_task_setnice(p, niceval);
77956 if (no_nice) {
77957 error = no_nice;
77958@@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
77959 goto error;
77960 }
77961
77962+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
77963+ goto error;
77964+
77965 if (rgid != (gid_t) -1 ||
77966 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
77967 new->sgid = new->egid;
77968@@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
77969 old = current_cred();
77970
77971 retval = -EPERM;
77972+
77973+ if (gr_check_group_change(kgid, kgid, kgid))
77974+ goto error;
77975+
77976 if (nsown_capable(CAP_SETGID))
77977 new->gid = new->egid = new->sgid = new->fsgid = kgid;
77978 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
77979@@ -647,7 +660,7 @@ error:
77980 /*
77981 * change the user struct in a credentials set to match the new UID
77982 */
77983-static int set_user(struct cred *new)
77984+int set_user(struct cred *new)
77985 {
77986 struct user_struct *new_user;
77987
77988@@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
77989 goto error;
77990 }
77991
77992+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
77993+ goto error;
77994+
77995 if (!uid_eq(new->uid, old->uid)) {
77996 retval = set_user(new);
77997 if (retval < 0)
77998@@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
77999 old = current_cred();
78000
78001 retval = -EPERM;
78002+
78003+ if (gr_check_crash_uid(kuid))
78004+ goto error;
78005+ if (gr_check_user_change(kuid, kuid, kuid))
78006+ goto error;
78007+
78008 if (nsown_capable(CAP_SETUID)) {
78009 new->suid = new->uid = kuid;
78010 if (!uid_eq(kuid, old->uid)) {
78011@@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
78012 goto error;
78013 }
78014
78015+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
78016+ goto error;
78017+
78018 if (ruid != (uid_t) -1) {
78019 new->uid = kruid;
78020 if (!uid_eq(kruid, old->uid)) {
78021@@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
78022 goto error;
78023 }
78024
78025+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
78026+ goto error;
78027+
78028 if (rgid != (gid_t) -1)
78029 new->gid = krgid;
78030 if (egid != (gid_t) -1)
78031@@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
78032 if (!uid_valid(kuid))
78033 return old_fsuid;
78034
78035+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
78036+ goto error;
78037+
78038 new = prepare_creds();
78039 if (!new)
78040 return old_fsuid;
78041@@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
78042 }
78043 }
78044
78045+error:
78046 abort_creds(new);
78047 return old_fsuid;
78048
78049@@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
78050 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
78051 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
78052 nsown_capable(CAP_SETGID)) {
78053+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
78054+ goto error;
78055+
78056 if (!gid_eq(kgid, old->fsgid)) {
78057 new->fsgid = kgid;
78058 goto change_okay;
78059 }
78060 }
78061
78062+error:
78063 abort_creds(new);
78064 return old_fsgid;
78065
78066@@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
78067 return -EFAULT;
78068
78069 down_read(&uts_sem);
78070- error = __copy_to_user(&name->sysname, &utsname()->sysname,
78071+ error = __copy_to_user(name->sysname, &utsname()->sysname,
78072 __OLD_UTS_LEN);
78073 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
78074- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
78075+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
78076 __OLD_UTS_LEN);
78077 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
78078- error |= __copy_to_user(&name->release, &utsname()->release,
78079+ error |= __copy_to_user(name->release, &utsname()->release,
78080 __OLD_UTS_LEN);
78081 error |= __put_user(0, name->release + __OLD_UTS_LEN);
78082- error |= __copy_to_user(&name->version, &utsname()->version,
78083+ error |= __copy_to_user(name->version, &utsname()->version,
78084 __OLD_UTS_LEN);
78085 error |= __put_user(0, name->version + __OLD_UTS_LEN);
78086- error |= __copy_to_user(&name->machine, &utsname()->machine,
78087+ error |= __copy_to_user(name->machine, &utsname()->machine,
78088 __OLD_UTS_LEN);
78089 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
78090 up_read(&uts_sem);
78091@@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
78092 error = get_dumpable(me->mm);
78093 break;
78094 case PR_SET_DUMPABLE:
78095- if (arg2 < 0 || arg2 > 1) {
78096+ if (arg2 > 1) {
78097 error = -EINVAL;
78098 break;
78099 }
78100diff --git a/kernel/sysctl.c b/kernel/sysctl.c
78101index c88878d..e4fa5d1 100644
78102--- a/kernel/sysctl.c
78103+++ b/kernel/sysctl.c
78104@@ -92,7 +92,6 @@
78105
78106
78107 #if defined(CONFIG_SYSCTL)
78108-
78109 /* External variables not in a header file. */
78110 extern int sysctl_overcommit_memory;
78111 extern int sysctl_overcommit_ratio;
78112@@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
78113 void __user *buffer, size_t *lenp, loff_t *ppos);
78114 #endif
78115
78116-#ifdef CONFIG_PRINTK
78117 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
78118 void __user *buffer, size_t *lenp, loff_t *ppos);
78119-#endif
78120
78121 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
78122 void __user *buffer, size_t *lenp, loff_t *ppos);
78123@@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
78124
78125 #endif
78126
78127+extern struct ctl_table grsecurity_table[];
78128+
78129 static struct ctl_table kern_table[];
78130 static struct ctl_table vm_table[];
78131 static struct ctl_table fs_table[];
78132@@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
78133 int sysctl_legacy_va_layout;
78134 #endif
78135
78136+#ifdef CONFIG_PAX_SOFTMODE
78137+static ctl_table pax_table[] = {
78138+ {
78139+ .procname = "softmode",
78140+ .data = &pax_softmode,
78141+ .maxlen = sizeof(unsigned int),
78142+ .mode = 0600,
78143+ .proc_handler = &proc_dointvec,
78144+ },
78145+
78146+ { }
78147+};
78148+#endif
78149+
78150 /* The default sysctl tables: */
78151
78152 static struct ctl_table sysctl_base_table[] = {
78153@@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
78154 #endif
78155
78156 static struct ctl_table kern_table[] = {
78157+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
78158+ {
78159+ .procname = "grsecurity",
78160+ .mode = 0500,
78161+ .child = grsecurity_table,
78162+ },
78163+#endif
78164+
78165+#ifdef CONFIG_PAX_SOFTMODE
78166+ {
78167+ .procname = "pax",
78168+ .mode = 0500,
78169+ .child = pax_table,
78170+ },
78171+#endif
78172+
78173 {
78174 .procname = "sched_child_runs_first",
78175 .data = &sysctl_sched_child_runs_first,
78176@@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
78177 .data = &modprobe_path,
78178 .maxlen = KMOD_PATH_LEN,
78179 .mode = 0644,
78180- .proc_handler = proc_dostring,
78181+ .proc_handler = proc_dostring_modpriv,
78182 },
78183 {
78184 .procname = "modules_disabled",
78185@@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
78186 .extra1 = &zero,
78187 .extra2 = &one,
78188 },
78189+#endif
78190 {
78191 .procname = "kptr_restrict",
78192 .data = &kptr_restrict,
78193 .maxlen = sizeof(int),
78194 .mode = 0644,
78195 .proc_handler = proc_dointvec_minmax_sysadmin,
78196+#ifdef CONFIG_GRKERNSEC_HIDESYM
78197+ .extra1 = &two,
78198+#else
78199 .extra1 = &zero,
78200+#endif
78201 .extra2 = &two,
78202 },
78203-#endif
78204 {
78205 .procname = "ngroups_max",
78206 .data = &ngroups_max,
78207@@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
78208 .proc_handler = proc_dointvec_minmax,
78209 .extra1 = &zero,
78210 },
78211+ {
78212+ .procname = "heap_stack_gap",
78213+ .data = &sysctl_heap_stack_gap,
78214+ .maxlen = sizeof(sysctl_heap_stack_gap),
78215+ .mode = 0644,
78216+ .proc_handler = proc_doulongvec_minmax,
78217+ },
78218 #else
78219 {
78220 .procname = "nr_trim_pages",
78221@@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
78222 buffer, lenp, ppos);
78223 }
78224
78225+int proc_dostring_modpriv(struct ctl_table *table, int write,
78226+ void __user *buffer, size_t *lenp, loff_t *ppos)
78227+{
78228+ if (write && !capable(CAP_SYS_MODULE))
78229+ return -EPERM;
78230+
78231+ return _proc_do_string(table->data, table->maxlen, write,
78232+ buffer, lenp, ppos);
78233+}
78234+
78235 static size_t proc_skip_spaces(char **buf)
78236 {
78237 size_t ret;
78238@@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
78239 len = strlen(tmp);
78240 if (len > *size)
78241 len = *size;
78242+ if (len > sizeof(tmp))
78243+ len = sizeof(tmp);
78244 if (copy_to_user(*buf, tmp, len))
78245 return -EFAULT;
78246 *size -= len;
78247@@ -1985,7 +2037,7 @@ int proc_dointvec(struct ctl_table *table, int write,
78248 static int proc_taint(struct ctl_table *table, int write,
78249 void __user *buffer, size_t *lenp, loff_t *ppos)
78250 {
78251- struct ctl_table t;
78252+ ctl_table_no_const t;
78253 unsigned long tmptaint = get_taint();
78254 int err;
78255
78256@@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
78257 return err;
78258 }
78259
78260-#ifdef CONFIG_PRINTK
78261 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
78262 void __user *buffer, size_t *lenp, loff_t *ppos)
78263 {
78264@@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
78265
78266 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
78267 }
78268-#endif
78269
78270 struct do_proc_dointvec_minmax_conv_param {
78271 int *min;
78272@@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
78273 *i = val;
78274 } else {
78275 val = convdiv * (*i) / convmul;
78276- if (!first)
78277+ if (!first) {
78278 err = proc_put_char(&buffer, &left, '\t');
78279+ if (err)
78280+ break;
78281+ }
78282 err = proc_put_long(&buffer, &left, val, false);
78283 if (err)
78284 break;
78285@@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
78286 return -ENOSYS;
78287 }
78288
78289+int proc_dostring_modpriv(struct ctl_table *table, int write,
78290+ void __user *buffer, size_t *lenp, loff_t *ppos)
78291+{
78292+ return -ENOSYS;
78293+}
78294+
78295 int proc_dointvec(struct ctl_table *table, int write,
78296 void __user *buffer, size_t *lenp, loff_t *ppos)
78297 {
78298@@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
78299 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
78300 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
78301 EXPORT_SYMBOL(proc_dostring);
78302+EXPORT_SYMBOL(proc_dostring_modpriv);
78303 EXPORT_SYMBOL(proc_doulongvec_minmax);
78304 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
78305diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
78306index 0ddf3a0..a199f50 100644
78307--- a/kernel/sysctl_binary.c
78308+++ b/kernel/sysctl_binary.c
78309@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
78310 int i;
78311
78312 set_fs(KERNEL_DS);
78313- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
78314+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
78315 set_fs(old_fs);
78316 if (result < 0)
78317 goto out_kfree;
78318@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
78319 }
78320
78321 set_fs(KERNEL_DS);
78322- result = vfs_write(file, buffer, str - buffer, &pos);
78323+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
78324 set_fs(old_fs);
78325 if (result < 0)
78326 goto out_kfree;
78327@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
78328 int i;
78329
78330 set_fs(KERNEL_DS);
78331- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
78332+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
78333 set_fs(old_fs);
78334 if (result < 0)
78335 goto out_kfree;
78336@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
78337 }
78338
78339 set_fs(KERNEL_DS);
78340- result = vfs_write(file, buffer, str - buffer, &pos);
78341+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
78342 set_fs(old_fs);
78343 if (result < 0)
78344 goto out_kfree;
78345@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
78346 int i;
78347
78348 set_fs(KERNEL_DS);
78349- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
78350+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
78351 set_fs(old_fs);
78352 if (result < 0)
78353 goto out;
78354@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
78355 __le16 dnaddr;
78356
78357 set_fs(KERNEL_DS);
78358- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
78359+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
78360 set_fs(old_fs);
78361 if (result < 0)
78362 goto out;
78363@@ -1234,7 +1234,7 @@ static ssize_t bin_dn_node_address(struct file *file,
78364 le16_to_cpu(dnaddr) & 0x3ff);
78365
78366 set_fs(KERNEL_DS);
78367- result = vfs_write(file, buf, len, &pos);
78368+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
78369 set_fs(old_fs);
78370 if (result < 0)
78371 goto out;
78372diff --git a/kernel/taskstats.c b/kernel/taskstats.c
78373index 145bb4d..b2aa969 100644
78374--- a/kernel/taskstats.c
78375+++ b/kernel/taskstats.c
78376@@ -28,9 +28,12 @@
78377 #include <linux/fs.h>
78378 #include <linux/file.h>
78379 #include <linux/pid_namespace.h>
78380+#include <linux/grsecurity.h>
78381 #include <net/genetlink.h>
78382 #include <linux/atomic.h>
78383
78384+extern int gr_is_taskstats_denied(int pid);
78385+
78386 /*
78387 * Maximum length of a cpumask that can be specified in
78388 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
78389@@ -570,6 +573,9 @@ err:
78390
78391 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
78392 {
78393+ if (gr_is_taskstats_denied(current->pid))
78394+ return -EACCES;
78395+
78396 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
78397 return cmd_attr_register_cpumask(info);
78398 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
78399diff --git a/kernel/time.c b/kernel/time.c
78400index d226c6a..2f0d217 100644
78401--- a/kernel/time.c
78402+++ b/kernel/time.c
78403@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
78404 return error;
78405
78406 if (tz) {
78407+ /* we log in do_settimeofday called below, so don't log twice
78408+ */
78409+ if (!tv)
78410+ gr_log_timechange();
78411+
78412 sys_tz = *tz;
78413 update_vsyscall_tz();
78414 if (firsttime) {
78415@@ -493,7 +498,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
78416 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
78417 * value to a scaled second value.
78418 */
78419-unsigned long
78420+unsigned long __intentional_overflow(-1)
78421 timespec_to_jiffies(const struct timespec *value)
78422 {
78423 unsigned long sec = value->tv_sec;
78424diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
78425index f11d83b..d016d91 100644
78426--- a/kernel/time/alarmtimer.c
78427+++ b/kernel/time/alarmtimer.c
78428@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
78429 struct platform_device *pdev;
78430 int error = 0;
78431 int i;
78432- struct k_clock alarm_clock = {
78433+ static struct k_clock alarm_clock = {
78434 .clock_getres = alarm_clock_getres,
78435 .clock_get = alarm_clock_get,
78436 .timer_create = alarm_timer_create,
78437diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
78438index a13987a..36cd791 100644
78439--- a/kernel/time/tick-broadcast.c
78440+++ b/kernel/time/tick-broadcast.c
78441@@ -116,7 +116,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
78442 * then clear the broadcast bit.
78443 */
78444 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
78445- int cpu = smp_processor_id();
78446+ cpu = smp_processor_id();
78447
78448 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
78449 tick_broadcast_clear_oneshot(cpu);
78450diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
78451index cbc6acb..3a77191 100644
78452--- a/kernel/time/timekeeping.c
78453+++ b/kernel/time/timekeeping.c
78454@@ -15,6 +15,7 @@
78455 #include <linux/init.h>
78456 #include <linux/mm.h>
78457 #include <linux/sched.h>
78458+#include <linux/grsecurity.h>
78459 #include <linux/syscore_ops.h>
78460 #include <linux/clocksource.h>
78461 #include <linux/jiffies.h>
78462@@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
78463 if (!timespec_valid_strict(tv))
78464 return -EINVAL;
78465
78466+ gr_log_timechange();
78467+
78468 write_seqlock_irqsave(&tk->lock, flags);
78469
78470 timekeeping_forward_now(tk);
78471diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
78472index af5a7e9..715611a 100644
78473--- a/kernel/time/timer_list.c
78474+++ b/kernel/time/timer_list.c
78475@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
78476
78477 static void print_name_offset(struct seq_file *m, void *sym)
78478 {
78479+#ifdef CONFIG_GRKERNSEC_HIDESYM
78480+ SEQ_printf(m, "<%p>", NULL);
78481+#else
78482 char symname[KSYM_NAME_LEN];
78483
78484 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
78485 SEQ_printf(m, "<%pK>", sym);
78486 else
78487 SEQ_printf(m, "%s", symname);
78488+#endif
78489 }
78490
78491 static void
78492@@ -112,7 +116,11 @@ next_one:
78493 static void
78494 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
78495 {
78496+#ifdef CONFIG_GRKERNSEC_HIDESYM
78497+ SEQ_printf(m, " .base: %p\n", NULL);
78498+#else
78499 SEQ_printf(m, " .base: %pK\n", base);
78500+#endif
78501 SEQ_printf(m, " .index: %d\n",
78502 base->index);
78503 SEQ_printf(m, " .resolution: %Lu nsecs\n",
78504@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
78505 {
78506 struct proc_dir_entry *pe;
78507
78508+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78509+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
78510+#else
78511 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
78512+#endif
78513 if (!pe)
78514 return -ENOMEM;
78515 return 0;
78516diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
78517index 0b537f2..40d6c20 100644
78518--- a/kernel/time/timer_stats.c
78519+++ b/kernel/time/timer_stats.c
78520@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
78521 static unsigned long nr_entries;
78522 static struct entry entries[MAX_ENTRIES];
78523
78524-static atomic_t overflow_count;
78525+static atomic_unchecked_t overflow_count;
78526
78527 /*
78528 * The entries are in a hash-table, for fast lookup:
78529@@ -140,7 +140,7 @@ static void reset_entries(void)
78530 nr_entries = 0;
78531 memset(entries, 0, sizeof(entries));
78532 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
78533- atomic_set(&overflow_count, 0);
78534+ atomic_set_unchecked(&overflow_count, 0);
78535 }
78536
78537 static struct entry *alloc_entry(void)
78538@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
78539 if (likely(entry))
78540 entry->count++;
78541 else
78542- atomic_inc(&overflow_count);
78543+ atomic_inc_unchecked(&overflow_count);
78544
78545 out_unlock:
78546 raw_spin_unlock_irqrestore(lock, flags);
78547@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
78548
78549 static void print_name_offset(struct seq_file *m, unsigned long addr)
78550 {
78551+#ifdef CONFIG_GRKERNSEC_HIDESYM
78552+ seq_printf(m, "<%p>", NULL);
78553+#else
78554 char symname[KSYM_NAME_LEN];
78555
78556 if (lookup_symbol_name(addr, symname) < 0)
78557- seq_printf(m, "<%p>", (void *)addr);
78558+ seq_printf(m, "<%pK>", (void *)addr);
78559 else
78560 seq_printf(m, "%s", symname);
78561+#endif
78562 }
78563
78564 static int tstats_show(struct seq_file *m, void *v)
78565@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
78566
78567 seq_puts(m, "Timer Stats Version: v0.2\n");
78568 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
78569- if (atomic_read(&overflow_count))
78570+ if (atomic_read_unchecked(&overflow_count))
78571 seq_printf(m, "Overflow: %d entries\n",
78572- atomic_read(&overflow_count));
78573+ atomic_read_unchecked(&overflow_count));
78574
78575 for (i = 0; i < nr_entries; i++) {
78576 entry = entries + i;
78577@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
78578 {
78579 struct proc_dir_entry *pe;
78580
78581+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78582+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
78583+#else
78584 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
78585+#endif
78586 if (!pe)
78587 return -ENOMEM;
78588 return 0;
78589diff --git a/kernel/timer.c b/kernel/timer.c
78590index 367d008..5dee98f 100644
78591--- a/kernel/timer.c
78592+++ b/kernel/timer.c
78593@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
78594 /*
78595 * This function runs timers and the timer-tq in bottom half context.
78596 */
78597-static void run_timer_softirq(struct softirq_action *h)
78598+static void run_timer_softirq(void)
78599 {
78600 struct tvec_base *base = __this_cpu_read(tvec_bases);
78601
78602@@ -1481,7 +1481,7 @@ static void process_timeout(unsigned long __data)
78603 *
78604 * In all cases the return value is guaranteed to be non-negative.
78605 */
78606-signed long __sched schedule_timeout(signed long timeout)
78607+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
78608 {
78609 struct timer_list timer;
78610 unsigned long expire;
78611@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
78612 return NOTIFY_OK;
78613 }
78614
78615-static struct notifier_block __cpuinitdata timers_nb = {
78616+static struct notifier_block timers_nb = {
78617 .notifier_call = timer_cpu_notify,
78618 };
78619
78620diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
78621index c0bd030..62a1927 100644
78622--- a/kernel/trace/blktrace.c
78623+++ b/kernel/trace/blktrace.c
78624@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
78625 struct blk_trace *bt = filp->private_data;
78626 char buf[16];
78627
78628- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
78629+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
78630
78631 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
78632 }
78633@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
78634 return 1;
78635
78636 bt = buf->chan->private_data;
78637- atomic_inc(&bt->dropped);
78638+ atomic_inc_unchecked(&bt->dropped);
78639 return 0;
78640 }
78641
78642@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
78643
78644 bt->dir = dir;
78645 bt->dev = dev;
78646- atomic_set(&bt->dropped, 0);
78647+ atomic_set_unchecked(&bt->dropped, 0);
78648
78649 ret = -EIO;
78650 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
78651diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
78652index b27052c..0e1af95 100644
78653--- a/kernel/trace/ftrace.c
78654+++ b/kernel/trace/ftrace.c
78655@@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
78656 if (unlikely(ftrace_disabled))
78657 return 0;
78658
78659+ ret = ftrace_arch_code_modify_prepare();
78660+ FTRACE_WARN_ON(ret);
78661+ if (ret)
78662+ return 0;
78663+
78664 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
78665+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
78666 if (ret) {
78667 ftrace_bug(ret, ip);
78668- return 0;
78669 }
78670- return 1;
78671+ return ret ? 0 : 1;
78672 }
78673
78674 /*
78675@@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
78676
78677 int
78678 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
78679- void *data)
78680+ void *data)
78681 {
78682 struct ftrace_func_probe *entry;
78683 struct ftrace_page *pg;
78684@@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
78685 if (!count)
78686 return 0;
78687
78688+ pax_open_kernel();
78689 sort(start, count, sizeof(*start),
78690 ftrace_cmp_ips, ftrace_swap_ips);
78691+ pax_close_kernel();
78692
78693 start_pg = ftrace_allocate_pages(count);
78694 if (!start_pg)
78695@@ -4559,8 +4566,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
78696 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
78697
78698 static int ftrace_graph_active;
78699-static struct notifier_block ftrace_suspend_notifier;
78700-
78701 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
78702 {
78703 return 0;
78704@@ -4704,6 +4709,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
78705 return NOTIFY_DONE;
78706 }
78707
78708+static struct notifier_block ftrace_suspend_notifier = {
78709+ .notifier_call = ftrace_suspend_notifier_call
78710+};
78711+
78712 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
78713 trace_func_graph_ent_t entryfunc)
78714 {
78715@@ -4717,7 +4726,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
78716 goto out;
78717 }
78718
78719- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
78720 register_pm_notifier(&ftrace_suspend_notifier);
78721
78722 ftrace_graph_active++;
78723diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
78724index ce8514f..8233573 100644
78725--- a/kernel/trace/ring_buffer.c
78726+++ b/kernel/trace/ring_buffer.c
78727@@ -346,9 +346,9 @@ struct buffer_data_page {
78728 */
78729 struct buffer_page {
78730 struct list_head list; /* list of buffer pages */
78731- local_t write; /* index for next write */
78732+ local_unchecked_t write; /* index for next write */
78733 unsigned read; /* index for next read */
78734- local_t entries; /* entries on this page */
78735+ local_unchecked_t entries; /* entries on this page */
78736 unsigned long real_end; /* real end of data */
78737 struct buffer_data_page *page; /* Actual data page */
78738 };
78739@@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
78740 unsigned long last_overrun;
78741 local_t entries_bytes;
78742 local_t entries;
78743- local_t overrun;
78744- local_t commit_overrun;
78745+ local_unchecked_t overrun;
78746+ local_unchecked_t commit_overrun;
78747 local_t dropped_events;
78748 local_t committing;
78749 local_t commits;
78750@@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
78751 *
78752 * We add a counter to the write field to denote this.
78753 */
78754- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
78755- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
78756+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
78757+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
78758
78759 /*
78760 * Just make sure we have seen our old_write and synchronize
78761@@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
78762 * cmpxchg to only update if an interrupt did not already
78763 * do it for us. If the cmpxchg fails, we don't care.
78764 */
78765- (void)local_cmpxchg(&next_page->write, old_write, val);
78766- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
78767+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
78768+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
78769
78770 /*
78771 * No need to worry about races with clearing out the commit.
78772@@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
78773
78774 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
78775 {
78776- return local_read(&bpage->entries) & RB_WRITE_MASK;
78777+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
78778 }
78779
78780 static inline unsigned long rb_page_write(struct buffer_page *bpage)
78781 {
78782- return local_read(&bpage->write) & RB_WRITE_MASK;
78783+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
78784 }
78785
78786 static int
78787@@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
78788 * bytes consumed in ring buffer from here.
78789 * Increment overrun to account for the lost events.
78790 */
78791- local_add(page_entries, &cpu_buffer->overrun);
78792+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
78793 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
78794 }
78795
78796@@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
78797 * it is our responsibility to update
78798 * the counters.
78799 */
78800- local_add(entries, &cpu_buffer->overrun);
78801+ local_add_unchecked(entries, &cpu_buffer->overrun);
78802 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
78803
78804 /*
78805@@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
78806 if (tail == BUF_PAGE_SIZE)
78807 tail_page->real_end = 0;
78808
78809- local_sub(length, &tail_page->write);
78810+ local_sub_unchecked(length, &tail_page->write);
78811 return;
78812 }
78813
78814@@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
78815 rb_event_set_padding(event);
78816
78817 /* Set the write back to the previous setting */
78818- local_sub(length, &tail_page->write);
78819+ local_sub_unchecked(length, &tail_page->write);
78820 return;
78821 }
78822
78823@@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
78824
78825 /* Set write to end of buffer */
78826 length = (tail + length) - BUF_PAGE_SIZE;
78827- local_sub(length, &tail_page->write);
78828+ local_sub_unchecked(length, &tail_page->write);
78829 }
78830
78831 /*
78832@@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
78833 * about it.
78834 */
78835 if (unlikely(next_page == commit_page)) {
78836- local_inc(&cpu_buffer->commit_overrun);
78837+ local_inc_unchecked(&cpu_buffer->commit_overrun);
78838 goto out_reset;
78839 }
78840
78841@@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
78842 cpu_buffer->tail_page) &&
78843 (cpu_buffer->commit_page ==
78844 cpu_buffer->reader_page))) {
78845- local_inc(&cpu_buffer->commit_overrun);
78846+ local_inc_unchecked(&cpu_buffer->commit_overrun);
78847 goto out_reset;
78848 }
78849 }
78850@@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
78851 length += RB_LEN_TIME_EXTEND;
78852
78853 tail_page = cpu_buffer->tail_page;
78854- write = local_add_return(length, &tail_page->write);
78855+ write = local_add_return_unchecked(length, &tail_page->write);
78856
78857 /* set write to only the index of the write */
78858 write &= RB_WRITE_MASK;
78859@@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
78860 kmemcheck_annotate_bitfield(event, bitfield);
78861 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
78862
78863- local_inc(&tail_page->entries);
78864+ local_inc_unchecked(&tail_page->entries);
78865
78866 /*
78867 * If this is the first commit on the page, then update
78868@@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
78869
78870 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
78871 unsigned long write_mask =
78872- local_read(&bpage->write) & ~RB_WRITE_MASK;
78873+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
78874 unsigned long event_length = rb_event_length(event);
78875 /*
78876 * This is on the tail page. It is possible that
78877@@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
78878 */
78879 old_index += write_mask;
78880 new_index += write_mask;
78881- index = local_cmpxchg(&bpage->write, old_index, new_index);
78882+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
78883 if (index == old_index) {
78884 /* update counters */
78885 local_sub(event_length, &cpu_buffer->entries_bytes);
78886@@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
78887
78888 /* Do the likely case first */
78889 if (likely(bpage->page == (void *)addr)) {
78890- local_dec(&bpage->entries);
78891+ local_dec_unchecked(&bpage->entries);
78892 return;
78893 }
78894
78895@@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
78896 start = bpage;
78897 do {
78898 if (bpage->page == (void *)addr) {
78899- local_dec(&bpage->entries);
78900+ local_dec_unchecked(&bpage->entries);
78901 return;
78902 }
78903 rb_inc_page(cpu_buffer, &bpage);
78904@@ -2926,7 +2926,7 @@ static inline unsigned long
78905 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
78906 {
78907 return local_read(&cpu_buffer->entries) -
78908- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
78909+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
78910 }
78911
78912 /**
78913@@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
78914 return 0;
78915
78916 cpu_buffer = buffer->buffers[cpu];
78917- ret = local_read(&cpu_buffer->overrun);
78918+ ret = local_read_unchecked(&cpu_buffer->overrun);
78919
78920 return ret;
78921 }
78922@@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
78923 return 0;
78924
78925 cpu_buffer = buffer->buffers[cpu];
78926- ret = local_read(&cpu_buffer->commit_overrun);
78927+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
78928
78929 return ret;
78930 }
78931@@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
78932 /* if you care about this being correct, lock the buffer */
78933 for_each_buffer_cpu(buffer, cpu) {
78934 cpu_buffer = buffer->buffers[cpu];
78935- overruns += local_read(&cpu_buffer->overrun);
78936+ overruns += local_read_unchecked(&cpu_buffer->overrun);
78937 }
78938
78939 return overruns;
78940@@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
78941 /*
78942 * Reset the reader page to size zero.
78943 */
78944- local_set(&cpu_buffer->reader_page->write, 0);
78945- local_set(&cpu_buffer->reader_page->entries, 0);
78946+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
78947+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
78948 local_set(&cpu_buffer->reader_page->page->commit, 0);
78949 cpu_buffer->reader_page->real_end = 0;
78950
78951@@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
78952 * want to compare with the last_overrun.
78953 */
78954 smp_mb();
78955- overwrite = local_read(&(cpu_buffer->overrun));
78956+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
78957
78958 /*
78959 * Here's the tricky part.
78960@@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
78961
78962 cpu_buffer->head_page
78963 = list_entry(cpu_buffer->pages, struct buffer_page, list);
78964- local_set(&cpu_buffer->head_page->write, 0);
78965- local_set(&cpu_buffer->head_page->entries, 0);
78966+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
78967+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
78968 local_set(&cpu_buffer->head_page->page->commit, 0);
78969
78970 cpu_buffer->head_page->read = 0;
78971@@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
78972
78973 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
78974 INIT_LIST_HEAD(&cpu_buffer->new_pages);
78975- local_set(&cpu_buffer->reader_page->write, 0);
78976- local_set(&cpu_buffer->reader_page->entries, 0);
78977+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
78978+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
78979 local_set(&cpu_buffer->reader_page->page->commit, 0);
78980 cpu_buffer->reader_page->read = 0;
78981
78982 local_set(&cpu_buffer->entries_bytes, 0);
78983- local_set(&cpu_buffer->overrun, 0);
78984- local_set(&cpu_buffer->commit_overrun, 0);
78985+ local_set_unchecked(&cpu_buffer->overrun, 0);
78986+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
78987 local_set(&cpu_buffer->dropped_events, 0);
78988 local_set(&cpu_buffer->entries, 0);
78989 local_set(&cpu_buffer->committing, 0);
78990@@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
78991 rb_init_page(bpage);
78992 bpage = reader->page;
78993 reader->page = *data_page;
78994- local_set(&reader->write, 0);
78995- local_set(&reader->entries, 0);
78996+ local_set_unchecked(&reader->write, 0);
78997+ local_set_unchecked(&reader->entries, 0);
78998 reader->read = 0;
78999 *data_page = bpage;
79000
79001diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
79002index 2ffbc24..76105a2 100644
79003--- a/kernel/trace/trace.c
79004+++ b/kernel/trace/trace.c
79005@@ -4471,10 +4471,9 @@ static const struct file_operations tracing_dyn_info_fops = {
79006 };
79007 #endif
79008
79009-static struct dentry *d_tracer;
79010-
79011 struct dentry *tracing_init_dentry(void)
79012 {
79013+ static struct dentry *d_tracer;
79014 static int once;
79015
79016 if (d_tracer)
79017@@ -4494,10 +4493,9 @@ struct dentry *tracing_init_dentry(void)
79018 return d_tracer;
79019 }
79020
79021-static struct dentry *d_percpu;
79022-
79023 struct dentry *tracing_dentry_percpu(void)
79024 {
79025+ static struct dentry *d_percpu;
79026 static int once;
79027 struct dentry *d_tracer;
79028
79029diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
79030index 880073d..42db7c3 100644
79031--- a/kernel/trace/trace_events.c
79032+++ b/kernel/trace/trace_events.c
79033@@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
79034 struct ftrace_module_file_ops {
79035 struct list_head list;
79036 struct module *mod;
79037- struct file_operations id;
79038- struct file_operations enable;
79039- struct file_operations format;
79040- struct file_operations filter;
79041 };
79042
79043 static struct ftrace_module_file_ops *
79044@@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
79045
79046 file_ops->mod = mod;
79047
79048- file_ops->id = ftrace_event_id_fops;
79049- file_ops->id.owner = mod;
79050-
79051- file_ops->enable = ftrace_enable_fops;
79052- file_ops->enable.owner = mod;
79053-
79054- file_ops->filter = ftrace_event_filter_fops;
79055- file_ops->filter.owner = mod;
79056-
79057- file_ops->format = ftrace_event_format_fops;
79058- file_ops->format.owner = mod;
79059+ pax_open_kernel();
79060+ mod->trace_id.owner = mod;
79061+ mod->trace_enable.owner = mod;
79062+ mod->trace_filter.owner = mod;
79063+ mod->trace_format.owner = mod;
79064+ pax_close_kernel();
79065
79066 list_add(&file_ops->list, &ftrace_module_file_list);
79067
79068@@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
79069
79070 for_each_event(call, start, end) {
79071 __trace_add_event_call(*call, mod,
79072- &file_ops->id, &file_ops->enable,
79073- &file_ops->filter, &file_ops->format);
79074+ &mod->trace_id, &mod->trace_enable,
79075+ &mod->trace_filter, &mod->trace_format);
79076 }
79077 }
79078
79079diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
79080index fd3c8aa..5f324a6 100644
79081--- a/kernel/trace/trace_mmiotrace.c
79082+++ b/kernel/trace/trace_mmiotrace.c
79083@@ -24,7 +24,7 @@ struct header_iter {
79084 static struct trace_array *mmio_trace_array;
79085 static bool overrun_detected;
79086 static unsigned long prev_overruns;
79087-static atomic_t dropped_count;
79088+static atomic_unchecked_t dropped_count;
79089
79090 static void mmio_reset_data(struct trace_array *tr)
79091 {
79092@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
79093
79094 static unsigned long count_overruns(struct trace_iterator *iter)
79095 {
79096- unsigned long cnt = atomic_xchg(&dropped_count, 0);
79097+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
79098 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
79099
79100 if (over > prev_overruns)
79101@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
79102 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
79103 sizeof(*entry), 0, pc);
79104 if (!event) {
79105- atomic_inc(&dropped_count);
79106+ atomic_inc_unchecked(&dropped_count);
79107 return;
79108 }
79109 entry = ring_buffer_event_data(event);
79110@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
79111 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
79112 sizeof(*entry), 0, pc);
79113 if (!event) {
79114- atomic_inc(&dropped_count);
79115+ atomic_inc_unchecked(&dropped_count);
79116 return;
79117 }
79118 entry = ring_buffer_event_data(event);
79119diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
79120index 194d796..76edb8f 100644
79121--- a/kernel/trace/trace_output.c
79122+++ b/kernel/trace/trace_output.c
79123@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
79124
79125 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
79126 if (!IS_ERR(p)) {
79127- p = mangle_path(s->buffer + s->len, p, "\n");
79128+ p = mangle_path(s->buffer + s->len, p, "\n\\");
79129 if (p) {
79130 s->len = p - s->buffer;
79131 return 1;
79132@@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
79133 goto out;
79134 }
79135
79136+ pax_open_kernel();
79137 if (event->funcs->trace == NULL)
79138- event->funcs->trace = trace_nop_print;
79139+ *(void **)&event->funcs->trace = trace_nop_print;
79140 if (event->funcs->raw == NULL)
79141- event->funcs->raw = trace_nop_print;
79142+ *(void **)&event->funcs->raw = trace_nop_print;
79143 if (event->funcs->hex == NULL)
79144- event->funcs->hex = trace_nop_print;
79145+ *(void **)&event->funcs->hex = trace_nop_print;
79146 if (event->funcs->binary == NULL)
79147- event->funcs->binary = trace_nop_print;
79148+ *(void **)&event->funcs->binary = trace_nop_print;
79149+ pax_close_kernel();
79150
79151 key = event->type & (EVENT_HASHSIZE - 1);
79152
79153diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
79154index 42ca822..cdcacc6 100644
79155--- a/kernel/trace/trace_stack.c
79156+++ b/kernel/trace/trace_stack.c
79157@@ -52,7 +52,7 @@ static inline void check_stack(void)
79158 return;
79159
79160 /* we do not handle interrupt stacks yet */
79161- if (!object_is_on_stack(&this_size))
79162+ if (!object_starts_on_stack(&this_size))
79163 return;
79164
79165 local_irq_save(flags);
79166diff --git a/kernel/user.c b/kernel/user.c
79167index 33acb5e..57ebfd4 100644
79168--- a/kernel/user.c
79169+++ b/kernel/user.c
79170@@ -47,9 +47,7 @@ struct user_namespace init_user_ns = {
79171 .count = 4294967295U,
79172 },
79173 },
79174- .kref = {
79175- .refcount = ATOMIC_INIT(3),
79176- },
79177+ .count = ATOMIC_INIT(3),
79178 .owner = GLOBAL_ROOT_UID,
79179 .group = GLOBAL_ROOT_GID,
79180 .proc_inum = PROC_USER_INIT_INO,
79181diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
79182index dbfe36a7..2a3c1df 100644
79183--- a/kernel/user_namespace.c
79184+++ b/kernel/user_namespace.c
79185@@ -79,7 +79,7 @@ int create_user_ns(struct cred *new)
79186 return ret;
79187 }
79188
79189- kref_init(&ns->kref);
79190+ atomic_set(&ns->count, 1);
79191 /* Leave the new->user_ns reference with the new user namespace. */
79192 ns->parent = parent_ns;
79193 ns->owner = owner;
79194@@ -105,15 +105,16 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
79195 return create_user_ns(cred);
79196 }
79197
79198-void free_user_ns(struct kref *kref)
79199+void free_user_ns(struct user_namespace *ns)
79200 {
79201- struct user_namespace *parent, *ns =
79202- container_of(kref, struct user_namespace, kref);
79203+ struct user_namespace *parent;
79204
79205- parent = ns->parent;
79206- proc_free_inum(ns->proc_inum);
79207- kmem_cache_free(user_ns_cachep, ns);
79208- put_user_ns(parent);
79209+ do {
79210+ parent = ns->parent;
79211+ proc_free_inum(ns->proc_inum);
79212+ kmem_cache_free(user_ns_cachep, ns);
79213+ ns = parent;
79214+ } while (atomic_dec_and_test(&parent->count));
79215 }
79216 EXPORT_SYMBOL(free_user_ns);
79217
79218@@ -804,7 +805,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
79219 if (atomic_read(&current->mm->mm_users) > 1)
79220 return -EINVAL;
79221
79222- if (current->fs->users != 1)
79223+ if (atomic_read(&current->fs->users) != 1)
79224 return -EINVAL;
79225
79226 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
79227diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
79228index 63da38c..639904e 100644
79229--- a/kernel/utsname_sysctl.c
79230+++ b/kernel/utsname_sysctl.c
79231@@ -46,7 +46,7 @@ static void put_uts(ctl_table *table, int write, void *which)
79232 static int proc_do_uts_string(ctl_table *table, int write,
79233 void __user *buffer, size_t *lenp, loff_t *ppos)
79234 {
79235- struct ctl_table uts_table;
79236+ ctl_table_no_const uts_table;
79237 int r;
79238 memcpy(&uts_table, table, sizeof(uts_table));
79239 uts_table.data = get_uts(table, write);
79240diff --git a/kernel/watchdog.c b/kernel/watchdog.c
79241index 75a2ab3..5961da7 100644
79242--- a/kernel/watchdog.c
79243+++ b/kernel/watchdog.c
79244@@ -527,7 +527,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
79245 }
79246 #endif /* CONFIG_SYSCTL */
79247
79248-static struct smp_hotplug_thread watchdog_threads = {
79249+static struct smp_hotplug_thread watchdog_threads __read_only = {
79250 .store = &softlockup_watchdog,
79251 .thread_should_run = watchdog_should_run,
79252 .thread_fn = watchdog,
79253diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
79254index 67604e5..fe94fb1 100644
79255--- a/lib/Kconfig.debug
79256+++ b/lib/Kconfig.debug
79257@@ -550,7 +550,7 @@ config DEBUG_MUTEXES
79258
79259 config DEBUG_LOCK_ALLOC
79260 bool "Lock debugging: detect incorrect freeing of live locks"
79261- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79262+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79263 select DEBUG_SPINLOCK
79264 select DEBUG_MUTEXES
79265 select LOCKDEP
79266@@ -564,7 +564,7 @@ config DEBUG_LOCK_ALLOC
79267
79268 config PROVE_LOCKING
79269 bool "Lock debugging: prove locking correctness"
79270- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79271+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79272 select LOCKDEP
79273 select DEBUG_SPINLOCK
79274 select DEBUG_MUTEXES
79275@@ -670,7 +670,7 @@ config LOCKDEP
79276
79277 config LOCK_STAT
79278 bool "Lock usage statistics"
79279- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79280+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79281 select LOCKDEP
79282 select DEBUG_SPINLOCK
79283 select DEBUG_MUTEXES
79284@@ -1278,6 +1278,7 @@ config LATENCYTOP
79285 depends on DEBUG_KERNEL
79286 depends on STACKTRACE_SUPPORT
79287 depends on PROC_FS
79288+ depends on !GRKERNSEC_HIDESYM
79289 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
79290 select KALLSYMS
79291 select KALLSYMS_ALL
79292@@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
79293
79294 config PROVIDE_OHCI1394_DMA_INIT
79295 bool "Remote debugging over FireWire early on boot"
79296- depends on PCI && X86
79297+ depends on PCI && X86 && !GRKERNSEC
79298 help
79299 If you want to debug problems which hang or crash the kernel early
79300 on boot and the crashing machine has a FireWire port, you can use
79301@@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
79302
79303 config FIREWIRE_OHCI_REMOTE_DMA
79304 bool "Remote debugging over FireWire with firewire-ohci"
79305- depends on FIREWIRE_OHCI
79306+ depends on FIREWIRE_OHCI && !GRKERNSEC
79307 help
79308 This option lets you use the FireWire bus for remote debugging
79309 with help of the firewire-ohci driver. It enables unfiltered
79310diff --git a/lib/Makefile b/lib/Makefile
79311index 02ed6c0..bd243da 100644
79312--- a/lib/Makefile
79313+++ b/lib/Makefile
79314@@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
79315
79316 obj-$(CONFIG_BTREE) += btree.o
79317 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
79318-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
79319+obj-y += list_debug.o
79320 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
79321
79322 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
79323diff --git a/lib/bitmap.c b/lib/bitmap.c
79324index 06f7e4f..f3cf2b0 100644
79325--- a/lib/bitmap.c
79326+++ b/lib/bitmap.c
79327@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
79328 {
79329 int c, old_c, totaldigits, ndigits, nchunks, nbits;
79330 u32 chunk;
79331- const char __user __force *ubuf = (const char __user __force *)buf;
79332+ const char __user *ubuf = (const char __force_user *)buf;
79333
79334 bitmap_zero(maskp, nmaskbits);
79335
79336@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
79337 {
79338 if (!access_ok(VERIFY_READ, ubuf, ulen))
79339 return -EFAULT;
79340- return __bitmap_parse((const char __force *)ubuf,
79341+ return __bitmap_parse((const char __force_kernel *)ubuf,
79342 ulen, 1, maskp, nmaskbits);
79343
79344 }
79345@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
79346 {
79347 unsigned a, b;
79348 int c, old_c, totaldigits;
79349- const char __user __force *ubuf = (const char __user __force *)buf;
79350+ const char __user *ubuf = (const char __force_user *)buf;
79351 int exp_digit, in_range;
79352
79353 totaldigits = c = 0;
79354@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
79355 {
79356 if (!access_ok(VERIFY_READ, ubuf, ulen))
79357 return -EFAULT;
79358- return __bitmap_parselist((const char __force *)ubuf,
79359+ return __bitmap_parselist((const char __force_kernel *)ubuf,
79360 ulen, 1, maskp, nmaskbits);
79361 }
79362 EXPORT_SYMBOL(bitmap_parselist_user);
79363diff --git a/lib/bug.c b/lib/bug.c
79364index d0cdf14..4d07bd2 100644
79365--- a/lib/bug.c
79366+++ b/lib/bug.c
79367@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
79368 return BUG_TRAP_TYPE_NONE;
79369
79370 bug = find_bug(bugaddr);
79371+ if (!bug)
79372+ return BUG_TRAP_TYPE_NONE;
79373
79374 file = NULL;
79375 line = 0;
79376diff --git a/lib/debugobjects.c b/lib/debugobjects.c
79377index d11808c..dc2d6f8 100644
79378--- a/lib/debugobjects.c
79379+++ b/lib/debugobjects.c
79380@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
79381 if (limit > 4)
79382 return;
79383
79384- is_on_stack = object_is_on_stack(addr);
79385+ is_on_stack = object_starts_on_stack(addr);
79386 if (is_on_stack == onstack)
79387 return;
79388
79389diff --git a/lib/devres.c b/lib/devres.c
79390index 80b9c76..9e32279 100644
79391--- a/lib/devres.c
79392+++ b/lib/devres.c
79393@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
79394 void devm_iounmap(struct device *dev, void __iomem *addr)
79395 {
79396 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
79397- (void *)addr));
79398+ (void __force *)addr));
79399 iounmap(addr);
79400 }
79401 EXPORT_SYMBOL(devm_iounmap);
79402@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
79403 {
79404 ioport_unmap(addr);
79405 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
79406- devm_ioport_map_match, (void *)addr));
79407+ devm_ioport_map_match, (void __force *)addr));
79408 }
79409 EXPORT_SYMBOL(devm_ioport_unmap);
79410
79411diff --git a/lib/div64.c b/lib/div64.c
79412index a163b6c..9618fa5 100644
79413--- a/lib/div64.c
79414+++ b/lib/div64.c
79415@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
79416 EXPORT_SYMBOL(__div64_32);
79417
79418 #ifndef div_s64_rem
79419-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
79420+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
79421 {
79422 u64 quotient;
79423
79424@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
79425 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
79426 */
79427 #ifndef div64_u64
79428-u64 div64_u64(u64 dividend, u64 divisor)
79429+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
79430 {
79431 u32 high = divisor >> 32;
79432 u64 quot;
79433diff --git a/lib/dma-debug.c b/lib/dma-debug.c
79434index 5e396ac..58d5de1 100644
79435--- a/lib/dma-debug.c
79436+++ b/lib/dma-debug.c
79437@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
79438
79439 void dma_debug_add_bus(struct bus_type *bus)
79440 {
79441- struct notifier_block *nb;
79442+ notifier_block_no_const *nb;
79443
79444 if (global_disable)
79445 return;
79446@@ -942,7 +942,7 @@ out:
79447
79448 static void check_for_stack(struct device *dev, void *addr)
79449 {
79450- if (object_is_on_stack(addr))
79451+ if (object_starts_on_stack(addr))
79452 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
79453 "stack [addr=%p]\n", addr);
79454 }
79455diff --git a/lib/inflate.c b/lib/inflate.c
79456index 013a761..c28f3fc 100644
79457--- a/lib/inflate.c
79458+++ b/lib/inflate.c
79459@@ -269,7 +269,7 @@ static void free(void *where)
79460 malloc_ptr = free_mem_ptr;
79461 }
79462 #else
79463-#define malloc(a) kmalloc(a, GFP_KERNEL)
79464+#define malloc(a) kmalloc((a), GFP_KERNEL)
79465 #define free(a) kfree(a)
79466 #endif
79467
79468diff --git a/lib/ioremap.c b/lib/ioremap.c
79469index 0c9216c..863bd89 100644
79470--- a/lib/ioremap.c
79471+++ b/lib/ioremap.c
79472@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
79473 unsigned long next;
79474
79475 phys_addr -= addr;
79476- pmd = pmd_alloc(&init_mm, pud, addr);
79477+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
79478 if (!pmd)
79479 return -ENOMEM;
79480 do {
79481@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
79482 unsigned long next;
79483
79484 phys_addr -= addr;
79485- pud = pud_alloc(&init_mm, pgd, addr);
79486+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
79487 if (!pud)
79488 return -ENOMEM;
79489 do {
79490diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
79491index bd2bea9..6b3c95e 100644
79492--- a/lib/is_single_threaded.c
79493+++ b/lib/is_single_threaded.c
79494@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
79495 struct task_struct *p, *t;
79496 bool ret;
79497
79498+ if (!mm)
79499+ return true;
79500+
79501 if (atomic_read(&task->signal->live) != 1)
79502 return false;
79503
79504diff --git a/lib/kobject.c b/lib/kobject.c
79505index e07ee1f..998489d 100644
79506--- a/lib/kobject.c
79507+++ b/lib/kobject.c
79508@@ -852,9 +852,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
79509
79510
79511 static DEFINE_SPINLOCK(kobj_ns_type_lock);
79512-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
79513+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
79514
79515-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
79516+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
79517 {
79518 enum kobj_ns_type type = ops->type;
79519 int error;
79520diff --git a/lib/list_debug.c b/lib/list_debug.c
79521index c24c2f7..06e070b 100644
79522--- a/lib/list_debug.c
79523+++ b/lib/list_debug.c
79524@@ -11,7 +11,9 @@
79525 #include <linux/bug.h>
79526 #include <linux/kernel.h>
79527 #include <linux/rculist.h>
79528+#include <linux/mm.h>
79529
79530+#ifdef CONFIG_DEBUG_LIST
79531 /*
79532 * Insert a new entry between two known consecutive entries.
79533 *
79534@@ -19,21 +21,32 @@
79535 * the prev/next entries already!
79536 */
79537
79538-void __list_add(struct list_head *new,
79539- struct list_head *prev,
79540- struct list_head *next)
79541+static bool __list_add_debug(struct list_head *new,
79542+ struct list_head *prev,
79543+ struct list_head *next)
79544 {
79545- WARN(next->prev != prev,
79546+ if (WARN(next->prev != prev,
79547 "list_add corruption. next->prev should be "
79548 "prev (%p), but was %p. (next=%p).\n",
79549- prev, next->prev, next);
79550- WARN(prev->next != next,
79551+ prev, next->prev, next) ||
79552+ WARN(prev->next != next,
79553 "list_add corruption. prev->next should be "
79554 "next (%p), but was %p. (prev=%p).\n",
79555- next, prev->next, prev);
79556- WARN(new == prev || new == next,
79557- "list_add double add: new=%p, prev=%p, next=%p.\n",
79558- new, prev, next);
79559+ next, prev->next, prev) ||
79560+ WARN(new == prev || new == next,
79561+ "list_add double add: new=%p, prev=%p, next=%p.\n",
79562+ new, prev, next))
79563+ return false;
79564+ return true;
79565+}
79566+
79567+void __list_add(struct list_head *new,
79568+ struct list_head *prev,
79569+ struct list_head *next)
79570+{
79571+ if (!__list_add_debug(new, prev, next))
79572+ return;
79573+
79574 next->prev = new;
79575 new->next = next;
79576 new->prev = prev;
79577@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
79578 }
79579 EXPORT_SYMBOL(__list_add);
79580
79581-void __list_del_entry(struct list_head *entry)
79582+static bool __list_del_entry_debug(struct list_head *entry)
79583 {
79584 struct list_head *prev, *next;
79585
79586@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
79587 WARN(next->prev != entry,
79588 "list_del corruption. next->prev should be %p, "
79589 "but was %p\n", entry, next->prev))
79590+ return false;
79591+ return true;
79592+}
79593+
79594+void __list_del_entry(struct list_head *entry)
79595+{
79596+ if (!__list_del_entry_debug(entry))
79597 return;
79598
79599- __list_del(prev, next);
79600+ __list_del(entry->prev, entry->next);
79601 }
79602 EXPORT_SYMBOL(__list_del_entry);
79603
79604@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
79605 void __list_add_rcu(struct list_head *new,
79606 struct list_head *prev, struct list_head *next)
79607 {
79608- WARN(next->prev != prev,
79609- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
79610- prev, next->prev, next);
79611- WARN(prev->next != next,
79612- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
79613- next, prev->next, prev);
79614+ if (!__list_add_debug(new, prev, next))
79615+ return;
79616+
79617 new->next = next;
79618 new->prev = prev;
79619 rcu_assign_pointer(list_next_rcu(prev), new);
79620 next->prev = new;
79621 }
79622 EXPORT_SYMBOL(__list_add_rcu);
79623+#endif
79624+
79625+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
79626+{
79627+#ifdef CONFIG_DEBUG_LIST
79628+ if (!__list_add_debug(new, prev, next))
79629+ return;
79630+#endif
79631+
79632+ pax_open_kernel();
79633+ next->prev = new;
79634+ new->next = next;
79635+ new->prev = prev;
79636+ prev->next = new;
79637+ pax_close_kernel();
79638+}
79639+EXPORT_SYMBOL(__pax_list_add);
79640+
79641+void pax_list_del(struct list_head *entry)
79642+{
79643+#ifdef CONFIG_DEBUG_LIST
79644+ if (!__list_del_entry_debug(entry))
79645+ return;
79646+#endif
79647+
79648+ pax_open_kernel();
79649+ __list_del(entry->prev, entry->next);
79650+ entry->next = LIST_POISON1;
79651+ entry->prev = LIST_POISON2;
79652+ pax_close_kernel();
79653+}
79654+EXPORT_SYMBOL(pax_list_del);
79655+
79656+void pax_list_del_init(struct list_head *entry)
79657+{
79658+ pax_open_kernel();
79659+ __list_del(entry->prev, entry->next);
79660+ INIT_LIST_HEAD(entry);
79661+ pax_close_kernel();
79662+}
79663+EXPORT_SYMBOL(pax_list_del_init);
79664+
79665+void __pax_list_add_rcu(struct list_head *new,
79666+ struct list_head *prev, struct list_head *next)
79667+{
79668+#ifdef CONFIG_DEBUG_LIST
79669+ if (!__list_add_debug(new, prev, next))
79670+ return;
79671+#endif
79672+
79673+ pax_open_kernel();
79674+ new->next = next;
79675+ new->prev = prev;
79676+ rcu_assign_pointer(list_next_rcu(prev), new);
79677+ next->prev = new;
79678+ pax_close_kernel();
79679+}
79680+EXPORT_SYMBOL(__pax_list_add_rcu);
79681+
79682+void pax_list_del_rcu(struct list_head *entry)
79683+{
79684+#ifdef CONFIG_DEBUG_LIST
79685+ if (!__list_del_entry_debug(entry))
79686+ return;
79687+#endif
79688+
79689+ pax_open_kernel();
79690+ __list_del(entry->prev, entry->next);
79691+ entry->next = LIST_POISON1;
79692+ entry->prev = LIST_POISON2;
79693+ pax_close_kernel();
79694+}
79695+EXPORT_SYMBOL(pax_list_del_rcu);
79696diff --git a/lib/radix-tree.c b/lib/radix-tree.c
79697index e796429..6e38f9f 100644
79698--- a/lib/radix-tree.c
79699+++ b/lib/radix-tree.c
79700@@ -92,7 +92,7 @@ struct radix_tree_preload {
79701 int nr;
79702 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
79703 };
79704-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
79705+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
79706
79707 static inline void *ptr_to_indirect(void *ptr)
79708 {
79709diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
79710index bb2b201..46abaf9 100644
79711--- a/lib/strncpy_from_user.c
79712+++ b/lib/strncpy_from_user.c
79713@@ -21,7 +21,7 @@
79714 */
79715 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
79716 {
79717- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79718+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79719 long res = 0;
79720
79721 /*
79722diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
79723index a28df52..3d55877 100644
79724--- a/lib/strnlen_user.c
79725+++ b/lib/strnlen_user.c
79726@@ -26,7 +26,7 @@
79727 */
79728 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
79729 {
79730- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79731+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79732 long align, res = 0;
79733 unsigned long c;
79734
79735diff --git a/lib/swiotlb.c b/lib/swiotlb.c
79736index 196b069..358f342 100644
79737--- a/lib/swiotlb.c
79738+++ b/lib/swiotlb.c
79739@@ -642,7 +642,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
79740
79741 void
79742 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
79743- dma_addr_t dev_addr)
79744+ dma_addr_t dev_addr, struct dma_attrs *attrs)
79745 {
79746 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
79747
79748diff --git a/lib/vsprintf.c b/lib/vsprintf.c
79749index fab33a9..3b5fe68 100644
79750--- a/lib/vsprintf.c
79751+++ b/lib/vsprintf.c
79752@@ -16,6 +16,9 @@
79753 * - scnprintf and vscnprintf
79754 */
79755
79756+#ifdef CONFIG_GRKERNSEC_HIDESYM
79757+#define __INCLUDED_BY_HIDESYM 1
79758+#endif
79759 #include <stdarg.h>
79760 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
79761 #include <linux/types.h>
79762@@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
79763 char sym[KSYM_SYMBOL_LEN];
79764 if (ext == 'B')
79765 sprint_backtrace(sym, value);
79766- else if (ext != 'f' && ext != 's')
79767+ else if (ext != 'f' && ext != 's' && ext != 'a')
79768 sprint_symbol(sym, value);
79769 else
79770 sprint_symbol_no_offset(sym, value);
79771@@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
79772 return number(buf, end, *(const netdev_features_t *)addr, spec);
79773 }
79774
79775+#ifdef CONFIG_GRKERNSEC_HIDESYM
79776+int kptr_restrict __read_mostly = 2;
79777+#else
79778 int kptr_restrict __read_mostly;
79779+#endif
79780
79781 /*
79782 * Show a '%p' thing. A kernel extension is that the '%p' is followed
79783@@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
79784 * - 'S' For symbolic direct pointers with offset
79785 * - 's' For symbolic direct pointers without offset
79786 * - 'B' For backtraced symbolic direct pointers with offset
79787+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
79788+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
79789 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
79790 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
79791 * - 'M' For a 6-byte MAC address, it prints the address in the
79792@@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79793
79794 if (!ptr && *fmt != 'K') {
79795 /*
79796- * Print (null) with the same width as a pointer so it makes
79797+ * Print (nil) with the same width as a pointer so it makes
79798 * tabular output look nice.
79799 */
79800 if (spec.field_width == -1)
79801 spec.field_width = default_width;
79802- return string(buf, end, "(null)", spec);
79803+ return string(buf, end, "(nil)", spec);
79804 }
79805
79806 switch (*fmt) {
79807@@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79808 /* Fallthrough */
79809 case 'S':
79810 case 's':
79811+#ifdef CONFIG_GRKERNSEC_HIDESYM
79812+ break;
79813+#else
79814+ return symbol_string(buf, end, ptr, spec, *fmt);
79815+#endif
79816+ case 'A':
79817+ case 'a':
79818 case 'B':
79819 return symbol_string(buf, end, ptr, spec, *fmt);
79820 case 'R':
79821@@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79822 va_end(va);
79823 return buf;
79824 }
79825+ case 'P':
79826+ break;
79827 case 'K':
79828 /*
79829 * %pK cannot be used in IRQ context because its test
79830@@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79831 }
79832 break;
79833 }
79834+
79835+#ifdef CONFIG_GRKERNSEC_HIDESYM
79836+ /* 'P' = approved pointers to copy to userland,
79837+ as in the /proc/kallsyms case, as we make it display nothing
79838+ for non-root users, and the real contents for root users
79839+ Also ignore 'K' pointers, since we force their NULLing for non-root users
79840+ above
79841+ */
79842+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
79843+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
79844+ dump_stack();
79845+ ptr = NULL;
79846+ }
79847+#endif
79848+
79849 spec.flags |= SMALL;
79850 if (spec.field_width == -1) {
79851 spec.field_width = default_width;
79852@@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
79853 typeof(type) value; \
79854 if (sizeof(type) == 8) { \
79855 args = PTR_ALIGN(args, sizeof(u32)); \
79856- *(u32 *)&value = *(u32 *)args; \
79857- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
79858+ *(u32 *)&value = *(const u32 *)args; \
79859+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
79860 } else { \
79861 args = PTR_ALIGN(args, sizeof(type)); \
79862- value = *(typeof(type) *)args; \
79863+ value = *(const typeof(type) *)args; \
79864 } \
79865 args += sizeof(type); \
79866 value; \
79867@@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
79868 case FORMAT_TYPE_STR: {
79869 const char *str_arg = args;
79870 args += strlen(str_arg) + 1;
79871- str = string(str, end, (char *)str_arg, spec);
79872+ str = string(str, end, str_arg, spec);
79873 break;
79874 }
79875
79876diff --git a/localversion-grsec b/localversion-grsec
79877new file mode 100644
79878index 0000000..7cd6065
79879--- /dev/null
79880+++ b/localversion-grsec
79881@@ -0,0 +1 @@
79882+-grsec
79883diff --git a/mm/Kconfig b/mm/Kconfig
79884index 278e3ab..87c384d 100644
79885--- a/mm/Kconfig
79886+++ b/mm/Kconfig
79887@@ -286,10 +286,10 @@ config KSM
79888 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
79889
79890 config DEFAULT_MMAP_MIN_ADDR
79891- int "Low address space to protect from user allocation"
79892+ int "Low address space to protect from user allocation"
79893 depends on MMU
79894- default 4096
79895- help
79896+ default 65536
79897+ help
79898 This is the portion of low virtual memory which should be protected
79899 from userspace allocation. Keeping a user from writing to low pages
79900 can help reduce the impact of kernel NULL pointer bugs.
79901@@ -320,7 +320,7 @@ config MEMORY_FAILURE
79902
79903 config HWPOISON_INJECT
79904 tristate "HWPoison pages injector"
79905- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
79906+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
79907 select PROC_PAGE_MONITOR
79908
79909 config NOMMU_INITIAL_TRIM_EXCESS
79910diff --git a/mm/filemap.c b/mm/filemap.c
79911index 83efee7..3f99381 100644
79912--- a/mm/filemap.c
79913+++ b/mm/filemap.c
79914@@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
79915 struct address_space *mapping = file->f_mapping;
79916
79917 if (!mapping->a_ops->readpage)
79918- return -ENOEXEC;
79919+ return -ENODEV;
79920 file_accessed(file);
79921 vma->vm_ops = &generic_file_vm_ops;
79922 return 0;
79923@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
79924 *pos = i_size_read(inode);
79925
79926 if (limit != RLIM_INFINITY) {
79927+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
79928 if (*pos >= limit) {
79929 send_sig(SIGXFSZ, current, 0);
79930 return -EFBIG;
79931diff --git a/mm/fremap.c b/mm/fremap.c
79932index a0aaf0e..20325c3 100644
79933--- a/mm/fremap.c
79934+++ b/mm/fremap.c
79935@@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
79936 retry:
79937 vma = find_vma(mm, start);
79938
79939+#ifdef CONFIG_PAX_SEGMEXEC
79940+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
79941+ goto out;
79942+#endif
79943+
79944 /*
79945 * Make sure the vma is shared, that it supports prefaulting,
79946 * and that the remapped range is valid and fully within
79947diff --git a/mm/highmem.c b/mm/highmem.c
79948index b32b70c..e512eb0 100644
79949--- a/mm/highmem.c
79950+++ b/mm/highmem.c
79951@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
79952 * So no dangers, even with speculative execution.
79953 */
79954 page = pte_page(pkmap_page_table[i]);
79955+ pax_open_kernel();
79956 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
79957-
79958+ pax_close_kernel();
79959 set_page_address(page, NULL);
79960 need_flush = 1;
79961 }
79962@@ -198,9 +199,11 @@ start:
79963 }
79964 }
79965 vaddr = PKMAP_ADDR(last_pkmap_nr);
79966+
79967+ pax_open_kernel();
79968 set_pte_at(&init_mm, vaddr,
79969 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
79970-
79971+ pax_close_kernel();
79972 pkmap_count[last_pkmap_nr] = 1;
79973 set_page_address(page, (void *)vaddr);
79974
79975diff --git a/mm/hugetlb.c b/mm/hugetlb.c
79976index d7cec92..b05cc33 100644
79977--- a/mm/hugetlb.c
79978+++ b/mm/hugetlb.c
79979@@ -2008,15 +2008,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
79980 struct hstate *h = &default_hstate;
79981 unsigned long tmp;
79982 int ret;
79983+ ctl_table_no_const hugetlb_table;
79984
79985 tmp = h->max_huge_pages;
79986
79987 if (write && h->order >= MAX_ORDER)
79988 return -EINVAL;
79989
79990- table->data = &tmp;
79991- table->maxlen = sizeof(unsigned long);
79992- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
79993+ hugetlb_table = *table;
79994+ hugetlb_table.data = &tmp;
79995+ hugetlb_table.maxlen = sizeof(unsigned long);
79996+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
79997 if (ret)
79998 goto out;
79999
80000@@ -2073,15 +2075,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
80001 struct hstate *h = &default_hstate;
80002 unsigned long tmp;
80003 int ret;
80004+ ctl_table_no_const hugetlb_table;
80005
80006 tmp = h->nr_overcommit_huge_pages;
80007
80008 if (write && h->order >= MAX_ORDER)
80009 return -EINVAL;
80010
80011- table->data = &tmp;
80012- table->maxlen = sizeof(unsigned long);
80013- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
80014+ hugetlb_table = *table;
80015+ hugetlb_table.data = &tmp;
80016+ hugetlb_table.maxlen = sizeof(unsigned long);
80017+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
80018 if (ret)
80019 goto out;
80020
80021@@ -2515,6 +2519,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
80022 return 1;
80023 }
80024
80025+#ifdef CONFIG_PAX_SEGMEXEC
80026+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
80027+{
80028+ struct mm_struct *mm = vma->vm_mm;
80029+ struct vm_area_struct *vma_m;
80030+ unsigned long address_m;
80031+ pte_t *ptep_m;
80032+
80033+ vma_m = pax_find_mirror_vma(vma);
80034+ if (!vma_m)
80035+ return;
80036+
80037+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80038+ address_m = address + SEGMEXEC_TASK_SIZE;
80039+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
80040+ get_page(page_m);
80041+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
80042+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
80043+}
80044+#endif
80045+
80046 /*
80047 * Hugetlb_cow() should be called with page lock of the original hugepage held.
80048 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
80049@@ -2633,6 +2658,11 @@ retry_avoidcopy:
80050 make_huge_pte(vma, new_page, 1));
80051 page_remove_rmap(old_page);
80052 hugepage_add_new_anon_rmap(new_page, vma, address);
80053+
80054+#ifdef CONFIG_PAX_SEGMEXEC
80055+ pax_mirror_huge_pte(vma, address, new_page);
80056+#endif
80057+
80058 /* Make the old page be freed below */
80059 new_page = old_page;
80060 }
80061@@ -2792,6 +2822,10 @@ retry:
80062 && (vma->vm_flags & VM_SHARED)));
80063 set_huge_pte_at(mm, address, ptep, new_pte);
80064
80065+#ifdef CONFIG_PAX_SEGMEXEC
80066+ pax_mirror_huge_pte(vma, address, page);
80067+#endif
80068+
80069 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
80070 /* Optimization, do the COW without a second fault */
80071 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
80072@@ -2821,6 +2855,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80073 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
80074 struct hstate *h = hstate_vma(vma);
80075
80076+#ifdef CONFIG_PAX_SEGMEXEC
80077+ struct vm_area_struct *vma_m;
80078+#endif
80079+
80080 address &= huge_page_mask(h);
80081
80082 ptep = huge_pte_offset(mm, address);
80083@@ -2834,6 +2872,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80084 VM_FAULT_SET_HINDEX(hstate_index(h));
80085 }
80086
80087+#ifdef CONFIG_PAX_SEGMEXEC
80088+ vma_m = pax_find_mirror_vma(vma);
80089+ if (vma_m) {
80090+ unsigned long address_m;
80091+
80092+ if (vma->vm_start > vma_m->vm_start) {
80093+ address_m = address;
80094+ address -= SEGMEXEC_TASK_SIZE;
80095+ vma = vma_m;
80096+ h = hstate_vma(vma);
80097+ } else
80098+ address_m = address + SEGMEXEC_TASK_SIZE;
80099+
80100+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
80101+ return VM_FAULT_OOM;
80102+ address_m &= HPAGE_MASK;
80103+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
80104+ }
80105+#endif
80106+
80107 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
80108 if (!ptep)
80109 return VM_FAULT_OOM;
80110diff --git a/mm/internal.h b/mm/internal.h
80111index 9ba2110..eaf0674 100644
80112--- a/mm/internal.h
80113+++ b/mm/internal.h
80114@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
80115 * in mm/page_alloc.c
80116 */
80117 extern void __free_pages_bootmem(struct page *page, unsigned int order);
80118+extern void free_compound_page(struct page *page);
80119 extern void prep_compound_page(struct page *page, unsigned long order);
80120 #ifdef CONFIG_MEMORY_FAILURE
80121 extern bool is_free_buddy_page(struct page *page);
80122diff --git a/mm/kmemleak.c b/mm/kmemleak.c
80123index 752a705..6c3102e 100644
80124--- a/mm/kmemleak.c
80125+++ b/mm/kmemleak.c
80126@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
80127
80128 for (i = 0; i < object->trace_len; i++) {
80129 void *ptr = (void *)object->trace[i];
80130- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
80131+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
80132 }
80133 }
80134
80135@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
80136 return -ENOMEM;
80137 }
80138
80139- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
80140+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
80141 &kmemleak_fops);
80142 if (!dentry)
80143 pr_warning("Failed to create the debugfs kmemleak file\n");
80144diff --git a/mm/maccess.c b/mm/maccess.c
80145index d53adf9..03a24bf 100644
80146--- a/mm/maccess.c
80147+++ b/mm/maccess.c
80148@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
80149 set_fs(KERNEL_DS);
80150 pagefault_disable();
80151 ret = __copy_from_user_inatomic(dst,
80152- (__force const void __user *)src, size);
80153+ (const void __force_user *)src, size);
80154 pagefault_enable();
80155 set_fs(old_fs);
80156
80157@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
80158
80159 set_fs(KERNEL_DS);
80160 pagefault_disable();
80161- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
80162+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
80163 pagefault_enable();
80164 set_fs(old_fs);
80165
80166diff --git a/mm/madvise.c b/mm/madvise.c
80167index 03dfa5c..b032917 100644
80168--- a/mm/madvise.c
80169+++ b/mm/madvise.c
80170@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
80171 pgoff_t pgoff;
80172 unsigned long new_flags = vma->vm_flags;
80173
80174+#ifdef CONFIG_PAX_SEGMEXEC
80175+ struct vm_area_struct *vma_m;
80176+#endif
80177+
80178 switch (behavior) {
80179 case MADV_NORMAL:
80180 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
80181@@ -123,6 +127,13 @@ success:
80182 /*
80183 * vm_flags is protected by the mmap_sem held in write mode.
80184 */
80185+
80186+#ifdef CONFIG_PAX_SEGMEXEC
80187+ vma_m = pax_find_mirror_vma(vma);
80188+ if (vma_m)
80189+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
80190+#endif
80191+
80192 vma->vm_flags = new_flags;
80193
80194 out:
80195@@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
80196 struct vm_area_struct ** prev,
80197 unsigned long start, unsigned long end)
80198 {
80199+
80200+#ifdef CONFIG_PAX_SEGMEXEC
80201+ struct vm_area_struct *vma_m;
80202+#endif
80203+
80204 *prev = vma;
80205 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
80206 return -EINVAL;
80207@@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
80208 zap_page_range(vma, start, end - start, &details);
80209 } else
80210 zap_page_range(vma, start, end - start, NULL);
80211+
80212+#ifdef CONFIG_PAX_SEGMEXEC
80213+ vma_m = pax_find_mirror_vma(vma);
80214+ if (vma_m) {
80215+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
80216+ struct zap_details details = {
80217+ .nonlinear_vma = vma_m,
80218+ .last_index = ULONG_MAX,
80219+ };
80220+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
80221+ } else
80222+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
80223+ }
80224+#endif
80225+
80226 return 0;
80227 }
80228
80229@@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
80230 if (end < start)
80231 goto out;
80232
80233+#ifdef CONFIG_PAX_SEGMEXEC
80234+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
80235+ if (end > SEGMEXEC_TASK_SIZE)
80236+ goto out;
80237+ } else
80238+#endif
80239+
80240+ if (end > TASK_SIZE)
80241+ goto out;
80242+
80243 error = 0;
80244 if (end == start)
80245 goto out;
80246diff --git a/mm/memory-failure.c b/mm/memory-failure.c
80247index c6e4dd3..1f41988 100644
80248--- a/mm/memory-failure.c
80249+++ b/mm/memory-failure.c
80250@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
80251
80252 int sysctl_memory_failure_recovery __read_mostly = 1;
80253
80254-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
80255+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
80256
80257 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
80258
80259@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
80260 pfn, t->comm, t->pid);
80261 si.si_signo = SIGBUS;
80262 si.si_errno = 0;
80263- si.si_addr = (void *)addr;
80264+ si.si_addr = (void __user *)addr;
80265 #ifdef __ARCH_SI_TRAPNO
80266 si.si_trapno = trapno;
80267 #endif
80268@@ -760,7 +760,7 @@ static struct page_state {
80269 unsigned long res;
80270 char *msg;
80271 int (*action)(struct page *p, unsigned long pfn);
80272-} error_states[] = {
80273+} __do_const error_states[] = {
80274 { reserved, reserved, "reserved kernel", me_kernel },
80275 /*
80276 * free pages are specially detected outside this table:
80277@@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80278 }
80279
80280 nr_pages = 1 << compound_trans_order(hpage);
80281- atomic_long_add(nr_pages, &mce_bad_pages);
80282+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
80283
80284 /*
80285 * We need/can do nothing about count=0 pages.
80286@@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80287 if (!PageHWPoison(hpage)
80288 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
80289 || (p != hpage && TestSetPageHWPoison(hpage))) {
80290- atomic_long_sub(nr_pages, &mce_bad_pages);
80291+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80292 return 0;
80293 }
80294 set_page_hwpoison_huge_page(hpage);
80295@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80296 }
80297 if (hwpoison_filter(p)) {
80298 if (TestClearPageHWPoison(p))
80299- atomic_long_sub(nr_pages, &mce_bad_pages);
80300+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80301 unlock_page(hpage);
80302 put_page(hpage);
80303 return 0;
80304@@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
80305 return 0;
80306 }
80307 if (TestClearPageHWPoison(p))
80308- atomic_long_sub(nr_pages, &mce_bad_pages);
80309+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80310 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
80311 return 0;
80312 }
80313@@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
80314 */
80315 if (TestClearPageHWPoison(page)) {
80316 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
80317- atomic_long_sub(nr_pages, &mce_bad_pages);
80318+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80319 freeit = 1;
80320 if (PageHuge(page))
80321 clear_page_hwpoison_huge_page(page);
80322@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
80323 }
80324 done:
80325 if (!PageHWPoison(hpage))
80326- atomic_long_add(1 << compound_trans_order(hpage),
80327+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
80328 &mce_bad_pages);
80329 set_page_hwpoison_huge_page(hpage);
80330 dequeue_hwpoisoned_huge_page(hpage);
80331@@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
80332 return ret;
80333
80334 done:
80335- atomic_long_add(1, &mce_bad_pages);
80336+ atomic_long_add_unchecked(1, &mce_bad_pages);
80337 SetPageHWPoison(page);
80338 /* keep elevated page count for bad page */
80339 return ret;
80340diff --git a/mm/memory.c b/mm/memory.c
80341index bb1369f..efb96b5 100644
80342--- a/mm/memory.c
80343+++ b/mm/memory.c
80344@@ -433,6 +433,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
80345 free_pte_range(tlb, pmd, addr);
80346 } while (pmd++, addr = next, addr != end);
80347
80348+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
80349 start &= PUD_MASK;
80350 if (start < floor)
80351 return;
80352@@ -447,6 +448,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
80353 pmd = pmd_offset(pud, start);
80354 pud_clear(pud);
80355 pmd_free_tlb(tlb, pmd, start);
80356+#endif
80357+
80358 }
80359
80360 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80361@@ -466,6 +469,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80362 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
80363 } while (pud++, addr = next, addr != end);
80364
80365+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
80366 start &= PGDIR_MASK;
80367 if (start < floor)
80368 return;
80369@@ -480,6 +484,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80370 pud = pud_offset(pgd, start);
80371 pgd_clear(pgd);
80372 pud_free_tlb(tlb, pud, start);
80373+#endif
80374+
80375 }
80376
80377 /*
80378@@ -1618,12 +1624,6 @@ no_page_table:
80379 return page;
80380 }
80381
80382-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
80383-{
80384- return stack_guard_page_start(vma, addr) ||
80385- stack_guard_page_end(vma, addr+PAGE_SIZE);
80386-}
80387-
80388 /**
80389 * __get_user_pages() - pin user pages in memory
80390 * @tsk: task_struct of target task
80391@@ -1709,10 +1709,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80392
80393 i = 0;
80394
80395- do {
80396+ while (nr_pages) {
80397 struct vm_area_struct *vma;
80398
80399- vma = find_extend_vma(mm, start);
80400+ vma = find_vma(mm, start);
80401 if (!vma && in_gate_area(mm, start)) {
80402 unsigned long pg = start & PAGE_MASK;
80403 pgd_t *pgd;
80404@@ -1760,7 +1760,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80405 goto next_page;
80406 }
80407
80408- if (!vma ||
80409+ if (!vma || start < vma->vm_start ||
80410 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
80411 !(vm_flags & vma->vm_flags))
80412 return i ? : -EFAULT;
80413@@ -1787,11 +1787,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80414 int ret;
80415 unsigned int fault_flags = 0;
80416
80417- /* For mlock, just skip the stack guard page. */
80418- if (foll_flags & FOLL_MLOCK) {
80419- if (stack_guard_page(vma, start))
80420- goto next_page;
80421- }
80422 if (foll_flags & FOLL_WRITE)
80423 fault_flags |= FAULT_FLAG_WRITE;
80424 if (nonblocking)
80425@@ -1865,7 +1860,7 @@ next_page:
80426 start += PAGE_SIZE;
80427 nr_pages--;
80428 } while (nr_pages && start < vma->vm_end);
80429- } while (nr_pages);
80430+ }
80431 return i;
80432 }
80433 EXPORT_SYMBOL(__get_user_pages);
80434@@ -2072,6 +2067,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
80435 page_add_file_rmap(page);
80436 set_pte_at(mm, addr, pte, mk_pte(page, prot));
80437
80438+#ifdef CONFIG_PAX_SEGMEXEC
80439+ pax_mirror_file_pte(vma, addr, page, ptl);
80440+#endif
80441+
80442 retval = 0;
80443 pte_unmap_unlock(pte, ptl);
80444 return retval;
80445@@ -2116,9 +2115,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
80446 if (!page_count(page))
80447 return -EINVAL;
80448 if (!(vma->vm_flags & VM_MIXEDMAP)) {
80449+
80450+#ifdef CONFIG_PAX_SEGMEXEC
80451+ struct vm_area_struct *vma_m;
80452+#endif
80453+
80454 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
80455 BUG_ON(vma->vm_flags & VM_PFNMAP);
80456 vma->vm_flags |= VM_MIXEDMAP;
80457+
80458+#ifdef CONFIG_PAX_SEGMEXEC
80459+ vma_m = pax_find_mirror_vma(vma);
80460+ if (vma_m)
80461+ vma_m->vm_flags |= VM_MIXEDMAP;
80462+#endif
80463+
80464 }
80465 return insert_page(vma, addr, page, vma->vm_page_prot);
80466 }
80467@@ -2201,6 +2212,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
80468 unsigned long pfn)
80469 {
80470 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
80471+ BUG_ON(vma->vm_mirror);
80472
80473 if (addr < vma->vm_start || addr >= vma->vm_end)
80474 return -EFAULT;
80475@@ -2401,7 +2413,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
80476
80477 BUG_ON(pud_huge(*pud));
80478
80479- pmd = pmd_alloc(mm, pud, addr);
80480+ pmd = (mm == &init_mm) ?
80481+ pmd_alloc_kernel(mm, pud, addr) :
80482+ pmd_alloc(mm, pud, addr);
80483 if (!pmd)
80484 return -ENOMEM;
80485 do {
80486@@ -2421,7 +2435,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
80487 unsigned long next;
80488 int err;
80489
80490- pud = pud_alloc(mm, pgd, addr);
80491+ pud = (mm == &init_mm) ?
80492+ pud_alloc_kernel(mm, pgd, addr) :
80493+ pud_alloc(mm, pgd, addr);
80494 if (!pud)
80495 return -ENOMEM;
80496 do {
80497@@ -2509,6 +2525,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
80498 copy_user_highpage(dst, src, va, vma);
80499 }
80500
80501+#ifdef CONFIG_PAX_SEGMEXEC
80502+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
80503+{
80504+ struct mm_struct *mm = vma->vm_mm;
80505+ spinlock_t *ptl;
80506+ pte_t *pte, entry;
80507+
80508+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
80509+ entry = *pte;
80510+ if (!pte_present(entry)) {
80511+ if (!pte_none(entry)) {
80512+ BUG_ON(pte_file(entry));
80513+ free_swap_and_cache(pte_to_swp_entry(entry));
80514+ pte_clear_not_present_full(mm, address, pte, 0);
80515+ }
80516+ } else {
80517+ struct page *page;
80518+
80519+ flush_cache_page(vma, address, pte_pfn(entry));
80520+ entry = ptep_clear_flush(vma, address, pte);
80521+ BUG_ON(pte_dirty(entry));
80522+ page = vm_normal_page(vma, address, entry);
80523+ if (page) {
80524+ update_hiwater_rss(mm);
80525+ if (PageAnon(page))
80526+ dec_mm_counter_fast(mm, MM_ANONPAGES);
80527+ else
80528+ dec_mm_counter_fast(mm, MM_FILEPAGES);
80529+ page_remove_rmap(page);
80530+ page_cache_release(page);
80531+ }
80532+ }
80533+ pte_unmap_unlock(pte, ptl);
80534+}
80535+
80536+/* PaX: if vma is mirrored, synchronize the mirror's PTE
80537+ *
80538+ * the ptl of the lower mapped page is held on entry and is not released on exit
80539+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
80540+ */
80541+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
80542+{
80543+ struct mm_struct *mm = vma->vm_mm;
80544+ unsigned long address_m;
80545+ spinlock_t *ptl_m;
80546+ struct vm_area_struct *vma_m;
80547+ pmd_t *pmd_m;
80548+ pte_t *pte_m, entry_m;
80549+
80550+ BUG_ON(!page_m || !PageAnon(page_m));
80551+
80552+ vma_m = pax_find_mirror_vma(vma);
80553+ if (!vma_m)
80554+ return;
80555+
80556+ BUG_ON(!PageLocked(page_m));
80557+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80558+ address_m = address + SEGMEXEC_TASK_SIZE;
80559+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
80560+ pte_m = pte_offset_map(pmd_m, address_m);
80561+ ptl_m = pte_lockptr(mm, pmd_m);
80562+ if (ptl != ptl_m) {
80563+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
80564+ if (!pte_none(*pte_m))
80565+ goto out;
80566+ }
80567+
80568+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
80569+ page_cache_get(page_m);
80570+ page_add_anon_rmap(page_m, vma_m, address_m);
80571+ inc_mm_counter_fast(mm, MM_ANONPAGES);
80572+ set_pte_at(mm, address_m, pte_m, entry_m);
80573+ update_mmu_cache(vma_m, address_m, entry_m);
80574+out:
80575+ if (ptl != ptl_m)
80576+ spin_unlock(ptl_m);
80577+ pte_unmap(pte_m);
80578+ unlock_page(page_m);
80579+}
80580+
80581+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
80582+{
80583+ struct mm_struct *mm = vma->vm_mm;
80584+ unsigned long address_m;
80585+ spinlock_t *ptl_m;
80586+ struct vm_area_struct *vma_m;
80587+ pmd_t *pmd_m;
80588+ pte_t *pte_m, entry_m;
80589+
80590+ BUG_ON(!page_m || PageAnon(page_m));
80591+
80592+ vma_m = pax_find_mirror_vma(vma);
80593+ if (!vma_m)
80594+ return;
80595+
80596+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80597+ address_m = address + SEGMEXEC_TASK_SIZE;
80598+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
80599+ pte_m = pte_offset_map(pmd_m, address_m);
80600+ ptl_m = pte_lockptr(mm, pmd_m);
80601+ if (ptl != ptl_m) {
80602+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
80603+ if (!pte_none(*pte_m))
80604+ goto out;
80605+ }
80606+
80607+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
80608+ page_cache_get(page_m);
80609+ page_add_file_rmap(page_m);
80610+ inc_mm_counter_fast(mm, MM_FILEPAGES);
80611+ set_pte_at(mm, address_m, pte_m, entry_m);
80612+ update_mmu_cache(vma_m, address_m, entry_m);
80613+out:
80614+ if (ptl != ptl_m)
80615+ spin_unlock(ptl_m);
80616+ pte_unmap(pte_m);
80617+}
80618+
80619+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
80620+{
80621+ struct mm_struct *mm = vma->vm_mm;
80622+ unsigned long address_m;
80623+ spinlock_t *ptl_m;
80624+ struct vm_area_struct *vma_m;
80625+ pmd_t *pmd_m;
80626+ pte_t *pte_m, entry_m;
80627+
80628+ vma_m = pax_find_mirror_vma(vma);
80629+ if (!vma_m)
80630+ return;
80631+
80632+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80633+ address_m = address + SEGMEXEC_TASK_SIZE;
80634+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
80635+ pte_m = pte_offset_map(pmd_m, address_m);
80636+ ptl_m = pte_lockptr(mm, pmd_m);
80637+ if (ptl != ptl_m) {
80638+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
80639+ if (!pte_none(*pte_m))
80640+ goto out;
80641+ }
80642+
80643+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
80644+ set_pte_at(mm, address_m, pte_m, entry_m);
80645+out:
80646+ if (ptl != ptl_m)
80647+ spin_unlock(ptl_m);
80648+ pte_unmap(pte_m);
80649+}
80650+
80651+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
80652+{
80653+ struct page *page_m;
80654+ pte_t entry;
80655+
80656+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
80657+ goto out;
80658+
80659+ entry = *pte;
80660+ page_m = vm_normal_page(vma, address, entry);
80661+ if (!page_m)
80662+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
80663+ else if (PageAnon(page_m)) {
80664+ if (pax_find_mirror_vma(vma)) {
80665+ pte_unmap_unlock(pte, ptl);
80666+ lock_page(page_m);
80667+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
80668+ if (pte_same(entry, *pte))
80669+ pax_mirror_anon_pte(vma, address, page_m, ptl);
80670+ else
80671+ unlock_page(page_m);
80672+ }
80673+ } else
80674+ pax_mirror_file_pte(vma, address, page_m, ptl);
80675+
80676+out:
80677+ pte_unmap_unlock(pte, ptl);
80678+}
80679+#endif
80680+
80681 /*
80682 * This routine handles present pages, when users try to write
80683 * to a shared page. It is done by copying the page to a new address
80684@@ -2725,6 +2921,12 @@ gotten:
80685 */
80686 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
80687 if (likely(pte_same(*page_table, orig_pte))) {
80688+
80689+#ifdef CONFIG_PAX_SEGMEXEC
80690+ if (pax_find_mirror_vma(vma))
80691+ BUG_ON(!trylock_page(new_page));
80692+#endif
80693+
80694 if (old_page) {
80695 if (!PageAnon(old_page)) {
80696 dec_mm_counter_fast(mm, MM_FILEPAGES);
80697@@ -2776,6 +2978,10 @@ gotten:
80698 page_remove_rmap(old_page);
80699 }
80700
80701+#ifdef CONFIG_PAX_SEGMEXEC
80702+ pax_mirror_anon_pte(vma, address, new_page, ptl);
80703+#endif
80704+
80705 /* Free the old page.. */
80706 new_page = old_page;
80707 ret |= VM_FAULT_WRITE;
80708@@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
80709 swap_free(entry);
80710 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
80711 try_to_free_swap(page);
80712+
80713+#ifdef CONFIG_PAX_SEGMEXEC
80714+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
80715+#endif
80716+
80717 unlock_page(page);
80718 if (swapcache) {
80719 /*
80720@@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
80721
80722 /* No need to invalidate - it was non-present before */
80723 update_mmu_cache(vma, address, page_table);
80724+
80725+#ifdef CONFIG_PAX_SEGMEXEC
80726+ pax_mirror_anon_pte(vma, address, page, ptl);
80727+#endif
80728+
80729 unlock:
80730 pte_unmap_unlock(page_table, ptl);
80731 out:
80732@@ -3093,40 +3309,6 @@ out_release:
80733 }
80734
80735 /*
80736- * This is like a special single-page "expand_{down|up}wards()",
80737- * except we must first make sure that 'address{-|+}PAGE_SIZE'
80738- * doesn't hit another vma.
80739- */
80740-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
80741-{
80742- address &= PAGE_MASK;
80743- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
80744- struct vm_area_struct *prev = vma->vm_prev;
80745-
80746- /*
80747- * Is there a mapping abutting this one below?
80748- *
80749- * That's only ok if it's the same stack mapping
80750- * that has gotten split..
80751- */
80752- if (prev && prev->vm_end == address)
80753- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
80754-
80755- expand_downwards(vma, address - PAGE_SIZE);
80756- }
80757- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
80758- struct vm_area_struct *next = vma->vm_next;
80759-
80760- /* As VM_GROWSDOWN but s/below/above/ */
80761- if (next && next->vm_start == address + PAGE_SIZE)
80762- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
80763-
80764- expand_upwards(vma, address + PAGE_SIZE);
80765- }
80766- return 0;
80767-}
80768-
80769-/*
80770 * We enter with non-exclusive mmap_sem (to exclude vma changes,
80771 * but allow concurrent faults), and pte mapped but not yet locked.
80772 * We return with mmap_sem still held, but pte unmapped and unlocked.
80773@@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
80774 unsigned long address, pte_t *page_table, pmd_t *pmd,
80775 unsigned int flags)
80776 {
80777- struct page *page;
80778+ struct page *page = NULL;
80779 spinlock_t *ptl;
80780 pte_t entry;
80781
80782- pte_unmap(page_table);
80783-
80784- /* Check if we need to add a guard page to the stack */
80785- if (check_stack_guard_page(vma, address) < 0)
80786- return VM_FAULT_SIGBUS;
80787-
80788- /* Use the zero-page for reads */
80789 if (!(flags & FAULT_FLAG_WRITE)) {
80790 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
80791 vma->vm_page_prot));
80792- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
80793+ ptl = pte_lockptr(mm, pmd);
80794+ spin_lock(ptl);
80795 if (!pte_none(*page_table))
80796 goto unlock;
80797 goto setpte;
80798 }
80799
80800 /* Allocate our own private page. */
80801+ pte_unmap(page_table);
80802+
80803 if (unlikely(anon_vma_prepare(vma)))
80804 goto oom;
80805 page = alloc_zeroed_user_highpage_movable(vma, address);
80806@@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
80807 if (!pte_none(*page_table))
80808 goto release;
80809
80810+#ifdef CONFIG_PAX_SEGMEXEC
80811+ if (pax_find_mirror_vma(vma))
80812+ BUG_ON(!trylock_page(page));
80813+#endif
80814+
80815 inc_mm_counter_fast(mm, MM_ANONPAGES);
80816 page_add_new_anon_rmap(page, vma, address);
80817 setpte:
80818@@ -3181,6 +3364,12 @@ setpte:
80819
80820 /* No need to invalidate - it was non-present before */
80821 update_mmu_cache(vma, address, page_table);
80822+
80823+#ifdef CONFIG_PAX_SEGMEXEC
80824+ if (page)
80825+ pax_mirror_anon_pte(vma, address, page, ptl);
80826+#endif
80827+
80828 unlock:
80829 pte_unmap_unlock(page_table, ptl);
80830 return 0;
80831@@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80832 */
80833 /* Only go through if we didn't race with anybody else... */
80834 if (likely(pte_same(*page_table, orig_pte))) {
80835+
80836+#ifdef CONFIG_PAX_SEGMEXEC
80837+ if (anon && pax_find_mirror_vma(vma))
80838+ BUG_ON(!trylock_page(page));
80839+#endif
80840+
80841 flush_icache_page(vma, page);
80842 entry = mk_pte(page, vma->vm_page_prot);
80843 if (flags & FAULT_FLAG_WRITE)
80844@@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80845
80846 /* no need to invalidate: a not-present page won't be cached */
80847 update_mmu_cache(vma, address, page_table);
80848+
80849+#ifdef CONFIG_PAX_SEGMEXEC
80850+ if (anon)
80851+ pax_mirror_anon_pte(vma, address, page, ptl);
80852+ else
80853+ pax_mirror_file_pte(vma, address, page, ptl);
80854+#endif
80855+
80856 } else {
80857 if (cow_page)
80858 mem_cgroup_uncharge_page(cow_page);
80859@@ -3664,6 +3867,12 @@ int handle_pte_fault(struct mm_struct *mm,
80860 if (flags & FAULT_FLAG_WRITE)
80861 flush_tlb_fix_spurious_fault(vma, address);
80862 }
80863+
80864+#ifdef CONFIG_PAX_SEGMEXEC
80865+ pax_mirror_pte(vma, address, pte, pmd, ptl);
80866+ return 0;
80867+#endif
80868+
80869 unlock:
80870 pte_unmap_unlock(pte, ptl);
80871 return 0;
80872@@ -3680,6 +3889,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80873 pmd_t *pmd;
80874 pte_t *pte;
80875
80876+#ifdef CONFIG_PAX_SEGMEXEC
80877+ struct vm_area_struct *vma_m;
80878+#endif
80879+
80880 __set_current_state(TASK_RUNNING);
80881
80882 count_vm_event(PGFAULT);
80883@@ -3691,6 +3904,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80884 if (unlikely(is_vm_hugetlb_page(vma)))
80885 return hugetlb_fault(mm, vma, address, flags);
80886
80887+#ifdef CONFIG_PAX_SEGMEXEC
80888+ vma_m = pax_find_mirror_vma(vma);
80889+ if (vma_m) {
80890+ unsigned long address_m;
80891+ pgd_t *pgd_m;
80892+ pud_t *pud_m;
80893+ pmd_t *pmd_m;
80894+
80895+ if (vma->vm_start > vma_m->vm_start) {
80896+ address_m = address;
80897+ address -= SEGMEXEC_TASK_SIZE;
80898+ vma = vma_m;
80899+ } else
80900+ address_m = address + SEGMEXEC_TASK_SIZE;
80901+
80902+ pgd_m = pgd_offset(mm, address_m);
80903+ pud_m = pud_alloc(mm, pgd_m, address_m);
80904+ if (!pud_m)
80905+ return VM_FAULT_OOM;
80906+ pmd_m = pmd_alloc(mm, pud_m, address_m);
80907+ if (!pmd_m)
80908+ return VM_FAULT_OOM;
80909+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
80910+ return VM_FAULT_OOM;
80911+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
80912+ }
80913+#endif
80914+
80915 retry:
80916 pgd = pgd_offset(mm, address);
80917 pud = pud_alloc(mm, pgd, address);
80918@@ -3789,6 +4030,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80919 spin_unlock(&mm->page_table_lock);
80920 return 0;
80921 }
80922+
80923+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80924+{
80925+ pud_t *new = pud_alloc_one(mm, address);
80926+ if (!new)
80927+ return -ENOMEM;
80928+
80929+ smp_wmb(); /* See comment in __pte_alloc */
80930+
80931+ spin_lock(&mm->page_table_lock);
80932+ if (pgd_present(*pgd)) /* Another has populated it */
80933+ pud_free(mm, new);
80934+ else
80935+ pgd_populate_kernel(mm, pgd, new);
80936+ spin_unlock(&mm->page_table_lock);
80937+ return 0;
80938+}
80939 #endif /* __PAGETABLE_PUD_FOLDED */
80940
80941 #ifndef __PAGETABLE_PMD_FOLDED
80942@@ -3819,6 +4077,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80943 spin_unlock(&mm->page_table_lock);
80944 return 0;
80945 }
80946+
80947+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80948+{
80949+ pmd_t *new = pmd_alloc_one(mm, address);
80950+ if (!new)
80951+ return -ENOMEM;
80952+
80953+ smp_wmb(); /* See comment in __pte_alloc */
80954+
80955+ spin_lock(&mm->page_table_lock);
80956+#ifndef __ARCH_HAS_4LEVEL_HACK
80957+ if (pud_present(*pud)) /* Another has populated it */
80958+ pmd_free(mm, new);
80959+ else
80960+ pud_populate_kernel(mm, pud, new);
80961+#else
80962+ if (pgd_present(*pud)) /* Another has populated it */
80963+ pmd_free(mm, new);
80964+ else
80965+ pgd_populate_kernel(mm, pud, new);
80966+#endif /* __ARCH_HAS_4LEVEL_HACK */
80967+ spin_unlock(&mm->page_table_lock);
80968+ return 0;
80969+}
80970 #endif /* __PAGETABLE_PMD_FOLDED */
80971
80972 int make_pages_present(unsigned long addr, unsigned long end)
80973@@ -3856,7 +4138,7 @@ static int __init gate_vma_init(void)
80974 gate_vma.vm_start = FIXADDR_USER_START;
80975 gate_vma.vm_end = FIXADDR_USER_END;
80976 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
80977- gate_vma.vm_page_prot = __P101;
80978+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
80979
80980 return 0;
80981 }
80982diff --git a/mm/mempolicy.c b/mm/mempolicy.c
80983index 3df6d12..a11056a 100644
80984--- a/mm/mempolicy.c
80985+++ b/mm/mempolicy.c
80986@@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
80987 unsigned long vmstart;
80988 unsigned long vmend;
80989
80990+#ifdef CONFIG_PAX_SEGMEXEC
80991+ struct vm_area_struct *vma_m;
80992+#endif
80993+
80994 vma = find_vma(mm, start);
80995 if (!vma || vma->vm_start > start)
80996 return -EFAULT;
80997@@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
80998 if (err)
80999 goto out;
81000 }
81001+
81002 err = vma_replace_policy(vma, new_pol);
81003 if (err)
81004 goto out;
81005+
81006+#ifdef CONFIG_PAX_SEGMEXEC
81007+ vma_m = pax_find_mirror_vma(vma);
81008+ if (vma_m) {
81009+ err = vma_replace_policy(vma_m, new_pol);
81010+ if (err)
81011+ goto out;
81012+ }
81013+#endif
81014+
81015 }
81016
81017 out:
81018@@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
81019
81020 if (end < start)
81021 return -EINVAL;
81022+
81023+#ifdef CONFIG_PAX_SEGMEXEC
81024+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
81025+ if (end > SEGMEXEC_TASK_SIZE)
81026+ return -EINVAL;
81027+ } else
81028+#endif
81029+
81030+ if (end > TASK_SIZE)
81031+ return -EINVAL;
81032+
81033 if (end == start)
81034 return 0;
81035
81036@@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
81037 */
81038 tcred = __task_cred(task);
81039 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
81040- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
81041- !capable(CAP_SYS_NICE)) {
81042+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
81043 rcu_read_unlock();
81044 err = -EPERM;
81045 goto out_put;
81046@@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
81047 goto out;
81048 }
81049
81050+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81051+ if (mm != current->mm &&
81052+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
81053+ mmput(mm);
81054+ err = -EPERM;
81055+ goto out;
81056+ }
81057+#endif
81058+
81059 err = do_migrate_pages(mm, old, new,
81060 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
81061
81062diff --git a/mm/migrate.c b/mm/migrate.c
81063index 2fd8b4a..d70358f 100644
81064--- a/mm/migrate.c
81065+++ b/mm/migrate.c
81066@@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
81067 */
81068 tcred = __task_cred(task);
81069 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
81070- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
81071- !capable(CAP_SYS_NICE)) {
81072+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
81073 rcu_read_unlock();
81074 err = -EPERM;
81075 goto out;
81076diff --git a/mm/mlock.c b/mm/mlock.c
81077index c9bd528..da8d069 100644
81078--- a/mm/mlock.c
81079+++ b/mm/mlock.c
81080@@ -13,6 +13,7 @@
81081 #include <linux/pagemap.h>
81082 #include <linux/mempolicy.h>
81083 #include <linux/syscalls.h>
81084+#include <linux/security.h>
81085 #include <linux/sched.h>
81086 #include <linux/export.h>
81087 #include <linux/rmap.h>
81088@@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
81089 {
81090 unsigned long nstart, end, tmp;
81091 struct vm_area_struct * vma, * prev;
81092- int error;
81093+ int error = 0;
81094
81095 VM_BUG_ON(start & ~PAGE_MASK);
81096 VM_BUG_ON(len != PAGE_ALIGN(len));
81097@@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
81098 return -EINVAL;
81099 if (end == start)
81100 return 0;
81101+ if (end > TASK_SIZE)
81102+ return -EINVAL;
81103+
81104 vma = find_vma(current->mm, start);
81105 if (!vma || vma->vm_start > start)
81106 return -ENOMEM;
81107@@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
81108 for (nstart = start ; ; ) {
81109 vm_flags_t newflags;
81110
81111+#ifdef CONFIG_PAX_SEGMEXEC
81112+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
81113+ break;
81114+#endif
81115+
81116 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
81117
81118 newflags = vma->vm_flags | VM_LOCKED;
81119@@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
81120 lock_limit >>= PAGE_SHIFT;
81121
81122 /* check against resource limits */
81123+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
81124 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
81125 error = do_mlock(start, len, 1);
81126 up_write(&current->mm->mmap_sem);
81127@@ -528,6 +538,12 @@ static int do_mlockall(int flags)
81128 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
81129 vm_flags_t newflags;
81130
81131+#ifdef CONFIG_PAX_SEGMEXEC
81132+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
81133+ break;
81134+#endif
81135+
81136+ BUG_ON(vma->vm_end > TASK_SIZE);
81137 newflags = vma->vm_flags | VM_LOCKED;
81138 if (!(flags & MCL_CURRENT))
81139 newflags &= ~VM_LOCKED;
81140@@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
81141 lock_limit >>= PAGE_SHIFT;
81142
81143 ret = -ENOMEM;
81144+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
81145 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
81146 capable(CAP_IPC_LOCK))
81147 ret = do_mlockall(flags);
81148diff --git a/mm/mmap.c b/mm/mmap.c
81149index 8832b87..4bbb1b2 100644
81150--- a/mm/mmap.c
81151+++ b/mm/mmap.c
81152@@ -32,6 +32,7 @@
81153 #include <linux/khugepaged.h>
81154 #include <linux/uprobes.h>
81155 #include <linux/rbtree_augmented.h>
81156+#include <linux/random.h>
81157
81158 #include <asm/uaccess.h>
81159 #include <asm/cacheflush.h>
81160@@ -48,6 +49,16 @@
81161 #define arch_rebalance_pgtables(addr, len) (addr)
81162 #endif
81163
81164+static inline void verify_mm_writelocked(struct mm_struct *mm)
81165+{
81166+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
81167+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
81168+ up_read(&mm->mmap_sem);
81169+ BUG();
81170+ }
81171+#endif
81172+}
81173+
81174 static void unmap_region(struct mm_struct *mm,
81175 struct vm_area_struct *vma, struct vm_area_struct *prev,
81176 unsigned long start, unsigned long end);
81177@@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
81178 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
81179 *
81180 */
81181-pgprot_t protection_map[16] = {
81182+pgprot_t protection_map[16] __read_only = {
81183 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
81184 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
81185 };
81186
81187-pgprot_t vm_get_page_prot(unsigned long vm_flags)
81188+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
81189 {
81190- return __pgprot(pgprot_val(protection_map[vm_flags &
81191+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
81192 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
81193 pgprot_val(arch_vm_get_page_prot(vm_flags)));
81194+
81195+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
81196+ if (!(__supported_pte_mask & _PAGE_NX) &&
81197+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
81198+ (vm_flags & (VM_READ | VM_WRITE)))
81199+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
81200+#endif
81201+
81202+ return prot;
81203 }
81204 EXPORT_SYMBOL(vm_get_page_prot);
81205
81206 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
81207 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
81208 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
81209+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
81210 /*
81211 * Make sure vm_committed_as in one cacheline and not cacheline shared with
81212 * other variables. It can be updated by several CPUs frequently.
81213@@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
81214 struct vm_area_struct *next = vma->vm_next;
81215
81216 might_sleep();
81217+ BUG_ON(vma->vm_mirror);
81218 if (vma->vm_ops && vma->vm_ops->close)
81219 vma->vm_ops->close(vma);
81220 if (vma->vm_file)
81221@@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
81222 * not page aligned -Ram Gupta
81223 */
81224 rlim = rlimit(RLIMIT_DATA);
81225+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
81226 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
81227 (mm->end_data - mm->start_data) > rlim)
81228 goto out;
81229@@ -888,6 +911,12 @@ static int
81230 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
81231 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
81232 {
81233+
81234+#ifdef CONFIG_PAX_SEGMEXEC
81235+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
81236+ return 0;
81237+#endif
81238+
81239 if (is_mergeable_vma(vma, file, vm_flags) &&
81240 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
81241 if (vma->vm_pgoff == vm_pgoff)
81242@@ -907,6 +936,12 @@ static int
81243 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
81244 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
81245 {
81246+
81247+#ifdef CONFIG_PAX_SEGMEXEC
81248+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
81249+ return 0;
81250+#endif
81251+
81252 if (is_mergeable_vma(vma, file, vm_flags) &&
81253 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
81254 pgoff_t vm_pglen;
81255@@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
81256 struct vm_area_struct *vma_merge(struct mm_struct *mm,
81257 struct vm_area_struct *prev, unsigned long addr,
81258 unsigned long end, unsigned long vm_flags,
81259- struct anon_vma *anon_vma, struct file *file,
81260+ struct anon_vma *anon_vma, struct file *file,
81261 pgoff_t pgoff, struct mempolicy *policy)
81262 {
81263 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
81264 struct vm_area_struct *area, *next;
81265 int err;
81266
81267+#ifdef CONFIG_PAX_SEGMEXEC
81268+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
81269+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
81270+
81271+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
81272+#endif
81273+
81274 /*
81275 * We later require that vma->vm_flags == vm_flags,
81276 * so this tests vma->vm_flags & VM_SPECIAL, too.
81277@@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81278 if (next && next->vm_end == end) /* cases 6, 7, 8 */
81279 next = next->vm_next;
81280
81281+#ifdef CONFIG_PAX_SEGMEXEC
81282+ if (prev)
81283+ prev_m = pax_find_mirror_vma(prev);
81284+ if (area)
81285+ area_m = pax_find_mirror_vma(area);
81286+ if (next)
81287+ next_m = pax_find_mirror_vma(next);
81288+#endif
81289+
81290 /*
81291 * Can it merge with the predecessor?
81292 */
81293@@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81294 /* cases 1, 6 */
81295 err = vma_adjust(prev, prev->vm_start,
81296 next->vm_end, prev->vm_pgoff, NULL);
81297- } else /* cases 2, 5, 7 */
81298+
81299+#ifdef CONFIG_PAX_SEGMEXEC
81300+ if (!err && prev_m)
81301+ err = vma_adjust(prev_m, prev_m->vm_start,
81302+ next_m->vm_end, prev_m->vm_pgoff, NULL);
81303+#endif
81304+
81305+ } else { /* cases 2, 5, 7 */
81306 err = vma_adjust(prev, prev->vm_start,
81307 end, prev->vm_pgoff, NULL);
81308+
81309+#ifdef CONFIG_PAX_SEGMEXEC
81310+ if (!err && prev_m)
81311+ err = vma_adjust(prev_m, prev_m->vm_start,
81312+ end_m, prev_m->vm_pgoff, NULL);
81313+#endif
81314+
81315+ }
81316 if (err)
81317 return NULL;
81318 khugepaged_enter_vma_merge(prev);
81319@@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81320 mpol_equal(policy, vma_policy(next)) &&
81321 can_vma_merge_before(next, vm_flags,
81322 anon_vma, file, pgoff+pglen)) {
81323- if (prev && addr < prev->vm_end) /* case 4 */
81324+ if (prev && addr < prev->vm_end) { /* case 4 */
81325 err = vma_adjust(prev, prev->vm_start,
81326 addr, prev->vm_pgoff, NULL);
81327- else /* cases 3, 8 */
81328+
81329+#ifdef CONFIG_PAX_SEGMEXEC
81330+ if (!err && prev_m)
81331+ err = vma_adjust(prev_m, prev_m->vm_start,
81332+ addr_m, prev_m->vm_pgoff, NULL);
81333+#endif
81334+
81335+ } else { /* cases 3, 8 */
81336 err = vma_adjust(area, addr, next->vm_end,
81337 next->vm_pgoff - pglen, NULL);
81338+
81339+#ifdef CONFIG_PAX_SEGMEXEC
81340+ if (!err && area_m)
81341+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
81342+ next_m->vm_pgoff - pglen, NULL);
81343+#endif
81344+
81345+ }
81346 if (err)
81347 return NULL;
81348 khugepaged_enter_vma_merge(area);
81349@@ -1120,8 +1201,10 @@ none:
81350 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
81351 struct file *file, long pages)
81352 {
81353- const unsigned long stack_flags
81354- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
81355+
81356+#ifdef CONFIG_PAX_RANDMMAP
81357+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
81358+#endif
81359
81360 mm->total_vm += pages;
81361
81362@@ -1129,7 +1212,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
81363 mm->shared_vm += pages;
81364 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
81365 mm->exec_vm += pages;
81366- } else if (flags & stack_flags)
81367+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
81368 mm->stack_vm += pages;
81369 }
81370 #endif /* CONFIG_PROC_FS */
81371@@ -1165,7 +1248,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81372 * (the exception is when the underlying filesystem is noexec
81373 * mounted, in which case we dont add PROT_EXEC.)
81374 */
81375- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
81376+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
81377 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
81378 prot |= PROT_EXEC;
81379
81380@@ -1191,7 +1274,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81381 /* Obtain the address to map to. we verify (or select) it and ensure
81382 * that it represents a valid section of the address space.
81383 */
81384- addr = get_unmapped_area(file, addr, len, pgoff, flags);
81385+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
81386 if (addr & ~PAGE_MASK)
81387 return addr;
81388
81389@@ -1202,6 +1285,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81390 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
81391 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
81392
81393+#ifdef CONFIG_PAX_MPROTECT
81394+ if (mm->pax_flags & MF_PAX_MPROTECT) {
81395+#ifndef CONFIG_PAX_MPROTECT_COMPAT
81396+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
81397+ gr_log_rwxmmap(file);
81398+
81399+#ifdef CONFIG_PAX_EMUPLT
81400+ vm_flags &= ~VM_EXEC;
81401+#else
81402+ return -EPERM;
81403+#endif
81404+
81405+ }
81406+
81407+ if (!(vm_flags & VM_EXEC))
81408+ vm_flags &= ~VM_MAYEXEC;
81409+#else
81410+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
81411+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
81412+#endif
81413+ else
81414+ vm_flags &= ~VM_MAYWRITE;
81415+ }
81416+#endif
81417+
81418+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
81419+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
81420+ vm_flags &= ~VM_PAGEEXEC;
81421+#endif
81422+
81423 if (flags & MAP_LOCKED)
81424 if (!can_do_mlock())
81425 return -EPERM;
81426@@ -1213,6 +1326,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81427 locked += mm->locked_vm;
81428 lock_limit = rlimit(RLIMIT_MEMLOCK);
81429 lock_limit >>= PAGE_SHIFT;
81430+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
81431 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
81432 return -EAGAIN;
81433 }
81434@@ -1279,6 +1393,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81435 }
81436 }
81437
81438+ if (!gr_acl_handle_mmap(file, prot))
81439+ return -EACCES;
81440+
81441 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
81442 }
81443
81444@@ -1356,7 +1473,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
81445 vm_flags_t vm_flags = vma->vm_flags;
81446
81447 /* If it was private or non-writable, the write bit is already clear */
81448- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
81449+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
81450 return 0;
81451
81452 /* The backer wishes to know when pages are first written to? */
81453@@ -1405,16 +1522,30 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
81454 unsigned long charged = 0;
81455 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
81456
81457+#ifdef CONFIG_PAX_SEGMEXEC
81458+ struct vm_area_struct *vma_m = NULL;
81459+#endif
81460+
81461+ /*
81462+ * mm->mmap_sem is required to protect against another thread
81463+ * changing the mappings in case we sleep.
81464+ */
81465+ verify_mm_writelocked(mm);
81466+
81467 /* Clear old maps */
81468 error = -ENOMEM;
81469-munmap_back:
81470 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
81471 if (do_munmap(mm, addr, len))
81472 return -ENOMEM;
81473- goto munmap_back;
81474+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
81475 }
81476
81477 /* Check against address space limit. */
81478+
81479+#ifdef CONFIG_PAX_RANDMMAP
81480+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
81481+#endif
81482+
81483 if (!may_expand_vm(mm, len >> PAGE_SHIFT))
81484 return -ENOMEM;
81485
81486@@ -1460,6 +1591,16 @@ munmap_back:
81487 goto unacct_error;
81488 }
81489
81490+#ifdef CONFIG_PAX_SEGMEXEC
81491+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
81492+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81493+ if (!vma_m) {
81494+ error = -ENOMEM;
81495+ goto free_vma;
81496+ }
81497+ }
81498+#endif
81499+
81500 vma->vm_mm = mm;
81501 vma->vm_start = addr;
81502 vma->vm_end = addr + len;
81503@@ -1484,6 +1625,13 @@ munmap_back:
81504 if (error)
81505 goto unmap_and_free_vma;
81506
81507+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
81508+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
81509+ vma->vm_flags |= VM_PAGEEXEC;
81510+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
81511+ }
81512+#endif
81513+
81514 /* Can addr have changed??
81515 *
81516 * Answer: Yes, several device drivers can do it in their
81517@@ -1522,6 +1670,11 @@ munmap_back:
81518 vma_link(mm, vma, prev, rb_link, rb_parent);
81519 file = vma->vm_file;
81520
81521+#ifdef CONFIG_PAX_SEGMEXEC
81522+ if (vma_m)
81523+ BUG_ON(pax_mirror_vma(vma_m, vma));
81524+#endif
81525+
81526 /* Once vma denies write, undo our temporary denial count */
81527 if (correct_wcount)
81528 atomic_inc(&inode->i_writecount);
81529@@ -1529,6 +1682,7 @@ out:
81530 perf_event_mmap(vma);
81531
81532 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
81533+ track_exec_limit(mm, addr, addr + len, vm_flags);
81534 if (vm_flags & VM_LOCKED) {
81535 if (!mlock_vma_pages_range(vma, addr, addr + len))
81536 mm->locked_vm += (len >> PAGE_SHIFT);
81537@@ -1550,6 +1704,12 @@ unmap_and_free_vma:
81538 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
81539 charged = 0;
81540 free_vma:
81541+
81542+#ifdef CONFIG_PAX_SEGMEXEC
81543+ if (vma_m)
81544+ kmem_cache_free(vm_area_cachep, vma_m);
81545+#endif
81546+
81547 kmem_cache_free(vm_area_cachep, vma);
81548 unacct_error:
81549 if (charged)
81550@@ -1557,6 +1717,62 @@ unacct_error:
81551 return error;
81552 }
81553
81554+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81555+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81556+{
81557+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
81558+ return (random32() & 0xFF) << PAGE_SHIFT;
81559+
81560+ return 0;
81561+}
81562+#endif
81563+
81564+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
81565+{
81566+ if (!vma) {
81567+#ifdef CONFIG_STACK_GROWSUP
81568+ if (addr > sysctl_heap_stack_gap)
81569+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
81570+ else
81571+ vma = find_vma(current->mm, 0);
81572+ if (vma && (vma->vm_flags & VM_GROWSUP))
81573+ return false;
81574+#endif
81575+ return true;
81576+ }
81577+
81578+ if (addr + len > vma->vm_start)
81579+ return false;
81580+
81581+ if (vma->vm_flags & VM_GROWSDOWN)
81582+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
81583+#ifdef CONFIG_STACK_GROWSUP
81584+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
81585+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
81586+#endif
81587+ else if (offset)
81588+ return offset <= vma->vm_start - addr - len;
81589+
81590+ return true;
81591+}
81592+
81593+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
81594+{
81595+ if (vma->vm_start < len)
81596+ return -ENOMEM;
81597+
81598+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
81599+ if (offset <= vma->vm_start - len)
81600+ return vma->vm_start - len - offset;
81601+ else
81602+ return -ENOMEM;
81603+ }
81604+
81605+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
81606+ return vma->vm_start - len - sysctl_heap_stack_gap;
81607+ return -ENOMEM;
81608+}
81609+
81610 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
81611 {
81612 /*
81613@@ -1776,6 +1992,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
81614 struct mm_struct *mm = current->mm;
81615 struct vm_area_struct *vma;
81616 struct vm_unmapped_area_info info;
81617+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
81618
81619 if (len > TASK_SIZE)
81620 return -ENOMEM;
81621@@ -1783,17 +2000,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
81622 if (flags & MAP_FIXED)
81623 return addr;
81624
81625+#ifdef CONFIG_PAX_RANDMMAP
81626+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
81627+#endif
81628+
81629 if (addr) {
81630 addr = PAGE_ALIGN(addr);
81631 vma = find_vma(mm, addr);
81632- if (TASK_SIZE - len >= addr &&
81633- (!vma || addr + len <= vma->vm_start))
81634+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
81635 return addr;
81636 }
81637
81638 info.flags = 0;
81639 info.length = len;
81640 info.low_limit = TASK_UNMAPPED_BASE;
81641+
81642+#ifdef CONFIG_PAX_RANDMMAP
81643+ if (mm->pax_flags & MF_PAX_RANDMMAP)
81644+ info.low_limit += mm->delta_mmap;
81645+#endif
81646+
81647 info.high_limit = TASK_SIZE;
81648 info.align_mask = 0;
81649 return vm_unmapped_area(&info);
81650@@ -1802,10 +2028,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
81651
81652 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
81653 {
81654+
81655+#ifdef CONFIG_PAX_SEGMEXEC
81656+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
81657+ return;
81658+#endif
81659+
81660 /*
81661 * Is this a new hole at the lowest possible address?
81662 */
81663- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
81664+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
81665 mm->free_area_cache = addr;
81666 }
81667
81668@@ -1823,6 +2055,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81669 struct mm_struct *mm = current->mm;
81670 unsigned long addr = addr0;
81671 struct vm_unmapped_area_info info;
81672+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
81673
81674 /* requested length too big for entire address space */
81675 if (len > TASK_SIZE)
81676@@ -1831,12 +2064,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81677 if (flags & MAP_FIXED)
81678 return addr;
81679
81680+#ifdef CONFIG_PAX_RANDMMAP
81681+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
81682+#endif
81683+
81684 /* requesting a specific address */
81685 if (addr) {
81686 addr = PAGE_ALIGN(addr);
81687 vma = find_vma(mm, addr);
81688- if (TASK_SIZE - len >= addr &&
81689- (!vma || addr + len <= vma->vm_start))
81690+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
81691 return addr;
81692 }
81693
81694@@ -1857,6 +2093,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81695 VM_BUG_ON(addr != -ENOMEM);
81696 info.flags = 0;
81697 info.low_limit = TASK_UNMAPPED_BASE;
81698+
81699+#ifdef CONFIG_PAX_RANDMMAP
81700+ if (mm->pax_flags & MF_PAX_RANDMMAP)
81701+ info.low_limit += mm->delta_mmap;
81702+#endif
81703+
81704 info.high_limit = TASK_SIZE;
81705 addr = vm_unmapped_area(&info);
81706 }
81707@@ -1867,6 +2109,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81708
81709 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
81710 {
81711+
81712+#ifdef CONFIG_PAX_SEGMEXEC
81713+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
81714+ return;
81715+#endif
81716+
81717 /*
81718 * Is this a new hole at the highest possible address?
81719 */
81720@@ -1874,8 +2122,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
81721 mm->free_area_cache = addr;
81722
81723 /* dont allow allocations above current base */
81724- if (mm->free_area_cache > mm->mmap_base)
81725+ if (mm->free_area_cache > mm->mmap_base) {
81726 mm->free_area_cache = mm->mmap_base;
81727+ mm->cached_hole_size = ~0UL;
81728+ }
81729 }
81730
81731 unsigned long
81732@@ -1974,6 +2224,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
81733 return vma;
81734 }
81735
81736+#ifdef CONFIG_PAX_SEGMEXEC
81737+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
81738+{
81739+ struct vm_area_struct *vma_m;
81740+
81741+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
81742+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
81743+ BUG_ON(vma->vm_mirror);
81744+ return NULL;
81745+ }
81746+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
81747+ vma_m = vma->vm_mirror;
81748+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
81749+ BUG_ON(vma->vm_file != vma_m->vm_file);
81750+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
81751+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
81752+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
81753+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
81754+ return vma_m;
81755+}
81756+#endif
81757+
81758 /*
81759 * Verify that the stack growth is acceptable and
81760 * update accounting. This is shared with both the
81761@@ -1990,6 +2262,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
81762 return -ENOMEM;
81763
81764 /* Stack limit test */
81765+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
81766 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
81767 return -ENOMEM;
81768
81769@@ -2000,6 +2273,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
81770 locked = mm->locked_vm + grow;
81771 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
81772 limit >>= PAGE_SHIFT;
81773+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
81774 if (locked > limit && !capable(CAP_IPC_LOCK))
81775 return -ENOMEM;
81776 }
81777@@ -2029,37 +2303,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
81778 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
81779 * vma is the last one with address > vma->vm_end. Have to extend vma.
81780 */
81781+#ifndef CONFIG_IA64
81782+static
81783+#endif
81784 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
81785 {
81786 int error;
81787+ bool locknext;
81788
81789 if (!(vma->vm_flags & VM_GROWSUP))
81790 return -EFAULT;
81791
81792+ /* Also guard against wrapping around to address 0. */
81793+ if (address < PAGE_ALIGN(address+1))
81794+ address = PAGE_ALIGN(address+1);
81795+ else
81796+ return -ENOMEM;
81797+
81798 /*
81799 * We must make sure the anon_vma is allocated
81800 * so that the anon_vma locking is not a noop.
81801 */
81802 if (unlikely(anon_vma_prepare(vma)))
81803 return -ENOMEM;
81804+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
81805+ if (locknext && anon_vma_prepare(vma->vm_next))
81806+ return -ENOMEM;
81807 vma_lock_anon_vma(vma);
81808+ if (locknext)
81809+ vma_lock_anon_vma(vma->vm_next);
81810
81811 /*
81812 * vma->vm_start/vm_end cannot change under us because the caller
81813 * is required to hold the mmap_sem in read mode. We need the
81814- * anon_vma lock to serialize against concurrent expand_stacks.
81815- * Also guard against wrapping around to address 0.
81816+ * anon_vma locks to serialize against concurrent expand_stacks
81817+ * and expand_upwards.
81818 */
81819- if (address < PAGE_ALIGN(address+4))
81820- address = PAGE_ALIGN(address+4);
81821- else {
81822- vma_unlock_anon_vma(vma);
81823- return -ENOMEM;
81824- }
81825 error = 0;
81826
81827 /* Somebody else might have raced and expanded it already */
81828- if (address > vma->vm_end) {
81829+ 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)
81830+ error = -ENOMEM;
81831+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
81832 unsigned long size, grow;
81833
81834 size = address - vma->vm_start;
81835@@ -2094,6 +2379,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
81836 }
81837 }
81838 }
81839+ if (locknext)
81840+ vma_unlock_anon_vma(vma->vm_next);
81841 vma_unlock_anon_vma(vma);
81842 khugepaged_enter_vma_merge(vma);
81843 validate_mm(vma->vm_mm);
81844@@ -2108,6 +2395,8 @@ int expand_downwards(struct vm_area_struct *vma,
81845 unsigned long address)
81846 {
81847 int error;
81848+ bool lockprev = false;
81849+ struct vm_area_struct *prev;
81850
81851 /*
81852 * We must make sure the anon_vma is allocated
81853@@ -2121,6 +2410,15 @@ int expand_downwards(struct vm_area_struct *vma,
81854 if (error)
81855 return error;
81856
81857+ prev = vma->vm_prev;
81858+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
81859+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
81860+#endif
81861+ if (lockprev && anon_vma_prepare(prev))
81862+ return -ENOMEM;
81863+ if (lockprev)
81864+ vma_lock_anon_vma(prev);
81865+
81866 vma_lock_anon_vma(vma);
81867
81868 /*
81869@@ -2130,9 +2428,17 @@ int expand_downwards(struct vm_area_struct *vma,
81870 */
81871
81872 /* Somebody else might have raced and expanded it already */
81873- if (address < vma->vm_start) {
81874+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
81875+ error = -ENOMEM;
81876+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
81877 unsigned long size, grow;
81878
81879+#ifdef CONFIG_PAX_SEGMEXEC
81880+ struct vm_area_struct *vma_m;
81881+
81882+ vma_m = pax_find_mirror_vma(vma);
81883+#endif
81884+
81885 size = vma->vm_end - address;
81886 grow = (vma->vm_start - address) >> PAGE_SHIFT;
81887
81888@@ -2157,6 +2463,18 @@ int expand_downwards(struct vm_area_struct *vma,
81889 vma->vm_pgoff -= grow;
81890 anon_vma_interval_tree_post_update_vma(vma);
81891 vma_gap_update(vma);
81892+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
81893+
81894+#ifdef CONFIG_PAX_SEGMEXEC
81895+ if (vma_m) {
81896+ anon_vma_interval_tree_pre_update_vma(vma_m);
81897+ vma_m->vm_start -= grow << PAGE_SHIFT;
81898+ vma_m->vm_pgoff -= grow;
81899+ anon_vma_interval_tree_post_update_vma(vma_m);
81900+ vma_gap_update(vma_m);
81901+ }
81902+#endif
81903+
81904 spin_unlock(&vma->vm_mm->page_table_lock);
81905
81906 perf_event_mmap(vma);
81907@@ -2263,6 +2581,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
81908 do {
81909 long nrpages = vma_pages(vma);
81910
81911+#ifdef CONFIG_PAX_SEGMEXEC
81912+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
81913+ vma = remove_vma(vma);
81914+ continue;
81915+ }
81916+#endif
81917+
81918 if (vma->vm_flags & VM_ACCOUNT)
81919 nr_accounted += nrpages;
81920 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
81921@@ -2308,6 +2633,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
81922 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
81923 vma->vm_prev = NULL;
81924 do {
81925+
81926+#ifdef CONFIG_PAX_SEGMEXEC
81927+ if (vma->vm_mirror) {
81928+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
81929+ vma->vm_mirror->vm_mirror = NULL;
81930+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
81931+ vma->vm_mirror = NULL;
81932+ }
81933+#endif
81934+
81935 vma_rb_erase(vma, &mm->mm_rb);
81936 mm->map_count--;
81937 tail_vma = vma;
81938@@ -2339,14 +2674,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81939 struct vm_area_struct *new;
81940 int err = -ENOMEM;
81941
81942+#ifdef CONFIG_PAX_SEGMEXEC
81943+ struct vm_area_struct *vma_m, *new_m = NULL;
81944+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
81945+#endif
81946+
81947 if (is_vm_hugetlb_page(vma) && (addr &
81948 ~(huge_page_mask(hstate_vma(vma)))))
81949 return -EINVAL;
81950
81951+#ifdef CONFIG_PAX_SEGMEXEC
81952+ vma_m = pax_find_mirror_vma(vma);
81953+#endif
81954+
81955 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81956 if (!new)
81957 goto out_err;
81958
81959+#ifdef CONFIG_PAX_SEGMEXEC
81960+ if (vma_m) {
81961+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81962+ if (!new_m) {
81963+ kmem_cache_free(vm_area_cachep, new);
81964+ goto out_err;
81965+ }
81966+ }
81967+#endif
81968+
81969 /* most fields are the same, copy all, and then fixup */
81970 *new = *vma;
81971
81972@@ -2359,6 +2713,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81973 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
81974 }
81975
81976+#ifdef CONFIG_PAX_SEGMEXEC
81977+ if (vma_m) {
81978+ *new_m = *vma_m;
81979+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
81980+ new_m->vm_mirror = new;
81981+ new->vm_mirror = new_m;
81982+
81983+ if (new_below)
81984+ new_m->vm_end = addr_m;
81985+ else {
81986+ new_m->vm_start = addr_m;
81987+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
81988+ }
81989+ }
81990+#endif
81991+
81992 pol = mpol_dup(vma_policy(vma));
81993 if (IS_ERR(pol)) {
81994 err = PTR_ERR(pol);
81995@@ -2381,6 +2751,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81996 else
81997 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
81998
81999+#ifdef CONFIG_PAX_SEGMEXEC
82000+ if (!err && vma_m) {
82001+ if (anon_vma_clone(new_m, vma_m))
82002+ goto out_free_mpol;
82003+
82004+ mpol_get(pol);
82005+ vma_set_policy(new_m, pol);
82006+
82007+ if (new_m->vm_file)
82008+ get_file(new_m->vm_file);
82009+
82010+ if (new_m->vm_ops && new_m->vm_ops->open)
82011+ new_m->vm_ops->open(new_m);
82012+
82013+ if (new_below)
82014+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
82015+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
82016+ else
82017+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
82018+
82019+ if (err) {
82020+ if (new_m->vm_ops && new_m->vm_ops->close)
82021+ new_m->vm_ops->close(new_m);
82022+ if (new_m->vm_file)
82023+ fput(new_m->vm_file);
82024+ mpol_put(pol);
82025+ }
82026+ }
82027+#endif
82028+
82029 /* Success. */
82030 if (!err)
82031 return 0;
82032@@ -2390,10 +2790,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82033 new->vm_ops->close(new);
82034 if (new->vm_file)
82035 fput(new->vm_file);
82036- unlink_anon_vmas(new);
82037 out_free_mpol:
82038 mpol_put(pol);
82039 out_free_vma:
82040+
82041+#ifdef CONFIG_PAX_SEGMEXEC
82042+ if (new_m) {
82043+ unlink_anon_vmas(new_m);
82044+ kmem_cache_free(vm_area_cachep, new_m);
82045+ }
82046+#endif
82047+
82048+ unlink_anon_vmas(new);
82049 kmem_cache_free(vm_area_cachep, new);
82050 out_err:
82051 return err;
82052@@ -2406,6 +2814,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82053 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
82054 unsigned long addr, int new_below)
82055 {
82056+
82057+#ifdef CONFIG_PAX_SEGMEXEC
82058+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
82059+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
82060+ if (mm->map_count >= sysctl_max_map_count-1)
82061+ return -ENOMEM;
82062+ } else
82063+#endif
82064+
82065 if (mm->map_count >= sysctl_max_map_count)
82066 return -ENOMEM;
82067
82068@@ -2417,11 +2834,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
82069 * work. This now handles partial unmappings.
82070 * Jeremy Fitzhardinge <jeremy@goop.org>
82071 */
82072+#ifdef CONFIG_PAX_SEGMEXEC
82073 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
82074 {
82075+ int ret = __do_munmap(mm, start, len);
82076+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
82077+ return ret;
82078+
82079+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
82080+}
82081+
82082+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
82083+#else
82084+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
82085+#endif
82086+{
82087 unsigned long end;
82088 struct vm_area_struct *vma, *prev, *last;
82089
82090+ /*
82091+ * mm->mmap_sem is required to protect against another thread
82092+ * changing the mappings in case we sleep.
82093+ */
82094+ verify_mm_writelocked(mm);
82095+
82096 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
82097 return -EINVAL;
82098
82099@@ -2496,6 +2932,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
82100 /* Fix up all other VM information */
82101 remove_vma_list(mm, vma);
82102
82103+ track_exec_limit(mm, start, end, 0UL);
82104+
82105 return 0;
82106 }
82107
82108@@ -2504,6 +2942,13 @@ int vm_munmap(unsigned long start, size_t len)
82109 int ret;
82110 struct mm_struct *mm = current->mm;
82111
82112+
82113+#ifdef CONFIG_PAX_SEGMEXEC
82114+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
82115+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
82116+ return -EINVAL;
82117+#endif
82118+
82119 down_write(&mm->mmap_sem);
82120 ret = do_munmap(mm, start, len);
82121 up_write(&mm->mmap_sem);
82122@@ -2517,16 +2962,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
82123 return vm_munmap(addr, len);
82124 }
82125
82126-static inline void verify_mm_writelocked(struct mm_struct *mm)
82127-{
82128-#ifdef CONFIG_DEBUG_VM
82129- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
82130- WARN_ON(1);
82131- up_read(&mm->mmap_sem);
82132- }
82133-#endif
82134-}
82135-
82136 /*
82137 * this is really a simplified "do_mmap". it only handles
82138 * anonymous maps. eventually we may be able to do some
82139@@ -2540,6 +2975,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82140 struct rb_node ** rb_link, * rb_parent;
82141 pgoff_t pgoff = addr >> PAGE_SHIFT;
82142 int error;
82143+ unsigned long charged;
82144
82145 len = PAGE_ALIGN(len);
82146 if (!len)
82147@@ -2547,16 +2983,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82148
82149 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
82150
82151+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
82152+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
82153+ flags &= ~VM_EXEC;
82154+
82155+#ifdef CONFIG_PAX_MPROTECT
82156+ if (mm->pax_flags & MF_PAX_MPROTECT)
82157+ flags &= ~VM_MAYEXEC;
82158+#endif
82159+
82160+ }
82161+#endif
82162+
82163 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
82164 if (error & ~PAGE_MASK)
82165 return error;
82166
82167+ charged = len >> PAGE_SHIFT;
82168+
82169 /*
82170 * mlock MCL_FUTURE?
82171 */
82172 if (mm->def_flags & VM_LOCKED) {
82173 unsigned long locked, lock_limit;
82174- locked = len >> PAGE_SHIFT;
82175+ locked = charged;
82176 locked += mm->locked_vm;
82177 lock_limit = rlimit(RLIMIT_MEMLOCK);
82178 lock_limit >>= PAGE_SHIFT;
82179@@ -2573,21 +3023,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82180 /*
82181 * Clear old maps. this also does some error checking for us
82182 */
82183- munmap_back:
82184 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
82185 if (do_munmap(mm, addr, len))
82186 return -ENOMEM;
82187- goto munmap_back;
82188+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
82189 }
82190
82191 /* Check against address space limits *after* clearing old maps... */
82192- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
82193+ if (!may_expand_vm(mm, charged))
82194 return -ENOMEM;
82195
82196 if (mm->map_count > sysctl_max_map_count)
82197 return -ENOMEM;
82198
82199- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
82200+ if (security_vm_enough_memory_mm(mm, charged))
82201 return -ENOMEM;
82202
82203 /* Can we just expand an old private anonymous mapping? */
82204@@ -2601,7 +3050,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82205 */
82206 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82207 if (!vma) {
82208- vm_unacct_memory(len >> PAGE_SHIFT);
82209+ vm_unacct_memory(charged);
82210 return -ENOMEM;
82211 }
82212
82213@@ -2615,11 +3064,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82214 vma_link(mm, vma, prev, rb_link, rb_parent);
82215 out:
82216 perf_event_mmap(vma);
82217- mm->total_vm += len >> PAGE_SHIFT;
82218+ mm->total_vm += charged;
82219 if (flags & VM_LOCKED) {
82220 if (!mlock_vma_pages_range(vma, addr, addr + len))
82221- mm->locked_vm += (len >> PAGE_SHIFT);
82222+ mm->locked_vm += charged;
82223 }
82224+ track_exec_limit(mm, addr, addr + len, flags);
82225 return addr;
82226 }
82227
82228@@ -2677,6 +3127,7 @@ void exit_mmap(struct mm_struct *mm)
82229 while (vma) {
82230 if (vma->vm_flags & VM_ACCOUNT)
82231 nr_accounted += vma_pages(vma);
82232+ vma->vm_mirror = NULL;
82233 vma = remove_vma(vma);
82234 }
82235 vm_unacct_memory(nr_accounted);
82236@@ -2693,6 +3144,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
82237 struct vm_area_struct *prev;
82238 struct rb_node **rb_link, *rb_parent;
82239
82240+#ifdef CONFIG_PAX_SEGMEXEC
82241+ struct vm_area_struct *vma_m = NULL;
82242+#endif
82243+
82244+ if (security_mmap_addr(vma->vm_start))
82245+ return -EPERM;
82246+
82247 /*
82248 * The vm_pgoff of a purely anonymous vma should be irrelevant
82249 * until its first write fault, when page's anon_vma and index
82250@@ -2716,7 +3174,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
82251 security_vm_enough_memory_mm(mm, vma_pages(vma)))
82252 return -ENOMEM;
82253
82254+#ifdef CONFIG_PAX_SEGMEXEC
82255+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
82256+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82257+ if (!vma_m)
82258+ return -ENOMEM;
82259+ }
82260+#endif
82261+
82262 vma_link(mm, vma, prev, rb_link, rb_parent);
82263+
82264+#ifdef CONFIG_PAX_SEGMEXEC
82265+ if (vma_m)
82266+ BUG_ON(pax_mirror_vma(vma_m, vma));
82267+#endif
82268+
82269 return 0;
82270 }
82271
82272@@ -2736,6 +3208,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
82273 struct mempolicy *pol;
82274 bool faulted_in_anon_vma = true;
82275
82276+ BUG_ON(vma->vm_mirror);
82277+
82278 /*
82279 * If anonymous vma has not yet been faulted, update new pgoff
82280 * to match new location, to increase its chance of merging.
82281@@ -2802,6 +3276,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
82282 return NULL;
82283 }
82284
82285+#ifdef CONFIG_PAX_SEGMEXEC
82286+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
82287+{
82288+ struct vm_area_struct *prev_m;
82289+ struct rb_node **rb_link_m, *rb_parent_m;
82290+ struct mempolicy *pol_m;
82291+
82292+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
82293+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
82294+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
82295+ *vma_m = *vma;
82296+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
82297+ if (anon_vma_clone(vma_m, vma))
82298+ return -ENOMEM;
82299+ pol_m = vma_policy(vma_m);
82300+ mpol_get(pol_m);
82301+ vma_set_policy(vma_m, pol_m);
82302+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
82303+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
82304+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
82305+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
82306+ if (vma_m->vm_file)
82307+ get_file(vma_m->vm_file);
82308+ if (vma_m->vm_ops && vma_m->vm_ops->open)
82309+ vma_m->vm_ops->open(vma_m);
82310+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
82311+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
82312+ vma_m->vm_mirror = vma;
82313+ vma->vm_mirror = vma_m;
82314+ return 0;
82315+}
82316+#endif
82317+
82318 /*
82319 * Return true if the calling process may expand its vm space by the passed
82320 * number of pages
82321@@ -2813,6 +3320,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
82322
82323 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
82324
82325+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
82326 if (cur + npages > lim)
82327 return 0;
82328 return 1;
82329@@ -2883,6 +3391,22 @@ int install_special_mapping(struct mm_struct *mm,
82330 vma->vm_start = addr;
82331 vma->vm_end = addr + len;
82332
82333+#ifdef CONFIG_PAX_MPROTECT
82334+ if (mm->pax_flags & MF_PAX_MPROTECT) {
82335+#ifndef CONFIG_PAX_MPROTECT_COMPAT
82336+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
82337+ return -EPERM;
82338+ if (!(vm_flags & VM_EXEC))
82339+ vm_flags &= ~VM_MAYEXEC;
82340+#else
82341+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
82342+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
82343+#endif
82344+ else
82345+ vm_flags &= ~VM_MAYWRITE;
82346+ }
82347+#endif
82348+
82349 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
82350 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
82351
82352diff --git a/mm/mprotect.c b/mm/mprotect.c
82353index 94722a4..9837984 100644
82354--- a/mm/mprotect.c
82355+++ b/mm/mprotect.c
82356@@ -23,10 +23,17 @@
82357 #include <linux/mmu_notifier.h>
82358 #include <linux/migrate.h>
82359 #include <linux/perf_event.h>
82360+
82361+#ifdef CONFIG_PAX_MPROTECT
82362+#include <linux/elf.h>
82363+#include <linux/binfmts.h>
82364+#endif
82365+
82366 #include <asm/uaccess.h>
82367 #include <asm/pgtable.h>
82368 #include <asm/cacheflush.h>
82369 #include <asm/tlbflush.h>
82370+#include <asm/mmu_context.h>
82371
82372 #ifndef pgprot_modify
82373 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
82374@@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
82375 return pages;
82376 }
82377
82378+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
82379+/* called while holding the mmap semaphor for writing except stack expansion */
82380+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
82381+{
82382+ unsigned long oldlimit, newlimit = 0UL;
82383+
82384+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
82385+ return;
82386+
82387+ spin_lock(&mm->page_table_lock);
82388+ oldlimit = mm->context.user_cs_limit;
82389+ if ((prot & VM_EXEC) && oldlimit < end)
82390+ /* USER_CS limit moved up */
82391+ newlimit = end;
82392+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
82393+ /* USER_CS limit moved down */
82394+ newlimit = start;
82395+
82396+ if (newlimit) {
82397+ mm->context.user_cs_limit = newlimit;
82398+
82399+#ifdef CONFIG_SMP
82400+ wmb();
82401+ cpus_clear(mm->context.cpu_user_cs_mask);
82402+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
82403+#endif
82404+
82405+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
82406+ }
82407+ spin_unlock(&mm->page_table_lock);
82408+ if (newlimit == end) {
82409+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
82410+
82411+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
82412+ if (is_vm_hugetlb_page(vma))
82413+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
82414+ else
82415+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
82416+ }
82417+}
82418+#endif
82419+
82420 int
82421 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
82422 unsigned long start, unsigned long end, unsigned long newflags)
82423@@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
82424 int error;
82425 int dirty_accountable = 0;
82426
82427+#ifdef CONFIG_PAX_SEGMEXEC
82428+ struct vm_area_struct *vma_m = NULL;
82429+ unsigned long start_m, end_m;
82430+
82431+ start_m = start + SEGMEXEC_TASK_SIZE;
82432+ end_m = end + SEGMEXEC_TASK_SIZE;
82433+#endif
82434+
82435 if (newflags == oldflags) {
82436 *pprev = vma;
82437 return 0;
82438 }
82439
82440+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
82441+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
82442+
82443+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
82444+ return -ENOMEM;
82445+
82446+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
82447+ return -ENOMEM;
82448+ }
82449+
82450 /*
82451 * If we make a private mapping writable we increase our commit;
82452 * but (without finer accounting) cannot reduce our commit if we
82453@@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
82454 }
82455 }
82456
82457+#ifdef CONFIG_PAX_SEGMEXEC
82458+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
82459+ if (start != vma->vm_start) {
82460+ error = split_vma(mm, vma, start, 1);
82461+ if (error)
82462+ goto fail;
82463+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
82464+ *pprev = (*pprev)->vm_next;
82465+ }
82466+
82467+ if (end != vma->vm_end) {
82468+ error = split_vma(mm, vma, end, 0);
82469+ if (error)
82470+ goto fail;
82471+ }
82472+
82473+ if (pax_find_mirror_vma(vma)) {
82474+ error = __do_munmap(mm, start_m, end_m - start_m);
82475+ if (error)
82476+ goto fail;
82477+ } else {
82478+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82479+ if (!vma_m) {
82480+ error = -ENOMEM;
82481+ goto fail;
82482+ }
82483+ vma->vm_flags = newflags;
82484+ error = pax_mirror_vma(vma_m, vma);
82485+ if (error) {
82486+ vma->vm_flags = oldflags;
82487+ goto fail;
82488+ }
82489+ }
82490+ }
82491+#endif
82492+
82493 /*
82494 * First try to merge with previous and/or next vma.
82495 */
82496@@ -296,9 +399,21 @@ success:
82497 * vm_flags and vm_page_prot are protected by the mmap_sem
82498 * held in write mode.
82499 */
82500+
82501+#ifdef CONFIG_PAX_SEGMEXEC
82502+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
82503+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
82504+#endif
82505+
82506 vma->vm_flags = newflags;
82507+
82508+#ifdef CONFIG_PAX_MPROTECT
82509+ if (mm->binfmt && mm->binfmt->handle_mprotect)
82510+ mm->binfmt->handle_mprotect(vma, newflags);
82511+#endif
82512+
82513 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
82514- vm_get_page_prot(newflags));
82515+ vm_get_page_prot(vma->vm_flags));
82516
82517 if (vma_wants_writenotify(vma)) {
82518 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
82519@@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82520 end = start + len;
82521 if (end <= start)
82522 return -ENOMEM;
82523+
82524+#ifdef CONFIG_PAX_SEGMEXEC
82525+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
82526+ if (end > SEGMEXEC_TASK_SIZE)
82527+ return -EINVAL;
82528+ } else
82529+#endif
82530+
82531+ if (end > TASK_SIZE)
82532+ return -EINVAL;
82533+
82534 if (!arch_validate_prot(prot))
82535 return -EINVAL;
82536
82537@@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82538 /*
82539 * Does the application expect PROT_READ to imply PROT_EXEC:
82540 */
82541- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
82542+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
82543 prot |= PROT_EXEC;
82544
82545 vm_flags = calc_vm_prot_bits(prot);
82546@@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82547 if (start > vma->vm_start)
82548 prev = vma;
82549
82550+#ifdef CONFIG_PAX_MPROTECT
82551+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
82552+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
82553+#endif
82554+
82555 for (nstart = start ; ; ) {
82556 unsigned long newflags;
82557
82558@@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82559
82560 /* newflags >> 4 shift VM_MAY% in place of VM_% */
82561 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
82562+ if (prot & (PROT_WRITE | PROT_EXEC))
82563+ gr_log_rwxmprotect(vma->vm_file);
82564+
82565+ error = -EACCES;
82566+ goto out;
82567+ }
82568+
82569+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
82570 error = -EACCES;
82571 goto out;
82572 }
82573@@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82574 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
82575 if (error)
82576 goto out;
82577+
82578+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
82579+
82580 nstart = tmp;
82581
82582 if (nstart < prev->vm_end)
82583diff --git a/mm/mremap.c b/mm/mremap.c
82584index e1031e1..1f2a0a1 100644
82585--- a/mm/mremap.c
82586+++ b/mm/mremap.c
82587@@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
82588 continue;
82589 pte = ptep_get_and_clear(mm, old_addr, old_pte);
82590 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
82591+
82592+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
82593+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
82594+ pte = pte_exprotect(pte);
82595+#endif
82596+
82597 set_pte_at(mm, new_addr, new_pte, pte);
82598 }
82599
82600@@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
82601 if (is_vm_hugetlb_page(vma))
82602 goto Einval;
82603
82604+#ifdef CONFIG_PAX_SEGMEXEC
82605+ if (pax_find_mirror_vma(vma))
82606+ goto Einval;
82607+#endif
82608+
82609 /* We can't remap across vm area boundaries */
82610 if (old_len > vma->vm_end - addr)
82611 goto Efault;
82612@@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
82613 unsigned long ret = -EINVAL;
82614 unsigned long charged = 0;
82615 unsigned long map_flags;
82616+ unsigned long pax_task_size = TASK_SIZE;
82617
82618 if (new_addr & ~PAGE_MASK)
82619 goto out;
82620
82621- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
82622+#ifdef CONFIG_PAX_SEGMEXEC
82623+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
82624+ pax_task_size = SEGMEXEC_TASK_SIZE;
82625+#endif
82626+
82627+ pax_task_size -= PAGE_SIZE;
82628+
82629+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
82630 goto out;
82631
82632 /* Check if the location we're moving into overlaps the
82633 * old location at all, and fail if it does.
82634 */
82635- if ((new_addr <= addr) && (new_addr+new_len) > addr)
82636- goto out;
82637-
82638- if ((addr <= new_addr) && (addr+old_len) > new_addr)
82639+ if (addr + old_len > new_addr && new_addr + new_len > addr)
82640 goto out;
82641
82642 ret = do_munmap(mm, new_addr, new_len);
82643@@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82644 struct vm_area_struct *vma;
82645 unsigned long ret = -EINVAL;
82646 unsigned long charged = 0;
82647+ unsigned long pax_task_size = TASK_SIZE;
82648
82649 down_write(&current->mm->mmap_sem);
82650
82651@@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82652 if (!new_len)
82653 goto out;
82654
82655+#ifdef CONFIG_PAX_SEGMEXEC
82656+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
82657+ pax_task_size = SEGMEXEC_TASK_SIZE;
82658+#endif
82659+
82660+ pax_task_size -= PAGE_SIZE;
82661+
82662+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
82663+ old_len > pax_task_size || addr > pax_task_size-old_len)
82664+ goto out;
82665+
82666 if (flags & MREMAP_FIXED) {
82667 if (flags & MREMAP_MAYMOVE)
82668 ret = mremap_to(addr, old_len, new_addr, new_len);
82669@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82670 addr + new_len);
82671 }
82672 ret = addr;
82673+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
82674 goto out;
82675 }
82676 }
82677@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82678 goto out;
82679 }
82680
82681+ map_flags = vma->vm_flags;
82682 ret = move_vma(vma, addr, old_len, new_len, new_addr);
82683+ if (!(ret & ~PAGE_MASK)) {
82684+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
82685+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
82686+ }
82687 }
82688 out:
82689 if (ret & ~PAGE_MASK)
82690diff --git a/mm/nommu.c b/mm/nommu.c
82691index 79c3cac..4d357e0 100644
82692--- a/mm/nommu.c
82693+++ b/mm/nommu.c
82694@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
82695 int sysctl_overcommit_ratio = 50; /* default is 50% */
82696 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
82697 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
82698-int heap_stack_gap = 0;
82699
82700 atomic_long_t mmap_pages_allocated;
82701
82702@@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
82703 EXPORT_SYMBOL(find_vma);
82704
82705 /*
82706- * find a VMA
82707- * - we don't extend stack VMAs under NOMMU conditions
82708- */
82709-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
82710-{
82711- return find_vma(mm, addr);
82712-}
82713-
82714-/*
82715 * expand a stack to a given address
82716 * - not supported under NOMMU conditions
82717 */
82718@@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
82719
82720 /* most fields are the same, copy all, and then fixup */
82721 *new = *vma;
82722+ INIT_LIST_HEAD(&new->anon_vma_chain);
82723 *region = *vma->vm_region;
82724 new->vm_region = region;
82725
82726diff --git a/mm/page-writeback.c b/mm/page-writeback.c
82727index 0713bfb..b95bb87 100644
82728--- a/mm/page-writeback.c
82729+++ b/mm/page-writeback.c
82730@@ -655,7 +655,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
82731 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
82732 * - the bdi dirty thresh drops quickly due to change of JBOD workload
82733 */
82734-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
82735+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
82736 unsigned long thresh,
82737 unsigned long bg_thresh,
82738 unsigned long dirty,
82739@@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
82740 }
82741 }
82742
82743-static struct notifier_block __cpuinitdata ratelimit_nb = {
82744+static struct notifier_block ratelimit_nb = {
82745 .notifier_call = ratelimit_handler,
82746 .next = NULL,
82747 };
82748diff --git a/mm/page_alloc.c b/mm/page_alloc.c
82749index 6a83cd3..3ab04ef 100644
82750--- a/mm/page_alloc.c
82751+++ b/mm/page_alloc.c
82752@@ -58,6 +58,7 @@
82753 #include <linux/prefetch.h>
82754 #include <linux/migrate.h>
82755 #include <linux/page-debug-flags.h>
82756+#include <linux/random.h>
82757
82758 #include <asm/tlbflush.h>
82759 #include <asm/div64.h>
82760@@ -338,7 +339,7 @@ out:
82761 * This usage means that zero-order pages may not be compound.
82762 */
82763
82764-static void free_compound_page(struct page *page)
82765+void free_compound_page(struct page *page)
82766 {
82767 __free_pages_ok(page, compound_order(page));
82768 }
82769@@ -693,6 +694,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
82770 int i;
82771 int bad = 0;
82772
82773+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82774+ unsigned long index = 1UL << order;
82775+#endif
82776+
82777 trace_mm_page_free(page, order);
82778 kmemcheck_free_shadow(page, order);
82779
82780@@ -708,6 +713,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
82781 debug_check_no_obj_freed(page_address(page),
82782 PAGE_SIZE << order);
82783 }
82784+
82785+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82786+ for (; index; --index)
82787+ sanitize_highpage(page + index - 1);
82788+#endif
82789+
82790 arch_free_page(page, order);
82791 kernel_map_pages(page, 1 << order, 0);
82792
82793@@ -730,6 +741,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
82794 local_irq_restore(flags);
82795 }
82796
82797+#ifdef CONFIG_PAX_LATENT_ENTROPY
82798+bool __meminitdata extra_latent_entropy;
82799+
82800+static int __init setup_pax_extra_latent_entropy(char *str)
82801+{
82802+ extra_latent_entropy = true;
82803+ return 0;
82804+}
82805+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
82806+
82807+volatile u64 latent_entropy;
82808+#endif
82809+
82810 /*
82811 * Read access to zone->managed_pages is safe because it's unsigned long,
82812 * but we still need to serialize writers. Currently all callers of
82813@@ -752,6 +776,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
82814 set_page_count(p, 0);
82815 }
82816
82817+#ifdef CONFIG_PAX_LATENT_ENTROPY
82818+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
82819+ u64 hash = 0;
82820+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
82821+ const u64 *data = lowmem_page_address(page);
82822+
82823+ for (index = 0; index < end; index++)
82824+ hash ^= hash + data[index];
82825+ latent_entropy ^= hash;
82826+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
82827+ }
82828+#endif
82829+
82830 page_zone(page)->managed_pages += 1 << order;
82831 set_page_refcounted(page);
82832 __free_pages(page, order);
82833@@ -861,8 +898,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
82834 arch_alloc_page(page, order);
82835 kernel_map_pages(page, 1 << order, 1);
82836
82837+#ifndef CONFIG_PAX_MEMORY_SANITIZE
82838 if (gfp_flags & __GFP_ZERO)
82839 prep_zero_page(page, order, gfp_flags);
82840+#endif
82841
82842 if (order && (gfp_flags & __GFP_COMP))
82843 prep_compound_page(page, order);
82844@@ -3752,7 +3791,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
82845 unsigned long pfn;
82846
82847 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
82848+#ifdef CONFIG_X86_32
82849+ /* boot failures in VMware 8 on 32bit vanilla since
82850+ this change */
82851+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
82852+#else
82853 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
82854+#endif
82855 return 1;
82856 }
82857 return 0;
82858diff --git a/mm/percpu.c b/mm/percpu.c
82859index 8c8e08f..73a5cda 100644
82860--- a/mm/percpu.c
82861+++ b/mm/percpu.c
82862@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
82863 static unsigned int pcpu_high_unit_cpu __read_mostly;
82864
82865 /* the address of the first chunk which starts with the kernel static area */
82866-void *pcpu_base_addr __read_mostly;
82867+void *pcpu_base_addr __read_only;
82868 EXPORT_SYMBOL_GPL(pcpu_base_addr);
82869
82870 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
82871diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
82872index fd26d04..0cea1b0 100644
82873--- a/mm/process_vm_access.c
82874+++ b/mm/process_vm_access.c
82875@@ -13,6 +13,7 @@
82876 #include <linux/uio.h>
82877 #include <linux/sched.h>
82878 #include <linux/highmem.h>
82879+#include <linux/security.h>
82880 #include <linux/ptrace.h>
82881 #include <linux/slab.h>
82882 #include <linux/syscalls.h>
82883@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
82884 size_t iov_l_curr_offset = 0;
82885 ssize_t iov_len;
82886
82887+ return -ENOSYS; // PaX: until properly audited
82888+
82889 /*
82890 * Work out how many pages of struct pages we're going to need
82891 * when eventually calling get_user_pages
82892 */
82893 for (i = 0; i < riovcnt; i++) {
82894 iov_len = rvec[i].iov_len;
82895- if (iov_len > 0) {
82896- nr_pages_iov = ((unsigned long)rvec[i].iov_base
82897- + iov_len)
82898- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
82899- / PAGE_SIZE + 1;
82900- nr_pages = max(nr_pages, nr_pages_iov);
82901- }
82902+ if (iov_len <= 0)
82903+ continue;
82904+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
82905+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
82906+ nr_pages = max(nr_pages, nr_pages_iov);
82907 }
82908
82909 if (nr_pages == 0)
82910@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
82911 goto free_proc_pages;
82912 }
82913
82914+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
82915+ rc = -EPERM;
82916+ goto put_task_struct;
82917+ }
82918+
82919 mm = mm_access(task, PTRACE_MODE_ATTACH);
82920 if (!mm || IS_ERR(mm)) {
82921 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
82922diff --git a/mm/rmap.c b/mm/rmap.c
82923index 2c78f8c..9e9c624 100644
82924--- a/mm/rmap.c
82925+++ b/mm/rmap.c
82926@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82927 struct anon_vma *anon_vma = vma->anon_vma;
82928 struct anon_vma_chain *avc;
82929
82930+#ifdef CONFIG_PAX_SEGMEXEC
82931+ struct anon_vma_chain *avc_m = NULL;
82932+#endif
82933+
82934 might_sleep();
82935 if (unlikely(!anon_vma)) {
82936 struct mm_struct *mm = vma->vm_mm;
82937@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82938 if (!avc)
82939 goto out_enomem;
82940
82941+#ifdef CONFIG_PAX_SEGMEXEC
82942+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
82943+ if (!avc_m)
82944+ goto out_enomem_free_avc;
82945+#endif
82946+
82947 anon_vma = find_mergeable_anon_vma(vma);
82948 allocated = NULL;
82949 if (!anon_vma) {
82950@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82951 /* page_table_lock to protect against threads */
82952 spin_lock(&mm->page_table_lock);
82953 if (likely(!vma->anon_vma)) {
82954+
82955+#ifdef CONFIG_PAX_SEGMEXEC
82956+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
82957+
82958+ if (vma_m) {
82959+ BUG_ON(vma_m->anon_vma);
82960+ vma_m->anon_vma = anon_vma;
82961+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
82962+ avc_m = NULL;
82963+ }
82964+#endif
82965+
82966 vma->anon_vma = anon_vma;
82967 anon_vma_chain_link(vma, avc, anon_vma);
82968 allocated = NULL;
82969@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82970
82971 if (unlikely(allocated))
82972 put_anon_vma(allocated);
82973+
82974+#ifdef CONFIG_PAX_SEGMEXEC
82975+ if (unlikely(avc_m))
82976+ anon_vma_chain_free(avc_m);
82977+#endif
82978+
82979 if (unlikely(avc))
82980 anon_vma_chain_free(avc);
82981 }
82982 return 0;
82983
82984 out_enomem_free_avc:
82985+
82986+#ifdef CONFIG_PAX_SEGMEXEC
82987+ if (avc_m)
82988+ anon_vma_chain_free(avc_m);
82989+#endif
82990+
82991 anon_vma_chain_free(avc);
82992 out_enomem:
82993 return -ENOMEM;
82994@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
82995 * Attach the anon_vmas from src to dst.
82996 * Returns 0 on success, -ENOMEM on failure.
82997 */
82998-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
82999+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
83000 {
83001 struct anon_vma_chain *avc, *pavc;
83002 struct anon_vma *root = NULL;
83003@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
83004 * the corresponding VMA in the parent process is attached to.
83005 * Returns 0 on success, non-zero on failure.
83006 */
83007-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
83008+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
83009 {
83010 struct anon_vma_chain *avc;
83011 struct anon_vma *anon_vma;
83012diff --git a/mm/shmem.c b/mm/shmem.c
83013index efd0b3a..994b702 100644
83014--- a/mm/shmem.c
83015+++ b/mm/shmem.c
83016@@ -31,7 +31,7 @@
83017 #include <linux/export.h>
83018 #include <linux/swap.h>
83019
83020-static struct vfsmount *shm_mnt;
83021+struct vfsmount *shm_mnt;
83022
83023 #ifdef CONFIG_SHMEM
83024 /*
83025@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
83026 #define BOGO_DIRENT_SIZE 20
83027
83028 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
83029-#define SHORT_SYMLINK_LEN 128
83030+#define SHORT_SYMLINK_LEN 64
83031
83032 /*
83033 * shmem_fallocate and shmem_writepage communicate via inode->i_private
83034@@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
83035 static int shmem_xattr_validate(const char *name)
83036 {
83037 struct { const char *prefix; size_t len; } arr[] = {
83038+
83039+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83040+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
83041+#endif
83042+
83043 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
83044 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
83045 };
83046@@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
83047 if (err)
83048 return err;
83049
83050+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83051+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
83052+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
83053+ return -EOPNOTSUPP;
83054+ if (size > 8)
83055+ return -EINVAL;
83056+ }
83057+#endif
83058+
83059 return simple_xattr_set(&info->xattrs, name, value, size, flags);
83060 }
83061
83062@@ -2562,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
83063 int err = -ENOMEM;
83064
83065 /* Round up to L1_CACHE_BYTES to resist false sharing */
83066- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
83067- L1_CACHE_BYTES), GFP_KERNEL);
83068+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
83069 if (!sbinfo)
83070 return -ENOMEM;
83071
83072diff --git a/mm/slab.c b/mm/slab.c
83073index e7667a3..a48e73b 100644
83074--- a/mm/slab.c
83075+++ b/mm/slab.c
83076@@ -306,7 +306,7 @@ struct kmem_list3 {
83077 * Need this for bootstrapping a per node allocator.
83078 */
83079 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
83080-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
83081+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
83082 #define CACHE_CACHE 0
83083 #define SIZE_AC MAX_NUMNODES
83084 #define SIZE_L3 (2 * MAX_NUMNODES)
83085@@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
83086 if ((x)->max_freeable < i) \
83087 (x)->max_freeable = i; \
83088 } while (0)
83089-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
83090-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
83091-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
83092-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
83093+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
83094+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
83095+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
83096+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
83097 #else
83098 #define STATS_INC_ACTIVE(x) do { } while (0)
83099 #define STATS_DEC_ACTIVE(x) do { } while (0)
83100@@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
83101 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
83102 */
83103 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
83104- const struct slab *slab, void *obj)
83105+ const struct slab *slab, const void *obj)
83106 {
83107 u32 offset = (obj - slab->s_mem);
83108 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
83109@@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
83110 struct cache_names {
83111 char *name;
83112 char *name_dma;
83113+ char *name_usercopy;
83114 };
83115
83116 static struct cache_names __initdata cache_names[] = {
83117-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
83118+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
83119 #include <linux/kmalloc_sizes.h>
83120- {NULL,}
83121+ {NULL}
83122 #undef CACHE
83123 };
83124
83125@@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
83126 if (unlikely(gfpflags & GFP_DMA))
83127 return csizep->cs_dmacachep;
83128 #endif
83129+
83130+#ifdef CONFIG_PAX_USERCOPY_SLABS
83131+ if (unlikely(gfpflags & GFP_USERCOPY))
83132+ return csizep->cs_usercopycachep;
83133+#endif
83134+
83135 return csizep->cs_cachep;
83136 }
83137
83138@@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
83139 return notifier_from_errno(err);
83140 }
83141
83142-static struct notifier_block __cpuinitdata cpucache_notifier = {
83143+static struct notifier_block cpucache_notifier = {
83144 &cpuup_callback, NULL, 0
83145 };
83146
83147@@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
83148 */
83149
83150 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
83151- sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
83152+ sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
83153
83154 if (INDEX_AC != INDEX_L3)
83155 sizes[INDEX_L3].cs_cachep =
83156 create_kmalloc_cache(names[INDEX_L3].name,
83157- sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
83158+ sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
83159
83160 slab_early_init = 0;
83161
83162@@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
83163 */
83164 if (!sizes->cs_cachep)
83165 sizes->cs_cachep = create_kmalloc_cache(names->name,
83166- sizes->cs_size, ARCH_KMALLOC_FLAGS);
83167+ sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
83168
83169 #ifdef CONFIG_ZONE_DMA
83170 sizes->cs_dmacachep = create_kmalloc_cache(
83171 names->name_dma, sizes->cs_size,
83172 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
83173 #endif
83174+
83175+#ifdef CONFIG_PAX_USERCOPY_SLABS
83176+ sizes->cs_usercopycachep = create_kmalloc_cache(
83177+ names->name_usercopy, sizes->cs_size,
83178+ ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
83179+#endif
83180+
83181 sizes++;
83182 names++;
83183 }
83184@@ -3924,6 +3938,7 @@ void kfree(const void *objp)
83185
83186 if (unlikely(ZERO_OR_NULL_PTR(objp)))
83187 return;
83188+ VM_BUG_ON(!virt_addr_valid(objp));
83189 local_irq_save(flags);
83190 kfree_debugcheck(objp);
83191 c = virt_to_cache(objp);
83192@@ -4365,10 +4380,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
83193 }
83194 /* cpu stats */
83195 {
83196- unsigned long allochit = atomic_read(&cachep->allochit);
83197- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
83198- unsigned long freehit = atomic_read(&cachep->freehit);
83199- unsigned long freemiss = atomic_read(&cachep->freemiss);
83200+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
83201+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
83202+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
83203+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
83204
83205 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
83206 allochit, allocmiss, freehit, freemiss);
83207@@ -4600,13 +4615,71 @@ static const struct file_operations proc_slabstats_operations = {
83208 static int __init slab_proc_init(void)
83209 {
83210 #ifdef CONFIG_DEBUG_SLAB_LEAK
83211- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
83212+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
83213 #endif
83214 return 0;
83215 }
83216 module_init(slab_proc_init);
83217 #endif
83218
83219+bool is_usercopy_object(const void *ptr)
83220+{
83221+ struct page *page;
83222+ struct kmem_cache *cachep;
83223+
83224+ if (ZERO_OR_NULL_PTR(ptr))
83225+ return false;
83226+
83227+ if (!slab_is_available())
83228+ return false;
83229+
83230+ if (!virt_addr_valid(ptr))
83231+ return false;
83232+
83233+ page = virt_to_head_page(ptr);
83234+
83235+ if (!PageSlab(page))
83236+ return false;
83237+
83238+ cachep = page->slab_cache;
83239+ return cachep->flags & SLAB_USERCOPY;
83240+}
83241+
83242+#ifdef CONFIG_PAX_USERCOPY
83243+const char *check_heap_object(const void *ptr, unsigned long n)
83244+{
83245+ struct page *page;
83246+ struct kmem_cache *cachep;
83247+ struct slab *slabp;
83248+ unsigned int objnr;
83249+ unsigned long offset;
83250+
83251+ if (ZERO_OR_NULL_PTR(ptr))
83252+ return "<null>";
83253+
83254+ if (!virt_addr_valid(ptr))
83255+ return NULL;
83256+
83257+ page = virt_to_head_page(ptr);
83258+
83259+ if (!PageSlab(page))
83260+ return NULL;
83261+
83262+ cachep = page->slab_cache;
83263+ if (!(cachep->flags & SLAB_USERCOPY))
83264+ return cachep->name;
83265+
83266+ slabp = page->slab_page;
83267+ objnr = obj_to_index(cachep, slabp, ptr);
83268+ BUG_ON(objnr >= cachep->num);
83269+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
83270+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
83271+ return NULL;
83272+
83273+ return cachep->name;
83274+}
83275+#endif
83276+
83277 /**
83278 * ksize - get the actual amount of memory allocated for a given object
83279 * @objp: Pointer to the object
83280diff --git a/mm/slab.h b/mm/slab.h
83281index 34a98d6..73633d1 100644
83282--- a/mm/slab.h
83283+++ b/mm/slab.h
83284@@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
83285
83286 /* Legal flag mask for kmem_cache_create(), for various configurations */
83287 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
83288- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
83289+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
83290
83291 #if defined(CONFIG_DEBUG_SLAB)
83292 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
83293@@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
83294 return s;
83295
83296 page = virt_to_head_page(x);
83297+
83298+ BUG_ON(!PageSlab(page));
83299+
83300 cachep = page->slab_cache;
83301 if (slab_equal_or_root(cachep, s))
83302 return cachep;
83303diff --git a/mm/slab_common.c b/mm/slab_common.c
83304index 3f3cd97..93b0236 100644
83305--- a/mm/slab_common.c
83306+++ b/mm/slab_common.c
83307@@ -22,7 +22,7 @@
83308
83309 #include "slab.h"
83310
83311-enum slab_state slab_state;
83312+enum slab_state slab_state __read_only;
83313 LIST_HEAD(slab_caches);
83314 DEFINE_MUTEX(slab_mutex);
83315 struct kmem_cache *kmem_cache;
83316@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
83317
83318 err = __kmem_cache_create(s, flags);
83319 if (!err) {
83320- s->refcount = 1;
83321+ atomic_set(&s->refcount, 1);
83322 list_add(&s->list, &slab_caches);
83323 memcg_cache_list_add(memcg, s);
83324 } else {
83325@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
83326
83327 get_online_cpus();
83328 mutex_lock(&slab_mutex);
83329- s->refcount--;
83330- if (!s->refcount) {
83331+ if (atomic_dec_and_test(&s->refcount)) {
83332 list_del(&s->list);
83333
83334 if (!__kmem_cache_shutdown(s)) {
83335@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
83336 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
83337 name, size, err);
83338
83339- s->refcount = -1; /* Exempt from merging for now */
83340+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
83341 }
83342
83343 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
83344@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
83345
83346 create_boot_cache(s, name, size, flags);
83347 list_add(&s->list, &slab_caches);
83348- s->refcount = 1;
83349+ atomic_set(&s->refcount, 1);
83350 return s;
83351 }
83352
83353diff --git a/mm/slob.c b/mm/slob.c
83354index a99fdf7..6ee34ec 100644
83355--- a/mm/slob.c
83356+++ b/mm/slob.c
83357@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
83358 /*
83359 * Return the size of a slob block.
83360 */
83361-static slobidx_t slob_units(slob_t *s)
83362+static slobidx_t slob_units(const slob_t *s)
83363 {
83364 if (s->units > 0)
83365 return s->units;
83366@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
83367 /*
83368 * Return the next free slob block pointer after this one.
83369 */
83370-static slob_t *slob_next(slob_t *s)
83371+static slob_t *slob_next(const slob_t *s)
83372 {
83373 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
83374 slobidx_t next;
83375@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
83376 /*
83377 * Returns true if s is the last free block in its page.
83378 */
83379-static int slob_last(slob_t *s)
83380+static int slob_last(const slob_t *s)
83381 {
83382 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
83383 }
83384
83385-static void *slob_new_pages(gfp_t gfp, int order, int node)
83386+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
83387 {
83388- void *page;
83389+ struct page *page;
83390
83391 #ifdef CONFIG_NUMA
83392 if (node != NUMA_NO_NODE)
83393@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
83394 if (!page)
83395 return NULL;
83396
83397- return page_address(page);
83398+ __SetPageSlab(page);
83399+ return page;
83400 }
83401
83402-static void slob_free_pages(void *b, int order)
83403+static void slob_free_pages(struct page *sp, int order)
83404 {
83405 if (current->reclaim_state)
83406 current->reclaim_state->reclaimed_slab += 1 << order;
83407- free_pages((unsigned long)b, order);
83408+ __ClearPageSlab(sp);
83409+ reset_page_mapcount(sp);
83410+ sp->private = 0;
83411+ __free_pages(sp, order);
83412 }
83413
83414 /*
83415@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
83416
83417 /* Not enough space: must allocate a new page */
83418 if (!b) {
83419- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
83420- if (!b)
83421+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
83422+ if (!sp)
83423 return NULL;
83424- sp = virt_to_page(b);
83425- __SetPageSlab(sp);
83426+ b = page_address(sp);
83427
83428 spin_lock_irqsave(&slob_lock, flags);
83429 sp->units = SLOB_UNITS(PAGE_SIZE);
83430 sp->freelist = b;
83431+ sp->private = 0;
83432 INIT_LIST_HEAD(&sp->list);
83433 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
83434 set_slob_page_free(sp, slob_list);
83435@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
83436 if (slob_page_free(sp))
83437 clear_slob_page_free(sp);
83438 spin_unlock_irqrestore(&slob_lock, flags);
83439- __ClearPageSlab(sp);
83440- reset_page_mapcount(sp);
83441- slob_free_pages(b, 0);
83442+ slob_free_pages(sp, 0);
83443 return;
83444 }
83445
83446@@ -424,11 +426,10 @@ out:
83447 */
83448
83449 static __always_inline void *
83450-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
83451+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
83452 {
83453- unsigned int *m;
83454- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83455- void *ret;
83456+ slob_t *m;
83457+ void *ret = NULL;
83458
83459 gfp &= gfp_allowed_mask;
83460
83461@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
83462
83463 if (!m)
83464 return NULL;
83465- *m = size;
83466+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
83467+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
83468+ m[0].units = size;
83469+ m[1].units = align;
83470 ret = (void *)m + align;
83471
83472 trace_kmalloc_node(caller, ret,
83473 size, size + align, gfp, node);
83474 } else {
83475 unsigned int order = get_order(size);
83476+ struct page *page;
83477
83478 if (likely(order))
83479 gfp |= __GFP_COMP;
83480- ret = slob_new_pages(gfp, order, node);
83481+ page = slob_new_pages(gfp, order, node);
83482+ if (page) {
83483+ ret = page_address(page);
83484+ page->private = size;
83485+ }
83486
83487 trace_kmalloc_node(caller, ret,
83488 size, PAGE_SIZE << order, gfp, node);
83489 }
83490
83491- kmemleak_alloc(ret, size, 1, gfp);
83492+ return ret;
83493+}
83494+
83495+static __always_inline void *
83496+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
83497+{
83498+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83499+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
83500+
83501+ if (!ZERO_OR_NULL_PTR(ret))
83502+ kmemleak_alloc(ret, size, 1, gfp);
83503 return ret;
83504 }
83505
83506@@ -493,34 +512,112 @@ void kfree(const void *block)
83507 return;
83508 kmemleak_free(block);
83509
83510+ VM_BUG_ON(!virt_addr_valid(block));
83511 sp = virt_to_page(block);
83512- if (PageSlab(sp)) {
83513+ VM_BUG_ON(!PageSlab(sp));
83514+ if (!sp->private) {
83515 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83516- unsigned int *m = (unsigned int *)(block - align);
83517- slob_free(m, *m + align);
83518- } else
83519+ slob_t *m = (slob_t *)(block - align);
83520+ slob_free(m, m[0].units + align);
83521+ } else {
83522+ __ClearPageSlab(sp);
83523+ reset_page_mapcount(sp);
83524+ sp->private = 0;
83525 __free_pages(sp, compound_order(sp));
83526+ }
83527 }
83528 EXPORT_SYMBOL(kfree);
83529
83530+bool is_usercopy_object(const void *ptr)
83531+{
83532+ if (!slab_is_available())
83533+ return false;
83534+
83535+ // PAX: TODO
83536+
83537+ return false;
83538+}
83539+
83540+#ifdef CONFIG_PAX_USERCOPY
83541+const char *check_heap_object(const void *ptr, unsigned long n)
83542+{
83543+ struct page *page;
83544+ const slob_t *free;
83545+ const void *base;
83546+ unsigned long flags;
83547+
83548+ if (ZERO_OR_NULL_PTR(ptr))
83549+ return "<null>";
83550+
83551+ if (!virt_addr_valid(ptr))
83552+ return NULL;
83553+
83554+ page = virt_to_head_page(ptr);
83555+ if (!PageSlab(page))
83556+ return NULL;
83557+
83558+ if (page->private) {
83559+ base = page;
83560+ if (base <= ptr && n <= page->private - (ptr - base))
83561+ return NULL;
83562+ return "<slob>";
83563+ }
83564+
83565+ /* some tricky double walking to find the chunk */
83566+ spin_lock_irqsave(&slob_lock, flags);
83567+ base = (void *)((unsigned long)ptr & PAGE_MASK);
83568+ free = page->freelist;
83569+
83570+ while (!slob_last(free) && (void *)free <= ptr) {
83571+ base = free + slob_units(free);
83572+ free = slob_next(free);
83573+ }
83574+
83575+ while (base < (void *)free) {
83576+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
83577+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
83578+ int offset;
83579+
83580+ if (ptr < base + align)
83581+ break;
83582+
83583+ offset = ptr - base - align;
83584+ if (offset >= m) {
83585+ base += size;
83586+ continue;
83587+ }
83588+
83589+ if (n > m - offset)
83590+ break;
83591+
83592+ spin_unlock_irqrestore(&slob_lock, flags);
83593+ return NULL;
83594+ }
83595+
83596+ spin_unlock_irqrestore(&slob_lock, flags);
83597+ return "<slob>";
83598+}
83599+#endif
83600+
83601 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
83602 size_t ksize(const void *block)
83603 {
83604 struct page *sp;
83605 int align;
83606- unsigned int *m;
83607+ slob_t *m;
83608
83609 BUG_ON(!block);
83610 if (unlikely(block == ZERO_SIZE_PTR))
83611 return 0;
83612
83613 sp = virt_to_page(block);
83614- if (unlikely(!PageSlab(sp)))
83615- return PAGE_SIZE << compound_order(sp);
83616+ VM_BUG_ON(!PageSlab(sp));
83617+ if (sp->private)
83618+ return sp->private;
83619
83620 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83621- m = (unsigned int *)(block - align);
83622- return SLOB_UNITS(*m) * SLOB_UNIT;
83623+ m = (slob_t *)(block - align);
83624+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
83625 }
83626 EXPORT_SYMBOL(ksize);
83627
83628@@ -536,23 +633,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
83629
83630 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
83631 {
83632- void *b;
83633+ void *b = NULL;
83634
83635 flags &= gfp_allowed_mask;
83636
83637 lockdep_trace_alloc(flags);
83638
83639+#ifdef CONFIG_PAX_USERCOPY_SLABS
83640+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
83641+#else
83642 if (c->size < PAGE_SIZE) {
83643 b = slob_alloc(c->size, flags, c->align, node);
83644 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
83645 SLOB_UNITS(c->size) * SLOB_UNIT,
83646 flags, node);
83647 } else {
83648- b = slob_new_pages(flags, get_order(c->size), node);
83649+ struct page *sp;
83650+
83651+ sp = slob_new_pages(flags, get_order(c->size), node);
83652+ if (sp) {
83653+ b = page_address(sp);
83654+ sp->private = c->size;
83655+ }
83656 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
83657 PAGE_SIZE << get_order(c->size),
83658 flags, node);
83659 }
83660+#endif
83661
83662 if (c->ctor)
83663 c->ctor(b);
83664@@ -564,10 +671,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
83665
83666 static void __kmem_cache_free(void *b, int size)
83667 {
83668- if (size < PAGE_SIZE)
83669+ struct page *sp;
83670+
83671+ sp = virt_to_page(b);
83672+ BUG_ON(!PageSlab(sp));
83673+ if (!sp->private)
83674 slob_free(b, size);
83675 else
83676- slob_free_pages(b, get_order(size));
83677+ slob_free_pages(sp, get_order(size));
83678 }
83679
83680 static void kmem_rcu_free(struct rcu_head *head)
83681@@ -580,17 +691,31 @@ static void kmem_rcu_free(struct rcu_head *head)
83682
83683 void kmem_cache_free(struct kmem_cache *c, void *b)
83684 {
83685+ int size = c->size;
83686+
83687+#ifdef CONFIG_PAX_USERCOPY_SLABS
83688+ if (size + c->align < PAGE_SIZE) {
83689+ size += c->align;
83690+ b -= c->align;
83691+ }
83692+#endif
83693+
83694 kmemleak_free_recursive(b, c->flags);
83695 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
83696 struct slob_rcu *slob_rcu;
83697- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
83698- slob_rcu->size = c->size;
83699+ slob_rcu = b + (size - sizeof(struct slob_rcu));
83700+ slob_rcu->size = size;
83701 call_rcu(&slob_rcu->head, kmem_rcu_free);
83702 } else {
83703- __kmem_cache_free(b, c->size);
83704+ __kmem_cache_free(b, size);
83705 }
83706
83707+#ifdef CONFIG_PAX_USERCOPY_SLABS
83708+ trace_kfree(_RET_IP_, b);
83709+#else
83710 trace_kmem_cache_free(_RET_IP_, b);
83711+#endif
83712+
83713 }
83714 EXPORT_SYMBOL(kmem_cache_free);
83715
83716diff --git a/mm/slub.c b/mm/slub.c
83717index ba2ca53..991c4f7 100644
83718--- a/mm/slub.c
83719+++ b/mm/slub.c
83720@@ -197,7 +197,7 @@ struct track {
83721
83722 enum track_item { TRACK_ALLOC, TRACK_FREE };
83723
83724-#ifdef CONFIG_SYSFS
83725+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83726 static int sysfs_slab_add(struct kmem_cache *);
83727 static int sysfs_slab_alias(struct kmem_cache *, const char *);
83728 static void sysfs_slab_remove(struct kmem_cache *);
83729@@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
83730 if (!t->addr)
83731 return;
83732
83733- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
83734+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
83735 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
83736 #ifdef CONFIG_STACKTRACE
83737 {
83738@@ -2653,7 +2653,7 @@ static int slub_min_objects;
83739 * Merge control. If this is set then no merging of slab caches will occur.
83740 * (Could be removed. This was introduced to pacify the merge skeptics.)
83741 */
83742-static int slub_nomerge;
83743+static int slub_nomerge = 1;
83744
83745 /*
83746 * Calculate the order of allocation given an slab object size.
83747@@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
83748 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
83749 #endif
83750
83751+#ifdef CONFIG_PAX_USERCOPY_SLABS
83752+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
83753+#endif
83754+
83755 static int __init setup_slub_min_order(char *str)
83756 {
83757 get_option(&str, &slub_min_order);
83758@@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
83759 return kmalloc_dma_caches[index];
83760
83761 #endif
83762+
83763+#ifdef CONFIG_PAX_USERCOPY_SLABS
83764+ if (flags & SLAB_USERCOPY)
83765+ return kmalloc_usercopy_caches[index];
83766+
83767+#endif
83768+
83769 return kmalloc_caches[index];
83770 }
83771
83772@@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
83773 EXPORT_SYMBOL(__kmalloc_node);
83774 #endif
83775
83776+bool is_usercopy_object(const void *ptr)
83777+{
83778+ struct page *page;
83779+ struct kmem_cache *s;
83780+
83781+ if (ZERO_OR_NULL_PTR(ptr))
83782+ return false;
83783+
83784+ if (!slab_is_available())
83785+ return false;
83786+
83787+ if (!virt_addr_valid(ptr))
83788+ return false;
83789+
83790+ page = virt_to_head_page(ptr);
83791+
83792+ if (!PageSlab(page))
83793+ return false;
83794+
83795+ s = page->slab_cache;
83796+ return s->flags & SLAB_USERCOPY;
83797+}
83798+
83799+#ifdef CONFIG_PAX_USERCOPY
83800+const char *check_heap_object(const void *ptr, unsigned long n)
83801+{
83802+ struct page *page;
83803+ struct kmem_cache *s;
83804+ unsigned long offset;
83805+
83806+ if (ZERO_OR_NULL_PTR(ptr))
83807+ return "<null>";
83808+
83809+ if (!virt_addr_valid(ptr))
83810+ return NULL;
83811+
83812+ page = virt_to_head_page(ptr);
83813+
83814+ if (!PageSlab(page))
83815+ return NULL;
83816+
83817+ s = page->slab_cache;
83818+ if (!(s->flags & SLAB_USERCOPY))
83819+ return s->name;
83820+
83821+ offset = (ptr - page_address(page)) % s->size;
83822+ if (offset <= s->object_size && n <= s->object_size - offset)
83823+ return NULL;
83824+
83825+ return s->name;
83826+}
83827+#endif
83828+
83829 size_t ksize(const void *object)
83830 {
83831 struct page *page;
83832@@ -3404,6 +3468,7 @@ void kfree(const void *x)
83833 if (unlikely(ZERO_OR_NULL_PTR(x)))
83834 return;
83835
83836+ VM_BUG_ON(!virt_addr_valid(x));
83837 page = virt_to_head_page(x);
83838 if (unlikely(!PageSlab(page))) {
83839 BUG_ON(!PageCompound(page));
83840@@ -3712,17 +3777,17 @@ void __init kmem_cache_init(void)
83841
83842 /* Caches that are not of the two-to-the-power-of size */
83843 if (KMALLOC_MIN_SIZE <= 32) {
83844- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
83845+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
83846 caches++;
83847 }
83848
83849 if (KMALLOC_MIN_SIZE <= 64) {
83850- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
83851+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
83852 caches++;
83853 }
83854
83855 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
83856- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
83857+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
83858 caches++;
83859 }
83860
83861@@ -3764,6 +3829,22 @@ void __init kmem_cache_init(void)
83862 }
83863 }
83864 #endif
83865+
83866+#ifdef CONFIG_PAX_USERCOPY_SLABS
83867+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
83868+ struct kmem_cache *s = kmalloc_caches[i];
83869+
83870+ if (s && s->size) {
83871+ char *name = kasprintf(GFP_NOWAIT,
83872+ "usercopy-kmalloc-%d", s->object_size);
83873+
83874+ BUG_ON(!name);
83875+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
83876+ s->object_size, SLAB_USERCOPY);
83877+ }
83878+ }
83879+#endif
83880+
83881 printk(KERN_INFO
83882 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
83883 " CPUs=%d, Nodes=%d\n",
83884@@ -3790,7 +3871,7 @@ static int slab_unmergeable(struct kmem_cache *s)
83885 /*
83886 * We may have set a slab to be unmergeable during bootstrap.
83887 */
83888- if (s->refcount < 0)
83889+ if (atomic_read(&s->refcount) < 0)
83890 return 1;
83891
83892 return 0;
83893@@ -3848,7 +3929,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
83894
83895 s = find_mergeable(memcg, size, align, flags, name, ctor);
83896 if (s) {
83897- s->refcount++;
83898+ atomic_inc(&s->refcount);
83899 /*
83900 * Adjust the object sizes so that we clear
83901 * the complete object on kzalloc.
83902@@ -3857,7 +3938,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
83903 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
83904
83905 if (sysfs_slab_alias(s, name)) {
83906- s->refcount--;
83907+ atomic_dec(&s->refcount);
83908 s = NULL;
83909 }
83910 }
83911@@ -3919,7 +4000,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
83912 return NOTIFY_OK;
83913 }
83914
83915-static struct notifier_block __cpuinitdata slab_notifier = {
83916+static struct notifier_block slab_notifier = {
83917 .notifier_call = slab_cpuup_callback
83918 };
83919
83920@@ -3977,7 +4058,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
83921 }
83922 #endif
83923
83924-#ifdef CONFIG_SYSFS
83925+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83926 static int count_inuse(struct page *page)
83927 {
83928 return page->inuse;
83929@@ -4364,12 +4445,12 @@ static void resiliency_test(void)
83930 validate_slab_cache(kmalloc_caches[9]);
83931 }
83932 #else
83933-#ifdef CONFIG_SYSFS
83934+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83935 static void resiliency_test(void) {};
83936 #endif
83937 #endif
83938
83939-#ifdef CONFIG_SYSFS
83940+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83941 enum slab_stat_type {
83942 SL_ALL, /* All slabs */
83943 SL_PARTIAL, /* Only partially allocated slabs */
83944@@ -4613,7 +4694,7 @@ SLAB_ATTR_RO(ctor);
83945
83946 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
83947 {
83948- return sprintf(buf, "%d\n", s->refcount - 1);
83949+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
83950 }
83951 SLAB_ATTR_RO(aliases);
83952
83953@@ -5266,6 +5347,7 @@ static char *create_unique_id(struct kmem_cache *s)
83954 return name;
83955 }
83956
83957+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83958 static int sysfs_slab_add(struct kmem_cache *s)
83959 {
83960 int err;
83961@@ -5323,6 +5405,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
83962 kobject_del(&s->kobj);
83963 kobject_put(&s->kobj);
83964 }
83965+#endif
83966
83967 /*
83968 * Need to buffer aliases during bootup until sysfs becomes
83969@@ -5336,6 +5419,7 @@ struct saved_alias {
83970
83971 static struct saved_alias *alias_list;
83972
83973+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83974 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
83975 {
83976 struct saved_alias *al;
83977@@ -5358,6 +5442,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
83978 alias_list = al;
83979 return 0;
83980 }
83981+#endif
83982
83983 static int __init slab_sysfs_init(void)
83984 {
83985diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
83986index 1b7e22a..3fcd4f3 100644
83987--- a/mm/sparse-vmemmap.c
83988+++ b/mm/sparse-vmemmap.c
83989@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
83990 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
83991 if (!p)
83992 return NULL;
83993- pud_populate(&init_mm, pud, p);
83994+ pud_populate_kernel(&init_mm, pud, p);
83995 }
83996 return pud;
83997 }
83998@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
83999 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
84000 if (!p)
84001 return NULL;
84002- pgd_populate(&init_mm, pgd, p);
84003+ pgd_populate_kernel(&init_mm, pgd, p);
84004 }
84005 return pgd;
84006 }
84007diff --git a/mm/sparse.c b/mm/sparse.c
84008index 6b5fb76..db0c190 100644
84009--- a/mm/sparse.c
84010+++ b/mm/sparse.c
84011@@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
84012
84013 for (i = 0; i < PAGES_PER_SECTION; i++) {
84014 if (PageHWPoison(&memmap[i])) {
84015- atomic_long_sub(1, &mce_bad_pages);
84016+ atomic_long_sub_unchecked(1, &mce_bad_pages);
84017 ClearPageHWPoison(&memmap[i]);
84018 }
84019 }
84020diff --git a/mm/swap.c b/mm/swap.c
84021index 6310dc2..3662b3f 100644
84022--- a/mm/swap.c
84023+++ b/mm/swap.c
84024@@ -30,6 +30,7 @@
84025 #include <linux/backing-dev.h>
84026 #include <linux/memcontrol.h>
84027 #include <linux/gfp.h>
84028+#include <linux/hugetlb.h>
84029
84030 #include "internal.h"
84031
84032@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
84033
84034 __page_cache_release(page);
84035 dtor = get_compound_page_dtor(page);
84036+ if (!PageHuge(page))
84037+ BUG_ON(dtor != free_compound_page);
84038 (*dtor)(page);
84039 }
84040
84041diff --git a/mm/swapfile.c b/mm/swapfile.c
84042index e97a0e5..b50e796 100644
84043--- a/mm/swapfile.c
84044+++ b/mm/swapfile.c
84045@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
84046
84047 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
84048 /* Activity counter to indicate that a swapon or swapoff has occurred */
84049-static atomic_t proc_poll_event = ATOMIC_INIT(0);
84050+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
84051
84052 static inline unsigned char swap_count(unsigned char ent)
84053 {
84054@@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
84055 }
84056 filp_close(swap_file, NULL);
84057 err = 0;
84058- atomic_inc(&proc_poll_event);
84059+ atomic_inc_unchecked(&proc_poll_event);
84060 wake_up_interruptible(&proc_poll_wait);
84061
84062 out_dput:
84063@@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
84064
84065 poll_wait(file, &proc_poll_wait, wait);
84066
84067- if (seq->poll_event != atomic_read(&proc_poll_event)) {
84068- seq->poll_event = atomic_read(&proc_poll_event);
84069+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
84070+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
84071 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
84072 }
84073
84074@@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
84075 return ret;
84076
84077 seq = file->private_data;
84078- seq->poll_event = atomic_read(&proc_poll_event);
84079+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
84080 return 0;
84081 }
84082
84083@@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
84084 (frontswap_map) ? "FS" : "");
84085
84086 mutex_unlock(&swapon_mutex);
84087- atomic_inc(&proc_poll_event);
84088+ atomic_inc_unchecked(&proc_poll_event);
84089 wake_up_interruptible(&proc_poll_wait);
84090
84091 if (S_ISREG(inode->i_mode))
84092diff --git a/mm/util.c b/mm/util.c
84093index c55e26b..3f913a9 100644
84094--- a/mm/util.c
84095+++ b/mm/util.c
84096@@ -292,6 +292,12 @@ done:
84097 void arch_pick_mmap_layout(struct mm_struct *mm)
84098 {
84099 mm->mmap_base = TASK_UNMAPPED_BASE;
84100+
84101+#ifdef CONFIG_PAX_RANDMMAP
84102+ if (mm->pax_flags & MF_PAX_RANDMMAP)
84103+ mm->mmap_base += mm->delta_mmap;
84104+#endif
84105+
84106 mm->get_unmapped_area = arch_get_unmapped_area;
84107 mm->unmap_area = arch_unmap_area;
84108 }
84109diff --git a/mm/vmalloc.c b/mm/vmalloc.c
84110index 5123a16..f234a48 100644
84111--- a/mm/vmalloc.c
84112+++ b/mm/vmalloc.c
84113@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
84114
84115 pte = pte_offset_kernel(pmd, addr);
84116 do {
84117- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
84118- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
84119+
84120+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84121+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
84122+ BUG_ON(!pte_exec(*pte));
84123+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
84124+ continue;
84125+ }
84126+#endif
84127+
84128+ {
84129+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
84130+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
84131+ }
84132 } while (pte++, addr += PAGE_SIZE, addr != end);
84133 }
84134
84135@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
84136 pte = pte_alloc_kernel(pmd, addr);
84137 if (!pte)
84138 return -ENOMEM;
84139+
84140+ pax_open_kernel();
84141 do {
84142 struct page *page = pages[*nr];
84143
84144- if (WARN_ON(!pte_none(*pte)))
84145+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84146+ if (pgprot_val(prot) & _PAGE_NX)
84147+#endif
84148+
84149+ if (!pte_none(*pte)) {
84150+ pax_close_kernel();
84151+ WARN_ON(1);
84152 return -EBUSY;
84153- if (WARN_ON(!page))
84154+ }
84155+ if (!page) {
84156+ pax_close_kernel();
84157+ WARN_ON(1);
84158 return -ENOMEM;
84159+ }
84160 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
84161 (*nr)++;
84162 } while (pte++, addr += PAGE_SIZE, addr != end);
84163+ pax_close_kernel();
84164 return 0;
84165 }
84166
84167@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
84168 pmd_t *pmd;
84169 unsigned long next;
84170
84171- pmd = pmd_alloc(&init_mm, pud, addr);
84172+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
84173 if (!pmd)
84174 return -ENOMEM;
84175 do {
84176@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
84177 pud_t *pud;
84178 unsigned long next;
84179
84180- pud = pud_alloc(&init_mm, pgd, addr);
84181+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
84182 if (!pud)
84183 return -ENOMEM;
84184 do {
84185@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
84186 * and fall back on vmalloc() if that fails. Others
84187 * just put it in the vmalloc space.
84188 */
84189-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
84190+#ifdef CONFIG_MODULES
84191+#ifdef MODULES_VADDR
84192 unsigned long addr = (unsigned long)x;
84193 if (addr >= MODULES_VADDR && addr < MODULES_END)
84194 return 1;
84195 #endif
84196+
84197+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84198+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
84199+ return 1;
84200+#endif
84201+
84202+#endif
84203+
84204 return is_vmalloc_addr(x);
84205 }
84206
84207@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
84208
84209 if (!pgd_none(*pgd)) {
84210 pud_t *pud = pud_offset(pgd, addr);
84211+#ifdef CONFIG_X86
84212+ if (!pud_large(*pud))
84213+#endif
84214 if (!pud_none(*pud)) {
84215 pmd_t *pmd = pmd_offset(pud, addr);
84216+#ifdef CONFIG_X86
84217+ if (!pmd_large(*pmd))
84218+#endif
84219 if (!pmd_none(*pmd)) {
84220 pte_t *ptep, pte;
84221
84222@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
84223 * Allocate a region of KVA of the specified size and alignment, within the
84224 * vstart and vend.
84225 */
84226-static struct vmap_area *alloc_vmap_area(unsigned long size,
84227+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
84228 unsigned long align,
84229 unsigned long vstart, unsigned long vend,
84230 int node, gfp_t gfp_mask)
84231@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
84232 struct vm_struct *area;
84233
84234 BUG_ON(in_interrupt());
84235+
84236+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
84237+ if (flags & VM_KERNEXEC) {
84238+ if (start != VMALLOC_START || end != VMALLOC_END)
84239+ return NULL;
84240+ start = (unsigned long)MODULES_EXEC_VADDR;
84241+ end = (unsigned long)MODULES_EXEC_END;
84242+ }
84243+#endif
84244+
84245 if (flags & VM_IOREMAP) {
84246 int bit = fls(size);
84247
84248@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
84249 if (count > totalram_pages)
84250 return NULL;
84251
84252+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
84253+ if (!(pgprot_val(prot) & _PAGE_NX))
84254+ flags |= VM_KERNEXEC;
84255+#endif
84256+
84257 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
84258 __builtin_return_address(0));
84259 if (!area)
84260@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
84261 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
84262 goto fail;
84263
84264+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
84265+ if (!(pgprot_val(prot) & _PAGE_NX))
84266+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
84267+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
84268+ else
84269+#endif
84270+
84271 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
84272 start, end, node, gfp_mask, caller);
84273 if (!area)
84274@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
84275 * For tight control over page level allocator and protection flags
84276 * use __vmalloc() instead.
84277 */
84278-
84279 void *vmalloc_exec(unsigned long size)
84280 {
84281- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
84282+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
84283 -1, __builtin_return_address(0));
84284 }
84285
84286@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
84287 unsigned long uaddr = vma->vm_start;
84288 unsigned long usize = vma->vm_end - vma->vm_start;
84289
84290+ BUG_ON(vma->vm_mirror);
84291+
84292 if ((PAGE_SIZE-1) & (unsigned long)addr)
84293 return -EINVAL;
84294
84295@@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
84296 v->addr, v->addr + v->size, v->size);
84297
84298 if (v->caller)
84299+#ifdef CONFIG_GRKERNSEC_HIDESYM
84300+ seq_printf(m, " %pK", v->caller);
84301+#else
84302 seq_printf(m, " %pS", v->caller);
84303+#endif
84304
84305 if (v->nr_pages)
84306 seq_printf(m, " pages=%d", v->nr_pages);
84307diff --git a/mm/vmstat.c b/mm/vmstat.c
84308index 9800306..76b4b27 100644
84309--- a/mm/vmstat.c
84310+++ b/mm/vmstat.c
84311@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
84312 *
84313 * vm_stat contains the global counters
84314 */
84315-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
84316+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
84317 EXPORT_SYMBOL(vm_stat);
84318
84319 #ifdef CONFIG_SMP
84320@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
84321 v = p->vm_stat_diff[i];
84322 p->vm_stat_diff[i] = 0;
84323 local_irq_restore(flags);
84324- atomic_long_add(v, &zone->vm_stat[i]);
84325+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
84326 global_diff[i] += v;
84327 #ifdef CONFIG_NUMA
84328 /* 3 seconds idle till flush */
84329@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
84330
84331 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
84332 if (global_diff[i])
84333- atomic_long_add(global_diff[i], &vm_stat[i]);
84334+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
84335 }
84336
84337 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
84338@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
84339 if (pset->vm_stat_diff[i]) {
84340 int v = pset->vm_stat_diff[i];
84341 pset->vm_stat_diff[i] = 0;
84342- atomic_long_add(v, &zone->vm_stat[i]);
84343- atomic_long_add(v, &vm_stat[i]);
84344+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
84345+ atomic_long_add_unchecked(v, &vm_stat[i]);
84346 }
84347 }
84348 #endif
84349@@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
84350 return NOTIFY_OK;
84351 }
84352
84353-static struct notifier_block __cpuinitdata vmstat_notifier =
84354+static struct notifier_block vmstat_notifier =
84355 { &vmstat_cpuup_callback, NULL, 0 };
84356 #endif
84357
84358@@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
84359 start_cpu_timer(cpu);
84360 #endif
84361 #ifdef CONFIG_PROC_FS
84362- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
84363- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
84364- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
84365- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
84366+ {
84367+ mode_t gr_mode = S_IRUGO;
84368+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84369+ gr_mode = S_IRUSR;
84370+#endif
84371+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
84372+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
84373+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84374+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
84375+#else
84376+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
84377+#endif
84378+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
84379+ }
84380 #endif
84381 return 0;
84382 }
84383diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
84384index a292e80..785ee68 100644
84385--- a/net/8021q/vlan.c
84386+++ b/net/8021q/vlan.c
84387@@ -485,7 +485,7 @@ out:
84388 return NOTIFY_DONE;
84389 }
84390
84391-static struct notifier_block vlan_notifier_block __read_mostly = {
84392+static struct notifier_block vlan_notifier_block = {
84393 .notifier_call = vlan_device_event,
84394 };
84395
84396@@ -560,8 +560,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
84397 err = -EPERM;
84398 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
84399 break;
84400- if ((args.u.name_type >= 0) &&
84401- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
84402+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
84403 struct vlan_net *vn;
84404
84405 vn = net_generic(net, vlan_net_id);
84406diff --git a/net/9p/mod.c b/net/9p/mod.c
84407index 6ab36ae..6f1841b 100644
84408--- a/net/9p/mod.c
84409+++ b/net/9p/mod.c
84410@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
84411 void v9fs_register_trans(struct p9_trans_module *m)
84412 {
84413 spin_lock(&v9fs_trans_lock);
84414- list_add_tail(&m->list, &v9fs_trans_list);
84415+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
84416 spin_unlock(&v9fs_trans_lock);
84417 }
84418 EXPORT_SYMBOL(v9fs_register_trans);
84419@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
84420 void v9fs_unregister_trans(struct p9_trans_module *m)
84421 {
84422 spin_lock(&v9fs_trans_lock);
84423- list_del_init(&m->list);
84424+ pax_list_del_init((struct list_head *)&m->list);
84425 spin_unlock(&v9fs_trans_lock);
84426 }
84427 EXPORT_SYMBOL(v9fs_unregister_trans);
84428diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
84429index 02efb25..41541a9 100644
84430--- a/net/9p/trans_fd.c
84431+++ b/net/9p/trans_fd.c
84432@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
84433 oldfs = get_fs();
84434 set_fs(get_ds());
84435 /* The cast to a user pointer is valid due to the set_fs() */
84436- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
84437+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
84438 set_fs(oldfs);
84439
84440 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
84441diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
84442index 876fbe8..8bbea9f 100644
84443--- a/net/atm/atm_misc.c
84444+++ b/net/atm/atm_misc.c
84445@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
84446 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
84447 return 1;
84448 atm_return(vcc, truesize);
84449- atomic_inc(&vcc->stats->rx_drop);
84450+ atomic_inc_unchecked(&vcc->stats->rx_drop);
84451 return 0;
84452 }
84453 EXPORT_SYMBOL(atm_charge);
84454@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
84455 }
84456 }
84457 atm_return(vcc, guess);
84458- atomic_inc(&vcc->stats->rx_drop);
84459+ atomic_inc_unchecked(&vcc->stats->rx_drop);
84460 return NULL;
84461 }
84462 EXPORT_SYMBOL(atm_alloc_charge);
84463@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
84464
84465 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
84466 {
84467-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
84468+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
84469 __SONET_ITEMS
84470 #undef __HANDLE_ITEM
84471 }
84472@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
84473
84474 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
84475 {
84476-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
84477+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
84478 __SONET_ITEMS
84479 #undef __HANDLE_ITEM
84480 }
84481diff --git a/net/atm/lec.h b/net/atm/lec.h
84482index a86aff9..3a0d6f6 100644
84483--- a/net/atm/lec.h
84484+++ b/net/atm/lec.h
84485@@ -48,7 +48,7 @@ struct lane2_ops {
84486 const u8 *tlvs, u32 sizeoftlvs);
84487 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
84488 const u8 *tlvs, u32 sizeoftlvs);
84489-};
84490+} __no_const;
84491
84492 /*
84493 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
84494diff --git a/net/atm/proc.c b/net/atm/proc.c
84495index 0d020de..011c7bb 100644
84496--- a/net/atm/proc.c
84497+++ b/net/atm/proc.c
84498@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
84499 const struct k_atm_aal_stats *stats)
84500 {
84501 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
84502- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
84503- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
84504- atomic_read(&stats->rx_drop));
84505+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
84506+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
84507+ atomic_read_unchecked(&stats->rx_drop));
84508 }
84509
84510 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
84511diff --git a/net/atm/resources.c b/net/atm/resources.c
84512index 0447d5d..3cf4728 100644
84513--- a/net/atm/resources.c
84514+++ b/net/atm/resources.c
84515@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
84516 static void copy_aal_stats(struct k_atm_aal_stats *from,
84517 struct atm_aal_stats *to)
84518 {
84519-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
84520+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
84521 __AAL_STAT_ITEMS
84522 #undef __HANDLE_ITEM
84523 }
84524@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
84525 static void subtract_aal_stats(struct k_atm_aal_stats *from,
84526 struct atm_aal_stats *to)
84527 {
84528-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
84529+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
84530 __AAL_STAT_ITEMS
84531 #undef __HANDLE_ITEM
84532 }
84533diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
84534index d5744b7..506bae3 100644
84535--- a/net/ax25/sysctl_net_ax25.c
84536+++ b/net/ax25/sysctl_net_ax25.c
84537@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
84538 {
84539 char path[sizeof("net/ax25/") + IFNAMSIZ];
84540 int k;
84541- struct ctl_table *table;
84542+ ctl_table_no_const *table;
84543
84544 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
84545 if (!table)
84546diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
84547index 1ee94d0..14beea2 100644
84548--- a/net/batman-adv/bat_iv_ogm.c
84549+++ b/net/batman-adv/bat_iv_ogm.c
84550@@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
84551
84552 /* randomize initial seqno to avoid collision */
84553 get_random_bytes(&random_seqno, sizeof(random_seqno));
84554- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
84555+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
84556
84557 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
84558 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
84559@@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
84560 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
84561
84562 /* change sequence number to network order */
84563- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
84564+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
84565 batadv_ogm_packet->seqno = htonl(seqno);
84566- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
84567+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
84568
84569 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
84570 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
84571@@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
84572 return;
84573
84574 /* could be changed by schedule_own_packet() */
84575- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
84576+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
84577
84578 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
84579 has_directlink_flag = 1;
84580diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
84581index f1d37cd..4190879 100644
84582--- a/net/batman-adv/hard-interface.c
84583+++ b/net/batman-adv/hard-interface.c
84584@@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
84585 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
84586 dev_add_pack(&hard_iface->batman_adv_ptype);
84587
84588- atomic_set(&hard_iface->frag_seqno, 1);
84589+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
84590 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
84591 hard_iface->net_dev->name);
84592
84593@@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
84594 /* This can't be called via a bat_priv callback because
84595 * we have no bat_priv yet.
84596 */
84597- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
84598+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
84599 hard_iface->bat_iv.ogm_buff = NULL;
84600
84601 return hard_iface;
84602diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
84603index 6b548fd..fc32c8d 100644
84604--- a/net/batman-adv/soft-interface.c
84605+++ b/net/batman-adv/soft-interface.c
84606@@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
84607 primary_if->net_dev->dev_addr, ETH_ALEN);
84608
84609 /* set broadcast sequence number */
84610- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
84611+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
84612 bcast_packet->seqno = htonl(seqno);
84613
84614 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
84615@@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
84616 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
84617
84618 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
84619- atomic_set(&bat_priv->bcast_seqno, 1);
84620+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
84621 atomic_set(&bat_priv->tt.vn, 0);
84622 atomic_set(&bat_priv->tt.local_changes, 0);
84623 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
84624diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
84625index ae9ac9a..11e0fe7 100644
84626--- a/net/batman-adv/types.h
84627+++ b/net/batman-adv/types.h
84628@@ -48,7 +48,7 @@
84629 struct batadv_hard_iface_bat_iv {
84630 unsigned char *ogm_buff;
84631 int ogm_buff_len;
84632- atomic_t ogm_seqno;
84633+ atomic_unchecked_t ogm_seqno;
84634 };
84635
84636 struct batadv_hard_iface {
84637@@ -56,7 +56,7 @@ struct batadv_hard_iface {
84638 int16_t if_num;
84639 char if_status;
84640 struct net_device *net_dev;
84641- atomic_t frag_seqno;
84642+ atomic_unchecked_t frag_seqno;
84643 struct kobject *hardif_obj;
84644 atomic_t refcount;
84645 struct packet_type batman_adv_ptype;
84646@@ -284,7 +284,7 @@ struct batadv_priv {
84647 atomic_t orig_interval; /* uint */
84648 atomic_t hop_penalty; /* uint */
84649 atomic_t log_level; /* uint */
84650- atomic_t bcast_seqno;
84651+ atomic_unchecked_t bcast_seqno;
84652 atomic_t bcast_queue_left;
84653 atomic_t batman_queue_left;
84654 char num_ifaces;
84655diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
84656index 10aff49..ea8e021 100644
84657--- a/net/batman-adv/unicast.c
84658+++ b/net/batman-adv/unicast.c
84659@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
84660 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
84661 frag2->flags = large_tail;
84662
84663- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
84664+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
84665 frag1->seqno = htons(seqno - 1);
84666 frag2->seqno = htons(seqno);
84667
84668diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
84669index 07f0739..3c42e34 100644
84670--- a/net/bluetooth/hci_sock.c
84671+++ b/net/bluetooth/hci_sock.c
84672@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
84673 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
84674 }
84675
84676- len = min_t(unsigned int, len, sizeof(uf));
84677+ len = min((size_t)len, sizeof(uf));
84678 if (copy_from_user(&uf, optval, len)) {
84679 err = -EFAULT;
84680 break;
84681diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
84682index 22e6583..426e2f3 100644
84683--- a/net/bluetooth/l2cap_core.c
84684+++ b/net/bluetooth/l2cap_core.c
84685@@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
84686 break;
84687
84688 case L2CAP_CONF_RFC:
84689- if (olen == sizeof(rfc))
84690- memcpy(&rfc, (void *)val, olen);
84691+ if (olen != sizeof(rfc))
84692+ break;
84693+
84694+ memcpy(&rfc, (void *)val, olen);
84695
84696 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
84697 rfc.mode != chan->mode)
84698diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
84699index 1bcfb84..dad9f98 100644
84700--- a/net/bluetooth/l2cap_sock.c
84701+++ b/net/bluetooth/l2cap_sock.c
84702@@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
84703 struct sock *sk = sock->sk;
84704 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
84705 struct l2cap_options opts;
84706- int len, err = 0;
84707+ int err = 0;
84708+ size_t len = optlen;
84709 u32 opt;
84710
84711 BT_DBG("sk %p", sk);
84712@@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
84713 opts.max_tx = chan->max_tx;
84714 opts.txwin_size = chan->tx_win;
84715
84716- len = min_t(unsigned int, sizeof(opts), optlen);
84717+ len = min(sizeof(opts), len);
84718 if (copy_from_user((char *) &opts, optval, len)) {
84719 err = -EFAULT;
84720 break;
84721@@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
84722 struct bt_security sec;
84723 struct bt_power pwr;
84724 struct l2cap_conn *conn;
84725- int len, err = 0;
84726+ int err = 0;
84727+ size_t len = optlen;
84728 u32 opt;
84729
84730 BT_DBG("sk %p", sk);
84731@@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
84732
84733 sec.level = BT_SECURITY_LOW;
84734
84735- len = min_t(unsigned int, sizeof(sec), optlen);
84736+ len = min(sizeof(sec), len);
84737 if (copy_from_user((char *) &sec, optval, len)) {
84738 err = -EFAULT;
84739 break;
84740@@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
84741
84742 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
84743
84744- len = min_t(unsigned int, sizeof(pwr), optlen);
84745+ len = min(sizeof(pwr), len);
84746 if (copy_from_user((char *) &pwr, optval, len)) {
84747 err = -EFAULT;
84748 break;
84749diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
84750index ce3f665..2c7d08f 100644
84751--- a/net/bluetooth/rfcomm/sock.c
84752+++ b/net/bluetooth/rfcomm/sock.c
84753@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
84754 struct sock *sk = sock->sk;
84755 struct bt_security sec;
84756 int err = 0;
84757- size_t len;
84758+ size_t len = optlen;
84759 u32 opt;
84760
84761 BT_DBG("sk %p", sk);
84762@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
84763
84764 sec.level = BT_SECURITY_LOW;
84765
84766- len = min_t(unsigned int, sizeof(sec), optlen);
84767+ len = min(sizeof(sec), len);
84768 if (copy_from_user((char *) &sec, optval, len)) {
84769 err = -EFAULT;
84770 break;
84771diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
84772index bd6fd0f..6492cba 100644
84773--- a/net/bluetooth/rfcomm/tty.c
84774+++ b/net/bluetooth/rfcomm/tty.c
84775@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
84776 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
84777
84778 spin_lock_irqsave(&dev->port.lock, flags);
84779- if (dev->port.count > 0) {
84780+ if (atomic_read(&dev->port.count) > 0) {
84781 spin_unlock_irqrestore(&dev->port.lock, flags);
84782 return;
84783 }
84784@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
84785 return -ENODEV;
84786
84787 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
84788- dev->channel, dev->port.count);
84789+ dev->channel, atomic_read(&dev->port.count));
84790
84791 spin_lock_irqsave(&dev->port.lock, flags);
84792- if (++dev->port.count > 1) {
84793+ if (atomic_inc_return(&dev->port.count) > 1) {
84794 spin_unlock_irqrestore(&dev->port.lock, flags);
84795 return 0;
84796 }
84797@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
84798 return;
84799
84800 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
84801- dev->port.count);
84802+ atomic_read(&dev->port.count));
84803
84804 spin_lock_irqsave(&dev->port.lock, flags);
84805- if (!--dev->port.count) {
84806+ if (!atomic_dec_return(&dev->port.count)) {
84807 spin_unlock_irqrestore(&dev->port.lock, flags);
84808 if (dev->tty_dev->parent)
84809 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
84810diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
84811index 5fe2ff3..121d696 100644
84812--- a/net/bridge/netfilter/ebtables.c
84813+++ b/net/bridge/netfilter/ebtables.c
84814@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
84815 tmp.valid_hooks = t->table->valid_hooks;
84816 }
84817 mutex_unlock(&ebt_mutex);
84818- if (copy_to_user(user, &tmp, *len) != 0){
84819+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
84820 BUGPRINT("c2u Didn't work\n");
84821 ret = -EFAULT;
84822 break;
84823@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
84824 goto out;
84825 tmp.valid_hooks = t->valid_hooks;
84826
84827- if (copy_to_user(user, &tmp, *len) != 0) {
84828+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
84829 ret = -EFAULT;
84830 break;
84831 }
84832@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
84833 tmp.entries_size = t->table->entries_size;
84834 tmp.valid_hooks = t->table->valid_hooks;
84835
84836- if (copy_to_user(user, &tmp, *len) != 0) {
84837+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
84838 ret = -EFAULT;
84839 break;
84840 }
84841diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
84842index a376ec1..1fbd6be 100644
84843--- a/net/caif/cfctrl.c
84844+++ b/net/caif/cfctrl.c
84845@@ -10,6 +10,7 @@
84846 #include <linux/spinlock.h>
84847 #include <linux/slab.h>
84848 #include <linux/pkt_sched.h>
84849+#include <linux/sched.h>
84850 #include <net/caif/caif_layer.h>
84851 #include <net/caif/cfpkt.h>
84852 #include <net/caif/cfctrl.h>
84853@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
84854 memset(&dev_info, 0, sizeof(dev_info));
84855 dev_info.id = 0xff;
84856 cfsrvl_init(&this->serv, 0, &dev_info, false);
84857- atomic_set(&this->req_seq_no, 1);
84858- atomic_set(&this->rsp_seq_no, 1);
84859+ atomic_set_unchecked(&this->req_seq_no, 1);
84860+ atomic_set_unchecked(&this->rsp_seq_no, 1);
84861 this->serv.layer.receive = cfctrl_recv;
84862 sprintf(this->serv.layer.name, "ctrl");
84863 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
84864@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
84865 struct cfctrl_request_info *req)
84866 {
84867 spin_lock_bh(&ctrl->info_list_lock);
84868- atomic_inc(&ctrl->req_seq_no);
84869- req->sequence_no = atomic_read(&ctrl->req_seq_no);
84870+ atomic_inc_unchecked(&ctrl->req_seq_no);
84871+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
84872 list_add_tail(&req->list, &ctrl->list);
84873 spin_unlock_bh(&ctrl->info_list_lock);
84874 }
84875@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
84876 if (p != first)
84877 pr_warn("Requests are not received in order\n");
84878
84879- atomic_set(&ctrl->rsp_seq_no,
84880+ atomic_set_unchecked(&ctrl->rsp_seq_no,
84881 p->sequence_no);
84882 list_del(&p->list);
84883 goto out;
84884diff --git a/net/can/af_can.c b/net/can/af_can.c
84885index ddac1ee..3ee0a78 100644
84886--- a/net/can/af_can.c
84887+++ b/net/can/af_can.c
84888@@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
84889 };
84890
84891 /* notifier block for netdevice event */
84892-static struct notifier_block can_netdev_notifier __read_mostly = {
84893+static struct notifier_block can_netdev_notifier = {
84894 .notifier_call = can_notifier,
84895 };
84896
84897diff --git a/net/can/gw.c b/net/can/gw.c
84898index 574dda78e..3d2b3da 100644
84899--- a/net/can/gw.c
84900+++ b/net/can/gw.c
84901@@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
84902 MODULE_ALIAS("can-gw");
84903
84904 static HLIST_HEAD(cgw_list);
84905-static struct notifier_block notifier;
84906
84907 static struct kmem_cache *cgw_cache __read_mostly;
84908
84909@@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
84910 return err;
84911 }
84912
84913+static struct notifier_block notifier = {
84914+ .notifier_call = cgw_notifier
84915+};
84916+
84917 static __init int cgw_module_init(void)
84918 {
84919 printk(banner);
84920@@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
84921 return -ENOMEM;
84922
84923 /* set notifier */
84924- notifier.notifier_call = cgw_notifier;
84925 register_netdevice_notifier(&notifier);
84926
84927 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
84928diff --git a/net/compat.c b/net/compat.c
84929index 79ae884..17c5c09 100644
84930--- a/net/compat.c
84931+++ b/net/compat.c
84932@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
84933 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
84934 __get_user(kmsg->msg_flags, &umsg->msg_flags))
84935 return -EFAULT;
84936- kmsg->msg_name = compat_ptr(tmp1);
84937- kmsg->msg_iov = compat_ptr(tmp2);
84938- kmsg->msg_control = compat_ptr(tmp3);
84939+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
84940+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
84941+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
84942 return 0;
84943 }
84944
84945@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84946
84947 if (kern_msg->msg_namelen) {
84948 if (mode == VERIFY_READ) {
84949- int err = move_addr_to_kernel(kern_msg->msg_name,
84950+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
84951 kern_msg->msg_namelen,
84952 kern_address);
84953 if (err < 0)
84954@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84955 kern_msg->msg_name = NULL;
84956
84957 tot_len = iov_from_user_compat_to_kern(kern_iov,
84958- (struct compat_iovec __user *)kern_msg->msg_iov,
84959+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
84960 kern_msg->msg_iovlen);
84961 if (tot_len >= 0)
84962 kern_msg->msg_iov = kern_iov;
84963@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84964
84965 #define CMSG_COMPAT_FIRSTHDR(msg) \
84966 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
84967- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
84968+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
84969 (struct compat_cmsghdr __user *)NULL)
84970
84971 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
84972 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
84973 (ucmlen) <= (unsigned long) \
84974 ((mhdr)->msg_controllen - \
84975- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
84976+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
84977
84978 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
84979 struct compat_cmsghdr __user *cmsg, int cmsg_len)
84980 {
84981 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
84982- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
84983+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
84984 msg->msg_controllen)
84985 return NULL;
84986 return (struct compat_cmsghdr __user *)ptr;
84987@@ -219,7 +219,7 @@ Efault:
84988
84989 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
84990 {
84991- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
84992+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
84993 struct compat_cmsghdr cmhdr;
84994 struct compat_timeval ctv;
84995 struct compat_timespec cts[3];
84996@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
84997
84998 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
84999 {
85000- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
85001+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
85002 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
85003 int fdnum = scm->fp->count;
85004 struct file **fp = scm->fp->fp;
85005@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
85006 return -EFAULT;
85007 old_fs = get_fs();
85008 set_fs(KERNEL_DS);
85009- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
85010+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
85011 set_fs(old_fs);
85012
85013 return err;
85014@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
85015 len = sizeof(ktime);
85016 old_fs = get_fs();
85017 set_fs(KERNEL_DS);
85018- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
85019+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
85020 set_fs(old_fs);
85021
85022 if (!err) {
85023@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
85024 case MCAST_JOIN_GROUP:
85025 case MCAST_LEAVE_GROUP:
85026 {
85027- struct compat_group_req __user *gr32 = (void *)optval;
85028+ struct compat_group_req __user *gr32 = (void __user *)optval;
85029 struct group_req __user *kgr =
85030 compat_alloc_user_space(sizeof(struct group_req));
85031 u32 interface;
85032@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
85033 case MCAST_BLOCK_SOURCE:
85034 case MCAST_UNBLOCK_SOURCE:
85035 {
85036- struct compat_group_source_req __user *gsr32 = (void *)optval;
85037+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
85038 struct group_source_req __user *kgsr = compat_alloc_user_space(
85039 sizeof(struct group_source_req));
85040 u32 interface;
85041@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
85042 }
85043 case MCAST_MSFILTER:
85044 {
85045- struct compat_group_filter __user *gf32 = (void *)optval;
85046+ struct compat_group_filter __user *gf32 = (void __user *)optval;
85047 struct group_filter __user *kgf;
85048 u32 interface, fmode, numsrc;
85049
85050@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
85051 char __user *optval, int __user *optlen,
85052 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
85053 {
85054- struct compat_group_filter __user *gf32 = (void *)optval;
85055+ struct compat_group_filter __user *gf32 = (void __user *)optval;
85056 struct group_filter __user *kgf;
85057 int __user *koptlen;
85058 u32 interface, fmode, numsrc;
85059@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
85060
85061 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
85062 return -EINVAL;
85063- if (copy_from_user(a, args, nas[call]))
85064+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
85065 return -EFAULT;
85066 a0 = a[0];
85067 a1 = a[1];
85068diff --git a/net/core/datagram.c b/net/core/datagram.c
85069index 368f9c3..f82d4a3 100644
85070--- a/net/core/datagram.c
85071+++ b/net/core/datagram.c
85072@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
85073 }
85074
85075 kfree_skb(skb);
85076- atomic_inc(&sk->sk_drops);
85077+ atomic_inc_unchecked(&sk->sk_drops);
85078 sk_mem_reclaim_partial(sk);
85079
85080 return err;
85081diff --git a/net/core/dev.c b/net/core/dev.c
85082index 1339f77..6fd27dc 100644
85083--- a/net/core/dev.c
85084+++ b/net/core/dev.c
85085@@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
85086 if (no_module && capable(CAP_NET_ADMIN))
85087 no_module = request_module("netdev-%s", name);
85088 if (no_module && capable(CAP_SYS_MODULE)) {
85089+#ifdef CONFIG_GRKERNSEC_MODHARDEN
85090+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
85091+#else
85092 if (!request_module("%s", name))
85093 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
85094 name);
85095+#endif
85096 }
85097 }
85098 EXPORT_SYMBOL(dev_load);
85099@@ -1715,7 +1719,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
85100 {
85101 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
85102 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
85103- atomic_long_inc(&dev->rx_dropped);
85104+ atomic_long_inc_unchecked(&dev->rx_dropped);
85105 kfree_skb(skb);
85106 return NET_RX_DROP;
85107 }
85108@@ -1725,7 +1729,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
85109 nf_reset(skb);
85110
85111 if (unlikely(!is_skb_forwardable(dev, skb))) {
85112- atomic_long_inc(&dev->rx_dropped);
85113+ atomic_long_inc_unchecked(&dev->rx_dropped);
85114 kfree_skb(skb);
85115 return NET_RX_DROP;
85116 }
85117@@ -2180,7 +2184,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
85118
85119 struct dev_gso_cb {
85120 void (*destructor)(struct sk_buff *skb);
85121-};
85122+} __no_const;
85123
85124 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
85125
85126@@ -3053,7 +3057,7 @@ enqueue:
85127
85128 local_irq_restore(flags);
85129
85130- atomic_long_inc(&skb->dev->rx_dropped);
85131+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
85132 kfree_skb(skb);
85133 return NET_RX_DROP;
85134 }
85135@@ -3125,7 +3129,7 @@ int netif_rx_ni(struct sk_buff *skb)
85136 }
85137 EXPORT_SYMBOL(netif_rx_ni);
85138
85139-static void net_tx_action(struct softirq_action *h)
85140+static void net_tx_action(void)
85141 {
85142 struct softnet_data *sd = &__get_cpu_var(softnet_data);
85143
85144@@ -3457,7 +3461,7 @@ ncls:
85145 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
85146 } else {
85147 drop:
85148- atomic_long_inc(&skb->dev->rx_dropped);
85149+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
85150 kfree_skb(skb);
85151 /* Jamal, now you will not able to escape explaining
85152 * me how you were going to use this. :-)
85153@@ -4040,7 +4044,7 @@ void netif_napi_del(struct napi_struct *napi)
85154 }
85155 EXPORT_SYMBOL(netif_napi_del);
85156
85157-static void net_rx_action(struct softirq_action *h)
85158+static void net_rx_action(void)
85159 {
85160 struct softnet_data *sd = &__get_cpu_var(softnet_data);
85161 unsigned long time_limit = jiffies + 2;
85162@@ -4524,8 +4528,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
85163 else
85164 seq_printf(seq, "%04x", ntohs(pt->type));
85165
85166+#ifdef CONFIG_GRKERNSEC_HIDESYM
85167+ seq_printf(seq, " %-8s %p\n",
85168+ pt->dev ? pt->dev->name : "", NULL);
85169+#else
85170 seq_printf(seq, " %-8s %pF\n",
85171 pt->dev ? pt->dev->name : "", pt->func);
85172+#endif
85173 }
85174
85175 return 0;
85176@@ -6097,7 +6106,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
85177 } else {
85178 netdev_stats_to_stats64(storage, &dev->stats);
85179 }
85180- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
85181+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
85182 return storage;
85183 }
85184 EXPORT_SYMBOL(dev_get_stats);
85185diff --git a/net/core/flow.c b/net/core/flow.c
85186index b0901ee..7d3c2ca 100644
85187--- a/net/core/flow.c
85188+++ b/net/core/flow.c
85189@@ -61,7 +61,7 @@ struct flow_cache {
85190 struct timer_list rnd_timer;
85191 };
85192
85193-atomic_t flow_cache_genid = ATOMIC_INIT(0);
85194+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
85195 EXPORT_SYMBOL(flow_cache_genid);
85196 static struct flow_cache flow_cache_global;
85197 static struct kmem_cache *flow_cachep __read_mostly;
85198@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
85199
85200 static int flow_entry_valid(struct flow_cache_entry *fle)
85201 {
85202- if (atomic_read(&flow_cache_genid) != fle->genid)
85203+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
85204 return 0;
85205 if (fle->object && !fle->object->ops->check(fle->object))
85206 return 0;
85207@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
85208 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
85209 fcp->hash_count++;
85210 }
85211- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
85212+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
85213 flo = fle->object;
85214 if (!flo)
85215 goto ret_object;
85216@@ -280,7 +280,7 @@ nocache:
85217 }
85218 flo = resolver(net, key, family, dir, flo, ctx);
85219 if (fle) {
85220- fle->genid = atomic_read(&flow_cache_genid);
85221+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
85222 if (!IS_ERR(flo))
85223 fle->object = flo;
85224 else
85225diff --git a/net/core/iovec.c b/net/core/iovec.c
85226index 7e7aeb0..2a998cb 100644
85227--- a/net/core/iovec.c
85228+++ b/net/core/iovec.c
85229@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
85230 if (m->msg_namelen) {
85231 if (mode == VERIFY_READ) {
85232 void __user *namep;
85233- namep = (void __user __force *) m->msg_name;
85234+ namep = (void __force_user *) m->msg_name;
85235 err = move_addr_to_kernel(namep, m->msg_namelen,
85236 address);
85237 if (err < 0)
85238@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
85239 }
85240
85241 size = m->msg_iovlen * sizeof(struct iovec);
85242- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
85243+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
85244 return -EFAULT;
85245
85246 m->msg_iov = iov;
85247diff --git a/net/core/neighbour.c b/net/core/neighbour.c
85248index c815f28..e6403f2 100644
85249--- a/net/core/neighbour.c
85250+++ b/net/core/neighbour.c
85251@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
85252 size_t *lenp, loff_t *ppos)
85253 {
85254 int size, ret;
85255- ctl_table tmp = *ctl;
85256+ ctl_table_no_const tmp = *ctl;
85257
85258 tmp.extra1 = &zero;
85259 tmp.extra2 = &unres_qlen_max;
85260diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
85261index 28c5f5a..7edf2e2 100644
85262--- a/net/core/net-sysfs.c
85263+++ b/net/core/net-sysfs.c
85264@@ -1455,7 +1455,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
85265 }
85266 EXPORT_SYMBOL(netdev_class_remove_file);
85267
85268-int netdev_kobject_init(void)
85269+int __init netdev_kobject_init(void)
85270 {
85271 kobj_ns_type_register(&net_ns_type_operations);
85272 return class_register(&net_class);
85273diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
85274index 8acce01..2e306bb 100644
85275--- a/net/core/net_namespace.c
85276+++ b/net/core/net_namespace.c
85277@@ -442,7 +442,7 @@ static int __register_pernet_operations(struct list_head *list,
85278 int error;
85279 LIST_HEAD(net_exit_list);
85280
85281- list_add_tail(&ops->list, list);
85282+ pax_list_add_tail((struct list_head *)&ops->list, list);
85283 if (ops->init || (ops->id && ops->size)) {
85284 for_each_net(net) {
85285 error = ops_init(ops, net);
85286@@ -455,7 +455,7 @@ static int __register_pernet_operations(struct list_head *list,
85287
85288 out_undo:
85289 /* If I have an error cleanup all namespaces I initialized */
85290- list_del(&ops->list);
85291+ pax_list_del((struct list_head *)&ops->list);
85292 ops_exit_list(ops, &net_exit_list);
85293 ops_free_list(ops, &net_exit_list);
85294 return error;
85295@@ -466,7 +466,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
85296 struct net *net;
85297 LIST_HEAD(net_exit_list);
85298
85299- list_del(&ops->list);
85300+ pax_list_del((struct list_head *)&ops->list);
85301 for_each_net(net)
85302 list_add_tail(&net->exit_list, &net_exit_list);
85303 ops_exit_list(ops, &net_exit_list);
85304@@ -600,7 +600,7 @@ int register_pernet_device(struct pernet_operations *ops)
85305 mutex_lock(&net_mutex);
85306 error = register_pernet_operations(&pernet_list, ops);
85307 if (!error && (first_device == &pernet_list))
85308- first_device = &ops->list;
85309+ first_device = (struct list_head *)&ops->list;
85310 mutex_unlock(&net_mutex);
85311 return error;
85312 }
85313diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
85314index 6212ec9..dd4ad3b 100644
85315--- a/net/core/rtnetlink.c
85316+++ b/net/core/rtnetlink.c
85317@@ -58,7 +58,7 @@ struct rtnl_link {
85318 rtnl_doit_func doit;
85319 rtnl_dumpit_func dumpit;
85320 rtnl_calcit_func calcit;
85321-};
85322+} __no_const;
85323
85324 static DEFINE_MUTEX(rtnl_mutex);
85325
85326@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
85327 if (rtnl_link_ops_get(ops->kind))
85328 return -EEXIST;
85329
85330- if (!ops->dellink)
85331- ops->dellink = unregister_netdevice_queue;
85332+ if (!ops->dellink) {
85333+ pax_open_kernel();
85334+ *(void **)&ops->dellink = unregister_netdevice_queue;
85335+ pax_close_kernel();
85336+ }
85337
85338- list_add_tail(&ops->list, &link_ops);
85339+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
85340 return 0;
85341 }
85342 EXPORT_SYMBOL_GPL(__rtnl_link_register);
85343@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
85344 for_each_net(net) {
85345 __rtnl_kill_links(net, ops);
85346 }
85347- list_del(&ops->list);
85348+ pax_list_del((struct list_head *)&ops->list);
85349 }
85350 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
85351
85352diff --git a/net/core/scm.c b/net/core/scm.c
85353index 905dcc6..14ee2d6 100644
85354--- a/net/core/scm.c
85355+++ b/net/core/scm.c
85356@@ -224,7 +224,7 @@ EXPORT_SYMBOL(__scm_send);
85357 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
85358 {
85359 struct cmsghdr __user *cm
85360- = (__force struct cmsghdr __user *)msg->msg_control;
85361+ = (struct cmsghdr __force_user *)msg->msg_control;
85362 struct cmsghdr cmhdr;
85363 int cmlen = CMSG_LEN(len);
85364 int err;
85365@@ -247,7 +247,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
85366 err = -EFAULT;
85367 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
85368 goto out;
85369- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
85370+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
85371 goto out;
85372 cmlen = CMSG_SPACE(len);
85373 if (msg->msg_controllen < cmlen)
85374@@ -263,7 +263,7 @@ EXPORT_SYMBOL(put_cmsg);
85375 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
85376 {
85377 struct cmsghdr __user *cm
85378- = (__force struct cmsghdr __user*)msg->msg_control;
85379+ = (struct cmsghdr __force_user *)msg->msg_control;
85380
85381 int fdmax = 0;
85382 int fdnum = scm->fp->count;
85383@@ -283,7 +283,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
85384 if (fdnum < fdmax)
85385 fdmax = fdnum;
85386
85387- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
85388+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
85389 i++, cmfptr++)
85390 {
85391 struct socket *sock;
85392diff --git a/net/core/sock.c b/net/core/sock.c
85393index bc131d4..029e378 100644
85394--- a/net/core/sock.c
85395+++ b/net/core/sock.c
85396@@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85397 struct sk_buff_head *list = &sk->sk_receive_queue;
85398
85399 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
85400- atomic_inc(&sk->sk_drops);
85401+ atomic_inc_unchecked(&sk->sk_drops);
85402 trace_sock_rcvqueue_full(sk, skb);
85403 return -ENOMEM;
85404 }
85405@@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85406 return err;
85407
85408 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
85409- atomic_inc(&sk->sk_drops);
85410+ atomic_inc_unchecked(&sk->sk_drops);
85411 return -ENOBUFS;
85412 }
85413
85414@@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85415 skb_dst_force(skb);
85416
85417 spin_lock_irqsave(&list->lock, flags);
85418- skb->dropcount = atomic_read(&sk->sk_drops);
85419+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
85420 __skb_queue_tail(list, skb);
85421 spin_unlock_irqrestore(&list->lock, flags);
85422
85423@@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
85424 skb->dev = NULL;
85425
85426 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
85427- atomic_inc(&sk->sk_drops);
85428+ atomic_inc_unchecked(&sk->sk_drops);
85429 goto discard_and_relse;
85430 }
85431 if (nested)
85432@@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
85433 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
85434 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
85435 bh_unlock_sock(sk);
85436- atomic_inc(&sk->sk_drops);
85437+ atomic_inc_unchecked(&sk->sk_drops);
85438 goto discard_and_relse;
85439 }
85440
85441@@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
85442 struct timeval tm;
85443 } v;
85444
85445- int lv = sizeof(int);
85446- int len;
85447+ unsigned int lv = sizeof(int);
85448+ unsigned int len;
85449
85450 if (get_user(len, optlen))
85451 return -EFAULT;
85452- if (len < 0)
85453+ if (len > INT_MAX)
85454 return -EINVAL;
85455
85456 memset(&v, 0, sizeof(v));
85457@@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
85458
85459 case SO_PEERNAME:
85460 {
85461- char address[128];
85462+ char address[_K_SS_MAXSIZE];
85463
85464 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
85465 return -ENOTCONN;
85466- if (lv < len)
85467+ if (lv < len || sizeof address < len)
85468 return -EINVAL;
85469 if (copy_to_user(optval, address, len))
85470 return -EFAULT;
85471@@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
85472
85473 if (len > lv)
85474 len = lv;
85475- if (copy_to_user(optval, &v, len))
85476+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
85477 return -EFAULT;
85478 lenout:
85479 if (put_user(len, optlen))
85480@@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
85481 */
85482 smp_wmb();
85483 atomic_set(&sk->sk_refcnt, 1);
85484- atomic_set(&sk->sk_drops, 0);
85485+ atomic_set_unchecked(&sk->sk_drops, 0);
85486 }
85487 EXPORT_SYMBOL(sock_init_data);
85488
85489diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
85490index 750f44f..922399c 100644
85491--- a/net/core/sock_diag.c
85492+++ b/net/core/sock_diag.c
85493@@ -9,26 +9,33 @@
85494 #include <linux/inet_diag.h>
85495 #include <linux/sock_diag.h>
85496
85497-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
85498+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
85499 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
85500 static DEFINE_MUTEX(sock_diag_table_mutex);
85501
85502 int sock_diag_check_cookie(void *sk, __u32 *cookie)
85503 {
85504+#ifndef CONFIG_GRKERNSEC_HIDESYM
85505 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
85506 cookie[1] != INET_DIAG_NOCOOKIE) &&
85507 ((u32)(unsigned long)sk != cookie[0] ||
85508 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
85509 return -ESTALE;
85510 else
85511+#endif
85512 return 0;
85513 }
85514 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
85515
85516 void sock_diag_save_cookie(void *sk, __u32 *cookie)
85517 {
85518+#ifdef CONFIG_GRKERNSEC_HIDESYM
85519+ cookie[0] = 0;
85520+ cookie[1] = 0;
85521+#else
85522 cookie[0] = (u32)(unsigned long)sk;
85523 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
85524+#endif
85525 }
85526 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
85527
85528@@ -75,8 +82,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
85529 mutex_lock(&sock_diag_table_mutex);
85530 if (sock_diag_handlers[hndl->family])
85531 err = -EBUSY;
85532- else
85533+ else {
85534+ pax_open_kernel();
85535 sock_diag_handlers[hndl->family] = hndl;
85536+ pax_close_kernel();
85537+ }
85538 mutex_unlock(&sock_diag_table_mutex);
85539
85540 return err;
85541@@ -92,26 +102,13 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
85542
85543 mutex_lock(&sock_diag_table_mutex);
85544 BUG_ON(sock_diag_handlers[family] != hnld);
85545+ pax_open_kernel();
85546 sock_diag_handlers[family] = NULL;
85547+ pax_close_kernel();
85548 mutex_unlock(&sock_diag_table_mutex);
85549 }
85550 EXPORT_SYMBOL_GPL(sock_diag_unregister);
85551
85552-static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
85553-{
85554- if (sock_diag_handlers[family] == NULL)
85555- request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
85556- NETLINK_SOCK_DIAG, family);
85557-
85558- mutex_lock(&sock_diag_table_mutex);
85559- return sock_diag_handlers[family];
85560-}
85561-
85562-static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
85563-{
85564- mutex_unlock(&sock_diag_table_mutex);
85565-}
85566-
85567 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85568 {
85569 int err;
85570@@ -124,12 +121,17 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85571 if (req->sdiag_family >= AF_MAX)
85572 return -EINVAL;
85573
85574- hndl = sock_diag_lock_handler(req->sdiag_family);
85575+ if (sock_diag_handlers[req->sdiag_family] == NULL)
85576+ request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
85577+ NETLINK_SOCK_DIAG, req->sdiag_family);
85578+
85579+ mutex_lock(&sock_diag_table_mutex);
85580+ hndl = sock_diag_handlers[req->sdiag_family];
85581 if (hndl == NULL)
85582 err = -ENOENT;
85583 else
85584 err = hndl->dump(skb, nlh);
85585- sock_diag_unlock_handler(hndl);
85586+ mutex_unlock(&sock_diag_table_mutex);
85587
85588 return err;
85589 }
85590diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
85591index d1b0804..98cf5f7 100644
85592--- a/net/core/sysctl_net_core.c
85593+++ b/net/core/sysctl_net_core.c
85594@@ -26,7 +26,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
85595 {
85596 unsigned int orig_size, size;
85597 int ret, i;
85598- ctl_table tmp = {
85599+ ctl_table_no_const tmp = {
85600 .data = &size,
85601 .maxlen = sizeof(size),
85602 .mode = table->mode
85603@@ -205,13 +205,12 @@ static struct ctl_table netns_core_table[] = {
85604
85605 static __net_init int sysctl_core_net_init(struct net *net)
85606 {
85607- struct ctl_table *tbl;
85608+ ctl_table_no_const *tbl = NULL;
85609
85610 net->core.sysctl_somaxconn = SOMAXCONN;
85611
85612- tbl = netns_core_table;
85613 if (!net_eq(net, &init_net)) {
85614- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
85615+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
85616 if (tbl == NULL)
85617 goto err_dup;
85618
85619@@ -221,17 +220,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
85620 if (net->user_ns != &init_user_ns) {
85621 tbl[0].procname = NULL;
85622 }
85623- }
85624-
85625- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
85626+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
85627+ } else
85628+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
85629 if (net->core.sysctl_hdr == NULL)
85630 goto err_reg;
85631
85632 return 0;
85633
85634 err_reg:
85635- if (tbl != netns_core_table)
85636- kfree(tbl);
85637+ kfree(tbl);
85638 err_dup:
85639 return -ENOMEM;
85640 }
85641@@ -246,7 +244,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
85642 kfree(tbl);
85643 }
85644
85645-static __net_initdata struct pernet_operations sysctl_core_ops = {
85646+static __net_initconst struct pernet_operations sysctl_core_ops = {
85647 .init = sysctl_core_net_init,
85648 .exit = sysctl_core_net_exit,
85649 };
85650diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
85651index 307c322..78a4c6f 100644
85652--- a/net/decnet/af_decnet.c
85653+++ b/net/decnet/af_decnet.c
85654@@ -468,6 +468,7 @@ static struct proto dn_proto = {
85655 .sysctl_rmem = sysctl_decnet_rmem,
85656 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
85657 .obj_size = sizeof(struct dn_sock),
85658+ .slab_flags = SLAB_USERCOPY,
85659 };
85660
85661 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
85662diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
85663index a55eecc..dd8428c 100644
85664--- a/net/decnet/sysctl_net_decnet.c
85665+++ b/net/decnet/sysctl_net_decnet.c
85666@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
85667
85668 if (len > *lenp) len = *lenp;
85669
85670- if (copy_to_user(buffer, addr, len))
85671+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
85672 return -EFAULT;
85673
85674 *lenp = len;
85675@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
85676
85677 if (len > *lenp) len = *lenp;
85678
85679- if (copy_to_user(buffer, devname, len))
85680+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
85681 return -EFAULT;
85682
85683 *lenp = len;
85684diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
85685index fcf104e..95552d4 100644
85686--- a/net/ipv4/af_inet.c
85687+++ b/net/ipv4/af_inet.c
85688@@ -1717,13 +1717,9 @@ static int __init inet_init(void)
85689
85690 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
85691
85692- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
85693- if (!sysctl_local_reserved_ports)
85694- goto out;
85695-
85696 rc = proto_register(&tcp_prot, 1);
85697 if (rc)
85698- goto out_free_reserved_ports;
85699+ goto out;
85700
85701 rc = proto_register(&udp_prot, 1);
85702 if (rc)
85703@@ -1832,8 +1828,6 @@ out_unregister_udp_proto:
85704 proto_unregister(&udp_prot);
85705 out_unregister_tcp_proto:
85706 proto_unregister(&tcp_prot);
85707-out_free_reserved_ports:
85708- kfree(sysctl_local_reserved_ports);
85709 goto out;
85710 }
85711
85712diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
85713index a69b4e4..dbccba5 100644
85714--- a/net/ipv4/ah4.c
85715+++ b/net/ipv4/ah4.c
85716@@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
85717 return;
85718
85719 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
85720- atomic_inc(&flow_cache_genid);
85721+ atomic_inc_unchecked(&flow_cache_genid);
85722 rt_genid_bump(net);
85723
85724 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
85725diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
85726index a8e4f26..25e5f40 100644
85727--- a/net/ipv4/devinet.c
85728+++ b/net/ipv4/devinet.c
85729@@ -1763,7 +1763,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
85730 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
85731 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
85732
85733-static struct devinet_sysctl_table {
85734+static const struct devinet_sysctl_table {
85735 struct ctl_table_header *sysctl_header;
85736 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
85737 } devinet_sysctl = {
85738@@ -1881,7 +1881,7 @@ static __net_init int devinet_init_net(struct net *net)
85739 int err;
85740 struct ipv4_devconf *all, *dflt;
85741 #ifdef CONFIG_SYSCTL
85742- struct ctl_table *tbl = ctl_forward_entry;
85743+ ctl_table_no_const *tbl = NULL;
85744 struct ctl_table_header *forw_hdr;
85745 #endif
85746
85747@@ -1899,7 +1899,7 @@ static __net_init int devinet_init_net(struct net *net)
85748 goto err_alloc_dflt;
85749
85750 #ifdef CONFIG_SYSCTL
85751- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
85752+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
85753 if (tbl == NULL)
85754 goto err_alloc_ctl;
85755
85756@@ -1919,7 +1919,10 @@ static __net_init int devinet_init_net(struct net *net)
85757 goto err_reg_dflt;
85758
85759 err = -ENOMEM;
85760- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
85761+ if (!net_eq(net, &init_net))
85762+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
85763+ else
85764+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
85765 if (forw_hdr == NULL)
85766 goto err_reg_ctl;
85767 net->ipv4.forw_hdr = forw_hdr;
85768@@ -1935,8 +1938,7 @@ err_reg_ctl:
85769 err_reg_dflt:
85770 __devinet_sysctl_unregister(all);
85771 err_reg_all:
85772- if (tbl != ctl_forward_entry)
85773- kfree(tbl);
85774+ kfree(tbl);
85775 err_alloc_ctl:
85776 #endif
85777 if (dflt != &ipv4_devconf_dflt)
85778diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
85779index 3b4f0cd..8cb864c 100644
85780--- a/net/ipv4/esp4.c
85781+++ b/net/ipv4/esp4.c
85782@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
85783 return;
85784
85785 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
85786- atomic_inc(&flow_cache_genid);
85787+ atomic_inc_unchecked(&flow_cache_genid);
85788 rt_genid_bump(net);
85789
85790 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
85791diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
85792index 5cd75e2..f57ef39 100644
85793--- a/net/ipv4/fib_frontend.c
85794+++ b/net/ipv4/fib_frontend.c
85795@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
85796 #ifdef CONFIG_IP_ROUTE_MULTIPATH
85797 fib_sync_up(dev);
85798 #endif
85799- atomic_inc(&net->ipv4.dev_addr_genid);
85800+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
85801 rt_cache_flush(dev_net(dev));
85802 break;
85803 case NETDEV_DOWN:
85804 fib_del_ifaddr(ifa, NULL);
85805- atomic_inc(&net->ipv4.dev_addr_genid);
85806+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
85807 if (ifa->ifa_dev->ifa_list == NULL) {
85808 /* Last address was deleted from this interface.
85809 * Disable IP.
85810@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
85811 #ifdef CONFIG_IP_ROUTE_MULTIPATH
85812 fib_sync_up(dev);
85813 #endif
85814- atomic_inc(&net->ipv4.dev_addr_genid);
85815+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
85816 rt_cache_flush(net);
85817 break;
85818 case NETDEV_DOWN:
85819diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
85820index 4797a80..2bd54e9 100644
85821--- a/net/ipv4/fib_semantics.c
85822+++ b/net/ipv4/fib_semantics.c
85823@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
85824 nh->nh_saddr = inet_select_addr(nh->nh_dev,
85825 nh->nh_gw,
85826 nh->nh_parent->fib_scope);
85827- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
85828+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
85829
85830 return nh->nh_saddr;
85831 }
85832diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
85833index d0670f0..744ac80 100644
85834--- a/net/ipv4/inet_connection_sock.c
85835+++ b/net/ipv4/inet_connection_sock.c
85836@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
85837 .range = { 32768, 61000 },
85838 };
85839
85840-unsigned long *sysctl_local_reserved_ports;
85841+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
85842 EXPORT_SYMBOL(sysctl_local_reserved_ports);
85843
85844 void inet_get_local_port_range(int *low, int *high)
85845diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
85846index fa3ae81..0dbe6b8 100644
85847--- a/net/ipv4/inet_hashtables.c
85848+++ b/net/ipv4/inet_hashtables.c
85849@@ -18,12 +18,15 @@
85850 #include <linux/sched.h>
85851 #include <linux/slab.h>
85852 #include <linux/wait.h>
85853+#include <linux/security.h>
85854
85855 #include <net/inet_connection_sock.h>
85856 #include <net/inet_hashtables.h>
85857 #include <net/secure_seq.h>
85858 #include <net/ip.h>
85859
85860+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
85861+
85862 /*
85863 * Allocate and initialize a new local port bind bucket.
85864 * The bindhash mutex for snum's hash chain must be held here.
85865@@ -540,6 +543,8 @@ ok:
85866 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
85867 spin_unlock(&head->lock);
85868
85869+ gr_update_task_in_ip_table(current, inet_sk(sk));
85870+
85871 if (tw) {
85872 inet_twsk_deschedule(tw, death_row);
85873 while (twrefcnt) {
85874diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
85875index 000e3d2..5472da3 100644
85876--- a/net/ipv4/inetpeer.c
85877+++ b/net/ipv4/inetpeer.c
85878@@ -503,8 +503,8 @@ relookup:
85879 if (p) {
85880 p->daddr = *daddr;
85881 atomic_set(&p->refcnt, 1);
85882- atomic_set(&p->rid, 0);
85883- atomic_set(&p->ip_id_count,
85884+ atomic_set_unchecked(&p->rid, 0);
85885+ atomic_set_unchecked(&p->ip_id_count,
85886 (daddr->family == AF_INET) ?
85887 secure_ip_id(daddr->addr.a4) :
85888 secure_ipv6_id(daddr->addr.a6));
85889diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
85890index a8fc332..4ca4ca65 100644
85891--- a/net/ipv4/ip_fragment.c
85892+++ b/net/ipv4/ip_fragment.c
85893@@ -319,7 +319,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
85894 return 0;
85895
85896 start = qp->rid;
85897- end = atomic_inc_return(&peer->rid);
85898+ end = atomic_inc_return_unchecked(&peer->rid);
85899 qp->rid = end;
85900
85901 rc = qp->q.fragments && (end - start) > max;
85902@@ -786,12 +786,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
85903
85904 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85905 {
85906- struct ctl_table *table;
85907+ ctl_table_no_const *table = NULL;
85908 struct ctl_table_header *hdr;
85909
85910- table = ip4_frags_ns_ctl_table;
85911 if (!net_eq(net, &init_net)) {
85912- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
85913+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
85914 if (table == NULL)
85915 goto err_alloc;
85916
85917@@ -802,9 +801,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85918 /* Don't export sysctls to unprivileged users */
85919 if (net->user_ns != &init_user_ns)
85920 table[0].procname = NULL;
85921- }
85922+ hdr = register_net_sysctl(net, "net/ipv4", table);
85923+ } else
85924+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
85925
85926- hdr = register_net_sysctl(net, "net/ipv4", table);
85927 if (hdr == NULL)
85928 goto err_reg;
85929
85930@@ -812,8 +812,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85931 return 0;
85932
85933 err_reg:
85934- if (!net_eq(net, &init_net))
85935- kfree(table);
85936+ kfree(table);
85937 err_alloc:
85938 return -ENOMEM;
85939 }
85940diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
85941index a85062b..2958a9b 100644
85942--- a/net/ipv4/ip_gre.c
85943+++ b/net/ipv4/ip_gre.c
85944@@ -124,7 +124,7 @@ static bool log_ecn_error = true;
85945 module_param(log_ecn_error, bool, 0644);
85946 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
85947
85948-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
85949+static struct rtnl_link_ops ipgre_link_ops;
85950 static int ipgre_tunnel_init(struct net_device *dev);
85951 static void ipgre_tunnel_setup(struct net_device *dev);
85952 static int ipgre_tunnel_bind_dev(struct net_device *dev);
85953@@ -1753,7 +1753,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
85954 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
85955 };
85956
85957-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
85958+static struct rtnl_link_ops ipgre_link_ops = {
85959 .kind = "gre",
85960 .maxtype = IFLA_GRE_MAX,
85961 .policy = ipgre_policy,
85962@@ -1766,7 +1766,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
85963 .fill_info = ipgre_fill_info,
85964 };
85965
85966-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
85967+static struct rtnl_link_ops ipgre_tap_ops = {
85968 .kind = "gretap",
85969 .maxtype = IFLA_GRE_MAX,
85970 .policy = ipgre_policy,
85971diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
85972index d9c4f11..02b82db 100644
85973--- a/net/ipv4/ip_sockglue.c
85974+++ b/net/ipv4/ip_sockglue.c
85975@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
85976 len = min_t(unsigned int, len, opt->optlen);
85977 if (put_user(len, optlen))
85978 return -EFAULT;
85979- if (copy_to_user(optval, opt->__data, len))
85980+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
85981+ copy_to_user(optval, opt->__data, len))
85982 return -EFAULT;
85983 return 0;
85984 }
85985@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
85986 if (sk->sk_type != SOCK_STREAM)
85987 return -ENOPROTOOPT;
85988
85989- msg.msg_control = optval;
85990+ msg.msg_control = (void __force_kernel *)optval;
85991 msg.msg_controllen = len;
85992 msg.msg_flags = flags;
85993
85994diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
85995index c3a4233..1412161 100644
85996--- a/net/ipv4/ip_vti.c
85997+++ b/net/ipv4/ip_vti.c
85998@@ -47,7 +47,7 @@
85999 #define HASH_SIZE 16
86000 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
86001
86002-static struct rtnl_link_ops vti_link_ops __read_mostly;
86003+static struct rtnl_link_ops vti_link_ops;
86004
86005 static int vti_net_id __read_mostly;
86006 struct vti_net {
86007@@ -886,7 +886,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
86008 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
86009 };
86010
86011-static struct rtnl_link_ops vti_link_ops __read_mostly = {
86012+static struct rtnl_link_ops vti_link_ops = {
86013 .kind = "vti",
86014 .maxtype = IFLA_VTI_MAX,
86015 .policy = vti_policy,
86016diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
86017index 9a46dae..5f793a0 100644
86018--- a/net/ipv4/ipcomp.c
86019+++ b/net/ipv4/ipcomp.c
86020@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
86021 return;
86022
86023 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
86024- atomic_inc(&flow_cache_genid);
86025+ atomic_inc_unchecked(&flow_cache_genid);
86026 rt_genid_bump(net);
86027
86028 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
86029diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
86030index a2e50ae..e152b7c 100644
86031--- a/net/ipv4/ipconfig.c
86032+++ b/net/ipv4/ipconfig.c
86033@@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
86034
86035 mm_segment_t oldfs = get_fs();
86036 set_fs(get_ds());
86037- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
86038+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
86039 set_fs(oldfs);
86040 return res;
86041 }
86042@@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
86043
86044 mm_segment_t oldfs = get_fs();
86045 set_fs(get_ds());
86046- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
86047+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
86048 set_fs(oldfs);
86049 return res;
86050 }
86051@@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
86052
86053 mm_segment_t oldfs = get_fs();
86054 set_fs(get_ds());
86055- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
86056+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
86057 set_fs(oldfs);
86058 return res;
86059 }
86060diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
86061index 191fc24..1b3b804 100644
86062--- a/net/ipv4/ipip.c
86063+++ b/net/ipv4/ipip.c
86064@@ -138,7 +138,7 @@ struct ipip_net {
86065 static int ipip_tunnel_init(struct net_device *dev);
86066 static void ipip_tunnel_setup(struct net_device *dev);
86067 static void ipip_dev_free(struct net_device *dev);
86068-static struct rtnl_link_ops ipip_link_ops __read_mostly;
86069+static struct rtnl_link_ops ipip_link_ops;
86070
86071 static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
86072 struct rtnl_link_stats64 *tot)
86073@@ -972,7 +972,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
86074 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
86075 };
86076
86077-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
86078+static struct rtnl_link_ops ipip_link_ops = {
86079 .kind = "ipip",
86080 .maxtype = IFLA_IPTUN_MAX,
86081 .policy = ipip_policy,
86082diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
86083index 3ea4127..849297b 100644
86084--- a/net/ipv4/netfilter/arp_tables.c
86085+++ b/net/ipv4/netfilter/arp_tables.c
86086@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
86087 #endif
86088
86089 static int get_info(struct net *net, void __user *user,
86090- const int *len, int compat)
86091+ int len, int compat)
86092 {
86093 char name[XT_TABLE_MAXNAMELEN];
86094 struct xt_table *t;
86095 int ret;
86096
86097- if (*len != sizeof(struct arpt_getinfo)) {
86098- duprintf("length %u != %Zu\n", *len,
86099+ if (len != sizeof(struct arpt_getinfo)) {
86100+ duprintf("length %u != %Zu\n", len,
86101 sizeof(struct arpt_getinfo));
86102 return -EINVAL;
86103 }
86104@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
86105 info.size = private->size;
86106 strcpy(info.name, name);
86107
86108- if (copy_to_user(user, &info, *len) != 0)
86109+ if (copy_to_user(user, &info, len) != 0)
86110 ret = -EFAULT;
86111 else
86112 ret = 0;
86113@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
86114
86115 switch (cmd) {
86116 case ARPT_SO_GET_INFO:
86117- ret = get_info(sock_net(sk), user, len, 1);
86118+ ret = get_info(sock_net(sk), user, *len, 1);
86119 break;
86120 case ARPT_SO_GET_ENTRIES:
86121 ret = compat_get_entries(sock_net(sk), user, len);
86122@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
86123
86124 switch (cmd) {
86125 case ARPT_SO_GET_INFO:
86126- ret = get_info(sock_net(sk), user, len, 0);
86127+ ret = get_info(sock_net(sk), user, *len, 0);
86128 break;
86129
86130 case ARPT_SO_GET_ENTRIES:
86131diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
86132index 17c5e06..1b91206 100644
86133--- a/net/ipv4/netfilter/ip_tables.c
86134+++ b/net/ipv4/netfilter/ip_tables.c
86135@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
86136 #endif
86137
86138 static int get_info(struct net *net, void __user *user,
86139- const int *len, int compat)
86140+ int len, int compat)
86141 {
86142 char name[XT_TABLE_MAXNAMELEN];
86143 struct xt_table *t;
86144 int ret;
86145
86146- if (*len != sizeof(struct ipt_getinfo)) {
86147- duprintf("length %u != %zu\n", *len,
86148+ if (len != sizeof(struct ipt_getinfo)) {
86149+ duprintf("length %u != %zu\n", len,
86150 sizeof(struct ipt_getinfo));
86151 return -EINVAL;
86152 }
86153@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
86154 info.size = private->size;
86155 strcpy(info.name, name);
86156
86157- if (copy_to_user(user, &info, *len) != 0)
86158+ if (copy_to_user(user, &info, len) != 0)
86159 ret = -EFAULT;
86160 else
86161 ret = 0;
86162@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86163
86164 switch (cmd) {
86165 case IPT_SO_GET_INFO:
86166- ret = get_info(sock_net(sk), user, len, 1);
86167+ ret = get_info(sock_net(sk), user, *len, 1);
86168 break;
86169 case IPT_SO_GET_ENTRIES:
86170 ret = compat_get_entries(sock_net(sk), user, len);
86171@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86172
86173 switch (cmd) {
86174 case IPT_SO_GET_INFO:
86175- ret = get_info(sock_net(sk), user, len, 0);
86176+ ret = get_info(sock_net(sk), user, *len, 0);
86177 break;
86178
86179 case IPT_SO_GET_ENTRIES:
86180diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
86181index dc454cc..5bb917f 100644
86182--- a/net/ipv4/ping.c
86183+++ b/net/ipv4/ping.c
86184@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
86185 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
86186 0, sock_i_ino(sp),
86187 atomic_read(&sp->sk_refcnt), sp,
86188- atomic_read(&sp->sk_drops), len);
86189+ atomic_read_unchecked(&sp->sk_drops), len);
86190 }
86191
86192 static int ping_seq_show(struct seq_file *seq, void *v)
86193diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
86194index 6f08991..55867ad 100644
86195--- a/net/ipv4/raw.c
86196+++ b/net/ipv4/raw.c
86197@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
86198 int raw_rcv(struct sock *sk, struct sk_buff *skb)
86199 {
86200 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
86201- atomic_inc(&sk->sk_drops);
86202+ atomic_inc_unchecked(&sk->sk_drops);
86203 kfree_skb(skb);
86204 return NET_RX_DROP;
86205 }
86206@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
86207
86208 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
86209 {
86210+ struct icmp_filter filter;
86211+
86212 if (optlen > sizeof(struct icmp_filter))
86213 optlen = sizeof(struct icmp_filter);
86214- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
86215+ if (copy_from_user(&filter, optval, optlen))
86216 return -EFAULT;
86217+ raw_sk(sk)->filter = filter;
86218 return 0;
86219 }
86220
86221 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
86222 {
86223 int len, ret = -EFAULT;
86224+ struct icmp_filter filter;
86225
86226 if (get_user(len, optlen))
86227 goto out;
86228@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
86229 if (len > sizeof(struct icmp_filter))
86230 len = sizeof(struct icmp_filter);
86231 ret = -EFAULT;
86232- if (put_user(len, optlen) ||
86233- copy_to_user(optval, &raw_sk(sk)->filter, len))
86234+ filter = raw_sk(sk)->filter;
86235+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
86236 goto out;
86237 ret = 0;
86238 out: return ret;
86239@@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
86240 0, 0L, 0,
86241 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
86242 0, sock_i_ino(sp),
86243- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
86244+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
86245 }
86246
86247 static int raw_seq_show(struct seq_file *seq, void *v)
86248diff --git a/net/ipv4/route.c b/net/ipv4/route.c
86249index a0fcc47..32e2c89 100644
86250--- a/net/ipv4/route.c
86251+++ b/net/ipv4/route.c
86252@@ -2552,34 +2552,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
86253 .maxlen = sizeof(int),
86254 .mode = 0200,
86255 .proc_handler = ipv4_sysctl_rtcache_flush,
86256+ .extra1 = &init_net,
86257 },
86258 { },
86259 };
86260
86261 static __net_init int sysctl_route_net_init(struct net *net)
86262 {
86263- struct ctl_table *tbl;
86264+ ctl_table_no_const *tbl = NULL;
86265
86266- tbl = ipv4_route_flush_table;
86267 if (!net_eq(net, &init_net)) {
86268- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
86269+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
86270 if (tbl == NULL)
86271 goto err_dup;
86272
86273 /* Don't export sysctls to unprivileged users */
86274 if (net->user_ns != &init_user_ns)
86275 tbl[0].procname = NULL;
86276- }
86277- tbl[0].extra1 = net;
86278+ tbl[0].extra1 = net;
86279+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
86280+ } else
86281+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
86282
86283- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
86284 if (net->ipv4.route_hdr == NULL)
86285 goto err_reg;
86286 return 0;
86287
86288 err_reg:
86289- if (tbl != ipv4_route_flush_table)
86290- kfree(tbl);
86291+ kfree(tbl);
86292 err_dup:
86293 return -ENOMEM;
86294 }
86295@@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
86296
86297 static __net_init int rt_genid_init(struct net *net)
86298 {
86299- atomic_set(&net->rt_genid, 0);
86300+ atomic_set_unchecked(&net->rt_genid, 0);
86301 get_random_bytes(&net->ipv4.dev_addr_genid,
86302 sizeof(net->ipv4.dev_addr_genid));
86303 return 0;
86304diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
86305index d84400b..62e066e 100644
86306--- a/net/ipv4/sysctl_net_ipv4.c
86307+++ b/net/ipv4/sysctl_net_ipv4.c
86308@@ -54,7 +54,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
86309 {
86310 int ret;
86311 int range[2];
86312- ctl_table tmp = {
86313+ ctl_table_no_const tmp = {
86314 .data = &range,
86315 .maxlen = sizeof(range),
86316 .mode = table->mode,
86317@@ -107,7 +107,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
86318 int ret;
86319 gid_t urange[2];
86320 kgid_t low, high;
86321- ctl_table tmp = {
86322+ ctl_table_no_const tmp = {
86323 .data = &urange,
86324 .maxlen = sizeof(urange),
86325 .mode = table->mode,
86326@@ -138,7 +138,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
86327 void __user *buffer, size_t *lenp, loff_t *ppos)
86328 {
86329 char val[TCP_CA_NAME_MAX];
86330- ctl_table tbl = {
86331+ ctl_table_no_const tbl = {
86332 .data = val,
86333 .maxlen = TCP_CA_NAME_MAX,
86334 };
86335@@ -157,7 +157,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
86336 void __user *buffer, size_t *lenp,
86337 loff_t *ppos)
86338 {
86339- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
86340+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
86341 int ret;
86342
86343 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
86344@@ -174,7 +174,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
86345 void __user *buffer, size_t *lenp,
86346 loff_t *ppos)
86347 {
86348- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
86349+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
86350 int ret;
86351
86352 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
86353@@ -200,15 +200,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
86354 struct mem_cgroup *memcg;
86355 #endif
86356
86357- ctl_table tmp = {
86358+ ctl_table_no_const tmp = {
86359 .data = &vec,
86360 .maxlen = sizeof(vec),
86361 .mode = ctl->mode,
86362 };
86363
86364 if (!write) {
86365- ctl->data = &net->ipv4.sysctl_tcp_mem;
86366- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
86367+ ctl_table_no_const tcp_mem = *ctl;
86368+
86369+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
86370+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
86371 }
86372
86373 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
86374@@ -235,7 +237,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
86375 int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
86376 size_t *lenp, loff_t *ppos)
86377 {
86378- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
86379+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
86380 struct tcp_fastopen_context *ctxt;
86381 int ret;
86382 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
86383@@ -476,7 +478,7 @@ static struct ctl_table ipv4_table[] = {
86384 },
86385 {
86386 .procname = "ip_local_reserved_ports",
86387- .data = NULL, /* initialized in sysctl_ipv4_init */
86388+ .data = sysctl_local_reserved_ports,
86389 .maxlen = 65536,
86390 .mode = 0644,
86391 .proc_handler = proc_do_large_bitmap,
86392@@ -860,11 +862,10 @@ static struct ctl_table ipv4_net_table[] = {
86393
86394 static __net_init int ipv4_sysctl_init_net(struct net *net)
86395 {
86396- struct ctl_table *table;
86397+ ctl_table_no_const *table = NULL;
86398
86399- table = ipv4_net_table;
86400 if (!net_eq(net, &init_net)) {
86401- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
86402+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
86403 if (table == NULL)
86404 goto err_alloc;
86405
86406@@ -897,15 +898,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
86407
86408 tcp_init_mem(net);
86409
86410- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
86411+ if (!net_eq(net, &init_net))
86412+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
86413+ else
86414+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
86415 if (net->ipv4.ipv4_hdr == NULL)
86416 goto err_reg;
86417
86418 return 0;
86419
86420 err_reg:
86421- if (!net_eq(net, &init_net))
86422- kfree(table);
86423+ kfree(table);
86424 err_alloc:
86425 return -ENOMEM;
86426 }
86427@@ -927,16 +930,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
86428 static __init int sysctl_ipv4_init(void)
86429 {
86430 struct ctl_table_header *hdr;
86431- struct ctl_table *i;
86432-
86433- for (i = ipv4_table; i->procname; i++) {
86434- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
86435- i->data = sysctl_local_reserved_ports;
86436- break;
86437- }
86438- }
86439- if (!i->procname)
86440- return -EINVAL;
86441
86442 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
86443 if (hdr == NULL)
86444diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
86445index 66702d3..31ff8f9 100644
86446--- a/net/ipv4/tcp_input.c
86447+++ b/net/ipv4/tcp_input.c
86448@@ -4733,7 +4733,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
86449 * simplifies code)
86450 */
86451 static void
86452-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
86453+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
86454 struct sk_buff *head, struct sk_buff *tail,
86455 u32 start, u32 end)
86456 {
86457@@ -5850,6 +5850,7 @@ discard:
86458 tcp_paws_reject(&tp->rx_opt, 0))
86459 goto discard_and_undo;
86460
86461+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
86462 if (th->syn) {
86463 /* We see SYN without ACK. It is attempt of
86464 * simultaneous connect with crossed SYNs.
86465@@ -5900,6 +5901,7 @@ discard:
86466 goto discard;
86467 #endif
86468 }
86469+#endif
86470 /* "fifth, if neither of the SYN or RST bits is set then
86471 * drop the segment and return."
86472 */
86473@@ -5944,7 +5946,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
86474 goto discard;
86475
86476 if (th->syn) {
86477- if (th->fin)
86478+ if (th->fin || th->urg || th->psh)
86479 goto discard;
86480 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
86481 return 1;
86482diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
86483index d9130a9..00328ff 100644
86484--- a/net/ipv4/tcp_ipv4.c
86485+++ b/net/ipv4/tcp_ipv4.c
86486@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
86487 EXPORT_SYMBOL(sysctl_tcp_low_latency);
86488
86489
86490+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86491+extern int grsec_enable_blackhole;
86492+#endif
86493+
86494 #ifdef CONFIG_TCP_MD5SIG
86495 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
86496 __be32 daddr, __be32 saddr, const struct tcphdr *th);
86497@@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
86498 return 0;
86499
86500 reset:
86501+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86502+ if (!grsec_enable_blackhole)
86503+#endif
86504 tcp_v4_send_reset(rsk, skb);
86505 discard:
86506 kfree_skb(skb);
86507@@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
86508 TCP_SKB_CB(skb)->sacked = 0;
86509
86510 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
86511- if (!sk)
86512+ if (!sk) {
86513+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86514+ ret = 1;
86515+#endif
86516 goto no_tcp_socket;
86517-
86518+ }
86519 process:
86520- if (sk->sk_state == TCP_TIME_WAIT)
86521+ if (sk->sk_state == TCP_TIME_WAIT) {
86522+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86523+ ret = 2;
86524+#endif
86525 goto do_time_wait;
86526+ }
86527
86528 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
86529 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
86530@@ -2050,6 +2064,10 @@ no_tcp_socket:
86531 bad_packet:
86532 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
86533 } else {
86534+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86535+ if (!grsec_enable_blackhole || (ret == 1 &&
86536+ (skb->dev->flags & IFF_LOOPBACK)))
86537+#endif
86538 tcp_v4_send_reset(NULL, skb);
86539 }
86540
86541diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
86542index f35f2df..ccb5ca6 100644
86543--- a/net/ipv4/tcp_minisocks.c
86544+++ b/net/ipv4/tcp_minisocks.c
86545@@ -27,6 +27,10 @@
86546 #include <net/inet_common.h>
86547 #include <net/xfrm.h>
86548
86549+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86550+extern int grsec_enable_blackhole;
86551+#endif
86552+
86553 int sysctl_tcp_syncookies __read_mostly = 1;
86554 EXPORT_SYMBOL(sysctl_tcp_syncookies);
86555
86556@@ -742,7 +746,10 @@ embryonic_reset:
86557 * avoid becoming vulnerable to outside attack aiming at
86558 * resetting legit local connections.
86559 */
86560- req->rsk_ops->send_reset(sk, skb);
86561+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86562+ if (!grsec_enable_blackhole)
86563+#endif
86564+ req->rsk_ops->send_reset(sk, skb);
86565 } else if (fastopen) { /* received a valid RST pkt */
86566 reqsk_fastopen_remove(sk, req, true);
86567 tcp_reset(sk);
86568diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
86569index 4526fe6..1a34e43 100644
86570--- a/net/ipv4/tcp_probe.c
86571+++ b/net/ipv4/tcp_probe.c
86572@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
86573 if (cnt + width >= len)
86574 break;
86575
86576- if (copy_to_user(buf + cnt, tbuf, width))
86577+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
86578 return -EFAULT;
86579 cnt += width;
86580 }
86581diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
86582index b78aac3..e18230b 100644
86583--- a/net/ipv4/tcp_timer.c
86584+++ b/net/ipv4/tcp_timer.c
86585@@ -22,6 +22,10 @@
86586 #include <linux/gfp.h>
86587 #include <net/tcp.h>
86588
86589+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86590+extern int grsec_lastack_retries;
86591+#endif
86592+
86593 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
86594 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
86595 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
86596@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
86597 }
86598 }
86599
86600+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86601+ if ((sk->sk_state == TCP_LAST_ACK) &&
86602+ (grsec_lastack_retries > 0) &&
86603+ (grsec_lastack_retries < retry_until))
86604+ retry_until = grsec_lastack_retries;
86605+#endif
86606+
86607 if (retransmits_timed_out(sk, retry_until,
86608 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
86609 /* Has it gone just too far? */
86610diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
86611index 1f4d405..3524677 100644
86612--- a/net/ipv4/udp.c
86613+++ b/net/ipv4/udp.c
86614@@ -87,6 +87,7 @@
86615 #include <linux/types.h>
86616 #include <linux/fcntl.h>
86617 #include <linux/module.h>
86618+#include <linux/security.h>
86619 #include <linux/socket.h>
86620 #include <linux/sockios.h>
86621 #include <linux/igmp.h>
86622@@ -111,6 +112,10 @@
86623 #include <trace/events/skb.h>
86624 #include "udp_impl.h"
86625
86626+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86627+extern int grsec_enable_blackhole;
86628+#endif
86629+
86630 struct udp_table udp_table __read_mostly;
86631 EXPORT_SYMBOL(udp_table);
86632
86633@@ -569,6 +574,9 @@ found:
86634 return s;
86635 }
86636
86637+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
86638+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
86639+
86640 /*
86641 * This routine is called by the ICMP module when it gets some
86642 * sort of error condition. If err < 0 then the socket should
86643@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
86644 dport = usin->sin_port;
86645 if (dport == 0)
86646 return -EINVAL;
86647+
86648+ err = gr_search_udp_sendmsg(sk, usin);
86649+ if (err)
86650+ return err;
86651 } else {
86652 if (sk->sk_state != TCP_ESTABLISHED)
86653 return -EDESTADDRREQ;
86654+
86655+ err = gr_search_udp_sendmsg(sk, NULL);
86656+ if (err)
86657+ return err;
86658+
86659 daddr = inet->inet_daddr;
86660 dport = inet->inet_dport;
86661 /* Open fast path for connected socket.
86662@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
86663 udp_lib_checksum_complete(skb)) {
86664 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
86665 IS_UDPLITE(sk));
86666- atomic_inc(&sk->sk_drops);
86667+ atomic_inc_unchecked(&sk->sk_drops);
86668 __skb_unlink(skb, rcvq);
86669 __skb_queue_tail(&list_kill, skb);
86670 }
86671@@ -1194,6 +1211,10 @@ try_again:
86672 if (!skb)
86673 goto out;
86674
86675+ err = gr_search_udp_recvmsg(sk, skb);
86676+ if (err)
86677+ goto out_free;
86678+
86679 ulen = skb->len - sizeof(struct udphdr);
86680 copied = len;
86681 if (copied > ulen)
86682@@ -1227,7 +1248,7 @@ try_again:
86683 if (unlikely(err)) {
86684 trace_kfree_skb(skb, udp_recvmsg);
86685 if (!peeked) {
86686- atomic_inc(&sk->sk_drops);
86687+ atomic_inc_unchecked(&sk->sk_drops);
86688 UDP_INC_STATS_USER(sock_net(sk),
86689 UDP_MIB_INERRORS, is_udplite);
86690 }
86691@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86692
86693 drop:
86694 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
86695- atomic_inc(&sk->sk_drops);
86696+ atomic_inc_unchecked(&sk->sk_drops);
86697 kfree_skb(skb);
86698 return -1;
86699 }
86700@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
86701 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
86702
86703 if (!skb1) {
86704- atomic_inc(&sk->sk_drops);
86705+ atomic_inc_unchecked(&sk->sk_drops);
86706 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
86707 IS_UDPLITE(sk));
86708 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
86709@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
86710 goto csum_error;
86711
86712 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
86713+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86714+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
86715+#endif
86716 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
86717
86718 /*
86719@@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
86720 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
86721 0, sock_i_ino(sp),
86722 atomic_read(&sp->sk_refcnt), sp,
86723- atomic_read(&sp->sk_drops), len);
86724+ atomic_read_unchecked(&sp->sk_drops), len);
86725 }
86726
86727 int udp4_seq_show(struct seq_file *seq, void *v)
86728diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
86729index 1b5d8cb..ffb0833 100644
86730--- a/net/ipv6/addrconf.c
86731+++ b/net/ipv6/addrconf.c
86732@@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
86733 p.iph.ihl = 5;
86734 p.iph.protocol = IPPROTO_IPV6;
86735 p.iph.ttl = 64;
86736- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
86737+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
86738
86739 if (ops->ndo_do_ioctl) {
86740 mm_segment_t oldfs = get_fs();
86741@@ -4388,7 +4388,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
86742 int *valp = ctl->data;
86743 int val = *valp;
86744 loff_t pos = *ppos;
86745- ctl_table lctl;
86746+ ctl_table_no_const lctl;
86747 int ret;
86748
86749 /*
86750@@ -4470,7 +4470,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
86751 int *valp = ctl->data;
86752 int val = *valp;
86753 loff_t pos = *ppos;
86754- ctl_table lctl;
86755+ ctl_table_no_const lctl;
86756 int ret;
86757
86758 /*
86759diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
86760index fff5bdd..15194fb 100644
86761--- a/net/ipv6/icmp.c
86762+++ b/net/ipv6/icmp.c
86763@@ -973,7 +973,7 @@ ctl_table ipv6_icmp_table_template[] = {
86764
86765 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
86766 {
86767- struct ctl_table *table;
86768+ ctl_table_no_const *table;
86769
86770 table = kmemdup(ipv6_icmp_table_template,
86771 sizeof(ipv6_icmp_table_template),
86772diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
86773index 131dd09..f7ed64f 100644
86774--- a/net/ipv6/ip6_gre.c
86775+++ b/net/ipv6/ip6_gre.c
86776@@ -73,7 +73,7 @@ struct ip6gre_net {
86777 struct net_device *fb_tunnel_dev;
86778 };
86779
86780-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
86781+static struct rtnl_link_ops ip6gre_link_ops;
86782 static int ip6gre_tunnel_init(struct net_device *dev);
86783 static void ip6gre_tunnel_setup(struct net_device *dev);
86784 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
86785@@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
86786 }
86787
86788
86789-static struct inet6_protocol ip6gre_protocol __read_mostly = {
86790+static struct inet6_protocol ip6gre_protocol = {
86791 .handler = ip6gre_rcv,
86792 .err_handler = ip6gre_err,
86793 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
86794@@ -1671,7 +1671,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
86795 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
86796 };
86797
86798-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
86799+static struct rtnl_link_ops ip6gre_link_ops = {
86800 .kind = "ip6gre",
86801 .maxtype = IFLA_GRE_MAX,
86802 .policy = ip6gre_policy,
86803@@ -1684,7 +1684,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
86804 .fill_info = ip6gre_fill_info,
86805 };
86806
86807-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
86808+static struct rtnl_link_ops ip6gre_tap_ops = {
86809 .kind = "ip6gretap",
86810 .maxtype = IFLA_GRE_MAX,
86811 .policy = ip6gre_policy,
86812diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
86813index a14f28b..b4b8956 100644
86814--- a/net/ipv6/ip6_tunnel.c
86815+++ b/net/ipv6/ip6_tunnel.c
86816@@ -87,7 +87,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
86817
86818 static int ip6_tnl_dev_init(struct net_device *dev);
86819 static void ip6_tnl_dev_setup(struct net_device *dev);
86820-static struct rtnl_link_ops ip6_link_ops __read_mostly;
86821+static struct rtnl_link_ops ip6_link_ops;
86822
86823 static int ip6_tnl_net_id __read_mostly;
86824 struct ip6_tnl_net {
86825@@ -1686,7 +1686,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
86826 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
86827 };
86828
86829-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
86830+static struct rtnl_link_ops ip6_link_ops = {
86831 .kind = "ip6tnl",
86832 .maxtype = IFLA_IPTUN_MAX,
86833 .policy = ip6_tnl_policy,
86834diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
86835index d1e2e8e..51c19ae 100644
86836--- a/net/ipv6/ipv6_sockglue.c
86837+++ b/net/ipv6/ipv6_sockglue.c
86838@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
86839 if (sk->sk_type != SOCK_STREAM)
86840 return -ENOPROTOOPT;
86841
86842- msg.msg_control = optval;
86843+ msg.msg_control = (void __force_kernel *)optval;
86844 msg.msg_controllen = len;
86845 msg.msg_flags = flags;
86846
86847diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
86848index 125a90d..2a11f36 100644
86849--- a/net/ipv6/netfilter/ip6_tables.c
86850+++ b/net/ipv6/netfilter/ip6_tables.c
86851@@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
86852 #endif
86853
86854 static int get_info(struct net *net, void __user *user,
86855- const int *len, int compat)
86856+ int len, int compat)
86857 {
86858 char name[XT_TABLE_MAXNAMELEN];
86859 struct xt_table *t;
86860 int ret;
86861
86862- if (*len != sizeof(struct ip6t_getinfo)) {
86863- duprintf("length %u != %zu\n", *len,
86864+ if (len != sizeof(struct ip6t_getinfo)) {
86865+ duprintf("length %u != %zu\n", len,
86866 sizeof(struct ip6t_getinfo));
86867 return -EINVAL;
86868 }
86869@@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
86870 info.size = private->size;
86871 strcpy(info.name, name);
86872
86873- if (copy_to_user(user, &info, *len) != 0)
86874+ if (copy_to_user(user, &info, len) != 0)
86875 ret = -EFAULT;
86876 else
86877 ret = 0;
86878@@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86879
86880 switch (cmd) {
86881 case IP6T_SO_GET_INFO:
86882- ret = get_info(sock_net(sk), user, len, 1);
86883+ ret = get_info(sock_net(sk), user, *len, 1);
86884 break;
86885 case IP6T_SO_GET_ENTRIES:
86886 ret = compat_get_entries(sock_net(sk), user, len);
86887@@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86888
86889 switch (cmd) {
86890 case IP6T_SO_GET_INFO:
86891- ret = get_info(sock_net(sk), user, len, 0);
86892+ ret = get_info(sock_net(sk), user, *len, 0);
86893 break;
86894
86895 case IP6T_SO_GET_ENTRIES:
86896diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
86897index 2f3a018..8bca195 100644
86898--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
86899+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
86900@@ -89,12 +89,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
86901
86902 static int nf_ct_frag6_sysctl_register(struct net *net)
86903 {
86904- struct ctl_table *table;
86905+ ctl_table_no_const *table = NULL;
86906 struct ctl_table_header *hdr;
86907
86908- table = nf_ct_frag6_sysctl_table;
86909 if (!net_eq(net, &init_net)) {
86910- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
86911+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
86912 GFP_KERNEL);
86913 if (table == NULL)
86914 goto err_alloc;
86915@@ -102,9 +101,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
86916 table[0].data = &net->ipv6.frags.high_thresh;
86917 table[1].data = &net->ipv6.frags.low_thresh;
86918 table[2].data = &net->ipv6.frags.timeout;
86919- }
86920-
86921- hdr = register_net_sysctl(net, "net/netfilter", table);
86922+ hdr = register_net_sysctl(net, "net/netfilter", table);
86923+ } else
86924+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
86925 if (hdr == NULL)
86926 goto err_reg;
86927
86928@@ -112,8 +111,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
86929 return 0;
86930
86931 err_reg:
86932- if (!net_eq(net, &init_net))
86933- kfree(table);
86934+ kfree(table);
86935 err_alloc:
86936 return -ENOMEM;
86937 }
86938diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
86939index 70fa814..d70c28c 100644
86940--- a/net/ipv6/raw.c
86941+++ b/net/ipv6/raw.c
86942@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
86943 {
86944 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
86945 skb_checksum_complete(skb)) {
86946- atomic_inc(&sk->sk_drops);
86947+ atomic_inc_unchecked(&sk->sk_drops);
86948 kfree_skb(skb);
86949 return NET_RX_DROP;
86950 }
86951@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
86952 struct raw6_sock *rp = raw6_sk(sk);
86953
86954 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
86955- atomic_inc(&sk->sk_drops);
86956+ atomic_inc_unchecked(&sk->sk_drops);
86957 kfree_skb(skb);
86958 return NET_RX_DROP;
86959 }
86960@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
86961
86962 if (inet->hdrincl) {
86963 if (skb_checksum_complete(skb)) {
86964- atomic_inc(&sk->sk_drops);
86965+ atomic_inc_unchecked(&sk->sk_drops);
86966 kfree_skb(skb);
86967 return NET_RX_DROP;
86968 }
86969@@ -604,7 +604,7 @@ out:
86970 return err;
86971 }
86972
86973-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
86974+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
86975 struct flowi6 *fl6, struct dst_entry **dstp,
86976 unsigned int flags)
86977 {
86978@@ -916,12 +916,15 @@ do_confirm:
86979 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
86980 char __user *optval, int optlen)
86981 {
86982+ struct icmp6_filter filter;
86983+
86984 switch (optname) {
86985 case ICMPV6_FILTER:
86986 if (optlen > sizeof(struct icmp6_filter))
86987 optlen = sizeof(struct icmp6_filter);
86988- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
86989+ if (copy_from_user(&filter, optval, optlen))
86990 return -EFAULT;
86991+ raw6_sk(sk)->filter = filter;
86992 return 0;
86993 default:
86994 return -ENOPROTOOPT;
86995@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
86996 char __user *optval, int __user *optlen)
86997 {
86998 int len;
86999+ struct icmp6_filter filter;
87000
87001 switch (optname) {
87002 case ICMPV6_FILTER:
87003@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
87004 len = sizeof(struct icmp6_filter);
87005 if (put_user(len, optlen))
87006 return -EFAULT;
87007- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
87008+ filter = raw6_sk(sk)->filter;
87009+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
87010 return -EFAULT;
87011 return 0;
87012 default:
87013@@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
87014 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
87015 0,
87016 sock_i_ino(sp),
87017- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
87018+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
87019 }
87020
87021 static int raw6_seq_show(struct seq_file *seq, void *v)
87022diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
87023index d9ba8a2..f3f9e14 100644
87024--- a/net/ipv6/reassembly.c
87025+++ b/net/ipv6/reassembly.c
87026@@ -608,12 +608,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
87027
87028 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
87029 {
87030- struct ctl_table *table;
87031+ ctl_table_no_const *table = NULL;
87032 struct ctl_table_header *hdr;
87033
87034- table = ip6_frags_ns_ctl_table;
87035 if (!net_eq(net, &init_net)) {
87036- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
87037+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
87038 if (table == NULL)
87039 goto err_alloc;
87040
87041@@ -624,9 +623,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
87042 /* Don't export sysctls to unprivileged users */
87043 if (net->user_ns != &init_user_ns)
87044 table[0].procname = NULL;
87045- }
87046+ hdr = register_net_sysctl(net, "net/ipv6", table);
87047+ } else
87048+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
87049
87050- hdr = register_net_sysctl(net, "net/ipv6", table);
87051 if (hdr == NULL)
87052 goto err_reg;
87053
87054@@ -634,8 +634,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
87055 return 0;
87056
87057 err_reg:
87058- if (!net_eq(net, &init_net))
87059- kfree(table);
87060+ kfree(table);
87061 err_alloc:
87062 return -ENOMEM;
87063 }
87064diff --git a/net/ipv6/route.c b/net/ipv6/route.c
87065index 5845613..3af8fc7 100644
87066--- a/net/ipv6/route.c
87067+++ b/net/ipv6/route.c
87068@@ -2966,7 +2966,7 @@ ctl_table ipv6_route_table_template[] = {
87069
87070 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
87071 {
87072- struct ctl_table *table;
87073+ ctl_table_no_const *table;
87074
87075 table = kmemdup(ipv6_route_table_template,
87076 sizeof(ipv6_route_table_template),
87077diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
87078index cfba99b..20ca511 100644
87079--- a/net/ipv6/sit.c
87080+++ b/net/ipv6/sit.c
87081@@ -72,7 +72,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
87082 static int ipip6_tunnel_init(struct net_device *dev);
87083 static void ipip6_tunnel_setup(struct net_device *dev);
87084 static void ipip6_dev_free(struct net_device *dev);
87085-static struct rtnl_link_ops sit_link_ops __read_mostly;
87086+static struct rtnl_link_ops sit_link_ops;
87087
87088 static int sit_net_id __read_mostly;
87089 struct sit_net {
87090@@ -1463,7 +1463,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
87091 #endif
87092 };
87093
87094-static struct rtnl_link_ops sit_link_ops __read_mostly = {
87095+static struct rtnl_link_ops sit_link_ops = {
87096 .kind = "sit",
87097 .maxtype = IFLA_IPTUN_MAX,
87098 .policy = ipip6_policy,
87099diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
87100index e85c48b..b8268d3 100644
87101--- a/net/ipv6/sysctl_net_ipv6.c
87102+++ b/net/ipv6/sysctl_net_ipv6.c
87103@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
87104
87105 static int __net_init ipv6_sysctl_net_init(struct net *net)
87106 {
87107- struct ctl_table *ipv6_table;
87108+ ctl_table_no_const *ipv6_table;
87109 struct ctl_table *ipv6_route_table;
87110 struct ctl_table *ipv6_icmp_table;
87111 int err;
87112diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
87113index 8d19346..e47216f 100644
87114--- a/net/ipv6/tcp_ipv6.c
87115+++ b/net/ipv6/tcp_ipv6.c
87116@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
87117 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
87118 }
87119
87120+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87121+extern int grsec_enable_blackhole;
87122+#endif
87123+
87124 static void tcp_v6_hash(struct sock *sk)
87125 {
87126 if (sk->sk_state != TCP_CLOSE) {
87127@@ -1440,6 +1444,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
87128 return 0;
87129
87130 reset:
87131+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87132+ if (!grsec_enable_blackhole)
87133+#endif
87134 tcp_v6_send_reset(sk, skb);
87135 discard:
87136 if (opt_skb)
87137@@ -1521,12 +1528,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
87138 TCP_SKB_CB(skb)->sacked = 0;
87139
87140 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
87141- if (!sk)
87142+ if (!sk) {
87143+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87144+ ret = 1;
87145+#endif
87146 goto no_tcp_socket;
87147+ }
87148
87149 process:
87150- if (sk->sk_state == TCP_TIME_WAIT)
87151+ if (sk->sk_state == TCP_TIME_WAIT) {
87152+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87153+ ret = 2;
87154+#endif
87155 goto do_time_wait;
87156+ }
87157
87158 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
87159 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
87160@@ -1575,6 +1590,10 @@ no_tcp_socket:
87161 bad_packet:
87162 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
87163 } else {
87164+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87165+ if (!grsec_enable_blackhole || (ret == 1 &&
87166+ (skb->dev->flags & IFF_LOOPBACK)))
87167+#endif
87168 tcp_v6_send_reset(NULL, skb);
87169 }
87170
87171diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
87172index fb08329..2d6919e 100644
87173--- a/net/ipv6/udp.c
87174+++ b/net/ipv6/udp.c
87175@@ -51,6 +51,10 @@
87176 #include <trace/events/skb.h>
87177 #include "udp_impl.h"
87178
87179+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87180+extern int grsec_enable_blackhole;
87181+#endif
87182+
87183 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
87184 {
87185 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
87186@@ -395,7 +399,7 @@ try_again:
87187 if (unlikely(err)) {
87188 trace_kfree_skb(skb, udpv6_recvmsg);
87189 if (!peeked) {
87190- atomic_inc(&sk->sk_drops);
87191+ atomic_inc_unchecked(&sk->sk_drops);
87192 if (is_udp4)
87193 UDP_INC_STATS_USER(sock_net(sk),
87194 UDP_MIB_INERRORS,
87195@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
87196 return rc;
87197 drop:
87198 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
87199- atomic_inc(&sk->sk_drops);
87200+ atomic_inc_unchecked(&sk->sk_drops);
87201 kfree_skb(skb);
87202 return -1;
87203 }
87204@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
87205 if (likely(skb1 == NULL))
87206 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
87207 if (!skb1) {
87208- atomic_inc(&sk->sk_drops);
87209+ atomic_inc_unchecked(&sk->sk_drops);
87210 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
87211 IS_UDPLITE(sk));
87212 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
87213@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
87214 goto discard;
87215
87216 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
87217+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87218+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
87219+#endif
87220 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
87221
87222 kfree_skb(skb);
87223@@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
87224 0,
87225 sock_i_ino(sp),
87226 atomic_read(&sp->sk_refcnt), sp,
87227- atomic_read(&sp->sk_drops));
87228+ atomic_read_unchecked(&sp->sk_drops));
87229 }
87230
87231 int udp6_seq_show(struct seq_file *seq, void *v)
87232diff --git a/net/irda/af_irda.c b/net/irda/af_irda.c
87233index b833677..4d04105 100644
87234--- a/net/irda/af_irda.c
87235+++ b/net/irda/af_irda.c
87236@@ -2584,8 +2584,10 @@ bed:
87237 NULL, NULL, NULL);
87238
87239 /* Check if the we got some results */
87240- if (!self->cachedaddr)
87241- return -EAGAIN; /* Didn't find any devices */
87242+ if (!self->cachedaddr) {
87243+ err = -EAGAIN; /* Didn't find any devices */
87244+ goto out;
87245+ }
87246 daddr = self->cachedaddr;
87247 /* Cleanup */
87248 self->cachedaddr = 0;
87249diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
87250index a68c88c..d55b0c5 100644
87251--- a/net/irda/ircomm/ircomm_tty.c
87252+++ b/net/irda/ircomm/ircomm_tty.c
87253@@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
87254 add_wait_queue(&port->open_wait, &wait);
87255
87256 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
87257- __FILE__, __LINE__, tty->driver->name, port->count);
87258+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
87259
87260 spin_lock_irqsave(&port->lock, flags);
87261 if (!tty_hung_up_p(filp)) {
87262 extra_count = 1;
87263- port->count--;
87264+ atomic_dec(&port->count);
87265 }
87266 spin_unlock_irqrestore(&port->lock, flags);
87267 port->blocked_open++;
87268@@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
87269 }
87270
87271 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
87272- __FILE__, __LINE__, tty->driver->name, port->count);
87273+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
87274
87275 schedule();
87276 }
87277@@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
87278 if (extra_count) {
87279 /* ++ is not atomic, so this should be protected - Jean II */
87280 spin_lock_irqsave(&port->lock, flags);
87281- port->count++;
87282+ atomic_inc(&port->count);
87283 spin_unlock_irqrestore(&port->lock, flags);
87284 }
87285 port->blocked_open--;
87286
87287 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
87288- __FILE__, __LINE__, tty->driver->name, port->count);
87289+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
87290
87291 if (!retval)
87292 port->flags |= ASYNC_NORMAL_ACTIVE;
87293@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
87294
87295 /* ++ is not atomic, so this should be protected - Jean II */
87296 spin_lock_irqsave(&self->port.lock, flags);
87297- self->port.count++;
87298+ atomic_inc(&self->port.count);
87299 spin_unlock_irqrestore(&self->port.lock, flags);
87300 tty_port_tty_set(&self->port, tty);
87301
87302 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
87303- self->line, self->port.count);
87304+ self->line, atomic_read(&self->port.count));
87305
87306 /* Not really used by us, but lets do it anyway */
87307 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
87308@@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
87309 tty_kref_put(port->tty);
87310 }
87311 port->tty = NULL;
87312- port->count = 0;
87313+ atomic_set(&port->count, 0);
87314 spin_unlock_irqrestore(&port->lock, flags);
87315
87316 wake_up_interruptible(&port->open_wait);
87317@@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
87318 seq_putc(m, '\n');
87319
87320 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
87321- seq_printf(m, "Open count: %d\n", self->port.count);
87322+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
87323 seq_printf(m, "Max data size: %d\n", self->max_data_size);
87324 seq_printf(m, "Max header size: %d\n", self->max_header_size);
87325
87326diff --git a/net/irda/iriap.c b/net/irda/iriap.c
87327index e71e85b..29340a9 100644
87328--- a/net/irda/iriap.c
87329+++ b/net/irda/iriap.c
87330@@ -495,8 +495,11 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
87331 /* case CS_ISO_8859_9: */
87332 /* case CS_UNICODE: */
87333 default:
87334- IRDA_DEBUG(0, "%s(), charset %s, not supported\n",
87335- __func__, ias_charset_types[charset]);
87336+ IRDA_DEBUG(0, "%s(), charset [%d] %s, not supported\n",
87337+ __func__, charset,
87338+ charset < ARRAY_SIZE(ias_charset_types) ?
87339+ ias_charset_types[charset] :
87340+ "(unknown)");
87341
87342 /* Aborting, close connection! */
87343 iriap_disconnect_request(self);
87344diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
87345index cd6f7a9..e63fe89 100644
87346--- a/net/iucv/af_iucv.c
87347+++ b/net/iucv/af_iucv.c
87348@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
87349
87350 write_lock_bh(&iucv_sk_list.lock);
87351
87352- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
87353+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
87354 while (__iucv_get_sock_by_name(name)) {
87355 sprintf(name, "%08x",
87356- atomic_inc_return(&iucv_sk_list.autobind_name));
87357+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
87358 }
87359
87360 write_unlock_bh(&iucv_sk_list.lock);
87361diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
87362index df08250..02021fe 100644
87363--- a/net/iucv/iucv.c
87364+++ b/net/iucv/iucv.c
87365@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
87366 return NOTIFY_OK;
87367 }
87368
87369-static struct notifier_block __refdata iucv_cpu_notifier = {
87370+static struct notifier_block iucv_cpu_notifier = {
87371 .notifier_call = iucv_cpu_notify,
87372 };
87373
87374diff --git a/net/key/af_key.c b/net/key/af_key.c
87375index 5b426a6..970032b 100644
87376--- a/net/key/af_key.c
87377+++ b/net/key/af_key.c
87378@@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
87379 static u32 get_acqseq(void)
87380 {
87381 u32 res;
87382- static atomic_t acqseq;
87383+ static atomic_unchecked_t acqseq;
87384
87385 do {
87386- res = atomic_inc_return(&acqseq);
87387+ res = atomic_inc_return_unchecked(&acqseq);
87388 } while (!res);
87389 return res;
87390 }
87391diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
87392index 0479c64..d031db6 100644
87393--- a/net/mac80211/cfg.c
87394+++ b/net/mac80211/cfg.c
87395@@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
87396 ret = ieee80211_vif_use_channel(sdata, chandef,
87397 IEEE80211_CHANCTX_EXCLUSIVE);
87398 }
87399- } else if (local->open_count == local->monitors) {
87400+ } else if (local_read(&local->open_count) == local->monitors) {
87401 local->_oper_channel = chandef->chan;
87402 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
87403 ieee80211_hw_config(local, 0);
87404@@ -2716,7 +2716,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
87405 else
87406 local->probe_req_reg--;
87407
87408- if (!local->open_count)
87409+ if (!local_read(&local->open_count))
87410 break;
87411
87412 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
87413diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
87414index 2ed065c..948177f 100644
87415--- a/net/mac80211/ieee80211_i.h
87416+++ b/net/mac80211/ieee80211_i.h
87417@@ -28,6 +28,7 @@
87418 #include <net/ieee80211_radiotap.h>
87419 #include <net/cfg80211.h>
87420 #include <net/mac80211.h>
87421+#include <asm/local.h>
87422 #include "key.h"
87423 #include "sta_info.h"
87424 #include "debug.h"
87425@@ -909,7 +910,7 @@ struct ieee80211_local {
87426 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
87427 spinlock_t queue_stop_reason_lock;
87428
87429- int open_count;
87430+ local_t open_count;
87431 int monitors, cooked_mntrs;
87432 /* number of interfaces with corresponding FIF_ flags */
87433 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
87434diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
87435index 8be854e..ad72a69 100644
87436--- a/net/mac80211/iface.c
87437+++ b/net/mac80211/iface.c
87438@@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87439 break;
87440 }
87441
87442- if (local->open_count == 0) {
87443+ if (local_read(&local->open_count) == 0) {
87444 res = drv_start(local);
87445 if (res)
87446 goto err_del_bss;
87447@@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87448 break;
87449 }
87450
87451- if (local->monitors == 0 && local->open_count == 0) {
87452+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
87453 res = ieee80211_add_virtual_monitor(local);
87454 if (res)
87455 goto err_stop;
87456@@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87457 mutex_unlock(&local->mtx);
87458
87459 if (coming_up)
87460- local->open_count++;
87461+ local_inc(&local->open_count);
87462
87463 if (hw_reconf_flags)
87464 ieee80211_hw_config(local, hw_reconf_flags);
87465@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87466 err_del_interface:
87467 drv_remove_interface(local, sdata);
87468 err_stop:
87469- if (!local->open_count)
87470+ if (!local_read(&local->open_count))
87471 drv_stop(local);
87472 err_del_bss:
87473 sdata->bss = NULL;
87474@@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
87475 }
87476
87477 if (going_down)
87478- local->open_count--;
87479+ local_dec(&local->open_count);
87480
87481 switch (sdata->vif.type) {
87482 case NL80211_IFTYPE_AP_VLAN:
87483@@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
87484
87485 ieee80211_recalc_ps(local, -1);
87486
87487- if (local->open_count == 0) {
87488+ if (local_read(&local->open_count) == 0) {
87489 if (local->ops->napi_poll)
87490 napi_disable(&local->napi);
87491 ieee80211_clear_tx_pending(local);
87492@@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
87493 }
87494 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
87495
87496- if (local->monitors == local->open_count && local->monitors > 0)
87497+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
87498 ieee80211_add_virtual_monitor(local);
87499 }
87500
87501diff --git a/net/mac80211/main.c b/net/mac80211/main.c
87502index 1b087ff..bf600e9 100644
87503--- a/net/mac80211/main.c
87504+++ b/net/mac80211/main.c
87505@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
87506 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
87507 IEEE80211_CONF_CHANGE_POWER);
87508
87509- if (changed && local->open_count) {
87510+ if (changed && local_read(&local->open_count)) {
87511 ret = drv_config(local, changed);
87512 /*
87513 * Goal:
87514diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
87515index 79a48f3..5e185c9 100644
87516--- a/net/mac80211/pm.c
87517+++ b/net/mac80211/pm.c
87518@@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
87519 struct sta_info *sta;
87520 struct ieee80211_chanctx *ctx;
87521
87522- if (!local->open_count)
87523+ if (!local_read(&local->open_count))
87524 goto suspend;
87525
87526 ieee80211_scan_cancel(local);
87527@@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
87528 cancel_work_sync(&local->dynamic_ps_enable_work);
87529 del_timer_sync(&local->dynamic_ps_timer);
87530
87531- local->wowlan = wowlan && local->open_count;
87532+ local->wowlan = wowlan && local_read(&local->open_count);
87533 if (local->wowlan) {
87534 int err = drv_suspend(local, wowlan);
87535 if (err < 0) {
87536@@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
87537 mutex_unlock(&local->chanctx_mtx);
87538
87539 /* stop hardware - this must stop RX */
87540- if (local->open_count)
87541+ if (local_read(&local->open_count))
87542 ieee80211_stop_device(local);
87543
87544 suspend:
87545diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
87546index dd88381..eef4dd6 100644
87547--- a/net/mac80211/rate.c
87548+++ b/net/mac80211/rate.c
87549@@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
87550
87551 ASSERT_RTNL();
87552
87553- if (local->open_count)
87554+ if (local_read(&local->open_count))
87555 return -EBUSY;
87556
87557 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
87558diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
87559index c97a065..ff61928 100644
87560--- a/net/mac80211/rc80211_pid_debugfs.c
87561+++ b/net/mac80211/rc80211_pid_debugfs.c
87562@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
87563
87564 spin_unlock_irqrestore(&events->lock, status);
87565
87566- if (copy_to_user(buf, pb, p))
87567+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
87568 return -EFAULT;
87569
87570 return p;
87571diff --git a/net/mac80211/util.c b/net/mac80211/util.c
87572index f11e8c5..08d0013 100644
87573--- a/net/mac80211/util.c
87574+++ b/net/mac80211/util.c
87575@@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
87576 }
87577 #endif
87578 /* everything else happens only if HW was up & running */
87579- if (!local->open_count)
87580+ if (!local_read(&local->open_count))
87581 goto wake_up;
87582
87583 /*
87584diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
87585index 49e96df..63a51c3 100644
87586--- a/net/netfilter/Kconfig
87587+++ b/net/netfilter/Kconfig
87588@@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
87589
87590 To compile it as a module, choose M here. If unsure, say N.
87591
87592+config NETFILTER_XT_MATCH_GRADM
87593+ tristate '"gradm" match support'
87594+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
87595+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
87596+ ---help---
87597+ The gradm match allows to match on grsecurity RBAC being enabled.
87598+ It is useful when iptables rules are applied early on bootup to
87599+ prevent connections to the machine (except from a trusted host)
87600+ while the RBAC system is disabled.
87601+
87602 config NETFILTER_XT_MATCH_HASHLIMIT
87603 tristate '"hashlimit" match support'
87604 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
87605diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
87606index 3259697..54d5393 100644
87607--- a/net/netfilter/Makefile
87608+++ b/net/netfilter/Makefile
87609@@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
87610 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
87611 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
87612 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
87613+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
87614 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
87615 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
87616 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
87617diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
87618index 6d6d8f2..a676749 100644
87619--- a/net/netfilter/ipset/ip_set_core.c
87620+++ b/net/netfilter/ipset/ip_set_core.c
87621@@ -1800,7 +1800,7 @@ done:
87622 return ret;
87623 }
87624
87625-static struct nf_sockopt_ops so_set __read_mostly = {
87626+static struct nf_sockopt_ops so_set = {
87627 .pf = PF_INET,
87628 .get_optmin = SO_IP_SET,
87629 .get_optmax = SO_IP_SET + 1,
87630diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
87631index 30e764a..c3b6a9d 100644
87632--- a/net/netfilter/ipvs/ip_vs_conn.c
87633+++ b/net/netfilter/ipvs/ip_vs_conn.c
87634@@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
87635 /* Increase the refcnt counter of the dest */
87636 atomic_inc(&dest->refcnt);
87637
87638- conn_flags = atomic_read(&dest->conn_flags);
87639+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
87640 if (cp->protocol != IPPROTO_UDP)
87641 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
87642 flags = cp->flags;
87643@@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
87644 atomic_set(&cp->refcnt, 1);
87645
87646 atomic_set(&cp->n_control, 0);
87647- atomic_set(&cp->in_pkts, 0);
87648+ atomic_set_unchecked(&cp->in_pkts, 0);
87649
87650 atomic_inc(&ipvs->conn_count);
87651 if (flags & IP_VS_CONN_F_NO_CPORT)
87652@@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
87653
87654 /* Don't drop the entry if its number of incoming packets is not
87655 located in [0, 8] */
87656- i = atomic_read(&cp->in_pkts);
87657+ i = atomic_read_unchecked(&cp->in_pkts);
87658 if (i > 8 || i < 0) return 0;
87659
87660 if (!todrop_rate[i]) return 0;
87661diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
87662index 47edf5a..235b07d 100644
87663--- a/net/netfilter/ipvs/ip_vs_core.c
87664+++ b/net/netfilter/ipvs/ip_vs_core.c
87665@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
87666 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
87667 /* do not touch skb anymore */
87668
87669- atomic_inc(&cp->in_pkts);
87670+ atomic_inc_unchecked(&cp->in_pkts);
87671 ip_vs_conn_put(cp);
87672 return ret;
87673 }
87674@@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
87675 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
87676 pkts = sysctl_sync_threshold(ipvs);
87677 else
87678- pkts = atomic_add_return(1, &cp->in_pkts);
87679+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
87680
87681 if (ipvs->sync_state & IP_VS_STATE_MASTER)
87682 ip_vs_sync_conn(net, cp, pkts);
87683diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
87684index ec664cb..7f34a77 100644
87685--- a/net/netfilter/ipvs/ip_vs_ctl.c
87686+++ b/net/netfilter/ipvs/ip_vs_ctl.c
87687@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
87688 ip_vs_rs_hash(ipvs, dest);
87689 write_unlock_bh(&ipvs->rs_lock);
87690 }
87691- atomic_set(&dest->conn_flags, conn_flags);
87692+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
87693
87694 /* bind the service */
87695 if (!dest->svc) {
87696@@ -1688,7 +1688,7 @@ proc_do_sync_ports(ctl_table *table, int write,
87697 * align with netns init in ip_vs_control_net_init()
87698 */
87699
87700-static struct ctl_table vs_vars[] = {
87701+static ctl_table_no_const vs_vars[] __read_only = {
87702 {
87703 .procname = "amemthresh",
87704 .maxlen = sizeof(int),
87705@@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
87706 " %-7s %-6d %-10d %-10d\n",
87707 &dest->addr.in6,
87708 ntohs(dest->port),
87709- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
87710+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
87711 atomic_read(&dest->weight),
87712 atomic_read(&dest->activeconns),
87713 atomic_read(&dest->inactconns));
87714@@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
87715 "%-7s %-6d %-10d %-10d\n",
87716 ntohl(dest->addr.ip),
87717 ntohs(dest->port),
87718- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
87719+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
87720 atomic_read(&dest->weight),
87721 atomic_read(&dest->activeconns),
87722 atomic_read(&dest->inactconns));
87723@@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
87724
87725 entry.addr = dest->addr.ip;
87726 entry.port = dest->port;
87727- entry.conn_flags = atomic_read(&dest->conn_flags);
87728+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
87729 entry.weight = atomic_read(&dest->weight);
87730 entry.u_threshold = dest->u_threshold;
87731 entry.l_threshold = dest->l_threshold;
87732@@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
87733 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
87734 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
87735 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
87736- (atomic_read(&dest->conn_flags) &
87737+ (atomic_read_unchecked(&dest->conn_flags) &
87738 IP_VS_CONN_F_FWD_MASK)) ||
87739 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
87740 atomic_read(&dest->weight)) ||
87741@@ -3688,7 +3688,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
87742 {
87743 int idx;
87744 struct netns_ipvs *ipvs = net_ipvs(net);
87745- struct ctl_table *tbl;
87746+ ctl_table_no_const *tbl;
87747
87748 atomic_set(&ipvs->dropentry, 0);
87749 spin_lock_init(&ipvs->dropentry_lock);
87750diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
87751index fdd89b9..bd96aa9 100644
87752--- a/net/netfilter/ipvs/ip_vs_lblc.c
87753+++ b/net/netfilter/ipvs/ip_vs_lblc.c
87754@@ -115,7 +115,7 @@ struct ip_vs_lblc_table {
87755 * IPVS LBLC sysctl table
87756 */
87757 #ifdef CONFIG_SYSCTL
87758-static ctl_table vs_vars_table[] = {
87759+static ctl_table_no_const vs_vars_table[] __read_only = {
87760 {
87761 .procname = "lblc_expiration",
87762 .data = NULL,
87763diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
87764index c03b6a3..8ce3681 100644
87765--- a/net/netfilter/ipvs/ip_vs_lblcr.c
87766+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
87767@@ -288,7 +288,7 @@ struct ip_vs_lblcr_table {
87768 * IPVS LBLCR sysctl table
87769 */
87770
87771-static ctl_table vs_vars_table[] = {
87772+static ctl_table_no_const vs_vars_table[] __read_only = {
87773 {
87774 .procname = "lblcr_expiration",
87775 .data = NULL,
87776diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
87777index 44fd10c..2a163b3 100644
87778--- a/net/netfilter/ipvs/ip_vs_sync.c
87779+++ b/net/netfilter/ipvs/ip_vs_sync.c
87780@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
87781 cp = cp->control;
87782 if (cp) {
87783 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
87784- pkts = atomic_add_return(1, &cp->in_pkts);
87785+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
87786 else
87787 pkts = sysctl_sync_threshold(ipvs);
87788 ip_vs_sync_conn(net, cp->control, pkts);
87789@@ -758,7 +758,7 @@ control:
87790 if (!cp)
87791 return;
87792 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
87793- pkts = atomic_add_return(1, &cp->in_pkts);
87794+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
87795 else
87796 pkts = sysctl_sync_threshold(ipvs);
87797 goto sloop;
87798@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
87799
87800 if (opt)
87801 memcpy(&cp->in_seq, opt, sizeof(*opt));
87802- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
87803+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
87804 cp->state = state;
87805 cp->old_state = cp->state;
87806 /*
87807diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
87808index ee6b7a9..f9a89f6 100644
87809--- a/net/netfilter/ipvs/ip_vs_xmit.c
87810+++ b/net/netfilter/ipvs/ip_vs_xmit.c
87811@@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
87812 else
87813 rc = NF_ACCEPT;
87814 /* do not touch skb anymore */
87815- atomic_inc(&cp->in_pkts);
87816+ atomic_inc_unchecked(&cp->in_pkts);
87817 goto out;
87818 }
87819
87820@@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
87821 else
87822 rc = NF_ACCEPT;
87823 /* do not touch skb anymore */
87824- atomic_inc(&cp->in_pkts);
87825+ atomic_inc_unchecked(&cp->in_pkts);
87826 goto out;
87827 }
87828
87829diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
87830index 7df424e..a527b02 100644
87831--- a/net/netfilter/nf_conntrack_acct.c
87832+++ b/net/netfilter/nf_conntrack_acct.c
87833@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
87834 #ifdef CONFIG_SYSCTL
87835 static int nf_conntrack_acct_init_sysctl(struct net *net)
87836 {
87837- struct ctl_table *table;
87838+ ctl_table_no_const *table;
87839
87840 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
87841 GFP_KERNEL);
87842diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
87843index e4a0c4f..c263f28 100644
87844--- a/net/netfilter/nf_conntrack_core.c
87845+++ b/net/netfilter/nf_conntrack_core.c
87846@@ -1529,6 +1529,10 @@ err_extend:
87847 #define DYING_NULLS_VAL ((1<<30)+1)
87848 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
87849
87850+#ifdef CONFIG_GRKERNSEC_HIDESYM
87851+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
87852+#endif
87853+
87854 static int nf_conntrack_init_net(struct net *net)
87855 {
87856 int ret;
87857@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
87858 goto err_stat;
87859 }
87860
87861+#ifdef CONFIG_GRKERNSEC_HIDESYM
87862+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
87863+#else
87864 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
87865+#endif
87866 if (!net->ct.slabname) {
87867 ret = -ENOMEM;
87868 goto err_slabname;
87869diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
87870index faa978f..1afb18f 100644
87871--- a/net/netfilter/nf_conntrack_ecache.c
87872+++ b/net/netfilter/nf_conntrack_ecache.c
87873@@ -186,7 +186,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
87874 #ifdef CONFIG_SYSCTL
87875 static int nf_conntrack_event_init_sysctl(struct net *net)
87876 {
87877- struct ctl_table *table;
87878+ ctl_table_no_const *table;
87879
87880 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
87881 GFP_KERNEL);
87882diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
87883index 884f2b3..d53b33a 100644
87884--- a/net/netfilter/nf_conntrack_helper.c
87885+++ b/net/netfilter/nf_conntrack_helper.c
87886@@ -55,7 +55,7 @@ static struct ctl_table helper_sysctl_table[] = {
87887
87888 static int nf_conntrack_helper_init_sysctl(struct net *net)
87889 {
87890- struct ctl_table *table;
87891+ ctl_table_no_const *table;
87892
87893 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
87894 GFP_KERNEL);
87895diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
87896index 51e928d..72a413a 100644
87897--- a/net/netfilter/nf_conntrack_proto.c
87898+++ b/net/netfilter/nf_conntrack_proto.c
87899@@ -51,7 +51,7 @@ nf_ct_register_sysctl(struct net *net,
87900
87901 static void
87902 nf_ct_unregister_sysctl(struct ctl_table_header **header,
87903- struct ctl_table **table,
87904+ ctl_table_no_const **table,
87905 unsigned int users)
87906 {
87907 if (users > 0)
87908diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
87909index e7185c6..4ad6c9c 100644
87910--- a/net/netfilter/nf_conntrack_standalone.c
87911+++ b/net/netfilter/nf_conntrack_standalone.c
87912@@ -470,7 +470,7 @@ static ctl_table nf_ct_netfilter_table[] = {
87913
87914 static int nf_conntrack_standalone_init_sysctl(struct net *net)
87915 {
87916- struct ctl_table *table;
87917+ ctl_table_no_const *table;
87918
87919 if (net_eq(net, &init_net)) {
87920 nf_ct_netfilter_header =
87921diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
87922index 7ea8026..bc9512d 100644
87923--- a/net/netfilter/nf_conntrack_timestamp.c
87924+++ b/net/netfilter/nf_conntrack_timestamp.c
87925@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
87926 #ifdef CONFIG_SYSCTL
87927 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
87928 {
87929- struct ctl_table *table;
87930+ ctl_table_no_const *table;
87931
87932 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
87933 GFP_KERNEL);
87934diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
87935index 9e31269..bc4c1b7 100644
87936--- a/net/netfilter/nf_log.c
87937+++ b/net/netfilter/nf_log.c
87938@@ -215,7 +215,7 @@ static const struct file_operations nflog_file_ops = {
87939
87940 #ifdef CONFIG_SYSCTL
87941 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
87942-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
87943+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
87944 static struct ctl_table_header *nf_log_dir_header;
87945
87946 static int nf_log_proc_dostring(ctl_table *table, int write,
87947@@ -246,14 +246,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
87948 rcu_assign_pointer(nf_loggers[tindex], logger);
87949 mutex_unlock(&nf_log_mutex);
87950 } else {
87951+ ctl_table_no_const nf_log_table = *table;
87952+
87953 mutex_lock(&nf_log_mutex);
87954 logger = rcu_dereference_protected(nf_loggers[tindex],
87955 lockdep_is_held(&nf_log_mutex));
87956 if (!logger)
87957- table->data = "NONE";
87958+ nf_log_table.data = "NONE";
87959 else
87960- table->data = logger->name;
87961- r = proc_dostring(table, write, buffer, lenp, ppos);
87962+ nf_log_table.data = logger->name;
87963+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
87964 mutex_unlock(&nf_log_mutex);
87965 }
87966
87967diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
87968index f042ae5..30ea486 100644
87969--- a/net/netfilter/nf_sockopt.c
87970+++ b/net/netfilter/nf_sockopt.c
87971@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
87972 }
87973 }
87974
87975- list_add(&reg->list, &nf_sockopts);
87976+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
87977 out:
87978 mutex_unlock(&nf_sockopt_mutex);
87979 return ret;
87980@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
87981 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
87982 {
87983 mutex_lock(&nf_sockopt_mutex);
87984- list_del(&reg->list);
87985+ pax_list_del((struct list_head *)&reg->list);
87986 mutex_unlock(&nf_sockopt_mutex);
87987 }
87988 EXPORT_SYMBOL(nf_unregister_sockopt);
87989diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
87990index 92fd8ec..3f6ea4b 100644
87991--- a/net/netfilter/nfnetlink_log.c
87992+++ b/net/netfilter/nfnetlink_log.c
87993@@ -72,7 +72,7 @@ struct nfulnl_instance {
87994 };
87995
87996 static DEFINE_SPINLOCK(instances_lock);
87997-static atomic_t global_seq;
87998+static atomic_unchecked_t global_seq;
87999
88000 #define INSTANCE_BUCKETS 16
88001 static struct hlist_head instance_table[INSTANCE_BUCKETS];
88002@@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
88003 /* global sequence number */
88004 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
88005 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
88006- htonl(atomic_inc_return(&global_seq))))
88007+ htonl(atomic_inc_return_unchecked(&global_seq))))
88008 goto nla_put_failure;
88009
88010 if (data_len) {
88011diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
88012new file mode 100644
88013index 0000000..c566332
88014--- /dev/null
88015+++ b/net/netfilter/xt_gradm.c
88016@@ -0,0 +1,51 @@
88017+/*
88018+ * gradm match for netfilter
88019