]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.8.0-201302262242.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.0-201302262242.patch
CommitLineData
e61f7527
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b89a739..dba90c5 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,11 @@ series
176 setup
177 setup.bin
178 setup.elf
179+size_overflow_hash.h
180 sImage
181+slabinfo
182 sm_tbl*
183+sortextable
184 split-include
185 syscalltab.h
186 tables.c
187@@ -224,6 +252,7 @@ tftpboot.img
188 timeconst.h
189 times.h*
190 trix_boot.h
191+user_constants.h
192 utsrelease.h*
193 vdso-syms.lds
194 vdso.lds
195@@ -235,13 +264,17 @@ vdso32.lds
196 vdso32.so.dbg
197 vdso64.lds
198 vdso64.so.dbg
199+vdsox32.lds
200+vdsox32-syms.lds
201 version.h*
202 vmImage
203 vmlinux
204 vmlinux-*
205 vmlinux.aout
206 vmlinux.bin.all
207+vmlinux.bin.bz2
208 vmlinux.lds
209+vmlinux.relocs
210 vmlinuz
211 voffset.h
212 vsyscall.lds
213@@ -249,9 +282,11 @@ vsyscall_32.lds
214 wanxlfw.inc
215 uImage
216 unifdef
217+utsrelease.h
218 wakeup.bin
219 wakeup.elf
220 wakeup.lds
221 zImage*
222 zconf.hash.c
223+zconf.lex.c
224 zoffset.h
225diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
226index 6c72381..2fe9ae4 100644
227--- a/Documentation/kernel-parameters.txt
228+++ b/Documentation/kernel-parameters.txt
229@@ -917,6 +917,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
230 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
231 Default: 1024
232
233+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
234+ ignore grsecurity's /proc restrictions
235+
236+
237 hashdist= [KNL,NUMA] Large hashes allocated during boot
238 are distributed across NUMA nodes. Defaults on
239 for 64-bit NUMA, off otherwise.
240@@ -2116,6 +2120,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
241 the specified number of seconds. This is to be used if
242 your oopses keep scrolling off the screen.
243
244+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
245+ virtualization environments that don't cope well with the
246+ expand down segment used by UDEREF on X86-32 or the frequent
247+ page table updates on X86-64.
248+
249+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
250+
251 pcbit= [HW,ISDN]
252
253 pcd. [PARIDE]
254diff --git a/Makefile b/Makefile
255index d69266c..e4f6593 100644
256--- a/Makefile
257+++ b/Makefile
258@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
259
260 HOSTCC = gcc
261 HOSTCXX = g++
262-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
263-HOSTCXXFLAGS = -O2
264+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
265+HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
266+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
267
268 # Decide whether to build built-in, modular, or both.
269 # Normally, just do built-in.
270@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
271 # Rules shared between *config targets and build targets
272
273 # Basic helpers built in scripts/
274-PHONY += scripts_basic
275-scripts_basic:
276+PHONY += scripts_basic gcc-plugins
277+scripts_basic: gcc-plugins
278 $(Q)$(MAKE) $(build)=scripts/basic
279 $(Q)rm -f .tmp_quiet_recordmcount
280
281@@ -575,6 +576,64 @@ else
282 KBUILD_CFLAGS += -O2
283 endif
284
285+ifndef DISABLE_PAX_PLUGINS
286+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
287+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
288+else
289+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
290+endif
291+ifneq ($(PLUGINCC),)
292+ifndef DISABLE_PAX_CONSTIFY_PLUGIN
293+ifndef CONFIG_UML
294+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
295+endif
296+endif
297+ifdef CONFIG_PAX_MEMORY_STACKLEAK
298+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
299+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
300+endif
301+ifdef CONFIG_KALLOCSTAT_PLUGIN
302+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
303+endif
304+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
305+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
306+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
307+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
308+endif
309+ifdef CONFIG_CHECKER_PLUGIN
310+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
311+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
312+endif
313+endif
314+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
315+ifdef CONFIG_PAX_SIZE_OVERFLOW
316+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
317+endif
318+ifdef CONFIG_PAX_LATENT_ENTROPY
319+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
320+endif
321+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
322+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
323+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
324+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
325+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
326+ifeq ($(KBUILD_EXTMOD),)
327+gcc-plugins:
328+ $(Q)$(MAKE) $(build)=tools/gcc
329+else
330+gcc-plugins: ;
331+endif
332+else
333+gcc-plugins:
334+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
335+ $(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.))
336+else
337+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
338+endif
339+ $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
340+endif
341+endif
342+
343 include $(srctree)/arch/$(SRCARCH)/Makefile
344
345 ifdef CONFIG_READABLE_ASM
346@@ -731,7 +790,7 @@ export mod_sign_cmd
347
348
349 ifeq ($(KBUILD_EXTMOD),)
350-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
351+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
352
353 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
354 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
355@@ -778,6 +837,8 @@ endif
356
357 # The actual objects are generated when descending,
358 # make sure no implicit rule kicks in
359+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
360+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
361 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
362
363 # Handle descending into subdirectories listed in $(vmlinux-dirs)
364@@ -787,7 +848,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
365 # Error messages still appears in the original language
366
367 PHONY += $(vmlinux-dirs)
368-$(vmlinux-dirs): prepare scripts
369+$(vmlinux-dirs): gcc-plugins prepare scripts
370 $(Q)$(MAKE) $(build)=$@
371
372 # Store (new) KERNELRELASE string in include/config/kernel.release
373@@ -831,6 +892,7 @@ prepare0: archprepare FORCE
374 $(Q)$(MAKE) $(build)=.
375
376 # All the preparing..
377+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
378 prepare: prepare0
379
380 # Generate some files
381@@ -938,6 +1000,8 @@ all: modules
382 # using awk while concatenating to the final file.
383
384 PHONY += modules
385+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
386+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
387 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
388 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
389 @$(kecho) ' Building modules, stage 2.';
390@@ -953,7 +1017,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
391
392 # Target to prepare building external modules
393 PHONY += modules_prepare
394-modules_prepare: prepare scripts
395+modules_prepare: gcc-plugins prepare scripts
396
397 # Target to install modules
398 PHONY += modules_install
399@@ -1019,7 +1083,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
400 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
401 signing_key.priv signing_key.x509 x509.genkey \
402 extra_certificates signing_key.x509.keyid \
403- signing_key.x509.signer
404+ signing_key.x509.signer tools/gcc/size_overflow_hash.h
405
406 # clean - Delete most, but leave enough to build external modules
407 #
408@@ -1059,6 +1123,7 @@ distclean: mrproper
409 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
410 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
411 -o -name '.*.rej' \
412+ -o -name '.*.rej' -o -name '*.so' \
413 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
414 -type f -print | xargs rm -f
415
416@@ -1219,6 +1284,8 @@ PHONY += $(module-dirs) modules
417 $(module-dirs): crmodverdir $(objtree)/Module.symvers
418 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
419
420+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
421+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
422 modules: $(module-dirs)
423 @$(kecho) ' Building modules, stage 2.';
424 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
425@@ -1355,17 +1422,21 @@ else
426 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
427 endif
428
429-%.s: %.c prepare scripts FORCE
430+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
431+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
432+%.s: %.c gcc-plugins prepare scripts FORCE
433 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
434 %.i: %.c prepare scripts FORCE
435 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
436-%.o: %.c prepare scripts FORCE
437+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
438+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
439+%.o: %.c gcc-plugins prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441 %.lst: %.c prepare scripts FORCE
442 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
443-%.s: %.S prepare scripts FORCE
444+%.s: %.S gcc-plugins prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446-%.o: %.S prepare scripts FORCE
447+%.o: %.S gcc-plugins prepare scripts FORCE
448 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
449 %.symtypes: %.c prepare scripts FORCE
450 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
451@@ -1375,11 +1446,15 @@ endif
452 $(cmd_crmodverdir)
453 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
454 $(build)=$(build-dir)
455-%/: prepare scripts FORCE
456+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
457+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
458+%/: gcc-plugins prepare scripts FORCE
459 $(cmd_crmodverdir)
460 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
461 $(build)=$(build-dir)
462-%.ko: prepare scripts FORCE
463+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
464+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
465+%.ko: gcc-plugins prepare scripts FORCE
466 $(cmd_crmodverdir)
467 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
468 $(build)=$(build-dir) $(@:.ko=.o)
469diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
470index c2cbe4f..f7264b4 100644
471--- a/arch/alpha/include/asm/atomic.h
472+++ b/arch/alpha/include/asm/atomic.h
473@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
474 #define atomic_dec(v) atomic_sub(1,(v))
475 #define atomic64_dec(v) atomic64_sub(1,(v))
476
477+#define atomic64_read_unchecked(v) atomic64_read(v)
478+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
479+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
480+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
481+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
482+#define atomic64_inc_unchecked(v) atomic64_inc(v)
483+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
484+#define atomic64_dec_unchecked(v) atomic64_dec(v)
485+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
486+
487 #define smp_mb__before_atomic_dec() smp_mb()
488 #define smp_mb__after_atomic_dec() smp_mb()
489 #define smp_mb__before_atomic_inc() smp_mb()
490diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
491index ad368a9..fbe0f25 100644
492--- a/arch/alpha/include/asm/cache.h
493+++ b/arch/alpha/include/asm/cache.h
494@@ -4,19 +4,19 @@
495 #ifndef __ARCH_ALPHA_CACHE_H
496 #define __ARCH_ALPHA_CACHE_H
497
498+#include <linux/const.h>
499
500 /* Bytes per L1 (data) cache line. */
501 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
502-# define L1_CACHE_BYTES 64
503 # define L1_CACHE_SHIFT 6
504 #else
505 /* Both EV4 and EV5 are write-through, read-allocate,
506 direct-mapped, physical.
507 */
508-# define L1_CACHE_BYTES 32
509 # define L1_CACHE_SHIFT 5
510 #endif
511
512+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
513 #define SMP_CACHE_BYTES L1_CACHE_BYTES
514
515 #endif
516diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
517index 968d999..d36b2df 100644
518--- a/arch/alpha/include/asm/elf.h
519+++ b/arch/alpha/include/asm/elf.h
520@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
521
522 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
523
524+#ifdef CONFIG_PAX_ASLR
525+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
526+
527+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
528+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
529+#endif
530+
531 /* $0 is set by ld.so to a pointer to a function which might be
532 registered using atexit. This provides a mean for the dynamic
533 linker to call DT_FINI functions for shared libraries that have
534diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
535index bc2a0da..8ad11ee 100644
536--- a/arch/alpha/include/asm/pgalloc.h
537+++ b/arch/alpha/include/asm/pgalloc.h
538@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539 pgd_set(pgd, pmd);
540 }
541
542+static inline void
543+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
544+{
545+ pgd_populate(mm, pgd, pmd);
546+}
547+
548 extern pgd_t *pgd_alloc(struct mm_struct *mm);
549
550 static inline void
551diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
552index 81a4342..348b927 100644
553--- a/arch/alpha/include/asm/pgtable.h
554+++ b/arch/alpha/include/asm/pgtable.h
555@@ -102,6 +102,17 @@ struct vm_area_struct;
556 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
557 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
558 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
559+
560+#ifdef CONFIG_PAX_PAGEEXEC
561+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
562+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
563+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
564+#else
565+# define PAGE_SHARED_NOEXEC PAGE_SHARED
566+# define PAGE_COPY_NOEXEC PAGE_COPY
567+# define PAGE_READONLY_NOEXEC PAGE_READONLY
568+#endif
569+
570 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
571
572 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
573diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
574index 2fd00b7..cfd5069 100644
575--- a/arch/alpha/kernel/module.c
576+++ b/arch/alpha/kernel/module.c
577@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
578
579 /* The small sections were sorted to the end of the segment.
580 The following should definitely cover them. */
581- gp = (u64)me->module_core + me->core_size - 0x8000;
582+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
583 got = sechdrs[me->arch.gotsecindex].sh_addr;
584
585 for (i = 0; i < n; i++) {
586diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
587index 14db93e..47bed62 100644
588--- a/arch/alpha/kernel/osf_sys.c
589+++ b/arch/alpha/kernel/osf_sys.c
590@@ -1295,16 +1295,16 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
591 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
592
593 static unsigned long
594-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
595- unsigned long limit)
596+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
597+ unsigned long limit, unsigned long flags)
598 {
599 struct vm_area_struct *vma = find_vma(current->mm, addr);
600-
601+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
602 while (1) {
603 /* At this point: (!vma || addr < vma->vm_end). */
604 if (limit - len < addr)
605 return -ENOMEM;
606- if (!vma || addr + len <= vma->vm_start)
607+ if (check_heap_stack_gap(vma, addr, len, offset))
608 return addr;
609 addr = vma->vm_end;
610 vma = vma->vm_next;
611@@ -1340,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
612 merely specific addresses, but regions of memory -- perhaps
613 this feature should be incorporated into all ports? */
614
615+#ifdef CONFIG_PAX_RANDMMAP
616+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
617+#endif
618+
619 if (addr) {
620- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
621+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
622 if (addr != (unsigned long) -ENOMEM)
623 return addr;
624 }
625
626 /* Next, try allocating at TASK_UNMAPPED_BASE. */
627- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
628- len, limit);
629+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
630+
631 if (addr != (unsigned long) -ENOMEM)
632 return addr;
633
634 /* Finally, try allocating in low memory. */
635- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
636+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
637
638 return addr;
639 }
640diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
641index 0c4132d..88f0d53 100644
642--- a/arch/alpha/mm/fault.c
643+++ b/arch/alpha/mm/fault.c
644@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
645 __reload_thread(pcb);
646 }
647
648+#ifdef CONFIG_PAX_PAGEEXEC
649+/*
650+ * PaX: decide what to do with offenders (regs->pc = fault address)
651+ *
652+ * returns 1 when task should be killed
653+ * 2 when patched PLT trampoline was detected
654+ * 3 when unpatched PLT trampoline was detected
655+ */
656+static int pax_handle_fetch_fault(struct pt_regs *regs)
657+{
658+
659+#ifdef CONFIG_PAX_EMUPLT
660+ int err;
661+
662+ do { /* PaX: patched PLT emulation #1 */
663+ unsigned int ldah, ldq, jmp;
664+
665+ err = get_user(ldah, (unsigned int *)regs->pc);
666+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
667+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
668+
669+ if (err)
670+ break;
671+
672+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
673+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
674+ jmp == 0x6BFB0000U)
675+ {
676+ unsigned long r27, addr;
677+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
678+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
679+
680+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
681+ err = get_user(r27, (unsigned long *)addr);
682+ if (err)
683+ break;
684+
685+ regs->r27 = r27;
686+ regs->pc = r27;
687+ return 2;
688+ }
689+ } while (0);
690+
691+ do { /* PaX: patched PLT emulation #2 */
692+ unsigned int ldah, lda, br;
693+
694+ err = get_user(ldah, (unsigned int *)regs->pc);
695+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
696+ err |= get_user(br, (unsigned int *)(regs->pc+8));
697+
698+ if (err)
699+ break;
700+
701+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
702+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
703+ (br & 0xFFE00000U) == 0xC3E00000U)
704+ {
705+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
706+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
707+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
708+
709+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
710+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
711+ return 2;
712+ }
713+ } while (0);
714+
715+ do { /* PaX: unpatched PLT emulation */
716+ unsigned int br;
717+
718+ err = get_user(br, (unsigned int *)regs->pc);
719+
720+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
721+ unsigned int br2, ldq, nop, jmp;
722+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
723+
724+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
725+ err = get_user(br2, (unsigned int *)addr);
726+ err |= get_user(ldq, (unsigned int *)(addr+4));
727+ err |= get_user(nop, (unsigned int *)(addr+8));
728+ err |= get_user(jmp, (unsigned int *)(addr+12));
729+ err |= get_user(resolver, (unsigned long *)(addr+16));
730+
731+ if (err)
732+ break;
733+
734+ if (br2 == 0xC3600000U &&
735+ ldq == 0xA77B000CU &&
736+ nop == 0x47FF041FU &&
737+ jmp == 0x6B7B0000U)
738+ {
739+ regs->r28 = regs->pc+4;
740+ regs->r27 = addr+16;
741+ regs->pc = resolver;
742+ return 3;
743+ }
744+ }
745+ } while (0);
746+#endif
747+
748+ return 1;
749+}
750+
751+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
752+{
753+ unsigned long i;
754+
755+ printk(KERN_ERR "PAX: bytes at PC: ");
756+ for (i = 0; i < 5; i++) {
757+ unsigned int c;
758+ if (get_user(c, (unsigned int *)pc+i))
759+ printk(KERN_CONT "???????? ");
760+ else
761+ printk(KERN_CONT "%08x ", c);
762+ }
763+ printk("\n");
764+}
765+#endif
766
767 /*
768 * This routine handles page faults. It determines the address,
769@@ -133,8 +251,29 @@ retry:
770 good_area:
771 si_code = SEGV_ACCERR;
772 if (cause < 0) {
773- if (!(vma->vm_flags & VM_EXEC))
774+ if (!(vma->vm_flags & VM_EXEC)) {
775+
776+#ifdef CONFIG_PAX_PAGEEXEC
777+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
778+ goto bad_area;
779+
780+ up_read(&mm->mmap_sem);
781+ switch (pax_handle_fetch_fault(regs)) {
782+
783+#ifdef CONFIG_PAX_EMUPLT
784+ case 2:
785+ case 3:
786+ return;
787+#endif
788+
789+ }
790+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
791+ do_group_exit(SIGKILL);
792+#else
793 goto bad_area;
794+#endif
795+
796+ }
797 } else if (!cause) {
798 /* Allow reads even for write-only mappings */
799 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
800diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
801index 67874b8..0e40765 100644
802--- a/arch/arm/Kconfig
803+++ b/arch/arm/Kconfig
804@@ -1813,7 +1813,7 @@ config ALIGNMENT_TRAP
805
806 config UACCESS_WITH_MEMCPY
807 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
808- depends on MMU
809+ depends on MMU && !PAX_MEMORY_UDEREF
810 default y if CPU_FEROCEON
811 help
812 Implement faster copy_to_user and clear_user methods for CPU
813diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
814index c79f61f..9ac0642 100644
815--- a/arch/arm/include/asm/atomic.h
816+++ b/arch/arm/include/asm/atomic.h
817@@ -17,17 +17,35 @@
818 #include <asm/barrier.h>
819 #include <asm/cmpxchg.h>
820
821+#ifdef CONFIG_GENERIC_ATOMIC64
822+#include <asm-generic/atomic64.h>
823+#endif
824+
825 #define ATOMIC_INIT(i) { (i) }
826
827 #ifdef __KERNEL__
828
829+#define _ASM_EXTABLE(from, to) \
830+" .pushsection __ex_table,\"a\"\n"\
831+" .align 3\n" \
832+" .long " #from ", " #to"\n" \
833+" .popsection"
834+
835 /*
836 * On ARM, ordinary assignment (str instruction) doesn't clear the local
837 * strex/ldrex monitor on some implementations. The reason we can use it for
838 * atomic_set() is the clrex or dummy strex done on every exception return.
839 */
840 #define atomic_read(v) (*(volatile int *)&(v)->counter)
841+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
842+{
843+ return v->counter;
844+}
845 #define atomic_set(v,i) (((v)->counter) = (i))
846+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
847+{
848+ v->counter = i;
849+}
850
851 #if __LINUX_ARM_ARCH__ >= 6
852
853@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
854 int result;
855
856 __asm__ __volatile__("@ atomic_add\n"
857+"1: ldrex %1, [%3]\n"
858+" adds %0, %1, %4\n"
859+
860+#ifdef CONFIG_PAX_REFCOUNT
861+" bvc 3f\n"
862+"2: bkpt 0xf103\n"
863+"3:\n"
864+#endif
865+
866+" strex %1, %0, [%3]\n"
867+" teq %1, #0\n"
868+" bne 1b"
869+
870+#ifdef CONFIG_PAX_REFCOUNT
871+"\n4:\n"
872+ _ASM_EXTABLE(2b, 4b)
873+#endif
874+
875+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
876+ : "r" (&v->counter), "Ir" (i)
877+ : "cc");
878+}
879+
880+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
881+{
882+ unsigned long tmp;
883+ int result;
884+
885+ __asm__ __volatile__("@ atomic_add_unchecked\n"
886 "1: ldrex %0, [%3]\n"
887 " add %0, %0, %4\n"
888 " strex %1, %0, [%3]\n"
889@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
890 smp_mb();
891
892 __asm__ __volatile__("@ atomic_add_return\n"
893+"1: ldrex %1, [%3]\n"
894+" adds %0, %1, %4\n"
895+
896+#ifdef CONFIG_PAX_REFCOUNT
897+" bvc 3f\n"
898+" mov %0, %1\n"
899+"2: bkpt 0xf103\n"
900+"3:\n"
901+#endif
902+
903+" strex %1, %0, [%3]\n"
904+" teq %1, #0\n"
905+" bne 1b"
906+
907+#ifdef CONFIG_PAX_REFCOUNT
908+"\n4:\n"
909+ _ASM_EXTABLE(2b, 4b)
910+#endif
911+
912+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
913+ : "r" (&v->counter), "Ir" (i)
914+ : "cc");
915+
916+ smp_mb();
917+
918+ return result;
919+}
920+
921+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
922+{
923+ unsigned long tmp;
924+ int result;
925+
926+ smp_mb();
927+
928+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
929 "1: ldrex %0, [%3]\n"
930 " add %0, %0, %4\n"
931 " strex %1, %0, [%3]\n"
932@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
933 int result;
934
935 __asm__ __volatile__("@ atomic_sub\n"
936+"1: ldrex %1, [%3]\n"
937+" subs %0, %1, %4\n"
938+
939+#ifdef CONFIG_PAX_REFCOUNT
940+" bvc 3f\n"
941+"2: bkpt 0xf103\n"
942+"3:\n"
943+#endif
944+
945+" strex %1, %0, [%3]\n"
946+" teq %1, #0\n"
947+" bne 1b"
948+
949+#ifdef CONFIG_PAX_REFCOUNT
950+"\n4:\n"
951+ _ASM_EXTABLE(2b, 4b)
952+#endif
953+
954+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
955+ : "r" (&v->counter), "Ir" (i)
956+ : "cc");
957+}
958+
959+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
960+{
961+ unsigned long tmp;
962+ int result;
963+
964+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
965 "1: ldrex %0, [%3]\n"
966 " sub %0, %0, %4\n"
967 " strex %1, %0, [%3]\n"
968@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
969 smp_mb();
970
971 __asm__ __volatile__("@ atomic_sub_return\n"
972-"1: ldrex %0, [%3]\n"
973-" sub %0, %0, %4\n"
974+"1: ldrex %1, [%3]\n"
975+" subs %0, %1, %4\n"
976+
977+#ifdef CONFIG_PAX_REFCOUNT
978+" bvc 3f\n"
979+" mov %0, %1\n"
980+"2: bkpt 0xf103\n"
981+"3:\n"
982+#endif
983+
984 " strex %1, %0, [%3]\n"
985 " teq %1, #0\n"
986 " bne 1b"
987+
988+#ifdef CONFIG_PAX_REFCOUNT
989+"\n4:\n"
990+ _ASM_EXTABLE(2b, 4b)
991+#endif
992+
993 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
994 : "r" (&v->counter), "Ir" (i)
995 : "cc");
996@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
997 return oldval;
998 }
999
1000+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1001+{
1002+ unsigned long oldval, res;
1003+
1004+ smp_mb();
1005+
1006+ do {
1007+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1008+ "ldrex %1, [%3]\n"
1009+ "mov %0, #0\n"
1010+ "teq %1, %4\n"
1011+ "strexeq %0, %5, [%3]\n"
1012+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1013+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1014+ : "cc");
1015+ } while (res);
1016+
1017+ smp_mb();
1018+
1019+ return oldval;
1020+}
1021+
1022 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1023 {
1024 unsigned long tmp, tmp2;
1025@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1026
1027 return val;
1028 }
1029+
1030+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1031+{
1032+ return atomic_add_return(i, v);
1033+}
1034+
1035 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1036+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1037+{
1038+ (void) atomic_add_return(i, v);
1039+}
1040
1041 static inline int atomic_sub_return(int i, atomic_t *v)
1042 {
1043@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1044 return val;
1045 }
1046 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1047+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1048+{
1049+ (void) atomic_sub_return(i, v);
1050+}
1051
1052 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1053 {
1054@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1055 return ret;
1056 }
1057
1058+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1059+{
1060+ return atomic_cmpxchg(v, old, new);
1061+}
1062+
1063 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1064 {
1065 unsigned long flags;
1066@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1067 #endif /* __LINUX_ARM_ARCH__ */
1068
1069 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1070+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1071+{
1072+ return xchg(&v->counter, new);
1073+}
1074
1075 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1076 {
1077@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1078 }
1079
1080 #define atomic_inc(v) atomic_add(1, v)
1081+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1082+{
1083+ atomic_add_unchecked(1, v);
1084+}
1085 #define atomic_dec(v) atomic_sub(1, v)
1086+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1087+{
1088+ atomic_sub_unchecked(1, v);
1089+}
1090
1091 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1092+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1093+{
1094+ return atomic_add_return_unchecked(1, v) == 0;
1095+}
1096 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1097 #define atomic_inc_return(v) (atomic_add_return(1, v))
1098+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1099+{
1100+ return atomic_add_return_unchecked(1, v);
1101+}
1102 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1103 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1104
1105@@ -241,6 +428,14 @@ typedef struct {
1106 u64 __aligned(8) counter;
1107 } atomic64_t;
1108
1109+#ifdef CONFIG_PAX_REFCOUNT
1110+typedef struct {
1111+ u64 __aligned(8) counter;
1112+} atomic64_unchecked_t;
1113+#else
1114+typedef atomic64_t atomic64_unchecked_t;
1115+#endif
1116+
1117 #define ATOMIC64_INIT(i) { (i) }
1118
1119 static inline u64 atomic64_read(const atomic64_t *v)
1120@@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1121 return result;
1122 }
1123
1124+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1125+{
1126+ u64 result;
1127+
1128+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1129+" ldrexd %0, %H0, [%1]"
1130+ : "=&r" (result)
1131+ : "r" (&v->counter), "Qo" (v->counter)
1132+ );
1133+
1134+ return result;
1135+}
1136+
1137 static inline void atomic64_set(atomic64_t *v, u64 i)
1138 {
1139 u64 tmp;
1140@@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1141 : "cc");
1142 }
1143
1144+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1145+{
1146+ u64 tmp;
1147+
1148+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1149+"1: ldrexd %0, %H0, [%2]\n"
1150+" strexd %0, %3, %H3, [%2]\n"
1151+" teq %0, #0\n"
1152+" bne 1b"
1153+ : "=&r" (tmp), "=Qo" (v->counter)
1154+ : "r" (&v->counter), "r" (i)
1155+ : "cc");
1156+}
1157+
1158 static inline void atomic64_add(u64 i, atomic64_t *v)
1159 {
1160 u64 result;
1161@@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1162 __asm__ __volatile__("@ atomic64_add\n"
1163 "1: ldrexd %0, %H0, [%3]\n"
1164 " adds %0, %0, %4\n"
1165+" adcs %H0, %H0, %H4\n"
1166+
1167+#ifdef CONFIG_PAX_REFCOUNT
1168+" bvc 3f\n"
1169+"2: bkpt 0xf103\n"
1170+"3:\n"
1171+#endif
1172+
1173+" strexd %1, %0, %H0, [%3]\n"
1174+" teq %1, #0\n"
1175+" bne 1b"
1176+
1177+#ifdef CONFIG_PAX_REFCOUNT
1178+"\n4:\n"
1179+ _ASM_EXTABLE(2b, 4b)
1180+#endif
1181+
1182+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1183+ : "r" (&v->counter), "r" (i)
1184+ : "cc");
1185+}
1186+
1187+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1188+{
1189+ u64 result;
1190+ unsigned long tmp;
1191+
1192+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1193+"1: ldrexd %0, %H0, [%3]\n"
1194+" adds %0, %0, %4\n"
1195 " adc %H0, %H0, %H4\n"
1196 " strexd %1, %0, %H0, [%3]\n"
1197 " teq %1, #0\n"
1198@@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1199
1200 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1201 {
1202- u64 result;
1203- unsigned long tmp;
1204+ u64 result, tmp;
1205
1206 smp_mb();
1207
1208 __asm__ __volatile__("@ atomic64_add_return\n"
1209+"1: ldrexd %1, %H1, [%3]\n"
1210+" adds %0, %1, %4\n"
1211+" adcs %H0, %H1, %H4\n"
1212+
1213+#ifdef CONFIG_PAX_REFCOUNT
1214+" bvc 3f\n"
1215+" mov %0, %1\n"
1216+" mov %H0, %H1\n"
1217+"2: bkpt 0xf103\n"
1218+"3:\n"
1219+#endif
1220+
1221+" strexd %1, %0, %H0, [%3]\n"
1222+" teq %1, #0\n"
1223+" bne 1b"
1224+
1225+#ifdef CONFIG_PAX_REFCOUNT
1226+"\n4:\n"
1227+ _ASM_EXTABLE(2b, 4b)
1228+#endif
1229+
1230+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1231+ : "r" (&v->counter), "r" (i)
1232+ : "cc");
1233+
1234+ smp_mb();
1235+
1236+ return result;
1237+}
1238+
1239+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1240+{
1241+ u64 result;
1242+ unsigned long tmp;
1243+
1244+ smp_mb();
1245+
1246+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1247 "1: ldrexd %0, %H0, [%3]\n"
1248 " adds %0, %0, %4\n"
1249 " adc %H0, %H0, %H4\n"
1250@@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1251 __asm__ __volatile__("@ atomic64_sub\n"
1252 "1: ldrexd %0, %H0, [%3]\n"
1253 " subs %0, %0, %4\n"
1254+" sbcs %H0, %H0, %H4\n"
1255+
1256+#ifdef CONFIG_PAX_REFCOUNT
1257+" bvc 3f\n"
1258+"2: bkpt 0xf103\n"
1259+"3:\n"
1260+#endif
1261+
1262+" strexd %1, %0, %H0, [%3]\n"
1263+" teq %1, #0\n"
1264+" bne 1b"
1265+
1266+#ifdef CONFIG_PAX_REFCOUNT
1267+"\n4:\n"
1268+ _ASM_EXTABLE(2b, 4b)
1269+#endif
1270+
1271+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1272+ : "r" (&v->counter), "r" (i)
1273+ : "cc");
1274+}
1275+
1276+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1277+{
1278+ u64 result;
1279+ unsigned long tmp;
1280+
1281+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1282+"1: ldrexd %0, %H0, [%3]\n"
1283+" subs %0, %0, %4\n"
1284 " sbc %H0, %H0, %H4\n"
1285 " strexd %1, %0, %H0, [%3]\n"
1286 " teq %1, #0\n"
1287@@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1288
1289 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1290 {
1291- u64 result;
1292- unsigned long tmp;
1293+ u64 result, tmp;
1294
1295 smp_mb();
1296
1297 __asm__ __volatile__("@ atomic64_sub_return\n"
1298-"1: ldrexd %0, %H0, [%3]\n"
1299-" subs %0, %0, %4\n"
1300-" sbc %H0, %H0, %H4\n"
1301+"1: ldrexd %1, %H1, [%3]\n"
1302+" subs %0, %1, %4\n"
1303+" sbcs %H0, %H1, %H4\n"
1304+
1305+#ifdef CONFIG_PAX_REFCOUNT
1306+" bvc 3f\n"
1307+" mov %0, %1\n"
1308+" mov %H0, %H1\n"
1309+"2: bkpt 0xf103\n"
1310+"3:\n"
1311+#endif
1312+
1313 " strexd %1, %0, %H0, [%3]\n"
1314 " teq %1, #0\n"
1315 " bne 1b"
1316+
1317+#ifdef CONFIG_PAX_REFCOUNT
1318+"\n4:\n"
1319+ _ASM_EXTABLE(2b, 4b)
1320+#endif
1321+
1322 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1323 : "r" (&v->counter), "r" (i)
1324 : "cc");
1325@@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1326 return oldval;
1327 }
1328
1329+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1330+{
1331+ u64 oldval;
1332+ unsigned long res;
1333+
1334+ smp_mb();
1335+
1336+ do {
1337+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1338+ "ldrexd %1, %H1, [%3]\n"
1339+ "mov %0, #0\n"
1340+ "teq %1, %4\n"
1341+ "teqeq %H1, %H4\n"
1342+ "strexdeq %0, %5, %H5, [%3]"
1343+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1344+ : "r" (&ptr->counter), "r" (old), "r" (new)
1345+ : "cc");
1346+ } while (res);
1347+
1348+ smp_mb();
1349+
1350+ return oldval;
1351+}
1352+
1353 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1354 {
1355 u64 result;
1356@@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1357
1358 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1359 {
1360- u64 result;
1361- unsigned long tmp;
1362+ u64 result, tmp;
1363
1364 smp_mb();
1365
1366 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1367-"1: ldrexd %0, %H0, [%3]\n"
1368-" subs %0, %0, #1\n"
1369-" sbc %H0, %H0, #0\n"
1370+"1: ldrexd %1, %H1, [%3]\n"
1371+" subs %0, %1, #1\n"
1372+" sbcs %H0, %H1, #0\n"
1373+
1374+#ifdef CONFIG_PAX_REFCOUNT
1375+" bvc 3f\n"
1376+" mov %0, %1\n"
1377+" mov %H0, %H1\n"
1378+"2: bkpt 0xf103\n"
1379+"3:\n"
1380+#endif
1381+
1382 " teq %H0, #0\n"
1383-" bmi 2f\n"
1384+" bmi 4f\n"
1385 " strexd %1, %0, %H0, [%3]\n"
1386 " teq %1, #0\n"
1387 " bne 1b\n"
1388-"2:"
1389+"4:\n"
1390+
1391+#ifdef CONFIG_PAX_REFCOUNT
1392+ _ASM_EXTABLE(2b, 4b)
1393+#endif
1394+
1395 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1396 : "r" (&v->counter)
1397 : "cc");
1398@@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1399 " teq %0, %5\n"
1400 " teqeq %H0, %H5\n"
1401 " moveq %1, #0\n"
1402-" beq 2f\n"
1403+" beq 4f\n"
1404 " adds %0, %0, %6\n"
1405-" adc %H0, %H0, %H6\n"
1406+" adcs %H0, %H0, %H6\n"
1407+
1408+#ifdef CONFIG_PAX_REFCOUNT
1409+" bvc 3f\n"
1410+"2: bkpt 0xf103\n"
1411+"3:\n"
1412+#endif
1413+
1414 " strexd %2, %0, %H0, [%4]\n"
1415 " teq %2, #0\n"
1416 " bne 1b\n"
1417-"2:"
1418+"4:\n"
1419+
1420+#ifdef CONFIG_PAX_REFCOUNT
1421+ _ASM_EXTABLE(2b, 4b)
1422+#endif
1423+
1424 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1425 : "r" (&v->counter), "r" (u), "r" (a)
1426 : "cc");
1427@@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1428
1429 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1430 #define atomic64_inc(v) atomic64_add(1LL, (v))
1431+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1432 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1433+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1434 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1435 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1436 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1437+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1438 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1439 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1440 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1441diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1442index 75fe66b..ba3dee4 100644
1443--- a/arch/arm/include/asm/cache.h
1444+++ b/arch/arm/include/asm/cache.h
1445@@ -4,8 +4,10 @@
1446 #ifndef __ASMARM_CACHE_H
1447 #define __ASMARM_CACHE_H
1448
1449+#include <linux/const.h>
1450+
1451 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1452-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1453+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1454
1455 /*
1456 * Memory returned by kmalloc() may be used for DMA, so we must make
1457@@ -24,5 +26,6 @@
1458 #endif
1459
1460 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1461+#define __read_only __attribute__ ((__section__(".data..read_only")))
1462
1463 #endif
1464diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1465index e1489c5..d418304 100644
1466--- a/arch/arm/include/asm/cacheflush.h
1467+++ b/arch/arm/include/asm/cacheflush.h
1468@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1469 void (*dma_unmap_area)(const void *, size_t, int);
1470
1471 void (*dma_flush_range)(const void *, const void *);
1472-};
1473+} __no_const;
1474
1475 /*
1476 * Select the calling method
1477diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1478index 6dcc164..b14d917 100644
1479--- a/arch/arm/include/asm/checksum.h
1480+++ b/arch/arm/include/asm/checksum.h
1481@@ -37,7 +37,19 @@ __wsum
1482 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1483
1484 __wsum
1485-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1486+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1487+
1488+static inline __wsum
1489+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1490+{
1491+ __wsum ret;
1492+ pax_open_userland();
1493+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1494+ pax_close_userland();
1495+ return ret;
1496+}
1497+
1498+
1499
1500 /*
1501 * Fold a partial checksum without adding pseudo headers
1502diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1503index 7eb18c1..e38b6d2 100644
1504--- a/arch/arm/include/asm/cmpxchg.h
1505+++ b/arch/arm/include/asm/cmpxchg.h
1506@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1507
1508 #define xchg(ptr,x) \
1509 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1510+#define xchg_unchecked(ptr,x) \
1511+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1512
1513 #include <asm-generic/cmpxchg-local.h>
1514
1515diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1516index ab98fdd..6b19938 100644
1517--- a/arch/arm/include/asm/delay.h
1518+++ b/arch/arm/include/asm/delay.h
1519@@ -24,9 +24,9 @@ extern struct arm_delay_ops {
1520 void (*delay)(unsigned long);
1521 void (*const_udelay)(unsigned long);
1522 void (*udelay)(unsigned long);
1523-} arm_delay_ops;
1524+} *arm_delay_ops;
1525
1526-#define __delay(n) arm_delay_ops.delay(n)
1527+#define __delay(n) arm_delay_ops->delay(n)
1528
1529 /*
1530 * This function intentionally does not exist; if you see references to
1531@@ -47,8 +47,8 @@ extern void __bad_udelay(void);
1532 * first constant multiplications gets optimized away if the delay is
1533 * a constant)
1534 */
1535-#define __udelay(n) arm_delay_ops.udelay(n)
1536-#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1537+#define __udelay(n) arm_delay_ops->udelay(n)
1538+#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1539
1540 #define udelay(n) \
1541 (__builtin_constant_p(n) ? \
1542diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1543index 6ddbe44..758b5f2 100644
1544--- a/arch/arm/include/asm/domain.h
1545+++ b/arch/arm/include/asm/domain.h
1546@@ -48,18 +48,37 @@
1547 * Domain types
1548 */
1549 #define DOMAIN_NOACCESS 0
1550-#define DOMAIN_CLIENT 1
1551 #ifdef CONFIG_CPU_USE_DOMAINS
1552+#define DOMAIN_USERCLIENT 1
1553+#define DOMAIN_KERNELCLIENT 1
1554 #define DOMAIN_MANAGER 3
1555+#define DOMAIN_VECTORS DOMAIN_USER
1556 #else
1557+
1558+#ifdef CONFIG_PAX_KERNEXEC
1559 #define DOMAIN_MANAGER 1
1560+#define DOMAIN_KERNEXEC 3
1561+#else
1562+#define DOMAIN_MANAGER 1
1563+#endif
1564+
1565+#ifdef CONFIG_PAX_MEMORY_UDEREF
1566+#define DOMAIN_USERCLIENT 0
1567+#define DOMAIN_UDEREF 1
1568+#define DOMAIN_VECTORS DOMAIN_KERNEL
1569+#else
1570+#define DOMAIN_USERCLIENT 1
1571+#define DOMAIN_VECTORS DOMAIN_USER
1572+#endif
1573+#define DOMAIN_KERNELCLIENT 1
1574+
1575 #endif
1576
1577 #define domain_val(dom,type) ((type) << (2*(dom)))
1578
1579 #ifndef __ASSEMBLY__
1580
1581-#ifdef CONFIG_CPU_USE_DOMAINS
1582+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1583 static inline void set_domain(unsigned val)
1584 {
1585 asm volatile(
1586@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1587 isb();
1588 }
1589
1590-#define modify_domain(dom,type) \
1591- do { \
1592- struct thread_info *thread = current_thread_info(); \
1593- unsigned int domain = thread->cpu_domain; \
1594- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1595- thread->cpu_domain = domain | domain_val(dom, type); \
1596- set_domain(thread->cpu_domain); \
1597- } while (0)
1598-
1599+extern void modify_domain(unsigned int dom, unsigned int type);
1600 #else
1601 static inline void set_domain(unsigned val) { }
1602 static inline void modify_domain(unsigned dom, unsigned type) { }
1603diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1604index 38050b1..9d90e8b 100644
1605--- a/arch/arm/include/asm/elf.h
1606+++ b/arch/arm/include/asm/elf.h
1607@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1608 the loader. We need to make sure that it is out of the way of the program
1609 that it will "exec", and that there is sufficient room for the brk. */
1610
1611-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1612+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1613+
1614+#ifdef CONFIG_PAX_ASLR
1615+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1616+
1617+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1618+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1619+#endif
1620
1621 /* When the program starts, a1 contains a pointer to a function to be
1622 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1623@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1624 extern void elf_set_personality(const struct elf32_hdr *);
1625 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1626
1627-struct mm_struct;
1628-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1629-#define arch_randomize_brk arch_randomize_brk
1630-
1631 #endif
1632diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1633index de53547..52b9a28 100644
1634--- a/arch/arm/include/asm/fncpy.h
1635+++ b/arch/arm/include/asm/fncpy.h
1636@@ -81,7 +81,9 @@
1637 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1638 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1639 \
1640+ pax_open_kernel(); \
1641 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1642+ pax_close_kernel(); \
1643 flush_icache_range((unsigned long)(dest_buf), \
1644 (unsigned long)(dest_buf) + (size)); \
1645 \
1646diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1647index e42cf59..7b94b8f 100644
1648--- a/arch/arm/include/asm/futex.h
1649+++ b/arch/arm/include/asm/futex.h
1650@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1651 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1652 return -EFAULT;
1653
1654+ pax_open_userland();
1655+
1656 smp_mb();
1657 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1658 "1: ldrex %1, [%4]\n"
1659@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1660 : "cc", "memory");
1661 smp_mb();
1662
1663+ pax_close_userland();
1664+
1665 *uval = val;
1666 return ret;
1667 }
1668@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1669 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1670 return -EFAULT;
1671
1672+ pax_open_userland();
1673+
1674 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1675 "1: " TUSER(ldr) " %1, [%4]\n"
1676 " teq %1, %2\n"
1677@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1678 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1679 : "cc", "memory");
1680
1681+ pax_close_userland();
1682+
1683 *uval = val;
1684 return ret;
1685 }
1686@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1687 return -EFAULT;
1688
1689 pagefault_disable(); /* implies preempt_disable() */
1690+ pax_open_userland();
1691
1692 switch (op) {
1693 case FUTEX_OP_SET:
1694@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1695 ret = -ENOSYS;
1696 }
1697
1698+ pax_close_userland();
1699 pagefault_enable(); /* subsumes preempt_enable() */
1700
1701 if (!ret) {
1702diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1703index 83eb2f7..ed77159 100644
1704--- a/arch/arm/include/asm/kmap_types.h
1705+++ b/arch/arm/include/asm/kmap_types.h
1706@@ -4,6 +4,6 @@
1707 /*
1708 * This is the "bare minimum". AIO seems to require this.
1709 */
1710-#define KM_TYPE_NR 16
1711+#define KM_TYPE_NR 17
1712
1713 #endif
1714diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1715index 9e614a1..3302cca 100644
1716--- a/arch/arm/include/asm/mach/dma.h
1717+++ b/arch/arm/include/asm/mach/dma.h
1718@@ -22,7 +22,7 @@ struct dma_ops {
1719 int (*residue)(unsigned int, dma_t *); /* optional */
1720 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1721 const char *type;
1722-};
1723+} __do_const;
1724
1725 struct dma_struct {
1726 void *addr; /* single DMA address */
1727diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1728index 2fe141f..192dc01 100644
1729--- a/arch/arm/include/asm/mach/map.h
1730+++ b/arch/arm/include/asm/mach/map.h
1731@@ -27,13 +27,16 @@ struct map_desc {
1732 #define MT_MINICLEAN 6
1733 #define MT_LOW_VECTORS 7
1734 #define MT_HIGH_VECTORS 8
1735-#define MT_MEMORY 9
1736+#define MT_MEMORY_RWX 9
1737 #define MT_ROM 10
1738-#define MT_MEMORY_NONCACHED 11
1739+#define MT_MEMORY_NONCACHED_RX 11
1740 #define MT_MEMORY_DTCM 12
1741 #define MT_MEMORY_ITCM 13
1742 #define MT_MEMORY_SO 14
1743 #define MT_MEMORY_DMA_READY 15
1744+#define MT_MEMORY_RW 16
1745+#define MT_MEMORY_RX 17
1746+#define MT_MEMORY_NONCACHED_RW 18
1747
1748 #ifdef CONFIG_MMU
1749 extern void iotable_init(struct map_desc *, int);
1750diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1751index 53426c6..c7baff3 100644
1752--- a/arch/arm/include/asm/outercache.h
1753+++ b/arch/arm/include/asm/outercache.h
1754@@ -35,7 +35,7 @@ struct outer_cache_fns {
1755 #endif
1756 void (*set_debug)(unsigned long);
1757 void (*resume)(void);
1758-};
1759+} __no_const;
1760
1761 #ifdef CONFIG_OUTER_CACHE
1762
1763diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1764index 812a494..71fc0b6 100644
1765--- a/arch/arm/include/asm/page.h
1766+++ b/arch/arm/include/asm/page.h
1767@@ -114,7 +114,7 @@ struct cpu_user_fns {
1768 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1769 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1770 unsigned long vaddr, struct vm_area_struct *vma);
1771-};
1772+} __no_const;
1773
1774 #ifdef MULTI_USER
1775 extern struct cpu_user_fns cpu_user;
1776diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1777index 943504f..c37a730 100644
1778--- a/arch/arm/include/asm/pgalloc.h
1779+++ b/arch/arm/include/asm/pgalloc.h
1780@@ -17,6 +17,7 @@
1781 #include <asm/processor.h>
1782 #include <asm/cacheflush.h>
1783 #include <asm/tlbflush.h>
1784+#include <asm/system_info.h>
1785
1786 #define check_pgt_cache() do { } while (0)
1787
1788@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1789 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1790 }
1791
1792+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1793+{
1794+ pud_populate(mm, pud, pmd);
1795+}
1796+
1797 #else /* !CONFIG_ARM_LPAE */
1798
1799 /*
1800@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1801 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1802 #define pmd_free(mm, pmd) do { } while (0)
1803 #define pud_populate(mm,pmd,pte) BUG()
1804+#define pud_populate_kernel(mm,pmd,pte) BUG()
1805
1806 #endif /* CONFIG_ARM_LPAE */
1807
1808@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1809 __free_page(pte);
1810 }
1811
1812+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1813+{
1814+#ifdef CONFIG_ARM_LPAE
1815+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1816+#else
1817+ if (addr & SECTION_SIZE)
1818+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1819+ else
1820+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1821+#endif
1822+ flush_pmd_entry(pmdp);
1823+}
1824+
1825 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1826 pmdval_t prot)
1827 {
1828@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1829 static inline void
1830 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1831 {
1832- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1833+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1834 }
1835 #define pmd_pgtable(pmd) pmd_page(pmd)
1836
1837diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1838index 5cfba15..f415e1a 100644
1839--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1840+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1841@@ -20,12 +20,15 @@
1842 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1843 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1844 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1845+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1846 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1847 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1848 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1849+
1850 /*
1851 * - section
1852 */
1853+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1854 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1855 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1856 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1857@@ -37,6 +40,7 @@
1858 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1859 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1860 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1861+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1862
1863 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1864 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1865@@ -66,6 +70,7 @@
1866 * - extended small page/tiny page
1867 */
1868 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1869+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1870 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1871 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1872 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1873diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1874index f97ee02..07f1be5 100644
1875--- a/arch/arm/include/asm/pgtable-2level.h
1876+++ b/arch/arm/include/asm/pgtable-2level.h
1877@@ -125,6 +125,7 @@
1878 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1879 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1880 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1881+#define L_PTE_PXN (_AT(pteval_t, 1) << 12) /* v7*/
1882
1883 /*
1884 * These are the memory types, defined to be compatible with
1885diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1886index d795282..a43ea90 100644
1887--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1888+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1889@@ -32,15 +32,18 @@
1890 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1891 #define PMD_BIT4 (_AT(pmdval_t, 0))
1892 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1893+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1894
1895 /*
1896 * - section
1897 */
1898 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1899 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1900+#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1901 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1902 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1903 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1904+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1905 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1906 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1907 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1908@@ -66,6 +69,7 @@
1909 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1910 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1911 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1912+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1913 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1914
1915 /*
1916diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1917index a3f3792..7b932a6 100644
1918--- a/arch/arm/include/asm/pgtable-3level.h
1919+++ b/arch/arm/include/asm/pgtable-3level.h
1920@@ -74,6 +74,7 @@
1921 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1922 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1923 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1924+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1925 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1926 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1927 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1928@@ -82,6 +83,7 @@
1929 /*
1930 * To be used in assembly code with the upper page attributes.
1931 */
1932+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1933 #define L_PTE_XN_HIGH (1 << (54 - 32))
1934 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1935
1936diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1937index 9c82f988..514705a 100644
1938--- a/arch/arm/include/asm/pgtable.h
1939+++ b/arch/arm/include/asm/pgtable.h
1940@@ -30,6 +30,9 @@
1941 #include <asm/pgtable-2level.h>
1942 #endif
1943
1944+#define ktla_ktva(addr) (addr)
1945+#define ktva_ktla(addr) (addr)
1946+
1947 /*
1948 * Just any arbitrary offset to the start of the vmalloc VM area: the
1949 * current 8MB value just means that there will be a 8MB "hole" after the
1950@@ -45,6 +48,9 @@
1951 #define LIBRARY_TEXT_START 0x0c000000
1952
1953 #ifndef __ASSEMBLY__
1954+extern pteval_t __supported_pte_mask;
1955+extern pmdval_t __supported_pmd_mask;
1956+
1957 extern void __pte_error(const char *file, int line, pte_t);
1958 extern void __pmd_error(const char *file, int line, pmd_t);
1959 extern void __pgd_error(const char *file, int line, pgd_t);
1960@@ -53,6 +59,50 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1961 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1962 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1963
1964+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1965+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1966+
1967+#ifdef CONFIG_PAX_KERNEXEC
1968+#include <asm/domain.h>
1969+#include <linux/thread_info.h>
1970+#include <linux/preempt.h>
1971+#endif
1972+
1973+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1974+static inline int test_domain(int domain, int domaintype)
1975+{
1976+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
1977+}
1978+#endif
1979+
1980+#ifdef CONFIG_PAX_KERNEXEC
1981+static inline unsigned long pax_open_kernel(void) {
1982+#ifdef CONFIG_ARM_LPAE
1983+ /* TODO */
1984+#else
1985+ preempt_disable();
1986+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
1987+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
1988+#endif
1989+ return 0;
1990+}
1991+
1992+static inline unsigned long pax_close_kernel(void) {
1993+#ifdef CONFIG_ARM_LPAE
1994+ /* TODO */
1995+#else
1996+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
1997+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
1998+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
1999+ preempt_enable_no_resched();
2000+#endif
2001+ return 0;
2002+}
2003+#else
2004+static inline unsigned long pax_open_kernel(void) { return 0; }
2005+static inline unsigned long pax_close_kernel(void) { return 0; }
2006+#endif
2007+
2008 /*
2009 * This is the lowest virtual address we can permit any user space
2010 * mapping to be mapped at. This is particularly important for
2011@@ -63,8 +113,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2012 /*
2013 * The pgprot_* and protection_map entries will be fixed up in runtime
2014 * to include the cachable and bufferable bits based on memory policy,
2015- * as well as any architecture dependent bits like global/ASID and SMP
2016- * shared mapping bits.
2017+ * as well as any architecture dependent bits like global/ASID, PXN,
2018+ * and SMP shared mapping bits.
2019 */
2020 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2021
2022@@ -240,7 +290,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2023
2024 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2025 {
2026- const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | L_PTE_NONE;
2027+ const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | L_PTE_NONE | __supported_pte_mask;
2028 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2029 return pte;
2030 }
2031diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2032index f3628fb..a0672dd 100644
2033--- a/arch/arm/include/asm/proc-fns.h
2034+++ b/arch/arm/include/asm/proc-fns.h
2035@@ -75,7 +75,7 @@ extern struct processor {
2036 unsigned int suspend_size;
2037 void (*do_suspend)(void *);
2038 void (*do_resume)(void *);
2039-} processor;
2040+} __do_const processor;
2041
2042 #ifndef MULTI_CPU
2043 extern void cpu_proc_init(void);
2044diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
2045index 06e7d50..8a8e251 100644
2046--- a/arch/arm/include/asm/processor.h
2047+++ b/arch/arm/include/asm/processor.h
2048@@ -65,9 +65,8 @@ struct thread_struct {
2049 regs->ARM_cpsr |= PSR_ENDSTATE; \
2050 regs->ARM_pc = pc & ~1; /* pc */ \
2051 regs->ARM_sp = sp; /* sp */ \
2052- regs->ARM_r2 = stack[2]; /* r2 (envp) */ \
2053- regs->ARM_r1 = stack[1]; /* r1 (argv) */ \
2054- regs->ARM_r0 = stack[0]; /* r0 (argc) */ \
2055+ /* r2 (envp), r1 (argv), r0 (argc) */ \
2056+ (void)copy_from_user(&regs->ARM_r0, (const char __user *)stack, 3 * sizeof(unsigned long)); \
2057 nommu_start_thread(regs); \
2058 })
2059
2060diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2061index d3a22be..3a69ad5 100644
2062--- a/arch/arm/include/asm/smp.h
2063+++ b/arch/arm/include/asm/smp.h
2064@@ -107,7 +107,7 @@ struct smp_operations {
2065 int (*cpu_disable)(unsigned int cpu);
2066 #endif
2067 #endif
2068-};
2069+} __no_const;
2070
2071 /*
2072 * set platform specific SMP operations
2073diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2074index cddda1f..ff357f7 100644
2075--- a/arch/arm/include/asm/thread_info.h
2076+++ b/arch/arm/include/asm/thread_info.h
2077@@ -77,9 +77,9 @@ struct thread_info {
2078 .flags = 0, \
2079 .preempt_count = INIT_PREEMPT_COUNT, \
2080 .addr_limit = KERNEL_DS, \
2081- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2082- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2083- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2084+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2085+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2086+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2087 .restart_block = { \
2088 .fn = do_no_restart_syscall, \
2089 }, \
2090@@ -152,6 +152,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2091 #define TIF_SYSCALL_AUDIT 9
2092 #define TIF_SYSCALL_TRACEPOINT 10
2093 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2094+
2095+/* within 8 bits of TIF_SYSCALL_TRACE
2096+ * to meet flexible second operand requirements
2097+ */
2098+#define TIF_GRSEC_SETXID 12
2099+
2100 #define TIF_USING_IWMMXT 17
2101 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2102 #define TIF_RESTORE_SIGMASK 20
2103@@ -165,10 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2104 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2105 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2106 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2107+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2108
2109 /* Checks for any syscall work in entry-common.S */
2110 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2111- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2112+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2113
2114 /*
2115 * Change these and you break ASM code in entry-common.S
2116diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2117index 7e1f760..752fcb7 100644
2118--- a/arch/arm/include/asm/uaccess.h
2119+++ b/arch/arm/include/asm/uaccess.h
2120@@ -18,6 +18,7 @@
2121 #include <asm/domain.h>
2122 #include <asm/unified.h>
2123 #include <asm/compiler.h>
2124+#include <asm/pgtable.h>
2125
2126 #define VERIFY_READ 0
2127 #define VERIFY_WRITE 1
2128@@ -60,10 +61,34 @@ extern int __put_user_bad(void);
2129 #define USER_DS TASK_SIZE
2130 #define get_fs() (current_thread_info()->addr_limit)
2131
2132+static inline void pax_open_userland(void)
2133+{
2134+
2135+#ifdef CONFIG_PAX_MEMORY_UDEREF
2136+ if (get_fs() == USER_DS) {
2137+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2138+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2139+ }
2140+#endif
2141+
2142+}
2143+
2144+static inline void pax_close_userland(void)
2145+{
2146+
2147+#ifdef CONFIG_PAX_MEMORY_UDEREF
2148+ if (get_fs() == USER_DS) {
2149+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2150+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2151+ }
2152+#endif
2153+
2154+}
2155+
2156 static inline void set_fs(mm_segment_t fs)
2157 {
2158 current_thread_info()->addr_limit = fs;
2159- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2160+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2161 }
2162
2163 #define segment_eq(a,b) ((a) == (b))
2164@@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2165
2166 #define get_user(x,p) \
2167 ({ \
2168+ int __e; \
2169 might_fault(); \
2170- __get_user_check(x,p); \
2171+ pax_open_userland(); \
2172+ __e = __get_user_check(x,p); \
2173+ pax_close_userland(); \
2174+ __e; \
2175 })
2176
2177 extern int __put_user_1(void *, unsigned int);
2178@@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2179
2180 #define put_user(x,p) \
2181 ({ \
2182+ int __e; \
2183 might_fault(); \
2184- __put_user_check(x,p); \
2185+ pax_open_userland(); \
2186+ __e = __put_user_check(x,p); \
2187+ pax_close_userland(); \
2188+ __e; \
2189 })
2190
2191 #else /* CONFIG_MMU */
2192@@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2193 #define __get_user(x,ptr) \
2194 ({ \
2195 long __gu_err = 0; \
2196+ pax_open_userland(); \
2197 __get_user_err((x),(ptr),__gu_err); \
2198+ pax_close_userland(); \
2199 __gu_err; \
2200 })
2201
2202 #define __get_user_error(x,ptr,err) \
2203 ({ \
2204+ pax_open_userland(); \
2205 __get_user_err((x),(ptr),err); \
2206+ pax_close_userland(); \
2207 (void) 0; \
2208 })
2209
2210@@ -312,13 +349,17 @@ do { \
2211 #define __put_user(x,ptr) \
2212 ({ \
2213 long __pu_err = 0; \
2214+ pax_open_userland(); \
2215 __put_user_err((x),(ptr),__pu_err); \
2216+ pax_close_userland(); \
2217 __pu_err; \
2218 })
2219
2220 #define __put_user_error(x,ptr,err) \
2221 ({ \
2222+ pax_open_userland(); \
2223 __put_user_err((x),(ptr),err); \
2224+ pax_close_userland(); \
2225 (void) 0; \
2226 })
2227
2228@@ -418,11 +459,44 @@ do { \
2229
2230
2231 #ifdef CONFIG_MMU
2232-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2233-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2234+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2235+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2236+
2237+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2238+{
2239+ unsigned long ret;
2240+
2241+ check_object_size(to, n, false);
2242+ pax_open_userland();
2243+ ret = ___copy_from_user(to, from, n);
2244+ pax_close_userland();
2245+ return ret;
2246+}
2247+
2248+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2249+{
2250+ unsigned long ret;
2251+
2252+ check_object_size(from, n, true);
2253+ pax_open_userland();
2254+ ret = ___copy_to_user(to, from, n);
2255+ pax_close_userland();
2256+ return ret;
2257+}
2258+
2259 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2260-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2261+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2262 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2263+
2264+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2265+{
2266+ unsigned long ret;
2267+ pax_open_userland();
2268+ ret = ___clear_user(addr, n);
2269+ pax_close_userland();
2270+ return ret;
2271+}
2272+
2273 #else
2274 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2275 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2276@@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2277
2278 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2279 {
2280+ if ((long)n < 0)
2281+ return n;
2282+
2283 if (access_ok(VERIFY_READ, from, n))
2284 n = __copy_from_user(to, from, n);
2285 else /* security hole - plug it */
2286@@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2287
2288 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2289 {
2290+ if ((long)n < 0)
2291+ return n;
2292+
2293 if (access_ok(VERIFY_WRITE, to, n))
2294 n = __copy_to_user(to, from, n);
2295 return n;
2296diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2297index 96ee092..37f1844 100644
2298--- a/arch/arm/include/uapi/asm/ptrace.h
2299+++ b/arch/arm/include/uapi/asm/ptrace.h
2300@@ -73,7 +73,7 @@
2301 * ARMv7 groups of PSR bits
2302 */
2303 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2304-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2305+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2306 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2307 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2308
2309diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2310index 60d3b73..9168db0 100644
2311--- a/arch/arm/kernel/armksyms.c
2312+++ b/arch/arm/kernel/armksyms.c
2313@@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
2314 #ifdef CONFIG_MMU
2315 EXPORT_SYMBOL(copy_page);
2316
2317-EXPORT_SYMBOL(__copy_from_user);
2318-EXPORT_SYMBOL(__copy_to_user);
2319+EXPORT_SYMBOL(___copy_from_user);
2320+EXPORT_SYMBOL(___copy_to_user);
2321 EXPORT_SYMBOL(__clear_user);
2322
2323 EXPORT_SYMBOL(__get_user_1);
2324diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2325index 0f82098..3dbd3ee 100644
2326--- a/arch/arm/kernel/entry-armv.S
2327+++ b/arch/arm/kernel/entry-armv.S
2328@@ -47,6 +47,87 @@
2329 9997:
2330 .endm
2331
2332+ .macro pax_enter_kernel
2333+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2334+ @ make aligned space for saved DACR
2335+ sub sp, sp, #8
2336+ @ save regs
2337+ stmdb sp!, {r1, r2}
2338+ @ read DACR from cpu_domain into r1
2339+ mov r2, sp
2340+ @ assume 8K pages, since we have to split the immediate in two
2341+ bic r2, r2, #(0x1fc0)
2342+ bic r2, r2, #(0x3f)
2343+ ldr r1, [r2, #TI_CPU_DOMAIN]
2344+ @ store old DACR on stack
2345+ str r1, [sp, #8]
2346+#ifdef CONFIG_PAX_KERNEXEC
2347+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2348+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2349+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2350+#endif
2351+#ifdef CONFIG_PAX_MEMORY_UDEREF
2352+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2353+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2354+#endif
2355+ @ write r1 to current_thread_info()->cpu_domain
2356+ str r1, [r2, #TI_CPU_DOMAIN]
2357+ @ write r1 to DACR
2358+ mcr p15, 0, r1, c3, c0, 0
2359+ @ instruction sync
2360+ instr_sync
2361+ @ restore regs
2362+ ldmia sp!, {r1, r2}
2363+#endif
2364+ .endm
2365+
2366+ .macro pax_open_userland
2367+#ifdef CONFIG_PAX_MEMORY_UDEREF
2368+ @ save regs
2369+ stmdb sp!, {r0, r1}
2370+ @ read DACR from cpu_domain into r1
2371+ mov r0, sp
2372+ @ assume 8K pages, since we have to split the immediate in two
2373+ bic r0, r0, #(0x1fc0)
2374+ bic r0, r0, #(0x3f)
2375+ ldr r1, [r0, #TI_CPU_DOMAIN]
2376+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2377+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2378+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2379+ @ write r1 to current_thread_info()->cpu_domain
2380+ str r1, [r0, #TI_CPU_DOMAIN]
2381+ @ write r1 to DACR
2382+ mcr p15, 0, r1, c3, c0, 0
2383+ @ instruction sync
2384+ instr_sync
2385+ @ restore regs
2386+ ldmia sp!, {r0, r1}
2387+#endif
2388+ .endm
2389+
2390+ .macro pax_close_userland
2391+#ifdef CONFIG_PAX_MEMORY_UDEREF
2392+ @ save regs
2393+ stmdb sp!, {r0, r1}
2394+ @ read DACR from cpu_domain into r1
2395+ mov r0, sp
2396+ @ assume 8K pages, since we have to split the immediate in two
2397+ bic r0, r0, #(0x1fc0)
2398+ bic r0, r0, #(0x3f)
2399+ ldr r1, [r0, #TI_CPU_DOMAIN]
2400+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2401+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2402+ @ write r1 to current_thread_info()->cpu_domain
2403+ str r1, [r0, #TI_CPU_DOMAIN]
2404+ @ write r1 to DACR
2405+ mcr p15, 0, r1, c3, c0, 0
2406+ @ instruction sync
2407+ instr_sync
2408+ @ restore regs
2409+ ldmia sp!, {r0, r1}
2410+#endif
2411+ .endm
2412+
2413 .macro pabt_helper
2414 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2415 #ifdef MULTI_PABORT
2416@@ -89,11 +170,15 @@
2417 * Invalid mode handlers
2418 */
2419 .macro inv_entry, reason
2420+
2421+ pax_enter_kernel
2422+
2423 sub sp, sp, #S_FRAME_SIZE
2424 ARM( stmib sp, {r1 - lr} )
2425 THUMB( stmia sp, {r0 - r12} )
2426 THUMB( str sp, [sp, #S_SP] )
2427 THUMB( str lr, [sp, #S_LR] )
2428+
2429 mov r1, #\reason
2430 .endm
2431
2432@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2433 .macro svc_entry, stack_hole=0
2434 UNWIND(.fnstart )
2435 UNWIND(.save {r0 - pc} )
2436+
2437+ pax_enter_kernel
2438+
2439 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2440+
2441 #ifdef CONFIG_THUMB2_KERNEL
2442 SPFIX( str r0, [sp] ) @ temporarily saved
2443 SPFIX( mov r0, sp )
2444@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2445 ldmia r0, {r3 - r5}
2446 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2447 mov r6, #-1 @ "" "" "" ""
2448+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2449+ @ offset sp by 8 as done in pax_enter_kernel
2450+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2451+#else
2452 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2453+#endif
2454 SPFIX( addeq r2, r2, #4 )
2455 str r3, [sp, #-4]! @ save the "real" r0 copied
2456 @ from the exception stack
2457@@ -359,6 +453,9 @@ ENDPROC(__pabt_svc)
2458 .macro usr_entry
2459 UNWIND(.fnstart )
2460 UNWIND(.cantunwind ) @ don't unwind the user space
2461+
2462+ pax_enter_kernel_user
2463+
2464 sub sp, sp, #S_FRAME_SIZE
2465 ARM( stmib sp, {r1 - r12} )
2466 THUMB( stmia sp, {r0 - r12} )
2467@@ -456,7 +553,9 @@ __und_usr:
2468 tst r3, #PSR_T_BIT @ Thumb mode?
2469 bne __und_usr_thumb
2470 sub r4, r2, #4 @ ARM instr at LR - 4
2471+ pax_open_userland
2472 1: ldrt r0, [r4]
2473+ pax_close_userland
2474 #ifdef CONFIG_CPU_ENDIAN_BE8
2475 rev r0, r0 @ little endian instruction
2476 #endif
2477@@ -491,10 +590,14 @@ __und_usr_thumb:
2478 */
2479 .arch armv6t2
2480 #endif
2481+ pax_open_userland
2482 2: ldrht r5, [r4]
2483+ pax_close_userland
2484 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2485 blo __und_usr_fault_16 @ 16bit undefined instruction
2486+ pax_open_userland
2487 3: ldrht r0, [r2]
2488+ pax_close_userland
2489 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2490 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2491 orr r0, r0, r5, lsl #16
2492@@ -733,7 +836,7 @@ ENTRY(__switch_to)
2493 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2494 THUMB( str sp, [ip], #4 )
2495 THUMB( str lr, [ip], #4 )
2496-#ifdef CONFIG_CPU_USE_DOMAINS
2497+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2498 ldr r6, [r2, #TI_CPU_DOMAIN]
2499 #endif
2500 set_tls r3, r4, r5
2501@@ -742,7 +845,7 @@ ENTRY(__switch_to)
2502 ldr r8, =__stack_chk_guard
2503 ldr r7, [r7, #TSK_STACK_CANARY]
2504 #endif
2505-#ifdef CONFIG_CPU_USE_DOMAINS
2506+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2507 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2508 #endif
2509 mov r5, r0
2510diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2511index a6c301e..908821b 100644
2512--- a/arch/arm/kernel/entry-common.S
2513+++ b/arch/arm/kernel/entry-common.S
2514@@ -10,18 +10,46 @@
2515
2516 #include <asm/unistd.h>
2517 #include <asm/ftrace.h>
2518+#include <asm/domain.h>
2519 #include <asm/unwind.h>
2520
2521+#include "entry-header.S"
2522+
2523 #ifdef CONFIG_NEED_RET_TO_USER
2524 #include <mach/entry-macro.S>
2525 #else
2526 .macro arch_ret_to_user, tmp1, tmp2
2527+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2528+ @ save regs
2529+ stmdb sp!, {r1, r2}
2530+ @ read DACR from cpu_domain into r1
2531+ mov r2, sp
2532+ @ assume 8K pages, since we have to split the immediate in two
2533+ bic r2, r2, #(0x1fc0)
2534+ bic r2, r2, #(0x3f)
2535+ ldr r1, [r2, #TI_CPU_DOMAIN]
2536+#ifdef CONFIG_PAX_KERNEXEC
2537+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2538+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2539+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2540+#endif
2541+#ifdef CONFIG_PAX_MEMORY_UDEREF
2542+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2543+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2544+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2545+#endif
2546+ @ write r1 to current_thread_info()->cpu_domain
2547+ str r1, [r2, #TI_CPU_DOMAIN]
2548+ @ write r1 to DACR
2549+ mcr p15, 0, r1, c3, c0, 0
2550+ @ instruction sync
2551+ instr_sync
2552+ @ restore regs
2553+ ldmia sp!, {r1, r2}
2554+#endif
2555 .endm
2556 #endif
2557
2558-#include "entry-header.S"
2559-
2560-
2561 .align 5
2562 /*
2563 * This is the fast syscall return path. We do as little as
2564@@ -339,6 +367,7 @@ ENDPROC(ftrace_stub)
2565
2566 .align 5
2567 ENTRY(vector_swi)
2568+
2569 sub sp, sp, #S_FRAME_SIZE
2570 stmia sp, {r0 - r12} @ Calling r0 - r12
2571 ARM( add r8, sp, #S_PC )
2572@@ -388,6 +417,12 @@ ENTRY(vector_swi)
2573 ldr scno, [lr, #-4] @ get SWI instruction
2574 #endif
2575
2576+ /*
2577+ * do this here to avoid a performance hit of wrapping the code above
2578+ * that directly dereferences userland to parse the SWI instruction
2579+ */
2580+ pax_enter_kernel_user
2581+
2582 #ifdef CONFIG_ALIGNMENT_TRAP
2583 ldr ip, __cr_alignment
2584 ldr ip, [ip]
2585diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2586index 9a8531e..812e287 100644
2587--- a/arch/arm/kernel/entry-header.S
2588+++ b/arch/arm/kernel/entry-header.S
2589@@ -73,9 +73,66 @@
2590 msr cpsr_c, \rtemp @ switch back to the SVC mode
2591 .endm
2592
2593+ .macro pax_enter_kernel_user
2594+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2595+ @ save regs
2596+ stmdb sp!, {r0, r1}
2597+ @ read DACR from cpu_domain into r1
2598+ mov r0, sp
2599+ @ assume 8K pages, since we have to split the immediate in two
2600+ bic r0, r0, #(0x1fc0)
2601+ bic r0, r0, #(0x3f)
2602+ ldr r1, [r0, #TI_CPU_DOMAIN]
2603+#ifdef CONFIG_PAX_MEMORY_UDEREF
2604+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2605+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2606+#endif
2607+#ifdef CONFIG_PAX_KERNEXEC
2608+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2609+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2610+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2611+#endif
2612+ @ write r1 to current_thread_info()->cpu_domain
2613+ str r1, [r0, #TI_CPU_DOMAIN]
2614+ @ write r1 to DACR
2615+ mcr p15, 0, r1, c3, c0, 0
2616+ @ instruction sync
2617+ instr_sync
2618+ @ restore regs
2619+ ldmia sp!, {r0, r1}
2620+#endif
2621+ .endm
2622+
2623+ .macro pax_exit_kernel
2624+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2625+ @ save regs
2626+ stmdb sp!, {r0, r1}
2627+ @ read old DACR from stack into r1
2628+ ldr r1, [sp, #(8 + S_SP)]
2629+ sub r1, r1, #8
2630+ ldr r1, [r1]
2631+
2632+ @ write r1 to current_thread_info()->cpu_domain
2633+ mov r0, sp
2634+ @ assume 8K pages, since we have to split the immediate in two
2635+ bic r0, r0, #(0x1fc0)
2636+ bic r0, r0, #(0x3f)
2637+ str r1, [r0, #TI_CPU_DOMAIN]
2638+ @ write r1 to DACR
2639+ mcr p15, 0, r1, c3, c0, 0
2640+ @ instruction sync
2641+ instr_sync
2642+ @ restore regs
2643+ ldmia sp!, {r0, r1}
2644+#endif
2645+ .endm
2646+
2647 #ifndef CONFIG_THUMB2_KERNEL
2648 .macro svc_exit, rpsr
2649 msr spsr_cxsf, \rpsr
2650+
2651+ pax_exit_kernel
2652+
2653 #if defined(CONFIG_CPU_V6)
2654 ldr r0, [sp]
2655 strex r1, r2, [sp] @ clear the exclusive monitor
2656@@ -121,6 +178,9 @@
2657 .endm
2658 #else /* CONFIG_THUMB2_KERNEL */
2659 .macro svc_exit, rpsr
2660+
2661+ pax_exit_kernel
2662+
2663 ldr lr, [sp, #S_SP] @ top of the stack
2664 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2665 clrex @ clear the exclusive monitor
2666diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2667index 2adda11..7fbe958 100644
2668--- a/arch/arm/kernel/fiq.c
2669+++ b/arch/arm/kernel/fiq.c
2670@@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2671 #if defined(CONFIG_CPU_USE_DOMAINS)
2672 memcpy((void *)0xffff001c, start, length);
2673 #else
2674+ pax_open_kernel();
2675 memcpy(vectors_page + 0x1c, start, length);
2676+ pax_close_kernel();
2677 #endif
2678 flush_icache_range(0xffff001c, 0xffff001c + length);
2679 if (!vectors_high())
2680diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2681index 486a15a..2d6880e 100644
2682--- a/arch/arm/kernel/head.S
2683+++ b/arch/arm/kernel/head.S
2684@@ -52,7 +52,9 @@
2685 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2686
2687 .macro pgtbl, rd, phys
2688- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2689+ mov \rd, #TEXT_OFFSET
2690+ sub \rd, #PG_DIR_SIZE
2691+ add \rd, \rd, \phys
2692 .endm
2693
2694 /*
2695@@ -416,7 +418,7 @@ __enable_mmu:
2696 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2697 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2698 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2699- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2700+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2701 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2702 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2703 #endif
2704diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2705index 5ff2e77..556d030 100644
2706--- a/arch/arm/kernel/hw_breakpoint.c
2707+++ b/arch/arm/kernel/hw_breakpoint.c
2708@@ -1011,7 +1011,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2709 return NOTIFY_OK;
2710 }
2711
2712-static struct notifier_block __cpuinitdata dbg_reset_nb = {
2713+static struct notifier_block dbg_reset_nb = {
2714 .notifier_call = dbg_reset_notify,
2715 };
2716
2717diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2718index 1e9be5d..03edbc2 100644
2719--- a/arch/arm/kernel/module.c
2720+++ b/arch/arm/kernel/module.c
2721@@ -37,12 +37,37 @@
2722 #endif
2723
2724 #ifdef CONFIG_MMU
2725-void *module_alloc(unsigned long size)
2726+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2727 {
2728+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2729+ return NULL;
2730 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2731- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2732+ GFP_KERNEL, prot, -1,
2733 __builtin_return_address(0));
2734 }
2735+
2736+void *module_alloc(unsigned long size)
2737+{
2738+
2739+#ifdef CONFIG_PAX_KERNEXEC
2740+ return __module_alloc(size, PAGE_KERNEL);
2741+#else
2742+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2743+#endif
2744+
2745+}
2746+
2747+#ifdef CONFIG_PAX_KERNEXEC
2748+void module_free_exec(struct module *mod, void *module_region)
2749+{
2750+ module_free(mod, module_region);
2751+}
2752+
2753+void *module_alloc_exec(unsigned long size)
2754+{
2755+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2756+}
2757+#endif
2758 #endif
2759
2760 int
2761diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2762index 5f66206..dce492f 100644
2763--- a/arch/arm/kernel/perf_event_cpu.c
2764+++ b/arch/arm/kernel/perf_event_cpu.c
2765@@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2766 return NOTIFY_OK;
2767 }
2768
2769-static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2770+static struct notifier_block cpu_pmu_hotplug_notifier = {
2771 .notifier_call = cpu_pmu_notify,
2772 };
2773
2774diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2775index c6dec5f..f853532 100644
2776--- a/arch/arm/kernel/process.c
2777+++ b/arch/arm/kernel/process.c
2778@@ -28,7 +28,6 @@
2779 #include <linux/tick.h>
2780 #include <linux/utsname.h>
2781 #include <linux/uaccess.h>
2782-#include <linux/random.h>
2783 #include <linux/hw_breakpoint.h>
2784 #include <linux/cpuidle.h>
2785 #include <linux/leds.h>
2786@@ -256,9 +255,10 @@ void machine_power_off(void)
2787 machine_shutdown();
2788 if (pm_power_off)
2789 pm_power_off();
2790+ BUG();
2791 }
2792
2793-void machine_restart(char *cmd)
2794+__noreturn void machine_restart(char *cmd)
2795 {
2796 machine_shutdown();
2797
2798@@ -283,8 +283,8 @@ void __show_regs(struct pt_regs *regs)
2799 init_utsname()->release,
2800 (int)strcspn(init_utsname()->version, " "),
2801 init_utsname()->version);
2802- print_symbol("PC is at %s\n", instruction_pointer(regs));
2803- print_symbol("LR is at %s\n", regs->ARM_lr);
2804+ printk("PC is at %pA\n", instruction_pointer(regs));
2805+ printk("LR is at %pA\n", regs->ARM_lr);
2806 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2807 "sp : %08lx ip : %08lx fp : %08lx\n",
2808 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2809@@ -452,12 +452,6 @@ unsigned long get_wchan(struct task_struct *p)
2810 return 0;
2811 }
2812
2813-unsigned long arch_randomize_brk(struct mm_struct *mm)
2814-{
2815- unsigned long range_end = mm->brk + 0x02000000;
2816- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2817-}
2818-
2819 #ifdef CONFIG_MMU
2820 /*
2821 * The vectors page is always readable from user space for the
2822diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2823index 03deeff..741ce88 100644
2824--- a/arch/arm/kernel/ptrace.c
2825+++ b/arch/arm/kernel/ptrace.c
2826@@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2827 return current_thread_info()->syscall;
2828 }
2829
2830+#ifdef CONFIG_GRKERNSEC_SETXID
2831+extern void gr_delayed_cred_worker(void);
2832+#endif
2833+
2834 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2835 {
2836 current_thread_info()->syscall = scno;
2837
2838+#ifdef CONFIG_GRKERNSEC_SETXID
2839+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2840+ gr_delayed_cred_worker();
2841+#endif
2842+
2843 /* Do the secure computing check first; failures should be fast. */
2844 if (secure_computing(scno) == -1)
2845 return -1;
2846diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2847index 3f6cbb2..6d856f5 100644
2848--- a/arch/arm/kernel/setup.c
2849+++ b/arch/arm/kernel/setup.c
2850@@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2851 unsigned int elf_hwcap __read_mostly;
2852 EXPORT_SYMBOL(elf_hwcap);
2853
2854+pteval_t __supported_pte_mask __read_only;
2855+pmdval_t __supported_pmd_mask __read_only;
2856
2857 #ifdef MULTI_CPU
2858-struct processor processor __read_mostly;
2859+struct processor processor;
2860 #endif
2861 #ifdef MULTI_TLB
2862-struct cpu_tlb_fns cpu_tlb __read_mostly;
2863+struct cpu_tlb_fns cpu_tlb __read_only;
2864 #endif
2865 #ifdef MULTI_USER
2866-struct cpu_user_fns cpu_user __read_mostly;
2867+struct cpu_user_fns cpu_user __read_only;
2868 #endif
2869 #ifdef MULTI_CACHE
2870-struct cpu_cache_fns cpu_cache __read_mostly;
2871+struct cpu_cache_fns cpu_cache __read_only;
2872 #endif
2873 #ifdef CONFIG_OUTER_CACHE
2874-struct outer_cache_fns outer_cache __read_mostly;
2875+struct outer_cache_fns outer_cache __read_only;
2876 EXPORT_SYMBOL(outer_cache);
2877 #endif
2878
2879@@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2880 asm("mrc p15, 0, %0, c0, c1, 4"
2881 : "=r" (mmfr0));
2882 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2883- (mmfr0 & 0x000000f0) >= 0x00000030)
2884+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2885 cpu_arch = CPU_ARCH_ARMv7;
2886- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2887+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2888+ __supported_pte_mask |= L_PTE_PXN;
2889+ __supported_pmd_mask |= PMD_PXNTABLE;
2890+ }
2891+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2892 (mmfr0 & 0x000000f0) == 0x00000020)
2893 cpu_arch = CPU_ARCH_ARMv6;
2894 else
2895@@ -462,7 +468,7 @@ static void __init setup_processor(void)
2896 __cpu_architecture = __get_cpu_architecture();
2897
2898 #ifdef MULTI_CPU
2899- processor = *list->proc;
2900+ memcpy((void *)&processor, list->proc, sizeof processor);
2901 #endif
2902 #ifdef MULTI_TLB
2903 cpu_tlb = *list->tlb;
2904diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2905index 84f4cbf..672f5b8 100644
2906--- a/arch/arm/kernel/smp.c
2907+++ b/arch/arm/kernel/smp.c
2908@@ -70,7 +70,7 @@ enum ipi_msg_type {
2909
2910 static DECLARE_COMPLETION(cpu_running);
2911
2912-static struct smp_operations smp_ops;
2913+static struct smp_operations smp_ops __read_only;
2914
2915 void __init smp_set_ops(struct smp_operations *ops)
2916 {
2917diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2918index b0179b8..b7b16c7 100644
2919--- a/arch/arm/kernel/traps.c
2920+++ b/arch/arm/kernel/traps.c
2921@@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
2922 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
2923 {
2924 #ifdef CONFIG_KALLSYMS
2925- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
2926+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
2927 #else
2928 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
2929 #endif
2930@@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2931 static int die_owner = -1;
2932 static unsigned int die_nest_count;
2933
2934+extern void gr_handle_kernel_exploit(void);
2935+
2936 static unsigned long oops_begin(void)
2937 {
2938 int cpu;
2939@@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
2940 panic("Fatal exception in interrupt");
2941 if (panic_on_oops)
2942 panic("Fatal exception");
2943+
2944+ gr_handle_kernel_exploit();
2945+
2946 if (signr)
2947 do_exit(signr);
2948 }
2949@@ -601,7 +606,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
2950 * The user helper at 0xffff0fe0 must be used instead.
2951 * (see entry-armv.S for details)
2952 */
2953+ pax_open_kernel();
2954 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
2955+ pax_close_kernel();
2956 }
2957 return 0;
2958
2959@@ -849,5 +856,9 @@ void __init early_trap_init(void *vectors_base)
2960 sigreturn_codes, sizeof(sigreturn_codes));
2961
2962 flush_icache_range(vectors, vectors + PAGE_SIZE);
2963- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
2964+
2965+#ifndef CONFIG_PAX_MEMORY_UDEREF
2966+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
2967+#endif
2968+
2969 }
2970diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
2971index 11c1785..c67d54c 100644
2972--- a/arch/arm/kernel/vmlinux.lds.S
2973+++ b/arch/arm/kernel/vmlinux.lds.S
2974@@ -8,7 +8,11 @@
2975 #include <asm/thread_info.h>
2976 #include <asm/memory.h>
2977 #include <asm/page.h>
2978-
2979+
2980+#ifdef CONFIG_PAX_KERNEXEC
2981+#include <asm/pgtable.h>
2982+#endif
2983+
2984 #define PROC_INFO \
2985 . = ALIGN(4); \
2986 VMLINUX_SYMBOL(__proc_info_begin) = .; \
2987@@ -90,6 +94,11 @@ SECTIONS
2988 _text = .;
2989 HEAD_TEXT
2990 }
2991+
2992+#ifdef CONFIG_PAX_KERNEXEC
2993+ . = ALIGN(1<<SECTION_SHIFT);
2994+#endif
2995+
2996 .text : { /* Real text segment */
2997 _stext = .; /* Text and read-only data */
2998 __exception_text_start = .;
2999@@ -144,6 +153,10 @@ SECTIONS
3000
3001 _etext = .; /* End of text and rodata section */
3002
3003+#ifdef CONFIG_PAX_KERNEXEC
3004+ . = ALIGN(1<<SECTION_SHIFT);
3005+#endif
3006+
3007 #ifndef CONFIG_XIP_KERNEL
3008 . = ALIGN(PAGE_SIZE);
3009 __init_begin = .;
3010@@ -203,6 +216,11 @@ SECTIONS
3011 . = PAGE_OFFSET + TEXT_OFFSET;
3012 #else
3013 __init_end = .;
3014+
3015+#ifdef CONFIG_PAX_KERNEXEC
3016+ . = ALIGN(1<<SECTION_SHIFT);
3017+#endif
3018+
3019 . = ALIGN(THREAD_SIZE);
3020 __data_loc = .;
3021 #endif
3022diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3023index 14a0d98..7771a7d 100644
3024--- a/arch/arm/lib/clear_user.S
3025+++ b/arch/arm/lib/clear_user.S
3026@@ -12,14 +12,14 @@
3027
3028 .text
3029
3030-/* Prototype: int __clear_user(void *addr, size_t sz)
3031+/* Prototype: int ___clear_user(void *addr, size_t sz)
3032 * Purpose : clear some user memory
3033 * Params : addr - user memory address to clear
3034 * : sz - number of bytes to clear
3035 * Returns : number of bytes NOT cleared
3036 */
3037 ENTRY(__clear_user_std)
3038-WEAK(__clear_user)
3039+WEAK(___clear_user)
3040 stmfd sp!, {r1, lr}
3041 mov r2, #0
3042 cmp r1, #4
3043@@ -44,7 +44,7 @@ WEAK(__clear_user)
3044 USER( strnebt r2, [r0])
3045 mov r0, #0
3046 ldmfd sp!, {r1, pc}
3047-ENDPROC(__clear_user)
3048+ENDPROC(___clear_user)
3049 ENDPROC(__clear_user_std)
3050
3051 .pushsection .fixup,"ax"
3052diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3053index 66a477a..bee61d3 100644
3054--- a/arch/arm/lib/copy_from_user.S
3055+++ b/arch/arm/lib/copy_from_user.S
3056@@ -16,7 +16,7 @@
3057 /*
3058 * Prototype:
3059 *
3060- * size_t __copy_from_user(void *to, const void *from, size_t n)
3061+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3062 *
3063 * Purpose:
3064 *
3065@@ -84,11 +84,11 @@
3066
3067 .text
3068
3069-ENTRY(__copy_from_user)
3070+ENTRY(___copy_from_user)
3071
3072 #include "copy_template.S"
3073
3074-ENDPROC(__copy_from_user)
3075+ENDPROC(___copy_from_user)
3076
3077 .pushsection .fixup,"ax"
3078 .align 0
3079diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3080index 6ee2f67..d1cce76 100644
3081--- a/arch/arm/lib/copy_page.S
3082+++ b/arch/arm/lib/copy_page.S
3083@@ -10,6 +10,7 @@
3084 * ASM optimised string functions
3085 */
3086 #include <linux/linkage.h>
3087+#include <linux/const.h>
3088 #include <asm/assembler.h>
3089 #include <asm/asm-offsets.h>
3090 #include <asm/cache.h>
3091diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3092index d066df6..df28194 100644
3093--- a/arch/arm/lib/copy_to_user.S
3094+++ b/arch/arm/lib/copy_to_user.S
3095@@ -16,7 +16,7 @@
3096 /*
3097 * Prototype:
3098 *
3099- * size_t __copy_to_user(void *to, const void *from, size_t n)
3100+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3101 *
3102 * Purpose:
3103 *
3104@@ -88,11 +88,11 @@
3105 .text
3106
3107 ENTRY(__copy_to_user_std)
3108-WEAK(__copy_to_user)
3109+WEAK(___copy_to_user)
3110
3111 #include "copy_template.S"
3112
3113-ENDPROC(__copy_to_user)
3114+ENDPROC(___copy_to_user)
3115 ENDPROC(__copy_to_user_std)
3116
3117 .pushsection .fixup,"ax"
3118diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3119index 7d08b43..f7ca7ea 100644
3120--- a/arch/arm/lib/csumpartialcopyuser.S
3121+++ b/arch/arm/lib/csumpartialcopyuser.S
3122@@ -57,8 +57,8 @@
3123 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3124 */
3125
3126-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3127-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3128+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3129+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3130
3131 #include "csumpartialcopygeneric.S"
3132
3133diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3134index 0dc5385..45833ef 100644
3135--- a/arch/arm/lib/delay.c
3136+++ b/arch/arm/lib/delay.c
3137@@ -28,12 +28,14 @@
3138 /*
3139 * Default to the loop-based delay implementation.
3140 */
3141-struct arm_delay_ops arm_delay_ops = {
3142+static struct arm_delay_ops arm_loop_delay_ops = {
3143 .delay = __loop_delay,
3144 .const_udelay = __loop_const_udelay,
3145 .udelay = __loop_udelay,
3146 };
3147
3148+struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
3149+
3150 static const struct delay_timer *delay_timer;
3151 static bool delay_calibrated;
3152
3153@@ -67,6 +69,12 @@ static void __timer_udelay(unsigned long usecs)
3154 __timer_const_udelay(usecs * UDELAY_MULT);
3155 }
3156
3157+static struct arm_delay_ops arm_timer_delay_ops = {
3158+ .delay = __timer_delay,
3159+ .const_udelay = __timer_const_udelay,
3160+ .udelay = __timer_udelay,
3161+};
3162+
3163 void __init register_current_timer_delay(const struct delay_timer *timer)
3164 {
3165 if (!delay_calibrated) {
3166@@ -74,9 +82,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
3167 delay_timer = timer;
3168 lpj_fine = timer->freq / HZ;
3169 loops_per_jiffy = lpj_fine;
3170- arm_delay_ops.delay = __timer_delay;
3171- arm_delay_ops.const_udelay = __timer_const_udelay;
3172- arm_delay_ops.udelay = __timer_udelay;
3173+ arm_delay_ops = &arm_timer_delay_ops;
3174 delay_calibrated = true;
3175 } else {
3176 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
3177diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3178index 025f742..8432b08 100644
3179--- a/arch/arm/lib/uaccess_with_memcpy.c
3180+++ b/arch/arm/lib/uaccess_with_memcpy.c
3181@@ -104,7 +104,7 @@ out:
3182 }
3183
3184 unsigned long
3185-__copy_to_user(void __user *to, const void *from, unsigned long n)
3186+___copy_to_user(void __user *to, const void *from, unsigned long n)
3187 {
3188 /*
3189 * This test is stubbed out of the main function above to keep
3190diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3191index bac21a5..b67ef8e 100644
3192--- a/arch/arm/mach-kirkwood/common.c
3193+++ b/arch/arm/mach-kirkwood/common.c
3194@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3195 clk_gate_ops.disable(hw);
3196 }
3197
3198-static struct clk_ops clk_gate_fn_ops;
3199+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3200+{
3201+ return clk_gate_ops.is_enabled(hw);
3202+}
3203+
3204+static struct clk_ops clk_gate_fn_ops = {
3205+ .enable = clk_gate_fn_enable,
3206+ .disable = clk_gate_fn_disable,
3207+ .is_enabled = clk_gate_fn_is_enabled,
3208+};
3209
3210 static struct clk __init *clk_register_gate_fn(struct device *dev,
3211 const char *name,
3212@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3213 gate_fn->fn_en = fn_en;
3214 gate_fn->fn_dis = fn_dis;
3215
3216- /* ops is the gate ops, but with our enable/disable functions */
3217- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3218- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3219- clk_gate_fn_ops = clk_gate_ops;
3220- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3221- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3222- }
3223-
3224 clk = clk_register(dev, &gate_fn->gate.hw);
3225
3226 if (IS_ERR(clk))
3227diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3228index 0abb30f..54064da 100644
3229--- a/arch/arm/mach-omap2/board-n8x0.c
3230+++ b/arch/arm/mach-omap2/board-n8x0.c
3231@@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3232 }
3233 #endif
3234
3235-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3236+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3237 .late_init = n8x0_menelaus_late_init,
3238 };
3239
3240diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3241index 5d3b4f4..ddba3c0 100644
3242--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3243+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3244@@ -340,7 +340,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3245 return NOTIFY_OK;
3246 }
3247
3248-static struct notifier_block __refdata irq_hotplug_notifier = {
3249+static struct notifier_block irq_hotplug_notifier = {
3250 .notifier_call = irq_cpu_hotplug_notify,
3251 };
3252
3253diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3254index 4653efb..8c60bf7 100644
3255--- a/arch/arm/mach-omap2/omap_hwmod.c
3256+++ b/arch/arm/mach-omap2/omap_hwmod.c
3257@@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
3258 int (*init_clkdm)(struct omap_hwmod *oh);
3259 void (*update_context_lost)(struct omap_hwmod *oh);
3260 int (*get_context_lost)(struct omap_hwmod *oh);
3261-};
3262+} __no_const;
3263
3264 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3265-static struct omap_hwmod_soc_ops soc_ops;
3266+static struct omap_hwmod_soc_ops soc_ops __read_only;
3267
3268 /* omap_hwmod_list contains all registered struct omap_hwmods */
3269 static LIST_HEAD(omap_hwmod_list);
3270diff --git a/arch/arm/mach-ux500/include/mach/setup.h b/arch/arm/mach-ux500/include/mach/setup.h
3271index 6be4c4d..32ac32a 100644
3272--- a/arch/arm/mach-ux500/include/mach/setup.h
3273+++ b/arch/arm/mach-ux500/include/mach/setup.h
3274@@ -38,13 +38,6 @@ extern struct sys_timer ux500_timer;
3275 .type = MT_DEVICE, \
3276 }
3277
3278-#define __MEM_DEV_DESC(x, sz) { \
3279- .virtual = IO_ADDRESS(x), \
3280- .pfn = __phys_to_pfn(x), \
3281- .length = sz, \
3282- .type = MT_MEMORY, \
3283-}
3284-
3285 extern struct smp_operations ux500_smp_ops;
3286 extern void ux500_cpu_die(unsigned int cpu);
3287
3288diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3289index 3fd629d..8b1aca9 100644
3290--- a/arch/arm/mm/Kconfig
3291+++ b/arch/arm/mm/Kconfig
3292@@ -425,7 +425,7 @@ config CPU_32v5
3293
3294 config CPU_32v6
3295 bool
3296- select CPU_USE_DOMAINS if CPU_V6 && MMU
3297+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC
3298 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3299
3300 config CPU_32v6K
3301@@ -577,6 +577,7 @@ config CPU_CP15_MPU
3302
3303 config CPU_USE_DOMAINS
3304 bool
3305+ depends on !ARM_LPAE && !PAX_KERNEXEC
3306 help
3307 This option enables or disables the use of domain switching
3308 via the set_fs() function.
3309diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3310index 5dbf13f..6393f55 100644
3311--- a/arch/arm/mm/fault.c
3312+++ b/arch/arm/mm/fault.c
3313@@ -25,6 +25,7 @@
3314 #include <asm/system_misc.h>
3315 #include <asm/system_info.h>
3316 #include <asm/tlbflush.h>
3317+#include <asm/sections.h>
3318
3319 #include "fault.h"
3320
3321@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3322 if (fixup_exception(regs))
3323 return;
3324
3325+#ifdef CONFIG_PAX_KERNEXEC
3326+ if ((fsr & FSR_WRITE) &&
3327+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3328+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3329+ {
3330+ if (current->signal->curr_ip)
3331+ 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),
3332+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
3333+ else
3334+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3335+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
3336+ }
3337+#endif
3338+
3339 /*
3340 * No handler, we'll have to terminate things with extreme prejudice.
3341 */
3342@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3343 }
3344 #endif
3345
3346+#ifdef CONFIG_PAX_PAGEEXEC
3347+ if (fsr & FSR_LNX_PF) {
3348+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3349+ do_group_exit(SIGKILL);
3350+ }
3351+#endif
3352+
3353 tsk->thread.address = addr;
3354 tsk->thread.error_code = fsr;
3355 tsk->thread.trap_no = 14;
3356@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3357 }
3358 #endif /* CONFIG_MMU */
3359
3360+#ifdef CONFIG_PAX_PAGEEXEC
3361+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3362+{
3363+ long i;
3364+
3365+ printk(KERN_ERR "PAX: bytes at PC: ");
3366+ for (i = 0; i < 20; i++) {
3367+ unsigned char c;
3368+ if (get_user(c, (__force unsigned char __user *)pc+i))
3369+ printk(KERN_CONT "?? ");
3370+ else
3371+ printk(KERN_CONT "%02x ", c);
3372+ }
3373+ printk("\n");
3374+
3375+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3376+ for (i = -1; i < 20; i++) {
3377+ unsigned long c;
3378+ if (get_user(c, (__force unsigned long __user *)sp+i))
3379+ printk(KERN_CONT "???????? ");
3380+ else
3381+ printk(KERN_CONT "%08lx ", c);
3382+ }
3383+ printk("\n");
3384+}
3385+#endif
3386+
3387 /*
3388 * First Level Translation Fault Handler
3389 *
3390@@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3391 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3392 struct siginfo info;
3393
3394+#ifdef CONFIG_PAX_MEMORY_UDEREF
3395+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3396+ if (current->signal->curr_ip)
3397+ 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),
3398+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3399+ else
3400+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3401+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3402+ goto die;
3403+ }
3404+#endif
3405+
3406 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3407 return;
3408
3409+die:
3410 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3411 inf->name, fsr, addr);
3412
3413@@ -575,9 +637,38 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3414 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3415 struct siginfo info;
3416
3417+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3418+ if (!user_mode(regs) && (is_domain_fault(ifsr) || is_xn_fault(ifsr))) {
3419+ if (current->signal->curr_ip)
3420+ 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),
3421+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3422+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3423+ else
3424+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3425+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3426+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3427+ goto die;
3428+ }
3429+#endif
3430+
3431+#ifdef CONFIG_PAX_REFCOUNT
3432+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3433+ unsigned int bkpt;
3434+
3435+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3436+ current->thread.error_code = ifsr;
3437+ current->thread.trap_no = 0;
3438+ pax_report_refcount_overflow(regs);
3439+ fixup_exception(regs);
3440+ return;
3441+ }
3442+ }
3443+#endif
3444+
3445 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3446 return;
3447
3448+die:
3449 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3450 inf->name, ifsr, addr);
3451
3452diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3453index cf08bdf..772656c 100644
3454--- a/arch/arm/mm/fault.h
3455+++ b/arch/arm/mm/fault.h
3456@@ -3,6 +3,7 @@
3457
3458 /*
3459 * Fault status register encodings. We steal bit 31 for our own purposes.
3460+ * Set when the FSR value is from an instruction fault.
3461 */
3462 #define FSR_LNX_PF (1 << 31)
3463 #define FSR_WRITE (1 << 11)
3464@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3465 }
3466 #endif
3467
3468+/* valid for LPAE and !LPAE */
3469+static inline int is_xn_fault(unsigned int fsr)
3470+{
3471+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3472+}
3473+
3474+static inline int is_domain_fault(unsigned int fsr)
3475+{
3476+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3477+}
3478+
3479 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3480 unsigned long search_exception_table(unsigned long addr);
3481
3482diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3483index ad722f1..763fdd3 100644
3484--- a/arch/arm/mm/init.c
3485+++ b/arch/arm/mm/init.c
3486@@ -30,6 +30,8 @@
3487 #include <asm/setup.h>
3488 #include <asm/tlb.h>
3489 #include <asm/fixmap.h>
3490+#include <asm/system_info.h>
3491+#include <asm/cp15.h>
3492
3493 #include <asm/mach/arch.h>
3494 #include <asm/mach/map.h>
3495@@ -736,7 +738,46 @@ void free_initmem(void)
3496 {
3497 #ifdef CONFIG_HAVE_TCM
3498 extern char __tcm_start, __tcm_end;
3499+#endif
3500
3501+#ifdef CONFIG_PAX_KERNEXEC
3502+ unsigned long addr;
3503+ pgd_t *pgd;
3504+ pud_t *pud;
3505+ pmd_t *pmd;
3506+ int cpu_arch = cpu_architecture();
3507+ unsigned int cr = get_cr();
3508+
3509+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3510+ /* make pages tables, etc before .text NX */
3511+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3512+ pgd = pgd_offset_k(addr);
3513+ pud = pud_offset(pgd, addr);
3514+ pmd = pmd_offset(pud, addr);
3515+ __section_update(pmd, addr, PMD_SECT_XN);
3516+ }
3517+ /* make init NX */
3518+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3519+ pgd = pgd_offset_k(addr);
3520+ pud = pud_offset(pgd, addr);
3521+ pmd = pmd_offset(pud, addr);
3522+ __section_update(pmd, addr, PMD_SECT_XN);
3523+ }
3524+ /* make kernel code/rodata RX */
3525+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3526+ pgd = pgd_offset_k(addr);
3527+ pud = pud_offset(pgd, addr);
3528+ pmd = pmd_offset(pud, addr);
3529+#ifdef CONFIG_ARM_LPAE
3530+ __section_update(pmd, addr, PMD_SECT_RDONLY);
3531+#else
3532+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3533+#endif
3534+ }
3535+ }
3536+#endif
3537+
3538+#ifdef CONFIG_HAVE_TCM
3539 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3540 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
3541 __phys_to_pfn(__pa(&__tcm_end)),
3542diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3543index 88fd86c..7a224ce 100644
3544--- a/arch/arm/mm/ioremap.c
3545+++ b/arch/arm/mm/ioremap.c
3546@@ -335,9 +335,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3547 unsigned int mtype;
3548
3549 if (cached)
3550- mtype = MT_MEMORY;
3551+ mtype = MT_MEMORY_RX;
3552 else
3553- mtype = MT_MEMORY_NONCACHED;
3554+ mtype = MT_MEMORY_NONCACHED_RX;
3555
3556 return __arm_ioremap_caller(phys_addr, size, mtype,
3557 __builtin_return_address(0));
3558diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3559index 10062ce..aa96dd7 100644
3560--- a/arch/arm/mm/mmap.c
3561+++ b/arch/arm/mm/mmap.c
3562@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3563 struct vm_area_struct *vma;
3564 int do_align = 0;
3565 int aliasing = cache_is_vipt_aliasing();
3566+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3567 struct vm_unmapped_area_info info;
3568
3569 /*
3570@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3571 if (len > TASK_SIZE)
3572 return -ENOMEM;
3573
3574+#ifdef CONFIG_PAX_RANDMMAP
3575+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3576+#endif
3577+
3578 if (addr) {
3579 if (do_align)
3580 addr = COLOUR_ALIGN(addr, pgoff);
3581@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3582 addr = PAGE_ALIGN(addr);
3583
3584 vma = find_vma(mm, addr);
3585- if (TASK_SIZE - len >= addr &&
3586- (!vma || addr + len <= vma->vm_start))
3587+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3588 return addr;
3589 }
3590
3591@@ -112,6 +116,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3592 unsigned long addr = addr0;
3593 int do_align = 0;
3594 int aliasing = cache_is_vipt_aliasing();
3595+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3596 struct vm_unmapped_area_info info;
3597
3598 /*
3599@@ -132,6 +137,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3600 return addr;
3601 }
3602
3603+#ifdef CONFIG_PAX_RANDMMAP
3604+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3605+#endif
3606+
3607 /* requesting a specific address */
3608 if (addr) {
3609 if (do_align)
3610@@ -139,8 +148,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3611 else
3612 addr = PAGE_ALIGN(addr);
3613 vma = find_vma(mm, addr);
3614- if (TASK_SIZE - len >= addr &&
3615- (!vma || addr + len <= vma->vm_start))
3616+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3617 return addr;
3618 }
3619
3620@@ -162,6 +170,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3621 VM_BUG_ON(addr != -ENOMEM);
3622 info.flags = 0;
3623 info.low_limit = mm->mmap_base;
3624+
3625+#ifdef CONFIG_PAX_RANDMMAP
3626+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3627+ info.low_limit += mm->delta_mmap;
3628+#endif
3629+
3630 info.high_limit = TASK_SIZE;
3631 addr = vm_unmapped_area(&info);
3632 }
3633@@ -173,6 +187,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3634 {
3635 unsigned long random_factor = 0UL;
3636
3637+#ifdef CONFIG_PAX_RANDMMAP
3638+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3639+#endif
3640+
3641 /* 8 bits of randomness in 20 address space bits */
3642 if ((current->flags & PF_RANDOMIZE) &&
3643 !(current->personality & ADDR_NO_RANDOMIZE))
3644@@ -180,10 +198,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3645
3646 if (mmap_is_legacy()) {
3647 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3648+
3649+#ifdef CONFIG_PAX_RANDMMAP
3650+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3651+ mm->mmap_base += mm->delta_mmap;
3652+#endif
3653+
3654 mm->get_unmapped_area = arch_get_unmapped_area;
3655 mm->unmap_area = arch_unmap_area;
3656 } else {
3657 mm->mmap_base = mmap_base(random_factor);
3658+
3659+#ifdef CONFIG_PAX_RANDMMAP
3660+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3661+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3662+#endif
3663+
3664 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3665 mm->unmap_area = arch_unmap_area_topdown;
3666 }
3667diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
3668index ce328c7..f82bebb 100644
3669--- a/arch/arm/mm/mmu.c
3670+++ b/arch/arm/mm/mmu.c
3671@@ -35,6 +35,23 @@
3672
3673 #include "mm.h"
3674
3675+
3676+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3677+void modify_domain(unsigned int dom, unsigned int type)
3678+{
3679+ struct thread_info *thread = current_thread_info();
3680+ unsigned int domain = thread->cpu_domain;
3681+ /*
3682+ * DOMAIN_MANAGER might be defined to some other value,
3683+ * use the arch-defined constant
3684+ */
3685+ domain &= ~domain_val(dom, 3);
3686+ thread->cpu_domain = domain | domain_val(dom, type);
3687+ set_domain(thread->cpu_domain);
3688+}
3689+EXPORT_SYMBOL(modify_domain);
3690+#endif
3691+
3692 /*
3693 * empty_zero_page is a special page that is used for
3694 * zero-initialized data and COW.
3695@@ -195,10 +212,18 @@ void adjust_cr(unsigned long mask, unsigned long set)
3696 }
3697 #endif
3698
3699-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
3700+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
3701 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
3702
3703-static struct mem_type mem_types[] = {
3704+#ifdef CONFIG_PAX_KERNEXEC
3705+#define L_PTE_KERNEXEC L_PTE_RDONLY
3706+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
3707+#else
3708+#define L_PTE_KERNEXEC L_PTE_DIRTY
3709+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
3710+#endif
3711+
3712+static struct mem_type mem_types[] __read_only = {
3713 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
3714 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
3715 L_PTE_SHARED,
3716@@ -227,16 +252,16 @@ static struct mem_type mem_types[] = {
3717 [MT_UNCACHED] = {
3718 .prot_pte = PROT_PTE_DEVICE,
3719 .prot_l1 = PMD_TYPE_TABLE,
3720- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3721+ .prot_sect = PROT_SECT_DEVICE,
3722 .domain = DOMAIN_IO,
3723 },
3724 [MT_CACHECLEAN] = {
3725- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3726+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3727 .domain = DOMAIN_KERNEL,
3728 },
3729 #ifndef CONFIG_ARM_LPAE
3730 [MT_MINICLEAN] = {
3731- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
3732+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
3733 .domain = DOMAIN_KERNEL,
3734 },
3735 #endif
3736@@ -244,36 +269,54 @@ static struct mem_type mem_types[] = {
3737 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3738 L_PTE_RDONLY,
3739 .prot_l1 = PMD_TYPE_TABLE,
3740- .domain = DOMAIN_USER,
3741+ .domain = DOMAIN_VECTORS,
3742 },
3743 [MT_HIGH_VECTORS] = {
3744 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3745 L_PTE_USER | L_PTE_RDONLY,
3746 .prot_l1 = PMD_TYPE_TABLE,
3747- .domain = DOMAIN_USER,
3748+ .domain = DOMAIN_VECTORS,
3749 },
3750- [MT_MEMORY] = {
3751+ [MT_MEMORY_RWX] = {
3752 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3753 .prot_l1 = PMD_TYPE_TABLE,
3754 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3755 .domain = DOMAIN_KERNEL,
3756 },
3757+ [MT_MEMORY_RW] = {
3758+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3759+ .prot_l1 = PMD_TYPE_TABLE,
3760+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3761+ .domain = DOMAIN_KERNEL,
3762+ },
3763+ [MT_MEMORY_RX] = {
3764+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
3765+ .prot_l1 = PMD_TYPE_TABLE,
3766+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
3767+ .domain = DOMAIN_KERNEL,
3768+ },
3769 [MT_ROM] = {
3770- .prot_sect = PMD_TYPE_SECT,
3771+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3772 .domain = DOMAIN_KERNEL,
3773 },
3774- [MT_MEMORY_NONCACHED] = {
3775+ [MT_MEMORY_NONCACHED_RW] = {
3776 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3777 L_PTE_MT_BUFFERABLE,
3778 .prot_l1 = PMD_TYPE_TABLE,
3779 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3780 .domain = DOMAIN_KERNEL,
3781 },
3782+ [MT_MEMORY_NONCACHED_RX] = {
3783+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
3784+ L_PTE_MT_BUFFERABLE,
3785+ .prot_l1 = PMD_TYPE_TABLE,
3786+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
3787+ .domain = DOMAIN_KERNEL,
3788+ },
3789 [MT_MEMORY_DTCM] = {
3790- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3791- L_PTE_XN,
3792+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3793 .prot_l1 = PMD_TYPE_TABLE,
3794- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3795+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3796 .domain = DOMAIN_KERNEL,
3797 },
3798 [MT_MEMORY_ITCM] = {
3799@@ -283,10 +326,10 @@ static struct mem_type mem_types[] = {
3800 },
3801 [MT_MEMORY_SO] = {
3802 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3803- L_PTE_MT_UNCACHED | L_PTE_XN,
3804+ L_PTE_MT_UNCACHED,
3805 .prot_l1 = PMD_TYPE_TABLE,
3806 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
3807- PMD_SECT_UNCACHED | PMD_SECT_XN,
3808+ PMD_SECT_UNCACHED,
3809 .domain = DOMAIN_KERNEL,
3810 },
3811 [MT_MEMORY_DMA_READY] = {
3812@@ -371,9 +414,35 @@ static void __init build_mem_type_table(void)
3813 * to prevent speculative instruction fetches.
3814 */
3815 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
3816+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
3817 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
3818+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
3819 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
3820+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
3821 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
3822+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
3823+
3824+ /* Mark other regions on ARMv6+ as execute-never */
3825+
3826+#ifdef CONFIG_PAX_KERNEXEC
3827+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
3828+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
3829+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
3830+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
3831+#ifndef CONFIG_ARM_LPAE
3832+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
3833+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
3834+#endif
3835+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
3836+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
3837+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
3838+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
3839+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
3840+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
3841+#endif
3842+
3843+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
3844+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
3845 }
3846 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
3847 /*
3848@@ -432,6 +501,9 @@ static void __init build_mem_type_table(void)
3849 * from SVC mode and no access from userspace.
3850 */
3851 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3852+#ifdef CONFIG_PAX_KERNEXEC
3853+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3854+#endif
3855 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3856 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3857 #endif
3858@@ -448,11 +520,17 @@ static void __init build_mem_type_table(void)
3859 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
3860 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
3861 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
3862- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
3863- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
3864+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
3865+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
3866+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
3867+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
3868+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
3869+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
3870 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
3871- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
3872- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
3873+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
3874+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
3875+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
3876+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
3877 }
3878 }
3879
3880@@ -463,15 +541,20 @@ static void __init build_mem_type_table(void)
3881 if (cpu_arch >= CPU_ARCH_ARMv6) {
3882 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
3883 /* Non-cacheable Normal is XCB = 001 */
3884- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
3885+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
3886+ PMD_SECT_BUFFERED;
3887+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
3888 PMD_SECT_BUFFERED;
3889 } else {
3890 /* For both ARMv6 and non-TEX-remapping ARMv7 */
3891- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
3892+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
3893+ PMD_SECT_TEX(1);
3894+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
3895 PMD_SECT_TEX(1);
3896 }
3897 } else {
3898- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
3899+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
3900+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
3901 }
3902
3903 #ifdef CONFIG_ARM_LPAE
3904@@ -487,6 +570,8 @@ static void __init build_mem_type_table(void)
3905 vecs_pgprot |= PTE_EXT_AF;
3906 #endif
3907
3908+ user_pgprot |= __supported_pte_mask;
3909+
3910 for (i = 0; i < 16; i++) {
3911 pteval_t v = pgprot_val(protection_map[i]);
3912 protection_map[i] = __pgprot(v | user_pgprot);
3913@@ -501,10 +586,15 @@ static void __init build_mem_type_table(void)
3914
3915 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
3916 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
3917- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
3918- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
3919+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
3920+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
3921+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
3922+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
3923+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
3924+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
3925 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
3926- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
3927+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
3928+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
3929 mem_types[MT_ROM].prot_sect |= cp->pmd;
3930
3931 switch (cp->pmd) {
3932@@ -1105,18 +1195,15 @@ void __init arm_mm_memblock_reserve(void)
3933 * called function. This means you can't use any function or debugging
3934 * method which may touch any device, otherwise the kernel _will_ crash.
3935 */
3936+
3937+static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
3938+
3939 static void __init devicemaps_init(struct machine_desc *mdesc)
3940 {
3941 struct map_desc map;
3942 unsigned long addr;
3943- void *vectors;
3944
3945- /*
3946- * Allocate the vector page early.
3947- */
3948- vectors = early_alloc(PAGE_SIZE);
3949-
3950- early_trap_init(vectors);
3951+ early_trap_init(&vectors);
3952
3953 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
3954 pmd_clear(pmd_off_k(addr));
3955@@ -1156,7 +1243,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
3956 * location (0xffff0000). If we aren't using high-vectors, also
3957 * create a mapping at the low-vectors virtual address.
3958 */
3959- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
3960+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
3961 map.virtual = 0xffff0000;
3962 map.length = PAGE_SIZE;
3963 map.type = MT_HIGH_VECTORS;
3964@@ -1214,8 +1301,39 @@ static void __init map_lowmem(void)
3965 map.pfn = __phys_to_pfn(start);
3966 map.virtual = __phys_to_virt(start);
3967 map.length = end - start;
3968- map.type = MT_MEMORY;
3969
3970+#ifdef CONFIG_PAX_KERNEXEC
3971+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
3972+ struct map_desc kernel;
3973+ struct map_desc initmap;
3974+
3975+ /* when freeing initmem we will make this RW */
3976+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
3977+ initmap.virtual = (unsigned long)__init_begin;
3978+ initmap.length = _sdata - __init_begin;
3979+ initmap.type = MT_MEMORY_RWX;
3980+ create_mapping(&initmap);
3981+
3982+ /* when freeing initmem we will make this RX */
3983+ kernel.pfn = __phys_to_pfn(__pa(_stext));
3984+ kernel.virtual = (unsigned long)_stext;
3985+ kernel.length = __init_begin - _stext;
3986+ kernel.type = MT_MEMORY_RWX;
3987+ create_mapping(&kernel);
3988+
3989+ if (map.virtual < (unsigned long)_stext) {
3990+ map.length = (unsigned long)_stext - map.virtual;
3991+ map.type = MT_MEMORY_RWX;
3992+ create_mapping(&map);
3993+ }
3994+
3995+ map.pfn = __phys_to_pfn(__pa(_sdata));
3996+ map.virtual = (unsigned long)_sdata;
3997+ map.length = end - __pa(_sdata);
3998+ }
3999+#endif
4000+
4001+ map.type = MT_MEMORY_RW;
4002 create_mapping(&map);
4003 }
4004 }
4005diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4006index 6d98c13..3cfb174 100644
4007--- a/arch/arm/mm/proc-v7-2level.S
4008+++ b/arch/arm/mm/proc-v7-2level.S
4009@@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4010 tst r1, #L_PTE_XN
4011 orrne r3, r3, #PTE_EXT_XN
4012
4013+ tst r1, #L_PTE_PXN
4014+ orrne r3, r3, #PTE_EXT_PXN
4015+
4016 tst r1, #L_PTE_YOUNG
4017 tstne r1, #L_PTE_VALID
4018 #ifndef CONFIG_CPU_USE_DOMAINS
4019diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4020index a5bc92d..0bb4730 100644
4021--- a/arch/arm/plat-omap/sram.c
4022+++ b/arch/arm/plat-omap/sram.c
4023@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4024 * Looks like we need to preserve some bootloader code at the
4025 * beginning of SRAM for jumping to flash for reboot to work...
4026 */
4027+ pax_open_kernel();
4028 memset_io(omap_sram_base + omap_sram_skip, 0,
4029 omap_sram_size - omap_sram_skip);
4030+ pax_close_kernel();
4031 }
4032diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
4033index b76c065..b6e766b 100644
4034--- a/arch/arm/plat-orion/include/plat/addr-map.h
4035+++ b/arch/arm/plat-orion/include/plat/addr-map.h
4036@@ -27,7 +27,7 @@ struct orion_addr_map_cfg {
4037 value in bridge_virt_base */
4038 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
4039 const int win);
4040-};
4041+} __no_const;
4042
4043 /*
4044 * Information needed to setup one address mapping.
4045diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4046index f5144cd..71f6d1f 100644
4047--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4048+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4049@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4050 int (*started)(unsigned ch);
4051 int (*flush)(unsigned ch);
4052 int (*stop)(unsigned ch);
4053-};
4054+} __no_const;
4055
4056 extern void *samsung_dmadev_get_ops(void);
4057 extern void *s3c_dma_get_ops(void);
4058diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4059index 0c3ba9f..95722b3 100644
4060--- a/arch/arm64/kernel/debug-monitors.c
4061+++ b/arch/arm64/kernel/debug-monitors.c
4062@@ -151,7 +151,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4063 return NOTIFY_OK;
4064 }
4065
4066-static struct notifier_block __cpuinitdata os_lock_nb = {
4067+static struct notifier_block os_lock_nb = {
4068 .notifier_call = os_lock_notify,
4069 };
4070
4071diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4072index 5ab825c..96aaec8 100644
4073--- a/arch/arm64/kernel/hw_breakpoint.c
4074+++ b/arch/arm64/kernel/hw_breakpoint.c
4075@@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4076 return NOTIFY_OK;
4077 }
4078
4079-static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4080+static struct notifier_block hw_breakpoint_reset_nb = {
4081 .notifier_call = hw_breakpoint_reset_notify,
4082 };
4083
4084diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4085index c3a58a1..78fbf54 100644
4086--- a/arch/avr32/include/asm/cache.h
4087+++ b/arch/avr32/include/asm/cache.h
4088@@ -1,8 +1,10 @@
4089 #ifndef __ASM_AVR32_CACHE_H
4090 #define __ASM_AVR32_CACHE_H
4091
4092+#include <linux/const.h>
4093+
4094 #define L1_CACHE_SHIFT 5
4095-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4096+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4097
4098 /*
4099 * Memory returned by kmalloc() may be used for DMA, so we must make
4100diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4101index e2c3287..6c4f98c 100644
4102--- a/arch/avr32/include/asm/elf.h
4103+++ b/arch/avr32/include/asm/elf.h
4104@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4105 the loader. We need to make sure that it is out of the way of the program
4106 that it will "exec", and that there is sufficient room for the brk. */
4107
4108-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4109+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4110
4111+#ifdef CONFIG_PAX_ASLR
4112+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4113+
4114+#define PAX_DELTA_MMAP_LEN 15
4115+#define PAX_DELTA_STACK_LEN 15
4116+#endif
4117
4118 /* This yields a mask that user programs can use to figure out what
4119 instruction set this CPU supports. This could be done in user space,
4120diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4121index 479330b..53717a8 100644
4122--- a/arch/avr32/include/asm/kmap_types.h
4123+++ b/arch/avr32/include/asm/kmap_types.h
4124@@ -2,9 +2,9 @@
4125 #define __ASM_AVR32_KMAP_TYPES_H
4126
4127 #ifdef CONFIG_DEBUG_HIGHMEM
4128-# define KM_TYPE_NR 29
4129+# define KM_TYPE_NR 30
4130 #else
4131-# define KM_TYPE_NR 14
4132+# define KM_TYPE_NR 15
4133 #endif
4134
4135 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4136diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4137index b2f2d2d..d1c85cb 100644
4138--- a/arch/avr32/mm/fault.c
4139+++ b/arch/avr32/mm/fault.c
4140@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4141
4142 int exception_trace = 1;
4143
4144+#ifdef CONFIG_PAX_PAGEEXEC
4145+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4146+{
4147+ unsigned long i;
4148+
4149+ printk(KERN_ERR "PAX: bytes at PC: ");
4150+ for (i = 0; i < 20; i++) {
4151+ unsigned char c;
4152+ if (get_user(c, (unsigned char *)pc+i))
4153+ printk(KERN_CONT "???????? ");
4154+ else
4155+ printk(KERN_CONT "%02x ", c);
4156+ }
4157+ printk("\n");
4158+}
4159+#endif
4160+
4161 /*
4162 * This routine handles page faults. It determines the address and the
4163 * problem, and then passes it off to one of the appropriate routines.
4164@@ -174,6 +191,16 @@ bad_area:
4165 up_read(&mm->mmap_sem);
4166
4167 if (user_mode(regs)) {
4168+
4169+#ifdef CONFIG_PAX_PAGEEXEC
4170+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4171+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4172+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4173+ do_group_exit(SIGKILL);
4174+ }
4175+ }
4176+#endif
4177+
4178 if (exception_trace && printk_ratelimit())
4179 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4180 "sp %08lx ecr %lu\n",
4181diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4182index 568885a..f8008df 100644
4183--- a/arch/blackfin/include/asm/cache.h
4184+++ b/arch/blackfin/include/asm/cache.h
4185@@ -7,6 +7,7 @@
4186 #ifndef __ARCH_BLACKFIN_CACHE_H
4187 #define __ARCH_BLACKFIN_CACHE_H
4188
4189+#include <linux/const.h>
4190 #include <linux/linkage.h> /* for asmlinkage */
4191
4192 /*
4193@@ -14,7 +15,7 @@
4194 * Blackfin loads 32 bytes for cache
4195 */
4196 #define L1_CACHE_SHIFT 5
4197-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4198+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4199 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4200
4201 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4202diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4203index aea2718..3639a60 100644
4204--- a/arch/cris/include/arch-v10/arch/cache.h
4205+++ b/arch/cris/include/arch-v10/arch/cache.h
4206@@ -1,8 +1,9 @@
4207 #ifndef _ASM_ARCH_CACHE_H
4208 #define _ASM_ARCH_CACHE_H
4209
4210+#include <linux/const.h>
4211 /* Etrax 100LX have 32-byte cache-lines. */
4212-#define L1_CACHE_BYTES 32
4213 #define L1_CACHE_SHIFT 5
4214+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4215
4216 #endif /* _ASM_ARCH_CACHE_H */
4217diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4218index 7caf25d..ee65ac5 100644
4219--- a/arch/cris/include/arch-v32/arch/cache.h
4220+++ b/arch/cris/include/arch-v32/arch/cache.h
4221@@ -1,11 +1,12 @@
4222 #ifndef _ASM_CRIS_ARCH_CACHE_H
4223 #define _ASM_CRIS_ARCH_CACHE_H
4224
4225+#include <linux/const.h>
4226 #include <arch/hwregs/dma.h>
4227
4228 /* A cache-line is 32 bytes. */
4229-#define L1_CACHE_BYTES 32
4230 #define L1_CACHE_SHIFT 5
4231+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4232
4233 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4234
4235diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4236index b86329d..6709906 100644
4237--- a/arch/frv/include/asm/atomic.h
4238+++ b/arch/frv/include/asm/atomic.h
4239@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4240 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4241 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4242
4243+#define atomic64_read_unchecked(v) atomic64_read(v)
4244+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4245+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4246+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4247+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4248+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4249+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4250+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4251+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4252+
4253 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4254 {
4255 int c, old;
4256diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4257index 2797163..c2a401d 100644
4258--- a/arch/frv/include/asm/cache.h
4259+++ b/arch/frv/include/asm/cache.h
4260@@ -12,10 +12,11 @@
4261 #ifndef __ASM_CACHE_H
4262 #define __ASM_CACHE_H
4263
4264+#include <linux/const.h>
4265
4266 /* bytes per L1 cache line */
4267 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4268-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4269+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4270
4271 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4272 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4273diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4274index 43901f2..0d8b865 100644
4275--- a/arch/frv/include/asm/kmap_types.h
4276+++ b/arch/frv/include/asm/kmap_types.h
4277@@ -2,6 +2,6 @@
4278 #ifndef _ASM_KMAP_TYPES_H
4279 #define _ASM_KMAP_TYPES_H
4280
4281-#define KM_TYPE_NR 17
4282+#define KM_TYPE_NR 18
4283
4284 #endif
4285diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4286index 385fd30..3aaf4fe 100644
4287--- a/arch/frv/mm/elf-fdpic.c
4288+++ b/arch/frv/mm/elf-fdpic.c
4289@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4290 {
4291 struct vm_area_struct *vma;
4292 unsigned long limit;
4293+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4294
4295 if (len > TASK_SIZE)
4296 return -ENOMEM;
4297@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4298 if (addr) {
4299 addr = PAGE_ALIGN(addr);
4300 vma = find_vma(current->mm, addr);
4301- if (TASK_SIZE - len >= addr &&
4302- (!vma || addr + len <= vma->vm_start))
4303+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4304 goto success;
4305 }
4306
4307@@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4308 for (; vma; vma = vma->vm_next) {
4309 if (addr > limit)
4310 break;
4311- if (addr + len <= vma->vm_start)
4312+ if (check_heap_stack_gap(vma, addr, len, offset))
4313 goto success;
4314 addr = vma->vm_end;
4315 }
4316@@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4317 for (; vma; vma = vma->vm_next) {
4318 if (addr > limit)
4319 break;
4320- if (addr + len <= vma->vm_start)
4321+ if (check_heap_stack_gap(vma, addr, len, offset))
4322 goto success;
4323 addr = vma->vm_end;
4324 }
4325diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4326index f4ca594..adc72fd6 100644
4327--- a/arch/hexagon/include/asm/cache.h
4328+++ b/arch/hexagon/include/asm/cache.h
4329@@ -21,9 +21,11 @@
4330 #ifndef __ASM_CACHE_H
4331 #define __ASM_CACHE_H
4332
4333+#include <linux/const.h>
4334+
4335 /* Bytes per L1 cache line */
4336-#define L1_CACHE_SHIFT (5)
4337-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4338+#define L1_CACHE_SHIFT 5
4339+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4340
4341 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4342 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4343diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4344index 6e6fe18..a6ae668 100644
4345--- a/arch/ia64/include/asm/atomic.h
4346+++ b/arch/ia64/include/asm/atomic.h
4347@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4348 #define atomic64_inc(v) atomic64_add(1, (v))
4349 #define atomic64_dec(v) atomic64_sub(1, (v))
4350
4351+#define atomic64_read_unchecked(v) atomic64_read(v)
4352+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4353+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4354+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4355+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4356+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4357+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4358+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4359+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4360+
4361 /* Atomic operations are already serializing */
4362 #define smp_mb__before_atomic_dec() barrier()
4363 #define smp_mb__after_atomic_dec() barrier()
4364diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4365index 988254a..e1ee885 100644
4366--- a/arch/ia64/include/asm/cache.h
4367+++ b/arch/ia64/include/asm/cache.h
4368@@ -1,6 +1,7 @@
4369 #ifndef _ASM_IA64_CACHE_H
4370 #define _ASM_IA64_CACHE_H
4371
4372+#include <linux/const.h>
4373
4374 /*
4375 * Copyright (C) 1998-2000 Hewlett-Packard Co
4376@@ -9,7 +10,7 @@
4377
4378 /* Bytes per L1 (data) cache line. */
4379 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4380-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4381+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4382
4383 #ifdef CONFIG_SMP
4384 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4385diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4386index b5298eb..67c6e62 100644
4387--- a/arch/ia64/include/asm/elf.h
4388+++ b/arch/ia64/include/asm/elf.h
4389@@ -42,6 +42,13 @@
4390 */
4391 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4392
4393+#ifdef CONFIG_PAX_ASLR
4394+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4395+
4396+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4397+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4398+#endif
4399+
4400 #define PT_IA_64_UNWIND 0x70000001
4401
4402 /* IA-64 relocations: */
4403diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4404index 96a8d92..617a1cf 100644
4405--- a/arch/ia64/include/asm/pgalloc.h
4406+++ b/arch/ia64/include/asm/pgalloc.h
4407@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4408 pgd_val(*pgd_entry) = __pa(pud);
4409 }
4410
4411+static inline void
4412+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4413+{
4414+ pgd_populate(mm, pgd_entry, pud);
4415+}
4416+
4417 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4418 {
4419 return quicklist_alloc(0, GFP_KERNEL, NULL);
4420@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4421 pud_val(*pud_entry) = __pa(pmd);
4422 }
4423
4424+static inline void
4425+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4426+{
4427+ pud_populate(mm, pud_entry, pmd);
4428+}
4429+
4430 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4431 {
4432 return quicklist_alloc(0, GFP_KERNEL, NULL);
4433diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4434index 815810c..d60bd4c 100644
4435--- a/arch/ia64/include/asm/pgtable.h
4436+++ b/arch/ia64/include/asm/pgtable.h
4437@@ -12,7 +12,7 @@
4438 * David Mosberger-Tang <davidm@hpl.hp.com>
4439 */
4440
4441-
4442+#include <linux/const.h>
4443 #include <asm/mman.h>
4444 #include <asm/page.h>
4445 #include <asm/processor.h>
4446@@ -142,6 +142,17 @@
4447 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4448 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4449 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4450+
4451+#ifdef CONFIG_PAX_PAGEEXEC
4452+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4453+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4454+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4455+#else
4456+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4457+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4458+# define PAGE_COPY_NOEXEC PAGE_COPY
4459+#endif
4460+
4461 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4462 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4463 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4464diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4465index 54ff557..70c88b7 100644
4466--- a/arch/ia64/include/asm/spinlock.h
4467+++ b/arch/ia64/include/asm/spinlock.h
4468@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4469 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4470
4471 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4472- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4473+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4474 }
4475
4476 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4477diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4478index 449c8c0..50cdf87 100644
4479--- a/arch/ia64/include/asm/uaccess.h
4480+++ b/arch/ia64/include/asm/uaccess.h
4481@@ -42,6 +42,8 @@
4482 #include <asm/pgtable.h>
4483 #include <asm/io.h>
4484
4485+extern void check_object_size(const void *ptr, unsigned long n, bool to);
4486+
4487 /*
4488 * For historical reasons, the following macros are grossly misnamed:
4489 */
4490@@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4491 static inline unsigned long
4492 __copy_to_user (void __user *to, const void *from, unsigned long count)
4493 {
4494+ if (count > INT_MAX)
4495+ return count;
4496+
4497+ if (!__builtin_constant_p(count))
4498+ check_object_size(from, count, true);
4499+
4500 return __copy_user(to, (__force void __user *) from, count);
4501 }
4502
4503 static inline unsigned long
4504 __copy_from_user (void *to, const void __user *from, unsigned long count)
4505 {
4506+ if (count > INT_MAX)
4507+ return count;
4508+
4509+ if (!__builtin_constant_p(count))
4510+ check_object_size(to, count, false);
4511+
4512 return __copy_user((__force void __user *) to, from, count);
4513 }
4514
4515@@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4516 ({ \
4517 void __user *__cu_to = (to); \
4518 const void *__cu_from = (from); \
4519- long __cu_len = (n); \
4520+ unsigned long __cu_len = (n); \
4521 \
4522- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4523+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4524+ if (!__builtin_constant_p(n)) \
4525+ check_object_size(__cu_from, __cu_len, true); \
4526 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4527+ } \
4528 __cu_len; \
4529 })
4530
4531@@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4532 ({ \
4533 void *__cu_to = (to); \
4534 const void __user *__cu_from = (from); \
4535- long __cu_len = (n); \
4536+ unsigned long __cu_len = (n); \
4537 \
4538 __chk_user_ptr(__cu_from); \
4539- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4540+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4541+ if (!__builtin_constant_p(n)) \
4542+ check_object_size(__cu_to, __cu_len, false); \
4543 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4544+ } \
4545 __cu_len; \
4546 })
4547
4548diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4549index 2d67317..07d8bfa 100644
4550--- a/arch/ia64/kernel/err_inject.c
4551+++ b/arch/ia64/kernel/err_inject.c
4552@@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4553 return NOTIFY_OK;
4554 }
4555
4556-static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4557+static struct notifier_block err_inject_cpu_notifier =
4558 {
4559 .notifier_call = err_inject_cpu_callback,
4560 };
4561diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4562index 65bf9cd..794f06b 100644
4563--- a/arch/ia64/kernel/mca.c
4564+++ b/arch/ia64/kernel/mca.c
4565@@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4566 return NOTIFY_OK;
4567 }
4568
4569-static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4570+static struct notifier_block mca_cpu_notifier = {
4571 .notifier_call = mca_cpu_callback
4572 };
4573
4574diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4575index 24603be..948052d 100644
4576--- a/arch/ia64/kernel/module.c
4577+++ b/arch/ia64/kernel/module.c
4578@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4579 void
4580 module_free (struct module *mod, void *module_region)
4581 {
4582- if (mod && mod->arch.init_unw_table &&
4583- module_region == mod->module_init) {
4584+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4585 unw_remove_unwind_table(mod->arch.init_unw_table);
4586 mod->arch.init_unw_table = NULL;
4587 }
4588@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4589 }
4590
4591 static inline int
4592+in_init_rx (const struct module *mod, uint64_t addr)
4593+{
4594+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4595+}
4596+
4597+static inline int
4598+in_init_rw (const struct module *mod, uint64_t addr)
4599+{
4600+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4601+}
4602+
4603+static inline int
4604 in_init (const struct module *mod, uint64_t addr)
4605 {
4606- return addr - (uint64_t) mod->module_init < mod->init_size;
4607+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4608+}
4609+
4610+static inline int
4611+in_core_rx (const struct module *mod, uint64_t addr)
4612+{
4613+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4614+}
4615+
4616+static inline int
4617+in_core_rw (const struct module *mod, uint64_t addr)
4618+{
4619+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4620 }
4621
4622 static inline int
4623 in_core (const struct module *mod, uint64_t addr)
4624 {
4625- return addr - (uint64_t) mod->module_core < mod->core_size;
4626+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4627 }
4628
4629 static inline int
4630@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4631 break;
4632
4633 case RV_BDREL:
4634- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4635+ if (in_init_rx(mod, val))
4636+ val -= (uint64_t) mod->module_init_rx;
4637+ else if (in_init_rw(mod, val))
4638+ val -= (uint64_t) mod->module_init_rw;
4639+ else if (in_core_rx(mod, val))
4640+ val -= (uint64_t) mod->module_core_rx;
4641+ else if (in_core_rw(mod, val))
4642+ val -= (uint64_t) mod->module_core_rw;
4643 break;
4644
4645 case RV_LTV:
4646@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4647 * addresses have been selected...
4648 */
4649 uint64_t gp;
4650- if (mod->core_size > MAX_LTOFF)
4651+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4652 /*
4653 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4654 * at the end of the module.
4655 */
4656- gp = mod->core_size - MAX_LTOFF / 2;
4657+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4658 else
4659- gp = mod->core_size / 2;
4660- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4661+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4662+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4663 mod->arch.gp = gp;
4664 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4665 }
4666diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4667index 77597e5..6f28f3f 100644
4668--- a/arch/ia64/kernel/palinfo.c
4669+++ b/arch/ia64/kernel/palinfo.c
4670@@ -1045,7 +1045,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4671 return NOTIFY_OK;
4672 }
4673
4674-static struct notifier_block __refdata palinfo_cpu_notifier =
4675+static struct notifier_block palinfo_cpu_notifier =
4676 {
4677 .notifier_call = palinfo_cpu_callback,
4678 .priority = 0,
4679diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4680index 79802e5..1a89ec5 100644
4681--- a/arch/ia64/kernel/salinfo.c
4682+++ b/arch/ia64/kernel/salinfo.c
4683@@ -616,7 +616,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4684 return NOTIFY_OK;
4685 }
4686
4687-static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
4688+static struct notifier_block salinfo_cpu_notifier =
4689 {
4690 .notifier_call = salinfo_cpu_callback,
4691 .priority = 0,
4692diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
4693index d9439ef..d0cac6b 100644
4694--- a/arch/ia64/kernel/sys_ia64.c
4695+++ b/arch/ia64/kernel/sys_ia64.c
4696@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4697 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
4698 struct mm_struct *mm = current->mm;
4699 struct vm_area_struct *vma;
4700+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4701
4702 if (len > RGN_MAP_LIMIT)
4703 return -ENOMEM;
4704@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4705 if (REGION_NUMBER(addr) == RGN_HPAGE)
4706 addr = 0;
4707 #endif
4708+
4709+#ifdef CONFIG_PAX_RANDMMAP
4710+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4711+ addr = mm->free_area_cache;
4712+ else
4713+#endif
4714+
4715 if (!addr)
4716 addr = mm->free_area_cache;
4717
4718@@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4719 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
4720 /* At this point: (!vma || addr < vma->vm_end). */
4721 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
4722- if (start_addr != TASK_UNMAPPED_BASE) {
4723+ if (start_addr != mm->mmap_base) {
4724 /* Start a new search --- just in case we missed some holes. */
4725- addr = TASK_UNMAPPED_BASE;
4726+ addr = mm->mmap_base;
4727 goto full_search;
4728 }
4729 return -ENOMEM;
4730 }
4731- if (!vma || addr + len <= vma->vm_start) {
4732+ if (check_heap_stack_gap(vma, addr, len, offset)) {
4733 /* Remember the address where we stopped this search: */
4734 mm->free_area_cache = addr + len;
4735 return addr;
4736diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
4737index dc00b2c..cce53c2 100644
4738--- a/arch/ia64/kernel/topology.c
4739+++ b/arch/ia64/kernel/topology.c
4740@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
4741 return NOTIFY_OK;
4742 }
4743
4744-static struct notifier_block __cpuinitdata cache_cpu_notifier =
4745+static struct notifier_block cache_cpu_notifier =
4746 {
4747 .notifier_call = cache_cpu_callback
4748 };
4749diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
4750index 0ccb28f..8992469 100644
4751--- a/arch/ia64/kernel/vmlinux.lds.S
4752+++ b/arch/ia64/kernel/vmlinux.lds.S
4753@@ -198,7 +198,7 @@ SECTIONS {
4754 /* Per-cpu data: */
4755 . = ALIGN(PERCPU_PAGE_SIZE);
4756 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
4757- __phys_per_cpu_start = __per_cpu_load;
4758+ __phys_per_cpu_start = per_cpu_load;
4759 /*
4760 * ensure percpu data fits
4761 * into percpu page size
4762diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
4763index 6cf0341..d352594 100644
4764--- a/arch/ia64/mm/fault.c
4765+++ b/arch/ia64/mm/fault.c
4766@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
4767 return pte_present(pte);
4768 }
4769
4770+#ifdef CONFIG_PAX_PAGEEXEC
4771+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4772+{
4773+ unsigned long i;
4774+
4775+ printk(KERN_ERR "PAX: bytes at PC: ");
4776+ for (i = 0; i < 8; i++) {
4777+ unsigned int c;
4778+ if (get_user(c, (unsigned int *)pc+i))
4779+ printk(KERN_CONT "???????? ");
4780+ else
4781+ printk(KERN_CONT "%08x ", c);
4782+ }
4783+ printk("\n");
4784+}
4785+#endif
4786+
4787 # define VM_READ_BIT 0
4788 # define VM_WRITE_BIT 1
4789 # define VM_EXEC_BIT 2
4790@@ -149,8 +166,21 @@ retry:
4791 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
4792 goto bad_area;
4793
4794- if ((vma->vm_flags & mask) != mask)
4795+ if ((vma->vm_flags & mask) != mask) {
4796+
4797+#ifdef CONFIG_PAX_PAGEEXEC
4798+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
4799+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
4800+ goto bad_area;
4801+
4802+ up_read(&mm->mmap_sem);
4803+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
4804+ do_group_exit(SIGKILL);
4805+ }
4806+#endif
4807+
4808 goto bad_area;
4809+ }
4810
4811 /*
4812 * If for any reason at all we couldn't handle the fault, make
4813diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
4814index 5ca674b..127c3cb 100644
4815--- a/arch/ia64/mm/hugetlbpage.c
4816+++ b/arch/ia64/mm/hugetlbpage.c
4817@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
4818 unsigned long pgoff, unsigned long flags)
4819 {
4820 struct vm_area_struct *vmm;
4821+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
4822
4823 if (len > RGN_MAP_LIMIT)
4824 return -ENOMEM;
4825@@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
4826 /* At this point: (!vmm || addr < vmm->vm_end). */
4827 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
4828 return -ENOMEM;
4829- if (!vmm || (addr + len) <= vmm->vm_start)
4830+ if (check_heap_stack_gap(vmm, addr, len, offset))
4831 return addr;
4832 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
4833 }
4834diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
4835index b755ea9..b9a969e 100644
4836--- a/arch/ia64/mm/init.c
4837+++ b/arch/ia64/mm/init.c
4838@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
4839 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
4840 vma->vm_end = vma->vm_start + PAGE_SIZE;
4841 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
4842+
4843+#ifdef CONFIG_PAX_PAGEEXEC
4844+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
4845+ vma->vm_flags &= ~VM_EXEC;
4846+
4847+#ifdef CONFIG_PAX_MPROTECT
4848+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
4849+ vma->vm_flags &= ~VM_MAYEXEC;
4850+#endif
4851+
4852+ }
4853+#endif
4854+
4855 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4856 down_write(&current->mm->mmap_sem);
4857 if (insert_vm_struct(current->mm, vma)) {
4858diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
4859index 40b3ee9..8c2c112 100644
4860--- a/arch/m32r/include/asm/cache.h
4861+++ b/arch/m32r/include/asm/cache.h
4862@@ -1,8 +1,10 @@
4863 #ifndef _ASM_M32R_CACHE_H
4864 #define _ASM_M32R_CACHE_H
4865
4866+#include <linux/const.h>
4867+
4868 /* L1 cache line size */
4869 #define L1_CACHE_SHIFT 4
4870-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4871+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4872
4873 #endif /* _ASM_M32R_CACHE_H */
4874diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
4875index 82abd15..d95ae5d 100644
4876--- a/arch/m32r/lib/usercopy.c
4877+++ b/arch/m32r/lib/usercopy.c
4878@@ -14,6 +14,9 @@
4879 unsigned long
4880 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
4881 {
4882+ if ((long)n < 0)
4883+ return n;
4884+
4885 prefetch(from);
4886 if (access_ok(VERIFY_WRITE, to, n))
4887 __copy_user(to,from,n);
4888@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
4889 unsigned long
4890 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
4891 {
4892+ if ((long)n < 0)
4893+ return n;
4894+
4895 prefetchw(to);
4896 if (access_ok(VERIFY_READ, from, n))
4897 __copy_user_zeroing(to,from,n);
4898diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
4899index 0395c51..5f26031 100644
4900--- a/arch/m68k/include/asm/cache.h
4901+++ b/arch/m68k/include/asm/cache.h
4902@@ -4,9 +4,11 @@
4903 #ifndef __ARCH_M68K_CACHE_H
4904 #define __ARCH_M68K_CACHE_H
4905
4906+#include <linux/const.h>
4907+
4908 /* bytes per L1 cache line */
4909 #define L1_CACHE_SHIFT 4
4910-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
4911+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4912
4913 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4914
4915diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
4916index 4efe96a..60e8699 100644
4917--- a/arch/microblaze/include/asm/cache.h
4918+++ b/arch/microblaze/include/asm/cache.h
4919@@ -13,11 +13,12 @@
4920 #ifndef _ASM_MICROBLAZE_CACHE_H
4921 #define _ASM_MICROBLAZE_CACHE_H
4922
4923+#include <linux/const.h>
4924 #include <asm/registers.h>
4925
4926 #define L1_CACHE_SHIFT 5
4927 /* word-granular cache in microblaze */
4928-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4929+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4930
4931 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4932
4933diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
4934index 01cc6ba..bcb7a5d 100644
4935--- a/arch/mips/include/asm/atomic.h
4936+++ b/arch/mips/include/asm/atomic.h
4937@@ -21,6 +21,10 @@
4938 #include <asm/cmpxchg.h>
4939 #include <asm/war.h>
4940
4941+#ifdef CONFIG_GENERIC_ATOMIC64
4942+#include <asm-generic/atomic64.h>
4943+#endif
4944+
4945 #define ATOMIC_INIT(i) { (i) }
4946
4947 /*
4948@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
4949 */
4950 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
4951
4952+#define atomic64_read_unchecked(v) atomic64_read(v)
4953+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4954+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4955+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4956+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4957+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4958+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4959+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4960+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4961+
4962 #endif /* CONFIG_64BIT */
4963
4964 /*
4965diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
4966index b4db69f..8f3b093 100644
4967--- a/arch/mips/include/asm/cache.h
4968+++ b/arch/mips/include/asm/cache.h
4969@@ -9,10 +9,11 @@
4970 #ifndef _ASM_CACHE_H
4971 #define _ASM_CACHE_H
4972
4973+#include <linux/const.h>
4974 #include <kmalloc.h>
4975
4976 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
4977-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4978+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4979
4980 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4981 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4982diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
4983index 455c0ac..ad65fbe 100644
4984--- a/arch/mips/include/asm/elf.h
4985+++ b/arch/mips/include/asm/elf.h
4986@@ -372,13 +372,16 @@ extern const char *__elf_platform;
4987 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4988 #endif
4989
4990+#ifdef CONFIG_PAX_ASLR
4991+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
4992+
4993+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
4994+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
4995+#endif
4996+
4997 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4998 struct linux_binprm;
4999 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5000 int uses_interp);
5001
5002-struct mm_struct;
5003-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5004-#define arch_randomize_brk arch_randomize_brk
5005-
5006 #endif /* _ASM_ELF_H */
5007diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5008index c1f6afa..38cc6e9 100644
5009--- a/arch/mips/include/asm/exec.h
5010+++ b/arch/mips/include/asm/exec.h
5011@@ -12,6 +12,6 @@
5012 #ifndef _ASM_EXEC_H
5013 #define _ASM_EXEC_H
5014
5015-extern unsigned long arch_align_stack(unsigned long sp);
5016+#define arch_align_stack(x) ((x) & ~0xfUL)
5017
5018 #endif /* _ASM_EXEC_H */
5019diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5020index dbaec94..6a14935 100644
5021--- a/arch/mips/include/asm/page.h
5022+++ b/arch/mips/include/asm/page.h
5023@@ -96,7 +96,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5024 #ifdef CONFIG_CPU_MIPS32
5025 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5026 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5027- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5028+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5029 #else
5030 typedef struct { unsigned long long pte; } pte_t;
5031 #define pte_val(x) ((x).pte)
5032diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5033index 881d18b..cea38bc 100644
5034--- a/arch/mips/include/asm/pgalloc.h
5035+++ b/arch/mips/include/asm/pgalloc.h
5036@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5037 {
5038 set_pud(pud, __pud((unsigned long)pmd));
5039 }
5040+
5041+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5042+{
5043+ pud_populate(mm, pud, pmd);
5044+}
5045 #endif
5046
5047 /*
5048diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5049index b2050b9..d71bb1b 100644
5050--- a/arch/mips/include/asm/thread_info.h
5051+++ b/arch/mips/include/asm/thread_info.h
5052@@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
5053 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5054 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5055 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5056+/* li takes a 32bit immediate */
5057+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5058 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5059
5060 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5061@@ -126,15 +128,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
5062 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5063 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5064 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5065+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5066+
5067+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5068
5069 /* work to do in syscall_trace_leave() */
5070-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5071+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5072
5073 /* work to do on interrupt/exception return */
5074 #define _TIF_WORK_MASK \
5075 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5076 /* work to do on any return to u-space */
5077-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5078+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5079
5080 #endif /* __KERNEL__ */
5081
5082diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5083index 9fdd8bc..4bd7f1a 100644
5084--- a/arch/mips/kernel/binfmt_elfn32.c
5085+++ b/arch/mips/kernel/binfmt_elfn32.c
5086@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5087 #undef ELF_ET_DYN_BASE
5088 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5089
5090+#ifdef CONFIG_PAX_ASLR
5091+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5092+
5093+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5094+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5095+#endif
5096+
5097 #include <asm/processor.h>
5098 #include <linux/module.h>
5099 #include <linux/elfcore.h>
5100diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5101index ff44823..97f8906 100644
5102--- a/arch/mips/kernel/binfmt_elfo32.c
5103+++ b/arch/mips/kernel/binfmt_elfo32.c
5104@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5105 #undef ELF_ET_DYN_BASE
5106 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5107
5108+#ifdef CONFIG_PAX_ASLR
5109+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5110+
5111+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5112+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5113+#endif
5114+
5115 #include <asm/processor.h>
5116
5117 /*
5118diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5119index a11c6f9..be5e164 100644
5120--- a/arch/mips/kernel/process.c
5121+++ b/arch/mips/kernel/process.c
5122@@ -460,15 +460,3 @@ unsigned long get_wchan(struct task_struct *task)
5123 out:
5124 return pc;
5125 }
5126-
5127-/*
5128- * Don't forget that the stack pointer must be aligned on a 8 bytes
5129- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5130- */
5131-unsigned long arch_align_stack(unsigned long sp)
5132-{
5133- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5134- sp -= get_random_int() & ~PAGE_MASK;
5135-
5136- return sp & ALMASK;
5137-}
5138diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5139index 4812c6d..2069554 100644
5140--- a/arch/mips/kernel/ptrace.c
5141+++ b/arch/mips/kernel/ptrace.c
5142@@ -528,6 +528,10 @@ static inline int audit_arch(void)
5143 return arch;
5144 }
5145
5146+#ifdef CONFIG_GRKERNSEC_SETXID
5147+extern void gr_delayed_cred_worker(void);
5148+#endif
5149+
5150 /*
5151 * Notification of system call entry/exit
5152 * - triggered by current->work.syscall_trace
5153@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5154 /* do the secure computing check first */
5155 secure_computing_strict(regs->regs[2]);
5156
5157+#ifdef CONFIG_GRKERNSEC_SETXID
5158+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5159+ gr_delayed_cred_worker();
5160+#endif
5161+
5162 if (!(current->ptrace & PT_PTRACED))
5163 goto out;
5164
5165diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5166index d20a4bc..7096ae5 100644
5167--- a/arch/mips/kernel/scall32-o32.S
5168+++ b/arch/mips/kernel/scall32-o32.S
5169@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5170
5171 stack_done:
5172 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5173- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5174+ li t1, _TIF_SYSCALL_WORK
5175 and t0, t1
5176 bnez t0, syscall_trace_entry # -> yes
5177
5178diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5179index b64f642..0fe6eab 100644
5180--- a/arch/mips/kernel/scall64-64.S
5181+++ b/arch/mips/kernel/scall64-64.S
5182@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5183
5184 sd a3, PT_R26(sp) # save a3 for syscall restarting
5185
5186- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5187+ li t1, _TIF_SYSCALL_WORK
5188 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5189 and t0, t1, t0
5190 bnez t0, syscall_trace_entry
5191diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5192index c29ac19..c592d05 100644
5193--- a/arch/mips/kernel/scall64-n32.S
5194+++ b/arch/mips/kernel/scall64-n32.S
5195@@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5196
5197 sd a3, PT_R26(sp) # save a3 for syscall restarting
5198
5199- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5200+ li t1, _TIF_SYSCALL_WORK
5201 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5202 and t0, t1, t0
5203 bnez t0, n32_syscall_trace_entry
5204diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5205index cf3e75e..72e93fe 100644
5206--- a/arch/mips/kernel/scall64-o32.S
5207+++ b/arch/mips/kernel/scall64-o32.S
5208@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5209 PTR 4b, bad_stack
5210 .previous
5211
5212- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5213+ li t1, _TIF_SYSCALL_WORK
5214 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5215 and t0, t1, t0
5216 bnez t0, trace_a_syscall
5217diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5218index ddcec1e..c7f983e 100644
5219--- a/arch/mips/mm/fault.c
5220+++ b/arch/mips/mm/fault.c
5221@@ -27,6 +27,23 @@
5222 #include <asm/highmem.h> /* For VMALLOC_END */
5223 #include <linux/kdebug.h>
5224
5225+#ifdef CONFIG_PAX_PAGEEXEC
5226+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5227+{
5228+ unsigned long i;
5229+
5230+ printk(KERN_ERR "PAX: bytes at PC: ");
5231+ for (i = 0; i < 5; i++) {
5232+ unsigned int c;
5233+ if (get_user(c, (unsigned int *)pc+i))
5234+ printk(KERN_CONT "???????? ");
5235+ else
5236+ printk(KERN_CONT "%08x ", c);
5237+ }
5238+ printk("\n");
5239+}
5240+#endif
5241+
5242 /*
5243 * This routine handles page faults. It determines the address,
5244 * and the problem, and then passes it off to one of the appropriate
5245diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5246index 7e5fe27..479a219 100644
5247--- a/arch/mips/mm/mmap.c
5248+++ b/arch/mips/mm/mmap.c
5249@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5250 struct vm_area_struct *vma;
5251 unsigned long addr = addr0;
5252 int do_color_align;
5253+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5254 struct vm_unmapped_area_info info;
5255
5256 if (unlikely(len > TASK_SIZE))
5257@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5258 do_color_align = 1;
5259
5260 /* requesting a specific address */
5261+
5262+#ifdef CONFIG_PAX_RANDMMAP
5263+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5264+#endif
5265+
5266 if (addr) {
5267 if (do_color_align)
5268 addr = COLOUR_ALIGN(addr, pgoff);
5269@@ -91,8 +97,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5270 addr = PAGE_ALIGN(addr);
5271
5272 vma = find_vma(mm, addr);
5273- if (TASK_SIZE - len >= addr &&
5274- (!vma || addr + len <= vma->vm_start))
5275+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5276 return addr;
5277 }
5278
5279@@ -146,6 +151,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5280 {
5281 unsigned long random_factor = 0UL;
5282
5283+#ifdef CONFIG_PAX_RANDMMAP
5284+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5285+#endif
5286+
5287 if (current->flags & PF_RANDOMIZE) {
5288 random_factor = get_random_int();
5289 random_factor = random_factor << PAGE_SHIFT;
5290@@ -157,42 +166,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5291
5292 if (mmap_is_legacy()) {
5293 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5294+
5295+#ifdef CONFIG_PAX_RANDMMAP
5296+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5297+ mm->mmap_base += mm->delta_mmap;
5298+#endif
5299+
5300 mm->get_unmapped_area = arch_get_unmapped_area;
5301 mm->unmap_area = arch_unmap_area;
5302 } else {
5303 mm->mmap_base = mmap_base(random_factor);
5304+
5305+#ifdef CONFIG_PAX_RANDMMAP
5306+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5307+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5308+#endif
5309+
5310 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5311 mm->unmap_area = arch_unmap_area_topdown;
5312 }
5313 }
5314
5315-static inline unsigned long brk_rnd(void)
5316-{
5317- unsigned long rnd = get_random_int();
5318-
5319- rnd = rnd << PAGE_SHIFT;
5320- /* 8MB for 32bit, 256MB for 64bit */
5321- if (TASK_IS_32BIT_ADDR)
5322- rnd = rnd & 0x7ffffful;
5323- else
5324- rnd = rnd & 0xffffffful;
5325-
5326- return rnd;
5327-}
5328-
5329-unsigned long arch_randomize_brk(struct mm_struct *mm)
5330-{
5331- unsigned long base = mm->brk;
5332- unsigned long ret;
5333-
5334- ret = PAGE_ALIGN(base + brk_rnd());
5335-
5336- if (ret < mm->brk)
5337- return mm->brk;
5338-
5339- return ret;
5340-}
5341-
5342 int __virt_addr_valid(const volatile void *kaddr)
5343 {
5344 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5345diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5346index 967d144..db12197 100644
5347--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5348+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5349@@ -11,12 +11,14 @@
5350 #ifndef _ASM_PROC_CACHE_H
5351 #define _ASM_PROC_CACHE_H
5352
5353+#include <linux/const.h>
5354+
5355 /* L1 cache */
5356
5357 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5358 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5359-#define L1_CACHE_BYTES 16 /* bytes per entry */
5360 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5361+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5362 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5363
5364 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5365diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5366index bcb5df2..84fabd2 100644
5367--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5368+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5369@@ -16,13 +16,15 @@
5370 #ifndef _ASM_PROC_CACHE_H
5371 #define _ASM_PROC_CACHE_H
5372
5373+#include <linux/const.h>
5374+
5375 /*
5376 * L1 cache
5377 */
5378 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5379 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5380-#define L1_CACHE_BYTES 32 /* bytes per entry */
5381 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5382+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5383 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5384
5385 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5386diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5387index 4ce7a01..449202a 100644
5388--- a/arch/openrisc/include/asm/cache.h
5389+++ b/arch/openrisc/include/asm/cache.h
5390@@ -19,11 +19,13 @@
5391 #ifndef __ASM_OPENRISC_CACHE_H
5392 #define __ASM_OPENRISC_CACHE_H
5393
5394+#include <linux/const.h>
5395+
5396 /* FIXME: How can we replace these with values from the CPU...
5397 * they shouldn't be hard-coded!
5398 */
5399
5400-#define L1_CACHE_BYTES 16
5401 #define L1_CACHE_SHIFT 4
5402+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5403
5404 #endif /* __ASM_OPENRISC_CACHE_H */
5405diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5406index af9cf30..2aae9b2 100644
5407--- a/arch/parisc/include/asm/atomic.h
5408+++ b/arch/parisc/include/asm/atomic.h
5409@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5410
5411 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5412
5413+#define atomic64_read_unchecked(v) atomic64_read(v)
5414+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5415+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5416+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5417+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5418+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5419+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5420+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5421+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5422+
5423 #endif /* !CONFIG_64BIT */
5424
5425
5426diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5427index 47f11c7..3420df2 100644
5428--- a/arch/parisc/include/asm/cache.h
5429+++ b/arch/parisc/include/asm/cache.h
5430@@ -5,6 +5,7 @@
5431 #ifndef __ARCH_PARISC_CACHE_H
5432 #define __ARCH_PARISC_CACHE_H
5433
5434+#include <linux/const.h>
5435
5436 /*
5437 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5438@@ -15,13 +16,13 @@
5439 * just ruin performance.
5440 */
5441 #ifdef CONFIG_PA20
5442-#define L1_CACHE_BYTES 64
5443 #define L1_CACHE_SHIFT 6
5444 #else
5445-#define L1_CACHE_BYTES 32
5446 #define L1_CACHE_SHIFT 5
5447 #endif
5448
5449+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5450+
5451 #ifndef __ASSEMBLY__
5452
5453 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5454diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5455index 19f6cb1..6c78cf2 100644
5456--- a/arch/parisc/include/asm/elf.h
5457+++ b/arch/parisc/include/asm/elf.h
5458@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5459
5460 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5461
5462+#ifdef CONFIG_PAX_ASLR
5463+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5464+
5465+#define PAX_DELTA_MMAP_LEN 16
5466+#define PAX_DELTA_STACK_LEN 16
5467+#endif
5468+
5469 /* This yields a mask that user programs can use to figure out what
5470 instruction set this CPU supports. This could be done in user space,
5471 but it's not easy, and we've already done it here. */
5472diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5473index fc987a1..6e068ef 100644
5474--- a/arch/parisc/include/asm/pgalloc.h
5475+++ b/arch/parisc/include/asm/pgalloc.h
5476@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5477 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5478 }
5479
5480+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5481+{
5482+ pgd_populate(mm, pgd, pmd);
5483+}
5484+
5485 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5486 {
5487 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5488@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5489 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5490 #define pmd_free(mm, x) do { } while (0)
5491 #define pgd_populate(mm, pmd, pte) BUG()
5492+#define pgd_populate_kernel(mm, pmd, pte) BUG()
5493
5494 #endif
5495
5496diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5497index ee99f23..802b0a1 100644
5498--- a/arch/parisc/include/asm/pgtable.h
5499+++ b/arch/parisc/include/asm/pgtable.h
5500@@ -212,6 +212,17 @@ struct vm_area_struct;
5501 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5502 #define PAGE_COPY PAGE_EXECREAD
5503 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5504+
5505+#ifdef CONFIG_PAX_PAGEEXEC
5506+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5507+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5508+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5509+#else
5510+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5511+# define PAGE_COPY_NOEXEC PAGE_COPY
5512+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5513+#endif
5514+
5515 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5516 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5517 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5518diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5519index 4ba2c93..f5e3974 100644
5520--- a/arch/parisc/include/asm/uaccess.h
5521+++ b/arch/parisc/include/asm/uaccess.h
5522@@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5523 const void __user *from,
5524 unsigned long n)
5525 {
5526- int sz = __compiletime_object_size(to);
5527+ size_t sz = __compiletime_object_size(to);
5528 int ret = -EFAULT;
5529
5530- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5531+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5532 ret = __copy_from_user(to, from, n);
5533 else
5534 copy_from_user_overflow();
5535diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5536index 2a625fb..9908930 100644
5537--- a/arch/parisc/kernel/module.c
5538+++ b/arch/parisc/kernel/module.c
5539@@ -98,16 +98,38 @@
5540
5541 /* three functions to determine where in the module core
5542 * or init pieces the location is */
5543+static inline int in_init_rx(struct module *me, void *loc)
5544+{
5545+ return (loc >= me->module_init_rx &&
5546+ loc < (me->module_init_rx + me->init_size_rx));
5547+}
5548+
5549+static inline int in_init_rw(struct module *me, void *loc)
5550+{
5551+ return (loc >= me->module_init_rw &&
5552+ loc < (me->module_init_rw + me->init_size_rw));
5553+}
5554+
5555 static inline int in_init(struct module *me, void *loc)
5556 {
5557- return (loc >= me->module_init &&
5558- loc <= (me->module_init + me->init_size));
5559+ return in_init_rx(me, loc) || in_init_rw(me, loc);
5560+}
5561+
5562+static inline int in_core_rx(struct module *me, void *loc)
5563+{
5564+ return (loc >= me->module_core_rx &&
5565+ loc < (me->module_core_rx + me->core_size_rx));
5566+}
5567+
5568+static inline int in_core_rw(struct module *me, void *loc)
5569+{
5570+ return (loc >= me->module_core_rw &&
5571+ loc < (me->module_core_rw + me->core_size_rw));
5572 }
5573
5574 static inline int in_core(struct module *me, void *loc)
5575 {
5576- return (loc >= me->module_core &&
5577- loc <= (me->module_core + me->core_size));
5578+ return in_core_rx(me, loc) || in_core_rw(me, loc);
5579 }
5580
5581 static inline int in_local(struct module *me, void *loc)
5582@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5583 }
5584
5585 /* align things a bit */
5586- me->core_size = ALIGN(me->core_size, 16);
5587- me->arch.got_offset = me->core_size;
5588- me->core_size += gots * sizeof(struct got_entry);
5589+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5590+ me->arch.got_offset = me->core_size_rw;
5591+ me->core_size_rw += gots * sizeof(struct got_entry);
5592
5593- me->core_size = ALIGN(me->core_size, 16);
5594- me->arch.fdesc_offset = me->core_size;
5595- me->core_size += fdescs * sizeof(Elf_Fdesc);
5596+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5597+ me->arch.fdesc_offset = me->core_size_rw;
5598+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5599
5600 me->arch.got_max = gots;
5601 me->arch.fdesc_max = fdescs;
5602@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5603
5604 BUG_ON(value == 0);
5605
5606- got = me->module_core + me->arch.got_offset;
5607+ got = me->module_core_rw + me->arch.got_offset;
5608 for (i = 0; got[i].addr; i++)
5609 if (got[i].addr == value)
5610 goto out;
5611@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5612 #ifdef CONFIG_64BIT
5613 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5614 {
5615- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5616+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5617
5618 if (!value) {
5619 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5620@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5621
5622 /* Create new one */
5623 fdesc->addr = value;
5624- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5625+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5626 return (Elf_Addr)fdesc;
5627 }
5628 #endif /* CONFIG_64BIT */
5629@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5630
5631 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5632 end = table + sechdrs[me->arch.unwind_section].sh_size;
5633- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5634+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5635
5636 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5637 me->arch.unwind_section, table, end, gp);
5638diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5639index f76c108..92bad82 100644
5640--- a/arch/parisc/kernel/sys_parisc.c
5641+++ b/arch/parisc/kernel/sys_parisc.c
5642@@ -33,9 +33,11 @@
5643 #include <linux/utsname.h>
5644 #include <linux/personality.h>
5645
5646-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5647+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5648+ unsigned long flags)
5649 {
5650 struct vm_area_struct *vma;
5651+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5652
5653 addr = PAGE_ALIGN(addr);
5654
5655@@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5656 /* At this point: (!vma || addr < vma->vm_end). */
5657 if (TASK_SIZE - len < addr)
5658 return -ENOMEM;
5659- if (!vma || addr + len <= vma->vm_start)
5660+ if (check_heap_stack_gap(vma, addr, len, offset))
5661 return addr;
5662 addr = vma->vm_end;
5663 }
5664@@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
5665 return offset & 0x3FF000;
5666 }
5667
5668-static unsigned long get_shared_area(struct address_space *mapping,
5669- unsigned long addr, unsigned long len, unsigned long pgoff)
5670+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5671+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5672 {
5673 struct vm_area_struct *vma;
5674 int offset = mapping ? get_offset(mapping) : 0;
5675+ unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5676
5677 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
5678
5679@@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5680 /* At this point: (!vma || addr < vma->vm_end). */
5681 if (TASK_SIZE - len < addr)
5682 return -ENOMEM;
5683- if (!vma || addr + len <= vma->vm_start)
5684+ if (check_heap_stack_gap(vma, addr, len, rand_offset))
5685 return addr;
5686 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
5687 if (addr < vma->vm_end) /* handle wraparound */
5688@@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5689 if (flags & MAP_FIXED)
5690 return addr;
5691 if (!addr)
5692- addr = TASK_UNMAPPED_BASE;
5693+ addr = current->mm->mmap_base;
5694
5695 if (filp) {
5696- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
5697+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
5698 } else if(flags & MAP_SHARED) {
5699- addr = get_shared_area(NULL, addr, len, pgoff);
5700+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
5701 } else {
5702- addr = get_unshared_area(addr, len);
5703+ addr = get_unshared_area(filp, addr, len, flags);
5704 }
5705 return addr;
5706 }
5707diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
5708index 45ba99f..8e22c33 100644
5709--- a/arch/parisc/kernel/traps.c
5710+++ b/arch/parisc/kernel/traps.c
5711@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
5712
5713 down_read(&current->mm->mmap_sem);
5714 vma = find_vma(current->mm,regs->iaoq[0]);
5715- if (vma && (regs->iaoq[0] >= vma->vm_start)
5716- && (vma->vm_flags & VM_EXEC)) {
5717-
5718+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
5719 fault_address = regs->iaoq[0];
5720 fault_space = regs->iasq[0];
5721
5722diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
5723index 18162ce..94de376 100644
5724--- a/arch/parisc/mm/fault.c
5725+++ b/arch/parisc/mm/fault.c
5726@@ -15,6 +15,7 @@
5727 #include <linux/sched.h>
5728 #include <linux/interrupt.h>
5729 #include <linux/module.h>
5730+#include <linux/unistd.h>
5731
5732 #include <asm/uaccess.h>
5733 #include <asm/traps.h>
5734@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
5735 static unsigned long
5736 parisc_acctyp(unsigned long code, unsigned int inst)
5737 {
5738- if (code == 6 || code == 16)
5739+ if (code == 6 || code == 7 || code == 16)
5740 return VM_EXEC;
5741
5742 switch (inst & 0xf0000000) {
5743@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
5744 }
5745 #endif
5746
5747+#ifdef CONFIG_PAX_PAGEEXEC
5748+/*
5749+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
5750+ *
5751+ * returns 1 when task should be killed
5752+ * 2 when rt_sigreturn trampoline was detected
5753+ * 3 when unpatched PLT trampoline was detected
5754+ */
5755+static int pax_handle_fetch_fault(struct pt_regs *regs)
5756+{
5757+
5758+#ifdef CONFIG_PAX_EMUPLT
5759+ int err;
5760+
5761+ do { /* PaX: unpatched PLT emulation */
5762+ unsigned int bl, depwi;
5763+
5764+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
5765+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
5766+
5767+ if (err)
5768+ break;
5769+
5770+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
5771+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
5772+
5773+ err = get_user(ldw, (unsigned int *)addr);
5774+ err |= get_user(bv, (unsigned int *)(addr+4));
5775+ err |= get_user(ldw2, (unsigned int *)(addr+8));
5776+
5777+ if (err)
5778+ break;
5779+
5780+ if (ldw == 0x0E801096U &&
5781+ bv == 0xEAC0C000U &&
5782+ ldw2 == 0x0E881095U)
5783+ {
5784+ unsigned int resolver, map;
5785+
5786+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
5787+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
5788+ if (err)
5789+ break;
5790+
5791+ regs->gr[20] = instruction_pointer(regs)+8;
5792+ regs->gr[21] = map;
5793+ regs->gr[22] = resolver;
5794+ regs->iaoq[0] = resolver | 3UL;
5795+ regs->iaoq[1] = regs->iaoq[0] + 4;
5796+ return 3;
5797+ }
5798+ }
5799+ } while (0);
5800+#endif
5801+
5802+#ifdef CONFIG_PAX_EMUTRAMP
5803+
5804+#ifndef CONFIG_PAX_EMUSIGRT
5805+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
5806+ return 1;
5807+#endif
5808+
5809+ do { /* PaX: rt_sigreturn emulation */
5810+ unsigned int ldi1, ldi2, bel, nop;
5811+
5812+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
5813+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
5814+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
5815+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
5816+
5817+ if (err)
5818+ break;
5819+
5820+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
5821+ ldi2 == 0x3414015AU &&
5822+ bel == 0xE4008200U &&
5823+ nop == 0x08000240U)
5824+ {
5825+ regs->gr[25] = (ldi1 & 2) >> 1;
5826+ regs->gr[20] = __NR_rt_sigreturn;
5827+ regs->gr[31] = regs->iaoq[1] + 16;
5828+ regs->sr[0] = regs->iasq[1];
5829+ regs->iaoq[0] = 0x100UL;
5830+ regs->iaoq[1] = regs->iaoq[0] + 4;
5831+ regs->iasq[0] = regs->sr[2];
5832+ regs->iasq[1] = regs->sr[2];
5833+ return 2;
5834+ }
5835+ } while (0);
5836+#endif
5837+
5838+ return 1;
5839+}
5840+
5841+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5842+{
5843+ unsigned long i;
5844+
5845+ printk(KERN_ERR "PAX: bytes at PC: ");
5846+ for (i = 0; i < 5; i++) {
5847+ unsigned int c;
5848+ if (get_user(c, (unsigned int *)pc+i))
5849+ printk(KERN_CONT "???????? ");
5850+ else
5851+ printk(KERN_CONT "%08x ", c);
5852+ }
5853+ printk("\n");
5854+}
5855+#endif
5856+
5857 int fixup_exception(struct pt_regs *regs)
5858 {
5859 const struct exception_table_entry *fix;
5860@@ -192,8 +303,33 @@ good_area:
5861
5862 acc_type = parisc_acctyp(code,regs->iir);
5863
5864- if ((vma->vm_flags & acc_type) != acc_type)
5865+ if ((vma->vm_flags & acc_type) != acc_type) {
5866+
5867+#ifdef CONFIG_PAX_PAGEEXEC
5868+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
5869+ (address & ~3UL) == instruction_pointer(regs))
5870+ {
5871+ up_read(&mm->mmap_sem);
5872+ switch (pax_handle_fetch_fault(regs)) {
5873+
5874+#ifdef CONFIG_PAX_EMUPLT
5875+ case 3:
5876+ return;
5877+#endif
5878+
5879+#ifdef CONFIG_PAX_EMUTRAMP
5880+ case 2:
5881+ return;
5882+#endif
5883+
5884+ }
5885+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
5886+ do_group_exit(SIGKILL);
5887+ }
5888+#endif
5889+
5890 goto bad_area;
5891+ }
5892
5893 /*
5894 * If for any reason at all we couldn't handle the fault, make
5895diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
5896index e3b1d41..8e81edf 100644
5897--- a/arch/powerpc/include/asm/atomic.h
5898+++ b/arch/powerpc/include/asm/atomic.h
5899@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
5900 return t1;
5901 }
5902
5903+#define atomic64_read_unchecked(v) atomic64_read(v)
5904+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5905+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5906+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5907+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5908+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5909+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5910+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5911+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5912+
5913 #endif /* __powerpc64__ */
5914
5915 #endif /* __KERNEL__ */
5916diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
5917index 9e495c9..b6878e5 100644
5918--- a/arch/powerpc/include/asm/cache.h
5919+++ b/arch/powerpc/include/asm/cache.h
5920@@ -3,6 +3,7 @@
5921
5922 #ifdef __KERNEL__
5923
5924+#include <linux/const.h>
5925
5926 /* bytes per L1 cache line */
5927 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
5928@@ -22,7 +23,7 @@
5929 #define L1_CACHE_SHIFT 7
5930 #endif
5931
5932-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5933+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5934
5935 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5936
5937diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
5938index 6abf0a1..459d0f1 100644
5939--- a/arch/powerpc/include/asm/elf.h
5940+++ b/arch/powerpc/include/asm/elf.h
5941@@ -28,8 +28,19 @@
5942 the loader. We need to make sure that it is out of the way of the program
5943 that it will "exec", and that there is sufficient room for the brk. */
5944
5945-extern unsigned long randomize_et_dyn(unsigned long base);
5946-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
5947+#define ELF_ET_DYN_BASE (0x20000000)
5948+
5949+#ifdef CONFIG_PAX_ASLR
5950+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
5951+
5952+#ifdef __powerpc64__
5953+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
5954+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
5955+#else
5956+#define PAX_DELTA_MMAP_LEN 15
5957+#define PAX_DELTA_STACK_LEN 15
5958+#endif
5959+#endif
5960
5961 /*
5962 * Our registers are always unsigned longs, whether we're a 32 bit
5963@@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5964 (0x7ff >> (PAGE_SHIFT - 12)) : \
5965 (0x3ffff >> (PAGE_SHIFT - 12)))
5966
5967-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5968-#define arch_randomize_brk arch_randomize_brk
5969-
5970-
5971 #ifdef CONFIG_SPU_BASE
5972 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
5973 #define NT_SPU 1
5974diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
5975index 8196e9c..d83a9f3 100644
5976--- a/arch/powerpc/include/asm/exec.h
5977+++ b/arch/powerpc/include/asm/exec.h
5978@@ -4,6 +4,6 @@
5979 #ifndef _ASM_POWERPC_EXEC_H
5980 #define _ASM_POWERPC_EXEC_H
5981
5982-extern unsigned long arch_align_stack(unsigned long sp);
5983+#define arch_align_stack(x) ((x) & ~0xfUL)
5984
5985 #endif /* _ASM_POWERPC_EXEC_H */
5986diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
5987index 5acabbd..7ea14fa 100644
5988--- a/arch/powerpc/include/asm/kmap_types.h
5989+++ b/arch/powerpc/include/asm/kmap_types.h
5990@@ -10,7 +10,7 @@
5991 * 2 of the License, or (at your option) any later version.
5992 */
5993
5994-#define KM_TYPE_NR 16
5995+#define KM_TYPE_NR 17
5996
5997 #endif /* __KERNEL__ */
5998 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
5999diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6000index 8565c25..2865190 100644
6001--- a/arch/powerpc/include/asm/mman.h
6002+++ b/arch/powerpc/include/asm/mman.h
6003@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6004 }
6005 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6006
6007-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6008+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6009 {
6010 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6011 }
6012diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6013index f072e97..b436dee 100644
6014--- a/arch/powerpc/include/asm/page.h
6015+++ b/arch/powerpc/include/asm/page.h
6016@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6017 * and needs to be executable. This means the whole heap ends
6018 * up being executable.
6019 */
6020-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6021- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6022+#define VM_DATA_DEFAULT_FLAGS32 \
6023+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6024+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6025
6026 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6027 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6028@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6029 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6030 #endif
6031
6032+#define ktla_ktva(addr) (addr)
6033+#define ktva_ktla(addr) (addr)
6034+
6035 /*
6036 * Use the top bit of the higher-level page table entries to indicate whether
6037 * the entries we point to contain hugepages. This works because we know that
6038diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6039index cd915d6..c10cee8 100644
6040--- a/arch/powerpc/include/asm/page_64.h
6041+++ b/arch/powerpc/include/asm/page_64.h
6042@@ -154,15 +154,18 @@ do { \
6043 * stack by default, so in the absence of a PT_GNU_STACK program header
6044 * we turn execute permission off.
6045 */
6046-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6047- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6048+#define VM_STACK_DEFAULT_FLAGS32 \
6049+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6050+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6051
6052 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6053 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6054
6055+#ifndef CONFIG_PAX_PAGEEXEC
6056 #define VM_STACK_DEFAULT_FLAGS \
6057 (is_32bit_task() ? \
6058 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6059+#endif
6060
6061 #include <asm-generic/getorder.h>
6062
6063diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6064index 292725c..f87ae14 100644
6065--- a/arch/powerpc/include/asm/pgalloc-64.h
6066+++ b/arch/powerpc/include/asm/pgalloc-64.h
6067@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6068 #ifndef CONFIG_PPC_64K_PAGES
6069
6070 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6071+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6072
6073 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6074 {
6075@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6076 pud_set(pud, (unsigned long)pmd);
6077 }
6078
6079+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6080+{
6081+ pud_populate(mm, pud, pmd);
6082+}
6083+
6084 #define pmd_populate(mm, pmd, pte_page) \
6085 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6086 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6087@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6088 #else /* CONFIG_PPC_64K_PAGES */
6089
6090 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6091+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6092
6093 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6094 pte_t *pte)
6095diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6096index a9cbd3b..3b67efa 100644
6097--- a/arch/powerpc/include/asm/pgtable.h
6098+++ b/arch/powerpc/include/asm/pgtable.h
6099@@ -2,6 +2,7 @@
6100 #define _ASM_POWERPC_PGTABLE_H
6101 #ifdef __KERNEL__
6102
6103+#include <linux/const.h>
6104 #ifndef __ASSEMBLY__
6105 #include <asm/processor.h> /* For TASK_SIZE */
6106 #include <asm/mmu.h>
6107diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6108index 4aad413..85d86bf 100644
6109--- a/arch/powerpc/include/asm/pte-hash32.h
6110+++ b/arch/powerpc/include/asm/pte-hash32.h
6111@@ -21,6 +21,7 @@
6112 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6113 #define _PAGE_USER 0x004 /* usermode access allowed */
6114 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6115+#define _PAGE_EXEC _PAGE_GUARDED
6116 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6117 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6118 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6119diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6120index 3d5c9dc..62f8414 100644
6121--- a/arch/powerpc/include/asm/reg.h
6122+++ b/arch/powerpc/include/asm/reg.h
6123@@ -215,6 +215,7 @@
6124 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6125 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6126 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6127+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6128 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6129 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6130 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6131diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6132index 406b7b9..af63426 100644
6133--- a/arch/powerpc/include/asm/thread_info.h
6134+++ b/arch/powerpc/include/asm/thread_info.h
6135@@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
6136 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6137 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6138 #define TIF_SINGLESTEP 8 /* singlestepping active */
6139-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
6140 #define TIF_SECCOMP 10 /* secure computing */
6141 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
6142 #define TIF_NOERROR 12 /* Force successful syscall return */
6143@@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6144 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
6145 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6146 for stack store? */
6147+#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6148+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6149+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
6150
6151 /* as above, but as bit values */
6152 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6153@@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
6154 #define _TIF_UPROBE (1<<TIF_UPROBE)
6155 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6156 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6157+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6158 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6159- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
6160+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6161+ _TIF_GRSEC_SETXID)
6162
6163 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6164 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6165diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6166index 4db4959..335e00c 100644
6167--- a/arch/powerpc/include/asm/uaccess.h
6168+++ b/arch/powerpc/include/asm/uaccess.h
6169@@ -13,6 +13,8 @@
6170 #define VERIFY_READ 0
6171 #define VERIFY_WRITE 1
6172
6173+extern void check_object_size(const void *ptr, unsigned long n, bool to);
6174+
6175 /*
6176 * The fs value determines whether argument validity checking should be
6177 * performed or not. If get_fs() == USER_DS, checking is performed, with
6178@@ -318,52 +320,6 @@ do { \
6179 extern unsigned long __copy_tofrom_user(void __user *to,
6180 const void __user *from, unsigned long size);
6181
6182-#ifndef __powerpc64__
6183-
6184-static inline unsigned long copy_from_user(void *to,
6185- const void __user *from, unsigned long n)
6186-{
6187- unsigned long over;
6188-
6189- if (access_ok(VERIFY_READ, from, n))
6190- return __copy_tofrom_user((__force void __user *)to, from, n);
6191- if ((unsigned long)from < TASK_SIZE) {
6192- over = (unsigned long)from + n - TASK_SIZE;
6193- return __copy_tofrom_user((__force void __user *)to, from,
6194- n - over) + over;
6195- }
6196- return n;
6197-}
6198-
6199-static inline unsigned long copy_to_user(void __user *to,
6200- const void *from, unsigned long n)
6201-{
6202- unsigned long over;
6203-
6204- if (access_ok(VERIFY_WRITE, to, n))
6205- return __copy_tofrom_user(to, (__force void __user *)from, n);
6206- if ((unsigned long)to < TASK_SIZE) {
6207- over = (unsigned long)to + n - TASK_SIZE;
6208- return __copy_tofrom_user(to, (__force void __user *)from,
6209- n - over) + over;
6210- }
6211- return n;
6212-}
6213-
6214-#else /* __powerpc64__ */
6215-
6216-#define __copy_in_user(to, from, size) \
6217- __copy_tofrom_user((to), (from), (size))
6218-
6219-extern unsigned long copy_from_user(void *to, const void __user *from,
6220- unsigned long n);
6221-extern unsigned long copy_to_user(void __user *to, const void *from,
6222- unsigned long n);
6223-extern unsigned long copy_in_user(void __user *to, const void __user *from,
6224- unsigned long n);
6225-
6226-#endif /* __powerpc64__ */
6227-
6228 static inline unsigned long __copy_from_user_inatomic(void *to,
6229 const void __user *from, unsigned long n)
6230 {
6231@@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6232 if (ret == 0)
6233 return 0;
6234 }
6235+
6236+ if (!__builtin_constant_p(n))
6237+ check_object_size(to, n, false);
6238+
6239 return __copy_tofrom_user((__force void __user *)to, from, n);
6240 }
6241
6242@@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6243 if (ret == 0)
6244 return 0;
6245 }
6246+
6247+ if (!__builtin_constant_p(n))
6248+ check_object_size(from, n, true);
6249+
6250 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6251 }
6252
6253@@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6254 return __copy_to_user_inatomic(to, from, size);
6255 }
6256
6257+#ifndef __powerpc64__
6258+
6259+static inline unsigned long __must_check copy_from_user(void *to,
6260+ const void __user *from, unsigned long n)
6261+{
6262+ unsigned long over;
6263+
6264+ if ((long)n < 0)
6265+ return n;
6266+
6267+ if (access_ok(VERIFY_READ, from, n)) {
6268+ if (!__builtin_constant_p(n))
6269+ check_object_size(to, n, false);
6270+ return __copy_tofrom_user((__force void __user *)to, from, n);
6271+ }
6272+ if ((unsigned long)from < TASK_SIZE) {
6273+ over = (unsigned long)from + n - TASK_SIZE;
6274+ if (!__builtin_constant_p(n - over))
6275+ check_object_size(to, n - over, false);
6276+ return __copy_tofrom_user((__force void __user *)to, from,
6277+ n - over) + over;
6278+ }
6279+ return n;
6280+}
6281+
6282+static inline unsigned long __must_check copy_to_user(void __user *to,
6283+ const void *from, unsigned long n)
6284+{
6285+ unsigned long over;
6286+
6287+ if ((long)n < 0)
6288+ return n;
6289+
6290+ if (access_ok(VERIFY_WRITE, to, n)) {
6291+ if (!__builtin_constant_p(n))
6292+ check_object_size(from, n, true);
6293+ return __copy_tofrom_user(to, (__force void __user *)from, n);
6294+ }
6295+ if ((unsigned long)to < TASK_SIZE) {
6296+ over = (unsigned long)to + n - TASK_SIZE;
6297+ if (!__builtin_constant_p(n))
6298+ check_object_size(from, n - over, true);
6299+ return __copy_tofrom_user(to, (__force void __user *)from,
6300+ n - over) + over;
6301+ }
6302+ return n;
6303+}
6304+
6305+#else /* __powerpc64__ */
6306+
6307+#define __copy_in_user(to, from, size) \
6308+ __copy_tofrom_user((to), (from), (size))
6309+
6310+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6311+{
6312+ if ((long)n < 0 || n > INT_MAX)
6313+ return n;
6314+
6315+ if (!__builtin_constant_p(n))
6316+ check_object_size(to, n, false);
6317+
6318+ if (likely(access_ok(VERIFY_READ, from, n)))
6319+ n = __copy_from_user(to, from, n);
6320+ else
6321+ memset(to, 0, n);
6322+ return n;
6323+}
6324+
6325+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6326+{
6327+ if ((long)n < 0 || n > INT_MAX)
6328+ return n;
6329+
6330+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
6331+ if (!__builtin_constant_p(n))
6332+ check_object_size(from, n, true);
6333+ n = __copy_to_user(to, from, n);
6334+ }
6335+ return n;
6336+}
6337+
6338+extern unsigned long copy_in_user(void __user *to, const void __user *from,
6339+ unsigned long n);
6340+
6341+#endif /* __powerpc64__ */
6342+
6343 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6344
6345 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6346diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6347index 4684e33..acc4d19e 100644
6348--- a/arch/powerpc/kernel/exceptions-64e.S
6349+++ b/arch/powerpc/kernel/exceptions-64e.S
6350@@ -715,6 +715,7 @@ storage_fault_common:
6351 std r14,_DAR(r1)
6352 std r15,_DSISR(r1)
6353 addi r3,r1,STACK_FRAME_OVERHEAD
6354+ bl .save_nvgprs
6355 mr r4,r14
6356 mr r5,r15
6357 ld r14,PACA_EXGEN+EX_R14(r13)
6358@@ -723,8 +724,7 @@ storage_fault_common:
6359 cmpdi r3,0
6360 bne- 1f
6361 b .ret_from_except_lite
6362-1: bl .save_nvgprs
6363- mr r5,r3
6364+1: mr r5,r3
6365 addi r3,r1,STACK_FRAME_OVERHEAD
6366 ld r4,_DAR(r1)
6367 bl .bad_page_fault
6368diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6369index 4665e82..080ea99 100644
6370--- a/arch/powerpc/kernel/exceptions-64s.S
6371+++ b/arch/powerpc/kernel/exceptions-64s.S
6372@@ -1206,10 +1206,10 @@ handle_page_fault:
6373 11: ld r4,_DAR(r1)
6374 ld r5,_DSISR(r1)
6375 addi r3,r1,STACK_FRAME_OVERHEAD
6376+ bl .save_nvgprs
6377 bl .do_page_fault
6378 cmpdi r3,0
6379 beq+ 12f
6380- bl .save_nvgprs
6381 mr r5,r3
6382 addi r3,r1,STACK_FRAME_OVERHEAD
6383 lwz r4,_DAR(r1)
6384diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6385index 2e3200c..72095ce 100644
6386--- a/arch/powerpc/kernel/module_32.c
6387+++ b/arch/powerpc/kernel/module_32.c
6388@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6389 me->arch.core_plt_section = i;
6390 }
6391 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6392- printk("Module doesn't contain .plt or .init.plt sections.\n");
6393+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6394 return -ENOEXEC;
6395 }
6396
6397@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6398
6399 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6400 /* Init, or core PLT? */
6401- if (location >= mod->module_core
6402- && location < mod->module_core + mod->core_size)
6403+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6404+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6405 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6406- else
6407+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6408+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6409 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6410+ else {
6411+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6412+ return ~0UL;
6413+ }
6414
6415 /* Find this entry, or if that fails, the next avail. entry */
6416 while (entry->jump[0]) {
6417diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6418index 8143067..21ae55b 100644
6419--- a/arch/powerpc/kernel/process.c
6420+++ b/arch/powerpc/kernel/process.c
6421@@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
6422 * Lookup NIP late so we have the best change of getting the
6423 * above info out without failing
6424 */
6425- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6426- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6427+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6428+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6429 #endif
6430 show_stack(current, (unsigned long *) regs->gpr[1]);
6431 if (!user_mode(regs))
6432@@ -1129,10 +1129,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6433 newsp = stack[0];
6434 ip = stack[STACK_FRAME_LR_SAVE];
6435 if (!firstframe || ip != lr) {
6436- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6437+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6438 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6439 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6440- printk(" (%pS)",
6441+ printk(" (%pA)",
6442 (void *)current->ret_stack[curr_frame].ret);
6443 curr_frame--;
6444 }
6445@@ -1152,7 +1152,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6446 struct pt_regs *regs = (struct pt_regs *)
6447 (sp + STACK_FRAME_OVERHEAD);
6448 lr = regs->link;
6449- printk("--- Exception: %lx at %pS\n LR = %pS\n",
6450+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
6451 regs->trap, (void *)regs->nip, (void *)lr);
6452 firstframe = 1;
6453 }
6454@@ -1194,58 +1194,3 @@ void __ppc64_runlatch_off(void)
6455 mtspr(SPRN_CTRLT, ctrl);
6456 }
6457 #endif /* CONFIG_PPC64 */
6458-
6459-unsigned long arch_align_stack(unsigned long sp)
6460-{
6461- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6462- sp -= get_random_int() & ~PAGE_MASK;
6463- return sp & ~0xf;
6464-}
6465-
6466-static inline unsigned long brk_rnd(void)
6467-{
6468- unsigned long rnd = 0;
6469-
6470- /* 8MB for 32bit, 1GB for 64bit */
6471- if (is_32bit_task())
6472- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6473- else
6474- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6475-
6476- return rnd << PAGE_SHIFT;
6477-}
6478-
6479-unsigned long arch_randomize_brk(struct mm_struct *mm)
6480-{
6481- unsigned long base = mm->brk;
6482- unsigned long ret;
6483-
6484-#ifdef CONFIG_PPC_STD_MMU_64
6485- /*
6486- * If we are using 1TB segments and we are allowed to randomise
6487- * the heap, we can put it above 1TB so it is backed by a 1TB
6488- * segment. Otherwise the heap will be in the bottom 1TB
6489- * which always uses 256MB segments and this may result in a
6490- * performance penalty.
6491- */
6492- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6493- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6494-#endif
6495-
6496- ret = PAGE_ALIGN(base + brk_rnd());
6497-
6498- if (ret < mm->brk)
6499- return mm->brk;
6500-
6501- return ret;
6502-}
6503-
6504-unsigned long randomize_et_dyn(unsigned long base)
6505-{
6506- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6507-
6508- if (ret < base)
6509- return base;
6510-
6511- return ret;
6512-}
6513diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6514index c497000..8fde506 100644
6515--- a/arch/powerpc/kernel/ptrace.c
6516+++ b/arch/powerpc/kernel/ptrace.c
6517@@ -1737,6 +1737,10 @@ long arch_ptrace(struct task_struct *child, long request,
6518 return ret;
6519 }
6520
6521+#ifdef CONFIG_GRKERNSEC_SETXID
6522+extern void gr_delayed_cred_worker(void);
6523+#endif
6524+
6525 /*
6526 * We must return the syscall number to actually look up in the table.
6527 * This can be -1L to skip running any syscall at all.
6528@@ -1747,6 +1751,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6529
6530 secure_computing_strict(regs->gpr[0]);
6531
6532+#ifdef CONFIG_GRKERNSEC_SETXID
6533+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6534+ gr_delayed_cred_worker();
6535+#endif
6536+
6537 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6538 tracehook_report_syscall_entry(regs))
6539 /*
6540@@ -1781,6 +1790,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6541 {
6542 int step;
6543
6544+#ifdef CONFIG_GRKERNSEC_SETXID
6545+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6546+ gr_delayed_cred_worker();
6547+#endif
6548+
6549 audit_syscall_exit(regs);
6550
6551 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6552diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6553index 804e323..79181c1 100644
6554--- a/arch/powerpc/kernel/signal_32.c
6555+++ b/arch/powerpc/kernel/signal_32.c
6556@@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6557 /* Save user registers on the stack */
6558 frame = &rt_sf->uc.uc_mcontext;
6559 addr = frame;
6560- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6561+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6562 if (save_user_regs(regs, frame, 0, 1))
6563 goto badframe;
6564 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6565diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6566index 1ca045d..139c3f7 100644
6567--- a/arch/powerpc/kernel/signal_64.c
6568+++ b/arch/powerpc/kernel/signal_64.c
6569@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6570 current->thread.fpscr.val = 0;
6571
6572 /* Set up to return from userspace. */
6573- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6574+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6575 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6576 } else {
6577 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6578diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6579index 3ce1f86..c30e629 100644
6580--- a/arch/powerpc/kernel/sysfs.c
6581+++ b/arch/powerpc/kernel/sysfs.c
6582@@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6583 return NOTIFY_OK;
6584 }
6585
6586-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6587+static struct notifier_block sysfs_cpu_nb = {
6588 .notifier_call = sysfs_cpu_notify,
6589 };
6590
6591diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6592index 3251840..3f7c77a 100644
6593--- a/arch/powerpc/kernel/traps.c
6594+++ b/arch/powerpc/kernel/traps.c
6595@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6596 return flags;
6597 }
6598
6599+extern void gr_handle_kernel_exploit(void);
6600+
6601 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6602 int signr)
6603 {
6604@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6605 panic("Fatal exception in interrupt");
6606 if (panic_on_oops)
6607 panic("Fatal exception");
6608+
6609+ gr_handle_kernel_exploit();
6610+
6611 do_exit(signr);
6612 }
6613
6614diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6615index 1b2076f..835e4be 100644
6616--- a/arch/powerpc/kernel/vdso.c
6617+++ b/arch/powerpc/kernel/vdso.c
6618@@ -34,6 +34,7 @@
6619 #include <asm/firmware.h>
6620 #include <asm/vdso.h>
6621 #include <asm/vdso_datapage.h>
6622+#include <asm/mman.h>
6623
6624 #include "setup.h"
6625
6626@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6627 vdso_base = VDSO32_MBASE;
6628 #endif
6629
6630- current->mm->context.vdso_base = 0;
6631+ current->mm->context.vdso_base = ~0UL;
6632
6633 /* vDSO has a problem and was disabled, just don't "enable" it for the
6634 * process
6635@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6636 vdso_base = get_unmapped_area(NULL, vdso_base,
6637 (vdso_pages << PAGE_SHIFT) +
6638 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6639- 0, 0);
6640+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
6641 if (IS_ERR_VALUE(vdso_base)) {
6642 rc = vdso_base;
6643 goto fail_mmapsem;
6644diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6645index 5eea6f3..5d10396 100644
6646--- a/arch/powerpc/lib/usercopy_64.c
6647+++ b/arch/powerpc/lib/usercopy_64.c
6648@@ -9,22 +9,6 @@
6649 #include <linux/module.h>
6650 #include <asm/uaccess.h>
6651
6652-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6653-{
6654- if (likely(access_ok(VERIFY_READ, from, n)))
6655- n = __copy_from_user(to, from, n);
6656- else
6657- memset(to, 0, n);
6658- return n;
6659-}
6660-
6661-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6662-{
6663- if (likely(access_ok(VERIFY_WRITE, to, n)))
6664- n = __copy_to_user(to, from, n);
6665- return n;
6666-}
6667-
6668 unsigned long copy_in_user(void __user *to, const void __user *from,
6669 unsigned long n)
6670 {
6671@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
6672 return n;
6673 }
6674
6675-EXPORT_SYMBOL(copy_from_user);
6676-EXPORT_SYMBOL(copy_to_user);
6677 EXPORT_SYMBOL(copy_in_user);
6678
6679diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
6680index 3a8489a..6a63b3b 100644
6681--- a/arch/powerpc/mm/fault.c
6682+++ b/arch/powerpc/mm/fault.c
6683@@ -32,6 +32,10 @@
6684 #include <linux/perf_event.h>
6685 #include <linux/magic.h>
6686 #include <linux/ratelimit.h>
6687+#include <linux/slab.h>
6688+#include <linux/pagemap.h>
6689+#include <linux/compiler.h>
6690+#include <linux/unistd.h>
6691
6692 #include <asm/firmware.h>
6693 #include <asm/page.h>
6694@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
6695 }
6696 #endif
6697
6698+#ifdef CONFIG_PAX_PAGEEXEC
6699+/*
6700+ * PaX: decide what to do with offenders (regs->nip = fault address)
6701+ *
6702+ * returns 1 when task should be killed
6703+ */
6704+static int pax_handle_fetch_fault(struct pt_regs *regs)
6705+{
6706+ return 1;
6707+}
6708+
6709+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6710+{
6711+ unsigned long i;
6712+
6713+ printk(KERN_ERR "PAX: bytes at PC: ");
6714+ for (i = 0; i < 5; i++) {
6715+ unsigned int c;
6716+ if (get_user(c, (unsigned int __user *)pc+i))
6717+ printk(KERN_CONT "???????? ");
6718+ else
6719+ printk(KERN_CONT "%08x ", c);
6720+ }
6721+ printk("\n");
6722+}
6723+#endif
6724+
6725 /*
6726 * Check whether the instruction at regs->nip is a store using
6727 * an update addressing form which will update r1.
6728@@ -213,7 +244,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
6729 * indicate errors in DSISR but can validly be set in SRR1.
6730 */
6731 if (trap == 0x400)
6732- error_code &= 0x48200000;
6733+ error_code &= 0x58200000;
6734 else
6735 is_write = error_code & DSISR_ISSTORE;
6736 #else
6737@@ -364,7 +395,7 @@ good_area:
6738 * "undefined". Of those that can be set, this is the only
6739 * one which seems bad.
6740 */
6741- if (error_code & 0x10000000)
6742+ if (error_code & DSISR_GUARDED)
6743 /* Guarded storage error. */
6744 goto bad_area;
6745 #endif /* CONFIG_8xx */
6746@@ -379,7 +410,7 @@ good_area:
6747 * processors use the same I/D cache coherency mechanism
6748 * as embedded.
6749 */
6750- if (error_code & DSISR_PROTFAULT)
6751+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
6752 goto bad_area;
6753 #endif /* CONFIG_PPC_STD_MMU */
6754
6755@@ -462,6 +493,23 @@ bad_area:
6756 bad_area_nosemaphore:
6757 /* User mode accesses cause a SIGSEGV */
6758 if (user_mode(regs)) {
6759+
6760+#ifdef CONFIG_PAX_PAGEEXEC
6761+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
6762+#ifdef CONFIG_PPC_STD_MMU
6763+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
6764+#else
6765+ if (is_exec && regs->nip == address) {
6766+#endif
6767+ switch (pax_handle_fetch_fault(regs)) {
6768+ }
6769+
6770+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
6771+ do_group_exit(SIGKILL);
6772+ }
6773+ }
6774+#endif
6775+
6776 _exception(SIGSEGV, regs, code, address);
6777 return 0;
6778 }
6779diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
6780index 67a42ed..cd463e0 100644
6781--- a/arch/powerpc/mm/mmap_64.c
6782+++ b/arch/powerpc/mm/mmap_64.c
6783@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
6784 {
6785 unsigned long rnd = 0;
6786
6787+#ifdef CONFIG_PAX_RANDMMAP
6788+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6789+#endif
6790+
6791 if (current->flags & PF_RANDOMIZE) {
6792 /* 8MB for 32bit, 1GB for 64bit */
6793 if (is_32bit_task())
6794@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6795 */
6796 if (mmap_is_legacy()) {
6797 mm->mmap_base = TASK_UNMAPPED_BASE;
6798+
6799+#ifdef CONFIG_PAX_RANDMMAP
6800+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6801+ mm->mmap_base += mm->delta_mmap;
6802+#endif
6803+
6804 mm->get_unmapped_area = arch_get_unmapped_area;
6805 mm->unmap_area = arch_unmap_area;
6806 } else {
6807 mm->mmap_base = mmap_base();
6808+
6809+#ifdef CONFIG_PAX_RANDMMAP
6810+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6811+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6812+#endif
6813+
6814 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6815 mm->unmap_area = arch_unmap_area_topdown;
6816 }
6817diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
6818index e779642..e5bb889 100644
6819--- a/arch/powerpc/mm/mmu_context_nohash.c
6820+++ b/arch/powerpc/mm/mmu_context_nohash.c
6821@@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
6822 return NOTIFY_OK;
6823 }
6824
6825-static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
6826+static struct notifier_block mmu_context_cpu_nb = {
6827 .notifier_call = mmu_context_cpu_notify,
6828 };
6829
6830diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
6831index bba87ca..c346a33 100644
6832--- a/arch/powerpc/mm/numa.c
6833+++ b/arch/powerpc/mm/numa.c
6834@@ -932,7 +932,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
6835 return ret;
6836 }
6837
6838-static struct notifier_block __cpuinitdata ppc64_numa_nb = {
6839+static struct notifier_block ppc64_numa_nb = {
6840 .notifier_call = cpu_numa_callback,
6841 .priority = 1 /* Must run before sched domains notifier. */
6842 };
6843diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
6844index cf9dada..241529f 100644
6845--- a/arch/powerpc/mm/slice.c
6846+++ b/arch/powerpc/mm/slice.c
6847@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
6848 if ((mm->task_size - len) < addr)
6849 return 0;
6850 vma = find_vma(mm, addr);
6851- return (!vma || (addr + len) <= vma->vm_start);
6852+ return check_heap_stack_gap(vma, addr, len, 0);
6853 }
6854
6855 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
6856@@ -272,7 +272,7 @@ full_search:
6857 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
6858 continue;
6859 }
6860- if (!vma || addr + len <= vma->vm_start) {
6861+ if (check_heap_stack_gap(vma, addr, len, 0)) {
6862 /*
6863 * Remember the place where we stopped the search:
6864 */
6865@@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6866 }
6867 }
6868
6869- addr = mm->mmap_base;
6870- while (addr > len) {
6871+ if (mm->mmap_base < len)
6872+ addr = -ENOMEM;
6873+ else
6874+ addr = mm->mmap_base - len;
6875+
6876+ while (!IS_ERR_VALUE(addr)) {
6877 /* Go down by chunk size */
6878- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
6879+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
6880
6881 /* Check for hit with different page size */
6882 mask = slice_range_to_mask(addr, len);
6883@@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6884 * return with success:
6885 */
6886 vma = find_vma(mm, addr);
6887- if (!vma || (addr + len) <= vma->vm_start) {
6888+ if (check_heap_stack_gap(vma, addr, len, 0)) {
6889 /* remember the address as a hint for next time */
6890 if (use_cache)
6891 mm->free_area_cache = addr;
6892@@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6893 mm->cached_hole_size = vma->vm_start - addr;
6894
6895 /* try just below the current vma->vm_start */
6896- addr = vma->vm_start;
6897+ addr = skip_heap_stack_gap(vma, len, 0);
6898 }
6899
6900 /*
6901@@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
6902 if (fixed && addr > (mm->task_size - len))
6903 return -EINVAL;
6904
6905+#ifdef CONFIG_PAX_RANDMMAP
6906+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
6907+ addr = 0;
6908+#endif
6909+
6910 /* If hint, make sure it matches our alignment restrictions */
6911 if (!fixed && addr) {
6912 addr = _ALIGN_UP(addr, 1ul << pshift);
6913diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
6914index bdb738a..49c9f95 100644
6915--- a/arch/powerpc/platforms/powermac/smp.c
6916+++ b/arch/powerpc/platforms/powermac/smp.c
6917@@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
6918 return NOTIFY_OK;
6919 }
6920
6921-static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
6922+static struct notifier_block smp_core99_cpu_nb = {
6923 .notifier_call = smp_core99_cpu_notify,
6924 };
6925 #endif /* CONFIG_HOTPLUG_CPU */
6926diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
6927index c797832..ce575c8 100644
6928--- a/arch/s390/include/asm/atomic.h
6929+++ b/arch/s390/include/asm/atomic.h
6930@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
6931 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
6932 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6933
6934+#define atomic64_read_unchecked(v) atomic64_read(v)
6935+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6936+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6937+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6938+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6939+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6940+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6941+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6942+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6943+
6944 #define smp_mb__before_atomic_dec() smp_mb()
6945 #define smp_mb__after_atomic_dec() smp_mb()
6946 #define smp_mb__before_atomic_inc() smp_mb()
6947diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
6948index 4d7ccac..d03d0ad 100644
6949--- a/arch/s390/include/asm/cache.h
6950+++ b/arch/s390/include/asm/cache.h
6951@@ -9,8 +9,10 @@
6952 #ifndef __ARCH_S390_CACHE_H
6953 #define __ARCH_S390_CACHE_H
6954
6955-#define L1_CACHE_BYTES 256
6956+#include <linux/const.h>
6957+
6958 #define L1_CACHE_SHIFT 8
6959+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6960 #define NET_SKB_PAD 32
6961
6962 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
6963diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
6964index 178ff96..8c93bd1 100644
6965--- a/arch/s390/include/asm/elf.h
6966+++ b/arch/s390/include/asm/elf.h
6967@@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
6968 the loader. We need to make sure that it is out of the way of the program
6969 that it will "exec", and that there is sufficient room for the brk. */
6970
6971-extern unsigned long randomize_et_dyn(unsigned long base);
6972-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
6973+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
6974+
6975+#ifdef CONFIG_PAX_ASLR
6976+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
6977+
6978+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
6979+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
6980+#endif
6981
6982 /* This yields a mask that user programs can use to figure out what
6983 instruction set this CPU supports. */
6984@@ -210,9 +216,6 @@ struct linux_binprm;
6985 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6986 int arch_setup_additional_pages(struct linux_binprm *, int);
6987
6988-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6989-#define arch_randomize_brk arch_randomize_brk
6990-
6991 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
6992
6993 #endif
6994diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
6995index c4a93d6..4d2a9b4 100644
6996--- a/arch/s390/include/asm/exec.h
6997+++ b/arch/s390/include/asm/exec.h
6998@@ -7,6 +7,6 @@
6999 #ifndef __ASM_EXEC_H
7000 #define __ASM_EXEC_H
7001
7002-extern unsigned long arch_align_stack(unsigned long sp);
7003+#define arch_align_stack(x) ((x) & ~0xfUL)
7004
7005 #endif /* __ASM_EXEC_H */
7006diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7007index 34268df..ea97318 100644
7008--- a/arch/s390/include/asm/uaccess.h
7009+++ b/arch/s390/include/asm/uaccess.h
7010@@ -252,6 +252,10 @@ static inline unsigned long __must_check
7011 copy_to_user(void __user *to, const void *from, unsigned long n)
7012 {
7013 might_fault();
7014+
7015+ if ((long)n < 0)
7016+ return n;
7017+
7018 if (access_ok(VERIFY_WRITE, to, n))
7019 n = __copy_to_user(to, from, n);
7020 return n;
7021@@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7022 static inline unsigned long __must_check
7023 __copy_from_user(void *to, const void __user *from, unsigned long n)
7024 {
7025+ if ((long)n < 0)
7026+ return n;
7027+
7028 if (__builtin_constant_p(n) && (n <= 256))
7029 return uaccess.copy_from_user_small(n, from, to);
7030 else
7031@@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7032 static inline unsigned long __must_check
7033 copy_from_user(void *to, const void __user *from, unsigned long n)
7034 {
7035- unsigned int sz = __compiletime_object_size(to);
7036+ size_t sz = __compiletime_object_size(to);
7037
7038 might_fault();
7039- if (unlikely(sz != -1 && sz < n)) {
7040+
7041+ if ((long)n < 0)
7042+ return n;
7043+
7044+ if (unlikely(sz != (size_t)-1 && sz < n)) {
7045 copy_from_user_overflow();
7046 return n;
7047 }
7048diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7049index 4610dea..cf0af21 100644
7050--- a/arch/s390/kernel/module.c
7051+++ b/arch/s390/kernel/module.c
7052@@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7053
7054 /* Increase core size by size of got & plt and set start
7055 offsets for got and plt. */
7056- me->core_size = ALIGN(me->core_size, 4);
7057- me->arch.got_offset = me->core_size;
7058- me->core_size += me->arch.got_size;
7059- me->arch.plt_offset = me->core_size;
7060- me->core_size += me->arch.plt_size;
7061+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
7062+ me->arch.got_offset = me->core_size_rw;
7063+ me->core_size_rw += me->arch.got_size;
7064+ me->arch.plt_offset = me->core_size_rx;
7065+ me->core_size_rx += me->arch.plt_size;
7066 return 0;
7067 }
7068
7069@@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7070 if (info->got_initialized == 0) {
7071 Elf_Addr *gotent;
7072
7073- gotent = me->module_core + me->arch.got_offset +
7074+ gotent = me->module_core_rw + me->arch.got_offset +
7075 info->got_offset;
7076 *gotent = val;
7077 info->got_initialized = 1;
7078@@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7079 else if (r_type == R_390_GOTENT ||
7080 r_type == R_390_GOTPLTENT)
7081 *(unsigned int *) loc =
7082- (val + (Elf_Addr) me->module_core - loc) >> 1;
7083+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
7084 else if (r_type == R_390_GOT64 ||
7085 r_type == R_390_GOTPLT64)
7086 *(unsigned long *) loc = val;
7087@@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7088 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7089 if (info->plt_initialized == 0) {
7090 unsigned int *ip;
7091- ip = me->module_core + me->arch.plt_offset +
7092+ ip = me->module_core_rx + me->arch.plt_offset +
7093 info->plt_offset;
7094 #ifndef CONFIG_64BIT
7095 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7096@@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7097 val - loc + 0xffffUL < 0x1ffffeUL) ||
7098 (r_type == R_390_PLT32DBL &&
7099 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7100- val = (Elf_Addr) me->module_core +
7101+ val = (Elf_Addr) me->module_core_rx +
7102 me->arch.plt_offset +
7103 info->plt_offset;
7104 val += rela->r_addend - loc;
7105@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7106 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7107 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7108 val = val + rela->r_addend -
7109- ((Elf_Addr) me->module_core + me->arch.got_offset);
7110+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7111 if (r_type == R_390_GOTOFF16)
7112 *(unsigned short *) loc = val;
7113 else if (r_type == R_390_GOTOFF32)
7114@@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7115 break;
7116 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7117 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7118- val = (Elf_Addr) me->module_core + me->arch.got_offset +
7119+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7120 rela->r_addend - loc;
7121 if (r_type == R_390_GOTPC)
7122 *(unsigned int *) loc = val;
7123diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7124index 536d645..4a5bd9e 100644
7125--- a/arch/s390/kernel/process.c
7126+++ b/arch/s390/kernel/process.c
7127@@ -250,39 +250,3 @@ unsigned long get_wchan(struct task_struct *p)
7128 }
7129 return 0;
7130 }
7131-
7132-unsigned long arch_align_stack(unsigned long sp)
7133-{
7134- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7135- sp -= get_random_int() & ~PAGE_MASK;
7136- return sp & ~0xf;
7137-}
7138-
7139-static inline unsigned long brk_rnd(void)
7140-{
7141- /* 8MB for 32bit, 1GB for 64bit */
7142- if (is_32bit_task())
7143- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7144- else
7145- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7146-}
7147-
7148-unsigned long arch_randomize_brk(struct mm_struct *mm)
7149-{
7150- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7151-
7152- if (ret < mm->brk)
7153- return mm->brk;
7154- return ret;
7155-}
7156-
7157-unsigned long randomize_et_dyn(unsigned long base)
7158-{
7159- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7160-
7161- if (!(current->flags & PF_RANDOMIZE))
7162- return base;
7163- if (ret < base)
7164- return base;
7165- return ret;
7166-}
7167diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7168index c59a5ef..3fae59c 100644
7169--- a/arch/s390/mm/mmap.c
7170+++ b/arch/s390/mm/mmap.c
7171@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7172 */
7173 if (mmap_is_legacy()) {
7174 mm->mmap_base = TASK_UNMAPPED_BASE;
7175+
7176+#ifdef CONFIG_PAX_RANDMMAP
7177+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7178+ mm->mmap_base += mm->delta_mmap;
7179+#endif
7180+
7181 mm->get_unmapped_area = arch_get_unmapped_area;
7182 mm->unmap_area = arch_unmap_area;
7183 } else {
7184 mm->mmap_base = mmap_base();
7185+
7186+#ifdef CONFIG_PAX_RANDMMAP
7187+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7188+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7189+#endif
7190+
7191 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7192 mm->unmap_area = arch_unmap_area_topdown;
7193 }
7194@@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7195 */
7196 if (mmap_is_legacy()) {
7197 mm->mmap_base = TASK_UNMAPPED_BASE;
7198+
7199+#ifdef CONFIG_PAX_RANDMMAP
7200+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7201+ mm->mmap_base += mm->delta_mmap;
7202+#endif
7203+
7204 mm->get_unmapped_area = s390_get_unmapped_area;
7205 mm->unmap_area = arch_unmap_area;
7206 } else {
7207 mm->mmap_base = mmap_base();
7208+
7209+#ifdef CONFIG_PAX_RANDMMAP
7210+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7211+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7212+#endif
7213+
7214 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7215 mm->unmap_area = arch_unmap_area_topdown;
7216 }
7217diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7218index ae3d59f..f65f075 100644
7219--- a/arch/score/include/asm/cache.h
7220+++ b/arch/score/include/asm/cache.h
7221@@ -1,7 +1,9 @@
7222 #ifndef _ASM_SCORE_CACHE_H
7223 #define _ASM_SCORE_CACHE_H
7224
7225+#include <linux/const.h>
7226+
7227 #define L1_CACHE_SHIFT 4
7228-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7229+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7230
7231 #endif /* _ASM_SCORE_CACHE_H */
7232diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7233index f9f3cd5..58ff438 100644
7234--- a/arch/score/include/asm/exec.h
7235+++ b/arch/score/include/asm/exec.h
7236@@ -1,6 +1,6 @@
7237 #ifndef _ASM_SCORE_EXEC_H
7238 #define _ASM_SCORE_EXEC_H
7239
7240-extern unsigned long arch_align_stack(unsigned long sp);
7241+#define arch_align_stack(x) (x)
7242
7243 #endif /* _ASM_SCORE_EXEC_H */
7244diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7245index 7956846..5f37677 100644
7246--- a/arch/score/kernel/process.c
7247+++ b/arch/score/kernel/process.c
7248@@ -134,8 +134,3 @@ unsigned long get_wchan(struct task_struct *task)
7249
7250 return task_pt_regs(task)->cp0_epc;
7251 }
7252-
7253-unsigned long arch_align_stack(unsigned long sp)
7254-{
7255- return sp;
7256-}
7257diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7258index ef9e555..331bd29 100644
7259--- a/arch/sh/include/asm/cache.h
7260+++ b/arch/sh/include/asm/cache.h
7261@@ -9,10 +9,11 @@
7262 #define __ASM_SH_CACHE_H
7263 #ifdef __KERNEL__
7264
7265+#include <linux/const.h>
7266 #include <linux/init.h>
7267 #include <cpu/cache.h>
7268
7269-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7270+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7271
7272 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7273
7274diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7275index 03f2b55..b027032 100644
7276--- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7277+++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7278@@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7279 return NOTIFY_OK;
7280 }
7281
7282-static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7283+static struct notifier_block shx3_cpu_notifier = {
7284 .notifier_call = shx3_cpu_callback,
7285 };
7286
7287diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7288index 6777177..cb5e44f 100644
7289--- a/arch/sh/mm/mmap.c
7290+++ b/arch/sh/mm/mmap.c
7291@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7292 struct mm_struct *mm = current->mm;
7293 struct vm_area_struct *vma;
7294 int do_colour_align;
7295+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7296 struct vm_unmapped_area_info info;
7297
7298 if (flags & MAP_FIXED) {
7299@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7300 if (filp || (flags & MAP_SHARED))
7301 do_colour_align = 1;
7302
7303+#ifdef CONFIG_PAX_RANDMMAP
7304+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7305+#endif
7306+
7307 if (addr) {
7308 if (do_colour_align)
7309 addr = COLOUR_ALIGN(addr, pgoff);
7310@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7311 addr = PAGE_ALIGN(addr);
7312
7313 vma = find_vma(mm, addr);
7314- if (TASK_SIZE - len >= addr &&
7315- (!vma || addr + len <= vma->vm_start))
7316+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7317 return addr;
7318 }
7319
7320 info.flags = 0;
7321 info.length = len;
7322- info.low_limit = TASK_UNMAPPED_BASE;
7323+ info.low_limit = mm->mmap_base;
7324 info.high_limit = TASK_SIZE;
7325 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7326 info.align_offset = pgoff << PAGE_SHIFT;
7327@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7328 struct mm_struct *mm = current->mm;
7329 unsigned long addr = addr0;
7330 int do_colour_align;
7331+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7332 struct vm_unmapped_area_info info;
7333
7334 if (flags & MAP_FIXED) {
7335@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7336 if (filp || (flags & MAP_SHARED))
7337 do_colour_align = 1;
7338
7339+#ifdef CONFIG_PAX_RANDMMAP
7340+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7341+#endif
7342+
7343 /* requesting a specific address */
7344 if (addr) {
7345 if (do_colour_align)
7346@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7347 addr = PAGE_ALIGN(addr);
7348
7349 vma = find_vma(mm, addr);
7350- if (TASK_SIZE - len >= addr &&
7351- (!vma || addr + len <= vma->vm_start))
7352+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7353 return addr;
7354 }
7355
7356@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7357 VM_BUG_ON(addr != -ENOMEM);
7358 info.flags = 0;
7359 info.low_limit = TASK_UNMAPPED_BASE;
7360+
7361+#ifdef CONFIG_PAX_RANDMMAP
7362+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7363+ info.low_limit += mm->delta_mmap;
7364+#endif
7365+
7366 info.high_limit = TASK_SIZE;
7367 addr = vm_unmapped_area(&info);
7368 }
7369diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7370index be56a24..443328f 100644
7371--- a/arch/sparc/include/asm/atomic_64.h
7372+++ b/arch/sparc/include/asm/atomic_64.h
7373@@ -14,18 +14,40 @@
7374 #define ATOMIC64_INIT(i) { (i) }
7375
7376 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7377+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7378+{
7379+ return v->counter;
7380+}
7381 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7382+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7383+{
7384+ return v->counter;
7385+}
7386
7387 #define atomic_set(v, i) (((v)->counter) = i)
7388+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7389+{
7390+ v->counter = i;
7391+}
7392 #define atomic64_set(v, i) (((v)->counter) = i)
7393+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7394+{
7395+ v->counter = i;
7396+}
7397
7398 extern void atomic_add(int, atomic_t *);
7399+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7400 extern void atomic64_add(long, atomic64_t *);
7401+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7402 extern void atomic_sub(int, atomic_t *);
7403+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7404 extern void atomic64_sub(long, atomic64_t *);
7405+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7406
7407 extern int atomic_add_ret(int, atomic_t *);
7408+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7409 extern long atomic64_add_ret(long, atomic64_t *);
7410+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7411 extern int atomic_sub_ret(int, atomic_t *);
7412 extern long atomic64_sub_ret(long, atomic64_t *);
7413
7414@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7415 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7416
7417 #define atomic_inc_return(v) atomic_add_ret(1, v)
7418+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7419+{
7420+ return atomic_add_ret_unchecked(1, v);
7421+}
7422 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7423+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7424+{
7425+ return atomic64_add_ret_unchecked(1, v);
7426+}
7427
7428 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7429 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7430
7431 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7432+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7433+{
7434+ return atomic_add_ret_unchecked(i, v);
7435+}
7436 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7437+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7438+{
7439+ return atomic64_add_ret_unchecked(i, v);
7440+}
7441
7442 /*
7443 * atomic_inc_and_test - increment and test
7444@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7445 * other cases.
7446 */
7447 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7448+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7449+{
7450+ return atomic_inc_return_unchecked(v) == 0;
7451+}
7452 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7453
7454 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7455@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7456 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7457
7458 #define atomic_inc(v) atomic_add(1, v)
7459+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7460+{
7461+ atomic_add_unchecked(1, v);
7462+}
7463 #define atomic64_inc(v) atomic64_add(1, v)
7464+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7465+{
7466+ atomic64_add_unchecked(1, v);
7467+}
7468
7469 #define atomic_dec(v) atomic_sub(1, v)
7470+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7471+{
7472+ atomic_sub_unchecked(1, v);
7473+}
7474 #define atomic64_dec(v) atomic64_sub(1, v)
7475+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7476+{
7477+ atomic64_sub_unchecked(1, v);
7478+}
7479
7480 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7481 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7482
7483 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7484+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7485+{
7486+ return cmpxchg(&v->counter, old, new);
7487+}
7488 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7489+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7490+{
7491+ return xchg(&v->counter, new);
7492+}
7493
7494 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7495 {
7496- int c, old;
7497+ int c, old, new;
7498 c = atomic_read(v);
7499 for (;;) {
7500- if (unlikely(c == (u)))
7501+ if (unlikely(c == u))
7502 break;
7503- old = atomic_cmpxchg((v), c, c + (a));
7504+
7505+ asm volatile("addcc %2, %0, %0\n"
7506+
7507+#ifdef CONFIG_PAX_REFCOUNT
7508+ "tvs %%icc, 6\n"
7509+#endif
7510+
7511+ : "=r" (new)
7512+ : "0" (c), "ir" (a)
7513+ : "cc");
7514+
7515+ old = atomic_cmpxchg(v, c, new);
7516 if (likely(old == c))
7517 break;
7518 c = old;
7519@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7520 #define atomic64_cmpxchg(v, o, n) \
7521 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7522 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7523+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7524+{
7525+ return xchg(&v->counter, new);
7526+}
7527
7528 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7529 {
7530- long c, old;
7531+ long c, old, new;
7532 c = atomic64_read(v);
7533 for (;;) {
7534- if (unlikely(c == (u)))
7535+ if (unlikely(c == u))
7536 break;
7537- old = atomic64_cmpxchg((v), c, c + (a));
7538+
7539+ asm volatile("addcc %2, %0, %0\n"
7540+
7541+#ifdef CONFIG_PAX_REFCOUNT
7542+ "tvs %%xcc, 6\n"
7543+#endif
7544+
7545+ : "=r" (new)
7546+ : "0" (c), "ir" (a)
7547+ : "cc");
7548+
7549+ old = atomic64_cmpxchg(v, c, new);
7550 if (likely(old == c))
7551 break;
7552 c = old;
7553 }
7554- return c != (u);
7555+ return c != u;
7556 }
7557
7558 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7559diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7560index 5bb6991..5c2132e 100644
7561--- a/arch/sparc/include/asm/cache.h
7562+++ b/arch/sparc/include/asm/cache.h
7563@@ -7,10 +7,12 @@
7564 #ifndef _SPARC_CACHE_H
7565 #define _SPARC_CACHE_H
7566
7567+#include <linux/const.h>
7568+
7569 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7570
7571 #define L1_CACHE_SHIFT 5
7572-#define L1_CACHE_BYTES 32
7573+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7574
7575 #ifdef CONFIG_SPARC32
7576 #define SMP_CACHE_BYTES_SHIFT 5
7577diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7578index ac74a2c..a9e58af 100644
7579--- a/arch/sparc/include/asm/elf_32.h
7580+++ b/arch/sparc/include/asm/elf_32.h
7581@@ -114,6 +114,13 @@ typedef struct {
7582
7583 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7584
7585+#ifdef CONFIG_PAX_ASLR
7586+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7587+
7588+#define PAX_DELTA_MMAP_LEN 16
7589+#define PAX_DELTA_STACK_LEN 16
7590+#endif
7591+
7592 /* This yields a mask that user programs can use to figure out what
7593 instruction set this cpu supports. This can NOT be done in userspace
7594 on Sparc. */
7595diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7596index 370ca1e..d4f4a98 100644
7597--- a/arch/sparc/include/asm/elf_64.h
7598+++ b/arch/sparc/include/asm/elf_64.h
7599@@ -189,6 +189,13 @@ typedef struct {
7600 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7601 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7602
7603+#ifdef CONFIG_PAX_ASLR
7604+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7605+
7606+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7607+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7608+#endif
7609+
7610 extern unsigned long sparc64_elf_hwcap;
7611 #define ELF_HWCAP sparc64_elf_hwcap
7612
7613diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7614index 9b1c36d..209298b 100644
7615--- a/arch/sparc/include/asm/pgalloc_32.h
7616+++ b/arch/sparc/include/asm/pgalloc_32.h
7617@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7618 }
7619
7620 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7621+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7622
7623 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7624 unsigned long address)
7625diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7626index bcfe063..b333142 100644
7627--- a/arch/sparc/include/asm/pgalloc_64.h
7628+++ b/arch/sparc/include/asm/pgalloc_64.h
7629@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7630 }
7631
7632 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7633+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7634
7635 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7636 {
7637diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7638index 6fc1348..390c50a 100644
7639--- a/arch/sparc/include/asm/pgtable_32.h
7640+++ b/arch/sparc/include/asm/pgtable_32.h
7641@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7642 #define PAGE_SHARED SRMMU_PAGE_SHARED
7643 #define PAGE_COPY SRMMU_PAGE_COPY
7644 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7645+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7646+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7647+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7648 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7649
7650 /* Top-level page directory - dummy used by init-mm.
7651@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7652
7653 /* xwr */
7654 #define __P000 PAGE_NONE
7655-#define __P001 PAGE_READONLY
7656-#define __P010 PAGE_COPY
7657-#define __P011 PAGE_COPY
7658+#define __P001 PAGE_READONLY_NOEXEC
7659+#define __P010 PAGE_COPY_NOEXEC
7660+#define __P011 PAGE_COPY_NOEXEC
7661 #define __P100 PAGE_READONLY
7662 #define __P101 PAGE_READONLY
7663 #define __P110 PAGE_COPY
7664 #define __P111 PAGE_COPY
7665
7666 #define __S000 PAGE_NONE
7667-#define __S001 PAGE_READONLY
7668-#define __S010 PAGE_SHARED
7669-#define __S011 PAGE_SHARED
7670+#define __S001 PAGE_READONLY_NOEXEC
7671+#define __S010 PAGE_SHARED_NOEXEC
7672+#define __S011 PAGE_SHARED_NOEXEC
7673 #define __S100 PAGE_READONLY
7674 #define __S101 PAGE_READONLY
7675 #define __S110 PAGE_SHARED
7676diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7677index 79da178..c2eede8 100644
7678--- a/arch/sparc/include/asm/pgtsrmmu.h
7679+++ b/arch/sparc/include/asm/pgtsrmmu.h
7680@@ -115,6 +115,11 @@
7681 SRMMU_EXEC | SRMMU_REF)
7682 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7683 SRMMU_EXEC | SRMMU_REF)
7684+
7685+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
7686+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7687+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7688+
7689 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
7690 SRMMU_DIRTY | SRMMU_REF)
7691
7692diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
7693index 9689176..63c18ea 100644
7694--- a/arch/sparc/include/asm/spinlock_64.h
7695+++ b/arch/sparc/include/asm/spinlock_64.h
7696@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
7697
7698 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
7699
7700-static void inline arch_read_lock(arch_rwlock_t *lock)
7701+static inline void arch_read_lock(arch_rwlock_t *lock)
7702 {
7703 unsigned long tmp1, tmp2;
7704
7705 __asm__ __volatile__ (
7706 "1: ldsw [%2], %0\n"
7707 " brlz,pn %0, 2f\n"
7708-"4: add %0, 1, %1\n"
7709+"4: addcc %0, 1, %1\n"
7710+
7711+#ifdef CONFIG_PAX_REFCOUNT
7712+" tvs %%icc, 6\n"
7713+#endif
7714+
7715 " cas [%2], %0, %1\n"
7716 " cmp %0, %1\n"
7717 " bne,pn %%icc, 1b\n"
7718@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
7719 " .previous"
7720 : "=&r" (tmp1), "=&r" (tmp2)
7721 : "r" (lock)
7722- : "memory");
7723+ : "memory", "cc");
7724 }
7725
7726-static int inline arch_read_trylock(arch_rwlock_t *lock)
7727+static inline int arch_read_trylock(arch_rwlock_t *lock)
7728 {
7729 int tmp1, tmp2;
7730
7731@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7732 "1: ldsw [%2], %0\n"
7733 " brlz,a,pn %0, 2f\n"
7734 " mov 0, %0\n"
7735-" add %0, 1, %1\n"
7736+" addcc %0, 1, %1\n"
7737+
7738+#ifdef CONFIG_PAX_REFCOUNT
7739+" tvs %%icc, 6\n"
7740+#endif
7741+
7742 " cas [%2], %0, %1\n"
7743 " cmp %0, %1\n"
7744 " bne,pn %%icc, 1b\n"
7745@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7746 return tmp1;
7747 }
7748
7749-static void inline arch_read_unlock(arch_rwlock_t *lock)
7750+static inline void arch_read_unlock(arch_rwlock_t *lock)
7751 {
7752 unsigned long tmp1, tmp2;
7753
7754 __asm__ __volatile__(
7755 "1: lduw [%2], %0\n"
7756-" sub %0, 1, %1\n"
7757+" subcc %0, 1, %1\n"
7758+
7759+#ifdef CONFIG_PAX_REFCOUNT
7760+" tvs %%icc, 6\n"
7761+#endif
7762+
7763 " cas [%2], %0, %1\n"
7764 " cmp %0, %1\n"
7765 " bne,pn %%xcc, 1b\n"
7766@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
7767 : "memory");
7768 }
7769
7770-static void inline arch_write_lock(arch_rwlock_t *lock)
7771+static inline void arch_write_lock(arch_rwlock_t *lock)
7772 {
7773 unsigned long mask, tmp1, tmp2;
7774
7775@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
7776 : "memory");
7777 }
7778
7779-static void inline arch_write_unlock(arch_rwlock_t *lock)
7780+static inline void arch_write_unlock(arch_rwlock_t *lock)
7781 {
7782 __asm__ __volatile__(
7783 " stw %%g0, [%0]"
7784@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
7785 : "memory");
7786 }
7787
7788-static int inline arch_write_trylock(arch_rwlock_t *lock)
7789+static inline int arch_write_trylock(arch_rwlock_t *lock)
7790 {
7791 unsigned long mask, tmp1, tmp2, result;
7792
7793diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
7794index 25849ae..924c54b 100644
7795--- a/arch/sparc/include/asm/thread_info_32.h
7796+++ b/arch/sparc/include/asm/thread_info_32.h
7797@@ -49,6 +49,8 @@ struct thread_info {
7798 unsigned long w_saved;
7799
7800 struct restart_block restart_block;
7801+
7802+ unsigned long lowest_stack;
7803 };
7804
7805 /*
7806diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
7807index 269bd92..e46a9b8 100644
7808--- a/arch/sparc/include/asm/thread_info_64.h
7809+++ b/arch/sparc/include/asm/thread_info_64.h
7810@@ -63,6 +63,8 @@ struct thread_info {
7811 struct pt_regs *kern_una_regs;
7812 unsigned int kern_una_insn;
7813
7814+ unsigned long lowest_stack;
7815+
7816 unsigned long fpregs[0] __attribute__ ((aligned(64)));
7817 };
7818
7819@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
7820 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
7821 /* flag bit 6 is available */
7822 #define TIF_32BIT 7 /* 32-bit binary */
7823-/* flag bit 8 is available */
7824+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
7825 #define TIF_SECCOMP 9 /* secure computing */
7826 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
7827 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
7828+
7829 /* NOTE: Thread flags >= 12 should be ones we have no interest
7830 * in using in assembly, else we can't use the mask as
7831 * an immediate value in instructions such as andcc.
7832@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
7833 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
7834 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7835 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
7836+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7837
7838 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
7839 _TIF_DO_NOTIFY_RESUME_MASK | \
7840 _TIF_NEED_RESCHED)
7841 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
7842
7843+#define _TIF_WORK_SYSCALL \
7844+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
7845+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
7846+
7847+
7848 /*
7849 * Thread-synchronous status.
7850 *
7851diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
7852index 0167d26..9acd8ed 100644
7853--- a/arch/sparc/include/asm/uaccess.h
7854+++ b/arch/sparc/include/asm/uaccess.h
7855@@ -1,5 +1,13 @@
7856 #ifndef ___ASM_SPARC_UACCESS_H
7857 #define ___ASM_SPARC_UACCESS_H
7858+
7859+#ifdef __KERNEL__
7860+#ifndef __ASSEMBLY__
7861+#include <linux/types.h>
7862+extern void check_object_size(const void *ptr, unsigned long n, bool to);
7863+#endif
7864+#endif
7865+
7866 #if defined(__sparc__) && defined(__arch64__)
7867 #include <asm/uaccess_64.h>
7868 #else
7869diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
7870index 53a28dd..50c38c3 100644
7871--- a/arch/sparc/include/asm/uaccess_32.h
7872+++ b/arch/sparc/include/asm/uaccess_32.h
7873@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
7874
7875 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
7876 {
7877- if (n && __access_ok((unsigned long) to, n))
7878+ if ((long)n < 0)
7879+ return n;
7880+
7881+ if (n && __access_ok((unsigned long) to, n)) {
7882+ if (!__builtin_constant_p(n))
7883+ check_object_size(from, n, true);
7884 return __copy_user(to, (__force void __user *) from, n);
7885- else
7886+ } else
7887 return n;
7888 }
7889
7890 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
7891 {
7892+ if ((long)n < 0)
7893+ return n;
7894+
7895+ if (!__builtin_constant_p(n))
7896+ check_object_size(from, n, true);
7897+
7898 return __copy_user(to, (__force void __user *) from, n);
7899 }
7900
7901 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
7902 {
7903- if (n && __access_ok((unsigned long) from, n))
7904+ if ((long)n < 0)
7905+ return n;
7906+
7907+ if (n && __access_ok((unsigned long) from, n)) {
7908+ if (!__builtin_constant_p(n))
7909+ check_object_size(to, n, false);
7910 return __copy_user((__force void __user *) to, from, n);
7911- else
7912+ } else
7913 return n;
7914 }
7915
7916 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
7917 {
7918+ if ((long)n < 0)
7919+ return n;
7920+
7921 return __copy_user((__force void __user *) to, from, n);
7922 }
7923
7924diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
7925index e562d3c..191f176 100644
7926--- a/arch/sparc/include/asm/uaccess_64.h
7927+++ b/arch/sparc/include/asm/uaccess_64.h
7928@@ -10,6 +10,7 @@
7929 #include <linux/compiler.h>
7930 #include <linux/string.h>
7931 #include <linux/thread_info.h>
7932+#include <linux/kernel.h>
7933 #include <asm/asi.h>
7934 #include <asm/spitfire.h>
7935 #include <asm-generic/uaccess-unaligned.h>
7936@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
7937 static inline unsigned long __must_check
7938 copy_from_user(void *to, const void __user *from, unsigned long size)
7939 {
7940- unsigned long ret = ___copy_from_user(to, from, size);
7941+ unsigned long ret;
7942
7943+ if ((long)size < 0 || size > INT_MAX)
7944+ return size;
7945+
7946+ if (!__builtin_constant_p(size))
7947+ check_object_size(to, size, false);
7948+
7949+ ret = ___copy_from_user(to, from, size);
7950 if (unlikely(ret))
7951 ret = copy_from_user_fixup(to, from, size);
7952
7953@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
7954 static inline unsigned long __must_check
7955 copy_to_user(void __user *to, const void *from, unsigned long size)
7956 {
7957- unsigned long ret = ___copy_to_user(to, from, size);
7958+ unsigned long ret;
7959
7960+ if ((long)size < 0 || size > INT_MAX)
7961+ return size;
7962+
7963+ if (!__builtin_constant_p(size))
7964+ check_object_size(from, size, true);
7965+
7966+ ret = ___copy_to_user(to, from, size);
7967 if (unlikely(ret))
7968 ret = copy_to_user_fixup(to, from, size);
7969 return ret;
7970diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
7971index 6cf591b..b49e65a 100644
7972--- a/arch/sparc/kernel/Makefile
7973+++ b/arch/sparc/kernel/Makefile
7974@@ -3,7 +3,7 @@
7975 #
7976
7977 asflags-y := -ansi
7978-ccflags-y := -Werror
7979+#ccflags-y := -Werror
7980
7981 extra-y := head_$(BITS).o
7982
7983diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
7984index be8e862..5b50b12 100644
7985--- a/arch/sparc/kernel/process_32.c
7986+++ b/arch/sparc/kernel/process_32.c
7987@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
7988
7989 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
7990 r->psr, r->pc, r->npc, r->y, print_tainted());
7991- printk("PC: <%pS>\n", (void *) r->pc);
7992+ printk("PC: <%pA>\n", (void *) r->pc);
7993 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
7994 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
7995 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
7996 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
7997 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
7998 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
7999- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8000+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8001
8002 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8003 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8004@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8005 rw = (struct reg_window32 *) fp;
8006 pc = rw->ins[7];
8007 printk("[%08lx : ", pc);
8008- printk("%pS ] ", (void *) pc);
8009+ printk("%pA ] ", (void *) pc);
8010 fp = rw->ins[6];
8011 } while (++count < 16);
8012 printk("\n");
8013diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8014index cdb80b2..5ca141d 100644
8015--- a/arch/sparc/kernel/process_64.c
8016+++ b/arch/sparc/kernel/process_64.c
8017@@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
8018 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8019 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8020 if (regs->tstate & TSTATE_PRIV)
8021- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8022+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8023 }
8024
8025 void show_regs(struct pt_regs *regs)
8026 {
8027 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8028 regs->tpc, regs->tnpc, regs->y, print_tainted());
8029- printk("TPC: <%pS>\n", (void *) regs->tpc);
8030+ printk("TPC: <%pA>\n", (void *) regs->tpc);
8031 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8032 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8033 regs->u_regs[3]);
8034@@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
8035 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8036 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8037 regs->u_regs[15]);
8038- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8039+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8040 show_regwindow(regs);
8041 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8042 }
8043@@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
8044 ((tp && tp->task) ? tp->task->pid : -1));
8045
8046 if (gp->tstate & TSTATE_PRIV) {
8047- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8048+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8049 (void *) gp->tpc,
8050 (void *) gp->o7,
8051 (void *) gp->i7,
8052diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8053index 7ff45e4..a58f271 100644
8054--- a/arch/sparc/kernel/ptrace_64.c
8055+++ b/arch/sparc/kernel/ptrace_64.c
8056@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8057 return ret;
8058 }
8059
8060+#ifdef CONFIG_GRKERNSEC_SETXID
8061+extern void gr_delayed_cred_worker(void);
8062+#endif
8063+
8064 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8065 {
8066 int ret = 0;
8067@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8068 /* do the secure computing check first */
8069 secure_computing_strict(regs->u_regs[UREG_G1]);
8070
8071+#ifdef CONFIG_GRKERNSEC_SETXID
8072+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8073+ gr_delayed_cred_worker();
8074+#endif
8075+
8076 if (test_thread_flag(TIF_SYSCALL_TRACE))
8077 ret = tracehook_report_syscall_entry(regs);
8078
8079@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8080
8081 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8082 {
8083+#ifdef CONFIG_GRKERNSEC_SETXID
8084+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8085+ gr_delayed_cred_worker();
8086+#endif
8087+
8088 audit_syscall_exit(regs);
8089
8090 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8091diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8092index 2da0bdc..79128d2 100644
8093--- a/arch/sparc/kernel/sys_sparc_32.c
8094+++ b/arch/sparc/kernel/sys_sparc_32.c
8095@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8096 if (len > TASK_SIZE - PAGE_SIZE)
8097 return -ENOMEM;
8098 if (!addr)
8099- addr = TASK_UNMAPPED_BASE;
8100+ addr = current->mm->mmap_base;
8101
8102 info.flags = 0;
8103 info.length = len;
8104diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8105index 708bc29..f0129cb 100644
8106--- a/arch/sparc/kernel/sys_sparc_64.c
8107+++ b/arch/sparc/kernel/sys_sparc_64.c
8108@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8109 struct vm_area_struct * vma;
8110 unsigned long task_size = TASK_SIZE;
8111 int do_color_align;
8112+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8113 struct vm_unmapped_area_info info;
8114
8115 if (flags & MAP_FIXED) {
8116 /* We do not accept a shared mapping if it would violate
8117 * cache aliasing constraints.
8118 */
8119- if ((flags & MAP_SHARED) &&
8120+ if ((filp || (flags & MAP_SHARED)) &&
8121 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8122 return -EINVAL;
8123 return addr;
8124@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8125 if (filp || (flags & MAP_SHARED))
8126 do_color_align = 1;
8127
8128+#ifdef CONFIG_PAX_RANDMMAP
8129+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8130+#endif
8131+
8132 if (addr) {
8133 if (do_color_align)
8134 addr = COLOR_ALIGN(addr, pgoff);
8135@@ -118,14 +123,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8136 addr = PAGE_ALIGN(addr);
8137
8138 vma = find_vma(mm, addr);
8139- if (task_size - len >= addr &&
8140- (!vma || addr + len <= vma->vm_start))
8141+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8142 return addr;
8143 }
8144
8145 info.flags = 0;
8146 info.length = len;
8147- info.low_limit = TASK_UNMAPPED_BASE;
8148+ info.low_limit = mm->mmap_base;
8149 info.high_limit = min(task_size, VA_EXCLUDE_START);
8150 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8151 info.align_offset = pgoff << PAGE_SHIFT;
8152@@ -134,6 +138,12 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8153 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8154 VM_BUG_ON(addr != -ENOMEM);
8155 info.low_limit = VA_EXCLUDE_END;
8156+
8157+#ifdef CONFIG_PAX_RANDMMAP
8158+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8159+ info.low_limit += mm->delta_mmap;
8160+#endif
8161+
8162 info.high_limit = task_size;
8163 addr = vm_unmapped_area(&info);
8164 }
8165@@ -151,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8166 unsigned long task_size = STACK_TOP32;
8167 unsigned long addr = addr0;
8168 int do_color_align;
8169+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8170 struct vm_unmapped_area_info info;
8171
8172 /* This should only ever run for 32-bit processes. */
8173@@ -160,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8174 /* We do not accept a shared mapping if it would violate
8175 * cache aliasing constraints.
8176 */
8177- if ((flags & MAP_SHARED) &&
8178+ if ((filp || (flags & MAP_SHARED)) &&
8179 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8180 return -EINVAL;
8181 return addr;
8182@@ -173,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8183 if (filp || (flags & MAP_SHARED))
8184 do_color_align = 1;
8185
8186+#ifdef CONFIG_PAX_RANDMMAP
8187+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8188+#endif
8189+
8190 /* requesting a specific address */
8191 if (addr) {
8192 if (do_color_align)
8193@@ -181,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8194 addr = PAGE_ALIGN(addr);
8195
8196 vma = find_vma(mm, addr);
8197- if (task_size - len >= addr &&
8198- (!vma || addr + len <= vma->vm_start))
8199+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8200 return addr;
8201 }
8202
8203@@ -204,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8204 VM_BUG_ON(addr != -ENOMEM);
8205 info.flags = 0;
8206 info.low_limit = TASK_UNMAPPED_BASE;
8207+
8208+#ifdef CONFIG_PAX_RANDMMAP
8209+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8210+ info.low_limit += mm->delta_mmap;
8211+#endif
8212+
8213 info.high_limit = STACK_TOP32;
8214 addr = vm_unmapped_area(&info);
8215 }
8216@@ -264,6 +284,10 @@ static unsigned long mmap_rnd(void)
8217 {
8218 unsigned long rnd = 0UL;
8219
8220+#ifdef CONFIG_PAX_RANDMMAP
8221+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8222+#endif
8223+
8224 if (current->flags & PF_RANDOMIZE) {
8225 unsigned long val = get_random_int();
8226 if (test_thread_flag(TIF_32BIT))
8227@@ -289,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8228 gap == RLIM_INFINITY ||
8229 sysctl_legacy_va_layout) {
8230 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8231+
8232+#ifdef CONFIG_PAX_RANDMMAP
8233+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8234+ mm->mmap_base += mm->delta_mmap;
8235+#endif
8236+
8237 mm->get_unmapped_area = arch_get_unmapped_area;
8238 mm->unmap_area = arch_unmap_area;
8239 } else {
8240@@ -301,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8241 gap = (task_size / 6 * 5);
8242
8243 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8244+
8245+#ifdef CONFIG_PAX_RANDMMAP
8246+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8247+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8248+#endif
8249+
8250 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8251 mm->unmap_area = arch_unmap_area_topdown;
8252 }
8253diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8254index e0fed77..604a7e5 100644
8255--- a/arch/sparc/kernel/syscalls.S
8256+++ b/arch/sparc/kernel/syscalls.S
8257@@ -58,7 +58,7 @@ sys32_rt_sigreturn:
8258 #endif
8259 .align 32
8260 1: ldx [%g6 + TI_FLAGS], %l5
8261- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8262+ andcc %l5, _TIF_WORK_SYSCALL, %g0
8263 be,pt %icc, rtrap
8264 nop
8265 call syscall_trace_leave
8266@@ -190,7 +190,7 @@ linux_sparc_syscall32:
8267
8268 srl %i5, 0, %o5 ! IEU1
8269 srl %i2, 0, %o2 ! IEU0 Group
8270- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8271+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8272 bne,pn %icc, linux_syscall_trace32 ! CTI
8273 mov %i0, %l5 ! IEU1
8274 call %l7 ! CTI Group brk forced
8275@@ -213,7 +213,7 @@ linux_sparc_syscall:
8276
8277 mov %i3, %o3 ! IEU1
8278 mov %i4, %o4 ! IEU0 Group
8279- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8280+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8281 bne,pn %icc, linux_syscall_trace ! CTI Group
8282 mov %i0, %l5 ! IEU0
8283 2: call %l7 ! CTI Group brk forced
8284@@ -229,7 +229,7 @@ ret_sys_call:
8285
8286 cmp %o0, -ERESTART_RESTARTBLOCK
8287 bgeu,pn %xcc, 1f
8288- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8289+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8290 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8291
8292 2:
8293diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8294index 654e8aa..45f431b 100644
8295--- a/arch/sparc/kernel/sysfs.c
8296+++ b/arch/sparc/kernel/sysfs.c
8297@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8298 return NOTIFY_OK;
8299 }
8300
8301-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8302+static struct notifier_block sysfs_cpu_nb = {
8303 .notifier_call = sysfs_cpu_notify,
8304 };
8305
8306diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8307index a5785ea..405c5f7 100644
8308--- a/arch/sparc/kernel/traps_32.c
8309+++ b/arch/sparc/kernel/traps_32.c
8310@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8311 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8312 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8313
8314+extern void gr_handle_kernel_exploit(void);
8315+
8316 void die_if_kernel(char *str, struct pt_regs *regs)
8317 {
8318 static int die_counter;
8319@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8320 count++ < 30 &&
8321 (((unsigned long) rw) >= PAGE_OFFSET) &&
8322 !(((unsigned long) rw) & 0x7)) {
8323- printk("Caller[%08lx]: %pS\n", rw->ins[7],
8324+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
8325 (void *) rw->ins[7]);
8326 rw = (struct reg_window32 *)rw->ins[6];
8327 }
8328 }
8329 printk("Instruction DUMP:");
8330 instruction_dump ((unsigned long *) regs->pc);
8331- if(regs->psr & PSR_PS)
8332+ if(regs->psr & PSR_PS) {
8333+ gr_handle_kernel_exploit();
8334 do_exit(SIGKILL);
8335+ }
8336 do_exit(SIGSEGV);
8337 }
8338
8339diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8340index e7ecf15..6520e65 100644
8341--- a/arch/sparc/kernel/traps_64.c
8342+++ b/arch/sparc/kernel/traps_64.c
8343@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8344 i + 1,
8345 p->trapstack[i].tstate, p->trapstack[i].tpc,
8346 p->trapstack[i].tnpc, p->trapstack[i].tt);
8347- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8348+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8349 }
8350 }
8351
8352@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8353
8354 lvl -= 0x100;
8355 if (regs->tstate & TSTATE_PRIV) {
8356+
8357+#ifdef CONFIG_PAX_REFCOUNT
8358+ if (lvl == 6)
8359+ pax_report_refcount_overflow(regs);
8360+#endif
8361+
8362 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8363 die_if_kernel(buffer, regs);
8364 }
8365@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8366 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8367 {
8368 char buffer[32];
8369-
8370+
8371 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8372 0, lvl, SIGTRAP) == NOTIFY_STOP)
8373 return;
8374
8375+#ifdef CONFIG_PAX_REFCOUNT
8376+ if (lvl == 6)
8377+ pax_report_refcount_overflow(regs);
8378+#endif
8379+
8380 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8381
8382 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8383@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8384 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8385 printk("%s" "ERROR(%d): ",
8386 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8387- printk("TPC<%pS>\n", (void *) regs->tpc);
8388+ printk("TPC<%pA>\n", (void *) regs->tpc);
8389 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8390 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8391 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8392@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8393 smp_processor_id(),
8394 (type & 0x1) ? 'I' : 'D',
8395 regs->tpc);
8396- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8397+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8398 panic("Irrecoverable Cheetah+ parity error.");
8399 }
8400
8401@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8402 smp_processor_id(),
8403 (type & 0x1) ? 'I' : 'D',
8404 regs->tpc);
8405- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8406+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8407 }
8408
8409 struct sun4v_error_entry {
8410@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8411
8412 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8413 regs->tpc, tl);
8414- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8415+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8416 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8417- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8418+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8419 (void *) regs->u_regs[UREG_I7]);
8420 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8421 "pte[%lx] error[%lx]\n",
8422@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8423
8424 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8425 regs->tpc, tl);
8426- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8427+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8428 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8429- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8430+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8431 (void *) regs->u_regs[UREG_I7]);
8432 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8433 "pte[%lx] error[%lx]\n",
8434@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8435 fp = (unsigned long)sf->fp + STACK_BIAS;
8436 }
8437
8438- printk(" [%016lx] %pS\n", pc, (void *) pc);
8439+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8440 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8441 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8442 int index = tsk->curr_ret_stack;
8443 if (tsk->ret_stack && index >= graph) {
8444 pc = tsk->ret_stack[index - graph].ret;
8445- printk(" [%016lx] %pS\n", pc, (void *) pc);
8446+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8447 graph++;
8448 }
8449 }
8450@@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8451 return (struct reg_window *) (fp + STACK_BIAS);
8452 }
8453
8454+extern void gr_handle_kernel_exploit(void);
8455+
8456 void die_if_kernel(char *str, struct pt_regs *regs)
8457 {
8458 static int die_counter;
8459@@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8460 while (rw &&
8461 count++ < 30 &&
8462 kstack_valid(tp, (unsigned long) rw)) {
8463- printk("Caller[%016lx]: %pS\n", rw->ins[7],
8464+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
8465 (void *) rw->ins[7]);
8466
8467 rw = kernel_stack_up(rw);
8468@@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8469 }
8470 user_instruction_dump ((unsigned int __user *) regs->tpc);
8471 }
8472- if (regs->tstate & TSTATE_PRIV)
8473+ if (regs->tstate & TSTATE_PRIV) {
8474+ gr_handle_kernel_exploit();
8475 do_exit(SIGKILL);
8476+ }
8477 do_exit(SIGSEGV);
8478 }
8479 EXPORT_SYMBOL(die_if_kernel);
8480diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8481index 8201c25e..072a2a7 100644
8482--- a/arch/sparc/kernel/unaligned_64.c
8483+++ b/arch/sparc/kernel/unaligned_64.c
8484@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8485 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8486
8487 if (__ratelimit(&ratelimit)) {
8488- printk("Kernel unaligned access at TPC[%lx] %pS\n",
8489+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
8490 regs->tpc, (void *) regs->tpc);
8491 }
8492 }
8493diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8494index 8410065f2..4fd4ca22 100644
8495--- a/arch/sparc/lib/Makefile
8496+++ b/arch/sparc/lib/Makefile
8497@@ -2,7 +2,7 @@
8498 #
8499
8500 asflags-y := -ansi -DST_DIV0=0x02
8501-ccflags-y := -Werror
8502+#ccflags-y := -Werror
8503
8504 lib-$(CONFIG_SPARC32) += ashrdi3.o
8505 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8506diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8507index 85c233d..68500e0 100644
8508--- a/arch/sparc/lib/atomic_64.S
8509+++ b/arch/sparc/lib/atomic_64.S
8510@@ -17,7 +17,12 @@
8511 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8512 BACKOFF_SETUP(%o2)
8513 1: lduw [%o1], %g1
8514- add %g1, %o0, %g7
8515+ addcc %g1, %o0, %g7
8516+
8517+#ifdef CONFIG_PAX_REFCOUNT
8518+ tvs %icc, 6
8519+#endif
8520+
8521 cas [%o1], %g1, %g7
8522 cmp %g1, %g7
8523 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8524@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8525 2: BACKOFF_SPIN(%o2, %o3, 1b)
8526 ENDPROC(atomic_add)
8527
8528+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8529+ BACKOFF_SETUP(%o2)
8530+1: lduw [%o1], %g1
8531+ add %g1, %o0, %g7
8532+ cas [%o1], %g1, %g7
8533+ cmp %g1, %g7
8534+ bne,pn %icc, 2f
8535+ nop
8536+ retl
8537+ nop
8538+2: BACKOFF_SPIN(%o2, %o3, 1b)
8539+ENDPROC(atomic_add_unchecked)
8540+
8541 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8542 BACKOFF_SETUP(%o2)
8543 1: lduw [%o1], %g1
8544- sub %g1, %o0, %g7
8545+ subcc %g1, %o0, %g7
8546+
8547+#ifdef CONFIG_PAX_REFCOUNT
8548+ tvs %icc, 6
8549+#endif
8550+
8551 cas [%o1], %g1, %g7
8552 cmp %g1, %g7
8553 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8554@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8555 2: BACKOFF_SPIN(%o2, %o3, 1b)
8556 ENDPROC(atomic_sub)
8557
8558+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8559+ BACKOFF_SETUP(%o2)
8560+1: lduw [%o1], %g1
8561+ sub %g1, %o0, %g7
8562+ cas [%o1], %g1, %g7
8563+ cmp %g1, %g7
8564+ bne,pn %icc, 2f
8565+ nop
8566+ retl
8567+ nop
8568+2: BACKOFF_SPIN(%o2, %o3, 1b)
8569+ENDPROC(atomic_sub_unchecked)
8570+
8571 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8572 BACKOFF_SETUP(%o2)
8573 1: lduw [%o1], %g1
8574- add %g1, %o0, %g7
8575+ addcc %g1, %o0, %g7
8576+
8577+#ifdef CONFIG_PAX_REFCOUNT
8578+ tvs %icc, 6
8579+#endif
8580+
8581 cas [%o1], %g1, %g7
8582 cmp %g1, %g7
8583 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8584@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8585 2: BACKOFF_SPIN(%o2, %o3, 1b)
8586 ENDPROC(atomic_add_ret)
8587
8588+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8589+ BACKOFF_SETUP(%o2)
8590+1: lduw [%o1], %g1
8591+ addcc %g1, %o0, %g7
8592+ cas [%o1], %g1, %g7
8593+ cmp %g1, %g7
8594+ bne,pn %icc, 2f
8595+ add %g7, %o0, %g7
8596+ sra %g7, 0, %o0
8597+ retl
8598+ nop
8599+2: BACKOFF_SPIN(%o2, %o3, 1b)
8600+ENDPROC(atomic_add_ret_unchecked)
8601+
8602 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8603 BACKOFF_SETUP(%o2)
8604 1: lduw [%o1], %g1
8605- sub %g1, %o0, %g7
8606+ subcc %g1, %o0, %g7
8607+
8608+#ifdef CONFIG_PAX_REFCOUNT
8609+ tvs %icc, 6
8610+#endif
8611+
8612 cas [%o1], %g1, %g7
8613 cmp %g1, %g7
8614 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8615@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
8616 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8617 BACKOFF_SETUP(%o2)
8618 1: ldx [%o1], %g1
8619- add %g1, %o0, %g7
8620+ addcc %g1, %o0, %g7
8621+
8622+#ifdef CONFIG_PAX_REFCOUNT
8623+ tvs %xcc, 6
8624+#endif
8625+
8626 casx [%o1], %g1, %g7
8627 cmp %g1, %g7
8628 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8629@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8630 2: BACKOFF_SPIN(%o2, %o3, 1b)
8631 ENDPROC(atomic64_add)
8632
8633+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8634+ BACKOFF_SETUP(%o2)
8635+1: ldx [%o1], %g1
8636+ addcc %g1, %o0, %g7
8637+ casx [%o1], %g1, %g7
8638+ cmp %g1, %g7
8639+ bne,pn %xcc, 2f
8640+ nop
8641+ retl
8642+ nop
8643+2: BACKOFF_SPIN(%o2, %o3, 1b)
8644+ENDPROC(atomic64_add_unchecked)
8645+
8646 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8647 BACKOFF_SETUP(%o2)
8648 1: ldx [%o1], %g1
8649- sub %g1, %o0, %g7
8650+ subcc %g1, %o0, %g7
8651+
8652+#ifdef CONFIG_PAX_REFCOUNT
8653+ tvs %xcc, 6
8654+#endif
8655+
8656 casx [%o1], %g1, %g7
8657 cmp %g1, %g7
8658 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8659@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8660 2: BACKOFF_SPIN(%o2, %o3, 1b)
8661 ENDPROC(atomic64_sub)
8662
8663+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8664+ BACKOFF_SETUP(%o2)
8665+1: ldx [%o1], %g1
8666+ subcc %g1, %o0, %g7
8667+ casx [%o1], %g1, %g7
8668+ cmp %g1, %g7
8669+ bne,pn %xcc, 2f
8670+ nop
8671+ retl
8672+ nop
8673+2: BACKOFF_SPIN(%o2, %o3, 1b)
8674+ENDPROC(atomic64_sub_unchecked)
8675+
8676 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8677 BACKOFF_SETUP(%o2)
8678 1: ldx [%o1], %g1
8679- add %g1, %o0, %g7
8680+ addcc %g1, %o0, %g7
8681+
8682+#ifdef CONFIG_PAX_REFCOUNT
8683+ tvs %xcc, 6
8684+#endif
8685+
8686 casx [%o1], %g1, %g7
8687 cmp %g1, %g7
8688 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8689@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8690 2: BACKOFF_SPIN(%o2, %o3, 1b)
8691 ENDPROC(atomic64_add_ret)
8692
8693+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8694+ BACKOFF_SETUP(%o2)
8695+1: ldx [%o1], %g1
8696+ addcc %g1, %o0, %g7
8697+ casx [%o1], %g1, %g7
8698+ cmp %g1, %g7
8699+ bne,pn %xcc, 2f
8700+ add %g7, %o0, %g7
8701+ mov %g7, %o0
8702+ retl
8703+ nop
8704+2: BACKOFF_SPIN(%o2, %o3, 1b)
8705+ENDPROC(atomic64_add_ret_unchecked)
8706+
8707 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8708 BACKOFF_SETUP(%o2)
8709 1: ldx [%o1], %g1
8710- sub %g1, %o0, %g7
8711+ subcc %g1, %o0, %g7
8712+
8713+#ifdef CONFIG_PAX_REFCOUNT
8714+ tvs %xcc, 6
8715+#endif
8716+
8717 casx [%o1], %g1, %g7
8718 cmp %g1, %g7
8719 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8720diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
8721index 0c4e35e..745d3e4 100644
8722--- a/arch/sparc/lib/ksyms.c
8723+++ b/arch/sparc/lib/ksyms.c
8724@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
8725
8726 /* Atomic counter implementation. */
8727 EXPORT_SYMBOL(atomic_add);
8728+EXPORT_SYMBOL(atomic_add_unchecked);
8729 EXPORT_SYMBOL(atomic_add_ret);
8730+EXPORT_SYMBOL(atomic_add_ret_unchecked);
8731 EXPORT_SYMBOL(atomic_sub);
8732+EXPORT_SYMBOL(atomic_sub_unchecked);
8733 EXPORT_SYMBOL(atomic_sub_ret);
8734 EXPORT_SYMBOL(atomic64_add);
8735+EXPORT_SYMBOL(atomic64_add_unchecked);
8736 EXPORT_SYMBOL(atomic64_add_ret);
8737+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
8738 EXPORT_SYMBOL(atomic64_sub);
8739+EXPORT_SYMBOL(atomic64_sub_unchecked);
8740 EXPORT_SYMBOL(atomic64_sub_ret);
8741 EXPORT_SYMBOL(atomic64_dec_if_positive);
8742
8743diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
8744index 30c3ecc..736f015 100644
8745--- a/arch/sparc/mm/Makefile
8746+++ b/arch/sparc/mm/Makefile
8747@@ -2,7 +2,7 @@
8748 #
8749
8750 asflags-y := -ansi
8751-ccflags-y := -Werror
8752+#ccflags-y := -Werror
8753
8754 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
8755 obj-y += fault_$(BITS).o
8756diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
8757index e98bfda..ea8d221 100644
8758--- a/arch/sparc/mm/fault_32.c
8759+++ b/arch/sparc/mm/fault_32.c
8760@@ -21,6 +21,9 @@
8761 #include <linux/perf_event.h>
8762 #include <linux/interrupt.h>
8763 #include <linux/kdebug.h>
8764+#include <linux/slab.h>
8765+#include <linux/pagemap.h>
8766+#include <linux/compiler.h>
8767
8768 #include <asm/page.h>
8769 #include <asm/pgtable.h>
8770@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
8771 return safe_compute_effective_address(regs, insn);
8772 }
8773
8774+#ifdef CONFIG_PAX_PAGEEXEC
8775+#ifdef CONFIG_PAX_DLRESOLVE
8776+static void pax_emuplt_close(struct vm_area_struct *vma)
8777+{
8778+ vma->vm_mm->call_dl_resolve = 0UL;
8779+}
8780+
8781+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8782+{
8783+ unsigned int *kaddr;
8784+
8785+ vmf->page = alloc_page(GFP_HIGHUSER);
8786+ if (!vmf->page)
8787+ return VM_FAULT_OOM;
8788+
8789+ kaddr = kmap(vmf->page);
8790+ memset(kaddr, 0, PAGE_SIZE);
8791+ kaddr[0] = 0x9DE3BFA8U; /* save */
8792+ flush_dcache_page(vmf->page);
8793+ kunmap(vmf->page);
8794+ return VM_FAULT_MAJOR;
8795+}
8796+
8797+static const struct vm_operations_struct pax_vm_ops = {
8798+ .close = pax_emuplt_close,
8799+ .fault = pax_emuplt_fault
8800+};
8801+
8802+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
8803+{
8804+ int ret;
8805+
8806+ INIT_LIST_HEAD(&vma->anon_vma_chain);
8807+ vma->vm_mm = current->mm;
8808+ vma->vm_start = addr;
8809+ vma->vm_end = addr + PAGE_SIZE;
8810+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
8811+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
8812+ vma->vm_ops = &pax_vm_ops;
8813+
8814+ ret = insert_vm_struct(current->mm, vma);
8815+ if (ret)
8816+ return ret;
8817+
8818+ ++current->mm->total_vm;
8819+ return 0;
8820+}
8821+#endif
8822+
8823+/*
8824+ * PaX: decide what to do with offenders (regs->pc = fault address)
8825+ *
8826+ * returns 1 when task should be killed
8827+ * 2 when patched PLT trampoline was detected
8828+ * 3 when unpatched PLT trampoline was detected
8829+ */
8830+static int pax_handle_fetch_fault(struct pt_regs *regs)
8831+{
8832+
8833+#ifdef CONFIG_PAX_EMUPLT
8834+ int err;
8835+
8836+ do { /* PaX: patched PLT emulation #1 */
8837+ unsigned int sethi1, sethi2, jmpl;
8838+
8839+ err = get_user(sethi1, (unsigned int *)regs->pc);
8840+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
8841+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
8842+
8843+ if (err)
8844+ break;
8845+
8846+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
8847+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
8848+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
8849+ {
8850+ unsigned int addr;
8851+
8852+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
8853+ addr = regs->u_regs[UREG_G1];
8854+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8855+ regs->pc = addr;
8856+ regs->npc = addr+4;
8857+ return 2;
8858+ }
8859+ } while (0);
8860+
8861+ do { /* PaX: patched PLT emulation #2 */
8862+ unsigned int ba;
8863+
8864+ err = get_user(ba, (unsigned int *)regs->pc);
8865+
8866+ if (err)
8867+ break;
8868+
8869+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
8870+ unsigned int addr;
8871+
8872+ if ((ba & 0xFFC00000U) == 0x30800000U)
8873+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
8874+ else
8875+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8876+ regs->pc = addr;
8877+ regs->npc = addr+4;
8878+ return 2;
8879+ }
8880+ } while (0);
8881+
8882+ do { /* PaX: patched PLT emulation #3 */
8883+ unsigned int sethi, bajmpl, nop;
8884+
8885+ err = get_user(sethi, (unsigned int *)regs->pc);
8886+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
8887+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
8888+
8889+ if (err)
8890+ break;
8891+
8892+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8893+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
8894+ nop == 0x01000000U)
8895+ {
8896+ unsigned int addr;
8897+
8898+ addr = (sethi & 0x003FFFFFU) << 10;
8899+ regs->u_regs[UREG_G1] = addr;
8900+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
8901+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8902+ else
8903+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8904+ regs->pc = addr;
8905+ regs->npc = addr+4;
8906+ return 2;
8907+ }
8908+ } while (0);
8909+
8910+ do { /* PaX: unpatched PLT emulation step 1 */
8911+ unsigned int sethi, ba, nop;
8912+
8913+ err = get_user(sethi, (unsigned int *)regs->pc);
8914+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
8915+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
8916+
8917+ if (err)
8918+ break;
8919+
8920+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8921+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
8922+ nop == 0x01000000U)
8923+ {
8924+ unsigned int addr, save, call;
8925+
8926+ if ((ba & 0xFFC00000U) == 0x30800000U)
8927+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
8928+ else
8929+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8930+
8931+ err = get_user(save, (unsigned int *)addr);
8932+ err |= get_user(call, (unsigned int *)(addr+4));
8933+ err |= get_user(nop, (unsigned int *)(addr+8));
8934+ if (err)
8935+ break;
8936+
8937+#ifdef CONFIG_PAX_DLRESOLVE
8938+ if (save == 0x9DE3BFA8U &&
8939+ (call & 0xC0000000U) == 0x40000000U &&
8940+ nop == 0x01000000U)
8941+ {
8942+ struct vm_area_struct *vma;
8943+ unsigned long call_dl_resolve;
8944+
8945+ down_read(&current->mm->mmap_sem);
8946+ call_dl_resolve = current->mm->call_dl_resolve;
8947+ up_read(&current->mm->mmap_sem);
8948+ if (likely(call_dl_resolve))
8949+ goto emulate;
8950+
8951+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
8952+
8953+ down_write(&current->mm->mmap_sem);
8954+ if (current->mm->call_dl_resolve) {
8955+ call_dl_resolve = current->mm->call_dl_resolve;
8956+ up_write(&current->mm->mmap_sem);
8957+ if (vma)
8958+ kmem_cache_free(vm_area_cachep, vma);
8959+ goto emulate;
8960+ }
8961+
8962+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
8963+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
8964+ up_write(&current->mm->mmap_sem);
8965+ if (vma)
8966+ kmem_cache_free(vm_area_cachep, vma);
8967+ return 1;
8968+ }
8969+
8970+ if (pax_insert_vma(vma, call_dl_resolve)) {
8971+ up_write(&current->mm->mmap_sem);
8972+ kmem_cache_free(vm_area_cachep, vma);
8973+ return 1;
8974+ }
8975+
8976+ current->mm->call_dl_resolve = call_dl_resolve;
8977+ up_write(&current->mm->mmap_sem);
8978+
8979+emulate:
8980+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8981+ regs->pc = call_dl_resolve;
8982+ regs->npc = addr+4;
8983+ return 3;
8984+ }
8985+#endif
8986+
8987+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
8988+ if ((save & 0xFFC00000U) == 0x05000000U &&
8989+ (call & 0xFFFFE000U) == 0x85C0A000U &&
8990+ nop == 0x01000000U)
8991+ {
8992+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8993+ regs->u_regs[UREG_G2] = addr + 4;
8994+ addr = (save & 0x003FFFFFU) << 10;
8995+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8996+ regs->pc = addr;
8997+ regs->npc = addr+4;
8998+ return 3;
8999+ }
9000+ }
9001+ } while (0);
9002+
9003+ do { /* PaX: unpatched PLT emulation step 2 */
9004+ unsigned int save, call, nop;
9005+
9006+ err = get_user(save, (unsigned int *)(regs->pc-4));
9007+ err |= get_user(call, (unsigned int *)regs->pc);
9008+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
9009+ if (err)
9010+ break;
9011+
9012+ if (save == 0x9DE3BFA8U &&
9013+ (call & 0xC0000000U) == 0x40000000U &&
9014+ nop == 0x01000000U)
9015+ {
9016+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9017+
9018+ regs->u_regs[UREG_RETPC] = regs->pc;
9019+ regs->pc = dl_resolve;
9020+ regs->npc = dl_resolve+4;
9021+ return 3;
9022+ }
9023+ } while (0);
9024+#endif
9025+
9026+ return 1;
9027+}
9028+
9029+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9030+{
9031+ unsigned long i;
9032+
9033+ printk(KERN_ERR "PAX: bytes at PC: ");
9034+ for (i = 0; i < 8; i++) {
9035+ unsigned int c;
9036+ if (get_user(c, (unsigned int *)pc+i))
9037+ printk(KERN_CONT "???????? ");
9038+ else
9039+ printk(KERN_CONT "%08x ", c);
9040+ }
9041+ printk("\n");
9042+}
9043+#endif
9044+
9045 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9046 int text_fault)
9047 {
9048@@ -230,6 +504,24 @@ good_area:
9049 if (!(vma->vm_flags & VM_WRITE))
9050 goto bad_area;
9051 } else {
9052+
9053+#ifdef CONFIG_PAX_PAGEEXEC
9054+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9055+ up_read(&mm->mmap_sem);
9056+ switch (pax_handle_fetch_fault(regs)) {
9057+
9058+#ifdef CONFIG_PAX_EMUPLT
9059+ case 2:
9060+ case 3:
9061+ return;
9062+#endif
9063+
9064+ }
9065+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9066+ do_group_exit(SIGKILL);
9067+ }
9068+#endif
9069+
9070 /* Allow reads even for write-only mappings */
9071 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9072 goto bad_area;
9073diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9074index 097aee7..5ca6697 100644
9075--- a/arch/sparc/mm/fault_64.c
9076+++ b/arch/sparc/mm/fault_64.c
9077@@ -21,6 +21,9 @@
9078 #include <linux/kprobes.h>
9079 #include <linux/kdebug.h>
9080 #include <linux/percpu.h>
9081+#include <linux/slab.h>
9082+#include <linux/pagemap.h>
9083+#include <linux/compiler.h>
9084
9085 #include <asm/page.h>
9086 #include <asm/pgtable.h>
9087@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9088 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9089 regs->tpc);
9090 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9091- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9092+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9093 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9094 dump_stack();
9095 unhandled_fault(regs->tpc, current, regs);
9096@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9097 show_regs(regs);
9098 }
9099
9100+#ifdef CONFIG_PAX_PAGEEXEC
9101+#ifdef CONFIG_PAX_DLRESOLVE
9102+static void pax_emuplt_close(struct vm_area_struct *vma)
9103+{
9104+ vma->vm_mm->call_dl_resolve = 0UL;
9105+}
9106+
9107+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9108+{
9109+ unsigned int *kaddr;
9110+
9111+ vmf->page = alloc_page(GFP_HIGHUSER);
9112+ if (!vmf->page)
9113+ return VM_FAULT_OOM;
9114+
9115+ kaddr = kmap(vmf->page);
9116+ memset(kaddr, 0, PAGE_SIZE);
9117+ kaddr[0] = 0x9DE3BFA8U; /* save */
9118+ flush_dcache_page(vmf->page);
9119+ kunmap(vmf->page);
9120+ return VM_FAULT_MAJOR;
9121+}
9122+
9123+static const struct vm_operations_struct pax_vm_ops = {
9124+ .close = pax_emuplt_close,
9125+ .fault = pax_emuplt_fault
9126+};
9127+
9128+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9129+{
9130+ int ret;
9131+
9132+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9133+ vma->vm_mm = current->mm;
9134+ vma->vm_start = addr;
9135+ vma->vm_end = addr + PAGE_SIZE;
9136+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9137+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9138+ vma->vm_ops = &pax_vm_ops;
9139+
9140+ ret = insert_vm_struct(current->mm, vma);
9141+ if (ret)
9142+ return ret;
9143+
9144+ ++current->mm->total_vm;
9145+ return 0;
9146+}
9147+#endif
9148+
9149+/*
9150+ * PaX: decide what to do with offenders (regs->tpc = fault address)
9151+ *
9152+ * returns 1 when task should be killed
9153+ * 2 when patched PLT trampoline was detected
9154+ * 3 when unpatched PLT trampoline was detected
9155+ */
9156+static int pax_handle_fetch_fault(struct pt_regs *regs)
9157+{
9158+
9159+#ifdef CONFIG_PAX_EMUPLT
9160+ int err;
9161+
9162+ do { /* PaX: patched PLT emulation #1 */
9163+ unsigned int sethi1, sethi2, jmpl;
9164+
9165+ err = get_user(sethi1, (unsigned int *)regs->tpc);
9166+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9167+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9168+
9169+ if (err)
9170+ break;
9171+
9172+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9173+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9174+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9175+ {
9176+ unsigned long addr;
9177+
9178+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9179+ addr = regs->u_regs[UREG_G1];
9180+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9181+
9182+ if (test_thread_flag(TIF_32BIT))
9183+ addr &= 0xFFFFFFFFUL;
9184+
9185+ regs->tpc = addr;
9186+ regs->tnpc = addr+4;
9187+ return 2;
9188+ }
9189+ } while (0);
9190+
9191+ do { /* PaX: patched PLT emulation #2 */
9192+ unsigned int ba;
9193+
9194+ err = get_user(ba, (unsigned int *)regs->tpc);
9195+
9196+ if (err)
9197+ break;
9198+
9199+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9200+ unsigned long addr;
9201+
9202+ if ((ba & 0xFFC00000U) == 0x30800000U)
9203+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9204+ else
9205+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9206+
9207+ if (test_thread_flag(TIF_32BIT))
9208+ addr &= 0xFFFFFFFFUL;
9209+
9210+ regs->tpc = addr;
9211+ regs->tnpc = addr+4;
9212+ return 2;
9213+ }
9214+ } while (0);
9215+
9216+ do { /* PaX: patched PLT emulation #3 */
9217+ unsigned int sethi, bajmpl, nop;
9218+
9219+ err = get_user(sethi, (unsigned int *)regs->tpc);
9220+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9221+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9222+
9223+ if (err)
9224+ break;
9225+
9226+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9227+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9228+ nop == 0x01000000U)
9229+ {
9230+ unsigned long addr;
9231+
9232+ addr = (sethi & 0x003FFFFFU) << 10;
9233+ regs->u_regs[UREG_G1] = addr;
9234+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9235+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9236+ else
9237+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9238+
9239+ if (test_thread_flag(TIF_32BIT))
9240+ addr &= 0xFFFFFFFFUL;
9241+
9242+ regs->tpc = addr;
9243+ regs->tnpc = addr+4;
9244+ return 2;
9245+ }
9246+ } while (0);
9247+
9248+ do { /* PaX: patched PLT emulation #4 */
9249+ unsigned int sethi, mov1, call, mov2;
9250+
9251+ err = get_user(sethi, (unsigned int *)regs->tpc);
9252+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9253+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
9254+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9255+
9256+ if (err)
9257+ break;
9258+
9259+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9260+ mov1 == 0x8210000FU &&
9261+ (call & 0xC0000000U) == 0x40000000U &&
9262+ mov2 == 0x9E100001U)
9263+ {
9264+ unsigned long addr;
9265+
9266+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9267+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9268+
9269+ if (test_thread_flag(TIF_32BIT))
9270+ addr &= 0xFFFFFFFFUL;
9271+
9272+ regs->tpc = addr;
9273+ regs->tnpc = addr+4;
9274+ return 2;
9275+ }
9276+ } while (0);
9277+
9278+ do { /* PaX: patched PLT emulation #5 */
9279+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9280+
9281+ err = get_user(sethi, (unsigned int *)regs->tpc);
9282+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9283+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9284+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9285+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9286+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9287+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9288+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9289+
9290+ if (err)
9291+ break;
9292+
9293+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9294+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9295+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9296+ (or1 & 0xFFFFE000U) == 0x82106000U &&
9297+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9298+ sllx == 0x83287020U &&
9299+ jmpl == 0x81C04005U &&
9300+ nop == 0x01000000U)
9301+ {
9302+ unsigned long addr;
9303+
9304+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9305+ regs->u_regs[UREG_G1] <<= 32;
9306+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9307+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9308+ regs->tpc = addr;
9309+ regs->tnpc = addr+4;
9310+ return 2;
9311+ }
9312+ } while (0);
9313+
9314+ do { /* PaX: patched PLT emulation #6 */
9315+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9316+
9317+ err = get_user(sethi, (unsigned int *)regs->tpc);
9318+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9319+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9320+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9321+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
9322+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9323+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9324+
9325+ if (err)
9326+ break;
9327+
9328+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9329+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9330+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9331+ sllx == 0x83287020U &&
9332+ (or & 0xFFFFE000U) == 0x8A116000U &&
9333+ jmpl == 0x81C04005U &&
9334+ nop == 0x01000000U)
9335+ {
9336+ unsigned long addr;
9337+
9338+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9339+ regs->u_regs[UREG_G1] <<= 32;
9340+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9341+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9342+ regs->tpc = addr;
9343+ regs->tnpc = addr+4;
9344+ return 2;
9345+ }
9346+ } while (0);
9347+
9348+ do { /* PaX: unpatched PLT emulation step 1 */
9349+ unsigned int sethi, ba, nop;
9350+
9351+ err = get_user(sethi, (unsigned int *)regs->tpc);
9352+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9353+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9354+
9355+ if (err)
9356+ break;
9357+
9358+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9359+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9360+ nop == 0x01000000U)
9361+ {
9362+ unsigned long addr;
9363+ unsigned int save, call;
9364+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9365+
9366+ if ((ba & 0xFFC00000U) == 0x30800000U)
9367+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9368+ else
9369+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9370+
9371+ if (test_thread_flag(TIF_32BIT))
9372+ addr &= 0xFFFFFFFFUL;
9373+
9374+ err = get_user(save, (unsigned int *)addr);
9375+ err |= get_user(call, (unsigned int *)(addr+4));
9376+ err |= get_user(nop, (unsigned int *)(addr+8));
9377+ if (err)
9378+ break;
9379+
9380+#ifdef CONFIG_PAX_DLRESOLVE
9381+ if (save == 0x9DE3BFA8U &&
9382+ (call & 0xC0000000U) == 0x40000000U &&
9383+ nop == 0x01000000U)
9384+ {
9385+ struct vm_area_struct *vma;
9386+ unsigned long call_dl_resolve;
9387+
9388+ down_read(&current->mm->mmap_sem);
9389+ call_dl_resolve = current->mm->call_dl_resolve;
9390+ up_read(&current->mm->mmap_sem);
9391+ if (likely(call_dl_resolve))
9392+ goto emulate;
9393+
9394+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9395+
9396+ down_write(&current->mm->mmap_sem);
9397+ if (current->mm->call_dl_resolve) {
9398+ call_dl_resolve = current->mm->call_dl_resolve;
9399+ up_write(&current->mm->mmap_sem);
9400+ if (vma)
9401+ kmem_cache_free(vm_area_cachep, vma);
9402+ goto emulate;
9403+ }
9404+
9405+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9406+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9407+ up_write(&current->mm->mmap_sem);
9408+ if (vma)
9409+ kmem_cache_free(vm_area_cachep, vma);
9410+ return 1;
9411+ }
9412+
9413+ if (pax_insert_vma(vma, call_dl_resolve)) {
9414+ up_write(&current->mm->mmap_sem);
9415+ kmem_cache_free(vm_area_cachep, vma);
9416+ return 1;
9417+ }
9418+
9419+ current->mm->call_dl_resolve = call_dl_resolve;
9420+ up_write(&current->mm->mmap_sem);
9421+
9422+emulate:
9423+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9424+ regs->tpc = call_dl_resolve;
9425+ regs->tnpc = addr+4;
9426+ return 3;
9427+ }
9428+#endif
9429+
9430+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9431+ if ((save & 0xFFC00000U) == 0x05000000U &&
9432+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9433+ nop == 0x01000000U)
9434+ {
9435+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9436+ regs->u_regs[UREG_G2] = addr + 4;
9437+ addr = (save & 0x003FFFFFU) << 10;
9438+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9439+
9440+ if (test_thread_flag(TIF_32BIT))
9441+ addr &= 0xFFFFFFFFUL;
9442+
9443+ regs->tpc = addr;
9444+ regs->tnpc = addr+4;
9445+ return 3;
9446+ }
9447+
9448+ /* PaX: 64-bit PLT stub */
9449+ err = get_user(sethi1, (unsigned int *)addr);
9450+ err |= get_user(sethi2, (unsigned int *)(addr+4));
9451+ err |= get_user(or1, (unsigned int *)(addr+8));
9452+ err |= get_user(or2, (unsigned int *)(addr+12));
9453+ err |= get_user(sllx, (unsigned int *)(addr+16));
9454+ err |= get_user(add, (unsigned int *)(addr+20));
9455+ err |= get_user(jmpl, (unsigned int *)(addr+24));
9456+ err |= get_user(nop, (unsigned int *)(addr+28));
9457+ if (err)
9458+ break;
9459+
9460+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9461+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9462+ (or1 & 0xFFFFE000U) == 0x88112000U &&
9463+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9464+ sllx == 0x89293020U &&
9465+ add == 0x8A010005U &&
9466+ jmpl == 0x89C14000U &&
9467+ nop == 0x01000000U)
9468+ {
9469+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9470+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9471+ regs->u_regs[UREG_G4] <<= 32;
9472+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9473+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9474+ regs->u_regs[UREG_G4] = addr + 24;
9475+ addr = regs->u_regs[UREG_G5];
9476+ regs->tpc = addr;
9477+ regs->tnpc = addr+4;
9478+ return 3;
9479+ }
9480+ }
9481+ } while (0);
9482+
9483+#ifdef CONFIG_PAX_DLRESOLVE
9484+ do { /* PaX: unpatched PLT emulation step 2 */
9485+ unsigned int save, call, nop;
9486+
9487+ err = get_user(save, (unsigned int *)(regs->tpc-4));
9488+ err |= get_user(call, (unsigned int *)regs->tpc);
9489+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9490+ if (err)
9491+ break;
9492+
9493+ if (save == 0x9DE3BFA8U &&
9494+ (call & 0xC0000000U) == 0x40000000U &&
9495+ nop == 0x01000000U)
9496+ {
9497+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9498+
9499+ if (test_thread_flag(TIF_32BIT))
9500+ dl_resolve &= 0xFFFFFFFFUL;
9501+
9502+ regs->u_regs[UREG_RETPC] = regs->tpc;
9503+ regs->tpc = dl_resolve;
9504+ regs->tnpc = dl_resolve+4;
9505+ return 3;
9506+ }
9507+ } while (0);
9508+#endif
9509+
9510+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9511+ unsigned int sethi, ba, nop;
9512+
9513+ err = get_user(sethi, (unsigned int *)regs->tpc);
9514+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9515+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9516+
9517+ if (err)
9518+ break;
9519+
9520+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9521+ (ba & 0xFFF00000U) == 0x30600000U &&
9522+ nop == 0x01000000U)
9523+ {
9524+ unsigned long addr;
9525+
9526+ addr = (sethi & 0x003FFFFFU) << 10;
9527+ regs->u_regs[UREG_G1] = addr;
9528+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9529+
9530+ if (test_thread_flag(TIF_32BIT))
9531+ addr &= 0xFFFFFFFFUL;
9532+
9533+ regs->tpc = addr;
9534+ regs->tnpc = addr+4;
9535+ return 2;
9536+ }
9537+ } while (0);
9538+
9539+#endif
9540+
9541+ return 1;
9542+}
9543+
9544+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9545+{
9546+ unsigned long i;
9547+
9548+ printk(KERN_ERR "PAX: bytes at PC: ");
9549+ for (i = 0; i < 8; i++) {
9550+ unsigned int c;
9551+ if (get_user(c, (unsigned int *)pc+i))
9552+ printk(KERN_CONT "???????? ");
9553+ else
9554+ printk(KERN_CONT "%08x ", c);
9555+ }
9556+ printk("\n");
9557+}
9558+#endif
9559+
9560 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9561 {
9562 struct mm_struct *mm = current->mm;
9563@@ -341,6 +804,29 @@ retry:
9564 if (!vma)
9565 goto bad_area;
9566
9567+#ifdef CONFIG_PAX_PAGEEXEC
9568+ /* PaX: detect ITLB misses on non-exec pages */
9569+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9570+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9571+ {
9572+ if (address != regs->tpc)
9573+ goto good_area;
9574+
9575+ up_read(&mm->mmap_sem);
9576+ switch (pax_handle_fetch_fault(regs)) {
9577+
9578+#ifdef CONFIG_PAX_EMUPLT
9579+ case 2:
9580+ case 3:
9581+ return;
9582+#endif
9583+
9584+ }
9585+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9586+ do_group_exit(SIGKILL);
9587+ }
9588+#endif
9589+
9590 /* Pure DTLB misses do not tell us whether the fault causing
9591 * load/store/atomic was a write or not, it only says that there
9592 * was no match. So in such a case we (carefully) read the
9593diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
9594index d2b5944..bd813f2 100644
9595--- a/arch/sparc/mm/hugetlbpage.c
9596+++ b/arch/sparc/mm/hugetlbpage.c
9597@@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9598
9599 info.flags = 0;
9600 info.length = len;
9601- info.low_limit = TASK_UNMAPPED_BASE;
9602+ info.low_limit = mm->mmap_base;
9603 info.high_limit = min(task_size, VA_EXCLUDE_START);
9604 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
9605 info.align_offset = 0;
9606@@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9607 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9608 VM_BUG_ON(addr != -ENOMEM);
9609 info.low_limit = VA_EXCLUDE_END;
9610+
9611+#ifdef CONFIG_PAX_RANDMMAP
9612+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9613+ info.low_limit += mm->delta_mmap;
9614+#endif
9615+
9616 info.high_limit = task_size;
9617 addr = vm_unmapped_area(&info);
9618 }
9619@@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9620 VM_BUG_ON(addr != -ENOMEM);
9621 info.flags = 0;
9622 info.low_limit = TASK_UNMAPPED_BASE;
9623+
9624+#ifdef CONFIG_PAX_RANDMMAP
9625+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9626+ info.low_limit += mm->delta_mmap;
9627+#endif
9628+
9629 info.high_limit = STACK_TOP32;
9630 addr = vm_unmapped_area(&info);
9631 }
9632@@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9633 struct mm_struct *mm = current->mm;
9634 struct vm_area_struct *vma;
9635 unsigned long task_size = TASK_SIZE;
9636+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
9637
9638 if (test_thread_flag(TIF_32BIT))
9639 task_size = STACK_TOP32;
9640@@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9641 return addr;
9642 }
9643
9644+#ifdef CONFIG_PAX_RANDMMAP
9645+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9646+#endif
9647+
9648 if (addr) {
9649 addr = ALIGN(addr, HPAGE_SIZE);
9650 vma = find_vma(mm, addr);
9651- if (task_size - len >= addr &&
9652- (!vma || addr + len <= vma->vm_start))
9653+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9654 return addr;
9655 }
9656 if (mm->get_unmapped_area == arch_get_unmapped_area)
9657diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
9658index f4500c6..889656c 100644
9659--- a/arch/tile/include/asm/atomic_64.h
9660+++ b/arch/tile/include/asm/atomic_64.h
9661@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9662
9663 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9664
9665+#define atomic64_read_unchecked(v) atomic64_read(v)
9666+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9667+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9668+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9669+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9670+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9671+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9672+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9673+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9674+
9675 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
9676 #define smp_mb__before_atomic_dec() smp_mb()
9677 #define smp_mb__after_atomic_dec() smp_mb()
9678diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
9679index a9a5299..0fce79e 100644
9680--- a/arch/tile/include/asm/cache.h
9681+++ b/arch/tile/include/asm/cache.h
9682@@ -15,11 +15,12 @@
9683 #ifndef _ASM_TILE_CACHE_H
9684 #define _ASM_TILE_CACHE_H
9685
9686+#include <linux/const.h>
9687 #include <arch/chip.h>
9688
9689 /* bytes per L1 data cache line */
9690 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
9691-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9692+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9693
9694 /* bytes per L2 cache line */
9695 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
9696diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
9697index 9ab078a..d6635c2 100644
9698--- a/arch/tile/include/asm/uaccess.h
9699+++ b/arch/tile/include/asm/uaccess.h
9700@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
9701 const void __user *from,
9702 unsigned long n)
9703 {
9704- int sz = __compiletime_object_size(to);
9705+ size_t sz = __compiletime_object_size(to);
9706
9707- if (likely(sz == -1 || sz >= n))
9708+ if (likely(sz == (size_t)-1 || sz >= n))
9709 n = _copy_from_user(to, from, n);
9710 else
9711 copy_from_user_overflow();
9712diff --git a/arch/um/Makefile b/arch/um/Makefile
9713index 133f7de..1d6f2f1 100644
9714--- a/arch/um/Makefile
9715+++ b/arch/um/Makefile
9716@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
9717 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
9718 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
9719
9720+ifdef CONSTIFY_PLUGIN
9721+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
9722+endif
9723+
9724 #This will adjust *FLAGS accordingly to the platform.
9725 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
9726
9727diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
9728index 19e1bdd..3665b77 100644
9729--- a/arch/um/include/asm/cache.h
9730+++ b/arch/um/include/asm/cache.h
9731@@ -1,6 +1,7 @@
9732 #ifndef __UM_CACHE_H
9733 #define __UM_CACHE_H
9734
9735+#include <linux/const.h>
9736
9737 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
9738 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9739@@ -12,6 +13,6 @@
9740 # define L1_CACHE_SHIFT 5
9741 #endif
9742
9743-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9744+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9745
9746 #endif
9747diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
9748index 2e0a6b1..a64d0f5 100644
9749--- a/arch/um/include/asm/kmap_types.h
9750+++ b/arch/um/include/asm/kmap_types.h
9751@@ -8,6 +8,6 @@
9752
9753 /* No more #include "asm/arch/kmap_types.h" ! */
9754
9755-#define KM_TYPE_NR 14
9756+#define KM_TYPE_NR 15
9757
9758 #endif
9759diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
9760index 5ff53d9..5850cdf 100644
9761--- a/arch/um/include/asm/page.h
9762+++ b/arch/um/include/asm/page.h
9763@@ -14,6 +14,9 @@
9764 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
9765 #define PAGE_MASK (~(PAGE_SIZE-1))
9766
9767+#define ktla_ktva(addr) (addr)
9768+#define ktva_ktla(addr) (addr)
9769+
9770 #ifndef __ASSEMBLY__
9771
9772 struct page;
9773diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
9774index 0032f92..cd151e0 100644
9775--- a/arch/um/include/asm/pgtable-3level.h
9776+++ b/arch/um/include/asm/pgtable-3level.h
9777@@ -58,6 +58,7 @@
9778 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
9779 #define pud_populate(mm, pud, pmd) \
9780 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
9781+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
9782
9783 #ifdef CONFIG_64BIT
9784 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
9785diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
9786index b462b13..e7a19aa 100644
9787--- a/arch/um/kernel/process.c
9788+++ b/arch/um/kernel/process.c
9789@@ -386,22 +386,6 @@ int singlestepping(void * t)
9790 return 2;
9791 }
9792
9793-/*
9794- * Only x86 and x86_64 have an arch_align_stack().
9795- * All other arches have "#define arch_align_stack(x) (x)"
9796- * in their asm/system.h
9797- * As this is included in UML from asm-um/system-generic.h,
9798- * we can use it to behave as the subarch does.
9799- */
9800-#ifndef arch_align_stack
9801-unsigned long arch_align_stack(unsigned long sp)
9802-{
9803- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9804- sp -= get_random_int() % 8192;
9805- return sp & ~0xf;
9806-}
9807-#endif
9808-
9809 unsigned long get_wchan(struct task_struct *p)
9810 {
9811 unsigned long stack_page, sp, ip;
9812diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
9813index ad8f795..2c7eec6 100644
9814--- a/arch/unicore32/include/asm/cache.h
9815+++ b/arch/unicore32/include/asm/cache.h
9816@@ -12,8 +12,10 @@
9817 #ifndef __UNICORE_CACHE_H__
9818 #define __UNICORE_CACHE_H__
9819
9820-#define L1_CACHE_SHIFT (5)
9821-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9822+#include <linux/const.h>
9823+
9824+#define L1_CACHE_SHIFT 5
9825+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9826
9827 /*
9828 * Memory returned by kmalloc() may be used for DMA, so we must make
9829diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
9830index 225543b..f12405b 100644
9831--- a/arch/x86/Kconfig
9832+++ b/arch/x86/Kconfig
9833@@ -238,7 +238,7 @@ config X86_HT
9834
9835 config X86_32_LAZY_GS
9836 def_bool y
9837- depends on X86_32 && !CC_STACKPROTECTOR
9838+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
9839
9840 config ARCH_HWEIGHT_CFLAGS
9841 string
9842@@ -1031,6 +1031,7 @@ config MICROCODE_OLD_INTERFACE
9843
9844 config X86_MSR
9845 tristate "/dev/cpu/*/msr - Model-specific register support"
9846+ depends on !GRKERNSEC_KMEM
9847 ---help---
9848 This device gives privileged processes access to the x86
9849 Model-Specific Registers (MSRs). It is a character device with
9850@@ -1054,7 +1055,7 @@ choice
9851
9852 config NOHIGHMEM
9853 bool "off"
9854- depends on !X86_NUMAQ
9855+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
9856 ---help---
9857 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
9858 However, the address space of 32-bit x86 processors is only 4
9859@@ -1091,7 +1092,7 @@ config NOHIGHMEM
9860
9861 config HIGHMEM4G
9862 bool "4GB"
9863- depends on !X86_NUMAQ
9864+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
9865 ---help---
9866 Select this if you have a 32-bit processor and between 1 and 4
9867 gigabytes of physical RAM.
9868@@ -1145,7 +1146,7 @@ config PAGE_OFFSET
9869 hex
9870 default 0xB0000000 if VMSPLIT_3G_OPT
9871 default 0x80000000 if VMSPLIT_2G
9872- default 0x78000000 if VMSPLIT_2G_OPT
9873+ default 0x70000000 if VMSPLIT_2G_OPT
9874 default 0x40000000 if VMSPLIT_1G
9875 default 0xC0000000
9876 depends on X86_32
9877@@ -1546,6 +1547,7 @@ config SECCOMP
9878
9879 config CC_STACKPROTECTOR
9880 bool "Enable -fstack-protector buffer overflow detection"
9881+ depends on X86_64 || !PAX_MEMORY_UDEREF
9882 ---help---
9883 This option turns on the -fstack-protector GCC feature. This
9884 feature puts, at the beginning of functions, a canary value on
9885@@ -1603,6 +1605,7 @@ config KEXEC_JUMP
9886 config PHYSICAL_START
9887 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
9888 default "0x1000000"
9889+ range 0x400000 0x40000000
9890 ---help---
9891 This gives the physical address where the kernel is loaded.
9892
9893@@ -1666,6 +1669,7 @@ config X86_NEED_RELOCS
9894 config PHYSICAL_ALIGN
9895 hex "Alignment value to which kernel should be aligned" if X86_32
9896 default "0x1000000"
9897+ range 0x400000 0x1000000 if PAX_KERNEXEC
9898 range 0x2000 0x1000000
9899 ---help---
9900 This value puts the alignment restrictions on physical address
9901@@ -1741,9 +1745,10 @@ config DEBUG_HOTPLUG_CPU0
9902 If unsure, say N.
9903
9904 config COMPAT_VDSO
9905- def_bool y
9906+ def_bool n
9907 prompt "Compat VDSO support"
9908 depends on X86_32 || IA32_EMULATION
9909+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
9910 ---help---
9911 Map the 32-bit VDSO to the predictable old-style address too.
9912
9913diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
9914index c026cca..14657ae 100644
9915--- a/arch/x86/Kconfig.cpu
9916+++ b/arch/x86/Kconfig.cpu
9917@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
9918
9919 config X86_F00F_BUG
9920 def_bool y
9921- depends on M586MMX || M586TSC || M586 || M486
9922+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
9923
9924 config X86_INVD_BUG
9925 def_bool y
9926@@ -327,7 +327,7 @@ config X86_INVD_BUG
9927
9928 config X86_ALIGNMENT_16
9929 def_bool y
9930- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
9931+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
9932
9933 config X86_INTEL_USERCOPY
9934 def_bool y
9935@@ -373,7 +373,7 @@ config X86_CMPXCHG64
9936 # generates cmov.
9937 config X86_CMOV
9938 def_bool y
9939- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
9940+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
9941
9942 config X86_MINIMUM_CPU_FAMILY
9943 int
9944diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
9945index b322f12..652d0d9 100644
9946--- a/arch/x86/Kconfig.debug
9947+++ b/arch/x86/Kconfig.debug
9948@@ -84,7 +84,7 @@ config X86_PTDUMP
9949 config DEBUG_RODATA
9950 bool "Write protect kernel read-only data structures"
9951 default y
9952- depends on DEBUG_KERNEL
9953+ depends on DEBUG_KERNEL && BROKEN
9954 ---help---
9955 Mark the kernel read-only data as write-protected in the pagetables,
9956 in order to catch accidental (and incorrect) writes to such const
9957@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
9958
9959 config DEBUG_SET_MODULE_RONX
9960 bool "Set loadable kernel module data as NX and text as RO"
9961- depends on MODULES
9962+ depends on MODULES && BROKEN
9963 ---help---
9964 This option helps catch unintended modifications to loadable
9965 kernel module's text and read-only data. It also prevents execution
9966@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
9967
9968 config DEBUG_STRICT_USER_COPY_CHECKS
9969 bool "Strict copy size checks"
9970- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
9971+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
9972 ---help---
9973 Enabling this option turns a certain set of sanity checks for user
9974 copy operations into compile time failures.
9975diff --git a/arch/x86/Makefile b/arch/x86/Makefile
9976index e71fc42..7829607 100644
9977--- a/arch/x86/Makefile
9978+++ b/arch/x86/Makefile
9979@@ -50,6 +50,7 @@ else
9980 UTS_MACHINE := x86_64
9981 CHECKFLAGS += -D__x86_64__ -m64
9982
9983+ biarch := $(call cc-option,-m64)
9984 KBUILD_AFLAGS += -m64
9985 KBUILD_CFLAGS += -m64
9986
9987@@ -230,3 +231,12 @@ define archhelp
9988 echo ' FDARGS="..." arguments for the booted kernel'
9989 echo ' FDINITRD=file initrd for the booted kernel'
9990 endef
9991+
9992+define OLD_LD
9993+
9994+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
9995+*** Please upgrade your binutils to 2.18 or newer
9996+endef
9997+
9998+archprepare:
9999+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10000diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10001index 379814b..add62ce 100644
10002--- a/arch/x86/boot/Makefile
10003+++ b/arch/x86/boot/Makefile
10004@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10005 $(call cc-option, -fno-stack-protector) \
10006 $(call cc-option, -mpreferred-stack-boundary=2)
10007 KBUILD_CFLAGS += $(call cc-option, -m32)
10008+ifdef CONSTIFY_PLUGIN
10009+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10010+endif
10011 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10012 GCOV_PROFILE := n
10013
10014diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10015index 878e4b9..20537ab 100644
10016--- a/arch/x86/boot/bitops.h
10017+++ b/arch/x86/boot/bitops.h
10018@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10019 u8 v;
10020 const u32 *p = (const u32 *)addr;
10021
10022- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10023+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10024 return v;
10025 }
10026
10027@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10028
10029 static inline void set_bit(int nr, void *addr)
10030 {
10031- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10032+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10033 }
10034
10035 #endif /* BOOT_BITOPS_H */
10036diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10037index 18997e5..83d9c67 100644
10038--- a/arch/x86/boot/boot.h
10039+++ b/arch/x86/boot/boot.h
10040@@ -85,7 +85,7 @@ static inline void io_delay(void)
10041 static inline u16 ds(void)
10042 {
10043 u16 seg;
10044- asm("movw %%ds,%0" : "=rm" (seg));
10045+ asm volatile("movw %%ds,%0" : "=rm" (seg));
10046 return seg;
10047 }
10048
10049@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10050 static inline int memcmp(const void *s1, const void *s2, size_t len)
10051 {
10052 u8 diff;
10053- asm("repe; cmpsb; setnz %0"
10054+ asm volatile("repe; cmpsb; setnz %0"
10055 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10056 return diff;
10057 }
10058diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10059index 8a84501..b2d165f 100644
10060--- a/arch/x86/boot/compressed/Makefile
10061+++ b/arch/x86/boot/compressed/Makefile
10062@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10063 KBUILD_CFLAGS += $(cflags-y)
10064 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10065 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10066+ifdef CONSTIFY_PLUGIN
10067+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10068+endif
10069
10070 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10071 GCOV_PROFILE := n
10072diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10073index f8fa411..c570c53 100644
10074--- a/arch/x86/boot/compressed/eboot.c
10075+++ b/arch/x86/boot/compressed/eboot.c
10076@@ -145,7 +145,6 @@ again:
10077 *addr = max_addr;
10078 }
10079
10080-free_pool:
10081 efi_call_phys1(sys_table->boottime->free_pool, map);
10082
10083 fail:
10084@@ -209,7 +208,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10085 if (i == map_size / desc_size)
10086 status = EFI_NOT_FOUND;
10087
10088-free_pool:
10089 efi_call_phys1(sys_table->boottime->free_pool, map);
10090 fail:
10091 return status;
10092diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10093index 1e3184f..0d11e2e 100644
10094--- a/arch/x86/boot/compressed/head_32.S
10095+++ b/arch/x86/boot/compressed/head_32.S
10096@@ -118,7 +118,7 @@ preferred_addr:
10097 notl %eax
10098 andl %eax, %ebx
10099 #else
10100- movl $LOAD_PHYSICAL_ADDR, %ebx
10101+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10102 #endif
10103
10104 /* Target address to relocate to for decompression */
10105@@ -204,7 +204,7 @@ relocated:
10106 * and where it was actually loaded.
10107 */
10108 movl %ebp, %ebx
10109- subl $LOAD_PHYSICAL_ADDR, %ebx
10110+ subl $____LOAD_PHYSICAL_ADDR, %ebx
10111 jz 2f /* Nothing to be done if loaded at compiled addr. */
10112 /*
10113 * Process relocations.
10114@@ -212,8 +212,7 @@ relocated:
10115
10116 1: subl $4, %edi
10117 movl (%edi), %ecx
10118- testl %ecx, %ecx
10119- jz 2f
10120+ jecxz 2f
10121 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10122 jmp 1b
10123 2:
10124diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10125index f5d1aaa..cce11dc 100644
10126--- a/arch/x86/boot/compressed/head_64.S
10127+++ b/arch/x86/boot/compressed/head_64.S
10128@@ -91,7 +91,7 @@ ENTRY(startup_32)
10129 notl %eax
10130 andl %eax, %ebx
10131 #else
10132- movl $LOAD_PHYSICAL_ADDR, %ebx
10133+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10134 #endif
10135
10136 /* Target address to relocate to for decompression */
10137@@ -273,7 +273,7 @@ preferred_addr:
10138 notq %rax
10139 andq %rax, %rbp
10140 #else
10141- movq $LOAD_PHYSICAL_ADDR, %rbp
10142+ movq $____LOAD_PHYSICAL_ADDR, %rbp
10143 #endif
10144
10145 /* Target address to relocate to for decompression */
10146diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10147index 88f7ff6..ed695dd 100644
10148--- a/arch/x86/boot/compressed/misc.c
10149+++ b/arch/x86/boot/compressed/misc.c
10150@@ -303,7 +303,7 @@ static void parse_elf(void *output)
10151 case PT_LOAD:
10152 #ifdef CONFIG_RELOCATABLE
10153 dest = output;
10154- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10155+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10156 #else
10157 dest = (void *)(phdr->p_paddr);
10158 #endif
10159@@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10160 error("Destination address too large");
10161 #endif
10162 #ifndef CONFIG_RELOCATABLE
10163- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10164+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10165 error("Wrong destination address");
10166 #endif
10167
10168diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10169index 4d3ff03..e4972ff 100644
10170--- a/arch/x86/boot/cpucheck.c
10171+++ b/arch/x86/boot/cpucheck.c
10172@@ -74,7 +74,7 @@ static int has_fpu(void)
10173 u16 fcw = -1, fsw = -1;
10174 u32 cr0;
10175
10176- asm("movl %%cr0,%0" : "=r" (cr0));
10177+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
10178 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10179 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10180 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10181@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10182 {
10183 u32 f0, f1;
10184
10185- asm("pushfl ; "
10186+ asm volatile("pushfl ; "
10187 "pushfl ; "
10188 "popl %0 ; "
10189 "movl %0,%1 ; "
10190@@ -115,7 +115,7 @@ static void get_flags(void)
10191 set_bit(X86_FEATURE_FPU, cpu.flags);
10192
10193 if (has_eflag(X86_EFLAGS_ID)) {
10194- asm("cpuid"
10195+ asm volatile("cpuid"
10196 : "=a" (max_intel_level),
10197 "=b" (cpu_vendor[0]),
10198 "=d" (cpu_vendor[1]),
10199@@ -124,7 +124,7 @@ static void get_flags(void)
10200
10201 if (max_intel_level >= 0x00000001 &&
10202 max_intel_level <= 0x0000ffff) {
10203- asm("cpuid"
10204+ asm volatile("cpuid"
10205 : "=a" (tfms),
10206 "=c" (cpu.flags[4]),
10207 "=d" (cpu.flags[0])
10208@@ -136,7 +136,7 @@ static void get_flags(void)
10209 cpu.model += ((tfms >> 16) & 0xf) << 4;
10210 }
10211
10212- asm("cpuid"
10213+ asm volatile("cpuid"
10214 : "=a" (max_amd_level)
10215 : "a" (0x80000000)
10216 : "ebx", "ecx", "edx");
10217@@ -144,7 +144,7 @@ static void get_flags(void)
10218 if (max_amd_level >= 0x80000001 &&
10219 max_amd_level <= 0x8000ffff) {
10220 u32 eax = 0x80000001;
10221- asm("cpuid"
10222+ asm volatile("cpuid"
10223 : "+a" (eax),
10224 "=c" (cpu.flags[6]),
10225 "=d" (cpu.flags[1])
10226@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10227 u32 ecx = MSR_K7_HWCR;
10228 u32 eax, edx;
10229
10230- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10231+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10232 eax &= ~(1 << 15);
10233- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10234+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10235
10236 get_flags(); /* Make sure it really did something */
10237 err = check_flags();
10238@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10239 u32 ecx = MSR_VIA_FCR;
10240 u32 eax, edx;
10241
10242- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10243+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10244 eax |= (1<<1)|(1<<7);
10245- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10246+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10247
10248 set_bit(X86_FEATURE_CX8, cpu.flags);
10249 err = check_flags();
10250@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10251 u32 eax, edx;
10252 u32 level = 1;
10253
10254- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10255- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10256- asm("cpuid"
10257+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10258+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10259+ asm volatile("cpuid"
10260 : "+a" (level), "=d" (cpu.flags[0])
10261 : : "ecx", "ebx");
10262- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10263+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10264
10265 err = check_flags();
10266 }
10267diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10268index 944ce59..87ee37a 100644
10269--- a/arch/x86/boot/header.S
10270+++ b/arch/x86/boot/header.S
10271@@ -401,10 +401,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10272 # single linked list of
10273 # struct setup_data
10274
10275-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10276+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10277
10278 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10279+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10280+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10281+#else
10282 #define VO_INIT_SIZE (VO__end - VO__text)
10283+#endif
10284 #if ZO_INIT_SIZE > VO_INIT_SIZE
10285 #define INIT_SIZE ZO_INIT_SIZE
10286 #else
10287diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10288index db75d07..8e6d0af 100644
10289--- a/arch/x86/boot/memory.c
10290+++ b/arch/x86/boot/memory.c
10291@@ -19,7 +19,7 @@
10292
10293 static int detect_memory_e820(void)
10294 {
10295- int count = 0;
10296+ unsigned int count = 0;
10297 struct biosregs ireg, oreg;
10298 struct e820entry *desc = boot_params.e820_map;
10299 static struct e820entry buf; /* static so it is zeroed */
10300diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10301index 11e8c6e..fdbb1ed 100644
10302--- a/arch/x86/boot/video-vesa.c
10303+++ b/arch/x86/boot/video-vesa.c
10304@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10305
10306 boot_params.screen_info.vesapm_seg = oreg.es;
10307 boot_params.screen_info.vesapm_off = oreg.di;
10308+ boot_params.screen_info.vesapm_size = oreg.cx;
10309 }
10310
10311 /*
10312diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10313index 43eda28..5ab5fdb 100644
10314--- a/arch/x86/boot/video.c
10315+++ b/arch/x86/boot/video.c
10316@@ -96,7 +96,7 @@ static void store_mode_params(void)
10317 static unsigned int get_entry(void)
10318 {
10319 char entry_buf[4];
10320- int i, len = 0;
10321+ unsigned int i, len = 0;
10322 int key;
10323 unsigned int v;
10324
10325diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10326index 5b577d5..3c1fed4 100644
10327--- a/arch/x86/crypto/aes-x86_64-asm_64.S
10328+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10329@@ -8,6 +8,8 @@
10330 * including this sentence is retained in full.
10331 */
10332
10333+#include <asm/alternative-asm.h>
10334+
10335 .extern crypto_ft_tab
10336 .extern crypto_it_tab
10337 .extern crypto_fl_tab
10338@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
10339 je B192; \
10340 leaq 32(r9),r9;
10341
10342+#define ret pax_force_retaddr 0, 1; ret
10343+
10344 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10345 movq r1,r2; \
10346 movq r3,r4; \
10347diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10348index 3470624..201259d 100644
10349--- a/arch/x86/crypto/aesni-intel_asm.S
10350+++ b/arch/x86/crypto/aesni-intel_asm.S
10351@@ -31,6 +31,7 @@
10352
10353 #include <linux/linkage.h>
10354 #include <asm/inst.h>
10355+#include <asm/alternative-asm.h>
10356
10357 #ifdef __x86_64__
10358 .data
10359@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
10360 pop %r14
10361 pop %r13
10362 pop %r12
10363+ pax_force_retaddr 0, 1
10364 ret
10365+ENDPROC(aesni_gcm_dec)
10366
10367
10368 /*****************************************************************************
10369@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
10370 pop %r14
10371 pop %r13
10372 pop %r12
10373+ pax_force_retaddr 0, 1
10374 ret
10375+ENDPROC(aesni_gcm_enc)
10376
10377 #endif
10378
10379@@ -1714,6 +1719,7 @@ _key_expansion_256a:
10380 pxor %xmm1, %xmm0
10381 movaps %xmm0, (TKEYP)
10382 add $0x10, TKEYP
10383+ pax_force_retaddr_bts
10384 ret
10385
10386 .align 4
10387@@ -1738,6 +1744,7 @@ _key_expansion_192a:
10388 shufps $0b01001110, %xmm2, %xmm1
10389 movaps %xmm1, 0x10(TKEYP)
10390 add $0x20, TKEYP
10391+ pax_force_retaddr_bts
10392 ret
10393
10394 .align 4
10395@@ -1757,6 +1764,7 @@ _key_expansion_192b:
10396
10397 movaps %xmm0, (TKEYP)
10398 add $0x10, TKEYP
10399+ pax_force_retaddr_bts
10400 ret
10401
10402 .align 4
10403@@ -1769,6 +1777,7 @@ _key_expansion_256b:
10404 pxor %xmm1, %xmm2
10405 movaps %xmm2, (TKEYP)
10406 add $0x10, TKEYP
10407+ pax_force_retaddr_bts
10408 ret
10409
10410 /*
10411@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
10412 #ifndef __x86_64__
10413 popl KEYP
10414 #endif
10415+ pax_force_retaddr 0, 1
10416 ret
10417+ENDPROC(aesni_set_key)
10418
10419 /*
10420 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
10421@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
10422 popl KLEN
10423 popl KEYP
10424 #endif
10425+ pax_force_retaddr 0, 1
10426 ret
10427+ENDPROC(aesni_enc)
10428
10429 /*
10430 * _aesni_enc1: internal ABI
10431@@ -1959,6 +1972,7 @@ _aesni_enc1:
10432 AESENC KEY STATE
10433 movaps 0x70(TKEYP), KEY
10434 AESENCLAST KEY STATE
10435+ pax_force_retaddr_bts
10436 ret
10437
10438 /*
10439@@ -2067,6 +2081,7 @@ _aesni_enc4:
10440 AESENCLAST KEY STATE2
10441 AESENCLAST KEY STATE3
10442 AESENCLAST KEY STATE4
10443+ pax_force_retaddr_bts
10444 ret
10445
10446 /*
10447@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
10448 popl KLEN
10449 popl KEYP
10450 #endif
10451+ pax_force_retaddr 0, 1
10452 ret
10453+ENDPROC(aesni_dec)
10454
10455 /*
10456 * _aesni_dec1: internal ABI
10457@@ -2146,6 +2163,7 @@ _aesni_dec1:
10458 AESDEC KEY STATE
10459 movaps 0x70(TKEYP), KEY
10460 AESDECLAST KEY STATE
10461+ pax_force_retaddr_bts
10462 ret
10463
10464 /*
10465@@ -2254,6 +2272,7 @@ _aesni_dec4:
10466 AESDECLAST KEY STATE2
10467 AESDECLAST KEY STATE3
10468 AESDECLAST KEY STATE4
10469+ pax_force_retaddr_bts
10470 ret
10471
10472 /*
10473@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
10474 popl KEYP
10475 popl LEN
10476 #endif
10477+ pax_force_retaddr 0, 1
10478 ret
10479+ENDPROC(aesni_ecb_enc)
10480
10481 /*
10482 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10483@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
10484 popl KEYP
10485 popl LEN
10486 #endif
10487+ pax_force_retaddr 0, 1
10488 ret
10489+ENDPROC(aesni_ecb_dec)
10490
10491 /*
10492 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10493@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
10494 popl LEN
10495 popl IVP
10496 #endif
10497+ pax_force_retaddr 0, 1
10498 ret
10499+ENDPROC(aesni_cbc_enc)
10500
10501 /*
10502 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10503@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
10504 popl LEN
10505 popl IVP
10506 #endif
10507+ pax_force_retaddr 0, 1
10508 ret
10509+ENDPROC(aesni_cbc_dec)
10510
10511 #ifdef __x86_64__
10512 .align 16
10513@@ -2526,6 +2553,7 @@ _aesni_inc_init:
10514 mov $1, TCTR_LOW
10515 MOVQ_R64_XMM TCTR_LOW INC
10516 MOVQ_R64_XMM CTR TCTR_LOW
10517+ pax_force_retaddr_bts
10518 ret
10519
10520 /*
10521@@ -2554,6 +2582,7 @@ _aesni_inc:
10522 .Linc_low:
10523 movaps CTR, IV
10524 PSHUFB_XMM BSWAP_MASK IV
10525+ pax_force_retaddr_bts
10526 ret
10527
10528 /*
10529@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
10530 .Lctr_enc_ret:
10531 movups IV, (IVP)
10532 .Lctr_enc_just_ret:
10533+ pax_force_retaddr 0, 1
10534 ret
10535+ENDPROC(aesni_ctr_enc)
10536 #endif
10537diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10538index 391d245..67f35c2 100644
10539--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10540+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10541@@ -20,6 +20,8 @@
10542 *
10543 */
10544
10545+#include <asm/alternative-asm.h>
10546+
10547 .file "blowfish-x86_64-asm.S"
10548 .text
10549
10550@@ -151,9 +153,11 @@ __blowfish_enc_blk:
10551 jnz __enc_xor;
10552
10553 write_block();
10554+ pax_force_retaddr 0, 1
10555 ret;
10556 __enc_xor:
10557 xor_block();
10558+ pax_force_retaddr 0, 1
10559 ret;
10560
10561 .align 8
10562@@ -188,6 +192,7 @@ blowfish_dec_blk:
10563
10564 movq %r11, %rbp;
10565
10566+ pax_force_retaddr 0, 1
10567 ret;
10568
10569 /**********************************************************************
10570@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
10571
10572 popq %rbx;
10573 popq %rbp;
10574+ pax_force_retaddr 0, 1
10575 ret;
10576
10577 __enc_xor4:
10578@@ -349,6 +355,7 @@ __enc_xor4:
10579
10580 popq %rbx;
10581 popq %rbp;
10582+ pax_force_retaddr 0, 1
10583 ret;
10584
10585 .align 8
10586@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
10587 popq %rbx;
10588 popq %rbp;
10589
10590+ pax_force_retaddr 0, 1
10591 ret;
10592
10593diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
10594index 0b33743..7a56206 100644
10595--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
10596+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
10597@@ -20,6 +20,8 @@
10598 *
10599 */
10600
10601+#include <asm/alternative-asm.h>
10602+
10603 .file "camellia-x86_64-asm_64.S"
10604 .text
10605
10606@@ -229,12 +231,14 @@ __enc_done:
10607 enc_outunpack(mov, RT1);
10608
10609 movq RRBP, %rbp;
10610+ pax_force_retaddr 0, 1
10611 ret;
10612
10613 __enc_xor:
10614 enc_outunpack(xor, RT1);
10615
10616 movq RRBP, %rbp;
10617+ pax_force_retaddr 0, 1
10618 ret;
10619
10620 .global camellia_dec_blk;
10621@@ -275,6 +279,7 @@ __dec_rounds16:
10622 dec_outunpack();
10623
10624 movq RRBP, %rbp;
10625+ pax_force_retaddr 0, 1
10626 ret;
10627
10628 /**********************************************************************
10629@@ -468,6 +473,7 @@ __enc2_done:
10630
10631 movq RRBP, %rbp;
10632 popq %rbx;
10633+ pax_force_retaddr 0, 1
10634 ret;
10635
10636 __enc2_xor:
10637@@ -475,6 +481,7 @@ __enc2_xor:
10638
10639 movq RRBP, %rbp;
10640 popq %rbx;
10641+ pax_force_retaddr 0, 1
10642 ret;
10643
10644 .global camellia_dec_blk_2way;
10645@@ -517,4 +524,5 @@ __dec2_rounds16:
10646
10647 movq RRBP, %rbp;
10648 movq RXOR, %rbx;
10649+ pax_force_retaddr 0, 1
10650 ret;
10651diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10652index 15b00ac..2071784 100644
10653--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10654+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10655@@ -23,6 +23,8 @@
10656 *
10657 */
10658
10659+#include <asm/alternative-asm.h>
10660+
10661 .file "cast5-avx-x86_64-asm_64.S"
10662
10663 .extern cast_s1
10664@@ -281,6 +283,7 @@ __skip_enc:
10665 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10666 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10667
10668+ pax_force_retaddr 0, 1
10669 ret;
10670
10671 .align 16
10672@@ -353,6 +356,7 @@ __dec_tail:
10673 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10674 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10675
10676+ pax_force_retaddr 0, 1
10677 ret;
10678
10679 __skip_dec:
10680@@ -392,6 +396,7 @@ cast5_ecb_enc_16way:
10681 vmovdqu RR4, (6*4*4)(%r11);
10682 vmovdqu RL4, (7*4*4)(%r11);
10683
10684+ pax_force_retaddr
10685 ret;
10686
10687 .align 16
10688@@ -427,6 +432,7 @@ cast5_ecb_dec_16way:
10689 vmovdqu RR4, (6*4*4)(%r11);
10690 vmovdqu RL4, (7*4*4)(%r11);
10691
10692+ pax_force_retaddr
10693 ret;
10694
10695 .align 16
10696@@ -479,6 +485,7 @@ cast5_cbc_dec_16way:
10697
10698 popq %r12;
10699
10700+ pax_force_retaddr
10701 ret;
10702
10703 .align 16
10704@@ -555,4 +562,5 @@ cast5_ctr_16way:
10705
10706 popq %r12;
10707
10708+ pax_force_retaddr
10709 ret;
10710diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10711index 2569d0d..637c289 100644
10712--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10713+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10714@@ -23,6 +23,8 @@
10715 *
10716 */
10717
10718+#include <asm/alternative-asm.h>
10719+
10720 #include "glue_helper-asm-avx.S"
10721
10722 .file "cast6-avx-x86_64-asm_64.S"
10723@@ -294,6 +296,7 @@ __cast6_enc_blk8:
10724 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
10725 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
10726
10727+ pax_force_retaddr 0, 1
10728 ret;
10729
10730 .align 8
10731@@ -340,6 +343,7 @@ __cast6_dec_blk8:
10732 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
10733 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
10734
10735+ pax_force_retaddr 0, 1
10736 ret;
10737
10738 .align 8
10739@@ -361,6 +365,7 @@ cast6_ecb_enc_8way:
10740
10741 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10742
10743+ pax_force_retaddr
10744 ret;
10745
10746 .align 8
10747@@ -382,6 +387,7 @@ cast6_ecb_dec_8way:
10748
10749 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10750
10751+ pax_force_retaddr
10752 ret;
10753
10754 .align 8
10755@@ -408,6 +414,7 @@ cast6_cbc_dec_8way:
10756
10757 popq %r12;
10758
10759+ pax_force_retaddr
10760 ret;
10761
10762 .align 8
10763@@ -436,4 +443,5 @@ cast6_ctr_8way:
10764
10765 popq %r12;
10766
10767+ pax_force_retaddr
10768 ret;
10769diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
10770index 6214a9b..1f4fc9a 100644
10771--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
10772+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
10773@@ -1,3 +1,5 @@
10774+#include <asm/alternative-asm.h>
10775+
10776 # enter ECRYPT_encrypt_bytes
10777 .text
10778 .p2align 5
10779@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
10780 add %r11,%rsp
10781 mov %rdi,%rax
10782 mov %rsi,%rdx
10783+ pax_force_retaddr 0, 1
10784 ret
10785 # bytesatleast65:
10786 ._bytesatleast65:
10787@@ -891,6 +894,7 @@ ECRYPT_keysetup:
10788 add %r11,%rsp
10789 mov %rdi,%rax
10790 mov %rsi,%rdx
10791+ pax_force_retaddr
10792 ret
10793 # enter ECRYPT_ivsetup
10794 .text
10795@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
10796 add %r11,%rsp
10797 mov %rdi,%rax
10798 mov %rsi,%rdx
10799+ pax_force_retaddr
10800 ret
10801diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10802index 02b0e9f..cf4cf5c 100644
10803--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10804+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10805@@ -24,6 +24,8 @@
10806 *
10807 */
10808
10809+#include <asm/alternative-asm.h>
10810+
10811 #include "glue_helper-asm-avx.S"
10812
10813 .file "serpent-avx-x86_64-asm_64.S"
10814@@ -618,6 +620,7 @@ __serpent_enc_blk8_avx:
10815 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10816 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10817
10818+ pax_force_retaddr
10819 ret;
10820
10821 .align 8
10822@@ -673,6 +676,7 @@ __serpent_dec_blk8_avx:
10823 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
10824 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
10825
10826+ pax_force_retaddr
10827 ret;
10828
10829 .align 8
10830@@ -692,6 +696,7 @@ serpent_ecb_enc_8way_avx:
10831
10832 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10833
10834+ pax_force_retaddr
10835 ret;
10836
10837 .align 8
10838@@ -711,6 +716,7 @@ serpent_ecb_dec_8way_avx:
10839
10840 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
10841
10842+ pax_force_retaddr
10843 ret;
10844
10845 .align 8
10846@@ -730,6 +736,7 @@ serpent_cbc_dec_8way_avx:
10847
10848 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
10849
10850+ pax_force_retaddr
10851 ret;
10852
10853 .align 8
10854@@ -751,4 +758,5 @@ serpent_ctr_8way_avx:
10855
10856 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10857
10858+ pax_force_retaddr
10859 ret;
10860diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10861index 3ee1ff0..cbc568b 100644
10862--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10863+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10864@@ -24,6 +24,8 @@
10865 *
10866 */
10867
10868+#include <asm/alternative-asm.h>
10869+
10870 .file "serpent-sse2-x86_64-asm_64.S"
10871 .text
10872
10873@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
10874 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10875 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10876
10877+ pax_force_retaddr
10878 ret;
10879
10880 __enc_xor8:
10881 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10882 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10883
10884+ pax_force_retaddr
10885 ret;
10886
10887 .align 8
10888@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
10889 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
10890 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
10891
10892+ pax_force_retaddr
10893 ret;
10894diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
10895index 49d6987..df66bd4 100644
10896--- a/arch/x86/crypto/sha1_ssse3_asm.S
10897+++ b/arch/x86/crypto/sha1_ssse3_asm.S
10898@@ -28,6 +28,8 @@
10899 * (at your option) any later version.
10900 */
10901
10902+#include <asm/alternative-asm.h>
10903+
10904 #define CTX %rdi // arg1
10905 #define BUF %rsi // arg2
10906 #define CNT %rdx // arg3
10907@@ -104,6 +106,7 @@
10908 pop %r12
10909 pop %rbp
10910 pop %rbx
10911+ pax_force_retaddr 0, 1
10912 ret
10913
10914 .size \name, .-\name
10915diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
10916index ebac16b..8092eb9 100644
10917--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
10918+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
10919@@ -23,6 +23,8 @@
10920 *
10921 */
10922
10923+#include <asm/alternative-asm.h>
10924+
10925 #include "glue_helper-asm-avx.S"
10926
10927 .file "twofish-avx-x86_64-asm_64.S"
10928@@ -283,6 +285,7 @@ __twofish_enc_blk8:
10929 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
10930 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
10931
10932+ pax_force_retaddr 0, 1
10933 ret;
10934
10935 .align 8
10936@@ -324,6 +327,7 @@ __twofish_dec_blk8:
10937 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
10938 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
10939
10940+ pax_force_retaddr 0, 1
10941 ret;
10942
10943 .align 8
10944@@ -345,6 +349,7 @@ twofish_ecb_enc_8way:
10945
10946 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
10947
10948+ pax_force_retaddr 0, 1
10949 ret;
10950
10951 .align 8
10952@@ -366,6 +371,7 @@ twofish_ecb_dec_8way:
10953
10954 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10955
10956+ pax_force_retaddr 0, 1
10957 ret;
10958
10959 .align 8
10960@@ -392,6 +398,7 @@ twofish_cbc_dec_8way:
10961
10962 popq %r12;
10963
10964+ pax_force_retaddr 0, 1
10965 ret;
10966
10967 .align 8
10968@@ -420,4 +427,5 @@ twofish_ctr_8way:
10969
10970 popq %r12;
10971
10972+ pax_force_retaddr 0, 1
10973 ret;
10974diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
10975index 5b012a2..36d5364 100644
10976--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
10977+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
10978@@ -20,6 +20,8 @@
10979 *
10980 */
10981
10982+#include <asm/alternative-asm.h>
10983+
10984 .file "twofish-x86_64-asm-3way.S"
10985 .text
10986
10987@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
10988 popq %r13;
10989 popq %r14;
10990 popq %r15;
10991+ pax_force_retaddr 0, 1
10992 ret;
10993
10994 __enc_xor3:
10995@@ -271,6 +274,7 @@ __enc_xor3:
10996 popq %r13;
10997 popq %r14;
10998 popq %r15;
10999+ pax_force_retaddr 0, 1
11000 ret;
11001
11002 .global twofish_dec_blk_3way
11003@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
11004 popq %r13;
11005 popq %r14;
11006 popq %r15;
11007+ pax_force_retaddr 0, 1
11008 ret;
11009
11010diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11011index 7bcf3fc..f53832f 100644
11012--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11013+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11014@@ -21,6 +21,7 @@
11015 .text
11016
11017 #include <asm/asm-offsets.h>
11018+#include <asm/alternative-asm.h>
11019
11020 #define a_offset 0
11021 #define b_offset 4
11022@@ -268,6 +269,7 @@ twofish_enc_blk:
11023
11024 popq R1
11025 movq $1,%rax
11026+ pax_force_retaddr 0, 1
11027 ret
11028
11029 twofish_dec_blk:
11030@@ -319,4 +321,5 @@ twofish_dec_blk:
11031
11032 popq R1
11033 movq $1,%rax
11034+ pax_force_retaddr 0, 1
11035 ret
11036diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11037index a703af1..f5b9c36 100644
11038--- a/arch/x86/ia32/ia32_aout.c
11039+++ b/arch/x86/ia32/ia32_aout.c
11040@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11041 unsigned long dump_start, dump_size;
11042 struct user32 dump;
11043
11044+ memset(&dump, 0, sizeof(dump));
11045+
11046 fs = get_fs();
11047 set_fs(KERNEL_DS);
11048 has_dumped = 1;
11049diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11050index a1daf4a..f8c4537 100644
11051--- a/arch/x86/ia32/ia32_signal.c
11052+++ b/arch/x86/ia32/ia32_signal.c
11053@@ -348,7 +348,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
11054 sp -= frame_size;
11055 /* Align the stack pointer according to the i386 ABI,
11056 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11057- sp = ((sp + 4) & -16ul) - 4;
11058+ sp = ((sp - 12) & -16ul) - 4;
11059 return (void __user *) sp;
11060 }
11061
11062@@ -406,7 +406,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
11063 * These are actually not used anymore, but left because some
11064 * gdb versions depend on them as a marker.
11065 */
11066- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11067+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11068 } put_user_catch(err);
11069
11070 if (err)
11071@@ -448,7 +448,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11072 0xb8,
11073 __NR_ia32_rt_sigreturn,
11074 0x80cd,
11075- 0,
11076+ 0
11077 };
11078
11079 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
11080@@ -471,16 +471,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11081
11082 if (ka->sa.sa_flags & SA_RESTORER)
11083 restorer = ka->sa.sa_restorer;
11084+ else if (current->mm->context.vdso)
11085+ /* Return stub is in 32bit vsyscall page */
11086+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11087 else
11088- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11089- rt_sigreturn);
11090+ restorer = &frame->retcode;
11091 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11092
11093 /*
11094 * Not actually used anymore, but left because some gdb
11095 * versions need it.
11096 */
11097- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11098+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11099 } put_user_catch(err);
11100
11101 err |= copy_siginfo_to_user32(&frame->info, info);
11102diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11103index 142c4ce..19b683f 100644
11104--- a/arch/x86/ia32/ia32entry.S
11105+++ b/arch/x86/ia32/ia32entry.S
11106@@ -15,8 +15,10 @@
11107 #include <asm/irqflags.h>
11108 #include <asm/asm.h>
11109 #include <asm/smap.h>
11110+#include <asm/pgtable.h>
11111 #include <linux/linkage.h>
11112 #include <linux/err.h>
11113+#include <asm/alternative-asm.h>
11114
11115 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11116 #include <linux/elf-em.h>
11117@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11118 ENDPROC(native_irq_enable_sysexit)
11119 #endif
11120
11121+ .macro pax_enter_kernel_user
11122+ pax_set_fptr_mask
11123+#ifdef CONFIG_PAX_MEMORY_UDEREF
11124+ call pax_enter_kernel_user
11125+#endif
11126+ .endm
11127+
11128+ .macro pax_exit_kernel_user
11129+#ifdef CONFIG_PAX_MEMORY_UDEREF
11130+ call pax_exit_kernel_user
11131+#endif
11132+#ifdef CONFIG_PAX_RANDKSTACK
11133+ pushq %rax
11134+ pushq %r11
11135+ call pax_randomize_kstack
11136+ popq %r11
11137+ popq %rax
11138+#endif
11139+ .endm
11140+
11141+.macro pax_erase_kstack
11142+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11143+ call pax_erase_kstack
11144+#endif
11145+.endm
11146+
11147 /*
11148 * 32bit SYSENTER instruction entry.
11149 *
11150@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11151 CFI_REGISTER rsp,rbp
11152 SWAPGS_UNSAFE_STACK
11153 movq PER_CPU_VAR(kernel_stack), %rsp
11154- addq $(KERNEL_STACK_OFFSET),%rsp
11155- /*
11156- * No need to follow this irqs on/off section: the syscall
11157- * disabled irqs, here we enable it straight after entry:
11158- */
11159- ENABLE_INTERRUPTS(CLBR_NONE)
11160 movl %ebp,%ebp /* zero extension */
11161 pushq_cfi $__USER32_DS
11162 /*CFI_REL_OFFSET ss,0*/
11163@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11164 CFI_REL_OFFSET rsp,0
11165 pushfq_cfi
11166 /*CFI_REL_OFFSET rflags,0*/
11167- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11168- CFI_REGISTER rip,r10
11169+ orl $X86_EFLAGS_IF,(%rsp)
11170+ GET_THREAD_INFO(%r11)
11171+ movl TI_sysenter_return(%r11), %r11d
11172+ CFI_REGISTER rip,r11
11173 pushq_cfi $__USER32_CS
11174 /*CFI_REL_OFFSET cs,0*/
11175 movl %eax, %eax
11176- pushq_cfi %r10
11177+ pushq_cfi %r11
11178 CFI_REL_OFFSET rip,0
11179 pushq_cfi %rax
11180 cld
11181 SAVE_ARGS 0,1,0
11182+ pax_enter_kernel_user
11183+
11184+#ifdef CONFIG_PAX_RANDKSTACK
11185+ pax_erase_kstack
11186+#endif
11187+
11188+ /*
11189+ * No need to follow this irqs on/off section: the syscall
11190+ * disabled irqs, here we enable it straight after entry:
11191+ */
11192+ ENABLE_INTERRUPTS(CLBR_NONE)
11193 /* no need to do an access_ok check here because rbp has been
11194 32bit zero extended */
11195+
11196+#ifdef CONFIG_PAX_MEMORY_UDEREF
11197+ mov $PAX_USER_SHADOW_BASE,%r11
11198+ add %r11,%rbp
11199+#endif
11200+
11201 ASM_STAC
11202 1: movl (%rbp),%ebp
11203 _ASM_EXTABLE(1b,ia32_badarg)
11204 ASM_CLAC
11205- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11206- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11207+ GET_THREAD_INFO(%r11)
11208+ orl $TS_COMPAT,TI_status(%r11)
11209+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11210 CFI_REMEMBER_STATE
11211 jnz sysenter_tracesys
11212 cmpq $(IA32_NR_syscalls-1),%rax
11213@@ -162,12 +204,15 @@ sysenter_do_call:
11214 sysenter_dispatch:
11215 call *ia32_sys_call_table(,%rax,8)
11216 movq %rax,RAX-ARGOFFSET(%rsp)
11217+ GET_THREAD_INFO(%r11)
11218 DISABLE_INTERRUPTS(CLBR_NONE)
11219 TRACE_IRQS_OFF
11220- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11221+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11222 jnz sysexit_audit
11223 sysexit_from_sys_call:
11224- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11225+ pax_exit_kernel_user
11226+ pax_erase_kstack
11227+ andl $~TS_COMPAT,TI_status(%r11)
11228 /* clear IF, that popfq doesn't enable interrupts early */
11229 andl $~0x200,EFLAGS-R11(%rsp)
11230 movl RIP-R11(%rsp),%edx /* User %eip */
11231@@ -193,6 +238,9 @@ sysexit_from_sys_call:
11232 movl %eax,%esi /* 2nd arg: syscall number */
11233 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11234 call __audit_syscall_entry
11235+
11236+ pax_erase_kstack
11237+
11238 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11239 cmpq $(IA32_NR_syscalls-1),%rax
11240 ja ia32_badsys
11241@@ -204,7 +252,7 @@ sysexit_from_sys_call:
11242 .endm
11243
11244 .macro auditsys_exit exit
11245- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11246+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11247 jnz ia32_ret_from_sys_call
11248 TRACE_IRQS_ON
11249 ENABLE_INTERRUPTS(CLBR_NONE)
11250@@ -215,11 +263,12 @@ sysexit_from_sys_call:
11251 1: setbe %al /* 1 if error, 0 if not */
11252 movzbl %al,%edi /* zero-extend that into %edi */
11253 call __audit_syscall_exit
11254+ GET_THREAD_INFO(%r11)
11255 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11256 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11257 DISABLE_INTERRUPTS(CLBR_NONE)
11258 TRACE_IRQS_OFF
11259- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11260+ testl %edi,TI_flags(%r11)
11261 jz \exit
11262 CLEAR_RREGS -ARGOFFSET
11263 jmp int_with_check
11264@@ -237,7 +286,7 @@ sysexit_audit:
11265
11266 sysenter_tracesys:
11267 #ifdef CONFIG_AUDITSYSCALL
11268- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11269+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11270 jz sysenter_auditsys
11271 #endif
11272 SAVE_REST
11273@@ -249,6 +298,9 @@ sysenter_tracesys:
11274 RESTORE_REST
11275 cmpq $(IA32_NR_syscalls-1),%rax
11276 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11277+
11278+ pax_erase_kstack
11279+
11280 jmp sysenter_do_call
11281 CFI_ENDPROC
11282 ENDPROC(ia32_sysenter_target)
11283@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11284 ENTRY(ia32_cstar_target)
11285 CFI_STARTPROC32 simple
11286 CFI_SIGNAL_FRAME
11287- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11288+ CFI_DEF_CFA rsp,0
11289 CFI_REGISTER rip,rcx
11290 /*CFI_REGISTER rflags,r11*/
11291 SWAPGS_UNSAFE_STACK
11292 movl %esp,%r8d
11293 CFI_REGISTER rsp,r8
11294 movq PER_CPU_VAR(kernel_stack),%rsp
11295+ SAVE_ARGS 8*6,0,0
11296+ pax_enter_kernel_user
11297+
11298+#ifdef CONFIG_PAX_RANDKSTACK
11299+ pax_erase_kstack
11300+#endif
11301+
11302 /*
11303 * No need to follow this irqs on/off section: the syscall
11304 * disabled irqs and here we enable it straight after entry:
11305 */
11306 ENABLE_INTERRUPTS(CLBR_NONE)
11307- SAVE_ARGS 8,0,0
11308 movl %eax,%eax /* zero extension */
11309 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11310 movq %rcx,RIP-ARGOFFSET(%rsp)
11311@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11312 /* no need to do an access_ok check here because r8 has been
11313 32bit zero extended */
11314 /* hardware stack frame is complete now */
11315+
11316+#ifdef CONFIG_PAX_MEMORY_UDEREF
11317+ mov $PAX_USER_SHADOW_BASE,%r11
11318+ add %r11,%r8
11319+#endif
11320+
11321 ASM_STAC
11322 1: movl (%r8),%r9d
11323 _ASM_EXTABLE(1b,ia32_badarg)
11324 ASM_CLAC
11325- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11326- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11327+ GET_THREAD_INFO(%r11)
11328+ orl $TS_COMPAT,TI_status(%r11)
11329+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11330 CFI_REMEMBER_STATE
11331 jnz cstar_tracesys
11332 cmpq $IA32_NR_syscalls-1,%rax
11333@@ -319,12 +384,15 @@ cstar_do_call:
11334 cstar_dispatch:
11335 call *ia32_sys_call_table(,%rax,8)
11336 movq %rax,RAX-ARGOFFSET(%rsp)
11337+ GET_THREAD_INFO(%r11)
11338 DISABLE_INTERRUPTS(CLBR_NONE)
11339 TRACE_IRQS_OFF
11340- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11341+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11342 jnz sysretl_audit
11343 sysretl_from_sys_call:
11344- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11345+ pax_exit_kernel_user
11346+ pax_erase_kstack
11347+ andl $~TS_COMPAT,TI_status(%r11)
11348 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11349 movl RIP-ARGOFFSET(%rsp),%ecx
11350 CFI_REGISTER rip,rcx
11351@@ -352,7 +420,7 @@ sysretl_audit:
11352
11353 cstar_tracesys:
11354 #ifdef CONFIG_AUDITSYSCALL
11355- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11356+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11357 jz cstar_auditsys
11358 #endif
11359 xchgl %r9d,%ebp
11360@@ -366,6 +434,9 @@ cstar_tracesys:
11361 xchgl %ebp,%r9d
11362 cmpq $(IA32_NR_syscalls-1),%rax
11363 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11364+
11365+ pax_erase_kstack
11366+
11367 jmp cstar_do_call
11368 END(ia32_cstar_target)
11369
11370@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11371 CFI_REL_OFFSET rip,RIP-RIP
11372 PARAVIRT_ADJUST_EXCEPTION_FRAME
11373 SWAPGS
11374- /*
11375- * No need to follow this irqs on/off section: the syscall
11376- * disabled irqs and here we enable it straight after entry:
11377- */
11378- ENABLE_INTERRUPTS(CLBR_NONE)
11379 movl %eax,%eax
11380 pushq_cfi %rax
11381 cld
11382 /* note the registers are not zero extended to the sf.
11383 this could be a problem. */
11384 SAVE_ARGS 0,1,0
11385- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11386- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11387+ pax_enter_kernel_user
11388+
11389+#ifdef CONFIG_PAX_RANDKSTACK
11390+ pax_erase_kstack
11391+#endif
11392+
11393+ /*
11394+ * No need to follow this irqs on/off section: the syscall
11395+ * disabled irqs and here we enable it straight after entry:
11396+ */
11397+ ENABLE_INTERRUPTS(CLBR_NONE)
11398+ GET_THREAD_INFO(%r11)
11399+ orl $TS_COMPAT,TI_status(%r11)
11400+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11401 jnz ia32_tracesys
11402 cmpq $(IA32_NR_syscalls-1),%rax
11403 ja ia32_badsys
11404@@ -442,6 +520,9 @@ ia32_tracesys:
11405 RESTORE_REST
11406 cmpq $(IA32_NR_syscalls-1),%rax
11407 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11408+
11409+ pax_erase_kstack
11410+
11411 jmp ia32_do_call
11412 END(ia32_syscall)
11413
11414diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11415index d0b689b..34be51d 100644
11416--- a/arch/x86/ia32/sys_ia32.c
11417+++ b/arch/x86/ia32/sys_ia32.c
11418@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11419 */
11420 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11421 {
11422- typeof(ubuf->st_uid) uid = 0;
11423- typeof(ubuf->st_gid) gid = 0;
11424+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
11425+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
11426 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11427 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11428 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11429@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
11430 mm_segment_t old_fs = get_fs();
11431
11432 set_fs(KERNEL_DS);
11433- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
11434+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
11435 set_fs(old_fs);
11436 if (put_compat_timespec(&t, interval))
11437 return -EFAULT;
11438@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
11439 mm_segment_t old_fs = get_fs();
11440
11441 set_fs(KERNEL_DS);
11442- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
11443+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
11444 set_fs(old_fs);
11445 if (!ret) {
11446 switch (_NSIG_WORDS) {
11447@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
11448 if (copy_siginfo_from_user32(&info, uinfo))
11449 return -EFAULT;
11450 set_fs(KERNEL_DS);
11451- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
11452+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
11453 set_fs(old_fs);
11454 return ret;
11455 }
11456@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
11457 return -EFAULT;
11458
11459 set_fs(KERNEL_DS);
11460- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
11461+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
11462 count);
11463 set_fs(old_fs);
11464
11465diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11466index 372231c..a5aa1a1 100644
11467--- a/arch/x86/include/asm/alternative-asm.h
11468+++ b/arch/x86/include/asm/alternative-asm.h
11469@@ -18,6 +18,45 @@
11470 .endm
11471 #endif
11472
11473+#ifdef KERNEXEC_PLUGIN
11474+ .macro pax_force_retaddr_bts rip=0
11475+ btsq $63,\rip(%rsp)
11476+ .endm
11477+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11478+ .macro pax_force_retaddr rip=0, reload=0
11479+ btsq $63,\rip(%rsp)
11480+ .endm
11481+ .macro pax_force_fptr ptr
11482+ btsq $63,\ptr
11483+ .endm
11484+ .macro pax_set_fptr_mask
11485+ .endm
11486+#endif
11487+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11488+ .macro pax_force_retaddr rip=0, reload=0
11489+ .if \reload
11490+ pax_set_fptr_mask
11491+ .endif
11492+ orq %r10,\rip(%rsp)
11493+ .endm
11494+ .macro pax_force_fptr ptr
11495+ orq %r10,\ptr
11496+ .endm
11497+ .macro pax_set_fptr_mask
11498+ movabs $0x8000000000000000,%r10
11499+ .endm
11500+#endif
11501+#else
11502+ .macro pax_force_retaddr rip=0, reload=0
11503+ .endm
11504+ .macro pax_force_fptr ptr
11505+ .endm
11506+ .macro pax_force_retaddr_bts rip=0
11507+ .endm
11508+ .macro pax_set_fptr_mask
11509+ .endm
11510+#endif
11511+
11512 .macro altinstruction_entry orig alt feature orig_len alt_len
11513 .long \orig - .
11514 .long \alt - .
11515diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11516index 58ed6d9..f1cbe58 100644
11517--- a/arch/x86/include/asm/alternative.h
11518+++ b/arch/x86/include/asm/alternative.h
11519@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11520 ".pushsection .discard,\"aw\",@progbits\n" \
11521 DISCARD_ENTRY(1) \
11522 ".popsection\n" \
11523- ".pushsection .altinstr_replacement, \"ax\"\n" \
11524+ ".pushsection .altinstr_replacement, \"a\"\n" \
11525 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11526 ".popsection"
11527
11528@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11529 DISCARD_ENTRY(1) \
11530 DISCARD_ENTRY(2) \
11531 ".popsection\n" \
11532- ".pushsection .altinstr_replacement, \"ax\"\n" \
11533+ ".pushsection .altinstr_replacement, \"a\"\n" \
11534 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11535 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11536 ".popsection"
11537diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11538index 3388034..050f0b9 100644
11539--- a/arch/x86/include/asm/apic.h
11540+++ b/arch/x86/include/asm/apic.h
11541@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11542
11543 #ifdef CONFIG_X86_LOCAL_APIC
11544
11545-extern unsigned int apic_verbosity;
11546+extern int apic_verbosity;
11547 extern int local_apic_timer_c2_ok;
11548
11549 extern int disable_apic;
11550diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11551index 20370c6..a2eb9b0 100644
11552--- a/arch/x86/include/asm/apm.h
11553+++ b/arch/x86/include/asm/apm.h
11554@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11555 __asm__ __volatile__(APM_DO_ZERO_SEGS
11556 "pushl %%edi\n\t"
11557 "pushl %%ebp\n\t"
11558- "lcall *%%cs:apm_bios_entry\n\t"
11559+ "lcall *%%ss:apm_bios_entry\n\t"
11560 "setc %%al\n\t"
11561 "popl %%ebp\n\t"
11562 "popl %%edi\n\t"
11563@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
11564 __asm__ __volatile__(APM_DO_ZERO_SEGS
11565 "pushl %%edi\n\t"
11566 "pushl %%ebp\n\t"
11567- "lcall *%%cs:apm_bios_entry\n\t"
11568+ "lcall *%%ss:apm_bios_entry\n\t"
11569 "setc %%bl\n\t"
11570 "popl %%ebp\n\t"
11571 "popl %%edi\n\t"
11572diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
11573index 722aa3b..3a0bb27 100644
11574--- a/arch/x86/include/asm/atomic.h
11575+++ b/arch/x86/include/asm/atomic.h
11576@@ -22,7 +22,18 @@
11577 */
11578 static inline int atomic_read(const atomic_t *v)
11579 {
11580- return (*(volatile int *)&(v)->counter);
11581+ return (*(volatile const int *)&(v)->counter);
11582+}
11583+
11584+/**
11585+ * atomic_read_unchecked - read atomic variable
11586+ * @v: pointer of type atomic_unchecked_t
11587+ *
11588+ * Atomically reads the value of @v.
11589+ */
11590+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
11591+{
11592+ return (*(volatile const int *)&(v)->counter);
11593 }
11594
11595 /**
11596@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
11597 }
11598
11599 /**
11600+ * atomic_set_unchecked - set atomic variable
11601+ * @v: pointer of type atomic_unchecked_t
11602+ * @i: required value
11603+ *
11604+ * Atomically sets the value of @v to @i.
11605+ */
11606+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
11607+{
11608+ v->counter = i;
11609+}
11610+
11611+/**
11612 * atomic_add - add integer to atomic variable
11613 * @i: integer value to add
11614 * @v: pointer of type atomic_t
11615@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
11616 */
11617 static inline void atomic_add(int i, atomic_t *v)
11618 {
11619- asm volatile(LOCK_PREFIX "addl %1,%0"
11620+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
11621+
11622+#ifdef CONFIG_PAX_REFCOUNT
11623+ "jno 0f\n"
11624+ LOCK_PREFIX "subl %1,%0\n"
11625+ "int $4\n0:\n"
11626+ _ASM_EXTABLE(0b, 0b)
11627+#endif
11628+
11629+ : "+m" (v->counter)
11630+ : "ir" (i));
11631+}
11632+
11633+/**
11634+ * atomic_add_unchecked - add integer to atomic variable
11635+ * @i: integer value to add
11636+ * @v: pointer of type atomic_unchecked_t
11637+ *
11638+ * Atomically adds @i to @v.
11639+ */
11640+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
11641+{
11642+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
11643 : "+m" (v->counter)
11644 : "ir" (i));
11645 }
11646@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
11647 */
11648 static inline void atomic_sub(int i, atomic_t *v)
11649 {
11650- asm volatile(LOCK_PREFIX "subl %1,%0"
11651+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
11652+
11653+#ifdef CONFIG_PAX_REFCOUNT
11654+ "jno 0f\n"
11655+ LOCK_PREFIX "addl %1,%0\n"
11656+ "int $4\n0:\n"
11657+ _ASM_EXTABLE(0b, 0b)
11658+#endif
11659+
11660+ : "+m" (v->counter)
11661+ : "ir" (i));
11662+}
11663+
11664+/**
11665+ * atomic_sub_unchecked - subtract integer from atomic variable
11666+ * @i: integer value to subtract
11667+ * @v: pointer of type atomic_unchecked_t
11668+ *
11669+ * Atomically subtracts @i from @v.
11670+ */
11671+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
11672+{
11673+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
11674 : "+m" (v->counter)
11675 : "ir" (i));
11676 }
11677@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11678 {
11679 unsigned char c;
11680
11681- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
11682+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
11683+
11684+#ifdef CONFIG_PAX_REFCOUNT
11685+ "jno 0f\n"
11686+ LOCK_PREFIX "addl %2,%0\n"
11687+ "int $4\n0:\n"
11688+ _ASM_EXTABLE(0b, 0b)
11689+#endif
11690+
11691+ "sete %1\n"
11692 : "+m" (v->counter), "=qm" (c)
11693 : "ir" (i) : "memory");
11694 return c;
11695@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11696 */
11697 static inline void atomic_inc(atomic_t *v)
11698 {
11699- asm volatile(LOCK_PREFIX "incl %0"
11700+ asm volatile(LOCK_PREFIX "incl %0\n"
11701+
11702+#ifdef CONFIG_PAX_REFCOUNT
11703+ "jno 0f\n"
11704+ LOCK_PREFIX "decl %0\n"
11705+ "int $4\n0:\n"
11706+ _ASM_EXTABLE(0b, 0b)
11707+#endif
11708+
11709+ : "+m" (v->counter));
11710+}
11711+
11712+/**
11713+ * atomic_inc_unchecked - increment atomic variable
11714+ * @v: pointer of type atomic_unchecked_t
11715+ *
11716+ * Atomically increments @v by 1.
11717+ */
11718+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
11719+{
11720+ asm volatile(LOCK_PREFIX "incl %0\n"
11721 : "+m" (v->counter));
11722 }
11723
11724@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
11725 */
11726 static inline void atomic_dec(atomic_t *v)
11727 {
11728- asm volatile(LOCK_PREFIX "decl %0"
11729+ asm volatile(LOCK_PREFIX "decl %0\n"
11730+
11731+#ifdef CONFIG_PAX_REFCOUNT
11732+ "jno 0f\n"
11733+ LOCK_PREFIX "incl %0\n"
11734+ "int $4\n0:\n"
11735+ _ASM_EXTABLE(0b, 0b)
11736+#endif
11737+
11738+ : "+m" (v->counter));
11739+}
11740+
11741+/**
11742+ * atomic_dec_unchecked - decrement atomic variable
11743+ * @v: pointer of type atomic_unchecked_t
11744+ *
11745+ * Atomically decrements @v by 1.
11746+ */
11747+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
11748+{
11749+ asm volatile(LOCK_PREFIX "decl %0\n"
11750 : "+m" (v->counter));
11751 }
11752
11753@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
11754 {
11755 unsigned char c;
11756
11757- asm volatile(LOCK_PREFIX "decl %0; sete %1"
11758+ asm volatile(LOCK_PREFIX "decl %0\n"
11759+
11760+#ifdef CONFIG_PAX_REFCOUNT
11761+ "jno 0f\n"
11762+ LOCK_PREFIX "incl %0\n"
11763+ "int $4\n0:\n"
11764+ _ASM_EXTABLE(0b, 0b)
11765+#endif
11766+
11767+ "sete %1\n"
11768 : "+m" (v->counter), "=qm" (c)
11769 : : "memory");
11770 return c != 0;
11771@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
11772 {
11773 unsigned char c;
11774
11775- asm volatile(LOCK_PREFIX "incl %0; sete %1"
11776+ asm volatile(LOCK_PREFIX "incl %0\n"
11777+
11778+#ifdef CONFIG_PAX_REFCOUNT
11779+ "jno 0f\n"
11780+ LOCK_PREFIX "decl %0\n"
11781+ "int $4\n0:\n"
11782+ _ASM_EXTABLE(0b, 0b)
11783+#endif
11784+
11785+ "sete %1\n"
11786+ : "+m" (v->counter), "=qm" (c)
11787+ : : "memory");
11788+ return c != 0;
11789+}
11790+
11791+/**
11792+ * atomic_inc_and_test_unchecked - increment and test
11793+ * @v: pointer of type atomic_unchecked_t
11794+ *
11795+ * Atomically increments @v by 1
11796+ * and returns true if the result is zero, or false for all
11797+ * other cases.
11798+ */
11799+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
11800+{
11801+ unsigned char c;
11802+
11803+ asm volatile(LOCK_PREFIX "incl %0\n"
11804+ "sete %1\n"
11805 : "+m" (v->counter), "=qm" (c)
11806 : : "memory");
11807 return c != 0;
11808@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
11809 {
11810 unsigned char c;
11811
11812- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
11813+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
11814+
11815+#ifdef CONFIG_PAX_REFCOUNT
11816+ "jno 0f\n"
11817+ LOCK_PREFIX "subl %2,%0\n"
11818+ "int $4\n0:\n"
11819+ _ASM_EXTABLE(0b, 0b)
11820+#endif
11821+
11822+ "sets %1\n"
11823 : "+m" (v->counter), "=qm" (c)
11824 : "ir" (i) : "memory");
11825 return c;
11826@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
11827 */
11828 static inline int atomic_add_return(int i, atomic_t *v)
11829 {
11830+ return i + xadd_check_overflow(&v->counter, i);
11831+}
11832+
11833+/**
11834+ * atomic_add_return_unchecked - add integer and return
11835+ * @i: integer value to add
11836+ * @v: pointer of type atomic_unchecked_t
11837+ *
11838+ * Atomically adds @i to @v and returns @i + @v
11839+ */
11840+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
11841+{
11842 return i + xadd(&v->counter, i);
11843 }
11844
11845@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
11846 }
11847
11848 #define atomic_inc_return(v) (atomic_add_return(1, v))
11849+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
11850+{
11851+ return atomic_add_return_unchecked(1, v);
11852+}
11853 #define atomic_dec_return(v) (atomic_sub_return(1, v))
11854
11855 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
11856@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
11857 return cmpxchg(&v->counter, old, new);
11858 }
11859
11860+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
11861+{
11862+ return cmpxchg(&v->counter, old, new);
11863+}
11864+
11865 static inline int atomic_xchg(atomic_t *v, int new)
11866 {
11867 return xchg(&v->counter, new);
11868 }
11869
11870+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
11871+{
11872+ return xchg(&v->counter, new);
11873+}
11874+
11875 /**
11876 * __atomic_add_unless - add unless the number is already a given value
11877 * @v: pointer of type atomic_t
11878@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
11879 */
11880 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
11881 {
11882- int c, old;
11883+ int c, old, new;
11884 c = atomic_read(v);
11885 for (;;) {
11886- if (unlikely(c == (u)))
11887+ if (unlikely(c == u))
11888 break;
11889- old = atomic_cmpxchg((v), c, c + (a));
11890+
11891+ asm volatile("addl %2,%0\n"
11892+
11893+#ifdef CONFIG_PAX_REFCOUNT
11894+ "jno 0f\n"
11895+ "subl %2,%0\n"
11896+ "int $4\n0:\n"
11897+ _ASM_EXTABLE(0b, 0b)
11898+#endif
11899+
11900+ : "=r" (new)
11901+ : "0" (c), "ir" (a));
11902+
11903+ old = atomic_cmpxchg(v, c, new);
11904 if (likely(old == c))
11905 break;
11906 c = old;
11907@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
11908 }
11909
11910 /**
11911+ * atomic_inc_not_zero_hint - increment if not null
11912+ * @v: pointer of type atomic_t
11913+ * @hint: probable value of the atomic before the increment
11914+ *
11915+ * This version of atomic_inc_not_zero() gives a hint of probable
11916+ * value of the atomic. This helps processor to not read the memory
11917+ * before doing the atomic read/modify/write cycle, lowering
11918+ * number of bus transactions on some arches.
11919+ *
11920+ * Returns: 0 if increment was not done, 1 otherwise.
11921+ */
11922+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
11923+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
11924+{
11925+ int val, c = hint, new;
11926+
11927+ /* sanity test, should be removed by compiler if hint is a constant */
11928+ if (!hint)
11929+ return __atomic_add_unless(v, 1, 0);
11930+
11931+ do {
11932+ asm volatile("incl %0\n"
11933+
11934+#ifdef CONFIG_PAX_REFCOUNT
11935+ "jno 0f\n"
11936+ "decl %0\n"
11937+ "int $4\n0:\n"
11938+ _ASM_EXTABLE(0b, 0b)
11939+#endif
11940+
11941+ : "=r" (new)
11942+ : "0" (c));
11943+
11944+ val = atomic_cmpxchg(v, c, new);
11945+ if (val == c)
11946+ return 1;
11947+ c = val;
11948+ } while (c);
11949+
11950+ return 0;
11951+}
11952+
11953+/**
11954 * atomic_inc_short - increment of a short integer
11955 * @v: pointer to type int
11956 *
11957@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
11958 #endif
11959
11960 /* These are x86-specific, used by some header files */
11961-#define atomic_clear_mask(mask, addr) \
11962- asm volatile(LOCK_PREFIX "andl %0,%1" \
11963- : : "r" (~(mask)), "m" (*(addr)) : "memory")
11964+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
11965+{
11966+ asm volatile(LOCK_PREFIX "andl %1,%0"
11967+ : "+m" (v->counter)
11968+ : "r" (~(mask))
11969+ : "memory");
11970+}
11971
11972-#define atomic_set_mask(mask, addr) \
11973- asm volatile(LOCK_PREFIX "orl %0,%1" \
11974- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
11975- : "memory")
11976+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
11977+{
11978+ asm volatile(LOCK_PREFIX "andl %1,%0"
11979+ : "+m" (v->counter)
11980+ : "r" (~(mask))
11981+ : "memory");
11982+}
11983+
11984+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
11985+{
11986+ asm volatile(LOCK_PREFIX "orl %1,%0"
11987+ : "+m" (v->counter)
11988+ : "r" (mask)
11989+ : "memory");
11990+}
11991+
11992+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
11993+{
11994+ asm volatile(LOCK_PREFIX "orl %1,%0"
11995+ : "+m" (v->counter)
11996+ : "r" (mask)
11997+ : "memory");
11998+}
11999
12000 /* Atomic operations are already serializing on x86 */
12001 #define smp_mb__before_atomic_dec() barrier()
12002diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12003index b154de7..aadebd8 100644
12004--- a/arch/x86/include/asm/atomic64_32.h
12005+++ b/arch/x86/include/asm/atomic64_32.h
12006@@ -12,6 +12,14 @@ typedef struct {
12007 u64 __aligned(8) counter;
12008 } atomic64_t;
12009
12010+#ifdef CONFIG_PAX_REFCOUNT
12011+typedef struct {
12012+ u64 __aligned(8) counter;
12013+} atomic64_unchecked_t;
12014+#else
12015+typedef atomic64_t atomic64_unchecked_t;
12016+#endif
12017+
12018 #define ATOMIC64_INIT(val) { (val) }
12019
12020 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12021@@ -37,21 +45,31 @@ typedef struct {
12022 ATOMIC64_DECL_ONE(sym##_386)
12023
12024 ATOMIC64_DECL_ONE(add_386);
12025+ATOMIC64_DECL_ONE(add_unchecked_386);
12026 ATOMIC64_DECL_ONE(sub_386);
12027+ATOMIC64_DECL_ONE(sub_unchecked_386);
12028 ATOMIC64_DECL_ONE(inc_386);
12029+ATOMIC64_DECL_ONE(inc_unchecked_386);
12030 ATOMIC64_DECL_ONE(dec_386);
12031+ATOMIC64_DECL_ONE(dec_unchecked_386);
12032 #endif
12033
12034 #define alternative_atomic64(f, out, in...) \
12035 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12036
12037 ATOMIC64_DECL(read);
12038+ATOMIC64_DECL(read_unchecked);
12039 ATOMIC64_DECL(set);
12040+ATOMIC64_DECL(set_unchecked);
12041 ATOMIC64_DECL(xchg);
12042 ATOMIC64_DECL(add_return);
12043+ATOMIC64_DECL(add_return_unchecked);
12044 ATOMIC64_DECL(sub_return);
12045+ATOMIC64_DECL(sub_return_unchecked);
12046 ATOMIC64_DECL(inc_return);
12047+ATOMIC64_DECL(inc_return_unchecked);
12048 ATOMIC64_DECL(dec_return);
12049+ATOMIC64_DECL(dec_return_unchecked);
12050 ATOMIC64_DECL(dec_if_positive);
12051 ATOMIC64_DECL(inc_not_zero);
12052 ATOMIC64_DECL(add_unless);
12053@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12054 }
12055
12056 /**
12057+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12058+ * @p: pointer to type atomic64_unchecked_t
12059+ * @o: expected value
12060+ * @n: new value
12061+ *
12062+ * Atomically sets @v to @n if it was equal to @o and returns
12063+ * the old value.
12064+ */
12065+
12066+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12067+{
12068+ return cmpxchg64(&v->counter, o, n);
12069+}
12070+
12071+/**
12072 * atomic64_xchg - xchg atomic64 variable
12073 * @v: pointer to type atomic64_t
12074 * @n: value to assign
12075@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12076 }
12077
12078 /**
12079+ * atomic64_set_unchecked - set atomic64 variable
12080+ * @v: pointer to type atomic64_unchecked_t
12081+ * @n: value to assign
12082+ *
12083+ * Atomically sets the value of @v to @n.
12084+ */
12085+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12086+{
12087+ unsigned high = (unsigned)(i >> 32);
12088+ unsigned low = (unsigned)i;
12089+ alternative_atomic64(set, /* no output */,
12090+ "S" (v), "b" (low), "c" (high)
12091+ : "eax", "edx", "memory");
12092+}
12093+
12094+/**
12095 * atomic64_read - read atomic64 variable
12096 * @v: pointer to type atomic64_t
12097 *
12098@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12099 }
12100
12101 /**
12102+ * atomic64_read_unchecked - read atomic64 variable
12103+ * @v: pointer to type atomic64_unchecked_t
12104+ *
12105+ * Atomically reads the value of @v and returns it.
12106+ */
12107+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12108+{
12109+ long long r;
12110+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12111+ return r;
12112+ }
12113+
12114+/**
12115 * atomic64_add_return - add and return
12116 * @i: integer value to add
12117 * @v: pointer to type atomic64_t
12118@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12119 return i;
12120 }
12121
12122+/**
12123+ * atomic64_add_return_unchecked - add and return
12124+ * @i: integer value to add
12125+ * @v: pointer to type atomic64_unchecked_t
12126+ *
12127+ * Atomically adds @i to @v and returns @i + *@v
12128+ */
12129+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12130+{
12131+ alternative_atomic64(add_return_unchecked,
12132+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12133+ ASM_NO_INPUT_CLOBBER("memory"));
12134+ return i;
12135+}
12136+
12137 /*
12138 * Other variants with different arithmetic operators:
12139 */
12140@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12141 return a;
12142 }
12143
12144+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12145+{
12146+ long long a;
12147+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
12148+ "S" (v) : "memory", "ecx");
12149+ return a;
12150+}
12151+
12152 static inline long long atomic64_dec_return(atomic64_t *v)
12153 {
12154 long long a;
12155@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12156 }
12157
12158 /**
12159+ * atomic64_add_unchecked - add integer to atomic64 variable
12160+ * @i: integer value to add
12161+ * @v: pointer to type atomic64_unchecked_t
12162+ *
12163+ * Atomically adds @i to @v.
12164+ */
12165+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12166+{
12167+ __alternative_atomic64(add_unchecked, add_return_unchecked,
12168+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12169+ ASM_NO_INPUT_CLOBBER("memory"));
12170+ return i;
12171+}
12172+
12173+/**
12174 * atomic64_sub - subtract the atomic64 variable
12175 * @i: integer value to subtract
12176 * @v: pointer to type atomic64_t
12177diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12178index 0e1cbfc..5623683 100644
12179--- a/arch/x86/include/asm/atomic64_64.h
12180+++ b/arch/x86/include/asm/atomic64_64.h
12181@@ -18,7 +18,19 @@
12182 */
12183 static inline long atomic64_read(const atomic64_t *v)
12184 {
12185- return (*(volatile long *)&(v)->counter);
12186+ return (*(volatile const long *)&(v)->counter);
12187+}
12188+
12189+/**
12190+ * atomic64_read_unchecked - read atomic64 variable
12191+ * @v: pointer of type atomic64_unchecked_t
12192+ *
12193+ * Atomically reads the value of @v.
12194+ * Doesn't imply a read memory barrier.
12195+ */
12196+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12197+{
12198+ return (*(volatile const long *)&(v)->counter);
12199 }
12200
12201 /**
12202@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12203 }
12204
12205 /**
12206+ * atomic64_set_unchecked - set atomic64 variable
12207+ * @v: pointer to type atomic64_unchecked_t
12208+ * @i: required value
12209+ *
12210+ * Atomically sets the value of @v to @i.
12211+ */
12212+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12213+{
12214+ v->counter = i;
12215+}
12216+
12217+/**
12218 * atomic64_add - add integer to atomic64 variable
12219 * @i: integer value to add
12220 * @v: pointer to type atomic64_t
12221@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12222 */
12223 static inline void atomic64_add(long i, atomic64_t *v)
12224 {
12225+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
12226+
12227+#ifdef CONFIG_PAX_REFCOUNT
12228+ "jno 0f\n"
12229+ LOCK_PREFIX "subq %1,%0\n"
12230+ "int $4\n0:\n"
12231+ _ASM_EXTABLE(0b, 0b)
12232+#endif
12233+
12234+ : "=m" (v->counter)
12235+ : "er" (i), "m" (v->counter));
12236+}
12237+
12238+/**
12239+ * atomic64_add_unchecked - add integer to atomic64 variable
12240+ * @i: integer value to add
12241+ * @v: pointer to type atomic64_unchecked_t
12242+ *
12243+ * Atomically adds @i to @v.
12244+ */
12245+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12246+{
12247 asm volatile(LOCK_PREFIX "addq %1,%0"
12248 : "=m" (v->counter)
12249 : "er" (i), "m" (v->counter));
12250@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12251 */
12252 static inline void atomic64_sub(long i, atomic64_t *v)
12253 {
12254- asm volatile(LOCK_PREFIX "subq %1,%0"
12255+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12256+
12257+#ifdef CONFIG_PAX_REFCOUNT
12258+ "jno 0f\n"
12259+ LOCK_PREFIX "addq %1,%0\n"
12260+ "int $4\n0:\n"
12261+ _ASM_EXTABLE(0b, 0b)
12262+#endif
12263+
12264+ : "=m" (v->counter)
12265+ : "er" (i), "m" (v->counter));
12266+}
12267+
12268+/**
12269+ * atomic64_sub_unchecked - subtract the atomic64 variable
12270+ * @i: integer value to subtract
12271+ * @v: pointer to type atomic64_unchecked_t
12272+ *
12273+ * Atomically subtracts @i from @v.
12274+ */
12275+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12276+{
12277+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12278 : "=m" (v->counter)
12279 : "er" (i), "m" (v->counter));
12280 }
12281@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12282 {
12283 unsigned char c;
12284
12285- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12286+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
12287+
12288+#ifdef CONFIG_PAX_REFCOUNT
12289+ "jno 0f\n"
12290+ LOCK_PREFIX "addq %2,%0\n"
12291+ "int $4\n0:\n"
12292+ _ASM_EXTABLE(0b, 0b)
12293+#endif
12294+
12295+ "sete %1\n"
12296 : "=m" (v->counter), "=qm" (c)
12297 : "er" (i), "m" (v->counter) : "memory");
12298 return c;
12299@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12300 */
12301 static inline void atomic64_inc(atomic64_t *v)
12302 {
12303+ asm volatile(LOCK_PREFIX "incq %0\n"
12304+
12305+#ifdef CONFIG_PAX_REFCOUNT
12306+ "jno 0f\n"
12307+ LOCK_PREFIX "decq %0\n"
12308+ "int $4\n0:\n"
12309+ _ASM_EXTABLE(0b, 0b)
12310+#endif
12311+
12312+ : "=m" (v->counter)
12313+ : "m" (v->counter));
12314+}
12315+
12316+/**
12317+ * atomic64_inc_unchecked - increment atomic64 variable
12318+ * @v: pointer to type atomic64_unchecked_t
12319+ *
12320+ * Atomically increments @v by 1.
12321+ */
12322+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12323+{
12324 asm volatile(LOCK_PREFIX "incq %0"
12325 : "=m" (v->counter)
12326 : "m" (v->counter));
12327@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12328 */
12329 static inline void atomic64_dec(atomic64_t *v)
12330 {
12331- asm volatile(LOCK_PREFIX "decq %0"
12332+ asm volatile(LOCK_PREFIX "decq %0\n"
12333+
12334+#ifdef CONFIG_PAX_REFCOUNT
12335+ "jno 0f\n"
12336+ LOCK_PREFIX "incq %0\n"
12337+ "int $4\n0:\n"
12338+ _ASM_EXTABLE(0b, 0b)
12339+#endif
12340+
12341+ : "=m" (v->counter)
12342+ : "m" (v->counter));
12343+}
12344+
12345+/**
12346+ * atomic64_dec_unchecked - decrement atomic64 variable
12347+ * @v: pointer to type atomic64_t
12348+ *
12349+ * Atomically decrements @v by 1.
12350+ */
12351+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12352+{
12353+ asm volatile(LOCK_PREFIX "decq %0\n"
12354 : "=m" (v->counter)
12355 : "m" (v->counter));
12356 }
12357@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12358 {
12359 unsigned char c;
12360
12361- asm volatile(LOCK_PREFIX "decq %0; sete %1"
12362+ asm volatile(LOCK_PREFIX "decq %0\n"
12363+
12364+#ifdef CONFIG_PAX_REFCOUNT
12365+ "jno 0f\n"
12366+ LOCK_PREFIX "incq %0\n"
12367+ "int $4\n0:\n"
12368+ _ASM_EXTABLE(0b, 0b)
12369+#endif
12370+
12371+ "sete %1\n"
12372 : "=m" (v->counter), "=qm" (c)
12373 : "m" (v->counter) : "memory");
12374 return c != 0;
12375@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12376 {
12377 unsigned char c;
12378
12379- asm volatile(LOCK_PREFIX "incq %0; sete %1"
12380+ asm volatile(LOCK_PREFIX "incq %0\n"
12381+
12382+#ifdef CONFIG_PAX_REFCOUNT
12383+ "jno 0f\n"
12384+ LOCK_PREFIX "decq %0\n"
12385+ "int $4\n0:\n"
12386+ _ASM_EXTABLE(0b, 0b)
12387+#endif
12388+
12389+ "sete %1\n"
12390 : "=m" (v->counter), "=qm" (c)
12391 : "m" (v->counter) : "memory");
12392 return c != 0;
12393@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12394 {
12395 unsigned char c;
12396
12397- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12398+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
12399+
12400+#ifdef CONFIG_PAX_REFCOUNT
12401+ "jno 0f\n"
12402+ LOCK_PREFIX "subq %2,%0\n"
12403+ "int $4\n0:\n"
12404+ _ASM_EXTABLE(0b, 0b)
12405+#endif
12406+
12407+ "sets %1\n"
12408 : "=m" (v->counter), "=qm" (c)
12409 : "er" (i), "m" (v->counter) : "memory");
12410 return c;
12411@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12412 */
12413 static inline long atomic64_add_return(long i, atomic64_t *v)
12414 {
12415+ return i + xadd_check_overflow(&v->counter, i);
12416+}
12417+
12418+/**
12419+ * atomic64_add_return_unchecked - add and return
12420+ * @i: integer value to add
12421+ * @v: pointer to type atomic64_unchecked_t
12422+ *
12423+ * Atomically adds @i to @v and returns @i + @v
12424+ */
12425+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12426+{
12427 return i + xadd(&v->counter, i);
12428 }
12429
12430@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12431 }
12432
12433 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12434+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12435+{
12436+ return atomic64_add_return_unchecked(1, v);
12437+}
12438 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12439
12440 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12441@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12442 return cmpxchg(&v->counter, old, new);
12443 }
12444
12445+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12446+{
12447+ return cmpxchg(&v->counter, old, new);
12448+}
12449+
12450 static inline long atomic64_xchg(atomic64_t *v, long new)
12451 {
12452 return xchg(&v->counter, new);
12453@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12454 */
12455 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12456 {
12457- long c, old;
12458+ long c, old, new;
12459 c = atomic64_read(v);
12460 for (;;) {
12461- if (unlikely(c == (u)))
12462+ if (unlikely(c == u))
12463 break;
12464- old = atomic64_cmpxchg((v), c, c + (a));
12465+
12466+ asm volatile("add %2,%0\n"
12467+
12468+#ifdef CONFIG_PAX_REFCOUNT
12469+ "jno 0f\n"
12470+ "sub %2,%0\n"
12471+ "int $4\n0:\n"
12472+ _ASM_EXTABLE(0b, 0b)
12473+#endif
12474+
12475+ : "=r" (new)
12476+ : "0" (c), "ir" (a));
12477+
12478+ old = atomic64_cmpxchg(v, c, new);
12479 if (likely(old == c))
12480 break;
12481 c = old;
12482 }
12483- return c != (u);
12484+ return c != u;
12485 }
12486
12487 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12488diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12489index 6dfd019..0c6699f 100644
12490--- a/arch/x86/include/asm/bitops.h
12491+++ b/arch/x86/include/asm/bitops.h
12492@@ -40,7 +40,7 @@
12493 * a mask operation on a byte.
12494 */
12495 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12496-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12497+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12498 #define CONST_MASK(nr) (1 << ((nr) & 7))
12499
12500 /**
12501diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12502index 4fa687a..60f2d39 100644
12503--- a/arch/x86/include/asm/boot.h
12504+++ b/arch/x86/include/asm/boot.h
12505@@ -6,10 +6,15 @@
12506 #include <uapi/asm/boot.h>
12507
12508 /* Physical address where kernel should be loaded. */
12509-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12510+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12511 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12512 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12513
12514+#ifndef __ASSEMBLY__
12515+extern unsigned char __LOAD_PHYSICAL_ADDR[];
12516+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12517+#endif
12518+
12519 /* Minimum kernel alignment, as a power of two */
12520 #ifdef CONFIG_X86_64
12521 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12522diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12523index 48f99f1..d78ebf9 100644
12524--- a/arch/x86/include/asm/cache.h
12525+++ b/arch/x86/include/asm/cache.h
12526@@ -5,12 +5,13 @@
12527
12528 /* L1 cache line size */
12529 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12530-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12531+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12532
12533 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12534+#define __read_only __attribute__((__section__(".data..read_only")))
12535
12536 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12537-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12538+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12539
12540 #ifdef CONFIG_X86_VSMP
12541 #ifdef CONFIG_SMP
12542diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12543index 9863ee3..4a1f8e1 100644
12544--- a/arch/x86/include/asm/cacheflush.h
12545+++ b/arch/x86/include/asm/cacheflush.h
12546@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12547 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12548
12549 if (pg_flags == _PGMT_DEFAULT)
12550- return -1;
12551+ return ~0UL;
12552 else if (pg_flags == _PGMT_WC)
12553 return _PAGE_CACHE_WC;
12554 else if (pg_flags == _PGMT_UC_MINUS)
12555diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
12556index 46fc474..b02b0f9 100644
12557--- a/arch/x86/include/asm/checksum_32.h
12558+++ b/arch/x86/include/asm/checksum_32.h
12559@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
12560 int len, __wsum sum,
12561 int *src_err_ptr, int *dst_err_ptr);
12562
12563+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
12564+ int len, __wsum sum,
12565+ int *src_err_ptr, int *dst_err_ptr);
12566+
12567+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
12568+ int len, __wsum sum,
12569+ int *src_err_ptr, int *dst_err_ptr);
12570+
12571 /*
12572 * Note: when you get a NULL pointer exception here this means someone
12573 * passed in an incorrect kernel address to one of these functions.
12574@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
12575 int *err_ptr)
12576 {
12577 might_sleep();
12578- return csum_partial_copy_generic((__force void *)src, dst,
12579+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
12580 len, sum, err_ptr, NULL);
12581 }
12582
12583@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
12584 {
12585 might_sleep();
12586 if (access_ok(VERIFY_WRITE, dst, len))
12587- return csum_partial_copy_generic(src, (__force void *)dst,
12588+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
12589 len, sum, NULL, err_ptr);
12590
12591 if (len)
12592diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
12593index 8d871ea..c1a0dc9 100644
12594--- a/arch/x86/include/asm/cmpxchg.h
12595+++ b/arch/x86/include/asm/cmpxchg.h
12596@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
12597 __compiletime_error("Bad argument size for cmpxchg");
12598 extern void __xadd_wrong_size(void)
12599 __compiletime_error("Bad argument size for xadd");
12600+extern void __xadd_check_overflow_wrong_size(void)
12601+ __compiletime_error("Bad argument size for xadd_check_overflow");
12602 extern void __add_wrong_size(void)
12603 __compiletime_error("Bad argument size for add");
12604+extern void __add_check_overflow_wrong_size(void)
12605+ __compiletime_error("Bad argument size for add_check_overflow");
12606
12607 /*
12608 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
12609@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
12610 __ret; \
12611 })
12612
12613+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
12614+ ({ \
12615+ __typeof__ (*(ptr)) __ret = (arg); \
12616+ switch (sizeof(*(ptr))) { \
12617+ case __X86_CASE_L: \
12618+ asm volatile (lock #op "l %0, %1\n" \
12619+ "jno 0f\n" \
12620+ "mov %0,%1\n" \
12621+ "int $4\n0:\n" \
12622+ _ASM_EXTABLE(0b, 0b) \
12623+ : "+r" (__ret), "+m" (*(ptr)) \
12624+ : : "memory", "cc"); \
12625+ break; \
12626+ case __X86_CASE_Q: \
12627+ asm volatile (lock #op "q %q0, %1\n" \
12628+ "jno 0f\n" \
12629+ "mov %0,%1\n" \
12630+ "int $4\n0:\n" \
12631+ _ASM_EXTABLE(0b, 0b) \
12632+ : "+r" (__ret), "+m" (*(ptr)) \
12633+ : : "memory", "cc"); \
12634+ break; \
12635+ default: \
12636+ __ ## op ## _check_overflow_wrong_size(); \
12637+ } \
12638+ __ret; \
12639+ })
12640+
12641 /*
12642 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
12643 * Since this is generally used to protect other memory information, we
12644@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
12645 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
12646 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
12647
12648+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
12649+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
12650+
12651 #define __add(ptr, inc, lock) \
12652 ({ \
12653 __typeof__ (*(ptr)) __ret = (inc); \
12654diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
12655index 2d9075e..b75a844 100644
12656--- a/arch/x86/include/asm/cpufeature.h
12657+++ b/arch/x86/include/asm/cpufeature.h
12658@@ -206,7 +206,7 @@
12659 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
12660 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
12661 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
12662-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
12663+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
12664 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
12665 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
12666 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
12667@@ -375,7 +375,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
12668 ".section .discard,\"aw\",@progbits\n"
12669 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
12670 ".previous\n"
12671- ".section .altinstr_replacement,\"ax\"\n"
12672+ ".section .altinstr_replacement,\"a\"\n"
12673 "3: movb $1,%0\n"
12674 "4:\n"
12675 ".previous\n"
12676diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
12677index 8bf1c06..f723dfd 100644
12678--- a/arch/x86/include/asm/desc.h
12679+++ b/arch/x86/include/asm/desc.h
12680@@ -4,6 +4,7 @@
12681 #include <asm/desc_defs.h>
12682 #include <asm/ldt.h>
12683 #include <asm/mmu.h>
12684+#include <asm/pgtable.h>
12685
12686 #include <linux/smp.h>
12687 #include <linux/percpu.h>
12688@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
12689
12690 desc->type = (info->read_exec_only ^ 1) << 1;
12691 desc->type |= info->contents << 2;
12692+ desc->type |= info->seg_not_present ^ 1;
12693
12694 desc->s = 1;
12695 desc->dpl = 0x3;
12696@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
12697 }
12698
12699 extern struct desc_ptr idt_descr;
12700-extern gate_desc idt_table[];
12701 extern struct desc_ptr nmi_idt_descr;
12702-extern gate_desc nmi_idt_table[];
12703-
12704-struct gdt_page {
12705- struct desc_struct gdt[GDT_ENTRIES];
12706-} __attribute__((aligned(PAGE_SIZE)));
12707-
12708-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
12709+extern gate_desc idt_table[256];
12710+extern gate_desc nmi_idt_table[256];
12711
12712+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
12713 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
12714 {
12715- return per_cpu(gdt_page, cpu).gdt;
12716+ return cpu_gdt_table[cpu];
12717 }
12718
12719 #ifdef CONFIG_X86_64
12720@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
12721 unsigned long base, unsigned dpl, unsigned flags,
12722 unsigned short seg)
12723 {
12724- gate->a = (seg << 16) | (base & 0xffff);
12725- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
12726+ gate->gate.offset_low = base;
12727+ gate->gate.seg = seg;
12728+ gate->gate.reserved = 0;
12729+ gate->gate.type = type;
12730+ gate->gate.s = 0;
12731+ gate->gate.dpl = dpl;
12732+ gate->gate.p = 1;
12733+ gate->gate.offset_high = base >> 16;
12734 }
12735
12736 #endif
12737@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
12738
12739 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
12740 {
12741+ pax_open_kernel();
12742 memcpy(&idt[entry], gate, sizeof(*gate));
12743+ pax_close_kernel();
12744 }
12745
12746 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
12747 {
12748+ pax_open_kernel();
12749 memcpy(&ldt[entry], desc, 8);
12750+ pax_close_kernel();
12751 }
12752
12753 static inline void
12754@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
12755 default: size = sizeof(*gdt); break;
12756 }
12757
12758+ pax_open_kernel();
12759 memcpy(&gdt[entry], desc, size);
12760+ pax_close_kernel();
12761 }
12762
12763 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
12764@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
12765
12766 static inline void native_load_tr_desc(void)
12767 {
12768+ pax_open_kernel();
12769 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
12770+ pax_close_kernel();
12771 }
12772
12773 static inline void native_load_gdt(const struct desc_ptr *dtr)
12774@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
12775 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
12776 unsigned int i;
12777
12778+ pax_open_kernel();
12779 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
12780 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
12781+ pax_close_kernel();
12782 }
12783
12784 #define _LDT_empty(info) \
12785@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
12786 }
12787
12788 #ifdef CONFIG_X86_64
12789-static inline void set_nmi_gate(int gate, void *addr)
12790+static inline void set_nmi_gate(int gate, const void *addr)
12791 {
12792 gate_desc s;
12793
12794@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
12795 }
12796 #endif
12797
12798-static inline void _set_gate(int gate, unsigned type, void *addr,
12799+static inline void _set_gate(int gate, unsigned type, const void *addr,
12800 unsigned dpl, unsigned ist, unsigned seg)
12801 {
12802 gate_desc s;
12803@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
12804 * Pentium F0 0F bugfix can have resulted in the mapped
12805 * IDT being write-protected.
12806 */
12807-static inline void set_intr_gate(unsigned int n, void *addr)
12808+static inline void set_intr_gate(unsigned int n, const void *addr)
12809 {
12810 BUG_ON((unsigned)n > 0xFF);
12811 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
12812@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
12813 /*
12814 * This routine sets up an interrupt gate at directory privilege level 3.
12815 */
12816-static inline void set_system_intr_gate(unsigned int n, void *addr)
12817+static inline void set_system_intr_gate(unsigned int n, const void *addr)
12818 {
12819 BUG_ON((unsigned)n > 0xFF);
12820 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
12821 }
12822
12823-static inline void set_system_trap_gate(unsigned int n, void *addr)
12824+static inline void set_system_trap_gate(unsigned int n, const void *addr)
12825 {
12826 BUG_ON((unsigned)n > 0xFF);
12827 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
12828 }
12829
12830-static inline void set_trap_gate(unsigned int n, void *addr)
12831+static inline void set_trap_gate(unsigned int n, const void *addr)
12832 {
12833 BUG_ON((unsigned)n > 0xFF);
12834 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
12835@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
12836 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
12837 {
12838 BUG_ON((unsigned)n > 0xFF);
12839- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
12840+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
12841 }
12842
12843-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
12844+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
12845 {
12846 BUG_ON((unsigned)n > 0xFF);
12847 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
12848 }
12849
12850-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
12851+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
12852 {
12853 BUG_ON((unsigned)n > 0xFF);
12854 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
12855 }
12856
12857+#ifdef CONFIG_X86_32
12858+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
12859+{
12860+ struct desc_struct d;
12861+
12862+ if (likely(limit))
12863+ limit = (limit - 1UL) >> PAGE_SHIFT;
12864+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
12865+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
12866+}
12867+#endif
12868+
12869 #endif /* _ASM_X86_DESC_H */
12870diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
12871index 278441f..b95a174 100644
12872--- a/arch/x86/include/asm/desc_defs.h
12873+++ b/arch/x86/include/asm/desc_defs.h
12874@@ -31,6 +31,12 @@ struct desc_struct {
12875 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
12876 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
12877 };
12878+ struct {
12879+ u16 offset_low;
12880+ u16 seg;
12881+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
12882+ unsigned offset_high: 16;
12883+ } gate;
12884 };
12885 } __attribute__((packed));
12886
12887diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
12888index 9c999c1..3860cb8 100644
12889--- a/arch/x86/include/asm/elf.h
12890+++ b/arch/x86/include/asm/elf.h
12891@@ -243,7 +243,25 @@ extern int force_personality32;
12892 the loader. We need to make sure that it is out of the way of the program
12893 that it will "exec", and that there is sufficient room for the brk. */
12894
12895+#ifdef CONFIG_PAX_SEGMEXEC
12896+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
12897+#else
12898 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
12899+#endif
12900+
12901+#ifdef CONFIG_PAX_ASLR
12902+#ifdef CONFIG_X86_32
12903+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
12904+
12905+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
12906+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
12907+#else
12908+#define PAX_ELF_ET_DYN_BASE 0x400000UL
12909+
12910+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
12911+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
12912+#endif
12913+#endif
12914
12915 /* This yields a mask that user programs can use to figure out what
12916 instruction set this CPU supports. This could be done in user space,
12917@@ -296,16 +314,12 @@ do { \
12918
12919 #define ARCH_DLINFO \
12920 do { \
12921- if (vdso_enabled) \
12922- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
12923- (unsigned long)current->mm->context.vdso); \
12924+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
12925 } while (0)
12926
12927 #define ARCH_DLINFO_X32 \
12928 do { \
12929- if (vdso_enabled) \
12930- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
12931- (unsigned long)current->mm->context.vdso); \
12932+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
12933 } while (0)
12934
12935 #define AT_SYSINFO 32
12936@@ -320,7 +334,7 @@ else \
12937
12938 #endif /* !CONFIG_X86_32 */
12939
12940-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
12941+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
12942
12943 #define VDSO_ENTRY \
12944 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
12945@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
12946 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
12947 #define compat_arch_setup_additional_pages syscall32_setup_pages
12948
12949-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
12950-#define arch_randomize_brk arch_randomize_brk
12951-
12952 /*
12953 * True on X86_32 or when emulating IA32 on X86_64
12954 */
12955diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
12956index 75ce3f4..882e801 100644
12957--- a/arch/x86/include/asm/emergency-restart.h
12958+++ b/arch/x86/include/asm/emergency-restart.h
12959@@ -13,6 +13,6 @@ enum reboot_type {
12960
12961 extern enum reboot_type reboot_type;
12962
12963-extern void machine_emergency_restart(void);
12964+extern void machine_emergency_restart(void) __noreturn;
12965
12966 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
12967diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
12968index 41ab26e..a88c9e6 100644
12969--- a/arch/x86/include/asm/fpu-internal.h
12970+++ b/arch/x86/include/asm/fpu-internal.h
12971@@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
12972 ({ \
12973 int err; \
12974 asm volatile(ASM_STAC "\n" \
12975- "1:" #insn "\n\t" \
12976+ "1:" \
12977+ __copyuser_seg \
12978+ #insn "\n\t" \
12979 "2: " ASM_CLAC "\n" \
12980 ".section .fixup,\"ax\"\n" \
12981 "3: movl $-1,%[err]\n" \
12982@@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
12983 "emms\n\t" /* clear stack tags */
12984 "fildl %P[addr]", /* set F?P to defined value */
12985 X86_FEATURE_FXSAVE_LEAK,
12986- [addr] "m" (tsk->thread.fpu.has_fpu));
12987+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
12988
12989 return fpu_restore_checking(&tsk->thread.fpu);
12990 }
12991diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
12992index be27ba1..8f13ff9 100644
12993--- a/arch/x86/include/asm/futex.h
12994+++ b/arch/x86/include/asm/futex.h
12995@@ -12,6 +12,7 @@
12996 #include <asm/smap.h>
12997
12998 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
12999+ typecheck(u32 __user *, uaddr); \
13000 asm volatile("\t" ASM_STAC "\n" \
13001 "1:\t" insn "\n" \
13002 "2:\t" ASM_CLAC "\n" \
13003@@ -20,15 +21,16 @@
13004 "\tjmp\t2b\n" \
13005 "\t.previous\n" \
13006 _ASM_EXTABLE(1b, 3b) \
13007- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13008+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13009 : "i" (-EFAULT), "0" (oparg), "1" (0))
13010
13011 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13012+ typecheck(u32 __user *, uaddr); \
13013 asm volatile("\t" ASM_STAC "\n" \
13014 "1:\tmovl %2, %0\n" \
13015 "\tmovl\t%0, %3\n" \
13016 "\t" insn "\n" \
13017- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13018+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13019 "\tjnz\t1b\n" \
13020 "3:\t" ASM_CLAC "\n" \
13021 "\t.section .fixup,\"ax\"\n" \
13022@@ -38,7 +40,7 @@
13023 _ASM_EXTABLE(1b, 4b) \
13024 _ASM_EXTABLE(2b, 4b) \
13025 : "=&a" (oldval), "=&r" (ret), \
13026- "+m" (*uaddr), "=&r" (tem) \
13027+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13028 : "r" (oparg), "i" (-EFAULT), "1" (0))
13029
13030 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13031@@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13032
13033 switch (op) {
13034 case FUTEX_OP_SET:
13035- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13036+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13037 break;
13038 case FUTEX_OP_ADD:
13039- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13040+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13041 uaddr, oparg);
13042 break;
13043 case FUTEX_OP_OR:
13044@@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13045 return -EFAULT;
13046
13047 asm volatile("\t" ASM_STAC "\n"
13048- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13049+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13050 "2:\t" ASM_CLAC "\n"
13051 "\t.section .fixup, \"ax\"\n"
13052 "3:\tmov %3, %0\n"
13053 "\tjmp 2b\n"
13054 "\t.previous\n"
13055 _ASM_EXTABLE(1b, 3b)
13056- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13057+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13058 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13059 : "memory"
13060 );
13061diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13062index eb92a6e..b98b2f4 100644
13063--- a/arch/x86/include/asm/hw_irq.h
13064+++ b/arch/x86/include/asm/hw_irq.h
13065@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
13066 extern void enable_IO_APIC(void);
13067
13068 /* Statistics */
13069-extern atomic_t irq_err_count;
13070-extern atomic_t irq_mis_count;
13071+extern atomic_unchecked_t irq_err_count;
13072+extern atomic_unchecked_t irq_mis_count;
13073
13074 /* EISA */
13075 extern void eisa_set_level_irq(unsigned int irq);
13076diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13077index d8e8eef..15b1179 100644
13078--- a/arch/x86/include/asm/io.h
13079+++ b/arch/x86/include/asm/io.h
13080@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13081 return ioremap_nocache(offset, size);
13082 }
13083
13084-extern void iounmap(volatile void __iomem *addr);
13085+extern void iounmap(const volatile void __iomem *addr);
13086
13087 extern void set_iounmap_nonlazy(void);
13088
13089@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13090
13091 #include <linux/vmalloc.h>
13092
13093+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13094+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13095+{
13096+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13097+}
13098+
13099+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13100+{
13101+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13102+}
13103+
13104 /*
13105 * Convert a virtual cached pointer to an uncached pointer
13106 */
13107diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13108index bba3cf8..06bc8da 100644
13109--- a/arch/x86/include/asm/irqflags.h
13110+++ b/arch/x86/include/asm/irqflags.h
13111@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13112 sti; \
13113 sysexit
13114
13115+#define GET_CR0_INTO_RDI mov %cr0, %rdi
13116+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13117+#define GET_CR3_INTO_RDI mov %cr3, %rdi
13118+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13119+
13120 #else
13121 #define INTERRUPT_RETURN iret
13122 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13123diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13124index d3ddd17..c9fb0cc 100644
13125--- a/arch/x86/include/asm/kprobes.h
13126+++ b/arch/x86/include/asm/kprobes.h
13127@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13128 #define RELATIVEJUMP_SIZE 5
13129 #define RELATIVECALL_OPCODE 0xe8
13130 #define RELATIVE_ADDR_SIZE 4
13131-#define MAX_STACK_SIZE 64
13132-#define MIN_STACK_SIZE(ADDR) \
13133- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13134- THREAD_SIZE - (unsigned long)(ADDR))) \
13135- ? (MAX_STACK_SIZE) \
13136- : (((unsigned long)current_thread_info()) + \
13137- THREAD_SIZE - (unsigned long)(ADDR)))
13138+#define MAX_STACK_SIZE 64UL
13139+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13140
13141 #define flush_insn_slot(p) do { } while (0)
13142
13143diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13144index 2d89e39..baee879 100644
13145--- a/arch/x86/include/asm/local.h
13146+++ b/arch/x86/include/asm/local.h
13147@@ -10,33 +10,97 @@ typedef struct {
13148 atomic_long_t a;
13149 } local_t;
13150
13151+typedef struct {
13152+ atomic_long_unchecked_t a;
13153+} local_unchecked_t;
13154+
13155 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13156
13157 #define local_read(l) atomic_long_read(&(l)->a)
13158+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13159 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13160+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13161
13162 static inline void local_inc(local_t *l)
13163 {
13164- asm volatile(_ASM_INC "%0"
13165+ asm volatile(_ASM_INC "%0\n"
13166+
13167+#ifdef CONFIG_PAX_REFCOUNT
13168+ "jno 0f\n"
13169+ _ASM_DEC "%0\n"
13170+ "int $4\n0:\n"
13171+ _ASM_EXTABLE(0b, 0b)
13172+#endif
13173+
13174+ : "+m" (l->a.counter));
13175+}
13176+
13177+static inline void local_inc_unchecked(local_unchecked_t *l)
13178+{
13179+ asm volatile(_ASM_INC "%0\n"
13180 : "+m" (l->a.counter));
13181 }
13182
13183 static inline void local_dec(local_t *l)
13184 {
13185- asm volatile(_ASM_DEC "%0"
13186+ asm volatile(_ASM_DEC "%0\n"
13187+
13188+#ifdef CONFIG_PAX_REFCOUNT
13189+ "jno 0f\n"
13190+ _ASM_INC "%0\n"
13191+ "int $4\n0:\n"
13192+ _ASM_EXTABLE(0b, 0b)
13193+#endif
13194+
13195+ : "+m" (l->a.counter));
13196+}
13197+
13198+static inline void local_dec_unchecked(local_unchecked_t *l)
13199+{
13200+ asm volatile(_ASM_DEC "%0\n"
13201 : "+m" (l->a.counter));
13202 }
13203
13204 static inline void local_add(long i, local_t *l)
13205 {
13206- asm volatile(_ASM_ADD "%1,%0"
13207+ asm volatile(_ASM_ADD "%1,%0\n"
13208+
13209+#ifdef CONFIG_PAX_REFCOUNT
13210+ "jno 0f\n"
13211+ _ASM_SUB "%1,%0\n"
13212+ "int $4\n0:\n"
13213+ _ASM_EXTABLE(0b, 0b)
13214+#endif
13215+
13216+ : "+m" (l->a.counter)
13217+ : "ir" (i));
13218+}
13219+
13220+static inline void local_add_unchecked(long i, local_unchecked_t *l)
13221+{
13222+ asm volatile(_ASM_ADD "%1,%0\n"
13223 : "+m" (l->a.counter)
13224 : "ir" (i));
13225 }
13226
13227 static inline void local_sub(long i, local_t *l)
13228 {
13229- asm volatile(_ASM_SUB "%1,%0"
13230+ asm volatile(_ASM_SUB "%1,%0\n"
13231+
13232+#ifdef CONFIG_PAX_REFCOUNT
13233+ "jno 0f\n"
13234+ _ASM_ADD "%1,%0\n"
13235+ "int $4\n0:\n"
13236+ _ASM_EXTABLE(0b, 0b)
13237+#endif
13238+
13239+ : "+m" (l->a.counter)
13240+ : "ir" (i));
13241+}
13242+
13243+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13244+{
13245+ asm volatile(_ASM_SUB "%1,%0\n"
13246 : "+m" (l->a.counter)
13247 : "ir" (i));
13248 }
13249@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13250 {
13251 unsigned char c;
13252
13253- asm volatile(_ASM_SUB "%2,%0; sete %1"
13254+ asm volatile(_ASM_SUB "%2,%0\n"
13255+
13256+#ifdef CONFIG_PAX_REFCOUNT
13257+ "jno 0f\n"
13258+ _ASM_ADD "%2,%0\n"
13259+ "int $4\n0:\n"
13260+ _ASM_EXTABLE(0b, 0b)
13261+#endif
13262+
13263+ "sete %1\n"
13264 : "+m" (l->a.counter), "=qm" (c)
13265 : "ir" (i) : "memory");
13266 return c;
13267@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13268 {
13269 unsigned char c;
13270
13271- asm volatile(_ASM_DEC "%0; sete %1"
13272+ asm volatile(_ASM_DEC "%0\n"
13273+
13274+#ifdef CONFIG_PAX_REFCOUNT
13275+ "jno 0f\n"
13276+ _ASM_INC "%0\n"
13277+ "int $4\n0:\n"
13278+ _ASM_EXTABLE(0b, 0b)
13279+#endif
13280+
13281+ "sete %1\n"
13282 : "+m" (l->a.counter), "=qm" (c)
13283 : : "memory");
13284 return c != 0;
13285@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13286 {
13287 unsigned char c;
13288
13289- asm volatile(_ASM_INC "%0; sete %1"
13290+ asm volatile(_ASM_INC "%0\n"
13291+
13292+#ifdef CONFIG_PAX_REFCOUNT
13293+ "jno 0f\n"
13294+ _ASM_DEC "%0\n"
13295+ "int $4\n0:\n"
13296+ _ASM_EXTABLE(0b, 0b)
13297+#endif
13298+
13299+ "sete %1\n"
13300 : "+m" (l->a.counter), "=qm" (c)
13301 : : "memory");
13302 return c != 0;
13303@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13304 {
13305 unsigned char c;
13306
13307- asm volatile(_ASM_ADD "%2,%0; sets %1"
13308+ asm volatile(_ASM_ADD "%2,%0\n"
13309+
13310+#ifdef CONFIG_PAX_REFCOUNT
13311+ "jno 0f\n"
13312+ _ASM_SUB "%2,%0\n"
13313+ "int $4\n0:\n"
13314+ _ASM_EXTABLE(0b, 0b)
13315+#endif
13316+
13317+ "sets %1\n"
13318 : "+m" (l->a.counter), "=qm" (c)
13319 : "ir" (i) : "memory");
13320 return c;
13321@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13322 static inline long local_add_return(long i, local_t *l)
13323 {
13324 long __i = i;
13325+ asm volatile(_ASM_XADD "%0, %1\n"
13326+
13327+#ifdef CONFIG_PAX_REFCOUNT
13328+ "jno 0f\n"
13329+ _ASM_MOV "%0,%1\n"
13330+ "int $4\n0:\n"
13331+ _ASM_EXTABLE(0b, 0b)
13332+#endif
13333+
13334+ : "+r" (i), "+m" (l->a.counter)
13335+ : : "memory");
13336+ return i + __i;
13337+}
13338+
13339+/**
13340+ * local_add_return_unchecked - add and return
13341+ * @i: integer value to add
13342+ * @l: pointer to type local_unchecked_t
13343+ *
13344+ * Atomically adds @i to @l and returns @i + @l
13345+ */
13346+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13347+{
13348+ long __i = i;
13349 asm volatile(_ASM_XADD "%0, %1;"
13350 : "+r" (i), "+m" (l->a.counter)
13351 : : "memory");
13352@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13353
13354 #define local_cmpxchg(l, o, n) \
13355 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13356+#define local_cmpxchg_unchecked(l, o, n) \
13357+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
13358 /* Always has a lock prefix */
13359 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13360
13361diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13362new file mode 100644
13363index 0000000..2bfd3ba
13364--- /dev/null
13365+++ b/arch/x86/include/asm/mman.h
13366@@ -0,0 +1,15 @@
13367+#ifndef _X86_MMAN_H
13368+#define _X86_MMAN_H
13369+
13370+#include <uapi/asm/mman.h>
13371+
13372+#ifdef __KERNEL__
13373+#ifndef __ASSEMBLY__
13374+#ifdef CONFIG_X86_32
13375+#define arch_mmap_check i386_mmap_check
13376+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13377+#endif
13378+#endif
13379+#endif
13380+
13381+#endif /* X86_MMAN_H */
13382diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13383index 5f55e69..e20bfb1 100644
13384--- a/arch/x86/include/asm/mmu.h
13385+++ b/arch/x86/include/asm/mmu.h
13386@@ -9,7 +9,7 @@
13387 * we put the segment information here.
13388 */
13389 typedef struct {
13390- void *ldt;
13391+ struct desc_struct *ldt;
13392 int size;
13393
13394 #ifdef CONFIG_X86_64
13395@@ -18,7 +18,19 @@ typedef struct {
13396 #endif
13397
13398 struct mutex lock;
13399- void *vdso;
13400+ unsigned long vdso;
13401+
13402+#ifdef CONFIG_X86_32
13403+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13404+ unsigned long user_cs_base;
13405+ unsigned long user_cs_limit;
13406+
13407+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13408+ cpumask_t cpu_user_cs_mask;
13409+#endif
13410+
13411+#endif
13412+#endif
13413 } mm_context_t;
13414
13415 #ifdef CONFIG_SMP
13416diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13417index cdbf367..adb37ac 100644
13418--- a/arch/x86/include/asm/mmu_context.h
13419+++ b/arch/x86/include/asm/mmu_context.h
13420@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13421
13422 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13423 {
13424+
13425+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13426+ unsigned int i;
13427+ pgd_t *pgd;
13428+
13429+ pax_open_kernel();
13430+ pgd = get_cpu_pgd(smp_processor_id());
13431+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13432+ set_pgd_batched(pgd+i, native_make_pgd(0));
13433+ pax_close_kernel();
13434+#endif
13435+
13436 #ifdef CONFIG_SMP
13437 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13438 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13439@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13440 struct task_struct *tsk)
13441 {
13442 unsigned cpu = smp_processor_id();
13443+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13444+ int tlbstate = TLBSTATE_OK;
13445+#endif
13446
13447 if (likely(prev != next)) {
13448 #ifdef CONFIG_SMP
13449+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13450+ tlbstate = this_cpu_read(cpu_tlbstate.state);
13451+#endif
13452 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13453 this_cpu_write(cpu_tlbstate.active_mm, next);
13454 #endif
13455 cpumask_set_cpu(cpu, mm_cpumask(next));
13456
13457 /* Re-load page tables */
13458+#ifdef CONFIG_PAX_PER_CPU_PGD
13459+ pax_open_kernel();
13460+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13461+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13462+ pax_close_kernel();
13463+ load_cr3(get_cpu_pgd(cpu));
13464+#else
13465 load_cr3(next->pgd);
13466+#endif
13467
13468 /* stop flush ipis for the previous mm */
13469 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13470@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13471 */
13472 if (unlikely(prev->context.ldt != next->context.ldt))
13473 load_LDT_nolock(&next->context);
13474- }
13475+
13476+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13477+ if (!(__supported_pte_mask & _PAGE_NX)) {
13478+ smp_mb__before_clear_bit();
13479+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13480+ smp_mb__after_clear_bit();
13481+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13482+ }
13483+#endif
13484+
13485+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13486+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13487+ prev->context.user_cs_limit != next->context.user_cs_limit))
13488+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13489 #ifdef CONFIG_SMP
13490+ else if (unlikely(tlbstate != TLBSTATE_OK))
13491+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13492+#endif
13493+#endif
13494+
13495+ }
13496 else {
13497+
13498+#ifdef CONFIG_PAX_PER_CPU_PGD
13499+ pax_open_kernel();
13500+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13501+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13502+ pax_close_kernel();
13503+ load_cr3(get_cpu_pgd(cpu));
13504+#endif
13505+
13506+#ifdef CONFIG_SMP
13507 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13508 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
13509
13510@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13511 * tlb flush IPI delivery. We must reload CR3
13512 * to make sure to use no freed page tables.
13513 */
13514+
13515+#ifndef CONFIG_PAX_PER_CPU_PGD
13516 load_cr3(next->pgd);
13517+#endif
13518+
13519 load_LDT_nolock(&next->context);
13520+
13521+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
13522+ if (!(__supported_pte_mask & _PAGE_NX))
13523+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13524+#endif
13525+
13526+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13527+#ifdef CONFIG_PAX_PAGEEXEC
13528+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
13529+#endif
13530+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13531+#endif
13532+
13533 }
13534+#endif
13535 }
13536-#endif
13537 }
13538
13539 #define activate_mm(prev, next) \
13540diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
13541index e3b7819..b257c64 100644
13542--- a/arch/x86/include/asm/module.h
13543+++ b/arch/x86/include/asm/module.h
13544@@ -5,6 +5,7 @@
13545
13546 #ifdef CONFIG_X86_64
13547 /* X86_64 does not define MODULE_PROC_FAMILY */
13548+#define MODULE_PROC_FAMILY ""
13549 #elif defined CONFIG_M486
13550 #define MODULE_PROC_FAMILY "486 "
13551 #elif defined CONFIG_M586
13552@@ -57,8 +58,20 @@
13553 #error unknown processor family
13554 #endif
13555
13556-#ifdef CONFIG_X86_32
13557-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
13558+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13559+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
13560+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
13561+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
13562+#else
13563+#define MODULE_PAX_KERNEXEC ""
13564 #endif
13565
13566+#ifdef CONFIG_PAX_MEMORY_UDEREF
13567+#define MODULE_PAX_UDEREF "UDEREF "
13568+#else
13569+#define MODULE_PAX_UDEREF ""
13570+#endif
13571+
13572+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
13573+
13574 #endif /* _ASM_X86_MODULE_H */
13575diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
13576index 320f7bb..e89f8f8 100644
13577--- a/arch/x86/include/asm/page_64_types.h
13578+++ b/arch/x86/include/asm/page_64_types.h
13579@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
13580
13581 /* duplicated to the one in bootmem.h */
13582 extern unsigned long max_pfn;
13583-extern unsigned long phys_base;
13584+extern const unsigned long phys_base;
13585
13586 extern unsigned long __phys_addr(unsigned long);
13587 #define __phys_reloc_hide(x) (x)
13588diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
13589index 5edd174..9cf5821 100644
13590--- a/arch/x86/include/asm/paravirt.h
13591+++ b/arch/x86/include/asm/paravirt.h
13592@@ -630,6 +630,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
13593 val);
13594 }
13595
13596+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
13597+{
13598+ pgdval_t val = native_pgd_val(pgd);
13599+
13600+ if (sizeof(pgdval_t) > sizeof(long))
13601+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
13602+ val, (u64)val >> 32);
13603+ else
13604+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
13605+ val);
13606+}
13607+
13608 static inline void pgd_clear(pgd_t *pgdp)
13609 {
13610 set_pgd(pgdp, __pgd(0));
13611@@ -711,6 +723,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
13612 pv_mmu_ops.set_fixmap(idx, phys, flags);
13613 }
13614
13615+#ifdef CONFIG_PAX_KERNEXEC
13616+static inline unsigned long pax_open_kernel(void)
13617+{
13618+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
13619+}
13620+
13621+static inline unsigned long pax_close_kernel(void)
13622+{
13623+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
13624+}
13625+#else
13626+static inline unsigned long pax_open_kernel(void) { return 0; }
13627+static inline unsigned long pax_close_kernel(void) { return 0; }
13628+#endif
13629+
13630 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
13631
13632 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
13633@@ -927,7 +954,7 @@ extern void default_banner(void);
13634
13635 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
13636 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
13637-#define PARA_INDIRECT(addr) *%cs:addr
13638+#define PARA_INDIRECT(addr) *%ss:addr
13639 #endif
13640
13641 #define INTERRUPT_RETURN \
13642@@ -1002,6 +1029,21 @@ extern void default_banner(void);
13643 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
13644 CLBR_NONE, \
13645 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
13646+
13647+#define GET_CR0_INTO_RDI \
13648+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
13649+ mov %rax,%rdi
13650+
13651+#define SET_RDI_INTO_CR0 \
13652+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
13653+
13654+#define GET_CR3_INTO_RDI \
13655+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
13656+ mov %rax,%rdi
13657+
13658+#define SET_RDI_INTO_CR3 \
13659+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
13660+
13661 #endif /* CONFIG_X86_32 */
13662
13663 #endif /* __ASSEMBLY__ */
13664diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
13665index 142236e..5446ffbc 100644
13666--- a/arch/x86/include/asm/paravirt_types.h
13667+++ b/arch/x86/include/asm/paravirt_types.h
13668@@ -84,7 +84,7 @@ struct pv_init_ops {
13669 */
13670 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
13671 unsigned long addr, unsigned len);
13672-};
13673+} __no_const;
13674
13675
13676 struct pv_lazy_ops {
13677@@ -97,7 +97,7 @@ struct pv_time_ops {
13678 unsigned long long (*sched_clock)(void);
13679 unsigned long long (*steal_clock)(int cpu);
13680 unsigned long (*get_tsc_khz)(void);
13681-};
13682+} __no_const;
13683
13684 struct pv_cpu_ops {
13685 /* hooks for various privileged instructions */
13686@@ -191,7 +191,7 @@ struct pv_cpu_ops {
13687
13688 void (*start_context_switch)(struct task_struct *prev);
13689 void (*end_context_switch)(struct task_struct *next);
13690-};
13691+} __no_const;
13692
13693 struct pv_irq_ops {
13694 /*
13695@@ -222,7 +222,7 @@ struct pv_apic_ops {
13696 unsigned long start_eip,
13697 unsigned long start_esp);
13698 #endif
13699-};
13700+} __no_const;
13701
13702 struct pv_mmu_ops {
13703 unsigned long (*read_cr2)(void);
13704@@ -312,6 +312,7 @@ struct pv_mmu_ops {
13705 struct paravirt_callee_save make_pud;
13706
13707 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
13708+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
13709 #endif /* PAGETABLE_LEVELS == 4 */
13710 #endif /* PAGETABLE_LEVELS >= 3 */
13711
13712@@ -323,6 +324,12 @@ struct pv_mmu_ops {
13713 an mfn. We can tell which is which from the index. */
13714 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
13715 phys_addr_t phys, pgprot_t flags);
13716+
13717+#ifdef CONFIG_PAX_KERNEXEC
13718+ unsigned long (*pax_open_kernel)(void);
13719+ unsigned long (*pax_close_kernel)(void);
13720+#endif
13721+
13722 };
13723
13724 struct arch_spinlock;
13725@@ -333,7 +340,7 @@ struct pv_lock_ops {
13726 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
13727 int (*spin_trylock)(struct arch_spinlock *lock);
13728 void (*spin_unlock)(struct arch_spinlock *lock);
13729-};
13730+} __no_const;
13731
13732 /* This contains all the paravirt structures: we get a convenient
13733 * number for each function using the offset which we use to indicate
13734diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
13735index b4389a4..7024269 100644
13736--- a/arch/x86/include/asm/pgalloc.h
13737+++ b/arch/x86/include/asm/pgalloc.h
13738@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
13739 pmd_t *pmd, pte_t *pte)
13740 {
13741 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
13742+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
13743+}
13744+
13745+static inline void pmd_populate_user(struct mm_struct *mm,
13746+ pmd_t *pmd, pte_t *pte)
13747+{
13748+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
13749 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
13750 }
13751
13752@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
13753
13754 #ifdef CONFIG_X86_PAE
13755 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
13756+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
13757+{
13758+ pud_populate(mm, pudp, pmd);
13759+}
13760 #else /* !CONFIG_X86_PAE */
13761 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
13762 {
13763 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
13764 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
13765 }
13766+
13767+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
13768+{
13769+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
13770+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
13771+}
13772 #endif /* CONFIG_X86_PAE */
13773
13774 #if PAGETABLE_LEVELS > 3
13775@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
13776 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
13777 }
13778
13779+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
13780+{
13781+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
13782+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
13783+}
13784+
13785 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
13786 {
13787 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
13788diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
13789index f2b489c..4f7e2e5 100644
13790--- a/arch/x86/include/asm/pgtable-2level.h
13791+++ b/arch/x86/include/asm/pgtable-2level.h
13792@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
13793
13794 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
13795 {
13796+ pax_open_kernel();
13797 *pmdp = pmd;
13798+ pax_close_kernel();
13799 }
13800
13801 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
13802diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
13803index 4cc9f2b..5fd9226 100644
13804--- a/arch/x86/include/asm/pgtable-3level.h
13805+++ b/arch/x86/include/asm/pgtable-3level.h
13806@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
13807
13808 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
13809 {
13810+ pax_open_kernel();
13811 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
13812+ pax_close_kernel();
13813 }
13814
13815 static inline void native_set_pud(pud_t *pudp, pud_t pud)
13816 {
13817+ pax_open_kernel();
13818 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
13819+ pax_close_kernel();
13820 }
13821
13822 /*
13823diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
13824index 1c1a955..50f828c 100644
13825--- a/arch/x86/include/asm/pgtable.h
13826+++ b/arch/x86/include/asm/pgtable.h
13827@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
13828
13829 #ifndef __PAGETABLE_PUD_FOLDED
13830 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
13831+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
13832 #define pgd_clear(pgd) native_pgd_clear(pgd)
13833 #endif
13834
13835@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
13836
13837 #define arch_end_context_switch(prev) do {} while(0)
13838
13839+#define pax_open_kernel() native_pax_open_kernel()
13840+#define pax_close_kernel() native_pax_close_kernel()
13841 #endif /* CONFIG_PARAVIRT */
13842
13843+#define __HAVE_ARCH_PAX_OPEN_KERNEL
13844+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
13845+
13846+#ifdef CONFIG_PAX_KERNEXEC
13847+static inline unsigned long native_pax_open_kernel(void)
13848+{
13849+ unsigned long cr0;
13850+
13851+ preempt_disable();
13852+ barrier();
13853+ cr0 = read_cr0() ^ X86_CR0_WP;
13854+ BUG_ON(cr0 & X86_CR0_WP);
13855+ write_cr0(cr0);
13856+ return cr0 ^ X86_CR0_WP;
13857+}
13858+
13859+static inline unsigned long native_pax_close_kernel(void)
13860+{
13861+ unsigned long cr0;
13862+
13863+ cr0 = read_cr0() ^ X86_CR0_WP;
13864+ BUG_ON(!(cr0 & X86_CR0_WP));
13865+ write_cr0(cr0);
13866+ barrier();
13867+ preempt_enable_no_resched();
13868+ return cr0 ^ X86_CR0_WP;
13869+}
13870+#else
13871+static inline unsigned long native_pax_open_kernel(void) { return 0; }
13872+static inline unsigned long native_pax_close_kernel(void) { return 0; }
13873+#endif
13874+
13875 /*
13876 * The following only work if pte_present() is true.
13877 * Undefined behaviour if not..
13878 */
13879+static inline int pte_user(pte_t pte)
13880+{
13881+ return pte_val(pte) & _PAGE_USER;
13882+}
13883+
13884 static inline int pte_dirty(pte_t pte)
13885 {
13886 return pte_flags(pte) & _PAGE_DIRTY;
13887@@ -200,9 +240,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
13888 return pte_clear_flags(pte, _PAGE_RW);
13889 }
13890
13891+static inline pte_t pte_mkread(pte_t pte)
13892+{
13893+ return __pte(pte_val(pte) | _PAGE_USER);
13894+}
13895+
13896 static inline pte_t pte_mkexec(pte_t pte)
13897 {
13898- return pte_clear_flags(pte, _PAGE_NX);
13899+#ifdef CONFIG_X86_PAE
13900+ if (__supported_pte_mask & _PAGE_NX)
13901+ return pte_clear_flags(pte, _PAGE_NX);
13902+ else
13903+#endif
13904+ return pte_set_flags(pte, _PAGE_USER);
13905+}
13906+
13907+static inline pte_t pte_exprotect(pte_t pte)
13908+{
13909+#ifdef CONFIG_X86_PAE
13910+ if (__supported_pte_mask & _PAGE_NX)
13911+ return pte_set_flags(pte, _PAGE_NX);
13912+ else
13913+#endif
13914+ return pte_clear_flags(pte, _PAGE_USER);
13915 }
13916
13917 static inline pte_t pte_mkdirty(pte_t pte)
13918@@ -394,6 +454,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
13919 #endif
13920
13921 #ifndef __ASSEMBLY__
13922+
13923+#ifdef CONFIG_PAX_PER_CPU_PGD
13924+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
13925+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
13926+{
13927+ return cpu_pgd[cpu];
13928+}
13929+#endif
13930+
13931 #include <linux/mm_types.h>
13932
13933 static inline int pte_none(pte_t pte)
13934@@ -583,7 +652,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
13935
13936 static inline int pgd_bad(pgd_t pgd)
13937 {
13938- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
13939+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
13940 }
13941
13942 static inline int pgd_none(pgd_t pgd)
13943@@ -606,7 +675,12 @@ static inline int pgd_none(pgd_t pgd)
13944 * pgd_offset() returns a (pgd_t *)
13945 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
13946 */
13947-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
13948+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
13949+
13950+#ifdef CONFIG_PAX_PER_CPU_PGD
13951+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
13952+#endif
13953+
13954 /*
13955 * a shortcut which implies the use of the kernel's pgd, instead
13956 * of a process's
13957@@ -617,6 +691,20 @@ static inline int pgd_none(pgd_t pgd)
13958 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
13959 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
13960
13961+#ifdef CONFIG_X86_32
13962+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
13963+#else
13964+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
13965+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
13966+
13967+#ifdef CONFIG_PAX_MEMORY_UDEREF
13968+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
13969+#else
13970+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
13971+#endif
13972+
13973+#endif
13974+
13975 #ifndef __ASSEMBLY__
13976
13977 extern int direct_gbpages;
13978@@ -781,11 +869,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
13979 * dst and src can be on the same page, but the range must not overlap,
13980 * and must not cross a page boundary.
13981 */
13982-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
13983+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
13984 {
13985- memcpy(dst, src, count * sizeof(pgd_t));
13986+ pax_open_kernel();
13987+ while (count--)
13988+ *dst++ = *src++;
13989+ pax_close_kernel();
13990 }
13991
13992+#ifdef CONFIG_PAX_PER_CPU_PGD
13993+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
13994+#endif
13995+
13996+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13997+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
13998+#else
13999+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14000+#endif
14001
14002 #include <asm-generic/pgtable.h>
14003 #endif /* __ASSEMBLY__ */
14004diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14005index 8faa215..a8a17ea 100644
14006--- a/arch/x86/include/asm/pgtable_32.h
14007+++ b/arch/x86/include/asm/pgtable_32.h
14008@@ -25,9 +25,6 @@
14009 struct mm_struct;
14010 struct vm_area_struct;
14011
14012-extern pgd_t swapper_pg_dir[1024];
14013-extern pgd_t initial_page_table[1024];
14014-
14015 static inline void pgtable_cache_init(void) { }
14016 static inline void check_pgt_cache(void) { }
14017 void paging_init(void);
14018@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14019 # include <asm/pgtable-2level.h>
14020 #endif
14021
14022+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14023+extern pgd_t initial_page_table[PTRS_PER_PGD];
14024+#ifdef CONFIG_X86_PAE
14025+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14026+#endif
14027+
14028 #if defined(CONFIG_HIGHPTE)
14029 #define pte_offset_map(dir, address) \
14030 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14031@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14032 /* Clear a kernel PTE and flush it from the TLB */
14033 #define kpte_clear_flush(ptep, vaddr) \
14034 do { \
14035+ pax_open_kernel(); \
14036 pte_clear(&init_mm, (vaddr), (ptep)); \
14037+ pax_close_kernel(); \
14038 __flush_tlb_one((vaddr)); \
14039 } while (0)
14040
14041@@ -75,6 +80,9 @@ do { \
14042
14043 #endif /* !__ASSEMBLY__ */
14044
14045+#define HAVE_ARCH_UNMAPPED_AREA
14046+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14047+
14048 /*
14049 * kern_addr_valid() is (1) for FLATMEM and (0) for
14050 * SPARSEMEM and DISCONTIGMEM
14051diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14052index ed5903b..c7fe163 100644
14053--- a/arch/x86/include/asm/pgtable_32_types.h
14054+++ b/arch/x86/include/asm/pgtable_32_types.h
14055@@ -8,7 +8,7 @@
14056 */
14057 #ifdef CONFIG_X86_PAE
14058 # include <asm/pgtable-3level_types.h>
14059-# define PMD_SIZE (1UL << PMD_SHIFT)
14060+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14061 # define PMD_MASK (~(PMD_SIZE - 1))
14062 #else
14063 # include <asm/pgtable-2level_types.h>
14064@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14065 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14066 #endif
14067
14068+#ifdef CONFIG_PAX_KERNEXEC
14069+#ifndef __ASSEMBLY__
14070+extern unsigned char MODULES_EXEC_VADDR[];
14071+extern unsigned char MODULES_EXEC_END[];
14072+#endif
14073+#include <asm/boot.h>
14074+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14075+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14076+#else
14077+#define ktla_ktva(addr) (addr)
14078+#define ktva_ktla(addr) (addr)
14079+#endif
14080+
14081 #define MODULES_VADDR VMALLOC_START
14082 #define MODULES_END VMALLOC_END
14083 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14084diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14085index 47356f9..deb94a2 100644
14086--- a/arch/x86/include/asm/pgtable_64.h
14087+++ b/arch/x86/include/asm/pgtable_64.h
14088@@ -16,10 +16,14 @@
14089
14090 extern pud_t level3_kernel_pgt[512];
14091 extern pud_t level3_ident_pgt[512];
14092+extern pud_t level3_vmalloc_start_pgt[512];
14093+extern pud_t level3_vmalloc_end_pgt[512];
14094+extern pud_t level3_vmemmap_pgt[512];
14095+extern pud_t level2_vmemmap_pgt[512];
14096 extern pmd_t level2_kernel_pgt[512];
14097 extern pmd_t level2_fixmap_pgt[512];
14098-extern pmd_t level2_ident_pgt[512];
14099-extern pgd_t init_level4_pgt[];
14100+extern pmd_t level2_ident_pgt[512*2];
14101+extern pgd_t init_level4_pgt[512];
14102
14103 #define swapper_pg_dir init_level4_pgt
14104
14105@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14106
14107 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14108 {
14109+ pax_open_kernel();
14110 *pmdp = pmd;
14111+ pax_close_kernel();
14112 }
14113
14114 static inline void native_pmd_clear(pmd_t *pmd)
14115@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14116
14117 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14118 {
14119+ pax_open_kernel();
14120 *pudp = pud;
14121+ pax_close_kernel();
14122 }
14123
14124 static inline void native_pud_clear(pud_t *pud)
14125@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14126
14127 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14128 {
14129+ pax_open_kernel();
14130+ *pgdp = pgd;
14131+ pax_close_kernel();
14132+}
14133+
14134+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14135+{
14136 *pgdp = pgd;
14137 }
14138
14139diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14140index 766ea16..5b96cb3 100644
14141--- a/arch/x86/include/asm/pgtable_64_types.h
14142+++ b/arch/x86/include/asm/pgtable_64_types.h
14143@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
14144 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14145 #define MODULES_END _AC(0xffffffffff000000, UL)
14146 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14147+#define MODULES_EXEC_VADDR MODULES_VADDR
14148+#define MODULES_EXEC_END MODULES_END
14149+
14150+#define ktla_ktva(addr) (addr)
14151+#define ktva_ktla(addr) (addr)
14152
14153 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
14154diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14155index 3c32db8..1ddccf5 100644
14156--- a/arch/x86/include/asm/pgtable_types.h
14157+++ b/arch/x86/include/asm/pgtable_types.h
14158@@ -16,13 +16,12 @@
14159 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14160 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14161 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14162-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14163+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14164 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14165 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14166 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14167-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14168-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14169-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14170+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14171+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14172 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14173
14174 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14175@@ -40,7 +39,6 @@
14176 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14177 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14178 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14179-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14180 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14181 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14182 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14183@@ -57,8 +55,10 @@
14184
14185 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14186 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14187-#else
14188+#elif defined(CONFIG_KMEMCHECK)
14189 #define _PAGE_NX (_AT(pteval_t, 0))
14190+#else
14191+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14192 #endif
14193
14194 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14195@@ -116,6 +116,9 @@
14196 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14197 _PAGE_ACCESSED)
14198
14199+#define PAGE_READONLY_NOEXEC PAGE_READONLY
14200+#define PAGE_SHARED_NOEXEC PAGE_SHARED
14201+
14202 #define __PAGE_KERNEL_EXEC \
14203 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14204 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14205@@ -126,7 +129,7 @@
14206 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14207 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14208 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14209-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14210+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14211 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14212 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14213 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14214@@ -188,8 +191,8 @@
14215 * bits are combined, this will alow user to access the high address mapped
14216 * VDSO in the presence of CONFIG_COMPAT_VDSO
14217 */
14218-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14219-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14220+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14221+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14222 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14223 #endif
14224
14225@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14226 {
14227 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14228 }
14229+#endif
14230
14231+#if PAGETABLE_LEVELS == 3
14232+#include <asm-generic/pgtable-nopud.h>
14233+#endif
14234+
14235+#if PAGETABLE_LEVELS == 2
14236+#include <asm-generic/pgtable-nopmd.h>
14237+#endif
14238+
14239+#ifndef __ASSEMBLY__
14240 #if PAGETABLE_LEVELS > 3
14241 typedef struct { pudval_t pud; } pud_t;
14242
14243@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14244 return pud.pud;
14245 }
14246 #else
14247-#include <asm-generic/pgtable-nopud.h>
14248-
14249 static inline pudval_t native_pud_val(pud_t pud)
14250 {
14251 return native_pgd_val(pud.pgd);
14252@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14253 return pmd.pmd;
14254 }
14255 #else
14256-#include <asm-generic/pgtable-nopmd.h>
14257-
14258 static inline pmdval_t native_pmd_val(pmd_t pmd)
14259 {
14260 return native_pgd_val(pmd.pud.pgd);
14261@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14262
14263 extern pteval_t __supported_pte_mask;
14264 extern void set_nx(void);
14265-extern int nx_enabled;
14266
14267 #define pgprot_writecombine pgprot_writecombine
14268 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14269diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14270index 888184b..a07ac89 100644
14271--- a/arch/x86/include/asm/processor.h
14272+++ b/arch/x86/include/asm/processor.h
14273@@ -287,7 +287,7 @@ struct tss_struct {
14274
14275 } ____cacheline_aligned;
14276
14277-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14278+extern struct tss_struct init_tss[NR_CPUS];
14279
14280 /*
14281 * Save the original ist values for checking stack pointers during debugging
14282@@ -827,11 +827,18 @@ static inline void spin_lock_prefetch(const void *x)
14283 */
14284 #define TASK_SIZE PAGE_OFFSET
14285 #define TASK_SIZE_MAX TASK_SIZE
14286+
14287+#ifdef CONFIG_PAX_SEGMEXEC
14288+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14289+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14290+#else
14291 #define STACK_TOP TASK_SIZE
14292-#define STACK_TOP_MAX STACK_TOP
14293+#endif
14294+
14295+#define STACK_TOP_MAX TASK_SIZE
14296
14297 #define INIT_THREAD { \
14298- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14299+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14300 .vm86_info = NULL, \
14301 .sysenter_cs = __KERNEL_CS, \
14302 .io_bitmap_ptr = NULL, \
14303@@ -845,7 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
14304 */
14305 #define INIT_TSS { \
14306 .x86_tss = { \
14307- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14308+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14309 .ss0 = __KERNEL_DS, \
14310 .ss1 = __KERNEL_CS, \
14311 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14312@@ -856,11 +863,7 @@ static inline void spin_lock_prefetch(const void *x)
14313 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14314
14315 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14316-#define KSTK_TOP(info) \
14317-({ \
14318- unsigned long *__ptr = (unsigned long *)(info); \
14319- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14320-})
14321+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14322
14323 /*
14324 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14325@@ -875,7 +878,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14326 #define task_pt_regs(task) \
14327 ({ \
14328 struct pt_regs *__regs__; \
14329- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14330+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14331 __regs__ - 1; \
14332 })
14333
14334@@ -885,13 +888,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14335 /*
14336 * User space process size. 47bits minus one guard page.
14337 */
14338-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14339+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14340
14341 /* This decides where the kernel will search for a free chunk of vm
14342 * space during mmap's.
14343 */
14344 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14345- 0xc0000000 : 0xFFFFe000)
14346+ 0xc0000000 : 0xFFFFf000)
14347
14348 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14349 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14350@@ -902,11 +905,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14351 #define STACK_TOP_MAX TASK_SIZE_MAX
14352
14353 #define INIT_THREAD { \
14354- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14355+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14356 }
14357
14358 #define INIT_TSS { \
14359- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14360+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14361 }
14362
14363 /*
14364@@ -934,6 +937,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14365 */
14366 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14367
14368+#ifdef CONFIG_PAX_SEGMEXEC
14369+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14370+#endif
14371+
14372 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14373
14374 /* Get/set a process' ability to use the timestamp counter instruction */
14375@@ -994,12 +1001,12 @@ extern bool cpu_has_amd_erratum(const int *);
14376 #define cpu_has_amd_erratum(x) (false)
14377 #endif /* CONFIG_CPU_SUP_AMD */
14378
14379-extern unsigned long arch_align_stack(unsigned long sp);
14380+#define arch_align_stack(x) ((x) & ~0xfUL)
14381 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14382
14383 void default_idle(void);
14384 bool set_pm_idle_to_default(void);
14385
14386-void stop_this_cpu(void *dummy);
14387+void stop_this_cpu(void *dummy) __noreturn;
14388
14389 #endif /* _ASM_X86_PROCESSOR_H */
14390diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14391index 942a086..6c26446 100644
14392--- a/arch/x86/include/asm/ptrace.h
14393+++ b/arch/x86/include/asm/ptrace.h
14394@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14395 }
14396
14397 /*
14398- * user_mode_vm(regs) determines whether a register set came from user mode.
14399+ * user_mode(regs) determines whether a register set came from user mode.
14400 * This is true if V8086 mode was enabled OR if the register set was from
14401 * protected mode with RPL-3 CS value. This tricky test checks that with
14402 * one comparison. Many places in the kernel can bypass this full check
14403- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14404+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14405+ * be used.
14406 */
14407-static inline int user_mode(struct pt_regs *regs)
14408+static inline int user_mode_novm(struct pt_regs *regs)
14409 {
14410 #ifdef CONFIG_X86_32
14411 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
14412 #else
14413- return !!(regs->cs & 3);
14414+ return !!(regs->cs & SEGMENT_RPL_MASK);
14415 #endif
14416 }
14417
14418-static inline int user_mode_vm(struct pt_regs *regs)
14419+static inline int user_mode(struct pt_regs *regs)
14420 {
14421 #ifdef CONFIG_X86_32
14422 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
14423 USER_RPL;
14424 #else
14425- return user_mode(regs);
14426+ return user_mode_novm(regs);
14427 #endif
14428 }
14429
14430@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
14431 #ifdef CONFIG_X86_64
14432 static inline bool user_64bit_mode(struct pt_regs *regs)
14433 {
14434+ unsigned long cs = regs->cs & 0xffff;
14435 #ifndef CONFIG_PARAVIRT
14436 /*
14437 * On non-paravirt systems, this is the only long mode CPL 3
14438 * selector. We do not allow long mode selectors in the LDT.
14439 */
14440- return regs->cs == __USER_CS;
14441+ return cs == __USER_CS;
14442 #else
14443 /* Headers are too twisted for this to go in paravirt.h. */
14444- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
14445+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
14446 #endif
14447 }
14448
14449@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
14450 * Traps from the kernel do not save sp and ss.
14451 * Use the helper function to retrieve sp.
14452 */
14453- if (offset == offsetof(struct pt_regs, sp) &&
14454- regs->cs == __KERNEL_CS)
14455- return kernel_stack_pointer(regs);
14456+ if (offset == offsetof(struct pt_regs, sp)) {
14457+ unsigned long cs = regs->cs & 0xffff;
14458+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
14459+ return kernel_stack_pointer(regs);
14460+ }
14461 #endif
14462 return *(unsigned long *)((unsigned long)regs + offset);
14463 }
14464diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
14465index fe1ec5b..dc5c3fe 100644
14466--- a/arch/x86/include/asm/realmode.h
14467+++ b/arch/x86/include/asm/realmode.h
14468@@ -22,16 +22,14 @@ struct real_mode_header {
14469 #endif
14470 /* APM/BIOS reboot */
14471 u32 machine_real_restart_asm;
14472-#ifdef CONFIG_X86_64
14473 u32 machine_real_restart_seg;
14474-#endif
14475 };
14476
14477 /* This must match data at trampoline_32/64.S */
14478 struct trampoline_header {
14479 #ifdef CONFIG_X86_32
14480 u32 start;
14481- u16 gdt_pad;
14482+ u16 boot_cs;
14483 u16 gdt_limit;
14484 u32 gdt_base;
14485 #else
14486diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
14487index a82c4f1..ac45053 100644
14488--- a/arch/x86/include/asm/reboot.h
14489+++ b/arch/x86/include/asm/reboot.h
14490@@ -6,13 +6,13 @@
14491 struct pt_regs;
14492
14493 struct machine_ops {
14494- void (*restart)(char *cmd);
14495- void (*halt)(void);
14496- void (*power_off)(void);
14497+ void (* __noreturn restart)(char *cmd);
14498+ void (* __noreturn halt)(void);
14499+ void (* __noreturn power_off)(void);
14500 void (*shutdown)(void);
14501 void (*crash_shutdown)(struct pt_regs *);
14502- void (*emergency_restart)(void);
14503-};
14504+ void (* __noreturn emergency_restart)(void);
14505+} __no_const;
14506
14507 extern struct machine_ops machine_ops;
14508
14509diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
14510index 2dbe4a7..ce1db00 100644
14511--- a/arch/x86/include/asm/rwsem.h
14512+++ b/arch/x86/include/asm/rwsem.h
14513@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
14514 {
14515 asm volatile("# beginning down_read\n\t"
14516 LOCK_PREFIX _ASM_INC "(%1)\n\t"
14517+
14518+#ifdef CONFIG_PAX_REFCOUNT
14519+ "jno 0f\n"
14520+ LOCK_PREFIX _ASM_DEC "(%1)\n"
14521+ "int $4\n0:\n"
14522+ _ASM_EXTABLE(0b, 0b)
14523+#endif
14524+
14525 /* adds 0x00000001 */
14526 " jns 1f\n"
14527 " call call_rwsem_down_read_failed\n"
14528@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
14529 "1:\n\t"
14530 " mov %1,%2\n\t"
14531 " add %3,%2\n\t"
14532+
14533+#ifdef CONFIG_PAX_REFCOUNT
14534+ "jno 0f\n"
14535+ "sub %3,%2\n"
14536+ "int $4\n0:\n"
14537+ _ASM_EXTABLE(0b, 0b)
14538+#endif
14539+
14540 " jle 2f\n\t"
14541 LOCK_PREFIX " cmpxchg %2,%0\n\t"
14542 " jnz 1b\n\t"
14543@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
14544 long tmp;
14545 asm volatile("# beginning down_write\n\t"
14546 LOCK_PREFIX " xadd %1,(%2)\n\t"
14547+
14548+#ifdef CONFIG_PAX_REFCOUNT
14549+ "jno 0f\n"
14550+ "mov %1,(%2)\n"
14551+ "int $4\n0:\n"
14552+ _ASM_EXTABLE(0b, 0b)
14553+#endif
14554+
14555 /* adds 0xffff0001, returns the old value */
14556 " test %1,%1\n\t"
14557 /* was the count 0 before? */
14558@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
14559 long tmp;
14560 asm volatile("# beginning __up_read\n\t"
14561 LOCK_PREFIX " xadd %1,(%2)\n\t"
14562+
14563+#ifdef CONFIG_PAX_REFCOUNT
14564+ "jno 0f\n"
14565+ "mov %1,(%2)\n"
14566+ "int $4\n0:\n"
14567+ _ASM_EXTABLE(0b, 0b)
14568+#endif
14569+
14570 /* subtracts 1, returns the old value */
14571 " jns 1f\n\t"
14572 " call call_rwsem_wake\n" /* expects old value in %edx */
14573@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
14574 long tmp;
14575 asm volatile("# beginning __up_write\n\t"
14576 LOCK_PREFIX " xadd %1,(%2)\n\t"
14577+
14578+#ifdef CONFIG_PAX_REFCOUNT
14579+ "jno 0f\n"
14580+ "mov %1,(%2)\n"
14581+ "int $4\n0:\n"
14582+ _ASM_EXTABLE(0b, 0b)
14583+#endif
14584+
14585 /* subtracts 0xffff0001, returns the old value */
14586 " jns 1f\n\t"
14587 " call call_rwsem_wake\n" /* expects old value in %edx */
14588@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
14589 {
14590 asm volatile("# beginning __downgrade_write\n\t"
14591 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
14592+
14593+#ifdef CONFIG_PAX_REFCOUNT
14594+ "jno 0f\n"
14595+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
14596+ "int $4\n0:\n"
14597+ _ASM_EXTABLE(0b, 0b)
14598+#endif
14599+
14600 /*
14601 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
14602 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
14603@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
14604 */
14605 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
14606 {
14607- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
14608+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
14609+
14610+#ifdef CONFIG_PAX_REFCOUNT
14611+ "jno 0f\n"
14612+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
14613+ "int $4\n0:\n"
14614+ _ASM_EXTABLE(0b, 0b)
14615+#endif
14616+
14617 : "+m" (sem->count)
14618 : "er" (delta));
14619 }
14620@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
14621 */
14622 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
14623 {
14624- return delta + xadd(&sem->count, delta);
14625+ return delta + xadd_check_overflow(&sem->count, delta);
14626 }
14627
14628 #endif /* __KERNEL__ */
14629diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
14630index c48a950..c6d7468 100644
14631--- a/arch/x86/include/asm/segment.h
14632+++ b/arch/x86/include/asm/segment.h
14633@@ -64,10 +64,15 @@
14634 * 26 - ESPFIX small SS
14635 * 27 - per-cpu [ offset to per-cpu data area ]
14636 * 28 - stack_canary-20 [ for stack protector ]
14637- * 29 - unused
14638- * 30 - unused
14639+ * 29 - PCI BIOS CS
14640+ * 30 - PCI BIOS DS
14641 * 31 - TSS for double fault handler
14642 */
14643+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
14644+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
14645+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
14646+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
14647+
14648 #define GDT_ENTRY_TLS_MIN 6
14649 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
14650
14651@@ -79,6 +84,8 @@
14652
14653 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
14654
14655+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
14656+
14657 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
14658
14659 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
14660@@ -104,6 +111,12 @@
14661 #define __KERNEL_STACK_CANARY 0
14662 #endif
14663
14664+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
14665+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
14666+
14667+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
14668+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
14669+
14670 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
14671
14672 /*
14673@@ -141,7 +154,7 @@
14674 */
14675
14676 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
14677-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
14678+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
14679
14680
14681 #else
14682@@ -165,6 +178,8 @@
14683 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
14684 #define __USER32_DS __USER_DS
14685
14686+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
14687+
14688 #define GDT_ENTRY_TSS 8 /* needs two entries */
14689 #define GDT_ENTRY_LDT 10 /* needs two entries */
14690 #define GDT_ENTRY_TLS_MIN 12
14691@@ -185,6 +200,7 @@
14692 #endif
14693
14694 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
14695+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
14696 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
14697 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
14698 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
14699@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
14700 {
14701 unsigned long __limit;
14702 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
14703- return __limit + 1;
14704+ return __limit;
14705 }
14706
14707 #endif /* !__ASSEMBLY__ */
14708diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
14709index b073aae..39f9bdd 100644
14710--- a/arch/x86/include/asm/smp.h
14711+++ b/arch/x86/include/asm/smp.h
14712@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
14713 /* cpus sharing the last level cache: */
14714 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
14715 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
14716-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
14717+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
14718
14719 static inline struct cpumask *cpu_sibling_mask(int cpu)
14720 {
14721@@ -79,7 +79,7 @@ struct smp_ops {
14722
14723 void (*send_call_func_ipi)(const struct cpumask *mask);
14724 void (*send_call_func_single_ipi)(int cpu);
14725-};
14726+} __no_const;
14727
14728 /* Globals due to paravirt */
14729 extern void set_cpu_sibling_map(int cpu);
14730@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
14731 extern int safe_smp_processor_id(void);
14732
14733 #elif defined(CONFIG_X86_64_SMP)
14734-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
14735-
14736-#define stack_smp_processor_id() \
14737-({ \
14738- struct thread_info *ti; \
14739- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
14740- ti->cpu; \
14741-})
14742+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
14743+#define stack_smp_processor_id() raw_smp_processor_id()
14744 #define safe_smp_processor_id() smp_processor_id()
14745
14746 #endif
14747diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
14748index 33692ea..350a534 100644
14749--- a/arch/x86/include/asm/spinlock.h
14750+++ b/arch/x86/include/asm/spinlock.h
14751@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
14752 static inline void arch_read_lock(arch_rwlock_t *rw)
14753 {
14754 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
14755+
14756+#ifdef CONFIG_PAX_REFCOUNT
14757+ "jno 0f\n"
14758+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
14759+ "int $4\n0:\n"
14760+ _ASM_EXTABLE(0b, 0b)
14761+#endif
14762+
14763 "jns 1f\n"
14764 "call __read_lock_failed\n\t"
14765 "1:\n"
14766@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
14767 static inline void arch_write_lock(arch_rwlock_t *rw)
14768 {
14769 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
14770+
14771+#ifdef CONFIG_PAX_REFCOUNT
14772+ "jno 0f\n"
14773+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
14774+ "int $4\n0:\n"
14775+ _ASM_EXTABLE(0b, 0b)
14776+#endif
14777+
14778 "jz 1f\n"
14779 "call __write_lock_failed\n\t"
14780 "1:\n"
14781@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
14782
14783 static inline void arch_read_unlock(arch_rwlock_t *rw)
14784 {
14785- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
14786+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
14787+
14788+#ifdef CONFIG_PAX_REFCOUNT
14789+ "jno 0f\n"
14790+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
14791+ "int $4\n0:\n"
14792+ _ASM_EXTABLE(0b, 0b)
14793+#endif
14794+
14795 :"+m" (rw->lock) : : "memory");
14796 }
14797
14798 static inline void arch_write_unlock(arch_rwlock_t *rw)
14799 {
14800- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
14801+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
14802+
14803+#ifdef CONFIG_PAX_REFCOUNT
14804+ "jno 0f\n"
14805+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
14806+ "int $4\n0:\n"
14807+ _ASM_EXTABLE(0b, 0b)
14808+#endif
14809+
14810 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
14811 }
14812
14813diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
14814index 6a99859..03cb807 100644
14815--- a/arch/x86/include/asm/stackprotector.h
14816+++ b/arch/x86/include/asm/stackprotector.h
14817@@ -47,7 +47,7 @@
14818 * head_32 for boot CPU and setup_per_cpu_areas() for others.
14819 */
14820 #define GDT_STACK_CANARY_INIT \
14821- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
14822+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
14823
14824 /*
14825 * Initialize the stackprotector canary value.
14826@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
14827
14828 static inline void load_stack_canary_segment(void)
14829 {
14830-#ifdef CONFIG_X86_32
14831+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
14832 asm volatile ("mov %0, %%gs" : : "r" (0));
14833 #endif
14834 }
14835diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
14836index 70bbe39..4ae2bd4 100644
14837--- a/arch/x86/include/asm/stacktrace.h
14838+++ b/arch/x86/include/asm/stacktrace.h
14839@@ -11,28 +11,20 @@
14840
14841 extern int kstack_depth_to_print;
14842
14843-struct thread_info;
14844+struct task_struct;
14845 struct stacktrace_ops;
14846
14847-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
14848- unsigned long *stack,
14849- unsigned long bp,
14850- const struct stacktrace_ops *ops,
14851- void *data,
14852- unsigned long *end,
14853- int *graph);
14854+typedef unsigned long walk_stack_t(struct task_struct *task,
14855+ void *stack_start,
14856+ unsigned long *stack,
14857+ unsigned long bp,
14858+ const struct stacktrace_ops *ops,
14859+ void *data,
14860+ unsigned long *end,
14861+ int *graph);
14862
14863-extern unsigned long
14864-print_context_stack(struct thread_info *tinfo,
14865- unsigned long *stack, unsigned long bp,
14866- const struct stacktrace_ops *ops, void *data,
14867- unsigned long *end, int *graph);
14868-
14869-extern unsigned long
14870-print_context_stack_bp(struct thread_info *tinfo,
14871- unsigned long *stack, unsigned long bp,
14872- const struct stacktrace_ops *ops, void *data,
14873- unsigned long *end, int *graph);
14874+extern walk_stack_t print_context_stack;
14875+extern walk_stack_t print_context_stack_bp;
14876
14877 /* Generic stack tracer with callbacks */
14878
14879@@ -40,7 +32,7 @@ struct stacktrace_ops {
14880 void (*address)(void *data, unsigned long address, int reliable);
14881 /* On negative return stop dumping */
14882 int (*stack)(void *data, char *name);
14883- walk_stack_t walk_stack;
14884+ walk_stack_t *walk_stack;
14885 };
14886
14887 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
14888diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
14889index 4ec45b3..a4f0a8a 100644
14890--- a/arch/x86/include/asm/switch_to.h
14891+++ b/arch/x86/include/asm/switch_to.h
14892@@ -108,7 +108,7 @@ do { \
14893 "call __switch_to\n\t" \
14894 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
14895 __switch_canary \
14896- "movq %P[thread_info](%%rsi),%%r8\n\t" \
14897+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
14898 "movq %%rax,%%rdi\n\t" \
14899 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
14900 "jnz ret_from_fork\n\t" \
14901@@ -119,7 +119,7 @@ do { \
14902 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
14903 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
14904 [_tif_fork] "i" (_TIF_FORK), \
14905- [thread_info] "i" (offsetof(struct task_struct, stack)), \
14906+ [thread_info] "m" (current_tinfo), \
14907 [current_task] "m" (current_task) \
14908 __switch_canary_iparam \
14909 : "memory", "cc" __EXTRA_CLOBBER)
14910diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
14911index 2d946e6..e453ec4 100644
14912--- a/arch/x86/include/asm/thread_info.h
14913+++ b/arch/x86/include/asm/thread_info.h
14914@@ -10,6 +10,7 @@
14915 #include <linux/compiler.h>
14916 #include <asm/page.h>
14917 #include <asm/types.h>
14918+#include <asm/percpu.h>
14919
14920 /*
14921 * low level task data that entry.S needs immediate access to
14922@@ -24,7 +25,6 @@ struct exec_domain;
14923 #include <linux/atomic.h>
14924
14925 struct thread_info {
14926- struct task_struct *task; /* main task structure */
14927 struct exec_domain *exec_domain; /* execution domain */
14928 __u32 flags; /* low level flags */
14929 __u32 status; /* thread synchronous flags */
14930@@ -34,19 +34,13 @@ struct thread_info {
14931 mm_segment_t addr_limit;
14932 struct restart_block restart_block;
14933 void __user *sysenter_return;
14934-#ifdef CONFIG_X86_32
14935- unsigned long previous_esp; /* ESP of the previous stack in
14936- case of nested (IRQ) stacks
14937- */
14938- __u8 supervisor_stack[0];
14939-#endif
14940+ unsigned long lowest_stack;
14941 unsigned int sig_on_uaccess_error:1;
14942 unsigned int uaccess_err:1; /* uaccess failed */
14943 };
14944
14945-#define INIT_THREAD_INFO(tsk) \
14946+#define INIT_THREAD_INFO \
14947 { \
14948- .task = &tsk, \
14949 .exec_domain = &default_exec_domain, \
14950 .flags = 0, \
14951 .cpu = 0, \
14952@@ -57,7 +51,7 @@ struct thread_info {
14953 }, \
14954 }
14955
14956-#define init_thread_info (init_thread_union.thread_info)
14957+#define init_thread_info (init_thread_union.stack)
14958 #define init_stack (init_thread_union.stack)
14959
14960 #else /* !__ASSEMBLY__ */
14961@@ -98,6 +92,7 @@ struct thread_info {
14962 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
14963 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
14964 #define TIF_X32 30 /* 32-bit native x86-64 binary */
14965+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
14966
14967 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
14968 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
14969@@ -122,17 +117,18 @@ struct thread_info {
14970 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
14971 #define _TIF_ADDR32 (1 << TIF_ADDR32)
14972 #define _TIF_X32 (1 << TIF_X32)
14973+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
14974
14975 /* work to do in syscall_trace_enter() */
14976 #define _TIF_WORK_SYSCALL_ENTRY \
14977 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
14978 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
14979- _TIF_NOHZ)
14980+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
14981
14982 /* work to do in syscall_trace_leave() */
14983 #define _TIF_WORK_SYSCALL_EXIT \
14984 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
14985- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
14986+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
14987
14988 /* work to do on interrupt/exception return */
14989 #define _TIF_WORK_MASK \
14990@@ -143,7 +139,7 @@ struct thread_info {
14991 /* work to do on any return to user space */
14992 #define _TIF_ALLWORK_MASK \
14993 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
14994- _TIF_NOHZ)
14995+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
14996
14997 /* Only used for 64 bit */
14998 #define _TIF_DO_NOTIFY_MASK \
14999@@ -159,45 +155,40 @@ struct thread_info {
15000
15001 #define PREEMPT_ACTIVE 0x10000000
15002
15003-#ifdef CONFIG_X86_32
15004-
15005-#define STACK_WARN (THREAD_SIZE/8)
15006-/*
15007- * macros/functions for gaining access to the thread information structure
15008- *
15009- * preempt_count needs to be 1 initially, until the scheduler is functional.
15010- */
15011-#ifndef __ASSEMBLY__
15012-
15013-
15014-/* how to get the current stack pointer from C */
15015-register unsigned long current_stack_pointer asm("esp") __used;
15016-
15017-/* how to get the thread information struct from C */
15018-static inline struct thread_info *current_thread_info(void)
15019-{
15020- return (struct thread_info *)
15021- (current_stack_pointer & ~(THREAD_SIZE - 1));
15022-}
15023-
15024-#else /* !__ASSEMBLY__ */
15025-
15026+#ifdef __ASSEMBLY__
15027 /* how to get the thread information struct from ASM */
15028 #define GET_THREAD_INFO(reg) \
15029- movl $-THREAD_SIZE, reg; \
15030- andl %esp, reg
15031+ mov PER_CPU_VAR(current_tinfo), reg
15032
15033 /* use this one if reg already contains %esp */
15034-#define GET_THREAD_INFO_WITH_ESP(reg) \
15035- andl $-THREAD_SIZE, reg
15036+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15037+#else
15038+/* how to get the thread information struct from C */
15039+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15040+
15041+static __always_inline struct thread_info *current_thread_info(void)
15042+{
15043+ return this_cpu_read_stable(current_tinfo);
15044+}
15045+#endif
15046+
15047+#ifdef CONFIG_X86_32
15048+
15049+#define STACK_WARN (THREAD_SIZE/8)
15050+/*
15051+ * macros/functions for gaining access to the thread information structure
15052+ *
15053+ * preempt_count needs to be 1 initially, until the scheduler is functional.
15054+ */
15055+#ifndef __ASSEMBLY__
15056+
15057+/* how to get the current stack pointer from C */
15058+register unsigned long current_stack_pointer asm("esp") __used;
15059
15060 #endif
15061
15062 #else /* X86_32 */
15063
15064-#include <asm/percpu.h>
15065-#define KERNEL_STACK_OFFSET (5*8)
15066-
15067 /*
15068 * macros/functions for gaining access to the thread information structure
15069 * preempt_count needs to be 1 initially, until the scheduler is functional.
15070@@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
15071 #ifndef __ASSEMBLY__
15072 DECLARE_PER_CPU(unsigned long, kernel_stack);
15073
15074-static inline struct thread_info *current_thread_info(void)
15075-{
15076- struct thread_info *ti;
15077- ti = (void *)(this_cpu_read_stable(kernel_stack) +
15078- KERNEL_STACK_OFFSET - THREAD_SIZE);
15079- return ti;
15080-}
15081-
15082-#else /* !__ASSEMBLY__ */
15083-
15084-/* how to get the thread information struct from ASM */
15085-#define GET_THREAD_INFO(reg) \
15086- movq PER_CPU_VAR(kernel_stack),reg ; \
15087- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15088-
15089-/*
15090- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15091- * a certain register (to be used in assembler memory operands).
15092- */
15093-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15094-
15095+/* how to get the current stack pointer from C */
15096+register unsigned long current_stack_pointer asm("rsp") __used;
15097 #endif
15098
15099 #endif /* !X86_32 */
15100@@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
15101 extern void arch_task_cache_init(void);
15102 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15103 extern void arch_release_task_struct(struct task_struct *tsk);
15104+
15105+#define __HAVE_THREAD_FUNCTIONS
15106+#define task_thread_info(task) (&(task)->tinfo)
15107+#define task_stack_page(task) ((task)->stack)
15108+#define setup_thread_stack(p, org) do {} while (0)
15109+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15110+
15111 #endif
15112 #endif /* _ASM_X86_THREAD_INFO_H */
15113diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15114index 1709801..0a60f2f 100644
15115--- a/arch/x86/include/asm/uaccess.h
15116+++ b/arch/x86/include/asm/uaccess.h
15117@@ -7,6 +7,7 @@
15118 #include <linux/compiler.h>
15119 #include <linux/thread_info.h>
15120 #include <linux/string.h>
15121+#include <linux/sched.h>
15122 #include <asm/asm.h>
15123 #include <asm/page.h>
15124 #include <asm/smap.h>
15125@@ -29,7 +30,12 @@
15126
15127 #define get_ds() (KERNEL_DS)
15128 #define get_fs() (current_thread_info()->addr_limit)
15129+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15130+void __set_fs(mm_segment_t x);
15131+void set_fs(mm_segment_t x);
15132+#else
15133 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15134+#endif
15135
15136 #define segment_eq(a, b) ((a).seg == (b).seg)
15137
15138@@ -77,8 +83,33 @@
15139 * checks that the pointer is in the user space range - after calling
15140 * this function, memory access functions may still return -EFAULT.
15141 */
15142-#define access_ok(type, addr, size) \
15143- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15144+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15145+#define access_ok(type, addr, size) \
15146+({ \
15147+ long __size = size; \
15148+ unsigned long __addr = (unsigned long)addr; \
15149+ unsigned long __addr_ao = __addr & PAGE_MASK; \
15150+ unsigned long __end_ao = __addr + __size - 1; \
15151+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15152+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15153+ while(__addr_ao <= __end_ao) { \
15154+ char __c_ao; \
15155+ __addr_ao += PAGE_SIZE; \
15156+ if (__size > PAGE_SIZE) \
15157+ cond_resched(); \
15158+ if (__get_user(__c_ao, (char __user *)__addr)) \
15159+ break; \
15160+ if (type != VERIFY_WRITE) { \
15161+ __addr = __addr_ao; \
15162+ continue; \
15163+ } \
15164+ if (__put_user(__c_ao, (char __user *)__addr)) \
15165+ break; \
15166+ __addr = __addr_ao; \
15167+ } \
15168+ } \
15169+ __ret_ao; \
15170+})
15171
15172 /*
15173 * The exception table consists of pairs of addresses relative to the
15174@@ -189,13 +220,21 @@ extern int __get_user_bad(void);
15175 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15176 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15177
15178-
15179+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15180+#define __copyuser_seg "gs;"
15181+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15182+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15183+#else
15184+#define __copyuser_seg
15185+#define __COPYUSER_SET_ES
15186+#define __COPYUSER_RESTORE_ES
15187+#endif
15188
15189 #ifdef CONFIG_X86_32
15190 #define __put_user_asm_u64(x, addr, err, errret) \
15191 asm volatile(ASM_STAC "\n" \
15192- "1: movl %%eax,0(%2)\n" \
15193- "2: movl %%edx,4(%2)\n" \
15194+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15195+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15196 "3: " ASM_CLAC "\n" \
15197 ".section .fixup,\"ax\"\n" \
15198 "4: movl %3,%0\n" \
15199@@ -208,8 +247,8 @@ extern int __get_user_bad(void);
15200
15201 #define __put_user_asm_ex_u64(x, addr) \
15202 asm volatile(ASM_STAC "\n" \
15203- "1: movl %%eax,0(%1)\n" \
15204- "2: movl %%edx,4(%1)\n" \
15205+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15206+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15207 "3: " ASM_CLAC "\n" \
15208 _ASM_EXTABLE_EX(1b, 2b) \
15209 _ASM_EXTABLE_EX(2b, 3b) \
15210@@ -259,7 +298,7 @@ extern void __put_user_8(void);
15211 __typeof__(*(ptr)) __pu_val; \
15212 __chk_user_ptr(ptr); \
15213 might_fault(); \
15214- __pu_val = x; \
15215+ __pu_val = (x); \
15216 switch (sizeof(*(ptr))) { \
15217 case 1: \
15218 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15219@@ -358,7 +397,7 @@ do { \
15220
15221 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15222 asm volatile(ASM_STAC "\n" \
15223- "1: mov"itype" %2,%"rtype"1\n" \
15224+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15225 "2: " ASM_CLAC "\n" \
15226 ".section .fixup,\"ax\"\n" \
15227 "3: mov %3,%0\n" \
15228@@ -366,7 +405,7 @@ do { \
15229 " jmp 2b\n" \
15230 ".previous\n" \
15231 _ASM_EXTABLE(1b, 3b) \
15232- : "=r" (err), ltype(x) \
15233+ : "=r" (err), ltype (x) \
15234 : "m" (__m(addr)), "i" (errret), "0" (err))
15235
15236 #define __get_user_size_ex(x, ptr, size) \
15237@@ -391,7 +430,7 @@ do { \
15238 } while (0)
15239
15240 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15241- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15242+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15243 "2:\n" \
15244 _ASM_EXTABLE_EX(1b, 2b) \
15245 : ltype(x) : "m" (__m(addr)))
15246@@ -408,13 +447,24 @@ do { \
15247 int __gu_err; \
15248 unsigned long __gu_val; \
15249 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15250- (x) = (__force __typeof__(*(ptr)))__gu_val; \
15251+ (x) = (__typeof__(*(ptr)))__gu_val; \
15252 __gu_err; \
15253 })
15254
15255 /* FIXME: this hack is definitely wrong -AK */
15256 struct __large_struct { unsigned long buf[100]; };
15257-#define __m(x) (*(struct __large_struct __user *)(x))
15258+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15259+#define ____m(x) \
15260+({ \
15261+ unsigned long ____x = (unsigned long)(x); \
15262+ if (____x < PAX_USER_SHADOW_BASE) \
15263+ ____x += PAX_USER_SHADOW_BASE; \
15264+ (void __user *)____x; \
15265+})
15266+#else
15267+#define ____m(x) (x)
15268+#endif
15269+#define __m(x) (*(struct __large_struct __user *)____m(x))
15270
15271 /*
15272 * Tell gcc we read from memory instead of writing: this is because
15273@@ -423,7 +473,7 @@ struct __large_struct { unsigned long buf[100]; };
15274 */
15275 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15276 asm volatile(ASM_STAC "\n" \
15277- "1: mov"itype" %"rtype"1,%2\n" \
15278+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15279 "2: " ASM_CLAC "\n" \
15280 ".section .fixup,\"ax\"\n" \
15281 "3: mov %3,%0\n" \
15282@@ -431,10 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
15283 ".previous\n" \
15284 _ASM_EXTABLE(1b, 3b) \
15285 : "=r"(err) \
15286- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15287+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15288
15289 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15290- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15291+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15292 "2:\n" \
15293 _ASM_EXTABLE_EX(1b, 2b) \
15294 : : ltype(x), "m" (__m(addr)))
15295@@ -473,8 +523,12 @@ struct __large_struct { unsigned long buf[100]; };
15296 * On error, the variable @x is set to zero.
15297 */
15298
15299+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15300+#define __get_user(x, ptr) get_user((x), (ptr))
15301+#else
15302 #define __get_user(x, ptr) \
15303 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15304+#endif
15305
15306 /**
15307 * __put_user: - Write a simple value into user space, with less checking.
15308@@ -496,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
15309 * Returns zero on success, or -EFAULT on error.
15310 */
15311
15312+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15313+#define __put_user(x, ptr) put_user((x), (ptr))
15314+#else
15315 #define __put_user(x, ptr) \
15316 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15317+#endif
15318
15319 #define __get_user_unaligned __get_user
15320 #define __put_user_unaligned __put_user
15321@@ -515,7 +573,7 @@ struct __large_struct { unsigned long buf[100]; };
15322 #define get_user_ex(x, ptr) do { \
15323 unsigned long __gue_val; \
15324 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15325- (x) = (__force __typeof__(*(ptr)))__gue_val; \
15326+ (x) = (__typeof__(*(ptr)))__gue_val; \
15327 } while (0)
15328
15329 #define put_user_try uaccess_try
15330@@ -532,8 +590,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15331 extern __must_check long strlen_user(const char __user *str);
15332 extern __must_check long strnlen_user(const char __user *str, long n);
15333
15334-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
15335-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
15336+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15337+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15338
15339 /*
15340 * movsl can be slow when source and dest are not both 8-byte aligned
15341diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15342index 7f760a9..04b1c65 100644
15343--- a/arch/x86/include/asm/uaccess_32.h
15344+++ b/arch/x86/include/asm/uaccess_32.h
15345@@ -11,15 +11,15 @@
15346 #include <asm/page.h>
15347
15348 unsigned long __must_check __copy_to_user_ll
15349- (void __user *to, const void *from, unsigned long n);
15350+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15351 unsigned long __must_check __copy_from_user_ll
15352- (void *to, const void __user *from, unsigned long n);
15353+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15354 unsigned long __must_check __copy_from_user_ll_nozero
15355- (void *to, const void __user *from, unsigned long n);
15356+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15357 unsigned long __must_check __copy_from_user_ll_nocache
15358- (void *to, const void __user *from, unsigned long n);
15359+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15360 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15361- (void *to, const void __user *from, unsigned long n);
15362+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15363
15364 /**
15365 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15366@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15367 static __always_inline unsigned long __must_check
15368 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15369 {
15370+ if ((long)n < 0)
15371+ return n;
15372+
15373+ check_object_size(from, n, true);
15374+
15375 if (__builtin_constant_p(n)) {
15376 unsigned long ret;
15377
15378@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15379 __copy_to_user(void __user *to, const void *from, unsigned long n)
15380 {
15381 might_fault();
15382+
15383 return __copy_to_user_inatomic(to, from, n);
15384 }
15385
15386 static __always_inline unsigned long
15387 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15388 {
15389+ if ((long)n < 0)
15390+ return n;
15391+
15392 /* Avoid zeroing the tail if the copy fails..
15393 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15394 * but as the zeroing behaviour is only significant when n is not
15395@@ -137,6 +146,12 @@ static __always_inline unsigned long
15396 __copy_from_user(void *to, const void __user *from, unsigned long n)
15397 {
15398 might_fault();
15399+
15400+ if ((long)n < 0)
15401+ return n;
15402+
15403+ check_object_size(to, n, false);
15404+
15405 if (__builtin_constant_p(n)) {
15406 unsigned long ret;
15407
15408@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
15409 const void __user *from, unsigned long n)
15410 {
15411 might_fault();
15412+
15413+ if ((long)n < 0)
15414+ return n;
15415+
15416 if (__builtin_constant_p(n)) {
15417 unsigned long ret;
15418
15419@@ -181,15 +200,19 @@ static __always_inline unsigned long
15420 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
15421 unsigned long n)
15422 {
15423- return __copy_from_user_ll_nocache_nozero(to, from, n);
15424+ if ((long)n < 0)
15425+ return n;
15426+
15427+ return __copy_from_user_ll_nocache_nozero(to, from, n);
15428 }
15429
15430-unsigned long __must_check copy_to_user(void __user *to,
15431- const void *from, unsigned long n);
15432-unsigned long __must_check _copy_from_user(void *to,
15433- const void __user *from,
15434- unsigned long n);
15435-
15436+extern void copy_to_user_overflow(void)
15437+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15438+ __compiletime_error("copy_to_user() buffer size is not provably correct")
15439+#else
15440+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
15441+#endif
15442+;
15443
15444 extern void copy_from_user_overflow(void)
15445 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15446@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
15447 #endif
15448 ;
15449
15450-static inline unsigned long __must_check copy_from_user(void *to,
15451- const void __user *from,
15452- unsigned long n)
15453+/**
15454+ * copy_to_user: - Copy a block of data into user space.
15455+ * @to: Destination address, in user space.
15456+ * @from: Source address, in kernel space.
15457+ * @n: Number of bytes to copy.
15458+ *
15459+ * Context: User context only. This function may sleep.
15460+ *
15461+ * Copy data from kernel space to user space.
15462+ *
15463+ * Returns number of bytes that could not be copied.
15464+ * On success, this will be zero.
15465+ */
15466+static inline unsigned long __must_check
15467+copy_to_user(void __user *to, const void *from, unsigned long n)
15468 {
15469- int sz = __compiletime_object_size(to);
15470+ size_t sz = __compiletime_object_size(from);
15471
15472- if (likely(sz == -1 || sz >= n))
15473- n = _copy_from_user(to, from, n);
15474- else
15475+ if (unlikely(sz != (size_t)-1 && sz < n))
15476+ copy_to_user_overflow();
15477+ else if (access_ok(VERIFY_WRITE, to, n))
15478+ n = __copy_to_user(to, from, n);
15479+ return n;
15480+}
15481+
15482+/**
15483+ * copy_from_user: - Copy a block of data from user space.
15484+ * @to: Destination address, in kernel space.
15485+ * @from: Source address, in user space.
15486+ * @n: Number of bytes to copy.
15487+ *
15488+ * Context: User context only. This function may sleep.
15489+ *
15490+ * Copy data from user space to kernel space.
15491+ *
15492+ * Returns number of bytes that could not be copied.
15493+ * On success, this will be zero.
15494+ *
15495+ * If some data could not be copied, this function will pad the copied
15496+ * data to the requested size using zero bytes.
15497+ */
15498+static inline unsigned long __must_check
15499+copy_from_user(void *to, const void __user *from, unsigned long n)
15500+{
15501+ size_t sz = __compiletime_object_size(to);
15502+
15503+ check_object_size(to, n, false);
15504+
15505+ if (unlikely(sz != (size_t)-1 && sz < n))
15506 copy_from_user_overflow();
15507-
15508+ else if (access_ok(VERIFY_READ, from, n))
15509+ n = __copy_from_user(to, from, n);
15510+ else if ((long)n > 0)
15511+ memset(to, 0, n);
15512 return n;
15513 }
15514
15515diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
15516index 142810c..747941a 100644
15517--- a/arch/x86/include/asm/uaccess_64.h
15518+++ b/arch/x86/include/asm/uaccess_64.h
15519@@ -10,6 +10,9 @@
15520 #include <asm/alternative.h>
15521 #include <asm/cpufeature.h>
15522 #include <asm/page.h>
15523+#include <asm/pgtable.h>
15524+
15525+#define set_fs(x) (current_thread_info()->addr_limit = (x))
15526
15527 /*
15528 * Copy To/From Userspace
15529@@ -17,13 +20,13 @@
15530
15531 /* Handles exceptions in both to and from, but doesn't do access_ok */
15532 __must_check unsigned long
15533-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
15534+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
15535 __must_check unsigned long
15536-copy_user_generic_string(void *to, const void *from, unsigned len);
15537+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
15538 __must_check unsigned long
15539-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
15540+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
15541
15542-static __always_inline __must_check unsigned long
15543+static __always_inline __must_check __size_overflow(3) unsigned long
15544 copy_user_generic(void *to, const void *from, unsigned len)
15545 {
15546 unsigned ret;
15547@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
15548 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
15549 "=d" (len)),
15550 "1" (to), "2" (from), "3" (len)
15551- : "memory", "rcx", "r8", "r9", "r10", "r11");
15552+ : "memory", "rcx", "r8", "r9", "r11");
15553 return ret;
15554 }
15555
15556+static __always_inline __must_check unsigned long
15557+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
15558+static __always_inline __must_check unsigned long
15559+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
15560 __must_check unsigned long
15561-_copy_to_user(void __user *to, const void *from, unsigned len);
15562-__must_check unsigned long
15563-_copy_from_user(void *to, const void __user *from, unsigned len);
15564-__must_check unsigned long
15565-copy_in_user(void __user *to, const void __user *from, unsigned len);
15566+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
15567+
15568+extern void copy_to_user_overflow(void)
15569+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15570+ __compiletime_error("copy_to_user() buffer size is not provably correct")
15571+#else
15572+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
15573+#endif
15574+;
15575+
15576+extern void copy_from_user_overflow(void)
15577+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15578+ __compiletime_error("copy_from_user() buffer size is not provably correct")
15579+#else
15580+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
15581+#endif
15582+;
15583
15584 static inline unsigned long __must_check copy_from_user(void *to,
15585 const void __user *from,
15586 unsigned long n)
15587 {
15588- int sz = __compiletime_object_size(to);
15589-
15590 might_fault();
15591- if (likely(sz == -1 || sz >= n))
15592- n = _copy_from_user(to, from, n);
15593-#ifdef CONFIG_DEBUG_VM
15594- else
15595- WARN(1, "Buffer overflow detected!\n");
15596-#endif
15597+
15598+ check_object_size(to, n, false);
15599+
15600+ if (access_ok(VERIFY_READ, from, n))
15601+ n = __copy_from_user(to, from, n);
15602+ else if (n < INT_MAX)
15603+ memset(to, 0, n);
15604 return n;
15605 }
15606
15607 static __always_inline __must_check
15608-int copy_to_user(void __user *dst, const void *src, unsigned size)
15609+int copy_to_user(void __user *dst, const void *src, unsigned long size)
15610 {
15611 might_fault();
15612
15613- return _copy_to_user(dst, src, size);
15614+ if (access_ok(VERIFY_WRITE, dst, size))
15615+ size = __copy_to_user(dst, src, size);
15616+ return size;
15617 }
15618
15619 static __always_inline __must_check
15620-int __copy_from_user(void *dst, const void __user *src, unsigned size)
15621+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
15622 {
15623- int ret = 0;
15624+ size_t sz = __compiletime_object_size(dst);
15625+ unsigned ret = 0;
15626
15627 might_fault();
15628+
15629+ if (size > INT_MAX)
15630+ return size;
15631+
15632+ check_object_size(dst, size, false);
15633+
15634+#ifdef CONFIG_PAX_MEMORY_UDEREF
15635+ if (!__access_ok(VERIFY_READ, src, size))
15636+ return size;
15637+#endif
15638+
15639+ if (unlikely(sz != (size_t)-1 && sz < size)) {
15640+ copy_from_user_overflow();
15641+ return size;
15642+ }
15643+
15644 if (!__builtin_constant_p(size))
15645- return copy_user_generic(dst, (__force void *)src, size);
15646+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15647 switch (size) {
15648- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
15649+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
15650 ret, "b", "b", "=q", 1);
15651 return ret;
15652- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
15653+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
15654 ret, "w", "w", "=r", 2);
15655 return ret;
15656- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
15657+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
15658 ret, "l", "k", "=r", 4);
15659 return ret;
15660- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
15661+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15662 ret, "q", "", "=r", 8);
15663 return ret;
15664 case 10:
15665- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
15666+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15667 ret, "q", "", "=r", 10);
15668 if (unlikely(ret))
15669 return ret;
15670 __get_user_asm(*(u16 *)(8 + (char *)dst),
15671- (u16 __user *)(8 + (char __user *)src),
15672+ (const u16 __user *)(8 + (const char __user *)src),
15673 ret, "w", "w", "=r", 2);
15674 return ret;
15675 case 16:
15676- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
15677+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15678 ret, "q", "", "=r", 16);
15679 if (unlikely(ret))
15680 return ret;
15681 __get_user_asm(*(u64 *)(8 + (char *)dst),
15682- (u64 __user *)(8 + (char __user *)src),
15683+ (const u64 __user *)(8 + (const char __user *)src),
15684 ret, "q", "", "=r", 8);
15685 return ret;
15686 default:
15687- return copy_user_generic(dst, (__force void *)src, size);
15688+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15689 }
15690 }
15691
15692 static __always_inline __must_check
15693-int __copy_to_user(void __user *dst, const void *src, unsigned size)
15694+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
15695 {
15696- int ret = 0;
15697+ size_t sz = __compiletime_object_size(src);
15698+ unsigned ret = 0;
15699
15700 might_fault();
15701+
15702+ if (size > INT_MAX)
15703+ return size;
15704+
15705+ check_object_size(src, size, true);
15706+
15707+#ifdef CONFIG_PAX_MEMORY_UDEREF
15708+ if (!__access_ok(VERIFY_WRITE, dst, size))
15709+ return size;
15710+#endif
15711+
15712+ if (unlikely(sz != (size_t)-1 && sz < size)) {
15713+ copy_to_user_overflow();
15714+ return size;
15715+ }
15716+
15717 if (!__builtin_constant_p(size))
15718- return copy_user_generic((__force void *)dst, src, size);
15719+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15720 switch (size) {
15721- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
15722+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
15723 ret, "b", "b", "iq", 1);
15724 return ret;
15725- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
15726+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
15727 ret, "w", "w", "ir", 2);
15728 return ret;
15729- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
15730+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
15731 ret, "l", "k", "ir", 4);
15732 return ret;
15733- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
15734+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15735 ret, "q", "", "er", 8);
15736 return ret;
15737 case 10:
15738- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
15739+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15740 ret, "q", "", "er", 10);
15741 if (unlikely(ret))
15742 return ret;
15743 asm("":::"memory");
15744- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
15745+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
15746 ret, "w", "w", "ir", 2);
15747 return ret;
15748 case 16:
15749- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
15750+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15751 ret, "q", "", "er", 16);
15752 if (unlikely(ret))
15753 return ret;
15754 asm("":::"memory");
15755- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
15756+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
15757 ret, "q", "", "er", 8);
15758 return ret;
15759 default:
15760- return copy_user_generic((__force void *)dst, src, size);
15761+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15762 }
15763 }
15764
15765 static __always_inline __must_check
15766-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15767+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
15768 {
15769- int ret = 0;
15770+ unsigned ret = 0;
15771
15772 might_fault();
15773+
15774+ if (size > INT_MAX)
15775+ return size;
15776+
15777+#ifdef CONFIG_PAX_MEMORY_UDEREF
15778+ if (!__access_ok(VERIFY_READ, src, size))
15779+ return size;
15780+ if (!__access_ok(VERIFY_WRITE, dst, size))
15781+ return size;
15782+#endif
15783+
15784 if (!__builtin_constant_p(size))
15785- return copy_user_generic((__force void *)dst,
15786- (__force void *)src, size);
15787+ return copy_user_generic((__force_kernel void *)____m(dst),
15788+ (__force_kernel const void *)____m(src), size);
15789 switch (size) {
15790 case 1: {
15791 u8 tmp;
15792- __get_user_asm(tmp, (u8 __user *)src,
15793+ __get_user_asm(tmp, (const u8 __user *)src,
15794 ret, "b", "b", "=q", 1);
15795 if (likely(!ret))
15796 __put_user_asm(tmp, (u8 __user *)dst,
15797@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15798 }
15799 case 2: {
15800 u16 tmp;
15801- __get_user_asm(tmp, (u16 __user *)src,
15802+ __get_user_asm(tmp, (const u16 __user *)src,
15803 ret, "w", "w", "=r", 2);
15804 if (likely(!ret))
15805 __put_user_asm(tmp, (u16 __user *)dst,
15806@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15807
15808 case 4: {
15809 u32 tmp;
15810- __get_user_asm(tmp, (u32 __user *)src,
15811+ __get_user_asm(tmp, (const u32 __user *)src,
15812 ret, "l", "k", "=r", 4);
15813 if (likely(!ret))
15814 __put_user_asm(tmp, (u32 __user *)dst,
15815@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15816 }
15817 case 8: {
15818 u64 tmp;
15819- __get_user_asm(tmp, (u64 __user *)src,
15820+ __get_user_asm(tmp, (const u64 __user *)src,
15821 ret, "q", "", "=r", 8);
15822 if (likely(!ret))
15823 __put_user_asm(tmp, (u64 __user *)dst,
15824@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15825 return ret;
15826 }
15827 default:
15828- return copy_user_generic((__force void *)dst,
15829- (__force void *)src, size);
15830+ return copy_user_generic((__force_kernel void *)____m(dst),
15831+ (__force_kernel const void *)____m(src), size);
15832 }
15833 }
15834
15835 static __must_check __always_inline int
15836-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
15837+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
15838 {
15839- return copy_user_generic(dst, (__force const void *)src, size);
15840+ if (size > INT_MAX)
15841+ return size;
15842+
15843+#ifdef CONFIG_PAX_MEMORY_UDEREF
15844+ if (!__access_ok(VERIFY_READ, src, size))
15845+ return size;
15846+#endif
15847+
15848+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15849 }
15850
15851-static __must_check __always_inline int
15852-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
15853+static __must_check __always_inline unsigned long
15854+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
15855 {
15856- return copy_user_generic((__force void *)dst, src, size);
15857+ if (size > INT_MAX)
15858+ return size;
15859+
15860+#ifdef CONFIG_PAX_MEMORY_UDEREF
15861+ if (!__access_ok(VERIFY_WRITE, dst, size))
15862+ return size;
15863+#endif
15864+
15865+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15866 }
15867
15868-extern long __copy_user_nocache(void *dst, const void __user *src,
15869- unsigned size, int zerorest);
15870+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
15871+ unsigned long size, int zerorest) __size_overflow(3);
15872
15873-static inline int
15874-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
15875+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
15876 {
15877 might_sleep();
15878+
15879+ if (size > INT_MAX)
15880+ return size;
15881+
15882+#ifdef CONFIG_PAX_MEMORY_UDEREF
15883+ if (!__access_ok(VERIFY_READ, src, size))
15884+ return size;
15885+#endif
15886+
15887 return __copy_user_nocache(dst, src, size, 1);
15888 }
15889
15890-static inline int
15891-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
15892- unsigned size)
15893+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
15894+ unsigned long size)
15895 {
15896+ if (size > INT_MAX)
15897+ return size;
15898+
15899+#ifdef CONFIG_PAX_MEMORY_UDEREF
15900+ if (!__access_ok(VERIFY_READ, src, size))
15901+ return size;
15902+#endif
15903+
15904 return __copy_user_nocache(dst, src, size, 0);
15905 }
15906
15907-unsigned long
15908-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
15909+extern unsigned long
15910+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
15911
15912 #endif /* _ASM_X86_UACCESS_64_H */
15913diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
15914index 5b238981..77fdd78 100644
15915--- a/arch/x86/include/asm/word-at-a-time.h
15916+++ b/arch/x86/include/asm/word-at-a-time.h
15917@@ -11,7 +11,7 @@
15918 * and shift, for example.
15919 */
15920 struct word_at_a_time {
15921- const unsigned long one_bits, high_bits;
15922+ unsigned long one_bits, high_bits;
15923 };
15924
15925 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
15926diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
15927index 5769349..a3d3e2a 100644
15928--- a/arch/x86/include/asm/x86_init.h
15929+++ b/arch/x86/include/asm/x86_init.h
15930@@ -141,7 +141,7 @@ struct x86_init_ops {
15931 struct x86_init_timers timers;
15932 struct x86_init_iommu iommu;
15933 struct x86_init_pci pci;
15934-};
15935+} __no_const;
15936
15937 /**
15938 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
15939@@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
15940 void (*setup_percpu_clockev)(void);
15941 void (*early_percpu_clock_init)(void);
15942 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
15943-};
15944+} __no_const;
15945
15946 /**
15947 * struct x86_platform_ops - platform specific runtime functions
15948@@ -178,7 +178,7 @@ struct x86_platform_ops {
15949 void (*save_sched_clock_state)(void);
15950 void (*restore_sched_clock_state)(void);
15951 void (*apic_post_init)(void);
15952-};
15953+} __no_const;
15954
15955 struct pci_dev;
15956
15957@@ -187,14 +187,14 @@ struct x86_msi_ops {
15958 void (*teardown_msi_irq)(unsigned int irq);
15959 void (*teardown_msi_irqs)(struct pci_dev *dev);
15960 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
15961-};
15962+} __no_const;
15963
15964 struct x86_io_apic_ops {
15965 void (*init) (void);
15966 unsigned int (*read) (unsigned int apic, unsigned int reg);
15967 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
15968 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
15969-};
15970+} __no_const;
15971
15972 extern struct x86_init_ops x86_init;
15973 extern struct x86_cpuinit_ops x86_cpuinit;
15974diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
15975index 0415cda..b43d877 100644
15976--- a/arch/x86/include/asm/xsave.h
15977+++ b/arch/x86/include/asm/xsave.h
15978@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
15979 return -EFAULT;
15980
15981 __asm__ __volatile__(ASM_STAC "\n"
15982- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
15983+ "1:"
15984+ __copyuser_seg
15985+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
15986 "2: " ASM_CLAC "\n"
15987 ".section .fixup,\"ax\"\n"
15988 "3: movl $-1,%[err]\n"
15989@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
15990 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
15991 {
15992 int err;
15993- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
15994+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
15995 u32 lmask = mask;
15996 u32 hmask = mask >> 32;
15997
15998 __asm__ __volatile__(ASM_STAC "\n"
15999- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16000+ "1:"
16001+ __copyuser_seg
16002+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16003 "2: " ASM_CLAC "\n"
16004 ".section .fixup,\"ax\"\n"
16005 "3: movl $-1,%[err]\n"
16006diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16007index bbae024..e1528f9 100644
16008--- a/arch/x86/include/uapi/asm/e820.h
16009+++ b/arch/x86/include/uapi/asm/e820.h
16010@@ -63,7 +63,7 @@ struct e820map {
16011 #define ISA_START_ADDRESS 0xa0000
16012 #define ISA_END_ADDRESS 0x100000
16013
16014-#define BIOS_BEGIN 0x000a0000
16015+#define BIOS_BEGIN 0x000c0000
16016 #define BIOS_END 0x00100000
16017
16018 #define BIOS_ROM_BASE 0xffe00000
16019diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16020index 34e923a..0c6bb6e 100644
16021--- a/arch/x86/kernel/Makefile
16022+++ b/arch/x86/kernel/Makefile
16023@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16024 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16025 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16026 obj-y += probe_roms.o
16027-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16028+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16029 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16030 obj-y += syscall_$(BITS).o
16031 obj-$(CONFIG_X86_64) += vsyscall_64.o
16032diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16033index d5e0d71..6533e08 100644
16034--- a/arch/x86/kernel/acpi/sleep.c
16035+++ b/arch/x86/kernel/acpi/sleep.c
16036@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16037 #else /* CONFIG_64BIT */
16038 #ifdef CONFIG_SMP
16039 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16040+
16041+ pax_open_kernel();
16042 early_gdt_descr.address =
16043 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16044+ pax_close_kernel();
16045+
16046 initial_gs = per_cpu_offset(smp_processor_id());
16047 #endif
16048 initial_code = (unsigned long)wakeup_long64;
16049diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16050index 13ab720..95d5442 100644
16051--- a/arch/x86/kernel/acpi/wakeup_32.S
16052+++ b/arch/x86/kernel/acpi/wakeup_32.S
16053@@ -30,13 +30,11 @@ wakeup_pmode_return:
16054 # and restore the stack ... but you need gdt for this to work
16055 movl saved_context_esp, %esp
16056
16057- movl %cs:saved_magic, %eax
16058- cmpl $0x12345678, %eax
16059+ cmpl $0x12345678, saved_magic
16060 jne bogus_magic
16061
16062 # jump to place where we left off
16063- movl saved_eip, %eax
16064- jmp *%eax
16065+ jmp *(saved_eip)
16066
16067 bogus_magic:
16068 jmp bogus_magic
16069diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16070index ef5ccca..bd83949 100644
16071--- a/arch/x86/kernel/alternative.c
16072+++ b/arch/x86/kernel/alternative.c
16073@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16074 */
16075 for (a = start; a < end; a++) {
16076 instr = (u8 *)&a->instr_offset + a->instr_offset;
16077+
16078+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16079+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16080+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16081+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16082+#endif
16083+
16084 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16085 BUG_ON(a->replacementlen > a->instrlen);
16086 BUG_ON(a->instrlen > sizeof(insnbuf));
16087@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16088 for (poff = start; poff < end; poff++) {
16089 u8 *ptr = (u8 *)poff + *poff;
16090
16091+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16092+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16093+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16094+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16095+#endif
16096+
16097 if (!*poff || ptr < text || ptr >= text_end)
16098 continue;
16099 /* turn DS segment override prefix into lock prefix */
16100- if (*ptr == 0x3e)
16101+ if (*ktla_ktva(ptr) == 0x3e)
16102 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16103 }
16104 mutex_unlock(&text_mutex);
16105@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16106 for (poff = start; poff < end; poff++) {
16107 u8 *ptr = (u8 *)poff + *poff;
16108
16109+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16110+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16111+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16112+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16113+#endif
16114+
16115 if (!*poff || ptr < text || ptr >= text_end)
16116 continue;
16117 /* turn lock prefix into DS segment override prefix */
16118- if (*ptr == 0xf0)
16119+ if (*ktla_ktva(ptr) == 0xf0)
16120 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16121 }
16122 mutex_unlock(&text_mutex);
16123@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16124
16125 BUG_ON(p->len > MAX_PATCH_LEN);
16126 /* prep the buffer with the original instructions */
16127- memcpy(insnbuf, p->instr, p->len);
16128+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16129 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16130 (unsigned long)p->instr, p->len);
16131
16132@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16133 if (!uniproc_patched || num_possible_cpus() == 1)
16134 free_init_pages("SMP alternatives",
16135 (unsigned long)__smp_locks,
16136- (unsigned long)__smp_locks_end);
16137+ PAGE_ALIGN((unsigned long)__smp_locks_end));
16138 #endif
16139
16140 apply_paravirt(__parainstructions, __parainstructions_end);
16141@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16142 * instructions. And on the local CPU you need to be protected again NMI or MCE
16143 * handlers seeing an inconsistent instruction while you patch.
16144 */
16145-void *__init_or_module text_poke_early(void *addr, const void *opcode,
16146+void *__kprobes text_poke_early(void *addr, const void *opcode,
16147 size_t len)
16148 {
16149 unsigned long flags;
16150 local_irq_save(flags);
16151- memcpy(addr, opcode, len);
16152+
16153+ pax_open_kernel();
16154+ memcpy(ktla_ktva(addr), opcode, len);
16155 sync_core();
16156+ pax_close_kernel();
16157+
16158 local_irq_restore(flags);
16159 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16160 that causes hangs on some VIA CPUs. */
16161@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16162 */
16163 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16164 {
16165- unsigned long flags;
16166- char *vaddr;
16167+ unsigned char *vaddr = ktla_ktva(addr);
16168 struct page *pages[2];
16169- int i;
16170+ size_t i;
16171
16172 if (!core_kernel_text((unsigned long)addr)) {
16173- pages[0] = vmalloc_to_page(addr);
16174- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16175+ pages[0] = vmalloc_to_page(vaddr);
16176+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16177 } else {
16178- pages[0] = virt_to_page(addr);
16179+ pages[0] = virt_to_page(vaddr);
16180 WARN_ON(!PageReserved(pages[0]));
16181- pages[1] = virt_to_page(addr + PAGE_SIZE);
16182+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16183 }
16184 BUG_ON(!pages[0]);
16185- local_irq_save(flags);
16186- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16187- if (pages[1])
16188- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16189- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16190- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16191- clear_fixmap(FIX_TEXT_POKE0);
16192- if (pages[1])
16193- clear_fixmap(FIX_TEXT_POKE1);
16194- local_flush_tlb();
16195- sync_core();
16196- /* Could also do a CLFLUSH here to speed up CPU recovery; but
16197- that causes hangs on some VIA CPUs. */
16198+ text_poke_early(addr, opcode, len);
16199 for (i = 0; i < len; i++)
16200- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16201- local_irq_restore(flags);
16202+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16203 return addr;
16204 }
16205
16206diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16207index b994cc8..812b537 100644
16208--- a/arch/x86/kernel/apic/apic.c
16209+++ b/arch/x86/kernel/apic/apic.c
16210@@ -131,7 +131,7 @@ static int __init parse_lapic(char *arg)
16211 {
16212 if (config_enabled(CONFIG_X86_32) && !arg)
16213 force_enable_local_apic = 1;
16214- else if (!strncmp(arg, "notscdeadline", 13))
16215+ else if (arg && !strncmp(arg, "notscdeadline", 13))
16216 setup_clear_cpu_cap(X86_FEATURE_TSC_DEADLINE_TIMER);
16217 return 0;
16218 }
16219@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16220 /*
16221 * Debug level, exported for io_apic.c
16222 */
16223-unsigned int apic_verbosity;
16224+int apic_verbosity;
16225
16226 int pic_mode;
16227
16228@@ -1956,7 +1956,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16229 apic_write(APIC_ESR, 0);
16230 v1 = apic_read(APIC_ESR);
16231 ack_APIC_irq();
16232- atomic_inc(&irq_err_count);
16233+ atomic_inc_unchecked(&irq_err_count);
16234
16235 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16236 smp_processor_id(), v0 , v1);
16237diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16238index 00c77cf..2dc6a2d 100644
16239--- a/arch/x86/kernel/apic/apic_flat_64.c
16240+++ b/arch/x86/kernel/apic/apic_flat_64.c
16241@@ -157,7 +157,7 @@ static int flat_probe(void)
16242 return 1;
16243 }
16244
16245-static struct apic apic_flat = {
16246+static struct apic apic_flat __read_only = {
16247 .name = "flat",
16248 .probe = flat_probe,
16249 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16250@@ -271,7 +271,7 @@ static int physflat_probe(void)
16251 return 0;
16252 }
16253
16254-static struct apic apic_physflat = {
16255+static struct apic apic_physflat __read_only = {
16256
16257 .name = "physical flat",
16258 .probe = physflat_probe,
16259diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16260index d50e364..543bee3 100644
16261--- a/arch/x86/kernel/apic/bigsmp_32.c
16262+++ b/arch/x86/kernel/apic/bigsmp_32.c
16263@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16264 return dmi_bigsmp;
16265 }
16266
16267-static struct apic apic_bigsmp = {
16268+static struct apic apic_bigsmp __read_only = {
16269
16270 .name = "bigsmp",
16271 .probe = probe_bigsmp,
16272diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16273index 0874799..24a836e 100644
16274--- a/arch/x86/kernel/apic/es7000_32.c
16275+++ b/arch/x86/kernel/apic/es7000_32.c
16276@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16277 return ret && es7000_apic_is_cluster();
16278 }
16279
16280-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16281-static struct apic __refdata apic_es7000_cluster = {
16282+static struct apic apic_es7000_cluster __read_only = {
16283
16284 .name = "es7000",
16285 .probe = probe_es7000,
16286@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16287 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16288 };
16289
16290-static struct apic __refdata apic_es7000 = {
16291+static struct apic __refdata apic_es7000 __read_only = {
16292
16293 .name = "es7000",
16294 .probe = probe_es7000,
16295diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16296index b739d39..6e4f1db 100644
16297--- a/arch/x86/kernel/apic/io_apic.c
16298+++ b/arch/x86/kernel/apic/io_apic.c
16299@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16300 }
16301 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16302
16303-void lock_vector_lock(void)
16304+void lock_vector_lock(void) __acquires(vector_lock)
16305 {
16306 /* Used to the online set of cpus does not change
16307 * during assign_irq_vector.
16308@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
16309 raw_spin_lock(&vector_lock);
16310 }
16311
16312-void unlock_vector_lock(void)
16313+void unlock_vector_lock(void) __releases(vector_lock)
16314 {
16315 raw_spin_unlock(&vector_lock);
16316 }
16317@@ -2399,7 +2399,7 @@ static void ack_apic_edge(struct irq_data *data)
16318 ack_APIC_irq();
16319 }
16320
16321-atomic_t irq_mis_count;
16322+atomic_unchecked_t irq_mis_count;
16323
16324 #ifdef CONFIG_GENERIC_PENDING_IRQ
16325 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16326@@ -2540,7 +2540,7 @@ static void ack_apic_level(struct irq_data *data)
16327 * at the cpu.
16328 */
16329 if (!(v & (1 << (i & 0x1f)))) {
16330- atomic_inc(&irq_mis_count);
16331+ atomic_inc_unchecked(&irq_mis_count);
16332
16333 eoi_ioapic_irq(irq, cfg);
16334 }
16335diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16336index d661ee9..791fd33 100644
16337--- a/arch/x86/kernel/apic/numaq_32.c
16338+++ b/arch/x86/kernel/apic/numaq_32.c
16339@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16340 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16341 }
16342
16343-/* Use __refdata to keep false positive warning calm. */
16344-static struct apic __refdata apic_numaq = {
16345+static struct apic apic_numaq __read_only = {
16346
16347 .name = "NUMAQ",
16348 .probe = probe_numaq,
16349diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16350index eb35ef9..f184a21 100644
16351--- a/arch/x86/kernel/apic/probe_32.c
16352+++ b/arch/x86/kernel/apic/probe_32.c
16353@@ -72,7 +72,7 @@ static int probe_default(void)
16354 return 1;
16355 }
16356
16357-static struct apic apic_default = {
16358+static struct apic apic_default __read_only = {
16359
16360 .name = "default",
16361 .probe = probe_default,
16362diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16363index 77c95c0..434f8a4 100644
16364--- a/arch/x86/kernel/apic/summit_32.c
16365+++ b/arch/x86/kernel/apic/summit_32.c
16366@@ -486,7 +486,7 @@ void setup_summit(void)
16367 }
16368 #endif
16369
16370-static struct apic apic_summit = {
16371+static struct apic apic_summit __read_only = {
16372
16373 .name = "summit",
16374 .probe = probe_summit,
16375diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16376index c88baa4..757aee1 100644
16377--- a/arch/x86/kernel/apic/x2apic_cluster.c
16378+++ b/arch/x86/kernel/apic/x2apic_cluster.c
16379@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
16380 return notifier_from_errno(err);
16381 }
16382
16383-static struct notifier_block __refdata x2apic_cpu_notifier = {
16384+static struct notifier_block x2apic_cpu_notifier = {
16385 .notifier_call = update_clusterinfo,
16386 };
16387
16388@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
16389 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
16390 }
16391
16392-static struct apic apic_x2apic_cluster = {
16393+static struct apic apic_x2apic_cluster __read_only = {
16394
16395 .name = "cluster x2apic",
16396 .probe = x2apic_cluster_probe,
16397diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
16398index 562a76d..a003c0f 100644
16399--- a/arch/x86/kernel/apic/x2apic_phys.c
16400+++ b/arch/x86/kernel/apic/x2apic_phys.c
16401@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
16402 return apic == &apic_x2apic_phys;
16403 }
16404
16405-static struct apic apic_x2apic_phys = {
16406+static struct apic apic_x2apic_phys __read_only = {
16407
16408 .name = "physical x2apic",
16409 .probe = x2apic_phys_probe,
16410diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
16411index 8cfade9..b9d04fc 100644
16412--- a/arch/x86/kernel/apic/x2apic_uv_x.c
16413+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
16414@@ -333,7 +333,7 @@ static int uv_probe(void)
16415 return apic == &apic_x2apic_uv_x;
16416 }
16417
16418-static struct apic __refdata apic_x2apic_uv_x = {
16419+static struct apic apic_x2apic_uv_x __read_only = {
16420
16421 .name = "UV large system",
16422 .probe = uv_probe,
16423diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
16424index d65464e..1035d31 100644
16425--- a/arch/x86/kernel/apm_32.c
16426+++ b/arch/x86/kernel/apm_32.c
16427@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
16428 * This is for buggy BIOS's that refer to (real mode) segment 0x40
16429 * even though they are called in protected mode.
16430 */
16431-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
16432+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
16433 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
16434
16435 static const char driver_version[] = "1.16ac"; /* no spaces */
16436@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
16437 BUG_ON(cpu != 0);
16438 gdt = get_cpu_gdt_table(cpu);
16439 save_desc_40 = gdt[0x40 / 8];
16440+
16441+ pax_open_kernel();
16442 gdt[0x40 / 8] = bad_bios_desc;
16443+ pax_close_kernel();
16444
16445 apm_irq_save(flags);
16446 APM_DO_SAVE_SEGS;
16447@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
16448 &call->esi);
16449 APM_DO_RESTORE_SEGS;
16450 apm_irq_restore(flags);
16451+
16452+ pax_open_kernel();
16453 gdt[0x40 / 8] = save_desc_40;
16454+ pax_close_kernel();
16455+
16456 put_cpu();
16457
16458 return call->eax & 0xff;
16459@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
16460 BUG_ON(cpu != 0);
16461 gdt = get_cpu_gdt_table(cpu);
16462 save_desc_40 = gdt[0x40 / 8];
16463+
16464+ pax_open_kernel();
16465 gdt[0x40 / 8] = bad_bios_desc;
16466+ pax_close_kernel();
16467
16468 apm_irq_save(flags);
16469 APM_DO_SAVE_SEGS;
16470@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
16471 &call->eax);
16472 APM_DO_RESTORE_SEGS;
16473 apm_irq_restore(flags);
16474+
16475+ pax_open_kernel();
16476 gdt[0x40 / 8] = save_desc_40;
16477+ pax_close_kernel();
16478+
16479 put_cpu();
16480 return error;
16481 }
16482@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
16483 * code to that CPU.
16484 */
16485 gdt = get_cpu_gdt_table(0);
16486+
16487+ pax_open_kernel();
16488 set_desc_base(&gdt[APM_CS >> 3],
16489 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
16490 set_desc_base(&gdt[APM_CS_16 >> 3],
16491 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
16492 set_desc_base(&gdt[APM_DS >> 3],
16493 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
16494+ pax_close_kernel();
16495
16496 proc_create("apm", 0, NULL, &apm_file_ops);
16497
16498diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
16499index 2861082..6d4718e 100644
16500--- a/arch/x86/kernel/asm-offsets.c
16501+++ b/arch/x86/kernel/asm-offsets.c
16502@@ -33,6 +33,8 @@ void common(void) {
16503 OFFSET(TI_status, thread_info, status);
16504 OFFSET(TI_addr_limit, thread_info, addr_limit);
16505 OFFSET(TI_preempt_count, thread_info, preempt_count);
16506+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
16507+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
16508
16509 BLANK();
16510 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
16511@@ -53,8 +55,26 @@ void common(void) {
16512 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
16513 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
16514 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
16515+
16516+#ifdef CONFIG_PAX_KERNEXEC
16517+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
16518 #endif
16519
16520+#ifdef CONFIG_PAX_MEMORY_UDEREF
16521+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
16522+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
16523+#ifdef CONFIG_X86_64
16524+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
16525+#endif
16526+#endif
16527+
16528+#endif
16529+
16530+ BLANK();
16531+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
16532+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
16533+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
16534+
16535 #ifdef CONFIG_XEN
16536 BLANK();
16537 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
16538diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
16539index 1b4754f..fbb4227 100644
16540--- a/arch/x86/kernel/asm-offsets_64.c
16541+++ b/arch/x86/kernel/asm-offsets_64.c
16542@@ -76,6 +76,7 @@ int main(void)
16543 BLANK();
16544 #undef ENTRY
16545
16546+ DEFINE(TSS_size, sizeof(struct tss_struct));
16547 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
16548 BLANK();
16549
16550diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
16551index a0e067d..9c7db16 100644
16552--- a/arch/x86/kernel/cpu/Makefile
16553+++ b/arch/x86/kernel/cpu/Makefile
16554@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
16555 CFLAGS_REMOVE_perf_event.o = -pg
16556 endif
16557
16558-# Make sure load_percpu_segment has no stackprotector
16559-nostackp := $(call cc-option, -fno-stack-protector)
16560-CFLAGS_common.o := $(nostackp)
16561-
16562 obj-y := intel_cacheinfo.o scattered.o topology.o
16563 obj-y += proc.o capflags.o powerflags.o common.o
16564 obj-y += vmware.o hypervisor.o mshyperv.o
16565diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
16566index 15239ff..e23e04e 100644
16567--- a/arch/x86/kernel/cpu/amd.c
16568+++ b/arch/x86/kernel/cpu/amd.c
16569@@ -733,7 +733,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
16570 unsigned int size)
16571 {
16572 /* AMD errata T13 (order #21922) */
16573- if ((c->x86 == 6)) {
16574+ if (c->x86 == 6) {
16575 /* Duron Rev A0 */
16576 if (c->x86_model == 3 && c->x86_mask == 0)
16577 size = 64;
16578diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
16579index 9c3ab43..51e6366 100644
16580--- a/arch/x86/kernel/cpu/common.c
16581+++ b/arch/x86/kernel/cpu/common.c
16582@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
16583
16584 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
16585
16586-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
16587-#ifdef CONFIG_X86_64
16588- /*
16589- * We need valid kernel segments for data and code in long mode too
16590- * IRET will check the segment types kkeil 2000/10/28
16591- * Also sysret mandates a special GDT layout
16592- *
16593- * TLS descriptors are currently at a different place compared to i386.
16594- * Hopefully nobody expects them at a fixed place (Wine?)
16595- */
16596- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
16597- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
16598- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
16599- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
16600- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
16601- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
16602-#else
16603- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
16604- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16605- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
16606- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
16607- /*
16608- * Segments used for calling PnP BIOS have byte granularity.
16609- * They code segments and data segments have fixed 64k limits,
16610- * the transfer segment sizes are set at run time.
16611- */
16612- /* 32-bit code */
16613- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
16614- /* 16-bit code */
16615- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
16616- /* 16-bit data */
16617- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
16618- /* 16-bit data */
16619- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
16620- /* 16-bit data */
16621- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
16622- /*
16623- * The APM segments have byte granularity and their bases
16624- * are set at run time. All have 64k limits.
16625- */
16626- /* 32-bit code */
16627- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
16628- /* 16-bit code */
16629- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
16630- /* data */
16631- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
16632-
16633- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16634- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16635- GDT_STACK_CANARY_INIT
16636-#endif
16637-} };
16638-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
16639-
16640 static int __init x86_xsave_setup(char *s)
16641 {
16642 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
16643@@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
16644 {
16645 struct desc_ptr gdt_descr;
16646
16647- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
16648+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
16649 gdt_descr.size = GDT_SIZE - 1;
16650 load_gdt(&gdt_descr);
16651 /* Reload the per-cpu base */
16652@@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
16653 /* Filter out anything that depends on CPUID levels we don't have */
16654 filter_cpuid_features(c, true);
16655
16656+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16657+ setup_clear_cpu_cap(X86_FEATURE_SEP);
16658+#endif
16659+
16660 /* If the model name is still unset, do table lookup. */
16661 if (!c->x86_model_id[0]) {
16662 const char *p;
16663@@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
16664 }
16665 __setup("clearcpuid=", setup_disablecpuid);
16666
16667+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
16668+EXPORT_PER_CPU_SYMBOL(current_tinfo);
16669+
16670 #ifdef CONFIG_X86_64
16671 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
16672-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
16673- (unsigned long) nmi_idt_table };
16674+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
16675
16676 DEFINE_PER_CPU_FIRST(union irq_stack_union,
16677 irq_stack_union) __aligned(PAGE_SIZE);
16678@@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
16679 EXPORT_PER_CPU_SYMBOL(current_task);
16680
16681 DEFINE_PER_CPU(unsigned long, kernel_stack) =
16682- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
16683+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
16684 EXPORT_PER_CPU_SYMBOL(kernel_stack);
16685
16686 DEFINE_PER_CPU(char *, irq_stack_ptr) =
16687@@ -1224,7 +1176,7 @@ void __cpuinit cpu_init(void)
16688 int i;
16689
16690 cpu = stack_smp_processor_id();
16691- t = &per_cpu(init_tss, cpu);
16692+ t = init_tss + cpu;
16693 oist = &per_cpu(orig_ist, cpu);
16694
16695 #ifdef CONFIG_NUMA
16696@@ -1250,7 +1202,7 @@ void __cpuinit cpu_init(void)
16697 switch_to_new_gdt(cpu);
16698 loadsegment(fs, 0);
16699
16700- load_idt((const struct desc_ptr *)&idt_descr);
16701+ load_idt(&idt_descr);
16702
16703 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
16704 syscall_init();
16705@@ -1259,7 +1211,6 @@ void __cpuinit cpu_init(void)
16706 wrmsrl(MSR_KERNEL_GS_BASE, 0);
16707 barrier();
16708
16709- x86_configure_nx();
16710 enable_x2apic();
16711
16712 /*
16713@@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
16714 {
16715 int cpu = smp_processor_id();
16716 struct task_struct *curr = current;
16717- struct tss_struct *t = &per_cpu(init_tss, cpu);
16718+ struct tss_struct *t = init_tss + cpu;
16719 struct thread_struct *thread = &curr->thread;
16720
16721 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
16722diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
16723index fcaabd0..7b55a26 100644
16724--- a/arch/x86/kernel/cpu/intel.c
16725+++ b/arch/x86/kernel/cpu/intel.c
16726@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
16727 * Update the IDT descriptor and reload the IDT so that
16728 * it uses the read-only mapped virtual address.
16729 */
16730- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
16731+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
16732 load_idt(&idt_descr);
16733 }
16734 #endif
16735diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
16736index 84c1309..39b7224 100644
16737--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
16738+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
16739@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
16740 };
16741
16742 #ifdef CONFIG_AMD_NB
16743+static struct attribute *default_attrs_amd_nb[] = {
16744+ &type.attr,
16745+ &level.attr,
16746+ &coherency_line_size.attr,
16747+ &physical_line_partition.attr,
16748+ &ways_of_associativity.attr,
16749+ &number_of_sets.attr,
16750+ &size.attr,
16751+ &shared_cpu_map.attr,
16752+ &shared_cpu_list.attr,
16753+ NULL,
16754+ NULL,
16755+ NULL,
16756+ NULL
16757+};
16758+
16759 static struct attribute ** __cpuinit amd_l3_attrs(void)
16760 {
16761 static struct attribute **attrs;
16762@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
16763
16764 n = ARRAY_SIZE(default_attrs);
16765
16766- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
16767- n += 2;
16768-
16769- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
16770- n += 1;
16771-
16772- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
16773- if (attrs == NULL)
16774- return attrs = default_attrs;
16775-
16776- for (n = 0; default_attrs[n]; n++)
16777- attrs[n] = default_attrs[n];
16778+ attrs = default_attrs_amd_nb;
16779
16780 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
16781 attrs[n++] = &cache_disable_0.attr;
16782@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
16783 .default_attrs = default_attrs,
16784 };
16785
16786+#ifdef CONFIG_AMD_NB
16787+static struct kobj_type ktype_cache_amd_nb = {
16788+ .sysfs_ops = &sysfs_ops,
16789+ .default_attrs = default_attrs_amd_nb,
16790+};
16791+#endif
16792+
16793 static struct kobj_type ktype_percpu_entry = {
16794 .sysfs_ops = &sysfs_ops,
16795 };
16796@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
16797 return retval;
16798 }
16799
16800+#ifdef CONFIG_AMD_NB
16801+ amd_l3_attrs();
16802+#endif
16803+
16804 for (i = 0; i < num_cache_leaves; i++) {
16805+ struct kobj_type *ktype;
16806+
16807 this_object = INDEX_KOBJECT_PTR(cpu, i);
16808 this_object->cpu = cpu;
16809 this_object->index = i;
16810
16811 this_leaf = CPUID4_INFO_IDX(cpu, i);
16812
16813- ktype_cache.default_attrs = default_attrs;
16814+ ktype = &ktype_cache;
16815 #ifdef CONFIG_AMD_NB
16816 if (this_leaf->base.nb)
16817- ktype_cache.default_attrs = amd_l3_attrs();
16818+ ktype = &ktype_cache_amd_nb;
16819 #endif
16820 retval = kobject_init_and_add(&(this_object->kobj),
16821- &ktype_cache,
16822+ ktype,
16823 per_cpu(ici_cache_kobject, cpu),
16824 "index%1lu", i);
16825 if (unlikely(retval)) {
16826@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
16827 return NOTIFY_OK;
16828 }
16829
16830-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
16831+static struct notifier_block cacheinfo_cpu_notifier = {
16832 .notifier_call = cacheinfo_cpu_callback,
16833 };
16834
16835diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
16836index 80dbda8..b45ebad 100644
16837--- a/arch/x86/kernel/cpu/mcheck/mce.c
16838+++ b/arch/x86/kernel/cpu/mcheck/mce.c
16839@@ -45,6 +45,7 @@
16840 #include <asm/processor.h>
16841 #include <asm/mce.h>
16842 #include <asm/msr.h>
16843+#include <asm/local.h>
16844
16845 #include "mce-internal.h"
16846
16847@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
16848 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
16849 m->cs, m->ip);
16850
16851- if (m->cs == __KERNEL_CS)
16852+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
16853 print_symbol("{%s}", m->ip);
16854 pr_cont("\n");
16855 }
16856@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
16857
16858 #define PANIC_TIMEOUT 5 /* 5 seconds */
16859
16860-static atomic_t mce_paniced;
16861+static atomic_unchecked_t mce_paniced;
16862
16863 static int fake_panic;
16864-static atomic_t mce_fake_paniced;
16865+static atomic_unchecked_t mce_fake_paniced;
16866
16867 /* Panic in progress. Enable interrupts and wait for final IPI */
16868 static void wait_for_panic(void)
16869@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
16870 /*
16871 * Make sure only one CPU runs in machine check panic
16872 */
16873- if (atomic_inc_return(&mce_paniced) > 1)
16874+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
16875 wait_for_panic();
16876 barrier();
16877
16878@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
16879 console_verbose();
16880 } else {
16881 /* Don't log too much for fake panic */
16882- if (atomic_inc_return(&mce_fake_paniced) > 1)
16883+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
16884 return;
16885 }
16886 /* First print corrected ones that are still unlogged */
16887@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
16888 * might have been modified by someone else.
16889 */
16890 rmb();
16891- if (atomic_read(&mce_paniced))
16892+ if (atomic_read_unchecked(&mce_paniced))
16893 wait_for_panic();
16894 if (!mca_cfg.monarch_timeout)
16895 goto out;
16896@@ -1662,7 +1663,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
16897 }
16898
16899 /* Call the installed machine check handler for this CPU setup. */
16900-void (*machine_check_vector)(struct pt_regs *, long error_code) =
16901+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
16902 unexpected_machine_check;
16903
16904 /*
16905@@ -1685,7 +1686,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
16906 return;
16907 }
16908
16909+ pax_open_kernel();
16910 machine_check_vector = do_machine_check;
16911+ pax_close_kernel();
16912
16913 __mcheck_cpu_init_generic();
16914 __mcheck_cpu_init_vendor(c);
16915@@ -1699,7 +1702,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
16916 */
16917
16918 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
16919-static int mce_chrdev_open_count; /* #times opened */
16920+static local_t mce_chrdev_open_count; /* #times opened */
16921 static int mce_chrdev_open_exclu; /* already open exclusive? */
16922
16923 static int mce_chrdev_open(struct inode *inode, struct file *file)
16924@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
16925 spin_lock(&mce_chrdev_state_lock);
16926
16927 if (mce_chrdev_open_exclu ||
16928- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
16929+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
16930 spin_unlock(&mce_chrdev_state_lock);
16931
16932 return -EBUSY;
16933@@ -1715,7 +1718,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
16934
16935 if (file->f_flags & O_EXCL)
16936 mce_chrdev_open_exclu = 1;
16937- mce_chrdev_open_count++;
16938+ local_inc(&mce_chrdev_open_count);
16939
16940 spin_unlock(&mce_chrdev_state_lock);
16941
16942@@ -1726,7 +1729,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
16943 {
16944 spin_lock(&mce_chrdev_state_lock);
16945
16946- mce_chrdev_open_count--;
16947+ local_dec(&mce_chrdev_open_count);
16948 mce_chrdev_open_exclu = 0;
16949
16950 spin_unlock(&mce_chrdev_state_lock);
16951@@ -2372,7 +2375,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
16952 return NOTIFY_OK;
16953 }
16954
16955-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
16956+static struct notifier_block mce_cpu_notifier = {
16957 .notifier_call = mce_cpu_callback,
16958 };
16959
16960@@ -2450,7 +2453,7 @@ struct dentry *mce_get_debugfs_dir(void)
16961 static void mce_reset(void)
16962 {
16963 cpu_missing = 0;
16964- atomic_set(&mce_fake_paniced, 0);
16965+ atomic_set_unchecked(&mce_fake_paniced, 0);
16966 atomic_set(&mce_executing, 0);
16967 atomic_set(&mce_callin, 0);
16968 atomic_set(&global_nwo, 0);
16969diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
16970index 2d5454c..51987eb 100644
16971--- a/arch/x86/kernel/cpu/mcheck/p5.c
16972+++ b/arch/x86/kernel/cpu/mcheck/p5.c
16973@@ -11,6 +11,7 @@
16974 #include <asm/processor.h>
16975 #include <asm/mce.h>
16976 #include <asm/msr.h>
16977+#include <asm/pgtable.h>
16978
16979 /* By default disabled */
16980 int mce_p5_enabled __read_mostly;
16981@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
16982 if (!cpu_has(c, X86_FEATURE_MCE))
16983 return;
16984
16985+ pax_open_kernel();
16986 machine_check_vector = pentium_machine_check;
16987+ pax_close_kernel();
16988 /* Make sure the vector pointer is visible before we enable MCEs: */
16989 wmb();
16990
16991diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
16992index 47a1870..8c019a7 100644
16993--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
16994+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
16995@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
16996 return notifier_from_errno(err);
16997 }
16998
16999-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17000+static struct notifier_block thermal_throttle_cpu_notifier =
17001 {
17002 .notifier_call = thermal_throttle_cpu_callback,
17003 };
17004diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17005index 2d7998f..17c9de1 100644
17006--- a/arch/x86/kernel/cpu/mcheck/winchip.c
17007+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17008@@ -10,6 +10,7 @@
17009 #include <asm/processor.h>
17010 #include <asm/mce.h>
17011 #include <asm/msr.h>
17012+#include <asm/pgtable.h>
17013
17014 /* Machine check handler for WinChip C6: */
17015 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17016@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17017 {
17018 u32 lo, hi;
17019
17020+ pax_open_kernel();
17021 machine_check_vector = winchip_machine_check;
17022+ pax_close_kernel();
17023 /* Make sure the vector pointer is visible before we enable MCEs: */
17024 wmb();
17025
17026diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17027index 726bf96..81f0526 100644
17028--- a/arch/x86/kernel/cpu/mtrr/main.c
17029+++ b/arch/x86/kernel/cpu/mtrr/main.c
17030@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17031 u64 size_or_mask, size_and_mask;
17032 static bool mtrr_aps_delayed_init;
17033
17034-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17035+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17036
17037 const struct mtrr_ops *mtrr_if;
17038
17039diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17040index df5e41f..816c719 100644
17041--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17042+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17043@@ -25,7 +25,7 @@ struct mtrr_ops {
17044 int (*validate_add_page)(unsigned long base, unsigned long size,
17045 unsigned int type);
17046 int (*have_wrcomb)(void);
17047-};
17048+} __do_const;
17049
17050 extern int generic_get_free_region(unsigned long base, unsigned long size,
17051 int replace_reg);
17052diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17053index 6774c17..a691911 100644
17054--- a/arch/x86/kernel/cpu/perf_event.c
17055+++ b/arch/x86/kernel/cpu/perf_event.c
17056@@ -1880,7 +1880,7 @@ static unsigned long get_segment_base(unsigned int segment)
17057 if (idx > GDT_ENTRIES)
17058 return 0;
17059
17060- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17061+ desc = get_cpu_gdt_table(smp_processor_id());
17062 }
17063
17064 return get_desc_base(desc + idx);
17065@@ -1970,7 +1970,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17066 break;
17067
17068 perf_callchain_store(entry, frame.return_address);
17069- fp = frame.next_frame;
17070+ fp = (const void __force_user *)frame.next_frame;
17071 }
17072 }
17073
17074diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17075index 4914e94..60b06e3 100644
17076--- a/arch/x86/kernel/cpu/perf_event_intel.c
17077+++ b/arch/x86/kernel/cpu/perf_event_intel.c
17078@@ -1958,10 +1958,10 @@ __init int intel_pmu_init(void)
17079 * v2 and above have a perf capabilities MSR
17080 */
17081 if (version > 1) {
17082- u64 capabilities;
17083+ u64 capabilities = x86_pmu.intel_cap.capabilities;
17084
17085- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17086- x86_pmu.intel_cap.capabilities = capabilities;
17087+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17088+ x86_pmu.intel_cap.capabilities = capabilities;
17089 }
17090
17091 intel_ds_init();
17092diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17093index b43200d..62cddfe 100644
17094--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17095+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17096@@ -2826,7 +2826,7 @@ static int
17097 return NOTIFY_OK;
17098 }
17099
17100-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17101+static struct notifier_block uncore_cpu_nb = {
17102 .notifier_call = uncore_cpu_notifier,
17103 /*
17104 * to migrate uncore events, our notifier should be executed
17105diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17106index 60c7891..9e911d3 100644
17107--- a/arch/x86/kernel/cpuid.c
17108+++ b/arch/x86/kernel/cpuid.c
17109@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17110 return notifier_from_errno(err);
17111 }
17112
17113-static struct notifier_block __refdata cpuid_class_cpu_notifier =
17114+static struct notifier_block cpuid_class_cpu_notifier =
17115 {
17116 .notifier_call = cpuid_class_cpu_callback,
17117 };
17118diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17119index 74467fe..18793d5 100644
17120--- a/arch/x86/kernel/crash.c
17121+++ b/arch/x86/kernel/crash.c
17122@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17123 {
17124 #ifdef CONFIG_X86_32
17125 struct pt_regs fixed_regs;
17126-#endif
17127
17128-#ifdef CONFIG_X86_32
17129- if (!user_mode_vm(regs)) {
17130+ if (!user_mode(regs)) {
17131 crash_fixup_ss_esp(&fixed_regs, regs);
17132 regs = &fixed_regs;
17133 }
17134diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17135index 37250fe..bf2ec74 100644
17136--- a/arch/x86/kernel/doublefault_32.c
17137+++ b/arch/x86/kernel/doublefault_32.c
17138@@ -11,7 +11,7 @@
17139
17140 #define DOUBLEFAULT_STACKSIZE (1024)
17141 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17142-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17143+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17144
17145 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17146
17147@@ -21,7 +21,7 @@ static void doublefault_fn(void)
17148 unsigned long gdt, tss;
17149
17150 store_gdt(&gdt_desc);
17151- gdt = gdt_desc.address;
17152+ gdt = (unsigned long)gdt_desc.address;
17153
17154 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17155
17156@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17157 /* 0x2 bit is always set */
17158 .flags = X86_EFLAGS_SF | 0x2,
17159 .sp = STACK_START,
17160- .es = __USER_DS,
17161+ .es = __KERNEL_DS,
17162 .cs = __KERNEL_CS,
17163 .ss = __KERNEL_DS,
17164- .ds = __USER_DS,
17165+ .ds = __KERNEL_DS,
17166 .fs = __KERNEL_PERCPU,
17167
17168 .__cr3 = __pa_nodebug(swapper_pg_dir),
17169diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17170index ae42418b..787c16b 100644
17171--- a/arch/x86/kernel/dumpstack.c
17172+++ b/arch/x86/kernel/dumpstack.c
17173@@ -2,6 +2,9 @@
17174 * Copyright (C) 1991, 1992 Linus Torvalds
17175 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17176 */
17177+#ifdef CONFIG_GRKERNSEC_HIDESYM
17178+#define __INCLUDED_BY_HIDESYM 1
17179+#endif
17180 #include <linux/kallsyms.h>
17181 #include <linux/kprobes.h>
17182 #include <linux/uaccess.h>
17183@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17184 static void
17185 print_ftrace_graph_addr(unsigned long addr, void *data,
17186 const struct stacktrace_ops *ops,
17187- struct thread_info *tinfo, int *graph)
17188+ struct task_struct *task, int *graph)
17189 {
17190- struct task_struct *task;
17191 unsigned long ret_addr;
17192 int index;
17193
17194 if (addr != (unsigned long)return_to_handler)
17195 return;
17196
17197- task = tinfo->task;
17198 index = task->curr_ret_stack;
17199
17200 if (!task->ret_stack || index < *graph)
17201@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17202 static inline void
17203 print_ftrace_graph_addr(unsigned long addr, void *data,
17204 const struct stacktrace_ops *ops,
17205- struct thread_info *tinfo, int *graph)
17206+ struct task_struct *task, int *graph)
17207 { }
17208 #endif
17209
17210@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17211 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17212 */
17213
17214-static inline int valid_stack_ptr(struct thread_info *tinfo,
17215- void *p, unsigned int size, void *end)
17216+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17217 {
17218- void *t = tinfo;
17219 if (end) {
17220 if (p < end && p >= (end-THREAD_SIZE))
17221 return 1;
17222@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17223 }
17224
17225 unsigned long
17226-print_context_stack(struct thread_info *tinfo,
17227+print_context_stack(struct task_struct *task, void *stack_start,
17228 unsigned long *stack, unsigned long bp,
17229 const struct stacktrace_ops *ops, void *data,
17230 unsigned long *end, int *graph)
17231 {
17232 struct stack_frame *frame = (struct stack_frame *)bp;
17233
17234- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17235+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17236 unsigned long addr;
17237
17238 addr = *stack;
17239@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17240 } else {
17241 ops->address(data, addr, 0);
17242 }
17243- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17244+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17245 }
17246 stack++;
17247 }
17248@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17249 EXPORT_SYMBOL_GPL(print_context_stack);
17250
17251 unsigned long
17252-print_context_stack_bp(struct thread_info *tinfo,
17253+print_context_stack_bp(struct task_struct *task, void *stack_start,
17254 unsigned long *stack, unsigned long bp,
17255 const struct stacktrace_ops *ops, void *data,
17256 unsigned long *end, int *graph)
17257@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17258 struct stack_frame *frame = (struct stack_frame *)bp;
17259 unsigned long *ret_addr = &frame->return_address;
17260
17261- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17262+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17263 unsigned long addr = *ret_addr;
17264
17265 if (!__kernel_text_address(addr))
17266@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17267 ops->address(data, addr, 1);
17268 frame = frame->next_frame;
17269 ret_addr = &frame->return_address;
17270- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17271+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17272 }
17273
17274 return (unsigned long)frame;
17275@@ -189,7 +188,7 @@ void dump_stack(void)
17276
17277 bp = stack_frame(current, NULL);
17278 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
17279- current->pid, current->comm, print_tainted(),
17280+ task_pid_nr(current), current->comm, print_tainted(),
17281 init_utsname()->release,
17282 (int)strcspn(init_utsname()->version, " "),
17283 init_utsname()->version);
17284@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
17285 }
17286 EXPORT_SYMBOL_GPL(oops_begin);
17287
17288+extern void gr_handle_kernel_exploit(void);
17289+
17290 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17291 {
17292 if (regs && kexec_should_crash(current))
17293@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17294 panic("Fatal exception in interrupt");
17295 if (panic_on_oops)
17296 panic("Fatal exception");
17297- do_exit(signr);
17298+
17299+ gr_handle_kernel_exploit();
17300+
17301+ do_group_exit(signr);
17302 }
17303
17304 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17305@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17306 print_modules();
17307 show_regs(regs);
17308 #ifdef CONFIG_X86_32
17309- if (user_mode_vm(regs)) {
17310+ if (user_mode(regs)) {
17311 sp = regs->sp;
17312 ss = regs->ss & 0xffff;
17313 } else {
17314@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
17315 unsigned long flags = oops_begin();
17316 int sig = SIGSEGV;
17317
17318- if (!user_mode_vm(regs))
17319+ if (!user_mode(regs))
17320 report_bug(regs->ip, regs);
17321
17322 if (__die(str, regs, err))
17323diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
17324index 1038a41..db2c12b 100644
17325--- a/arch/x86/kernel/dumpstack_32.c
17326+++ b/arch/x86/kernel/dumpstack_32.c
17327@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17328 bp = stack_frame(task, regs);
17329
17330 for (;;) {
17331- struct thread_info *context;
17332+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17333
17334- context = (struct thread_info *)
17335- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
17336- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
17337+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17338
17339- stack = (unsigned long *)context->previous_esp;
17340- if (!stack)
17341+ if (stack_start == task_stack_page(task))
17342 break;
17343+ stack = *(unsigned long **)stack_start;
17344 if (ops->stack(data, "IRQ") < 0)
17345 break;
17346 touch_nmi_watchdog();
17347@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
17348 {
17349 int i;
17350
17351- __show_regs(regs, !user_mode_vm(regs));
17352+ __show_regs(regs, !user_mode(regs));
17353
17354 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
17355 TASK_COMM_LEN, current->comm, task_pid_nr(current),
17356@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
17357 * When in-kernel, we also print out the stack and code at the
17358 * time of the fault..
17359 */
17360- if (!user_mode_vm(regs)) {
17361+ if (!user_mode(regs)) {
17362 unsigned int code_prologue = code_bytes * 43 / 64;
17363 unsigned int code_len = code_bytes;
17364 unsigned char c;
17365 u8 *ip;
17366+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
17367
17368 pr_emerg("Stack:\n");
17369 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
17370
17371 pr_emerg("Code:");
17372
17373- ip = (u8 *)regs->ip - code_prologue;
17374+ ip = (u8 *)regs->ip - code_prologue + cs_base;
17375 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
17376 /* try starting at IP */
17377- ip = (u8 *)regs->ip;
17378+ ip = (u8 *)regs->ip + cs_base;
17379 code_len = code_len - code_prologue + 1;
17380 }
17381 for (i = 0; i < code_len; i++, ip++) {
17382@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
17383 pr_cont(" Bad EIP value.");
17384 break;
17385 }
17386- if (ip == (u8 *)regs->ip)
17387+ if (ip == (u8 *)regs->ip + cs_base)
17388 pr_cont(" <%02x>", c);
17389 else
17390 pr_cont(" %02x", c);
17391@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
17392 {
17393 unsigned short ud2;
17394
17395+ ip = ktla_ktva(ip);
17396 if (ip < PAGE_OFFSET)
17397 return 0;
17398 if (probe_kernel_address((unsigned short *)ip, ud2))
17399@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
17400
17401 return ud2 == 0x0b0f;
17402 }
17403+
17404+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17405+void pax_check_alloca(unsigned long size)
17406+{
17407+ unsigned long sp = (unsigned long)&sp, stack_left;
17408+
17409+ /* all kernel stacks are of the same size */
17410+ stack_left = sp & (THREAD_SIZE - 1);
17411+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17412+}
17413+EXPORT_SYMBOL(pax_check_alloca);
17414+#endif
17415diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
17416index b653675..51cc8c0 100644
17417--- a/arch/x86/kernel/dumpstack_64.c
17418+++ b/arch/x86/kernel/dumpstack_64.c
17419@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17420 unsigned long *irq_stack_end =
17421 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
17422 unsigned used = 0;
17423- struct thread_info *tinfo;
17424 int graph = 0;
17425 unsigned long dummy;
17426+ void *stack_start;
17427
17428 if (!task)
17429 task = current;
17430@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17431 * current stack address. If the stacks consist of nested
17432 * exceptions
17433 */
17434- tinfo = task_thread_info(task);
17435 for (;;) {
17436 char *id;
17437 unsigned long *estack_end;
17438+
17439 estack_end = in_exception_stack(cpu, (unsigned long)stack,
17440 &used, &id);
17441
17442@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17443 if (ops->stack(data, id) < 0)
17444 break;
17445
17446- bp = ops->walk_stack(tinfo, stack, bp, ops,
17447+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
17448 data, estack_end, &graph);
17449 ops->stack(data, "<EOE>");
17450 /*
17451@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17452 * second-to-last pointer (index -2 to end) in the
17453 * exception stack:
17454 */
17455+ if ((u16)estack_end[-1] != __KERNEL_DS)
17456+ goto out;
17457 stack = (unsigned long *) estack_end[-2];
17458 continue;
17459 }
17460@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17461 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
17462 if (ops->stack(data, "IRQ") < 0)
17463 break;
17464- bp = ops->walk_stack(tinfo, stack, bp,
17465+ bp = ops->walk_stack(task, irq_stack, stack, bp,
17466 ops, data, irq_stack_end, &graph);
17467 /*
17468 * We link to the next stack (which would be
17469@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17470 /*
17471 * This handles the process stack:
17472 */
17473- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
17474+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17475+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17476+out:
17477 put_cpu();
17478 }
17479 EXPORT_SYMBOL(dump_trace);
17480@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
17481 {
17482 int i;
17483 unsigned long sp;
17484- const int cpu = smp_processor_id();
17485+ const int cpu = raw_smp_processor_id();
17486 struct task_struct *cur = current;
17487
17488 sp = regs->sp;
17489@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
17490
17491 return ud2 == 0x0b0f;
17492 }
17493+
17494+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17495+void pax_check_alloca(unsigned long size)
17496+{
17497+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
17498+ unsigned cpu, used;
17499+ char *id;
17500+
17501+ /* check the process stack first */
17502+ stack_start = (unsigned long)task_stack_page(current);
17503+ stack_end = stack_start + THREAD_SIZE;
17504+ if (likely(stack_start <= sp && sp < stack_end)) {
17505+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
17506+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17507+ return;
17508+ }
17509+
17510+ cpu = get_cpu();
17511+
17512+ /* check the irq stacks */
17513+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
17514+ stack_start = stack_end - IRQ_STACK_SIZE;
17515+ if (stack_start <= sp && sp < stack_end) {
17516+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
17517+ put_cpu();
17518+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17519+ return;
17520+ }
17521+
17522+ /* check the exception stacks */
17523+ used = 0;
17524+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
17525+ stack_start = stack_end - EXCEPTION_STKSZ;
17526+ if (stack_end && stack_start <= sp && sp < stack_end) {
17527+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
17528+ put_cpu();
17529+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17530+ return;
17531+ }
17532+
17533+ put_cpu();
17534+
17535+ /* unknown stack */
17536+ BUG();
17537+}
17538+EXPORT_SYMBOL(pax_check_alloca);
17539+#endif
17540diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
17541index 9b9f18b..9fcaa04 100644
17542--- a/arch/x86/kernel/early_printk.c
17543+++ b/arch/x86/kernel/early_printk.c
17544@@ -7,6 +7,7 @@
17545 #include <linux/pci_regs.h>
17546 #include <linux/pci_ids.h>
17547 #include <linux/errno.h>
17548+#include <linux/sched.h>
17549 #include <asm/io.h>
17550 #include <asm/processor.h>
17551 #include <asm/fcntl.h>
17552diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
17553index 6ed91d9..6cc365b 100644
17554--- a/arch/x86/kernel/entry_32.S
17555+++ b/arch/x86/kernel/entry_32.S
17556@@ -177,13 +177,153 @@
17557 /*CFI_REL_OFFSET gs, PT_GS*/
17558 .endm
17559 .macro SET_KERNEL_GS reg
17560+
17561+#ifdef CONFIG_CC_STACKPROTECTOR
17562 movl $(__KERNEL_STACK_CANARY), \reg
17563+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17564+ movl $(__USER_DS), \reg
17565+#else
17566+ xorl \reg, \reg
17567+#endif
17568+
17569 movl \reg, %gs
17570 .endm
17571
17572 #endif /* CONFIG_X86_32_LAZY_GS */
17573
17574-.macro SAVE_ALL
17575+.macro pax_enter_kernel
17576+#ifdef CONFIG_PAX_KERNEXEC
17577+ call pax_enter_kernel
17578+#endif
17579+.endm
17580+
17581+.macro pax_exit_kernel
17582+#ifdef CONFIG_PAX_KERNEXEC
17583+ call pax_exit_kernel
17584+#endif
17585+.endm
17586+
17587+#ifdef CONFIG_PAX_KERNEXEC
17588+ENTRY(pax_enter_kernel)
17589+#ifdef CONFIG_PARAVIRT
17590+ pushl %eax
17591+ pushl %ecx
17592+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
17593+ mov %eax, %esi
17594+#else
17595+ mov %cr0, %esi
17596+#endif
17597+ bts $16, %esi
17598+ jnc 1f
17599+ mov %cs, %esi
17600+ cmp $__KERNEL_CS, %esi
17601+ jz 3f
17602+ ljmp $__KERNEL_CS, $3f
17603+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
17604+2:
17605+#ifdef CONFIG_PARAVIRT
17606+ mov %esi, %eax
17607+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17608+#else
17609+ mov %esi, %cr0
17610+#endif
17611+3:
17612+#ifdef CONFIG_PARAVIRT
17613+ popl %ecx
17614+ popl %eax
17615+#endif
17616+ ret
17617+ENDPROC(pax_enter_kernel)
17618+
17619+ENTRY(pax_exit_kernel)
17620+#ifdef CONFIG_PARAVIRT
17621+ pushl %eax
17622+ pushl %ecx
17623+#endif
17624+ mov %cs, %esi
17625+ cmp $__KERNEXEC_KERNEL_CS, %esi
17626+ jnz 2f
17627+#ifdef CONFIG_PARAVIRT
17628+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
17629+ mov %eax, %esi
17630+#else
17631+ mov %cr0, %esi
17632+#endif
17633+ btr $16, %esi
17634+ ljmp $__KERNEL_CS, $1f
17635+1:
17636+#ifdef CONFIG_PARAVIRT
17637+ mov %esi, %eax
17638+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
17639+#else
17640+ mov %esi, %cr0
17641+#endif
17642+2:
17643+#ifdef CONFIG_PARAVIRT
17644+ popl %ecx
17645+ popl %eax
17646+#endif
17647+ ret
17648+ENDPROC(pax_exit_kernel)
17649+#endif
17650+
17651+.macro pax_erase_kstack
17652+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17653+ call pax_erase_kstack
17654+#endif
17655+.endm
17656+
17657+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17658+/*
17659+ * ebp: thread_info
17660+ */
17661+ENTRY(pax_erase_kstack)
17662+ pushl %edi
17663+ pushl %ecx
17664+ pushl %eax
17665+
17666+ mov TI_lowest_stack(%ebp), %edi
17667+ mov $-0xBEEF, %eax
17668+ std
17669+
17670+1: mov %edi, %ecx
17671+ and $THREAD_SIZE_asm - 1, %ecx
17672+ shr $2, %ecx
17673+ repne scasl
17674+ jecxz 2f
17675+
17676+ cmp $2*16, %ecx
17677+ jc 2f
17678+
17679+ mov $2*16, %ecx
17680+ repe scasl
17681+ jecxz 2f
17682+ jne 1b
17683+
17684+2: cld
17685+ mov %esp, %ecx
17686+ sub %edi, %ecx
17687+
17688+ cmp $THREAD_SIZE_asm, %ecx
17689+ jb 3f
17690+ ud2
17691+3:
17692+
17693+ shr $2, %ecx
17694+ rep stosl
17695+
17696+ mov TI_task_thread_sp0(%ebp), %edi
17697+ sub $128, %edi
17698+ mov %edi, TI_lowest_stack(%ebp)
17699+
17700+ popl %eax
17701+ popl %ecx
17702+ popl %edi
17703+ ret
17704+ENDPROC(pax_erase_kstack)
17705+#endif
17706+
17707+.macro __SAVE_ALL _DS
17708 cld
17709 PUSH_GS
17710 pushl_cfi %fs
17711@@ -206,7 +346,7 @@
17712 CFI_REL_OFFSET ecx, 0
17713 pushl_cfi %ebx
17714 CFI_REL_OFFSET ebx, 0
17715- movl $(__USER_DS), %edx
17716+ movl $\_DS, %edx
17717 movl %edx, %ds
17718 movl %edx, %es
17719 movl $(__KERNEL_PERCPU), %edx
17720@@ -214,6 +354,15 @@
17721 SET_KERNEL_GS %edx
17722 .endm
17723
17724+.macro SAVE_ALL
17725+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
17726+ __SAVE_ALL __KERNEL_DS
17727+ pax_enter_kernel
17728+#else
17729+ __SAVE_ALL __USER_DS
17730+#endif
17731+.endm
17732+
17733 .macro RESTORE_INT_REGS
17734 popl_cfi %ebx
17735 CFI_RESTORE ebx
17736@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
17737 popfl_cfi
17738 jmp syscall_exit
17739 CFI_ENDPROC
17740-END(ret_from_fork)
17741+ENDPROC(ret_from_fork)
17742
17743 ENTRY(ret_from_kernel_thread)
17744 CFI_STARTPROC
17745@@ -344,7 +493,15 @@ ret_from_intr:
17746 andl $SEGMENT_RPL_MASK, %eax
17747 #endif
17748 cmpl $USER_RPL, %eax
17749+
17750+#ifdef CONFIG_PAX_KERNEXEC
17751+ jae resume_userspace
17752+
17753+ pax_exit_kernel
17754+ jmp resume_kernel
17755+#else
17756 jb resume_kernel # not returning to v8086 or userspace
17757+#endif
17758
17759 ENTRY(resume_userspace)
17760 LOCKDEP_SYS_EXIT
17761@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
17762 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
17763 # int/exception return?
17764 jne work_pending
17765- jmp restore_all
17766-END(ret_from_exception)
17767+ jmp restore_all_pax
17768+ENDPROC(ret_from_exception)
17769
17770 #ifdef CONFIG_PREEMPT
17771 ENTRY(resume_kernel)
17772@@ -372,7 +529,7 @@ need_resched:
17773 jz restore_all
17774 call preempt_schedule_irq
17775 jmp need_resched
17776-END(resume_kernel)
17777+ENDPROC(resume_kernel)
17778 #endif
17779 CFI_ENDPROC
17780 /*
17781@@ -406,30 +563,45 @@ sysenter_past_esp:
17782 /*CFI_REL_OFFSET cs, 0*/
17783 /*
17784 * Push current_thread_info()->sysenter_return to the stack.
17785- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
17786- * pushed above; +8 corresponds to copy_thread's esp0 setting.
17787 */
17788- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
17789+ pushl_cfi $0
17790 CFI_REL_OFFSET eip, 0
17791
17792 pushl_cfi %eax
17793 SAVE_ALL
17794+ GET_THREAD_INFO(%ebp)
17795+ movl TI_sysenter_return(%ebp),%ebp
17796+ movl %ebp,PT_EIP(%esp)
17797 ENABLE_INTERRUPTS(CLBR_NONE)
17798
17799 /*
17800 * Load the potential sixth argument from user stack.
17801 * Careful about security.
17802 */
17803+ movl PT_OLDESP(%esp),%ebp
17804+
17805+#ifdef CONFIG_PAX_MEMORY_UDEREF
17806+ mov PT_OLDSS(%esp),%ds
17807+1: movl %ds:(%ebp),%ebp
17808+ push %ss
17809+ pop %ds
17810+#else
17811 cmpl $__PAGE_OFFSET-3,%ebp
17812 jae syscall_fault
17813 ASM_STAC
17814 1: movl (%ebp),%ebp
17815 ASM_CLAC
17816+#endif
17817+
17818 movl %ebp,PT_EBP(%esp)
17819 _ASM_EXTABLE(1b,syscall_fault)
17820
17821 GET_THREAD_INFO(%ebp)
17822
17823+#ifdef CONFIG_PAX_RANDKSTACK
17824+ pax_erase_kstack
17825+#endif
17826+
17827 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
17828 jnz sysenter_audit
17829 sysenter_do_call:
17830@@ -444,12 +616,24 @@ sysenter_do_call:
17831 testl $_TIF_ALLWORK_MASK, %ecx
17832 jne sysexit_audit
17833 sysenter_exit:
17834+
17835+#ifdef CONFIG_PAX_RANDKSTACK
17836+ pushl_cfi %eax
17837+ movl %esp, %eax
17838+ call pax_randomize_kstack
17839+ popl_cfi %eax
17840+#endif
17841+
17842+ pax_erase_kstack
17843+
17844 /* if something modifies registers it must also disable sysexit */
17845 movl PT_EIP(%esp), %edx
17846 movl PT_OLDESP(%esp), %ecx
17847 xorl %ebp,%ebp
17848 TRACE_IRQS_ON
17849 1: mov PT_FS(%esp), %fs
17850+2: mov PT_DS(%esp), %ds
17851+3: mov PT_ES(%esp), %es
17852 PTGS_TO_GS
17853 ENABLE_INTERRUPTS_SYSEXIT
17854
17855@@ -466,6 +650,9 @@ sysenter_audit:
17856 movl %eax,%edx /* 2nd arg: syscall number */
17857 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
17858 call __audit_syscall_entry
17859+
17860+ pax_erase_kstack
17861+
17862 pushl_cfi %ebx
17863 movl PT_EAX(%esp),%eax /* reload syscall number */
17864 jmp sysenter_do_call
17865@@ -491,10 +678,16 @@ sysexit_audit:
17866
17867 CFI_ENDPROC
17868 .pushsection .fixup,"ax"
17869-2: movl $0,PT_FS(%esp)
17870+4: movl $0,PT_FS(%esp)
17871+ jmp 1b
17872+5: movl $0,PT_DS(%esp)
17873+ jmp 1b
17874+6: movl $0,PT_ES(%esp)
17875 jmp 1b
17876 .popsection
17877- _ASM_EXTABLE(1b,2b)
17878+ _ASM_EXTABLE(1b,4b)
17879+ _ASM_EXTABLE(2b,5b)
17880+ _ASM_EXTABLE(3b,6b)
17881 PTGS_TO_GS_EX
17882 ENDPROC(ia32_sysenter_target)
17883
17884@@ -509,6 +702,11 @@ ENTRY(system_call)
17885 pushl_cfi %eax # save orig_eax
17886 SAVE_ALL
17887 GET_THREAD_INFO(%ebp)
17888+
17889+#ifdef CONFIG_PAX_RANDKSTACK
17890+ pax_erase_kstack
17891+#endif
17892+
17893 # system call tracing in operation / emulation
17894 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
17895 jnz syscall_trace_entry
17896@@ -527,6 +725,15 @@ syscall_exit:
17897 testl $_TIF_ALLWORK_MASK, %ecx # current->work
17898 jne syscall_exit_work
17899
17900+restore_all_pax:
17901+
17902+#ifdef CONFIG_PAX_RANDKSTACK
17903+ movl %esp, %eax
17904+ call pax_randomize_kstack
17905+#endif
17906+
17907+ pax_erase_kstack
17908+
17909 restore_all:
17910 TRACE_IRQS_IRET
17911 restore_all_notrace:
17912@@ -583,14 +790,34 @@ ldt_ss:
17913 * compensating for the offset by changing to the ESPFIX segment with
17914 * a base address that matches for the difference.
17915 */
17916-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
17917+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
17918 mov %esp, %edx /* load kernel esp */
17919 mov PT_OLDESP(%esp), %eax /* load userspace esp */
17920 mov %dx, %ax /* eax: new kernel esp */
17921 sub %eax, %edx /* offset (low word is 0) */
17922+#ifdef CONFIG_SMP
17923+ movl PER_CPU_VAR(cpu_number), %ebx
17924+ shll $PAGE_SHIFT_asm, %ebx
17925+ addl $cpu_gdt_table, %ebx
17926+#else
17927+ movl $cpu_gdt_table, %ebx
17928+#endif
17929 shr $16, %edx
17930- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
17931- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
17932+
17933+#ifdef CONFIG_PAX_KERNEXEC
17934+ mov %cr0, %esi
17935+ btr $16, %esi
17936+ mov %esi, %cr0
17937+#endif
17938+
17939+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
17940+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
17941+
17942+#ifdef CONFIG_PAX_KERNEXEC
17943+ bts $16, %esi
17944+ mov %esi, %cr0
17945+#endif
17946+
17947 pushl_cfi $__ESPFIX_SS
17948 pushl_cfi %eax /* new kernel esp */
17949 /* Disable interrupts, but do not irqtrace this section: we
17950@@ -619,20 +846,18 @@ work_resched:
17951 movl TI_flags(%ebp), %ecx
17952 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
17953 # than syscall tracing?
17954- jz restore_all
17955+ jz restore_all_pax
17956 testb $_TIF_NEED_RESCHED, %cl
17957 jnz work_resched
17958
17959 work_notifysig: # deal with pending signals and
17960 # notify-resume requests
17961+ movl %esp, %eax
17962 #ifdef CONFIG_VM86
17963 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
17964- movl %esp, %eax
17965 jne work_notifysig_v86 # returning to kernel-space or
17966 # vm86-space
17967 1:
17968-#else
17969- movl %esp, %eax
17970 #endif
17971 TRACE_IRQS_ON
17972 ENABLE_INTERRUPTS(CLBR_NONE)
17973@@ -653,7 +878,7 @@ work_notifysig_v86:
17974 movl %eax, %esp
17975 jmp 1b
17976 #endif
17977-END(work_pending)
17978+ENDPROC(work_pending)
17979
17980 # perform syscall exit tracing
17981 ALIGN
17982@@ -661,11 +886,14 @@ syscall_trace_entry:
17983 movl $-ENOSYS,PT_EAX(%esp)
17984 movl %esp, %eax
17985 call syscall_trace_enter
17986+
17987+ pax_erase_kstack
17988+
17989 /* What it returned is what we'll actually use. */
17990 cmpl $(NR_syscalls), %eax
17991 jnae syscall_call
17992 jmp syscall_exit
17993-END(syscall_trace_entry)
17994+ENDPROC(syscall_trace_entry)
17995
17996 # perform syscall exit tracing
17997 ALIGN
17998@@ -678,21 +906,25 @@ syscall_exit_work:
17999 movl %esp, %eax
18000 call syscall_trace_leave
18001 jmp resume_userspace
18002-END(syscall_exit_work)
18003+ENDPROC(syscall_exit_work)
18004 CFI_ENDPROC
18005
18006 RING0_INT_FRAME # can't unwind into user space anyway
18007 syscall_fault:
18008+#ifdef CONFIG_PAX_MEMORY_UDEREF
18009+ push %ss
18010+ pop %ds
18011+#endif
18012 ASM_CLAC
18013 GET_THREAD_INFO(%ebp)
18014 movl $-EFAULT,PT_EAX(%esp)
18015 jmp resume_userspace
18016-END(syscall_fault)
18017+ENDPROC(syscall_fault)
18018
18019 syscall_badsys:
18020 movl $-ENOSYS,PT_EAX(%esp)
18021 jmp resume_userspace
18022-END(syscall_badsys)
18023+ENDPROC(syscall_badsys)
18024 CFI_ENDPROC
18025 /*
18026 * End of kprobes section
18027@@ -753,8 +985,15 @@ PTREGSCALL1(vm86old)
18028 * normal stack and adjusts ESP with the matching offset.
18029 */
18030 /* fixup the stack */
18031- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18032- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18033+#ifdef CONFIG_SMP
18034+ movl PER_CPU_VAR(cpu_number), %ebx
18035+ shll $PAGE_SHIFT_asm, %ebx
18036+ addl $cpu_gdt_table, %ebx
18037+#else
18038+ movl $cpu_gdt_table, %ebx
18039+#endif
18040+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18041+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18042 shl $16, %eax
18043 addl %esp, %eax /* the adjusted stack pointer */
18044 pushl_cfi $__KERNEL_DS
18045@@ -807,7 +1046,7 @@ vector=vector+1
18046 .endr
18047 2: jmp common_interrupt
18048 .endr
18049-END(irq_entries_start)
18050+ENDPROC(irq_entries_start)
18051
18052 .previous
18053 END(interrupt)
18054@@ -858,7 +1097,7 @@ ENTRY(coprocessor_error)
18055 pushl_cfi $do_coprocessor_error
18056 jmp error_code
18057 CFI_ENDPROC
18058-END(coprocessor_error)
18059+ENDPROC(coprocessor_error)
18060
18061 ENTRY(simd_coprocessor_error)
18062 RING0_INT_FRAME
18063@@ -880,7 +1119,7 @@ ENTRY(simd_coprocessor_error)
18064 #endif
18065 jmp error_code
18066 CFI_ENDPROC
18067-END(simd_coprocessor_error)
18068+ENDPROC(simd_coprocessor_error)
18069
18070 ENTRY(device_not_available)
18071 RING0_INT_FRAME
18072@@ -889,18 +1128,18 @@ ENTRY(device_not_available)
18073 pushl_cfi $do_device_not_available
18074 jmp error_code
18075 CFI_ENDPROC
18076-END(device_not_available)
18077+ENDPROC(device_not_available)
18078
18079 #ifdef CONFIG_PARAVIRT
18080 ENTRY(native_iret)
18081 iret
18082 _ASM_EXTABLE(native_iret, iret_exc)
18083-END(native_iret)
18084+ENDPROC(native_iret)
18085
18086 ENTRY(native_irq_enable_sysexit)
18087 sti
18088 sysexit
18089-END(native_irq_enable_sysexit)
18090+ENDPROC(native_irq_enable_sysexit)
18091 #endif
18092
18093 ENTRY(overflow)
18094@@ -910,7 +1149,7 @@ ENTRY(overflow)
18095 pushl_cfi $do_overflow
18096 jmp error_code
18097 CFI_ENDPROC
18098-END(overflow)
18099+ENDPROC(overflow)
18100
18101 ENTRY(bounds)
18102 RING0_INT_FRAME
18103@@ -919,7 +1158,7 @@ ENTRY(bounds)
18104 pushl_cfi $do_bounds
18105 jmp error_code
18106 CFI_ENDPROC
18107-END(bounds)
18108+ENDPROC(bounds)
18109
18110 ENTRY(invalid_op)
18111 RING0_INT_FRAME
18112@@ -928,7 +1167,7 @@ ENTRY(invalid_op)
18113 pushl_cfi $do_invalid_op
18114 jmp error_code
18115 CFI_ENDPROC
18116-END(invalid_op)
18117+ENDPROC(invalid_op)
18118
18119 ENTRY(coprocessor_segment_overrun)
18120 RING0_INT_FRAME
18121@@ -937,7 +1176,7 @@ ENTRY(coprocessor_segment_overrun)
18122 pushl_cfi $do_coprocessor_segment_overrun
18123 jmp error_code
18124 CFI_ENDPROC
18125-END(coprocessor_segment_overrun)
18126+ENDPROC(coprocessor_segment_overrun)
18127
18128 ENTRY(invalid_TSS)
18129 RING0_EC_FRAME
18130@@ -945,7 +1184,7 @@ ENTRY(invalid_TSS)
18131 pushl_cfi $do_invalid_TSS
18132 jmp error_code
18133 CFI_ENDPROC
18134-END(invalid_TSS)
18135+ENDPROC(invalid_TSS)
18136
18137 ENTRY(segment_not_present)
18138 RING0_EC_FRAME
18139@@ -953,7 +1192,7 @@ ENTRY(segment_not_present)
18140 pushl_cfi $do_segment_not_present
18141 jmp error_code
18142 CFI_ENDPROC
18143-END(segment_not_present)
18144+ENDPROC(segment_not_present)
18145
18146 ENTRY(stack_segment)
18147 RING0_EC_FRAME
18148@@ -961,7 +1200,7 @@ ENTRY(stack_segment)
18149 pushl_cfi $do_stack_segment
18150 jmp error_code
18151 CFI_ENDPROC
18152-END(stack_segment)
18153+ENDPROC(stack_segment)
18154
18155 ENTRY(alignment_check)
18156 RING0_EC_FRAME
18157@@ -969,7 +1208,7 @@ ENTRY(alignment_check)
18158 pushl_cfi $do_alignment_check
18159 jmp error_code
18160 CFI_ENDPROC
18161-END(alignment_check)
18162+ENDPROC(alignment_check)
18163
18164 ENTRY(divide_error)
18165 RING0_INT_FRAME
18166@@ -978,7 +1217,7 @@ ENTRY(divide_error)
18167 pushl_cfi $do_divide_error
18168 jmp error_code
18169 CFI_ENDPROC
18170-END(divide_error)
18171+ENDPROC(divide_error)
18172
18173 #ifdef CONFIG_X86_MCE
18174 ENTRY(machine_check)
18175@@ -988,7 +1227,7 @@ ENTRY(machine_check)
18176 pushl_cfi machine_check_vector
18177 jmp error_code
18178 CFI_ENDPROC
18179-END(machine_check)
18180+ENDPROC(machine_check)
18181 #endif
18182
18183 ENTRY(spurious_interrupt_bug)
18184@@ -998,7 +1237,7 @@ ENTRY(spurious_interrupt_bug)
18185 pushl_cfi $do_spurious_interrupt_bug
18186 jmp error_code
18187 CFI_ENDPROC
18188-END(spurious_interrupt_bug)
18189+ENDPROC(spurious_interrupt_bug)
18190 /*
18191 * End of kprobes section
18192 */
18193@@ -1101,7 +1340,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
18194
18195 ENTRY(mcount)
18196 ret
18197-END(mcount)
18198+ENDPROC(mcount)
18199
18200 ENTRY(ftrace_caller)
18201 cmpl $0, function_trace_stop
18202@@ -1134,7 +1373,7 @@ ftrace_graph_call:
18203 .globl ftrace_stub
18204 ftrace_stub:
18205 ret
18206-END(ftrace_caller)
18207+ENDPROC(ftrace_caller)
18208
18209 ENTRY(ftrace_regs_caller)
18210 pushf /* push flags before compare (in cs location) */
18211@@ -1235,7 +1474,7 @@ trace:
18212 popl %ecx
18213 popl %eax
18214 jmp ftrace_stub
18215-END(mcount)
18216+ENDPROC(mcount)
18217 #endif /* CONFIG_DYNAMIC_FTRACE */
18218 #endif /* CONFIG_FUNCTION_TRACER */
18219
18220@@ -1253,7 +1492,7 @@ ENTRY(ftrace_graph_caller)
18221 popl %ecx
18222 popl %eax
18223 ret
18224-END(ftrace_graph_caller)
18225+ENDPROC(ftrace_graph_caller)
18226
18227 .globl return_to_handler
18228 return_to_handler:
18229@@ -1309,15 +1548,18 @@ error_code:
18230 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18231 REG_TO_PTGS %ecx
18232 SET_KERNEL_GS %ecx
18233- movl $(__USER_DS), %ecx
18234+ movl $(__KERNEL_DS), %ecx
18235 movl %ecx, %ds
18236 movl %ecx, %es
18237+
18238+ pax_enter_kernel
18239+
18240 TRACE_IRQS_OFF
18241 movl %esp,%eax # pt_regs pointer
18242 call *%edi
18243 jmp ret_from_exception
18244 CFI_ENDPROC
18245-END(page_fault)
18246+ENDPROC(page_fault)
18247
18248 /*
18249 * Debug traps and NMI can happen at the one SYSENTER instruction
18250@@ -1360,7 +1602,7 @@ debug_stack_correct:
18251 call do_debug
18252 jmp ret_from_exception
18253 CFI_ENDPROC
18254-END(debug)
18255+ENDPROC(debug)
18256
18257 /*
18258 * NMI is doubly nasty. It can happen _while_ we're handling
18259@@ -1398,6 +1640,9 @@ nmi_stack_correct:
18260 xorl %edx,%edx # zero error code
18261 movl %esp,%eax # pt_regs pointer
18262 call do_nmi
18263+
18264+ pax_exit_kernel
18265+
18266 jmp restore_all_notrace
18267 CFI_ENDPROC
18268
18269@@ -1434,12 +1679,15 @@ nmi_espfix_stack:
18270 FIXUP_ESPFIX_STACK # %eax == %esp
18271 xorl %edx,%edx # zero error code
18272 call do_nmi
18273+
18274+ pax_exit_kernel
18275+
18276 RESTORE_REGS
18277 lss 12+4(%esp), %esp # back to espfix stack
18278 CFI_ADJUST_CFA_OFFSET -24
18279 jmp irq_return
18280 CFI_ENDPROC
18281-END(nmi)
18282+ENDPROC(nmi)
18283
18284 ENTRY(int3)
18285 RING0_INT_FRAME
18286@@ -1452,14 +1700,14 @@ ENTRY(int3)
18287 call do_int3
18288 jmp ret_from_exception
18289 CFI_ENDPROC
18290-END(int3)
18291+ENDPROC(int3)
18292
18293 ENTRY(general_protection)
18294 RING0_EC_FRAME
18295 pushl_cfi $do_general_protection
18296 jmp error_code
18297 CFI_ENDPROC
18298-END(general_protection)
18299+ENDPROC(general_protection)
18300
18301 #ifdef CONFIG_KVM_GUEST
18302 ENTRY(async_page_fault)
18303@@ -1468,7 +1716,7 @@ ENTRY(async_page_fault)
18304 pushl_cfi $do_async_page_fault
18305 jmp error_code
18306 CFI_ENDPROC
18307-END(async_page_fault)
18308+ENDPROC(async_page_fault)
18309 #endif
18310
18311 /*
18312diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
18313index cb3c591..bc63707 100644
18314--- a/arch/x86/kernel/entry_64.S
18315+++ b/arch/x86/kernel/entry_64.S
18316@@ -59,6 +59,8 @@
18317 #include <asm/context_tracking.h>
18318 #include <asm/smap.h>
18319 #include <linux/err.h>
18320+#include <asm/pgtable.h>
18321+#include <asm/alternative-asm.h>
18322
18323 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
18324 #include <linux/elf-em.h>
18325@@ -80,8 +82,9 @@
18326 #ifdef CONFIG_DYNAMIC_FTRACE
18327
18328 ENTRY(function_hook)
18329+ pax_force_retaddr
18330 retq
18331-END(function_hook)
18332+ENDPROC(function_hook)
18333
18334 /* skip is set if stack has been adjusted */
18335 .macro ftrace_caller_setup skip=0
18336@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
18337 #endif
18338
18339 GLOBAL(ftrace_stub)
18340+ pax_force_retaddr
18341 retq
18342-END(ftrace_caller)
18343+ENDPROC(ftrace_caller)
18344
18345 ENTRY(ftrace_regs_caller)
18346 /* Save the current flags before compare (in SS location)*/
18347@@ -191,7 +195,7 @@ ftrace_restore_flags:
18348 popfq
18349 jmp ftrace_stub
18350
18351-END(ftrace_regs_caller)
18352+ENDPROC(ftrace_regs_caller)
18353
18354
18355 #else /* ! CONFIG_DYNAMIC_FTRACE */
18356@@ -212,6 +216,7 @@ ENTRY(function_hook)
18357 #endif
18358
18359 GLOBAL(ftrace_stub)
18360+ pax_force_retaddr
18361 retq
18362
18363 trace:
18364@@ -225,12 +230,13 @@ trace:
18365 #endif
18366 subq $MCOUNT_INSN_SIZE, %rdi
18367
18368+ pax_force_fptr ftrace_trace_function
18369 call *ftrace_trace_function
18370
18371 MCOUNT_RESTORE_FRAME
18372
18373 jmp ftrace_stub
18374-END(function_hook)
18375+ENDPROC(function_hook)
18376 #endif /* CONFIG_DYNAMIC_FTRACE */
18377 #endif /* CONFIG_FUNCTION_TRACER */
18378
18379@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
18380
18381 MCOUNT_RESTORE_FRAME
18382
18383+ pax_force_retaddr
18384 retq
18385-END(ftrace_graph_caller)
18386+ENDPROC(ftrace_graph_caller)
18387
18388 GLOBAL(return_to_handler)
18389 subq $24, %rsp
18390@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
18391 movq 8(%rsp), %rdx
18392 movq (%rsp), %rax
18393 addq $24, %rsp
18394+ pax_force_fptr %rdi
18395 jmp *%rdi
18396+ENDPROC(return_to_handler)
18397 #endif
18398
18399
18400@@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
18401 ENDPROC(native_usergs_sysret64)
18402 #endif /* CONFIG_PARAVIRT */
18403
18404+ .macro ljmpq sel, off
18405+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
18406+ .byte 0x48; ljmp *1234f(%rip)
18407+ .pushsection .rodata
18408+ .align 16
18409+ 1234: .quad \off; .word \sel
18410+ .popsection
18411+#else
18412+ pushq $\sel
18413+ pushq $\off
18414+ lretq
18415+#endif
18416+ .endm
18417+
18418+ .macro pax_enter_kernel
18419+ pax_set_fptr_mask
18420+#ifdef CONFIG_PAX_KERNEXEC
18421+ call pax_enter_kernel
18422+#endif
18423+ .endm
18424+
18425+ .macro pax_exit_kernel
18426+#ifdef CONFIG_PAX_KERNEXEC
18427+ call pax_exit_kernel
18428+#endif
18429+ .endm
18430+
18431+#ifdef CONFIG_PAX_KERNEXEC
18432+ENTRY(pax_enter_kernel)
18433+ pushq %rdi
18434+
18435+#ifdef CONFIG_PARAVIRT
18436+ PV_SAVE_REGS(CLBR_RDI)
18437+#endif
18438+
18439+ GET_CR0_INTO_RDI
18440+ bts $16,%rdi
18441+ jnc 3f
18442+ mov %cs,%edi
18443+ cmp $__KERNEL_CS,%edi
18444+ jnz 2f
18445+1:
18446+
18447+#ifdef CONFIG_PARAVIRT
18448+ PV_RESTORE_REGS(CLBR_RDI)
18449+#endif
18450+
18451+ popq %rdi
18452+ pax_force_retaddr
18453+ retq
18454+
18455+2: ljmpq __KERNEL_CS,1f
18456+3: ljmpq __KERNEXEC_KERNEL_CS,4f
18457+4: SET_RDI_INTO_CR0
18458+ jmp 1b
18459+ENDPROC(pax_enter_kernel)
18460+
18461+ENTRY(pax_exit_kernel)
18462+ pushq %rdi
18463+
18464+#ifdef CONFIG_PARAVIRT
18465+ PV_SAVE_REGS(CLBR_RDI)
18466+#endif
18467+
18468+ mov %cs,%rdi
18469+ cmp $__KERNEXEC_KERNEL_CS,%edi
18470+ jz 2f
18471+1:
18472+
18473+#ifdef CONFIG_PARAVIRT
18474+ PV_RESTORE_REGS(CLBR_RDI);
18475+#endif
18476+
18477+ popq %rdi
18478+ pax_force_retaddr
18479+ retq
18480+
18481+2: GET_CR0_INTO_RDI
18482+ btr $16,%rdi
18483+ ljmpq __KERNEL_CS,3f
18484+3: SET_RDI_INTO_CR0
18485+ jmp 1b
18486+ENDPROC(pax_exit_kernel)
18487+#endif
18488+
18489+ .macro pax_enter_kernel_user
18490+ pax_set_fptr_mask
18491+#ifdef CONFIG_PAX_MEMORY_UDEREF
18492+ call pax_enter_kernel_user
18493+#endif
18494+ .endm
18495+
18496+ .macro pax_exit_kernel_user
18497+#ifdef CONFIG_PAX_MEMORY_UDEREF
18498+ call pax_exit_kernel_user
18499+#endif
18500+#ifdef CONFIG_PAX_RANDKSTACK
18501+ pushq %rax
18502+ call pax_randomize_kstack
18503+ popq %rax
18504+#endif
18505+ .endm
18506+
18507+#ifdef CONFIG_PAX_MEMORY_UDEREF
18508+ENTRY(pax_enter_kernel_user)
18509+ pushq %rdi
18510+ pushq %rbx
18511+
18512+#ifdef CONFIG_PARAVIRT
18513+ PV_SAVE_REGS(CLBR_RDI)
18514+#endif
18515+
18516+ GET_CR3_INTO_RDI
18517+ mov %rdi,%rbx
18518+ add $__START_KERNEL_map,%rbx
18519+ sub phys_base(%rip),%rbx
18520+
18521+#ifdef CONFIG_PARAVIRT
18522+ pushq %rdi
18523+ cmpl $0, pv_info+PARAVIRT_enabled
18524+ jz 1f
18525+ i = 0
18526+ .rept USER_PGD_PTRS
18527+ mov i*8(%rbx),%rsi
18528+ mov $0,%sil
18529+ lea i*8(%rbx),%rdi
18530+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
18531+ i = i + 1
18532+ .endr
18533+ jmp 2f
18534+1:
18535+#endif
18536+
18537+ i = 0
18538+ .rept USER_PGD_PTRS
18539+ movb $0,i*8(%rbx)
18540+ i = i + 1
18541+ .endr
18542+
18543+#ifdef CONFIG_PARAVIRT
18544+2: popq %rdi
18545+#endif
18546+ SET_RDI_INTO_CR3
18547+
18548+#ifdef CONFIG_PAX_KERNEXEC
18549+ GET_CR0_INTO_RDI
18550+ bts $16,%rdi
18551+ SET_RDI_INTO_CR0
18552+#endif
18553+
18554+#ifdef CONFIG_PARAVIRT
18555+ PV_RESTORE_REGS(CLBR_RDI)
18556+#endif
18557+
18558+ popq %rbx
18559+ popq %rdi
18560+ pax_force_retaddr
18561+ retq
18562+ENDPROC(pax_enter_kernel_user)
18563+
18564+ENTRY(pax_exit_kernel_user)
18565+ push %rdi
18566+
18567+#ifdef CONFIG_PARAVIRT
18568+ pushq %rbx
18569+ PV_SAVE_REGS(CLBR_RDI)
18570+#endif
18571+
18572+#ifdef CONFIG_PAX_KERNEXEC
18573+ GET_CR0_INTO_RDI
18574+ btr $16,%rdi
18575+ SET_RDI_INTO_CR0
18576+#endif
18577+
18578+ GET_CR3_INTO_RDI
18579+ add $__START_KERNEL_map,%rdi
18580+ sub phys_base(%rip),%rdi
18581+
18582+#ifdef CONFIG_PARAVIRT
18583+ cmpl $0, pv_info+PARAVIRT_enabled
18584+ jz 1f
18585+ mov %rdi,%rbx
18586+ i = 0
18587+ .rept USER_PGD_PTRS
18588+ mov i*8(%rbx),%rsi
18589+ mov $0x67,%sil
18590+ lea i*8(%rbx),%rdi
18591+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
18592+ i = i + 1
18593+ .endr
18594+ jmp 2f
18595+1:
18596+#endif
18597+
18598+ i = 0
18599+ .rept USER_PGD_PTRS
18600+ movb $0x67,i*8(%rdi)
18601+ i = i + 1
18602+ .endr
18603+
18604+#ifdef CONFIG_PARAVIRT
18605+2: PV_RESTORE_REGS(CLBR_RDI)
18606+ popq %rbx
18607+#endif
18608+
18609+ popq %rdi
18610+ pax_force_retaddr
18611+ retq
18612+ENDPROC(pax_exit_kernel_user)
18613+#endif
18614+
18615+.macro pax_erase_kstack
18616+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18617+ call pax_erase_kstack
18618+#endif
18619+.endm
18620+
18621+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18622+ENTRY(pax_erase_kstack)
18623+ pushq %rdi
18624+ pushq %rcx
18625+ pushq %rax
18626+ pushq %r11
18627+
18628+ GET_THREAD_INFO(%r11)
18629+ mov TI_lowest_stack(%r11), %rdi
18630+ mov $-0xBEEF, %rax
18631+ std
18632+
18633+1: mov %edi, %ecx
18634+ and $THREAD_SIZE_asm - 1, %ecx
18635+ shr $3, %ecx
18636+ repne scasq
18637+ jecxz 2f
18638+
18639+ cmp $2*8, %ecx
18640+ jc 2f
18641+
18642+ mov $2*8, %ecx
18643+ repe scasq
18644+ jecxz 2f
18645+ jne 1b
18646+
18647+2: cld
18648+ mov %esp, %ecx
18649+ sub %edi, %ecx
18650+
18651+ cmp $THREAD_SIZE_asm, %rcx
18652+ jb 3f
18653+ ud2
18654+3:
18655+
18656+ shr $3, %ecx
18657+ rep stosq
18658+
18659+ mov TI_task_thread_sp0(%r11), %rdi
18660+ sub $256, %rdi
18661+ mov %rdi, TI_lowest_stack(%r11)
18662+
18663+ popq %r11
18664+ popq %rax
18665+ popq %rcx
18666+ popq %rdi
18667+ pax_force_retaddr
18668+ ret
18669+ENDPROC(pax_erase_kstack)
18670+#endif
18671
18672 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
18673 #ifdef CONFIG_TRACE_IRQFLAGS
18674@@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
18675 .endm
18676
18677 .macro UNFAKE_STACK_FRAME
18678- addq $8*6, %rsp
18679- CFI_ADJUST_CFA_OFFSET -(6*8)
18680+ addq $8*6 + ARG_SKIP, %rsp
18681+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
18682 .endm
18683
18684 /*
18685@@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
18686 movq %rsp, %rsi
18687
18688 leaq -RBP(%rsp),%rdi /* arg1 for handler */
18689- testl $3, CS-RBP(%rsi)
18690+ testb $3, CS-RBP(%rsi)
18691 je 1f
18692 SWAPGS
18693 /*
18694@@ -498,9 +774,10 @@ ENTRY(save_rest)
18695 movq_cfi r15, R15+16
18696 movq %r11, 8(%rsp) /* return address */
18697 FIXUP_TOP_OF_STACK %r11, 16
18698+ pax_force_retaddr
18699 ret
18700 CFI_ENDPROC
18701-END(save_rest)
18702+ENDPROC(save_rest)
18703
18704 /* save complete stack frame */
18705 .pushsection .kprobes.text, "ax"
18706@@ -529,9 +806,10 @@ ENTRY(save_paranoid)
18707 js 1f /* negative -> in kernel */
18708 SWAPGS
18709 xorl %ebx,%ebx
18710-1: ret
18711+1: pax_force_retaddr_bts
18712+ ret
18713 CFI_ENDPROC
18714-END(save_paranoid)
18715+ENDPROC(save_paranoid)
18716 .popsection
18717
18718 /*
18719@@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
18720
18721 RESTORE_REST
18722
18723- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
18724+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
18725 jz 1f
18726
18727 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
18728@@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
18729 RESTORE_REST
18730 jmp int_ret_from_sys_call
18731 CFI_ENDPROC
18732-END(ret_from_fork)
18733+ENDPROC(ret_from_fork)
18734
18735 /*
18736 * System call entry. Up to 6 arguments in registers are supported.
18737@@ -608,7 +886,7 @@ END(ret_from_fork)
18738 ENTRY(system_call)
18739 CFI_STARTPROC simple
18740 CFI_SIGNAL_FRAME
18741- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
18742+ CFI_DEF_CFA rsp,0
18743 CFI_REGISTER rip,rcx
18744 /*CFI_REGISTER rflags,r11*/
18745 SWAPGS_UNSAFE_STACK
18746@@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
18747
18748 movq %rsp,PER_CPU_VAR(old_rsp)
18749 movq PER_CPU_VAR(kernel_stack),%rsp
18750+ SAVE_ARGS 8*6,0
18751+ pax_enter_kernel_user
18752+
18753+#ifdef CONFIG_PAX_RANDKSTACK
18754+ pax_erase_kstack
18755+#endif
18756+
18757 /*
18758 * No need to follow this irqs off/on section - it's straight
18759 * and short:
18760 */
18761 ENABLE_INTERRUPTS(CLBR_NONE)
18762- SAVE_ARGS 8,0
18763 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
18764 movq %rcx,RIP-ARGOFFSET(%rsp)
18765 CFI_REL_OFFSET rip,RIP-ARGOFFSET
18766- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
18767+ GET_THREAD_INFO(%rcx)
18768+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
18769 jnz tracesys
18770 system_call_fastpath:
18771 #if __SYSCALL_MASK == ~0
18772@@ -640,7 +925,7 @@ system_call_fastpath:
18773 cmpl $__NR_syscall_max,%eax
18774 #endif
18775 ja badsys
18776- movq %r10,%rcx
18777+ movq R10-ARGOFFSET(%rsp),%rcx
18778 call *sys_call_table(,%rax,8) # XXX: rip relative
18779 movq %rax,RAX-ARGOFFSET(%rsp)
18780 /*
18781@@ -654,10 +939,13 @@ sysret_check:
18782 LOCKDEP_SYS_EXIT
18783 DISABLE_INTERRUPTS(CLBR_NONE)
18784 TRACE_IRQS_OFF
18785- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
18786+ GET_THREAD_INFO(%rcx)
18787+ movl TI_flags(%rcx),%edx
18788 andl %edi,%edx
18789 jnz sysret_careful
18790 CFI_REMEMBER_STATE
18791+ pax_exit_kernel_user
18792+ pax_erase_kstack
18793 /*
18794 * sysretq will re-enable interrupts:
18795 */
18796@@ -709,14 +997,18 @@ badsys:
18797 * jump back to the normal fast path.
18798 */
18799 auditsys:
18800- movq %r10,%r9 /* 6th arg: 4th syscall arg */
18801+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
18802 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
18803 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
18804 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
18805 movq %rax,%rsi /* 2nd arg: syscall number */
18806 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
18807 call __audit_syscall_entry
18808+
18809+ pax_erase_kstack
18810+
18811 LOAD_ARGS 0 /* reload call-clobbered registers */
18812+ pax_set_fptr_mask
18813 jmp system_call_fastpath
18814
18815 /*
18816@@ -737,7 +1029,7 @@ sysret_audit:
18817 /* Do syscall tracing */
18818 tracesys:
18819 #ifdef CONFIG_AUDITSYSCALL
18820- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
18821+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
18822 jz auditsys
18823 #endif
18824 SAVE_REST
18825@@ -745,12 +1037,16 @@ tracesys:
18826 FIXUP_TOP_OF_STACK %rdi
18827 movq %rsp,%rdi
18828 call syscall_trace_enter
18829+
18830+ pax_erase_kstack
18831+
18832 /*
18833 * Reload arg registers from stack in case ptrace changed them.
18834 * We don't reload %rax because syscall_trace_enter() returned
18835 * the value it wants us to use in the table lookup.
18836 */
18837 LOAD_ARGS ARGOFFSET, 1
18838+ pax_set_fptr_mask
18839 RESTORE_REST
18840 #if __SYSCALL_MASK == ~0
18841 cmpq $__NR_syscall_max,%rax
18842@@ -759,7 +1055,7 @@ tracesys:
18843 cmpl $__NR_syscall_max,%eax
18844 #endif
18845 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
18846- movq %r10,%rcx /* fixup for C */
18847+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
18848 call *sys_call_table(,%rax,8)
18849 movq %rax,RAX-ARGOFFSET(%rsp)
18850 /* Use IRET because user could have changed frame */
18851@@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
18852 andl %edi,%edx
18853 jnz int_careful
18854 andl $~TS_COMPAT,TI_status(%rcx)
18855- jmp retint_swapgs
18856+ pax_exit_kernel_user
18857+ pax_erase_kstack
18858+ jmp retint_swapgs_pax
18859
18860 /* Either reschedule or signal or syscall exit tracking needed. */
18861 /* First do a reschedule test. */
18862@@ -826,7 +1124,7 @@ int_restore_rest:
18863 TRACE_IRQS_OFF
18864 jmp int_with_check
18865 CFI_ENDPROC
18866-END(system_call)
18867+ENDPROC(system_call)
18868
18869 /*
18870 * Certain special system calls that need to save a complete full stack frame.
18871@@ -842,7 +1140,7 @@ ENTRY(\label)
18872 call \func
18873 jmp ptregscall_common
18874 CFI_ENDPROC
18875-END(\label)
18876+ENDPROC(\label)
18877 .endm
18878
18879 .macro FORK_LIKE func
18880@@ -856,9 +1154,10 @@ ENTRY(stub_\func)
18881 DEFAULT_FRAME 0 8 /* offset 8: return address */
18882 call sys_\func
18883 RESTORE_TOP_OF_STACK %r11, 8
18884+ pax_force_retaddr
18885 ret $REST_SKIP /* pop extended registers */
18886 CFI_ENDPROC
18887-END(stub_\func)
18888+ENDPROC(stub_\func)
18889 .endm
18890
18891 FORK_LIKE clone
18892@@ -875,9 +1174,10 @@ ENTRY(ptregscall_common)
18893 movq_cfi_restore R12+8, r12
18894 movq_cfi_restore RBP+8, rbp
18895 movq_cfi_restore RBX+8, rbx
18896+ pax_force_retaddr
18897 ret $REST_SKIP /* pop extended registers */
18898 CFI_ENDPROC
18899-END(ptregscall_common)
18900+ENDPROC(ptregscall_common)
18901
18902 ENTRY(stub_execve)
18903 CFI_STARTPROC
18904@@ -891,7 +1191,7 @@ ENTRY(stub_execve)
18905 RESTORE_REST
18906 jmp int_ret_from_sys_call
18907 CFI_ENDPROC
18908-END(stub_execve)
18909+ENDPROC(stub_execve)
18910
18911 /*
18912 * sigreturn is special because it needs to restore all registers on return.
18913@@ -909,7 +1209,7 @@ ENTRY(stub_rt_sigreturn)
18914 RESTORE_REST
18915 jmp int_ret_from_sys_call
18916 CFI_ENDPROC
18917-END(stub_rt_sigreturn)
18918+ENDPROC(stub_rt_sigreturn)
18919
18920 #ifdef CONFIG_X86_X32_ABI
18921 ENTRY(stub_x32_rt_sigreturn)
18922@@ -975,7 +1275,7 @@ vector=vector+1
18923 2: jmp common_interrupt
18924 .endr
18925 CFI_ENDPROC
18926-END(irq_entries_start)
18927+ENDPROC(irq_entries_start)
18928
18929 .previous
18930 END(interrupt)
18931@@ -995,6 +1295,16 @@ END(interrupt)
18932 subq $ORIG_RAX-RBP, %rsp
18933 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
18934 SAVE_ARGS_IRQ
18935+#ifdef CONFIG_PAX_MEMORY_UDEREF
18936+ testb $3, CS(%rdi)
18937+ jnz 1f
18938+ pax_enter_kernel
18939+ jmp 2f
18940+1: pax_enter_kernel_user
18941+2:
18942+#else
18943+ pax_enter_kernel
18944+#endif
18945 call \func
18946 .endm
18947
18948@@ -1027,7 +1337,7 @@ ret_from_intr:
18949
18950 exit_intr:
18951 GET_THREAD_INFO(%rcx)
18952- testl $3,CS-ARGOFFSET(%rsp)
18953+ testb $3,CS-ARGOFFSET(%rsp)
18954 je retint_kernel
18955
18956 /* Interrupt came from user space */
18957@@ -1049,12 +1359,16 @@ retint_swapgs: /* return to user-space */
18958 * The iretq could re-enable interrupts:
18959 */
18960 DISABLE_INTERRUPTS(CLBR_ANY)
18961+ pax_exit_kernel_user
18962+retint_swapgs_pax:
18963 TRACE_IRQS_IRETQ
18964 SWAPGS
18965 jmp restore_args
18966
18967 retint_restore_args: /* return to kernel space */
18968 DISABLE_INTERRUPTS(CLBR_ANY)
18969+ pax_exit_kernel
18970+ pax_force_retaddr (RIP-ARGOFFSET)
18971 /*
18972 * The iretq could re-enable interrupts:
18973 */
18974@@ -1137,7 +1451,7 @@ ENTRY(retint_kernel)
18975 #endif
18976
18977 CFI_ENDPROC
18978-END(common_interrupt)
18979+ENDPROC(common_interrupt)
18980 /*
18981 * End of kprobes section
18982 */
18983@@ -1155,7 +1469,7 @@ ENTRY(\sym)
18984 interrupt \do_sym
18985 jmp ret_from_intr
18986 CFI_ENDPROC
18987-END(\sym)
18988+ENDPROC(\sym)
18989 .endm
18990
18991 #ifdef CONFIG_SMP
18992@@ -1211,12 +1525,22 @@ ENTRY(\sym)
18993 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
18994 call error_entry
18995 DEFAULT_FRAME 0
18996+#ifdef CONFIG_PAX_MEMORY_UDEREF
18997+ testb $3, CS(%rsp)
18998+ jnz 1f
18999+ pax_enter_kernel
19000+ jmp 2f
19001+1: pax_enter_kernel_user
19002+2:
19003+#else
19004+ pax_enter_kernel
19005+#endif
19006 movq %rsp,%rdi /* pt_regs pointer */
19007 xorl %esi,%esi /* no error code */
19008 call \do_sym
19009 jmp error_exit /* %ebx: no swapgs flag */
19010 CFI_ENDPROC
19011-END(\sym)
19012+ENDPROC(\sym)
19013 .endm
19014
19015 .macro paranoidzeroentry sym do_sym
19016@@ -1229,15 +1553,25 @@ ENTRY(\sym)
19017 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19018 call save_paranoid
19019 TRACE_IRQS_OFF
19020+#ifdef CONFIG_PAX_MEMORY_UDEREF
19021+ testb $3, CS(%rsp)
19022+ jnz 1f
19023+ pax_enter_kernel
19024+ jmp 2f
19025+1: pax_enter_kernel_user
19026+2:
19027+#else
19028+ pax_enter_kernel
19029+#endif
19030 movq %rsp,%rdi /* pt_regs pointer */
19031 xorl %esi,%esi /* no error code */
19032 call \do_sym
19033 jmp paranoid_exit /* %ebx: no swapgs flag */
19034 CFI_ENDPROC
19035-END(\sym)
19036+ENDPROC(\sym)
19037 .endm
19038
19039-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19040+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19041 .macro paranoidzeroentry_ist sym do_sym ist
19042 ENTRY(\sym)
19043 INTR_FRAME
19044@@ -1248,14 +1582,30 @@ ENTRY(\sym)
19045 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19046 call save_paranoid
19047 TRACE_IRQS_OFF_DEBUG
19048+#ifdef CONFIG_PAX_MEMORY_UDEREF
19049+ testb $3, CS(%rsp)
19050+ jnz 1f
19051+ pax_enter_kernel
19052+ jmp 2f
19053+1: pax_enter_kernel_user
19054+2:
19055+#else
19056+ pax_enter_kernel
19057+#endif
19058 movq %rsp,%rdi /* pt_regs pointer */
19059 xorl %esi,%esi /* no error code */
19060+#ifdef CONFIG_SMP
19061+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19062+ lea init_tss(%r12), %r12
19063+#else
19064+ lea init_tss(%rip), %r12
19065+#endif
19066 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19067 call \do_sym
19068 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19069 jmp paranoid_exit /* %ebx: no swapgs flag */
19070 CFI_ENDPROC
19071-END(\sym)
19072+ENDPROC(\sym)
19073 .endm
19074
19075 .macro errorentry sym do_sym
19076@@ -1267,13 +1617,23 @@ ENTRY(\sym)
19077 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19078 call error_entry
19079 DEFAULT_FRAME 0
19080+#ifdef CONFIG_PAX_MEMORY_UDEREF
19081+ testb $3, CS(%rsp)
19082+ jnz 1f
19083+ pax_enter_kernel
19084+ jmp 2f
19085+1: pax_enter_kernel_user
19086+2:
19087+#else
19088+ pax_enter_kernel
19089+#endif
19090 movq %rsp,%rdi /* pt_regs pointer */
19091 movq ORIG_RAX(%rsp),%rsi /* get error code */
19092 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19093 call \do_sym
19094 jmp error_exit /* %ebx: no swapgs flag */
19095 CFI_ENDPROC
19096-END(\sym)
19097+ENDPROC(\sym)
19098 .endm
19099
19100 /* error code is on the stack already */
19101@@ -1287,13 +1647,23 @@ ENTRY(\sym)
19102 call save_paranoid
19103 DEFAULT_FRAME 0
19104 TRACE_IRQS_OFF
19105+#ifdef CONFIG_PAX_MEMORY_UDEREF
19106+ testb $3, CS(%rsp)
19107+ jnz 1f
19108+ pax_enter_kernel
19109+ jmp 2f
19110+1: pax_enter_kernel_user
19111+2:
19112+#else
19113+ pax_enter_kernel
19114+#endif
19115 movq %rsp,%rdi /* pt_regs pointer */
19116 movq ORIG_RAX(%rsp),%rsi /* get error code */
19117 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19118 call \do_sym
19119 jmp paranoid_exit /* %ebx: no swapgs flag */
19120 CFI_ENDPROC
19121-END(\sym)
19122+ENDPROC(\sym)
19123 .endm
19124
19125 zeroentry divide_error do_divide_error
19126@@ -1323,9 +1693,10 @@ gs_change:
19127 2: mfence /* workaround */
19128 SWAPGS
19129 popfq_cfi
19130+ pax_force_retaddr
19131 ret
19132 CFI_ENDPROC
19133-END(native_load_gs_index)
19134+ENDPROC(native_load_gs_index)
19135
19136 _ASM_EXTABLE(gs_change,bad_gs)
19137 .section .fixup,"ax"
19138@@ -1353,9 +1724,10 @@ ENTRY(call_softirq)
19139 CFI_DEF_CFA_REGISTER rsp
19140 CFI_ADJUST_CFA_OFFSET -8
19141 decl PER_CPU_VAR(irq_count)
19142+ pax_force_retaddr
19143 ret
19144 CFI_ENDPROC
19145-END(call_softirq)
19146+ENDPROC(call_softirq)
19147
19148 #ifdef CONFIG_XEN
19149 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19150@@ -1393,7 +1765,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19151 decl PER_CPU_VAR(irq_count)
19152 jmp error_exit
19153 CFI_ENDPROC
19154-END(xen_do_hypervisor_callback)
19155+ENDPROC(xen_do_hypervisor_callback)
19156
19157 /*
19158 * Hypervisor uses this for application faults while it executes.
19159@@ -1452,7 +1824,7 @@ ENTRY(xen_failsafe_callback)
19160 SAVE_ALL
19161 jmp error_exit
19162 CFI_ENDPROC
19163-END(xen_failsafe_callback)
19164+ENDPROC(xen_failsafe_callback)
19165
19166 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
19167 xen_hvm_callback_vector xen_evtchn_do_upcall
19168@@ -1501,16 +1873,31 @@ ENTRY(paranoid_exit)
19169 TRACE_IRQS_OFF_DEBUG
19170 testl %ebx,%ebx /* swapgs needed? */
19171 jnz paranoid_restore
19172- testl $3,CS(%rsp)
19173+ testb $3,CS(%rsp)
19174 jnz paranoid_userspace
19175+#ifdef CONFIG_PAX_MEMORY_UDEREF
19176+ pax_exit_kernel
19177+ TRACE_IRQS_IRETQ 0
19178+ SWAPGS_UNSAFE_STACK
19179+ RESTORE_ALL 8
19180+ pax_force_retaddr_bts
19181+ jmp irq_return
19182+#endif
19183 paranoid_swapgs:
19184+#ifdef CONFIG_PAX_MEMORY_UDEREF
19185+ pax_exit_kernel_user
19186+#else
19187+ pax_exit_kernel
19188+#endif
19189 TRACE_IRQS_IRETQ 0
19190 SWAPGS_UNSAFE_STACK
19191 RESTORE_ALL 8
19192 jmp irq_return
19193 paranoid_restore:
19194+ pax_exit_kernel
19195 TRACE_IRQS_IRETQ_DEBUG 0
19196 RESTORE_ALL 8
19197+ pax_force_retaddr_bts
19198 jmp irq_return
19199 paranoid_userspace:
19200 GET_THREAD_INFO(%rcx)
19201@@ -1539,7 +1926,7 @@ paranoid_schedule:
19202 TRACE_IRQS_OFF
19203 jmp paranoid_userspace
19204 CFI_ENDPROC
19205-END(paranoid_exit)
19206+ENDPROC(paranoid_exit)
19207
19208 /*
19209 * Exception entry point. This expects an error code/orig_rax on the stack.
19210@@ -1566,12 +1953,13 @@ ENTRY(error_entry)
19211 movq_cfi r14, R14+8
19212 movq_cfi r15, R15+8
19213 xorl %ebx,%ebx
19214- testl $3,CS+8(%rsp)
19215+ testb $3,CS+8(%rsp)
19216 je error_kernelspace
19217 error_swapgs:
19218 SWAPGS
19219 error_sti:
19220 TRACE_IRQS_OFF
19221+ pax_force_retaddr_bts
19222 ret
19223
19224 /*
19225@@ -1598,7 +1986,7 @@ bstep_iret:
19226 movq %rcx,RIP+8(%rsp)
19227 jmp error_swapgs
19228 CFI_ENDPROC
19229-END(error_entry)
19230+ENDPROC(error_entry)
19231
19232
19233 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19234@@ -1618,7 +2006,7 @@ ENTRY(error_exit)
19235 jnz retint_careful
19236 jmp retint_swapgs
19237 CFI_ENDPROC
19238-END(error_exit)
19239+ENDPROC(error_exit)
19240
19241 /*
19242 * Test if a given stack is an NMI stack or not.
19243@@ -1676,9 +2064,11 @@ ENTRY(nmi)
19244 * If %cs was not the kernel segment, then the NMI triggered in user
19245 * space, which means it is definitely not nested.
19246 */
19247+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
19248+ je 1f
19249 cmpl $__KERNEL_CS, 16(%rsp)
19250 jne first_nmi
19251-
19252+1:
19253 /*
19254 * Check the special variable on the stack to see if NMIs are
19255 * executing.
19256@@ -1847,6 +2237,17 @@ end_repeat_nmi:
19257 */
19258 movq %cr2, %r12
19259
19260+#ifdef CONFIG_PAX_MEMORY_UDEREF
19261+ testb $3, CS(%rsp)
19262+ jnz 1f
19263+ pax_enter_kernel
19264+ jmp 2f
19265+1: pax_enter_kernel_user
19266+2:
19267+#else
19268+ pax_enter_kernel
19269+#endif
19270+
19271 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
19272 movq %rsp,%rdi
19273 movq $-1,%rsi
19274@@ -1862,23 +2263,34 @@ end_repeat_nmi:
19275 testl %ebx,%ebx /* swapgs needed? */
19276 jnz nmi_restore
19277 nmi_swapgs:
19278+#ifdef CONFIG_PAX_MEMORY_UDEREF
19279+ pax_exit_kernel_user
19280+#else
19281+ pax_exit_kernel
19282+#endif
19283 SWAPGS_UNSAFE_STACK
19284+ RESTORE_ALL 6*8
19285+ /* Clear the NMI executing stack variable */
19286+ movq $0, 5*8(%rsp)
19287+ jmp irq_return
19288 nmi_restore:
19289+ pax_exit_kernel
19290 /* Pop the extra iret frame at once */
19291 RESTORE_ALL 6*8
19292+ pax_force_retaddr_bts
19293
19294 /* Clear the NMI executing stack variable */
19295 movq $0, 5*8(%rsp)
19296 jmp irq_return
19297 CFI_ENDPROC
19298-END(nmi)
19299+ENDPROC(nmi)
19300
19301 ENTRY(ignore_sysret)
19302 CFI_STARTPROC
19303 mov $-ENOSYS,%eax
19304 sysret
19305 CFI_ENDPROC
19306-END(ignore_sysret)
19307+ENDPROC(ignore_sysret)
19308
19309 /*
19310 * End of kprobes section
19311diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
19312index 1d41402..af9a46a 100644
19313--- a/arch/x86/kernel/ftrace.c
19314+++ b/arch/x86/kernel/ftrace.c
19315@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
19316 {
19317 unsigned char replaced[MCOUNT_INSN_SIZE];
19318
19319+ ip = ktla_ktva(ip);
19320+
19321 /*
19322 * Note: Due to modules and __init, code can
19323 * disappear and change, we need to protect against faulting
19324@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19325 unsigned char old[MCOUNT_INSN_SIZE], *new;
19326 int ret;
19327
19328- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
19329+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
19330 new = ftrace_call_replace(ip, (unsigned long)func);
19331
19332 /* See comment above by declaration of modifying_ftrace_code */
19333@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19334 /* Also update the regs callback function */
19335 if (!ret) {
19336 ip = (unsigned long)(&ftrace_regs_call);
19337- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
19338+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
19339 new = ftrace_call_replace(ip, (unsigned long)func);
19340 ret = ftrace_modify_code(ip, old, new);
19341 }
19342@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
19343 * kernel identity mapping to modify code.
19344 */
19345 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
19346- ip = (unsigned long)__va(__pa(ip));
19347+ ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
19348
19349 return probe_kernel_write((void *)ip, val, size);
19350 }
19351@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
19352 unsigned char replaced[MCOUNT_INSN_SIZE];
19353 unsigned char brk = BREAKPOINT_INSTRUCTION;
19354
19355- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
19356+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
19357 return -EFAULT;
19358
19359 /* Make sure it is what we expect it to be */
19360@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
19361 return ret;
19362
19363 fail_update:
19364- probe_kernel_write((void *)ip, &old_code[0], 1);
19365+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
19366 goto out;
19367 }
19368
19369@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
19370 {
19371 unsigned char code[MCOUNT_INSN_SIZE];
19372
19373+ ip = ktla_ktva(ip);
19374+
19375 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
19376 return -EFAULT;
19377
19378diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
19379index c18f59d..9c0c9f6 100644
19380--- a/arch/x86/kernel/head32.c
19381+++ b/arch/x86/kernel/head32.c
19382@@ -18,6 +18,7 @@
19383 #include <asm/io_apic.h>
19384 #include <asm/bios_ebda.h>
19385 #include <asm/tlbflush.h>
19386+#include <asm/boot.h>
19387
19388 static void __init i386_default_early_setup(void)
19389 {
19390@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
19391
19392 void __init i386_start_kernel(void)
19393 {
19394- memblock_reserve(__pa_symbol(&_text),
19395- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
19396+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
19397
19398 #ifdef CONFIG_BLK_DEV_INITRD
19399 /* Reserve INITRD */
19400diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
19401index c8932c7..d56b622 100644
19402--- a/arch/x86/kernel/head_32.S
19403+++ b/arch/x86/kernel/head_32.S
19404@@ -26,6 +26,12 @@
19405 /* Physical address */
19406 #define pa(X) ((X) - __PAGE_OFFSET)
19407
19408+#ifdef CONFIG_PAX_KERNEXEC
19409+#define ta(X) (X)
19410+#else
19411+#define ta(X) ((X) - __PAGE_OFFSET)
19412+#endif
19413+
19414 /*
19415 * References to members of the new_cpu_data structure.
19416 */
19417@@ -55,11 +61,7 @@
19418 * and small than max_low_pfn, otherwise will waste some page table entries
19419 */
19420
19421-#if PTRS_PER_PMD > 1
19422-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
19423-#else
19424-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
19425-#endif
19426+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
19427
19428 /* Number of possible pages in the lowmem region */
19429 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
19430@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
19431 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19432
19433 /*
19434+ * Real beginning of normal "text" segment
19435+ */
19436+ENTRY(stext)
19437+ENTRY(_stext)
19438+
19439+/*
19440 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
19441 * %esi points to the real-mode code as a 32-bit pointer.
19442 * CS and DS must be 4 GB flat segments, but we don't depend on
19443@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19444 * can.
19445 */
19446 __HEAD
19447+
19448+#ifdef CONFIG_PAX_KERNEXEC
19449+ jmp startup_32
19450+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
19451+.fill PAGE_SIZE-5,1,0xcc
19452+#endif
19453+
19454 ENTRY(startup_32)
19455 movl pa(stack_start),%ecx
19456
19457@@ -106,6 +121,59 @@ ENTRY(startup_32)
19458 2:
19459 leal -__PAGE_OFFSET(%ecx),%esp
19460
19461+#ifdef CONFIG_SMP
19462+ movl $pa(cpu_gdt_table),%edi
19463+ movl $__per_cpu_load,%eax
19464+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
19465+ rorl $16,%eax
19466+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
19467+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
19468+ movl $__per_cpu_end - 1,%eax
19469+ subl $__per_cpu_start,%eax
19470+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
19471+#endif
19472+
19473+#ifdef CONFIG_PAX_MEMORY_UDEREF
19474+ movl $NR_CPUS,%ecx
19475+ movl $pa(cpu_gdt_table),%edi
19476+1:
19477+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
19478+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
19479+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
19480+ addl $PAGE_SIZE_asm,%edi
19481+ loop 1b
19482+#endif
19483+
19484+#ifdef CONFIG_PAX_KERNEXEC
19485+ movl $pa(boot_gdt),%edi
19486+ movl $__LOAD_PHYSICAL_ADDR,%eax
19487+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
19488+ rorl $16,%eax
19489+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
19490+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
19491+ rorl $16,%eax
19492+
19493+ ljmp $(__BOOT_CS),$1f
19494+1:
19495+
19496+ movl $NR_CPUS,%ecx
19497+ movl $pa(cpu_gdt_table),%edi
19498+ addl $__PAGE_OFFSET,%eax
19499+1:
19500+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
19501+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
19502+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
19503+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
19504+ rorl $16,%eax
19505+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
19506+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
19507+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
19508+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
19509+ rorl $16,%eax
19510+ addl $PAGE_SIZE_asm,%edi
19511+ loop 1b
19512+#endif
19513+
19514 /*
19515 * Clear BSS first so that there are no surprises...
19516 */
19517@@ -196,8 +264,11 @@ ENTRY(startup_32)
19518 movl %eax, pa(max_pfn_mapped)
19519
19520 /* Do early initialization of the fixmap area */
19521- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
19522- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
19523+#ifdef CONFIG_COMPAT_VDSO
19524+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
19525+#else
19526+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
19527+#endif
19528 #else /* Not PAE */
19529
19530 page_pde_offset = (__PAGE_OFFSET >> 20);
19531@@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
19532 movl %eax, pa(max_pfn_mapped)
19533
19534 /* Do early initialization of the fixmap area */
19535- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
19536- movl %eax,pa(initial_page_table+0xffc)
19537+#ifdef CONFIG_COMPAT_VDSO
19538+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
19539+#else
19540+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
19541+#endif
19542 #endif
19543
19544 #ifdef CONFIG_PARAVIRT
19545@@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
19546 cmpl $num_subarch_entries, %eax
19547 jae bad_subarch
19548
19549- movl pa(subarch_entries)(,%eax,4), %eax
19550- subl $__PAGE_OFFSET, %eax
19551- jmp *%eax
19552+ jmp *pa(subarch_entries)(,%eax,4)
19553
19554 bad_subarch:
19555 WEAK(lguest_entry)
19556@@ -256,10 +328,10 @@ WEAK(xen_entry)
19557 __INITDATA
19558
19559 subarch_entries:
19560- .long default_entry /* normal x86/PC */
19561- .long lguest_entry /* lguest hypervisor */
19562- .long xen_entry /* Xen hypervisor */
19563- .long default_entry /* Moorestown MID */
19564+ .long ta(default_entry) /* normal x86/PC */
19565+ .long ta(lguest_entry) /* lguest hypervisor */
19566+ .long ta(xen_entry) /* Xen hypervisor */
19567+ .long ta(default_entry) /* Moorestown MID */
19568 num_subarch_entries = (. - subarch_entries) / 4
19569 .previous
19570 #else
19571@@ -335,6 +407,7 @@ default_entry:
19572 movl pa(mmu_cr4_features),%eax
19573 movl %eax,%cr4
19574
19575+#ifdef CONFIG_X86_PAE
19576 testb $X86_CR4_PAE, %al # check if PAE is enabled
19577 jz 6f
19578
19579@@ -363,6 +436,9 @@ default_entry:
19580 /* Make changes effective */
19581 wrmsr
19582
19583+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
19584+#endif
19585+
19586 6:
19587
19588 /*
19589@@ -460,14 +536,20 @@ is386: movl $2,%ecx # set MP
19590 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
19591 movl %eax,%ss # after changing gdt.
19592
19593- movl $(__USER_DS),%eax # DS/ES contains default USER segment
19594+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
19595 movl %eax,%ds
19596 movl %eax,%es
19597
19598 movl $(__KERNEL_PERCPU), %eax
19599 movl %eax,%fs # set this cpu's percpu
19600
19601+#ifdef CONFIG_CC_STACKPROTECTOR
19602 movl $(__KERNEL_STACK_CANARY),%eax
19603+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
19604+ movl $(__USER_DS),%eax
19605+#else
19606+ xorl %eax,%eax
19607+#endif
19608 movl %eax,%gs
19609
19610 xorl %eax,%eax # Clear LDT
19611@@ -544,8 +626,11 @@ setup_once:
19612 * relocation. Manually set base address in stack canary
19613 * segment descriptor.
19614 */
19615- movl $gdt_page,%eax
19616+ movl $cpu_gdt_table,%eax
19617 movl $stack_canary,%ecx
19618+#ifdef CONFIG_SMP
19619+ addl $__per_cpu_load,%ecx
19620+#endif
19621 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
19622 shrl $16, %ecx
19623 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
19624@@ -576,7 +661,7 @@ ENDPROC(early_idt_handlers)
19625 /* This is global to keep gas from relaxing the jumps */
19626 ENTRY(early_idt_handler)
19627 cld
19628- cmpl $2,%ss:early_recursion_flag
19629+ cmpl $1,%ss:early_recursion_flag
19630 je hlt_loop
19631 incl %ss:early_recursion_flag
19632
19633@@ -614,8 +699,8 @@ ENTRY(early_idt_handler)
19634 pushl (20+6*4)(%esp) /* trapno */
19635 pushl $fault_msg
19636 call printk
19637-#endif
19638 call dump_stack
19639+#endif
19640 hlt_loop:
19641 hlt
19642 jmp hlt_loop
19643@@ -634,8 +719,11 @@ ENDPROC(early_idt_handler)
19644 /* This is the default interrupt "handler" :-) */
19645 ALIGN
19646 ignore_int:
19647- cld
19648 #ifdef CONFIG_PRINTK
19649+ cmpl $2,%ss:early_recursion_flag
19650+ je hlt_loop
19651+ incl %ss:early_recursion_flag
19652+ cld
19653 pushl %eax
19654 pushl %ecx
19655 pushl %edx
19656@@ -644,9 +732,6 @@ ignore_int:
19657 movl $(__KERNEL_DS),%eax
19658 movl %eax,%ds
19659 movl %eax,%es
19660- cmpl $2,early_recursion_flag
19661- je hlt_loop
19662- incl early_recursion_flag
19663 pushl 16(%esp)
19664 pushl 24(%esp)
19665 pushl 32(%esp)
19666@@ -680,29 +765,43 @@ ENTRY(setup_once_ref)
19667 /*
19668 * BSS section
19669 */
19670-__PAGE_ALIGNED_BSS
19671- .align PAGE_SIZE
19672 #ifdef CONFIG_X86_PAE
19673+.section .initial_pg_pmd,"a",@progbits
19674 initial_pg_pmd:
19675 .fill 1024*KPMDS,4,0
19676 #else
19677+.section .initial_page_table,"a",@progbits
19678 ENTRY(initial_page_table)
19679 .fill 1024,4,0
19680 #endif
19681+.section .initial_pg_fixmap,"a",@progbits
19682 initial_pg_fixmap:
19683 .fill 1024,4,0
19684+.section .empty_zero_page,"a",@progbits
19685 ENTRY(empty_zero_page)
19686 .fill 4096,1,0
19687+.section .swapper_pg_dir,"a",@progbits
19688 ENTRY(swapper_pg_dir)
19689+#ifdef CONFIG_X86_PAE
19690+ .fill 4,8,0
19691+#else
19692 .fill 1024,4,0
19693+#endif
19694+
19695+/*
19696+ * The IDT has to be page-aligned to simplify the Pentium
19697+ * F0 0F bug workaround.. We have a special link segment
19698+ * for this.
19699+ */
19700+.section .idt,"a",@progbits
19701+ENTRY(idt_table)
19702+ .fill 256,8,0
19703
19704 /*
19705 * This starts the data section.
19706 */
19707 #ifdef CONFIG_X86_PAE
19708-__PAGE_ALIGNED_DATA
19709- /* Page-aligned for the benefit of paravirt? */
19710- .align PAGE_SIZE
19711+.section .initial_page_table,"a",@progbits
19712 ENTRY(initial_page_table)
19713 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
19714 # if KPMDS == 3
19715@@ -721,12 +820,20 @@ ENTRY(initial_page_table)
19716 # error "Kernel PMDs should be 1, 2 or 3"
19717 # endif
19718 .align PAGE_SIZE /* needs to be page-sized too */
19719+
19720+#ifdef CONFIG_PAX_PER_CPU_PGD
19721+ENTRY(cpu_pgd)
19722+ .rept NR_CPUS
19723+ .fill 4,8,0
19724+ .endr
19725+#endif
19726+
19727 #endif
19728
19729 .data
19730 .balign 4
19731 ENTRY(stack_start)
19732- .long init_thread_union+THREAD_SIZE
19733+ .long init_thread_union+THREAD_SIZE-8
19734
19735 __INITRODATA
19736 int_msg:
19737@@ -754,7 +861,7 @@ fault_msg:
19738 * segment size, and 32-bit linear address value:
19739 */
19740
19741- .data
19742+.section .rodata,"a",@progbits
19743 .globl boot_gdt_descr
19744 .globl idt_descr
19745
19746@@ -763,7 +870,7 @@ fault_msg:
19747 .word 0 # 32 bit align gdt_desc.address
19748 boot_gdt_descr:
19749 .word __BOOT_DS+7
19750- .long boot_gdt - __PAGE_OFFSET
19751+ .long pa(boot_gdt)
19752
19753 .word 0 # 32-bit align idt_desc.address
19754 idt_descr:
19755@@ -774,7 +881,7 @@ idt_descr:
19756 .word 0 # 32 bit align gdt_desc.address
19757 ENTRY(early_gdt_descr)
19758 .word GDT_ENTRIES*8-1
19759- .long gdt_page /* Overwritten for secondary CPUs */
19760+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
19761
19762 /*
19763 * The boot_gdt must mirror the equivalent in setup.S and is
19764@@ -783,5 +890,65 @@ ENTRY(early_gdt_descr)
19765 .align L1_CACHE_BYTES
19766 ENTRY(boot_gdt)
19767 .fill GDT_ENTRY_BOOT_CS,8,0
19768- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
19769- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
19770+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
19771+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
19772+
19773+ .align PAGE_SIZE_asm
19774+ENTRY(cpu_gdt_table)
19775+ .rept NR_CPUS
19776+ .quad 0x0000000000000000 /* NULL descriptor */
19777+ .quad 0x0000000000000000 /* 0x0b reserved */
19778+ .quad 0x0000000000000000 /* 0x13 reserved */
19779+ .quad 0x0000000000000000 /* 0x1b reserved */
19780+
19781+#ifdef CONFIG_PAX_KERNEXEC
19782+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
19783+#else
19784+ .quad 0x0000000000000000 /* 0x20 unused */
19785+#endif
19786+
19787+ .quad 0x0000000000000000 /* 0x28 unused */
19788+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
19789+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
19790+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
19791+ .quad 0x0000000000000000 /* 0x4b reserved */
19792+ .quad 0x0000000000000000 /* 0x53 reserved */
19793+ .quad 0x0000000000000000 /* 0x5b reserved */
19794+
19795+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
19796+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
19797+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
19798+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
19799+
19800+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
19801+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
19802+
19803+ /*
19804+ * Segments used for calling PnP BIOS have byte granularity.
19805+ * The code segments and data segments have fixed 64k limits,
19806+ * the transfer segment sizes are set at run time.
19807+ */
19808+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
19809+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
19810+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
19811+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
19812+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
19813+
19814+ /*
19815+ * The APM segments have byte granularity and their bases
19816+ * are set at run time. All have 64k limits.
19817+ */
19818+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
19819+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
19820+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
19821+
19822+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
19823+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
19824+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
19825+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
19826+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
19827+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
19828+
19829+ /* Be sure this is zeroed to avoid false validations in Xen */
19830+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
19831+ .endr
19832diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
19833index 980053c..74d3b44 100644
19834--- a/arch/x86/kernel/head_64.S
19835+++ b/arch/x86/kernel/head_64.S
19836@@ -20,6 +20,8 @@
19837 #include <asm/processor-flags.h>
19838 #include <asm/percpu.h>
19839 #include <asm/nops.h>
19840+#include <asm/cpufeature.h>
19841+#include <asm/alternative-asm.h>
19842
19843 #ifdef CONFIG_PARAVIRT
19844 #include <asm/asm-offsets.h>
19845@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
19846 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
19847 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
19848 L3_START_KERNEL = pud_index(__START_KERNEL_map)
19849+L4_VMALLOC_START = pgd_index(VMALLOC_START)
19850+L3_VMALLOC_START = pud_index(VMALLOC_START)
19851+L4_VMALLOC_END = pgd_index(VMALLOC_END)
19852+L3_VMALLOC_END = pud_index(VMALLOC_END)
19853+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
19854+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
19855
19856 .text
19857 __HEAD
19858@@ -88,35 +96,23 @@ startup_64:
19859 */
19860 addq %rbp, init_level4_pgt + 0(%rip)
19861 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
19862+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
19863+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
19864+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
19865 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
19866
19867 addq %rbp, level3_ident_pgt + 0(%rip)
19868+#ifndef CONFIG_XEN
19869+ addq %rbp, level3_ident_pgt + 8(%rip)
19870+#endif
19871
19872- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
19873- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
19874+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
19875+
19876+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
19877+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
19878
19879 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
19880-
19881- /* Add an Identity mapping if I am above 1G */
19882- leaq _text(%rip), %rdi
19883- andq $PMD_PAGE_MASK, %rdi
19884-
19885- movq %rdi, %rax
19886- shrq $PUD_SHIFT, %rax
19887- andq $(PTRS_PER_PUD - 1), %rax
19888- jz ident_complete
19889-
19890- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
19891- leaq level3_ident_pgt(%rip), %rbx
19892- movq %rdx, 0(%rbx, %rax, 8)
19893-
19894- movq %rdi, %rax
19895- shrq $PMD_SHIFT, %rax
19896- andq $(PTRS_PER_PMD - 1), %rax
19897- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
19898- leaq level2_spare_pgt(%rip), %rbx
19899- movq %rdx, 0(%rbx, %rax, 8)
19900-ident_complete:
19901+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
19902
19903 /*
19904 * Fixup the kernel text+data virtual addresses. Note that
19905@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
19906 * after the boot processor executes this code.
19907 */
19908
19909- /* Enable PAE mode and PGE */
19910- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
19911+ /* Enable PAE mode and PSE/PGE */
19912+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19913 movq %rax, %cr4
19914
19915 /* Setup early boot stage 4 level pagetables. */
19916@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
19917 movl $MSR_EFER, %ecx
19918 rdmsr
19919 btsl $_EFER_SCE, %eax /* Enable System Call */
19920- btl $20,%edi /* No Execute supported? */
19921+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
19922 jnc 1f
19923 btsl $_EFER_NX, %eax
19924+ leaq init_level4_pgt(%rip), %rdi
19925+#ifndef CONFIG_EFI
19926+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
19927+#endif
19928+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
19929+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
19930+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
19931+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
19932 1: wrmsr /* Make changes effective */
19933
19934 /* Setup cr0 */
19935@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
19936 * jump. In addition we need to ensure %cs is set so we make this
19937 * a far return.
19938 */
19939+ pax_set_fptr_mask
19940 movq initial_code(%rip),%rax
19941 pushq $0 # fake return address to stop unwinder
19942 pushq $__KERNEL_CS # set correct cs
19943@@ -284,7 +289,7 @@ ENDPROC(start_cpu0)
19944 bad_address:
19945 jmp bad_address
19946
19947- .section ".init.text","ax"
19948+ __INIT
19949 .globl early_idt_handlers
19950 early_idt_handlers:
19951 # 104(%rsp) %rflags
19952@@ -343,7 +348,7 @@ ENTRY(early_idt_handler)
19953 call dump_stack
19954 #ifdef CONFIG_KALLSYMS
19955 leaq early_idt_ripmsg(%rip),%rdi
19956- movq 40(%rsp),%rsi # %rip again
19957+ movq 88(%rsp),%rsi # %rip again
19958 call __print_symbol
19959 #endif
19960 #endif /* EARLY_PRINTK */
19961@@ -363,11 +368,15 @@ ENTRY(early_idt_handler)
19962 addq $16,%rsp # drop vector number and error code
19963 decl early_recursion_flag(%rip)
19964 INTERRUPT_RETURN
19965+ .previous
19966
19967+ __INITDATA
19968 .balign 4
19969 early_recursion_flag:
19970 .long 0
19971+ .previous
19972
19973+ .section .rodata,"a",@progbits
19974 #ifdef CONFIG_EARLY_PRINTK
19975 early_idt_msg:
19976 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
19977@@ -376,6 +385,7 @@ early_idt_ripmsg:
19978 #endif /* CONFIG_EARLY_PRINTK */
19979 .previous
19980
19981+ .section .rodata,"a",@progbits
19982 #define NEXT_PAGE(name) \
19983 .balign PAGE_SIZE; \
19984 ENTRY(name)
19985@@ -388,7 +398,6 @@ ENTRY(name)
19986 i = i + 1 ; \
19987 .endr
19988
19989- .data
19990 /*
19991 * This default setting generates an ident mapping at address 0x100000
19992 * and a mapping for the kernel that precisely maps virtual address
19993@@ -399,13 +408,41 @@ NEXT_PAGE(init_level4_pgt)
19994 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
19995 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
19996 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
19997+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
19998+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
19999+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
20000+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20001+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20002+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20003 .org init_level4_pgt + L4_START_KERNEL*8, 0
20004 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20005 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20006
20007+#ifdef CONFIG_PAX_PER_CPU_PGD
20008+NEXT_PAGE(cpu_pgd)
20009+ .rept NR_CPUS
20010+ .fill 512,8,0
20011+ .endr
20012+#endif
20013+
20014 NEXT_PAGE(level3_ident_pgt)
20015 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20016+#ifdef CONFIG_XEN
20017 .fill 511,8,0
20018+#else
20019+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20020+ .fill 510,8,0
20021+#endif
20022+
20023+NEXT_PAGE(level3_vmalloc_start_pgt)
20024+ .fill 512,8,0
20025+
20026+NEXT_PAGE(level3_vmalloc_end_pgt)
20027+ .fill 512,8,0
20028+
20029+NEXT_PAGE(level3_vmemmap_pgt)
20030+ .fill L3_VMEMMAP_START,8,0
20031+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20032
20033 NEXT_PAGE(level3_kernel_pgt)
20034 .fill L3_START_KERNEL,8,0
20035@@ -413,20 +450,23 @@ NEXT_PAGE(level3_kernel_pgt)
20036 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20037 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20038
20039+NEXT_PAGE(level2_vmemmap_pgt)
20040+ .fill 512,8,0
20041+
20042 NEXT_PAGE(level2_fixmap_pgt)
20043- .fill 506,8,0
20044- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20045- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20046- .fill 5,8,0
20047+ .fill 507,8,0
20048+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20049+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20050+ .fill 4,8,0
20051
20052-NEXT_PAGE(level1_fixmap_pgt)
20053+NEXT_PAGE(level1_vsyscall_pgt)
20054 .fill 512,8,0
20055
20056-NEXT_PAGE(level2_ident_pgt)
20057- /* Since I easily can, map the first 1G.
20058+ /* Since I easily can, map the first 2G.
20059 * Don't set NX because code runs from these pages.
20060 */
20061- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20062+NEXT_PAGE(level2_ident_pgt)
20063+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20064
20065 NEXT_PAGE(level2_kernel_pgt)
20066 /*
20067@@ -439,37 +479,59 @@ NEXT_PAGE(level2_kernel_pgt)
20068 * If you want to increase this then increase MODULES_VADDR
20069 * too.)
20070 */
20071- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
20072- KERNEL_IMAGE_SIZE/PMD_SIZE)
20073-
20074-NEXT_PAGE(level2_spare_pgt)
20075- .fill 512, 8, 0
20076+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
20077
20078 #undef PMDS
20079 #undef NEXT_PAGE
20080
20081- .data
20082+ .align PAGE_SIZE
20083+ENTRY(cpu_gdt_table)
20084+ .rept NR_CPUS
20085+ .quad 0x0000000000000000 /* NULL descriptor */
20086+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20087+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
20088+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
20089+ .quad 0x00cffb000000ffff /* __USER32_CS */
20090+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20091+ .quad 0x00affb000000ffff /* __USER_CS */
20092+
20093+#ifdef CONFIG_PAX_KERNEXEC
20094+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20095+#else
20096+ .quad 0x0 /* unused */
20097+#endif
20098+
20099+ .quad 0,0 /* TSS */
20100+ .quad 0,0 /* LDT */
20101+ .quad 0,0,0 /* three TLS descriptors */
20102+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
20103+ /* asm/segment.h:GDT_ENTRIES must match this */
20104+
20105+ /* zero the remaining page */
20106+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20107+ .endr
20108+
20109 .align 16
20110 .globl early_gdt_descr
20111 early_gdt_descr:
20112 .word GDT_ENTRIES*8-1
20113 early_gdt_descr_base:
20114- .quad INIT_PER_CPU_VAR(gdt_page)
20115+ .quad cpu_gdt_table
20116
20117 ENTRY(phys_base)
20118 /* This must match the first entry in level2_kernel_pgt */
20119 .quad 0x0000000000000000
20120
20121 #include "../../x86/xen/xen-head.S"
20122-
20123- .section .bss, "aw", @nobits
20124+
20125+ .section .rodata,"a",@progbits
20126 .align L1_CACHE_BYTES
20127 ENTRY(idt_table)
20128- .skip IDT_ENTRIES * 16
20129+ .fill 512,8,0
20130
20131 .align L1_CACHE_BYTES
20132 ENTRY(nmi_idt_table)
20133- .skip IDT_ENTRIES * 16
20134+ .fill 512,8,0
20135
20136 __PAGE_ALIGNED_BSS
20137 .align PAGE_SIZE
20138diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20139index 9c3bd4a..e1d9b35 100644
20140--- a/arch/x86/kernel/i386_ksyms_32.c
20141+++ b/arch/x86/kernel/i386_ksyms_32.c
20142@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20143 EXPORT_SYMBOL(cmpxchg8b_emu);
20144 #endif
20145
20146+EXPORT_SYMBOL_GPL(cpu_gdt_table);
20147+
20148 /* Networking helper routines. */
20149 EXPORT_SYMBOL(csum_partial_copy_generic);
20150+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20151+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20152
20153 EXPORT_SYMBOL(__get_user_1);
20154 EXPORT_SYMBOL(__get_user_2);
20155@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
20156
20157 EXPORT_SYMBOL(csum_partial);
20158 EXPORT_SYMBOL(empty_zero_page);
20159+
20160+#ifdef CONFIG_PAX_KERNEXEC
20161+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20162+#endif
20163diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20164index 245a71d..89d9ce4 100644
20165--- a/arch/x86/kernel/i387.c
20166+++ b/arch/x86/kernel/i387.c
20167@@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20168 static inline bool interrupted_user_mode(void)
20169 {
20170 struct pt_regs *regs = get_irq_regs();
20171- return regs && user_mode_vm(regs);
20172+ return regs && user_mode(regs);
20173 }
20174
20175 /*
20176diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20177index 9a5c460..dc4374d 100644
20178--- a/arch/x86/kernel/i8259.c
20179+++ b/arch/x86/kernel/i8259.c
20180@@ -209,7 +209,7 @@ spurious_8259A_irq:
20181 "spurious 8259A interrupt: IRQ%d.\n", irq);
20182 spurious_irq_mask |= irqmask;
20183 }
20184- atomic_inc(&irq_err_count);
20185+ atomic_inc_unchecked(&irq_err_count);
20186 /*
20187 * Theoretically we do not have to handle this IRQ,
20188 * but in Linux this does not cause problems and is
20189diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20190index 8c96897..be66bfa 100644
20191--- a/arch/x86/kernel/ioport.c
20192+++ b/arch/x86/kernel/ioport.c
20193@@ -6,6 +6,7 @@
20194 #include <linux/sched.h>
20195 #include <linux/kernel.h>
20196 #include <linux/capability.h>
20197+#include <linux/security.h>
20198 #include <linux/errno.h>
20199 #include <linux/types.h>
20200 #include <linux/ioport.h>
20201@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20202
20203 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
20204 return -EINVAL;
20205+#ifdef CONFIG_GRKERNSEC_IO
20206+ if (turn_on && grsec_disable_privio) {
20207+ gr_handle_ioperm();
20208+ return -EPERM;
20209+ }
20210+#endif
20211 if (turn_on && !capable(CAP_SYS_RAWIO))
20212 return -EPERM;
20213
20214@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20215 * because the ->io_bitmap_max value must match the bitmap
20216 * contents:
20217 */
20218- tss = &per_cpu(init_tss, get_cpu());
20219+ tss = init_tss + get_cpu();
20220
20221 if (turn_on)
20222 bitmap_clear(t->io_bitmap_ptr, from, num);
20223@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
20224 return -EINVAL;
20225 /* Trying to gain more privileges? */
20226 if (level > old) {
20227+#ifdef CONFIG_GRKERNSEC_IO
20228+ if (grsec_disable_privio) {
20229+ gr_handle_iopl();
20230+ return -EPERM;
20231+ }
20232+#endif
20233 if (!capable(CAP_SYS_RAWIO))
20234 return -EPERM;
20235 }
20236diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
20237index e4595f1..ee3bfb8 100644
20238--- a/arch/x86/kernel/irq.c
20239+++ b/arch/x86/kernel/irq.c
20240@@ -18,7 +18,7 @@
20241 #include <asm/mce.h>
20242 #include <asm/hw_irq.h>
20243
20244-atomic_t irq_err_count;
20245+atomic_unchecked_t irq_err_count;
20246
20247 /* Function pointer for generic interrupt vector handling */
20248 void (*x86_platform_ipi_callback)(void) = NULL;
20249@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
20250 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
20251 seq_printf(p, " Machine check polls\n");
20252 #endif
20253- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
20254+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
20255 #if defined(CONFIG_X86_IO_APIC)
20256- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
20257+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
20258 #endif
20259 return 0;
20260 }
20261@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
20262
20263 u64 arch_irq_stat(void)
20264 {
20265- u64 sum = atomic_read(&irq_err_count);
20266+ u64 sum = atomic_read_unchecked(&irq_err_count);
20267
20268 #ifdef CONFIG_X86_IO_APIC
20269- sum += atomic_read(&irq_mis_count);
20270+ sum += atomic_read_unchecked(&irq_mis_count);
20271 #endif
20272 return sum;
20273 }
20274diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
20275index 344faf8..355f60d 100644
20276--- a/arch/x86/kernel/irq_32.c
20277+++ b/arch/x86/kernel/irq_32.c
20278@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
20279 __asm__ __volatile__("andl %%esp,%0" :
20280 "=r" (sp) : "0" (THREAD_SIZE - 1));
20281
20282- return sp < (sizeof(struct thread_info) + STACK_WARN);
20283+ return sp < STACK_WARN;
20284 }
20285
20286 static void print_stack_overflow(void)
20287@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
20288 * per-CPU IRQ handling contexts (thread information and stack)
20289 */
20290 union irq_ctx {
20291- struct thread_info tinfo;
20292- u32 stack[THREAD_SIZE/sizeof(u32)];
20293+ unsigned long previous_esp;
20294+ u32 stack[THREAD_SIZE/sizeof(u32)];
20295 } __attribute__((aligned(THREAD_SIZE)));
20296
20297 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
20298@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
20299 static inline int
20300 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20301 {
20302- union irq_ctx *curctx, *irqctx;
20303+ union irq_ctx *irqctx;
20304 u32 *isp, arg1, arg2;
20305
20306- curctx = (union irq_ctx *) current_thread_info();
20307 irqctx = __this_cpu_read(hardirq_ctx);
20308
20309 /*
20310@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20311 * handler) we can't do that and just have to keep using the
20312 * current stack (which is the irq stack already after all)
20313 */
20314- if (unlikely(curctx == irqctx))
20315+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
20316 return 0;
20317
20318 /* build the stack frame on the IRQ stack */
20319- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20320- irqctx->tinfo.task = curctx->tinfo.task;
20321- irqctx->tinfo.previous_esp = current_stack_pointer;
20322+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20323+ irqctx->previous_esp = current_stack_pointer;
20324
20325- /* Copy the preempt_count so that the [soft]irq checks work. */
20326- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
20327+#ifdef CONFIG_PAX_MEMORY_UDEREF
20328+ __set_fs(MAKE_MM_SEG(0));
20329+#endif
20330
20331 if (unlikely(overflow))
20332 call_on_stack(print_stack_overflow, isp);
20333@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20334 : "0" (irq), "1" (desc), "2" (isp),
20335 "D" (desc->handle_irq)
20336 : "memory", "cc", "ecx");
20337+
20338+#ifdef CONFIG_PAX_MEMORY_UDEREF
20339+ __set_fs(current_thread_info()->addr_limit);
20340+#endif
20341+
20342 return 1;
20343 }
20344
20345@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20346 */
20347 void __cpuinit irq_ctx_init(int cpu)
20348 {
20349- union irq_ctx *irqctx;
20350-
20351 if (per_cpu(hardirq_ctx, cpu))
20352 return;
20353
20354- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20355- THREADINFO_GFP,
20356- THREAD_SIZE_ORDER));
20357- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20358- irqctx->tinfo.cpu = cpu;
20359- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
20360- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20361-
20362- per_cpu(hardirq_ctx, cpu) = irqctx;
20363-
20364- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20365- THREADINFO_GFP,
20366- THREAD_SIZE_ORDER));
20367- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20368- irqctx->tinfo.cpu = cpu;
20369- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20370-
20371- per_cpu(softirq_ctx, cpu) = irqctx;
20372+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20373+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20374+
20375+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20376+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20377
20378 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20379 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20380@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
20381 asmlinkage void do_softirq(void)
20382 {
20383 unsigned long flags;
20384- struct thread_info *curctx;
20385 union irq_ctx *irqctx;
20386 u32 *isp;
20387
20388@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
20389 local_irq_save(flags);
20390
20391 if (local_softirq_pending()) {
20392- curctx = current_thread_info();
20393 irqctx = __this_cpu_read(softirq_ctx);
20394- irqctx->tinfo.task = curctx->task;
20395- irqctx->tinfo.previous_esp = current_stack_pointer;
20396+ irqctx->previous_esp = current_stack_pointer;
20397
20398 /* build the stack frame on the softirq stack */
20399- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20400+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20401+
20402+#ifdef CONFIG_PAX_MEMORY_UDEREF
20403+ __set_fs(MAKE_MM_SEG(0));
20404+#endif
20405
20406 call_on_stack(__do_softirq, isp);
20407+
20408+#ifdef CONFIG_PAX_MEMORY_UDEREF
20409+ __set_fs(current_thread_info()->addr_limit);
20410+#endif
20411+
20412 /*
20413 * Shouldn't happen, we returned above if in_interrupt():
20414 */
20415@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
20416 if (unlikely(!desc))
20417 return false;
20418
20419- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20420+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20421 if (unlikely(overflow))
20422 print_stack_overflow();
20423 desc->handle_irq(irq, desc);
20424diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
20425index d04d3ec..ea4b374 100644
20426--- a/arch/x86/kernel/irq_64.c
20427+++ b/arch/x86/kernel/irq_64.c
20428@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
20429 u64 estack_top, estack_bottom;
20430 u64 curbase = (u64)task_stack_page(current);
20431
20432- if (user_mode_vm(regs))
20433+ if (user_mode(regs))
20434 return;
20435
20436 if (regs->sp >= curbase + sizeof(struct thread_info) +
20437diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
20438index dc1404b..bbc43e7 100644
20439--- a/arch/x86/kernel/kdebugfs.c
20440+++ b/arch/x86/kernel/kdebugfs.c
20441@@ -27,7 +27,7 @@ struct setup_data_node {
20442 u32 len;
20443 };
20444
20445-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
20446+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
20447 size_t count, loff_t *ppos)
20448 {
20449 struct setup_data_node *node = file->private_data;
20450diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
20451index 836f832..a8bda67 100644
20452--- a/arch/x86/kernel/kgdb.c
20453+++ b/arch/x86/kernel/kgdb.c
20454@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
20455 #ifdef CONFIG_X86_32
20456 switch (regno) {
20457 case GDB_SS:
20458- if (!user_mode_vm(regs))
20459+ if (!user_mode(regs))
20460 *(unsigned long *)mem = __KERNEL_DS;
20461 break;
20462 case GDB_SP:
20463- if (!user_mode_vm(regs))
20464+ if (!user_mode(regs))
20465 *(unsigned long *)mem = kernel_stack_pointer(regs);
20466 break;
20467 case GDB_GS:
20468@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
20469 bp->attr.bp_addr = breakinfo[breakno].addr;
20470 bp->attr.bp_len = breakinfo[breakno].len;
20471 bp->attr.bp_type = breakinfo[breakno].type;
20472- info->address = breakinfo[breakno].addr;
20473+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
20474+ info->address = ktla_ktva(breakinfo[breakno].addr);
20475+ else
20476+ info->address = breakinfo[breakno].addr;
20477 info->len = breakinfo[breakno].len;
20478 info->type = breakinfo[breakno].type;
20479 val = arch_install_hw_breakpoint(bp);
20480@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
20481 case 'k':
20482 /* clear the trace bit */
20483 linux_regs->flags &= ~X86_EFLAGS_TF;
20484- atomic_set(&kgdb_cpu_doing_single_step, -1);
20485+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
20486
20487 /* set the trace bit if we're stepping */
20488 if (remcomInBuffer[0] == 's') {
20489 linux_regs->flags |= X86_EFLAGS_TF;
20490- atomic_set(&kgdb_cpu_doing_single_step,
20491+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
20492 raw_smp_processor_id());
20493 }
20494
20495@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
20496
20497 switch (cmd) {
20498 case DIE_DEBUG:
20499- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
20500+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
20501 if (user_mode(regs))
20502 return single_step_cont(regs, args);
20503 break;
20504@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
20505 #endif /* CONFIG_DEBUG_RODATA */
20506
20507 bpt->type = BP_BREAKPOINT;
20508- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
20509+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
20510 BREAK_INSTR_SIZE);
20511 if (err)
20512 return err;
20513- err = probe_kernel_write((char *)bpt->bpt_addr,
20514+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
20515 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
20516 #ifdef CONFIG_DEBUG_RODATA
20517 if (!err)
20518@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
20519 return -EBUSY;
20520 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
20521 BREAK_INSTR_SIZE);
20522- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
20523+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
20524 if (err)
20525 return err;
20526 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
20527@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
20528 if (mutex_is_locked(&text_mutex))
20529 goto knl_write;
20530 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
20531- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
20532+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
20533 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
20534 goto knl_write;
20535 return err;
20536 knl_write:
20537 #endif /* CONFIG_DEBUG_RODATA */
20538- return probe_kernel_write((char *)bpt->bpt_addr,
20539+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
20540 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
20541 }
20542
20543diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
20544index c5e410e..ed5a7f0 100644
20545--- a/arch/x86/kernel/kprobes-opt.c
20546+++ b/arch/x86/kernel/kprobes-opt.c
20547@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
20548 * Verify if the address gap is in 2GB range, because this uses
20549 * a relative jump.
20550 */
20551- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
20552+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
20553 if (abs(rel) > 0x7fffffff)
20554 return -ERANGE;
20555
20556@@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
20557 op->optinsn.size = ret;
20558
20559 /* Copy arch-dep-instance from template */
20560- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
20561+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
20562
20563 /* Set probe information */
20564 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
20565
20566 /* Set probe function call */
20567- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
20568+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
20569
20570 /* Set returning jmp instruction at the tail of out-of-line buffer */
20571- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
20572+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
20573 (u8 *)op->kp.addr + op->optinsn.size);
20574
20575 flush_icache_range((unsigned long) buf,
20576@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
20577 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
20578
20579 /* Backup instructions which will be replaced by jump address */
20580- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
20581+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
20582 RELATIVE_ADDR_SIZE);
20583
20584 insn_buf[0] = RELATIVEJUMP_OPCODE;
20585@@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
20586 /* This kprobe is really able to run optimized path. */
20587 op = container_of(p, struct optimized_kprobe, kp);
20588 /* Detour through copied instructions */
20589- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
20590+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
20591 if (!reenter)
20592 reset_current_kprobe();
20593 preempt_enable_no_resched();
20594diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
20595index 57916c0..9e0b9d0 100644
20596--- a/arch/x86/kernel/kprobes.c
20597+++ b/arch/x86/kernel/kprobes.c
20598@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
20599 s32 raddr;
20600 } __attribute__((packed)) *insn;
20601
20602- insn = (struct __arch_relative_insn *)from;
20603+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
20604+
20605+ pax_open_kernel();
20606 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
20607 insn->op = op;
20608+ pax_close_kernel();
20609 }
20610
20611 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
20612@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
20613 kprobe_opcode_t opcode;
20614 kprobe_opcode_t *orig_opcodes = opcodes;
20615
20616- if (search_exception_tables((unsigned long)opcodes))
20617+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
20618 return 0; /* Page fault may occur on this address. */
20619
20620 retry:
20621@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
20622 * for the first byte, we can recover the original instruction
20623 * from it and kp->opcode.
20624 */
20625- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
20626+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
20627 buf[0] = kp->opcode;
20628- return (unsigned long)buf;
20629+ return ktva_ktla((unsigned long)buf);
20630 }
20631
20632 /*
20633@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
20634 /* Another subsystem puts a breakpoint, failed to recover */
20635 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
20636 return 0;
20637+ pax_open_kernel();
20638 memcpy(dest, insn.kaddr, insn.length);
20639+ pax_close_kernel();
20640
20641 #ifdef CONFIG_X86_64
20642 if (insn_rip_relative(&insn)) {
20643@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
20644 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
20645 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
20646 disp = (u8 *) dest + insn_offset_displacement(&insn);
20647+ pax_open_kernel();
20648 *(s32 *) disp = (s32) newdisp;
20649+ pax_close_kernel();
20650 }
20651 #endif
20652 return insn.length;
20653@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
20654 * nor set current_kprobe, because it doesn't use single
20655 * stepping.
20656 */
20657- regs->ip = (unsigned long)p->ainsn.insn;
20658+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
20659 preempt_enable_no_resched();
20660 return;
20661 }
20662@@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
20663 regs->flags &= ~X86_EFLAGS_IF;
20664 /* single step inline if the instruction is an int3 */
20665 if (p->opcode == BREAKPOINT_INSTRUCTION)
20666- regs->ip = (unsigned long)p->addr;
20667+ regs->ip = ktla_ktva((unsigned long)p->addr);
20668 else
20669- regs->ip = (unsigned long)p->ainsn.insn;
20670+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
20671 }
20672
20673 /*
20674@@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
20675 setup_singlestep(p, regs, kcb, 0);
20676 return 1;
20677 }
20678- } else if (*addr != BREAKPOINT_INSTRUCTION) {
20679+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
20680 /*
20681 * The breakpoint instruction was removed right
20682 * after we hit it. Another cpu has removed
20683@@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
20684 " movq %rax, 152(%rsp)\n"
20685 RESTORE_REGS_STRING
20686 " popfq\n"
20687+#ifdef KERNEXEC_PLUGIN
20688+ " btsq $63,(%rsp)\n"
20689+#endif
20690 #else
20691 " pushf\n"
20692 SAVE_REGS_STRING
20693@@ -788,7 +798,7 @@ static void __kprobes
20694 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
20695 {
20696 unsigned long *tos = stack_addr(regs);
20697- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
20698+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
20699 unsigned long orig_ip = (unsigned long)p->addr;
20700 kprobe_opcode_t *insn = p->ainsn.insn;
20701
20702@@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
20703 struct die_args *args = data;
20704 int ret = NOTIFY_DONE;
20705
20706- if (args->regs && user_mode_vm(args->regs))
20707+ if (args->regs && user_mode(args->regs))
20708 return ret;
20709
20710 switch (val) {
20711diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
20712index 9c2bd8b..bb1131c 100644
20713--- a/arch/x86/kernel/kvm.c
20714+++ b/arch/x86/kernel/kvm.c
20715@@ -452,7 +452,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
20716 return NOTIFY_OK;
20717 }
20718
20719-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
20720+static struct notifier_block kvm_cpu_notifier = {
20721 .notifier_call = kvm_cpu_notify,
20722 };
20723 #endif
20724diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
20725index ebc9873..1b9724b 100644
20726--- a/arch/x86/kernel/ldt.c
20727+++ b/arch/x86/kernel/ldt.c
20728@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
20729 if (reload) {
20730 #ifdef CONFIG_SMP
20731 preempt_disable();
20732- load_LDT(pc);
20733+ load_LDT_nolock(pc);
20734 if (!cpumask_equal(mm_cpumask(current->mm),
20735 cpumask_of(smp_processor_id())))
20736 smp_call_function(flush_ldt, current->mm, 1);
20737 preempt_enable();
20738 #else
20739- load_LDT(pc);
20740+ load_LDT_nolock(pc);
20741 #endif
20742 }
20743 if (oldsize) {
20744@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
20745 return err;
20746
20747 for (i = 0; i < old->size; i++)
20748- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
20749+ write_ldt_entry(new->ldt, i, old->ldt + i);
20750 return 0;
20751 }
20752
20753@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
20754 retval = copy_ldt(&mm->context, &old_mm->context);
20755 mutex_unlock(&old_mm->context.lock);
20756 }
20757+
20758+ if (tsk == current) {
20759+ mm->context.vdso = 0;
20760+
20761+#ifdef CONFIG_X86_32
20762+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
20763+ mm->context.user_cs_base = 0UL;
20764+ mm->context.user_cs_limit = ~0UL;
20765+
20766+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
20767+ cpus_clear(mm->context.cpu_user_cs_mask);
20768+#endif
20769+
20770+#endif
20771+#endif
20772+
20773+ }
20774+
20775 return retval;
20776 }
20777
20778@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
20779 }
20780 }
20781
20782+#ifdef CONFIG_PAX_SEGMEXEC
20783+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
20784+ error = -EINVAL;
20785+ goto out_unlock;
20786+ }
20787+#endif
20788+
20789 fill_ldt(&ldt, &ldt_info);
20790 if (oldmode)
20791 ldt.avl = 0;
20792diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
20793index 5b19e4d..6476a76 100644
20794--- a/arch/x86/kernel/machine_kexec_32.c
20795+++ b/arch/x86/kernel/machine_kexec_32.c
20796@@ -26,7 +26,7 @@
20797 #include <asm/cacheflush.h>
20798 #include <asm/debugreg.h>
20799
20800-static void set_idt(void *newidt, __u16 limit)
20801+static void set_idt(struct desc_struct *newidt, __u16 limit)
20802 {
20803 struct desc_ptr curidt;
20804
20805@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
20806 }
20807
20808
20809-static void set_gdt(void *newgdt, __u16 limit)
20810+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
20811 {
20812 struct desc_ptr curgdt;
20813
20814@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
20815 }
20816
20817 control_page = page_address(image->control_code_page);
20818- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
20819+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
20820
20821 relocate_kernel_ptr = control_page;
20822 page_list[PA_CONTROL_PAGE] = __pa(control_page);
20823diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
20824index 3a04b22..1d2eb09 100644
20825--- a/arch/x86/kernel/microcode_core.c
20826+++ b/arch/x86/kernel/microcode_core.c
20827@@ -512,7 +512,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
20828 return NOTIFY_OK;
20829 }
20830
20831-static struct notifier_block __refdata mc_cpu_notifier = {
20832+static struct notifier_block mc_cpu_notifier = {
20833 .notifier_call = mc_cpu_callback,
20834 };
20835
20836diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
20837index 3544aed..01ddc1c 100644
20838--- a/arch/x86/kernel/microcode_intel.c
20839+++ b/arch/x86/kernel/microcode_intel.c
20840@@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
20841
20842 static int get_ucode_user(void *to, const void *from, size_t n)
20843 {
20844- return copy_from_user(to, from, n);
20845+ return copy_from_user(to, (const void __force_user *)from, n);
20846 }
20847
20848 static enum ucode_state
20849 request_microcode_user(int cpu, const void __user *buf, size_t size)
20850 {
20851- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
20852+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
20853 }
20854
20855 static void microcode_fini_cpu(int cpu)
20856diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
20857index 216a4d7..228255a 100644
20858--- a/arch/x86/kernel/module.c
20859+++ b/arch/x86/kernel/module.c
20860@@ -43,15 +43,60 @@ do { \
20861 } while (0)
20862 #endif
20863
20864-void *module_alloc(unsigned long size)
20865+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
20866 {
20867- if (PAGE_ALIGN(size) > MODULES_LEN)
20868+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
20869 return NULL;
20870 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
20871- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
20872+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
20873 -1, __builtin_return_address(0));
20874 }
20875
20876+void *module_alloc(unsigned long size)
20877+{
20878+
20879+#ifdef CONFIG_PAX_KERNEXEC
20880+ return __module_alloc(size, PAGE_KERNEL);
20881+#else
20882+ return __module_alloc(size, PAGE_KERNEL_EXEC);
20883+#endif
20884+
20885+}
20886+
20887+#ifdef CONFIG_PAX_KERNEXEC
20888+#ifdef CONFIG_X86_32
20889+void *module_alloc_exec(unsigned long size)
20890+{
20891+ struct vm_struct *area;
20892+
20893+ if (size == 0)
20894+ return NULL;
20895+
20896+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
20897+ return area ? area->addr : NULL;
20898+}
20899+EXPORT_SYMBOL(module_alloc_exec);
20900+
20901+void module_free_exec(struct module *mod, void *module_region)
20902+{
20903+ vunmap(module_region);
20904+}
20905+EXPORT_SYMBOL(module_free_exec);
20906+#else
20907+void module_free_exec(struct module *mod, void *module_region)
20908+{
20909+ module_free(mod, module_region);
20910+}
20911+EXPORT_SYMBOL(module_free_exec);
20912+
20913+void *module_alloc_exec(unsigned long size)
20914+{
20915+ return __module_alloc(size, PAGE_KERNEL_RX);
20916+}
20917+EXPORT_SYMBOL(module_alloc_exec);
20918+#endif
20919+#endif
20920+
20921 #ifdef CONFIG_X86_32
20922 int apply_relocate(Elf32_Shdr *sechdrs,
20923 const char *strtab,
20924@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
20925 unsigned int i;
20926 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
20927 Elf32_Sym *sym;
20928- uint32_t *location;
20929+ uint32_t *plocation, location;
20930
20931 DEBUGP("Applying relocate section %u to %u\n",
20932 relsec, sechdrs[relsec].sh_info);
20933 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
20934 /* This is where to make the change */
20935- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
20936- + rel[i].r_offset;
20937+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
20938+ location = (uint32_t)plocation;
20939+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
20940+ plocation = ktla_ktva((void *)plocation);
20941 /* This is the symbol it is referring to. Note that all
20942 undefined symbols have been resolved. */
20943 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
20944@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
20945 switch (ELF32_R_TYPE(rel[i].r_info)) {
20946 case R_386_32:
20947 /* We add the value into the location given */
20948- *location += sym->st_value;
20949+ pax_open_kernel();
20950+ *plocation += sym->st_value;
20951+ pax_close_kernel();
20952 break;
20953 case R_386_PC32:
20954 /* Add the value, subtract its position */
20955- *location += sym->st_value - (uint32_t)location;
20956+ pax_open_kernel();
20957+ *plocation += sym->st_value - location;
20958+ pax_close_kernel();
20959 break;
20960 default:
20961 pr_err("%s: Unknown relocation: %u\n",
20962@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
20963 case R_X86_64_NONE:
20964 break;
20965 case R_X86_64_64:
20966+ pax_open_kernel();
20967 *(u64 *)loc = val;
20968+ pax_close_kernel();
20969 break;
20970 case R_X86_64_32:
20971+ pax_open_kernel();
20972 *(u32 *)loc = val;
20973+ pax_close_kernel();
20974 if (val != *(u32 *)loc)
20975 goto overflow;
20976 break;
20977 case R_X86_64_32S:
20978+ pax_open_kernel();
20979 *(s32 *)loc = val;
20980+ pax_close_kernel();
20981 if ((s64)val != *(s32 *)loc)
20982 goto overflow;
20983 break;
20984 case R_X86_64_PC32:
20985 val -= (u64)loc;
20986+ pax_open_kernel();
20987 *(u32 *)loc = val;
20988+ pax_close_kernel();
20989+
20990 #if 0
20991 if ((s64)val != *(s32 *)loc)
20992 goto overflow;
20993diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
20994index 4929502..686c291 100644
20995--- a/arch/x86/kernel/msr.c
20996+++ b/arch/x86/kernel/msr.c
20997@@ -234,7 +234,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
20998 return notifier_from_errno(err);
20999 }
21000
21001-static struct notifier_block __refdata msr_class_cpu_notifier = {
21002+static struct notifier_block msr_class_cpu_notifier = {
21003 .notifier_call = msr_class_cpu_callback,
21004 };
21005
21006diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21007index f84f5c5..e27e54b 100644
21008--- a/arch/x86/kernel/nmi.c
21009+++ b/arch/x86/kernel/nmi.c
21010@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21011 dotraplinkage notrace __kprobes void
21012 do_nmi(struct pt_regs *regs, long error_code)
21013 {
21014+
21015+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21016+ if (!user_mode(regs)) {
21017+ unsigned long cs = regs->cs & 0xFFFF;
21018+ unsigned long ip = ktva_ktla(regs->ip);
21019+
21020+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21021+ regs->ip = ip;
21022+ }
21023+#endif
21024+
21025 nmi_nesting_preprocess(regs);
21026
21027 nmi_enter();
21028diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21029index 676b8c7..870ba04 100644
21030--- a/arch/x86/kernel/paravirt-spinlocks.c
21031+++ b/arch/x86/kernel/paravirt-spinlocks.c
21032@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21033 arch_spin_lock(lock);
21034 }
21035
21036-struct pv_lock_ops pv_lock_ops = {
21037+struct pv_lock_ops pv_lock_ops __read_only = {
21038 #ifdef CONFIG_SMP
21039 .spin_is_locked = __ticket_spin_is_locked,
21040 .spin_is_contended = __ticket_spin_is_contended,
21041diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21042index 17fff18..5cfa0f4 100644
21043--- a/arch/x86/kernel/paravirt.c
21044+++ b/arch/x86/kernel/paravirt.c
21045@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21046 {
21047 return x;
21048 }
21049+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21050+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21051+#endif
21052
21053 void __init default_banner(void)
21054 {
21055@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21056 if (opfunc == NULL)
21057 /* If there's no function, patch it with a ud2a (BUG) */
21058 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21059- else if (opfunc == _paravirt_nop)
21060+ else if (opfunc == (void *)_paravirt_nop)
21061 /* If the operation is a nop, then nop the callsite */
21062 ret = paravirt_patch_nop();
21063
21064 /* identity functions just return their single argument */
21065- else if (opfunc == _paravirt_ident_32)
21066+ else if (opfunc == (void *)_paravirt_ident_32)
21067 ret = paravirt_patch_ident_32(insnbuf, len);
21068- else if (opfunc == _paravirt_ident_64)
21069+ else if (opfunc == (void *)_paravirt_ident_64)
21070 ret = paravirt_patch_ident_64(insnbuf, len);
21071+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21072+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21073+ ret = paravirt_patch_ident_64(insnbuf, len);
21074+#endif
21075
21076 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21077 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21078@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21079 if (insn_len > len || start == NULL)
21080 insn_len = len;
21081 else
21082- memcpy(insnbuf, start, insn_len);
21083+ memcpy(insnbuf, ktla_ktva(start), insn_len);
21084
21085 return insn_len;
21086 }
21087@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
21088 preempt_enable();
21089 }
21090
21091-struct pv_info pv_info = {
21092+struct pv_info pv_info __read_only = {
21093 .name = "bare hardware",
21094 .paravirt_enabled = 0,
21095 .kernel_rpl = 0,
21096@@ -315,16 +322,16 @@ struct pv_info pv_info = {
21097 #endif
21098 };
21099
21100-struct pv_init_ops pv_init_ops = {
21101+struct pv_init_ops pv_init_ops __read_only = {
21102 .patch = native_patch,
21103 };
21104
21105-struct pv_time_ops pv_time_ops = {
21106+struct pv_time_ops pv_time_ops __read_only = {
21107 .sched_clock = native_sched_clock,
21108 .steal_clock = native_steal_clock,
21109 };
21110
21111-struct pv_irq_ops pv_irq_ops = {
21112+struct pv_irq_ops pv_irq_ops __read_only = {
21113 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21114 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21115 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21116@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21117 #endif
21118 };
21119
21120-struct pv_cpu_ops pv_cpu_ops = {
21121+struct pv_cpu_ops pv_cpu_ops __read_only = {
21122 .cpuid = native_cpuid,
21123 .get_debugreg = native_get_debugreg,
21124 .set_debugreg = native_set_debugreg,
21125@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21126 .end_context_switch = paravirt_nop,
21127 };
21128
21129-struct pv_apic_ops pv_apic_ops = {
21130+struct pv_apic_ops pv_apic_ops __read_only= {
21131 #ifdef CONFIG_X86_LOCAL_APIC
21132 .startup_ipi_hook = paravirt_nop,
21133 #endif
21134 };
21135
21136-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
21137+#ifdef CONFIG_X86_32
21138+#ifdef CONFIG_X86_PAE
21139+/* 64-bit pagetable entries */
21140+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
21141+#else
21142 /* 32-bit pagetable entries */
21143 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
21144+#endif
21145 #else
21146 /* 64-bit pagetable entries */
21147 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
21148 #endif
21149
21150-struct pv_mmu_ops pv_mmu_ops = {
21151+struct pv_mmu_ops pv_mmu_ops __read_only = {
21152
21153 .read_cr2 = native_read_cr2,
21154 .write_cr2 = native_write_cr2,
21155@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
21156 .make_pud = PTE_IDENT,
21157
21158 .set_pgd = native_set_pgd,
21159+ .set_pgd_batched = native_set_pgd_batched,
21160 #endif
21161 #endif /* PAGETABLE_LEVELS >= 3 */
21162
21163@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
21164 },
21165
21166 .set_fixmap = native_set_fixmap,
21167+
21168+#ifdef CONFIG_PAX_KERNEXEC
21169+ .pax_open_kernel = native_pax_open_kernel,
21170+ .pax_close_kernel = native_pax_close_kernel,
21171+#endif
21172+
21173 };
21174
21175 EXPORT_SYMBOL_GPL(pv_time_ops);
21176diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
21177index 35ccf75..7a15747 100644
21178--- a/arch/x86/kernel/pci-iommu_table.c
21179+++ b/arch/x86/kernel/pci-iommu_table.c
21180@@ -2,7 +2,7 @@
21181 #include <asm/iommu_table.h>
21182 #include <linux/string.h>
21183 #include <linux/kallsyms.h>
21184-
21185+#include <linux/sched.h>
21186
21187 #define DEBUG 1
21188
21189diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
21190index 2ed787f..f70c9f6 100644
21191--- a/arch/x86/kernel/process.c
21192+++ b/arch/x86/kernel/process.c
21193@@ -36,7 +36,8 @@
21194 * section. Since TSS's are completely CPU-local, we want them
21195 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
21196 */
21197-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
21198+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
21199+EXPORT_SYMBOL(init_tss);
21200
21201 #ifdef CONFIG_X86_64
21202 static DEFINE_PER_CPU(unsigned char, is_idle);
21203@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
21204 task_xstate_cachep =
21205 kmem_cache_create("task_xstate", xstate_size,
21206 __alignof__(union thread_xstate),
21207- SLAB_PANIC | SLAB_NOTRACK, NULL);
21208+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
21209 }
21210
21211 /*
21212@@ -105,7 +106,7 @@ void exit_thread(void)
21213 unsigned long *bp = t->io_bitmap_ptr;
21214
21215 if (bp) {
21216- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
21217+ struct tss_struct *tss = init_tss + get_cpu();
21218
21219 t->io_bitmap_ptr = NULL;
21220 clear_thread_flag(TIF_IO_BITMAP);
21221@@ -136,7 +137,7 @@ void show_regs_common(void)
21222 board = dmi_get_system_info(DMI_BOARD_NAME);
21223
21224 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
21225- current->pid, current->comm, print_tainted(),
21226+ task_pid_nr(current), current->comm, print_tainted(),
21227 init_utsname()->release,
21228 (int)strcspn(init_utsname()->version, " "),
21229 init_utsname()->version,
21230@@ -149,6 +150,9 @@ void flush_thread(void)
21231 {
21232 struct task_struct *tsk = current;
21233
21234+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
21235+ loadsegment(gs, 0);
21236+#endif
21237 flush_ptrace_hw_breakpoint(tsk);
21238 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
21239 drop_init_fpu(tsk);
21240@@ -301,7 +305,7 @@ static void __exit_idle(void)
21241 void exit_idle(void)
21242 {
21243 /* idle loop has pid 0 */
21244- if (current->pid)
21245+ if (task_pid_nr(current))
21246 return;
21247 __exit_idle();
21248 }
21249@@ -404,7 +408,7 @@ bool set_pm_idle_to_default(void)
21250
21251 return ret;
21252 }
21253-void stop_this_cpu(void *dummy)
21254+__noreturn void stop_this_cpu(void *dummy)
21255 {
21256 local_irq_disable();
21257 /*
21258@@ -632,16 +636,37 @@ static int __init idle_setup(char *str)
21259 }
21260 early_param("idle", idle_setup);
21261
21262-unsigned long arch_align_stack(unsigned long sp)
21263+#ifdef CONFIG_PAX_RANDKSTACK
21264+void pax_randomize_kstack(struct pt_regs *regs)
21265 {
21266- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
21267- sp -= get_random_int() % 8192;
21268- return sp & ~0xf;
21269-}
21270+ struct thread_struct *thread = &current->thread;
21271+ unsigned long time;
21272
21273-unsigned long arch_randomize_brk(struct mm_struct *mm)
21274-{
21275- unsigned long range_end = mm->brk + 0x02000000;
21276- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
21277-}
21278+ if (!randomize_va_space)
21279+ return;
21280+
21281+ if (v8086_mode(regs))
21282+ return;
21283
21284+ rdtscl(time);
21285+
21286+ /* P4 seems to return a 0 LSB, ignore it */
21287+#ifdef CONFIG_MPENTIUM4
21288+ time &= 0x3EUL;
21289+ time <<= 2;
21290+#elif defined(CONFIG_X86_64)
21291+ time &= 0xFUL;
21292+ time <<= 4;
21293+#else
21294+ time &= 0x1FUL;
21295+ time <<= 3;
21296+#endif
21297+
21298+ thread->sp0 ^= time;
21299+ load_sp0(init_tss + smp_processor_id(), thread);
21300+
21301+#ifdef CONFIG_X86_64
21302+ this_cpu_write(kernel_stack, thread->sp0);
21303+#endif
21304+}
21305+#endif
21306diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
21307index b5a8905..d9cacac 100644
21308--- a/arch/x86/kernel/process_32.c
21309+++ b/arch/x86/kernel/process_32.c
21310@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
21311 unsigned long thread_saved_pc(struct task_struct *tsk)
21312 {
21313 return ((unsigned long *)tsk->thread.sp)[3];
21314+//XXX return tsk->thread.eip;
21315 }
21316
21317 void __show_regs(struct pt_regs *regs, int all)
21318@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
21319 unsigned long sp;
21320 unsigned short ss, gs;
21321
21322- if (user_mode_vm(regs)) {
21323+ if (user_mode(regs)) {
21324 sp = regs->sp;
21325 ss = regs->ss & 0xffff;
21326- gs = get_user_gs(regs);
21327 } else {
21328 sp = kernel_stack_pointer(regs);
21329 savesegment(ss, ss);
21330- savesegment(gs, gs);
21331 }
21332+ gs = get_user_gs(regs);
21333
21334 show_regs_common();
21335
21336 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
21337 (u16)regs->cs, regs->ip, regs->flags,
21338- smp_processor_id());
21339+ raw_smp_processor_id());
21340 print_symbol("EIP is at %s\n", regs->ip);
21341
21342 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
21343@@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
21344 int copy_thread(unsigned long clone_flags, unsigned long sp,
21345 unsigned long arg, struct task_struct *p)
21346 {
21347- struct pt_regs *childregs = task_pt_regs(p);
21348+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
21349 struct task_struct *tsk;
21350 int err;
21351
21352 p->thread.sp = (unsigned long) childregs;
21353 p->thread.sp0 = (unsigned long) (childregs+1);
21354+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21355
21356 if (unlikely(p->flags & PF_KTHREAD)) {
21357 /* kernel thread */
21358 memset(childregs, 0, sizeof(struct pt_regs));
21359 p->thread.ip = (unsigned long) ret_from_kernel_thread;
21360- task_user_gs(p) = __KERNEL_STACK_CANARY;
21361- childregs->ds = __USER_DS;
21362- childregs->es = __USER_DS;
21363+ savesegment(gs, childregs->gs);
21364+ childregs->ds = __KERNEL_DS;
21365+ childregs->es = __KERNEL_DS;
21366 childregs->fs = __KERNEL_PERCPU;
21367 childregs->bx = sp; /* function */
21368 childregs->bp = arg;
21369@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21370 struct thread_struct *prev = &prev_p->thread,
21371 *next = &next_p->thread;
21372 int cpu = smp_processor_id();
21373- struct tss_struct *tss = &per_cpu(init_tss, cpu);
21374+ struct tss_struct *tss = init_tss + cpu;
21375 fpu_switch_t fpu;
21376
21377 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
21378@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21379 */
21380 lazy_save_gs(prev->gs);
21381
21382+#ifdef CONFIG_PAX_MEMORY_UDEREF
21383+ __set_fs(task_thread_info(next_p)->addr_limit);
21384+#endif
21385+
21386 /*
21387 * Load the per-thread Thread-Local Storage descriptor.
21388 */
21389@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21390 */
21391 arch_end_context_switch(next_p);
21392
21393+ this_cpu_write(current_task, next_p);
21394+ this_cpu_write(current_tinfo, &next_p->tinfo);
21395+
21396 /*
21397 * Restore %gs if needed (which is common)
21398 */
21399@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21400
21401 switch_fpu_finish(next_p, fpu);
21402
21403- this_cpu_write(current_task, next_p);
21404-
21405 return prev_p;
21406 }
21407
21408@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
21409 } while (count++ < 16);
21410 return 0;
21411 }
21412-
21413diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
21414index 6e68a61..955a9a5 100644
21415--- a/arch/x86/kernel/process_64.c
21416+++ b/arch/x86/kernel/process_64.c
21417@@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
21418 struct pt_regs *childregs;
21419 struct task_struct *me = current;
21420
21421- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
21422+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
21423 childregs = task_pt_regs(p);
21424 p->thread.sp = (unsigned long) childregs;
21425 p->thread.usersp = me->thread.usersp;
21426+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21427 set_tsk_thread_flag(p, TIF_FORK);
21428 p->fpu_counter = 0;
21429 p->thread.io_bitmap_ptr = NULL;
21430@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21431 struct thread_struct *prev = &prev_p->thread;
21432 struct thread_struct *next = &next_p->thread;
21433 int cpu = smp_processor_id();
21434- struct tss_struct *tss = &per_cpu(init_tss, cpu);
21435+ struct tss_struct *tss = init_tss + cpu;
21436 unsigned fsindex, gsindex;
21437 fpu_switch_t fpu;
21438
21439@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21440 prev->usersp = this_cpu_read(old_rsp);
21441 this_cpu_write(old_rsp, next->usersp);
21442 this_cpu_write(current_task, next_p);
21443+ this_cpu_write(current_tinfo, &next_p->tinfo);
21444
21445- this_cpu_write(kernel_stack,
21446- (unsigned long)task_stack_page(next_p) +
21447- THREAD_SIZE - KERNEL_STACK_OFFSET);
21448+ this_cpu_write(kernel_stack, next->sp0);
21449
21450 /*
21451 * Now maybe reload the debug registers and handle I/O bitmaps
21452@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
21453 if (!p || p == current || p->state == TASK_RUNNING)
21454 return 0;
21455 stack = (unsigned long)task_stack_page(p);
21456- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
21457+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
21458 return 0;
21459 fp = *(u64 *)(p->thread.sp);
21460 do {
21461- if (fp < (unsigned long)stack ||
21462- fp >= (unsigned long)stack+THREAD_SIZE)
21463+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
21464 return 0;
21465 ip = *(u64 *)(fp+8);
21466 if (!in_sched_functions(ip))
21467diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
21468index b629bbe..0fa615a 100644
21469--- a/arch/x86/kernel/ptrace.c
21470+++ b/arch/x86/kernel/ptrace.c
21471@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
21472 {
21473 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
21474 unsigned long sp = (unsigned long)&regs->sp;
21475- struct thread_info *tinfo;
21476
21477- if (context == (sp & ~(THREAD_SIZE - 1)))
21478+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
21479 return sp;
21480
21481- tinfo = (struct thread_info *)context;
21482- if (tinfo->previous_esp)
21483- return tinfo->previous_esp;
21484+ sp = *(unsigned long *)context;
21485+ if (sp)
21486+ return sp;
21487
21488 return (unsigned long)regs;
21489 }
21490@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
21491 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
21492 {
21493 int i;
21494- int dr7 = 0;
21495+ unsigned long dr7 = 0;
21496 struct arch_hw_breakpoint *info;
21497
21498 for (i = 0; i < HBP_NUM; i++) {
21499@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
21500 unsigned long addr, unsigned long data)
21501 {
21502 int ret;
21503- unsigned long __user *datap = (unsigned long __user *)data;
21504+ unsigned long __user *datap = (__force unsigned long __user *)data;
21505
21506 switch (request) {
21507 /* read the word at location addr in the USER area. */
21508@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
21509 if ((int) addr < 0)
21510 return -EIO;
21511 ret = do_get_thread_area(child, addr,
21512- (struct user_desc __user *)data);
21513+ (__force struct user_desc __user *) data);
21514 break;
21515
21516 case PTRACE_SET_THREAD_AREA:
21517 if ((int) addr < 0)
21518 return -EIO;
21519 ret = do_set_thread_area(child, addr,
21520- (struct user_desc __user *)data, 0);
21521+ (__force struct user_desc __user *) data, 0);
21522 break;
21523 #endif
21524
21525@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
21526
21527 #ifdef CONFIG_X86_64
21528
21529-static struct user_regset x86_64_regsets[] __read_mostly = {
21530+static user_regset_no_const x86_64_regsets[] __read_only = {
21531 [REGSET_GENERAL] = {
21532 .core_note_type = NT_PRSTATUS,
21533 .n = sizeof(struct user_regs_struct) / sizeof(long),
21534@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
21535 #endif /* CONFIG_X86_64 */
21536
21537 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
21538-static struct user_regset x86_32_regsets[] __read_mostly = {
21539+static user_regset_no_const x86_32_regsets[] __read_only = {
21540 [REGSET_GENERAL] = {
21541 .core_note_type = NT_PRSTATUS,
21542 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
21543@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
21544 */
21545 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
21546
21547-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
21548+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
21549 {
21550 #ifdef CONFIG_X86_64
21551 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
21552@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
21553 memset(info, 0, sizeof(*info));
21554 info->si_signo = SIGTRAP;
21555 info->si_code = si_code;
21556- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
21557+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
21558 }
21559
21560 void user_single_step_siginfo(struct task_struct *tsk,
21561@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
21562 # define IS_IA32 0
21563 #endif
21564
21565+#ifdef CONFIG_GRKERNSEC_SETXID
21566+extern void gr_delayed_cred_worker(void);
21567+#endif
21568+
21569 /*
21570 * We must return the syscall number to actually look up in the table.
21571 * This can be -1L to skip running any syscall at all.
21572@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
21573
21574 user_exit();
21575
21576+#ifdef CONFIG_GRKERNSEC_SETXID
21577+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
21578+ gr_delayed_cred_worker();
21579+#endif
21580+
21581 /*
21582 * If we stepped into a sysenter/syscall insn, it trapped in
21583 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
21584@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
21585 */
21586 user_exit();
21587
21588+#ifdef CONFIG_GRKERNSEC_SETXID
21589+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
21590+ gr_delayed_cred_worker();
21591+#endif
21592+
21593 audit_syscall_exit(regs);
21594
21595 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
21596diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
21597index 85c3959..76b89f9 100644
21598--- a/arch/x86/kernel/pvclock.c
21599+++ b/arch/x86/kernel/pvclock.c
21600@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
21601 return pv_tsc_khz;
21602 }
21603
21604-static atomic64_t last_value = ATOMIC64_INIT(0);
21605+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
21606
21607 void pvclock_resume(void)
21608 {
21609- atomic64_set(&last_value, 0);
21610+ atomic64_set_unchecked(&last_value, 0);
21611 }
21612
21613 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
21614@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
21615 * updating at the same time, and one of them could be slightly behind,
21616 * making the assumption that last_value always go forward fail to hold.
21617 */
21618- last = atomic64_read(&last_value);
21619+ last = atomic64_read_unchecked(&last_value);
21620 do {
21621 if (ret < last)
21622 return last;
21623- last = atomic64_cmpxchg(&last_value, last, ret);
21624+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
21625 } while (unlikely(last != ret));
21626
21627 return ret;
21628diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
21629index 76fa1e9..abf09ea 100644
21630--- a/arch/x86/kernel/reboot.c
21631+++ b/arch/x86/kernel/reboot.c
21632@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
21633 EXPORT_SYMBOL(pm_power_off);
21634
21635 static const struct desc_ptr no_idt = {};
21636-static int reboot_mode;
21637+static unsigned short reboot_mode;
21638 enum reboot_type reboot_type = BOOT_ACPI;
21639 int reboot_force;
21640
21641@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
21642
21643 void __noreturn machine_real_restart(unsigned int type)
21644 {
21645+
21646+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21647+ struct desc_struct *gdt;
21648+#endif
21649+
21650 local_irq_disable();
21651
21652 /*
21653@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
21654
21655 /* Jump to the identity-mapped low memory code */
21656 #ifdef CONFIG_X86_32
21657- asm volatile("jmpl *%0" : :
21658+
21659+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21660+ gdt = get_cpu_gdt_table(smp_processor_id());
21661+ pax_open_kernel();
21662+#ifdef CONFIG_PAX_MEMORY_UDEREF
21663+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
21664+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
21665+ loadsegment(ds, __KERNEL_DS);
21666+ loadsegment(es, __KERNEL_DS);
21667+ loadsegment(ss, __KERNEL_DS);
21668+#endif
21669+#ifdef CONFIG_PAX_KERNEXEC
21670+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
21671+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
21672+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
21673+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
21674+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
21675+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
21676+#endif
21677+ pax_close_kernel();
21678+#endif
21679+
21680+ asm volatile("ljmpl *%0" : :
21681 "rm" (real_mode_header->machine_real_restart_asm),
21682 "a" (type));
21683 #else
21684@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
21685 * try to force a triple fault and then cycle between hitting the keyboard
21686 * controller and doing that
21687 */
21688-static void native_machine_emergency_restart(void)
21689+static void __noreturn native_machine_emergency_restart(void)
21690 {
21691 int i;
21692 int attempt = 0;
21693@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
21694 #endif
21695 }
21696
21697-static void __machine_emergency_restart(int emergency)
21698+static void __noreturn __machine_emergency_restart(int emergency)
21699 {
21700 reboot_emergency = emergency;
21701 machine_ops.emergency_restart();
21702 }
21703
21704-static void native_machine_restart(char *__unused)
21705+static void __noreturn native_machine_restart(char *__unused)
21706 {
21707 pr_notice("machine restart\n");
21708
21709@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
21710 __machine_emergency_restart(0);
21711 }
21712
21713-static void native_machine_halt(void)
21714+static void __noreturn native_machine_halt(void)
21715 {
21716 /* Stop other cpus and apics */
21717 machine_shutdown();
21718@@ -679,7 +706,7 @@ static void native_machine_halt(void)
21719 stop_this_cpu(NULL);
21720 }
21721
21722-static void native_machine_power_off(void)
21723+static void __noreturn native_machine_power_off(void)
21724 {
21725 if (pm_power_off) {
21726 if (!reboot_force)
21727@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
21728 }
21729 /* A fallback in case there is no PM info available */
21730 tboot_shutdown(TB_SHUTDOWN_HALT);
21731+ unreachable();
21732 }
21733
21734-struct machine_ops machine_ops = {
21735+struct machine_ops machine_ops __read_only = {
21736 .power_off = native_machine_power_off,
21737 .shutdown = native_machine_shutdown,
21738 .emergency_restart = native_machine_emergency_restart,
21739diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
21740index 7a6f3b3..bed145d7 100644
21741--- a/arch/x86/kernel/relocate_kernel_64.S
21742+++ b/arch/x86/kernel/relocate_kernel_64.S
21743@@ -11,6 +11,7 @@
21744 #include <asm/kexec.h>
21745 #include <asm/processor-flags.h>
21746 #include <asm/pgtable_types.h>
21747+#include <asm/alternative-asm.h>
21748
21749 /*
21750 * Must be relocatable PIC code callable as a C function
21751@@ -160,13 +161,14 @@ identity_mapped:
21752 xorq %rbp, %rbp
21753 xorq %r8, %r8
21754 xorq %r9, %r9
21755- xorq %r10, %r9
21756+ xorq %r10, %r10
21757 xorq %r11, %r11
21758 xorq %r12, %r12
21759 xorq %r13, %r13
21760 xorq %r14, %r14
21761 xorq %r15, %r15
21762
21763+ pax_force_retaddr 0, 1
21764 ret
21765
21766 1:
21767diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
21768index 8b24289..d37b58b 100644
21769--- a/arch/x86/kernel/setup.c
21770+++ b/arch/x86/kernel/setup.c
21771@@ -437,7 +437,7 @@ static void __init parse_setup_data(void)
21772
21773 switch (data->type) {
21774 case SETUP_E820_EXT:
21775- parse_e820_ext(data);
21776+ parse_e820_ext((struct setup_data __force_kernel *)data);
21777 break;
21778 case SETUP_DTB:
21779 add_dtb(pa_data);
21780@@ -706,7 +706,7 @@ static void __init trim_bios_range(void)
21781 * area (640->1Mb) as ram even though it is not.
21782 * take them out.
21783 */
21784- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
21785+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
21786
21787 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
21788 }
21789@@ -830,14 +830,14 @@ void __init setup_arch(char **cmdline_p)
21790
21791 if (!boot_params.hdr.root_flags)
21792 root_mountflags &= ~MS_RDONLY;
21793- init_mm.start_code = (unsigned long) _text;
21794- init_mm.end_code = (unsigned long) _etext;
21795+ init_mm.start_code = ktla_ktva((unsigned long) _text);
21796+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
21797 init_mm.end_data = (unsigned long) _edata;
21798 init_mm.brk = _brk_end;
21799
21800- code_resource.start = virt_to_phys(_text);
21801- code_resource.end = virt_to_phys(_etext)-1;
21802- data_resource.start = virt_to_phys(_etext);
21803+ code_resource.start = virt_to_phys(ktla_ktva(_text));
21804+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
21805+ data_resource.start = virt_to_phys(_sdata);
21806 data_resource.end = virt_to_phys(_edata)-1;
21807 bss_resource.start = virt_to_phys(&__bss_start);
21808 bss_resource.end = virt_to_phys(&__bss_stop)-1;
21809diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
21810index 5cdff03..5810740 100644
21811--- a/arch/x86/kernel/setup_percpu.c
21812+++ b/arch/x86/kernel/setup_percpu.c
21813@@ -21,19 +21,17 @@
21814 #include <asm/cpu.h>
21815 #include <asm/stackprotector.h>
21816
21817-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
21818+#ifdef CONFIG_SMP
21819+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
21820 EXPORT_PER_CPU_SYMBOL(cpu_number);
21821+#endif
21822
21823-#ifdef CONFIG_X86_64
21824 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
21825-#else
21826-#define BOOT_PERCPU_OFFSET 0
21827-#endif
21828
21829 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
21830 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
21831
21832-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
21833+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
21834 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
21835 };
21836 EXPORT_SYMBOL(__per_cpu_offset);
21837@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
21838 {
21839 #ifdef CONFIG_X86_32
21840 struct desc_struct gdt;
21841+ unsigned long base = per_cpu_offset(cpu);
21842
21843- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
21844- 0x2 | DESCTYPE_S, 0x8);
21845- gdt.s = 1;
21846+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
21847+ 0x83 | DESCTYPE_S, 0xC);
21848 write_gdt_entry(get_cpu_gdt_table(cpu),
21849 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
21850 #endif
21851@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
21852 /* alrighty, percpu areas up and running */
21853 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
21854 for_each_possible_cpu(cpu) {
21855+#ifdef CONFIG_CC_STACKPROTECTOR
21856+#ifdef CONFIG_X86_32
21857+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
21858+#endif
21859+#endif
21860 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
21861 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
21862 per_cpu(cpu_number, cpu) = cpu;
21863@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
21864 */
21865 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
21866 #endif
21867+#ifdef CONFIG_CC_STACKPROTECTOR
21868+#ifdef CONFIG_X86_32
21869+ if (!cpu)
21870+ per_cpu(stack_canary.canary, cpu) = canary;
21871+#endif
21872+#endif
21873 /*
21874 * Up to this point, the boot CPU has been using .init.data
21875 * area. Reload any changed state for the boot CPU.
21876diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
21877index d6bf1f3..3ffce5a 100644
21878--- a/arch/x86/kernel/signal.c
21879+++ b/arch/x86/kernel/signal.c
21880@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
21881 * Align the stack pointer according to the i386 ABI,
21882 * i.e. so that on function entry ((sp + 4) & 15) == 0.
21883 */
21884- sp = ((sp + 4) & -16ul) - 4;
21885+ sp = ((sp - 12) & -16ul) - 4;
21886 #else /* !CONFIG_X86_32 */
21887 sp = round_down(sp, 16) - 8;
21888 #endif
21889@@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
21890 }
21891
21892 if (current->mm->context.vdso)
21893- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
21894+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
21895 else
21896- restorer = &frame->retcode;
21897+ restorer = (void __user *)&frame->retcode;
21898 if (ka->sa.sa_flags & SA_RESTORER)
21899 restorer = ka->sa.sa_restorer;
21900
21901@@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
21902 * reasons and because gdb uses it as a signature to notice
21903 * signal handler stack frames.
21904 */
21905- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
21906+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
21907
21908 if (err)
21909 return -EFAULT;
21910@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
21911 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
21912
21913 /* Set up to return from userspace. */
21914- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
21915+ if (current->mm->context.vdso)
21916+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
21917+ else
21918+ restorer = (void __user *)&frame->retcode;
21919 if (ka->sa.sa_flags & SA_RESTORER)
21920 restorer = ka->sa.sa_restorer;
21921 put_user_ex(restorer, &frame->pretcode);
21922@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
21923 * reasons and because gdb uses it as a signature to notice
21924 * signal handler stack frames.
21925 */
21926- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
21927+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
21928 } put_user_catch(err);
21929
21930 err |= copy_siginfo_to_user(&frame->info, info);
21931diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
21932index 48d2b7d..90d328a 100644
21933--- a/arch/x86/kernel/smp.c
21934+++ b/arch/x86/kernel/smp.c
21935@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
21936
21937 __setup("nonmi_ipi", nonmi_ipi_setup);
21938
21939-struct smp_ops smp_ops = {
21940+struct smp_ops smp_ops __read_only = {
21941 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
21942 .smp_prepare_cpus = native_smp_prepare_cpus,
21943 .smp_cpus_done = native_smp_cpus_done,
21944diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
21945index ed0fe38..87fc692 100644
21946--- a/arch/x86/kernel/smpboot.c
21947+++ b/arch/x86/kernel/smpboot.c
21948@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
21949 idle->thread.sp = (unsigned long) (((struct pt_regs *)
21950 (THREAD_SIZE + task_stack_page(idle))) - 1);
21951 per_cpu(current_task, cpu) = idle;
21952+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
21953
21954 #ifdef CONFIG_X86_32
21955 /* Stack for startup_32 can be just as for start_secondary onwards */
21956@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
21957 #else
21958 clear_tsk_thread_flag(idle, TIF_FORK);
21959 initial_gs = per_cpu_offset(cpu);
21960- per_cpu(kernel_stack, cpu) =
21961- (unsigned long)task_stack_page(idle) -
21962- KERNEL_STACK_OFFSET + THREAD_SIZE;
21963+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
21964 #endif
21965+
21966+ pax_open_kernel();
21967 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21968+ pax_close_kernel();
21969+
21970 initial_code = (unsigned long)start_secondary;
21971 stack_start = idle->thread.sp;
21972
21973@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
21974 /* the FPU context is blank, nobody can own it */
21975 __cpu_disable_lazy_restore(cpu);
21976
21977+#ifdef CONFIG_PAX_PER_CPU_PGD
21978+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
21979+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
21980+ KERNEL_PGD_PTRS);
21981+#endif
21982+
21983+ /* the FPU context is blank, nobody can own it */
21984+ __cpu_disable_lazy_restore(cpu);
21985+
21986 err = do_boot_cpu(apicid, cpu, tidle);
21987 if (err) {
21988 pr_debug("do_boot_cpu failed %d\n", err);
21989diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
21990index 9b4d51d..5d28b58 100644
21991--- a/arch/x86/kernel/step.c
21992+++ b/arch/x86/kernel/step.c
21993@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
21994 struct desc_struct *desc;
21995 unsigned long base;
21996
21997- seg &= ~7UL;
21998+ seg >>= 3;
21999
22000 mutex_lock(&child->mm->context.lock);
22001- if (unlikely((seg >> 3) >= child->mm->context.size))
22002+ if (unlikely(seg >= child->mm->context.size))
22003 addr = -1L; /* bogus selector, access would fault */
22004 else {
22005 desc = child->mm->context.ldt + seg;
22006@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22007 addr += base;
22008 }
22009 mutex_unlock(&child->mm->context.lock);
22010- }
22011+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22012+ addr = ktla_ktva(addr);
22013
22014 return addr;
22015 }
22016@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22017 unsigned char opcode[15];
22018 unsigned long addr = convert_ip_to_linear(child, regs);
22019
22020+ if (addr == -EINVAL)
22021+ return 0;
22022+
22023 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22024 for (i = 0; i < copied; i++) {
22025 switch (opcode[i]) {
22026diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22027new file mode 100644
22028index 0000000..26bb1af
22029--- /dev/null
22030+++ b/arch/x86/kernel/sys_i386_32.c
22031@@ -0,0 +1,249 @@
22032+/*
22033+ * This file contains various random system calls that
22034+ * have a non-standard calling sequence on the Linux/i386
22035+ * platform.
22036+ */
22037+
22038+#include <linux/errno.h>
22039+#include <linux/sched.h>
22040+#include <linux/mm.h>
22041+#include <linux/fs.h>
22042+#include <linux/smp.h>
22043+#include <linux/sem.h>
22044+#include <linux/msg.h>
22045+#include <linux/shm.h>
22046+#include <linux/stat.h>
22047+#include <linux/syscalls.h>
22048+#include <linux/mman.h>
22049+#include <linux/file.h>
22050+#include <linux/utsname.h>
22051+#include <linux/ipc.h>
22052+
22053+#include <linux/uaccess.h>
22054+#include <linux/unistd.h>
22055+
22056+#include <asm/syscalls.h>
22057+
22058+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
22059+{
22060+ unsigned long pax_task_size = TASK_SIZE;
22061+
22062+#ifdef CONFIG_PAX_SEGMEXEC
22063+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
22064+ pax_task_size = SEGMEXEC_TASK_SIZE;
22065+#endif
22066+
22067+ if (len > pax_task_size || addr > pax_task_size - len)
22068+ return -EINVAL;
22069+
22070+ return 0;
22071+}
22072+
22073+unsigned long
22074+arch_get_unmapped_area(struct file *filp, unsigned long addr,
22075+ unsigned long len, unsigned long pgoff, unsigned long flags)
22076+{
22077+ struct mm_struct *mm = current->mm;
22078+ struct vm_area_struct *vma;
22079+ unsigned long start_addr, pax_task_size = TASK_SIZE;
22080+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22081+
22082+#ifdef CONFIG_PAX_SEGMEXEC
22083+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22084+ pax_task_size = SEGMEXEC_TASK_SIZE;
22085+#endif
22086+
22087+ pax_task_size -= PAGE_SIZE;
22088+
22089+ if (len > pax_task_size)
22090+ return -ENOMEM;
22091+
22092+ if (flags & MAP_FIXED)
22093+ return addr;
22094+
22095+#ifdef CONFIG_PAX_RANDMMAP
22096+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22097+#endif
22098+
22099+ if (addr) {
22100+ addr = PAGE_ALIGN(addr);
22101+ if (pax_task_size - len >= addr) {
22102+ vma = find_vma(mm, addr);
22103+ if (check_heap_stack_gap(vma, addr, len, offset))
22104+ return addr;
22105+ }
22106+ }
22107+ if (len > mm->cached_hole_size) {
22108+ start_addr = addr = mm->free_area_cache;
22109+ } else {
22110+ start_addr = addr = mm->mmap_base;
22111+ mm->cached_hole_size = 0;
22112+ }
22113+
22114+#ifdef CONFIG_PAX_PAGEEXEC
22115+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
22116+ start_addr = 0x00110000UL;
22117+
22118+#ifdef CONFIG_PAX_RANDMMAP
22119+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22120+ start_addr += mm->delta_mmap & 0x03FFF000UL;
22121+#endif
22122+
22123+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
22124+ start_addr = addr = mm->mmap_base;
22125+ else
22126+ addr = start_addr;
22127+ }
22128+#endif
22129+
22130+full_search:
22131+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22132+ /* At this point: (!vma || addr < vma->vm_end). */
22133+ if (pax_task_size - len < addr) {
22134+ /*
22135+ * Start a new search - just in case we missed
22136+ * some holes.
22137+ */
22138+ if (start_addr != mm->mmap_base) {
22139+ start_addr = addr = mm->mmap_base;
22140+ mm->cached_hole_size = 0;
22141+ goto full_search;
22142+ }
22143+ return -ENOMEM;
22144+ }
22145+ if (check_heap_stack_gap(vma, addr, len, offset))
22146+ break;
22147+ if (addr + mm->cached_hole_size < vma->vm_start)
22148+ mm->cached_hole_size = vma->vm_start - addr;
22149+ addr = vma->vm_end;
22150+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
22151+ start_addr = addr = mm->mmap_base;
22152+ mm->cached_hole_size = 0;
22153+ goto full_search;
22154+ }
22155+ }
22156+
22157+ /*
22158+ * Remember the place where we stopped the search:
22159+ */
22160+ mm->free_area_cache = addr + len;
22161+ return addr;
22162+}
22163+
22164+unsigned long
22165+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22166+ const unsigned long len, const unsigned long pgoff,
22167+ const unsigned long flags)
22168+{
22169+ struct vm_area_struct *vma;
22170+ struct mm_struct *mm = current->mm;
22171+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
22172+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22173+
22174+#ifdef CONFIG_PAX_SEGMEXEC
22175+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22176+ pax_task_size = SEGMEXEC_TASK_SIZE;
22177+#endif
22178+
22179+ pax_task_size -= PAGE_SIZE;
22180+
22181+ /* requested length too big for entire address space */
22182+ if (len > pax_task_size)
22183+ return -ENOMEM;
22184+
22185+ if (flags & MAP_FIXED)
22186+ return addr;
22187+
22188+#ifdef CONFIG_PAX_PAGEEXEC
22189+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
22190+ goto bottomup;
22191+#endif
22192+
22193+#ifdef CONFIG_PAX_RANDMMAP
22194+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22195+#endif
22196+
22197+ /* requesting a specific address */
22198+ if (addr) {
22199+ addr = PAGE_ALIGN(addr);
22200+ if (pax_task_size - len >= addr) {
22201+ vma = find_vma(mm, addr);
22202+ if (check_heap_stack_gap(vma, addr, len, offset))
22203+ return addr;
22204+ }
22205+ }
22206+
22207+ /* check if free_area_cache is useful for us */
22208+ if (len <= mm->cached_hole_size) {
22209+ mm->cached_hole_size = 0;
22210+ mm->free_area_cache = mm->mmap_base;
22211+ }
22212+
22213+ /* either no address requested or can't fit in requested address hole */
22214+ addr = mm->free_area_cache;
22215+
22216+ /* make sure it can fit in the remaining address space */
22217+ if (addr > len) {
22218+ vma = find_vma(mm, addr-len);
22219+ if (check_heap_stack_gap(vma, addr - len, len, offset))
22220+ /* remember the address as a hint for next time */
22221+ return (mm->free_area_cache = addr-len);
22222+ }
22223+
22224+ if (mm->mmap_base < len)
22225+ goto bottomup;
22226+
22227+ addr = mm->mmap_base-len;
22228+
22229+ do {
22230+ /*
22231+ * Lookup failure means no vma is above this address,
22232+ * else if new region fits below vma->vm_start,
22233+ * return with success:
22234+ */
22235+ vma = find_vma(mm, addr);
22236+ if (check_heap_stack_gap(vma, addr, len, offset))
22237+ /* remember the address as a hint for next time */
22238+ return (mm->free_area_cache = addr);
22239+
22240+ /* remember the largest hole we saw so far */
22241+ if (addr + mm->cached_hole_size < vma->vm_start)
22242+ mm->cached_hole_size = vma->vm_start - addr;
22243+
22244+ /* try just below the current vma->vm_start */
22245+ addr = skip_heap_stack_gap(vma, len, offset);
22246+ } while (!IS_ERR_VALUE(addr));
22247+
22248+bottomup:
22249+ /*
22250+ * A failed mmap() very likely causes application failure,
22251+ * so fall back to the bottom-up function here. This scenario
22252+ * can happen with large stack limits and large mmap()
22253+ * allocations.
22254+ */
22255+
22256+#ifdef CONFIG_PAX_SEGMEXEC
22257+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22258+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
22259+ else
22260+#endif
22261+
22262+ mm->mmap_base = TASK_UNMAPPED_BASE;
22263+
22264+#ifdef CONFIG_PAX_RANDMMAP
22265+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22266+ mm->mmap_base += mm->delta_mmap;
22267+#endif
22268+
22269+ mm->free_area_cache = mm->mmap_base;
22270+ mm->cached_hole_size = ~0UL;
22271+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
22272+ /*
22273+ * Restore the topdown base:
22274+ */
22275+ mm->mmap_base = base;
22276+ mm->free_area_cache = base;
22277+ mm->cached_hole_size = ~0UL;
22278+
22279+ return addr;
22280+}
22281diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
22282index 97ef74b..57a1882 100644
22283--- a/arch/x86/kernel/sys_x86_64.c
22284+++ b/arch/x86/kernel/sys_x86_64.c
22285@@ -81,8 +81,8 @@ out:
22286 return error;
22287 }
22288
22289-static void find_start_end(unsigned long flags, unsigned long *begin,
22290- unsigned long *end)
22291+static void find_start_end(struct mm_struct *mm, unsigned long flags,
22292+ unsigned long *begin, unsigned long *end)
22293 {
22294 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
22295 unsigned long new_begin;
22296@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
22297 *begin = new_begin;
22298 }
22299 } else {
22300- *begin = TASK_UNMAPPED_BASE;
22301+ *begin = mm->mmap_base;
22302 *end = TASK_SIZE;
22303 }
22304 }
22305@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
22306 struct vm_area_struct *vma;
22307 struct vm_unmapped_area_info info;
22308 unsigned long begin, end;
22309+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22310
22311 if (flags & MAP_FIXED)
22312 return addr;
22313
22314- find_start_end(flags, &begin, &end);
22315+ find_start_end(mm, flags, &begin, &end);
22316
22317 if (len > end)
22318 return -ENOMEM;
22319
22320+#ifdef CONFIG_PAX_RANDMMAP
22321+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22322+#endif
22323+
22324 if (addr) {
22325 addr = PAGE_ALIGN(addr);
22326 vma = find_vma(mm, addr);
22327- if (end - len >= addr &&
22328- (!vma || addr + len <= vma->vm_start))
22329+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
22330 return addr;
22331 }
22332
22333@@ -161,6 +165,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22334 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
22335 goto bottomup;
22336
22337+#ifdef CONFIG_PAX_RANDMMAP
22338+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22339+#endif
22340+
22341 /* requesting a specific address */
22342 if (addr) {
22343 addr = PAGE_ALIGN(addr);
22344diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
22345index f84fe00..f41d9f1 100644
22346--- a/arch/x86/kernel/tboot.c
22347+++ b/arch/x86/kernel/tboot.c
22348@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
22349
22350 void tboot_shutdown(u32 shutdown_type)
22351 {
22352- void (*shutdown)(void);
22353+ void (* __noreturn shutdown)(void);
22354
22355 if (!tboot_enabled())
22356 return;
22357@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
22358
22359 switch_to_tboot_pt();
22360
22361- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
22362+ shutdown = (void *)tboot->shutdown_entry;
22363 shutdown();
22364
22365 /* should not reach here */
22366@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
22367 return 0;
22368 }
22369
22370-static atomic_t ap_wfs_count;
22371+static atomic_unchecked_t ap_wfs_count;
22372
22373 static int tboot_wait_for_aps(int num_aps)
22374 {
22375@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
22376 {
22377 switch (action) {
22378 case CPU_DYING:
22379- atomic_inc(&ap_wfs_count);
22380+ atomic_inc_unchecked(&ap_wfs_count);
22381 if (num_online_cpus() == 1)
22382- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
22383+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
22384 return NOTIFY_BAD;
22385 break;
22386 }
22387 return NOTIFY_OK;
22388 }
22389
22390-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
22391+static struct notifier_block tboot_cpu_notifier =
22392 {
22393 .notifier_call = tboot_cpu_callback,
22394 };
22395@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
22396
22397 tboot_create_trampoline();
22398
22399- atomic_set(&ap_wfs_count, 0);
22400+ atomic_set_unchecked(&ap_wfs_count, 0);
22401 register_hotcpu_notifier(&tboot_cpu_notifier);
22402
22403 acpi_os_set_prepare_sleep(&tboot_sleep);
22404diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
22405index 24d3c91..d06b473 100644
22406--- a/arch/x86/kernel/time.c
22407+++ b/arch/x86/kernel/time.c
22408@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
22409 {
22410 unsigned long pc = instruction_pointer(regs);
22411
22412- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
22413+ if (!user_mode(regs) && in_lock_functions(pc)) {
22414 #ifdef CONFIG_FRAME_POINTER
22415- return *(unsigned long *)(regs->bp + sizeof(long));
22416+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
22417 #else
22418 unsigned long *sp =
22419 (unsigned long *)kernel_stack_pointer(regs);
22420@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
22421 * or above a saved flags. Eflags has bits 22-31 zero,
22422 * kernel addresses don't.
22423 */
22424+
22425+#ifdef CONFIG_PAX_KERNEXEC
22426+ return ktla_ktva(sp[0]);
22427+#else
22428 if (sp[0] >> 22)
22429 return sp[0];
22430 if (sp[1] >> 22)
22431 return sp[1];
22432 #endif
22433+
22434+#endif
22435 }
22436 return pc;
22437 }
22438diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
22439index 9d9d2f9..cad418a 100644
22440--- a/arch/x86/kernel/tls.c
22441+++ b/arch/x86/kernel/tls.c
22442@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
22443 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
22444 return -EINVAL;
22445
22446+#ifdef CONFIG_PAX_SEGMEXEC
22447+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
22448+ return -EINVAL;
22449+#endif
22450+
22451 set_tls_desc(p, idx, &info, 1);
22452
22453 return 0;
22454@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
22455
22456 if (kbuf)
22457 info = kbuf;
22458- else if (__copy_from_user(infobuf, ubuf, count))
22459+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
22460 return -EFAULT;
22461 else
22462 info = infobuf;
22463diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
22464index ecffca1..95c4d13 100644
22465--- a/arch/x86/kernel/traps.c
22466+++ b/arch/x86/kernel/traps.c
22467@@ -68,12 +68,6 @@
22468 #include <asm/setup.h>
22469
22470 asmlinkage int system_call(void);
22471-
22472-/*
22473- * The IDT has to be page-aligned to simplify the Pentium
22474- * F0 0F bug workaround.
22475- */
22476-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
22477 #endif
22478
22479 DECLARE_BITMAP(used_vectors, NR_VECTORS);
22480@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
22481 }
22482
22483 static int __kprobes
22484-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22485+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
22486 struct pt_regs *regs, long error_code)
22487 {
22488 #ifdef CONFIG_X86_32
22489- if (regs->flags & X86_VM_MASK) {
22490+ if (v8086_mode(regs)) {
22491 /*
22492 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
22493 * On nmi (interrupt 2), do_trap should not be called.
22494@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22495 return -1;
22496 }
22497 #endif
22498- if (!user_mode(regs)) {
22499+ if (!user_mode_novm(regs)) {
22500 if (!fixup_exception(regs)) {
22501 tsk->thread.error_code = error_code;
22502 tsk->thread.trap_nr = trapnr;
22503+
22504+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22505+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
22506+ str = "PAX: suspicious stack segment fault";
22507+#endif
22508+
22509 die(str, regs, error_code);
22510 }
22511+
22512+#ifdef CONFIG_PAX_REFCOUNT
22513+ if (trapnr == 4)
22514+ pax_report_refcount_overflow(regs);
22515+#endif
22516+
22517 return 0;
22518 }
22519
22520@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22521 }
22522
22523 static void __kprobes
22524-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
22525+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
22526 long error_code, siginfo_t *info)
22527 {
22528 struct task_struct *tsk = current;
22529@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
22530 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
22531 printk_ratelimit()) {
22532 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
22533- tsk->comm, tsk->pid, str,
22534+ tsk->comm, task_pid_nr(tsk), str,
22535 regs->ip, regs->sp, error_code);
22536 print_vma_addr(" in ", regs->ip);
22537 pr_cont("\n");
22538@@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
22539 conditional_sti(regs);
22540
22541 #ifdef CONFIG_X86_32
22542- if (regs->flags & X86_VM_MASK) {
22543+ if (v8086_mode(regs)) {
22544 local_irq_enable();
22545 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
22546 goto exit;
22547@@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
22548 #endif
22549
22550 tsk = current;
22551- if (!user_mode(regs)) {
22552+ if (!user_mode_novm(regs)) {
22553 if (fixup_exception(regs))
22554 goto exit;
22555
22556 tsk->thread.error_code = error_code;
22557 tsk->thread.trap_nr = X86_TRAP_GP;
22558 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
22559- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
22560+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
22561+
22562+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22563+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
22564+ die("PAX: suspicious general protection fault", regs, error_code);
22565+ else
22566+#endif
22567+
22568 die("general protection fault", regs, error_code);
22569+ }
22570 goto exit;
22571 }
22572
22573+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
22574+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
22575+ struct mm_struct *mm = tsk->mm;
22576+ unsigned long limit;
22577+
22578+ down_write(&mm->mmap_sem);
22579+ limit = mm->context.user_cs_limit;
22580+ if (limit < TASK_SIZE) {
22581+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
22582+ up_write(&mm->mmap_sem);
22583+ return;
22584+ }
22585+ up_write(&mm->mmap_sem);
22586+ }
22587+#endif
22588+
22589 tsk->thread.error_code = error_code;
22590 tsk->thread.trap_nr = X86_TRAP_GP;
22591
22592@@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
22593 /* It's safe to allow irq's after DR6 has been saved */
22594 preempt_conditional_sti(regs);
22595
22596- if (regs->flags & X86_VM_MASK) {
22597+ if (v8086_mode(regs)) {
22598 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
22599 X86_TRAP_DB);
22600 preempt_conditional_cli(regs);
22601@@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
22602 * We already checked v86 mode above, so we can check for kernel mode
22603 * by just checking the CPL of CS.
22604 */
22605- if ((dr6 & DR_STEP) && !user_mode(regs)) {
22606+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
22607 tsk->thread.debugreg6 &= ~DR_STEP;
22608 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
22609 regs->flags &= ~X86_EFLAGS_TF;
22610@@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
22611 return;
22612 conditional_sti(regs);
22613
22614- if (!user_mode_vm(regs))
22615+ if (!user_mode(regs))
22616 {
22617 if (!fixup_exception(regs)) {
22618 task->thread.error_code = error_code;
22619diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
22620index c71025b..b117501 100644
22621--- a/arch/x86/kernel/uprobes.c
22622+++ b/arch/x86/kernel/uprobes.c
22623@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
22624 int ret = NOTIFY_DONE;
22625
22626 /* We are only interested in userspace traps */
22627- if (regs && !user_mode_vm(regs))
22628+ if (regs && !user_mode(regs))
22629 return NOTIFY_DONE;
22630
22631 switch (val) {
22632diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
22633index b9242ba..50c5edd 100644
22634--- a/arch/x86/kernel/verify_cpu.S
22635+++ b/arch/x86/kernel/verify_cpu.S
22636@@ -20,6 +20,7 @@
22637 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
22638 * arch/x86/kernel/trampoline_64.S: secondary processor verification
22639 * arch/x86/kernel/head_32.S: processor startup
22640+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
22641 *
22642 * verify_cpu, returns the status of longmode and SSE in register %eax.
22643 * 0: Success 1: Failure
22644diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
22645index 1dfe69c..a3df6f6 100644
22646--- a/arch/x86/kernel/vm86_32.c
22647+++ b/arch/x86/kernel/vm86_32.c
22648@@ -43,6 +43,7 @@
22649 #include <linux/ptrace.h>
22650 #include <linux/audit.h>
22651 #include <linux/stddef.h>
22652+#include <linux/grsecurity.h>
22653
22654 #include <asm/uaccess.h>
22655 #include <asm/io.h>
22656@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
22657 do_exit(SIGSEGV);
22658 }
22659
22660- tss = &per_cpu(init_tss, get_cpu());
22661+ tss = init_tss + get_cpu();
22662 current->thread.sp0 = current->thread.saved_sp0;
22663 current->thread.sysenter_cs = __KERNEL_CS;
22664 load_sp0(tss, &current->thread);
22665@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
22666 struct task_struct *tsk;
22667 int tmp, ret = -EPERM;
22668
22669+#ifdef CONFIG_GRKERNSEC_VM86
22670+ if (!capable(CAP_SYS_RAWIO)) {
22671+ gr_handle_vm86();
22672+ goto out;
22673+ }
22674+#endif
22675+
22676 tsk = current;
22677 if (tsk->thread.saved_sp0)
22678 goto out;
22679@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
22680 int tmp, ret;
22681 struct vm86plus_struct __user *v86;
22682
22683+#ifdef CONFIG_GRKERNSEC_VM86
22684+ if (!capable(CAP_SYS_RAWIO)) {
22685+ gr_handle_vm86();
22686+ ret = -EPERM;
22687+ goto out;
22688+ }
22689+#endif
22690+
22691 tsk = current;
22692 switch (cmd) {
22693 case VM86_REQUEST_IRQ:
22694@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
22695 tsk->thread.saved_fs = info->regs32->fs;
22696 tsk->thread.saved_gs = get_user_gs(info->regs32);
22697
22698- tss = &per_cpu(init_tss, get_cpu());
22699+ tss = init_tss + get_cpu();
22700 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
22701 if (cpu_has_sep)
22702 tsk->thread.sysenter_cs = 0;
22703@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
22704 goto cannot_handle;
22705 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
22706 goto cannot_handle;
22707- intr_ptr = (unsigned long __user *) (i << 2);
22708+ intr_ptr = (__force unsigned long __user *) (i << 2);
22709 if (get_user(segoffs, intr_ptr))
22710 goto cannot_handle;
22711 if ((segoffs >> 16) == BIOSSEG)
22712diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
22713index 22a1530..8fbaaad 100644
22714--- a/arch/x86/kernel/vmlinux.lds.S
22715+++ b/arch/x86/kernel/vmlinux.lds.S
22716@@ -26,6 +26,13 @@
22717 #include <asm/page_types.h>
22718 #include <asm/cache.h>
22719 #include <asm/boot.h>
22720+#include <asm/segment.h>
22721+
22722+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22723+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
22724+#else
22725+#define __KERNEL_TEXT_OFFSET 0
22726+#endif
22727
22728 #undef i386 /* in case the preprocessor is a 32bit one */
22729
22730@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
22731
22732 PHDRS {
22733 text PT_LOAD FLAGS(5); /* R_E */
22734+#ifdef CONFIG_X86_32
22735+ module PT_LOAD FLAGS(5); /* R_E */
22736+#endif
22737+#ifdef CONFIG_XEN
22738+ rodata PT_LOAD FLAGS(5); /* R_E */
22739+#else
22740+ rodata PT_LOAD FLAGS(4); /* R__ */
22741+#endif
22742 data PT_LOAD FLAGS(6); /* RW_ */
22743-#ifdef CONFIG_X86_64
22744+ init.begin PT_LOAD FLAGS(6); /* RW_ */
22745 #ifdef CONFIG_SMP
22746 percpu PT_LOAD FLAGS(6); /* RW_ */
22747 #endif
22748+ text.init PT_LOAD FLAGS(5); /* R_E */
22749+ text.exit PT_LOAD FLAGS(5); /* R_E */
22750 init PT_LOAD FLAGS(7); /* RWE */
22751-#endif
22752 note PT_NOTE FLAGS(0); /* ___ */
22753 }
22754
22755 SECTIONS
22756 {
22757 #ifdef CONFIG_X86_32
22758- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
22759- phys_startup_32 = startup_32 - LOAD_OFFSET;
22760+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
22761 #else
22762- . = __START_KERNEL;
22763- phys_startup_64 = startup_64 - LOAD_OFFSET;
22764+ . = __START_KERNEL;
22765 #endif
22766
22767 /* Text and read-only data */
22768- .text : AT(ADDR(.text) - LOAD_OFFSET) {
22769- _text = .;
22770+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
22771 /* bootstrapping code */
22772+#ifdef CONFIG_X86_32
22773+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
22774+#else
22775+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
22776+#endif
22777+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
22778+ _text = .;
22779 HEAD_TEXT
22780 #ifdef CONFIG_X86_32
22781 . = ALIGN(PAGE_SIZE);
22782@@ -108,13 +128,48 @@ SECTIONS
22783 IRQENTRY_TEXT
22784 *(.fixup)
22785 *(.gnu.warning)
22786- /* End of text section */
22787- _etext = .;
22788 } :text = 0x9090
22789
22790- NOTES :text :note
22791+ . += __KERNEL_TEXT_OFFSET;
22792
22793- EXCEPTION_TABLE(16) :text = 0x9090
22794+#ifdef CONFIG_X86_32
22795+ . = ALIGN(PAGE_SIZE);
22796+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
22797+
22798+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
22799+ MODULES_EXEC_VADDR = .;
22800+ BYTE(0)
22801+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
22802+ . = ALIGN(HPAGE_SIZE) - 1;
22803+ MODULES_EXEC_END = .;
22804+#endif
22805+
22806+ } :module
22807+#endif
22808+
22809+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
22810+ /* End of text section */
22811+ BYTE(0)
22812+ _etext = . - __KERNEL_TEXT_OFFSET;
22813+ }
22814+
22815+#ifdef CONFIG_X86_32
22816+ . = ALIGN(PAGE_SIZE);
22817+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
22818+ *(.idt)
22819+ . = ALIGN(PAGE_SIZE);
22820+ *(.empty_zero_page)
22821+ *(.initial_pg_fixmap)
22822+ *(.initial_pg_pmd)
22823+ *(.initial_page_table)
22824+ *(.swapper_pg_dir)
22825+ } :rodata
22826+#endif
22827+
22828+ . = ALIGN(PAGE_SIZE);
22829+ NOTES :rodata :note
22830+
22831+ EXCEPTION_TABLE(16) :rodata
22832
22833 #if defined(CONFIG_DEBUG_RODATA)
22834 /* .text should occupy whole number of pages */
22835@@ -126,16 +181,20 @@ SECTIONS
22836
22837 /* Data */
22838 .data : AT(ADDR(.data) - LOAD_OFFSET) {
22839+
22840+#ifdef CONFIG_PAX_KERNEXEC
22841+ . = ALIGN(HPAGE_SIZE);
22842+#else
22843+ . = ALIGN(PAGE_SIZE);
22844+#endif
22845+
22846 /* Start of data section */
22847 _sdata = .;
22848
22849 /* init_task */
22850 INIT_TASK_DATA(THREAD_SIZE)
22851
22852-#ifdef CONFIG_X86_32
22853- /* 32 bit has nosave before _edata */
22854 NOSAVE_DATA
22855-#endif
22856
22857 PAGE_ALIGNED_DATA(PAGE_SIZE)
22858
22859@@ -176,12 +235,19 @@ SECTIONS
22860 #endif /* CONFIG_X86_64 */
22861
22862 /* Init code and data - will be freed after init */
22863- . = ALIGN(PAGE_SIZE);
22864 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
22865+ BYTE(0)
22866+
22867+#ifdef CONFIG_PAX_KERNEXEC
22868+ . = ALIGN(HPAGE_SIZE);
22869+#else
22870+ . = ALIGN(PAGE_SIZE);
22871+#endif
22872+
22873 __init_begin = .; /* paired with __init_end */
22874- }
22875+ } :init.begin
22876
22877-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
22878+#ifdef CONFIG_SMP
22879 /*
22880 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
22881 * output PHDR, so the next output section - .init.text - should
22882@@ -190,12 +256,27 @@ SECTIONS
22883 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
22884 #endif
22885
22886- INIT_TEXT_SECTION(PAGE_SIZE)
22887-#ifdef CONFIG_X86_64
22888- :init
22889-#endif
22890+ . = ALIGN(PAGE_SIZE);
22891+ init_begin = .;
22892+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
22893+ VMLINUX_SYMBOL(_sinittext) = .;
22894+ INIT_TEXT
22895+ VMLINUX_SYMBOL(_einittext) = .;
22896+ . = ALIGN(PAGE_SIZE);
22897+ } :text.init
22898
22899- INIT_DATA_SECTION(16)
22900+ /*
22901+ * .exit.text is discard at runtime, not link time, to deal with
22902+ * references from .altinstructions and .eh_frame
22903+ */
22904+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
22905+ EXIT_TEXT
22906+ . = ALIGN(16);
22907+ } :text.exit
22908+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
22909+
22910+ . = ALIGN(PAGE_SIZE);
22911+ INIT_DATA_SECTION(16) :init
22912
22913 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
22914 __x86_cpu_dev_start = .;
22915@@ -257,19 +338,12 @@ SECTIONS
22916 }
22917
22918 . = ALIGN(8);
22919- /*
22920- * .exit.text is discard at runtime, not link time, to deal with
22921- * references from .altinstructions and .eh_frame
22922- */
22923- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
22924- EXIT_TEXT
22925- }
22926
22927 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
22928 EXIT_DATA
22929 }
22930
22931-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
22932+#ifndef CONFIG_SMP
22933 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
22934 #endif
22935
22936@@ -288,16 +362,10 @@ SECTIONS
22937 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
22938 __smp_locks = .;
22939 *(.smp_locks)
22940- . = ALIGN(PAGE_SIZE);
22941 __smp_locks_end = .;
22942+ . = ALIGN(PAGE_SIZE);
22943 }
22944
22945-#ifdef CONFIG_X86_64
22946- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
22947- NOSAVE_DATA
22948- }
22949-#endif
22950-
22951 /* BSS */
22952 . = ALIGN(PAGE_SIZE);
22953 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
22954@@ -313,6 +381,7 @@ SECTIONS
22955 __brk_base = .;
22956 . += 64 * 1024; /* 64k alignment slop space */
22957 *(.brk_reservation) /* areas brk users have reserved */
22958+ . = ALIGN(HPAGE_SIZE);
22959 __brk_limit = .;
22960 }
22961
22962@@ -339,13 +408,12 @@ SECTIONS
22963 * for the boot processor.
22964 */
22965 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
22966-INIT_PER_CPU(gdt_page);
22967 INIT_PER_CPU(irq_stack_union);
22968
22969 /*
22970 * Build-time check on the image size:
22971 */
22972-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
22973+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
22974 "kernel image bigger than KERNEL_IMAGE_SIZE");
22975
22976 #ifdef CONFIG_SMP
22977diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
22978index 9a907a6..f83f921 100644
22979--- a/arch/x86/kernel/vsyscall_64.c
22980+++ b/arch/x86/kernel/vsyscall_64.c
22981@@ -56,15 +56,13 @@
22982 DEFINE_VVAR(int, vgetcpu_mode);
22983 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
22984
22985-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
22986+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
22987
22988 static int __init vsyscall_setup(char *str)
22989 {
22990 if (str) {
22991 if (!strcmp("emulate", str))
22992 vsyscall_mode = EMULATE;
22993- else if (!strcmp("native", str))
22994- vsyscall_mode = NATIVE;
22995 else if (!strcmp("none", str))
22996 vsyscall_mode = NONE;
22997 else
22998@@ -323,8 +321,7 @@ do_ret:
22999 return true;
23000
23001 sigsegv:
23002- force_sig(SIGSEGV, current);
23003- return true;
23004+ do_group_exit(SIGKILL);
23005 }
23006
23007 /*
23008@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23009 extern char __vvar_page;
23010 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23011
23012- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23013- vsyscall_mode == NATIVE
23014- ? PAGE_KERNEL_VSYSCALL
23015- : PAGE_KERNEL_VVAR);
23016+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23017 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23018 (unsigned long)VSYSCALL_START);
23019
23020diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23021index 1330dd1..d220b99 100644
23022--- a/arch/x86/kernel/x8664_ksyms_64.c
23023+++ b/arch/x86/kernel/x8664_ksyms_64.c
23024@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23025 EXPORT_SYMBOL(copy_user_generic_unrolled);
23026 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23027 EXPORT_SYMBOL(__copy_user_nocache);
23028-EXPORT_SYMBOL(_copy_from_user);
23029-EXPORT_SYMBOL(_copy_to_user);
23030
23031 EXPORT_SYMBOL(copy_page);
23032 EXPORT_SYMBOL(clear_page);
23033diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23034index 7a3d075..6cb373d 100644
23035--- a/arch/x86/kernel/x86_init.c
23036+++ b/arch/x86/kernel/x86_init.c
23037@@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
23038 },
23039 };
23040
23041-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23042+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23043 .early_percpu_clock_init = x86_init_noop,
23044 .setup_percpu_clockev = setup_secondary_APIC_clock,
23045 };
23046@@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23047 static void default_nmi_init(void) { };
23048 static int default_i8042_detect(void) { return 1; };
23049
23050-struct x86_platform_ops x86_platform = {
23051+struct x86_platform_ops x86_platform __read_only = {
23052 .calibrate_tsc = native_calibrate_tsc,
23053 .get_wallclock = mach_get_cmos_time,
23054 .set_wallclock = mach_set_rtc_mmss,
23055@@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
23056 };
23057
23058 EXPORT_SYMBOL_GPL(x86_platform);
23059-struct x86_msi_ops x86_msi = {
23060+struct x86_msi_ops x86_msi __read_only = {
23061 .setup_msi_irqs = native_setup_msi_irqs,
23062 .teardown_msi_irq = native_teardown_msi_irq,
23063 .teardown_msi_irqs = default_teardown_msi_irqs,
23064 .restore_msi_irqs = default_restore_msi_irqs,
23065 };
23066
23067-struct x86_io_apic_ops x86_io_apic_ops = {
23068+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23069 .init = native_io_apic_init_mappings,
23070 .read = native_io_apic_read,
23071 .write = native_io_apic_write,
23072diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23073index ada87a3..afea76d 100644
23074--- a/arch/x86/kernel/xsave.c
23075+++ b/arch/x86/kernel/xsave.c
23076@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23077 {
23078 int err;
23079
23080+ buf = (struct xsave_struct __user *)____m(buf);
23081 if (use_xsave())
23082 err = xsave_user(buf);
23083 else if (use_fxsr())
23084@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
23085 */
23086 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
23087 {
23088+ buf = (void __user *)____m(buf);
23089 if (use_xsave()) {
23090 if ((unsigned long)buf % 64 || fx_only) {
23091 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
23092diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
23093index a20ecb5..d0e2194 100644
23094--- a/arch/x86/kvm/cpuid.c
23095+++ b/arch/x86/kvm/cpuid.c
23096@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
23097 struct kvm_cpuid2 *cpuid,
23098 struct kvm_cpuid_entry2 __user *entries)
23099 {
23100- int r;
23101+ int r, i;
23102
23103 r = -E2BIG;
23104 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
23105 goto out;
23106 r = -EFAULT;
23107- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
23108- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23109+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23110 goto out;
23111+ for (i = 0; i < cpuid->nent; ++i) {
23112+ struct kvm_cpuid_entry2 cpuid_entry;
23113+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
23114+ goto out;
23115+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
23116+ }
23117 vcpu->arch.cpuid_nent = cpuid->nent;
23118 kvm_apic_set_version(vcpu);
23119 kvm_x86_ops->cpuid_update(vcpu);
23120@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
23121 struct kvm_cpuid2 *cpuid,
23122 struct kvm_cpuid_entry2 __user *entries)
23123 {
23124- int r;
23125+ int r, i;
23126
23127 r = -E2BIG;
23128 if (cpuid->nent < vcpu->arch.cpuid_nent)
23129 goto out;
23130 r = -EFAULT;
23131- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
23132- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23133+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23134 goto out;
23135+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
23136+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
23137+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
23138+ goto out;
23139+ }
23140 return 0;
23141
23142 out:
23143diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
23144index a27e763..54bfe43 100644
23145--- a/arch/x86/kvm/emulate.c
23146+++ b/arch/x86/kvm/emulate.c
23147@@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23148
23149 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
23150 do { \
23151+ unsigned long _tmp; \
23152 __asm__ __volatile__ ( \
23153 _PRE_EFLAGS("0", "4", "2") \
23154 _op _suffix " %"_x"3,%1; " \
23155@@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23156 /* Raw emulation: instruction has two explicit operands. */
23157 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
23158 do { \
23159- unsigned long _tmp; \
23160- \
23161 switch ((ctxt)->dst.bytes) { \
23162 case 2: \
23163 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
23164@@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23165
23166 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
23167 do { \
23168- unsigned long _tmp; \
23169 switch ((ctxt)->dst.bytes) { \
23170 case 1: \
23171 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
23172diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
23173index 9392f52..0e56d77 100644
23174--- a/arch/x86/kvm/lapic.c
23175+++ b/arch/x86/kvm/lapic.c
23176@@ -55,7 +55,7 @@
23177 #define APIC_BUS_CYCLE_NS 1
23178
23179 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
23180-#define apic_debug(fmt, arg...)
23181+#define apic_debug(fmt, arg...) do {} while (0)
23182
23183 #define APIC_LVT_NUM 6
23184 /* 14 is the version for Xeon and Pentium 8.4.8*/
23185diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
23186index 891eb6d..e027900 100644
23187--- a/arch/x86/kvm/paging_tmpl.h
23188+++ b/arch/x86/kvm/paging_tmpl.h
23189@@ -208,7 +208,7 @@ retry_walk:
23190 if (unlikely(kvm_is_error_hva(host_addr)))
23191 goto error;
23192
23193- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
23194+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
23195 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
23196 goto error;
23197 walker->ptep_user[walker->level - 1] = ptep_user;
23198diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
23199index d29d3cd..ec9d522 100644
23200--- a/arch/x86/kvm/svm.c
23201+++ b/arch/x86/kvm/svm.c
23202@@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
23203 int cpu = raw_smp_processor_id();
23204
23205 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
23206+
23207+ pax_open_kernel();
23208 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
23209+ pax_close_kernel();
23210+
23211 load_TR_desc();
23212 }
23213
23214@@ -3881,6 +3885,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
23215 #endif
23216 #endif
23217
23218+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23219+ __set_fs(current_thread_info()->addr_limit);
23220+#endif
23221+
23222 reload_tss(vcpu);
23223
23224 local_irq_disable();
23225diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
23226index 9120ae1..238abc0 100644
23227--- a/arch/x86/kvm/vmx.c
23228+++ b/arch/x86/kvm/vmx.c
23229@@ -1370,7 +1370,11 @@ static void reload_tss(void)
23230 struct desc_struct *descs;
23231
23232 descs = (void *)gdt->address;
23233+
23234+ pax_open_kernel();
23235 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
23236+ pax_close_kernel();
23237+
23238 load_TR_desc();
23239 }
23240
23241@@ -1594,6 +1598,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
23242 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
23243 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
23244
23245+#ifdef CONFIG_PAX_PER_CPU_PGD
23246+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23247+#endif
23248+
23249 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
23250 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
23251 vmx->loaded_vmcs->cpu = cpu;
23252@@ -2738,8 +2746,11 @@ static __init int hardware_setup(void)
23253 if (!cpu_has_vmx_flexpriority())
23254 flexpriority_enabled = 0;
23255
23256- if (!cpu_has_vmx_tpr_shadow())
23257- kvm_x86_ops->update_cr8_intercept = NULL;
23258+ if (!cpu_has_vmx_tpr_shadow()) {
23259+ pax_open_kernel();
23260+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
23261+ pax_close_kernel();
23262+ }
23263
23264 if (enable_ept && !cpu_has_vmx_ept_2m_page())
23265 kvm_disable_largepages();
23266@@ -3782,7 +3793,10 @@ static void vmx_set_constant_host_state(void)
23267
23268 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
23269 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
23270+
23271+#ifndef CONFIG_PAX_PER_CPU_PGD
23272 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23273+#endif
23274
23275 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
23276 #ifdef CONFIG_X86_64
23277@@ -3803,7 +3817,7 @@ static void vmx_set_constant_host_state(void)
23278 native_store_idt(&dt);
23279 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
23280
23281- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
23282+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
23283
23284 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
23285 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
23286@@ -6355,6 +6369,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23287 "jmp 2f \n\t"
23288 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
23289 "2: "
23290+
23291+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23292+ "ljmp %[cs],$3f\n\t"
23293+ "3: "
23294+#endif
23295+
23296 /* Save guest registers, load host registers, keep flags */
23297 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
23298 "pop %0 \n\t"
23299@@ -6407,6 +6427,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23300 #endif
23301 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
23302 [wordsize]"i"(sizeof(ulong))
23303+
23304+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23305+ ,[cs]"i"(__KERNEL_CS)
23306+#endif
23307+
23308 : "cc", "memory"
23309 #ifdef CONFIG_X86_64
23310 , "rax", "rbx", "rdi", "rsi"
23311@@ -6420,7 +6445,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23312 if (debugctlmsr)
23313 update_debugctlmsr(debugctlmsr);
23314
23315-#ifndef CONFIG_X86_64
23316+#ifdef CONFIG_X86_32
23317 /*
23318 * The sysexit path does not restore ds/es, so we must set them to
23319 * a reasonable value ourselves.
23320@@ -6429,8 +6454,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23321 * may be executed in interrupt context, which saves and restore segments
23322 * around it, nullifying its effect.
23323 */
23324- loadsegment(ds, __USER_DS);
23325- loadsegment(es, __USER_DS);
23326+ loadsegment(ds, __KERNEL_DS);
23327+ loadsegment(es, __KERNEL_DS);
23328+ loadsegment(ss, __KERNEL_DS);
23329+
23330+#ifdef CONFIG_PAX_KERNEXEC
23331+ loadsegment(fs, __KERNEL_PERCPU);
23332+#endif
23333+
23334+#ifdef CONFIG_PAX_MEMORY_UDEREF
23335+ __set_fs(current_thread_info()->addr_limit);
23336+#endif
23337+
23338 #endif
23339
23340 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
23341diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
23342index c243b81..9eb193f 100644
23343--- a/arch/x86/kvm/x86.c
23344+++ b/arch/x86/kvm/x86.c
23345@@ -1692,8 +1692,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
23346 {
23347 struct kvm *kvm = vcpu->kvm;
23348 int lm = is_long_mode(vcpu);
23349- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23350- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
23351+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23352+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
23353 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
23354 : kvm->arch.xen_hvm_config.blob_size_32;
23355 u32 page_num = data & ~PAGE_MASK;
23356@@ -2571,6 +2571,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
23357 if (n < msr_list.nmsrs)
23358 goto out;
23359 r = -EFAULT;
23360+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
23361+ goto out;
23362 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
23363 num_msrs_to_save * sizeof(u32)))
23364 goto out;
23365@@ -2700,7 +2702,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
23366 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
23367 struct kvm_interrupt *irq)
23368 {
23369- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
23370+ if (irq->irq >= KVM_NR_INTERRUPTS)
23371 return -EINVAL;
23372 if (irqchip_in_kernel(vcpu->kvm))
23373 return -ENXIO;
23374@@ -5213,7 +5215,7 @@ static struct notifier_block pvclock_gtod_notifier = {
23375 };
23376 #endif
23377
23378-int kvm_arch_init(void *opaque)
23379+int kvm_arch_init(const void *opaque)
23380 {
23381 int r;
23382 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
23383diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
23384index df4176c..23ce092 100644
23385--- a/arch/x86/lguest/boot.c
23386+++ b/arch/x86/lguest/boot.c
23387@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
23388 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
23389 * Launcher to reboot us.
23390 */
23391-static void lguest_restart(char *reason)
23392+static __noreturn void lguest_restart(char *reason)
23393 {
23394 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
23395+ BUG();
23396 }
23397
23398 /*G:050
23399diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
23400index 00933d5..3a64af9 100644
23401--- a/arch/x86/lib/atomic64_386_32.S
23402+++ b/arch/x86/lib/atomic64_386_32.S
23403@@ -48,6 +48,10 @@ BEGIN(read)
23404 movl (v), %eax
23405 movl 4(v), %edx
23406 RET_ENDP
23407+BEGIN(read_unchecked)
23408+ movl (v), %eax
23409+ movl 4(v), %edx
23410+RET_ENDP
23411 #undef v
23412
23413 #define v %esi
23414@@ -55,6 +59,10 @@ BEGIN(set)
23415 movl %ebx, (v)
23416 movl %ecx, 4(v)
23417 RET_ENDP
23418+BEGIN(set_unchecked)
23419+ movl %ebx, (v)
23420+ movl %ecx, 4(v)
23421+RET_ENDP
23422 #undef v
23423
23424 #define v %esi
23425@@ -70,6 +78,20 @@ RET_ENDP
23426 BEGIN(add)
23427 addl %eax, (v)
23428 adcl %edx, 4(v)
23429+
23430+#ifdef CONFIG_PAX_REFCOUNT
23431+ jno 0f
23432+ subl %eax, (v)
23433+ sbbl %edx, 4(v)
23434+ int $4
23435+0:
23436+ _ASM_EXTABLE(0b, 0b)
23437+#endif
23438+
23439+RET_ENDP
23440+BEGIN(add_unchecked)
23441+ addl %eax, (v)
23442+ adcl %edx, 4(v)
23443 RET_ENDP
23444 #undef v
23445
23446@@ -77,6 +99,24 @@ RET_ENDP
23447 BEGIN(add_return)
23448 addl (v), %eax
23449 adcl 4(v), %edx
23450+
23451+#ifdef CONFIG_PAX_REFCOUNT
23452+ into
23453+1234:
23454+ _ASM_EXTABLE(1234b, 2f)
23455+#endif
23456+
23457+ movl %eax, (v)
23458+ movl %edx, 4(v)
23459+
23460+#ifdef CONFIG_PAX_REFCOUNT
23461+2:
23462+#endif
23463+
23464+RET_ENDP
23465+BEGIN(add_return_unchecked)
23466+ addl (v), %eax
23467+ adcl 4(v), %edx
23468 movl %eax, (v)
23469 movl %edx, 4(v)
23470 RET_ENDP
23471@@ -86,6 +126,20 @@ RET_ENDP
23472 BEGIN(sub)
23473 subl %eax, (v)
23474 sbbl %edx, 4(v)
23475+
23476+#ifdef CONFIG_PAX_REFCOUNT
23477+ jno 0f
23478+ addl %eax, (v)
23479+ adcl %edx, 4(v)
23480+ int $4
23481+0:
23482+ _ASM_EXTABLE(0b, 0b)
23483+#endif
23484+
23485+RET_ENDP
23486+BEGIN(sub_unchecked)
23487+ subl %eax, (v)
23488+ sbbl %edx, 4(v)
23489 RET_ENDP
23490 #undef v
23491
23492@@ -96,6 +150,27 @@ BEGIN(sub_return)
23493 sbbl $0, %edx
23494 addl (v), %eax
23495 adcl 4(v), %edx
23496+
23497+#ifdef CONFIG_PAX_REFCOUNT
23498+ into
23499+1234:
23500+ _ASM_EXTABLE(1234b, 2f)
23501+#endif
23502+
23503+ movl %eax, (v)
23504+ movl %edx, 4(v)
23505+
23506+#ifdef CONFIG_PAX_REFCOUNT
23507+2:
23508+#endif
23509+
23510+RET_ENDP
23511+BEGIN(sub_return_unchecked)
23512+ negl %edx
23513+ negl %eax
23514+ sbbl $0, %edx
23515+ addl (v), %eax
23516+ adcl 4(v), %edx
23517 movl %eax, (v)
23518 movl %edx, 4(v)
23519 RET_ENDP
23520@@ -105,6 +180,20 @@ RET_ENDP
23521 BEGIN(inc)
23522 addl $1, (v)
23523 adcl $0, 4(v)
23524+
23525+#ifdef CONFIG_PAX_REFCOUNT
23526+ jno 0f
23527+ subl $1, (v)
23528+ sbbl $0, 4(v)
23529+ int $4
23530+0:
23531+ _ASM_EXTABLE(0b, 0b)
23532+#endif
23533+
23534+RET_ENDP
23535+BEGIN(inc_unchecked)
23536+ addl $1, (v)
23537+ adcl $0, 4(v)
23538 RET_ENDP
23539 #undef v
23540
23541@@ -114,6 +203,26 @@ BEGIN(inc_return)
23542 movl 4(v), %edx
23543 addl $1, %eax
23544 adcl $0, %edx
23545+
23546+#ifdef CONFIG_PAX_REFCOUNT
23547+ into
23548+1234:
23549+ _ASM_EXTABLE(1234b, 2f)
23550+#endif
23551+
23552+ movl %eax, (v)
23553+ movl %edx, 4(v)
23554+
23555+#ifdef CONFIG_PAX_REFCOUNT
23556+2:
23557+#endif
23558+
23559+RET_ENDP
23560+BEGIN(inc_return_unchecked)
23561+ movl (v), %eax
23562+ movl 4(v), %edx
23563+ addl $1, %eax
23564+ adcl $0, %edx
23565 movl %eax, (v)
23566 movl %edx, 4(v)
23567 RET_ENDP
23568@@ -123,6 +232,20 @@ RET_ENDP
23569 BEGIN(dec)
23570 subl $1, (v)
23571 sbbl $0, 4(v)
23572+
23573+#ifdef CONFIG_PAX_REFCOUNT
23574+ jno 0f
23575+ addl $1, (v)
23576+ adcl $0, 4(v)
23577+ int $4
23578+0:
23579+ _ASM_EXTABLE(0b, 0b)
23580+#endif
23581+
23582+RET_ENDP
23583+BEGIN(dec_unchecked)
23584+ subl $1, (v)
23585+ sbbl $0, 4(v)
23586 RET_ENDP
23587 #undef v
23588
23589@@ -132,6 +255,26 @@ BEGIN(dec_return)
23590 movl 4(v), %edx
23591 subl $1, %eax
23592 sbbl $0, %edx
23593+
23594+#ifdef CONFIG_PAX_REFCOUNT
23595+ into
23596+1234:
23597+ _ASM_EXTABLE(1234b, 2f)
23598+#endif
23599+
23600+ movl %eax, (v)
23601+ movl %edx, 4(v)
23602+
23603+#ifdef CONFIG_PAX_REFCOUNT
23604+2:
23605+#endif
23606+
23607+RET_ENDP
23608+BEGIN(dec_return_unchecked)
23609+ movl (v), %eax
23610+ movl 4(v), %edx
23611+ subl $1, %eax
23612+ sbbl $0, %edx
23613 movl %eax, (v)
23614 movl %edx, 4(v)
23615 RET_ENDP
23616@@ -143,6 +286,13 @@ BEGIN(add_unless)
23617 adcl %edx, %edi
23618 addl (v), %eax
23619 adcl 4(v), %edx
23620+
23621+#ifdef CONFIG_PAX_REFCOUNT
23622+ into
23623+1234:
23624+ _ASM_EXTABLE(1234b, 2f)
23625+#endif
23626+
23627 cmpl %eax, %ecx
23628 je 3f
23629 1:
23630@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
23631 1:
23632 addl $1, %eax
23633 adcl $0, %edx
23634+
23635+#ifdef CONFIG_PAX_REFCOUNT
23636+ into
23637+1234:
23638+ _ASM_EXTABLE(1234b, 2f)
23639+#endif
23640+
23641 movl %eax, (v)
23642 movl %edx, 4(v)
23643 movl $1, %eax
23644@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
23645 movl 4(v), %edx
23646 subl $1, %eax
23647 sbbl $0, %edx
23648+
23649+#ifdef CONFIG_PAX_REFCOUNT
23650+ into
23651+1234:
23652+ _ASM_EXTABLE(1234b, 1f)
23653+#endif
23654+
23655 js 1f
23656 movl %eax, (v)
23657 movl %edx, 4(v)
23658diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
23659index f5cc9eb..51fa319 100644
23660--- a/arch/x86/lib/atomic64_cx8_32.S
23661+++ b/arch/x86/lib/atomic64_cx8_32.S
23662@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
23663 CFI_STARTPROC
23664
23665 read64 %ecx
23666+ pax_force_retaddr
23667 ret
23668 CFI_ENDPROC
23669 ENDPROC(atomic64_read_cx8)
23670
23671+ENTRY(atomic64_read_unchecked_cx8)
23672+ CFI_STARTPROC
23673+
23674+ read64 %ecx
23675+ pax_force_retaddr
23676+ ret
23677+ CFI_ENDPROC
23678+ENDPROC(atomic64_read_unchecked_cx8)
23679+
23680 ENTRY(atomic64_set_cx8)
23681 CFI_STARTPROC
23682
23683@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
23684 cmpxchg8b (%esi)
23685 jne 1b
23686
23687+ pax_force_retaddr
23688 ret
23689 CFI_ENDPROC
23690 ENDPROC(atomic64_set_cx8)
23691
23692+ENTRY(atomic64_set_unchecked_cx8)
23693+ CFI_STARTPROC
23694+
23695+1:
23696+/* we don't need LOCK_PREFIX since aligned 64-bit writes
23697+ * are atomic on 586 and newer */
23698+ cmpxchg8b (%esi)
23699+ jne 1b
23700+
23701+ pax_force_retaddr
23702+ ret
23703+ CFI_ENDPROC
23704+ENDPROC(atomic64_set_unchecked_cx8)
23705+
23706 ENTRY(atomic64_xchg_cx8)
23707 CFI_STARTPROC
23708
23709@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
23710 cmpxchg8b (%esi)
23711 jne 1b
23712
23713+ pax_force_retaddr
23714 ret
23715 CFI_ENDPROC
23716 ENDPROC(atomic64_xchg_cx8)
23717
23718-.macro addsub_return func ins insc
23719-ENTRY(atomic64_\func\()_return_cx8)
23720+.macro addsub_return func ins insc unchecked=""
23721+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
23722 CFI_STARTPROC
23723 SAVE ebp
23724 SAVE ebx
23725@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
23726 movl %edx, %ecx
23727 \ins\()l %esi, %ebx
23728 \insc\()l %edi, %ecx
23729+
23730+.ifb \unchecked
23731+#ifdef CONFIG_PAX_REFCOUNT
23732+ into
23733+2:
23734+ _ASM_EXTABLE(2b, 3f)
23735+#endif
23736+.endif
23737+
23738 LOCK_PREFIX
23739 cmpxchg8b (%ebp)
23740 jne 1b
23741-
23742-10:
23743 movl %ebx, %eax
23744 movl %ecx, %edx
23745+
23746+.ifb \unchecked
23747+#ifdef CONFIG_PAX_REFCOUNT
23748+3:
23749+#endif
23750+.endif
23751+
23752 RESTORE edi
23753 RESTORE esi
23754 RESTORE ebx
23755 RESTORE ebp
23756+ pax_force_retaddr
23757 ret
23758 CFI_ENDPROC
23759-ENDPROC(atomic64_\func\()_return_cx8)
23760+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
23761 .endm
23762
23763 addsub_return add add adc
23764 addsub_return sub sub sbb
23765+addsub_return add add adc _unchecked
23766+addsub_return sub sub sbb _unchecked
23767
23768-.macro incdec_return func ins insc
23769-ENTRY(atomic64_\func\()_return_cx8)
23770+.macro incdec_return func ins insc unchecked=""
23771+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
23772 CFI_STARTPROC
23773 SAVE ebx
23774
23775@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
23776 movl %edx, %ecx
23777 \ins\()l $1, %ebx
23778 \insc\()l $0, %ecx
23779+
23780+.ifb \unchecked
23781+#ifdef CONFIG_PAX_REFCOUNT
23782+ into
23783+2:
23784+ _ASM_EXTABLE(2b, 3f)
23785+#endif
23786+.endif
23787+
23788 LOCK_PREFIX
23789 cmpxchg8b (%esi)
23790 jne 1b
23791
23792-10:
23793 movl %ebx, %eax
23794 movl %ecx, %edx
23795+
23796+.ifb \unchecked
23797+#ifdef CONFIG_PAX_REFCOUNT
23798+3:
23799+#endif
23800+.endif
23801+
23802 RESTORE ebx
23803+ pax_force_retaddr
23804 ret
23805 CFI_ENDPROC
23806-ENDPROC(atomic64_\func\()_return_cx8)
23807+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
23808 .endm
23809
23810 incdec_return inc add adc
23811 incdec_return dec sub sbb
23812+incdec_return inc add adc _unchecked
23813+incdec_return dec sub sbb _unchecked
23814
23815 ENTRY(atomic64_dec_if_positive_cx8)
23816 CFI_STARTPROC
23817@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
23818 movl %edx, %ecx
23819 subl $1, %ebx
23820 sbb $0, %ecx
23821+
23822+#ifdef CONFIG_PAX_REFCOUNT
23823+ into
23824+1234:
23825+ _ASM_EXTABLE(1234b, 2f)
23826+#endif
23827+
23828 js 2f
23829 LOCK_PREFIX
23830 cmpxchg8b (%esi)
23831@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
23832 movl %ebx, %eax
23833 movl %ecx, %edx
23834 RESTORE ebx
23835+ pax_force_retaddr
23836 ret
23837 CFI_ENDPROC
23838 ENDPROC(atomic64_dec_if_positive_cx8)
23839@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
23840 movl %edx, %ecx
23841 addl %ebp, %ebx
23842 adcl %edi, %ecx
23843+
23844+#ifdef CONFIG_PAX_REFCOUNT
23845+ into
23846+1234:
23847+ _ASM_EXTABLE(1234b, 3f)
23848+#endif
23849+
23850 LOCK_PREFIX
23851 cmpxchg8b (%esi)
23852 jne 1b
23853@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
23854 CFI_ADJUST_CFA_OFFSET -8
23855 RESTORE ebx
23856 RESTORE ebp
23857+ pax_force_retaddr
23858 ret
23859 4:
23860 cmpl %edx, 4(%esp)
23861@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
23862 xorl %ecx, %ecx
23863 addl $1, %ebx
23864 adcl %edx, %ecx
23865+
23866+#ifdef CONFIG_PAX_REFCOUNT
23867+ into
23868+1234:
23869+ _ASM_EXTABLE(1234b, 3f)
23870+#endif
23871+
23872 LOCK_PREFIX
23873 cmpxchg8b (%esi)
23874 jne 1b
23875@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
23876 movl $1, %eax
23877 3:
23878 RESTORE ebx
23879+ pax_force_retaddr
23880 ret
23881 CFI_ENDPROC
23882 ENDPROC(atomic64_inc_not_zero_cx8)
23883diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
23884index 2af5df3..62b1a5a 100644
23885--- a/arch/x86/lib/checksum_32.S
23886+++ b/arch/x86/lib/checksum_32.S
23887@@ -29,7 +29,8 @@
23888 #include <asm/dwarf2.h>
23889 #include <asm/errno.h>
23890 #include <asm/asm.h>
23891-
23892+#include <asm/segment.h>
23893+
23894 /*
23895 * computes a partial checksum, e.g. for TCP/UDP fragments
23896 */
23897@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
23898
23899 #define ARGBASE 16
23900 #define FP 12
23901-
23902-ENTRY(csum_partial_copy_generic)
23903+
23904+ENTRY(csum_partial_copy_generic_to_user)
23905 CFI_STARTPROC
23906+
23907+#ifdef CONFIG_PAX_MEMORY_UDEREF
23908+ pushl_cfi %gs
23909+ popl_cfi %es
23910+ jmp csum_partial_copy_generic
23911+#endif
23912+
23913+ENTRY(csum_partial_copy_generic_from_user)
23914+
23915+#ifdef CONFIG_PAX_MEMORY_UDEREF
23916+ pushl_cfi %gs
23917+ popl_cfi %ds
23918+#endif
23919+
23920+ENTRY(csum_partial_copy_generic)
23921 subl $4,%esp
23922 CFI_ADJUST_CFA_OFFSET 4
23923 pushl_cfi %edi
23924@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
23925 jmp 4f
23926 SRC(1: movw (%esi), %bx )
23927 addl $2, %esi
23928-DST( movw %bx, (%edi) )
23929+DST( movw %bx, %es:(%edi) )
23930 addl $2, %edi
23931 addw %bx, %ax
23932 adcl $0, %eax
23933@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
23934 SRC(1: movl (%esi), %ebx )
23935 SRC( movl 4(%esi), %edx )
23936 adcl %ebx, %eax
23937-DST( movl %ebx, (%edi) )
23938+DST( movl %ebx, %es:(%edi) )
23939 adcl %edx, %eax
23940-DST( movl %edx, 4(%edi) )
23941+DST( movl %edx, %es:4(%edi) )
23942
23943 SRC( movl 8(%esi), %ebx )
23944 SRC( movl 12(%esi), %edx )
23945 adcl %ebx, %eax
23946-DST( movl %ebx, 8(%edi) )
23947+DST( movl %ebx, %es:8(%edi) )
23948 adcl %edx, %eax
23949-DST( movl %edx, 12(%edi) )
23950+DST( movl %edx, %es:12(%edi) )
23951
23952 SRC( movl 16(%esi), %ebx )
23953 SRC( movl 20(%esi), %edx )
23954 adcl %ebx, %eax
23955-DST( movl %ebx, 16(%edi) )
23956+DST( movl %ebx, %es:16(%edi) )
23957 adcl %edx, %eax
23958-DST( movl %edx, 20(%edi) )
23959+DST( movl %edx, %es:20(%edi) )
23960
23961 SRC( movl 24(%esi), %ebx )
23962 SRC( movl 28(%esi), %edx )
23963 adcl %ebx, %eax
23964-DST( movl %ebx, 24(%edi) )
23965+DST( movl %ebx, %es:24(%edi) )
23966 adcl %edx, %eax
23967-DST( movl %edx, 28(%edi) )
23968+DST( movl %edx, %es:28(%edi) )
23969
23970 lea 32(%esi), %esi
23971 lea 32(%edi), %edi
23972@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
23973 shrl $2, %edx # This clears CF
23974 SRC(3: movl (%esi), %ebx )
23975 adcl %ebx, %eax
23976-DST( movl %ebx, (%edi) )
23977+DST( movl %ebx, %es:(%edi) )
23978 lea 4(%esi), %esi
23979 lea 4(%edi), %edi
23980 dec %edx
23981@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
23982 jb 5f
23983 SRC( movw (%esi), %cx )
23984 leal 2(%esi), %esi
23985-DST( movw %cx, (%edi) )
23986+DST( movw %cx, %es:(%edi) )
23987 leal 2(%edi), %edi
23988 je 6f
23989 shll $16,%ecx
23990 SRC(5: movb (%esi), %cl )
23991-DST( movb %cl, (%edi) )
23992+DST( movb %cl, %es:(%edi) )
23993 6: addl %ecx, %eax
23994 adcl $0, %eax
23995 7:
23996@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
23997
23998 6001:
23999 movl ARGBASE+20(%esp), %ebx # src_err_ptr
24000- movl $-EFAULT, (%ebx)
24001+ movl $-EFAULT, %ss:(%ebx)
24002
24003 # zero the complete destination - computing the rest
24004 # is too much work
24005@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24006
24007 6002:
24008 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24009- movl $-EFAULT,(%ebx)
24010+ movl $-EFAULT,%ss:(%ebx)
24011 jmp 5000b
24012
24013 .previous
24014
24015+ pushl_cfi %ss
24016+ popl_cfi %ds
24017+ pushl_cfi %ss
24018+ popl_cfi %es
24019 popl_cfi %ebx
24020 CFI_RESTORE ebx
24021 popl_cfi %esi
24022@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24023 popl_cfi %ecx # equivalent to addl $4,%esp
24024 ret
24025 CFI_ENDPROC
24026-ENDPROC(csum_partial_copy_generic)
24027+ENDPROC(csum_partial_copy_generic_to_user)
24028
24029 #else
24030
24031 /* Version for PentiumII/PPro */
24032
24033 #define ROUND1(x) \
24034+ nop; nop; nop; \
24035 SRC(movl x(%esi), %ebx ) ; \
24036 addl %ebx, %eax ; \
24037- DST(movl %ebx, x(%edi) ) ;
24038+ DST(movl %ebx, %es:x(%edi)) ;
24039
24040 #define ROUND(x) \
24041+ nop; nop; nop; \
24042 SRC(movl x(%esi), %ebx ) ; \
24043 adcl %ebx, %eax ; \
24044- DST(movl %ebx, x(%edi) ) ;
24045+ DST(movl %ebx, %es:x(%edi)) ;
24046
24047 #define ARGBASE 12
24048-
24049-ENTRY(csum_partial_copy_generic)
24050+
24051+ENTRY(csum_partial_copy_generic_to_user)
24052 CFI_STARTPROC
24053+
24054+#ifdef CONFIG_PAX_MEMORY_UDEREF
24055+ pushl_cfi %gs
24056+ popl_cfi %es
24057+ jmp csum_partial_copy_generic
24058+#endif
24059+
24060+ENTRY(csum_partial_copy_generic_from_user)
24061+
24062+#ifdef CONFIG_PAX_MEMORY_UDEREF
24063+ pushl_cfi %gs
24064+ popl_cfi %ds
24065+#endif
24066+
24067+ENTRY(csum_partial_copy_generic)
24068 pushl_cfi %ebx
24069 CFI_REL_OFFSET ebx, 0
24070 pushl_cfi %edi
24071@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
24072 subl %ebx, %edi
24073 lea -1(%esi),%edx
24074 andl $-32,%edx
24075- lea 3f(%ebx,%ebx), %ebx
24076+ lea 3f(%ebx,%ebx,2), %ebx
24077 testl %esi, %esi
24078 jmp *%ebx
24079 1: addl $64,%esi
24080@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
24081 jb 5f
24082 SRC( movw (%esi), %dx )
24083 leal 2(%esi), %esi
24084-DST( movw %dx, (%edi) )
24085+DST( movw %dx, %es:(%edi) )
24086 leal 2(%edi), %edi
24087 je 6f
24088 shll $16,%edx
24089 5:
24090 SRC( movb (%esi), %dl )
24091-DST( movb %dl, (%edi) )
24092+DST( movb %dl, %es:(%edi) )
24093 6: addl %edx, %eax
24094 adcl $0, %eax
24095 7:
24096 .section .fixup, "ax"
24097 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
24098- movl $-EFAULT, (%ebx)
24099+ movl $-EFAULT, %ss:(%ebx)
24100 # zero the complete destination (computing the rest is too much work)
24101 movl ARGBASE+8(%esp),%edi # dst
24102 movl ARGBASE+12(%esp),%ecx # len
24103@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
24104 rep; stosb
24105 jmp 7b
24106 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24107- movl $-EFAULT, (%ebx)
24108+ movl $-EFAULT, %ss:(%ebx)
24109 jmp 7b
24110 .previous
24111
24112+#ifdef CONFIG_PAX_MEMORY_UDEREF
24113+ pushl_cfi %ss
24114+ popl_cfi %ds
24115+ pushl_cfi %ss
24116+ popl_cfi %es
24117+#endif
24118+
24119 popl_cfi %esi
24120 CFI_RESTORE esi
24121 popl_cfi %edi
24122@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
24123 CFI_RESTORE ebx
24124 ret
24125 CFI_ENDPROC
24126-ENDPROC(csum_partial_copy_generic)
24127+ENDPROC(csum_partial_copy_generic_to_user)
24128
24129 #undef ROUND
24130 #undef ROUND1
24131diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
24132index f2145cf..cea889d 100644
24133--- a/arch/x86/lib/clear_page_64.S
24134+++ b/arch/x86/lib/clear_page_64.S
24135@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
24136 movl $4096/8,%ecx
24137 xorl %eax,%eax
24138 rep stosq
24139+ pax_force_retaddr
24140 ret
24141 CFI_ENDPROC
24142 ENDPROC(clear_page_c)
24143@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
24144 movl $4096,%ecx
24145 xorl %eax,%eax
24146 rep stosb
24147+ pax_force_retaddr
24148 ret
24149 CFI_ENDPROC
24150 ENDPROC(clear_page_c_e)
24151@@ -43,6 +45,7 @@ ENTRY(clear_page)
24152 leaq 64(%rdi),%rdi
24153 jnz .Lloop
24154 nop
24155+ pax_force_retaddr
24156 ret
24157 CFI_ENDPROC
24158 .Lclear_page_end:
24159@@ -58,7 +61,7 @@ ENDPROC(clear_page)
24160
24161 #include <asm/cpufeature.h>
24162
24163- .section .altinstr_replacement,"ax"
24164+ .section .altinstr_replacement,"a"
24165 1: .byte 0xeb /* jmp <disp8> */
24166 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
24167 2: .byte 0xeb /* jmp <disp8> */
24168diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
24169index 1e572c5..2a162cd 100644
24170--- a/arch/x86/lib/cmpxchg16b_emu.S
24171+++ b/arch/x86/lib/cmpxchg16b_emu.S
24172@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
24173
24174 popf
24175 mov $1, %al
24176+ pax_force_retaddr
24177 ret
24178
24179 not_same:
24180 popf
24181 xor %al,%al
24182+ pax_force_retaddr
24183 ret
24184
24185 CFI_ENDPROC
24186diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
24187index 176cca6..1166c50 100644
24188--- a/arch/x86/lib/copy_page_64.S
24189+++ b/arch/x86/lib/copy_page_64.S
24190@@ -9,6 +9,7 @@ copy_page_rep:
24191 CFI_STARTPROC
24192 movl $4096/8, %ecx
24193 rep movsq
24194+ pax_force_retaddr
24195 ret
24196 CFI_ENDPROC
24197 ENDPROC(copy_page_rep)
24198@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
24199
24200 ENTRY(copy_page)
24201 CFI_STARTPROC
24202- subq $2*8, %rsp
24203- CFI_ADJUST_CFA_OFFSET 2*8
24204+ subq $3*8, %rsp
24205+ CFI_ADJUST_CFA_OFFSET 3*8
24206 movq %rbx, (%rsp)
24207 CFI_REL_OFFSET rbx, 0
24208 movq %r12, 1*8(%rsp)
24209 CFI_REL_OFFSET r12, 1*8
24210+ movq %r13, 2*8(%rsp)
24211+ CFI_REL_OFFSET r13, 2*8
24212
24213 movl $(4096/64)-5, %ecx
24214 .p2align 4
24215@@ -36,7 +39,7 @@ ENTRY(copy_page)
24216 movq 0x8*2(%rsi), %rdx
24217 movq 0x8*3(%rsi), %r8
24218 movq 0x8*4(%rsi), %r9
24219- movq 0x8*5(%rsi), %r10
24220+ movq 0x8*5(%rsi), %r13
24221 movq 0x8*6(%rsi), %r11
24222 movq 0x8*7(%rsi), %r12
24223
24224@@ -47,7 +50,7 @@ ENTRY(copy_page)
24225 movq %rdx, 0x8*2(%rdi)
24226 movq %r8, 0x8*3(%rdi)
24227 movq %r9, 0x8*4(%rdi)
24228- movq %r10, 0x8*5(%rdi)
24229+ movq %r13, 0x8*5(%rdi)
24230 movq %r11, 0x8*6(%rdi)
24231 movq %r12, 0x8*7(%rdi)
24232
24233@@ -66,7 +69,7 @@ ENTRY(copy_page)
24234 movq 0x8*2(%rsi), %rdx
24235 movq 0x8*3(%rsi), %r8
24236 movq 0x8*4(%rsi), %r9
24237- movq 0x8*5(%rsi), %r10
24238+ movq 0x8*5(%rsi), %r13
24239 movq 0x8*6(%rsi), %r11
24240 movq 0x8*7(%rsi), %r12
24241
24242@@ -75,7 +78,7 @@ ENTRY(copy_page)
24243 movq %rdx, 0x8*2(%rdi)
24244 movq %r8, 0x8*3(%rdi)
24245 movq %r9, 0x8*4(%rdi)
24246- movq %r10, 0x8*5(%rdi)
24247+ movq %r13, 0x8*5(%rdi)
24248 movq %r11, 0x8*6(%rdi)
24249 movq %r12, 0x8*7(%rdi)
24250
24251@@ -87,8 +90,11 @@ ENTRY(copy_page)
24252 CFI_RESTORE rbx
24253 movq 1*8(%rsp), %r12
24254 CFI_RESTORE r12
24255- addq $2*8, %rsp
24256- CFI_ADJUST_CFA_OFFSET -2*8
24257+ movq 2*8(%rsp), %r13
24258+ CFI_RESTORE r13
24259+ addq $3*8, %rsp
24260+ CFI_ADJUST_CFA_OFFSET -3*8
24261+ pax_force_retaddr
24262 ret
24263 .Lcopy_page_end:
24264 CFI_ENDPROC
24265@@ -99,7 +105,7 @@ ENDPROC(copy_page)
24266
24267 #include <asm/cpufeature.h>
24268
24269- .section .altinstr_replacement,"ax"
24270+ .section .altinstr_replacement,"a"
24271 1: .byte 0xeb /* jmp <disp8> */
24272 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
24273 2:
24274diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
24275index a30ca15..d25fab6 100644
24276--- a/arch/x86/lib/copy_user_64.S
24277+++ b/arch/x86/lib/copy_user_64.S
24278@@ -18,6 +18,7 @@
24279 #include <asm/alternative-asm.h>
24280 #include <asm/asm.h>
24281 #include <asm/smap.h>
24282+#include <asm/pgtable.h>
24283
24284 /*
24285 * By placing feature2 after feature1 in altinstructions section, we logically
24286@@ -31,7 +32,7 @@
24287 .byte 0xe9 /* 32bit jump */
24288 .long \orig-1f /* by default jump to orig */
24289 1:
24290- .section .altinstr_replacement,"ax"
24291+ .section .altinstr_replacement,"a"
24292 2: .byte 0xe9 /* near jump with 32bit immediate */
24293 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
24294 3: .byte 0xe9 /* near jump with 32bit immediate */
24295@@ -70,47 +71,20 @@
24296 #endif
24297 .endm
24298
24299-/* Standard copy_to_user with segment limit checking */
24300-ENTRY(_copy_to_user)
24301- CFI_STARTPROC
24302- GET_THREAD_INFO(%rax)
24303- movq %rdi,%rcx
24304- addq %rdx,%rcx
24305- jc bad_to_user
24306- cmpq TI_addr_limit(%rax),%rcx
24307- ja bad_to_user
24308- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24309- copy_user_generic_unrolled,copy_user_generic_string, \
24310- copy_user_enhanced_fast_string
24311- CFI_ENDPROC
24312-ENDPROC(_copy_to_user)
24313-
24314-/* Standard copy_from_user with segment limit checking */
24315-ENTRY(_copy_from_user)
24316- CFI_STARTPROC
24317- GET_THREAD_INFO(%rax)
24318- movq %rsi,%rcx
24319- addq %rdx,%rcx
24320- jc bad_from_user
24321- cmpq TI_addr_limit(%rax),%rcx
24322- ja bad_from_user
24323- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24324- copy_user_generic_unrolled,copy_user_generic_string, \
24325- copy_user_enhanced_fast_string
24326- CFI_ENDPROC
24327-ENDPROC(_copy_from_user)
24328-
24329 .section .fixup,"ax"
24330 /* must zero dest */
24331 ENTRY(bad_from_user)
24332 bad_from_user:
24333 CFI_STARTPROC
24334+ testl %edx,%edx
24335+ js bad_to_user
24336 movl %edx,%ecx
24337 xorl %eax,%eax
24338 rep
24339 stosb
24340 bad_to_user:
24341 movl %edx,%eax
24342+ pax_force_retaddr
24343 ret
24344 CFI_ENDPROC
24345 ENDPROC(bad_from_user)
24346@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
24347 jz 17f
24348 1: movq (%rsi),%r8
24349 2: movq 1*8(%rsi),%r9
24350-3: movq 2*8(%rsi),%r10
24351+3: movq 2*8(%rsi),%rax
24352 4: movq 3*8(%rsi),%r11
24353 5: movq %r8,(%rdi)
24354 6: movq %r9,1*8(%rdi)
24355-7: movq %r10,2*8(%rdi)
24356+7: movq %rax,2*8(%rdi)
24357 8: movq %r11,3*8(%rdi)
24358 9: movq 4*8(%rsi),%r8
24359 10: movq 5*8(%rsi),%r9
24360-11: movq 6*8(%rsi),%r10
24361+11: movq 6*8(%rsi),%rax
24362 12: movq 7*8(%rsi),%r11
24363 13: movq %r8,4*8(%rdi)
24364 14: movq %r9,5*8(%rdi)
24365-15: movq %r10,6*8(%rdi)
24366+15: movq %rax,6*8(%rdi)
24367 16: movq %r11,7*8(%rdi)
24368 leaq 64(%rsi),%rsi
24369 leaq 64(%rdi),%rdi
24370@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
24371 jnz 21b
24372 23: xor %eax,%eax
24373 ASM_CLAC
24374+ pax_force_retaddr
24375 ret
24376
24377 .section .fixup,"ax"
24378@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
24379 movsb
24380 4: xorl %eax,%eax
24381 ASM_CLAC
24382+ pax_force_retaddr
24383 ret
24384
24385 .section .fixup,"ax"
24386@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
24387 movsb
24388 2: xorl %eax,%eax
24389 ASM_CLAC
24390+ pax_force_retaddr
24391 ret
24392
24393 .section .fixup,"ax"
24394diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
24395index 6a4f43c..f5f9e26 100644
24396--- a/arch/x86/lib/copy_user_nocache_64.S
24397+++ b/arch/x86/lib/copy_user_nocache_64.S
24398@@ -8,6 +8,7 @@
24399
24400 #include <linux/linkage.h>
24401 #include <asm/dwarf2.h>
24402+#include <asm/alternative-asm.h>
24403
24404 #define FIX_ALIGNMENT 1
24405
24406@@ -16,6 +17,7 @@
24407 #include <asm/thread_info.h>
24408 #include <asm/asm.h>
24409 #include <asm/smap.h>
24410+#include <asm/pgtable.h>
24411
24412 .macro ALIGN_DESTINATION
24413 #ifdef FIX_ALIGNMENT
24414@@ -49,6 +51,15 @@
24415 */
24416 ENTRY(__copy_user_nocache)
24417 CFI_STARTPROC
24418+
24419+#ifdef CONFIG_PAX_MEMORY_UDEREF
24420+ mov $PAX_USER_SHADOW_BASE,%rcx
24421+ cmp %rcx,%rsi
24422+ jae 1f
24423+ add %rcx,%rsi
24424+1:
24425+#endif
24426+
24427 ASM_STAC
24428 cmpl $8,%edx
24429 jb 20f /* less then 8 bytes, go to byte copy loop */
24430@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
24431 jz 17f
24432 1: movq (%rsi),%r8
24433 2: movq 1*8(%rsi),%r9
24434-3: movq 2*8(%rsi),%r10
24435+3: movq 2*8(%rsi),%rax
24436 4: movq 3*8(%rsi),%r11
24437 5: movnti %r8,(%rdi)
24438 6: movnti %r9,1*8(%rdi)
24439-7: movnti %r10,2*8(%rdi)
24440+7: movnti %rax,2*8(%rdi)
24441 8: movnti %r11,3*8(%rdi)
24442 9: movq 4*8(%rsi),%r8
24443 10: movq 5*8(%rsi),%r9
24444-11: movq 6*8(%rsi),%r10
24445+11: movq 6*8(%rsi),%rax
24446 12: movq 7*8(%rsi),%r11
24447 13: movnti %r8,4*8(%rdi)
24448 14: movnti %r9,5*8(%rdi)
24449-15: movnti %r10,6*8(%rdi)
24450+15: movnti %rax,6*8(%rdi)
24451 16: movnti %r11,7*8(%rdi)
24452 leaq 64(%rsi),%rsi
24453 leaq 64(%rdi),%rdi
24454@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
24455 23: xorl %eax,%eax
24456 ASM_CLAC
24457 sfence
24458+ pax_force_retaddr
24459 ret
24460
24461 .section .fixup,"ax"
24462diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
24463index 2419d5f..953ee51 100644
24464--- a/arch/x86/lib/csum-copy_64.S
24465+++ b/arch/x86/lib/csum-copy_64.S
24466@@ -9,6 +9,7 @@
24467 #include <asm/dwarf2.h>
24468 #include <asm/errno.h>
24469 #include <asm/asm.h>
24470+#include <asm/alternative-asm.h>
24471
24472 /*
24473 * Checksum copy with exception handling.
24474@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
24475 CFI_RESTORE rbp
24476 addq $7*8, %rsp
24477 CFI_ADJUST_CFA_OFFSET -7*8
24478+ pax_force_retaddr 0, 1
24479 ret
24480 CFI_RESTORE_STATE
24481
24482diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
24483index 25b7ae8..169fafc 100644
24484--- a/arch/x86/lib/csum-wrappers_64.c
24485+++ b/arch/x86/lib/csum-wrappers_64.c
24486@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
24487 len -= 2;
24488 }
24489 }
24490- isum = csum_partial_copy_generic((__force const void *)src,
24491+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
24492 dst, len, isum, errp, NULL);
24493 if (unlikely(*errp))
24494 goto out_err;
24495@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
24496 }
24497
24498 *errp = 0;
24499- return csum_partial_copy_generic(src, (void __force *)dst,
24500+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
24501 len, isum, NULL, errp);
24502 }
24503 EXPORT_SYMBOL(csum_partial_copy_to_user);
24504diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
24505index 156b9c8..b144132 100644
24506--- a/arch/x86/lib/getuser.S
24507+++ b/arch/x86/lib/getuser.S
24508@@ -34,17 +34,40 @@
24509 #include <asm/thread_info.h>
24510 #include <asm/asm.h>
24511 #include <asm/smap.h>
24512+#include <asm/segment.h>
24513+#include <asm/pgtable.h>
24514+#include <asm/alternative-asm.h>
24515+
24516+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24517+#define __copyuser_seg gs;
24518+#else
24519+#define __copyuser_seg
24520+#endif
24521
24522 .text
24523 ENTRY(__get_user_1)
24524 CFI_STARTPROC
24525+
24526+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24527 GET_THREAD_INFO(%_ASM_DX)
24528 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24529 jae bad_get_user
24530 ASM_STAC
24531-1: movzb (%_ASM_AX),%edx
24532+
24533+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24534+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24535+ cmp %_ASM_DX,%_ASM_AX
24536+ jae 1234f
24537+ add %_ASM_DX,%_ASM_AX
24538+1234:
24539+#endif
24540+
24541+#endif
24542+
24543+1: __copyuser_seg movzb (%_ASM_AX),%edx
24544 xor %eax,%eax
24545 ASM_CLAC
24546+ pax_force_retaddr
24547 ret
24548 CFI_ENDPROC
24549 ENDPROC(__get_user_1)
24550@@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
24551 ENTRY(__get_user_2)
24552 CFI_STARTPROC
24553 add $1,%_ASM_AX
24554+
24555+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24556 jc bad_get_user
24557 GET_THREAD_INFO(%_ASM_DX)
24558 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24559 jae bad_get_user
24560 ASM_STAC
24561-2: movzwl -1(%_ASM_AX),%edx
24562+
24563+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24564+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24565+ cmp %_ASM_DX,%_ASM_AX
24566+ jae 1234f
24567+ add %_ASM_DX,%_ASM_AX
24568+1234:
24569+#endif
24570+
24571+#endif
24572+
24573+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
24574 xor %eax,%eax
24575 ASM_CLAC
24576+ pax_force_retaddr
24577 ret
24578 CFI_ENDPROC
24579 ENDPROC(__get_user_2)
24580@@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
24581 ENTRY(__get_user_4)
24582 CFI_STARTPROC
24583 add $3,%_ASM_AX
24584+
24585+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24586 jc bad_get_user
24587 GET_THREAD_INFO(%_ASM_DX)
24588 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24589 jae bad_get_user
24590 ASM_STAC
24591-3: mov -3(%_ASM_AX),%edx
24592+
24593+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24594+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24595+ cmp %_ASM_DX,%_ASM_AX
24596+ jae 1234f
24597+ add %_ASM_DX,%_ASM_AX
24598+1234:
24599+#endif
24600+
24601+#endif
24602+
24603+3: __copyuser_seg mov -3(%_ASM_AX),%edx
24604 xor %eax,%eax
24605 ASM_CLAC
24606+ pax_force_retaddr
24607 ret
24608 CFI_ENDPROC
24609 ENDPROC(__get_user_4)
24610@@ -87,10 +138,20 @@ ENTRY(__get_user_8)
24611 GET_THREAD_INFO(%_ASM_DX)
24612 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24613 jae bad_get_user
24614+
24615+#ifdef CONFIG_PAX_MEMORY_UDEREF
24616+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24617+ cmp %_ASM_DX,%_ASM_AX
24618+ jae 1234f
24619+ add %_ASM_DX,%_ASM_AX
24620+1234:
24621+#endif
24622+
24623 ASM_STAC
24624 4: movq -7(%_ASM_AX),%_ASM_DX
24625 xor %eax,%eax
24626 ASM_CLAC
24627+ pax_force_retaddr
24628 ret
24629 CFI_ENDPROC
24630 ENDPROC(__get_user_8)
24631@@ -101,6 +162,7 @@ bad_get_user:
24632 xor %edx,%edx
24633 mov $(-EFAULT),%_ASM_AX
24634 ASM_CLAC
24635+ pax_force_retaddr
24636 ret
24637 CFI_ENDPROC
24638 END(bad_get_user)
24639diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
24640index 54fcffe..7be149e 100644
24641--- a/arch/x86/lib/insn.c
24642+++ b/arch/x86/lib/insn.c
24643@@ -20,8 +20,10 @@
24644
24645 #ifdef __KERNEL__
24646 #include <linux/string.h>
24647+#include <asm/pgtable_types.h>
24648 #else
24649 #include <string.h>
24650+#define ktla_ktva(addr) addr
24651 #endif
24652 #include <asm/inat.h>
24653 #include <asm/insn.h>
24654@@ -53,8 +55,8 @@
24655 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
24656 {
24657 memset(insn, 0, sizeof(*insn));
24658- insn->kaddr = kaddr;
24659- insn->next_byte = kaddr;
24660+ insn->kaddr = ktla_ktva(kaddr);
24661+ insn->next_byte = ktla_ktva(kaddr);
24662 insn->x86_64 = x86_64 ? 1 : 0;
24663 insn->opnd_bytes = 4;
24664 if (x86_64)
24665diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
24666index 05a95e7..326f2fa 100644
24667--- a/arch/x86/lib/iomap_copy_64.S
24668+++ b/arch/x86/lib/iomap_copy_64.S
24669@@ -17,6 +17,7 @@
24670
24671 #include <linux/linkage.h>
24672 #include <asm/dwarf2.h>
24673+#include <asm/alternative-asm.h>
24674
24675 /*
24676 * override generic version in lib/iomap_copy.c
24677@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
24678 CFI_STARTPROC
24679 movl %edx,%ecx
24680 rep movsd
24681+ pax_force_retaddr
24682 ret
24683 CFI_ENDPROC
24684 ENDPROC(__iowrite32_copy)
24685diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
24686index 1c273be..da9cc0e 100644
24687--- a/arch/x86/lib/memcpy_64.S
24688+++ b/arch/x86/lib/memcpy_64.S
24689@@ -33,6 +33,7 @@
24690 rep movsq
24691 movl %edx, %ecx
24692 rep movsb
24693+ pax_force_retaddr
24694 ret
24695 .Lmemcpy_e:
24696 .previous
24697@@ -49,6 +50,7 @@
24698 movq %rdi, %rax
24699 movq %rdx, %rcx
24700 rep movsb
24701+ pax_force_retaddr
24702 ret
24703 .Lmemcpy_e_e:
24704 .previous
24705@@ -76,13 +78,13 @@ ENTRY(memcpy)
24706 */
24707 movq 0*8(%rsi), %r8
24708 movq 1*8(%rsi), %r9
24709- movq 2*8(%rsi), %r10
24710+ movq 2*8(%rsi), %rcx
24711 movq 3*8(%rsi), %r11
24712 leaq 4*8(%rsi), %rsi
24713
24714 movq %r8, 0*8(%rdi)
24715 movq %r9, 1*8(%rdi)
24716- movq %r10, 2*8(%rdi)
24717+ movq %rcx, 2*8(%rdi)
24718 movq %r11, 3*8(%rdi)
24719 leaq 4*8(%rdi), %rdi
24720 jae .Lcopy_forward_loop
24721@@ -105,12 +107,12 @@ ENTRY(memcpy)
24722 subq $0x20, %rdx
24723 movq -1*8(%rsi), %r8
24724 movq -2*8(%rsi), %r9
24725- movq -3*8(%rsi), %r10
24726+ movq -3*8(%rsi), %rcx
24727 movq -4*8(%rsi), %r11
24728 leaq -4*8(%rsi), %rsi
24729 movq %r8, -1*8(%rdi)
24730 movq %r9, -2*8(%rdi)
24731- movq %r10, -3*8(%rdi)
24732+ movq %rcx, -3*8(%rdi)
24733 movq %r11, -4*8(%rdi)
24734 leaq -4*8(%rdi), %rdi
24735 jae .Lcopy_backward_loop
24736@@ -130,12 +132,13 @@ ENTRY(memcpy)
24737 */
24738 movq 0*8(%rsi), %r8
24739 movq 1*8(%rsi), %r9
24740- movq -2*8(%rsi, %rdx), %r10
24741+ movq -2*8(%rsi, %rdx), %rcx
24742 movq -1*8(%rsi, %rdx), %r11
24743 movq %r8, 0*8(%rdi)
24744 movq %r9, 1*8(%rdi)
24745- movq %r10, -2*8(%rdi, %rdx)
24746+ movq %rcx, -2*8(%rdi, %rdx)
24747 movq %r11, -1*8(%rdi, %rdx)
24748+ pax_force_retaddr
24749 retq
24750 .p2align 4
24751 .Lless_16bytes:
24752@@ -148,6 +151,7 @@ ENTRY(memcpy)
24753 movq -1*8(%rsi, %rdx), %r9
24754 movq %r8, 0*8(%rdi)
24755 movq %r9, -1*8(%rdi, %rdx)
24756+ pax_force_retaddr
24757 retq
24758 .p2align 4
24759 .Lless_8bytes:
24760@@ -161,6 +165,7 @@ ENTRY(memcpy)
24761 movl -4(%rsi, %rdx), %r8d
24762 movl %ecx, (%rdi)
24763 movl %r8d, -4(%rdi, %rdx)
24764+ pax_force_retaddr
24765 retq
24766 .p2align 4
24767 .Lless_3bytes:
24768@@ -179,6 +184,7 @@ ENTRY(memcpy)
24769 movb %cl, (%rdi)
24770
24771 .Lend:
24772+ pax_force_retaddr
24773 retq
24774 CFI_ENDPROC
24775 ENDPROC(memcpy)
24776diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
24777index ee16461..c39c199 100644
24778--- a/arch/x86/lib/memmove_64.S
24779+++ b/arch/x86/lib/memmove_64.S
24780@@ -61,13 +61,13 @@ ENTRY(memmove)
24781 5:
24782 sub $0x20, %rdx
24783 movq 0*8(%rsi), %r11
24784- movq 1*8(%rsi), %r10
24785+ movq 1*8(%rsi), %rcx
24786 movq 2*8(%rsi), %r9
24787 movq 3*8(%rsi), %r8
24788 leaq 4*8(%rsi), %rsi
24789
24790 movq %r11, 0*8(%rdi)
24791- movq %r10, 1*8(%rdi)
24792+ movq %rcx, 1*8(%rdi)
24793 movq %r9, 2*8(%rdi)
24794 movq %r8, 3*8(%rdi)
24795 leaq 4*8(%rdi), %rdi
24796@@ -81,10 +81,10 @@ ENTRY(memmove)
24797 4:
24798 movq %rdx, %rcx
24799 movq -8(%rsi, %rdx), %r11
24800- lea -8(%rdi, %rdx), %r10
24801+ lea -8(%rdi, %rdx), %r9
24802 shrq $3, %rcx
24803 rep movsq
24804- movq %r11, (%r10)
24805+ movq %r11, (%r9)
24806 jmp 13f
24807 .Lmemmove_end_forward:
24808
24809@@ -95,14 +95,14 @@ ENTRY(memmove)
24810 7:
24811 movq %rdx, %rcx
24812 movq (%rsi), %r11
24813- movq %rdi, %r10
24814+ movq %rdi, %r9
24815 leaq -8(%rsi, %rdx), %rsi
24816 leaq -8(%rdi, %rdx), %rdi
24817 shrq $3, %rcx
24818 std
24819 rep movsq
24820 cld
24821- movq %r11, (%r10)
24822+ movq %r11, (%r9)
24823 jmp 13f
24824
24825 /*
24826@@ -127,13 +127,13 @@ ENTRY(memmove)
24827 8:
24828 subq $0x20, %rdx
24829 movq -1*8(%rsi), %r11
24830- movq -2*8(%rsi), %r10
24831+ movq -2*8(%rsi), %rcx
24832 movq -3*8(%rsi), %r9
24833 movq -4*8(%rsi), %r8
24834 leaq -4*8(%rsi), %rsi
24835
24836 movq %r11, -1*8(%rdi)
24837- movq %r10, -2*8(%rdi)
24838+ movq %rcx, -2*8(%rdi)
24839 movq %r9, -3*8(%rdi)
24840 movq %r8, -4*8(%rdi)
24841 leaq -4*8(%rdi), %rdi
24842@@ -151,11 +151,11 @@ ENTRY(memmove)
24843 * Move data from 16 bytes to 31 bytes.
24844 */
24845 movq 0*8(%rsi), %r11
24846- movq 1*8(%rsi), %r10
24847+ movq 1*8(%rsi), %rcx
24848 movq -2*8(%rsi, %rdx), %r9
24849 movq -1*8(%rsi, %rdx), %r8
24850 movq %r11, 0*8(%rdi)
24851- movq %r10, 1*8(%rdi)
24852+ movq %rcx, 1*8(%rdi)
24853 movq %r9, -2*8(%rdi, %rdx)
24854 movq %r8, -1*8(%rdi, %rdx)
24855 jmp 13f
24856@@ -167,9 +167,9 @@ ENTRY(memmove)
24857 * Move data from 8 bytes to 15 bytes.
24858 */
24859 movq 0*8(%rsi), %r11
24860- movq -1*8(%rsi, %rdx), %r10
24861+ movq -1*8(%rsi, %rdx), %r9
24862 movq %r11, 0*8(%rdi)
24863- movq %r10, -1*8(%rdi, %rdx)
24864+ movq %r9, -1*8(%rdi, %rdx)
24865 jmp 13f
24866 10:
24867 cmpq $4, %rdx
24868@@ -178,9 +178,9 @@ ENTRY(memmove)
24869 * Move data from 4 bytes to 7 bytes.
24870 */
24871 movl (%rsi), %r11d
24872- movl -4(%rsi, %rdx), %r10d
24873+ movl -4(%rsi, %rdx), %r9d
24874 movl %r11d, (%rdi)
24875- movl %r10d, -4(%rdi, %rdx)
24876+ movl %r9d, -4(%rdi, %rdx)
24877 jmp 13f
24878 11:
24879 cmp $2, %rdx
24880@@ -189,9 +189,9 @@ ENTRY(memmove)
24881 * Move data from 2 bytes to 3 bytes.
24882 */
24883 movw (%rsi), %r11w
24884- movw -2(%rsi, %rdx), %r10w
24885+ movw -2(%rsi, %rdx), %r9w
24886 movw %r11w, (%rdi)
24887- movw %r10w, -2(%rdi, %rdx)
24888+ movw %r9w, -2(%rdi, %rdx)
24889 jmp 13f
24890 12:
24891 cmp $1, %rdx
24892@@ -202,6 +202,7 @@ ENTRY(memmove)
24893 movb (%rsi), %r11b
24894 movb %r11b, (%rdi)
24895 13:
24896+ pax_force_retaddr
24897 retq
24898 CFI_ENDPROC
24899
24900@@ -210,6 +211,7 @@ ENTRY(memmove)
24901 /* Forward moving data. */
24902 movq %rdx, %rcx
24903 rep movsb
24904+ pax_force_retaddr
24905 retq
24906 .Lmemmove_end_forward_efs:
24907 .previous
24908diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
24909index 2dcb380..963660a 100644
24910--- a/arch/x86/lib/memset_64.S
24911+++ b/arch/x86/lib/memset_64.S
24912@@ -30,6 +30,7 @@
24913 movl %edx,%ecx
24914 rep stosb
24915 movq %r9,%rax
24916+ pax_force_retaddr
24917 ret
24918 .Lmemset_e:
24919 .previous
24920@@ -52,6 +53,7 @@
24921 movq %rdx,%rcx
24922 rep stosb
24923 movq %r9,%rax
24924+ pax_force_retaddr
24925 ret
24926 .Lmemset_e_e:
24927 .previous
24928@@ -59,7 +61,7 @@
24929 ENTRY(memset)
24930 ENTRY(__memset)
24931 CFI_STARTPROC
24932- movq %rdi,%r10
24933+ movq %rdi,%r11
24934
24935 /* expand byte value */
24936 movzbl %sil,%ecx
24937@@ -117,7 +119,8 @@ ENTRY(__memset)
24938 jnz .Lloop_1
24939
24940 .Lende:
24941- movq %r10,%rax
24942+ movq %r11,%rax
24943+ pax_force_retaddr
24944 ret
24945
24946 CFI_RESTORE_STATE
24947diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
24948index c9f2d9b..e7fd2c0 100644
24949--- a/arch/x86/lib/mmx_32.c
24950+++ b/arch/x86/lib/mmx_32.c
24951@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
24952 {
24953 void *p;
24954 int i;
24955+ unsigned long cr0;
24956
24957 if (unlikely(in_interrupt()))
24958 return __memcpy(to, from, len);
24959@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
24960 kernel_fpu_begin();
24961
24962 __asm__ __volatile__ (
24963- "1: prefetch (%0)\n" /* This set is 28 bytes */
24964- " prefetch 64(%0)\n"
24965- " prefetch 128(%0)\n"
24966- " prefetch 192(%0)\n"
24967- " prefetch 256(%0)\n"
24968+ "1: prefetch (%1)\n" /* This set is 28 bytes */
24969+ " prefetch 64(%1)\n"
24970+ " prefetch 128(%1)\n"
24971+ " prefetch 192(%1)\n"
24972+ " prefetch 256(%1)\n"
24973 "2: \n"
24974 ".section .fixup, \"ax\"\n"
24975- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
24976+ "3: \n"
24977+
24978+#ifdef CONFIG_PAX_KERNEXEC
24979+ " movl %%cr0, %0\n"
24980+ " movl %0, %%eax\n"
24981+ " andl $0xFFFEFFFF, %%eax\n"
24982+ " movl %%eax, %%cr0\n"
24983+#endif
24984+
24985+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
24986+
24987+#ifdef CONFIG_PAX_KERNEXEC
24988+ " movl %0, %%cr0\n"
24989+#endif
24990+
24991 " jmp 2b\n"
24992 ".previous\n"
24993 _ASM_EXTABLE(1b, 3b)
24994- : : "r" (from));
24995+ : "=&r" (cr0) : "r" (from) : "ax");
24996
24997 for ( ; i > 5; i--) {
24998 __asm__ __volatile__ (
24999- "1: prefetch 320(%0)\n"
25000- "2: movq (%0), %%mm0\n"
25001- " movq 8(%0), %%mm1\n"
25002- " movq 16(%0), %%mm2\n"
25003- " movq 24(%0), %%mm3\n"
25004- " movq %%mm0, (%1)\n"
25005- " movq %%mm1, 8(%1)\n"
25006- " movq %%mm2, 16(%1)\n"
25007- " movq %%mm3, 24(%1)\n"
25008- " movq 32(%0), %%mm0\n"
25009- " movq 40(%0), %%mm1\n"
25010- " movq 48(%0), %%mm2\n"
25011- " movq 56(%0), %%mm3\n"
25012- " movq %%mm0, 32(%1)\n"
25013- " movq %%mm1, 40(%1)\n"
25014- " movq %%mm2, 48(%1)\n"
25015- " movq %%mm3, 56(%1)\n"
25016+ "1: prefetch 320(%1)\n"
25017+ "2: movq (%1), %%mm0\n"
25018+ " movq 8(%1), %%mm1\n"
25019+ " movq 16(%1), %%mm2\n"
25020+ " movq 24(%1), %%mm3\n"
25021+ " movq %%mm0, (%2)\n"
25022+ " movq %%mm1, 8(%2)\n"
25023+ " movq %%mm2, 16(%2)\n"
25024+ " movq %%mm3, 24(%2)\n"
25025+ " movq 32(%1), %%mm0\n"
25026+ " movq 40(%1), %%mm1\n"
25027+ " movq 48(%1), %%mm2\n"
25028+ " movq 56(%1), %%mm3\n"
25029+ " movq %%mm0, 32(%2)\n"
25030+ " movq %%mm1, 40(%2)\n"
25031+ " movq %%mm2, 48(%2)\n"
25032+ " movq %%mm3, 56(%2)\n"
25033 ".section .fixup, \"ax\"\n"
25034- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25035+ "3:\n"
25036+
25037+#ifdef CONFIG_PAX_KERNEXEC
25038+ " movl %%cr0, %0\n"
25039+ " movl %0, %%eax\n"
25040+ " andl $0xFFFEFFFF, %%eax\n"
25041+ " movl %%eax, %%cr0\n"
25042+#endif
25043+
25044+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25045+
25046+#ifdef CONFIG_PAX_KERNEXEC
25047+ " movl %0, %%cr0\n"
25048+#endif
25049+
25050 " jmp 2b\n"
25051 ".previous\n"
25052 _ASM_EXTABLE(1b, 3b)
25053- : : "r" (from), "r" (to) : "memory");
25054+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25055
25056 from += 64;
25057 to += 64;
25058@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
25059 static void fast_copy_page(void *to, void *from)
25060 {
25061 int i;
25062+ unsigned long cr0;
25063
25064 kernel_fpu_begin();
25065
25066@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
25067 * but that is for later. -AV
25068 */
25069 __asm__ __volatile__(
25070- "1: prefetch (%0)\n"
25071- " prefetch 64(%0)\n"
25072- " prefetch 128(%0)\n"
25073- " prefetch 192(%0)\n"
25074- " prefetch 256(%0)\n"
25075+ "1: prefetch (%1)\n"
25076+ " prefetch 64(%1)\n"
25077+ " prefetch 128(%1)\n"
25078+ " prefetch 192(%1)\n"
25079+ " prefetch 256(%1)\n"
25080 "2: \n"
25081 ".section .fixup, \"ax\"\n"
25082- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25083+ "3: \n"
25084+
25085+#ifdef CONFIG_PAX_KERNEXEC
25086+ " movl %%cr0, %0\n"
25087+ " movl %0, %%eax\n"
25088+ " andl $0xFFFEFFFF, %%eax\n"
25089+ " movl %%eax, %%cr0\n"
25090+#endif
25091+
25092+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25093+
25094+#ifdef CONFIG_PAX_KERNEXEC
25095+ " movl %0, %%cr0\n"
25096+#endif
25097+
25098 " jmp 2b\n"
25099 ".previous\n"
25100- _ASM_EXTABLE(1b, 3b) : : "r" (from));
25101+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25102
25103 for (i = 0; i < (4096-320)/64; i++) {
25104 __asm__ __volatile__ (
25105- "1: prefetch 320(%0)\n"
25106- "2: movq (%0), %%mm0\n"
25107- " movntq %%mm0, (%1)\n"
25108- " movq 8(%0), %%mm1\n"
25109- " movntq %%mm1, 8(%1)\n"
25110- " movq 16(%0), %%mm2\n"
25111- " movntq %%mm2, 16(%1)\n"
25112- " movq 24(%0), %%mm3\n"
25113- " movntq %%mm3, 24(%1)\n"
25114- " movq 32(%0), %%mm4\n"
25115- " movntq %%mm4, 32(%1)\n"
25116- " movq 40(%0), %%mm5\n"
25117- " movntq %%mm5, 40(%1)\n"
25118- " movq 48(%0), %%mm6\n"
25119- " movntq %%mm6, 48(%1)\n"
25120- " movq 56(%0), %%mm7\n"
25121- " movntq %%mm7, 56(%1)\n"
25122+ "1: prefetch 320(%1)\n"
25123+ "2: movq (%1), %%mm0\n"
25124+ " movntq %%mm0, (%2)\n"
25125+ " movq 8(%1), %%mm1\n"
25126+ " movntq %%mm1, 8(%2)\n"
25127+ " movq 16(%1), %%mm2\n"
25128+ " movntq %%mm2, 16(%2)\n"
25129+ " movq 24(%1), %%mm3\n"
25130+ " movntq %%mm3, 24(%2)\n"
25131+ " movq 32(%1), %%mm4\n"
25132+ " movntq %%mm4, 32(%2)\n"
25133+ " movq 40(%1), %%mm5\n"
25134+ " movntq %%mm5, 40(%2)\n"
25135+ " movq 48(%1), %%mm6\n"
25136+ " movntq %%mm6, 48(%2)\n"
25137+ " movq 56(%1), %%mm7\n"
25138+ " movntq %%mm7, 56(%2)\n"
25139 ".section .fixup, \"ax\"\n"
25140- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25141+ "3:\n"
25142+
25143+#ifdef CONFIG_PAX_KERNEXEC
25144+ " movl %%cr0, %0\n"
25145+ " movl %0, %%eax\n"
25146+ " andl $0xFFFEFFFF, %%eax\n"
25147+ " movl %%eax, %%cr0\n"
25148+#endif
25149+
25150+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25151+
25152+#ifdef CONFIG_PAX_KERNEXEC
25153+ " movl %0, %%cr0\n"
25154+#endif
25155+
25156 " jmp 2b\n"
25157 ".previous\n"
25158- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
25159+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25160
25161 from += 64;
25162 to += 64;
25163@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
25164 static void fast_copy_page(void *to, void *from)
25165 {
25166 int i;
25167+ unsigned long cr0;
25168
25169 kernel_fpu_begin();
25170
25171 __asm__ __volatile__ (
25172- "1: prefetch (%0)\n"
25173- " prefetch 64(%0)\n"
25174- " prefetch 128(%0)\n"
25175- " prefetch 192(%0)\n"
25176- " prefetch 256(%0)\n"
25177+ "1: prefetch (%1)\n"
25178+ " prefetch 64(%1)\n"
25179+ " prefetch 128(%1)\n"
25180+ " prefetch 192(%1)\n"
25181+ " prefetch 256(%1)\n"
25182 "2: \n"
25183 ".section .fixup, \"ax\"\n"
25184- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25185+ "3: \n"
25186+
25187+#ifdef CONFIG_PAX_KERNEXEC
25188+ " movl %%cr0, %0\n"
25189+ " movl %0, %%eax\n"
25190+ " andl $0xFFFEFFFF, %%eax\n"
25191+ " movl %%eax, %%cr0\n"
25192+#endif
25193+
25194+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25195+
25196+#ifdef CONFIG_PAX_KERNEXEC
25197+ " movl %0, %%cr0\n"
25198+#endif
25199+
25200 " jmp 2b\n"
25201 ".previous\n"
25202- _ASM_EXTABLE(1b, 3b) : : "r" (from));
25203+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25204
25205 for (i = 0; i < 4096/64; i++) {
25206 __asm__ __volatile__ (
25207- "1: prefetch 320(%0)\n"
25208- "2: movq (%0), %%mm0\n"
25209- " movq 8(%0), %%mm1\n"
25210- " movq 16(%0), %%mm2\n"
25211- " movq 24(%0), %%mm3\n"
25212- " movq %%mm0, (%1)\n"
25213- " movq %%mm1, 8(%1)\n"
25214- " movq %%mm2, 16(%1)\n"
25215- " movq %%mm3, 24(%1)\n"
25216- " movq 32(%0), %%mm0\n"
25217- " movq 40(%0), %%mm1\n"
25218- " movq 48(%0), %%mm2\n"
25219- " movq 56(%0), %%mm3\n"
25220- " movq %%mm0, 32(%1)\n"
25221- " movq %%mm1, 40(%1)\n"
25222- " movq %%mm2, 48(%1)\n"
25223- " movq %%mm3, 56(%1)\n"
25224+ "1: prefetch 320(%1)\n"
25225+ "2: movq (%1), %%mm0\n"
25226+ " movq 8(%1), %%mm1\n"
25227+ " movq 16(%1), %%mm2\n"
25228+ " movq 24(%1), %%mm3\n"
25229+ " movq %%mm0, (%2)\n"
25230+ " movq %%mm1, 8(%2)\n"
25231+ " movq %%mm2, 16(%2)\n"
25232+ " movq %%mm3, 24(%2)\n"
25233+ " movq 32(%1), %%mm0\n"
25234+ " movq 40(%1), %%mm1\n"
25235+ " movq 48(%1), %%mm2\n"
25236+ " movq 56(%1), %%mm3\n"
25237+ " movq %%mm0, 32(%2)\n"
25238+ " movq %%mm1, 40(%2)\n"
25239+ " movq %%mm2, 48(%2)\n"
25240+ " movq %%mm3, 56(%2)\n"
25241 ".section .fixup, \"ax\"\n"
25242- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25243+ "3:\n"
25244+
25245+#ifdef CONFIG_PAX_KERNEXEC
25246+ " movl %%cr0, %0\n"
25247+ " movl %0, %%eax\n"
25248+ " andl $0xFFFEFFFF, %%eax\n"
25249+ " movl %%eax, %%cr0\n"
25250+#endif
25251+
25252+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25253+
25254+#ifdef CONFIG_PAX_KERNEXEC
25255+ " movl %0, %%cr0\n"
25256+#endif
25257+
25258 " jmp 2b\n"
25259 ".previous\n"
25260 _ASM_EXTABLE(1b, 3b)
25261- : : "r" (from), "r" (to) : "memory");
25262+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25263
25264 from += 64;
25265 to += 64;
25266diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
25267index f6d13ee..aca5f0b 100644
25268--- a/arch/x86/lib/msr-reg.S
25269+++ b/arch/x86/lib/msr-reg.S
25270@@ -3,6 +3,7 @@
25271 #include <asm/dwarf2.h>
25272 #include <asm/asm.h>
25273 #include <asm/msr.h>
25274+#include <asm/alternative-asm.h>
25275
25276 #ifdef CONFIG_X86_64
25277 /*
25278@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
25279 CFI_STARTPROC
25280 pushq_cfi %rbx
25281 pushq_cfi %rbp
25282- movq %rdi, %r10 /* Save pointer */
25283+ movq %rdi, %r9 /* Save pointer */
25284 xorl %r11d, %r11d /* Return value */
25285 movl (%rdi), %eax
25286 movl 4(%rdi), %ecx
25287@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
25288 movl 28(%rdi), %edi
25289 CFI_REMEMBER_STATE
25290 1: \op
25291-2: movl %eax, (%r10)
25292+2: movl %eax, (%r9)
25293 movl %r11d, %eax /* Return value */
25294- movl %ecx, 4(%r10)
25295- movl %edx, 8(%r10)
25296- movl %ebx, 12(%r10)
25297- movl %ebp, 20(%r10)
25298- movl %esi, 24(%r10)
25299- movl %edi, 28(%r10)
25300+ movl %ecx, 4(%r9)
25301+ movl %edx, 8(%r9)
25302+ movl %ebx, 12(%r9)
25303+ movl %ebp, 20(%r9)
25304+ movl %esi, 24(%r9)
25305+ movl %edi, 28(%r9)
25306 popq_cfi %rbp
25307 popq_cfi %rbx
25308+ pax_force_retaddr
25309 ret
25310 3:
25311 CFI_RESTORE_STATE
25312diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
25313index fc6ba17..04471c5 100644
25314--- a/arch/x86/lib/putuser.S
25315+++ b/arch/x86/lib/putuser.S
25316@@ -16,7 +16,9 @@
25317 #include <asm/errno.h>
25318 #include <asm/asm.h>
25319 #include <asm/smap.h>
25320-
25321+#include <asm/segment.h>
25322+#include <asm/pgtable.h>
25323+#include <asm/alternative-asm.h>
25324
25325 /*
25326 * __put_user_X
25327@@ -30,57 +32,125 @@
25328 * as they get called from within inline assembly.
25329 */
25330
25331-#define ENTER CFI_STARTPROC ; \
25332- GET_THREAD_INFO(%_ASM_BX)
25333-#define EXIT ASM_CLAC ; \
25334- ret ; \
25335+#define ENTER CFI_STARTPROC
25336+#define EXIT ASM_CLAC ; \
25337+ pax_force_retaddr ; \
25338+ ret ; \
25339 CFI_ENDPROC
25340
25341+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25342+#define _DEST %_ASM_CX,%_ASM_BX
25343+#else
25344+#define _DEST %_ASM_CX
25345+#endif
25346+
25347+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25348+#define __copyuser_seg gs;
25349+#else
25350+#define __copyuser_seg
25351+#endif
25352+
25353 .text
25354 ENTRY(__put_user_1)
25355 ENTER
25356+
25357+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25358+ GET_THREAD_INFO(%_ASM_BX)
25359 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
25360 jae bad_put_user
25361 ASM_STAC
25362-1: movb %al,(%_ASM_CX)
25363+
25364+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25365+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25366+ cmp %_ASM_BX,%_ASM_CX
25367+ jb 1234f
25368+ xor %ebx,%ebx
25369+1234:
25370+#endif
25371+
25372+#endif
25373+
25374+1: __copyuser_seg movb %al,(_DEST)
25375 xor %eax,%eax
25376 EXIT
25377 ENDPROC(__put_user_1)
25378
25379 ENTRY(__put_user_2)
25380 ENTER
25381+
25382+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25383+ GET_THREAD_INFO(%_ASM_BX)
25384 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25385 sub $1,%_ASM_BX
25386 cmp %_ASM_BX,%_ASM_CX
25387 jae bad_put_user
25388 ASM_STAC
25389-2: movw %ax,(%_ASM_CX)
25390+
25391+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25392+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25393+ cmp %_ASM_BX,%_ASM_CX
25394+ jb 1234f
25395+ xor %ebx,%ebx
25396+1234:
25397+#endif
25398+
25399+#endif
25400+
25401+2: __copyuser_seg movw %ax,(_DEST)
25402 xor %eax,%eax
25403 EXIT
25404 ENDPROC(__put_user_2)
25405
25406 ENTRY(__put_user_4)
25407 ENTER
25408+
25409+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25410+ GET_THREAD_INFO(%_ASM_BX)
25411 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25412 sub $3,%_ASM_BX
25413 cmp %_ASM_BX,%_ASM_CX
25414 jae bad_put_user
25415 ASM_STAC
25416-3: movl %eax,(%_ASM_CX)
25417+
25418+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25419+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25420+ cmp %_ASM_BX,%_ASM_CX
25421+ jb 1234f
25422+ xor %ebx,%ebx
25423+1234:
25424+#endif
25425+
25426+#endif
25427+
25428+3: __copyuser_seg movl %eax,(_DEST)
25429 xor %eax,%eax
25430 EXIT
25431 ENDPROC(__put_user_4)
25432
25433 ENTRY(__put_user_8)
25434 ENTER
25435+
25436+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25437+ GET_THREAD_INFO(%_ASM_BX)
25438 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25439 sub $7,%_ASM_BX
25440 cmp %_ASM_BX,%_ASM_CX
25441 jae bad_put_user
25442 ASM_STAC
25443-4: mov %_ASM_AX,(%_ASM_CX)
25444+
25445+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25446+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25447+ cmp %_ASM_BX,%_ASM_CX
25448+ jb 1234f
25449+ xor %ebx,%ebx
25450+1234:
25451+#endif
25452+
25453+#endif
25454+
25455+4: __copyuser_seg mov %_ASM_AX,(_DEST)
25456 #ifdef CONFIG_X86_32
25457-5: movl %edx,4(%_ASM_CX)
25458+5: __copyuser_seg movl %edx,4(_DEST)
25459 #endif
25460 xor %eax,%eax
25461 EXIT
25462diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
25463index 1cad221..de671ee 100644
25464--- a/arch/x86/lib/rwlock.S
25465+++ b/arch/x86/lib/rwlock.S
25466@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
25467 FRAME
25468 0: LOCK_PREFIX
25469 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
25470+
25471+#ifdef CONFIG_PAX_REFCOUNT
25472+ jno 1234f
25473+ LOCK_PREFIX
25474+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
25475+ int $4
25476+1234:
25477+ _ASM_EXTABLE(1234b, 1234b)
25478+#endif
25479+
25480 1: rep; nop
25481 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
25482 jne 1b
25483 LOCK_PREFIX
25484 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
25485+
25486+#ifdef CONFIG_PAX_REFCOUNT
25487+ jno 1234f
25488+ LOCK_PREFIX
25489+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
25490+ int $4
25491+1234:
25492+ _ASM_EXTABLE(1234b, 1234b)
25493+#endif
25494+
25495 jnz 0b
25496 ENDFRAME
25497+ pax_force_retaddr
25498 ret
25499 CFI_ENDPROC
25500 END(__write_lock_failed)
25501@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
25502 FRAME
25503 0: LOCK_PREFIX
25504 READ_LOCK_SIZE(inc) (%__lock_ptr)
25505+
25506+#ifdef CONFIG_PAX_REFCOUNT
25507+ jno 1234f
25508+ LOCK_PREFIX
25509+ READ_LOCK_SIZE(dec) (%__lock_ptr)
25510+ int $4
25511+1234:
25512+ _ASM_EXTABLE(1234b, 1234b)
25513+#endif
25514+
25515 1: rep; nop
25516 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
25517 js 1b
25518 LOCK_PREFIX
25519 READ_LOCK_SIZE(dec) (%__lock_ptr)
25520+
25521+#ifdef CONFIG_PAX_REFCOUNT
25522+ jno 1234f
25523+ LOCK_PREFIX
25524+ READ_LOCK_SIZE(inc) (%__lock_ptr)
25525+ int $4
25526+1234:
25527+ _ASM_EXTABLE(1234b, 1234b)
25528+#endif
25529+
25530 js 0b
25531 ENDFRAME
25532+ pax_force_retaddr
25533 ret
25534 CFI_ENDPROC
25535 END(__read_lock_failed)
25536diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
25537index 5dff5f0..cadebf4 100644
25538--- a/arch/x86/lib/rwsem.S
25539+++ b/arch/x86/lib/rwsem.S
25540@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
25541 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
25542 CFI_RESTORE __ASM_REG(dx)
25543 restore_common_regs
25544+ pax_force_retaddr
25545 ret
25546 CFI_ENDPROC
25547 ENDPROC(call_rwsem_down_read_failed)
25548@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
25549 movq %rax,%rdi
25550 call rwsem_down_write_failed
25551 restore_common_regs
25552+ pax_force_retaddr
25553 ret
25554 CFI_ENDPROC
25555 ENDPROC(call_rwsem_down_write_failed)
25556@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
25557 movq %rax,%rdi
25558 call rwsem_wake
25559 restore_common_regs
25560-1: ret
25561+1: pax_force_retaddr
25562+ ret
25563 CFI_ENDPROC
25564 ENDPROC(call_rwsem_wake)
25565
25566@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
25567 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
25568 CFI_RESTORE __ASM_REG(dx)
25569 restore_common_regs
25570+ pax_force_retaddr
25571 ret
25572 CFI_ENDPROC
25573 ENDPROC(call_rwsem_downgrade_wake)
25574diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
25575index a63efd6..ccecad8 100644
25576--- a/arch/x86/lib/thunk_64.S
25577+++ b/arch/x86/lib/thunk_64.S
25578@@ -8,6 +8,7 @@
25579 #include <linux/linkage.h>
25580 #include <asm/dwarf2.h>
25581 #include <asm/calling.h>
25582+#include <asm/alternative-asm.h>
25583
25584 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
25585 .macro THUNK name, func, put_ret_addr_in_rdi=0
25586@@ -41,5 +42,6 @@
25587 SAVE_ARGS
25588 restore:
25589 RESTORE_ARGS
25590+ pax_force_retaddr
25591 ret
25592 CFI_ENDPROC
25593diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
25594index f0312d7..9c39d63 100644
25595--- a/arch/x86/lib/usercopy_32.c
25596+++ b/arch/x86/lib/usercopy_32.c
25597@@ -42,11 +42,13 @@ do { \
25598 int __d0; \
25599 might_fault(); \
25600 __asm__ __volatile__( \
25601+ __COPYUSER_SET_ES \
25602 ASM_STAC "\n" \
25603 "0: rep; stosl\n" \
25604 " movl %2,%0\n" \
25605 "1: rep; stosb\n" \
25606 "2: " ASM_CLAC "\n" \
25607+ __COPYUSER_RESTORE_ES \
25608 ".section .fixup,\"ax\"\n" \
25609 "3: lea 0(%2,%0,4),%0\n" \
25610 " jmp 2b\n" \
25611@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
25612
25613 #ifdef CONFIG_X86_INTEL_USERCOPY
25614 static unsigned long
25615-__copy_user_intel(void __user *to, const void *from, unsigned long size)
25616+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
25617 {
25618 int d0, d1;
25619 __asm__ __volatile__(
25620@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25621 " .align 2,0x90\n"
25622 "3: movl 0(%4), %%eax\n"
25623 "4: movl 4(%4), %%edx\n"
25624- "5: movl %%eax, 0(%3)\n"
25625- "6: movl %%edx, 4(%3)\n"
25626+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
25627+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
25628 "7: movl 8(%4), %%eax\n"
25629 "8: movl 12(%4),%%edx\n"
25630- "9: movl %%eax, 8(%3)\n"
25631- "10: movl %%edx, 12(%3)\n"
25632+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
25633+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
25634 "11: movl 16(%4), %%eax\n"
25635 "12: movl 20(%4), %%edx\n"
25636- "13: movl %%eax, 16(%3)\n"
25637- "14: movl %%edx, 20(%3)\n"
25638+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
25639+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
25640 "15: movl 24(%4), %%eax\n"
25641 "16: movl 28(%4), %%edx\n"
25642- "17: movl %%eax, 24(%3)\n"
25643- "18: movl %%edx, 28(%3)\n"
25644+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
25645+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
25646 "19: movl 32(%4), %%eax\n"
25647 "20: movl 36(%4), %%edx\n"
25648- "21: movl %%eax, 32(%3)\n"
25649- "22: movl %%edx, 36(%3)\n"
25650+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
25651+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
25652 "23: movl 40(%4), %%eax\n"
25653 "24: movl 44(%4), %%edx\n"
25654- "25: movl %%eax, 40(%3)\n"
25655- "26: movl %%edx, 44(%3)\n"
25656+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
25657+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
25658 "27: movl 48(%4), %%eax\n"
25659 "28: movl 52(%4), %%edx\n"
25660- "29: movl %%eax, 48(%3)\n"
25661- "30: movl %%edx, 52(%3)\n"
25662+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
25663+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
25664 "31: movl 56(%4), %%eax\n"
25665 "32: movl 60(%4), %%edx\n"
25666- "33: movl %%eax, 56(%3)\n"
25667- "34: movl %%edx, 60(%3)\n"
25668+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
25669+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
25670 " addl $-64, %0\n"
25671 " addl $64, %4\n"
25672 " addl $64, %3\n"
25673@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25674 " shrl $2, %0\n"
25675 " andl $3, %%eax\n"
25676 " cld\n"
25677+ __COPYUSER_SET_ES
25678 "99: rep; movsl\n"
25679 "36: movl %%eax, %0\n"
25680 "37: rep; movsb\n"
25681 "100:\n"
25682+ __COPYUSER_RESTORE_ES
25683 ".section .fixup,\"ax\"\n"
25684 "101: lea 0(%%eax,%0,4),%0\n"
25685 " jmp 100b\n"
25686@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25687 }
25688
25689 static unsigned long
25690+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
25691+{
25692+ int d0, d1;
25693+ __asm__ __volatile__(
25694+ " .align 2,0x90\n"
25695+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
25696+ " cmpl $67, %0\n"
25697+ " jbe 3f\n"
25698+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
25699+ " .align 2,0x90\n"
25700+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
25701+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
25702+ "5: movl %%eax, 0(%3)\n"
25703+ "6: movl %%edx, 4(%3)\n"
25704+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
25705+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
25706+ "9: movl %%eax, 8(%3)\n"
25707+ "10: movl %%edx, 12(%3)\n"
25708+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
25709+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
25710+ "13: movl %%eax, 16(%3)\n"
25711+ "14: movl %%edx, 20(%3)\n"
25712+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
25713+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
25714+ "17: movl %%eax, 24(%3)\n"
25715+ "18: movl %%edx, 28(%3)\n"
25716+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
25717+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
25718+ "21: movl %%eax, 32(%3)\n"
25719+ "22: movl %%edx, 36(%3)\n"
25720+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
25721+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
25722+ "25: movl %%eax, 40(%3)\n"
25723+ "26: movl %%edx, 44(%3)\n"
25724+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
25725+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
25726+ "29: movl %%eax, 48(%3)\n"
25727+ "30: movl %%edx, 52(%3)\n"
25728+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
25729+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
25730+ "33: movl %%eax, 56(%3)\n"
25731+ "34: movl %%edx, 60(%3)\n"
25732+ " addl $-64, %0\n"
25733+ " addl $64, %4\n"
25734+ " addl $64, %3\n"
25735+ " cmpl $63, %0\n"
25736+ " ja 1b\n"
25737+ "35: movl %0, %%eax\n"
25738+ " shrl $2, %0\n"
25739+ " andl $3, %%eax\n"
25740+ " cld\n"
25741+ "99: rep; "__copyuser_seg" movsl\n"
25742+ "36: movl %%eax, %0\n"
25743+ "37: rep; "__copyuser_seg" movsb\n"
25744+ "100:\n"
25745+ ".section .fixup,\"ax\"\n"
25746+ "101: lea 0(%%eax,%0,4),%0\n"
25747+ " jmp 100b\n"
25748+ ".previous\n"
25749+ _ASM_EXTABLE(1b,100b)
25750+ _ASM_EXTABLE(2b,100b)
25751+ _ASM_EXTABLE(3b,100b)
25752+ _ASM_EXTABLE(4b,100b)
25753+ _ASM_EXTABLE(5b,100b)
25754+ _ASM_EXTABLE(6b,100b)
25755+ _ASM_EXTABLE(7b,100b)
25756+ _ASM_EXTABLE(8b,100b)
25757+ _ASM_EXTABLE(9b,100b)
25758+ _ASM_EXTABLE(10b,100b)
25759+ _ASM_EXTABLE(11b,100b)
25760+ _ASM_EXTABLE(12b,100b)
25761+ _ASM_EXTABLE(13b,100b)
25762+ _ASM_EXTABLE(14b,100b)
25763+ _ASM_EXTABLE(15b,100b)
25764+ _ASM_EXTABLE(16b,100b)
25765+ _ASM_EXTABLE(17b,100b)
25766+ _ASM_EXTABLE(18b,100b)
25767+ _ASM_EXTABLE(19b,100b)
25768+ _ASM_EXTABLE(20b,100b)
25769+ _ASM_EXTABLE(21b,100b)
25770+ _ASM_EXTABLE(22b,100b)
25771+ _ASM_EXTABLE(23b,100b)
25772+ _ASM_EXTABLE(24b,100b)
25773+ _ASM_EXTABLE(25b,100b)
25774+ _ASM_EXTABLE(26b,100b)
25775+ _ASM_EXTABLE(27b,100b)
25776+ _ASM_EXTABLE(28b,100b)
25777+ _ASM_EXTABLE(29b,100b)
25778+ _ASM_EXTABLE(30b,100b)
25779+ _ASM_EXTABLE(31b,100b)
25780+ _ASM_EXTABLE(32b,100b)
25781+ _ASM_EXTABLE(33b,100b)
25782+ _ASM_EXTABLE(34b,100b)
25783+ _ASM_EXTABLE(35b,100b)
25784+ _ASM_EXTABLE(36b,100b)
25785+ _ASM_EXTABLE(37b,100b)
25786+ _ASM_EXTABLE(99b,101b)
25787+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
25788+ : "1"(to), "2"(from), "0"(size)
25789+ : "eax", "edx", "memory");
25790+ return size;
25791+}
25792+
25793+static unsigned long __size_overflow(3)
25794 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
25795 {
25796 int d0, d1;
25797 __asm__ __volatile__(
25798 " .align 2,0x90\n"
25799- "0: movl 32(%4), %%eax\n"
25800+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
25801 " cmpl $67, %0\n"
25802 " jbe 2f\n"
25803- "1: movl 64(%4), %%eax\n"
25804+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
25805 " .align 2,0x90\n"
25806- "2: movl 0(%4), %%eax\n"
25807- "21: movl 4(%4), %%edx\n"
25808+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
25809+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
25810 " movl %%eax, 0(%3)\n"
25811 " movl %%edx, 4(%3)\n"
25812- "3: movl 8(%4), %%eax\n"
25813- "31: movl 12(%4),%%edx\n"
25814+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
25815+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
25816 " movl %%eax, 8(%3)\n"
25817 " movl %%edx, 12(%3)\n"
25818- "4: movl 16(%4), %%eax\n"
25819- "41: movl 20(%4), %%edx\n"
25820+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
25821+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
25822 " movl %%eax, 16(%3)\n"
25823 " movl %%edx, 20(%3)\n"
25824- "10: movl 24(%4), %%eax\n"
25825- "51: movl 28(%4), %%edx\n"
25826+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
25827+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
25828 " movl %%eax, 24(%3)\n"
25829 " movl %%edx, 28(%3)\n"
25830- "11: movl 32(%4), %%eax\n"
25831- "61: movl 36(%4), %%edx\n"
25832+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
25833+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
25834 " movl %%eax, 32(%3)\n"
25835 " movl %%edx, 36(%3)\n"
25836- "12: movl 40(%4), %%eax\n"
25837- "71: movl 44(%4), %%edx\n"
25838+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
25839+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
25840 " movl %%eax, 40(%3)\n"
25841 " movl %%edx, 44(%3)\n"
25842- "13: movl 48(%4), %%eax\n"
25843- "81: movl 52(%4), %%edx\n"
25844+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
25845+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
25846 " movl %%eax, 48(%3)\n"
25847 " movl %%edx, 52(%3)\n"
25848- "14: movl 56(%4), %%eax\n"
25849- "91: movl 60(%4), %%edx\n"
25850+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
25851+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
25852 " movl %%eax, 56(%3)\n"
25853 " movl %%edx, 60(%3)\n"
25854 " addl $-64, %0\n"
25855@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
25856 " shrl $2, %0\n"
25857 " andl $3, %%eax\n"
25858 " cld\n"
25859- "6: rep; movsl\n"
25860+ "6: rep; "__copyuser_seg" movsl\n"
25861 " movl %%eax,%0\n"
25862- "7: rep; movsb\n"
25863+ "7: rep; "__copyuser_seg" movsb\n"
25864 "8:\n"
25865 ".section .fixup,\"ax\"\n"
25866 "9: lea 0(%%eax,%0,4),%0\n"
25867@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
25868 * hyoshiok@miraclelinux.com
25869 */
25870
25871-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
25872+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
25873 const void __user *from, unsigned long size)
25874 {
25875 int d0, d1;
25876
25877 __asm__ __volatile__(
25878 " .align 2,0x90\n"
25879- "0: movl 32(%4), %%eax\n"
25880+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
25881 " cmpl $67, %0\n"
25882 " jbe 2f\n"
25883- "1: movl 64(%4), %%eax\n"
25884+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
25885 " .align 2,0x90\n"
25886- "2: movl 0(%4), %%eax\n"
25887- "21: movl 4(%4), %%edx\n"
25888+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
25889+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
25890 " movnti %%eax, 0(%3)\n"
25891 " movnti %%edx, 4(%3)\n"
25892- "3: movl 8(%4), %%eax\n"
25893- "31: movl 12(%4),%%edx\n"
25894+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
25895+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
25896 " movnti %%eax, 8(%3)\n"
25897 " movnti %%edx, 12(%3)\n"
25898- "4: movl 16(%4), %%eax\n"
25899- "41: movl 20(%4), %%edx\n"
25900+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
25901+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
25902 " movnti %%eax, 16(%3)\n"
25903 " movnti %%edx, 20(%3)\n"
25904- "10: movl 24(%4), %%eax\n"
25905- "51: movl 28(%4), %%edx\n"
25906+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
25907+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
25908 " movnti %%eax, 24(%3)\n"
25909 " movnti %%edx, 28(%3)\n"
25910- "11: movl 32(%4), %%eax\n"
25911- "61: movl 36(%4), %%edx\n"
25912+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
25913+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
25914 " movnti %%eax, 32(%3)\n"
25915 " movnti %%edx, 36(%3)\n"
25916- "12: movl 40(%4), %%eax\n"
25917- "71: movl 44(%4), %%edx\n"
25918+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
25919+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
25920 " movnti %%eax, 40(%3)\n"
25921 " movnti %%edx, 44(%3)\n"
25922- "13: movl 48(%4), %%eax\n"
25923- "81: movl 52(%4), %%edx\n"
25924+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
25925+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
25926 " movnti %%eax, 48(%3)\n"
25927 " movnti %%edx, 52(%3)\n"
25928- "14: movl 56(%4), %%eax\n"
25929- "91: movl 60(%4), %%edx\n"
25930+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
25931+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
25932 " movnti %%eax, 56(%3)\n"
25933 " movnti %%edx, 60(%3)\n"
25934 " addl $-64, %0\n"
25935@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
25936 " shrl $2, %0\n"
25937 " andl $3, %%eax\n"
25938 " cld\n"
25939- "6: rep; movsl\n"
25940+ "6: rep; "__copyuser_seg" movsl\n"
25941 " movl %%eax,%0\n"
25942- "7: rep; movsb\n"
25943+ "7: rep; "__copyuser_seg" movsb\n"
25944 "8:\n"
25945 ".section .fixup,\"ax\"\n"
25946 "9: lea 0(%%eax,%0,4),%0\n"
25947@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
25948 return size;
25949 }
25950
25951-static unsigned long __copy_user_intel_nocache(void *to,
25952+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
25953 const void __user *from, unsigned long size)
25954 {
25955 int d0, d1;
25956
25957 __asm__ __volatile__(
25958 " .align 2,0x90\n"
25959- "0: movl 32(%4), %%eax\n"
25960+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
25961 " cmpl $67, %0\n"
25962 " jbe 2f\n"
25963- "1: movl 64(%4), %%eax\n"
25964+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
25965 " .align 2,0x90\n"
25966- "2: movl 0(%4), %%eax\n"
25967- "21: movl 4(%4), %%edx\n"
25968+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
25969+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
25970 " movnti %%eax, 0(%3)\n"
25971 " movnti %%edx, 4(%3)\n"
25972- "3: movl 8(%4), %%eax\n"
25973- "31: movl 12(%4),%%edx\n"
25974+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
25975+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
25976 " movnti %%eax, 8(%3)\n"
25977 " movnti %%edx, 12(%3)\n"
25978- "4: movl 16(%4), %%eax\n"
25979- "41: movl 20(%4), %%edx\n"
25980+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
25981+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
25982 " movnti %%eax, 16(%3)\n"
25983 " movnti %%edx, 20(%3)\n"
25984- "10: movl 24(%4), %%eax\n"
25985- "51: movl 28(%4), %%edx\n"
25986+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
25987+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
25988 " movnti %%eax, 24(%3)\n"
25989 " movnti %%edx, 28(%3)\n"
25990- "11: movl 32(%4), %%eax\n"
25991- "61: movl 36(%4), %%edx\n"
25992+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
25993+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
25994 " movnti %%eax, 32(%3)\n"
25995 " movnti %%edx, 36(%3)\n"
25996- "12: movl 40(%4), %%eax\n"
25997- "71: movl 44(%4), %%edx\n"
25998+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
25999+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26000 " movnti %%eax, 40(%3)\n"
26001 " movnti %%edx, 44(%3)\n"
26002- "13: movl 48(%4), %%eax\n"
26003- "81: movl 52(%4), %%edx\n"
26004+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26005+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26006 " movnti %%eax, 48(%3)\n"
26007 " movnti %%edx, 52(%3)\n"
26008- "14: movl 56(%4), %%eax\n"
26009- "91: movl 60(%4), %%edx\n"
26010+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26011+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26012 " movnti %%eax, 56(%3)\n"
26013 " movnti %%edx, 60(%3)\n"
26014 " addl $-64, %0\n"
26015@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26016 " shrl $2, %0\n"
26017 " andl $3, %%eax\n"
26018 " cld\n"
26019- "6: rep; movsl\n"
26020+ "6: rep; "__copyuser_seg" movsl\n"
26021 " movl %%eax,%0\n"
26022- "7: rep; movsb\n"
26023+ "7: rep; "__copyuser_seg" movsb\n"
26024 "8:\n"
26025 ".section .fixup,\"ax\"\n"
26026 "9: lea 0(%%eax,%0,4),%0\n"
26027@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26028 */
26029 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26030 unsigned long size);
26031-unsigned long __copy_user_intel(void __user *to, const void *from,
26032+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26033+ unsigned long size);
26034+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
26035 unsigned long size);
26036 unsigned long __copy_user_zeroing_intel_nocache(void *to,
26037 const void __user *from, unsigned long size);
26038 #endif /* CONFIG_X86_INTEL_USERCOPY */
26039
26040 /* Generic arbitrary sized copy. */
26041-#define __copy_user(to, from, size) \
26042+#define __copy_user(to, from, size, prefix, set, restore) \
26043 do { \
26044 int __d0, __d1, __d2; \
26045 __asm__ __volatile__( \
26046+ set \
26047 " cmp $7,%0\n" \
26048 " jbe 1f\n" \
26049 " movl %1,%0\n" \
26050 " negl %0\n" \
26051 " andl $7,%0\n" \
26052 " subl %0,%3\n" \
26053- "4: rep; movsb\n" \
26054+ "4: rep; "prefix"movsb\n" \
26055 " movl %3,%0\n" \
26056 " shrl $2,%0\n" \
26057 " andl $3,%3\n" \
26058 " .align 2,0x90\n" \
26059- "0: rep; movsl\n" \
26060+ "0: rep; "prefix"movsl\n" \
26061 " movl %3,%0\n" \
26062- "1: rep; movsb\n" \
26063+ "1: rep; "prefix"movsb\n" \
26064 "2:\n" \
26065+ restore \
26066 ".section .fixup,\"ax\"\n" \
26067 "5: addl %3,%0\n" \
26068 " jmp 2b\n" \
26069@@ -538,14 +650,14 @@ do { \
26070 " negl %0\n" \
26071 " andl $7,%0\n" \
26072 " subl %0,%3\n" \
26073- "4: rep; movsb\n" \
26074+ "4: rep; "__copyuser_seg"movsb\n" \
26075 " movl %3,%0\n" \
26076 " shrl $2,%0\n" \
26077 " andl $3,%3\n" \
26078 " .align 2,0x90\n" \
26079- "0: rep; movsl\n" \
26080+ "0: rep; "__copyuser_seg"movsl\n" \
26081 " movl %3,%0\n" \
26082- "1: rep; movsb\n" \
26083+ "1: rep; "__copyuser_seg"movsb\n" \
26084 "2:\n" \
26085 ".section .fixup,\"ax\"\n" \
26086 "5: addl %3,%0\n" \
26087@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
26088 {
26089 stac();
26090 if (movsl_is_ok(to, from, n))
26091- __copy_user(to, from, n);
26092+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
26093 else
26094- n = __copy_user_intel(to, from, n);
26095+ n = __generic_copy_to_user_intel(to, from, n);
26096 clac();
26097 return n;
26098 }
26099@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
26100 {
26101 stac();
26102 if (movsl_is_ok(to, from, n))
26103- __copy_user(to, from, n);
26104+ __copy_user(to, from, n, __copyuser_seg, "", "");
26105 else
26106- n = __copy_user_intel((void __user *)to,
26107- (const void *)from, n);
26108+ n = __generic_copy_from_user_intel(to, from, n);
26109 clac();
26110 return n;
26111 }
26112@@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
26113 if (n > 64 && cpu_has_xmm2)
26114 n = __copy_user_intel_nocache(to, from, n);
26115 else
26116- __copy_user(to, from, n);
26117+ __copy_user(to, from, n, __copyuser_seg, "", "");
26118 #else
26119- __copy_user(to, from, n);
26120+ __copy_user(to, from, n, __copyuser_seg, "", "");
26121 #endif
26122 clac();
26123 return n;
26124 }
26125 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
26126
26127-/**
26128- * copy_to_user: - Copy a block of data into user space.
26129- * @to: Destination address, in user space.
26130- * @from: Source address, in kernel space.
26131- * @n: Number of bytes to copy.
26132- *
26133- * Context: User context only. This function may sleep.
26134- *
26135- * Copy data from kernel space to user space.
26136- *
26137- * Returns number of bytes that could not be copied.
26138- * On success, this will be zero.
26139- */
26140-unsigned long
26141-copy_to_user(void __user *to, const void *from, unsigned long n)
26142-{
26143- if (access_ok(VERIFY_WRITE, to, n))
26144- n = __copy_to_user(to, from, n);
26145- return n;
26146-}
26147-EXPORT_SYMBOL(copy_to_user);
26148-
26149-/**
26150- * copy_from_user: - Copy a block of data from user space.
26151- * @to: Destination address, in kernel space.
26152- * @from: Source address, in user space.
26153- * @n: Number of bytes to copy.
26154- *
26155- * Context: User context only. This function may sleep.
26156- *
26157- * Copy data from user space to kernel space.
26158- *
26159- * Returns number of bytes that could not be copied.
26160- * On success, this will be zero.
26161- *
26162- * If some data could not be copied, this function will pad the copied
26163- * data to the requested size using zero bytes.
26164- */
26165-unsigned long
26166-_copy_from_user(void *to, const void __user *from, unsigned long n)
26167-{
26168- if (access_ok(VERIFY_READ, from, n))
26169- n = __copy_from_user(to, from, n);
26170- else
26171- memset(to, 0, n);
26172- return n;
26173-}
26174-EXPORT_SYMBOL(_copy_from_user);
26175-
26176 void copy_from_user_overflow(void)
26177 {
26178 WARN(1, "Buffer overflow detected!\n");
26179 }
26180 EXPORT_SYMBOL(copy_from_user_overflow);
26181+
26182+void copy_to_user_overflow(void)
26183+{
26184+ WARN(1, "Buffer overflow detected!\n");
26185+}
26186+EXPORT_SYMBOL(copy_to_user_overflow);
26187+
26188+#ifdef CONFIG_PAX_MEMORY_UDEREF
26189+void __set_fs(mm_segment_t x)
26190+{
26191+ switch (x.seg) {
26192+ case 0:
26193+ loadsegment(gs, 0);
26194+ break;
26195+ case TASK_SIZE_MAX:
26196+ loadsegment(gs, __USER_DS);
26197+ break;
26198+ case -1UL:
26199+ loadsegment(gs, __KERNEL_DS);
26200+ break;
26201+ default:
26202+ BUG();
26203+ }
26204+ return;
26205+}
26206+EXPORT_SYMBOL(__set_fs);
26207+
26208+void set_fs(mm_segment_t x)
26209+{
26210+ current_thread_info()->addr_limit = x;
26211+ __set_fs(x);
26212+}
26213+EXPORT_SYMBOL(set_fs);
26214+#endif
26215diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
26216index 05928aa..b33dea1 100644
26217--- a/arch/x86/lib/usercopy_64.c
26218+++ b/arch/x86/lib/usercopy_64.c
26219@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
26220 _ASM_EXTABLE(0b,3b)
26221 _ASM_EXTABLE(1b,2b)
26222 : [size8] "=&c"(size), [dst] "=&D" (__d0)
26223- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
26224+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
26225 [zero] "r" (0UL), [eight] "r" (8UL));
26226 clac();
26227 return size;
26228@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
26229 }
26230 EXPORT_SYMBOL(clear_user);
26231
26232-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
26233+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
26234 {
26235- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
26236- return copy_user_generic((__force void *)to, (__force void *)from, len);
26237- }
26238- return len;
26239+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
26240+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
26241+ return len;
26242 }
26243 EXPORT_SYMBOL(copy_in_user);
26244
26245@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
26246 * it is not necessary to optimize tail handling.
26247 */
26248 unsigned long
26249-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26250+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
26251 {
26252 char c;
26253 unsigned zero_len;
26254@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26255 clac();
26256 return len;
26257 }
26258+
26259+void copy_from_user_overflow(void)
26260+{
26261+ WARN(1, "Buffer overflow detected!\n");
26262+}
26263+EXPORT_SYMBOL(copy_from_user_overflow);
26264+
26265+void copy_to_user_overflow(void)
26266+{
26267+ WARN(1, "Buffer overflow detected!\n");
26268+}
26269+EXPORT_SYMBOL(copy_to_user_overflow);
26270diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
26271index 903ec1e..c4166b2 100644
26272--- a/arch/x86/mm/extable.c
26273+++ b/arch/x86/mm/extable.c
26274@@ -6,12 +6,24 @@
26275 static inline unsigned long
26276 ex_insn_addr(const struct exception_table_entry *x)
26277 {
26278- return (unsigned long)&x->insn + x->insn;
26279+ unsigned long reloc = 0;
26280+
26281+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26282+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26283+#endif
26284+
26285+ return (unsigned long)&x->insn + x->insn + reloc;
26286 }
26287 static inline unsigned long
26288 ex_fixup_addr(const struct exception_table_entry *x)
26289 {
26290- return (unsigned long)&x->fixup + x->fixup;
26291+ unsigned long reloc = 0;
26292+
26293+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26294+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26295+#endif
26296+
26297+ return (unsigned long)&x->fixup + x->fixup + reloc;
26298 }
26299
26300 int fixup_exception(struct pt_regs *regs)
26301@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
26302 unsigned long new_ip;
26303
26304 #ifdef CONFIG_PNPBIOS
26305- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
26306+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
26307 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
26308 extern u32 pnp_bios_is_utter_crap;
26309 pnp_bios_is_utter_crap = 1;
26310@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
26311 i += 4;
26312 p->fixup -= i;
26313 i += 4;
26314+
26315+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26316+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
26317+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26318+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26319+#endif
26320+
26321 }
26322 }
26323
26324diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
26325index fb674fd..272f369 100644
26326--- a/arch/x86/mm/fault.c
26327+++ b/arch/x86/mm/fault.c
26328@@ -13,12 +13,19 @@
26329 #include <linux/perf_event.h> /* perf_sw_event */
26330 #include <linux/hugetlb.h> /* hstate_index_to_shift */
26331 #include <linux/prefetch.h> /* prefetchw */
26332+#include <linux/unistd.h>
26333+#include <linux/compiler.h>
26334
26335 #include <asm/traps.h> /* dotraplinkage, ... */
26336 #include <asm/pgalloc.h> /* pgd_*(), ... */
26337 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
26338 #include <asm/fixmap.h> /* VSYSCALL_START */
26339 #include <asm/context_tracking.h> /* exception_enter(), ... */
26340+#include <asm/tlbflush.h>
26341+
26342+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26343+#include <asm/stacktrace.h>
26344+#endif
26345
26346 /*
26347 * Page fault error code bits:
26348@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
26349 int ret = 0;
26350
26351 /* kprobe_running() needs smp_processor_id() */
26352- if (kprobes_built_in() && !user_mode_vm(regs)) {
26353+ if (kprobes_built_in() && !user_mode(regs)) {
26354 preempt_disable();
26355 if (kprobe_running() && kprobe_fault_handler(regs, 14))
26356 ret = 1;
26357@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
26358 return !instr_lo || (instr_lo>>1) == 1;
26359 case 0x00:
26360 /* Prefetch instruction is 0x0F0D or 0x0F18 */
26361- if (probe_kernel_address(instr, opcode))
26362+ if (user_mode(regs)) {
26363+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
26364+ return 0;
26365+ } else if (probe_kernel_address(instr, opcode))
26366 return 0;
26367
26368 *prefetch = (instr_lo == 0xF) &&
26369@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
26370 while (instr < max_instr) {
26371 unsigned char opcode;
26372
26373- if (probe_kernel_address(instr, opcode))
26374+ if (user_mode(regs)) {
26375+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
26376+ break;
26377+ } else if (probe_kernel_address(instr, opcode))
26378 break;
26379
26380 instr++;
26381@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
26382 force_sig_info(si_signo, &info, tsk);
26383 }
26384
26385+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26386+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
26387+#endif
26388+
26389+#ifdef CONFIG_PAX_EMUTRAMP
26390+static int pax_handle_fetch_fault(struct pt_regs *regs);
26391+#endif
26392+
26393+#ifdef CONFIG_PAX_PAGEEXEC
26394+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
26395+{
26396+ pgd_t *pgd;
26397+ pud_t *pud;
26398+ pmd_t *pmd;
26399+
26400+ pgd = pgd_offset(mm, address);
26401+ if (!pgd_present(*pgd))
26402+ return NULL;
26403+ pud = pud_offset(pgd, address);
26404+ if (!pud_present(*pud))
26405+ return NULL;
26406+ pmd = pmd_offset(pud, address);
26407+ if (!pmd_present(*pmd))
26408+ return NULL;
26409+ return pmd;
26410+}
26411+#endif
26412+
26413 DEFINE_SPINLOCK(pgd_lock);
26414 LIST_HEAD(pgd_list);
26415
26416@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
26417 for (address = VMALLOC_START & PMD_MASK;
26418 address >= TASK_SIZE && address < FIXADDR_TOP;
26419 address += PMD_SIZE) {
26420+
26421+#ifdef CONFIG_PAX_PER_CPU_PGD
26422+ unsigned long cpu;
26423+#else
26424 struct page *page;
26425+#endif
26426
26427 spin_lock(&pgd_lock);
26428+
26429+#ifdef CONFIG_PAX_PER_CPU_PGD
26430+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26431+ pgd_t *pgd = get_cpu_pgd(cpu);
26432+ pmd_t *ret;
26433+#else
26434 list_for_each_entry(page, &pgd_list, lru) {
26435+ pgd_t *pgd = page_address(page);
26436 spinlock_t *pgt_lock;
26437 pmd_t *ret;
26438
26439@@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
26440 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26441
26442 spin_lock(pgt_lock);
26443- ret = vmalloc_sync_one(page_address(page), address);
26444+#endif
26445+
26446+ ret = vmalloc_sync_one(pgd, address);
26447+
26448+#ifndef CONFIG_PAX_PER_CPU_PGD
26449 spin_unlock(pgt_lock);
26450+#endif
26451
26452 if (!ret)
26453 break;
26454@@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
26455 * an interrupt in the middle of a task switch..
26456 */
26457 pgd_paddr = read_cr3();
26458+
26459+#ifdef CONFIG_PAX_PER_CPU_PGD
26460+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
26461+#endif
26462+
26463 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
26464 if (!pmd_k)
26465 return -1;
26466@@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
26467 * happen within a race in page table update. In the later
26468 * case just flush:
26469 */
26470+
26471+#ifdef CONFIG_PAX_PER_CPU_PGD
26472+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
26473+ pgd = pgd_offset_cpu(smp_processor_id(), address);
26474+#else
26475 pgd = pgd_offset(current->active_mm, address);
26476+#endif
26477+
26478 pgd_ref = pgd_offset_k(address);
26479 if (pgd_none(*pgd_ref))
26480 return -1;
26481@@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
26482 static int is_errata100(struct pt_regs *regs, unsigned long address)
26483 {
26484 #ifdef CONFIG_X86_64
26485- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
26486+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
26487 return 1;
26488 #endif
26489 return 0;
26490@@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
26491 }
26492
26493 static const char nx_warning[] = KERN_CRIT
26494-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
26495+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
26496
26497 static void
26498 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
26499@@ -577,15 +647,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
26500 if (!oops_may_print())
26501 return;
26502
26503- if (error_code & PF_INSTR) {
26504+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
26505 unsigned int level;
26506
26507 pte_t *pte = lookup_address(address, &level);
26508
26509 if (pte && pte_present(*pte) && !pte_exec(*pte))
26510- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
26511+ printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
26512 }
26513
26514+#ifdef CONFIG_PAX_KERNEXEC
26515+ if (init_mm.start_code <= address && address < init_mm.end_code) {
26516+ if (current->signal->curr_ip)
26517+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
26518+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
26519+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
26520+ else
26521+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
26522+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
26523+ }
26524+#endif
26525+
26526 printk(KERN_ALERT "BUG: unable to handle kernel ");
26527 if (address < PAGE_SIZE)
26528 printk(KERN_CONT "NULL pointer dereference");
26529@@ -748,6 +830,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
26530 return;
26531 }
26532 #endif
26533+
26534+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26535+ if (pax_is_fetch_fault(regs, error_code, address)) {
26536+
26537+#ifdef CONFIG_PAX_EMUTRAMP
26538+ switch (pax_handle_fetch_fault(regs)) {
26539+ case 2:
26540+ return;
26541+ }
26542+#endif
26543+
26544+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
26545+ do_group_exit(SIGKILL);
26546+ }
26547+#endif
26548+
26549 /* Kernel addresses are always protection faults: */
26550 if (address >= TASK_SIZE)
26551 error_code |= PF_PROT;
26552@@ -833,7 +931,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
26553 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
26554 printk(KERN_ERR
26555 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
26556- tsk->comm, tsk->pid, address);
26557+ tsk->comm, task_pid_nr(tsk), address);
26558 code = BUS_MCEERR_AR;
26559 }
26560 #endif
26561@@ -896,6 +994,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
26562 return 1;
26563 }
26564
26565+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26566+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
26567+{
26568+ pte_t *pte;
26569+ pmd_t *pmd;
26570+ spinlock_t *ptl;
26571+ unsigned char pte_mask;
26572+
26573+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
26574+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
26575+ return 0;
26576+
26577+ /* PaX: it's our fault, let's handle it if we can */
26578+
26579+ /* PaX: take a look at read faults before acquiring any locks */
26580+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
26581+ /* instruction fetch attempt from a protected page in user mode */
26582+ up_read(&mm->mmap_sem);
26583+
26584+#ifdef CONFIG_PAX_EMUTRAMP
26585+ switch (pax_handle_fetch_fault(regs)) {
26586+ case 2:
26587+ return 1;
26588+ }
26589+#endif
26590+
26591+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
26592+ do_group_exit(SIGKILL);
26593+ }
26594+
26595+ pmd = pax_get_pmd(mm, address);
26596+ if (unlikely(!pmd))
26597+ return 0;
26598+
26599+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
26600+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
26601+ pte_unmap_unlock(pte, ptl);
26602+ return 0;
26603+ }
26604+
26605+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
26606+ /* write attempt to a protected page in user mode */
26607+ pte_unmap_unlock(pte, ptl);
26608+ return 0;
26609+ }
26610+
26611+#ifdef CONFIG_SMP
26612+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
26613+#else
26614+ if (likely(address > get_limit(regs->cs)))
26615+#endif
26616+ {
26617+ set_pte(pte, pte_mkread(*pte));
26618+ __flush_tlb_one(address);
26619+ pte_unmap_unlock(pte, ptl);
26620+ up_read(&mm->mmap_sem);
26621+ return 1;
26622+ }
26623+
26624+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
26625+
26626+ /*
26627+ * PaX: fill DTLB with user rights and retry
26628+ */
26629+ __asm__ __volatile__ (
26630+ "orb %2,(%1)\n"
26631+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
26632+/*
26633+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
26634+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
26635+ * page fault when examined during a TLB load attempt. this is true not only
26636+ * for PTEs holding a non-present entry but also present entries that will
26637+ * raise a page fault (such as those set up by PaX, or the copy-on-write
26638+ * mechanism). in effect it means that we do *not* need to flush the TLBs
26639+ * for our target pages since their PTEs are simply not in the TLBs at all.
26640+
26641+ * the best thing in omitting it is that we gain around 15-20% speed in the
26642+ * fast path of the page fault handler and can get rid of tracing since we
26643+ * can no longer flush unintended entries.
26644+ */
26645+ "invlpg (%0)\n"
26646+#endif
26647+ __copyuser_seg"testb $0,(%0)\n"
26648+ "xorb %3,(%1)\n"
26649+ :
26650+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
26651+ : "memory", "cc");
26652+ pte_unmap_unlock(pte, ptl);
26653+ up_read(&mm->mmap_sem);
26654+ return 1;
26655+}
26656+#endif
26657+
26658 /*
26659 * Handle a spurious fault caused by a stale TLB entry.
26660 *
26661@@ -968,6 +1159,9 @@ int show_unhandled_signals = 1;
26662 static inline int
26663 access_error(unsigned long error_code, struct vm_area_struct *vma)
26664 {
26665+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
26666+ return 1;
26667+
26668 if (error_code & PF_WRITE) {
26669 /* write, present and write, not present: */
26670 if (unlikely(!(vma->vm_flags & VM_WRITE)))
26671@@ -996,7 +1190,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
26672 if (error_code & PF_USER)
26673 return false;
26674
26675- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
26676+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
26677 return false;
26678
26679 return true;
26680@@ -1012,18 +1206,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
26681 {
26682 struct vm_area_struct *vma;
26683 struct task_struct *tsk;
26684- unsigned long address;
26685 struct mm_struct *mm;
26686 int fault;
26687 int write = error_code & PF_WRITE;
26688 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
26689 (write ? FAULT_FLAG_WRITE : 0);
26690
26691- tsk = current;
26692- mm = tsk->mm;
26693-
26694 /* Get the faulting address: */
26695- address = read_cr2();
26696+ unsigned long address = read_cr2();
26697+
26698+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26699+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
26700+ if (!search_exception_tables(regs->ip)) {
26701+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
26702+ bad_area_nosemaphore(regs, error_code, address);
26703+ return;
26704+ }
26705+ if (address < PAX_USER_SHADOW_BASE) {
26706+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
26707+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
26708+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
26709+ } else
26710+ address -= PAX_USER_SHADOW_BASE;
26711+ }
26712+#endif
26713+
26714+ tsk = current;
26715+ mm = tsk->mm;
26716
26717 /*
26718 * Detect and handle instructions that would cause a page fault for
26719@@ -1084,7 +1293,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
26720 * User-mode registers count as a user access even for any
26721 * potential system fault or CPU buglet:
26722 */
26723- if (user_mode_vm(regs)) {
26724+ if (user_mode(regs)) {
26725 local_irq_enable();
26726 error_code |= PF_USER;
26727 } else {
26728@@ -1146,6 +1355,11 @@ retry:
26729 might_sleep();
26730 }
26731
26732+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26733+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
26734+ return;
26735+#endif
26736+
26737 vma = find_vma(mm, address);
26738 if (unlikely(!vma)) {
26739 bad_area(regs, error_code, address);
26740@@ -1157,18 +1371,24 @@ retry:
26741 bad_area(regs, error_code, address);
26742 return;
26743 }
26744- if (error_code & PF_USER) {
26745- /*
26746- * Accessing the stack below %sp is always a bug.
26747- * The large cushion allows instructions like enter
26748- * and pusha to work. ("enter $65535, $31" pushes
26749- * 32 pointers and then decrements %sp by 65535.)
26750- */
26751- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
26752- bad_area(regs, error_code, address);
26753- return;
26754- }
26755+ /*
26756+ * Accessing the stack below %sp is always a bug.
26757+ * The large cushion allows instructions like enter
26758+ * and pusha to work. ("enter $65535, $31" pushes
26759+ * 32 pointers and then decrements %sp by 65535.)
26760+ */
26761+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
26762+ bad_area(regs, error_code, address);
26763+ return;
26764 }
26765+
26766+#ifdef CONFIG_PAX_SEGMEXEC
26767+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
26768+ bad_area(regs, error_code, address);
26769+ return;
26770+ }
26771+#endif
26772+
26773 if (unlikely(expand_stack(vma, address))) {
26774 bad_area(regs, error_code, address);
26775 return;
26776@@ -1232,3 +1452,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
26777 __do_page_fault(regs, error_code);
26778 exception_exit(regs);
26779 }
26780+
26781+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26782+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
26783+{
26784+ struct mm_struct *mm = current->mm;
26785+ unsigned long ip = regs->ip;
26786+
26787+ if (v8086_mode(regs))
26788+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
26789+
26790+#ifdef CONFIG_PAX_PAGEEXEC
26791+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
26792+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
26793+ return true;
26794+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
26795+ return true;
26796+ return false;
26797+ }
26798+#endif
26799+
26800+#ifdef CONFIG_PAX_SEGMEXEC
26801+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
26802+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
26803+ return true;
26804+ return false;
26805+ }
26806+#endif
26807+
26808+ return false;
26809+}
26810+#endif
26811+
26812+#ifdef CONFIG_PAX_EMUTRAMP
26813+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
26814+{
26815+ int err;
26816+
26817+ do { /* PaX: libffi trampoline emulation */
26818+ unsigned char mov, jmp;
26819+ unsigned int addr1, addr2;
26820+
26821+#ifdef CONFIG_X86_64
26822+ if ((regs->ip + 9) >> 32)
26823+ break;
26824+#endif
26825+
26826+ err = get_user(mov, (unsigned char __user *)regs->ip);
26827+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
26828+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
26829+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
26830+
26831+ if (err)
26832+ break;
26833+
26834+ if (mov == 0xB8 && jmp == 0xE9) {
26835+ regs->ax = addr1;
26836+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
26837+ return 2;
26838+ }
26839+ } while (0);
26840+
26841+ do { /* PaX: gcc trampoline emulation #1 */
26842+ unsigned char mov1, mov2;
26843+ unsigned short jmp;
26844+ unsigned int addr1, addr2;
26845+
26846+#ifdef CONFIG_X86_64
26847+ if ((regs->ip + 11) >> 32)
26848+ break;
26849+#endif
26850+
26851+ err = get_user(mov1, (unsigned char __user *)regs->ip);
26852+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
26853+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
26854+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
26855+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
26856+
26857+ if (err)
26858+ break;
26859+
26860+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
26861+ regs->cx = addr1;
26862+ regs->ax = addr2;
26863+ regs->ip = addr2;
26864+ return 2;
26865+ }
26866+ } while (0);
26867+
26868+ do { /* PaX: gcc trampoline emulation #2 */
26869+ unsigned char mov, jmp;
26870+ unsigned int addr1, addr2;
26871+
26872+#ifdef CONFIG_X86_64
26873+ if ((regs->ip + 9) >> 32)
26874+ break;
26875+#endif
26876+
26877+ err = get_user(mov, (unsigned char __user *)regs->ip);
26878+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
26879+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
26880+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
26881+
26882+ if (err)
26883+ break;
26884+
26885+ if (mov == 0xB9 && jmp == 0xE9) {
26886+ regs->cx = addr1;
26887+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
26888+ return 2;
26889+ }
26890+ } while (0);
26891+
26892+ return 1; /* PaX in action */
26893+}
26894+
26895+#ifdef CONFIG_X86_64
26896+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
26897+{
26898+ int err;
26899+
26900+ do { /* PaX: libffi trampoline emulation */
26901+ unsigned short mov1, mov2, jmp1;
26902+ unsigned char stcclc, jmp2;
26903+ unsigned long addr1, addr2;
26904+
26905+ err = get_user(mov1, (unsigned short __user *)regs->ip);
26906+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
26907+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
26908+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
26909+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
26910+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
26911+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
26912+
26913+ if (err)
26914+ break;
26915+
26916+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
26917+ regs->r11 = addr1;
26918+ regs->r10 = addr2;
26919+ if (stcclc == 0xF8)
26920+ regs->flags &= ~X86_EFLAGS_CF;
26921+ else
26922+ regs->flags |= X86_EFLAGS_CF;
26923+ regs->ip = addr1;
26924+ return 2;
26925+ }
26926+ } while (0);
26927+
26928+ do { /* PaX: gcc trampoline emulation #1 */
26929+ unsigned short mov1, mov2, jmp1;
26930+ unsigned char jmp2;
26931+ unsigned int addr1;
26932+ unsigned long addr2;
26933+
26934+ err = get_user(mov1, (unsigned short __user *)regs->ip);
26935+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
26936+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
26937+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
26938+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
26939+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
26940+
26941+ if (err)
26942+ break;
26943+
26944+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
26945+ regs->r11 = addr1;
26946+ regs->r10 = addr2;
26947+ regs->ip = addr1;
26948+ return 2;
26949+ }
26950+ } while (0);
26951+
26952+ do { /* PaX: gcc trampoline emulation #2 */
26953+ unsigned short mov1, mov2, jmp1;
26954+ unsigned char jmp2;
26955+ unsigned long addr1, addr2;
26956+
26957+ err = get_user(mov1, (unsigned short __user *)regs->ip);
26958+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
26959+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
26960+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
26961+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
26962+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
26963+
26964+ if (err)
26965+ break;
26966+
26967+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
26968+ regs->r11 = addr1;
26969+ regs->r10 = addr2;
26970+ regs->ip = addr1;
26971+ return 2;
26972+ }
26973+ } while (0);
26974+
26975+ return 1; /* PaX in action */
26976+}
26977+#endif
26978+
26979+/*
26980+ * PaX: decide what to do with offenders (regs->ip = fault address)
26981+ *
26982+ * returns 1 when task should be killed
26983+ * 2 when gcc trampoline was detected
26984+ */
26985+static int pax_handle_fetch_fault(struct pt_regs *regs)
26986+{
26987+ if (v8086_mode(regs))
26988+ return 1;
26989+
26990+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
26991+ return 1;
26992+
26993+#ifdef CONFIG_X86_32
26994+ return pax_handle_fetch_fault_32(regs);
26995+#else
26996+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
26997+ return pax_handle_fetch_fault_32(regs);
26998+ else
26999+ return pax_handle_fetch_fault_64(regs);
27000+#endif
27001+}
27002+#endif
27003+
27004+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27005+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27006+{
27007+ long i;
27008+
27009+ printk(KERN_ERR "PAX: bytes at PC: ");
27010+ for (i = 0; i < 20; i++) {
27011+ unsigned char c;
27012+ if (get_user(c, (unsigned char __force_user *)pc+i))
27013+ printk(KERN_CONT "?? ");
27014+ else
27015+ printk(KERN_CONT "%02x ", c);
27016+ }
27017+ printk("\n");
27018+
27019+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27020+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
27021+ unsigned long c;
27022+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
27023+#ifdef CONFIG_X86_32
27024+ printk(KERN_CONT "???????? ");
27025+#else
27026+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27027+ printk(KERN_CONT "???????? ???????? ");
27028+ else
27029+ printk(KERN_CONT "???????????????? ");
27030+#endif
27031+ } else {
27032+#ifdef CONFIG_X86_64
27033+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
27034+ printk(KERN_CONT "%08x ", (unsigned int)c);
27035+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
27036+ } else
27037+#endif
27038+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
27039+ }
27040+ }
27041+ printk("\n");
27042+}
27043+#endif
27044+
27045+/**
27046+ * probe_kernel_write(): safely attempt to write to a location
27047+ * @dst: address to write to
27048+ * @src: pointer to the data that shall be written
27049+ * @size: size of the data chunk
27050+ *
27051+ * Safely write to address @dst from the buffer at @src. If a kernel fault
27052+ * happens, handle that and return -EFAULT.
27053+ */
27054+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
27055+{
27056+ long ret;
27057+ mm_segment_t old_fs = get_fs();
27058+
27059+ set_fs(KERNEL_DS);
27060+ pagefault_disable();
27061+ pax_open_kernel();
27062+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
27063+ pax_close_kernel();
27064+ pagefault_enable();
27065+ set_fs(old_fs);
27066+
27067+ return ret ? -EFAULT : 0;
27068+}
27069diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
27070index dd74e46..7d26398 100644
27071--- a/arch/x86/mm/gup.c
27072+++ b/arch/x86/mm/gup.c
27073@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
27074 addr = start;
27075 len = (unsigned long) nr_pages << PAGE_SHIFT;
27076 end = start + len;
27077- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27078+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27079 (void __user *)start, len)))
27080 return 0;
27081
27082diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
27083index 6f31ee5..8ee4164 100644
27084--- a/arch/x86/mm/highmem_32.c
27085+++ b/arch/x86/mm/highmem_32.c
27086@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
27087 idx = type + KM_TYPE_NR*smp_processor_id();
27088 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27089 BUG_ON(!pte_none(*(kmap_pte-idx)));
27090+
27091+ pax_open_kernel();
27092 set_pte(kmap_pte-idx, mk_pte(page, prot));
27093+ pax_close_kernel();
27094+
27095 arch_flush_lazy_mmu_mode();
27096
27097 return (void *)vaddr;
27098diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
27099index ae1aa71..56316db 100644
27100--- a/arch/x86/mm/hugetlbpage.c
27101+++ b/arch/x86/mm/hugetlbpage.c
27102@@ -279,6 +279,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
27103 info.flags = 0;
27104 info.length = len;
27105 info.low_limit = TASK_UNMAPPED_BASE;
27106+
27107+#ifdef CONFIG_PAX_RANDMMAP
27108+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27109+ info.low_limit += current->mm->delta_mmap;
27110+#endif
27111+
27112 info.high_limit = TASK_SIZE;
27113 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
27114 info.align_offset = 0;
27115@@ -311,6 +317,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
27116 VM_BUG_ON(addr != -ENOMEM);
27117 info.flags = 0;
27118 info.low_limit = TASK_UNMAPPED_BASE;
27119+
27120+#ifdef CONFIG_PAX_RANDMMAP
27121+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27122+ info.low_limit += current->mm->delta_mmap;
27123+#endif
27124+
27125 info.high_limit = TASK_SIZE;
27126 addr = vm_unmapped_area(&info);
27127 }
27128@@ -325,10 +337,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27129 struct hstate *h = hstate_file(file);
27130 struct mm_struct *mm = current->mm;
27131 struct vm_area_struct *vma;
27132+ unsigned long pax_task_size = TASK_SIZE;
27133+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
27134
27135 if (len & ~huge_page_mask(h))
27136 return -EINVAL;
27137- if (len > TASK_SIZE)
27138+
27139+#ifdef CONFIG_PAX_SEGMEXEC
27140+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27141+ pax_task_size = SEGMEXEC_TASK_SIZE;
27142+#endif
27143+
27144+ pax_task_size -= PAGE_SIZE;
27145+
27146+ if (len > pax_task_size)
27147 return -ENOMEM;
27148
27149 if (flags & MAP_FIXED) {
27150@@ -337,11 +359,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27151 return addr;
27152 }
27153
27154+#ifdef CONFIG_PAX_RANDMMAP
27155+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27156+#endif
27157+
27158 if (addr) {
27159 addr = ALIGN(addr, huge_page_size(h));
27160 vma = find_vma(mm, addr);
27161- if (TASK_SIZE - len >= addr &&
27162- (!vma || addr + len <= vma->vm_start))
27163+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27164 return addr;
27165 }
27166 if (mm->get_unmapped_area == arch_get_unmapped_area)
27167diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
27168index d7aea41..0fc945b 100644
27169--- a/arch/x86/mm/init.c
27170+++ b/arch/x86/mm/init.c
27171@@ -4,6 +4,7 @@
27172 #include <linux/swap.h>
27173 #include <linux/memblock.h>
27174 #include <linux/bootmem.h> /* for max_low_pfn */
27175+#include <linux/tboot.h>
27176
27177 #include <asm/cacheflush.h>
27178 #include <asm/e820.h>
27179@@ -16,6 +17,8 @@
27180 #include <asm/tlb.h>
27181 #include <asm/proto.h>
27182 #include <asm/dma.h> /* for MAX_DMA_PFN */
27183+#include <asm/desc.h>
27184+#include <asm/bios_ebda.h>
27185
27186 unsigned long __initdata pgt_buf_start;
27187 unsigned long __meminitdata pgt_buf_end;
27188@@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
27189 {
27190 int i;
27191 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
27192- unsigned long start = 0, good_end;
27193+ unsigned long start = 0x100000, good_end;
27194 phys_addr_t base;
27195
27196 for (i = 0; i < nr_range; i++) {
27197@@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
27198 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
27199 * mmio resources as well as potential bios/acpi data regions.
27200 */
27201+
27202+#ifdef CONFIG_GRKERNSEC_KMEM
27203+static unsigned int ebda_start __read_only;
27204+static unsigned int ebda_end __read_only;
27205+#endif
27206+
27207 int devmem_is_allowed(unsigned long pagenr)
27208 {
27209- if (pagenr < 256)
27210+#ifdef CONFIG_GRKERNSEC_KMEM
27211+ /* allow BDA */
27212+ if (!pagenr)
27213 return 1;
27214+ /* allow EBDA */
27215+ if (pagenr >= ebda_start && pagenr < ebda_end)
27216+ return 1;
27217+ /* if tboot is in use, allow access to its hardcoded serial log range */
27218+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
27219+ return 1;
27220+#else
27221+ if (!pagenr)
27222+ return 1;
27223+#ifdef CONFIG_VM86
27224+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
27225+ return 1;
27226+#endif
27227+#endif
27228+
27229+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
27230+ return 1;
27231+#ifdef CONFIG_GRKERNSEC_KMEM
27232+ /* throw out everything else below 1MB */
27233+ if (pagenr <= 256)
27234+ return 0;
27235+#endif
27236 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
27237 return 0;
27238 if (!page_is_ram(pagenr))
27239@@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
27240 #endif
27241 }
27242
27243+#ifdef CONFIG_GRKERNSEC_KMEM
27244+static inline void gr_init_ebda(void)
27245+{
27246+ unsigned int ebda_addr;
27247+ unsigned int ebda_size = 0;
27248+
27249+ ebda_addr = get_bios_ebda();
27250+ if (ebda_addr) {
27251+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
27252+ ebda_size <<= 10;
27253+ }
27254+ if (ebda_addr && ebda_size) {
27255+ ebda_start = ebda_addr >> PAGE_SHIFT;
27256+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
27257+ } else {
27258+ ebda_start = 0x9f000 >> PAGE_SHIFT;
27259+ ebda_end = 0xa0000 >> PAGE_SHIFT;
27260+ }
27261+}
27262+#else
27263+static inline void gr_init_ebda(void) { }
27264+#endif
27265+
27266 void free_initmem(void)
27267 {
27268+#ifdef CONFIG_PAX_KERNEXEC
27269+#ifdef CONFIG_X86_32
27270+ /* PaX: limit KERNEL_CS to actual size */
27271+ unsigned long addr, limit;
27272+ struct desc_struct d;
27273+ int cpu;
27274+#else
27275+ pgd_t *pgd;
27276+ pud_t *pud;
27277+ pmd_t *pmd;
27278+ unsigned long addr, end;
27279+#endif
27280+#endif
27281+
27282+ gr_init_ebda();
27283+
27284+#ifdef CONFIG_PAX_KERNEXEC
27285+#ifdef CONFIG_X86_32
27286+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
27287+ limit = (limit - 1UL) >> PAGE_SHIFT;
27288+
27289+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
27290+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
27291+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
27292+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
27293+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
27294+ }
27295+
27296+ /* PaX: make KERNEL_CS read-only */
27297+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
27298+ if (!paravirt_enabled())
27299+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
27300+/*
27301+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
27302+ pgd = pgd_offset_k(addr);
27303+ pud = pud_offset(pgd, addr);
27304+ pmd = pmd_offset(pud, addr);
27305+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27306+ }
27307+*/
27308+#ifdef CONFIG_X86_PAE
27309+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
27310+/*
27311+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
27312+ pgd = pgd_offset_k(addr);
27313+ pud = pud_offset(pgd, addr);
27314+ pmd = pmd_offset(pud, addr);
27315+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27316+ }
27317+*/
27318+#endif
27319+
27320+#ifdef CONFIG_MODULES
27321+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
27322+#endif
27323+
27324+#else
27325+ /* PaX: make kernel code/rodata read-only, rest non-executable */
27326+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
27327+ pgd = pgd_offset_k(addr);
27328+ pud = pud_offset(pgd, addr);
27329+ pmd = pmd_offset(pud, addr);
27330+ if (!pmd_present(*pmd))
27331+ continue;
27332+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
27333+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27334+ else
27335+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27336+ }
27337+
27338+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
27339+ end = addr + KERNEL_IMAGE_SIZE;
27340+ for (; addr < end; addr += PMD_SIZE) {
27341+ pgd = pgd_offset_k(addr);
27342+ pud = pud_offset(pgd, addr);
27343+ pmd = pmd_offset(pud, addr);
27344+ if (!pmd_present(*pmd))
27345+ continue;
27346+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
27347+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27348+ }
27349+#endif
27350+
27351+ flush_tlb_all();
27352+#endif
27353+
27354 free_init_pages("unused kernel memory",
27355 (unsigned long)(&__init_begin),
27356 (unsigned long)(&__init_end));
27357diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
27358index 745d66b..56bf568 100644
27359--- a/arch/x86/mm/init_32.c
27360+++ b/arch/x86/mm/init_32.c
27361@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
27362 }
27363
27364 /*
27365- * Creates a middle page table and puts a pointer to it in the
27366- * given global directory entry. This only returns the gd entry
27367- * in non-PAE compilation mode, since the middle layer is folded.
27368- */
27369-static pmd_t * __init one_md_table_init(pgd_t *pgd)
27370-{
27371- pud_t *pud;
27372- pmd_t *pmd_table;
27373-
27374-#ifdef CONFIG_X86_PAE
27375- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
27376- if (after_bootmem)
27377- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
27378- else
27379- pmd_table = (pmd_t *)alloc_low_page();
27380- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
27381- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
27382- pud = pud_offset(pgd, 0);
27383- BUG_ON(pmd_table != pmd_offset(pud, 0));
27384-
27385- return pmd_table;
27386- }
27387-#endif
27388- pud = pud_offset(pgd, 0);
27389- pmd_table = pmd_offset(pud, 0);
27390-
27391- return pmd_table;
27392-}
27393-
27394-/*
27395 * Create a page table and place a pointer to it in a middle page
27396 * directory entry:
27397 */
27398@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
27399 page_table = (pte_t *)alloc_low_page();
27400
27401 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
27402+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27403+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
27404+#else
27405 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
27406+#endif
27407 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
27408 }
27409
27410 return pte_offset_kernel(pmd, 0);
27411 }
27412
27413+static pmd_t * __init one_md_table_init(pgd_t *pgd)
27414+{
27415+ pud_t *pud;
27416+ pmd_t *pmd_table;
27417+
27418+ pud = pud_offset(pgd, 0);
27419+ pmd_table = pmd_offset(pud, 0);
27420+
27421+ return pmd_table;
27422+}
27423+
27424 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
27425 {
27426 int pgd_idx = pgd_index(vaddr);
27427@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27428 int pgd_idx, pmd_idx;
27429 unsigned long vaddr;
27430 pgd_t *pgd;
27431+ pud_t *pud;
27432 pmd_t *pmd;
27433 pte_t *pte = NULL;
27434
27435@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27436 pgd = pgd_base + pgd_idx;
27437
27438 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
27439- pmd = one_md_table_init(pgd);
27440- pmd = pmd + pmd_index(vaddr);
27441+ pud = pud_offset(pgd, vaddr);
27442+ pmd = pmd_offset(pud, vaddr);
27443+
27444+#ifdef CONFIG_X86_PAE
27445+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
27446+#endif
27447+
27448 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
27449 pmd++, pmd_idx++) {
27450 pte = page_table_kmap_check(one_page_table_init(pmd),
27451@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27452 }
27453 }
27454
27455-static inline int is_kernel_text(unsigned long addr)
27456+static inline int is_kernel_text(unsigned long start, unsigned long end)
27457 {
27458- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
27459- return 1;
27460- return 0;
27461+ if ((start > ktla_ktva((unsigned long)_etext) ||
27462+ end <= ktla_ktva((unsigned long)_stext)) &&
27463+ (start > ktla_ktva((unsigned long)_einittext) ||
27464+ end <= ktla_ktva((unsigned long)_sinittext)) &&
27465+
27466+#ifdef CONFIG_ACPI_SLEEP
27467+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
27468+#endif
27469+
27470+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
27471+ return 0;
27472+ return 1;
27473 }
27474
27475 /*
27476@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
27477 unsigned long last_map_addr = end;
27478 unsigned long start_pfn, end_pfn;
27479 pgd_t *pgd_base = swapper_pg_dir;
27480- int pgd_idx, pmd_idx, pte_ofs;
27481+ unsigned int pgd_idx, pmd_idx, pte_ofs;
27482 unsigned long pfn;
27483 pgd_t *pgd;
27484+ pud_t *pud;
27485 pmd_t *pmd;
27486 pte_t *pte;
27487 unsigned pages_2m, pages_4k;
27488@@ -280,8 +281,13 @@ repeat:
27489 pfn = start_pfn;
27490 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
27491 pgd = pgd_base + pgd_idx;
27492- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
27493- pmd = one_md_table_init(pgd);
27494+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
27495+ pud = pud_offset(pgd, 0);
27496+ pmd = pmd_offset(pud, 0);
27497+
27498+#ifdef CONFIG_X86_PAE
27499+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
27500+#endif
27501
27502 if (pfn >= end_pfn)
27503 continue;
27504@@ -293,14 +299,13 @@ repeat:
27505 #endif
27506 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
27507 pmd++, pmd_idx++) {
27508- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
27509+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
27510
27511 /*
27512 * Map with big pages if possible, otherwise
27513 * create normal page tables:
27514 */
27515 if (use_pse) {
27516- unsigned int addr2;
27517 pgprot_t prot = PAGE_KERNEL_LARGE;
27518 /*
27519 * first pass will use the same initial
27520@@ -310,11 +315,7 @@ repeat:
27521 __pgprot(PTE_IDENT_ATTR |
27522 _PAGE_PSE);
27523
27524- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
27525- PAGE_OFFSET + PAGE_SIZE-1;
27526-
27527- if (is_kernel_text(addr) ||
27528- is_kernel_text(addr2))
27529+ if (is_kernel_text(address, address + PMD_SIZE))
27530 prot = PAGE_KERNEL_LARGE_EXEC;
27531
27532 pages_2m++;
27533@@ -331,7 +332,7 @@ repeat:
27534 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
27535 pte += pte_ofs;
27536 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
27537- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
27538+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
27539 pgprot_t prot = PAGE_KERNEL;
27540 /*
27541 * first pass will use the same initial
27542@@ -339,7 +340,7 @@ repeat:
27543 */
27544 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
27545
27546- if (is_kernel_text(addr))
27547+ if (is_kernel_text(address, address + PAGE_SIZE))
27548 prot = PAGE_KERNEL_EXEC;
27549
27550 pages_4k++;
27551@@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
27552
27553 pud = pud_offset(pgd, va);
27554 pmd = pmd_offset(pud, va);
27555- if (!pmd_present(*pmd))
27556+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
27557 break;
27558
27559 pte = pte_offset_kernel(pmd, va);
27560@@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
27561
27562 static void __init pagetable_init(void)
27563 {
27564- pgd_t *pgd_base = swapper_pg_dir;
27565-
27566- permanent_kmaps_init(pgd_base);
27567+ permanent_kmaps_init(swapper_pg_dir);
27568 }
27569
27570-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
27571+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
27572 EXPORT_SYMBOL_GPL(__supported_pte_mask);
27573
27574 /* user-defined highmem size */
27575@@ -728,6 +727,12 @@ void __init mem_init(void)
27576
27577 pci_iommu_alloc();
27578
27579+#ifdef CONFIG_PAX_PER_CPU_PGD
27580+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
27581+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27582+ KERNEL_PGD_PTRS);
27583+#endif
27584+
27585 #ifdef CONFIG_FLATMEM
27586 BUG_ON(!mem_map);
27587 #endif
27588@@ -754,7 +759,7 @@ void __init mem_init(void)
27589 reservedpages++;
27590
27591 codesize = (unsigned long) &_etext - (unsigned long) &_text;
27592- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
27593+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
27594 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
27595
27596 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
27597@@ -795,10 +800,10 @@ void __init mem_init(void)
27598 ((unsigned long)&__init_end -
27599 (unsigned long)&__init_begin) >> 10,
27600
27601- (unsigned long)&_etext, (unsigned long)&_edata,
27602- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
27603+ (unsigned long)&_sdata, (unsigned long)&_edata,
27604+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
27605
27606- (unsigned long)&_text, (unsigned long)&_etext,
27607+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
27608 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
27609
27610 /*
27611@@ -876,6 +881,7 @@ void set_kernel_text_rw(void)
27612 if (!kernel_set_to_readonly)
27613 return;
27614
27615+ start = ktla_ktva(start);
27616 pr_debug("Set kernel text: %lx - %lx for read write\n",
27617 start, start+size);
27618
27619@@ -890,6 +896,7 @@ void set_kernel_text_ro(void)
27620 if (!kernel_set_to_readonly)
27621 return;
27622
27623+ start = ktla_ktva(start);
27624 pr_debug("Set kernel text: %lx - %lx for read only\n",
27625 start, start+size);
27626
27627@@ -918,6 +925,7 @@ void mark_rodata_ro(void)
27628 unsigned long start = PFN_ALIGN(_text);
27629 unsigned long size = PFN_ALIGN(_etext) - start;
27630
27631+ start = ktla_ktva(start);
27632 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
27633 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
27634 size >> 10);
27635diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
27636index 75c9a6a..498d677 100644
27637--- a/arch/x86/mm/init_64.c
27638+++ b/arch/x86/mm/init_64.c
27639@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
27640 * around without checking the pgd every time.
27641 */
27642
27643-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
27644+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
27645 EXPORT_SYMBOL_GPL(__supported_pte_mask);
27646
27647 int force_personality32;
27648@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27649
27650 for (address = start; address <= end; address += PGDIR_SIZE) {
27651 const pgd_t *pgd_ref = pgd_offset_k(address);
27652+
27653+#ifdef CONFIG_PAX_PER_CPU_PGD
27654+ unsigned long cpu;
27655+#else
27656 struct page *page;
27657+#endif
27658
27659 if (pgd_none(*pgd_ref))
27660 continue;
27661
27662 spin_lock(&pgd_lock);
27663+
27664+#ifdef CONFIG_PAX_PER_CPU_PGD
27665+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27666+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
27667+#else
27668 list_for_each_entry(page, &pgd_list, lru) {
27669 pgd_t *pgd;
27670 spinlock_t *pgt_lock;
27671@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27672 /* the pgt_lock only for Xen */
27673 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27674 spin_lock(pgt_lock);
27675+#endif
27676
27677 if (pgd_none(*pgd))
27678 set_pgd(pgd, *pgd_ref);
27679@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27680 BUG_ON(pgd_page_vaddr(*pgd)
27681 != pgd_page_vaddr(*pgd_ref));
27682
27683+#ifndef CONFIG_PAX_PER_CPU_PGD
27684 spin_unlock(pgt_lock);
27685+#endif
27686+
27687 }
27688 spin_unlock(&pgd_lock);
27689 }
27690@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
27691 {
27692 if (pgd_none(*pgd)) {
27693 pud_t *pud = (pud_t *)spp_getpage();
27694- pgd_populate(&init_mm, pgd, pud);
27695+ pgd_populate_kernel(&init_mm, pgd, pud);
27696 if (pud != pud_offset(pgd, 0))
27697 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
27698 pud, pud_offset(pgd, 0));
27699@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
27700 {
27701 if (pud_none(*pud)) {
27702 pmd_t *pmd = (pmd_t *) spp_getpage();
27703- pud_populate(&init_mm, pud, pmd);
27704+ pud_populate_kernel(&init_mm, pud, pmd);
27705 if (pmd != pmd_offset(pud, 0))
27706 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
27707 pmd, pmd_offset(pud, 0));
27708@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
27709 pmd = fill_pmd(pud, vaddr);
27710 pte = fill_pte(pmd, vaddr);
27711
27712+ pax_open_kernel();
27713 set_pte(pte, new_pte);
27714+ pax_close_kernel();
27715
27716 /*
27717 * It's enough to flush this one mapping.
27718@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
27719 pgd = pgd_offset_k((unsigned long)__va(phys));
27720 if (pgd_none(*pgd)) {
27721 pud = (pud_t *) spp_getpage();
27722- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
27723- _PAGE_USER));
27724+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
27725 }
27726 pud = pud_offset(pgd, (unsigned long)__va(phys));
27727 if (pud_none(*pud)) {
27728 pmd = (pmd_t *) spp_getpage();
27729- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
27730- _PAGE_USER));
27731+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
27732 }
27733 pmd = pmd_offset(pud, phys);
27734 BUG_ON(!pmd_none(*pmd));
27735@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
27736 if (pfn >= pgt_buf_top)
27737 panic("alloc_low_page: ran out of memory");
27738
27739- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
27740+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
27741 clear_page(adr);
27742 *phys = pfn * PAGE_SIZE;
27743 return adr;
27744@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
27745
27746 phys = __pa(virt);
27747 left = phys & (PAGE_SIZE - 1);
27748- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
27749+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
27750 adr = (void *)(((unsigned long)adr) | left);
27751
27752 return adr;
27753@@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
27754 unmap_low_page(pmd);
27755
27756 spin_lock(&init_mm.page_table_lock);
27757- pud_populate(&init_mm, pud, __va(pmd_phys));
27758+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
27759 spin_unlock(&init_mm.page_table_lock);
27760 }
27761 __flush_tlb_all();
27762@@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
27763 unmap_low_page(pud);
27764
27765 spin_lock(&init_mm.page_table_lock);
27766- pgd_populate(&init_mm, pgd, __va(pud_phys));
27767+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
27768 spin_unlock(&init_mm.page_table_lock);
27769 pgd_changed = true;
27770 }
27771@@ -693,6 +707,12 @@ void __init mem_init(void)
27772
27773 pci_iommu_alloc();
27774
27775+#ifdef CONFIG_PAX_PER_CPU_PGD
27776+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
27777+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27778+ KERNEL_PGD_PTRS);
27779+#endif
27780+
27781 /* clear_bss() already clear the empty_zero_page */
27782
27783 reservedpages = 0;
27784@@ -856,8 +876,8 @@ int kern_addr_valid(unsigned long addr)
27785 static struct vm_area_struct gate_vma = {
27786 .vm_start = VSYSCALL_START,
27787 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
27788- .vm_page_prot = PAGE_READONLY_EXEC,
27789- .vm_flags = VM_READ | VM_EXEC
27790+ .vm_page_prot = PAGE_READONLY,
27791+ .vm_flags = VM_READ
27792 };
27793
27794 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27795@@ -891,7 +911,7 @@ int in_gate_area_no_mm(unsigned long addr)
27796
27797 const char *arch_vma_name(struct vm_area_struct *vma)
27798 {
27799- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27800+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27801 return "[vdso]";
27802 if (vma == &gate_vma)
27803 return "[vsyscall]";
27804diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
27805index 7b179b4..6bd1777 100644
27806--- a/arch/x86/mm/iomap_32.c
27807+++ b/arch/x86/mm/iomap_32.c
27808@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
27809 type = kmap_atomic_idx_push();
27810 idx = type + KM_TYPE_NR * smp_processor_id();
27811 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27812+
27813+ pax_open_kernel();
27814 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
27815+ pax_close_kernel();
27816+
27817 arch_flush_lazy_mmu_mode();
27818
27819 return (void *)vaddr;
27820diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
27821index 78fe3f1..2f9433c 100644
27822--- a/arch/x86/mm/ioremap.c
27823+++ b/arch/x86/mm/ioremap.c
27824@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
27825 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
27826 int is_ram = page_is_ram(pfn);
27827
27828- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
27829+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
27830 return NULL;
27831 WARN_ON_ONCE(is_ram);
27832 }
27833@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
27834 *
27835 * Caller must ensure there is only one unmapping for the same pointer.
27836 */
27837-void iounmap(volatile void __iomem *addr)
27838+void iounmap(const volatile void __iomem *addr)
27839 {
27840 struct vm_struct *p, *o;
27841
27842@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
27843
27844 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
27845 if (page_is_ram(start >> PAGE_SHIFT))
27846+#ifdef CONFIG_HIGHMEM
27847+ if ((start >> PAGE_SHIFT) < max_low_pfn)
27848+#endif
27849 return __va(phys);
27850
27851 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
27852@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
27853 early_param("early_ioremap_debug", early_ioremap_debug_setup);
27854
27855 static __initdata int after_paging_init;
27856-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
27857+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
27858
27859 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
27860 {
27861@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
27862 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
27863
27864 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
27865- memset(bm_pte, 0, sizeof(bm_pte));
27866- pmd_populate_kernel(&init_mm, pmd, bm_pte);
27867+ pmd_populate_user(&init_mm, pmd, bm_pte);
27868
27869 /*
27870 * The boot-ioremap range spans multiple pmds, for which
27871diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
27872index d87dd6d..bf3fa66 100644
27873--- a/arch/x86/mm/kmemcheck/kmemcheck.c
27874+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
27875@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
27876 * memory (e.g. tracked pages)? For now, we need this to avoid
27877 * invoking kmemcheck for PnP BIOS calls.
27878 */
27879- if (regs->flags & X86_VM_MASK)
27880+ if (v8086_mode(regs))
27881 return false;
27882- if (regs->cs != __KERNEL_CS)
27883+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
27884 return false;
27885
27886 pte = kmemcheck_pte_lookup(address);
27887diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
27888index 845df68..1d8d29f 100644
27889--- a/arch/x86/mm/mmap.c
27890+++ b/arch/x86/mm/mmap.c
27891@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
27892 * Leave an at least ~128 MB hole with possible stack randomization.
27893 */
27894 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
27895-#define MAX_GAP (TASK_SIZE/6*5)
27896+#define MAX_GAP (pax_task_size/6*5)
27897
27898 static int mmap_is_legacy(void)
27899 {
27900@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
27901 return rnd << PAGE_SHIFT;
27902 }
27903
27904-static unsigned long mmap_base(void)
27905+static unsigned long mmap_base(struct mm_struct *mm)
27906 {
27907 unsigned long gap = rlimit(RLIMIT_STACK);
27908+ unsigned long pax_task_size = TASK_SIZE;
27909+
27910+#ifdef CONFIG_PAX_SEGMEXEC
27911+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27912+ pax_task_size = SEGMEXEC_TASK_SIZE;
27913+#endif
27914
27915 if (gap < MIN_GAP)
27916 gap = MIN_GAP;
27917 else if (gap > MAX_GAP)
27918 gap = MAX_GAP;
27919
27920- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
27921+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
27922 }
27923
27924 /*
27925 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
27926 * does, but not when emulating X86_32
27927 */
27928-static unsigned long mmap_legacy_base(void)
27929+static unsigned long mmap_legacy_base(struct mm_struct *mm)
27930 {
27931- if (mmap_is_ia32())
27932+ if (mmap_is_ia32()) {
27933+
27934+#ifdef CONFIG_PAX_SEGMEXEC
27935+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27936+ return SEGMEXEC_TASK_UNMAPPED_BASE;
27937+ else
27938+#endif
27939+
27940 return TASK_UNMAPPED_BASE;
27941- else
27942+ } else
27943 return TASK_UNMAPPED_BASE + mmap_rnd();
27944 }
27945
27946@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
27947 void arch_pick_mmap_layout(struct mm_struct *mm)
27948 {
27949 if (mmap_is_legacy()) {
27950- mm->mmap_base = mmap_legacy_base();
27951+ mm->mmap_base = mmap_legacy_base(mm);
27952+
27953+#ifdef CONFIG_PAX_RANDMMAP
27954+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27955+ mm->mmap_base += mm->delta_mmap;
27956+#endif
27957+
27958 mm->get_unmapped_area = arch_get_unmapped_area;
27959 mm->unmap_area = arch_unmap_area;
27960 } else {
27961- mm->mmap_base = mmap_base();
27962+ mm->mmap_base = mmap_base(mm);
27963+
27964+#ifdef CONFIG_PAX_RANDMMAP
27965+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27966+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
27967+#endif
27968+
27969 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
27970 mm->unmap_area = arch_unmap_area_topdown;
27971 }
27972diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
27973index dc0b727..f612039 100644
27974--- a/arch/x86/mm/mmio-mod.c
27975+++ b/arch/x86/mm/mmio-mod.c
27976@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
27977 break;
27978 default:
27979 {
27980- unsigned char *ip = (unsigned char *)instptr;
27981+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
27982 my_trace->opcode = MMIO_UNKNOWN_OP;
27983 my_trace->width = 0;
27984 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
27985@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
27986 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
27987 void __iomem *addr)
27988 {
27989- static atomic_t next_id;
27990+ static atomic_unchecked_t next_id;
27991 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
27992 /* These are page-unaligned. */
27993 struct mmiotrace_map map = {
27994@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
27995 .private = trace
27996 },
27997 .phys = offset,
27998- .id = atomic_inc_return(&next_id)
27999+ .id = atomic_inc_return_unchecked(&next_id)
28000 };
28001 map.map_id = trace->id;
28002
28003@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28004 ioremap_trace_core(offset, size, addr);
28005 }
28006
28007-static void iounmap_trace_core(volatile void __iomem *addr)
28008+static void iounmap_trace_core(const volatile void __iomem *addr)
28009 {
28010 struct mmiotrace_map map = {
28011 .phys = 0,
28012@@ -328,7 +328,7 @@ not_enabled:
28013 }
28014 }
28015
28016-void mmiotrace_iounmap(volatile void __iomem *addr)
28017+void mmiotrace_iounmap(const volatile void __iomem *addr)
28018 {
28019 might_sleep();
28020 if (is_enabled()) /* recheck and proper locking in *_core() */
28021diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
28022index b008656..773eac2 100644
28023--- a/arch/x86/mm/pageattr-test.c
28024+++ b/arch/x86/mm/pageattr-test.c
28025@@ -36,7 +36,7 @@ enum {
28026
28027 static int pte_testbit(pte_t pte)
28028 {
28029- return pte_flags(pte) & _PAGE_UNUSED1;
28030+ return pte_flags(pte) & _PAGE_CPA_TEST;
28031 }
28032
28033 struct split_state {
28034diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
28035index a718e0d..77419bc 100644
28036--- a/arch/x86/mm/pageattr.c
28037+++ b/arch/x86/mm/pageattr.c
28038@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28039 */
28040 #ifdef CONFIG_PCI_BIOS
28041 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
28042- pgprot_val(forbidden) |= _PAGE_NX;
28043+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28044 #endif
28045
28046 /*
28047@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28048 * Does not cover __inittext since that is gone later on. On
28049 * 64bit we do not enforce !NX on the low mapping
28050 */
28051- if (within(address, (unsigned long)_text, (unsigned long)_etext))
28052- pgprot_val(forbidden) |= _PAGE_NX;
28053+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
28054+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28055
28056+#ifdef CONFIG_DEBUG_RODATA
28057 /*
28058 * The .rodata section needs to be read-only. Using the pfn
28059 * catches all aliases.
28060@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28061 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
28062 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
28063 pgprot_val(forbidden) |= _PAGE_RW;
28064+#endif
28065
28066 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
28067 /*
28068@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28069 }
28070 #endif
28071
28072+#ifdef CONFIG_PAX_KERNEXEC
28073+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
28074+ pgprot_val(forbidden) |= _PAGE_RW;
28075+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28076+ }
28077+#endif
28078+
28079 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
28080
28081 return prot;
28082@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
28083 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
28084 {
28085 /* change init_mm */
28086+ pax_open_kernel();
28087 set_pte_atomic(kpte, pte);
28088+
28089 #ifdef CONFIG_X86_32
28090 if (!SHARED_KERNEL_PMD) {
28091+
28092+#ifdef CONFIG_PAX_PER_CPU_PGD
28093+ unsigned long cpu;
28094+#else
28095 struct page *page;
28096+#endif
28097
28098+#ifdef CONFIG_PAX_PER_CPU_PGD
28099+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28100+ pgd_t *pgd = get_cpu_pgd(cpu);
28101+#else
28102 list_for_each_entry(page, &pgd_list, lru) {
28103- pgd_t *pgd;
28104+ pgd_t *pgd = (pgd_t *)page_address(page);
28105+#endif
28106+
28107 pud_t *pud;
28108 pmd_t *pmd;
28109
28110- pgd = (pgd_t *)page_address(page) + pgd_index(address);
28111+ pgd += pgd_index(address);
28112 pud = pud_offset(pgd, address);
28113 pmd = pmd_offset(pud, address);
28114 set_pte_atomic((pte_t *)pmd, pte);
28115 }
28116 }
28117 #endif
28118+ pax_close_kernel();
28119 }
28120
28121 static int
28122diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
28123index 0eb572e..92f5c1e 100644
28124--- a/arch/x86/mm/pat.c
28125+++ b/arch/x86/mm/pat.c
28126@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
28127
28128 if (!entry) {
28129 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
28130- current->comm, current->pid, start, end - 1);
28131+ current->comm, task_pid_nr(current), start, end - 1);
28132 return -EINVAL;
28133 }
28134
28135@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28136
28137 while (cursor < to) {
28138 if (!devmem_is_allowed(pfn)) {
28139- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
28140- current->comm, from, to - 1);
28141+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
28142+ current->comm, from, to - 1, cursor);
28143 return 0;
28144 }
28145 cursor += PAGE_SIZE;
28146@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
28147 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
28148 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
28149 "for [mem %#010Lx-%#010Lx]\n",
28150- current->comm, current->pid,
28151+ current->comm, task_pid_nr(current),
28152 cattr_name(flags),
28153 base, (unsigned long long)(base + size-1));
28154 return -EINVAL;
28155@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28156 flags = lookup_memtype(paddr);
28157 if (want_flags != flags) {
28158 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
28159- current->comm, current->pid,
28160+ current->comm, task_pid_nr(current),
28161 cattr_name(want_flags),
28162 (unsigned long long)paddr,
28163 (unsigned long long)(paddr + size - 1),
28164@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28165 free_memtype(paddr, paddr + size);
28166 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
28167 " for [mem %#010Lx-%#010Lx], got %s\n",
28168- current->comm, current->pid,
28169+ current->comm, task_pid_nr(current),
28170 cattr_name(want_flags),
28171 (unsigned long long)paddr,
28172 (unsigned long long)(paddr + size - 1),
28173diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
28174index 9f0614d..92ae64a 100644
28175--- a/arch/x86/mm/pf_in.c
28176+++ b/arch/x86/mm/pf_in.c
28177@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
28178 int i;
28179 enum reason_type rv = OTHERS;
28180
28181- p = (unsigned char *)ins_addr;
28182+ p = (unsigned char *)ktla_ktva(ins_addr);
28183 p += skip_prefix(p, &prf);
28184 p += get_opcode(p, &opcode);
28185
28186@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
28187 struct prefix_bits prf;
28188 int i;
28189
28190- p = (unsigned char *)ins_addr;
28191+ p = (unsigned char *)ktla_ktva(ins_addr);
28192 p += skip_prefix(p, &prf);
28193 p += get_opcode(p, &opcode);
28194
28195@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
28196 struct prefix_bits prf;
28197 int i;
28198
28199- p = (unsigned char *)ins_addr;
28200+ p = (unsigned char *)ktla_ktva(ins_addr);
28201 p += skip_prefix(p, &prf);
28202 p += get_opcode(p, &opcode);
28203
28204@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
28205 struct prefix_bits prf;
28206 int i;
28207
28208- p = (unsigned char *)ins_addr;
28209+ p = (unsigned char *)ktla_ktva(ins_addr);
28210 p += skip_prefix(p, &prf);
28211 p += get_opcode(p, &opcode);
28212 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
28213@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
28214 struct prefix_bits prf;
28215 int i;
28216
28217- p = (unsigned char *)ins_addr;
28218+ p = (unsigned char *)ktla_ktva(ins_addr);
28219 p += skip_prefix(p, &prf);
28220 p += get_opcode(p, &opcode);
28221 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
28222diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
28223index e27fbf8..8b56dc9 100644
28224--- a/arch/x86/mm/pgtable.c
28225+++ b/arch/x86/mm/pgtable.c
28226@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
28227 list_del(&page->lru);
28228 }
28229
28230-#define UNSHARED_PTRS_PER_PGD \
28231- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28232+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28233+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
28234
28235+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
28236+{
28237+ unsigned int count = USER_PGD_PTRS;
28238
28239+ while (count--)
28240+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
28241+}
28242+#endif
28243+
28244+#ifdef CONFIG_PAX_PER_CPU_PGD
28245+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
28246+{
28247+ unsigned int count = USER_PGD_PTRS;
28248+
28249+ while (count--) {
28250+ pgd_t pgd;
28251+
28252+#ifdef CONFIG_X86_64
28253+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
28254+#else
28255+ pgd = *src++;
28256+#endif
28257+
28258+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28259+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
28260+#endif
28261+
28262+ *dst++ = pgd;
28263+ }
28264+
28265+}
28266+#endif
28267+
28268+#ifdef CONFIG_X86_64
28269+#define pxd_t pud_t
28270+#define pyd_t pgd_t
28271+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
28272+#define pxd_free(mm, pud) pud_free((mm), (pud))
28273+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
28274+#define pyd_offset(mm, address) pgd_offset((mm), (address))
28275+#define PYD_SIZE PGDIR_SIZE
28276+#else
28277+#define pxd_t pmd_t
28278+#define pyd_t pud_t
28279+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
28280+#define pxd_free(mm, pud) pmd_free((mm), (pud))
28281+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
28282+#define pyd_offset(mm, address) pud_offset((mm), (address))
28283+#define PYD_SIZE PUD_SIZE
28284+#endif
28285+
28286+#ifdef CONFIG_PAX_PER_CPU_PGD
28287+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
28288+static inline void pgd_dtor(pgd_t *pgd) {}
28289+#else
28290 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
28291 {
28292 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
28293@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
28294 pgd_list_del(pgd);
28295 spin_unlock(&pgd_lock);
28296 }
28297+#endif
28298
28299 /*
28300 * List of all pgd's needed for non-PAE so it can invalidate entries
28301@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
28302 * -- nyc
28303 */
28304
28305-#ifdef CONFIG_X86_PAE
28306+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
28307 /*
28308 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
28309 * updating the top-level pagetable entries to guarantee the
28310@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
28311 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
28312 * and initialize the kernel pmds here.
28313 */
28314-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
28315+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28316
28317 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28318 {
28319@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28320 */
28321 flush_tlb_mm(mm);
28322 }
28323+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
28324+#define PREALLOCATED_PXDS USER_PGD_PTRS
28325 #else /* !CONFIG_X86_PAE */
28326
28327 /* No need to prepopulate any pagetable entries in non-PAE modes. */
28328-#define PREALLOCATED_PMDS 0
28329+#define PREALLOCATED_PXDS 0
28330
28331 #endif /* CONFIG_X86_PAE */
28332
28333-static void free_pmds(pmd_t *pmds[])
28334+static void free_pxds(pxd_t *pxds[])
28335 {
28336 int i;
28337
28338- for(i = 0; i < PREALLOCATED_PMDS; i++)
28339- if (pmds[i])
28340- free_page((unsigned long)pmds[i]);
28341+ for(i = 0; i < PREALLOCATED_PXDS; i++)
28342+ if (pxds[i])
28343+ free_page((unsigned long)pxds[i]);
28344 }
28345
28346-static int preallocate_pmds(pmd_t *pmds[])
28347+static int preallocate_pxds(pxd_t *pxds[])
28348 {
28349 int i;
28350 bool failed = false;
28351
28352- for(i = 0; i < PREALLOCATED_PMDS; i++) {
28353- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
28354- if (pmd == NULL)
28355+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
28356+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
28357+ if (pxd == NULL)
28358 failed = true;
28359- pmds[i] = pmd;
28360+ pxds[i] = pxd;
28361 }
28362
28363 if (failed) {
28364- free_pmds(pmds);
28365+ free_pxds(pxds);
28366 return -ENOMEM;
28367 }
28368
28369@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
28370 * preallocate which never got a corresponding vma will need to be
28371 * freed manually.
28372 */
28373-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
28374+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
28375 {
28376 int i;
28377
28378- for(i = 0; i < PREALLOCATED_PMDS; i++) {
28379+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
28380 pgd_t pgd = pgdp[i];
28381
28382 if (pgd_val(pgd) != 0) {
28383- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
28384+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
28385
28386- pgdp[i] = native_make_pgd(0);
28387+ set_pgd(pgdp + i, native_make_pgd(0));
28388
28389- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
28390- pmd_free(mm, pmd);
28391+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
28392+ pxd_free(mm, pxd);
28393 }
28394 }
28395 }
28396
28397-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
28398+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
28399 {
28400- pud_t *pud;
28401+ pyd_t *pyd;
28402 unsigned long addr;
28403 int i;
28404
28405- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
28406+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
28407 return;
28408
28409- pud = pud_offset(pgd, 0);
28410+#ifdef CONFIG_X86_64
28411+ pyd = pyd_offset(mm, 0L);
28412+#else
28413+ pyd = pyd_offset(pgd, 0L);
28414+#endif
28415
28416- for (addr = i = 0; i < PREALLOCATED_PMDS;
28417- i++, pud++, addr += PUD_SIZE) {
28418- pmd_t *pmd = pmds[i];
28419+ for (addr = i = 0; i < PREALLOCATED_PXDS;
28420+ i++, pyd++, addr += PYD_SIZE) {
28421+ pxd_t *pxd = pxds[i];
28422
28423 if (i >= KERNEL_PGD_BOUNDARY)
28424- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
28425- sizeof(pmd_t) * PTRS_PER_PMD);
28426+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
28427+ sizeof(pxd_t) * PTRS_PER_PMD);
28428
28429- pud_populate(mm, pud, pmd);
28430+ pyd_populate(mm, pyd, pxd);
28431 }
28432 }
28433
28434 pgd_t *pgd_alloc(struct mm_struct *mm)
28435 {
28436 pgd_t *pgd;
28437- pmd_t *pmds[PREALLOCATED_PMDS];
28438+ pxd_t *pxds[PREALLOCATED_PXDS];
28439
28440 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
28441
28442@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
28443
28444 mm->pgd = pgd;
28445
28446- if (preallocate_pmds(pmds) != 0)
28447+ if (preallocate_pxds(pxds) != 0)
28448 goto out_free_pgd;
28449
28450 if (paravirt_pgd_alloc(mm) != 0)
28451- goto out_free_pmds;
28452+ goto out_free_pxds;
28453
28454 /*
28455 * Make sure that pre-populating the pmds is atomic with
28456@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
28457 spin_lock(&pgd_lock);
28458
28459 pgd_ctor(mm, pgd);
28460- pgd_prepopulate_pmd(mm, pgd, pmds);
28461+ pgd_prepopulate_pxd(mm, pgd, pxds);
28462
28463 spin_unlock(&pgd_lock);
28464
28465 return pgd;
28466
28467-out_free_pmds:
28468- free_pmds(pmds);
28469+out_free_pxds:
28470+ free_pxds(pxds);
28471 out_free_pgd:
28472 free_page((unsigned long)pgd);
28473 out:
28474@@ -295,7 +356,7 @@ out:
28475
28476 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
28477 {
28478- pgd_mop_up_pmds(mm, pgd);
28479+ pgd_mop_up_pxds(mm, pgd);
28480 pgd_dtor(pgd);
28481 paravirt_pgd_free(mm, pgd);
28482 free_page((unsigned long)pgd);
28483diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
28484index a69bcb8..19068ab 100644
28485--- a/arch/x86/mm/pgtable_32.c
28486+++ b/arch/x86/mm/pgtable_32.c
28487@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
28488 return;
28489 }
28490 pte = pte_offset_kernel(pmd, vaddr);
28491+
28492+ pax_open_kernel();
28493 if (pte_val(pteval))
28494 set_pte_at(&init_mm, vaddr, pte, pteval);
28495 else
28496 pte_clear(&init_mm, vaddr, pte);
28497+ pax_close_kernel();
28498
28499 /*
28500 * It's enough to flush this one mapping.
28501diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
28502index 410531d..0f16030 100644
28503--- a/arch/x86/mm/setup_nx.c
28504+++ b/arch/x86/mm/setup_nx.c
28505@@ -5,8 +5,10 @@
28506 #include <asm/pgtable.h>
28507 #include <asm/proto.h>
28508
28509+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28510 static int disable_nx __cpuinitdata;
28511
28512+#ifndef CONFIG_PAX_PAGEEXEC
28513 /*
28514 * noexec = on|off
28515 *
28516@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
28517 return 0;
28518 }
28519 early_param("noexec", noexec_setup);
28520+#endif
28521+
28522+#endif
28523
28524 void __cpuinit x86_configure_nx(void)
28525 {
28526+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28527 if (cpu_has_nx && !disable_nx)
28528 __supported_pte_mask |= _PAGE_NX;
28529 else
28530+#endif
28531 __supported_pte_mask &= ~_PAGE_NX;
28532 }
28533
28534diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
28535index 13a6b29..c2fff23 100644
28536--- a/arch/x86/mm/tlb.c
28537+++ b/arch/x86/mm/tlb.c
28538@@ -48,7 +48,11 @@ void leave_mm(int cpu)
28539 BUG();
28540 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
28541 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
28542+
28543+#ifndef CONFIG_PAX_PER_CPU_PGD
28544 load_cr3(swapper_pg_dir);
28545+#endif
28546+
28547 }
28548 }
28549 EXPORT_SYMBOL_GPL(leave_mm);
28550diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
28551index 877b9a1..a8ecf42 100644
28552--- a/arch/x86/net/bpf_jit.S
28553+++ b/arch/x86/net/bpf_jit.S
28554@@ -9,6 +9,7 @@
28555 */
28556 #include <linux/linkage.h>
28557 #include <asm/dwarf2.h>
28558+#include <asm/alternative-asm.h>
28559
28560 /*
28561 * Calling convention :
28562@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
28563 jle bpf_slow_path_word
28564 mov (SKBDATA,%rsi),%eax
28565 bswap %eax /* ntohl() */
28566+ pax_force_retaddr
28567 ret
28568
28569 sk_load_half:
28570@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
28571 jle bpf_slow_path_half
28572 movzwl (SKBDATA,%rsi),%eax
28573 rol $8,%ax # ntohs()
28574+ pax_force_retaddr
28575 ret
28576
28577 sk_load_byte:
28578@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
28579 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
28580 jle bpf_slow_path_byte
28581 movzbl (SKBDATA,%rsi),%eax
28582+ pax_force_retaddr
28583 ret
28584
28585 /**
28586@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
28587 movzbl (SKBDATA,%rsi),%ebx
28588 and $15,%bl
28589 shl $2,%bl
28590+ pax_force_retaddr
28591 ret
28592
28593 /* rsi contains offset and can be scratched */
28594@@ -109,6 +114,7 @@ bpf_slow_path_word:
28595 js bpf_error
28596 mov -12(%rbp),%eax
28597 bswap %eax
28598+ pax_force_retaddr
28599 ret
28600
28601 bpf_slow_path_half:
28602@@ -117,12 +123,14 @@ bpf_slow_path_half:
28603 mov -12(%rbp),%ax
28604 rol $8,%ax
28605 movzwl %ax,%eax
28606+ pax_force_retaddr
28607 ret
28608
28609 bpf_slow_path_byte:
28610 bpf_slow_path_common(1)
28611 js bpf_error
28612 movzbl -12(%rbp),%eax
28613+ pax_force_retaddr
28614 ret
28615
28616 bpf_slow_path_byte_msh:
28617@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
28618 and $15,%al
28619 shl $2,%al
28620 xchg %eax,%ebx
28621+ pax_force_retaddr
28622 ret
28623
28624 #define sk_negative_common(SIZE) \
28625@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
28626 sk_negative_common(4)
28627 mov (%rax), %eax
28628 bswap %eax
28629+ pax_force_retaddr
28630 ret
28631
28632 bpf_slow_path_half_neg:
28633@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
28634 mov (%rax),%ax
28635 rol $8,%ax
28636 movzwl %ax,%eax
28637+ pax_force_retaddr
28638 ret
28639
28640 bpf_slow_path_byte_neg:
28641@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
28642 .globl sk_load_byte_negative_offset
28643 sk_negative_common(1)
28644 movzbl (%rax), %eax
28645+ pax_force_retaddr
28646 ret
28647
28648 bpf_slow_path_byte_msh_neg:
28649@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
28650 and $15,%al
28651 shl $2,%al
28652 xchg %eax,%ebx
28653+ pax_force_retaddr
28654 ret
28655
28656 bpf_error:
28657@@ -197,4 +210,5 @@ bpf_error:
28658 xor %eax,%eax
28659 mov -8(%rbp),%rbx
28660 leaveq
28661+ pax_force_retaddr
28662 ret
28663diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
28664index d11a470..3f9adff3 100644
28665--- a/arch/x86/net/bpf_jit_comp.c
28666+++ b/arch/x86/net/bpf_jit_comp.c
28667@@ -12,6 +12,7 @@
28668 #include <linux/netdevice.h>
28669 #include <linux/filter.h>
28670 #include <linux/if_vlan.h>
28671+#include <linux/random.h>
28672
28673 /*
28674 * Conventions :
28675@@ -49,13 +50,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
28676 return ptr + len;
28677 }
28678
28679+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28680+#define MAX_INSTR_CODE_SIZE 96
28681+#else
28682+#define MAX_INSTR_CODE_SIZE 64
28683+#endif
28684+
28685 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
28686
28687 #define EMIT1(b1) EMIT(b1, 1)
28688 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
28689 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
28690 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
28691+
28692+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28693+/* original constant will appear in ecx */
28694+#define DILUTE_CONST_SEQUENCE(_off, _key) \
28695+do { \
28696+ /* mov ecx, randkey */ \
28697+ EMIT1(0xb9); \
28698+ EMIT(_key, 4); \
28699+ /* xor ecx, randkey ^ off */ \
28700+ EMIT2(0x81, 0xf1); \
28701+ EMIT((_key) ^ (_off), 4); \
28702+} while (0)
28703+
28704+#define EMIT1_off32(b1, _off) \
28705+do { \
28706+ switch (b1) { \
28707+ case 0x05: /* add eax, imm32 */ \
28708+ case 0x2d: /* sub eax, imm32 */ \
28709+ case 0x25: /* and eax, imm32 */ \
28710+ case 0x0d: /* or eax, imm32 */ \
28711+ case 0xb8: /* mov eax, imm32 */ \
28712+ case 0x3d: /* cmp eax, imm32 */ \
28713+ case 0xa9: /* test eax, imm32 */ \
28714+ DILUTE_CONST_SEQUENCE(_off, randkey); \
28715+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
28716+ break; \
28717+ case 0xbb: /* mov ebx, imm32 */ \
28718+ DILUTE_CONST_SEQUENCE(_off, randkey); \
28719+ /* mov ebx, ecx */ \
28720+ EMIT2(0x89, 0xcb); \
28721+ break; \
28722+ case 0xbe: /* mov esi, imm32 */ \
28723+ DILUTE_CONST_SEQUENCE(_off, randkey); \
28724+ /* mov esi, ecx */ \
28725+ EMIT2(0x89, 0xce); \
28726+ break; \
28727+ case 0xe9: /* jmp rel imm32 */ \
28728+ EMIT1(b1); \
28729+ EMIT(_off, 4); \
28730+ /* prevent fall-through, we're not called if off = 0 */ \
28731+ EMIT(0xcccccccc, 4); \
28732+ EMIT(0xcccccccc, 4); \
28733+ break; \
28734+ default: \
28735+ EMIT1(b1); \
28736+ EMIT(_off, 4); \
28737+ } \
28738+} while (0)
28739+
28740+#define EMIT2_off32(b1, b2, _off) \
28741+do { \
28742+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
28743+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
28744+ EMIT(randkey, 4); \
28745+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
28746+ EMIT((_off) - randkey, 4); \
28747+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
28748+ DILUTE_CONST_SEQUENCE(_off, randkey); \
28749+ /* imul eax, ecx */ \
28750+ EMIT3(0x0f, 0xaf, 0xc1); \
28751+ } else { \
28752+ EMIT2(b1, b2); \
28753+ EMIT(_off, 4); \
28754+ } \
28755+} while (0)
28756+#else
28757 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
28758+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
28759+#endif
28760
28761 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
28762 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
28763@@ -90,6 +165,24 @@ do { \
28764 #define X86_JBE 0x76
28765 #define X86_JA 0x77
28766
28767+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28768+#define APPEND_FLOW_VERIFY() \
28769+do { \
28770+ /* mov ecx, randkey */ \
28771+ EMIT1(0xb9); \
28772+ EMIT(randkey, 4); \
28773+ /* cmp ecx, randkey */ \
28774+ EMIT2(0x81, 0xf9); \
28775+ EMIT(randkey, 4); \
28776+ /* jz after 8 int 3s */ \
28777+ EMIT2(0x74, 0x08); \
28778+ EMIT(0xcccccccc, 4); \
28779+ EMIT(0xcccccccc, 4); \
28780+} while (0)
28781+#else
28782+#define APPEND_FLOW_VERIFY() do { } while (0)
28783+#endif
28784+
28785 #define EMIT_COND_JMP(op, offset) \
28786 do { \
28787 if (is_near(offset)) \
28788@@ -97,6 +190,7 @@ do { \
28789 else { \
28790 EMIT2(0x0f, op + 0x10); \
28791 EMIT(offset, 4); /* jxx .+off32 */ \
28792+ APPEND_FLOW_VERIFY(); \
28793 } \
28794 } while (0)
28795
28796@@ -121,12 +215,17 @@ static inline void bpf_flush_icache(void *start, void *end)
28797 set_fs(old_fs);
28798 }
28799
28800+struct bpf_jit_work {
28801+ struct work_struct work;
28802+ void *image;
28803+};
28804+
28805 #define CHOOSE_LOAD_FUNC(K, func) \
28806 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
28807
28808 void bpf_jit_compile(struct sk_filter *fp)
28809 {
28810- u8 temp[64];
28811+ u8 temp[MAX_INSTR_CODE_SIZE];
28812 u8 *prog;
28813 unsigned int proglen, oldproglen = 0;
28814 int ilen, i;
28815@@ -139,6 +238,9 @@ void bpf_jit_compile(struct sk_filter *fp)
28816 unsigned int *addrs;
28817 const struct sock_filter *filter = fp->insns;
28818 int flen = fp->len;
28819+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28820+ unsigned int randkey;
28821+#endif
28822
28823 if (!bpf_jit_enable)
28824 return;
28825@@ -147,11 +249,19 @@ void bpf_jit_compile(struct sk_filter *fp)
28826 if (addrs == NULL)
28827 return;
28828
28829+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
28830+ if (!fp->work)
28831+ goto out;
28832+
28833+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28834+ randkey = get_random_int();
28835+#endif
28836+
28837 /* Before first pass, make a rough estimation of addrs[]
28838- * each bpf instruction is translated to less than 64 bytes
28839+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
28840 */
28841 for (proglen = 0, i = 0; i < flen; i++) {
28842- proglen += 64;
28843+ proglen += MAX_INSTR_CODE_SIZE;
28844 addrs[i] = proglen;
28845 }
28846 cleanup_addr = proglen; /* epilogue address */
28847@@ -261,10 +371,8 @@ void bpf_jit_compile(struct sk_filter *fp)
28848 case BPF_S_ALU_MUL_K: /* A *= K */
28849 if (is_imm8(K))
28850 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
28851- else {
28852- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
28853- EMIT(K, 4);
28854- }
28855+ else
28856+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
28857 break;
28858 case BPF_S_ALU_DIV_X: /* A /= X; */
28859 seen |= SEEN_XREG;
28860@@ -304,13 +412,23 @@ void bpf_jit_compile(struct sk_filter *fp)
28861 break;
28862 case BPF_S_ALU_MOD_K: /* A %= K; */
28863 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
28864+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28865+ DILUTE_CONST_SEQUENCE(K, randkey);
28866+#else
28867 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
28868+#endif
28869 EMIT2(0xf7, 0xf1); /* div %ecx */
28870 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
28871 break;
28872 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
28873+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28874+ DILUTE_CONST_SEQUENCE(K, randkey);
28875+ // imul rax, rcx
28876+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
28877+#else
28878 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
28879 EMIT(K, 4);
28880+#endif
28881 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
28882 break;
28883 case BPF_S_ALU_AND_X:
28884@@ -564,8 +682,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
28885 if (is_imm8(K)) {
28886 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
28887 } else {
28888- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
28889- EMIT(K, 4);
28890+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
28891 }
28892 } else {
28893 EMIT2(0x89,0xde); /* mov %ebx,%esi */
28894@@ -648,17 +765,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
28895 break;
28896 default:
28897 /* hmm, too complex filter, give up with jit compiler */
28898- goto out;
28899+ goto error;
28900 }
28901 ilen = prog - temp;
28902 if (image) {
28903 if (unlikely(proglen + ilen > oldproglen)) {
28904 pr_err("bpb_jit_compile fatal error\n");
28905- kfree(addrs);
28906- module_free(NULL, image);
28907- return;
28908+ module_free_exec(NULL, image);
28909+ goto error;
28910 }
28911+ pax_open_kernel();
28912 memcpy(image + proglen, temp, ilen);
28913+ pax_close_kernel();
28914 }
28915 proglen += ilen;
28916 addrs[i] = proglen;
28917@@ -679,11 +797,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
28918 break;
28919 }
28920 if (proglen == oldproglen) {
28921- image = module_alloc(max_t(unsigned int,
28922- proglen,
28923- sizeof(struct work_struct)));
28924+ image = module_alloc_exec(proglen);
28925 if (!image)
28926- goto out;
28927+ goto error;
28928 }
28929 oldproglen = proglen;
28930 }
28931@@ -699,7 +815,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
28932 bpf_flush_icache(image, image + proglen);
28933
28934 fp->bpf_func = (void *)image;
28935- }
28936+ } else
28937+error:
28938+ kfree(fp->work);
28939+
28940 out:
28941 kfree(addrs);
28942 return;
28943@@ -707,18 +826,20 @@ out:
28944
28945 static void jit_free_defer(struct work_struct *arg)
28946 {
28947- module_free(NULL, arg);
28948+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
28949+ kfree(arg);
28950 }
28951
28952 /* run from softirq, we must use a work_struct to call
28953- * module_free() from process context
28954+ * module_free_exec() from process context
28955 */
28956 void bpf_jit_free(struct sk_filter *fp)
28957 {
28958 if (fp->bpf_func != sk_run_filter) {
28959- struct work_struct *work = (struct work_struct *)fp->bpf_func;
28960+ struct work_struct *work = &fp->work->work;
28961
28962 INIT_WORK(work, jit_free_defer);
28963+ fp->work->image = fp->bpf_func;
28964 schedule_work(work);
28965 }
28966 }
28967diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
28968index d6aa6e8..266395a 100644
28969--- a/arch/x86/oprofile/backtrace.c
28970+++ b/arch/x86/oprofile/backtrace.c
28971@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
28972 struct stack_frame_ia32 *fp;
28973 unsigned long bytes;
28974
28975- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
28976+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
28977 if (bytes != sizeof(bufhead))
28978 return NULL;
28979
28980- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
28981+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
28982
28983 oprofile_add_trace(bufhead[0].return_address);
28984
28985@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
28986 struct stack_frame bufhead[2];
28987 unsigned long bytes;
28988
28989- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
28990+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
28991 if (bytes != sizeof(bufhead))
28992 return NULL;
28993
28994@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
28995 {
28996 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
28997
28998- if (!user_mode_vm(regs)) {
28999+ if (!user_mode(regs)) {
29000 unsigned long stack = kernel_stack_pointer(regs);
29001 if (depth)
29002 dump_trace(NULL, regs, (unsigned long *)stack, 0,
29003diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
29004index e9e6ed5..e47ae67 100644
29005--- a/arch/x86/pci/amd_bus.c
29006+++ b/arch/x86/pci/amd_bus.c
29007@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
29008 return NOTIFY_OK;
29009 }
29010
29011-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
29012+static struct notifier_block amd_cpu_notifier = {
29013 .notifier_call = amd_cpu_notify,
29014 };
29015
29016diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
29017index 6eb18c4..20d83de 100644
29018--- a/arch/x86/pci/mrst.c
29019+++ b/arch/x86/pci/mrst.c
29020@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
29021 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
29022 pci_mmcfg_late_init();
29023 pcibios_enable_irq = mrst_pci_irq_enable;
29024- pci_root_ops = pci_mrst_ops;
29025+ pax_open_kernel();
29026+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
29027+ pax_close_kernel();
29028 pci_soc_mode = 1;
29029 /* Continue with standard init */
29030 return 1;
29031diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
29032index c77b24a..c979855 100644
29033--- a/arch/x86/pci/pcbios.c
29034+++ b/arch/x86/pci/pcbios.c
29035@@ -79,7 +79,7 @@ union bios32 {
29036 static struct {
29037 unsigned long address;
29038 unsigned short segment;
29039-} bios32_indirect = { 0, __KERNEL_CS };
29040+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
29041
29042 /*
29043 * Returns the entry point for the given service, NULL on error
29044@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
29045 unsigned long length; /* %ecx */
29046 unsigned long entry; /* %edx */
29047 unsigned long flags;
29048+ struct desc_struct d, *gdt;
29049
29050 local_irq_save(flags);
29051- __asm__("lcall *(%%edi); cld"
29052+
29053+ gdt = get_cpu_gdt_table(smp_processor_id());
29054+
29055+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
29056+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29057+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
29058+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29059+
29060+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
29061 : "=a" (return_code),
29062 "=b" (address),
29063 "=c" (length),
29064 "=d" (entry)
29065 : "0" (service),
29066 "1" (0),
29067- "D" (&bios32_indirect));
29068+ "D" (&bios32_indirect),
29069+ "r"(__PCIBIOS_DS)
29070+ : "memory");
29071+
29072+ pax_open_kernel();
29073+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
29074+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
29075+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
29076+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
29077+ pax_close_kernel();
29078+
29079 local_irq_restore(flags);
29080
29081 switch (return_code) {
29082- case 0:
29083- return address + entry;
29084- case 0x80: /* Not present */
29085- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29086- return 0;
29087- default: /* Shouldn't happen */
29088- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29089- service, return_code);
29090+ case 0: {
29091+ int cpu;
29092+ unsigned char flags;
29093+
29094+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
29095+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
29096+ printk(KERN_WARNING "bios32_service: not valid\n");
29097 return 0;
29098+ }
29099+ address = address + PAGE_OFFSET;
29100+ length += 16UL; /* some BIOSs underreport this... */
29101+ flags = 4;
29102+ if (length >= 64*1024*1024) {
29103+ length >>= PAGE_SHIFT;
29104+ flags |= 8;
29105+ }
29106+
29107+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
29108+ gdt = get_cpu_gdt_table(cpu);
29109+ pack_descriptor(&d, address, length, 0x9b, flags);
29110+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29111+ pack_descriptor(&d, address, length, 0x93, flags);
29112+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29113+ }
29114+ return entry;
29115+ }
29116+ case 0x80: /* Not present */
29117+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29118+ return 0;
29119+ default: /* Shouldn't happen */
29120+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29121+ service, return_code);
29122+ return 0;
29123 }
29124 }
29125
29126 static struct {
29127 unsigned long address;
29128 unsigned short segment;
29129-} pci_indirect = { 0, __KERNEL_CS };
29130+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
29131
29132-static int pci_bios_present;
29133+static int pci_bios_present __read_only;
29134
29135 static int check_pcibios(void)
29136 {
29137@@ -131,11 +174,13 @@ static int check_pcibios(void)
29138 unsigned long flags, pcibios_entry;
29139
29140 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
29141- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
29142+ pci_indirect.address = pcibios_entry;
29143
29144 local_irq_save(flags);
29145- __asm__(
29146- "lcall *(%%edi); cld\n\t"
29147+ __asm__("movw %w6, %%ds\n\t"
29148+ "lcall *%%ss:(%%edi); cld\n\t"
29149+ "push %%ss\n\t"
29150+ "pop %%ds\n\t"
29151 "jc 1f\n\t"
29152 "xor %%ah, %%ah\n"
29153 "1:"
29154@@ -144,7 +189,8 @@ static int check_pcibios(void)
29155 "=b" (ebx),
29156 "=c" (ecx)
29157 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
29158- "D" (&pci_indirect)
29159+ "D" (&pci_indirect),
29160+ "r" (__PCIBIOS_DS)
29161 : "memory");
29162 local_irq_restore(flags);
29163
29164@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29165
29166 switch (len) {
29167 case 1:
29168- __asm__("lcall *(%%esi); cld\n\t"
29169+ __asm__("movw %w6, %%ds\n\t"
29170+ "lcall *%%ss:(%%esi); cld\n\t"
29171+ "push %%ss\n\t"
29172+ "pop %%ds\n\t"
29173 "jc 1f\n\t"
29174 "xor %%ah, %%ah\n"
29175 "1:"
29176@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29177 : "1" (PCIBIOS_READ_CONFIG_BYTE),
29178 "b" (bx),
29179 "D" ((long)reg),
29180- "S" (&pci_indirect));
29181+ "S" (&pci_indirect),
29182+ "r" (__PCIBIOS_DS));
29183 /*
29184 * Zero-extend the result beyond 8 bits, do not trust the
29185 * BIOS having done it:
29186@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29187 *value &= 0xff;
29188 break;
29189 case 2:
29190- __asm__("lcall *(%%esi); cld\n\t"
29191+ __asm__("movw %w6, %%ds\n\t"
29192+ "lcall *%%ss:(%%esi); cld\n\t"
29193+ "push %%ss\n\t"
29194+ "pop %%ds\n\t"
29195 "jc 1f\n\t"
29196 "xor %%ah, %%ah\n"
29197 "1:"
29198@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29199 : "1" (PCIBIOS_READ_CONFIG_WORD),
29200 "b" (bx),
29201 "D" ((long)reg),
29202- "S" (&pci_indirect));
29203+ "S" (&pci_indirect),
29204+ "r" (__PCIBIOS_DS));
29205 /*
29206 * Zero-extend the result beyond 16 bits, do not trust the
29207 * BIOS having done it:
29208@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29209 *value &= 0xffff;
29210 break;
29211 case 4:
29212- __asm__("lcall *(%%esi); cld\n\t"
29213+ __asm__("movw %w6, %%ds\n\t"
29214+ "lcall *%%ss:(%%esi); cld\n\t"
29215+ "push %%ss\n\t"
29216+ "pop %%ds\n\t"
29217 "jc 1f\n\t"
29218 "xor %%ah, %%ah\n"
29219 "1:"
29220@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29221 : "1" (PCIBIOS_READ_CONFIG_DWORD),
29222 "b" (bx),
29223 "D" ((long)reg),
29224- "S" (&pci_indirect));
29225+ "S" (&pci_indirect),
29226+ "r" (__PCIBIOS_DS));
29227 break;
29228 }
29229
29230@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29231
29232 switch (len) {
29233 case 1:
29234- __asm__("lcall *(%%esi); cld\n\t"
29235+ __asm__("movw %w6, %%ds\n\t"
29236+ "lcall *%%ss:(%%esi); cld\n\t"
29237+ "push %%ss\n\t"
29238+ "pop %%ds\n\t"
29239 "jc 1f\n\t"
29240 "xor %%ah, %%ah\n"
29241 "1:"
29242@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29243 "c" (value),
29244 "b" (bx),
29245 "D" ((long)reg),
29246- "S" (&pci_indirect));
29247+ "S" (&pci_indirect),
29248+ "r" (__PCIBIOS_DS));
29249 break;
29250 case 2:
29251- __asm__("lcall *(%%esi); cld\n\t"
29252+ __asm__("movw %w6, %%ds\n\t"
29253+ "lcall *%%ss:(%%esi); cld\n\t"
29254+ "push %%ss\n\t"
29255+ "pop %%ds\n\t"
29256 "jc 1f\n\t"
29257 "xor %%ah, %%ah\n"
29258 "1:"
29259@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29260 "c" (value),
29261 "b" (bx),
29262 "D" ((long)reg),
29263- "S" (&pci_indirect));
29264+ "S" (&pci_indirect),
29265+ "r" (__PCIBIOS_DS));
29266 break;
29267 case 4:
29268- __asm__("lcall *(%%esi); cld\n\t"
29269+ __asm__("movw %w6, %%ds\n\t"
29270+ "lcall *%%ss:(%%esi); cld\n\t"
29271+ "push %%ss\n\t"
29272+ "pop %%ds\n\t"
29273 "jc 1f\n\t"
29274 "xor %%ah, %%ah\n"
29275 "1:"
29276@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29277 "c" (value),
29278 "b" (bx),
29279 "D" ((long)reg),
29280- "S" (&pci_indirect));
29281+ "S" (&pci_indirect),
29282+ "r" (__PCIBIOS_DS));
29283 break;
29284 }
29285
29286@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
29287
29288 DBG("PCI: Fetching IRQ routing table... ");
29289 __asm__("push %%es\n\t"
29290+ "movw %w8, %%ds\n\t"
29291 "push %%ds\n\t"
29292 "pop %%es\n\t"
29293- "lcall *(%%esi); cld\n\t"
29294+ "lcall *%%ss:(%%esi); cld\n\t"
29295 "pop %%es\n\t"
29296+ "push %%ss\n\t"
29297+ "pop %%ds\n"
29298 "jc 1f\n\t"
29299 "xor %%ah, %%ah\n"
29300 "1:"
29301@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
29302 "1" (0),
29303 "D" ((long) &opt),
29304 "S" (&pci_indirect),
29305- "m" (opt)
29306+ "m" (opt),
29307+ "r" (__PCIBIOS_DS)
29308 : "memory");
29309 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
29310 if (ret & 0xff00)
29311@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
29312 {
29313 int ret;
29314
29315- __asm__("lcall *(%%esi); cld\n\t"
29316+ __asm__("movw %w5, %%ds\n\t"
29317+ "lcall *%%ss:(%%esi); cld\n\t"
29318+ "push %%ss\n\t"
29319+ "pop %%ds\n"
29320 "jc 1f\n\t"
29321 "xor %%ah, %%ah\n"
29322 "1:"
29323@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
29324 : "0" (PCIBIOS_SET_PCI_HW_INT),
29325 "b" ((dev->bus->number << 8) | dev->devfn),
29326 "c" ((irq << 8) | (pin + 10)),
29327- "S" (&pci_indirect));
29328+ "S" (&pci_indirect),
29329+ "r" (__PCIBIOS_DS));
29330 return !(ret & 0xff00);
29331 }
29332 EXPORT_SYMBOL(pcibios_set_irq_routing);
29333diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
29334index 40e4469..1ab536e 100644
29335--- a/arch/x86/platform/efi/efi_32.c
29336+++ b/arch/x86/platform/efi/efi_32.c
29337@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
29338 {
29339 struct desc_ptr gdt_descr;
29340
29341+#ifdef CONFIG_PAX_KERNEXEC
29342+ struct desc_struct d;
29343+#endif
29344+
29345 local_irq_save(efi_rt_eflags);
29346
29347 load_cr3(initial_page_table);
29348 __flush_tlb_all();
29349
29350+#ifdef CONFIG_PAX_KERNEXEC
29351+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
29352+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
29353+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
29354+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
29355+#endif
29356+
29357 gdt_descr.address = __pa(get_cpu_gdt_table(0));
29358 gdt_descr.size = GDT_SIZE - 1;
29359 load_gdt(&gdt_descr);
29360@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
29361 {
29362 struct desc_ptr gdt_descr;
29363
29364+#ifdef CONFIG_PAX_KERNEXEC
29365+ struct desc_struct d;
29366+
29367+ memset(&d, 0, sizeof d);
29368+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
29369+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
29370+#endif
29371+
29372 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
29373 gdt_descr.size = GDT_SIZE - 1;
29374 load_gdt(&gdt_descr);
29375diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
29376index fbe66e6..eae5e38 100644
29377--- a/arch/x86/platform/efi/efi_stub_32.S
29378+++ b/arch/x86/platform/efi/efi_stub_32.S
29379@@ -6,7 +6,9 @@
29380 */
29381
29382 #include <linux/linkage.h>
29383+#include <linux/init.h>
29384 #include <asm/page_types.h>
29385+#include <asm/segment.h>
29386
29387 /*
29388 * efi_call_phys(void *, ...) is a function with variable parameters.
29389@@ -20,7 +22,7 @@
29390 * service functions will comply with gcc calling convention, too.
29391 */
29392
29393-.text
29394+__INIT
29395 ENTRY(efi_call_phys)
29396 /*
29397 * 0. The function can only be called in Linux kernel. So CS has been
29398@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
29399 * The mapping of lower virtual memory has been created in prelog and
29400 * epilog.
29401 */
29402- movl $1f, %edx
29403- subl $__PAGE_OFFSET, %edx
29404- jmp *%edx
29405+#ifdef CONFIG_PAX_KERNEXEC
29406+ movl $(__KERNEXEC_EFI_DS), %edx
29407+ mov %edx, %ds
29408+ mov %edx, %es
29409+ mov %edx, %ss
29410+ addl $2f,(1f)
29411+ ljmp *(1f)
29412+
29413+__INITDATA
29414+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
29415+.previous
29416+
29417+2:
29418+ subl $2b,(1b)
29419+#else
29420+ jmp 1f-__PAGE_OFFSET
29421 1:
29422+#endif
29423
29424 /*
29425 * 2. Now on the top of stack is the return
29426@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
29427 * parameter 2, ..., param n. To make things easy, we save the return
29428 * address of efi_call_phys in a global variable.
29429 */
29430- popl %edx
29431- movl %edx, saved_return_addr
29432- /* get the function pointer into ECX*/
29433- popl %ecx
29434- movl %ecx, efi_rt_function_ptr
29435- movl $2f, %edx
29436- subl $__PAGE_OFFSET, %edx
29437- pushl %edx
29438+ popl (saved_return_addr)
29439+ popl (efi_rt_function_ptr)
29440
29441 /*
29442 * 3. Clear PG bit in %CR0.
29443@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
29444 /*
29445 * 5. Call the physical function.
29446 */
29447- jmp *%ecx
29448+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
29449
29450-2:
29451 /*
29452 * 6. After EFI runtime service returns, control will return to
29453 * following instruction. We'd better readjust stack pointer first.
29454@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
29455 movl %cr0, %edx
29456 orl $0x80000000, %edx
29457 movl %edx, %cr0
29458- jmp 1f
29459-1:
29460+
29461 /*
29462 * 8. Now restore the virtual mode from flat mode by
29463 * adding EIP with PAGE_OFFSET.
29464 */
29465- movl $1f, %edx
29466- jmp *%edx
29467+#ifdef CONFIG_PAX_KERNEXEC
29468+ movl $(__KERNEL_DS), %edx
29469+ mov %edx, %ds
29470+ mov %edx, %es
29471+ mov %edx, %ss
29472+ ljmp $(__KERNEL_CS),$1f
29473+#else
29474+ jmp 1f+__PAGE_OFFSET
29475+#endif
29476 1:
29477
29478 /*
29479 * 9. Balance the stack. And because EAX contain the return value,
29480 * we'd better not clobber it.
29481 */
29482- leal efi_rt_function_ptr, %edx
29483- movl (%edx), %ecx
29484- pushl %ecx
29485+ pushl (efi_rt_function_ptr)
29486
29487 /*
29488- * 10. Push the saved return address onto the stack and return.
29489+ * 10. Return to the saved return address.
29490 */
29491- leal saved_return_addr, %edx
29492- movl (%edx), %ecx
29493- pushl %ecx
29494- ret
29495+ jmpl *(saved_return_addr)
29496 ENDPROC(efi_call_phys)
29497 .previous
29498
29499-.data
29500+__INITDATA
29501 saved_return_addr:
29502 .long 0
29503 efi_rt_function_ptr:
29504diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
29505index 4c07cca..2c8427d 100644
29506--- a/arch/x86/platform/efi/efi_stub_64.S
29507+++ b/arch/x86/platform/efi/efi_stub_64.S
29508@@ -7,6 +7,7 @@
29509 */
29510
29511 #include <linux/linkage.h>
29512+#include <asm/alternative-asm.h>
29513
29514 #define SAVE_XMM \
29515 mov %rsp, %rax; \
29516@@ -40,6 +41,7 @@ ENTRY(efi_call0)
29517 call *%rdi
29518 addq $32, %rsp
29519 RESTORE_XMM
29520+ pax_force_retaddr 0, 1
29521 ret
29522 ENDPROC(efi_call0)
29523
29524@@ -50,6 +52,7 @@ ENTRY(efi_call1)
29525 call *%rdi
29526 addq $32, %rsp
29527 RESTORE_XMM
29528+ pax_force_retaddr 0, 1
29529 ret
29530 ENDPROC(efi_call1)
29531
29532@@ -60,6 +63,7 @@ ENTRY(efi_call2)
29533 call *%rdi
29534 addq $32, %rsp
29535 RESTORE_XMM
29536+ pax_force_retaddr 0, 1
29537 ret
29538 ENDPROC(efi_call2)
29539
29540@@ -71,6 +75,7 @@ ENTRY(efi_call3)
29541 call *%rdi
29542 addq $32, %rsp
29543 RESTORE_XMM
29544+ pax_force_retaddr 0, 1
29545 ret
29546 ENDPROC(efi_call3)
29547
29548@@ -83,6 +88,7 @@ ENTRY(efi_call4)
29549 call *%rdi
29550 addq $32, %rsp
29551 RESTORE_XMM
29552+ pax_force_retaddr 0, 1
29553 ret
29554 ENDPROC(efi_call4)
29555
29556@@ -96,6 +102,7 @@ ENTRY(efi_call5)
29557 call *%rdi
29558 addq $48, %rsp
29559 RESTORE_XMM
29560+ pax_force_retaddr 0, 1
29561 ret
29562 ENDPROC(efi_call5)
29563
29564@@ -112,5 +119,6 @@ ENTRY(efi_call6)
29565 call *%rdi
29566 addq $48, %rsp
29567 RESTORE_XMM
29568+ pax_force_retaddr 0, 1
29569 ret
29570 ENDPROC(efi_call6)
29571diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
29572index e31bcd8..f12dc46 100644
29573--- a/arch/x86/platform/mrst/mrst.c
29574+++ b/arch/x86/platform/mrst/mrst.c
29575@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
29576 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
29577 int sfi_mrtc_num;
29578
29579-static void mrst_power_off(void)
29580+static __noreturn void mrst_power_off(void)
29581 {
29582+ BUG();
29583 }
29584
29585-static void mrst_reboot(void)
29586+static __noreturn void mrst_reboot(void)
29587 {
29588 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
29589+ BUG();
29590 }
29591
29592 /* parse all the mtimer info to a static mtimer array */
29593diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
29594index d6ee929..3637cb5 100644
29595--- a/arch/x86/platform/olpc/olpc_dt.c
29596+++ b/arch/x86/platform/olpc/olpc_dt.c
29597@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
29598 return res;
29599 }
29600
29601-static struct of_pdt_ops prom_olpc_ops __initdata = {
29602+static struct of_pdt_ops prom_olpc_ops __initconst = {
29603 .nextprop = olpc_dt_nextprop,
29604 .getproplen = olpc_dt_getproplen,
29605 .getproperty = olpc_dt_getproperty,
29606diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
29607index 120cee1..b2db75a 100644
29608--- a/arch/x86/power/cpu.c
29609+++ b/arch/x86/power/cpu.c
29610@@ -133,7 +133,7 @@ static void do_fpu_end(void)
29611 static void fix_processor_context(void)
29612 {
29613 int cpu = smp_processor_id();
29614- struct tss_struct *t = &per_cpu(init_tss, cpu);
29615+ struct tss_struct *t = init_tss + cpu;
29616
29617 set_tss_desc(cpu, t); /*
29618 * This just modifies memory; should not be
29619@@ -143,8 +143,6 @@ static void fix_processor_context(void)
29620 */
29621
29622 #ifdef CONFIG_X86_64
29623- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
29624-
29625 syscall_init(); /* This sets MSR_*STAR and related */
29626 #endif
29627 load_TR_desc(); /* This does ltr */
29628diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
29629index cbca565..bae7133 100644
29630--- a/arch/x86/realmode/init.c
29631+++ b/arch/x86/realmode/init.c
29632@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
29633 __va(real_mode_header->trampoline_header);
29634
29635 #ifdef CONFIG_X86_32
29636- trampoline_header->start = __pa(startup_32_smp);
29637+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
29638+
29639+#ifdef CONFIG_PAX_KERNEXEC
29640+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
29641+#endif
29642+
29643+ trampoline_header->boot_cs = __BOOT_CS;
29644 trampoline_header->gdt_limit = __BOOT_DS + 7;
29645 trampoline_header->gdt_base = __pa(boot_gdt);
29646 #else
29647diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
29648index 8869287..d577672 100644
29649--- a/arch/x86/realmode/rm/Makefile
29650+++ b/arch/x86/realmode/rm/Makefile
29651@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
29652 $(call cc-option, -fno-unit-at-a-time)) \
29653 $(call cc-option, -fno-stack-protector) \
29654 $(call cc-option, -mpreferred-stack-boundary=2)
29655+ifdef CONSTIFY_PLUGIN
29656+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
29657+endif
29658 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
29659 GCOV_PROFILE := n
29660diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
29661index a28221d..93c40f1 100644
29662--- a/arch/x86/realmode/rm/header.S
29663+++ b/arch/x86/realmode/rm/header.S
29664@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
29665 #endif
29666 /* APM/BIOS reboot */
29667 .long pa_machine_real_restart_asm
29668-#ifdef CONFIG_X86_64
29669+#ifdef CONFIG_X86_32
29670+ .long __KERNEL_CS
29671+#else
29672 .long __KERNEL32_CS
29673 #endif
29674 END(real_mode_header)
29675diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
29676index c1b2791..f9e31c7 100644
29677--- a/arch/x86/realmode/rm/trampoline_32.S
29678+++ b/arch/x86/realmode/rm/trampoline_32.S
29679@@ -25,6 +25,12 @@
29680 #include <asm/page_types.h>
29681 #include "realmode.h"
29682
29683+#ifdef CONFIG_PAX_KERNEXEC
29684+#define ta(X) (X)
29685+#else
29686+#define ta(X) (pa_ ## X)
29687+#endif
29688+
29689 .text
29690 .code16
29691
29692@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
29693
29694 cli # We should be safe anyway
29695
29696- movl tr_start, %eax # where we need to go
29697-
29698 movl $0xA5A5A5A5, trampoline_status
29699 # write marker for master knows we're running
29700
29701@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
29702 movw $1, %dx # protected mode (PE) bit
29703 lmsw %dx # into protected mode
29704
29705- ljmpl $__BOOT_CS, $pa_startup_32
29706+ ljmpl *(trampoline_header)
29707
29708 .section ".text32","ax"
29709 .code32
29710@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
29711 .balign 8
29712 GLOBAL(trampoline_header)
29713 tr_start: .space 4
29714- tr_gdt_pad: .space 2
29715+ tr_boot_cs: .space 2
29716 tr_gdt: .space 6
29717 END(trampoline_header)
29718
29719diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
29720index bb360dc..3e5945f 100644
29721--- a/arch/x86/realmode/rm/trampoline_64.S
29722+++ b/arch/x86/realmode/rm/trampoline_64.S
29723@@ -107,7 +107,7 @@ ENTRY(startup_32)
29724 wrmsr
29725
29726 # Enable paging and in turn activate Long Mode
29727- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
29728+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
29729 movl %eax, %cr0
29730
29731 /*
29732diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
29733index 79d67bd..c7e1b90 100644
29734--- a/arch/x86/tools/relocs.c
29735+++ b/arch/x86/tools/relocs.c
29736@@ -12,10 +12,13 @@
29737 #include <regex.h>
29738 #include <tools/le_byteshift.h>
29739
29740+#include "../../../include/generated/autoconf.h"
29741+
29742 static void die(char *fmt, ...);
29743
29744 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
29745 static Elf32_Ehdr ehdr;
29746+static Elf32_Phdr *phdr;
29747 static unsigned long reloc_count, reloc_idx;
29748 static unsigned long *relocs;
29749 static unsigned long reloc16_count, reloc16_idx;
29750@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
29751 }
29752 }
29753
29754+static void read_phdrs(FILE *fp)
29755+{
29756+ unsigned int i;
29757+
29758+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
29759+ if (!phdr) {
29760+ die("Unable to allocate %d program headers\n",
29761+ ehdr.e_phnum);
29762+ }
29763+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
29764+ die("Seek to %d failed: %s\n",
29765+ ehdr.e_phoff, strerror(errno));
29766+ }
29767+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
29768+ die("Cannot read ELF program headers: %s\n",
29769+ strerror(errno));
29770+ }
29771+ for(i = 0; i < ehdr.e_phnum; i++) {
29772+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
29773+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
29774+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
29775+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
29776+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
29777+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
29778+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
29779+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
29780+ }
29781+
29782+}
29783+
29784 static void read_shdrs(FILE *fp)
29785 {
29786- int i;
29787+ unsigned int i;
29788 Elf32_Shdr shdr;
29789
29790 secs = calloc(ehdr.e_shnum, sizeof(struct section));
29791@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
29792
29793 static void read_strtabs(FILE *fp)
29794 {
29795- int i;
29796+ unsigned int i;
29797 for (i = 0; i < ehdr.e_shnum; i++) {
29798 struct section *sec = &secs[i];
29799 if (sec->shdr.sh_type != SHT_STRTAB) {
29800@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
29801
29802 static void read_symtabs(FILE *fp)
29803 {
29804- int i,j;
29805+ unsigned int i,j;
29806 for (i = 0; i < ehdr.e_shnum; i++) {
29807 struct section *sec = &secs[i];
29808 if (sec->shdr.sh_type != SHT_SYMTAB) {
29809@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
29810 }
29811
29812
29813-static void read_relocs(FILE *fp)
29814+static void read_relocs(FILE *fp, int use_real_mode)
29815 {
29816- int i,j;
29817+ unsigned int i,j;
29818+ uint32_t base;
29819+
29820 for (i = 0; i < ehdr.e_shnum; i++) {
29821 struct section *sec = &secs[i];
29822 if (sec->shdr.sh_type != SHT_REL) {
29823@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
29824 die("Cannot read symbol table: %s\n",
29825 strerror(errno));
29826 }
29827+ base = 0;
29828+
29829+#ifdef CONFIG_X86_32
29830+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
29831+ if (phdr[j].p_type != PT_LOAD )
29832+ continue;
29833+ 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)
29834+ continue;
29835+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
29836+ break;
29837+ }
29838+#endif
29839+
29840 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
29841 Elf32_Rel *rel = &sec->reltab[j];
29842- rel->r_offset = elf32_to_cpu(rel->r_offset);
29843+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
29844 rel->r_info = elf32_to_cpu(rel->r_info);
29845 }
29846 }
29847@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
29848
29849 static void print_absolute_symbols(void)
29850 {
29851- int i;
29852+ unsigned int i;
29853 printf("Absolute symbols\n");
29854 printf(" Num: Value Size Type Bind Visibility Name\n");
29855 for (i = 0; i < ehdr.e_shnum; i++) {
29856 struct section *sec = &secs[i];
29857 char *sym_strtab;
29858- int j;
29859+ unsigned int j;
29860
29861 if (sec->shdr.sh_type != SHT_SYMTAB) {
29862 continue;
29863@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
29864
29865 static void print_absolute_relocs(void)
29866 {
29867- int i, printed = 0;
29868+ unsigned int i, printed = 0;
29869
29870 for (i = 0; i < ehdr.e_shnum; i++) {
29871 struct section *sec = &secs[i];
29872 struct section *sec_applies, *sec_symtab;
29873 char *sym_strtab;
29874 Elf32_Sym *sh_symtab;
29875- int j;
29876+ unsigned int j;
29877 if (sec->shdr.sh_type != SHT_REL) {
29878 continue;
29879 }
29880@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
29881 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
29882 int use_real_mode)
29883 {
29884- int i;
29885+ unsigned int i;
29886 /* Walk through the relocations */
29887 for (i = 0; i < ehdr.e_shnum; i++) {
29888 char *sym_strtab;
29889 Elf32_Sym *sh_symtab;
29890 struct section *sec_applies, *sec_symtab;
29891- int j;
29892+ unsigned int j;
29893 struct section *sec = &secs[i];
29894
29895 if (sec->shdr.sh_type != SHT_REL) {
29896@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
29897 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
29898 r_type = ELF32_R_TYPE(rel->r_info);
29899
29900+ if (!use_real_mode) {
29901+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
29902+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
29903+ continue;
29904+
29905+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
29906+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
29907+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
29908+ continue;
29909+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
29910+ continue;
29911+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
29912+ continue;
29913+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
29914+ continue;
29915+#endif
29916+ }
29917+
29918 shn_abs = sym->st_shndx == SHN_ABS;
29919
29920 switch (r_type) {
29921@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
29922
29923 static void emit_relocs(int as_text, int use_real_mode)
29924 {
29925- int i;
29926+ unsigned int i;
29927 /* Count how many relocations I have and allocate space for them. */
29928 reloc_count = 0;
29929 walk_relocs(count_reloc, use_real_mode);
29930@@ -808,10 +874,11 @@ int main(int argc, char **argv)
29931 fname, strerror(errno));
29932 }
29933 read_ehdr(fp);
29934+ read_phdrs(fp);
29935 read_shdrs(fp);
29936 read_strtabs(fp);
29937 read_symtabs(fp);
29938- read_relocs(fp);
29939+ read_relocs(fp, use_real_mode);
29940 if (show_absolute_syms) {
29941 print_absolute_symbols();
29942 goto out;
29943diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
29944index fd14be1..e3c79c0 100644
29945--- a/arch/x86/vdso/Makefile
29946+++ b/arch/x86/vdso/Makefile
29947@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
29948 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
29949 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
29950
29951-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
29952+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
29953 GCOV_PROFILE := n
29954
29955 #
29956diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
29957index 0faad64..39ef157 100644
29958--- a/arch/x86/vdso/vdso32-setup.c
29959+++ b/arch/x86/vdso/vdso32-setup.c
29960@@ -25,6 +25,7 @@
29961 #include <asm/tlbflush.h>
29962 #include <asm/vdso.h>
29963 #include <asm/proto.h>
29964+#include <asm/mman.h>
29965
29966 enum {
29967 VDSO_DISABLED = 0,
29968@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
29969 void enable_sep_cpu(void)
29970 {
29971 int cpu = get_cpu();
29972- struct tss_struct *tss = &per_cpu(init_tss, cpu);
29973+ struct tss_struct *tss = init_tss + cpu;
29974
29975 if (!boot_cpu_has(X86_FEATURE_SEP)) {
29976 put_cpu();
29977@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
29978 gate_vma.vm_start = FIXADDR_USER_START;
29979 gate_vma.vm_end = FIXADDR_USER_END;
29980 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
29981- gate_vma.vm_page_prot = __P101;
29982+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
29983
29984 return 0;
29985 }
29986@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29987 if (compat)
29988 addr = VDSO_HIGH_BASE;
29989 else {
29990- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
29991+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
29992 if (IS_ERR_VALUE(addr)) {
29993 ret = addr;
29994 goto up_fail;
29995 }
29996 }
29997
29998- current->mm->context.vdso = (void *)addr;
29999+ current->mm->context.vdso = addr;
30000
30001 if (compat_uses_vma || !compat) {
30002 /*
30003@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30004 }
30005
30006 current_thread_info()->sysenter_return =
30007- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30008+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30009
30010 up_fail:
30011 if (ret)
30012- current->mm->context.vdso = NULL;
30013+ current->mm->context.vdso = 0;
30014
30015 up_write(&mm->mmap_sem);
30016
30017@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
30018
30019 const char *arch_vma_name(struct vm_area_struct *vma)
30020 {
30021- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
30022+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
30023 return "[vdso]";
30024+
30025+#ifdef CONFIG_PAX_SEGMEXEC
30026+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
30027+ return "[vdso]";
30028+#endif
30029+
30030 return NULL;
30031 }
30032
30033@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
30034 * Check to see if the corresponding task was created in compat vdso
30035 * mode.
30036 */
30037- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
30038+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
30039 return &gate_vma;
30040 return NULL;
30041 }
30042diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
30043index 431e875..cbb23f3 100644
30044--- a/arch/x86/vdso/vma.c
30045+++ b/arch/x86/vdso/vma.c
30046@@ -16,8 +16,6 @@
30047 #include <asm/vdso.h>
30048 #include <asm/page.h>
30049
30050-unsigned int __read_mostly vdso_enabled = 1;
30051-
30052 extern char vdso_start[], vdso_end[];
30053 extern unsigned short vdso_sync_cpuid;
30054
30055@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
30056 * unaligned here as a result of stack start randomization.
30057 */
30058 addr = PAGE_ALIGN(addr);
30059- addr = align_vdso_addr(addr);
30060
30061 return addr;
30062 }
30063@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
30064 unsigned size)
30065 {
30066 struct mm_struct *mm = current->mm;
30067- unsigned long addr;
30068+ unsigned long addr = 0;
30069 int ret;
30070
30071- if (!vdso_enabled)
30072- return 0;
30073-
30074 down_write(&mm->mmap_sem);
30075+
30076+#ifdef CONFIG_PAX_RANDMMAP
30077+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30078+#endif
30079+
30080 addr = vdso_addr(mm->start_stack, size);
30081+ addr = align_vdso_addr(addr);
30082 addr = get_unmapped_area(NULL, addr, size, 0, 0);
30083 if (IS_ERR_VALUE(addr)) {
30084 ret = addr;
30085 goto up_fail;
30086 }
30087
30088- current->mm->context.vdso = (void *)addr;
30089+ mm->context.vdso = addr;
30090
30091 ret = install_special_mapping(mm, addr, size,
30092 VM_READ|VM_EXEC|
30093 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
30094 pages);
30095- if (ret) {
30096- current->mm->context.vdso = NULL;
30097- goto up_fail;
30098- }
30099+ if (ret)
30100+ mm->context.vdso = 0;
30101
30102 up_fail:
30103 up_write(&mm->mmap_sem);
30104@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30105 vdsox32_size);
30106 }
30107 #endif
30108-
30109-static __init int vdso_setup(char *s)
30110-{
30111- vdso_enabled = simple_strtoul(s, NULL, 0);
30112- return 0;
30113-}
30114-__setup("vdso=", vdso_setup);
30115diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
30116index e014092..c76ab69 100644
30117--- a/arch/x86/xen/enlighten.c
30118+++ b/arch/x86/xen/enlighten.c
30119@@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
30120
30121 struct shared_info xen_dummy_shared_info;
30122
30123-void *xen_initial_gdt;
30124-
30125 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
30126 __read_mostly int xen_have_vector_callback;
30127 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
30128@@ -495,8 +493,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
30129 {
30130 unsigned long va = dtr->address;
30131 unsigned int size = dtr->size + 1;
30132- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30133- unsigned long frames[pages];
30134+ unsigned long frames[65536 / PAGE_SIZE];
30135 int f;
30136
30137 /*
30138@@ -544,8 +541,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
30139 {
30140 unsigned long va = dtr->address;
30141 unsigned int size = dtr->size + 1;
30142- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30143- unsigned long frames[pages];
30144+ unsigned long frames[65536 / PAGE_SIZE];
30145 int f;
30146
30147 /*
30148@@ -938,7 +934,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
30149 return 0;
30150 }
30151
30152-static void set_xen_basic_apic_ops(void)
30153+static void __init set_xen_basic_apic_ops(void)
30154 {
30155 apic->read = xen_apic_read;
30156 apic->write = xen_apic_write;
30157@@ -1244,30 +1240,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
30158 #endif
30159 };
30160
30161-static void xen_reboot(int reason)
30162+static __noreturn void xen_reboot(int reason)
30163 {
30164 struct sched_shutdown r = { .reason = reason };
30165
30166- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
30167- BUG();
30168+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
30169+ BUG();
30170 }
30171
30172-static void xen_restart(char *msg)
30173+static __noreturn void xen_restart(char *msg)
30174 {
30175 xen_reboot(SHUTDOWN_reboot);
30176 }
30177
30178-static void xen_emergency_restart(void)
30179+static __noreturn void xen_emergency_restart(void)
30180 {
30181 xen_reboot(SHUTDOWN_reboot);
30182 }
30183
30184-static void xen_machine_halt(void)
30185+static __noreturn void xen_machine_halt(void)
30186 {
30187 xen_reboot(SHUTDOWN_poweroff);
30188 }
30189
30190-static void xen_machine_power_off(void)
30191+static __noreturn void xen_machine_power_off(void)
30192 {
30193 if (pm_power_off)
30194 pm_power_off();
30195@@ -1369,7 +1365,17 @@ asmlinkage void __init xen_start_kernel(void)
30196 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
30197
30198 /* Work out if we support NX */
30199- x86_configure_nx();
30200+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
30201+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
30202+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
30203+ unsigned l, h;
30204+
30205+ __supported_pte_mask |= _PAGE_NX;
30206+ rdmsr(MSR_EFER, l, h);
30207+ l |= EFER_NX;
30208+ wrmsr(MSR_EFER, l, h);
30209+ }
30210+#endif
30211
30212 xen_setup_features();
30213
30214@@ -1398,14 +1404,7 @@ asmlinkage void __init xen_start_kernel(void)
30215 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
30216 }
30217
30218- machine_ops = xen_machine_ops;
30219-
30220- /*
30221- * The only reliable way to retain the initial address of the
30222- * percpu gdt_page is to remember it here, so we can go and
30223- * mark it RW later, when the initial percpu area is freed.
30224- */
30225- xen_initial_gdt = &per_cpu(gdt_page, 0);
30226+ memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
30227
30228 xen_smp_init();
30229
30230@@ -1590,7 +1589,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
30231 return NOTIFY_OK;
30232 }
30233
30234-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
30235+static struct notifier_block xen_hvm_cpu_notifier = {
30236 .notifier_call = xen_hvm_cpu_notify,
30237 };
30238
30239diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
30240index 01de35c..0bda07b 100644
30241--- a/arch/x86/xen/mmu.c
30242+++ b/arch/x86/xen/mmu.c
30243@@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
30244 /* L3_k[510] -> level2_kernel_pgt
30245 * L3_i[511] -> level2_fixmap_pgt */
30246 convert_pfn_mfn(level3_kernel_pgt);
30247+ convert_pfn_mfn(level3_vmalloc_start_pgt);
30248+ convert_pfn_mfn(level3_vmalloc_end_pgt);
30249+ convert_pfn_mfn(level3_vmemmap_pgt);
30250
30251 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
30252 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
30253@@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
30254 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
30255 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
30256 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
30257+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
30258+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
30259+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
30260 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
30261 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
30262+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
30263 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
30264 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
30265
30266@@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
30267 pv_mmu_ops.set_pud = xen_set_pud;
30268 #if PAGETABLE_LEVELS == 4
30269 pv_mmu_ops.set_pgd = xen_set_pgd;
30270+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
30271 #endif
30272
30273 /* This will work as long as patching hasn't happened yet
30274@@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
30275 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
30276 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
30277 .set_pgd = xen_set_pgd_hyper,
30278+ .set_pgd_batched = xen_set_pgd_hyper,
30279
30280 .alloc_pud = xen_alloc_pmd_init,
30281 .release_pud = xen_release_pmd_init,
30282diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
30283index 34bc4ce..c34aa24 100644
30284--- a/arch/x86/xen/smp.c
30285+++ b/arch/x86/xen/smp.c
30286@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
30287 {
30288 BUG_ON(smp_processor_id() != 0);
30289 native_smp_prepare_boot_cpu();
30290-
30291- /* We've switched to the "real" per-cpu gdt, so make sure the
30292- old memory can be recycled */
30293- make_lowmem_page_readwrite(xen_initial_gdt);
30294-
30295 xen_filter_cpu_maps();
30296 xen_setup_vcpu_info_placement();
30297 }
30298@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
30299 gdt = get_cpu_gdt_table(cpu);
30300
30301 ctxt->flags = VGCF_IN_KERNEL;
30302- ctxt->user_regs.ds = __USER_DS;
30303- ctxt->user_regs.es = __USER_DS;
30304+ ctxt->user_regs.ds = __KERNEL_DS;
30305+ ctxt->user_regs.es = __KERNEL_DS;
30306 ctxt->user_regs.ss = __KERNEL_DS;
30307 #ifdef CONFIG_X86_32
30308 ctxt->user_regs.fs = __KERNEL_PERCPU;
30309- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
30310+ savesegment(gs, ctxt->user_regs.gs);
30311 #else
30312 ctxt->gs_base_kernel = per_cpu_offset(cpu);
30313 #endif
30314@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
30315 int rc;
30316
30317 per_cpu(current_task, cpu) = idle;
30318+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
30319 #ifdef CONFIG_X86_32
30320 irq_ctx_init(cpu);
30321 #else
30322 clear_tsk_thread_flag(idle, TIF_FORK);
30323- per_cpu(kernel_stack, cpu) =
30324- (unsigned long)task_stack_page(idle) -
30325- KERNEL_STACK_OFFSET + THREAD_SIZE;
30326+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
30327 #endif
30328 xen_setup_runstate_info(cpu);
30329 xen_setup_timer(cpu);
30330@@ -630,7 +624,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
30331
30332 void __init xen_smp_init(void)
30333 {
30334- smp_ops = xen_smp_ops;
30335+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
30336 xen_fill_possible_map();
30337 xen_init_spinlocks();
30338 }
30339diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
30340index 33ca6e4..0ded929 100644
30341--- a/arch/x86/xen/xen-asm_32.S
30342+++ b/arch/x86/xen/xen-asm_32.S
30343@@ -84,14 +84,14 @@ ENTRY(xen_iret)
30344 ESP_OFFSET=4 # bytes pushed onto stack
30345
30346 /*
30347- * Store vcpu_info pointer for easy access. Do it this way to
30348- * avoid having to reload %fs
30349+ * Store vcpu_info pointer for easy access.
30350 */
30351 #ifdef CONFIG_SMP
30352- GET_THREAD_INFO(%eax)
30353- movl %ss:TI_cpu(%eax), %eax
30354- movl %ss:__per_cpu_offset(,%eax,4), %eax
30355- mov %ss:xen_vcpu(%eax), %eax
30356+ push %fs
30357+ mov $(__KERNEL_PERCPU), %eax
30358+ mov %eax, %fs
30359+ mov PER_CPU_VAR(xen_vcpu), %eax
30360+ pop %fs
30361 #else
30362 movl %ss:xen_vcpu, %eax
30363 #endif
30364diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
30365index 7faed58..ba4427c 100644
30366--- a/arch/x86/xen/xen-head.S
30367+++ b/arch/x86/xen/xen-head.S
30368@@ -19,6 +19,17 @@ ENTRY(startup_xen)
30369 #ifdef CONFIG_X86_32
30370 mov %esi,xen_start_info
30371 mov $init_thread_union+THREAD_SIZE,%esp
30372+#ifdef CONFIG_SMP
30373+ movl $cpu_gdt_table,%edi
30374+ movl $__per_cpu_load,%eax
30375+ movw %ax,__KERNEL_PERCPU + 2(%edi)
30376+ rorl $16,%eax
30377+ movb %al,__KERNEL_PERCPU + 4(%edi)
30378+ movb %ah,__KERNEL_PERCPU + 7(%edi)
30379+ movl $__per_cpu_end - 1,%eax
30380+ subl $__per_cpu_start,%eax
30381+ movw %ax,__KERNEL_PERCPU + 0(%edi)
30382+#endif
30383 #else
30384 mov %rsi,xen_start_info
30385 mov $init_thread_union+THREAD_SIZE,%rsp
30386diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
30387index a95b417..b6dbd0b 100644
30388--- a/arch/x86/xen/xen-ops.h
30389+++ b/arch/x86/xen/xen-ops.h
30390@@ -10,8 +10,6 @@
30391 extern const char xen_hypervisor_callback[];
30392 extern const char xen_failsafe_callback[];
30393
30394-extern void *xen_initial_gdt;
30395-
30396 struct trap_info;
30397 void xen_copy_trap_info(struct trap_info *traps);
30398
30399diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
30400index 525bd3d..ef888b1 100644
30401--- a/arch/xtensa/variants/dc232b/include/variant/core.h
30402+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
30403@@ -119,9 +119,9 @@
30404 ----------------------------------------------------------------------*/
30405
30406 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
30407-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
30408 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
30409 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
30410+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30411
30412 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
30413 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
30414diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
30415index 2f33760..835e50a 100644
30416--- a/arch/xtensa/variants/fsf/include/variant/core.h
30417+++ b/arch/xtensa/variants/fsf/include/variant/core.h
30418@@ -11,6 +11,7 @@
30419 #ifndef _XTENSA_CORE_H
30420 #define _XTENSA_CORE_H
30421
30422+#include <linux/const.h>
30423
30424 /****************************************************************************
30425 Parameters Useful for Any Code, USER or PRIVILEGED
30426@@ -112,9 +113,9 @@
30427 ----------------------------------------------------------------------*/
30428
30429 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
30430-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
30431 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
30432 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
30433+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30434
30435 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
30436 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
30437diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
30438index af00795..2bb8105 100644
30439--- a/arch/xtensa/variants/s6000/include/variant/core.h
30440+++ b/arch/xtensa/variants/s6000/include/variant/core.h
30441@@ -11,6 +11,7 @@
30442 #ifndef _XTENSA_CORE_CONFIGURATION_H
30443 #define _XTENSA_CORE_CONFIGURATION_H
30444
30445+#include <linux/const.h>
30446
30447 /****************************************************************************
30448 Parameters Useful for Any Code, USER or PRIVILEGED
30449@@ -118,9 +119,9 @@
30450 ----------------------------------------------------------------------*/
30451
30452 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
30453-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
30454 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
30455 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
30456+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30457
30458 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
30459 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
30460diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
30461index 58916af..eb9dbcf6 100644
30462--- a/block/blk-iopoll.c
30463+++ b/block/blk-iopoll.c
30464@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
30465 }
30466 EXPORT_SYMBOL(blk_iopoll_complete);
30467
30468-static void blk_iopoll_softirq(struct softirq_action *h)
30469+static void blk_iopoll_softirq(void)
30470 {
30471 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
30472 int rearm = 0, budget = blk_iopoll_budget;
30473@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
30474 return NOTIFY_OK;
30475 }
30476
30477-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
30478+static struct notifier_block blk_iopoll_cpu_notifier = {
30479 .notifier_call = blk_iopoll_cpu_notify,
30480 };
30481
30482diff --git a/block/blk-map.c b/block/blk-map.c
30483index 623e1cd..ca1e109 100644
30484--- a/block/blk-map.c
30485+++ b/block/blk-map.c
30486@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
30487 if (!len || !kbuf)
30488 return -EINVAL;
30489
30490- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
30491+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
30492 if (do_copy)
30493 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
30494 else
30495diff --git a/block/blk-softirq.c b/block/blk-softirq.c
30496index 467c8de..f3628c5 100644
30497--- a/block/blk-softirq.c
30498+++ b/block/blk-softirq.c
30499@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
30500 * Softirq action handler - move entries to local list and loop over them
30501 * while passing them to the queue registered handler.
30502 */
30503-static void blk_done_softirq(struct softirq_action *h)
30504+static void blk_done_softirq(void)
30505 {
30506 struct list_head *cpu_list, local_list;
30507
30508@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
30509 return NOTIFY_OK;
30510 }
30511
30512-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
30513+static struct notifier_block blk_cpu_notifier = {
30514 .notifier_call = blk_cpu_notify,
30515 };
30516
30517diff --git a/block/bsg.c b/block/bsg.c
30518index ff64ae3..593560c 100644
30519--- a/block/bsg.c
30520+++ b/block/bsg.c
30521@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
30522 struct sg_io_v4 *hdr, struct bsg_device *bd,
30523 fmode_t has_write_perm)
30524 {
30525+ unsigned char tmpcmd[sizeof(rq->__cmd)];
30526+ unsigned char *cmdptr;
30527+
30528 if (hdr->request_len > BLK_MAX_CDB) {
30529 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
30530 if (!rq->cmd)
30531 return -ENOMEM;
30532- }
30533+ cmdptr = rq->cmd;
30534+ } else
30535+ cmdptr = tmpcmd;
30536
30537- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
30538+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
30539 hdr->request_len))
30540 return -EFAULT;
30541
30542+ if (cmdptr != rq->cmd)
30543+ memcpy(rq->cmd, cmdptr, hdr->request_len);
30544+
30545 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
30546 if (blk_verify_command(rq->cmd, has_write_perm))
30547 return -EPERM;
30548diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
30549index 7c668c8..db3521c 100644
30550--- a/block/compat_ioctl.c
30551+++ b/block/compat_ioctl.c
30552@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
30553 err |= __get_user(f->spec1, &uf->spec1);
30554 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
30555 err |= __get_user(name, &uf->name);
30556- f->name = compat_ptr(name);
30557+ f->name = (void __force_kernel *)compat_ptr(name);
30558 if (err) {
30559 err = -EFAULT;
30560 goto out;
30561diff --git a/block/partitions/efi.c b/block/partitions/efi.c
30562index b62fb88..bdab4c4 100644
30563--- a/block/partitions/efi.c
30564+++ b/block/partitions/efi.c
30565@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
30566 if (!gpt)
30567 return NULL;
30568
30569+ if (!le32_to_cpu(gpt->num_partition_entries))
30570+ return NULL;
30571+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
30572+ if (!pte)
30573+ return NULL;
30574+
30575 count = le32_to_cpu(gpt->num_partition_entries) *
30576 le32_to_cpu(gpt->sizeof_partition_entry);
30577- if (!count)
30578- return NULL;
30579- pte = kzalloc(count, GFP_KERNEL);
30580- if (!pte)
30581- return NULL;
30582-
30583 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
30584 (u8 *) pte,
30585 count) < count) {
30586diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
30587index 9a87daa..fb17486 100644
30588--- a/block/scsi_ioctl.c
30589+++ b/block/scsi_ioctl.c
30590@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
30591 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
30592 struct sg_io_hdr *hdr, fmode_t mode)
30593 {
30594- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
30595+ unsigned char tmpcmd[sizeof(rq->__cmd)];
30596+ unsigned char *cmdptr;
30597+
30598+ if (rq->cmd != rq->__cmd)
30599+ cmdptr = rq->cmd;
30600+ else
30601+ cmdptr = tmpcmd;
30602+
30603+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
30604 return -EFAULT;
30605+
30606+ if (cmdptr != rq->cmd)
30607+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
30608+
30609 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
30610 return -EPERM;
30611
30612@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
30613 int err;
30614 unsigned int in_len, out_len, bytes, opcode, cmdlen;
30615 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
30616+ unsigned char tmpcmd[sizeof(rq->__cmd)];
30617+ unsigned char *cmdptr;
30618
30619 if (!sic)
30620 return -EINVAL;
30621@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
30622 */
30623 err = -EFAULT;
30624 rq->cmd_len = cmdlen;
30625- if (copy_from_user(rq->cmd, sic->data, cmdlen))
30626+
30627+ if (rq->cmd != rq->__cmd)
30628+ cmdptr = rq->cmd;
30629+ else
30630+ cmdptr = tmpcmd;
30631+
30632+ if (copy_from_user(cmdptr, sic->data, cmdlen))
30633 goto error;
30634
30635+ if (rq->cmd != cmdptr)
30636+ memcpy(rq->cmd, cmdptr, cmdlen);
30637+
30638 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
30639 goto error;
30640
30641diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
30642index 533de95..7d4a8d2 100644
30643--- a/crypto/ablkcipher.c
30644+++ b/crypto/ablkcipher.c
30645@@ -388,9 +388,9 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
30646 {
30647 struct crypto_report_blkcipher rblkcipher;
30648
30649- snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "ablkcipher");
30650- snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30651- alg->cra_ablkcipher.geniv ?: "<default>");
30652+ strncpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type));
30653+ strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<default>",
30654+ sizeof(rblkcipher.geniv));
30655
30656 rblkcipher.blocksize = alg->cra_blocksize;
30657 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
30658@@ -469,9 +469,9 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
30659 {
30660 struct crypto_report_blkcipher rblkcipher;
30661
30662- snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "givcipher");
30663- snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30664- alg->cra_ablkcipher.geniv ?: "<built-in>");
30665+ strncpy(rblkcipher.type, "givcipher", sizeof(rblkcipher.type));
30666+ strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<built-in>",
30667+ sizeof(rblkcipher.geniv));
30668
30669 rblkcipher.blocksize = alg->cra_blocksize;
30670 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
30671diff --git a/crypto/aead.c b/crypto/aead.c
30672index 0b8121e..27bc487 100644
30673--- a/crypto/aead.c
30674+++ b/crypto/aead.c
30675@@ -117,9 +117,8 @@ static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg)
30676 struct crypto_report_aead raead;
30677 struct aead_alg *aead = &alg->cra_aead;
30678
30679- snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "aead");
30680- snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30681- aead->geniv ?: "<built-in>");
30682+ strncpy(raead.type, "aead", sizeof(raead.type));
30683+ strncpy(raead.geniv, aead->geniv ?: "<built-in>", sizeof(raead.geniv));
30684
30685 raead.blocksize = alg->cra_blocksize;
30686 raead.maxauthsize = aead->maxauthsize;
30687@@ -203,8 +202,8 @@ static int crypto_nivaead_report(struct sk_buff *skb, struct crypto_alg *alg)
30688 struct crypto_report_aead raead;
30689 struct aead_alg *aead = &alg->cra_aead;
30690
30691- snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "nivaead");
30692- snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s", aead->geniv);
30693+ strncpy(raead.type, "nivaead", sizeof(raead.type));
30694+ strncpy(raead.geniv, aead->geniv, sizeof(raead.geniv));
30695
30696 raead.blocksize = alg->cra_blocksize;
30697 raead.maxauthsize = aead->maxauthsize;
30698diff --git a/crypto/ahash.c b/crypto/ahash.c
30699index 3887856..793a27f 100644
30700--- a/crypto/ahash.c
30701+++ b/crypto/ahash.c
30702@@ -404,7 +404,7 @@ static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
30703 {
30704 struct crypto_report_hash rhash;
30705
30706- snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "ahash");
30707+ strncpy(rhash.type, "ahash", sizeof(rhash.type));
30708
30709 rhash.blocksize = alg->cra_blocksize;
30710 rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
30711diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
30712index a8d85a1..c44e014 100644
30713--- a/crypto/blkcipher.c
30714+++ b/crypto/blkcipher.c
30715@@ -499,9 +499,9 @@ static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
30716 {
30717 struct crypto_report_blkcipher rblkcipher;
30718
30719- snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "blkcipher");
30720- snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30721- alg->cra_blkcipher.geniv ?: "<default>");
30722+ strncpy(rblkcipher.type, "blkcipher", sizeof(rblkcipher.type));
30723+ strncpy(rblkcipher.geniv, alg->cra_blkcipher.geniv ?: "<default>",
30724+ sizeof(rblkcipher.geniv));
30725
30726 rblkcipher.blocksize = alg->cra_blocksize;
30727 rblkcipher.min_keysize = alg->cra_blkcipher.min_keysize;
30728diff --git a/crypto/cryptd.c b/crypto/cryptd.c
30729index 7bdd61b..afec999 100644
30730--- a/crypto/cryptd.c
30731+++ b/crypto/cryptd.c
30732@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
30733
30734 struct cryptd_blkcipher_request_ctx {
30735 crypto_completion_t complete;
30736-};
30737+} __no_const;
30738
30739 struct cryptd_hash_ctx {
30740 struct crypto_shash *child;
30741@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
30742
30743 struct cryptd_aead_request_ctx {
30744 crypto_completion_t complete;
30745-};
30746+} __no_const;
30747
30748 static void cryptd_queue_worker(struct work_struct *work);
30749
30750diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
30751index 35d700a..dfd511f 100644
30752--- a/crypto/crypto_user.c
30753+++ b/crypto/crypto_user.c
30754@@ -30,6 +30,8 @@
30755
30756 #include "internal.h"
30757
30758+#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
30759+
30760 static DEFINE_MUTEX(crypto_cfg_mutex);
30761
30762 /* The crypto netlink socket */
30763@@ -75,7 +77,7 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
30764 {
30765 struct crypto_report_cipher rcipher;
30766
30767- snprintf(rcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "cipher");
30768+ strncpy(rcipher.type, "cipher", sizeof(rcipher.type));
30769
30770 rcipher.blocksize = alg->cra_blocksize;
30771 rcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
30772@@ -94,8 +96,7 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
30773 {
30774 struct crypto_report_comp rcomp;
30775
30776- snprintf(rcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "compression");
30777-
30778+ strncpy(rcomp.type, "compression", sizeof(rcomp.type));
30779 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
30780 sizeof(struct crypto_report_comp), &rcomp))
30781 goto nla_put_failure;
30782@@ -108,12 +109,14 @@ nla_put_failure:
30783 static int crypto_report_one(struct crypto_alg *alg,
30784 struct crypto_user_alg *ualg, struct sk_buff *skb)
30785 {
30786- memcpy(&ualg->cru_name, &alg->cra_name, sizeof(ualg->cru_name));
30787- memcpy(&ualg->cru_driver_name, &alg->cra_driver_name,
30788- sizeof(ualg->cru_driver_name));
30789- memcpy(&ualg->cru_module_name, module_name(alg->cra_module),
30790- CRYPTO_MAX_ALG_NAME);
30791+ strncpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name));
30792+ strncpy(ualg->cru_driver_name, alg->cra_driver_name,
30793+ sizeof(ualg->cru_driver_name));
30794+ strncpy(ualg->cru_module_name, module_name(alg->cra_module),
30795+ sizeof(ualg->cru_module_name));
30796
30797+ ualg->cru_type = 0;
30798+ ualg->cru_mask = 0;
30799 ualg->cru_flags = alg->cra_flags;
30800 ualg->cru_refcnt = atomic_read(&alg->cra_refcnt);
30801
30802@@ -122,8 +125,7 @@ static int crypto_report_one(struct crypto_alg *alg,
30803 if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
30804 struct crypto_report_larval rl;
30805
30806- snprintf(rl.type, CRYPTO_MAX_ALG_NAME, "%s", "larval");
30807-
30808+ strncpy(rl.type, "larval", sizeof(rl.type));
30809 if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL,
30810 sizeof(struct crypto_report_larval), &rl))
30811 goto nla_put_failure;
30812@@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
30813 struct crypto_dump_info info;
30814 int err;
30815
30816- if (!p->cru_driver_name)
30817+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30818+ return -EINVAL;
30819+
30820+ if (!p->cru_driver_name[0])
30821 return -EINVAL;
30822
30823 alg = crypto_alg_match(p, 1);
30824@@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
30825 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
30826 LIST_HEAD(list);
30827
30828+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30829+ return -EINVAL;
30830+
30831 if (priority && !strlen(p->cru_driver_name))
30832 return -EINVAL;
30833
30834@@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
30835 struct crypto_alg *alg;
30836 struct crypto_user_alg *p = nlmsg_data(nlh);
30837
30838+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30839+ return -EINVAL;
30840+
30841 alg = crypto_alg_match(p, 1);
30842 if (!alg)
30843 return -ENOENT;
30844@@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
30845 struct crypto_user_alg *p = nlmsg_data(nlh);
30846 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
30847
30848+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30849+ return -EINVAL;
30850+
30851 if (strlen(p->cru_driver_name))
30852 exact = 1;
30853
30854diff --git a/crypto/pcompress.c b/crypto/pcompress.c
30855index 04e083f..7140fe7 100644
30856--- a/crypto/pcompress.c
30857+++ b/crypto/pcompress.c
30858@@ -53,8 +53,7 @@ static int crypto_pcomp_report(struct sk_buff *skb, struct crypto_alg *alg)
30859 {
30860 struct crypto_report_comp rpcomp;
30861
30862- snprintf(rpcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "pcomp");
30863-
30864+ strncpy(rpcomp.type, "pcomp", sizeof(rpcomp.type));
30865 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
30866 sizeof(struct crypto_report_comp), &rpcomp))
30867 goto nla_put_failure;
30868diff --git a/crypto/rng.c b/crypto/rng.c
30869index f3b7894..e0a25c2 100644
30870--- a/crypto/rng.c
30871+++ b/crypto/rng.c
30872@@ -65,7 +65,7 @@ static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)
30873 {
30874 struct crypto_report_rng rrng;
30875
30876- snprintf(rrng.type, CRYPTO_MAX_ALG_NAME, "%s", "rng");
30877+ strncpy(rrng.type, "rng", sizeof(rrng.type));
30878
30879 rrng.seedsize = alg->cra_rng.seedsize;
30880
30881diff --git a/crypto/shash.c b/crypto/shash.c
30882index f426330f..929058a 100644
30883--- a/crypto/shash.c
30884+++ b/crypto/shash.c
30885@@ -530,7 +530,8 @@ static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)
30886 struct crypto_report_hash rhash;
30887 struct shash_alg *salg = __crypto_shash_alg(alg);
30888
30889- snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "shash");
30890+ strncpy(rhash.type, "shash", sizeof(rhash.type));
30891+
30892 rhash.blocksize = alg->cra_blocksize;
30893 rhash.digestsize = salg->digestsize;
30894
30895diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
30896index e6defd8..c26a225 100644
30897--- a/drivers/acpi/apei/cper.c
30898+++ b/drivers/acpi/apei/cper.c
30899@@ -38,12 +38,12 @@
30900 */
30901 u64 cper_next_record_id(void)
30902 {
30903- static atomic64_t seq;
30904+ static atomic64_unchecked_t seq;
30905
30906- if (!atomic64_read(&seq))
30907- atomic64_set(&seq, ((u64)get_seconds()) << 32);
30908+ if (!atomic64_read_unchecked(&seq))
30909+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
30910
30911- return atomic64_inc_return(&seq);
30912+ return atomic64_inc_return_unchecked(&seq);
30913 }
30914 EXPORT_SYMBOL_GPL(cper_next_record_id);
30915
30916diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
30917index 7586544..636a2f0 100644
30918--- a/drivers/acpi/ec_sys.c
30919+++ b/drivers/acpi/ec_sys.c
30920@@ -12,6 +12,7 @@
30921 #include <linux/acpi.h>
30922 #include <linux/debugfs.h>
30923 #include <linux/module.h>
30924+#include <linux/uaccess.h>
30925 #include "internal.h"
30926
30927 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
30928@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
30929 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
30930 */
30931 unsigned int size = EC_SPACE_SIZE;
30932- u8 *data = (u8 *) buf;
30933+ u8 data;
30934 loff_t init_off = *off;
30935 int err = 0;
30936
30937@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
30938 size = count;
30939
30940 while (size) {
30941- err = ec_read(*off, &data[*off - init_off]);
30942+ err = ec_read(*off, &data);
30943 if (err)
30944 return err;
30945+ if (put_user(data, &buf[*off - init_off]))
30946+ return -EFAULT;
30947 *off += 1;
30948 size--;
30949 }
30950@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
30951
30952 unsigned int size = count;
30953 loff_t init_off = *off;
30954- u8 *data = (u8 *) buf;
30955 int err = 0;
30956
30957 if (*off >= EC_SPACE_SIZE)
30958@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
30959 }
30960
30961 while (size) {
30962- u8 byte_write = data[*off - init_off];
30963+ u8 byte_write;
30964+ if (get_user(byte_write, &buf[*off - init_off]))
30965+ return -EFAULT;
30966 err = ec_write(*off, byte_write);
30967 if (err)
30968 return err;
30969diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
30970index e83311b..142b5cc 100644
30971--- a/drivers/acpi/processor_driver.c
30972+++ b/drivers/acpi/processor_driver.c
30973@@ -558,7 +558,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
30974 return 0;
30975 #endif
30976
30977- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
30978+ BUG_ON(pr->id >= nr_cpu_ids);
30979
30980 /*
30981 * Buggy BIOS check
30982diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
30983index 46cd3f4..0871ad0 100644
30984--- a/drivers/ata/libata-core.c
30985+++ b/drivers/ata/libata-core.c
30986@@ -4780,7 +4780,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
30987 struct ata_port *ap;
30988 unsigned int tag;
30989
30990- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30991+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30992 ap = qc->ap;
30993
30994 qc->flags = 0;
30995@@ -4796,7 +4796,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
30996 struct ata_port *ap;
30997 struct ata_link *link;
30998
30999- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31000+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31001 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
31002 ap = qc->ap;
31003 link = qc->dev->link;
31004@@ -5892,6 +5892,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31005 return;
31006
31007 spin_lock(&lock);
31008+ pax_open_kernel();
31009
31010 for (cur = ops->inherits; cur; cur = cur->inherits) {
31011 void **inherit = (void **)cur;
31012@@ -5905,8 +5906,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31013 if (IS_ERR(*pp))
31014 *pp = NULL;
31015
31016- ops->inherits = NULL;
31017+ *(struct ata_port_operations **)&ops->inherits = NULL;
31018
31019+ pax_close_kernel();
31020 spin_unlock(&lock);
31021 }
31022
31023diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
31024index 405022d..fb70e53 100644
31025--- a/drivers/ata/pata_arasan_cf.c
31026+++ b/drivers/ata/pata_arasan_cf.c
31027@@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
31028 /* Handle platform specific quirks */
31029 if (pdata->quirk) {
31030 if (pdata->quirk & CF_BROKEN_PIO) {
31031- ap->ops->set_piomode = NULL;
31032+ pax_open_kernel();
31033+ *(void **)&ap->ops->set_piomode = NULL;
31034+ pax_close_kernel();
31035 ap->pio_mask = 0;
31036 }
31037 if (pdata->quirk & CF_BROKEN_MWDMA)
31038diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
31039index f9b983a..887b9d8 100644
31040--- a/drivers/atm/adummy.c
31041+++ b/drivers/atm/adummy.c
31042@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
31043 vcc->pop(vcc, skb);
31044 else
31045 dev_kfree_skb_any(skb);
31046- atomic_inc(&vcc->stats->tx);
31047+ atomic_inc_unchecked(&vcc->stats->tx);
31048
31049 return 0;
31050 }
31051diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
31052index 77a7480..05cde58 100644
31053--- a/drivers/atm/ambassador.c
31054+++ b/drivers/atm/ambassador.c
31055@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
31056 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
31057
31058 // VC layer stats
31059- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31060+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31061
31062 // free the descriptor
31063 kfree (tx_descr);
31064@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31065 dump_skb ("<<<", vc, skb);
31066
31067 // VC layer stats
31068- atomic_inc(&atm_vcc->stats->rx);
31069+ atomic_inc_unchecked(&atm_vcc->stats->rx);
31070 __net_timestamp(skb);
31071 // end of our responsibility
31072 atm_vcc->push (atm_vcc, skb);
31073@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31074 } else {
31075 PRINTK (KERN_INFO, "dropped over-size frame");
31076 // should we count this?
31077- atomic_inc(&atm_vcc->stats->rx_drop);
31078+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31079 }
31080
31081 } else {
31082@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
31083 }
31084
31085 if (check_area (skb->data, skb->len)) {
31086- atomic_inc(&atm_vcc->stats->tx_err);
31087+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
31088 return -ENOMEM; // ?
31089 }
31090
31091diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
31092index b22d71c..d6e1049 100644
31093--- a/drivers/atm/atmtcp.c
31094+++ b/drivers/atm/atmtcp.c
31095@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31096 if (vcc->pop) vcc->pop(vcc,skb);
31097 else dev_kfree_skb(skb);
31098 if (dev_data) return 0;
31099- atomic_inc(&vcc->stats->tx_err);
31100+ atomic_inc_unchecked(&vcc->stats->tx_err);
31101 return -ENOLINK;
31102 }
31103 size = skb->len+sizeof(struct atmtcp_hdr);
31104@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31105 if (!new_skb) {
31106 if (vcc->pop) vcc->pop(vcc,skb);
31107 else dev_kfree_skb(skb);
31108- atomic_inc(&vcc->stats->tx_err);
31109+ atomic_inc_unchecked(&vcc->stats->tx_err);
31110 return -ENOBUFS;
31111 }
31112 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
31113@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31114 if (vcc->pop) vcc->pop(vcc,skb);
31115 else dev_kfree_skb(skb);
31116 out_vcc->push(out_vcc,new_skb);
31117- atomic_inc(&vcc->stats->tx);
31118- atomic_inc(&out_vcc->stats->rx);
31119+ atomic_inc_unchecked(&vcc->stats->tx);
31120+ atomic_inc_unchecked(&out_vcc->stats->rx);
31121 return 0;
31122 }
31123
31124@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31125 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
31126 read_unlock(&vcc_sklist_lock);
31127 if (!out_vcc) {
31128- atomic_inc(&vcc->stats->tx_err);
31129+ atomic_inc_unchecked(&vcc->stats->tx_err);
31130 goto done;
31131 }
31132 skb_pull(skb,sizeof(struct atmtcp_hdr));
31133@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31134 __net_timestamp(new_skb);
31135 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
31136 out_vcc->push(out_vcc,new_skb);
31137- atomic_inc(&vcc->stats->tx);
31138- atomic_inc(&out_vcc->stats->rx);
31139+ atomic_inc_unchecked(&vcc->stats->tx);
31140+ atomic_inc_unchecked(&out_vcc->stats->rx);
31141 done:
31142 if (vcc->pop) vcc->pop(vcc,skb);
31143 else dev_kfree_skb(skb);
31144diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
31145index c1eb6fa..4c71be9 100644
31146--- a/drivers/atm/eni.c
31147+++ b/drivers/atm/eni.c
31148@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
31149 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
31150 vcc->dev->number);
31151 length = 0;
31152- atomic_inc(&vcc->stats->rx_err);
31153+ atomic_inc_unchecked(&vcc->stats->rx_err);
31154 }
31155 else {
31156 length = ATM_CELL_SIZE-1; /* no HEC */
31157@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31158 size);
31159 }
31160 eff = length = 0;
31161- atomic_inc(&vcc->stats->rx_err);
31162+ atomic_inc_unchecked(&vcc->stats->rx_err);
31163 }
31164 else {
31165 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
31166@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31167 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
31168 vcc->dev->number,vcc->vci,length,size << 2,descr);
31169 length = eff = 0;
31170- atomic_inc(&vcc->stats->rx_err);
31171+ atomic_inc_unchecked(&vcc->stats->rx_err);
31172 }
31173 }
31174 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
31175@@ -767,7 +767,7 @@ rx_dequeued++;
31176 vcc->push(vcc,skb);
31177 pushed++;
31178 }
31179- atomic_inc(&vcc->stats->rx);
31180+ atomic_inc_unchecked(&vcc->stats->rx);
31181 }
31182 wake_up(&eni_dev->rx_wait);
31183 }
31184@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
31185 PCI_DMA_TODEVICE);
31186 if (vcc->pop) vcc->pop(vcc,skb);
31187 else dev_kfree_skb_irq(skb);
31188- atomic_inc(&vcc->stats->tx);
31189+ atomic_inc_unchecked(&vcc->stats->tx);
31190 wake_up(&eni_dev->tx_wait);
31191 dma_complete++;
31192 }
31193diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
31194index b41c948..a002b17 100644
31195--- a/drivers/atm/firestream.c
31196+++ b/drivers/atm/firestream.c
31197@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
31198 }
31199 }
31200
31201- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31202+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31203
31204 fs_dprintk (FS_DEBUG_TXMEM, "i");
31205 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
31206@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31207 #endif
31208 skb_put (skb, qe->p1 & 0xffff);
31209 ATM_SKB(skb)->vcc = atm_vcc;
31210- atomic_inc(&atm_vcc->stats->rx);
31211+ atomic_inc_unchecked(&atm_vcc->stats->rx);
31212 __net_timestamp(skb);
31213 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
31214 atm_vcc->push (atm_vcc, skb);
31215@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31216 kfree (pe);
31217 }
31218 if (atm_vcc)
31219- atomic_inc(&atm_vcc->stats->rx_drop);
31220+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31221 break;
31222 case 0x1f: /* Reassembly abort: no buffers. */
31223 /* Silently increment error counter. */
31224 if (atm_vcc)
31225- atomic_inc(&atm_vcc->stats->rx_drop);
31226+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31227 break;
31228 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
31229 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
31230diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
31231index 204814e..cede831 100644
31232--- a/drivers/atm/fore200e.c
31233+++ b/drivers/atm/fore200e.c
31234@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
31235 #endif
31236 /* check error condition */
31237 if (*entry->status & STATUS_ERROR)
31238- atomic_inc(&vcc->stats->tx_err);
31239+ atomic_inc_unchecked(&vcc->stats->tx_err);
31240 else
31241- atomic_inc(&vcc->stats->tx);
31242+ atomic_inc_unchecked(&vcc->stats->tx);
31243 }
31244 }
31245
31246@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31247 if (skb == NULL) {
31248 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
31249
31250- atomic_inc(&vcc->stats->rx_drop);
31251+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31252 return -ENOMEM;
31253 }
31254
31255@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31256
31257 dev_kfree_skb_any(skb);
31258
31259- atomic_inc(&vcc->stats->rx_drop);
31260+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31261 return -ENOMEM;
31262 }
31263
31264 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31265
31266 vcc->push(vcc, skb);
31267- atomic_inc(&vcc->stats->rx);
31268+ atomic_inc_unchecked(&vcc->stats->rx);
31269
31270 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31271
31272@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
31273 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
31274 fore200e->atm_dev->number,
31275 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
31276- atomic_inc(&vcc->stats->rx_err);
31277+ atomic_inc_unchecked(&vcc->stats->rx_err);
31278 }
31279 }
31280
31281@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
31282 goto retry_here;
31283 }
31284
31285- atomic_inc(&vcc->stats->tx_err);
31286+ atomic_inc_unchecked(&vcc->stats->tx_err);
31287
31288 fore200e->tx_sat++;
31289 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
31290diff --git a/drivers/atm/he.c b/drivers/atm/he.c
31291index 72b6960..cf9167a 100644
31292--- a/drivers/atm/he.c
31293+++ b/drivers/atm/he.c
31294@@ -1699,7 +1699,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31295
31296 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
31297 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
31298- atomic_inc(&vcc->stats->rx_drop);
31299+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31300 goto return_host_buffers;
31301 }
31302
31303@@ -1726,7 +1726,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31304 RBRQ_LEN_ERR(he_dev->rbrq_head)
31305 ? "LEN_ERR" : "",
31306 vcc->vpi, vcc->vci);
31307- atomic_inc(&vcc->stats->rx_err);
31308+ atomic_inc_unchecked(&vcc->stats->rx_err);
31309 goto return_host_buffers;
31310 }
31311
31312@@ -1778,7 +1778,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31313 vcc->push(vcc, skb);
31314 spin_lock(&he_dev->global_lock);
31315
31316- atomic_inc(&vcc->stats->rx);
31317+ atomic_inc_unchecked(&vcc->stats->rx);
31318
31319 return_host_buffers:
31320 ++pdus_assembled;
31321@@ -2104,7 +2104,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
31322 tpd->vcc->pop(tpd->vcc, tpd->skb);
31323 else
31324 dev_kfree_skb_any(tpd->skb);
31325- atomic_inc(&tpd->vcc->stats->tx_err);
31326+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
31327 }
31328 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
31329 return;
31330@@ -2516,7 +2516,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31331 vcc->pop(vcc, skb);
31332 else
31333 dev_kfree_skb_any(skb);
31334- atomic_inc(&vcc->stats->tx_err);
31335+ atomic_inc_unchecked(&vcc->stats->tx_err);
31336 return -EINVAL;
31337 }
31338
31339@@ -2527,7 +2527,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31340 vcc->pop(vcc, skb);
31341 else
31342 dev_kfree_skb_any(skb);
31343- atomic_inc(&vcc->stats->tx_err);
31344+ atomic_inc_unchecked(&vcc->stats->tx_err);
31345 return -EINVAL;
31346 }
31347 #endif
31348@@ -2539,7 +2539,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31349 vcc->pop(vcc, skb);
31350 else
31351 dev_kfree_skb_any(skb);
31352- atomic_inc(&vcc->stats->tx_err);
31353+ atomic_inc_unchecked(&vcc->stats->tx_err);
31354 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31355 return -ENOMEM;
31356 }
31357@@ -2581,7 +2581,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31358 vcc->pop(vcc, skb);
31359 else
31360 dev_kfree_skb_any(skb);
31361- atomic_inc(&vcc->stats->tx_err);
31362+ atomic_inc_unchecked(&vcc->stats->tx_err);
31363 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31364 return -ENOMEM;
31365 }
31366@@ -2612,7 +2612,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31367 __enqueue_tpd(he_dev, tpd, cid);
31368 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31369
31370- atomic_inc(&vcc->stats->tx);
31371+ atomic_inc_unchecked(&vcc->stats->tx);
31372
31373 return 0;
31374 }
31375diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
31376index 1dc0519..1aadaf7 100644
31377--- a/drivers/atm/horizon.c
31378+++ b/drivers/atm/horizon.c
31379@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
31380 {
31381 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
31382 // VC layer stats
31383- atomic_inc(&vcc->stats->rx);
31384+ atomic_inc_unchecked(&vcc->stats->rx);
31385 __net_timestamp(skb);
31386 // end of our responsibility
31387 vcc->push (vcc, skb);
31388@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
31389 dev->tx_iovec = NULL;
31390
31391 // VC layer stats
31392- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31393+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31394
31395 // free the skb
31396 hrz_kfree_skb (skb);
31397diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
31398index 272f009..a18ba55 100644
31399--- a/drivers/atm/idt77252.c
31400+++ b/drivers/atm/idt77252.c
31401@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
31402 else
31403 dev_kfree_skb(skb);
31404
31405- atomic_inc(&vcc->stats->tx);
31406+ atomic_inc_unchecked(&vcc->stats->tx);
31407 }
31408
31409 atomic_dec(&scq->used);
31410@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31411 if ((sb = dev_alloc_skb(64)) == NULL) {
31412 printk("%s: Can't allocate buffers for aal0.\n",
31413 card->name);
31414- atomic_add(i, &vcc->stats->rx_drop);
31415+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
31416 break;
31417 }
31418 if (!atm_charge(vcc, sb->truesize)) {
31419 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
31420 card->name);
31421- atomic_add(i - 1, &vcc->stats->rx_drop);
31422+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
31423 dev_kfree_skb(sb);
31424 break;
31425 }
31426@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31427 ATM_SKB(sb)->vcc = vcc;
31428 __net_timestamp(sb);
31429 vcc->push(vcc, sb);
31430- atomic_inc(&vcc->stats->rx);
31431+ atomic_inc_unchecked(&vcc->stats->rx);
31432
31433 cell += ATM_CELL_PAYLOAD;
31434 }
31435@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31436 "(CDC: %08x)\n",
31437 card->name, len, rpp->len, readl(SAR_REG_CDC));
31438 recycle_rx_pool_skb(card, rpp);
31439- atomic_inc(&vcc->stats->rx_err);
31440+ atomic_inc_unchecked(&vcc->stats->rx_err);
31441 return;
31442 }
31443 if (stat & SAR_RSQE_CRC) {
31444 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
31445 recycle_rx_pool_skb(card, rpp);
31446- atomic_inc(&vcc->stats->rx_err);
31447+ atomic_inc_unchecked(&vcc->stats->rx_err);
31448 return;
31449 }
31450 if (skb_queue_len(&rpp->queue) > 1) {
31451@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31452 RXPRINTK("%s: Can't alloc RX skb.\n",
31453 card->name);
31454 recycle_rx_pool_skb(card, rpp);
31455- atomic_inc(&vcc->stats->rx_err);
31456+ atomic_inc_unchecked(&vcc->stats->rx_err);
31457 return;
31458 }
31459 if (!atm_charge(vcc, skb->truesize)) {
31460@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31461 __net_timestamp(skb);
31462
31463 vcc->push(vcc, skb);
31464- atomic_inc(&vcc->stats->rx);
31465+ atomic_inc_unchecked(&vcc->stats->rx);
31466
31467 return;
31468 }
31469@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31470 __net_timestamp(skb);
31471
31472 vcc->push(vcc, skb);
31473- atomic_inc(&vcc->stats->rx);
31474+ atomic_inc_unchecked(&vcc->stats->rx);
31475
31476 if (skb->truesize > SAR_FB_SIZE_3)
31477 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
31478@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
31479 if (vcc->qos.aal != ATM_AAL0) {
31480 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
31481 card->name, vpi, vci);
31482- atomic_inc(&vcc->stats->rx_drop);
31483+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31484 goto drop;
31485 }
31486
31487 if ((sb = dev_alloc_skb(64)) == NULL) {
31488 printk("%s: Can't allocate buffers for AAL0.\n",
31489 card->name);
31490- atomic_inc(&vcc->stats->rx_err);
31491+ atomic_inc_unchecked(&vcc->stats->rx_err);
31492 goto drop;
31493 }
31494
31495@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
31496 ATM_SKB(sb)->vcc = vcc;
31497 __net_timestamp(sb);
31498 vcc->push(vcc, sb);
31499- atomic_inc(&vcc->stats->rx);
31500+ atomic_inc_unchecked(&vcc->stats->rx);
31501
31502 drop:
31503 skb_pull(queue, 64);
31504@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31505
31506 if (vc == NULL) {
31507 printk("%s: NULL connection in send().\n", card->name);
31508- atomic_inc(&vcc->stats->tx_err);
31509+ atomic_inc_unchecked(&vcc->stats->tx_err);
31510 dev_kfree_skb(skb);
31511 return -EINVAL;
31512 }
31513 if (!test_bit(VCF_TX, &vc->flags)) {
31514 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
31515- atomic_inc(&vcc->stats->tx_err);
31516+ atomic_inc_unchecked(&vcc->stats->tx_err);
31517 dev_kfree_skb(skb);
31518 return -EINVAL;
31519 }
31520@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31521 break;
31522 default:
31523 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
31524- atomic_inc(&vcc->stats->tx_err);
31525+ atomic_inc_unchecked(&vcc->stats->tx_err);
31526 dev_kfree_skb(skb);
31527 return -EINVAL;
31528 }
31529
31530 if (skb_shinfo(skb)->nr_frags != 0) {
31531 printk("%s: No scatter-gather yet.\n", card->name);
31532- atomic_inc(&vcc->stats->tx_err);
31533+ atomic_inc_unchecked(&vcc->stats->tx_err);
31534 dev_kfree_skb(skb);
31535 return -EINVAL;
31536 }
31537@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31538
31539 err = queue_skb(card, vc, skb, oam);
31540 if (err) {
31541- atomic_inc(&vcc->stats->tx_err);
31542+ atomic_inc_unchecked(&vcc->stats->tx_err);
31543 dev_kfree_skb(skb);
31544 return err;
31545 }
31546@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
31547 skb = dev_alloc_skb(64);
31548 if (!skb) {
31549 printk("%s: Out of memory in send_oam().\n", card->name);
31550- atomic_inc(&vcc->stats->tx_err);
31551+ atomic_inc_unchecked(&vcc->stats->tx_err);
31552 return -ENOMEM;
31553 }
31554 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
31555diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
31556index 4217f29..88f547a 100644
31557--- a/drivers/atm/iphase.c
31558+++ b/drivers/atm/iphase.c
31559@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
31560 status = (u_short) (buf_desc_ptr->desc_mode);
31561 if (status & (RX_CER | RX_PTE | RX_OFL))
31562 {
31563- atomic_inc(&vcc->stats->rx_err);
31564+ atomic_inc_unchecked(&vcc->stats->rx_err);
31565 IF_ERR(printk("IA: bad packet, dropping it");)
31566 if (status & RX_CER) {
31567 IF_ERR(printk(" cause: packet CRC error\n");)
31568@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
31569 len = dma_addr - buf_addr;
31570 if (len > iadev->rx_buf_sz) {
31571 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
31572- atomic_inc(&vcc->stats->rx_err);
31573+ atomic_inc_unchecked(&vcc->stats->rx_err);
31574 goto out_free_desc;
31575 }
31576
31577@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
31578 ia_vcc = INPH_IA_VCC(vcc);
31579 if (ia_vcc == NULL)
31580 {
31581- atomic_inc(&vcc->stats->rx_err);
31582+ atomic_inc_unchecked(&vcc->stats->rx_err);
31583 atm_return(vcc, skb->truesize);
31584 dev_kfree_skb_any(skb);
31585 goto INCR_DLE;
31586@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
31587 if ((length > iadev->rx_buf_sz) || (length >
31588 (skb->len - sizeof(struct cpcs_trailer))))
31589 {
31590- atomic_inc(&vcc->stats->rx_err);
31591+ atomic_inc_unchecked(&vcc->stats->rx_err);
31592 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
31593 length, skb->len);)
31594 atm_return(vcc, skb->truesize);
31595@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
31596
31597 IF_RX(printk("rx_dle_intr: skb push");)
31598 vcc->push(vcc,skb);
31599- atomic_inc(&vcc->stats->rx);
31600+ atomic_inc_unchecked(&vcc->stats->rx);
31601 iadev->rx_pkt_cnt++;
31602 }
31603 INCR_DLE:
31604@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
31605 {
31606 struct k_sonet_stats *stats;
31607 stats = &PRIV(_ia_dev[board])->sonet_stats;
31608- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
31609- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
31610- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
31611- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
31612- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
31613- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
31614- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
31615- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
31616- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
31617+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
31618+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
31619+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
31620+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
31621+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
31622+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
31623+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
31624+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
31625+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
31626 }
31627 ia_cmds.status = 0;
31628 break;
31629@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
31630 if ((desc == 0) || (desc > iadev->num_tx_desc))
31631 {
31632 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
31633- atomic_inc(&vcc->stats->tx);
31634+ atomic_inc_unchecked(&vcc->stats->tx);
31635 if (vcc->pop)
31636 vcc->pop(vcc, skb);
31637 else
31638@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
31639 ATM_DESC(skb) = vcc->vci;
31640 skb_queue_tail(&iadev->tx_dma_q, skb);
31641
31642- atomic_inc(&vcc->stats->tx);
31643+ atomic_inc_unchecked(&vcc->stats->tx);
31644 iadev->tx_pkt_cnt++;
31645 /* Increment transaction counter */
31646 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
31647
31648 #if 0
31649 /* add flow control logic */
31650- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
31651+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
31652 if (iavcc->vc_desc_cnt > 10) {
31653 vcc->tx_quota = vcc->tx_quota * 3 / 4;
31654 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
31655diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
31656index fa7d701..1e404c7 100644
31657--- a/drivers/atm/lanai.c
31658+++ b/drivers/atm/lanai.c
31659@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
31660 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
31661 lanai_endtx(lanai, lvcc);
31662 lanai_free_skb(lvcc->tx.atmvcc, skb);
31663- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
31664+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
31665 }
31666
31667 /* Try to fill the buffer - don't call unless there is backlog */
31668@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
31669 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
31670 __net_timestamp(skb);
31671 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
31672- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
31673+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
31674 out:
31675 lvcc->rx.buf.ptr = end;
31676 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
31677@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31678 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
31679 "vcc %d\n", lanai->number, (unsigned int) s, vci);
31680 lanai->stats.service_rxnotaal5++;
31681- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31682+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31683 return 0;
31684 }
31685 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
31686@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31687 int bytes;
31688 read_unlock(&vcc_sklist_lock);
31689 DPRINTK("got trashed rx pdu on vci %d\n", vci);
31690- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31691+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31692 lvcc->stats.x.aal5.service_trash++;
31693 bytes = (SERVICE_GET_END(s) * 16) -
31694 (((unsigned long) lvcc->rx.buf.ptr) -
31695@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31696 }
31697 if (s & SERVICE_STREAM) {
31698 read_unlock(&vcc_sklist_lock);
31699- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31700+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31701 lvcc->stats.x.aal5.service_stream++;
31702 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
31703 "PDU on VCI %d!\n", lanai->number, vci);
31704@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31705 return 0;
31706 }
31707 DPRINTK("got rx crc error on vci %d\n", vci);
31708- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31709+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31710 lvcc->stats.x.aal5.service_rxcrc++;
31711 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
31712 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
31713diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
31714index ed1d2b7..8cffc1f 100644
31715--- a/drivers/atm/nicstar.c
31716+++ b/drivers/atm/nicstar.c
31717@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31718 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
31719 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
31720 card->index);
31721- atomic_inc(&vcc->stats->tx_err);
31722+ atomic_inc_unchecked(&vcc->stats->tx_err);
31723 dev_kfree_skb_any(skb);
31724 return -EINVAL;
31725 }
31726@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31727 if (!vc->tx) {
31728 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
31729 card->index);
31730- atomic_inc(&vcc->stats->tx_err);
31731+ atomic_inc_unchecked(&vcc->stats->tx_err);
31732 dev_kfree_skb_any(skb);
31733 return -EINVAL;
31734 }
31735@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31736 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
31737 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
31738 card->index);
31739- atomic_inc(&vcc->stats->tx_err);
31740+ atomic_inc_unchecked(&vcc->stats->tx_err);
31741 dev_kfree_skb_any(skb);
31742 return -EINVAL;
31743 }
31744
31745 if (skb_shinfo(skb)->nr_frags != 0) {
31746 printk("nicstar%d: No scatter-gather yet.\n", card->index);
31747- atomic_inc(&vcc->stats->tx_err);
31748+ atomic_inc_unchecked(&vcc->stats->tx_err);
31749 dev_kfree_skb_any(skb);
31750 return -EINVAL;
31751 }
31752@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31753 }
31754
31755 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
31756- atomic_inc(&vcc->stats->tx_err);
31757+ atomic_inc_unchecked(&vcc->stats->tx_err);
31758 dev_kfree_skb_any(skb);
31759 return -EIO;
31760 }
31761- atomic_inc(&vcc->stats->tx);
31762+ atomic_inc_unchecked(&vcc->stats->tx);
31763
31764 return 0;
31765 }
31766@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31767 printk
31768 ("nicstar%d: Can't allocate buffers for aal0.\n",
31769 card->index);
31770- atomic_add(i, &vcc->stats->rx_drop);
31771+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
31772 break;
31773 }
31774 if (!atm_charge(vcc, sb->truesize)) {
31775 RXPRINTK
31776 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
31777 card->index);
31778- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
31779+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
31780 dev_kfree_skb_any(sb);
31781 break;
31782 }
31783@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31784 ATM_SKB(sb)->vcc = vcc;
31785 __net_timestamp(sb);
31786 vcc->push(vcc, sb);
31787- atomic_inc(&vcc->stats->rx);
31788+ atomic_inc_unchecked(&vcc->stats->rx);
31789 cell += ATM_CELL_PAYLOAD;
31790 }
31791
31792@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31793 if (iovb == NULL) {
31794 printk("nicstar%d: Out of iovec buffers.\n",
31795 card->index);
31796- atomic_inc(&vcc->stats->rx_drop);
31797+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31798 recycle_rx_buf(card, skb);
31799 return;
31800 }
31801@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31802 small or large buffer itself. */
31803 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
31804 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
31805- atomic_inc(&vcc->stats->rx_err);
31806+ atomic_inc_unchecked(&vcc->stats->rx_err);
31807 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
31808 NS_MAX_IOVECS);
31809 NS_PRV_IOVCNT(iovb) = 0;
31810@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31811 ("nicstar%d: Expected a small buffer, and this is not one.\n",
31812 card->index);
31813 which_list(card, skb);
31814- atomic_inc(&vcc->stats->rx_err);
31815+ atomic_inc_unchecked(&vcc->stats->rx_err);
31816 recycle_rx_buf(card, skb);
31817 vc->rx_iov = NULL;
31818 recycle_iov_buf(card, iovb);
31819@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31820 ("nicstar%d: Expected a large buffer, and this is not one.\n",
31821 card->index);
31822 which_list(card, skb);
31823- atomic_inc(&vcc->stats->rx_err);
31824+ atomic_inc_unchecked(&vcc->stats->rx_err);
31825 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
31826 NS_PRV_IOVCNT(iovb));
31827 vc->rx_iov = NULL;
31828@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31829 printk(" - PDU size mismatch.\n");
31830 else
31831 printk(".\n");
31832- atomic_inc(&vcc->stats->rx_err);
31833+ atomic_inc_unchecked(&vcc->stats->rx_err);
31834 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
31835 NS_PRV_IOVCNT(iovb));
31836 vc->rx_iov = NULL;
31837@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31838 /* skb points to a small buffer */
31839 if (!atm_charge(vcc, skb->truesize)) {
31840 push_rxbufs(card, skb);
31841- atomic_inc(&vcc->stats->rx_drop);
31842+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31843 } else {
31844 skb_put(skb, len);
31845 dequeue_sm_buf(card, skb);
31846@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31847 ATM_SKB(skb)->vcc = vcc;
31848 __net_timestamp(skb);
31849 vcc->push(vcc, skb);
31850- atomic_inc(&vcc->stats->rx);
31851+ atomic_inc_unchecked(&vcc->stats->rx);
31852 }
31853 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
31854 struct sk_buff *sb;
31855@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31856 if (len <= NS_SMBUFSIZE) {
31857 if (!atm_charge(vcc, sb->truesize)) {
31858 push_rxbufs(card, sb);
31859- atomic_inc(&vcc->stats->rx_drop);
31860+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31861 } else {
31862 skb_put(sb, len);
31863 dequeue_sm_buf(card, sb);
31864@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31865 ATM_SKB(sb)->vcc = vcc;
31866 __net_timestamp(sb);
31867 vcc->push(vcc, sb);
31868- atomic_inc(&vcc->stats->rx);
31869+ atomic_inc_unchecked(&vcc->stats->rx);
31870 }
31871
31872 push_rxbufs(card, skb);
31873@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31874
31875 if (!atm_charge(vcc, skb->truesize)) {
31876 push_rxbufs(card, skb);
31877- atomic_inc(&vcc->stats->rx_drop);
31878+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31879 } else {
31880 dequeue_lg_buf(card, skb);
31881 #ifdef NS_USE_DESTRUCTORS
31882@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31883 ATM_SKB(skb)->vcc = vcc;
31884 __net_timestamp(skb);
31885 vcc->push(vcc, skb);
31886- atomic_inc(&vcc->stats->rx);
31887+ atomic_inc_unchecked(&vcc->stats->rx);
31888 }
31889
31890 push_rxbufs(card, sb);
31891@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31892 printk
31893 ("nicstar%d: Out of huge buffers.\n",
31894 card->index);
31895- atomic_inc(&vcc->stats->rx_drop);
31896+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31897 recycle_iovec_rx_bufs(card,
31898 (struct iovec *)
31899 iovb->data,
31900@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31901 card->hbpool.count++;
31902 } else
31903 dev_kfree_skb_any(hb);
31904- atomic_inc(&vcc->stats->rx_drop);
31905+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31906 } else {
31907 /* Copy the small buffer to the huge buffer */
31908 sb = (struct sk_buff *)iov->iov_base;
31909@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31910 #endif /* NS_USE_DESTRUCTORS */
31911 __net_timestamp(hb);
31912 vcc->push(vcc, hb);
31913- atomic_inc(&vcc->stats->rx);
31914+ atomic_inc_unchecked(&vcc->stats->rx);
31915 }
31916 }
31917
31918diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
31919index 0474a89..06ea4a1 100644
31920--- a/drivers/atm/solos-pci.c
31921+++ b/drivers/atm/solos-pci.c
31922@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
31923 }
31924 atm_charge(vcc, skb->truesize);
31925 vcc->push(vcc, skb);
31926- atomic_inc(&vcc->stats->rx);
31927+ atomic_inc_unchecked(&vcc->stats->rx);
31928 break;
31929
31930 case PKT_STATUS:
31931@@ -1117,7 +1117,7 @@ static uint32_t fpga_tx(struct solos_card *card)
31932 vcc = SKB_CB(oldskb)->vcc;
31933
31934 if (vcc) {
31935- atomic_inc(&vcc->stats->tx);
31936+ atomic_inc_unchecked(&vcc->stats->tx);
31937 solos_pop(vcc, oldskb);
31938 } else {
31939 dev_kfree_skb_irq(oldskb);
31940diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
31941index 0215934..ce9f5b1 100644
31942--- a/drivers/atm/suni.c
31943+++ b/drivers/atm/suni.c
31944@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
31945
31946
31947 #define ADD_LIMITED(s,v) \
31948- atomic_add((v),&stats->s); \
31949- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
31950+ atomic_add_unchecked((v),&stats->s); \
31951+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
31952
31953
31954 static void suni_hz(unsigned long from_timer)
31955diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
31956index 5120a96..e2572bd 100644
31957--- a/drivers/atm/uPD98402.c
31958+++ b/drivers/atm/uPD98402.c
31959@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
31960 struct sonet_stats tmp;
31961 int error = 0;
31962
31963- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
31964+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
31965 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
31966 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
31967 if (zero && !error) {
31968@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
31969
31970
31971 #define ADD_LIMITED(s,v) \
31972- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
31973- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
31974- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31975+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
31976+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
31977+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31978
31979
31980 static void stat_event(struct atm_dev *dev)
31981@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
31982 if (reason & uPD98402_INT_PFM) stat_event(dev);
31983 if (reason & uPD98402_INT_PCO) {
31984 (void) GET(PCOCR); /* clear interrupt cause */
31985- atomic_add(GET(HECCT),
31986+ atomic_add_unchecked(GET(HECCT),
31987 &PRIV(dev)->sonet_stats.uncorr_hcs);
31988 }
31989 if ((reason & uPD98402_INT_RFO) &&
31990@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
31991 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
31992 uPD98402_INT_LOS),PIMR); /* enable them */
31993 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
31994- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31995- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
31996- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
31997+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31998+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
31999+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
32000 return 0;
32001 }
32002
32003diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
32004index 969c3c2..9b72956 100644
32005--- a/drivers/atm/zatm.c
32006+++ b/drivers/atm/zatm.c
32007@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32008 }
32009 if (!size) {
32010 dev_kfree_skb_irq(skb);
32011- if (vcc) atomic_inc(&vcc->stats->rx_err);
32012+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
32013 continue;
32014 }
32015 if (!atm_charge(vcc,skb->truesize)) {
32016@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32017 skb->len = size;
32018 ATM_SKB(skb)->vcc = vcc;
32019 vcc->push(vcc,skb);
32020- atomic_inc(&vcc->stats->rx);
32021+ atomic_inc_unchecked(&vcc->stats->rx);
32022 }
32023 zout(pos & 0xffff,MTA(mbx));
32024 #if 0 /* probably a stupid idea */
32025@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
32026 skb_queue_head(&zatm_vcc->backlog,skb);
32027 break;
32028 }
32029- atomic_inc(&vcc->stats->tx);
32030+ atomic_inc_unchecked(&vcc->stats->tx);
32031 wake_up(&zatm_vcc->tx_wait);
32032 }
32033
32034diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
32035index 17cf7ca..7e553e1 100644
32036--- a/drivers/base/devtmpfs.c
32037+++ b/drivers/base/devtmpfs.c
32038@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
32039 if (!thread)
32040 return 0;
32041
32042- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
32043+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
32044 if (err)
32045 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
32046 else
32047diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
32048index e6ee5e8..98ad7fc 100644
32049--- a/drivers/base/power/wakeup.c
32050+++ b/drivers/base/power/wakeup.c
32051@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
32052 * They need to be modified together atomically, so it's better to use one
32053 * atomic variable to hold them both.
32054 */
32055-static atomic_t combined_event_count = ATOMIC_INIT(0);
32056+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
32057
32058 #define IN_PROGRESS_BITS (sizeof(int) * 4)
32059 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
32060
32061 static void split_counters(unsigned int *cnt, unsigned int *inpr)
32062 {
32063- unsigned int comb = atomic_read(&combined_event_count);
32064+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
32065
32066 *cnt = (comb >> IN_PROGRESS_BITS);
32067 *inpr = comb & MAX_IN_PROGRESS;
32068@@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
32069 ws->start_prevent_time = ws->last_time;
32070
32071 /* Increment the counter of events in progress. */
32072- cec = atomic_inc_return(&combined_event_count);
32073+ cec = atomic_inc_return_unchecked(&combined_event_count);
32074
32075 trace_wakeup_source_activate(ws->name, cec);
32076 }
32077@@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
32078 * Increment the counter of registered wakeup events and decrement the
32079 * couter of wakeup events in progress simultaneously.
32080 */
32081- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
32082+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
32083 trace_wakeup_source_deactivate(ws->name, cec);
32084
32085 split_counters(&cnt, &inpr);
32086diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
32087index ade58bc..867143d 100644
32088--- a/drivers/block/cciss.c
32089+++ b/drivers/block/cciss.c
32090@@ -1196,6 +1196,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
32091 int err;
32092 u32 cp;
32093
32094+ memset(&arg64, 0, sizeof(arg64));
32095+
32096 err = 0;
32097 err |=
32098 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
32099@@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
32100 while (!list_empty(&h->reqQ)) {
32101 c = list_entry(h->reqQ.next, CommandList_struct, list);
32102 /* can't do anything if fifo is full */
32103- if ((h->access.fifo_full(h))) {
32104+ if ((h->access->fifo_full(h))) {
32105 dev_warn(&h->pdev->dev, "fifo full\n");
32106 break;
32107 }
32108@@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
32109 h->Qdepth--;
32110
32111 /* Tell the controller execute command */
32112- h->access.submit_command(h, c);
32113+ h->access->submit_command(h, c);
32114
32115 /* Put job onto the completed Q */
32116 addQ(&h->cmpQ, c);
32117@@ -3441,17 +3443,17 @@ startio:
32118
32119 static inline unsigned long get_next_completion(ctlr_info_t *h)
32120 {
32121- return h->access.command_completed(h);
32122+ return h->access->command_completed(h);
32123 }
32124
32125 static inline int interrupt_pending(ctlr_info_t *h)
32126 {
32127- return h->access.intr_pending(h);
32128+ return h->access->intr_pending(h);
32129 }
32130
32131 static inline long interrupt_not_for_us(ctlr_info_t *h)
32132 {
32133- return ((h->access.intr_pending(h) == 0) ||
32134+ return ((h->access->intr_pending(h) == 0) ||
32135 (h->interrupts_enabled == 0));
32136 }
32137
32138@@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
32139 u32 a;
32140
32141 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
32142- return h->access.command_completed(h);
32143+ return h->access->command_completed(h);
32144
32145 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
32146 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
32147@@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
32148 trans_support & CFGTBL_Trans_use_short_tags);
32149
32150 /* Change the access methods to the performant access methods */
32151- h->access = SA5_performant_access;
32152+ h->access = &SA5_performant_access;
32153 h->transMethod = CFGTBL_Trans_Performant;
32154
32155 return;
32156@@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
32157 if (prod_index < 0)
32158 return -ENODEV;
32159 h->product_name = products[prod_index].product_name;
32160- h->access = *(products[prod_index].access);
32161+ h->access = products[prod_index].access;
32162
32163 if (cciss_board_disabled(h)) {
32164 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
32165@@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
32166 }
32167
32168 /* make sure the board interrupts are off */
32169- h->access.set_intr_mask(h, CCISS_INTR_OFF);
32170+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
32171 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
32172 if (rc)
32173 goto clean2;
32174@@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
32175 * fake ones to scoop up any residual completions.
32176 */
32177 spin_lock_irqsave(&h->lock, flags);
32178- h->access.set_intr_mask(h, CCISS_INTR_OFF);
32179+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
32180 spin_unlock_irqrestore(&h->lock, flags);
32181 free_irq(h->intr[h->intr_mode], h);
32182 rc = cciss_request_irq(h, cciss_msix_discard_completions,
32183@@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
32184 dev_info(&h->pdev->dev, "Board READY.\n");
32185 dev_info(&h->pdev->dev,
32186 "Waiting for stale completions to drain.\n");
32187- h->access.set_intr_mask(h, CCISS_INTR_ON);
32188+ h->access->set_intr_mask(h, CCISS_INTR_ON);
32189 msleep(10000);
32190- h->access.set_intr_mask(h, CCISS_INTR_OFF);
32191+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
32192
32193 rc = controller_reset_failed(h->cfgtable);
32194 if (rc)
32195@@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
32196 cciss_scsi_setup(h);
32197
32198 /* Turn the interrupts on so we can service requests */
32199- h->access.set_intr_mask(h, CCISS_INTR_ON);
32200+ h->access->set_intr_mask(h, CCISS_INTR_ON);
32201
32202 /* Get the firmware version */
32203 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
32204@@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
32205 kfree(flush_buf);
32206 if (return_code != IO_OK)
32207 dev_warn(&h->pdev->dev, "Error flushing cache\n");
32208- h->access.set_intr_mask(h, CCISS_INTR_OFF);
32209+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
32210 free_irq(h->intr[h->intr_mode], h);
32211 }
32212
32213diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
32214index 7fda30e..eb5dfe0 100644
32215--- a/drivers/block/cciss.h
32216+++ b/drivers/block/cciss.h
32217@@ -101,7 +101,7 @@ struct ctlr_info
32218 /* information about each logical volume */
32219 drive_info_struct *drv[CISS_MAX_LUN];
32220
32221- struct access_method access;
32222+ struct access_method *access;
32223
32224 /* queue and queue Info */
32225 struct list_head reqQ;
32226diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
32227index 3f08713..56a586a 100644
32228--- a/drivers/block/cpqarray.c
32229+++ b/drivers/block/cpqarray.c
32230@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
32231 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
32232 goto Enomem4;
32233 }
32234- hba[i]->access.set_intr_mask(hba[i], 0);
32235+ hba[i]->access->set_intr_mask(hba[i], 0);
32236 if (request_irq(hba[i]->intr, do_ida_intr,
32237 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
32238 {
32239@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
32240 add_timer(&hba[i]->timer);
32241
32242 /* Enable IRQ now that spinlock and rate limit timer are set up */
32243- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
32244+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
32245
32246 for(j=0; j<NWD; j++) {
32247 struct gendisk *disk = ida_gendisk[i][j];
32248@@ -694,7 +694,7 @@ DBGINFO(
32249 for(i=0; i<NR_PRODUCTS; i++) {
32250 if (board_id == products[i].board_id) {
32251 c->product_name = products[i].product_name;
32252- c->access = *(products[i].access);
32253+ c->access = products[i].access;
32254 break;
32255 }
32256 }
32257@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
32258 hba[ctlr]->intr = intr;
32259 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
32260 hba[ctlr]->product_name = products[j].product_name;
32261- hba[ctlr]->access = *(products[j].access);
32262+ hba[ctlr]->access = products[j].access;
32263 hba[ctlr]->ctlr = ctlr;
32264 hba[ctlr]->board_id = board_id;
32265 hba[ctlr]->pci_dev = NULL; /* not PCI */
32266@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
32267
32268 while((c = h->reqQ) != NULL) {
32269 /* Can't do anything if we're busy */
32270- if (h->access.fifo_full(h) == 0)
32271+ if (h->access->fifo_full(h) == 0)
32272 return;
32273
32274 /* Get the first entry from the request Q */
32275@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
32276 h->Qdepth--;
32277
32278 /* Tell the controller to do our bidding */
32279- h->access.submit_command(h, c);
32280+ h->access->submit_command(h, c);
32281
32282 /* Get onto the completion Q */
32283 addQ(&h->cmpQ, c);
32284@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
32285 unsigned long flags;
32286 __u32 a,a1;
32287
32288- istat = h->access.intr_pending(h);
32289+ istat = h->access->intr_pending(h);
32290 /* Is this interrupt for us? */
32291 if (istat == 0)
32292 return IRQ_NONE;
32293@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
32294 */
32295 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
32296 if (istat & FIFO_NOT_EMPTY) {
32297- while((a = h->access.command_completed(h))) {
32298+ while((a = h->access->command_completed(h))) {
32299 a1 = a; a &= ~3;
32300 if ((c = h->cmpQ) == NULL)
32301 {
32302@@ -1449,11 +1449,11 @@ static int sendcmd(
32303 /*
32304 * Disable interrupt
32305 */
32306- info_p->access.set_intr_mask(info_p, 0);
32307+ info_p->access->set_intr_mask(info_p, 0);
32308 /* Make sure there is room in the command FIFO */
32309 /* Actually it should be completely empty at this time. */
32310 for (i = 200000; i > 0; i--) {
32311- temp = info_p->access.fifo_full(info_p);
32312+ temp = info_p->access->fifo_full(info_p);
32313 if (temp != 0) {
32314 break;
32315 }
32316@@ -1466,7 +1466,7 @@ DBG(
32317 /*
32318 * Send the cmd
32319 */
32320- info_p->access.submit_command(info_p, c);
32321+ info_p->access->submit_command(info_p, c);
32322 complete = pollcomplete(ctlr);
32323
32324 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
32325@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
32326 * we check the new geometry. Then turn interrupts back on when
32327 * we're done.
32328 */
32329- host->access.set_intr_mask(host, 0);
32330+ host->access->set_intr_mask(host, 0);
32331 getgeometry(ctlr);
32332- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
32333+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
32334
32335 for(i=0; i<NWD; i++) {
32336 struct gendisk *disk = ida_gendisk[ctlr][i];
32337@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
32338 /* Wait (up to 2 seconds) for a command to complete */
32339
32340 for (i = 200000; i > 0; i--) {
32341- done = hba[ctlr]->access.command_completed(hba[ctlr]);
32342+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
32343 if (done == 0) {
32344 udelay(10); /* a short fixed delay */
32345 } else
32346diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
32347index be73e9d..7fbf140 100644
32348--- a/drivers/block/cpqarray.h
32349+++ b/drivers/block/cpqarray.h
32350@@ -99,7 +99,7 @@ struct ctlr_info {
32351 drv_info_t drv[NWD];
32352 struct proc_dir_entry *proc;
32353
32354- struct access_method access;
32355+ struct access_method *access;
32356
32357 cmdlist_t *reqQ;
32358 cmdlist_t *cmpQ;
32359diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
32360index 6b51afa..17e1191 100644
32361--- a/drivers/block/drbd/drbd_int.h
32362+++ b/drivers/block/drbd/drbd_int.h
32363@@ -582,7 +582,7 @@ struct drbd_epoch {
32364 struct drbd_tconn *tconn;
32365 struct list_head list;
32366 unsigned int barrier_nr;
32367- atomic_t epoch_size; /* increased on every request added. */
32368+ atomic_unchecked_t epoch_size; /* increased on every request added. */
32369 atomic_t active; /* increased on every req. added, and dec on every finished. */
32370 unsigned long flags;
32371 };
32372@@ -1011,7 +1011,7 @@ struct drbd_conf {
32373 int al_tr_cycle;
32374 int al_tr_pos; /* position of the next transaction in the journal */
32375 wait_queue_head_t seq_wait;
32376- atomic_t packet_seq;
32377+ atomic_unchecked_t packet_seq;
32378 unsigned int peer_seq;
32379 spinlock_t peer_seq_lock;
32380 unsigned int minor;
32381@@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
32382 char __user *uoptval;
32383 int err;
32384
32385- uoptval = (char __user __force *)optval;
32386+ uoptval = (char __force_user *)optval;
32387
32388 set_fs(KERNEL_DS);
32389 if (level == SOL_SOCKET)
32390diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
32391index 8c13eeb..217adee 100644
32392--- a/drivers/block/drbd/drbd_main.c
32393+++ b/drivers/block/drbd/drbd_main.c
32394@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
32395 p->sector = sector;
32396 p->block_id = block_id;
32397 p->blksize = blksize;
32398- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
32399+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
32400 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
32401 }
32402
32403@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
32404 return -EIO;
32405 p->sector = cpu_to_be64(req->i.sector);
32406 p->block_id = (unsigned long)req;
32407- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
32408+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
32409 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
32410 if (mdev->state.conn >= C_SYNC_SOURCE &&
32411 mdev->state.conn <= C_PAUSED_SYNC_T)
32412@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
32413 {
32414 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
32415
32416- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
32417- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
32418+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
32419+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
32420 kfree(tconn->current_epoch);
32421
32422 idr_destroy(&tconn->volumes);
32423diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
32424index a9eccfc..68e4533 100644
32425--- a/drivers/block/drbd/drbd_receiver.c
32426+++ b/drivers/block/drbd/drbd_receiver.c
32427@@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
32428 {
32429 int err;
32430
32431- atomic_set(&mdev->packet_seq, 0);
32432+ atomic_set_unchecked(&mdev->packet_seq, 0);
32433 mdev->peer_seq = 0;
32434
32435 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
32436@@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
32437 do {
32438 next_epoch = NULL;
32439
32440- epoch_size = atomic_read(&epoch->epoch_size);
32441+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
32442
32443 switch (ev & ~EV_CLEANUP) {
32444 case EV_PUT:
32445@@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
32446 rv = FE_DESTROYED;
32447 } else {
32448 epoch->flags = 0;
32449- atomic_set(&epoch->epoch_size, 0);
32450+ atomic_set_unchecked(&epoch->epoch_size, 0);
32451 /* atomic_set(&epoch->active, 0); is already zero */
32452 if (rv == FE_STILL_LIVE)
32453 rv = FE_RECYCLED;
32454@@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
32455 conn_wait_active_ee_empty(tconn);
32456 drbd_flush(tconn);
32457
32458- if (atomic_read(&tconn->current_epoch->epoch_size)) {
32459+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
32460 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
32461 if (epoch)
32462 break;
32463@@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
32464 }
32465
32466 epoch->flags = 0;
32467- atomic_set(&epoch->epoch_size, 0);
32468+ atomic_set_unchecked(&epoch->epoch_size, 0);
32469 atomic_set(&epoch->active, 0);
32470
32471 spin_lock(&tconn->epoch_lock);
32472- if (atomic_read(&tconn->current_epoch->epoch_size)) {
32473+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
32474 list_add(&epoch->list, &tconn->current_epoch->list);
32475 tconn->current_epoch = epoch;
32476 tconn->epochs++;
32477@@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
32478
32479 err = wait_for_and_update_peer_seq(mdev, peer_seq);
32480 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
32481- atomic_inc(&tconn->current_epoch->epoch_size);
32482+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
32483 err2 = drbd_drain_block(mdev, pi->size);
32484 if (!err)
32485 err = err2;
32486@@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
32487
32488 spin_lock(&tconn->epoch_lock);
32489 peer_req->epoch = tconn->current_epoch;
32490- atomic_inc(&peer_req->epoch->epoch_size);
32491+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
32492 atomic_inc(&peer_req->epoch->active);
32493 spin_unlock(&tconn->epoch_lock);
32494
32495@@ -4466,7 +4466,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
32496 if (!list_empty(&tconn->current_epoch->list))
32497 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
32498 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
32499- atomic_set(&tconn->current_epoch->epoch_size, 0);
32500+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
32501 tconn->send.seen_any_write_yet = false;
32502
32503 conn_info(tconn, "Connection closed\n");
32504diff --git a/drivers/block/loop.c b/drivers/block/loop.c
32505index ae12512..37fa397 100644
32506--- a/drivers/block/loop.c
32507+++ b/drivers/block/loop.c
32508@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
32509 mm_segment_t old_fs = get_fs();
32510
32511 set_fs(get_ds());
32512- bw = file->f_op->write(file, buf, len, &pos);
32513+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
32514 set_fs(old_fs);
32515 if (likely(bw == len))
32516 return 0;
32517diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
32518index d620b44..587561e 100644
32519--- a/drivers/cdrom/cdrom.c
32520+++ b/drivers/cdrom/cdrom.c
32521@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
32522 ENSURE(reset, CDC_RESET);
32523 ENSURE(generic_packet, CDC_GENERIC_PACKET);
32524 cdi->mc_flags = 0;
32525- cdo->n_minors = 0;
32526 cdi->options = CDO_USE_FFLAGS;
32527
32528 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
32529@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
32530 else
32531 cdi->cdda_method = CDDA_OLD;
32532
32533- if (!cdo->generic_packet)
32534- cdo->generic_packet = cdrom_dummy_generic_packet;
32535+ if (!cdo->generic_packet) {
32536+ pax_open_kernel();
32537+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
32538+ pax_close_kernel();
32539+ }
32540
32541 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
32542 mutex_lock(&cdrom_mutex);
32543@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
32544 if (cdi->exit)
32545 cdi->exit(cdi);
32546
32547- cdi->ops->n_minors--;
32548 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
32549 }
32550
32551diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
32552index d59cdcb..11afddf 100644
32553--- a/drivers/cdrom/gdrom.c
32554+++ b/drivers/cdrom/gdrom.c
32555@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
32556 .audio_ioctl = gdrom_audio_ioctl,
32557 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
32558 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
32559- .n_minors = 1,
32560 };
32561
32562 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
32563diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
32564index 72bedad..8181ce1 100644
32565--- a/drivers/char/Kconfig
32566+++ b/drivers/char/Kconfig
32567@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
32568
32569 config DEVKMEM
32570 bool "/dev/kmem virtual device support"
32571- default y
32572+ default n
32573+ depends on !GRKERNSEC_KMEM
32574 help
32575 Say Y here if you want to support the /dev/kmem device. The
32576 /dev/kmem device is rarely used, but can be used for certain
32577@@ -581,6 +582,7 @@ config DEVPORT
32578 bool
32579 depends on !M68K
32580 depends on ISA || PCI
32581+ depends on !GRKERNSEC_KMEM
32582 default y
32583
32584 source "drivers/s390/char/Kconfig"
32585diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
32586index 2e04433..22afc64 100644
32587--- a/drivers/char/agp/frontend.c
32588+++ b/drivers/char/agp/frontend.c
32589@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
32590 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
32591 return -EFAULT;
32592
32593- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
32594+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
32595 return -EFAULT;
32596
32597 client = agp_find_client_by_pid(reserve.pid);
32598diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
32599index 21cb980..f15107c 100644
32600--- a/drivers/char/genrtc.c
32601+++ b/drivers/char/genrtc.c
32602@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
32603 switch (cmd) {
32604
32605 case RTC_PLL_GET:
32606+ memset(&pll, 0, sizeof(pll));
32607 if (get_rtc_pll(&pll))
32608 return -EINVAL;
32609 else
32610diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
32611index fe6d4be..89f32100 100644
32612--- a/drivers/char/hpet.c
32613+++ b/drivers/char/hpet.c
32614@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
32615 }
32616
32617 static int
32618-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
32619+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
32620 struct hpet_info *info)
32621 {
32622 struct hpet_timer __iomem *timer;
32623diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
32624index 053201b0..8335cce 100644
32625--- a/drivers/char/ipmi/ipmi_msghandler.c
32626+++ b/drivers/char/ipmi/ipmi_msghandler.c
32627@@ -420,7 +420,7 @@ struct ipmi_smi {
32628 struct proc_dir_entry *proc_dir;
32629 char proc_dir_name[10];
32630
32631- atomic_t stats[IPMI_NUM_STATS];
32632+ atomic_unchecked_t stats[IPMI_NUM_STATS];
32633
32634 /*
32635 * run_to_completion duplicate of smb_info, smi_info
32636@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
32637
32638
32639 #define ipmi_inc_stat(intf, stat) \
32640- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
32641+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
32642 #define ipmi_get_stat(intf, stat) \
32643- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
32644+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
32645
32646 static int is_lan_addr(struct ipmi_addr *addr)
32647 {
32648@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
32649 INIT_LIST_HEAD(&intf->cmd_rcvrs);
32650 init_waitqueue_head(&intf->waitq);
32651 for (i = 0; i < IPMI_NUM_STATS; i++)
32652- atomic_set(&intf->stats[i], 0);
32653+ atomic_set_unchecked(&intf->stats[i], 0);
32654
32655 intf->proc_dir = NULL;
32656
32657diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
32658index 1c7fdcd..4899100 100644
32659--- a/drivers/char/ipmi/ipmi_si_intf.c
32660+++ b/drivers/char/ipmi/ipmi_si_intf.c
32661@@ -275,7 +275,7 @@ struct smi_info {
32662 unsigned char slave_addr;
32663
32664 /* Counters and things for the proc filesystem. */
32665- atomic_t stats[SI_NUM_STATS];
32666+ atomic_unchecked_t stats[SI_NUM_STATS];
32667
32668 struct task_struct *thread;
32669
32670@@ -284,9 +284,9 @@ struct smi_info {
32671 };
32672
32673 #define smi_inc_stat(smi, stat) \
32674- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
32675+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
32676 #define smi_get_stat(smi, stat) \
32677- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
32678+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
32679
32680 #define SI_MAX_PARMS 4
32681
32682@@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
32683 atomic_set(&new_smi->req_events, 0);
32684 new_smi->run_to_completion = 0;
32685 for (i = 0; i < SI_NUM_STATS; i++)
32686- atomic_set(&new_smi->stats[i], 0);
32687+ atomic_set_unchecked(&new_smi->stats[i], 0);
32688
32689 new_smi->interrupt_disabled = 1;
32690 atomic_set(&new_smi->stop_operation, 0);
32691diff --git a/drivers/char/mem.c b/drivers/char/mem.c
32692index c6fa3bc..4ca3e42 100644
32693--- a/drivers/char/mem.c
32694+++ b/drivers/char/mem.c
32695@@ -18,6 +18,7 @@
32696 #include <linux/raw.h>
32697 #include <linux/tty.h>
32698 #include <linux/capability.h>
32699+#include <linux/security.h>
32700 #include <linux/ptrace.h>
32701 #include <linux/device.h>
32702 #include <linux/highmem.h>
32703@@ -37,6 +38,10 @@
32704
32705 #define DEVPORT_MINOR 4
32706
32707+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
32708+extern const struct file_operations grsec_fops;
32709+#endif
32710+
32711 static inline unsigned long size_inside_page(unsigned long start,
32712 unsigned long size)
32713 {
32714@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32715
32716 while (cursor < to) {
32717 if (!devmem_is_allowed(pfn)) {
32718+#ifdef CONFIG_GRKERNSEC_KMEM
32719+ gr_handle_mem_readwrite(from, to);
32720+#else
32721 printk(KERN_INFO
32722 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
32723 current->comm, from, to);
32724+#endif
32725 return 0;
32726 }
32727 cursor += PAGE_SIZE;
32728@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32729 }
32730 return 1;
32731 }
32732+#elif defined(CONFIG_GRKERNSEC_KMEM)
32733+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32734+{
32735+ return 0;
32736+}
32737 #else
32738 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32739 {
32740@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
32741
32742 while (count > 0) {
32743 unsigned long remaining;
32744+ char *temp;
32745
32746 sz = size_inside_page(p, count);
32747
32748@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
32749 if (!ptr)
32750 return -EFAULT;
32751
32752- remaining = copy_to_user(buf, ptr, sz);
32753+#ifdef CONFIG_PAX_USERCOPY
32754+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
32755+ if (!temp) {
32756+ unxlate_dev_mem_ptr(p, ptr);
32757+ return -ENOMEM;
32758+ }
32759+ memcpy(temp, ptr, sz);
32760+#else
32761+ temp = ptr;
32762+#endif
32763+
32764+ remaining = copy_to_user(buf, temp, sz);
32765+
32766+#ifdef CONFIG_PAX_USERCOPY
32767+ kfree(temp);
32768+#endif
32769+
32770 unxlate_dev_mem_ptr(p, ptr);
32771 if (remaining)
32772 return -EFAULT;
32773@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
32774 size_t count, loff_t *ppos)
32775 {
32776 unsigned long p = *ppos;
32777- ssize_t low_count, read, sz;
32778+ ssize_t low_count, read, sz, err = 0;
32779 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
32780- int err = 0;
32781
32782 read = 0;
32783 if (p < (unsigned long) high_memory) {
32784@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
32785 }
32786 #endif
32787 while (low_count > 0) {
32788+ char *temp;
32789+
32790 sz = size_inside_page(p, low_count);
32791
32792 /*
32793@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
32794 */
32795 kbuf = xlate_dev_kmem_ptr((char *)p);
32796
32797- if (copy_to_user(buf, kbuf, sz))
32798+#ifdef CONFIG_PAX_USERCOPY
32799+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
32800+ if (!temp)
32801+ return -ENOMEM;
32802+ memcpy(temp, kbuf, sz);
32803+#else
32804+ temp = kbuf;
32805+#endif
32806+
32807+ err = copy_to_user(buf, temp, sz);
32808+
32809+#ifdef CONFIG_PAX_USERCOPY
32810+ kfree(temp);
32811+#endif
32812+
32813+ if (err)
32814 return -EFAULT;
32815 buf += sz;
32816 p += sz;
32817@@ -833,6 +880,9 @@ static const struct memdev {
32818 #ifdef CONFIG_CRASH_DUMP
32819 [12] = { "oldmem", 0, &oldmem_fops, NULL },
32820 #endif
32821+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
32822+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
32823+#endif
32824 };
32825
32826 static int memory_open(struct inode *inode, struct file *filp)
32827diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
32828index 9df78e2..01ba9ae 100644
32829--- a/drivers/char/nvram.c
32830+++ b/drivers/char/nvram.c
32831@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
32832
32833 spin_unlock_irq(&rtc_lock);
32834
32835- if (copy_to_user(buf, contents, tmp - contents))
32836+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
32837 return -EFAULT;
32838
32839 *ppos = i;
32840diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
32841index b66eaa0..2619d1b 100644
32842--- a/drivers/char/pcmcia/synclink_cs.c
32843+++ b/drivers/char/pcmcia/synclink_cs.c
32844@@ -2348,9 +2348,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32845
32846 if (debug_level >= DEBUG_LEVEL_INFO)
32847 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
32848- __FILE__,__LINE__, info->device_name, port->count);
32849+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
32850
32851- WARN_ON(!port->count);
32852+ WARN_ON(!atomic_read(&port->count));
32853
32854 if (tty_port_close_start(port, tty, filp) == 0)
32855 goto cleanup;
32856@@ -2368,7 +2368,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32857 cleanup:
32858 if (debug_level >= DEBUG_LEVEL_INFO)
32859 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
32860- tty->driver->name, port->count);
32861+ tty->driver->name, atomic_read(&port->count));
32862 }
32863
32864 /* Wait until the transmitter is empty.
32865@@ -2510,7 +2510,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32866
32867 if (debug_level >= DEBUG_LEVEL_INFO)
32868 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
32869- __FILE__,__LINE__,tty->driver->name, port->count);
32870+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
32871
32872 /* If port is closing, signal caller to try again */
32873 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
32874@@ -2530,11 +2530,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32875 goto cleanup;
32876 }
32877 spin_lock(&port->lock);
32878- port->count++;
32879+ atomic_inc(&port->count);
32880 spin_unlock(&port->lock);
32881 spin_unlock_irqrestore(&info->netlock, flags);
32882
32883- if (port->count == 1) {
32884+ if (atomic_read(&port->count) == 1) {
32885 /* 1st open on this device, init hardware */
32886 retval = startup(info, tty);
32887 if (retval < 0)
32888@@ -3889,7 +3889,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
32889 unsigned short new_crctype;
32890
32891 /* return error if TTY interface open */
32892- if (info->port.count)
32893+ if (atomic_read(&info->port.count))
32894 return -EBUSY;
32895
32896 switch (encoding)
32897@@ -3992,7 +3992,7 @@ static int hdlcdev_open(struct net_device *dev)
32898
32899 /* arbitrate between network and tty opens */
32900 spin_lock_irqsave(&info->netlock, flags);
32901- if (info->port.count != 0 || info->netcount != 0) {
32902+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
32903 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
32904 spin_unlock_irqrestore(&info->netlock, flags);
32905 return -EBUSY;
32906@@ -4081,7 +4081,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
32907 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
32908
32909 /* return error if TTY interface open */
32910- if (info->port.count)
32911+ if (atomic_read(&info->port.count))
32912 return -EBUSY;
32913
32914 if (cmd != SIOCWANDEV)
32915diff --git a/drivers/char/random.c b/drivers/char/random.c
32916index 85e81ec..bce8b97 100644
32917--- a/drivers/char/random.c
32918+++ b/drivers/char/random.c
32919@@ -272,8 +272,13 @@
32920 /*
32921 * Configuration information
32922 */
32923+#ifdef CONFIG_GRKERNSEC_RANDNET
32924+#define INPUT_POOL_WORDS 512
32925+#define OUTPUT_POOL_WORDS 128
32926+#else
32927 #define INPUT_POOL_WORDS 128
32928 #define OUTPUT_POOL_WORDS 32
32929+#endif
32930 #define SEC_XFER_SIZE 512
32931 #define EXTRACT_SIZE 10
32932
32933@@ -313,10 +318,17 @@ static struct poolinfo {
32934 int poolwords;
32935 int tap1, tap2, tap3, tap4, tap5;
32936 } poolinfo_table[] = {
32937+#ifdef CONFIG_GRKERNSEC_RANDNET
32938+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
32939+ { 512, 411, 308, 208, 104, 1 },
32940+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
32941+ { 128, 103, 76, 51, 25, 1 },
32942+#else
32943 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
32944 { 128, 103, 76, 51, 25, 1 },
32945 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
32946 { 32, 26, 20, 14, 7, 1 },
32947+#endif
32948 #if 0
32949 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
32950 { 2048, 1638, 1231, 819, 411, 1 },
32951@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
32952 input_rotate += i ? 7 : 14;
32953 }
32954
32955- ACCESS_ONCE(r->input_rotate) = input_rotate;
32956- ACCESS_ONCE(r->add_ptr) = i;
32957+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
32958+ ACCESS_ONCE_RW(r->add_ptr) = i;
32959 smp_wmb();
32960
32961 if (out)
32962@@ -1020,7 +1032,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
32963
32964 extract_buf(r, tmp);
32965 i = min_t(int, nbytes, EXTRACT_SIZE);
32966- if (copy_to_user(buf, tmp, i)) {
32967+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
32968 ret = -EFAULT;
32969 break;
32970 }
32971@@ -1356,7 +1368,7 @@ EXPORT_SYMBOL(generate_random_uuid);
32972 #include <linux/sysctl.h>
32973
32974 static int min_read_thresh = 8, min_write_thresh;
32975-static int max_read_thresh = INPUT_POOL_WORDS * 32;
32976+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
32977 static int max_write_thresh = INPUT_POOL_WORDS * 32;
32978 static char sysctl_bootid[16];
32979
32980diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
32981index d780295..b29f3a8 100644
32982--- a/drivers/char/sonypi.c
32983+++ b/drivers/char/sonypi.c
32984@@ -54,6 +54,7 @@
32985
32986 #include <asm/uaccess.h>
32987 #include <asm/io.h>
32988+#include <asm/local.h>
32989
32990 #include <linux/sonypi.h>
32991
32992@@ -490,7 +491,7 @@ static struct sonypi_device {
32993 spinlock_t fifo_lock;
32994 wait_queue_head_t fifo_proc_list;
32995 struct fasync_struct *fifo_async;
32996- int open_count;
32997+ local_t open_count;
32998 int model;
32999 struct input_dev *input_jog_dev;
33000 struct input_dev *input_key_dev;
33001@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
33002 static int sonypi_misc_release(struct inode *inode, struct file *file)
33003 {
33004 mutex_lock(&sonypi_device.lock);
33005- sonypi_device.open_count--;
33006+ local_dec(&sonypi_device.open_count);
33007 mutex_unlock(&sonypi_device.lock);
33008 return 0;
33009 }
33010@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
33011 {
33012 mutex_lock(&sonypi_device.lock);
33013 /* Flush input queue on first open */
33014- if (!sonypi_device.open_count)
33015+ if (!local_read(&sonypi_device.open_count))
33016 kfifo_reset(&sonypi_device.fifo);
33017- sonypi_device.open_count++;
33018+ local_inc(&sonypi_device.open_count);
33019 mutex_unlock(&sonypi_device.lock);
33020
33021 return 0;
33022diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
33023index 93211df..c7805f7 100644
33024--- a/drivers/char/tpm/tpm.c
33025+++ b/drivers/char/tpm/tpm.c
33026@@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
33027 chip->vendor.req_complete_val)
33028 goto out_recv;
33029
33030- if ((status == chip->vendor.req_canceled)) {
33031+ if (status == chip->vendor.req_canceled) {
33032 dev_err(chip->dev, "Operation Canceled\n");
33033 rc = -ECANCELED;
33034 goto out;
33035diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
33036index 56051d0..11cf3b7 100644
33037--- a/drivers/char/tpm/tpm_acpi.c
33038+++ b/drivers/char/tpm/tpm_acpi.c
33039@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
33040 virt = acpi_os_map_memory(start, len);
33041 if (!virt) {
33042 kfree(log->bios_event_log);
33043+ log->bios_event_log = NULL;
33044 printk("%s: ERROR - Unable to map memory\n", __func__);
33045 return -EIO;
33046 }
33047
33048- memcpy_fromio(log->bios_event_log, virt, len);
33049+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
33050
33051 acpi_os_unmap_memory(virt, len);
33052 return 0;
33053diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
33054index 84ddc55..1d32f1e 100644
33055--- a/drivers/char/tpm/tpm_eventlog.c
33056+++ b/drivers/char/tpm/tpm_eventlog.c
33057@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
33058 event = addr;
33059
33060 if ((event->event_type == 0 && event->event_size == 0) ||
33061- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
33062+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
33063 return NULL;
33064
33065 return addr;
33066@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
33067 return NULL;
33068
33069 if ((event->event_type == 0 && event->event_size == 0) ||
33070- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
33071+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
33072 return NULL;
33073
33074 (*pos)++;
33075@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
33076 int i;
33077
33078 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
33079- seq_putc(m, data[i]);
33080+ if (!seq_putc(m, data[i]))
33081+ return -EFAULT;
33082
33083 return 0;
33084 }
33085diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
33086index ee4dbea..69c817b 100644
33087--- a/drivers/char/virtio_console.c
33088+++ b/drivers/char/virtio_console.c
33089@@ -681,7 +681,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
33090 if (to_user) {
33091 ssize_t ret;
33092
33093- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
33094+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
33095 if (ret)
33096 return -EFAULT;
33097 } else {
33098@@ -780,7 +780,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
33099 if (!port_has_data(port) && !port->host_connected)
33100 return 0;
33101
33102- return fill_readbuf(port, ubuf, count, true);
33103+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
33104 }
33105
33106 static int wait_port_writable(struct port *port, bool nonblock)
33107diff --git a/drivers/clocksource/arm_generic.c b/drivers/clocksource/arm_generic.c
33108index 8ae1a61..9c00613 100644
33109--- a/drivers/clocksource/arm_generic.c
33110+++ b/drivers/clocksource/arm_generic.c
33111@@ -181,7 +181,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
33112 return NOTIFY_OK;
33113 }
33114
33115-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
33116+static struct notifier_block arch_timer_cpu_nb = {
33117 .notifier_call = arch_timer_cpu_notify,
33118 };
33119
33120diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
33121index 1f93dbd..edf95ff 100644
33122--- a/drivers/cpufreq/cpufreq.c
33123+++ b/drivers/cpufreq/cpufreq.c
33124@@ -1843,7 +1843,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
33125 return NOTIFY_OK;
33126 }
33127
33128-static struct notifier_block __refdata cpufreq_cpu_notifier = {
33129+static struct notifier_block cpufreq_cpu_notifier = {
33130 .notifier_call = cpufreq_cpu_callback,
33131 };
33132
33133diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
33134index 9d7732b..0b1a793 100644
33135--- a/drivers/cpufreq/cpufreq_stats.c
33136+++ b/drivers/cpufreq/cpufreq_stats.c
33137@@ -340,7 +340,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
33138 }
33139
33140 /* priority=1 so this will get called before cpufreq_remove_dev */
33141-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
33142+static struct notifier_block cpufreq_stat_cpu_notifier = {
33143 .notifier_call = cpufreq_stat_cpu_callback,
33144 .priority = 1,
33145 };
33146diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
33147index 3315e4b..fc38316 100644
33148--- a/drivers/dma/sh/shdma.c
33149+++ b/drivers/dma/sh/shdma.c
33150@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
33151 return ret;
33152 }
33153
33154-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
33155+static struct notifier_block sh_dmae_nmi_notifier = {
33156 .notifier_call = sh_dmae_nmi_handler,
33157
33158 /* Run before NMI debug handler and KGDB */
33159diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
33160index 0056c4d..725934f 100644
33161--- a/drivers/edac/edac_pci_sysfs.c
33162+++ b/drivers/edac/edac_pci_sysfs.c
33163@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
33164 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
33165 static int edac_pci_poll_msec = 1000; /* one second workq period */
33166
33167-static atomic_t pci_parity_count = ATOMIC_INIT(0);
33168-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
33169+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
33170+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
33171
33172 static struct kobject *edac_pci_top_main_kobj;
33173 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
33174@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33175 edac_printk(KERN_CRIT, EDAC_PCI,
33176 "Signaled System Error on %s\n",
33177 pci_name(dev));
33178- atomic_inc(&pci_nonparity_count);
33179+ atomic_inc_unchecked(&pci_nonparity_count);
33180 }
33181
33182 if (status & (PCI_STATUS_PARITY)) {
33183@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33184 "Master Data Parity Error on %s\n",
33185 pci_name(dev));
33186
33187- atomic_inc(&pci_parity_count);
33188+ atomic_inc_unchecked(&pci_parity_count);
33189 }
33190
33191 if (status & (PCI_STATUS_DETECTED_PARITY)) {
33192@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33193 "Detected Parity Error on %s\n",
33194 pci_name(dev));
33195
33196- atomic_inc(&pci_parity_count);
33197+ atomic_inc_unchecked(&pci_parity_count);
33198 }
33199 }
33200
33201@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33202 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
33203 "Signaled System Error on %s\n",
33204 pci_name(dev));
33205- atomic_inc(&pci_nonparity_count);
33206+ atomic_inc_unchecked(&pci_nonparity_count);
33207 }
33208
33209 if (status & (PCI_STATUS_PARITY)) {
33210@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33211 "Master Data Parity Error on "
33212 "%s\n", pci_name(dev));
33213
33214- atomic_inc(&pci_parity_count);
33215+ atomic_inc_unchecked(&pci_parity_count);
33216 }
33217
33218 if (status & (PCI_STATUS_DETECTED_PARITY)) {
33219@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33220 "Detected Parity Error on %s\n",
33221 pci_name(dev));
33222
33223- atomic_inc(&pci_parity_count);
33224+ atomic_inc_unchecked(&pci_parity_count);
33225 }
33226 }
33227 }
33228@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
33229 if (!check_pci_errors)
33230 return;
33231
33232- before_count = atomic_read(&pci_parity_count);
33233+ before_count = atomic_read_unchecked(&pci_parity_count);
33234
33235 /* scan all PCI devices looking for a Parity Error on devices and
33236 * bridges.
33237@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
33238 /* Only if operator has selected panic on PCI Error */
33239 if (edac_pci_get_panic_on_pe()) {
33240 /* If the count is different 'after' from 'before' */
33241- if (before_count != atomic_read(&pci_parity_count))
33242+ if (before_count != atomic_read_unchecked(&pci_parity_count))
33243 panic("EDAC: PCI Parity Error");
33244 }
33245 }
33246diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
33247index 6796799..99e8377 100644
33248--- a/drivers/edac/mce_amd.h
33249+++ b/drivers/edac/mce_amd.h
33250@@ -78,7 +78,7 @@ extern const char * const ii_msgs[];
33251 struct amd_decoder_ops {
33252 bool (*mc0_mce)(u16, u8);
33253 bool (*mc1_mce)(u16, u8);
33254-};
33255+} __no_const;
33256
33257 void amd_report_gart_errors(bool);
33258 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
33259diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
33260index 57ea7f4..789e3c3 100644
33261--- a/drivers/firewire/core-card.c
33262+++ b/drivers/firewire/core-card.c
33263@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
33264
33265 void fw_core_remove_card(struct fw_card *card)
33266 {
33267- struct fw_card_driver dummy_driver = dummy_driver_template;
33268+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
33269
33270 card->driver->update_phy_reg(card, 4,
33271 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
33272diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
33273index f8d2287..5aaf4db 100644
33274--- a/drivers/firewire/core-cdev.c
33275+++ b/drivers/firewire/core-cdev.c
33276@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
33277 int ret;
33278
33279 if ((request->channels == 0 && request->bandwidth == 0) ||
33280- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
33281- request->bandwidth < 0)
33282+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
33283 return -EINVAL;
33284
33285 r = kmalloc(sizeof(*r), GFP_KERNEL);
33286diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
33287index 28a94c7..58da63a 100644
33288--- a/drivers/firewire/core-transaction.c
33289+++ b/drivers/firewire/core-transaction.c
33290@@ -38,6 +38,7 @@
33291 #include <linux/timer.h>
33292 #include <linux/types.h>
33293 #include <linux/workqueue.h>
33294+#include <linux/sched.h>
33295
33296 #include <asm/byteorder.h>
33297
33298diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
33299index 515a42c..5ecf3ba 100644
33300--- a/drivers/firewire/core.h
33301+++ b/drivers/firewire/core.h
33302@@ -111,6 +111,7 @@ struct fw_card_driver {
33303
33304 int (*stop_iso)(struct fw_iso_context *ctx);
33305 };
33306+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
33307
33308 void fw_card_initialize(struct fw_card *card,
33309 const struct fw_card_driver *driver, struct device *device);
33310diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
33311index 982f1f5..d21e5da 100644
33312--- a/drivers/firmware/dmi_scan.c
33313+++ b/drivers/firmware/dmi_scan.c
33314@@ -491,11 +491,6 @@ void __init dmi_scan_machine(void)
33315 }
33316 }
33317 else {
33318- /*
33319- * no iounmap() for that ioremap(); it would be a no-op, but
33320- * it's so early in setup that sucker gets confused into doing
33321- * what it shouldn't if we actually call it.
33322- */
33323 p = dmi_ioremap(0xF0000, 0x10000);
33324 if (p == NULL)
33325 goto error;
33326@@ -770,7 +765,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
33327 if (buf == NULL)
33328 return -1;
33329
33330- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
33331+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
33332
33333 iounmap(buf);
33334 return 0;
33335diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
33336index f5596db..9355ce6 100644
33337--- a/drivers/firmware/efivars.c
33338+++ b/drivers/firmware/efivars.c
33339@@ -132,7 +132,7 @@ struct efivar_attribute {
33340 };
33341
33342 static struct efivars __efivars;
33343-static struct efivar_operations ops;
33344+static efivar_operations_no_const ops __read_only;
33345
33346 #define PSTORE_EFI_ATTRIBUTES \
33347 (EFI_VARIABLE_NON_VOLATILE | \
33348diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
33349index 9902732..64b62dd 100644
33350--- a/drivers/gpio/gpio-vr41xx.c
33351+++ b/drivers/gpio/gpio-vr41xx.c
33352@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
33353 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
33354 maskl, pendl, maskh, pendh);
33355
33356- atomic_inc(&irq_err_count);
33357+ atomic_inc_unchecked(&irq_err_count);
33358
33359 return -EINVAL;
33360 }
33361diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
33362index 7b2d378..cc947ea 100644
33363--- a/drivers/gpu/drm/drm_crtc_helper.c
33364+++ b/drivers/gpu/drm/drm_crtc_helper.c
33365@@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
33366 struct drm_crtc *tmp;
33367 int crtc_mask = 1;
33368
33369- WARN(!crtc, "checking null crtc?\n");
33370+ BUG_ON(!crtc);
33371
33372 dev = crtc->dev;
33373
33374diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
33375index be174ca..0bcbb71 100644
33376--- a/drivers/gpu/drm/drm_drv.c
33377+++ b/drivers/gpu/drm/drm_drv.c
33378@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
33379 /**
33380 * Copy and IOCTL return string to user space
33381 */
33382-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
33383+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
33384 {
33385 int len;
33386
33387@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
33388 return -ENODEV;
33389
33390 atomic_inc(&dev->ioctl_count);
33391- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
33392+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
33393 ++file_priv->ioctl_count;
33394
33395 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
33396diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
33397index 133b413..fd68225 100644
33398--- a/drivers/gpu/drm/drm_fops.c
33399+++ b/drivers/gpu/drm/drm_fops.c
33400@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
33401 }
33402
33403 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
33404- atomic_set(&dev->counts[i], 0);
33405+ atomic_set_unchecked(&dev->counts[i], 0);
33406
33407 dev->sigdata.lock = NULL;
33408
33409@@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
33410 if (drm_device_is_unplugged(dev))
33411 return -ENODEV;
33412
33413- if (!dev->open_count++)
33414+ if (local_inc_return(&dev->open_count) == 1)
33415 need_setup = 1;
33416 mutex_lock(&dev->struct_mutex);
33417 old_mapping = dev->dev_mapping;
33418@@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
33419 retcode = drm_open_helper(inode, filp, dev);
33420 if (retcode)
33421 goto err_undo;
33422- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
33423+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
33424 if (need_setup) {
33425 retcode = drm_setup(dev);
33426 if (retcode)
33427@@ -164,7 +164,7 @@ err_undo:
33428 iput(container_of(dev->dev_mapping, struct inode, i_data));
33429 dev->dev_mapping = old_mapping;
33430 mutex_unlock(&dev->struct_mutex);
33431- dev->open_count--;
33432+ local_dec(&dev->open_count);
33433 return retcode;
33434 }
33435 EXPORT_SYMBOL(drm_open);
33436@@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
33437
33438 mutex_lock(&drm_global_mutex);
33439
33440- DRM_DEBUG("open_count = %d\n", dev->open_count);
33441+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
33442
33443 if (dev->driver->preclose)
33444 dev->driver->preclose(dev, file_priv);
33445@@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
33446 * Begin inline drm_release
33447 */
33448
33449- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
33450+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
33451 task_pid_nr(current),
33452 (long)old_encode_dev(file_priv->minor->device),
33453- dev->open_count);
33454+ local_read(&dev->open_count));
33455
33456 /* Release any auth tokens that might point to this file_priv,
33457 (do that under the drm_global_mutex) */
33458@@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
33459 * End inline drm_release
33460 */
33461
33462- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
33463- if (!--dev->open_count) {
33464+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
33465+ if (local_dec_and_test(&dev->open_count)) {
33466 if (atomic_read(&dev->ioctl_count)) {
33467 DRM_ERROR("Device busy: %d\n",
33468 atomic_read(&dev->ioctl_count));
33469diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
33470index f731116..629842c 100644
33471--- a/drivers/gpu/drm/drm_global.c
33472+++ b/drivers/gpu/drm/drm_global.c
33473@@ -36,7 +36,7 @@
33474 struct drm_global_item {
33475 struct mutex mutex;
33476 void *object;
33477- int refcount;
33478+ atomic_t refcount;
33479 };
33480
33481 static struct drm_global_item glob[DRM_GLOBAL_NUM];
33482@@ -49,7 +49,7 @@ void drm_global_init(void)
33483 struct drm_global_item *item = &glob[i];
33484 mutex_init(&item->mutex);
33485 item->object = NULL;
33486- item->refcount = 0;
33487+ atomic_set(&item->refcount, 0);
33488 }
33489 }
33490
33491@@ -59,7 +59,7 @@ void drm_global_release(void)
33492 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
33493 struct drm_global_item *item = &glob[i];
33494 BUG_ON(item->object != NULL);
33495- BUG_ON(item->refcount != 0);
33496+ BUG_ON(atomic_read(&item->refcount) != 0);
33497 }
33498 }
33499
33500@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
33501 void *object;
33502
33503 mutex_lock(&item->mutex);
33504- if (item->refcount == 0) {
33505+ if (atomic_read(&item->refcount) == 0) {
33506 item->object = kzalloc(ref->size, GFP_KERNEL);
33507 if (unlikely(item->object == NULL)) {
33508 ret = -ENOMEM;
33509@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
33510 goto out_err;
33511
33512 }
33513- ++item->refcount;
33514+ atomic_inc(&item->refcount);
33515 ref->object = item->object;
33516 object = item->object;
33517 mutex_unlock(&item->mutex);
33518@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
33519 struct drm_global_item *item = &glob[ref->global_type];
33520
33521 mutex_lock(&item->mutex);
33522- BUG_ON(item->refcount == 0);
33523+ BUG_ON(atomic_read(&item->refcount) == 0);
33524 BUG_ON(ref->object != item->object);
33525- if (--item->refcount == 0) {
33526+ if (atomic_dec_and_test(&item->refcount)) {
33527 ref->release(ref);
33528 item->object = NULL;
33529 }
33530diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
33531index d4b20ce..77a8d41 100644
33532--- a/drivers/gpu/drm/drm_info.c
33533+++ b/drivers/gpu/drm/drm_info.c
33534@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
33535 struct drm_local_map *map;
33536 struct drm_map_list *r_list;
33537
33538- /* Hardcoded from _DRM_FRAME_BUFFER,
33539- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
33540- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
33541- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
33542+ static const char * const types[] = {
33543+ [_DRM_FRAME_BUFFER] = "FB",
33544+ [_DRM_REGISTERS] = "REG",
33545+ [_DRM_SHM] = "SHM",
33546+ [_DRM_AGP] = "AGP",
33547+ [_DRM_SCATTER_GATHER] = "SG",
33548+ [_DRM_CONSISTENT] = "PCI",
33549+ [_DRM_GEM] = "GEM" };
33550 const char *type;
33551 int i;
33552
33553@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
33554 map = r_list->map;
33555 if (!map)
33556 continue;
33557- if (map->type < 0 || map->type > 5)
33558+ if (map->type >= ARRAY_SIZE(types))
33559 type = "??";
33560 else
33561 type = types[map->type];
33562@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
33563 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
33564 vma->vm_flags & VM_LOCKED ? 'l' : '-',
33565 vma->vm_flags & VM_IO ? 'i' : '-',
33566+#ifdef CONFIG_GRKERNSEC_HIDESYM
33567+ 0);
33568+#else
33569 vma->vm_pgoff);
33570+#endif
33571
33572 #if defined(__i386__)
33573 pgprot = pgprot_val(vma->vm_page_prot);
33574diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
33575index 2f4c434..764794b 100644
33576--- a/drivers/gpu/drm/drm_ioc32.c
33577+++ b/drivers/gpu/drm/drm_ioc32.c
33578@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
33579 request = compat_alloc_user_space(nbytes);
33580 if (!access_ok(VERIFY_WRITE, request, nbytes))
33581 return -EFAULT;
33582- list = (struct drm_buf_desc *) (request + 1);
33583+ list = (struct drm_buf_desc __user *) (request + 1);
33584
33585 if (__put_user(count, &request->count)
33586 || __put_user(list, &request->list))
33587@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
33588 request = compat_alloc_user_space(nbytes);
33589 if (!access_ok(VERIFY_WRITE, request, nbytes))
33590 return -EFAULT;
33591- list = (struct drm_buf_pub *) (request + 1);
33592+ list = (struct drm_buf_pub __user *) (request + 1);
33593
33594 if (__put_user(count, &request->count)
33595 || __put_user(list, &request->list))
33596diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
33597index e77bd8b..1571b85 100644
33598--- a/drivers/gpu/drm/drm_ioctl.c
33599+++ b/drivers/gpu/drm/drm_ioctl.c
33600@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
33601 stats->data[i].value =
33602 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
33603 else
33604- stats->data[i].value = atomic_read(&dev->counts[i]);
33605+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
33606 stats->data[i].type = dev->types[i];
33607 }
33608
33609diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
33610index d752c96..fe08455 100644
33611--- a/drivers/gpu/drm/drm_lock.c
33612+++ b/drivers/gpu/drm/drm_lock.c
33613@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
33614 if (drm_lock_take(&master->lock, lock->context)) {
33615 master->lock.file_priv = file_priv;
33616 master->lock.lock_time = jiffies;
33617- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
33618+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
33619 break; /* Got lock */
33620 }
33621
33622@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
33623 return -EINVAL;
33624 }
33625
33626- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
33627+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
33628
33629 if (drm_lock_free(&master->lock, lock->context)) {
33630 /* FIXME: Should really bail out here. */
33631diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
33632index 200e104..59facda 100644
33633--- a/drivers/gpu/drm/drm_stub.c
33634+++ b/drivers/gpu/drm/drm_stub.c
33635@@ -516,7 +516,7 @@ void drm_unplug_dev(struct drm_device *dev)
33636
33637 drm_device_set_unplugged(dev);
33638
33639- if (dev->open_count == 0) {
33640+ if (local_read(&dev->open_count) == 0) {
33641 drm_put_dev(dev);
33642 }
33643 mutex_unlock(&drm_global_mutex);
33644diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
33645index 004ecdf..db1f6e0 100644
33646--- a/drivers/gpu/drm/i810/i810_dma.c
33647+++ b/drivers/gpu/drm/i810/i810_dma.c
33648@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
33649 dma->buflist[vertex->idx],
33650 vertex->discard, vertex->used);
33651
33652- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
33653- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
33654+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
33655+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
33656 sarea_priv->last_enqueue = dev_priv->counter - 1;
33657 sarea_priv->last_dispatch = (int)hw_status[5];
33658
33659@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
33660 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
33661 mc->last_render);
33662
33663- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
33664- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
33665+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
33666+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
33667 sarea_priv->last_enqueue = dev_priv->counter - 1;
33668 sarea_priv->last_dispatch = (int)hw_status[5];
33669
33670diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
33671index 6e0acad..93c8289 100644
33672--- a/drivers/gpu/drm/i810/i810_drv.h
33673+++ b/drivers/gpu/drm/i810/i810_drv.h
33674@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
33675 int page_flipping;
33676
33677 wait_queue_head_t irq_queue;
33678- atomic_t irq_received;
33679- atomic_t irq_emitted;
33680+ atomic_unchecked_t irq_received;
33681+ atomic_unchecked_t irq_emitted;
33682
33683 int front_offset;
33684 } drm_i810_private_t;
33685diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
33686index 9d4a2c2..32a119f 100644
33687--- a/drivers/gpu/drm/i915/i915_debugfs.c
33688+++ b/drivers/gpu/drm/i915/i915_debugfs.c
33689@@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
33690 I915_READ(GTIMR));
33691 }
33692 seq_printf(m, "Interrupts received: %d\n",
33693- atomic_read(&dev_priv->irq_received));
33694+ atomic_read_unchecked(&dev_priv->irq_received));
33695 for_each_ring(ring, dev_priv, i) {
33696 if (IS_GEN6(dev) || IS_GEN7(dev)) {
33697 seq_printf(m,
33698diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
33699index 99daa89..84ebd44 100644
33700--- a/drivers/gpu/drm/i915/i915_dma.c
33701+++ b/drivers/gpu/drm/i915/i915_dma.c
33702@@ -1253,7 +1253,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
33703 bool can_switch;
33704
33705 spin_lock(&dev->count_lock);
33706- can_switch = (dev->open_count == 0);
33707+ can_switch = (local_read(&dev->open_count) == 0);
33708 spin_unlock(&dev->count_lock);
33709 return can_switch;
33710 }
33711diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
33712index 12ab3bd..b3bed3b 100644
33713--- a/drivers/gpu/drm/i915/i915_drv.h
33714+++ b/drivers/gpu/drm/i915/i915_drv.h
33715@@ -656,7 +656,7 @@ typedef struct drm_i915_private {
33716 drm_dma_handle_t *status_page_dmah;
33717 struct resource mch_res;
33718
33719- atomic_t irq_received;
33720+ atomic_unchecked_t irq_received;
33721
33722 /* protects the irq masks */
33723 spinlock_t irq_lock;
33724@@ -1102,7 +1102,7 @@ struct drm_i915_gem_object {
33725 * will be page flipped away on the next vblank. When it
33726 * reaches 0, dev_priv->pending_flip_queue will be woken up.
33727 */
33728- atomic_t pending_flip;
33729+ atomic_unchecked_t pending_flip;
33730 };
33731 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
33732
33733@@ -1633,7 +1633,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
33734 struct drm_i915_private *dev_priv, unsigned port);
33735 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
33736 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
33737-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
33738+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
33739 {
33740 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
33741 }
33742diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
33743index 26d08bb..fccb984 100644
33744--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
33745+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
33746@@ -672,7 +672,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
33747 i915_gem_clflush_object(obj);
33748
33749 if (obj->base.pending_write_domain)
33750- flips |= atomic_read(&obj->pending_flip);
33751+ flips |= atomic_read_unchecked(&obj->pending_flip);
33752
33753 flush_domains |= obj->base.write_domain;
33754 }
33755@@ -703,9 +703,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
33756
33757 static int
33758 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
33759- int count)
33760+ unsigned int count)
33761 {
33762- int i;
33763+ unsigned int i;
33764
33765 for (i = 0; i < count; i++) {
33766 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
33767diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
33768index fe84338..a863190 100644
33769--- a/drivers/gpu/drm/i915/i915_irq.c
33770+++ b/drivers/gpu/drm/i915/i915_irq.c
33771@@ -535,7 +535,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
33772 u32 pipe_stats[I915_MAX_PIPES];
33773 bool blc_event;
33774
33775- atomic_inc(&dev_priv->irq_received);
33776+ atomic_inc_unchecked(&dev_priv->irq_received);
33777
33778 while (true) {
33779 iir = I915_READ(VLV_IIR);
33780@@ -688,7 +688,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
33781 irqreturn_t ret = IRQ_NONE;
33782 int i;
33783
33784- atomic_inc(&dev_priv->irq_received);
33785+ atomic_inc_unchecked(&dev_priv->irq_received);
33786
33787 /* disable master interrupt before clearing iir */
33788 de_ier = I915_READ(DEIER);
33789@@ -760,7 +760,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
33790 int ret = IRQ_NONE;
33791 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
33792
33793- atomic_inc(&dev_priv->irq_received);
33794+ atomic_inc_unchecked(&dev_priv->irq_received);
33795
33796 /* disable master interrupt before clearing iir */
33797 de_ier = I915_READ(DEIER);
33798@@ -1787,7 +1787,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
33799 {
33800 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33801
33802- atomic_set(&dev_priv->irq_received, 0);
33803+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33804
33805 I915_WRITE(HWSTAM, 0xeffe);
33806
33807@@ -1813,7 +1813,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
33808 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33809 int pipe;
33810
33811- atomic_set(&dev_priv->irq_received, 0);
33812+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33813
33814 /* VLV magic */
33815 I915_WRITE(VLV_IMR, 0);
33816@@ -2108,7 +2108,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
33817 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33818 int pipe;
33819
33820- atomic_set(&dev_priv->irq_received, 0);
33821+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33822
33823 for_each_pipe(pipe)
33824 I915_WRITE(PIPESTAT(pipe), 0);
33825@@ -2159,7 +2159,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
33826 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
33827 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
33828
33829- atomic_inc(&dev_priv->irq_received);
33830+ atomic_inc_unchecked(&dev_priv->irq_received);
33831
33832 iir = I915_READ16(IIR);
33833 if (iir == 0)
33834@@ -2244,7 +2244,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
33835 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33836 int pipe;
33837
33838- atomic_set(&dev_priv->irq_received, 0);
33839+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33840
33841 if (I915_HAS_HOTPLUG(dev)) {
33842 I915_WRITE(PORT_HOTPLUG_EN, 0);
33843@@ -2339,7 +2339,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
33844 };
33845 int pipe, ret = IRQ_NONE;
33846
33847- atomic_inc(&dev_priv->irq_received);
33848+ atomic_inc_unchecked(&dev_priv->irq_received);
33849
33850 iir = I915_READ(IIR);
33851 do {
33852@@ -2465,7 +2465,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
33853 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33854 int pipe;
33855
33856- atomic_set(&dev_priv->irq_received, 0);
33857+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33858
33859 I915_WRITE(PORT_HOTPLUG_EN, 0);
33860 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
33861@@ -2572,7 +2572,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
33862 int irq_received;
33863 int ret = IRQ_NONE, pipe;
33864
33865- atomic_inc(&dev_priv->irq_received);
33866+ atomic_inc_unchecked(&dev_priv->irq_received);
33867
33868 iir = I915_READ(IIR);
33869
33870diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
33871index da1ad9c..10d368b 100644
33872--- a/drivers/gpu/drm/i915/intel_display.c
33873+++ b/drivers/gpu/drm/i915/intel_display.c
33874@@ -2244,7 +2244,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
33875
33876 wait_event(dev_priv->pending_flip_queue,
33877 atomic_read(&dev_priv->mm.wedged) ||
33878- atomic_read(&obj->pending_flip) == 0);
33879+ atomic_read_unchecked(&obj->pending_flip) == 0);
33880
33881 /* Big Hammer, we also need to ensure that any pending
33882 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
33883@@ -7109,8 +7109,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
33884
33885 obj = work->old_fb_obj;
33886
33887- atomic_clear_mask(1 << intel_crtc->plane,
33888- &obj->pending_flip.counter);
33889+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
33890 wake_up(&dev_priv->pending_flip_queue);
33891
33892 queue_work(dev_priv->wq, &work->work);
33893@@ -7477,7 +7476,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33894 /* Block clients from rendering to the new back buffer until
33895 * the flip occurs and the object is no longer visible.
33896 */
33897- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33898+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33899 atomic_inc(&intel_crtc->unpin_work_count);
33900
33901 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
33902@@ -7494,7 +7493,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33903
33904 cleanup_pending:
33905 atomic_dec(&intel_crtc->unpin_work_count);
33906- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33907+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33908 drm_gem_object_unreference(&work->old_fb_obj->base);
33909 drm_gem_object_unreference(&obj->base);
33910 mutex_unlock(&dev->struct_mutex);
33911diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
33912index 54558a0..2d97005 100644
33913--- a/drivers/gpu/drm/mga/mga_drv.h
33914+++ b/drivers/gpu/drm/mga/mga_drv.h
33915@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
33916 u32 clear_cmd;
33917 u32 maccess;
33918
33919- atomic_t vbl_received; /**< Number of vblanks received. */
33920+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
33921 wait_queue_head_t fence_queue;
33922- atomic_t last_fence_retired;
33923+ atomic_unchecked_t last_fence_retired;
33924 u32 next_fence_to_post;
33925
33926 unsigned int fb_cpp;
33927diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
33928index 598c281..60d590e 100644
33929--- a/drivers/gpu/drm/mga/mga_irq.c
33930+++ b/drivers/gpu/drm/mga/mga_irq.c
33931@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
33932 if (crtc != 0)
33933 return 0;
33934
33935- return atomic_read(&dev_priv->vbl_received);
33936+ return atomic_read_unchecked(&dev_priv->vbl_received);
33937 }
33938
33939
33940@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33941 /* VBLANK interrupt */
33942 if (status & MGA_VLINEPEN) {
33943 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
33944- atomic_inc(&dev_priv->vbl_received);
33945+ atomic_inc_unchecked(&dev_priv->vbl_received);
33946 drm_handle_vblank(dev, 0);
33947 handled = 1;
33948 }
33949@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33950 if ((prim_start & ~0x03) != (prim_end & ~0x03))
33951 MGA_WRITE(MGA_PRIMEND, prim_end);
33952
33953- atomic_inc(&dev_priv->last_fence_retired);
33954+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
33955 DRM_WAKEUP(&dev_priv->fence_queue);
33956 handled = 1;
33957 }
33958@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
33959 * using fences.
33960 */
33961 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
33962- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
33963+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
33964 - *sequence) <= (1 << 23)));
33965
33966 *sequence = cur_fence;
33967diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
33968index 865eddf..62c4cc3 100644
33969--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
33970+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
33971@@ -1015,7 +1015,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
33972 struct bit_table {
33973 const char id;
33974 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
33975-};
33976+} __no_const;
33977
33978 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
33979
33980diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
33981index aa89eb9..d45d38b 100644
33982--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
33983+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
33984@@ -80,7 +80,7 @@ struct nouveau_drm {
33985 struct drm_global_reference mem_global_ref;
33986 struct ttm_bo_global_ref bo_global_ref;
33987 struct ttm_bo_device bdev;
33988- atomic_t validate_sequence;
33989+ atomic_unchecked_t validate_sequence;
33990 int (*move)(struct nouveau_channel *,
33991 struct ttm_buffer_object *,
33992 struct ttm_mem_reg *, struct ttm_mem_reg *);
33993diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
33994index cdb83ac..27f0a16 100644
33995--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
33996+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
33997@@ -43,7 +43,7 @@ struct nouveau_fence_priv {
33998 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
33999 struct nouveau_channel *);
34000 u32 (*read)(struct nouveau_channel *);
34001-};
34002+} __no_const;
34003
34004 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
34005
34006diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
34007index 8bf695c..9fbc90a 100644
34008--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
34009+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
34010@@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
34011 int trycnt = 0;
34012 int ret, i;
34013
34014- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
34015+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
34016 retry:
34017 if (++trycnt > 100000) {
34018 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
34019diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
34020index 25d3495..d81aaf6 100644
34021--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
34022+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
34023@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
34024 bool can_switch;
34025
34026 spin_lock(&dev->count_lock);
34027- can_switch = (dev->open_count == 0);
34028+ can_switch = (local_read(&dev->open_count) == 0);
34029 spin_unlock(&dev->count_lock);
34030 return can_switch;
34031 }
34032diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
34033index d4660cf..70dbe65 100644
34034--- a/drivers/gpu/drm/r128/r128_cce.c
34035+++ b/drivers/gpu/drm/r128/r128_cce.c
34036@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
34037
34038 /* GH: Simple idle check.
34039 */
34040- atomic_set(&dev_priv->idle_count, 0);
34041+ atomic_set_unchecked(&dev_priv->idle_count, 0);
34042
34043 /* We don't support anything other than bus-mastering ring mode,
34044 * but the ring can be in either AGP or PCI space for the ring
34045diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
34046index 930c71b..499aded 100644
34047--- a/drivers/gpu/drm/r128/r128_drv.h
34048+++ b/drivers/gpu/drm/r128/r128_drv.h
34049@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
34050 int is_pci;
34051 unsigned long cce_buffers_offset;
34052
34053- atomic_t idle_count;
34054+ atomic_unchecked_t idle_count;
34055
34056 int page_flipping;
34057 int current_page;
34058 u32 crtc_offset;
34059 u32 crtc_offset_cntl;
34060
34061- atomic_t vbl_received;
34062+ atomic_unchecked_t vbl_received;
34063
34064 u32 color_fmt;
34065 unsigned int front_offset;
34066diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
34067index 2ea4f09..d391371 100644
34068--- a/drivers/gpu/drm/r128/r128_irq.c
34069+++ b/drivers/gpu/drm/r128/r128_irq.c
34070@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
34071 if (crtc != 0)
34072 return 0;
34073
34074- return atomic_read(&dev_priv->vbl_received);
34075+ return atomic_read_unchecked(&dev_priv->vbl_received);
34076 }
34077
34078 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
34079@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
34080 /* VBLANK interrupt */
34081 if (status & R128_CRTC_VBLANK_INT) {
34082 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
34083- atomic_inc(&dev_priv->vbl_received);
34084+ atomic_inc_unchecked(&dev_priv->vbl_received);
34085 drm_handle_vblank(dev, 0);
34086 return IRQ_HANDLED;
34087 }
34088diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
34089index 19bb7e6..de7e2a2 100644
34090--- a/drivers/gpu/drm/r128/r128_state.c
34091+++ b/drivers/gpu/drm/r128/r128_state.c
34092@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
34093
34094 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
34095 {
34096- if (atomic_read(&dev_priv->idle_count) == 0)
34097+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
34098 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
34099 else
34100- atomic_set(&dev_priv->idle_count, 0);
34101+ atomic_set_unchecked(&dev_priv->idle_count, 0);
34102 }
34103
34104 #endif
34105diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
34106index 5a82b6b..9e69c73 100644
34107--- a/drivers/gpu/drm/radeon/mkregtable.c
34108+++ b/drivers/gpu/drm/radeon/mkregtable.c
34109@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
34110 regex_t mask_rex;
34111 regmatch_t match[4];
34112 char buf[1024];
34113- size_t end;
34114+ long end;
34115 int len;
34116 int done = 0;
34117 int r;
34118 unsigned o;
34119 struct offset *offset;
34120 char last_reg_s[10];
34121- int last_reg;
34122+ unsigned long last_reg;
34123
34124 if (regcomp
34125 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
34126diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
34127index 0d6562b..a154330 100644
34128--- a/drivers/gpu/drm/radeon/radeon_device.c
34129+++ b/drivers/gpu/drm/radeon/radeon_device.c
34130@@ -969,7 +969,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
34131 bool can_switch;
34132
34133 spin_lock(&dev->count_lock);
34134- can_switch = (dev->open_count == 0);
34135+ can_switch = (local_read(&dev->open_count) == 0);
34136 spin_unlock(&dev->count_lock);
34137 return can_switch;
34138 }
34139diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
34140index e7fdf16..f4f6490 100644
34141--- a/drivers/gpu/drm/radeon/radeon_drv.h
34142+++ b/drivers/gpu/drm/radeon/radeon_drv.h
34143@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
34144
34145 /* SW interrupt */
34146 wait_queue_head_t swi_queue;
34147- atomic_t swi_emitted;
34148+ atomic_unchecked_t swi_emitted;
34149 int vblank_crtc;
34150 uint32_t irq_enable_reg;
34151 uint32_t r500_disp_irq_reg;
34152diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
34153index c180df8..cd80dd2d 100644
34154--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
34155+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
34156@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
34157 request = compat_alloc_user_space(sizeof(*request));
34158 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
34159 || __put_user(req32.param, &request->param)
34160- || __put_user((void __user *)(unsigned long)req32.value,
34161+ || __put_user((unsigned long)req32.value,
34162 &request->value))
34163 return -EFAULT;
34164
34165diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
34166index e771033..a0bc6b3 100644
34167--- a/drivers/gpu/drm/radeon/radeon_irq.c
34168+++ b/drivers/gpu/drm/radeon/radeon_irq.c
34169@@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
34170 unsigned int ret;
34171 RING_LOCALS;
34172
34173- atomic_inc(&dev_priv->swi_emitted);
34174- ret = atomic_read(&dev_priv->swi_emitted);
34175+ atomic_inc_unchecked(&dev_priv->swi_emitted);
34176+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
34177
34178 BEGIN_RING(4);
34179 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
34180@@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
34181 drm_radeon_private_t *dev_priv =
34182 (drm_radeon_private_t *) dev->dev_private;
34183
34184- atomic_set(&dev_priv->swi_emitted, 0);
34185+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
34186 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
34187
34188 dev->max_vblank_count = 0x001fffff;
34189diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
34190index 8e9057b..af6dacb 100644
34191--- a/drivers/gpu/drm/radeon/radeon_state.c
34192+++ b/drivers/gpu/drm/radeon/radeon_state.c
34193@@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
34194 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
34195 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
34196
34197- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
34198+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
34199 sarea_priv->nbox * sizeof(depth_boxes[0])))
34200 return -EFAULT;
34201
34202@@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
34203 {
34204 drm_radeon_private_t *dev_priv = dev->dev_private;
34205 drm_radeon_getparam_t *param = data;
34206- int value;
34207+ int value = 0;
34208
34209 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
34210
34211diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
34212index 93f760e..33d9839 100644
34213--- a/drivers/gpu/drm/radeon/radeon_ttm.c
34214+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
34215@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
34216 man->size = size >> PAGE_SHIFT;
34217 }
34218
34219-static struct vm_operations_struct radeon_ttm_vm_ops;
34220+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
34221 static const struct vm_operations_struct *ttm_vm_ops = NULL;
34222
34223 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
34224@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
34225 }
34226 if (unlikely(ttm_vm_ops == NULL)) {
34227 ttm_vm_ops = vma->vm_ops;
34228+ pax_open_kernel();
34229 radeon_ttm_vm_ops = *ttm_vm_ops;
34230 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
34231+ pax_close_kernel();
34232 }
34233 vma->vm_ops = &radeon_ttm_vm_ops;
34234 return 0;
34235diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
34236index 5706d2a..17aedaa 100644
34237--- a/drivers/gpu/drm/radeon/rs690.c
34238+++ b/drivers/gpu/drm/radeon/rs690.c
34239@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
34240 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
34241 rdev->pm.sideport_bandwidth.full)
34242 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
34243- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
34244+ read_delay_latency.full = dfixed_const(800 * 1000);
34245 read_delay_latency.full = dfixed_div(read_delay_latency,
34246 rdev->pm.igp_sideport_mclk);
34247+ a.full = dfixed_const(370);
34248+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
34249 } else {
34250 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
34251 rdev->pm.k8_bandwidth.full)
34252diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
34253index bd2a3b4..122d9ad 100644
34254--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
34255+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
34256@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
34257 static int ttm_pool_mm_shrink(struct shrinker *shrink,
34258 struct shrink_control *sc)
34259 {
34260- static atomic_t start_pool = ATOMIC_INIT(0);
34261+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
34262 unsigned i;
34263- unsigned pool_offset = atomic_add_return(1, &start_pool);
34264+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
34265 struct ttm_page_pool *pool;
34266 int shrink_pages = sc->nr_to_scan;
34267
34268diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
34269index 893a650..6190d3b 100644
34270--- a/drivers/gpu/drm/via/via_drv.h
34271+++ b/drivers/gpu/drm/via/via_drv.h
34272@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
34273 typedef uint32_t maskarray_t[5];
34274
34275 typedef struct drm_via_irq {
34276- atomic_t irq_received;
34277+ atomic_unchecked_t irq_received;
34278 uint32_t pending_mask;
34279 uint32_t enable_mask;
34280 wait_queue_head_t irq_queue;
34281@@ -75,7 +75,7 @@ typedef struct drm_via_private {
34282 struct timeval last_vblank;
34283 int last_vblank_valid;
34284 unsigned usec_per_vblank;
34285- atomic_t vbl_received;
34286+ atomic_unchecked_t vbl_received;
34287 drm_via_state_t hc_state;
34288 char pci_buf[VIA_PCI_BUF_SIZE];
34289 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
34290diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
34291index ac98964..5dbf512 100644
34292--- a/drivers/gpu/drm/via/via_irq.c
34293+++ b/drivers/gpu/drm/via/via_irq.c
34294@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
34295 if (crtc != 0)
34296 return 0;
34297
34298- return atomic_read(&dev_priv->vbl_received);
34299+ return atomic_read_unchecked(&dev_priv->vbl_received);
34300 }
34301
34302 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34303@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34304
34305 status = VIA_READ(VIA_REG_INTERRUPT);
34306 if (status & VIA_IRQ_VBLANK_PENDING) {
34307- atomic_inc(&dev_priv->vbl_received);
34308- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
34309+ atomic_inc_unchecked(&dev_priv->vbl_received);
34310+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
34311 do_gettimeofday(&cur_vblank);
34312 if (dev_priv->last_vblank_valid) {
34313 dev_priv->usec_per_vblank =
34314@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34315 dev_priv->last_vblank = cur_vblank;
34316 dev_priv->last_vblank_valid = 1;
34317 }
34318- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
34319+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
34320 DRM_DEBUG("US per vblank is: %u\n",
34321 dev_priv->usec_per_vblank);
34322 }
34323@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34324
34325 for (i = 0; i < dev_priv->num_irqs; ++i) {
34326 if (status & cur_irq->pending_mask) {
34327- atomic_inc(&cur_irq->irq_received);
34328+ atomic_inc_unchecked(&cur_irq->irq_received);
34329 DRM_WAKEUP(&cur_irq->irq_queue);
34330 handled = 1;
34331 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
34332@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
34333 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
34334 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
34335 masks[irq][4]));
34336- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
34337+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
34338 } else {
34339 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
34340 (((cur_irq_sequence =
34341- atomic_read(&cur_irq->irq_received)) -
34342+ atomic_read_unchecked(&cur_irq->irq_received)) -
34343 *sequence) <= (1 << 23)));
34344 }
34345 *sequence = cur_irq_sequence;
34346@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
34347 }
34348
34349 for (i = 0; i < dev_priv->num_irqs; ++i) {
34350- atomic_set(&cur_irq->irq_received, 0);
34351+ atomic_set_unchecked(&cur_irq->irq_received, 0);
34352 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
34353 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
34354 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
34355@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
34356 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
34357 case VIA_IRQ_RELATIVE:
34358 irqwait->request.sequence +=
34359- atomic_read(&cur_irq->irq_received);
34360+ atomic_read_unchecked(&cur_irq->irq_received);
34361 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
34362 case VIA_IRQ_ABSOLUTE:
34363 break;
34364diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
34365index 13aeda7..4a952d1 100644
34366--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
34367+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
34368@@ -290,7 +290,7 @@ struct vmw_private {
34369 * Fencing and IRQs.
34370 */
34371
34372- atomic_t marker_seq;
34373+ atomic_unchecked_t marker_seq;
34374 wait_queue_head_t fence_queue;
34375 wait_queue_head_t fifo_queue;
34376 int fence_queue_waiters; /* Protected by hw_mutex */
34377diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
34378index 3eb1486..0a47ee9 100644
34379--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
34380+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
34381@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
34382 (unsigned int) min,
34383 (unsigned int) fifo->capabilities);
34384
34385- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
34386+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
34387 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
34388 vmw_marker_queue_init(&fifo->marker_queue);
34389 return vmw_fifo_send_fence(dev_priv, &dummy);
34390@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
34391 if (reserveable)
34392 iowrite32(bytes, fifo_mem +
34393 SVGA_FIFO_RESERVED);
34394- return fifo_mem + (next_cmd >> 2);
34395+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
34396 } else {
34397 need_bounce = true;
34398 }
34399@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
34400
34401 fm = vmw_fifo_reserve(dev_priv, bytes);
34402 if (unlikely(fm == NULL)) {
34403- *seqno = atomic_read(&dev_priv->marker_seq);
34404+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
34405 ret = -ENOMEM;
34406 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
34407 false, 3*HZ);
34408@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
34409 }
34410
34411 do {
34412- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
34413+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
34414 } while (*seqno == 0);
34415
34416 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
34417diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
34418index 4640adb..e1384ed 100644
34419--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
34420+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
34421@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
34422 * emitted. Then the fence is stale and signaled.
34423 */
34424
34425- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
34426+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
34427 > VMW_FENCE_WRAP);
34428
34429 return ret;
34430@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
34431
34432 if (fifo_idle)
34433 down_read(&fifo_state->rwsem);
34434- signal_seq = atomic_read(&dev_priv->marker_seq);
34435+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
34436 ret = 0;
34437
34438 for (;;) {
34439diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
34440index 8a8725c..afed796 100644
34441--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
34442+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
34443@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
34444 while (!vmw_lag_lt(queue, us)) {
34445 spin_lock(&queue->lock);
34446 if (list_empty(&queue->head))
34447- seqno = atomic_read(&dev_priv->marker_seq);
34448+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
34449 else {
34450 marker = list_first_entry(&queue->head,
34451 struct vmw_marker, head);
34452diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
34453index eb2ee11..6cc50ab 100644
34454--- a/drivers/hid/hid-core.c
34455+++ b/drivers/hid/hid-core.c
34456@@ -2240,7 +2240,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
34457
34458 int hid_add_device(struct hid_device *hdev)
34459 {
34460- static atomic_t id = ATOMIC_INIT(0);
34461+ static atomic_unchecked_t id = ATOMIC_INIT(0);
34462 int ret;
34463
34464 if (WARN_ON(hdev->status & HID_STAT_ADDED))
34465@@ -2274,7 +2274,7 @@ int hid_add_device(struct hid_device *hdev)
34466 /* XXX hack, any other cleaner solution after the driver core
34467 * is converted to allow more than 20 bytes as the device name? */
34468 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
34469- hdev->vendor, hdev->product, atomic_inc_return(&id));
34470+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
34471
34472 hid_debug_register(hdev, dev_name(&hdev->dev));
34473 ret = device_add(&hdev->dev);
34474diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
34475index eec3291..8ed706b 100644
34476--- a/drivers/hid/hid-wiimote-debug.c
34477+++ b/drivers/hid/hid-wiimote-debug.c
34478@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
34479 else if (size == 0)
34480 return -EIO;
34481
34482- if (copy_to_user(u, buf, size))
34483+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
34484 return -EFAULT;
34485
34486 *off += size;
34487diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
34488index 773a2f2..7ce08bc 100644
34489--- a/drivers/hv/channel.c
34490+++ b/drivers/hv/channel.c
34491@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
34492 int ret = 0;
34493 int t;
34494
34495- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
34496- atomic_inc(&vmbus_connection.next_gpadl_handle);
34497+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
34498+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
34499
34500 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
34501 if (ret)
34502diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
34503index 3648f8f..30ef30d 100644
34504--- a/drivers/hv/hv.c
34505+++ b/drivers/hv/hv.c
34506@@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
34507 u64 output_address = (output) ? virt_to_phys(output) : 0;
34508 u32 output_address_hi = output_address >> 32;
34509 u32 output_address_lo = output_address & 0xFFFFFFFF;
34510- void *hypercall_page = hv_context.hypercall_page;
34511+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
34512
34513 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
34514 "=a"(hv_status_lo) : "d" (control_hi),
34515diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
34516index d8d1fad..b91caf7 100644
34517--- a/drivers/hv/hyperv_vmbus.h
34518+++ b/drivers/hv/hyperv_vmbus.h
34519@@ -594,7 +594,7 @@ enum vmbus_connect_state {
34520 struct vmbus_connection {
34521 enum vmbus_connect_state conn_state;
34522
34523- atomic_t next_gpadl_handle;
34524+ atomic_unchecked_t next_gpadl_handle;
34525
34526 /*
34527 * Represents channel interrupts. Each bit position represents a
34528diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
34529index 8e1a9ec..4687821 100644
34530--- a/drivers/hv/vmbus_drv.c
34531+++ b/drivers/hv/vmbus_drv.c
34532@@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
34533 {
34534 int ret = 0;
34535
34536- static atomic_t device_num = ATOMIC_INIT(0);
34537+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
34538
34539 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
34540- atomic_inc_return(&device_num));
34541+ atomic_inc_return_unchecked(&device_num));
34542
34543 child_device_obj->device.bus = &hv_bus;
34544 child_device_obj->device.parent = &hv_acpi_dev->dev;
34545diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
34546index d64923d..72591e8 100644
34547--- a/drivers/hwmon/coretemp.c
34548+++ b/drivers/hwmon/coretemp.c
34549@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
34550 return NOTIFY_OK;
34551 }
34552
34553-static struct notifier_block coretemp_cpu_notifier __refdata = {
34554+static struct notifier_block coretemp_cpu_notifier = {
34555 .notifier_call = coretemp_cpu_callback,
34556 };
34557
34558diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
34559index 1c85d39..55ed3cf 100644
34560--- a/drivers/hwmon/sht15.c
34561+++ b/drivers/hwmon/sht15.c
34562@@ -169,7 +169,7 @@ struct sht15_data {
34563 int supply_uV;
34564 bool supply_uV_valid;
34565 struct work_struct update_supply_work;
34566- atomic_t interrupt_handled;
34567+ atomic_unchecked_t interrupt_handled;
34568 };
34569
34570 /**
34571@@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
34572 return ret;
34573
34574 gpio_direction_input(data->pdata->gpio_data);
34575- atomic_set(&data->interrupt_handled, 0);
34576+ atomic_set_unchecked(&data->interrupt_handled, 0);
34577
34578 enable_irq(gpio_to_irq(data->pdata->gpio_data));
34579 if (gpio_get_value(data->pdata->gpio_data) == 0) {
34580 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
34581 /* Only relevant if the interrupt hasn't occurred. */
34582- if (!atomic_read(&data->interrupt_handled))
34583+ if (!atomic_read_unchecked(&data->interrupt_handled))
34584 schedule_work(&data->read_work);
34585 }
34586 ret = wait_event_timeout(data->wait_queue,
34587@@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
34588
34589 /* First disable the interrupt */
34590 disable_irq_nosync(irq);
34591- atomic_inc(&data->interrupt_handled);
34592+ atomic_inc_unchecked(&data->interrupt_handled);
34593 /* Then schedule a reading work struct */
34594 if (data->state != SHT15_READING_NOTHING)
34595 schedule_work(&data->read_work);
34596@@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
34597 * If not, then start the interrupt again - care here as could
34598 * have gone low in meantime so verify it hasn't!
34599 */
34600- atomic_set(&data->interrupt_handled, 0);
34601+ atomic_set_unchecked(&data->interrupt_handled, 0);
34602 enable_irq(gpio_to_irq(data->pdata->gpio_data));
34603 /* If still not occurred or another handler was scheduled */
34604 if (gpio_get_value(data->pdata->gpio_data)
34605- || atomic_read(&data->interrupt_handled))
34606+ || atomic_read_unchecked(&data->interrupt_handled))
34607 return;
34608 }
34609
34610diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
34611index 76f157b..9c0db1b 100644
34612--- a/drivers/hwmon/via-cputemp.c
34613+++ b/drivers/hwmon/via-cputemp.c
34614@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
34615 return NOTIFY_OK;
34616 }
34617
34618-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
34619+static struct notifier_block via_cputemp_cpu_notifier = {
34620 .notifier_call = via_cputemp_cpu_callback,
34621 };
34622
34623diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
34624index 378fcb5..5e91fa8 100644
34625--- a/drivers/i2c/busses/i2c-amd756-s4882.c
34626+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
34627@@ -43,7 +43,7 @@
34628 extern struct i2c_adapter amd756_smbus;
34629
34630 static struct i2c_adapter *s4882_adapter;
34631-static struct i2c_algorithm *s4882_algo;
34632+static i2c_algorithm_no_const *s4882_algo;
34633
34634 /* Wrapper access functions for multiplexed SMBus */
34635 static DEFINE_MUTEX(amd756_lock);
34636diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
34637index 29015eb..af2d8e9 100644
34638--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
34639+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
34640@@ -41,7 +41,7 @@
34641 extern struct i2c_adapter *nforce2_smbus;
34642
34643 static struct i2c_adapter *s4985_adapter;
34644-static struct i2c_algorithm *s4985_algo;
34645+static i2c_algorithm_no_const *s4985_algo;
34646
34647 /* Wrapper access functions for multiplexed SMBus */
34648 static DEFINE_MUTEX(nforce2_lock);
34649diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
34650index 8126824..55a2798 100644
34651--- a/drivers/ide/ide-cd.c
34652+++ b/drivers/ide/ide-cd.c
34653@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
34654 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
34655 if ((unsigned long)buf & alignment
34656 || blk_rq_bytes(rq) & q->dma_pad_mask
34657- || object_is_on_stack(buf))
34658+ || object_starts_on_stack(buf))
34659 drive->dma = 0;
34660 }
34661 }
34662diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
34663index 394fea2..c833880 100644
34664--- a/drivers/infiniband/core/cm.c
34665+++ b/drivers/infiniband/core/cm.c
34666@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
34667
34668 struct cm_counter_group {
34669 struct kobject obj;
34670- atomic_long_t counter[CM_ATTR_COUNT];
34671+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
34672 };
34673
34674 struct cm_counter_attribute {
34675@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
34676 struct ib_mad_send_buf *msg = NULL;
34677 int ret;
34678
34679- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34680+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34681 counter[CM_REQ_COUNTER]);
34682
34683 /* Quick state check to discard duplicate REQs. */
34684@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
34685 if (!cm_id_priv)
34686 return;
34687
34688- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34689+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34690 counter[CM_REP_COUNTER]);
34691 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
34692 if (ret)
34693@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
34694 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
34695 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
34696 spin_unlock_irq(&cm_id_priv->lock);
34697- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34698+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34699 counter[CM_RTU_COUNTER]);
34700 goto out;
34701 }
34702@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
34703 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
34704 dreq_msg->local_comm_id);
34705 if (!cm_id_priv) {
34706- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34707+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34708 counter[CM_DREQ_COUNTER]);
34709 cm_issue_drep(work->port, work->mad_recv_wc);
34710 return -EINVAL;
34711@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
34712 case IB_CM_MRA_REP_RCVD:
34713 break;
34714 case IB_CM_TIMEWAIT:
34715- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34716+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34717 counter[CM_DREQ_COUNTER]);
34718 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34719 goto unlock;
34720@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
34721 cm_free_msg(msg);
34722 goto deref;
34723 case IB_CM_DREQ_RCVD:
34724- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34725+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34726 counter[CM_DREQ_COUNTER]);
34727 goto unlock;
34728 default:
34729@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
34730 ib_modify_mad(cm_id_priv->av.port->mad_agent,
34731 cm_id_priv->msg, timeout)) {
34732 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
34733- atomic_long_inc(&work->port->
34734+ atomic_long_inc_unchecked(&work->port->
34735 counter_group[CM_RECV_DUPLICATES].
34736 counter[CM_MRA_COUNTER]);
34737 goto out;
34738@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
34739 break;
34740 case IB_CM_MRA_REQ_RCVD:
34741 case IB_CM_MRA_REP_RCVD:
34742- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34743+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34744 counter[CM_MRA_COUNTER]);
34745 /* fall through */
34746 default:
34747@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
34748 case IB_CM_LAP_IDLE:
34749 break;
34750 case IB_CM_MRA_LAP_SENT:
34751- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34752+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34753 counter[CM_LAP_COUNTER]);
34754 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34755 goto unlock;
34756@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
34757 cm_free_msg(msg);
34758 goto deref;
34759 case IB_CM_LAP_RCVD:
34760- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34761+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34762 counter[CM_LAP_COUNTER]);
34763 goto unlock;
34764 default:
34765@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
34766 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
34767 if (cur_cm_id_priv) {
34768 spin_unlock_irq(&cm.lock);
34769- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34770+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34771 counter[CM_SIDR_REQ_COUNTER]);
34772 goto out; /* Duplicate message. */
34773 }
34774@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
34775 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
34776 msg->retries = 1;
34777
34778- atomic_long_add(1 + msg->retries,
34779+ atomic_long_add_unchecked(1 + msg->retries,
34780 &port->counter_group[CM_XMIT].counter[attr_index]);
34781 if (msg->retries)
34782- atomic_long_add(msg->retries,
34783+ atomic_long_add_unchecked(msg->retries,
34784 &port->counter_group[CM_XMIT_RETRIES].
34785 counter[attr_index]);
34786
34787@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
34788 }
34789
34790 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
34791- atomic_long_inc(&port->counter_group[CM_RECV].
34792+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
34793 counter[attr_id - CM_ATTR_ID_OFFSET]);
34794
34795 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
34796@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
34797 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
34798
34799 return sprintf(buf, "%ld\n",
34800- atomic_long_read(&group->counter[cm_attr->index]));
34801+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
34802 }
34803
34804 static const struct sysfs_ops cm_counter_ops = {
34805diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
34806index 176c8f9..2627b62 100644
34807--- a/drivers/infiniband/core/fmr_pool.c
34808+++ b/drivers/infiniband/core/fmr_pool.c
34809@@ -98,8 +98,8 @@ struct ib_fmr_pool {
34810
34811 struct task_struct *thread;
34812
34813- atomic_t req_ser;
34814- atomic_t flush_ser;
34815+ atomic_unchecked_t req_ser;
34816+ atomic_unchecked_t flush_ser;
34817
34818 wait_queue_head_t force_wait;
34819 };
34820@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34821 struct ib_fmr_pool *pool = pool_ptr;
34822
34823 do {
34824- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
34825+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
34826 ib_fmr_batch_release(pool);
34827
34828- atomic_inc(&pool->flush_ser);
34829+ atomic_inc_unchecked(&pool->flush_ser);
34830 wake_up_interruptible(&pool->force_wait);
34831
34832 if (pool->flush_function)
34833@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34834 }
34835
34836 set_current_state(TASK_INTERRUPTIBLE);
34837- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
34838+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
34839 !kthread_should_stop())
34840 schedule();
34841 __set_current_state(TASK_RUNNING);
34842@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
34843 pool->dirty_watermark = params->dirty_watermark;
34844 pool->dirty_len = 0;
34845 spin_lock_init(&pool->pool_lock);
34846- atomic_set(&pool->req_ser, 0);
34847- atomic_set(&pool->flush_ser, 0);
34848+ atomic_set_unchecked(&pool->req_ser, 0);
34849+ atomic_set_unchecked(&pool->flush_ser, 0);
34850 init_waitqueue_head(&pool->force_wait);
34851
34852 pool->thread = kthread_run(ib_fmr_cleanup_thread,
34853@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
34854 }
34855 spin_unlock_irq(&pool->pool_lock);
34856
34857- serial = atomic_inc_return(&pool->req_ser);
34858+ serial = atomic_inc_return_unchecked(&pool->req_ser);
34859 wake_up_process(pool->thread);
34860
34861 if (wait_event_interruptible(pool->force_wait,
34862- atomic_read(&pool->flush_ser) - serial >= 0))
34863+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
34864 return -EINTR;
34865
34866 return 0;
34867@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
34868 } else {
34869 list_add_tail(&fmr->list, &pool->dirty_list);
34870 if (++pool->dirty_len >= pool->dirty_watermark) {
34871- atomic_inc(&pool->req_ser);
34872+ atomic_inc_unchecked(&pool->req_ser);
34873 wake_up_process(pool->thread);
34874 }
34875 }
34876diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
34877index afd8179..598063f 100644
34878--- a/drivers/infiniband/hw/cxgb4/mem.c
34879+++ b/drivers/infiniband/hw/cxgb4/mem.c
34880@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34881 int err;
34882 struct fw_ri_tpte tpt;
34883 u32 stag_idx;
34884- static atomic_t key;
34885+ static atomic_unchecked_t key;
34886
34887 if (c4iw_fatal_error(rdev))
34888 return -EIO;
34889@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34890 if (rdev->stats.stag.cur > rdev->stats.stag.max)
34891 rdev->stats.stag.max = rdev->stats.stag.cur;
34892 mutex_unlock(&rdev->stats.lock);
34893- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
34894+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
34895 }
34896 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
34897 __func__, stag_state, type, pdid, stag_idx);
34898diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
34899index 79b3dbc..96e5fcc 100644
34900--- a/drivers/infiniband/hw/ipath/ipath_rc.c
34901+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
34902@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34903 struct ib_atomic_eth *ateth;
34904 struct ipath_ack_entry *e;
34905 u64 vaddr;
34906- atomic64_t *maddr;
34907+ atomic64_unchecked_t *maddr;
34908 u64 sdata;
34909 u32 rkey;
34910 u8 next;
34911@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34912 IB_ACCESS_REMOTE_ATOMIC)))
34913 goto nack_acc_unlck;
34914 /* Perform atomic OP and save result. */
34915- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34916+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34917 sdata = be64_to_cpu(ateth->swap_data);
34918 e = &qp->s_ack_queue[qp->r_head_ack_queue];
34919 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
34920- (u64) atomic64_add_return(sdata, maddr) - sdata :
34921+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34922 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34923 be64_to_cpu(ateth->compare_data),
34924 sdata);
34925diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
34926index 1f95bba..9530f87 100644
34927--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
34928+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
34929@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
34930 unsigned long flags;
34931 struct ib_wc wc;
34932 u64 sdata;
34933- atomic64_t *maddr;
34934+ atomic64_unchecked_t *maddr;
34935 enum ib_wc_status send_status;
34936
34937 /*
34938@@ -382,11 +382,11 @@ again:
34939 IB_ACCESS_REMOTE_ATOMIC)))
34940 goto acc_err;
34941 /* Perform atomic OP and save result. */
34942- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34943+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34944 sdata = wqe->wr.wr.atomic.compare_add;
34945 *(u64 *) sqp->s_sge.sge.vaddr =
34946 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
34947- (u64) atomic64_add_return(sdata, maddr) - sdata :
34948+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34949 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34950 sdata, wqe->wr.wr.atomic.swap);
34951 goto send_comp;
34952diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
34953index 5b152a3..c1f3e83 100644
34954--- a/drivers/infiniband/hw/nes/nes.c
34955+++ b/drivers/infiniband/hw/nes/nes.c
34956@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
34957 LIST_HEAD(nes_adapter_list);
34958 static LIST_HEAD(nes_dev_list);
34959
34960-atomic_t qps_destroyed;
34961+atomic_unchecked_t qps_destroyed;
34962
34963 static unsigned int ee_flsh_adapter;
34964 static unsigned int sysfs_nonidx_addr;
34965@@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
34966 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
34967 struct nes_adapter *nesadapter = nesdev->nesadapter;
34968
34969- atomic_inc(&qps_destroyed);
34970+ atomic_inc_unchecked(&qps_destroyed);
34971
34972 /* Free the control structures */
34973
34974diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
34975index 33cc589..3bd6538 100644
34976--- a/drivers/infiniband/hw/nes/nes.h
34977+++ b/drivers/infiniband/hw/nes/nes.h
34978@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
34979 extern unsigned int wqm_quanta;
34980 extern struct list_head nes_adapter_list;
34981
34982-extern atomic_t cm_connects;
34983-extern atomic_t cm_accepts;
34984-extern atomic_t cm_disconnects;
34985-extern atomic_t cm_closes;
34986-extern atomic_t cm_connecteds;
34987-extern atomic_t cm_connect_reqs;
34988-extern atomic_t cm_rejects;
34989-extern atomic_t mod_qp_timouts;
34990-extern atomic_t qps_created;
34991-extern atomic_t qps_destroyed;
34992-extern atomic_t sw_qps_destroyed;
34993+extern atomic_unchecked_t cm_connects;
34994+extern atomic_unchecked_t cm_accepts;
34995+extern atomic_unchecked_t cm_disconnects;
34996+extern atomic_unchecked_t cm_closes;
34997+extern atomic_unchecked_t cm_connecteds;
34998+extern atomic_unchecked_t cm_connect_reqs;
34999+extern atomic_unchecked_t cm_rejects;
35000+extern atomic_unchecked_t mod_qp_timouts;
35001+extern atomic_unchecked_t qps_created;
35002+extern atomic_unchecked_t qps_destroyed;
35003+extern atomic_unchecked_t sw_qps_destroyed;
35004 extern u32 mh_detected;
35005 extern u32 mh_pauses_sent;
35006 extern u32 cm_packets_sent;
35007@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
35008 extern u32 cm_packets_received;
35009 extern u32 cm_packets_dropped;
35010 extern u32 cm_packets_retrans;
35011-extern atomic_t cm_listens_created;
35012-extern atomic_t cm_listens_destroyed;
35013+extern atomic_unchecked_t cm_listens_created;
35014+extern atomic_unchecked_t cm_listens_destroyed;
35015 extern u32 cm_backlog_drops;
35016-extern atomic_t cm_loopbacks;
35017-extern atomic_t cm_nodes_created;
35018-extern atomic_t cm_nodes_destroyed;
35019-extern atomic_t cm_accel_dropped_pkts;
35020-extern atomic_t cm_resets_recvd;
35021-extern atomic_t pau_qps_created;
35022-extern atomic_t pau_qps_destroyed;
35023+extern atomic_unchecked_t cm_loopbacks;
35024+extern atomic_unchecked_t cm_nodes_created;
35025+extern atomic_unchecked_t cm_nodes_destroyed;
35026+extern atomic_unchecked_t cm_accel_dropped_pkts;
35027+extern atomic_unchecked_t cm_resets_recvd;
35028+extern atomic_unchecked_t pau_qps_created;
35029+extern atomic_unchecked_t pau_qps_destroyed;
35030
35031 extern u32 int_mod_timer_init;
35032 extern u32 int_mod_cq_depth_256;
35033diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
35034index 22ea67e..dcbe3bc 100644
35035--- a/drivers/infiniband/hw/nes/nes_cm.c
35036+++ b/drivers/infiniband/hw/nes/nes_cm.c
35037@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
35038 u32 cm_packets_retrans;
35039 u32 cm_packets_created;
35040 u32 cm_packets_received;
35041-atomic_t cm_listens_created;
35042-atomic_t cm_listens_destroyed;
35043+atomic_unchecked_t cm_listens_created;
35044+atomic_unchecked_t cm_listens_destroyed;
35045 u32 cm_backlog_drops;
35046-atomic_t cm_loopbacks;
35047-atomic_t cm_nodes_created;
35048-atomic_t cm_nodes_destroyed;
35049-atomic_t cm_accel_dropped_pkts;
35050-atomic_t cm_resets_recvd;
35051+atomic_unchecked_t cm_loopbacks;
35052+atomic_unchecked_t cm_nodes_created;
35053+atomic_unchecked_t cm_nodes_destroyed;
35054+atomic_unchecked_t cm_accel_dropped_pkts;
35055+atomic_unchecked_t cm_resets_recvd;
35056
35057 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
35058 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
35059@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
35060
35061 static struct nes_cm_core *g_cm_core;
35062
35063-atomic_t cm_connects;
35064-atomic_t cm_accepts;
35065-atomic_t cm_disconnects;
35066-atomic_t cm_closes;
35067-atomic_t cm_connecteds;
35068-atomic_t cm_connect_reqs;
35069-atomic_t cm_rejects;
35070+atomic_unchecked_t cm_connects;
35071+atomic_unchecked_t cm_accepts;
35072+atomic_unchecked_t cm_disconnects;
35073+atomic_unchecked_t cm_closes;
35074+atomic_unchecked_t cm_connecteds;
35075+atomic_unchecked_t cm_connect_reqs;
35076+atomic_unchecked_t cm_rejects;
35077
35078 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
35079 {
35080@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
35081 kfree(listener);
35082 listener = NULL;
35083 ret = 0;
35084- atomic_inc(&cm_listens_destroyed);
35085+ atomic_inc_unchecked(&cm_listens_destroyed);
35086 } else {
35087 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
35088 }
35089@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
35090 cm_node->rem_mac);
35091
35092 add_hte_node(cm_core, cm_node);
35093- atomic_inc(&cm_nodes_created);
35094+ atomic_inc_unchecked(&cm_nodes_created);
35095
35096 return cm_node;
35097 }
35098@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
35099 }
35100
35101 atomic_dec(&cm_core->node_cnt);
35102- atomic_inc(&cm_nodes_destroyed);
35103+ atomic_inc_unchecked(&cm_nodes_destroyed);
35104 nesqp = cm_node->nesqp;
35105 if (nesqp) {
35106 nesqp->cm_node = NULL;
35107@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
35108
35109 static void drop_packet(struct sk_buff *skb)
35110 {
35111- atomic_inc(&cm_accel_dropped_pkts);
35112+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
35113 dev_kfree_skb_any(skb);
35114 }
35115
35116@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
35117 {
35118
35119 int reset = 0; /* whether to send reset in case of err.. */
35120- atomic_inc(&cm_resets_recvd);
35121+ atomic_inc_unchecked(&cm_resets_recvd);
35122 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
35123 " refcnt=%d\n", cm_node, cm_node->state,
35124 atomic_read(&cm_node->ref_count));
35125@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
35126 rem_ref_cm_node(cm_node->cm_core, cm_node);
35127 return NULL;
35128 }
35129- atomic_inc(&cm_loopbacks);
35130+ atomic_inc_unchecked(&cm_loopbacks);
35131 loopbackremotenode->loopbackpartner = cm_node;
35132 loopbackremotenode->tcp_cntxt.rcv_wscale =
35133 NES_CM_DEFAULT_RCV_WND_SCALE;
35134@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
35135 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
35136 else {
35137 rem_ref_cm_node(cm_core, cm_node);
35138- atomic_inc(&cm_accel_dropped_pkts);
35139+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
35140 dev_kfree_skb_any(skb);
35141 }
35142 break;
35143@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35144
35145 if ((cm_id) && (cm_id->event_handler)) {
35146 if (issue_disconn) {
35147- atomic_inc(&cm_disconnects);
35148+ atomic_inc_unchecked(&cm_disconnects);
35149 cm_event.event = IW_CM_EVENT_DISCONNECT;
35150 cm_event.status = disconn_status;
35151 cm_event.local_addr = cm_id->local_addr;
35152@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35153 }
35154
35155 if (issue_close) {
35156- atomic_inc(&cm_closes);
35157+ atomic_inc_unchecked(&cm_closes);
35158 nes_disconnect(nesqp, 1);
35159
35160 cm_id->provider_data = nesqp;
35161@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35162
35163 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
35164 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
35165- atomic_inc(&cm_accepts);
35166+ atomic_inc_unchecked(&cm_accepts);
35167
35168 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
35169 netdev_refcnt_read(nesvnic->netdev));
35170@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
35171 struct nes_cm_core *cm_core;
35172 u8 *start_buff;
35173
35174- atomic_inc(&cm_rejects);
35175+ atomic_inc_unchecked(&cm_rejects);
35176 cm_node = (struct nes_cm_node *)cm_id->provider_data;
35177 loopback = cm_node->loopbackpartner;
35178 cm_core = cm_node->cm_core;
35179@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35180 ntohl(cm_id->local_addr.sin_addr.s_addr),
35181 ntohs(cm_id->local_addr.sin_port));
35182
35183- atomic_inc(&cm_connects);
35184+ atomic_inc_unchecked(&cm_connects);
35185 nesqp->active_conn = 1;
35186
35187 /* cache the cm_id in the qp */
35188@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
35189 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
35190 return err;
35191 }
35192- atomic_inc(&cm_listens_created);
35193+ atomic_inc_unchecked(&cm_listens_created);
35194 }
35195
35196 cm_id->add_ref(cm_id);
35197@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
35198
35199 if (nesqp->destroyed)
35200 return;
35201- atomic_inc(&cm_connecteds);
35202+ atomic_inc_unchecked(&cm_connecteds);
35203 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
35204 " local port 0x%04X. jiffies = %lu.\n",
35205 nesqp->hwqp.qp_id,
35206@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
35207
35208 cm_id->add_ref(cm_id);
35209 ret = cm_id->event_handler(cm_id, &cm_event);
35210- atomic_inc(&cm_closes);
35211+ atomic_inc_unchecked(&cm_closes);
35212 cm_event.event = IW_CM_EVENT_CLOSE;
35213 cm_event.status = 0;
35214 cm_event.provider_data = cm_id->provider_data;
35215@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
35216 return;
35217 cm_id = cm_node->cm_id;
35218
35219- atomic_inc(&cm_connect_reqs);
35220+ atomic_inc_unchecked(&cm_connect_reqs);
35221 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
35222 cm_node, cm_id, jiffies);
35223
35224@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
35225 return;
35226 cm_id = cm_node->cm_id;
35227
35228- atomic_inc(&cm_connect_reqs);
35229+ atomic_inc_unchecked(&cm_connect_reqs);
35230 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
35231 cm_node, cm_id, jiffies);
35232
35233diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
35234index 4166452..fc952c3 100644
35235--- a/drivers/infiniband/hw/nes/nes_mgt.c
35236+++ b/drivers/infiniband/hw/nes/nes_mgt.c
35237@@ -40,8 +40,8 @@
35238 #include "nes.h"
35239 #include "nes_mgt.h"
35240
35241-atomic_t pau_qps_created;
35242-atomic_t pau_qps_destroyed;
35243+atomic_unchecked_t pau_qps_created;
35244+atomic_unchecked_t pau_qps_destroyed;
35245
35246 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
35247 {
35248@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
35249 {
35250 struct sk_buff *skb;
35251 unsigned long flags;
35252- atomic_inc(&pau_qps_destroyed);
35253+ atomic_inc_unchecked(&pau_qps_destroyed);
35254
35255 /* Free packets that have not yet been forwarded */
35256 /* Lock is acquired by skb_dequeue when removing the skb */
35257@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
35258 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
35259 skb_queue_head_init(&nesqp->pau_list);
35260 spin_lock_init(&nesqp->pau_lock);
35261- atomic_inc(&pau_qps_created);
35262+ atomic_inc_unchecked(&pau_qps_created);
35263 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
35264 }
35265
35266diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
35267index 9542e16..a008c40 100644
35268--- a/drivers/infiniband/hw/nes/nes_nic.c
35269+++ b/drivers/infiniband/hw/nes/nes_nic.c
35270@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
35271 target_stat_values[++index] = mh_detected;
35272 target_stat_values[++index] = mh_pauses_sent;
35273 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
35274- target_stat_values[++index] = atomic_read(&cm_connects);
35275- target_stat_values[++index] = atomic_read(&cm_accepts);
35276- target_stat_values[++index] = atomic_read(&cm_disconnects);
35277- target_stat_values[++index] = atomic_read(&cm_connecteds);
35278- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
35279- target_stat_values[++index] = atomic_read(&cm_rejects);
35280- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
35281- target_stat_values[++index] = atomic_read(&qps_created);
35282- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
35283- target_stat_values[++index] = atomic_read(&qps_destroyed);
35284- target_stat_values[++index] = atomic_read(&cm_closes);
35285+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
35286+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
35287+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
35288+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
35289+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
35290+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
35291+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
35292+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
35293+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
35294+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
35295+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
35296 target_stat_values[++index] = cm_packets_sent;
35297 target_stat_values[++index] = cm_packets_bounced;
35298 target_stat_values[++index] = cm_packets_created;
35299 target_stat_values[++index] = cm_packets_received;
35300 target_stat_values[++index] = cm_packets_dropped;
35301 target_stat_values[++index] = cm_packets_retrans;
35302- target_stat_values[++index] = atomic_read(&cm_listens_created);
35303- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
35304+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
35305+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
35306 target_stat_values[++index] = cm_backlog_drops;
35307- target_stat_values[++index] = atomic_read(&cm_loopbacks);
35308- target_stat_values[++index] = atomic_read(&cm_nodes_created);
35309- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
35310- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
35311- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
35312+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
35313+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
35314+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
35315+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
35316+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
35317 target_stat_values[++index] = nesadapter->free_4kpbl;
35318 target_stat_values[++index] = nesadapter->free_256pbl;
35319 target_stat_values[++index] = int_mod_timer_init;
35320 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
35321 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
35322 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
35323- target_stat_values[++index] = atomic_read(&pau_qps_created);
35324- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
35325+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
35326+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
35327 }
35328
35329 /**
35330diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
35331index 07e4fba..685f041 100644
35332--- a/drivers/infiniband/hw/nes/nes_verbs.c
35333+++ b/drivers/infiniband/hw/nes/nes_verbs.c
35334@@ -46,9 +46,9 @@
35335
35336 #include <rdma/ib_umem.h>
35337
35338-atomic_t mod_qp_timouts;
35339-atomic_t qps_created;
35340-atomic_t sw_qps_destroyed;
35341+atomic_unchecked_t mod_qp_timouts;
35342+atomic_unchecked_t qps_created;
35343+atomic_unchecked_t sw_qps_destroyed;
35344
35345 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
35346
35347@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
35348 if (init_attr->create_flags)
35349 return ERR_PTR(-EINVAL);
35350
35351- atomic_inc(&qps_created);
35352+ atomic_inc_unchecked(&qps_created);
35353 switch (init_attr->qp_type) {
35354 case IB_QPT_RC:
35355 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
35356@@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
35357 struct iw_cm_event cm_event;
35358 int ret = 0;
35359
35360- atomic_inc(&sw_qps_destroyed);
35361+ atomic_inc_unchecked(&sw_qps_destroyed);
35362 nesqp->destroyed = 1;
35363
35364 /* Blow away the connection if it exists. */
35365diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
35366index 4d11575..3e890e5 100644
35367--- a/drivers/infiniband/hw/qib/qib.h
35368+++ b/drivers/infiniband/hw/qib/qib.h
35369@@ -51,6 +51,7 @@
35370 #include <linux/completion.h>
35371 #include <linux/kref.h>
35372 #include <linux/sched.h>
35373+#include <linux/slab.h>
35374
35375 #include "qib_common.h"
35376 #include "qib_verbs.h"
35377diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
35378index da739d9..da1c7f4 100644
35379--- a/drivers/input/gameport/gameport.c
35380+++ b/drivers/input/gameport/gameport.c
35381@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
35382 */
35383 static void gameport_init_port(struct gameport *gameport)
35384 {
35385- static atomic_t gameport_no = ATOMIC_INIT(0);
35386+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
35387
35388 __module_get(THIS_MODULE);
35389
35390 mutex_init(&gameport->drv_mutex);
35391 device_initialize(&gameport->dev);
35392 dev_set_name(&gameport->dev, "gameport%lu",
35393- (unsigned long)atomic_inc_return(&gameport_no) - 1);
35394+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
35395 gameport->dev.bus = &gameport_bus;
35396 gameport->dev.release = gameport_release_port;
35397 if (gameport->parent)
35398diff --git a/drivers/input/input.c b/drivers/input/input.c
35399index c044699..174d71a 100644
35400--- a/drivers/input/input.c
35401+++ b/drivers/input/input.c
35402@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
35403 */
35404 int input_register_device(struct input_dev *dev)
35405 {
35406- static atomic_t input_no = ATOMIC_INIT(0);
35407+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
35408 struct input_devres *devres = NULL;
35409 struct input_handler *handler;
35410 unsigned int packet_size;
35411@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
35412 dev->setkeycode = input_default_setkeycode;
35413
35414 dev_set_name(&dev->dev, "input%ld",
35415- (unsigned long) atomic_inc_return(&input_no) - 1);
35416+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
35417
35418 error = device_add(&dev->dev);
35419 if (error)
35420diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
35421index 04c69af..5f92d00 100644
35422--- a/drivers/input/joystick/sidewinder.c
35423+++ b/drivers/input/joystick/sidewinder.c
35424@@ -30,6 +30,7 @@
35425 #include <linux/kernel.h>
35426 #include <linux/module.h>
35427 #include <linux/slab.h>
35428+#include <linux/sched.h>
35429 #include <linux/init.h>
35430 #include <linux/input.h>
35431 #include <linux/gameport.h>
35432diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
35433index d6cbfe9..6225402 100644
35434--- a/drivers/input/joystick/xpad.c
35435+++ b/drivers/input/joystick/xpad.c
35436@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
35437
35438 static int xpad_led_probe(struct usb_xpad *xpad)
35439 {
35440- static atomic_t led_seq = ATOMIC_INIT(0);
35441+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
35442 long led_no;
35443 struct xpad_led *led;
35444 struct led_classdev *led_cdev;
35445@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
35446 if (!led)
35447 return -ENOMEM;
35448
35449- led_no = (long)atomic_inc_return(&led_seq) - 1;
35450+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
35451
35452 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
35453 led->xpad = xpad;
35454diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
35455index 4c842c3..590b0bf 100644
35456--- a/drivers/input/mousedev.c
35457+++ b/drivers/input/mousedev.c
35458@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
35459
35460 spin_unlock_irq(&client->packet_lock);
35461
35462- if (copy_to_user(buffer, data, count))
35463+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
35464 return -EFAULT;
35465
35466 return count;
35467diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
35468index 25fc597..558bf3b 100644
35469--- a/drivers/input/serio/serio.c
35470+++ b/drivers/input/serio/serio.c
35471@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
35472 */
35473 static void serio_init_port(struct serio *serio)
35474 {
35475- static atomic_t serio_no = ATOMIC_INIT(0);
35476+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
35477
35478 __module_get(THIS_MODULE);
35479
35480@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
35481 mutex_init(&serio->drv_mutex);
35482 device_initialize(&serio->dev);
35483 dev_set_name(&serio->dev, "serio%ld",
35484- (long)atomic_inc_return(&serio_no) - 1);
35485+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
35486 serio->dev.bus = &serio_bus;
35487 serio->dev.release = serio_release_port;
35488 serio->dev.groups = serio_device_attr_groups;
35489diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
35490index 89562a8..218999b 100644
35491--- a/drivers/isdn/capi/capi.c
35492+++ b/drivers/isdn/capi/capi.c
35493@@ -81,8 +81,8 @@ struct capiminor {
35494
35495 struct capi20_appl *ap;
35496 u32 ncci;
35497- atomic_t datahandle;
35498- atomic_t msgid;
35499+ atomic_unchecked_t datahandle;
35500+ atomic_unchecked_t msgid;
35501
35502 struct tty_port port;
35503 int ttyinstop;
35504@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
35505 capimsg_setu16(s, 2, mp->ap->applid);
35506 capimsg_setu8 (s, 4, CAPI_DATA_B3);
35507 capimsg_setu8 (s, 5, CAPI_RESP);
35508- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
35509+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
35510 capimsg_setu32(s, 8, mp->ncci);
35511 capimsg_setu16(s, 12, datahandle);
35512 }
35513@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
35514 mp->outbytes -= len;
35515 spin_unlock_bh(&mp->outlock);
35516
35517- datahandle = atomic_inc_return(&mp->datahandle);
35518+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
35519 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
35520 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
35521 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
35522 capimsg_setu16(skb->data, 2, mp->ap->applid);
35523 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
35524 capimsg_setu8 (skb->data, 5, CAPI_REQ);
35525- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
35526+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
35527 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
35528 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
35529 capimsg_setu16(skb->data, 16, len); /* Data length */
35530diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
35531index 67abf3f..076b3a6 100644
35532--- a/drivers/isdn/gigaset/interface.c
35533+++ b/drivers/isdn/gigaset/interface.c
35534@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
35535 }
35536 tty->driver_data = cs;
35537
35538- ++cs->port.count;
35539+ atomic_inc(&cs->port.count);
35540
35541- if (cs->port.count == 1) {
35542+ if (atomic_read(&cs->port.count) == 1) {
35543 tty_port_tty_set(&cs->port, tty);
35544 tty->low_latency = 1;
35545 }
35546@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
35547
35548 if (!cs->connected)
35549 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
35550- else if (!cs->port.count)
35551+ else if (!atomic_read(&cs->port.count))
35552 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35553- else if (!--cs->port.count)
35554+ else if (!atomic_dec_return(&cs->port.count))
35555 tty_port_tty_set(&cs->port, NULL);
35556
35557 mutex_unlock(&cs->mutex);
35558diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
35559index 821f7ac..28d4030 100644
35560--- a/drivers/isdn/hardware/avm/b1.c
35561+++ b/drivers/isdn/hardware/avm/b1.c
35562@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
35563 }
35564 if (left) {
35565 if (t4file->user) {
35566- if (copy_from_user(buf, dp, left))
35567+ if (left > sizeof buf || copy_from_user(buf, dp, left))
35568 return -EFAULT;
35569 } else {
35570 memcpy(buf, dp, left);
35571@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
35572 }
35573 if (left) {
35574 if (config->user) {
35575- if (copy_from_user(buf, dp, left))
35576+ if (left > sizeof buf || copy_from_user(buf, dp, left))
35577 return -EFAULT;
35578 } else {
35579 memcpy(buf, dp, left);
35580diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
35581index e09dc8a..15e2efb 100644
35582--- a/drivers/isdn/i4l/isdn_tty.c
35583+++ b/drivers/isdn/i4l/isdn_tty.c
35584@@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
35585
35586 #ifdef ISDN_DEBUG_MODEM_OPEN
35587 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
35588- port->count);
35589+ atomic_read(&port->count));
35590 #endif
35591- port->count++;
35592+ atomic_inc(&port->count);
35593 port->tty = tty;
35594 /*
35595 * Start up serial port
35596@@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
35597 #endif
35598 return;
35599 }
35600- if ((tty->count == 1) && (port->count != 1)) {
35601+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
35602 /*
35603 * Uh, oh. tty->count is 1, which means that the tty
35604 * structure will be freed. Info->count should always
35605@@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
35606 * serial port won't be shutdown.
35607 */
35608 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
35609- "info->count is %d\n", port->count);
35610- port->count = 1;
35611+ "info->count is %d\n", atomic_read(&port->count));
35612+ atomic_set(&port->count, 1);
35613 }
35614- if (--port->count < 0) {
35615+ if (atomic_dec_return(&port->count) < 0) {
35616 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
35617- info->line, port->count);
35618- port->count = 0;
35619+ info->line, atomic_read(&port->count));
35620+ atomic_set(&port->count, 0);
35621 }
35622- if (port->count) {
35623+ if (atomic_read(&port->count)) {
35624 #ifdef ISDN_DEBUG_MODEM_OPEN
35625 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
35626 #endif
35627@@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
35628 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
35629 return;
35630 isdn_tty_shutdown(info);
35631- port->count = 0;
35632+ atomic_set(&port->count, 0);
35633 port->flags &= ~ASYNC_NORMAL_ACTIVE;
35634 port->tty = NULL;
35635 wake_up_interruptible(&port->open_wait);
35636@@ -1975,7 +1975,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
35637 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
35638 modem_info *info = &dev->mdm.info[i];
35639
35640- if (info->port.count == 0)
35641+ if (atomic_read(&info->port.count) == 0)
35642 continue;
35643 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
35644 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
35645diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
35646index e74df7c..03a03ba 100644
35647--- a/drivers/isdn/icn/icn.c
35648+++ b/drivers/isdn/icn/icn.c
35649@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
35650 if (count > len)
35651 count = len;
35652 if (user) {
35653- if (copy_from_user(msg, buf, count))
35654+ if (count > sizeof msg || copy_from_user(msg, buf, count))
35655 return -EFAULT;
35656 } else
35657 memcpy(msg, buf, count);
35658diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
35659index a5ebc00..982886f 100644
35660--- a/drivers/lguest/core.c
35661+++ b/drivers/lguest/core.c
35662@@ -92,9 +92,17 @@ static __init int map_switcher(void)
35663 * it's worked so far. The end address needs +1 because __get_vm_area
35664 * allocates an extra guard page, so we need space for that.
35665 */
35666+
35667+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
35668+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35669+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
35670+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35671+#else
35672 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35673 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
35674 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35675+#endif
35676+
35677 if (!switcher_vma) {
35678 err = -ENOMEM;
35679 printk("lguest: could not map switcher pages high\n");
35680@@ -119,7 +127,7 @@ static __init int map_switcher(void)
35681 * Now the Switcher is mapped at the right address, we can't fail!
35682 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
35683 */
35684- memcpy(switcher_vma->addr, start_switcher_text,
35685+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
35686 end_switcher_text - start_switcher_text);
35687
35688 printk(KERN_INFO "lguest: mapped switcher at %p\n",
35689diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
35690index 4af12e1..0e89afe 100644
35691--- a/drivers/lguest/x86/core.c
35692+++ b/drivers/lguest/x86/core.c
35693@@ -59,7 +59,7 @@ static struct {
35694 /* Offset from where switcher.S was compiled to where we've copied it */
35695 static unsigned long switcher_offset(void)
35696 {
35697- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
35698+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
35699 }
35700
35701 /* This cpu's struct lguest_pages. */
35702@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
35703 * These copies are pretty cheap, so we do them unconditionally: */
35704 /* Save the current Host top-level page directory.
35705 */
35706+
35707+#ifdef CONFIG_PAX_PER_CPU_PGD
35708+ pages->state.host_cr3 = read_cr3();
35709+#else
35710 pages->state.host_cr3 = __pa(current->mm->pgd);
35711+#endif
35712+
35713 /*
35714 * Set up the Guest's page tables to see this CPU's pages (and no
35715 * other CPU's pages).
35716@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
35717 * compiled-in switcher code and the high-mapped copy we just made.
35718 */
35719 for (i = 0; i < IDT_ENTRIES; i++)
35720- default_idt_entries[i] += switcher_offset();
35721+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
35722
35723 /*
35724 * Set up the Switcher's per-cpu areas.
35725@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
35726 * it will be undisturbed when we switch. To change %cs and jump we
35727 * need this structure to feed to Intel's "lcall" instruction.
35728 */
35729- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
35730+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
35731 lguest_entry.segment = LGUEST_CS;
35732
35733 /*
35734diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
35735index 40634b0..4f5855e 100644
35736--- a/drivers/lguest/x86/switcher_32.S
35737+++ b/drivers/lguest/x86/switcher_32.S
35738@@ -87,6 +87,7 @@
35739 #include <asm/page.h>
35740 #include <asm/segment.h>
35741 #include <asm/lguest.h>
35742+#include <asm/processor-flags.h>
35743
35744 // We mark the start of the code to copy
35745 // It's placed in .text tho it's never run here
35746@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
35747 // Changes type when we load it: damn Intel!
35748 // For after we switch over our page tables
35749 // That entry will be read-only: we'd crash.
35750+
35751+#ifdef CONFIG_PAX_KERNEXEC
35752+ mov %cr0, %edx
35753+ xor $X86_CR0_WP, %edx
35754+ mov %edx, %cr0
35755+#endif
35756+
35757 movl $(GDT_ENTRY_TSS*8), %edx
35758 ltr %dx
35759
35760@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
35761 // Let's clear it again for our return.
35762 // The GDT descriptor of the Host
35763 // Points to the table after two "size" bytes
35764- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
35765+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
35766 // Clear "used" from type field (byte 5, bit 2)
35767- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
35768+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
35769+
35770+#ifdef CONFIG_PAX_KERNEXEC
35771+ mov %cr0, %eax
35772+ xor $X86_CR0_WP, %eax
35773+ mov %eax, %cr0
35774+#endif
35775
35776 // Once our page table's switched, the Guest is live!
35777 // The Host fades as we run this final step.
35778@@ -295,13 +309,12 @@ deliver_to_host:
35779 // I consulted gcc, and it gave
35780 // These instructions, which I gladly credit:
35781 leal (%edx,%ebx,8), %eax
35782- movzwl (%eax),%edx
35783- movl 4(%eax), %eax
35784- xorw %ax, %ax
35785- orl %eax, %edx
35786+ movl 4(%eax), %edx
35787+ movw (%eax), %dx
35788 // Now the address of the handler's in %edx
35789 // We call it now: its "iret" drops us home.
35790- jmp *%edx
35791+ ljmp $__KERNEL_CS, $1f
35792+1: jmp *%edx
35793
35794 // Every interrupt can come to us here
35795 // But we must truly tell each apart.
35796diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
35797index 7155945..4bcc562 100644
35798--- a/drivers/md/bitmap.c
35799+++ b/drivers/md/bitmap.c
35800@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
35801 chunk_kb ? "KB" : "B");
35802 if (bitmap->storage.file) {
35803 seq_printf(seq, ", file: ");
35804- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
35805+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
35806 }
35807
35808 seq_printf(seq, "\n");
35809diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
35810index 0666b5d..ed82cb4 100644
35811--- a/drivers/md/dm-ioctl.c
35812+++ b/drivers/md/dm-ioctl.c
35813@@ -1628,7 +1628,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
35814 cmd == DM_LIST_VERSIONS_CMD)
35815 return 0;
35816
35817- if ((cmd == DM_DEV_CREATE_CMD)) {
35818+ if (cmd == DM_DEV_CREATE_CMD) {
35819 if (!*param->name) {
35820 DMWARN("name not supplied when creating device");
35821 return -EINVAL;
35822diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
35823index fa51918..c26253c 100644
35824--- a/drivers/md/dm-raid1.c
35825+++ b/drivers/md/dm-raid1.c
35826@@ -40,7 +40,7 @@ enum dm_raid1_error {
35827
35828 struct mirror {
35829 struct mirror_set *ms;
35830- atomic_t error_count;
35831+ atomic_unchecked_t error_count;
35832 unsigned long error_type;
35833 struct dm_dev *dev;
35834 sector_t offset;
35835@@ -183,7 +183,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
35836 struct mirror *m;
35837
35838 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
35839- if (!atomic_read(&m->error_count))
35840+ if (!atomic_read_unchecked(&m->error_count))
35841 return m;
35842
35843 return NULL;
35844@@ -215,7 +215,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35845 * simple way to tell if a device has encountered
35846 * errors.
35847 */
35848- atomic_inc(&m->error_count);
35849+ atomic_inc_unchecked(&m->error_count);
35850
35851 if (test_and_set_bit(error_type, &m->error_type))
35852 return;
35853@@ -406,7 +406,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
35854 struct mirror *m = get_default_mirror(ms);
35855
35856 do {
35857- if (likely(!atomic_read(&m->error_count)))
35858+ if (likely(!atomic_read_unchecked(&m->error_count)))
35859 return m;
35860
35861 if (m-- == ms->mirror)
35862@@ -420,7 +420,7 @@ static int default_ok(struct mirror *m)
35863 {
35864 struct mirror *default_mirror = get_default_mirror(m->ms);
35865
35866- return !atomic_read(&default_mirror->error_count);
35867+ return !atomic_read_unchecked(&default_mirror->error_count);
35868 }
35869
35870 static int mirror_available(struct mirror_set *ms, struct bio *bio)
35871@@ -557,7 +557,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
35872 */
35873 if (likely(region_in_sync(ms, region, 1)))
35874 m = choose_mirror(ms, bio->bi_sector);
35875- else if (m && atomic_read(&m->error_count))
35876+ else if (m && atomic_read_unchecked(&m->error_count))
35877 m = NULL;
35878
35879 if (likely(m))
35880@@ -924,7 +924,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
35881 }
35882
35883 ms->mirror[mirror].ms = ms;
35884- atomic_set(&(ms->mirror[mirror].error_count), 0);
35885+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
35886 ms->mirror[mirror].error_type = 0;
35887 ms->mirror[mirror].offset = offset;
35888
35889@@ -1337,7 +1337,7 @@ static void mirror_resume(struct dm_target *ti)
35890 */
35891 static char device_status_char(struct mirror *m)
35892 {
35893- if (!atomic_read(&(m->error_count)))
35894+ if (!atomic_read_unchecked(&(m->error_count)))
35895 return 'A';
35896
35897 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
35898diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
35899index c89cde8..9d184cf 100644
35900--- a/drivers/md/dm-stripe.c
35901+++ b/drivers/md/dm-stripe.c
35902@@ -20,7 +20,7 @@ struct stripe {
35903 struct dm_dev *dev;
35904 sector_t physical_start;
35905
35906- atomic_t error_count;
35907+ atomic_unchecked_t error_count;
35908 };
35909
35910 struct stripe_c {
35911@@ -184,7 +184,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
35912 kfree(sc);
35913 return r;
35914 }
35915- atomic_set(&(sc->stripe[i].error_count), 0);
35916+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
35917 }
35918
35919 ti->private = sc;
35920@@ -325,7 +325,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
35921 DMEMIT("%d ", sc->stripes);
35922 for (i = 0; i < sc->stripes; i++) {
35923 DMEMIT("%s ", sc->stripe[i].dev->name);
35924- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
35925+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
35926 'D' : 'A';
35927 }
35928 buffer[i] = '\0';
35929@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
35930 */
35931 for (i = 0; i < sc->stripes; i++)
35932 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
35933- atomic_inc(&(sc->stripe[i].error_count));
35934- if (atomic_read(&(sc->stripe[i].error_count)) <
35935+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
35936+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
35937 DM_IO_ERROR_THRESHOLD)
35938 schedule_work(&sc->trigger_event);
35939 }
35940diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
35941index daf25d0..d74f49f 100644
35942--- a/drivers/md/dm-table.c
35943+++ b/drivers/md/dm-table.c
35944@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
35945 if (!dev_size)
35946 return 0;
35947
35948- if ((start >= dev_size) || (start + len > dev_size)) {
35949+ if ((start >= dev_size) || (len > dev_size - start)) {
35950 DMWARN("%s: %s too small for target: "
35951 "start=%llu, len=%llu, dev_size=%llu",
35952 dm_device_name(ti->table->md), bdevname(bdev, b),
35953diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
35954index 4d6e853..a234157 100644
35955--- a/drivers/md/dm-thin-metadata.c
35956+++ b/drivers/md/dm-thin-metadata.c
35957@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35958 {
35959 pmd->info.tm = pmd->tm;
35960 pmd->info.levels = 2;
35961- pmd->info.value_type.context = pmd->data_sm;
35962+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35963 pmd->info.value_type.size = sizeof(__le64);
35964 pmd->info.value_type.inc = data_block_inc;
35965 pmd->info.value_type.dec = data_block_dec;
35966@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35967
35968 pmd->bl_info.tm = pmd->tm;
35969 pmd->bl_info.levels = 1;
35970- pmd->bl_info.value_type.context = pmd->data_sm;
35971+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35972 pmd->bl_info.value_type.size = sizeof(__le64);
35973 pmd->bl_info.value_type.inc = data_block_inc;
35974 pmd->bl_info.value_type.dec = data_block_dec;
35975diff --git a/drivers/md/dm.c b/drivers/md/dm.c
35976index 314a0e2..1376406 100644
35977--- a/drivers/md/dm.c
35978+++ b/drivers/md/dm.c
35979@@ -170,9 +170,9 @@ struct mapped_device {
35980 /*
35981 * Event handling.
35982 */
35983- atomic_t event_nr;
35984+ atomic_unchecked_t event_nr;
35985 wait_queue_head_t eventq;
35986- atomic_t uevent_seq;
35987+ atomic_unchecked_t uevent_seq;
35988 struct list_head uevent_list;
35989 spinlock_t uevent_lock; /* Protect access to uevent_list */
35990
35991@@ -1872,8 +1872,8 @@ static struct mapped_device *alloc_dev(int minor)
35992 rwlock_init(&md->map_lock);
35993 atomic_set(&md->holders, 1);
35994 atomic_set(&md->open_count, 0);
35995- atomic_set(&md->event_nr, 0);
35996- atomic_set(&md->uevent_seq, 0);
35997+ atomic_set_unchecked(&md->event_nr, 0);
35998+ atomic_set_unchecked(&md->uevent_seq, 0);
35999 INIT_LIST_HEAD(&md->uevent_list);
36000 spin_lock_init(&md->uevent_lock);
36001
36002@@ -2014,7 +2014,7 @@ static void event_callback(void *context)
36003
36004 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
36005
36006- atomic_inc(&md->event_nr);
36007+ atomic_inc_unchecked(&md->event_nr);
36008 wake_up(&md->eventq);
36009 }
36010
36011@@ -2669,18 +2669,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
36012
36013 uint32_t dm_next_uevent_seq(struct mapped_device *md)
36014 {
36015- return atomic_add_return(1, &md->uevent_seq);
36016+ return atomic_add_return_unchecked(1, &md->uevent_seq);
36017 }
36018
36019 uint32_t dm_get_event_nr(struct mapped_device *md)
36020 {
36021- return atomic_read(&md->event_nr);
36022+ return atomic_read_unchecked(&md->event_nr);
36023 }
36024
36025 int dm_wait_event(struct mapped_device *md, int event_nr)
36026 {
36027 return wait_event_interruptible(md->eventq,
36028- (event_nr != atomic_read(&md->event_nr)));
36029+ (event_nr != atomic_read_unchecked(&md->event_nr)));
36030 }
36031
36032 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
36033diff --git a/drivers/md/md.c b/drivers/md/md.c
36034index 3db3d1b..9487468 100644
36035--- a/drivers/md/md.c
36036+++ b/drivers/md/md.c
36037@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
36038 * start build, activate spare
36039 */
36040 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
36041-static atomic_t md_event_count;
36042+static atomic_unchecked_t md_event_count;
36043 void md_new_event(struct mddev *mddev)
36044 {
36045- atomic_inc(&md_event_count);
36046+ atomic_inc_unchecked(&md_event_count);
36047 wake_up(&md_event_waiters);
36048 }
36049 EXPORT_SYMBOL_GPL(md_new_event);
36050@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
36051 */
36052 static void md_new_event_inintr(struct mddev *mddev)
36053 {
36054- atomic_inc(&md_event_count);
36055+ atomic_inc_unchecked(&md_event_count);
36056 wake_up(&md_event_waiters);
36057 }
36058
36059@@ -1503,7 +1503,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
36060 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
36061 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
36062 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
36063- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36064+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36065
36066 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
36067 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
36068@@ -1747,7 +1747,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
36069 else
36070 sb->resync_offset = cpu_to_le64(0);
36071
36072- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
36073+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
36074
36075 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
36076 sb->size = cpu_to_le64(mddev->dev_sectors);
36077@@ -2747,7 +2747,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
36078 static ssize_t
36079 errors_show(struct md_rdev *rdev, char *page)
36080 {
36081- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
36082+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
36083 }
36084
36085 static ssize_t
36086@@ -2756,7 +2756,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
36087 char *e;
36088 unsigned long n = simple_strtoul(buf, &e, 10);
36089 if (*buf && (*e == 0 || *e == '\n')) {
36090- atomic_set(&rdev->corrected_errors, n);
36091+ atomic_set_unchecked(&rdev->corrected_errors, n);
36092 return len;
36093 }
36094 return -EINVAL;
36095@@ -3203,8 +3203,8 @@ int md_rdev_init(struct md_rdev *rdev)
36096 rdev->sb_loaded = 0;
36097 rdev->bb_page = NULL;
36098 atomic_set(&rdev->nr_pending, 0);
36099- atomic_set(&rdev->read_errors, 0);
36100- atomic_set(&rdev->corrected_errors, 0);
36101+ atomic_set_unchecked(&rdev->read_errors, 0);
36102+ atomic_set_unchecked(&rdev->corrected_errors, 0);
36103
36104 INIT_LIST_HEAD(&rdev->same_set);
36105 init_waitqueue_head(&rdev->blocked_wait);
36106@@ -6980,7 +6980,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
36107
36108 spin_unlock(&pers_lock);
36109 seq_printf(seq, "\n");
36110- seq->poll_event = atomic_read(&md_event_count);
36111+ seq->poll_event = atomic_read_unchecked(&md_event_count);
36112 return 0;
36113 }
36114 if (v == (void*)2) {
36115@@ -7083,7 +7083,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
36116 return error;
36117
36118 seq = file->private_data;
36119- seq->poll_event = atomic_read(&md_event_count);
36120+ seq->poll_event = atomic_read_unchecked(&md_event_count);
36121 return error;
36122 }
36123
36124@@ -7097,7 +7097,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
36125 /* always allow read */
36126 mask = POLLIN | POLLRDNORM;
36127
36128- if (seq->poll_event != atomic_read(&md_event_count))
36129+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
36130 mask |= POLLERR | POLLPRI;
36131 return mask;
36132 }
36133@@ -7141,7 +7141,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
36134 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
36135 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
36136 (int)part_stat_read(&disk->part0, sectors[1]) -
36137- atomic_read(&disk->sync_io);
36138+ atomic_read_unchecked(&disk->sync_io);
36139 /* sync IO will cause sync_io to increase before the disk_stats
36140 * as sync_io is counted when a request starts, and
36141 * disk_stats is counted when it completes.
36142diff --git a/drivers/md/md.h b/drivers/md/md.h
36143index eca59c3..7c42285 100644
36144--- a/drivers/md/md.h
36145+++ b/drivers/md/md.h
36146@@ -94,13 +94,13 @@ struct md_rdev {
36147 * only maintained for arrays that
36148 * support hot removal
36149 */
36150- atomic_t read_errors; /* number of consecutive read errors that
36151+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
36152 * we have tried to ignore.
36153 */
36154 struct timespec last_read_error; /* monotonic time since our
36155 * last read error
36156 */
36157- atomic_t corrected_errors; /* number of corrected read errors,
36158+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
36159 * for reporting to userspace and storing
36160 * in superblock.
36161 */
36162@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
36163
36164 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
36165 {
36166- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36167+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36168 }
36169
36170 struct md_personality
36171diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
36172index 1cbfc6b..56e1dbb 100644
36173--- a/drivers/md/persistent-data/dm-space-map.h
36174+++ b/drivers/md/persistent-data/dm-space-map.h
36175@@ -60,6 +60,7 @@ struct dm_space_map {
36176 int (*root_size)(struct dm_space_map *sm, size_t *result);
36177 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
36178 };
36179+typedef struct dm_space_map __no_const dm_space_map_no_const;
36180
36181 /*----------------------------------------------------------------*/
36182
36183diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
36184index d5bddfc..b079b4b 100644
36185--- a/drivers/md/raid1.c
36186+++ b/drivers/md/raid1.c
36187@@ -1818,7 +1818,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
36188 if (r1_sync_page_io(rdev, sect, s,
36189 bio->bi_io_vec[idx].bv_page,
36190 READ) != 0)
36191- atomic_add(s, &rdev->corrected_errors);
36192+ atomic_add_unchecked(s, &rdev->corrected_errors);
36193 }
36194 sectors -= s;
36195 sect += s;
36196@@ -2040,7 +2040,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
36197 test_bit(In_sync, &rdev->flags)) {
36198 if (r1_sync_page_io(rdev, sect, s,
36199 conf->tmppage, READ)) {
36200- atomic_add(s, &rdev->corrected_errors);
36201+ atomic_add_unchecked(s, &rdev->corrected_errors);
36202 printk(KERN_INFO
36203 "md/raid1:%s: read error corrected "
36204 "(%d sectors at %llu on %s)\n",
36205diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
36206index 64d4824..8b9ea57 100644
36207--- a/drivers/md/raid10.c
36208+++ b/drivers/md/raid10.c
36209@@ -1877,7 +1877,7 @@ static void end_sync_read(struct bio *bio, int error)
36210 /* The write handler will notice the lack of
36211 * R10BIO_Uptodate and record any errors etc
36212 */
36213- atomic_add(r10_bio->sectors,
36214+ atomic_add_unchecked(r10_bio->sectors,
36215 &conf->mirrors[d].rdev->corrected_errors);
36216
36217 /* for reconstruct, we always reschedule after a read.
36218@@ -2226,7 +2226,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
36219 {
36220 struct timespec cur_time_mon;
36221 unsigned long hours_since_last;
36222- unsigned int read_errors = atomic_read(&rdev->read_errors);
36223+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
36224
36225 ktime_get_ts(&cur_time_mon);
36226
36227@@ -2248,9 +2248,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
36228 * overflowing the shift of read_errors by hours_since_last.
36229 */
36230 if (hours_since_last >= 8 * sizeof(read_errors))
36231- atomic_set(&rdev->read_errors, 0);
36232+ atomic_set_unchecked(&rdev->read_errors, 0);
36233 else
36234- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
36235+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
36236 }
36237
36238 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
36239@@ -2304,8 +2304,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
36240 return;
36241
36242 check_decay_read_errors(mddev, rdev);
36243- atomic_inc(&rdev->read_errors);
36244- if (atomic_read(&rdev->read_errors) > max_read_errors) {
36245+ atomic_inc_unchecked(&rdev->read_errors);
36246+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
36247 char b[BDEVNAME_SIZE];
36248 bdevname(rdev->bdev, b);
36249
36250@@ -2313,7 +2313,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
36251 "md/raid10:%s: %s: Raid device exceeded "
36252 "read_error threshold [cur %d:max %d]\n",
36253 mdname(mddev), b,
36254- atomic_read(&rdev->read_errors), max_read_errors);
36255+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
36256 printk(KERN_NOTICE
36257 "md/raid10:%s: %s: Failing raid device\n",
36258 mdname(mddev), b);
36259@@ -2468,7 +2468,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
36260 sect +
36261 choose_data_offset(r10_bio, rdev)),
36262 bdevname(rdev->bdev, b));
36263- atomic_add(s, &rdev->corrected_errors);
36264+ atomic_add_unchecked(s, &rdev->corrected_errors);
36265 }
36266
36267 rdev_dec_pending(rdev, mddev);
36268diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
36269index 19d77a0..56051b92 100644
36270--- a/drivers/md/raid5.c
36271+++ b/drivers/md/raid5.c
36272@@ -1797,21 +1797,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
36273 mdname(conf->mddev), STRIPE_SECTORS,
36274 (unsigned long long)s,
36275 bdevname(rdev->bdev, b));
36276- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
36277+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
36278 clear_bit(R5_ReadError, &sh->dev[i].flags);
36279 clear_bit(R5_ReWrite, &sh->dev[i].flags);
36280 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
36281 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
36282
36283- if (atomic_read(&rdev->read_errors))
36284- atomic_set(&rdev->read_errors, 0);
36285+ if (atomic_read_unchecked(&rdev->read_errors))
36286+ atomic_set_unchecked(&rdev->read_errors, 0);
36287 } else {
36288 const char *bdn = bdevname(rdev->bdev, b);
36289 int retry = 0;
36290 int set_bad = 0;
36291
36292 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
36293- atomic_inc(&rdev->read_errors);
36294+ atomic_inc_unchecked(&rdev->read_errors);
36295 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
36296 printk_ratelimited(
36297 KERN_WARNING
36298@@ -1839,7 +1839,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
36299 mdname(conf->mddev),
36300 (unsigned long long)s,
36301 bdn);
36302- } else if (atomic_read(&rdev->read_errors)
36303+ } else if (atomic_read_unchecked(&rdev->read_errors)
36304 > conf->max_nr_stripes)
36305 printk(KERN_WARNING
36306 "md/raid:%s: Too many read errors, failing device %s.\n",
36307diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
36308index d33101a..6b13069 100644
36309--- a/drivers/media/dvb-core/dvbdev.c
36310+++ b/drivers/media/dvb-core/dvbdev.c
36311@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
36312 const struct dvb_device *template, void *priv, int type)
36313 {
36314 struct dvb_device *dvbdev;
36315- struct file_operations *dvbdevfops;
36316+ file_operations_no_const *dvbdevfops;
36317 struct device *clsdev;
36318 int minor;
36319 int id;
36320diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
36321index 404f63a..4796533 100644
36322--- a/drivers/media/dvb-frontends/dib3000.h
36323+++ b/drivers/media/dvb-frontends/dib3000.h
36324@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
36325 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
36326 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
36327 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
36328-};
36329+} __no_const;
36330
36331 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
36332 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
36333diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
36334index 35cc526..9d90d83 100644
36335--- a/drivers/media/platform/omap/omap_vout.c
36336+++ b/drivers/media/platform/omap/omap_vout.c
36337@@ -63,7 +63,6 @@ enum omap_vout_channels {
36338 OMAP_VIDEO2,
36339 };
36340
36341-static struct videobuf_queue_ops video_vbq_ops;
36342 /* Variables configurable through module params*/
36343 static u32 video1_numbuffers = 3;
36344 static u32 video2_numbuffers = 3;
36345@@ -1010,6 +1009,12 @@ static int omap_vout_open(struct file *file)
36346 {
36347 struct videobuf_queue *q;
36348 struct omap_vout_device *vout = NULL;
36349+ static struct videobuf_queue_ops video_vbq_ops = {
36350+ .buf_setup = omap_vout_buffer_setup,
36351+ .buf_prepare = omap_vout_buffer_prepare,
36352+ .buf_release = omap_vout_buffer_release,
36353+ .buf_queue = omap_vout_buffer_queue,
36354+ };
36355
36356 vout = video_drvdata(file);
36357 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
36358@@ -1027,10 +1032,6 @@ static int omap_vout_open(struct file *file)
36359 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
36360
36361 q = &vout->vbq;
36362- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
36363- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
36364- video_vbq_ops.buf_release = omap_vout_buffer_release;
36365- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
36366 spin_lock_init(&vout->vbq_lock);
36367
36368 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
36369diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
36370index b671e20..34088b7 100644
36371--- a/drivers/media/platform/s5p-tv/mixer.h
36372+++ b/drivers/media/platform/s5p-tv/mixer.h
36373@@ -155,7 +155,7 @@ struct mxr_layer {
36374 /** layer index (unique identifier) */
36375 int idx;
36376 /** callbacks for layer methods */
36377- struct mxr_layer_ops ops;
36378+ struct mxr_layer_ops *ops;
36379 /** format array */
36380 const struct mxr_format **fmt_array;
36381 /** size of format array */
36382diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
36383index b93a21f..2535195 100644
36384--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
36385+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
36386@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
36387 {
36388 struct mxr_layer *layer;
36389 int ret;
36390- struct mxr_layer_ops ops = {
36391+ static struct mxr_layer_ops ops = {
36392 .release = mxr_graph_layer_release,
36393 .buffer_set = mxr_graph_buffer_set,
36394 .stream_set = mxr_graph_stream_set,
36395diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
36396index 3b1670a..595c939 100644
36397--- a/drivers/media/platform/s5p-tv/mixer_reg.c
36398+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
36399@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
36400 layer->update_buf = next;
36401 }
36402
36403- layer->ops.buffer_set(layer, layer->update_buf);
36404+ layer->ops->buffer_set(layer, layer->update_buf);
36405
36406 if (done && done != layer->shadow_buf)
36407 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
36408diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
36409index 1f3b743..e839271 100644
36410--- a/drivers/media/platform/s5p-tv/mixer_video.c
36411+++ b/drivers/media/platform/s5p-tv/mixer_video.c
36412@@ -208,7 +208,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
36413 layer->geo.src.height = layer->geo.src.full_height;
36414
36415 mxr_geometry_dump(mdev, &layer->geo);
36416- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36417+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36418 mxr_geometry_dump(mdev, &layer->geo);
36419 }
36420
36421@@ -226,7 +226,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
36422 layer->geo.dst.full_width = mbus_fmt.width;
36423 layer->geo.dst.full_height = mbus_fmt.height;
36424 layer->geo.dst.field = mbus_fmt.field;
36425- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36426+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36427
36428 mxr_geometry_dump(mdev, &layer->geo);
36429 }
36430@@ -332,7 +332,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
36431 /* set source size to highest accepted value */
36432 geo->src.full_width = max(geo->dst.full_width, pix->width);
36433 geo->src.full_height = max(geo->dst.full_height, pix->height);
36434- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36435+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36436 mxr_geometry_dump(mdev, &layer->geo);
36437 /* set cropping to total visible screen */
36438 geo->src.width = pix->width;
36439@@ -340,12 +340,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
36440 geo->src.x_offset = 0;
36441 geo->src.y_offset = 0;
36442 /* assure consistency of geometry */
36443- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
36444+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
36445 mxr_geometry_dump(mdev, &layer->geo);
36446 /* set full size to lowest possible value */
36447 geo->src.full_width = 0;
36448 geo->src.full_height = 0;
36449- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36450+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36451 mxr_geometry_dump(mdev, &layer->geo);
36452
36453 /* returning results */
36454@@ -472,7 +472,7 @@ static int mxr_s_selection(struct file *file, void *fh,
36455 target->width = s->r.width;
36456 target->height = s->r.height;
36457
36458- layer->ops.fix_geometry(layer, stage, s->flags);
36459+ layer->ops->fix_geometry(layer, stage, s->flags);
36460
36461 /* retrieve update selection rectangle */
36462 res.left = target->x_offset;
36463@@ -937,13 +937,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
36464 mxr_output_get(mdev);
36465
36466 mxr_layer_update_output(layer);
36467- layer->ops.format_set(layer);
36468+ layer->ops->format_set(layer);
36469 /* enabling layer in hardware */
36470 spin_lock_irqsave(&layer->enq_slock, flags);
36471 layer->state = MXR_LAYER_STREAMING;
36472 spin_unlock_irqrestore(&layer->enq_slock, flags);
36473
36474- layer->ops.stream_set(layer, MXR_ENABLE);
36475+ layer->ops->stream_set(layer, MXR_ENABLE);
36476 mxr_streamer_get(mdev);
36477
36478 return 0;
36479@@ -1013,7 +1013,7 @@ static int stop_streaming(struct vb2_queue *vq)
36480 spin_unlock_irqrestore(&layer->enq_slock, flags);
36481
36482 /* disabling layer in hardware */
36483- layer->ops.stream_set(layer, MXR_DISABLE);
36484+ layer->ops->stream_set(layer, MXR_DISABLE);
36485 /* remove one streamer */
36486 mxr_streamer_put(mdev);
36487 /* allow changes in output configuration */
36488@@ -1052,8 +1052,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
36489
36490 void mxr_layer_release(struct mxr_layer *layer)
36491 {
36492- if (layer->ops.release)
36493- layer->ops.release(layer);
36494+ if (layer->ops->release)
36495+ layer->ops->release(layer);
36496 }
36497
36498 void mxr_base_layer_release(struct mxr_layer *layer)
36499@@ -1079,7 +1079,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
36500
36501 layer->mdev = mdev;
36502 layer->idx = idx;
36503- layer->ops = *ops;
36504+ layer->ops = ops;
36505
36506 spin_lock_init(&layer->enq_slock);
36507 INIT_LIST_HEAD(&layer->enq_list);
36508diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
36509index 3d13a63..da31bf1 100644
36510--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
36511+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
36512@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
36513 {
36514 struct mxr_layer *layer;
36515 int ret;
36516- struct mxr_layer_ops ops = {
36517+ static struct mxr_layer_ops ops = {
36518 .release = mxr_vp_layer_release,
36519 .buffer_set = mxr_vp_buffer_set,
36520 .stream_set = mxr_vp_stream_set,
36521diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
36522index 643d80a..56bb96b 100644
36523--- a/drivers/media/radio/radio-cadet.c
36524+++ b/drivers/media/radio/radio-cadet.c
36525@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
36526 unsigned char readbuf[RDS_BUFFER];
36527 int i = 0;
36528
36529+ if (count > RDS_BUFFER)
36530+ return -EFAULT;
36531 mutex_lock(&dev->lock);
36532 if (dev->rdsstat == 0)
36533 cadet_start_rds(dev);
36534@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
36535 while (i < count && dev->rdsin != dev->rdsout)
36536 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
36537
36538- if (i && copy_to_user(data, readbuf, i))
36539+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
36540 i = -EFAULT;
36541 unlock:
36542 mutex_unlock(&dev->lock);
36543diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
36544index 3940bb0..fb3952a 100644
36545--- a/drivers/media/usb/dvb-usb/cxusb.c
36546+++ b/drivers/media/usb/dvb-usb/cxusb.c
36547@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
36548
36549 struct dib0700_adapter_state {
36550 int (*set_param_save) (struct dvb_frontend *);
36551-};
36552+} __no_const;
36553
36554 static int dib7070_set_param_override(struct dvb_frontend *fe)
36555 {
36556diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
36557index 9382895..ac8093c 100644
36558--- a/drivers/media/usb/dvb-usb/dw2102.c
36559+++ b/drivers/media/usb/dvb-usb/dw2102.c
36560@@ -95,7 +95,7 @@ struct su3000_state {
36561
36562 struct s6x0_state {
36563 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
36564-};
36565+} __no_const;
36566
36567 /* debug */
36568 static int dvb_usb_dw2102_debug;
36569diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
36570index fb69baa..cf7ad22 100644
36571--- a/drivers/message/fusion/mptbase.c
36572+++ b/drivers/message/fusion/mptbase.c
36573@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
36574 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
36575 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
36576
36577+#ifdef CONFIG_GRKERNSEC_HIDESYM
36578+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
36579+#else
36580 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
36581 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
36582+#endif
36583+
36584 /*
36585 * Rounding UP to nearest 4-kB boundary here...
36586 */
36587diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
36588index fa43c39..daeb158 100644
36589--- a/drivers/message/fusion/mptsas.c
36590+++ b/drivers/message/fusion/mptsas.c
36591@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
36592 return 0;
36593 }
36594
36595+static inline void
36596+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
36597+{
36598+ if (phy_info->port_details) {
36599+ phy_info->port_details->rphy = rphy;
36600+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
36601+ ioc->name, rphy));
36602+ }
36603+
36604+ if (rphy) {
36605+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
36606+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
36607+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
36608+ ioc->name, rphy, rphy->dev.release));
36609+ }
36610+}
36611+
36612 /* no mutex */
36613 static void
36614 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
36615@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
36616 return NULL;
36617 }
36618
36619-static inline void
36620-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
36621-{
36622- if (phy_info->port_details) {
36623- phy_info->port_details->rphy = rphy;
36624- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
36625- ioc->name, rphy));
36626- }
36627-
36628- if (rphy) {
36629- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
36630- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
36631- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
36632- ioc->name, rphy, rphy->dev.release));
36633- }
36634-}
36635-
36636 static inline struct sas_port *
36637 mptsas_get_port(struct mptsas_phyinfo *phy_info)
36638 {
36639diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
36640index 164afa7..b6b2e74 100644
36641--- a/drivers/message/fusion/mptscsih.c
36642+++ b/drivers/message/fusion/mptscsih.c
36643@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
36644
36645 h = shost_priv(SChost);
36646
36647- if (h) {
36648- if (h->info_kbuf == NULL)
36649- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36650- return h->info_kbuf;
36651- h->info_kbuf[0] = '\0';
36652+ if (!h)
36653+ return NULL;
36654
36655- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36656- h->info_kbuf[size-1] = '\0';
36657- }
36658+ if (h->info_kbuf == NULL)
36659+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36660+ return h->info_kbuf;
36661+ h->info_kbuf[0] = '\0';
36662+
36663+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36664+ h->info_kbuf[size-1] = '\0';
36665
36666 return h->info_kbuf;
36667 }
36668diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
36669index 8001aa6..b137580 100644
36670--- a/drivers/message/i2o/i2o_proc.c
36671+++ b/drivers/message/i2o/i2o_proc.c
36672@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
36673 "Array Controller Device"
36674 };
36675
36676-static char *chtostr(char *tmp, u8 *chars, int n)
36677-{
36678- tmp[0] = 0;
36679- return strncat(tmp, (char *)chars, n);
36680-}
36681-
36682 static int i2o_report_query_status(struct seq_file *seq, int block_status,
36683 char *group)
36684 {
36685@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36686 } *result;
36687
36688 i2o_exec_execute_ddm_table ddm_table;
36689- char tmp[28 + 1];
36690
36691 result = kmalloc(sizeof(*result), GFP_KERNEL);
36692 if (!result)
36693@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36694
36695 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
36696 seq_printf(seq, "%-#8x", ddm_table.module_id);
36697- seq_printf(seq, "%-29s",
36698- chtostr(tmp, ddm_table.module_name_version, 28));
36699+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
36700 seq_printf(seq, "%9d ", ddm_table.data_size);
36701 seq_printf(seq, "%8d", ddm_table.code_size);
36702
36703@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36704
36705 i2o_driver_result_table *result;
36706 i2o_driver_store_table *dst;
36707- char tmp[28 + 1];
36708
36709 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
36710 if (result == NULL)
36711@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36712
36713 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
36714 seq_printf(seq, "%-#8x", dst->module_id);
36715- seq_printf(seq, "%-29s",
36716- chtostr(tmp, dst->module_name_version, 28));
36717- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
36718+ seq_printf(seq, "%-.28s", dst->module_name_version);
36719+ seq_printf(seq, "%-.8s", dst->date);
36720 seq_printf(seq, "%8d ", dst->module_size);
36721 seq_printf(seq, "%8d ", dst->mpb_size);
36722 seq_printf(seq, "0x%04x", dst->module_flags);
36723@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36724 // == (allow) 512d bytes (max)
36725 static u16 *work16 = (u16 *) work32;
36726 int token;
36727- char tmp[16 + 1];
36728
36729 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
36730
36731@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36732 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
36733 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
36734 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
36735- seq_printf(seq, "Vendor info : %s\n",
36736- chtostr(tmp, (u8 *) (work32 + 2), 16));
36737- seq_printf(seq, "Product info : %s\n",
36738- chtostr(tmp, (u8 *) (work32 + 6), 16));
36739- seq_printf(seq, "Description : %s\n",
36740- chtostr(tmp, (u8 *) (work32 + 10), 16));
36741- seq_printf(seq, "Product rev. : %s\n",
36742- chtostr(tmp, (u8 *) (work32 + 14), 8));
36743+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
36744+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
36745+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
36746+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
36747
36748 seq_printf(seq, "Serial number : ");
36749 print_serial_number(seq, (u8 *) (work32 + 16),
36750@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36751 u8 pad[256]; // allow up to 256 byte (max) serial number
36752 } result;
36753
36754- char tmp[24 + 1];
36755-
36756 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
36757
36758 if (token < 0) {
36759@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36760 }
36761
36762 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
36763- seq_printf(seq, "Module name : %s\n",
36764- chtostr(tmp, result.module_name, 24));
36765- seq_printf(seq, "Module revision : %s\n",
36766- chtostr(tmp, result.module_rev, 8));
36767+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
36768+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
36769
36770 seq_printf(seq, "Serial number : ");
36771 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
36772@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36773 u8 instance_number[4];
36774 } result;
36775
36776- char tmp[64 + 1];
36777-
36778 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
36779
36780 if (token < 0) {
36781@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36782 return 0;
36783 }
36784
36785- seq_printf(seq, "Device name : %s\n",
36786- chtostr(tmp, result.device_name, 64));
36787- seq_printf(seq, "Service name : %s\n",
36788- chtostr(tmp, result.service_name, 64));
36789- seq_printf(seq, "Physical name : %s\n",
36790- chtostr(tmp, result.physical_location, 64));
36791- seq_printf(seq, "Instance number : %s\n",
36792- chtostr(tmp, result.instance_number, 4));
36793+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
36794+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
36795+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
36796+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
36797
36798 return 0;
36799 }
36800diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
36801index a8c08f3..155fe3d 100644
36802--- a/drivers/message/i2o/iop.c
36803+++ b/drivers/message/i2o/iop.c
36804@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
36805
36806 spin_lock_irqsave(&c->context_list_lock, flags);
36807
36808- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
36809- atomic_inc(&c->context_list_counter);
36810+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
36811+ atomic_inc_unchecked(&c->context_list_counter);
36812
36813- entry->context = atomic_read(&c->context_list_counter);
36814+ entry->context = atomic_read_unchecked(&c->context_list_counter);
36815
36816 list_add(&entry->list, &c->context_list);
36817
36818@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
36819
36820 #if BITS_PER_LONG == 64
36821 spin_lock_init(&c->context_list_lock);
36822- atomic_set(&c->context_list_counter, 0);
36823+ atomic_set_unchecked(&c->context_list_counter, 0);
36824 INIT_LIST_HEAD(&c->context_list);
36825 #endif
36826
36827diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
36828index 45ece11..8efa218 100644
36829--- a/drivers/mfd/janz-cmodio.c
36830+++ b/drivers/mfd/janz-cmodio.c
36831@@ -13,6 +13,7 @@
36832
36833 #include <linux/kernel.h>
36834 #include <linux/module.h>
36835+#include <linux/slab.h>
36836 #include <linux/init.h>
36837 #include <linux/pci.h>
36838 #include <linux/interrupt.h>
36839diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
36840index 3aa9a96..59cf685 100644
36841--- a/drivers/misc/kgdbts.c
36842+++ b/drivers/misc/kgdbts.c
36843@@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
36844 char before[BREAK_INSTR_SIZE];
36845 char after[BREAK_INSTR_SIZE];
36846
36847- probe_kernel_read(before, (char *)kgdbts_break_test,
36848+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
36849 BREAK_INSTR_SIZE);
36850 init_simple_test();
36851 ts.tst = plant_and_detach_test;
36852@@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
36853 /* Activate test with initial breakpoint */
36854 if (!is_early)
36855 kgdb_breakpoint();
36856- probe_kernel_read(after, (char *)kgdbts_break_test,
36857+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
36858 BREAK_INSTR_SIZE);
36859 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
36860 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
36861diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
36862index 4a87e5c..76bdf5c 100644
36863--- a/drivers/misc/lis3lv02d/lis3lv02d.c
36864+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
36865@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
36866 * the lid is closed. This leads to interrupts as soon as a little move
36867 * is done.
36868 */
36869- atomic_inc(&lis3->count);
36870+ atomic_inc_unchecked(&lis3->count);
36871
36872 wake_up_interruptible(&lis3->misc_wait);
36873 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
36874@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
36875 if (lis3->pm_dev)
36876 pm_runtime_get_sync(lis3->pm_dev);
36877
36878- atomic_set(&lis3->count, 0);
36879+ atomic_set_unchecked(&lis3->count, 0);
36880 return 0;
36881 }
36882
36883@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
36884 add_wait_queue(&lis3->misc_wait, &wait);
36885 while (true) {
36886 set_current_state(TASK_INTERRUPTIBLE);
36887- data = atomic_xchg(&lis3->count, 0);
36888+ data = atomic_xchg_unchecked(&lis3->count, 0);
36889 if (data)
36890 break;
36891
36892@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
36893 struct lis3lv02d, miscdev);
36894
36895 poll_wait(file, &lis3->misc_wait, wait);
36896- if (atomic_read(&lis3->count))
36897+ if (atomic_read_unchecked(&lis3->count))
36898 return POLLIN | POLLRDNORM;
36899 return 0;
36900 }
36901diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
36902index c439c82..1f20f57 100644
36903--- a/drivers/misc/lis3lv02d/lis3lv02d.h
36904+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
36905@@ -297,7 +297,7 @@ struct lis3lv02d {
36906 struct input_polled_dev *idev; /* input device */
36907 struct platform_device *pdev; /* platform device */
36908 struct regulator_bulk_data regulators[2];
36909- atomic_t count; /* interrupt count after last read */
36910+ atomic_unchecked_t count; /* interrupt count after last read */
36911 union axis_conversion ac; /* hw -> logical axis */
36912 int mapped_btns[3];
36913
36914diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
36915index 2f30bad..c4c13d0 100644
36916--- a/drivers/misc/sgi-gru/gruhandles.c
36917+++ b/drivers/misc/sgi-gru/gruhandles.c
36918@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
36919 unsigned long nsec;
36920
36921 nsec = CLKS2NSEC(clks);
36922- atomic_long_inc(&mcs_op_statistics[op].count);
36923- atomic_long_add(nsec, &mcs_op_statistics[op].total);
36924+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
36925+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
36926 if (mcs_op_statistics[op].max < nsec)
36927 mcs_op_statistics[op].max = nsec;
36928 }
36929diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
36930index 950dbe9..eeef0f8 100644
36931--- a/drivers/misc/sgi-gru/gruprocfs.c
36932+++ b/drivers/misc/sgi-gru/gruprocfs.c
36933@@ -32,9 +32,9 @@
36934
36935 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
36936
36937-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
36938+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
36939 {
36940- unsigned long val = atomic_long_read(v);
36941+ unsigned long val = atomic_long_read_unchecked(v);
36942
36943 seq_printf(s, "%16lu %s\n", val, id);
36944 }
36945@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
36946
36947 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
36948 for (op = 0; op < mcsop_last; op++) {
36949- count = atomic_long_read(&mcs_op_statistics[op].count);
36950- total = atomic_long_read(&mcs_op_statistics[op].total);
36951+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
36952+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
36953 max = mcs_op_statistics[op].max;
36954 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
36955 count ? total / count : 0, max);
36956diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
36957index 5c3ce24..4915ccb 100644
36958--- a/drivers/misc/sgi-gru/grutables.h
36959+++ b/drivers/misc/sgi-gru/grutables.h
36960@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
36961 * GRU statistics.
36962 */
36963 struct gru_stats_s {
36964- atomic_long_t vdata_alloc;
36965- atomic_long_t vdata_free;
36966- atomic_long_t gts_alloc;
36967- atomic_long_t gts_free;
36968- atomic_long_t gms_alloc;
36969- atomic_long_t gms_free;
36970- atomic_long_t gts_double_allocate;
36971- atomic_long_t assign_context;
36972- atomic_long_t assign_context_failed;
36973- atomic_long_t free_context;
36974- atomic_long_t load_user_context;
36975- atomic_long_t load_kernel_context;
36976- atomic_long_t lock_kernel_context;
36977- atomic_long_t unlock_kernel_context;
36978- atomic_long_t steal_user_context;
36979- atomic_long_t steal_kernel_context;
36980- atomic_long_t steal_context_failed;
36981- atomic_long_t nopfn;
36982- atomic_long_t asid_new;
36983- atomic_long_t asid_next;
36984- atomic_long_t asid_wrap;
36985- atomic_long_t asid_reuse;
36986- atomic_long_t intr;
36987- atomic_long_t intr_cbr;
36988- atomic_long_t intr_tfh;
36989- atomic_long_t intr_spurious;
36990- atomic_long_t intr_mm_lock_failed;
36991- atomic_long_t call_os;
36992- atomic_long_t call_os_wait_queue;
36993- atomic_long_t user_flush_tlb;
36994- atomic_long_t user_unload_context;
36995- atomic_long_t user_exception;
36996- atomic_long_t set_context_option;
36997- atomic_long_t check_context_retarget_intr;
36998- atomic_long_t check_context_unload;
36999- atomic_long_t tlb_dropin;
37000- atomic_long_t tlb_preload_page;
37001- atomic_long_t tlb_dropin_fail_no_asid;
37002- atomic_long_t tlb_dropin_fail_upm;
37003- atomic_long_t tlb_dropin_fail_invalid;
37004- atomic_long_t tlb_dropin_fail_range_active;
37005- atomic_long_t tlb_dropin_fail_idle;
37006- atomic_long_t tlb_dropin_fail_fmm;
37007- atomic_long_t tlb_dropin_fail_no_exception;
37008- atomic_long_t tfh_stale_on_fault;
37009- atomic_long_t mmu_invalidate_range;
37010- atomic_long_t mmu_invalidate_page;
37011- atomic_long_t flush_tlb;
37012- atomic_long_t flush_tlb_gru;
37013- atomic_long_t flush_tlb_gru_tgh;
37014- atomic_long_t flush_tlb_gru_zero_asid;
37015+ atomic_long_unchecked_t vdata_alloc;
37016+ atomic_long_unchecked_t vdata_free;
37017+ atomic_long_unchecked_t gts_alloc;
37018+ atomic_long_unchecked_t gts_free;
37019+ atomic_long_unchecked_t gms_alloc;
37020+ atomic_long_unchecked_t gms_free;
37021+ atomic_long_unchecked_t gts_double_allocate;
37022+ atomic_long_unchecked_t assign_context;
37023+ atomic_long_unchecked_t assign_context_failed;
37024+ atomic_long_unchecked_t free_context;
37025+ atomic_long_unchecked_t load_user_context;
37026+ atomic_long_unchecked_t load_kernel_context;
37027+ atomic_long_unchecked_t lock_kernel_context;
37028+ atomic_long_unchecked_t unlock_kernel_context;
37029+ atomic_long_unchecked_t steal_user_context;
37030+ atomic_long_unchecked_t steal_kernel_context;
37031+ atomic_long_unchecked_t steal_context_failed;
37032+ atomic_long_unchecked_t nopfn;
37033+ atomic_long_unchecked_t asid_new;
37034+ atomic_long_unchecked_t asid_next;
37035+ atomic_long_unchecked_t asid_wrap;
37036+ atomic_long_unchecked_t asid_reuse;
37037+ atomic_long_unchecked_t intr;
37038+ atomic_long_unchecked_t intr_cbr;
37039+ atomic_long_unchecked_t intr_tfh;
37040+ atomic_long_unchecked_t intr_spurious;
37041+ atomic_long_unchecked_t intr_mm_lock_failed;
37042+ atomic_long_unchecked_t call_os;
37043+ atomic_long_unchecked_t call_os_wait_queue;
37044+ atomic_long_unchecked_t user_flush_tlb;
37045+ atomic_long_unchecked_t user_unload_context;
37046+ atomic_long_unchecked_t user_exception;
37047+ atomic_long_unchecked_t set_context_option;
37048+ atomic_long_unchecked_t check_context_retarget_intr;
37049+ atomic_long_unchecked_t check_context_unload;
37050+ atomic_long_unchecked_t tlb_dropin;
37051+ atomic_long_unchecked_t tlb_preload_page;
37052+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
37053+ atomic_long_unchecked_t tlb_dropin_fail_upm;
37054+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
37055+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
37056+ atomic_long_unchecked_t tlb_dropin_fail_idle;
37057+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
37058+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
37059+ atomic_long_unchecked_t tfh_stale_on_fault;
37060+ atomic_long_unchecked_t mmu_invalidate_range;
37061+ atomic_long_unchecked_t mmu_invalidate_page;
37062+ atomic_long_unchecked_t flush_tlb;
37063+ atomic_long_unchecked_t flush_tlb_gru;
37064+ atomic_long_unchecked_t flush_tlb_gru_tgh;
37065+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
37066
37067- atomic_long_t copy_gpa;
37068- atomic_long_t read_gpa;
37069+ atomic_long_unchecked_t copy_gpa;
37070+ atomic_long_unchecked_t read_gpa;
37071
37072- atomic_long_t mesq_receive;
37073- atomic_long_t mesq_receive_none;
37074- atomic_long_t mesq_send;
37075- atomic_long_t mesq_send_failed;
37076- atomic_long_t mesq_noop;
37077- atomic_long_t mesq_send_unexpected_error;
37078- atomic_long_t mesq_send_lb_overflow;
37079- atomic_long_t mesq_send_qlimit_reached;
37080- atomic_long_t mesq_send_amo_nacked;
37081- atomic_long_t mesq_send_put_nacked;
37082- atomic_long_t mesq_page_overflow;
37083- atomic_long_t mesq_qf_locked;
37084- atomic_long_t mesq_qf_noop_not_full;
37085- atomic_long_t mesq_qf_switch_head_failed;
37086- atomic_long_t mesq_qf_unexpected_error;
37087- atomic_long_t mesq_noop_unexpected_error;
37088- atomic_long_t mesq_noop_lb_overflow;
37089- atomic_long_t mesq_noop_qlimit_reached;
37090- atomic_long_t mesq_noop_amo_nacked;
37091- atomic_long_t mesq_noop_put_nacked;
37092- atomic_long_t mesq_noop_page_overflow;
37093+ atomic_long_unchecked_t mesq_receive;
37094+ atomic_long_unchecked_t mesq_receive_none;
37095+ atomic_long_unchecked_t mesq_send;
37096+ atomic_long_unchecked_t mesq_send_failed;
37097+ atomic_long_unchecked_t mesq_noop;
37098+ atomic_long_unchecked_t mesq_send_unexpected_error;
37099+ atomic_long_unchecked_t mesq_send_lb_overflow;
37100+ atomic_long_unchecked_t mesq_send_qlimit_reached;
37101+ atomic_long_unchecked_t mesq_send_amo_nacked;
37102+ atomic_long_unchecked_t mesq_send_put_nacked;
37103+ atomic_long_unchecked_t mesq_page_overflow;
37104+ atomic_long_unchecked_t mesq_qf_locked;
37105+ atomic_long_unchecked_t mesq_qf_noop_not_full;
37106+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
37107+ atomic_long_unchecked_t mesq_qf_unexpected_error;
37108+ atomic_long_unchecked_t mesq_noop_unexpected_error;
37109+ atomic_long_unchecked_t mesq_noop_lb_overflow;
37110+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
37111+ atomic_long_unchecked_t mesq_noop_amo_nacked;
37112+ atomic_long_unchecked_t mesq_noop_put_nacked;
37113+ atomic_long_unchecked_t mesq_noop_page_overflow;
37114
37115 };
37116
37117@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
37118 tghop_invalidate, mcsop_last};
37119
37120 struct mcs_op_statistic {
37121- atomic_long_t count;
37122- atomic_long_t total;
37123+ atomic_long_unchecked_t count;
37124+ atomic_long_unchecked_t total;
37125 unsigned long max;
37126 };
37127
37128@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
37129
37130 #define STAT(id) do { \
37131 if (gru_options & OPT_STATS) \
37132- atomic_long_inc(&gru_stats.id); \
37133+ atomic_long_inc_unchecked(&gru_stats.id); \
37134 } while (0)
37135
37136 #ifdef CONFIG_SGI_GRU_DEBUG
37137diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
37138index c862cd4..0d176fe 100644
37139--- a/drivers/misc/sgi-xp/xp.h
37140+++ b/drivers/misc/sgi-xp/xp.h
37141@@ -288,7 +288,7 @@ struct xpc_interface {
37142 xpc_notify_func, void *);
37143 void (*received) (short, int, void *);
37144 enum xp_retval (*partid_to_nasids) (short, void *);
37145-};
37146+} __no_const;
37147
37148 extern struct xpc_interface xpc_interface;
37149
37150diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
37151index b94d5f7..7f494c5 100644
37152--- a/drivers/misc/sgi-xp/xpc.h
37153+++ b/drivers/misc/sgi-xp/xpc.h
37154@@ -835,6 +835,7 @@ struct xpc_arch_operations {
37155 void (*received_payload) (struct xpc_channel *, void *);
37156 void (*notify_senders_of_disconnect) (struct xpc_channel *);
37157 };
37158+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
37159
37160 /* struct xpc_partition act_state values (for XPC HB) */
37161
37162@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
37163 /* found in xpc_main.c */
37164 extern struct device *xpc_part;
37165 extern struct device *xpc_chan;
37166-extern struct xpc_arch_operations xpc_arch_ops;
37167+extern xpc_arch_operations_no_const xpc_arch_ops;
37168 extern int xpc_disengage_timelimit;
37169 extern int xpc_disengage_timedout;
37170 extern int xpc_activate_IRQ_rcvd;
37171diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
37172index d971817..33bdca5 100644
37173--- a/drivers/misc/sgi-xp/xpc_main.c
37174+++ b/drivers/misc/sgi-xp/xpc_main.c
37175@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
37176 .notifier_call = xpc_system_die,
37177 };
37178
37179-struct xpc_arch_operations xpc_arch_ops;
37180+xpc_arch_operations_no_const xpc_arch_ops;
37181
37182 /*
37183 * Timer function to enforce the timelimit on the partition disengage.
37184@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
37185
37186 if (((die_args->trapnr == X86_TRAP_MF) ||
37187 (die_args->trapnr == X86_TRAP_XF)) &&
37188- !user_mode_vm(die_args->regs))
37189+ !user_mode(die_args->regs))
37190 xpc_die_deactivate();
37191
37192 break;
37193diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
37194index 6d8f701..35b6369 100644
37195--- a/drivers/mmc/core/mmc_ops.c
37196+++ b/drivers/mmc/core/mmc_ops.c
37197@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
37198 void *data_buf;
37199 int is_on_stack;
37200
37201- is_on_stack = object_is_on_stack(buf);
37202+ is_on_stack = object_starts_on_stack(buf);
37203 if (is_on_stack) {
37204 /*
37205 * dma onto stack is unsafe/nonportable, but callers to this
37206diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
37207index 53b8fd9..615b462 100644
37208--- a/drivers/mmc/host/dw_mmc.h
37209+++ b/drivers/mmc/host/dw_mmc.h
37210@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
37211 int (*parse_dt)(struct dw_mci *host);
37212 int (*setup_bus)(struct dw_mci *host,
37213 struct device_node *slot_np, u8 bus_width);
37214-};
37215+} __do_const;
37216 #endif /* _DW_MMC_H_ */
37217diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
37218index 82a8de1..3c56ccb 100644
37219--- a/drivers/mmc/host/sdhci-s3c.c
37220+++ b/drivers/mmc/host/sdhci-s3c.c
37221@@ -721,9 +721,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
37222 * we can use overriding functions instead of default.
37223 */
37224 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
37225- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
37226- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
37227- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
37228+ pax_open_kernel();
37229+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
37230+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
37231+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
37232+ pax_close_kernel();
37233 }
37234
37235 /* It supports additional host capabilities if needed */
37236diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
37237index a4eb8b5..8c0628f 100644
37238--- a/drivers/mtd/devices/doc2000.c
37239+++ b/drivers/mtd/devices/doc2000.c
37240@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
37241
37242 /* The ECC will not be calculated correctly if less than 512 is written */
37243 /* DBB-
37244- if (len != 0x200 && eccbuf)
37245+ if (len != 0x200)
37246 printk(KERN_WARNING
37247 "ECC needs a full sector write (adr: %lx size %lx)\n",
37248 (long) to, (long) len);
37249diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
37250index 0c8bb6b..6f35deb 100644
37251--- a/drivers/mtd/nand/denali.c
37252+++ b/drivers/mtd/nand/denali.c
37253@@ -24,6 +24,7 @@
37254 #include <linux/slab.h>
37255 #include <linux/mtd/mtd.h>
37256 #include <linux/module.h>
37257+#include <linux/slab.h>
37258
37259 #include "denali.h"
37260
37261diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
37262index 51b9d6a..52af9a7 100644
37263--- a/drivers/mtd/nftlmount.c
37264+++ b/drivers/mtd/nftlmount.c
37265@@ -24,6 +24,7 @@
37266 #include <asm/errno.h>
37267 #include <linux/delay.h>
37268 #include <linux/slab.h>
37269+#include <linux/sched.h>
37270 #include <linux/mtd/mtd.h>
37271 #include <linux/mtd/nand.h>
37272 #include <linux/mtd/nftl.h>
37273diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
37274index 70dba5d..11a0919 100644
37275--- a/drivers/net/ethernet/8390/ax88796.c
37276+++ b/drivers/net/ethernet/8390/ax88796.c
37277@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
37278 if (ax->plat->reg_offsets)
37279 ei_local->reg_offset = ax->plat->reg_offsets;
37280 else {
37281+ resource_size_t _mem_size = mem_size;
37282+ do_div(_mem_size, 0x18);
37283 ei_local->reg_offset = ax->reg_offsets;
37284 for (ret = 0; ret < 0x18; ret++)
37285- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
37286+ ax->reg_offsets[ret] = _mem_size * ret;
37287 }
37288
37289 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
37290diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
37291index 0991534..8098e92 100644
37292--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
37293+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
37294@@ -1094,7 +1094,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
37295 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
37296 {
37297 /* RX_MODE controlling object */
37298- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
37299+ bnx2x_init_rx_mode_obj(bp);
37300
37301 /* multicast configuration controlling object */
37302 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
37303diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
37304index 09b625e..15b16fe 100644
37305--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
37306+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
37307@@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
37308 return rc;
37309 }
37310
37311-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
37312- struct bnx2x_rx_mode_obj *o)
37313+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
37314 {
37315 if (CHIP_IS_E1x(bp)) {
37316- o->wait_comp = bnx2x_empty_rx_mode_wait;
37317- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
37318+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
37319+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
37320 } else {
37321- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
37322- o->config_rx_mode = bnx2x_set_rx_mode_e2;
37323+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
37324+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
37325 }
37326 }
37327
37328diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
37329index adbd91b..58ec94a 100644
37330--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
37331+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
37332@@ -1293,8 +1293,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
37333
37334 /********************* RX MODE ****************/
37335
37336-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
37337- struct bnx2x_rx_mode_obj *o);
37338+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
37339
37340 /**
37341 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
37342diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
37343index d330e81..ce1fb9a 100644
37344--- a/drivers/net/ethernet/broadcom/tg3.h
37345+++ b/drivers/net/ethernet/broadcom/tg3.h
37346@@ -146,6 +146,7 @@
37347 #define CHIPREV_ID_5750_A0 0x4000
37348 #define CHIPREV_ID_5750_A1 0x4001
37349 #define CHIPREV_ID_5750_A3 0x4003
37350+#define CHIPREV_ID_5750_C1 0x4201
37351 #define CHIPREV_ID_5750_C2 0x4202
37352 #define CHIPREV_ID_5752_A0_HW 0x5000
37353 #define CHIPREV_ID_5752_A0 0x6000
37354diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
37355index 8cffcdf..aadf043 100644
37356--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
37357+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
37358@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
37359 */
37360 struct l2t_skb_cb {
37361 arp_failure_handler_func arp_failure_handler;
37362-};
37363+} __no_const;
37364
37365 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
37366
37367diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
37368index 4c83003..2a2a5b9 100644
37369--- a/drivers/net/ethernet/dec/tulip/de4x5.c
37370+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
37371@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
37372 for (i=0; i<ETH_ALEN; i++) {
37373 tmp.addr[i] = dev->dev_addr[i];
37374 }
37375- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
37376+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
37377 break;
37378
37379 case DE4X5_SET_HWADDR: /* Set the hardware address */
37380@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
37381 spin_lock_irqsave(&lp->lock, flags);
37382 memcpy(&statbuf, &lp->pktStats, ioc->len);
37383 spin_unlock_irqrestore(&lp->lock, flags);
37384- if (copy_to_user(ioc->data, &statbuf, ioc->len))
37385+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
37386 return -EFAULT;
37387 break;
37388 }
37389diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
37390index 4d6f3c5..6169e60 100644
37391--- a/drivers/net/ethernet/emulex/benet/be_main.c
37392+++ b/drivers/net/ethernet/emulex/benet/be_main.c
37393@@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
37394
37395 if (wrapped)
37396 newacc += 65536;
37397- ACCESS_ONCE(*acc) = newacc;
37398+ ACCESS_ONCE_RW(*acc) = newacc;
37399 }
37400
37401 void be_parse_stats(struct be_adapter *adapter)
37402diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
37403index 74d749e..eefb1bd 100644
37404--- a/drivers/net/ethernet/faraday/ftgmac100.c
37405+++ b/drivers/net/ethernet/faraday/ftgmac100.c
37406@@ -31,6 +31,8 @@
37407 #include <linux/netdevice.h>
37408 #include <linux/phy.h>
37409 #include <linux/platform_device.h>
37410+#include <linux/interrupt.h>
37411+#include <linux/irqreturn.h>
37412 #include <net/ip.h>
37413
37414 #include "ftgmac100.h"
37415diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
37416index b901a01..1ff32ee 100644
37417--- a/drivers/net/ethernet/faraday/ftmac100.c
37418+++ b/drivers/net/ethernet/faraday/ftmac100.c
37419@@ -31,6 +31,8 @@
37420 #include <linux/module.h>
37421 #include <linux/netdevice.h>
37422 #include <linux/platform_device.h>
37423+#include <linux/interrupt.h>
37424+#include <linux/irqreturn.h>
37425
37426 #include "ftmac100.h"
37427
37428diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
37429index bb9256a..56d8752 100644
37430--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
37431+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
37432@@ -806,7 +806,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
37433 }
37434
37435 /* update the base incval used to calculate frequency adjustment */
37436- ACCESS_ONCE(adapter->base_incval) = incval;
37437+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
37438 smp_mb();
37439
37440 /* need lock to prevent incorrect read while modifying cyclecounter */
37441diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
37442index fbe5363..266b4e3 100644
37443--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
37444+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
37445@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
37446 struct __vxge_hw_fifo *fifo;
37447 struct vxge_hw_fifo_config *config;
37448 u32 txdl_size, txdl_per_memblock;
37449- struct vxge_hw_mempool_cbs fifo_mp_callback;
37450+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
37451+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
37452+ };
37453+
37454 struct __vxge_hw_virtualpath *vpath;
37455
37456 if ((vp == NULL) || (attr == NULL)) {
37457@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
37458 goto exit;
37459 }
37460
37461- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
37462-
37463 fifo->mempool =
37464 __vxge_hw_mempool_create(vpath->hldev,
37465 fifo->config->memblock_size,
37466diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
37467index 998974f..ecd26db 100644
37468--- a/drivers/net/ethernet/realtek/r8169.c
37469+++ b/drivers/net/ethernet/realtek/r8169.c
37470@@ -741,22 +741,22 @@ struct rtl8169_private {
37471 struct mdio_ops {
37472 void (*write)(struct rtl8169_private *, int, int);
37473 int (*read)(struct rtl8169_private *, int);
37474- } mdio_ops;
37475+ } __no_const mdio_ops;
37476
37477 struct pll_power_ops {
37478 void (*down)(struct rtl8169_private *);
37479 void (*up)(struct rtl8169_private *);
37480- } pll_power_ops;
37481+ } __no_const pll_power_ops;
37482
37483 struct jumbo_ops {
37484 void (*enable)(struct rtl8169_private *);
37485 void (*disable)(struct rtl8169_private *);
37486- } jumbo_ops;
37487+ } __no_const jumbo_ops;
37488
37489 struct csi_ops {
37490 void (*write)(struct rtl8169_private *, int, int);
37491 u32 (*read)(struct rtl8169_private *, int);
37492- } csi_ops;
37493+ } __no_const csi_ops;
37494
37495 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
37496 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
37497diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
37498index 0767043f..08c2553 100644
37499--- a/drivers/net/ethernet/sfc/ptp.c
37500+++ b/drivers/net/ethernet/sfc/ptp.c
37501@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
37502 (u32)((u64)ptp->start.dma_addr >> 32));
37503
37504 /* Clear flag that signals MC ready */
37505- ACCESS_ONCE(*start) = 0;
37506+ ACCESS_ONCE_RW(*start) = 0;
37507 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
37508 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
37509
37510diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
37511index 0c74a70..3bc6f68 100644
37512--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
37513+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
37514@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
37515
37516 writel(value, ioaddr + MMC_CNTRL);
37517
37518- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
37519- MMC_CNTRL, value);
37520+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
37521+// MMC_CNTRL, value);
37522 }
37523
37524 /* To mask all all interrupts.*/
37525diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
37526index e6fe0d8..2b7d752 100644
37527--- a/drivers/net/hyperv/hyperv_net.h
37528+++ b/drivers/net/hyperv/hyperv_net.h
37529@@ -101,7 +101,7 @@ struct rndis_device {
37530
37531 enum rndis_device_state state;
37532 bool link_state;
37533- atomic_t new_req_id;
37534+ atomic_unchecked_t new_req_id;
37535
37536 spinlock_t request_lock;
37537 struct list_head req_list;
37538diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
37539index 2b657d4..9903bc0 100644
37540--- a/drivers/net/hyperv/rndis_filter.c
37541+++ b/drivers/net/hyperv/rndis_filter.c
37542@@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
37543 * template
37544 */
37545 set = &rndis_msg->msg.set_req;
37546- set->req_id = atomic_inc_return(&dev->new_req_id);
37547+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
37548
37549 /* Add to the request list */
37550 spin_lock_irqsave(&dev->request_lock, flags);
37551@@ -758,7 +758,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
37552
37553 /* Setup the rndis set */
37554 halt = &request->request_msg.msg.halt_req;
37555- halt->req_id = atomic_inc_return(&dev->new_req_id);
37556+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
37557
37558 /* Ignore return since this msg is optional. */
37559 rndis_filter_send_request(dev, request);
37560diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
37561index 1e9cb0b..7839125 100644
37562--- a/drivers/net/ieee802154/fakehard.c
37563+++ b/drivers/net/ieee802154/fakehard.c
37564@@ -386,7 +386,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
37565 phy->transmit_power = 0xbf;
37566
37567 dev->netdev_ops = &fake_ops;
37568- dev->ml_priv = &fake_mlme;
37569+ dev->ml_priv = (void *)&fake_mlme;
37570
37571 priv = netdev_priv(dev);
37572 priv->phy = phy;
37573diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
37574index d3fb97d..e229d3e 100644
37575--- a/drivers/net/macvlan.c
37576+++ b/drivers/net/macvlan.c
37577@@ -913,7 +913,7 @@ static int macvlan_device_event(struct notifier_block *unused,
37578 return NOTIFY_DONE;
37579 }
37580
37581-static struct notifier_block macvlan_notifier_block __read_mostly = {
37582+static struct notifier_block macvlan_notifier_block = {
37583 .notifier_call = macvlan_device_event,
37584 };
37585
37586diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
37587index 0f0f9ce..0ca5819 100644
37588--- a/drivers/net/macvtap.c
37589+++ b/drivers/net/macvtap.c
37590@@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
37591 return NOTIFY_DONE;
37592 }
37593
37594-static struct notifier_block macvtap_notifier_block __read_mostly = {
37595+static struct notifier_block macvtap_notifier_block = {
37596 .notifier_call = macvtap_device_event,
37597 };
37598
37599diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
37600index daec9b0..6428fcb 100644
37601--- a/drivers/net/phy/mdio-bitbang.c
37602+++ b/drivers/net/phy/mdio-bitbang.c
37603@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
37604 struct mdiobb_ctrl *ctrl = bus->priv;
37605
37606 module_put(ctrl->ops->owner);
37607+ mdiobus_unregister(bus);
37608 mdiobus_free(bus);
37609 }
37610 EXPORT_SYMBOL(free_mdio_bitbang);
37611diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
37612index 0b2706a..ba1430d 100644
37613--- a/drivers/net/ppp/ppp_generic.c
37614+++ b/drivers/net/ppp/ppp_generic.c
37615@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37616 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
37617 struct ppp_stats stats;
37618 struct ppp_comp_stats cstats;
37619- char *vers;
37620
37621 switch (cmd) {
37622 case SIOCGPPPSTATS:
37623@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37624 break;
37625
37626 case SIOCGPPPVER:
37627- vers = PPP_VERSION;
37628- if (copy_to_user(addr, vers, strlen(vers) + 1))
37629+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
37630 break;
37631 err = 0;
37632 break;
37633diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
37634index ad86660..9fd0884 100644
37635--- a/drivers/net/team/team.c
37636+++ b/drivers/net/team/team.c
37637@@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
37638 return NOTIFY_DONE;
37639 }
37640
37641-static struct notifier_block team_notifier_block __read_mostly = {
37642+static struct notifier_block team_notifier_block = {
37643 .notifier_call = team_device_event,
37644 };
37645
37646diff --git a/drivers/net/tun.c b/drivers/net/tun.c
37647index 2917a86..edd463f 100644
37648--- a/drivers/net/tun.c
37649+++ b/drivers/net/tun.c
37650@@ -1836,7 +1836,7 @@ unlock:
37651 }
37652
37653 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
37654- unsigned long arg, int ifreq_len)
37655+ unsigned long arg, size_t ifreq_len)
37656 {
37657 struct tun_file *tfile = file->private_data;
37658 struct tun_struct *tun;
37659@@ -1848,6 +1848,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
37660 int vnet_hdr_sz;
37661 int ret;
37662
37663+ if (ifreq_len > sizeof ifr)
37664+ return -EFAULT;
37665+
37666 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
37667 if (copy_from_user(&ifr, argp, ifreq_len))
37668 return -EFAULT;
37669diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
37670index cd8ccb2..cff5144 100644
37671--- a/drivers/net/usb/hso.c
37672+++ b/drivers/net/usb/hso.c
37673@@ -71,7 +71,7 @@
37674 #include <asm/byteorder.h>
37675 #include <linux/serial_core.h>
37676 #include <linux/serial.h>
37677-
37678+#include <asm/local.h>
37679
37680 #define MOD_AUTHOR "Option Wireless"
37681 #define MOD_DESCRIPTION "USB High Speed Option driver"
37682@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
37683 struct urb *urb;
37684
37685 urb = serial->rx_urb[0];
37686- if (serial->port.count > 0) {
37687+ if (atomic_read(&serial->port.count) > 0) {
37688 count = put_rxbuf_data(urb, serial);
37689 if (count == -1)
37690 return;
37691@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
37692 DUMP1(urb->transfer_buffer, urb->actual_length);
37693
37694 /* Anyone listening? */
37695- if (serial->port.count == 0)
37696+ if (atomic_read(&serial->port.count) == 0)
37697 return;
37698
37699 if (status == 0) {
37700@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37701 tty_port_tty_set(&serial->port, tty);
37702
37703 /* check for port already opened, if not set the termios */
37704- serial->port.count++;
37705- if (serial->port.count == 1) {
37706+ if (atomic_inc_return(&serial->port.count) == 1) {
37707 serial->rx_state = RX_IDLE;
37708 /* Force default termio settings */
37709 _hso_serial_set_termios(tty, NULL);
37710@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37711 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
37712 if (result) {
37713 hso_stop_serial_device(serial->parent);
37714- serial->port.count--;
37715+ atomic_dec(&serial->port.count);
37716 kref_put(&serial->parent->ref, hso_serial_ref_free);
37717 }
37718 } else {
37719@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
37720
37721 /* reset the rts and dtr */
37722 /* do the actual close */
37723- serial->port.count--;
37724+ atomic_dec(&serial->port.count);
37725
37726- if (serial->port.count <= 0) {
37727- serial->port.count = 0;
37728+ if (atomic_read(&serial->port.count) <= 0) {
37729+ atomic_set(&serial->port.count, 0);
37730 tty_port_tty_set(&serial->port, NULL);
37731 if (!usb_gone)
37732 hso_stop_serial_device(serial->parent);
37733@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
37734
37735 /* the actual setup */
37736 spin_lock_irqsave(&serial->serial_lock, flags);
37737- if (serial->port.count)
37738+ if (atomic_read(&serial->port.count))
37739 _hso_serial_set_termios(tty, old);
37740 else
37741 tty->termios = *old;
37742@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
37743 D1("Pending read interrupt on port %d\n", i);
37744 spin_lock(&serial->serial_lock);
37745 if (serial->rx_state == RX_IDLE &&
37746- serial->port.count > 0) {
37747+ atomic_read(&serial->port.count) > 0) {
37748 /* Setup and send a ctrl req read on
37749 * port i */
37750 if (!serial->rx_urb_filled[0]) {
37751@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
37752 /* Start all serial ports */
37753 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
37754 if (serial_table[i] && (serial_table[i]->interface == iface)) {
37755- if (dev2ser(serial_table[i])->port.count) {
37756+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
37757 result =
37758 hso_start_serial_device(serial_table[i], GFP_NOIO);
37759 hso_kick_transmit(dev2ser(serial_table[i]));
37760diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37761index 8d78253..bebbb68 100644
37762--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37763+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37764@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37765 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
37766 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
37767
37768- ACCESS_ONCE(ads->ds_link) = i->link;
37769- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
37770+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
37771+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
37772
37773 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
37774 ctl6 = SM(i->keytype, AR_EncrType);
37775@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37776
37777 if ((i->is_first || i->is_last) &&
37778 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
37779- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
37780+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
37781 | set11nTries(i->rates, 1)
37782 | set11nTries(i->rates, 2)
37783 | set11nTries(i->rates, 3)
37784 | (i->dur_update ? AR_DurUpdateEna : 0)
37785 | SM(0, AR_BurstDur);
37786
37787- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
37788+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
37789 | set11nRate(i->rates, 1)
37790 | set11nRate(i->rates, 2)
37791 | set11nRate(i->rates, 3);
37792 } else {
37793- ACCESS_ONCE(ads->ds_ctl2) = 0;
37794- ACCESS_ONCE(ads->ds_ctl3) = 0;
37795+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
37796+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
37797 }
37798
37799 if (!i->is_first) {
37800- ACCESS_ONCE(ads->ds_ctl0) = 0;
37801- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37802- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37803+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
37804+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37805+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37806 return;
37807 }
37808
37809@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37810 break;
37811 }
37812
37813- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37814+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37815 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37816 | SM(i->txpower, AR_XmitPower)
37817 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37818@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37819 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
37820 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
37821
37822- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37823- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37824+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37825+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37826
37827 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
37828 return;
37829
37830- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37831+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37832 | set11nPktDurRTSCTS(i->rates, 1);
37833
37834- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37835+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37836 | set11nPktDurRTSCTS(i->rates, 3);
37837
37838- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37839+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37840 | set11nRateFlags(i->rates, 1)
37841 | set11nRateFlags(i->rates, 2)
37842 | set11nRateFlags(i->rates, 3)
37843diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37844index 301bf72..3f5654f 100644
37845--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37846+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37847@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37848 (i->qcu << AR_TxQcuNum_S) | desc_len;
37849
37850 checksum += val;
37851- ACCESS_ONCE(ads->info) = val;
37852+ ACCESS_ONCE_RW(ads->info) = val;
37853
37854 checksum += i->link;
37855- ACCESS_ONCE(ads->link) = i->link;
37856+ ACCESS_ONCE_RW(ads->link) = i->link;
37857
37858 checksum += i->buf_addr[0];
37859- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
37860+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
37861 checksum += i->buf_addr[1];
37862- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
37863+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
37864 checksum += i->buf_addr[2];
37865- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
37866+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
37867 checksum += i->buf_addr[3];
37868- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
37869+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
37870
37871 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
37872- ACCESS_ONCE(ads->ctl3) = val;
37873+ ACCESS_ONCE_RW(ads->ctl3) = val;
37874 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
37875- ACCESS_ONCE(ads->ctl5) = val;
37876+ ACCESS_ONCE_RW(ads->ctl5) = val;
37877 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
37878- ACCESS_ONCE(ads->ctl7) = val;
37879+ ACCESS_ONCE_RW(ads->ctl7) = val;
37880 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
37881- ACCESS_ONCE(ads->ctl9) = val;
37882+ ACCESS_ONCE_RW(ads->ctl9) = val;
37883
37884 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
37885- ACCESS_ONCE(ads->ctl10) = checksum;
37886+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
37887
37888 if (i->is_first || i->is_last) {
37889- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
37890+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
37891 | set11nTries(i->rates, 1)
37892 | set11nTries(i->rates, 2)
37893 | set11nTries(i->rates, 3)
37894 | (i->dur_update ? AR_DurUpdateEna : 0)
37895 | SM(0, AR_BurstDur);
37896
37897- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
37898+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
37899 | set11nRate(i->rates, 1)
37900 | set11nRate(i->rates, 2)
37901 | set11nRate(i->rates, 3);
37902 } else {
37903- ACCESS_ONCE(ads->ctl13) = 0;
37904- ACCESS_ONCE(ads->ctl14) = 0;
37905+ ACCESS_ONCE_RW(ads->ctl13) = 0;
37906+ ACCESS_ONCE_RW(ads->ctl14) = 0;
37907 }
37908
37909 ads->ctl20 = 0;
37910@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37911
37912 ctl17 = SM(i->keytype, AR_EncrType);
37913 if (!i->is_first) {
37914- ACCESS_ONCE(ads->ctl11) = 0;
37915- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37916- ACCESS_ONCE(ads->ctl15) = 0;
37917- ACCESS_ONCE(ads->ctl16) = 0;
37918- ACCESS_ONCE(ads->ctl17) = ctl17;
37919- ACCESS_ONCE(ads->ctl18) = 0;
37920- ACCESS_ONCE(ads->ctl19) = 0;
37921+ ACCESS_ONCE_RW(ads->ctl11) = 0;
37922+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37923+ ACCESS_ONCE_RW(ads->ctl15) = 0;
37924+ ACCESS_ONCE_RW(ads->ctl16) = 0;
37925+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37926+ ACCESS_ONCE_RW(ads->ctl18) = 0;
37927+ ACCESS_ONCE_RW(ads->ctl19) = 0;
37928 return;
37929 }
37930
37931- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37932+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37933 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37934 | SM(i->txpower, AR_XmitPower)
37935 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37936@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37937 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
37938 ctl12 |= SM(val, AR_PAPRDChainMask);
37939
37940- ACCESS_ONCE(ads->ctl12) = ctl12;
37941- ACCESS_ONCE(ads->ctl17) = ctl17;
37942+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
37943+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37944
37945- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37946+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37947 | set11nPktDurRTSCTS(i->rates, 1);
37948
37949- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37950+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37951 | set11nPktDurRTSCTS(i->rates, 3);
37952
37953- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
37954+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
37955 | set11nRateFlags(i->rates, 1)
37956 | set11nRateFlags(i->rates, 2)
37957 | set11nRateFlags(i->rates, 3)
37958 | SM(i->rtscts_rate, AR_RTSCTSRate);
37959
37960- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
37961+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
37962 }
37963
37964 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
37965diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
37966index 9d26fc5..60d9f14 100644
37967--- a/drivers/net/wireless/ath/ath9k/hw.h
37968+++ b/drivers/net/wireless/ath/ath9k/hw.h
37969@@ -658,7 +658,7 @@ struct ath_hw_private_ops {
37970
37971 /* ANI */
37972 void (*ani_cache_ini_regs)(struct ath_hw *ah);
37973-};
37974+} __no_const;
37975
37976 /**
37977 * struct ath_hw_ops - callbacks used by hardware code and driver code
37978@@ -688,7 +688,7 @@ struct ath_hw_ops {
37979 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
37980 struct ath_hw_antcomb_conf *antconf);
37981 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
37982-};
37983+} __no_const;
37984
37985 struct ath_nf_limits {
37986 s16 max;
37987diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
37988index 3726cd6..b655808 100644
37989--- a/drivers/net/wireless/iwlegacy/3945-mac.c
37990+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
37991@@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
37992 */
37993 if (il3945_mod_params.disable_hw_scan) {
37994 D_INFO("Disabling hw_scan\n");
37995- il3945_mac_ops.hw_scan = NULL;
37996+ pax_open_kernel();
37997+ *(void **)&il3945_mac_ops.hw_scan = NULL;
37998+ pax_close_kernel();
37999 }
38000
38001 D_INFO("*** LOAD DRIVER ***\n");
38002diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
38003index 5b9533e..7733880 100644
38004--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
38005+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
38006@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
38007 {
38008 struct iwl_priv *priv = file->private_data;
38009 char buf[64];
38010- int buf_size;
38011+ size_t buf_size;
38012 u32 offset, len;
38013
38014 memset(buf, 0, sizeof(buf));
38015@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
38016 struct iwl_priv *priv = file->private_data;
38017
38018 char buf[8];
38019- int buf_size;
38020+ size_t buf_size;
38021 u32 reset_flag;
38022
38023 memset(buf, 0, sizeof(buf));
38024@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
38025 {
38026 struct iwl_priv *priv = file->private_data;
38027 char buf[8];
38028- int buf_size;
38029+ size_t buf_size;
38030 int ht40;
38031
38032 memset(buf, 0, sizeof(buf));
38033@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
38034 {
38035 struct iwl_priv *priv = file->private_data;
38036 char buf[8];
38037- int buf_size;
38038+ size_t buf_size;
38039 int value;
38040
38041 memset(buf, 0, sizeof(buf));
38042@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
38043 {
38044 struct iwl_priv *priv = file->private_data;
38045 char buf[8];
38046- int buf_size;
38047+ size_t buf_size;
38048 int clear;
38049
38050 memset(buf, 0, sizeof(buf));
38051@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
38052 {
38053 struct iwl_priv *priv = file->private_data;
38054 char buf[8];
38055- int buf_size;
38056+ size_t buf_size;
38057 int trace;
38058
38059 memset(buf, 0, sizeof(buf));
38060@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
38061 {
38062 struct iwl_priv *priv = file->private_data;
38063 char buf[8];
38064- int buf_size;
38065+ size_t buf_size;
38066 int missed;
38067
38068 memset(buf, 0, sizeof(buf));
38069@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
38070
38071 struct iwl_priv *priv = file->private_data;
38072 char buf[8];
38073- int buf_size;
38074+ size_t buf_size;
38075 int plcp;
38076
38077 memset(buf, 0, sizeof(buf));
38078@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
38079
38080 struct iwl_priv *priv = file->private_data;
38081 char buf[8];
38082- int buf_size;
38083+ size_t buf_size;
38084 int flush;
38085
38086 memset(buf, 0, sizeof(buf));
38087@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
38088
38089 struct iwl_priv *priv = file->private_data;
38090 char buf[8];
38091- int buf_size;
38092+ size_t buf_size;
38093 int rts;
38094
38095 if (!priv->cfg->ht_params)
38096@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
38097 {
38098 struct iwl_priv *priv = file->private_data;
38099 char buf[8];
38100- int buf_size;
38101+ size_t buf_size;
38102
38103 memset(buf, 0, sizeof(buf));
38104 buf_size = min(count, sizeof(buf) - 1);
38105@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
38106 struct iwl_priv *priv = file->private_data;
38107 u32 event_log_flag;
38108 char buf[8];
38109- int buf_size;
38110+ size_t buf_size;
38111
38112 /* check that the interface is up */
38113 if (!iwl_is_ready(priv))
38114@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
38115 struct iwl_priv *priv = file->private_data;
38116 char buf[8];
38117 u32 calib_disabled;
38118- int buf_size;
38119+ size_t buf_size;
38120
38121 memset(buf, 0, sizeof(buf));
38122 buf_size = min(count, sizeof(buf) - 1);
38123diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
38124index 35708b9..31f7754 100644
38125--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
38126+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
38127@@ -1100,7 +1100,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
38128 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
38129
38130 char buf[8];
38131- int buf_size;
38132+ size_t buf_size;
38133 u32 reset_flag;
38134
38135 memset(buf, 0, sizeof(buf));
38136@@ -1121,7 +1121,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
38137 {
38138 struct iwl_trans *trans = file->private_data;
38139 char buf[8];
38140- int buf_size;
38141+ size_t buf_size;
38142 int csr;
38143
38144 memset(buf, 0, sizeof(buf));
38145diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
38146index ff90855..e46d223 100644
38147--- a/drivers/net/wireless/mac80211_hwsim.c
38148+++ b/drivers/net/wireless/mac80211_hwsim.c
38149@@ -2062,25 +2062,19 @@ static int __init init_mac80211_hwsim(void)
38150
38151 if (channels > 1) {
38152 hwsim_if_comb.num_different_channels = channels;
38153- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
38154- mac80211_hwsim_ops.cancel_hw_scan =
38155- mac80211_hwsim_cancel_hw_scan;
38156- mac80211_hwsim_ops.sw_scan_start = NULL;
38157- mac80211_hwsim_ops.sw_scan_complete = NULL;
38158- mac80211_hwsim_ops.remain_on_channel =
38159- mac80211_hwsim_roc;
38160- mac80211_hwsim_ops.cancel_remain_on_channel =
38161- mac80211_hwsim_croc;
38162- mac80211_hwsim_ops.add_chanctx =
38163- mac80211_hwsim_add_chanctx;
38164- mac80211_hwsim_ops.remove_chanctx =
38165- mac80211_hwsim_remove_chanctx;
38166- mac80211_hwsim_ops.change_chanctx =
38167- mac80211_hwsim_change_chanctx;
38168- mac80211_hwsim_ops.assign_vif_chanctx =
38169- mac80211_hwsim_assign_vif_chanctx;
38170- mac80211_hwsim_ops.unassign_vif_chanctx =
38171- mac80211_hwsim_unassign_vif_chanctx;
38172+ pax_open_kernel();
38173+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
38174+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
38175+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
38176+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
38177+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
38178+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
38179+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
38180+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
38181+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
38182+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
38183+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
38184+ pax_close_kernel();
38185 }
38186
38187 spin_lock_init(&hwsim_radio_lock);
38188diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
38189index abe1d03..fb02c22 100644
38190--- a/drivers/net/wireless/rndis_wlan.c
38191+++ b/drivers/net/wireless/rndis_wlan.c
38192@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
38193
38194 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
38195
38196- if (rts_threshold < 0 || rts_threshold > 2347)
38197+ if (rts_threshold > 2347)
38198 rts_threshold = 2347;
38199
38200 tmp = cpu_to_le32(rts_threshold);
38201diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
38202index 0751b35..246ba3e 100644
38203--- a/drivers/net/wireless/rt2x00/rt2x00.h
38204+++ b/drivers/net/wireless/rt2x00/rt2x00.h
38205@@ -398,7 +398,7 @@ struct rt2x00_intf {
38206 * for hardware which doesn't support hardware
38207 * sequence counting.
38208 */
38209- atomic_t seqno;
38210+ atomic_unchecked_t seqno;
38211 };
38212
38213 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
38214diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
38215index e488b94..14b6a0c 100644
38216--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
38217+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
38218@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
38219 * sequence counter given by mac80211.
38220 */
38221 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
38222- seqno = atomic_add_return(0x10, &intf->seqno);
38223+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
38224 else
38225- seqno = atomic_read(&intf->seqno);
38226+ seqno = atomic_read_unchecked(&intf->seqno);
38227
38228 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
38229 hdr->seq_ctrl |= cpu_to_le16(seqno);
38230diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
38231index e57ee48..541cf6c 100644
38232--- a/drivers/net/wireless/ti/wl1251/sdio.c
38233+++ b/drivers/net/wireless/ti/wl1251/sdio.c
38234@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
38235
38236 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
38237
38238- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
38239- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
38240+ pax_open_kernel();
38241+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
38242+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
38243+ pax_close_kernel();
38244
38245 wl1251_info("using dedicated interrupt line");
38246 } else {
38247- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
38248- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
38249+ pax_open_kernel();
38250+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
38251+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
38252+ pax_close_kernel();
38253
38254 wl1251_info("using SDIO interrupt");
38255 }
38256diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
38257index e5f5f8f..fdf15b7 100644
38258--- a/drivers/net/wireless/ti/wl12xx/main.c
38259+++ b/drivers/net/wireless/ti/wl12xx/main.c
38260@@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
38261 sizeof(wl->conf.mem));
38262
38263 /* read data preparation is only needed by wl127x */
38264- wl->ops->prepare_read = wl127x_prepare_read;
38265+ pax_open_kernel();
38266+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
38267+ pax_close_kernel();
38268
38269 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
38270 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
38271@@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
38272 sizeof(wl->conf.mem));
38273
38274 /* read data preparation is only needed by wl127x */
38275- wl->ops->prepare_read = wl127x_prepare_read;
38276+ pax_open_kernel();
38277+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
38278+ pax_close_kernel();
38279
38280 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
38281 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
38282diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
38283index 8d8c1f8..e754844 100644
38284--- a/drivers/net/wireless/ti/wl18xx/main.c
38285+++ b/drivers/net/wireless/ti/wl18xx/main.c
38286@@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
38287 }
38288
38289 if (!checksum_param) {
38290- wl18xx_ops.set_rx_csum = NULL;
38291- wl18xx_ops.init_vif = NULL;
38292+ pax_open_kernel();
38293+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
38294+ *(void **)&wl18xx_ops.init_vif = NULL;
38295+ pax_close_kernel();
38296 }
38297
38298 /* Enable 11a Band only if we have 5G antennas */
38299diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
38300index d93b2b6..ae50401 100644
38301--- a/drivers/oprofile/buffer_sync.c
38302+++ b/drivers/oprofile/buffer_sync.c
38303@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
38304 if (cookie == NO_COOKIE)
38305 offset = pc;
38306 if (cookie == INVALID_COOKIE) {
38307- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
38308+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
38309 offset = pc;
38310 }
38311 if (cookie != last_cookie) {
38312@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
38313 /* add userspace sample */
38314
38315 if (!mm) {
38316- atomic_inc(&oprofile_stats.sample_lost_no_mm);
38317+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
38318 return 0;
38319 }
38320
38321 cookie = lookup_dcookie(mm, s->eip, &offset);
38322
38323 if (cookie == INVALID_COOKIE) {
38324- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
38325+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
38326 return 0;
38327 }
38328
38329@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
38330 /* ignore backtraces if failed to add a sample */
38331 if (state == sb_bt_start) {
38332 state = sb_bt_ignore;
38333- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
38334+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
38335 }
38336 }
38337 release_mm(mm);
38338diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
38339index c0cc4e7..44d4e54 100644
38340--- a/drivers/oprofile/event_buffer.c
38341+++ b/drivers/oprofile/event_buffer.c
38342@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
38343 }
38344
38345 if (buffer_pos == buffer_size) {
38346- atomic_inc(&oprofile_stats.event_lost_overflow);
38347+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
38348 return;
38349 }
38350
38351diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
38352index ed2c3ec..deda85a 100644
38353--- a/drivers/oprofile/oprof.c
38354+++ b/drivers/oprofile/oprof.c
38355@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
38356 if (oprofile_ops.switch_events())
38357 return;
38358
38359- atomic_inc(&oprofile_stats.multiplex_counter);
38360+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
38361 start_switch_worker();
38362 }
38363
38364diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
38365index 917d28e..d62d981 100644
38366--- a/drivers/oprofile/oprofile_stats.c
38367+++ b/drivers/oprofile/oprofile_stats.c
38368@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
38369 cpu_buf->sample_invalid_eip = 0;
38370 }
38371
38372- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
38373- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
38374- atomic_set(&oprofile_stats.event_lost_overflow, 0);
38375- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
38376- atomic_set(&oprofile_stats.multiplex_counter, 0);
38377+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
38378+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
38379+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
38380+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
38381+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
38382 }
38383
38384
38385diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
38386index 38b6fc0..b5cbfce 100644
38387--- a/drivers/oprofile/oprofile_stats.h
38388+++ b/drivers/oprofile/oprofile_stats.h
38389@@ -13,11 +13,11 @@
38390 #include <linux/atomic.h>
38391
38392 struct oprofile_stat_struct {
38393- atomic_t sample_lost_no_mm;
38394- atomic_t sample_lost_no_mapping;
38395- atomic_t bt_lost_no_mapping;
38396- atomic_t event_lost_overflow;
38397- atomic_t multiplex_counter;
38398+ atomic_unchecked_t sample_lost_no_mm;
38399+ atomic_unchecked_t sample_lost_no_mapping;
38400+ atomic_unchecked_t bt_lost_no_mapping;
38401+ atomic_unchecked_t event_lost_overflow;
38402+ atomic_unchecked_t multiplex_counter;
38403 };
38404
38405 extern struct oprofile_stat_struct oprofile_stats;
38406diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
38407index 849357c..b83c1e0 100644
38408--- a/drivers/oprofile/oprofilefs.c
38409+++ b/drivers/oprofile/oprofilefs.c
38410@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
38411
38412
38413 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
38414- char const *name, atomic_t *val)
38415+ char const *name, atomic_unchecked_t *val)
38416 {
38417 return __oprofilefs_create_file(sb, root, name,
38418 &atomic_ro_fops, 0444, val);
38419diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
38420index 93404f7..4a313d8 100644
38421--- a/drivers/oprofile/timer_int.c
38422+++ b/drivers/oprofile/timer_int.c
38423@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
38424 return NOTIFY_OK;
38425 }
38426
38427-static struct notifier_block __refdata oprofile_cpu_notifier = {
38428+static struct notifier_block oprofile_cpu_notifier = {
38429 .notifier_call = oprofile_cpu_notify,
38430 };
38431
38432diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
38433index 3f56bc0..707d642 100644
38434--- a/drivers/parport/procfs.c
38435+++ b/drivers/parport/procfs.c
38436@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
38437
38438 *ppos += len;
38439
38440- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
38441+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
38442 }
38443
38444 #ifdef CONFIG_PARPORT_1284
38445@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
38446
38447 *ppos += len;
38448
38449- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
38450+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
38451 }
38452 #endif /* IEEE1284.3 support. */
38453
38454diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
38455index a6a71c4..c91097b 100644
38456--- a/drivers/pci/hotplug/cpcihp_generic.c
38457+++ b/drivers/pci/hotplug/cpcihp_generic.c
38458@@ -73,7 +73,6 @@ static u16 port;
38459 static unsigned int enum_bit;
38460 static u8 enum_mask;
38461
38462-static struct cpci_hp_controller_ops generic_hpc_ops;
38463 static struct cpci_hp_controller generic_hpc;
38464
38465 static int __init validate_parameters(void)
38466@@ -139,6 +138,10 @@ static int query_enum(void)
38467 return ((value & enum_mask) == enum_mask);
38468 }
38469
38470+static struct cpci_hp_controller_ops generic_hpc_ops = {
38471+ .query_enum = query_enum,
38472+};
38473+
38474 static int __init cpcihp_generic_init(void)
38475 {
38476 int status;
38477@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
38478 pci_dev_put(dev);
38479
38480 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
38481- generic_hpc_ops.query_enum = query_enum;
38482 generic_hpc.ops = &generic_hpc_ops;
38483
38484 status = cpci_hp_register_controller(&generic_hpc);
38485diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
38486index 449b4bb..257e2e8 100644
38487--- a/drivers/pci/hotplug/cpcihp_zt5550.c
38488+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
38489@@ -59,7 +59,6 @@
38490 /* local variables */
38491 static bool debug;
38492 static bool poll;
38493-static struct cpci_hp_controller_ops zt5550_hpc_ops;
38494 static struct cpci_hp_controller zt5550_hpc;
38495
38496 /* Primary cPCI bus bridge device */
38497@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
38498 return 0;
38499 }
38500
38501+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
38502+ .query_enum = zt5550_hc_query_enum,
38503+};
38504+
38505 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
38506 {
38507 int status;
38508@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
38509 dbg("returned from zt5550_hc_config");
38510
38511 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
38512- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
38513 zt5550_hpc.ops = &zt5550_hpc_ops;
38514 if(!poll) {
38515 zt5550_hpc.irq = hc_dev->irq;
38516 zt5550_hpc.irq_flags = IRQF_SHARED;
38517 zt5550_hpc.dev_id = hc_dev;
38518
38519- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
38520- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
38521- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
38522+ pax_open_kernel();
38523+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
38524+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
38525+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
38526+ pax_open_kernel();
38527 } else {
38528 info("using ENUM# polling mode");
38529 }
38530diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
38531index 76ba8a1..20ca857 100644
38532--- a/drivers/pci/hotplug/cpqphp_nvram.c
38533+++ b/drivers/pci/hotplug/cpqphp_nvram.c
38534@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
38535
38536 void compaq_nvram_init (void __iomem *rom_start)
38537 {
38538+
38539+#ifndef CONFIG_PAX_KERNEXEC
38540 if (rom_start) {
38541 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
38542 }
38543+#endif
38544+
38545 dbg("int15 entry = %p\n", compaq_int15_entry_point);
38546
38547 /* initialize our int15 lock */
38548diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
38549index 8474b6a..ee81993 100644
38550--- a/drivers/pci/pcie/aspm.c
38551+++ b/drivers/pci/pcie/aspm.c
38552@@ -27,9 +27,9 @@
38553 #define MODULE_PARAM_PREFIX "pcie_aspm."
38554
38555 /* Note: those are not register definitions */
38556-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
38557-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
38558-#define ASPM_STATE_L1 (4) /* L1 state */
38559+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
38560+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
38561+#define ASPM_STATE_L1 (4U) /* L1 state */
38562 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
38563 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
38564
38565diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
38566index 6186f03..1a78714 100644
38567--- a/drivers/pci/probe.c
38568+++ b/drivers/pci/probe.c
38569@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
38570 struct pci_bus_region region;
38571 bool bar_too_big = false, bar_disabled = false;
38572
38573- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
38574+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
38575
38576 /* No printks while decoding is disabled! */
38577 if (!dev->mmio_always_on) {
38578diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
38579index 9b8505c..f00870a 100644
38580--- a/drivers/pci/proc.c
38581+++ b/drivers/pci/proc.c
38582@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
38583 static int __init pci_proc_init(void)
38584 {
38585 struct pci_dev *dev = NULL;
38586+
38587+#ifdef CONFIG_GRKERNSEC_PROC_ADD
38588+#ifdef CONFIG_GRKERNSEC_PROC_USER
38589+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
38590+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
38591+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
38592+#endif
38593+#else
38594 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
38595+#endif
38596 proc_create("devices", 0, proc_bus_pci_dir,
38597 &proc_bus_pci_dev_operations);
38598 proc_initialized = 1;
38599diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
38600index f946ca7..f25c833 100644
38601--- a/drivers/platform/x86/thinkpad_acpi.c
38602+++ b/drivers/platform/x86/thinkpad_acpi.c
38603@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
38604 return 0;
38605 }
38606
38607-void static hotkey_mask_warn_incomplete_mask(void)
38608+static void hotkey_mask_warn_incomplete_mask(void)
38609 {
38610 /* log only what the user can fix... */
38611 const u32 wantedmask = hotkey_driver_mask &
38612@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
38613 }
38614 }
38615
38616-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38617- struct tp_nvram_state *newn,
38618- const u32 event_mask)
38619-{
38620-
38621 #define TPACPI_COMPARE_KEY(__scancode, __member) \
38622 do { \
38623 if ((event_mask & (1 << __scancode)) && \
38624@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38625 tpacpi_hotkey_send_key(__scancode); \
38626 } while (0)
38627
38628- void issue_volchange(const unsigned int oldvol,
38629- const unsigned int newvol)
38630- {
38631- unsigned int i = oldvol;
38632+static void issue_volchange(const unsigned int oldvol,
38633+ const unsigned int newvol,
38634+ const u32 event_mask)
38635+{
38636+ unsigned int i = oldvol;
38637
38638- while (i > newvol) {
38639- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
38640- i--;
38641- }
38642- while (i < newvol) {
38643- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38644- i++;
38645- }
38646+ while (i > newvol) {
38647+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
38648+ i--;
38649 }
38650+ while (i < newvol) {
38651+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38652+ i++;
38653+ }
38654+}
38655
38656- void issue_brightnesschange(const unsigned int oldbrt,
38657- const unsigned int newbrt)
38658- {
38659- unsigned int i = oldbrt;
38660+static void issue_brightnesschange(const unsigned int oldbrt,
38661+ const unsigned int newbrt,
38662+ const u32 event_mask)
38663+{
38664+ unsigned int i = oldbrt;
38665
38666- while (i > newbrt) {
38667- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
38668- i--;
38669- }
38670- while (i < newbrt) {
38671- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38672- i++;
38673- }
38674+ while (i > newbrt) {
38675+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
38676+ i--;
38677+ }
38678+ while (i < newbrt) {
38679+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38680+ i++;
38681 }
38682+}
38683
38684+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38685+ struct tp_nvram_state *newn,
38686+ const u32 event_mask)
38687+{
38688 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
38689 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
38690 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
38691@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38692 oldn->volume_level != newn->volume_level) {
38693 /* recently muted, or repeated mute keypress, or
38694 * multiple presses ending in mute */
38695- issue_volchange(oldn->volume_level, newn->volume_level);
38696+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
38697 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
38698 }
38699 } else {
38700@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38701 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38702 }
38703 if (oldn->volume_level != newn->volume_level) {
38704- issue_volchange(oldn->volume_level, newn->volume_level);
38705+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
38706 } else if (oldn->volume_toggle != newn->volume_toggle) {
38707 /* repeated vol up/down keypress at end of scale ? */
38708 if (newn->volume_level == 0)
38709@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38710 /* handle brightness */
38711 if (oldn->brightness_level != newn->brightness_level) {
38712 issue_brightnesschange(oldn->brightness_level,
38713- newn->brightness_level);
38714+ newn->brightness_level,
38715+ event_mask);
38716 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
38717 /* repeated key presses that didn't change state */
38718 if (newn->brightness_level == 0)
38719@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38720 && !tp_features.bright_unkfw)
38721 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38722 }
38723+}
38724
38725 #undef TPACPI_COMPARE_KEY
38726 #undef TPACPI_MAY_SEND_KEY
38727-}
38728
38729 /*
38730 * Polling driver
38731diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
38732index 769d265..a3a05ca 100644
38733--- a/drivers/pnp/pnpbios/bioscalls.c
38734+++ b/drivers/pnp/pnpbios/bioscalls.c
38735@@ -58,7 +58,7 @@ do { \
38736 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
38737 } while(0)
38738
38739-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
38740+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
38741 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
38742
38743 /*
38744@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38745
38746 cpu = get_cpu();
38747 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
38748+
38749+ pax_open_kernel();
38750 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
38751+ pax_close_kernel();
38752
38753 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
38754 spin_lock_irqsave(&pnp_bios_lock, flags);
38755@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38756 :"memory");
38757 spin_unlock_irqrestore(&pnp_bios_lock, flags);
38758
38759+ pax_open_kernel();
38760 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
38761+ pax_close_kernel();
38762+
38763 put_cpu();
38764
38765 /* If we get here and this is set then the PnP BIOS faulted on us. */
38766@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
38767 return status;
38768 }
38769
38770-void pnpbios_calls_init(union pnp_bios_install_struct *header)
38771+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
38772 {
38773 int i;
38774
38775@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38776 pnp_bios_callpoint.offset = header->fields.pm16offset;
38777 pnp_bios_callpoint.segment = PNP_CS16;
38778
38779+ pax_open_kernel();
38780+
38781 for_each_possible_cpu(i) {
38782 struct desc_struct *gdt = get_cpu_gdt_table(i);
38783 if (!gdt)
38784@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38785 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
38786 (unsigned long)__va(header->fields.pm16dseg));
38787 }
38788+
38789+ pax_close_kernel();
38790 }
38791diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
38792index 3e6db1c..1fbbdae 100644
38793--- a/drivers/pnp/resource.c
38794+++ b/drivers/pnp/resource.c
38795@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
38796 return 1;
38797
38798 /* check if the resource is valid */
38799- if (*irq < 0 || *irq > 15)
38800+ if (*irq > 15)
38801 return 0;
38802
38803 /* check if the resource is reserved */
38804@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
38805 return 1;
38806
38807 /* check if the resource is valid */
38808- if (*dma < 0 || *dma == 4 || *dma > 7)
38809+ if (*dma == 4 || *dma > 7)
38810 return 0;
38811
38812 /* check if the resource is reserved */
38813diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
38814index 7df7c5f..bd48c47 100644
38815--- a/drivers/power/pda_power.c
38816+++ b/drivers/power/pda_power.c
38817@@ -37,7 +37,11 @@ static int polling;
38818
38819 #ifdef CONFIG_USB_OTG_UTILS
38820 static struct usb_phy *transceiver;
38821-static struct notifier_block otg_nb;
38822+static int otg_handle_notification(struct notifier_block *nb,
38823+ unsigned long event, void *unused);
38824+static struct notifier_block otg_nb = {
38825+ .notifier_call = otg_handle_notification
38826+};
38827 #endif
38828
38829 static struct regulator *ac_draw;
38830@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
38831
38832 #ifdef CONFIG_USB_OTG_UTILS
38833 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
38834- otg_nb.notifier_call = otg_handle_notification;
38835 ret = usb_register_notifier(transceiver, &otg_nb);
38836 if (ret) {
38837 dev_err(dev, "failure to register otg notifier\n");
38838diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
38839index 4d7c635..9860196 100644
38840--- a/drivers/regulator/max8660.c
38841+++ b/drivers/regulator/max8660.c
38842@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
38843 max8660->shadow_regs[MAX8660_OVER1] = 5;
38844 } else {
38845 /* Otherwise devices can be toggled via software */
38846- max8660_dcdc_ops.enable = max8660_dcdc_enable;
38847- max8660_dcdc_ops.disable = max8660_dcdc_disable;
38848+ pax_open_kernel();
38849+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
38850+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
38851+ pax_close_kernel();
38852 }
38853
38854 /*
38855diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
38856index 9a8ea91..c483dd9 100644
38857--- a/drivers/regulator/max8973-regulator.c
38858+++ b/drivers/regulator/max8973-regulator.c
38859@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
38860 if (!pdata->enable_ext_control) {
38861 max->desc.enable_reg = MAX8973_VOUT;
38862 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
38863- max8973_dcdc_ops.enable = regulator_enable_regmap;
38864- max8973_dcdc_ops.disable = regulator_disable_regmap;
38865- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
38866+ pax_open_kernel();
38867+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
38868+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
38869+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
38870+ pax_close_kernel();
38871 }
38872
38873 max->enable_external_control = pdata->enable_ext_control;
38874diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
38875index 0d84b1f..c2da6ac 100644
38876--- a/drivers/regulator/mc13892-regulator.c
38877+++ b/drivers/regulator/mc13892-regulator.c
38878@@ -540,10 +540,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
38879 }
38880 mc13xxx_unlock(mc13892);
38881
38882- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38883+ pax_open_kernel();
38884+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38885 = mc13892_vcam_set_mode;
38886- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38887+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38888 = mc13892_vcam_get_mode;
38889+ pax_close_kernel();
38890
38891 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
38892 ARRAY_SIZE(mc13892_regulators));
38893diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
38894index 9a86b4b..3a383dc 100644
38895--- a/drivers/rtc/rtc-dev.c
38896+++ b/drivers/rtc/rtc-dev.c
38897@@ -14,6 +14,7 @@
38898 #include <linux/module.h>
38899 #include <linux/rtc.h>
38900 #include <linux/sched.h>
38901+#include <linux/grsecurity.h>
38902 #include "rtc-core.h"
38903
38904 static dev_t rtc_devt;
38905@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
38906 if (copy_from_user(&tm, uarg, sizeof(tm)))
38907 return -EFAULT;
38908
38909+ gr_log_timechange();
38910+
38911 return rtc_set_time(rtc, &tm);
38912
38913 case RTC_PIE_ON:
38914diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
38915index 4ad7e36..d004679 100644
38916--- a/drivers/scsi/bfa/bfa.h
38917+++ b/drivers/scsi/bfa/bfa.h
38918@@ -196,7 +196,7 @@ struct bfa_hwif_s {
38919 u32 *end);
38920 int cpe_vec_q0;
38921 int rme_vec_q0;
38922-};
38923+} __no_const;
38924 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
38925
38926 struct bfa_faa_cbfn_s {
38927diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
38928index e693af6..2e525b6 100644
38929--- a/drivers/scsi/bfa/bfa_fcpim.h
38930+++ b/drivers/scsi/bfa/bfa_fcpim.h
38931@@ -36,7 +36,7 @@ struct bfa_iotag_s {
38932
38933 struct bfa_itn_s {
38934 bfa_isr_func_t isr;
38935-};
38936+} __no_const;
38937
38938 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
38939 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
38940diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
38941index 23a90e7..9cf04ee 100644
38942--- a/drivers/scsi/bfa/bfa_ioc.h
38943+++ b/drivers/scsi/bfa/bfa_ioc.h
38944@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
38945 bfa_ioc_disable_cbfn_t disable_cbfn;
38946 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
38947 bfa_ioc_reset_cbfn_t reset_cbfn;
38948-};
38949+} __no_const;
38950
38951 /*
38952 * IOC event notification mechanism.
38953@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
38954 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
38955 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
38956 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
38957-};
38958+} __no_const;
38959
38960 /*
38961 * Queue element to wait for room in request queue. FIFO order is
38962diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
38963index 593085a..47aa999 100644
38964--- a/drivers/scsi/hosts.c
38965+++ b/drivers/scsi/hosts.c
38966@@ -42,7 +42,7 @@
38967 #include "scsi_logging.h"
38968
38969
38970-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38971+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38972
38973
38974 static void scsi_host_cls_release(struct device *dev)
38975@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
38976 * subtract one because we increment first then return, but we need to
38977 * know what the next host number was before increment
38978 */
38979- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
38980+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
38981 shost->dma_channel = 0xff;
38982
38983 /* These three are default values which can be overridden */
38984diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
38985index 4f33806..afd6f60 100644
38986--- a/drivers/scsi/hpsa.c
38987+++ b/drivers/scsi/hpsa.c
38988@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
38989 unsigned long flags;
38990
38991 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
38992- return h->access.command_completed(h, q);
38993+ return h->access->command_completed(h, q);
38994
38995 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
38996 a = rq->head[rq->current_entry];
38997@@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
38998 while (!list_empty(&h->reqQ)) {
38999 c = list_entry(h->reqQ.next, struct CommandList, list);
39000 /* can't do anything if fifo is full */
39001- if ((h->access.fifo_full(h))) {
39002+ if ((h->access->fifo_full(h))) {
39003 dev_warn(&h->pdev->dev, "fifo full\n");
39004 break;
39005 }
39006@@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
39007
39008 /* Tell the controller execute command */
39009 spin_unlock_irqrestore(&h->lock, flags);
39010- h->access.submit_command(h, c);
39011+ h->access->submit_command(h, c);
39012 spin_lock_irqsave(&h->lock, flags);
39013 }
39014 spin_unlock_irqrestore(&h->lock, flags);
39015@@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
39016
39017 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
39018 {
39019- return h->access.command_completed(h, q);
39020+ return h->access->command_completed(h, q);
39021 }
39022
39023 static inline bool interrupt_pending(struct ctlr_info *h)
39024 {
39025- return h->access.intr_pending(h);
39026+ return h->access->intr_pending(h);
39027 }
39028
39029 static inline long interrupt_not_for_us(struct ctlr_info *h)
39030 {
39031- return (h->access.intr_pending(h) == 0) ||
39032+ return (h->access->intr_pending(h) == 0) ||
39033 (h->interrupts_enabled == 0);
39034 }
39035
39036@@ -4316,7 +4316,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
39037 if (prod_index < 0)
39038 return -ENODEV;
39039 h->product_name = products[prod_index].product_name;
39040- h->access = *(products[prod_index].access);
39041+ h->access = products[prod_index].access;
39042
39043 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
39044 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
39045@@ -4598,7 +4598,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
39046
39047 assert_spin_locked(&lockup_detector_lock);
39048 remove_ctlr_from_lockup_detector_list(h);
39049- h->access.set_intr_mask(h, HPSA_INTR_OFF);
39050+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
39051 spin_lock_irqsave(&h->lock, flags);
39052 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
39053 spin_unlock_irqrestore(&h->lock, flags);
39054@@ -4775,7 +4775,7 @@ reinit_after_soft_reset:
39055 }
39056
39057 /* make sure the board interrupts are off */
39058- h->access.set_intr_mask(h, HPSA_INTR_OFF);
39059+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
39060
39061 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
39062 goto clean2;
39063@@ -4809,7 +4809,7 @@ reinit_after_soft_reset:
39064 * fake ones to scoop up any residual completions.
39065 */
39066 spin_lock_irqsave(&h->lock, flags);
39067- h->access.set_intr_mask(h, HPSA_INTR_OFF);
39068+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
39069 spin_unlock_irqrestore(&h->lock, flags);
39070 free_irqs(h);
39071 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
39072@@ -4828,9 +4828,9 @@ reinit_after_soft_reset:
39073 dev_info(&h->pdev->dev, "Board READY.\n");
39074 dev_info(&h->pdev->dev,
39075 "Waiting for stale completions to drain.\n");
39076- h->access.set_intr_mask(h, HPSA_INTR_ON);
39077+ h->access->set_intr_mask(h, HPSA_INTR_ON);
39078 msleep(10000);
39079- h->access.set_intr_mask(h, HPSA_INTR_OFF);
39080+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
39081
39082 rc = controller_reset_failed(h->cfgtable);
39083 if (rc)
39084@@ -4851,7 +4851,7 @@ reinit_after_soft_reset:
39085 }
39086
39087 /* Turn the interrupts on so we can service requests */
39088- h->access.set_intr_mask(h, HPSA_INTR_ON);
39089+ h->access->set_intr_mask(h, HPSA_INTR_ON);
39090
39091 hpsa_hba_inquiry(h);
39092 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
39093@@ -4903,7 +4903,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
39094 * To write all data in the battery backed cache to disks
39095 */
39096 hpsa_flush_cache(h);
39097- h->access.set_intr_mask(h, HPSA_INTR_OFF);
39098+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
39099 hpsa_free_irqs_and_disable_msix(h);
39100 }
39101
39102@@ -5071,7 +5071,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
39103 return;
39104 }
39105 /* Change the access methods to the performant access methods */
39106- h->access = SA5_performant_access;
39107+ h->access = &SA5_performant_access;
39108 h->transMethod = CFGTBL_Trans_Performant;
39109 }
39110
39111diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
39112index 9816479..c5d4e97 100644
39113--- a/drivers/scsi/hpsa.h
39114+++ b/drivers/scsi/hpsa.h
39115@@ -79,7 +79,7 @@ struct ctlr_info {
39116 unsigned int msix_vector;
39117 unsigned int msi_vector;
39118 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
39119- struct access_method access;
39120+ struct access_method *access;
39121
39122 /* queue and queue Info */
39123 struct list_head reqQ;
39124diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
39125index c772d8d..35c362c 100644
39126--- a/drivers/scsi/libfc/fc_exch.c
39127+++ b/drivers/scsi/libfc/fc_exch.c
39128@@ -100,12 +100,12 @@ struct fc_exch_mgr {
39129 u16 pool_max_index;
39130
39131 struct {
39132- atomic_t no_free_exch;
39133- atomic_t no_free_exch_xid;
39134- atomic_t xid_not_found;
39135- atomic_t xid_busy;
39136- atomic_t seq_not_found;
39137- atomic_t non_bls_resp;
39138+ atomic_unchecked_t no_free_exch;
39139+ atomic_unchecked_t no_free_exch_xid;
39140+ atomic_unchecked_t xid_not_found;
39141+ atomic_unchecked_t xid_busy;
39142+ atomic_unchecked_t seq_not_found;
39143+ atomic_unchecked_t non_bls_resp;
39144 } stats;
39145 };
39146
39147@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
39148 /* allocate memory for exchange */
39149 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
39150 if (!ep) {
39151- atomic_inc(&mp->stats.no_free_exch);
39152+ atomic_inc_unchecked(&mp->stats.no_free_exch);
39153 goto out;
39154 }
39155 memset(ep, 0, sizeof(*ep));
39156@@ -786,7 +786,7 @@ out:
39157 return ep;
39158 err:
39159 spin_unlock_bh(&pool->lock);
39160- atomic_inc(&mp->stats.no_free_exch_xid);
39161+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
39162 mempool_free(ep, mp->ep_pool);
39163 return NULL;
39164 }
39165@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39166 xid = ntohs(fh->fh_ox_id); /* we originated exch */
39167 ep = fc_exch_find(mp, xid);
39168 if (!ep) {
39169- atomic_inc(&mp->stats.xid_not_found);
39170+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39171 reject = FC_RJT_OX_ID;
39172 goto out;
39173 }
39174@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39175 ep = fc_exch_find(mp, xid);
39176 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
39177 if (ep) {
39178- atomic_inc(&mp->stats.xid_busy);
39179+ atomic_inc_unchecked(&mp->stats.xid_busy);
39180 reject = FC_RJT_RX_ID;
39181 goto rel;
39182 }
39183@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39184 }
39185 xid = ep->xid; /* get our XID */
39186 } else if (!ep) {
39187- atomic_inc(&mp->stats.xid_not_found);
39188+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39189 reject = FC_RJT_RX_ID; /* XID not found */
39190 goto out;
39191 }
39192@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39193 } else {
39194 sp = &ep->seq;
39195 if (sp->id != fh->fh_seq_id) {
39196- atomic_inc(&mp->stats.seq_not_found);
39197+ atomic_inc_unchecked(&mp->stats.seq_not_found);
39198 if (f_ctl & FC_FC_END_SEQ) {
39199 /*
39200 * Update sequence_id based on incoming last
39201@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
39202
39203 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
39204 if (!ep) {
39205- atomic_inc(&mp->stats.xid_not_found);
39206+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39207 goto out;
39208 }
39209 if (ep->esb_stat & ESB_ST_COMPLETE) {
39210- atomic_inc(&mp->stats.xid_not_found);
39211+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39212 goto rel;
39213 }
39214 if (ep->rxid == FC_XID_UNKNOWN)
39215 ep->rxid = ntohs(fh->fh_rx_id);
39216 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
39217- atomic_inc(&mp->stats.xid_not_found);
39218+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39219 goto rel;
39220 }
39221 if (ep->did != ntoh24(fh->fh_s_id) &&
39222 ep->did != FC_FID_FLOGI) {
39223- atomic_inc(&mp->stats.xid_not_found);
39224+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39225 goto rel;
39226 }
39227 sof = fr_sof(fp);
39228@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
39229 sp->ssb_stat |= SSB_ST_RESP;
39230 sp->id = fh->fh_seq_id;
39231 } else if (sp->id != fh->fh_seq_id) {
39232- atomic_inc(&mp->stats.seq_not_found);
39233+ atomic_inc_unchecked(&mp->stats.seq_not_found);
39234 goto rel;
39235 }
39236
39237@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
39238 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
39239
39240 if (!sp)
39241- atomic_inc(&mp->stats.xid_not_found);
39242+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39243 else
39244- atomic_inc(&mp->stats.non_bls_resp);
39245+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
39246
39247 fc_frame_free(fp);
39248 }
39249@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
39250
39251 list_for_each_entry(ema, &lport->ema_list, ema_list) {
39252 mp = ema->mp;
39253- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
39254+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
39255 st->fc_no_free_exch_xid +=
39256- atomic_read(&mp->stats.no_free_exch_xid);
39257- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
39258- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
39259- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
39260- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
39261+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
39262+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
39263+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
39264+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
39265+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
39266 }
39267 }
39268 EXPORT_SYMBOL(fc_exch_update_stats);
39269diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
39270index bdb81cd..d3c7c2c 100644
39271--- a/drivers/scsi/libsas/sas_ata.c
39272+++ b/drivers/scsi/libsas/sas_ata.c
39273@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
39274 .postreset = ata_std_postreset,
39275 .error_handler = ata_std_error_handler,
39276 .post_internal_cmd = sas_ata_post_internal,
39277- .qc_defer = ata_std_qc_defer,
39278+ .qc_defer = ata_std_qc_defer,
39279 .qc_prep = ata_noop_qc_prep,
39280 .qc_issue = sas_ata_qc_issue,
39281 .qc_fill_rtf = sas_ata_qc_fill_rtf,
39282diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
39283index df4c13a..a51e90c 100644
39284--- a/drivers/scsi/lpfc/lpfc.h
39285+++ b/drivers/scsi/lpfc/lpfc.h
39286@@ -424,7 +424,7 @@ struct lpfc_vport {
39287 struct dentry *debug_nodelist;
39288 struct dentry *vport_debugfs_root;
39289 struct lpfc_debugfs_trc *disc_trc;
39290- atomic_t disc_trc_cnt;
39291+ atomic_unchecked_t disc_trc_cnt;
39292 #endif
39293 uint8_t stat_data_enabled;
39294 uint8_t stat_data_blocked;
39295@@ -842,8 +842,8 @@ struct lpfc_hba {
39296 struct timer_list fabric_block_timer;
39297 unsigned long bit_flags;
39298 #define FABRIC_COMANDS_BLOCKED 0
39299- atomic_t num_rsrc_err;
39300- atomic_t num_cmd_success;
39301+ atomic_unchecked_t num_rsrc_err;
39302+ atomic_unchecked_t num_cmd_success;
39303 unsigned long last_rsrc_error_time;
39304 unsigned long last_ramp_down_time;
39305 unsigned long last_ramp_up_time;
39306@@ -879,7 +879,7 @@ struct lpfc_hba {
39307
39308 struct dentry *debug_slow_ring_trc;
39309 struct lpfc_debugfs_trc *slow_ring_trc;
39310- atomic_t slow_ring_trc_cnt;
39311+ atomic_unchecked_t slow_ring_trc_cnt;
39312 /* iDiag debugfs sub-directory */
39313 struct dentry *idiag_root;
39314 struct dentry *idiag_pci_cfg;
39315diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
39316index f63f5ff..de29189 100644
39317--- a/drivers/scsi/lpfc/lpfc_debugfs.c
39318+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
39319@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
39320
39321 #include <linux/debugfs.h>
39322
39323-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
39324+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
39325 static unsigned long lpfc_debugfs_start_time = 0L;
39326
39327 /* iDiag */
39328@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
39329 lpfc_debugfs_enable = 0;
39330
39331 len = 0;
39332- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
39333+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
39334 (lpfc_debugfs_max_disc_trc - 1);
39335 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
39336 dtp = vport->disc_trc + i;
39337@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
39338 lpfc_debugfs_enable = 0;
39339
39340 len = 0;
39341- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
39342+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
39343 (lpfc_debugfs_max_slow_ring_trc - 1);
39344 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
39345 dtp = phba->slow_ring_trc + i;
39346@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
39347 !vport || !vport->disc_trc)
39348 return;
39349
39350- index = atomic_inc_return(&vport->disc_trc_cnt) &
39351+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
39352 (lpfc_debugfs_max_disc_trc - 1);
39353 dtp = vport->disc_trc + index;
39354 dtp->fmt = fmt;
39355 dtp->data1 = data1;
39356 dtp->data2 = data2;
39357 dtp->data3 = data3;
39358- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
39359+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
39360 dtp->jif = jiffies;
39361 #endif
39362 return;
39363@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
39364 !phba || !phba->slow_ring_trc)
39365 return;
39366
39367- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
39368+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
39369 (lpfc_debugfs_max_slow_ring_trc - 1);
39370 dtp = phba->slow_ring_trc + index;
39371 dtp->fmt = fmt;
39372 dtp->data1 = data1;
39373 dtp->data2 = data2;
39374 dtp->data3 = data3;
39375- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
39376+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
39377 dtp->jif = jiffies;
39378 #endif
39379 return;
39380@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
39381 "slow_ring buffer\n");
39382 goto debug_failed;
39383 }
39384- atomic_set(&phba->slow_ring_trc_cnt, 0);
39385+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
39386 memset(phba->slow_ring_trc, 0,
39387 (sizeof(struct lpfc_debugfs_trc) *
39388 lpfc_debugfs_max_slow_ring_trc));
39389@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
39390 "buffer\n");
39391 goto debug_failed;
39392 }
39393- atomic_set(&vport->disc_trc_cnt, 0);
39394+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
39395
39396 snprintf(name, sizeof(name), "discovery_trace");
39397 vport->debug_disc_trc =
39398diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
39399index 89ad558..76956c4 100644
39400--- a/drivers/scsi/lpfc/lpfc_init.c
39401+++ b/drivers/scsi/lpfc/lpfc_init.c
39402@@ -10618,8 +10618,10 @@ lpfc_init(void)
39403 "misc_register returned with status %d", error);
39404
39405 if (lpfc_enable_npiv) {
39406- lpfc_transport_functions.vport_create = lpfc_vport_create;
39407- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
39408+ pax_open_kernel();
39409+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
39410+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
39411+ pax_close_kernel();
39412 }
39413 lpfc_transport_template =
39414 fc_attach_transport(&lpfc_transport_functions);
39415diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
39416index 60e5a17..ff7a793 100644
39417--- a/drivers/scsi/lpfc/lpfc_scsi.c
39418+++ b/drivers/scsi/lpfc/lpfc_scsi.c
39419@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
39420 uint32_t evt_posted;
39421
39422 spin_lock_irqsave(&phba->hbalock, flags);
39423- atomic_inc(&phba->num_rsrc_err);
39424+ atomic_inc_unchecked(&phba->num_rsrc_err);
39425 phba->last_rsrc_error_time = jiffies;
39426
39427 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
39428@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
39429 unsigned long flags;
39430 struct lpfc_hba *phba = vport->phba;
39431 uint32_t evt_posted;
39432- atomic_inc(&phba->num_cmd_success);
39433+ atomic_inc_unchecked(&phba->num_cmd_success);
39434
39435 if (vport->cfg_lun_queue_depth <= queue_depth)
39436 return;
39437@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
39438 unsigned long num_rsrc_err, num_cmd_success;
39439 int i;
39440
39441- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
39442- num_cmd_success = atomic_read(&phba->num_cmd_success);
39443+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
39444+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
39445
39446 /*
39447 * The error and success command counters are global per
39448@@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
39449 }
39450 }
39451 lpfc_destroy_vport_work_array(phba, vports);
39452- atomic_set(&phba->num_rsrc_err, 0);
39453- atomic_set(&phba->num_cmd_success, 0);
39454+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
39455+ atomic_set_unchecked(&phba->num_cmd_success, 0);
39456 }
39457
39458 /**
39459@@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
39460 }
39461 }
39462 lpfc_destroy_vport_work_array(phba, vports);
39463- atomic_set(&phba->num_rsrc_err, 0);
39464- atomic_set(&phba->num_cmd_success, 0);
39465+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
39466+ atomic_set_unchecked(&phba->num_cmd_success, 0);
39467 }
39468
39469 /**
39470diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
39471index b46f5e9..c4c4ccb 100644
39472--- a/drivers/scsi/pmcraid.c
39473+++ b/drivers/scsi/pmcraid.c
39474@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
39475 res->scsi_dev = scsi_dev;
39476 scsi_dev->hostdata = res;
39477 res->change_detected = 0;
39478- atomic_set(&res->read_failures, 0);
39479- atomic_set(&res->write_failures, 0);
39480+ atomic_set_unchecked(&res->read_failures, 0);
39481+ atomic_set_unchecked(&res->write_failures, 0);
39482 rc = 0;
39483 }
39484 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
39485@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
39486
39487 /* If this was a SCSI read/write command keep count of errors */
39488 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
39489- atomic_inc(&res->read_failures);
39490+ atomic_inc_unchecked(&res->read_failures);
39491 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
39492- atomic_inc(&res->write_failures);
39493+ atomic_inc_unchecked(&res->write_failures);
39494
39495 if (!RES_IS_GSCSI(res->cfg_entry) &&
39496 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
39497@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
39498 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
39499 * hrrq_id assigned here in queuecommand
39500 */
39501- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
39502+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
39503 pinstance->num_hrrq;
39504 cmd->cmd_done = pmcraid_io_done;
39505
39506@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
39507 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
39508 * hrrq_id assigned here in queuecommand
39509 */
39510- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
39511+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
39512 pinstance->num_hrrq;
39513
39514 if (request_size) {
39515@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
39516
39517 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
39518 /* add resources only after host is added into system */
39519- if (!atomic_read(&pinstance->expose_resources))
39520+ if (!atomic_read_unchecked(&pinstance->expose_resources))
39521 return;
39522
39523 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
39524@@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
39525 init_waitqueue_head(&pinstance->reset_wait_q);
39526
39527 atomic_set(&pinstance->outstanding_cmds, 0);
39528- atomic_set(&pinstance->last_message_id, 0);
39529- atomic_set(&pinstance->expose_resources, 0);
39530+ atomic_set_unchecked(&pinstance->last_message_id, 0);
39531+ atomic_set_unchecked(&pinstance->expose_resources, 0);
39532
39533 INIT_LIST_HEAD(&pinstance->free_res_q);
39534 INIT_LIST_HEAD(&pinstance->used_res_q);
39535@@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
39536 /* Schedule worker thread to handle CCN and take care of adding and
39537 * removing devices to OS
39538 */
39539- atomic_set(&pinstance->expose_resources, 1);
39540+ atomic_set_unchecked(&pinstance->expose_resources, 1);
39541 schedule_work(&pinstance->worker_q);
39542 return rc;
39543
39544diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
39545index e1d150f..6c6df44 100644
39546--- a/drivers/scsi/pmcraid.h
39547+++ b/drivers/scsi/pmcraid.h
39548@@ -748,7 +748,7 @@ struct pmcraid_instance {
39549 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
39550
39551 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
39552- atomic_t last_message_id;
39553+ atomic_unchecked_t last_message_id;
39554
39555 /* configuration table */
39556 struct pmcraid_config_table *cfg_table;
39557@@ -777,7 +777,7 @@ struct pmcraid_instance {
39558 atomic_t outstanding_cmds;
39559
39560 /* should add/delete resources to mid-layer now ?*/
39561- atomic_t expose_resources;
39562+ atomic_unchecked_t expose_resources;
39563
39564
39565
39566@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
39567 struct pmcraid_config_table_entry_ext cfg_entry_ext;
39568 };
39569 struct scsi_device *scsi_dev; /* Link scsi_device structure */
39570- atomic_t read_failures; /* count of failed READ commands */
39571- atomic_t write_failures; /* count of failed WRITE commands */
39572+ atomic_unchecked_t read_failures; /* count of failed READ commands */
39573+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
39574
39575 /* To indicate add/delete/modify during CCN */
39576 u8 change_detected;
39577diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
39578index 83d7984..a27d947 100644
39579--- a/drivers/scsi/qla2xxx/qla_attr.c
39580+++ b/drivers/scsi/qla2xxx/qla_attr.c
39581@@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
39582 return 0;
39583 }
39584
39585-struct fc_function_template qla2xxx_transport_functions = {
39586+fc_function_template_no_const qla2xxx_transport_functions = {
39587
39588 .show_host_node_name = 1,
39589 .show_host_port_name = 1,
39590@@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
39591 .bsg_timeout = qla24xx_bsg_timeout,
39592 };
39593
39594-struct fc_function_template qla2xxx_transport_vport_functions = {
39595+fc_function_template_no_const qla2xxx_transport_vport_functions = {
39596
39597 .show_host_node_name = 1,
39598 .show_host_port_name = 1,
39599diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
39600index 2411d1a..4673766 100644
39601--- a/drivers/scsi/qla2xxx/qla_gbl.h
39602+++ b/drivers/scsi/qla2xxx/qla_gbl.h
39603@@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
39604 struct device_attribute;
39605 extern struct device_attribute *qla2x00_host_attrs[];
39606 struct fc_function_template;
39607-extern struct fc_function_template qla2xxx_transport_functions;
39608-extern struct fc_function_template qla2xxx_transport_vport_functions;
39609+extern fc_function_template_no_const qla2xxx_transport_functions;
39610+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
39611 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
39612 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
39613 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
39614diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
39615index 10d23f8..a7d5d4c 100644
39616--- a/drivers/scsi/qla2xxx/qla_os.c
39617+++ b/drivers/scsi/qla2xxx/qla_os.c
39618@@ -1472,8 +1472,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
39619 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
39620 /* Ok, a 64bit DMA mask is applicable. */
39621 ha->flags.enable_64bit_addressing = 1;
39622- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
39623- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
39624+ pax_open_kernel();
39625+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
39626+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
39627+ pax_close_kernel();
39628 return;
39629 }
39630 }
39631diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
39632index 329d553..f20d31d 100644
39633--- a/drivers/scsi/qla4xxx/ql4_def.h
39634+++ b/drivers/scsi/qla4xxx/ql4_def.h
39635@@ -273,7 +273,7 @@ struct ddb_entry {
39636 * (4000 only) */
39637 atomic_t relogin_timer; /* Max Time to wait for
39638 * relogin to complete */
39639- atomic_t relogin_retry_count; /* Num of times relogin has been
39640+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
39641 * retried */
39642 uint32_t default_time2wait; /* Default Min time between
39643 * relogins (+aens) */
39644diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
39645index 4cec123..7c1329f 100644
39646--- a/drivers/scsi/qla4xxx/ql4_os.c
39647+++ b/drivers/scsi/qla4xxx/ql4_os.c
39648@@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
39649 */
39650 if (!iscsi_is_session_online(cls_sess)) {
39651 /* Reset retry relogin timer */
39652- atomic_inc(&ddb_entry->relogin_retry_count);
39653+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
39654 DEBUG2(ql4_printk(KERN_INFO, ha,
39655 "%s: index[%d] relogin timed out-retrying"
39656 " relogin (%d), retry (%d)\n", __func__,
39657 ddb_entry->fw_ddb_index,
39658- atomic_read(&ddb_entry->relogin_retry_count),
39659+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
39660 ddb_entry->default_time2wait + 4));
39661 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
39662 atomic_set(&ddb_entry->retry_relogin_timer,
39663@@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
39664
39665 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
39666 atomic_set(&ddb_entry->relogin_timer, 0);
39667- atomic_set(&ddb_entry->relogin_retry_count, 0);
39668+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
39669 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
39670 ddb_entry->default_relogin_timeout =
39671 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
39672diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
39673index 2c0d0ec..4e8681a 100644
39674--- a/drivers/scsi/scsi.c
39675+++ b/drivers/scsi/scsi.c
39676@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
39677 unsigned long timeout;
39678 int rtn = 0;
39679
39680- atomic_inc(&cmd->device->iorequest_cnt);
39681+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
39682
39683 /* check if the device is still usable */
39684 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
39685diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
39686index f1bf5af..f67e943 100644
39687--- a/drivers/scsi/scsi_lib.c
39688+++ b/drivers/scsi/scsi_lib.c
39689@@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
39690 shost = sdev->host;
39691 scsi_init_cmd_errh(cmd);
39692 cmd->result = DID_NO_CONNECT << 16;
39693- atomic_inc(&cmd->device->iorequest_cnt);
39694+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
39695
39696 /*
39697 * SCSI request completion path will do scsi_device_unbusy(),
39698@@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
39699
39700 INIT_LIST_HEAD(&cmd->eh_entry);
39701
39702- atomic_inc(&cmd->device->iodone_cnt);
39703+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
39704 if (cmd->result)
39705- atomic_inc(&cmd->device->ioerr_cnt);
39706+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
39707
39708 disposition = scsi_decide_disposition(cmd);
39709 if (disposition != SUCCESS &&
39710diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
39711index 931a7d9..0c2a754 100644
39712--- a/drivers/scsi/scsi_sysfs.c
39713+++ b/drivers/scsi/scsi_sysfs.c
39714@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
39715 char *buf) \
39716 { \
39717 struct scsi_device *sdev = to_scsi_device(dev); \
39718- unsigned long long count = atomic_read(&sdev->field); \
39719+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
39720 return snprintf(buf, 20, "0x%llx\n", count); \
39721 } \
39722 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
39723diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
39724index 84a1fdf..693b0d6 100644
39725--- a/drivers/scsi/scsi_tgt_lib.c
39726+++ b/drivers/scsi/scsi_tgt_lib.c
39727@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
39728 int err;
39729
39730 dprintk("%lx %u\n", uaddr, len);
39731- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
39732+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
39733 if (err) {
39734 /*
39735 * TODO: need to fixup sg_tablesize, max_segment_size,
39736diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
39737index e894ca7..de9d7660 100644
39738--- a/drivers/scsi/scsi_transport_fc.c
39739+++ b/drivers/scsi/scsi_transport_fc.c
39740@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
39741 * Netlink Infrastructure
39742 */
39743
39744-static atomic_t fc_event_seq;
39745+static atomic_unchecked_t fc_event_seq;
39746
39747 /**
39748 * fc_get_event_number - Obtain the next sequential FC event number
39749@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
39750 u32
39751 fc_get_event_number(void)
39752 {
39753- return atomic_add_return(1, &fc_event_seq);
39754+ return atomic_add_return_unchecked(1, &fc_event_seq);
39755 }
39756 EXPORT_SYMBOL(fc_get_event_number);
39757
39758@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
39759 {
39760 int error;
39761
39762- atomic_set(&fc_event_seq, 0);
39763+ atomic_set_unchecked(&fc_event_seq, 0);
39764
39765 error = transport_class_register(&fc_host_class);
39766 if (error)
39767@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
39768 char *cp;
39769
39770 *val = simple_strtoul(buf, &cp, 0);
39771- if ((*cp && (*cp != '\n')) || (*val < 0))
39772+ if (*cp && (*cp != '\n'))
39773 return -EINVAL;
39774 /*
39775 * Check for overflow; dev_loss_tmo is u32
39776diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
39777index 31969f2..2b348f0 100644
39778--- a/drivers/scsi/scsi_transport_iscsi.c
39779+++ b/drivers/scsi/scsi_transport_iscsi.c
39780@@ -79,7 +79,7 @@ struct iscsi_internal {
39781 struct transport_container session_cont;
39782 };
39783
39784-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
39785+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
39786 static struct workqueue_struct *iscsi_eh_timer_workq;
39787
39788 static DEFINE_IDA(iscsi_sess_ida);
39789@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
39790 int err;
39791
39792 ihost = shost->shost_data;
39793- session->sid = atomic_add_return(1, &iscsi_session_nr);
39794+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
39795
39796 if (target_id == ISCSI_MAX_TARGET) {
39797 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
39798@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
39799 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
39800 ISCSI_TRANSPORT_VERSION);
39801
39802- atomic_set(&iscsi_session_nr, 0);
39803+ atomic_set_unchecked(&iscsi_session_nr, 0);
39804
39805 err = class_register(&iscsi_transport_class);
39806 if (err)
39807diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
39808index f379c7f..e8fc69c 100644
39809--- a/drivers/scsi/scsi_transport_srp.c
39810+++ b/drivers/scsi/scsi_transport_srp.c
39811@@ -33,7 +33,7 @@
39812 #include "scsi_transport_srp_internal.h"
39813
39814 struct srp_host_attrs {
39815- atomic_t next_port_id;
39816+ atomic_unchecked_t next_port_id;
39817 };
39818 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
39819
39820@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
39821 struct Scsi_Host *shost = dev_to_shost(dev);
39822 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
39823
39824- atomic_set(&srp_host->next_port_id, 0);
39825+ atomic_set_unchecked(&srp_host->next_port_id, 0);
39826 return 0;
39827 }
39828
39829@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
39830 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
39831 rport->roles = ids->roles;
39832
39833- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
39834+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
39835 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
39836
39837 transport_setup_device(&rport->dev);
39838diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
39839index 7992635..609faf8 100644
39840--- a/drivers/scsi/sd.c
39841+++ b/drivers/scsi/sd.c
39842@@ -2909,7 +2909,7 @@ static int sd_probe(struct device *dev)
39843 sdkp->disk = gd;
39844 sdkp->index = index;
39845 atomic_set(&sdkp->openers, 0);
39846- atomic_set(&sdkp->device->ioerr_cnt, 0);
39847+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
39848
39849 if (!sdp->request_queue->rq_timeout) {
39850 if (sdp->type != TYPE_MOD)
39851diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
39852index be2c9a6..275525c 100644
39853--- a/drivers/scsi/sg.c
39854+++ b/drivers/scsi/sg.c
39855@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
39856 sdp->disk->disk_name,
39857 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
39858 NULL,
39859- (char *)arg);
39860+ (char __user *)arg);
39861 case BLKTRACESTART:
39862 return blk_trace_startstop(sdp->device->request_queue, 1);
39863 case BLKTRACESTOP:
39864diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
39865index 19ee901..6e8c2ef 100644
39866--- a/drivers/spi/spi.c
39867+++ b/drivers/spi/spi.c
39868@@ -1616,7 +1616,7 @@ int spi_bus_unlock(struct spi_master *master)
39869 EXPORT_SYMBOL_GPL(spi_bus_unlock);
39870
39871 /* portable code must never pass more than 32 bytes */
39872-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
39873+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
39874
39875 static u8 *buf;
39876
39877diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
39878index 34afc16..ffe44dd 100644
39879--- a/drivers/staging/octeon/ethernet-rx.c
39880+++ b/drivers/staging/octeon/ethernet-rx.c
39881@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39882 /* Increment RX stats for virtual ports */
39883 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
39884 #ifdef CONFIG_64BIT
39885- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
39886- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
39887+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
39888+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
39889 #else
39890- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
39891- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
39892+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
39893+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
39894 #endif
39895 }
39896 netif_receive_skb(skb);
39897@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39898 dev->name);
39899 */
39900 #ifdef CONFIG_64BIT
39901- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
39902+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39903 #else
39904- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
39905+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
39906 #endif
39907 dev_kfree_skb_irq(skb);
39908 }
39909diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
39910index ef32dc1..a159d68 100644
39911--- a/drivers/staging/octeon/ethernet.c
39912+++ b/drivers/staging/octeon/ethernet.c
39913@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
39914 * since the RX tasklet also increments it.
39915 */
39916 #ifdef CONFIG_64BIT
39917- atomic64_add(rx_status.dropped_packets,
39918- (atomic64_t *)&priv->stats.rx_dropped);
39919+ atomic64_add_unchecked(rx_status.dropped_packets,
39920+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39921 #else
39922- atomic_add(rx_status.dropped_packets,
39923- (atomic_t *)&priv->stats.rx_dropped);
39924+ atomic_add_unchecked(rx_status.dropped_packets,
39925+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
39926 #endif
39927 }
39928
39929diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
39930index a2b7e03..aaf3630 100644
39931--- a/drivers/staging/ramster/tmem.c
39932+++ b/drivers/staging/ramster/tmem.c
39933@@ -50,25 +50,25 @@
39934 * A tmem host implementation must use this function to register callbacks
39935 * for memory allocation.
39936 */
39937-static struct tmem_hostops tmem_hostops;
39938+static struct tmem_hostops *tmem_hostops;
39939
39940 static void tmem_objnode_tree_init(void);
39941
39942 void tmem_register_hostops(struct tmem_hostops *m)
39943 {
39944 tmem_objnode_tree_init();
39945- tmem_hostops = *m;
39946+ tmem_hostops = m;
39947 }
39948
39949 /*
39950 * A tmem host implementation must use this function to register
39951 * callbacks for a page-accessible memory (PAM) implementation.
39952 */
39953-static struct tmem_pamops tmem_pamops;
39954+static struct tmem_pamops *tmem_pamops;
39955
39956 void tmem_register_pamops(struct tmem_pamops *m)
39957 {
39958- tmem_pamops = *m;
39959+ tmem_pamops = m;
39960 }
39961
39962 /*
39963@@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
39964 obj->pampd_count = 0;
39965 #ifdef CONFIG_RAMSTER
39966 if (tmem_pamops.new_obj != NULL)
39967- (*tmem_pamops.new_obj)(obj);
39968+ (tmem_pamops->new_obj)(obj);
39969 #endif
39970 SET_SENTINEL(obj, OBJ);
39971
39972@@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
39973 rbnode = rb_next(rbnode);
39974 tmem_pampd_destroy_all_in_obj(obj, true);
39975 tmem_obj_free(obj, hb);
39976- (*tmem_hostops.obj_free)(obj, pool);
39977+ (tmem_hostops->obj_free)(obj, pool);
39978 }
39979 spin_unlock(&hb->lock);
39980 }
39981@@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
39982 ASSERT_SENTINEL(obj, OBJ);
39983 BUG_ON(obj->pool == NULL);
39984 ASSERT_SENTINEL(obj->pool, POOL);
39985- objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
39986+ objnode = (tmem_hostops->objnode_alloc)(obj->pool);
39987 if (unlikely(objnode == NULL))
39988 goto out;
39989 objnode->obj = obj;
39990@@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
39991 ASSERT_SENTINEL(pool, POOL);
39992 objnode->obj->objnode_count--;
39993 objnode->obj = NULL;
39994- (*tmem_hostops.objnode_free)(objnode, pool);
39995+ (tmem_hostops->objnode_free)(objnode, pool);
39996 }
39997
39998 /*
39999@@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
40000 void *old_pampd = *(void **)slot;
40001 *(void **)slot = new_pampd;
40002 if (!no_free)
40003- (*tmem_pamops.free)(old_pampd, obj->pool,
40004+ (tmem_pamops->free)(old_pampd, obj->pool,
40005 NULL, 0, false);
40006 ret = new_pampd;
40007 }
40008@@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
40009 if (objnode->slots[i]) {
40010 if (ht == 1) {
40011 obj->pampd_count--;
40012- (*tmem_pamops.free)(objnode->slots[i],
40013+ (tmem_pamops->free)(objnode->slots[i],
40014 obj->pool, NULL, 0, true);
40015 objnode->slots[i] = NULL;
40016 continue;
40017@@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
40018 return;
40019 if (obj->objnode_tree_height == 0) {
40020 obj->pampd_count--;
40021- (*tmem_pamops.free)(obj->objnode_tree_root,
40022+ (tmem_pamops->free)(obj->objnode_tree_root,
40023 obj->pool, NULL, 0, true);
40024 } else {
40025 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
40026@@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
40027 obj->objnode_tree_root = NULL;
40028 #ifdef CONFIG_RAMSTER
40029 if (tmem_pamops.free_obj != NULL)
40030- (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
40031+ (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
40032 #endif
40033 }
40034
40035@@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40036 /* if found, is a dup put, flush the old one */
40037 pampd_del = tmem_pampd_delete_from_obj(obj, index);
40038 BUG_ON(pampd_del != pampd);
40039- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
40040+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
40041 if (obj->pampd_count == 0) {
40042 objnew = obj;
40043 objfound = NULL;
40044@@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40045 pampd = NULL;
40046 }
40047 } else {
40048- obj = objnew = (*tmem_hostops.obj_alloc)(pool);
40049+ obj = objnew = (tmem_hostops->obj_alloc)(pool);
40050 if (unlikely(obj == NULL)) {
40051 ret = -ENOMEM;
40052 goto out;
40053@@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40054 if (unlikely(ret == -ENOMEM))
40055 /* may have partially built objnode tree ("stump") */
40056 goto delete_and_free;
40057- (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
40058+ (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
40059 goto out;
40060
40061 delete_and_free:
40062 (void)tmem_pampd_delete_from_obj(obj, index);
40063 if (pampd)
40064- (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
40065+ (tmem_pamops->free)(pampd, pool, NULL, 0, true);
40066 if (objnew) {
40067 tmem_obj_free(objnew, hb);
40068- (*tmem_hostops.obj_free)(objnew, pool);
40069+ (tmem_hostops->obj_free)(objnew, pool);
40070 }
40071 out:
40072 spin_unlock(&hb->lock);
40073@@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
40074 if (pampd != NULL) {
40075 BUG_ON(obj == NULL);
40076 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
40077- (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
40078+ (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
40079 } else if (delete) {
40080 BUG_ON(obj == NULL);
40081 (void)tmem_pampd_delete_from_obj(obj, index);
40082@@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
40083 int ret = 0;
40084
40085 if (!is_ephemeral(pool))
40086- new_pampd = (*tmem_pamops.repatriate_preload)(
40087+ new_pampd = (tmem_pamops->repatriate_preload)(
40088 old_pampd, pool, oidp, index, &intransit);
40089 if (intransit)
40090 ret = -EAGAIN;
40091@@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
40092 /* must release the hb->lock else repatriate can't sleep */
40093 spin_unlock(&hb->lock);
40094 if (!intransit)
40095- ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
40096+ ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
40097 oidp, index, free, data);
40098 if (ret == -EAGAIN) {
40099 /* rare I think, but should cond_resched()??? */
40100@@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
40101 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
40102 /* if we bug here, pamops wasn't properly set up for ramster */
40103 BUG_ON(tmem_pamops.replace_in_obj == NULL);
40104- ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
40105+ ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
40106 out:
40107 spin_unlock(&hb->lock);
40108 return ret;
40109@@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40110 if (free) {
40111 if (obj->pampd_count == 0) {
40112 tmem_obj_free(obj, hb);
40113- (*tmem_hostops.obj_free)(obj, pool);
40114+ (tmem_hostops->obj_free)(obj, pool);
40115 obj = NULL;
40116 }
40117 }
40118 if (free)
40119- ret = (*tmem_pamops.get_data_and_free)(
40120+ ret = (tmem_pamops->get_data_and_free)(
40121 data, sizep, raw, pampd, pool, oidp, index);
40122 else
40123- ret = (*tmem_pamops.get_data)(
40124+ ret = (tmem_pamops->get_data)(
40125 data, sizep, raw, pampd, pool, oidp, index);
40126 if (ret < 0)
40127 goto out;
40128@@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
40129 pampd = tmem_pampd_delete_from_obj(obj, index);
40130 if (pampd == NULL)
40131 goto out;
40132- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
40133+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
40134 if (obj->pampd_count == 0) {
40135 tmem_obj_free(obj, hb);
40136- (*tmem_hostops.obj_free)(obj, pool);
40137+ (tmem_hostops->obj_free)(obj, pool);
40138 }
40139 ret = 0;
40140
40141@@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
40142 goto out;
40143 tmem_pampd_destroy_all_in_obj(obj, false);
40144 tmem_obj_free(obj, hb);
40145- (*tmem_hostops.obj_free)(obj, pool);
40146+ (tmem_hostops->obj_free)(obj, pool);
40147 ret = 0;
40148
40149 out:
40150diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
40151index dc23395..cf7e9b1 100644
40152--- a/drivers/staging/rtl8712/rtl871x_io.h
40153+++ b/drivers/staging/rtl8712/rtl871x_io.h
40154@@ -108,7 +108,7 @@ struct _io_ops {
40155 u8 *pmem);
40156 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
40157 u8 *pmem);
40158-};
40159+} __no_const;
40160
40161 struct io_req {
40162 struct list_head list;
40163diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
40164index 1f5088b..0e59820 100644
40165--- a/drivers/staging/sbe-2t3e3/netdev.c
40166+++ b/drivers/staging/sbe-2t3e3/netdev.c
40167@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40168 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
40169
40170 if (rlen)
40171- if (copy_to_user(data, &resp, rlen))
40172+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
40173 return -EFAULT;
40174
40175 return 0;
40176diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
40177index 5dddc4d..34fcb2f 100644
40178--- a/drivers/staging/usbip/vhci.h
40179+++ b/drivers/staging/usbip/vhci.h
40180@@ -83,7 +83,7 @@ struct vhci_hcd {
40181 unsigned resuming:1;
40182 unsigned long re_timeout;
40183
40184- atomic_t seqnum;
40185+ atomic_unchecked_t seqnum;
40186
40187 /*
40188 * NOTE:
40189diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
40190index c3aa219..bf8b3de 100644
40191--- a/drivers/staging/usbip/vhci_hcd.c
40192+++ b/drivers/staging/usbip/vhci_hcd.c
40193@@ -451,7 +451,7 @@ static void vhci_tx_urb(struct urb *urb)
40194 return;
40195 }
40196
40197- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
40198+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40199 if (priv->seqnum == 0xffff)
40200 dev_info(&urb->dev->dev, "seqnum max\n");
40201
40202@@ -703,7 +703,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
40203 return -ENOMEM;
40204 }
40205
40206- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
40207+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40208 if (unlink->seqnum == 0xffff)
40209 pr_info("seqnum max\n");
40210
40211@@ -907,7 +907,7 @@ static int vhci_start(struct usb_hcd *hcd)
40212 vdev->rhport = rhport;
40213 }
40214
40215- atomic_set(&vhci->seqnum, 0);
40216+ atomic_set_unchecked(&vhci->seqnum, 0);
40217 spin_lock_init(&vhci->lock);
40218
40219 hcd->power_budget = 0; /* no limit */
40220diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
40221index ba5f1c0..11d8122 100644
40222--- a/drivers/staging/usbip/vhci_rx.c
40223+++ b/drivers/staging/usbip/vhci_rx.c
40224@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
40225 if (!urb) {
40226 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
40227 pr_info("max seqnum %d\n",
40228- atomic_read(&the_controller->seqnum));
40229+ atomic_read_unchecked(&the_controller->seqnum));
40230 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
40231 return;
40232 }
40233diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
40234index 5f13890..36a044b 100644
40235--- a/drivers/staging/vt6655/hostap.c
40236+++ b/drivers/staging/vt6655/hostap.c
40237@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
40238 *
40239 */
40240
40241+static net_device_ops_no_const apdev_netdev_ops;
40242+
40243 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40244 {
40245 PSDevice apdev_priv;
40246 struct net_device *dev = pDevice->dev;
40247 int ret;
40248- const struct net_device_ops apdev_netdev_ops = {
40249- .ndo_start_xmit = pDevice->tx_80211,
40250- };
40251
40252 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
40253
40254@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40255 *apdev_priv = *pDevice;
40256 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
40257
40258+ /* only half broken now */
40259+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
40260 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
40261
40262 pDevice->apdev->type = ARPHRD_IEEE80211;
40263diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
40264index 26a7d0e..897b083 100644
40265--- a/drivers/staging/vt6656/hostap.c
40266+++ b/drivers/staging/vt6656/hostap.c
40267@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
40268 *
40269 */
40270
40271+static net_device_ops_no_const apdev_netdev_ops;
40272+
40273 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40274 {
40275 PSDevice apdev_priv;
40276 struct net_device *dev = pDevice->dev;
40277 int ret;
40278- const struct net_device_ops apdev_netdev_ops = {
40279- .ndo_start_xmit = pDevice->tx_80211,
40280- };
40281
40282 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
40283
40284@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40285 *apdev_priv = *pDevice;
40286 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
40287
40288+ /* only half broken now */
40289+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
40290 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
40291
40292 pDevice->apdev->type = ARPHRD_IEEE80211;
40293diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
40294index 56c8e60..1920c63 100644
40295--- a/drivers/staging/zcache/tmem.c
40296+++ b/drivers/staging/zcache/tmem.c
40297@@ -39,7 +39,7 @@
40298 * A tmem host implementation must use this function to register callbacks
40299 * for memory allocation.
40300 */
40301-static struct tmem_hostops tmem_hostops;
40302+static tmem_hostops_no_const tmem_hostops;
40303
40304 static void tmem_objnode_tree_init(void);
40305
40306@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
40307 * A tmem host implementation must use this function to register
40308 * callbacks for a page-accessible memory (PAM) implementation
40309 */
40310-static struct tmem_pamops tmem_pamops;
40311+static tmem_pamops_no_const tmem_pamops;
40312
40313 void tmem_register_pamops(struct tmem_pamops *m)
40314 {
40315diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
40316index 0d4aa82..f7832d4 100644
40317--- a/drivers/staging/zcache/tmem.h
40318+++ b/drivers/staging/zcache/tmem.h
40319@@ -180,6 +180,7 @@ struct tmem_pamops {
40320 void (*new_obj)(struct tmem_obj *);
40321 int (*replace_in_obj)(void *, struct tmem_obj *);
40322 };
40323+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
40324 extern void tmem_register_pamops(struct tmem_pamops *m);
40325
40326 /* memory allocation methods provided by the host implementation */
40327@@ -189,6 +190,7 @@ struct tmem_hostops {
40328 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
40329 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
40330 };
40331+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
40332 extern void tmem_register_hostops(struct tmem_hostops *m);
40333
40334 /* core tmem accessor functions */
40335diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
40336index f2aa754..11337b1 100644
40337--- a/drivers/target/target_core_device.c
40338+++ b/drivers/target/target_core_device.c
40339@@ -1375,7 +1375,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
40340 spin_lock_init(&dev->se_port_lock);
40341 spin_lock_init(&dev->se_tmr_lock);
40342 spin_lock_init(&dev->qf_cmd_lock);
40343- atomic_set(&dev->dev_ordered_id, 0);
40344+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
40345 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
40346 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
40347 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
40348diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
40349index bd587b7..173daf3 100644
40350--- a/drivers/target/target_core_transport.c
40351+++ b/drivers/target/target_core_transport.c
40352@@ -1077,7 +1077,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
40353 * Used to determine when ORDERED commands should go from
40354 * Dormant to Active status.
40355 */
40356- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
40357+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
40358 smp_mb__after_atomic_inc();
40359 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
40360 cmd->se_ordered_id, cmd->sam_task_attr,
40361diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
40362index b09c8d1f..c4225c0 100644
40363--- a/drivers/tty/cyclades.c
40364+++ b/drivers/tty/cyclades.c
40365@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
40366 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
40367 info->port.count);
40368 #endif
40369- info->port.count++;
40370+ atomic_inc(&info->port.count);
40371 #ifdef CY_DEBUG_COUNT
40372 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
40373- current->pid, info->port.count);
40374+ current->pid, atomic_read(&info->port.count));
40375 #endif
40376
40377 /*
40378@@ -3991,7 +3991,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
40379 for (j = 0; j < cy_card[i].nports; j++) {
40380 info = &cy_card[i].ports[j];
40381
40382- if (info->port.count) {
40383+ if (atomic_read(&info->port.count)) {
40384 /* XXX is the ldisc num worth this? */
40385 struct tty_struct *tty;
40386 struct tty_ldisc *ld;
40387diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
40388index 13ee53b..418d164 100644
40389--- a/drivers/tty/hvc/hvc_console.c
40390+++ b/drivers/tty/hvc/hvc_console.c
40391@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
40392
40393 spin_lock_irqsave(&hp->port.lock, flags);
40394 /* Check and then increment for fast path open. */
40395- if (hp->port.count++ > 0) {
40396+ if (atomic_inc_return(&hp->port.count) > 1) {
40397 spin_unlock_irqrestore(&hp->port.lock, flags);
40398 hvc_kick();
40399 return 0;
40400@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
40401
40402 spin_lock_irqsave(&hp->port.lock, flags);
40403
40404- if (--hp->port.count == 0) {
40405+ if (atomic_dec_return(&hp->port.count) == 0) {
40406 spin_unlock_irqrestore(&hp->port.lock, flags);
40407 /* We are done with the tty pointer now. */
40408 tty_port_tty_set(&hp->port, NULL);
40409@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
40410 */
40411 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
40412 } else {
40413- if (hp->port.count < 0)
40414+ if (atomic_read(&hp->port.count) < 0)
40415 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
40416- hp->vtermno, hp->port.count);
40417+ hp->vtermno, atomic_read(&hp->port.count));
40418 spin_unlock_irqrestore(&hp->port.lock, flags);
40419 }
40420 }
40421@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
40422 * open->hangup case this can be called after the final close so prevent
40423 * that from happening for now.
40424 */
40425- if (hp->port.count <= 0) {
40426+ if (atomic_read(&hp->port.count) <= 0) {
40427 spin_unlock_irqrestore(&hp->port.lock, flags);
40428 return;
40429 }
40430
40431- hp->port.count = 0;
40432+ atomic_set(&hp->port.count, 0);
40433 spin_unlock_irqrestore(&hp->port.lock, flags);
40434 tty_port_tty_set(&hp->port, NULL);
40435
40436@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
40437 return -EPIPE;
40438
40439 /* FIXME what's this (unprotected) check for? */
40440- if (hp->port.count <= 0)
40441+ if (atomic_read(&hp->port.count) <= 0)
40442 return -EIO;
40443
40444 spin_lock_irqsave(&hp->lock, flags);
40445diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
40446index 8776357..b2d4afd 100644
40447--- a/drivers/tty/hvc/hvcs.c
40448+++ b/drivers/tty/hvc/hvcs.c
40449@@ -83,6 +83,7 @@
40450 #include <asm/hvcserver.h>
40451 #include <asm/uaccess.h>
40452 #include <asm/vio.h>
40453+#include <asm/local.h>
40454
40455 /*
40456 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
40457@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
40458
40459 spin_lock_irqsave(&hvcsd->lock, flags);
40460
40461- if (hvcsd->port.count > 0) {
40462+ if (atomic_read(&hvcsd->port.count) > 0) {
40463 spin_unlock_irqrestore(&hvcsd->lock, flags);
40464 printk(KERN_INFO "HVCS: vterm state unchanged. "
40465 "The hvcs device node is still in use.\n");
40466@@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
40467 }
40468 }
40469
40470- hvcsd->port.count = 0;
40471+ atomic_set(&hvcsd->port.count, 0);
40472 hvcsd->port.tty = tty;
40473 tty->driver_data = hvcsd;
40474
40475@@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
40476 unsigned long flags;
40477
40478 spin_lock_irqsave(&hvcsd->lock, flags);
40479- hvcsd->port.count++;
40480+ atomic_inc(&hvcsd->port.count);
40481 hvcsd->todo_mask |= HVCS_SCHED_READ;
40482 spin_unlock_irqrestore(&hvcsd->lock, flags);
40483
40484@@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
40485 hvcsd = tty->driver_data;
40486
40487 spin_lock_irqsave(&hvcsd->lock, flags);
40488- if (--hvcsd->port.count == 0) {
40489+ if (atomic_dec_and_test(&hvcsd->port.count)) {
40490
40491 vio_disable_interrupts(hvcsd->vdev);
40492
40493@@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
40494
40495 free_irq(irq, hvcsd);
40496 return;
40497- } else if (hvcsd->port.count < 0) {
40498+ } else if (atomic_read(&hvcsd->port.count) < 0) {
40499 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
40500 " is missmanaged.\n",
40501- hvcsd->vdev->unit_address, hvcsd->port.count);
40502+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
40503 }
40504
40505 spin_unlock_irqrestore(&hvcsd->lock, flags);
40506@@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
40507
40508 spin_lock_irqsave(&hvcsd->lock, flags);
40509 /* Preserve this so that we know how many kref refs to put */
40510- temp_open_count = hvcsd->port.count;
40511+ temp_open_count = atomic_read(&hvcsd->port.count);
40512
40513 /*
40514 * Don't kref put inside the spinlock because the destruction
40515@@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
40516 tty->driver_data = NULL;
40517 hvcsd->port.tty = NULL;
40518
40519- hvcsd->port.count = 0;
40520+ atomic_set(&hvcsd->port.count, 0);
40521
40522 /* This will drop any buffered data on the floor which is OK in a hangup
40523 * scenario. */
40524@@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
40525 * the middle of a write operation? This is a crummy place to do this
40526 * but we want to keep it all in the spinlock.
40527 */
40528- if (hvcsd->port.count <= 0) {
40529+ if (atomic_read(&hvcsd->port.count) <= 0) {
40530 spin_unlock_irqrestore(&hvcsd->lock, flags);
40531 return -ENODEV;
40532 }
40533@@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
40534 {
40535 struct hvcs_struct *hvcsd = tty->driver_data;
40536
40537- if (!hvcsd || hvcsd->port.count <= 0)
40538+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
40539 return 0;
40540
40541 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
40542diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
40543index 2cde13d..645d78f 100644
40544--- a/drivers/tty/ipwireless/tty.c
40545+++ b/drivers/tty/ipwireless/tty.c
40546@@ -29,6 +29,7 @@
40547 #include <linux/tty_driver.h>
40548 #include <linux/tty_flip.h>
40549 #include <linux/uaccess.h>
40550+#include <asm/local.h>
40551
40552 #include "tty.h"
40553 #include "network.h"
40554@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
40555 mutex_unlock(&tty->ipw_tty_mutex);
40556 return -ENODEV;
40557 }
40558- if (tty->port.count == 0)
40559+ if (atomic_read(&tty->port.count) == 0)
40560 tty->tx_bytes_queued = 0;
40561
40562- tty->port.count++;
40563+ atomic_inc(&tty->port.count);
40564
40565 tty->port.tty = linux_tty;
40566 linux_tty->driver_data = tty;
40567@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
40568
40569 static void do_ipw_close(struct ipw_tty *tty)
40570 {
40571- tty->port.count--;
40572-
40573- if (tty->port.count == 0) {
40574+ if (atomic_dec_return(&tty->port.count) == 0) {
40575 struct tty_struct *linux_tty = tty->port.tty;
40576
40577 if (linux_tty != NULL) {
40578@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
40579 return;
40580
40581 mutex_lock(&tty->ipw_tty_mutex);
40582- if (tty->port.count == 0) {
40583+ if (atomic_read(&tty->port.count) == 0) {
40584 mutex_unlock(&tty->ipw_tty_mutex);
40585 return;
40586 }
40587@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
40588 return;
40589 }
40590
40591- if (!tty->port.count) {
40592+ if (!atomic_read(&tty->port.count)) {
40593 mutex_unlock(&tty->ipw_tty_mutex);
40594 return;
40595 }
40596@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
40597 return -ENODEV;
40598
40599 mutex_lock(&tty->ipw_tty_mutex);
40600- if (!tty->port.count) {
40601+ if (!atomic_read(&tty->port.count)) {
40602 mutex_unlock(&tty->ipw_tty_mutex);
40603 return -EINVAL;
40604 }
40605@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
40606 if (!tty)
40607 return -ENODEV;
40608
40609- if (!tty->port.count)
40610+ if (!atomic_read(&tty->port.count))
40611 return -EINVAL;
40612
40613 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
40614@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
40615 if (!tty)
40616 return 0;
40617
40618- if (!tty->port.count)
40619+ if (!atomic_read(&tty->port.count))
40620 return 0;
40621
40622 return tty->tx_bytes_queued;
40623@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
40624 if (!tty)
40625 return -ENODEV;
40626
40627- if (!tty->port.count)
40628+ if (!atomic_read(&tty->port.count))
40629 return -EINVAL;
40630
40631 return get_control_lines(tty);
40632@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
40633 if (!tty)
40634 return -ENODEV;
40635
40636- if (!tty->port.count)
40637+ if (!atomic_read(&tty->port.count))
40638 return -EINVAL;
40639
40640 return set_control_lines(tty, set, clear);
40641@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
40642 if (!tty)
40643 return -ENODEV;
40644
40645- if (!tty->port.count)
40646+ if (!atomic_read(&tty->port.count))
40647 return -EINVAL;
40648
40649 /* FIXME: Exactly how is the tty object locked here .. */
40650@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
40651 * are gone */
40652 mutex_lock(&ttyj->ipw_tty_mutex);
40653 }
40654- while (ttyj->port.count)
40655+ while (atomic_read(&ttyj->port.count))
40656 do_ipw_close(ttyj);
40657 ipwireless_disassociate_network_ttys(network,
40658 ttyj->channel_idx);
40659diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
40660index f9d2850..b006f04 100644
40661--- a/drivers/tty/moxa.c
40662+++ b/drivers/tty/moxa.c
40663@@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
40664 }
40665
40666 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
40667- ch->port.count++;
40668+ atomic_inc(&ch->port.count);
40669 tty->driver_data = ch;
40670 tty_port_tty_set(&ch->port, tty);
40671 mutex_lock(&ch->port.mutex);
40672diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
40673index dcc0430..040bef9 100644
40674--- a/drivers/tty/n_gsm.c
40675+++ b/drivers/tty/n_gsm.c
40676@@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
40677 spin_lock_init(&dlci->lock);
40678 mutex_init(&dlci->mutex);
40679 dlci->fifo = &dlci->_fifo;
40680- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
40681+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
40682 kfree(dlci);
40683 return NULL;
40684 }
40685@@ -2924,7 +2924,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
40686 struct gsm_dlci *dlci = tty->driver_data;
40687 struct tty_port *port = &dlci->port;
40688
40689- port->count++;
40690+ atomic_inc(&port->count);
40691 dlci_get(dlci);
40692 dlci_get(dlci->gsm->dlci[0]);
40693 mux_get(dlci->gsm);
40694diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
40695index 19083ef..6e34e97 100644
40696--- a/drivers/tty/n_tty.c
40697+++ b/drivers/tty/n_tty.c
40698@@ -2196,6 +2196,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
40699 {
40700 *ops = tty_ldisc_N_TTY;
40701 ops->owner = NULL;
40702- ops->refcount = ops->flags = 0;
40703+ atomic_set(&ops->refcount, 0);
40704+ ops->flags = 0;
40705 }
40706 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
40707diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
40708index 79ff3a5..1fe9399 100644
40709--- a/drivers/tty/pty.c
40710+++ b/drivers/tty/pty.c
40711@@ -791,8 +791,10 @@ static void __init unix98_pty_init(void)
40712 panic("Couldn't register Unix98 pts driver");
40713
40714 /* Now create the /dev/ptmx special device */
40715+ pax_open_kernel();
40716 tty_default_fops(&ptmx_fops);
40717- ptmx_fops.open = ptmx_open;
40718+ *(void **)&ptmx_fops.open = ptmx_open;
40719+ pax_close_kernel();
40720
40721 cdev_init(&ptmx_cdev, &ptmx_fops);
40722 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
40723diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
40724index e42009a..566a036 100644
40725--- a/drivers/tty/rocket.c
40726+++ b/drivers/tty/rocket.c
40727@@ -925,7 +925,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
40728 tty->driver_data = info;
40729 tty_port_tty_set(port, tty);
40730
40731- if (port->count++ == 0) {
40732+ if (atomic_inc_return(&port->count) == 1) {
40733 atomic_inc(&rp_num_ports_open);
40734
40735 #ifdef ROCKET_DEBUG_OPEN
40736@@ -934,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
40737 #endif
40738 }
40739 #ifdef ROCKET_DEBUG_OPEN
40740- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
40741+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
40742 #endif
40743
40744 /*
40745@@ -1529,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
40746 spin_unlock_irqrestore(&info->port.lock, flags);
40747 return;
40748 }
40749- if (info->port.count)
40750+ if (atomic_read(&info->port.count))
40751 atomic_dec(&rp_num_ports_open);
40752 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
40753 spin_unlock_irqrestore(&info->port.lock, flags);
40754diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
40755index 1002054..dd644a8 100644
40756--- a/drivers/tty/serial/kgdboc.c
40757+++ b/drivers/tty/serial/kgdboc.c
40758@@ -24,8 +24,9 @@
40759 #define MAX_CONFIG_LEN 40
40760
40761 static struct kgdb_io kgdboc_io_ops;
40762+static struct kgdb_io kgdboc_io_ops_console;
40763
40764-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
40765+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
40766 static int configured = -1;
40767
40768 static char config[MAX_CONFIG_LEN];
40769@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
40770 kgdboc_unregister_kbd();
40771 if (configured == 1)
40772 kgdb_unregister_io_module(&kgdboc_io_ops);
40773+ else if (configured == 2)
40774+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
40775 }
40776
40777 static int configure_kgdboc(void)
40778@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
40779 int err;
40780 char *cptr = config;
40781 struct console *cons;
40782+ int is_console = 0;
40783
40784 err = kgdboc_option_setup(config);
40785 if (err || !strlen(config) || isspace(config[0]))
40786 goto noconfig;
40787
40788 err = -ENODEV;
40789- kgdboc_io_ops.is_console = 0;
40790 kgdb_tty_driver = NULL;
40791
40792 kgdboc_use_kms = 0;
40793@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
40794 int idx;
40795 if (cons->device && cons->device(cons, &idx) == p &&
40796 idx == tty_line) {
40797- kgdboc_io_ops.is_console = 1;
40798+ is_console = 1;
40799 break;
40800 }
40801 cons = cons->next;
40802@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
40803 kgdb_tty_line = tty_line;
40804
40805 do_register:
40806- err = kgdb_register_io_module(&kgdboc_io_ops);
40807+ if (is_console) {
40808+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
40809+ configured = 2;
40810+ } else {
40811+ err = kgdb_register_io_module(&kgdboc_io_ops);
40812+ configured = 1;
40813+ }
40814 if (err)
40815 goto noconfig;
40816
40817@@ -205,8 +214,6 @@ do_register:
40818 if (err)
40819 goto nmi_con_failed;
40820
40821- configured = 1;
40822-
40823 return 0;
40824
40825 nmi_con_failed:
40826@@ -223,7 +230,7 @@ noconfig:
40827 static int __init init_kgdboc(void)
40828 {
40829 /* Already configured? */
40830- if (configured == 1)
40831+ if (configured >= 1)
40832 return 0;
40833
40834 return configure_kgdboc();
40835@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
40836 if (config[len - 1] == '\n')
40837 config[len - 1] = '\0';
40838
40839- if (configured == 1)
40840+ if (configured >= 1)
40841 cleanup_kgdboc();
40842
40843 /* Go and configure with the new params. */
40844@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
40845 .post_exception = kgdboc_post_exp_handler,
40846 };
40847
40848+static struct kgdb_io kgdboc_io_ops_console = {
40849+ .name = "kgdboc",
40850+ .read_char = kgdboc_get_char,
40851+ .write_char = kgdboc_put_char,
40852+ .pre_exception = kgdboc_pre_exp_handler,
40853+ .post_exception = kgdboc_post_exp_handler,
40854+ .is_console = 1
40855+};
40856+
40857 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
40858 /* This is only available if kgdboc is a built in for early debugging */
40859 static int __init kgdboc_early_init(char *opt)
40860diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
40861index e514b3a..c73d614 100644
40862--- a/drivers/tty/serial/samsung.c
40863+++ b/drivers/tty/serial/samsung.c
40864@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
40865 }
40866 }
40867
40868+static int s3c64xx_serial_startup(struct uart_port *port);
40869 static int s3c24xx_serial_startup(struct uart_port *port)
40870 {
40871 struct s3c24xx_uart_port *ourport = to_ourport(port);
40872 int ret;
40873
40874+ /* Startup sequence is different for s3c64xx and higher SoC's */
40875+ if (s3c24xx_serial_has_interrupt_mask(port))
40876+ return s3c64xx_serial_startup(port);
40877+
40878 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
40879 port->mapbase, port->membase);
40880
40881@@ -1122,10 +1127,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
40882 /* setup info for port */
40883 port->dev = &platdev->dev;
40884
40885- /* Startup sequence is different for s3c64xx and higher SoC's */
40886- if (s3c24xx_serial_has_interrupt_mask(port))
40887- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
40888-
40889 port->uartclk = 1;
40890
40891 if (cfg->uart_flags & UPF_CONS_FLOW) {
40892diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
40893index 2c7230a..2104f16 100644
40894--- a/drivers/tty/serial/serial_core.c
40895+++ b/drivers/tty/serial/serial_core.c
40896@@ -1455,7 +1455,7 @@ static void uart_hangup(struct tty_struct *tty)
40897 uart_flush_buffer(tty);
40898 uart_shutdown(tty, state);
40899 spin_lock_irqsave(&port->lock, flags);
40900- port->count = 0;
40901+ atomic_set(&port->count, 0);
40902 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
40903 spin_unlock_irqrestore(&port->lock, flags);
40904 tty_port_tty_set(port, NULL);
40905@@ -1551,7 +1551,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40906 goto end;
40907 }
40908
40909- port->count++;
40910+ atomic_inc(&port->count);
40911 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
40912 retval = -ENXIO;
40913 goto err_dec_count;
40914@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40915 /*
40916 * Make sure the device is in D0 state.
40917 */
40918- if (port->count == 1)
40919+ if (atomic_read(&port->count) == 1)
40920 uart_change_pm(state, 0);
40921
40922 /*
40923@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40924 end:
40925 return retval;
40926 err_dec_count:
40927- port->count--;
40928+ atomic_inc(&port->count);
40929 mutex_unlock(&port->mutex);
40930 goto end;
40931 }
40932diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
40933index 9e071f6..f30ae69 100644
40934--- a/drivers/tty/synclink.c
40935+++ b/drivers/tty/synclink.c
40936@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40937
40938 if (debug_level >= DEBUG_LEVEL_INFO)
40939 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
40940- __FILE__,__LINE__, info->device_name, info->port.count);
40941+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40942
40943 if (tty_port_close_start(&info->port, tty, filp) == 0)
40944 goto cleanup;
40945@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40946 cleanup:
40947 if (debug_level >= DEBUG_LEVEL_INFO)
40948 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
40949- tty->driver->name, info->port.count);
40950+ tty->driver->name, atomic_read(&info->port.count));
40951
40952 } /* end of mgsl_close() */
40953
40954@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
40955
40956 mgsl_flush_buffer(tty);
40957 shutdown(info);
40958-
40959- info->port.count = 0;
40960+
40961+ atomic_set(&info->port.count, 0);
40962 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40963 info->port.tty = NULL;
40964
40965@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40966
40967 if (debug_level >= DEBUG_LEVEL_INFO)
40968 printk("%s(%d):block_til_ready before block on %s count=%d\n",
40969- __FILE__,__LINE__, tty->driver->name, port->count );
40970+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40971
40972 spin_lock_irqsave(&info->irq_spinlock, flags);
40973 if (!tty_hung_up_p(filp)) {
40974 extra_count = true;
40975- port->count--;
40976+ atomic_dec(&port->count);
40977 }
40978 spin_unlock_irqrestore(&info->irq_spinlock, flags);
40979 port->blocked_open++;
40980@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40981
40982 if (debug_level >= DEBUG_LEVEL_INFO)
40983 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
40984- __FILE__,__LINE__, tty->driver->name, port->count );
40985+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40986
40987 tty_unlock(tty);
40988 schedule();
40989@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40990
40991 /* FIXME: Racy on hangup during close wait */
40992 if (extra_count)
40993- port->count++;
40994+ atomic_inc(&port->count);
40995 port->blocked_open--;
40996
40997 if (debug_level >= DEBUG_LEVEL_INFO)
40998 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
40999- __FILE__,__LINE__, tty->driver->name, port->count );
41000+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41001
41002 if (!retval)
41003 port->flags |= ASYNC_NORMAL_ACTIVE;
41004@@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
41005
41006 if (debug_level >= DEBUG_LEVEL_INFO)
41007 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
41008- __FILE__,__LINE__,tty->driver->name, info->port.count);
41009+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
41010
41011 /* If port is closing, signal caller to try again */
41012 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
41013@@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
41014 spin_unlock_irqrestore(&info->netlock, flags);
41015 goto cleanup;
41016 }
41017- info->port.count++;
41018+ atomic_inc(&info->port.count);
41019 spin_unlock_irqrestore(&info->netlock, flags);
41020
41021- if (info->port.count == 1) {
41022+ if (atomic_read(&info->port.count) == 1) {
41023 /* 1st open on this device, init hardware */
41024 retval = startup(info);
41025 if (retval < 0)
41026@@ -3451,8 +3451,8 @@ cleanup:
41027 if (retval) {
41028 if (tty->count == 1)
41029 info->port.tty = NULL; /* tty layer will release tty struct */
41030- if(info->port.count)
41031- info->port.count--;
41032+ if (atomic_read(&info->port.count))
41033+ atomic_dec(&info->port.count);
41034 }
41035
41036 return retval;
41037@@ -7662,7 +7662,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
41038 unsigned short new_crctype;
41039
41040 /* return error if TTY interface open */
41041- if (info->port.count)
41042+ if (atomic_read(&info->port.count))
41043 return -EBUSY;
41044
41045 switch (encoding)
41046@@ -7757,7 +7757,7 @@ static int hdlcdev_open(struct net_device *dev)
41047
41048 /* arbitrate between network and tty opens */
41049 spin_lock_irqsave(&info->netlock, flags);
41050- if (info->port.count != 0 || info->netcount != 0) {
41051+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
41052 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
41053 spin_unlock_irqrestore(&info->netlock, flags);
41054 return -EBUSY;
41055@@ -7843,7 +7843,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
41056 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
41057
41058 /* return error if TTY interface open */
41059- if (info->port.count)
41060+ if (atomic_read(&info->port.count))
41061 return -EBUSY;
41062
41063 if (cmd != SIOCWANDEV)
41064diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
41065index aba1e59..877ac33 100644
41066--- a/drivers/tty/synclink_gt.c
41067+++ b/drivers/tty/synclink_gt.c
41068@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
41069 tty->driver_data = info;
41070 info->port.tty = tty;
41071
41072- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
41073+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
41074
41075 /* If port is closing, signal caller to try again */
41076 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
41077@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
41078 mutex_unlock(&info->port.mutex);
41079 goto cleanup;
41080 }
41081- info->port.count++;
41082+ atomic_inc(&info->port.count);
41083 spin_unlock_irqrestore(&info->netlock, flags);
41084
41085- if (info->port.count == 1) {
41086+ if (atomic_read(&info->port.count) == 1) {
41087 /* 1st open on this device, init hardware */
41088 retval = startup(info);
41089 if (retval < 0) {
41090@@ -716,8 +716,8 @@ cleanup:
41091 if (retval) {
41092 if (tty->count == 1)
41093 info->port.tty = NULL; /* tty layer will release tty struct */
41094- if(info->port.count)
41095- info->port.count--;
41096+ if(atomic_read(&info->port.count))
41097+ atomic_dec(&info->port.count);
41098 }
41099
41100 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
41101@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41102
41103 if (sanity_check(info, tty->name, "close"))
41104 return;
41105- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
41106+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
41107
41108 if (tty_port_close_start(&info->port, tty, filp) == 0)
41109 goto cleanup;
41110@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41111 tty_port_close_end(&info->port, tty);
41112 info->port.tty = NULL;
41113 cleanup:
41114- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
41115+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
41116 }
41117
41118 static void hangup(struct tty_struct *tty)
41119@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
41120 shutdown(info);
41121
41122 spin_lock_irqsave(&info->port.lock, flags);
41123- info->port.count = 0;
41124+ atomic_set(&info->port.count, 0);
41125 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
41126 info->port.tty = NULL;
41127 spin_unlock_irqrestore(&info->port.lock, flags);
41128@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
41129 unsigned short new_crctype;
41130
41131 /* return error if TTY interface open */
41132- if (info->port.count)
41133+ if (atomic_read(&info->port.count))
41134 return -EBUSY;
41135
41136 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
41137@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
41138
41139 /* arbitrate between network and tty opens */
41140 spin_lock_irqsave(&info->netlock, flags);
41141- if (info->port.count != 0 || info->netcount != 0) {
41142+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
41143 DBGINFO(("%s hdlc_open busy\n", dev->name));
41144 spin_unlock_irqrestore(&info->netlock, flags);
41145 return -EBUSY;
41146@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
41147 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
41148
41149 /* return error if TTY interface open */
41150- if (info->port.count)
41151+ if (atomic_read(&info->port.count))
41152 return -EBUSY;
41153
41154 if (cmd != SIOCWANDEV)
41155@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
41156 if (port == NULL)
41157 continue;
41158 spin_lock(&port->lock);
41159- if ((port->port.count || port->netcount) &&
41160+ if ((atomic_read(&port->port.count) || port->netcount) &&
41161 port->pending_bh && !port->bh_running &&
41162 !port->bh_requested) {
41163 DBGISR(("%s bh queued\n", port->device_name));
41164@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41165 spin_lock_irqsave(&info->lock, flags);
41166 if (!tty_hung_up_p(filp)) {
41167 extra_count = true;
41168- port->count--;
41169+ atomic_dec(&port->count);
41170 }
41171 spin_unlock_irqrestore(&info->lock, flags);
41172 port->blocked_open++;
41173@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41174 remove_wait_queue(&port->open_wait, &wait);
41175
41176 if (extra_count)
41177- port->count++;
41178+ atomic_inc(&port->count);
41179 port->blocked_open--;
41180
41181 if (!retval)
41182diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
41183index fd43fb6..34704ad 100644
41184--- a/drivers/tty/synclinkmp.c
41185+++ b/drivers/tty/synclinkmp.c
41186@@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
41187
41188 if (debug_level >= DEBUG_LEVEL_INFO)
41189 printk("%s(%d):%s open(), old ref count = %d\n",
41190- __FILE__,__LINE__,tty->driver->name, info->port.count);
41191+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
41192
41193 /* If port is closing, signal caller to try again */
41194 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
41195@@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
41196 spin_unlock_irqrestore(&info->netlock, flags);
41197 goto cleanup;
41198 }
41199- info->port.count++;
41200+ atomic_inc(&info->port.count);
41201 spin_unlock_irqrestore(&info->netlock, flags);
41202
41203- if (info->port.count == 1) {
41204+ if (atomic_read(&info->port.count) == 1) {
41205 /* 1st open on this device, init hardware */
41206 retval = startup(info);
41207 if (retval < 0)
41208@@ -797,8 +797,8 @@ cleanup:
41209 if (retval) {
41210 if (tty->count == 1)
41211 info->port.tty = NULL; /* tty layer will release tty struct */
41212- if(info->port.count)
41213- info->port.count--;
41214+ if(atomic_read(&info->port.count))
41215+ atomic_dec(&info->port.count);
41216 }
41217
41218 return retval;
41219@@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41220
41221 if (debug_level >= DEBUG_LEVEL_INFO)
41222 printk("%s(%d):%s close() entry, count=%d\n",
41223- __FILE__,__LINE__, info->device_name, info->port.count);
41224+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
41225
41226 if (tty_port_close_start(&info->port, tty, filp) == 0)
41227 goto cleanup;
41228@@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41229 cleanup:
41230 if (debug_level >= DEBUG_LEVEL_INFO)
41231 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
41232- tty->driver->name, info->port.count);
41233+ tty->driver->name, atomic_read(&info->port.count));
41234 }
41235
41236 /* Called by tty_hangup() when a hangup is signaled.
41237@@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
41238 shutdown(info);
41239
41240 spin_lock_irqsave(&info->port.lock, flags);
41241- info->port.count = 0;
41242+ atomic_set(&info->port.count, 0);
41243 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
41244 info->port.tty = NULL;
41245 spin_unlock_irqrestore(&info->port.lock, flags);
41246@@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
41247 unsigned short new_crctype;
41248
41249 /* return error if TTY interface open */
41250- if (info->port.count)
41251+ if (atomic_read(&info->port.count))
41252 return -EBUSY;
41253
41254 switch (encoding)
41255@@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
41256
41257 /* arbitrate between network and tty opens */
41258 spin_lock_irqsave(&info->netlock, flags);
41259- if (info->port.count != 0 || info->netcount != 0) {
41260+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
41261 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
41262 spin_unlock_irqrestore(&info->netlock, flags);
41263 return -EBUSY;
41264@@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
41265 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
41266
41267 /* return error if TTY interface open */
41268- if (info->port.count)
41269+ if (atomic_read(&info->port.count))
41270 return -EBUSY;
41271
41272 if (cmd != SIOCWANDEV)
41273@@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
41274 * do not request bottom half processing if the
41275 * device is not open in a normal mode.
41276 */
41277- if ( port && (port->port.count || port->netcount) &&
41278+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
41279 port->pending_bh && !port->bh_running &&
41280 !port->bh_requested ) {
41281 if ( debug_level >= DEBUG_LEVEL_ISR )
41282@@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41283
41284 if (debug_level >= DEBUG_LEVEL_INFO)
41285 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
41286- __FILE__,__LINE__, tty->driver->name, port->count );
41287+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41288
41289 spin_lock_irqsave(&info->lock, flags);
41290 if (!tty_hung_up_p(filp)) {
41291 extra_count = true;
41292- port->count--;
41293+ atomic_dec(&port->count);
41294 }
41295 spin_unlock_irqrestore(&info->lock, flags);
41296 port->blocked_open++;
41297@@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41298
41299 if (debug_level >= DEBUG_LEVEL_INFO)
41300 printk("%s(%d):%s block_til_ready() count=%d\n",
41301- __FILE__,__LINE__, tty->driver->name, port->count );
41302+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41303
41304 tty_unlock(tty);
41305 schedule();
41306@@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41307 remove_wait_queue(&port->open_wait, &wait);
41308
41309 if (extra_count)
41310- port->count++;
41311+ atomic_inc(&port->count);
41312 port->blocked_open--;
41313
41314 if (debug_level >= DEBUG_LEVEL_INFO)
41315 printk("%s(%d):%s block_til_ready() after, count=%d\n",
41316- __FILE__,__LINE__, tty->driver->name, port->count );
41317+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41318
41319 if (!retval)
41320 port->flags |= ASYNC_NORMAL_ACTIVE;
41321diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
41322index b3c4a25..723916f 100644
41323--- a/drivers/tty/sysrq.c
41324+++ b/drivers/tty/sysrq.c
41325@@ -867,7 +867,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
41326 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
41327 size_t count, loff_t *ppos)
41328 {
41329- if (count) {
41330+ if (count && capable(CAP_SYS_ADMIN)) {
41331 char c;
41332
41333 if (get_user(c, buf))
41334diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
41335index da9fde8..c07975f 100644
41336--- a/drivers/tty/tty_io.c
41337+++ b/drivers/tty/tty_io.c
41338@@ -3391,7 +3391,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
41339
41340 void tty_default_fops(struct file_operations *fops)
41341 {
41342- *fops = tty_fops;
41343+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
41344 }
41345
41346 /*
41347diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
41348index c578229..45aa9ee 100644
41349--- a/drivers/tty/tty_ldisc.c
41350+++ b/drivers/tty/tty_ldisc.c
41351@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
41352 if (atomic_dec_and_test(&ld->users)) {
41353 struct tty_ldisc_ops *ldo = ld->ops;
41354
41355- ldo->refcount--;
41356+ atomic_dec(&ldo->refcount);
41357 module_put(ldo->owner);
41358 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41359
41360@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
41361 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
41362 tty_ldiscs[disc] = new_ldisc;
41363 new_ldisc->num = disc;
41364- new_ldisc->refcount = 0;
41365+ atomic_set(&new_ldisc->refcount, 0);
41366 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41367
41368 return ret;
41369@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
41370 return -EINVAL;
41371
41372 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
41373- if (tty_ldiscs[disc]->refcount)
41374+ if (atomic_read(&tty_ldiscs[disc]->refcount))
41375 ret = -EBUSY;
41376 else
41377 tty_ldiscs[disc] = NULL;
41378@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
41379 if (ldops) {
41380 ret = ERR_PTR(-EAGAIN);
41381 if (try_module_get(ldops->owner)) {
41382- ldops->refcount++;
41383+ atomic_inc(&ldops->refcount);
41384 ret = ldops;
41385 }
41386 }
41387@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
41388 unsigned long flags;
41389
41390 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
41391- ldops->refcount--;
41392+ atomic_dec(&ldops->refcount);
41393 module_put(ldops->owner);
41394 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41395 }
41396diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
41397index b7ff59d..7c6105e 100644
41398--- a/drivers/tty/tty_port.c
41399+++ b/drivers/tty/tty_port.c
41400@@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
41401 unsigned long flags;
41402
41403 spin_lock_irqsave(&port->lock, flags);
41404- port->count = 0;
41405+ atomic_set(&port->count, 0);
41406 port->flags &= ~ASYNC_NORMAL_ACTIVE;
41407 if (port->tty) {
41408 set_bit(TTY_IO_ERROR, &port->tty->flags);
41409@@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
41410 /* The port lock protects the port counts */
41411 spin_lock_irqsave(&port->lock, flags);
41412 if (!tty_hung_up_p(filp))
41413- port->count--;
41414+ atomic_dec(&port->count);
41415 port->blocked_open++;
41416 spin_unlock_irqrestore(&port->lock, flags);
41417
41418@@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
41419 we must not mess that up further */
41420 spin_lock_irqsave(&port->lock, flags);
41421 if (!tty_hung_up_p(filp))
41422- port->count++;
41423+ atomic_inc(&port->count);
41424 port->blocked_open--;
41425 if (retval == 0)
41426 port->flags |= ASYNC_NORMAL_ACTIVE;
41427@@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
41428 return 0;
41429 }
41430
41431- if (tty->count == 1 && port->count != 1) {
41432+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
41433 printk(KERN_WARNING
41434 "tty_port_close_start: tty->count = 1 port count = %d.\n",
41435- port->count);
41436- port->count = 1;
41437+ atomic_read(&port->count));
41438+ atomic_set(&port->count, 1);
41439 }
41440- if (--port->count < 0) {
41441+ if (atomic_dec_return(&port->count) < 0) {
41442 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
41443- port->count);
41444- port->count = 0;
41445+ atomic_read(&port->count));
41446+ atomic_set(&port->count, 0);
41447 }
41448
41449- if (port->count) {
41450+ if (atomic_read(&port->count)) {
41451 spin_unlock_irqrestore(&port->lock, flags);
41452 if (port->ops->drop)
41453 port->ops->drop(port);
41454@@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
41455 {
41456 spin_lock_irq(&port->lock);
41457 if (!tty_hung_up_p(filp))
41458- ++port->count;
41459+ atomic_inc(&port->count);
41460 spin_unlock_irq(&port->lock);
41461 tty_port_tty_set(port, tty);
41462
41463diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
41464index 681765b..d3ccdf2 100644
41465--- a/drivers/tty/vt/keyboard.c
41466+++ b/drivers/tty/vt/keyboard.c
41467@@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
41468 kbd->kbdmode == VC_OFF) &&
41469 value != KVAL(K_SAK))
41470 return; /* SAK is allowed even in raw mode */
41471+
41472+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
41473+ {
41474+ void *func = fn_handler[value];
41475+ if (func == fn_show_state || func == fn_show_ptregs ||
41476+ func == fn_show_mem)
41477+ return;
41478+ }
41479+#endif
41480+
41481 fn_handler[value](vc);
41482 }
41483
41484@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
41485 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
41486 return -EFAULT;
41487
41488- if (!capable(CAP_SYS_TTY_CONFIG))
41489- perm = 0;
41490-
41491 switch (cmd) {
41492 case KDGKBENT:
41493 /* Ensure another thread doesn't free it under us */
41494@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
41495 spin_unlock_irqrestore(&kbd_event_lock, flags);
41496 return put_user(val, &user_kbe->kb_value);
41497 case KDSKBENT:
41498+ if (!capable(CAP_SYS_TTY_CONFIG))
41499+ perm = 0;
41500+
41501 if (!perm)
41502 return -EPERM;
41503 if (!i && v == K_NOSUCHMAP) {
41504@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
41505 int i, j, k;
41506 int ret;
41507
41508- if (!capable(CAP_SYS_TTY_CONFIG))
41509- perm = 0;
41510-
41511 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
41512 if (!kbs) {
41513 ret = -ENOMEM;
41514@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
41515 kfree(kbs);
41516 return ((p && *p) ? -EOVERFLOW : 0);
41517 case KDSKBSENT:
41518+ if (!capable(CAP_SYS_TTY_CONFIG))
41519+ perm = 0;
41520+
41521 if (!perm) {
41522 ret = -EPERM;
41523 goto reterr;
41524diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
41525index 8fd8968..3614c9c 100644
41526--- a/drivers/tty/vt/vt.c
41527+++ b/drivers/tty/vt/vt.c
41528@@ -539,7 +539,7 @@ static void insert_char(struct vc_data *vc, unsigned int nr)
41529 {
41530 unsigned short *p = (unsigned short *) vc->vc_pos;
41531
41532- scr_memmovew(p + nr, p, (vc->vc_cols - vc->vc_x) * 2);
41533+ scr_memmovew(p + nr, p, (vc->vc_cols - vc->vc_x - nr) * 2);
41534 scr_memsetw(p, vc->vc_video_erase_char, nr * 2);
41535 vc->vc_need_wrap = 0;
41536 if (DO_UPDATE(vc))
41537diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
41538index 5110f36..8dc0a74 100644
41539--- a/drivers/uio/uio.c
41540+++ b/drivers/uio/uio.c
41541@@ -25,6 +25,7 @@
41542 #include <linux/kobject.h>
41543 #include <linux/cdev.h>
41544 #include <linux/uio_driver.h>
41545+#include <asm/local.h>
41546
41547 #define UIO_MAX_DEVICES (1U << MINORBITS)
41548
41549@@ -32,10 +33,10 @@ struct uio_device {
41550 struct module *owner;
41551 struct device *dev;
41552 int minor;
41553- atomic_t event;
41554+ atomic_unchecked_t event;
41555 struct fasync_struct *async_queue;
41556 wait_queue_head_t wait;
41557- int vma_count;
41558+ local_t vma_count;
41559 struct uio_info *info;
41560 struct kobject *map_dir;
41561 struct kobject *portio_dir;
41562@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
41563 struct device_attribute *attr, char *buf)
41564 {
41565 struct uio_device *idev = dev_get_drvdata(dev);
41566- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
41567+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
41568 }
41569
41570 static struct device_attribute uio_class_attributes[] = {
41571@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
41572 {
41573 struct uio_device *idev = info->uio_dev;
41574
41575- atomic_inc(&idev->event);
41576+ atomic_inc_unchecked(&idev->event);
41577 wake_up_interruptible(&idev->wait);
41578 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
41579 }
41580@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
41581 }
41582
41583 listener->dev = idev;
41584- listener->event_count = atomic_read(&idev->event);
41585+ listener->event_count = atomic_read_unchecked(&idev->event);
41586 filep->private_data = listener;
41587
41588 if (idev->info->open) {
41589@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
41590 return -EIO;
41591
41592 poll_wait(filep, &idev->wait, wait);
41593- if (listener->event_count != atomic_read(&idev->event))
41594+ if (listener->event_count != atomic_read_unchecked(&idev->event))
41595 return POLLIN | POLLRDNORM;
41596 return 0;
41597 }
41598@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
41599 do {
41600 set_current_state(TASK_INTERRUPTIBLE);
41601
41602- event_count = atomic_read(&idev->event);
41603+ event_count = atomic_read_unchecked(&idev->event);
41604 if (event_count != listener->event_count) {
41605 if (copy_to_user(buf, &event_count, count))
41606 retval = -EFAULT;
41607@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
41608 static void uio_vma_open(struct vm_area_struct *vma)
41609 {
41610 struct uio_device *idev = vma->vm_private_data;
41611- idev->vma_count++;
41612+ local_inc(&idev->vma_count);
41613 }
41614
41615 static void uio_vma_close(struct vm_area_struct *vma)
41616 {
41617 struct uio_device *idev = vma->vm_private_data;
41618- idev->vma_count--;
41619+ local_dec(&idev->vma_count);
41620 }
41621
41622 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41623@@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
41624 idev->owner = owner;
41625 idev->info = info;
41626 init_waitqueue_head(&idev->wait);
41627- atomic_set(&idev->event, 0);
41628+ atomic_set_unchecked(&idev->event, 0);
41629
41630 ret = uio_get_minor(idev);
41631 if (ret)
41632diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
41633index b7eb86a..36d28af 100644
41634--- a/drivers/usb/atm/cxacru.c
41635+++ b/drivers/usb/atm/cxacru.c
41636@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
41637 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
41638 if (ret < 2)
41639 return -EINVAL;
41640- if (index < 0 || index > 0x7f)
41641+ if (index > 0x7f)
41642 return -EINVAL;
41643 pos += tmp;
41644
41645diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
41646index 35f10bf..6a38a0b 100644
41647--- a/drivers/usb/atm/usbatm.c
41648+++ b/drivers/usb/atm/usbatm.c
41649@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41650 if (printk_ratelimit())
41651 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
41652 __func__, vpi, vci);
41653- atomic_inc(&vcc->stats->rx_err);
41654+ atomic_inc_unchecked(&vcc->stats->rx_err);
41655 return;
41656 }
41657
41658@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41659 if (length > ATM_MAX_AAL5_PDU) {
41660 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
41661 __func__, length, vcc);
41662- atomic_inc(&vcc->stats->rx_err);
41663+ atomic_inc_unchecked(&vcc->stats->rx_err);
41664 goto out;
41665 }
41666
41667@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41668 if (sarb->len < pdu_length) {
41669 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
41670 __func__, pdu_length, sarb->len, vcc);
41671- atomic_inc(&vcc->stats->rx_err);
41672+ atomic_inc_unchecked(&vcc->stats->rx_err);
41673 goto out;
41674 }
41675
41676 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
41677 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
41678 __func__, vcc);
41679- atomic_inc(&vcc->stats->rx_err);
41680+ atomic_inc_unchecked(&vcc->stats->rx_err);
41681 goto out;
41682 }
41683
41684@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41685 if (printk_ratelimit())
41686 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
41687 __func__, length);
41688- atomic_inc(&vcc->stats->rx_drop);
41689+ atomic_inc_unchecked(&vcc->stats->rx_drop);
41690 goto out;
41691 }
41692
41693@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41694
41695 vcc->push(vcc, skb);
41696
41697- atomic_inc(&vcc->stats->rx);
41698+ atomic_inc_unchecked(&vcc->stats->rx);
41699 out:
41700 skb_trim(sarb, 0);
41701 }
41702@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
41703 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
41704
41705 usbatm_pop(vcc, skb);
41706- atomic_inc(&vcc->stats->tx);
41707+ atomic_inc_unchecked(&vcc->stats->tx);
41708
41709 skb = skb_dequeue(&instance->sndqueue);
41710 }
41711@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
41712 if (!left--)
41713 return sprintf(page,
41714 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
41715- atomic_read(&atm_dev->stats.aal5.tx),
41716- atomic_read(&atm_dev->stats.aal5.tx_err),
41717- atomic_read(&atm_dev->stats.aal5.rx),
41718- atomic_read(&atm_dev->stats.aal5.rx_err),
41719- atomic_read(&atm_dev->stats.aal5.rx_drop));
41720+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
41721+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
41722+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
41723+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
41724+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
41725
41726 if (!left--) {
41727 if (instance->disconnected)
41728diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
41729index cbacea9..246cccd 100644
41730--- a/drivers/usb/core/devices.c
41731+++ b/drivers/usb/core/devices.c
41732@@ -126,7 +126,7 @@ static const char format_endpt[] =
41733 * time it gets called.
41734 */
41735 static struct device_connect_event {
41736- atomic_t count;
41737+ atomic_unchecked_t count;
41738 wait_queue_head_t wait;
41739 } device_event = {
41740 .count = ATOMIC_INIT(1),
41741@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
41742
41743 void usbfs_conn_disc_event(void)
41744 {
41745- atomic_add(2, &device_event.count);
41746+ atomic_add_unchecked(2, &device_event.count);
41747 wake_up(&device_event.wait);
41748 }
41749
41750@@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
41751
41752 poll_wait(file, &device_event.wait, wait);
41753
41754- event_count = atomic_read(&device_event.count);
41755+ event_count = atomic_read_unchecked(&device_event.count);
41756 if (file->f_version != event_count) {
41757 file->f_version = event_count;
41758 return POLLIN | POLLRDNORM;
41759diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
41760index 8e64adf..9a33a3c 100644
41761--- a/drivers/usb/core/hcd.c
41762+++ b/drivers/usb/core/hcd.c
41763@@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41764 */
41765 usb_get_urb(urb);
41766 atomic_inc(&urb->use_count);
41767- atomic_inc(&urb->dev->urbnum);
41768+ atomic_inc_unchecked(&urb->dev->urbnum);
41769 usbmon_urb_submit(&hcd->self, urb);
41770
41771 /* NOTE requirements on root-hub callers (usbfs and the hub
41772@@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41773 urb->hcpriv = NULL;
41774 INIT_LIST_HEAD(&urb->urb_list);
41775 atomic_dec(&urb->use_count);
41776- atomic_dec(&urb->dev->urbnum);
41777+ atomic_dec_unchecked(&urb->dev->urbnum);
41778 if (atomic_read(&urb->reject))
41779 wake_up(&usb_kill_urb_queue);
41780 usb_put_urb(urb);
41781diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
41782index 818e4a0..0fc9589 100644
41783--- a/drivers/usb/core/sysfs.c
41784+++ b/drivers/usb/core/sysfs.c
41785@@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
41786 struct usb_device *udev;
41787
41788 udev = to_usb_device(dev);
41789- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
41790+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
41791 }
41792 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
41793
41794diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
41795index f81b925..78d22ec 100644
41796--- a/drivers/usb/core/usb.c
41797+++ b/drivers/usb/core/usb.c
41798@@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
41799 set_dev_node(&dev->dev, dev_to_node(bus->controller));
41800 dev->state = USB_STATE_ATTACHED;
41801 dev->lpm_disable_count = 1;
41802- atomic_set(&dev->urbnum, 0);
41803+ atomic_set_unchecked(&dev->urbnum, 0);
41804
41805 INIT_LIST_HEAD(&dev->ep0.urb_list);
41806 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
41807diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
41808index 5e29dde..eca992f 100644
41809--- a/drivers/usb/early/ehci-dbgp.c
41810+++ b/drivers/usb/early/ehci-dbgp.c
41811@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
41812
41813 #ifdef CONFIG_KGDB
41814 static struct kgdb_io kgdbdbgp_io_ops;
41815-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
41816+static struct kgdb_io kgdbdbgp_io_ops_console;
41817+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
41818 #else
41819 #define dbgp_kgdb_mode (0)
41820 #endif
41821@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
41822 .write_char = kgdbdbgp_write_char,
41823 };
41824
41825+static struct kgdb_io kgdbdbgp_io_ops_console = {
41826+ .name = "kgdbdbgp",
41827+ .read_char = kgdbdbgp_read_char,
41828+ .write_char = kgdbdbgp_write_char,
41829+ .is_console = 1
41830+};
41831+
41832 static int kgdbdbgp_wait_time;
41833
41834 static int __init kgdbdbgp_parse_config(char *str)
41835@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
41836 ptr++;
41837 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
41838 }
41839- kgdb_register_io_module(&kgdbdbgp_io_ops);
41840- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
41841+ if (early_dbgp_console.index != -1)
41842+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
41843+ else
41844+ kgdb_register_io_module(&kgdbdbgp_io_ops);
41845
41846 return 0;
41847 }
41848diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
41849index 598dcc1..032dd4f 100644
41850--- a/drivers/usb/gadget/u_serial.c
41851+++ b/drivers/usb/gadget/u_serial.c
41852@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41853 spin_lock_irq(&port->port_lock);
41854
41855 /* already open? Great. */
41856- if (port->port.count) {
41857+ if (atomic_read(&port->port.count)) {
41858 status = 0;
41859- port->port.count++;
41860+ atomic_inc(&port->port.count);
41861
41862 /* currently opening/closing? wait ... */
41863 } else if (port->openclose) {
41864@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41865 tty->driver_data = port;
41866 port->port.tty = tty;
41867
41868- port->port.count = 1;
41869+ atomic_set(&port->port.count, 1);
41870 port->openclose = false;
41871
41872 /* if connected, start the I/O stream */
41873@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41874
41875 spin_lock_irq(&port->port_lock);
41876
41877- if (port->port.count != 1) {
41878- if (port->port.count == 0)
41879+ if (atomic_read(&port->port.count) != 1) {
41880+ if (atomic_read(&port->port.count) == 0)
41881 WARN_ON(1);
41882 else
41883- --port->port.count;
41884+ atomic_dec(&port->port.count);
41885 goto exit;
41886 }
41887
41888@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41889 * and sleep if necessary
41890 */
41891 port->openclose = true;
41892- port->port.count = 0;
41893+ atomic_set(&port->port.count, 0);
41894
41895 gser = port->port_usb;
41896 if (gser && gser->disconnect)
41897@@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
41898 int cond;
41899
41900 spin_lock_irq(&port->port_lock);
41901- cond = (port->port.count == 0) && !port->openclose;
41902+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
41903 spin_unlock_irq(&port->port_lock);
41904 return cond;
41905 }
41906@@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
41907 /* if it's already open, start I/O ... and notify the serial
41908 * protocol about open/close status (connect/disconnect).
41909 */
41910- if (port->port.count) {
41911+ if (atomic_read(&port->port.count)) {
41912 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
41913 gs_start_io(port);
41914 if (gser->connect)
41915@@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
41916
41917 port->port_usb = NULL;
41918 gser->ioport = NULL;
41919- if (port->port.count > 0 || port->openclose) {
41920+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
41921 wake_up_interruptible(&port->drain_wait);
41922 if (port->port.tty)
41923 tty_hangup(port->port.tty);
41924@@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
41925
41926 /* finally, free any unused/unusable I/O buffers */
41927 spin_lock_irqsave(&port->port_lock, flags);
41928- if (port->port.count == 0 && !port->openclose)
41929+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
41930 gs_buf_free(&port->port_write_buf);
41931 gs_free_requests(gser->out, &port->read_pool, NULL);
41932 gs_free_requests(gser->out, &port->read_queue, NULL);
41933diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
41934index 5f3bcd3..bfca43f 100644
41935--- a/drivers/usb/serial/console.c
41936+++ b/drivers/usb/serial/console.c
41937@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
41938
41939 info->port = port;
41940
41941- ++port->port.count;
41942+ atomic_inc(&port->port.count);
41943 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
41944 if (serial->type->set_termios) {
41945 /*
41946@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
41947 }
41948 /* Now that any required fake tty operations are completed restore
41949 * the tty port count */
41950- --port->port.count;
41951+ atomic_dec(&port->port.count);
41952 /* The console is special in terms of closing the device so
41953 * indicate this port is now acting as a system console. */
41954 port->port.console = 1;
41955@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
41956 free_tty:
41957 kfree(tty);
41958 reset_open_count:
41959- port->port.count = 0;
41960+ atomic_set(&port->port.count, 0);
41961 usb_autopm_put_interface(serial->interface);
41962 error_get_interface:
41963 usb_serial_put(serial);
41964diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
41965index d6bea3e..60b250e 100644
41966--- a/drivers/usb/wusbcore/wa-hc.h
41967+++ b/drivers/usb/wusbcore/wa-hc.h
41968@@ -192,7 +192,7 @@ struct wahc {
41969 struct list_head xfer_delayed_list;
41970 spinlock_t xfer_list_lock;
41971 struct work_struct xfer_work;
41972- atomic_t xfer_id_count;
41973+ atomic_unchecked_t xfer_id_count;
41974 };
41975
41976
41977@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
41978 INIT_LIST_HEAD(&wa->xfer_delayed_list);
41979 spin_lock_init(&wa->xfer_list_lock);
41980 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
41981- atomic_set(&wa->xfer_id_count, 1);
41982+ atomic_set_unchecked(&wa->xfer_id_count, 1);
41983 }
41984
41985 /**
41986diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
41987index 57c01ab..8a05959 100644
41988--- a/drivers/usb/wusbcore/wa-xfer.c
41989+++ b/drivers/usb/wusbcore/wa-xfer.c
41990@@ -296,7 +296,7 @@ out:
41991 */
41992 static void wa_xfer_id_init(struct wa_xfer *xfer)
41993 {
41994- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
41995+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
41996 }
41997
41998 /*
41999diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
42000index 8c55011..eed4ae1a 100644
42001--- a/drivers/video/aty/aty128fb.c
42002+++ b/drivers/video/aty/aty128fb.c
42003@@ -149,7 +149,7 @@ enum {
42004 };
42005
42006 /* Must match above enum */
42007-static char * const r128_family[] = {
42008+static const char * const r128_family[] = {
42009 "AGP",
42010 "PCI",
42011 "PRO AGP",
42012diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
42013index 5c3960d..15cf8fc 100644
42014--- a/drivers/video/fbcmap.c
42015+++ b/drivers/video/fbcmap.c
42016@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
42017 rc = -ENODEV;
42018 goto out;
42019 }
42020- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
42021- !info->fbops->fb_setcmap)) {
42022+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
42023 rc = -EINVAL;
42024 goto out1;
42025 }
42026diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
42027index 3ff0105..7589d98 100644
42028--- a/drivers/video/fbmem.c
42029+++ b/drivers/video/fbmem.c
42030@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42031 image->dx += image->width + 8;
42032 }
42033 } else if (rotate == FB_ROTATE_UD) {
42034- for (x = 0; x < num && image->dx >= 0; x++) {
42035+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
42036 info->fbops->fb_imageblit(info, image);
42037 image->dx -= image->width + 8;
42038 }
42039@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42040 image->dy += image->height + 8;
42041 }
42042 } else if (rotate == FB_ROTATE_CCW) {
42043- for (x = 0; x < num && image->dy >= 0; x++) {
42044+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
42045 info->fbops->fb_imageblit(info, image);
42046 image->dy -= image->height + 8;
42047 }
42048@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
42049 return -EFAULT;
42050 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
42051 return -EINVAL;
42052- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
42053+ if (con2fb.framebuffer >= FB_MAX)
42054 return -EINVAL;
42055 if (!registered_fb[con2fb.framebuffer])
42056 request_module("fb%d", con2fb.framebuffer);
42057diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
42058index 7672d2e..b56437f 100644
42059--- a/drivers/video/i810/i810_accel.c
42060+++ b/drivers/video/i810/i810_accel.c
42061@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
42062 }
42063 }
42064 printk("ringbuffer lockup!!!\n");
42065+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
42066 i810_report_error(mmio);
42067 par->dev_flags |= LOCKUP;
42068 info->pixmap.scan_align = 1;
42069diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
42070index 3c14e43..eafa544 100644
42071--- a/drivers/video/logo/logo_linux_clut224.ppm
42072+++ b/drivers/video/logo/logo_linux_clut224.ppm
42073@@ -1,1604 +1,1123 @@
42074 P3
42075-# Standard 224-color Linux logo
42076 80 80
42077 255
42078- 0 0 0 0 0 0 0 0 0 0 0 0
42079- 0 0 0 0 0 0 0 0 0 0 0 0
42080- 0 0 0 0 0 0 0 0 0 0 0 0
42081- 0 0 0 0 0 0 0 0 0 0 0 0
42082- 0 0 0 0 0 0 0 0 0 0 0 0
42083- 0 0 0 0 0 0 0 0 0 0 0 0
42084- 0 0 0 0 0 0 0 0 0 0 0 0
42085- 0 0 0 0 0 0 0 0 0 0 0 0
42086- 0 0 0 0 0 0 0 0 0 0 0 0
42087- 6 6 6 6 6 6 10 10 10 10 10 10
42088- 10 10 10 6 6 6 6 6 6 6 6 6
42089- 0 0 0 0 0 0 0 0 0 0 0 0
42090- 0 0 0 0 0 0 0 0 0 0 0 0
42091- 0 0 0 0 0 0 0 0 0 0 0 0
42092- 0 0 0 0 0 0 0 0 0 0 0 0
42093- 0 0 0 0 0 0 0 0 0 0 0 0
42094- 0 0 0 0 0 0 0 0 0 0 0 0
42095- 0 0 0 0 0 0 0 0 0 0 0 0
42096- 0 0 0 0 0 0 0 0 0 0 0 0
42097- 0 0 0 0 0 0 0 0 0 0 0 0
42098- 0 0 0 0 0 0 0 0 0 0 0 0
42099- 0 0 0 0 0 0 0 0 0 0 0 0
42100- 0 0 0 0 0 0 0 0 0 0 0 0
42101- 0 0 0 0 0 0 0 0 0 0 0 0
42102- 0 0 0 0 0 0 0 0 0 0 0 0
42103- 0 0 0 0 0 0 0 0 0 0 0 0
42104- 0 0 0 0 0 0 0 0 0 0 0 0
42105- 0 0 0 0 0 0 0 0 0 0 0 0
42106- 0 0 0 6 6 6 10 10 10 14 14 14
42107- 22 22 22 26 26 26 30 30 30 34 34 34
42108- 30 30 30 30 30 30 26 26 26 18 18 18
42109- 14 14 14 10 10 10 6 6 6 0 0 0
42110- 0 0 0 0 0 0 0 0 0 0 0 0
42111- 0 0 0 0 0 0 0 0 0 0 0 0
42112- 0 0 0 0 0 0 0 0 0 0 0 0
42113- 0 0 0 0 0 0 0 0 0 0 0 0
42114- 0 0 0 0 0 0 0 0 0 0 0 0
42115- 0 0 0 0 0 0 0 0 0 0 0 0
42116- 0 0 0 0 0 0 0 0 0 0 0 0
42117- 0 0 0 0 0 0 0 0 0 0 0 0
42118- 0 0 0 0 0 0 0 0 0 0 0 0
42119- 0 0 0 0 0 1 0 0 1 0 0 0
42120- 0 0 0 0 0 0 0 0 0 0 0 0
42121- 0 0 0 0 0 0 0 0 0 0 0 0
42122- 0 0 0 0 0 0 0 0 0 0 0 0
42123- 0 0 0 0 0 0 0 0 0 0 0 0
42124- 0 0 0 0 0 0 0 0 0 0 0 0
42125- 0 0 0 0 0 0 0 0 0 0 0 0
42126- 6 6 6 14 14 14 26 26 26 42 42 42
42127- 54 54 54 66 66 66 78 78 78 78 78 78
42128- 78 78 78 74 74 74 66 66 66 54 54 54
42129- 42 42 42 26 26 26 18 18 18 10 10 10
42130- 6 6 6 0 0 0 0 0 0 0 0 0
42131- 0 0 0 0 0 0 0 0 0 0 0 0
42132- 0 0 0 0 0 0 0 0 0 0 0 0
42133- 0 0 0 0 0 0 0 0 0 0 0 0
42134- 0 0 0 0 0 0 0 0 0 0 0 0
42135- 0 0 0 0 0 0 0 0 0 0 0 0
42136- 0 0 0 0 0 0 0 0 0 0 0 0
42137- 0 0 0 0 0 0 0 0 0 0 0 0
42138- 0 0 0 0 0 0 0 0 0 0 0 0
42139- 0 0 1 0 0 0 0 0 0 0 0 0
42140- 0 0 0 0 0 0 0 0 0 0 0 0
42141- 0 0 0 0 0 0 0 0 0 0 0 0
42142- 0 0 0 0 0 0 0 0 0 0 0 0
42143- 0 0 0 0 0 0 0 0 0 0 0 0
42144- 0 0 0 0 0 0 0 0 0 0 0 0
42145- 0 0 0 0 0 0 0 0 0 10 10 10
42146- 22 22 22 42 42 42 66 66 66 86 86 86
42147- 66 66 66 38 38 38 38 38 38 22 22 22
42148- 26 26 26 34 34 34 54 54 54 66 66 66
42149- 86 86 86 70 70 70 46 46 46 26 26 26
42150- 14 14 14 6 6 6 0 0 0 0 0 0
42151- 0 0 0 0 0 0 0 0 0 0 0 0
42152- 0 0 0 0 0 0 0 0 0 0 0 0
42153- 0 0 0 0 0 0 0 0 0 0 0 0
42154- 0 0 0 0 0 0 0 0 0 0 0 0
42155- 0 0 0 0 0 0 0 0 0 0 0 0
42156- 0 0 0 0 0 0 0 0 0 0 0 0
42157- 0 0 0 0 0 0 0 0 0 0 0 0
42158- 0 0 0 0 0 0 0 0 0 0 0 0
42159- 0 0 1 0 0 1 0 0 1 0 0 0
42160- 0 0 0 0 0 0 0 0 0 0 0 0
42161- 0 0 0 0 0 0 0 0 0 0 0 0
42162- 0 0 0 0 0 0 0 0 0 0 0 0
42163- 0 0 0 0 0 0 0 0 0 0 0 0
42164- 0 0 0 0 0 0 0 0 0 0 0 0
42165- 0 0 0 0 0 0 10 10 10 26 26 26
42166- 50 50 50 82 82 82 58 58 58 6 6 6
42167- 2 2 6 2 2 6 2 2 6 2 2 6
42168- 2 2 6 2 2 6 2 2 6 2 2 6
42169- 6 6 6 54 54 54 86 86 86 66 66 66
42170- 38 38 38 18 18 18 6 6 6 0 0 0
42171- 0 0 0 0 0 0 0 0 0 0 0 0
42172- 0 0 0 0 0 0 0 0 0 0 0 0
42173- 0 0 0 0 0 0 0 0 0 0 0 0
42174- 0 0 0 0 0 0 0 0 0 0 0 0
42175- 0 0 0 0 0 0 0 0 0 0 0 0
42176- 0 0 0 0 0 0 0 0 0 0 0 0
42177- 0 0 0 0 0 0 0 0 0 0 0 0
42178- 0 0 0 0 0 0 0 0 0 0 0 0
42179- 0 0 0 0 0 0 0 0 0 0 0 0
42180- 0 0 0 0 0 0 0 0 0 0 0 0
42181- 0 0 0 0 0 0 0 0 0 0 0 0
42182- 0 0 0 0 0 0 0 0 0 0 0 0
42183- 0 0 0 0 0 0 0 0 0 0 0 0
42184- 0 0 0 0 0 0 0 0 0 0 0 0
42185- 0 0 0 6 6 6 22 22 22 50 50 50
42186- 78 78 78 34 34 34 2 2 6 2 2 6
42187- 2 2 6 2 2 6 2 2 6 2 2 6
42188- 2 2 6 2 2 6 2 2 6 2 2 6
42189- 2 2 6 2 2 6 6 6 6 70 70 70
42190- 78 78 78 46 46 46 22 22 22 6 6 6
42191- 0 0 0 0 0 0 0 0 0 0 0 0
42192- 0 0 0 0 0 0 0 0 0 0 0 0
42193- 0 0 0 0 0 0 0 0 0 0 0 0
42194- 0 0 0 0 0 0 0 0 0 0 0 0
42195- 0 0 0 0 0 0 0 0 0 0 0 0
42196- 0 0 0 0 0 0 0 0 0 0 0 0
42197- 0 0 0 0 0 0 0 0 0 0 0 0
42198- 0 0 0 0 0 0 0 0 0 0 0 0
42199- 0 0 1 0 0 1 0 0 1 0 0 0
42200- 0 0 0 0 0 0 0 0 0 0 0 0
42201- 0 0 0 0 0 0 0 0 0 0 0 0
42202- 0 0 0 0 0 0 0 0 0 0 0 0
42203- 0 0 0 0 0 0 0 0 0 0 0 0
42204- 0 0 0 0 0 0 0 0 0 0 0 0
42205- 6 6 6 18 18 18 42 42 42 82 82 82
42206- 26 26 26 2 2 6 2 2 6 2 2 6
42207- 2 2 6 2 2 6 2 2 6 2 2 6
42208- 2 2 6 2 2 6 2 2 6 14 14 14
42209- 46 46 46 34 34 34 6 6 6 2 2 6
42210- 42 42 42 78 78 78 42 42 42 18 18 18
42211- 6 6 6 0 0 0 0 0 0 0 0 0
42212- 0 0 0 0 0 0 0 0 0 0 0 0
42213- 0 0 0 0 0 0 0 0 0 0 0 0
42214- 0 0 0 0 0 0 0 0 0 0 0 0
42215- 0 0 0 0 0 0 0 0 0 0 0 0
42216- 0 0 0 0 0 0 0 0 0 0 0 0
42217- 0 0 0 0 0 0 0 0 0 0 0 0
42218- 0 0 0 0 0 0 0 0 0 0 0 0
42219- 0 0 1 0 0 0 0 0 1 0 0 0
42220- 0 0 0 0 0 0 0 0 0 0 0 0
42221- 0 0 0 0 0 0 0 0 0 0 0 0
42222- 0 0 0 0 0 0 0 0 0 0 0 0
42223- 0 0 0 0 0 0 0 0 0 0 0 0
42224- 0 0 0 0 0 0 0 0 0 0 0 0
42225- 10 10 10 30 30 30 66 66 66 58 58 58
42226- 2 2 6 2 2 6 2 2 6 2 2 6
42227- 2 2 6 2 2 6 2 2 6 2 2 6
42228- 2 2 6 2 2 6 2 2 6 26 26 26
42229- 86 86 86 101 101 101 46 46 46 10 10 10
42230- 2 2 6 58 58 58 70 70 70 34 34 34
42231- 10 10 10 0 0 0 0 0 0 0 0 0
42232- 0 0 0 0 0 0 0 0 0 0 0 0
42233- 0 0 0 0 0 0 0 0 0 0 0 0
42234- 0 0 0 0 0 0 0 0 0 0 0 0
42235- 0 0 0 0 0 0 0 0 0 0 0 0
42236- 0 0 0 0 0 0 0 0 0 0 0 0
42237- 0 0 0 0 0 0 0 0 0 0 0 0
42238- 0 0 0 0 0 0 0 0 0 0 0 0
42239- 0 0 1 0 0 1 0 0 1 0 0 0
42240- 0 0 0 0 0 0 0 0 0 0 0 0
42241- 0 0 0 0 0 0 0 0 0 0 0 0
42242- 0 0 0 0 0 0 0 0 0 0 0 0
42243- 0 0 0 0 0 0 0 0 0 0 0 0
42244- 0 0 0 0 0 0 0 0 0 0 0 0
42245- 14 14 14 42 42 42 86 86 86 10 10 10
42246- 2 2 6 2 2 6 2 2 6 2 2 6
42247- 2 2 6 2 2 6 2 2 6 2 2 6
42248- 2 2 6 2 2 6 2 2 6 30 30 30
42249- 94 94 94 94 94 94 58 58 58 26 26 26
42250- 2 2 6 6 6 6 78 78 78 54 54 54
42251- 22 22 22 6 6 6 0 0 0 0 0 0
42252- 0 0 0 0 0 0 0 0 0 0 0 0
42253- 0 0 0 0 0 0 0 0 0 0 0 0
42254- 0 0 0 0 0 0 0 0 0 0 0 0
42255- 0 0 0 0 0 0 0 0 0 0 0 0
42256- 0 0 0 0 0 0 0 0 0 0 0 0
42257- 0 0 0 0 0 0 0 0 0 0 0 0
42258- 0 0 0 0 0 0 0 0 0 0 0 0
42259- 0 0 0 0 0 0 0 0 0 0 0 0
42260- 0 0 0 0 0 0 0 0 0 0 0 0
42261- 0 0 0 0 0 0 0 0 0 0 0 0
42262- 0 0 0 0 0 0 0 0 0 0 0 0
42263- 0 0 0 0 0 0 0 0 0 0 0 0
42264- 0 0 0 0 0 0 0 0 0 6 6 6
42265- 22 22 22 62 62 62 62 62 62 2 2 6
42266- 2 2 6 2 2 6 2 2 6 2 2 6
42267- 2 2 6 2 2 6 2 2 6 2 2 6
42268- 2 2 6 2 2 6 2 2 6 26 26 26
42269- 54 54 54 38 38 38 18 18 18 10 10 10
42270- 2 2 6 2 2 6 34 34 34 82 82 82
42271- 38 38 38 14 14 14 0 0 0 0 0 0
42272- 0 0 0 0 0 0 0 0 0 0 0 0
42273- 0 0 0 0 0 0 0 0 0 0 0 0
42274- 0 0 0 0 0 0 0 0 0 0 0 0
42275- 0 0 0 0 0 0 0 0 0 0 0 0
42276- 0 0 0 0 0 0 0 0 0 0 0 0
42277- 0 0 0 0 0 0 0 0 0 0 0 0
42278- 0 0 0 0 0 0 0 0 0 0 0 0
42279- 0 0 0 0 0 1 0 0 1 0 0 0
42280- 0 0 0 0 0 0 0 0 0 0 0 0
42281- 0 0 0 0 0 0 0 0 0 0 0 0
42282- 0 0 0 0 0 0 0 0 0 0 0 0
42283- 0 0 0 0 0 0 0 0 0 0 0 0
42284- 0 0 0 0 0 0 0 0 0 6 6 6
42285- 30 30 30 78 78 78 30 30 30 2 2 6
42286- 2 2 6 2 2 6 2 2 6 2 2 6
42287- 2 2 6 2 2 6 2 2 6 2 2 6
42288- 2 2 6 2 2 6 2 2 6 10 10 10
42289- 10 10 10 2 2 6 2 2 6 2 2 6
42290- 2 2 6 2 2 6 2 2 6 78 78 78
42291- 50 50 50 18 18 18 6 6 6 0 0 0
42292- 0 0 0 0 0 0 0 0 0 0 0 0
42293- 0 0 0 0 0 0 0 0 0 0 0 0
42294- 0 0 0 0 0 0 0 0 0 0 0 0
42295- 0 0 0 0 0 0 0 0 0 0 0 0
42296- 0 0 0 0 0 0 0 0 0 0 0 0
42297- 0 0 0 0 0 0 0 0 0 0 0 0
42298- 0 0 0 0 0 0 0 0 0 0 0 0
42299- 0 0 1 0 0 0 0 0 0 0 0 0
42300- 0 0 0 0 0 0 0 0 0 0 0 0
42301- 0 0 0 0 0 0 0 0 0 0 0 0
42302- 0 0 0 0 0 0 0 0 0 0 0 0
42303- 0 0 0 0 0 0 0 0 0 0 0 0
42304- 0 0 0 0 0 0 0 0 0 10 10 10
42305- 38 38 38 86 86 86 14 14 14 2 2 6
42306- 2 2 6 2 2 6 2 2 6 2 2 6
42307- 2 2 6 2 2 6 2 2 6 2 2 6
42308- 2 2 6 2 2 6 2 2 6 2 2 6
42309- 2 2 6 2 2 6 2 2 6 2 2 6
42310- 2 2 6 2 2 6 2 2 6 54 54 54
42311- 66 66 66 26 26 26 6 6 6 0 0 0
42312- 0 0 0 0 0 0 0 0 0 0 0 0
42313- 0 0 0 0 0 0 0 0 0 0 0 0
42314- 0 0 0 0 0 0 0 0 0 0 0 0
42315- 0 0 0 0 0 0 0 0 0 0 0 0
42316- 0 0 0 0 0 0 0 0 0 0 0 0
42317- 0 0 0 0 0 0 0 0 0 0 0 0
42318- 0 0 0 0 0 0 0 0 0 0 0 0
42319- 0 0 0 0 0 1 0 0 1 0 0 0
42320- 0 0 0 0 0 0 0 0 0 0 0 0
42321- 0 0 0 0 0 0 0 0 0 0 0 0
42322- 0 0 0 0 0 0 0 0 0 0 0 0
42323- 0 0 0 0 0 0 0 0 0 0 0 0
42324- 0 0 0 0 0 0 0 0 0 14 14 14
42325- 42 42 42 82 82 82 2 2 6 2 2 6
42326- 2 2 6 6 6 6 10 10 10 2 2 6
42327- 2 2 6 2 2 6 2 2 6 2 2 6
42328- 2 2 6 2 2 6 2 2 6 6 6 6
42329- 14 14 14 10 10 10 2 2 6 2 2 6
42330- 2 2 6 2 2 6 2 2 6 18 18 18
42331- 82 82 82 34 34 34 10 10 10 0 0 0
42332- 0 0 0 0 0 0 0 0 0 0 0 0
42333- 0 0 0 0 0 0 0 0 0 0 0 0
42334- 0 0 0 0 0 0 0 0 0 0 0 0
42335- 0 0 0 0 0 0 0 0 0 0 0 0
42336- 0 0 0 0 0 0 0 0 0 0 0 0
42337- 0 0 0 0 0 0 0 0 0 0 0 0
42338- 0 0 0 0 0 0 0 0 0 0 0 0
42339- 0 0 1 0 0 0 0 0 0 0 0 0
42340- 0 0 0 0 0 0 0 0 0 0 0 0
42341- 0 0 0 0 0 0 0 0 0 0 0 0
42342- 0 0 0 0 0 0 0 0 0 0 0 0
42343- 0 0 0 0 0 0 0 0 0 0 0 0
42344- 0 0 0 0 0 0 0 0 0 14 14 14
42345- 46 46 46 86 86 86 2 2 6 2 2 6
42346- 6 6 6 6 6 6 22 22 22 34 34 34
42347- 6 6 6 2 2 6 2 2 6 2 2 6
42348- 2 2 6 2 2 6 18 18 18 34 34 34
42349- 10 10 10 50 50 50 22 22 22 2 2 6
42350- 2 2 6 2 2 6 2 2 6 10 10 10
42351- 86 86 86 42 42 42 14 14 14 0 0 0
42352- 0 0 0 0 0 0 0 0 0 0 0 0
42353- 0 0 0 0 0 0 0 0 0 0 0 0
42354- 0 0 0 0 0 0 0 0 0 0 0 0
42355- 0 0 0 0 0 0 0 0 0 0 0 0
42356- 0 0 0 0 0 0 0 0 0 0 0 0
42357- 0 0 0 0 0 0 0 0 0 0 0 0
42358- 0 0 0 0 0 0 0 0 0 0 0 0
42359- 0 0 1 0 0 1 0 0 1 0 0 0
42360- 0 0 0 0 0 0 0 0 0 0 0 0
42361- 0 0 0 0 0 0 0 0 0 0 0 0
42362- 0 0 0 0 0 0 0 0 0 0 0 0
42363- 0 0 0 0 0 0 0 0 0 0 0 0
42364- 0 0 0 0 0 0 0 0 0 14 14 14
42365- 46 46 46 86 86 86 2 2 6 2 2 6
42366- 38 38 38 116 116 116 94 94 94 22 22 22
42367- 22 22 22 2 2 6 2 2 6 2 2 6
42368- 14 14 14 86 86 86 138 138 138 162 162 162
42369-154 154 154 38 38 38 26 26 26 6 6 6
42370- 2 2 6 2 2 6 2 2 6 2 2 6
42371- 86 86 86 46 46 46 14 14 14 0 0 0
42372- 0 0 0 0 0 0 0 0 0 0 0 0
42373- 0 0 0 0 0 0 0 0 0 0 0 0
42374- 0 0 0 0 0 0 0 0 0 0 0 0
42375- 0 0 0 0 0 0 0 0 0 0 0 0
42376- 0 0 0 0 0 0 0 0 0 0 0 0
42377- 0 0 0 0 0 0 0 0 0 0 0 0
42378- 0 0 0 0 0 0 0 0 0 0 0 0
42379- 0 0 0 0 0 0 0 0 0 0 0 0
42380- 0 0 0 0 0 0 0 0 0 0 0 0
42381- 0 0 0 0 0 0 0 0 0 0 0 0
42382- 0 0 0 0 0 0 0 0 0 0 0 0
42383- 0 0 0 0 0 0 0 0 0 0 0 0
42384- 0 0 0 0 0 0 0 0 0 14 14 14
42385- 46 46 46 86 86 86 2 2 6 14 14 14
42386-134 134 134 198 198 198 195 195 195 116 116 116
42387- 10 10 10 2 2 6 2 2 6 6 6 6
42388-101 98 89 187 187 187 210 210 210 218 218 218
42389-214 214 214 134 134 134 14 14 14 6 6 6
42390- 2 2 6 2 2 6 2 2 6 2 2 6
42391- 86 86 86 50 50 50 18 18 18 6 6 6
42392- 0 0 0 0 0 0 0 0 0 0 0 0
42393- 0 0 0 0 0 0 0 0 0 0 0 0
42394- 0 0 0 0 0 0 0 0 0 0 0 0
42395- 0 0 0 0 0 0 0 0 0 0 0 0
42396- 0 0 0 0 0 0 0 0 0 0 0 0
42397- 0 0 0 0 0 0 0 0 0 0 0 0
42398- 0 0 0 0 0 0 0 0 1 0 0 0
42399- 0 0 1 0 0 1 0 0 1 0 0 0
42400- 0 0 0 0 0 0 0 0 0 0 0 0
42401- 0 0 0 0 0 0 0 0 0 0 0 0
42402- 0 0 0 0 0 0 0 0 0 0 0 0
42403- 0 0 0 0 0 0 0 0 0 0 0 0
42404- 0 0 0 0 0 0 0 0 0 14 14 14
42405- 46 46 46 86 86 86 2 2 6 54 54 54
42406-218 218 218 195 195 195 226 226 226 246 246 246
42407- 58 58 58 2 2 6 2 2 6 30 30 30
42408-210 210 210 253 253 253 174 174 174 123 123 123
42409-221 221 221 234 234 234 74 74 74 2 2 6
42410- 2 2 6 2 2 6 2 2 6 2 2 6
42411- 70 70 70 58 58 58 22 22 22 6 6 6
42412- 0 0 0 0 0 0 0 0 0 0 0 0
42413- 0 0 0 0 0 0 0 0 0 0 0 0
42414- 0 0 0 0 0 0 0 0 0 0 0 0
42415- 0 0 0 0 0 0 0 0 0 0 0 0
42416- 0 0 0 0 0 0 0 0 0 0 0 0
42417- 0 0 0 0 0 0 0 0 0 0 0 0
42418- 0 0 0 0 0 0 0 0 0 0 0 0
42419- 0 0 0 0 0 0 0 0 0 0 0 0
42420- 0 0 0 0 0 0 0 0 0 0 0 0
42421- 0 0 0 0 0 0 0 0 0 0 0 0
42422- 0 0 0 0 0 0 0 0 0 0 0 0
42423- 0 0 0 0 0 0 0 0 0 0 0 0
42424- 0 0 0 0 0 0 0 0 0 14 14 14
42425- 46 46 46 82 82 82 2 2 6 106 106 106
42426-170 170 170 26 26 26 86 86 86 226 226 226
42427-123 123 123 10 10 10 14 14 14 46 46 46
42428-231 231 231 190 190 190 6 6 6 70 70 70
42429- 90 90 90 238 238 238 158 158 158 2 2 6
42430- 2 2 6 2 2 6 2 2 6 2 2 6
42431- 70 70 70 58 58 58 22 22 22 6 6 6
42432- 0 0 0 0 0 0 0 0 0 0 0 0
42433- 0 0 0 0 0 0 0 0 0 0 0 0
42434- 0 0 0 0 0 0 0 0 0 0 0 0
42435- 0 0 0 0 0 0 0 0 0 0 0 0
42436- 0 0 0 0 0 0 0 0 0 0 0 0
42437- 0 0 0 0 0 0 0 0 0 0 0 0
42438- 0 0 0 0 0 0 0 0 1 0 0 0
42439- 0 0 1 0 0 1 0 0 1 0 0 0
42440- 0 0 0 0 0 0 0 0 0 0 0 0
42441- 0 0 0 0 0 0 0 0 0 0 0 0
42442- 0 0 0 0 0 0 0 0 0 0 0 0
42443- 0 0 0 0 0 0 0 0 0 0 0 0
42444- 0 0 0 0 0 0 0 0 0 14 14 14
42445- 42 42 42 86 86 86 6 6 6 116 116 116
42446-106 106 106 6 6 6 70 70 70 149 149 149
42447-128 128 128 18 18 18 38 38 38 54 54 54
42448-221 221 221 106 106 106 2 2 6 14 14 14
42449- 46 46 46 190 190 190 198 198 198 2 2 6
42450- 2 2 6 2 2 6 2 2 6 2 2 6
42451- 74 74 74 62 62 62 22 22 22 6 6 6
42452- 0 0 0 0 0 0 0 0 0 0 0 0
42453- 0 0 0 0 0 0 0 0 0 0 0 0
42454- 0 0 0 0 0 0 0 0 0 0 0 0
42455- 0 0 0 0 0 0 0 0 0 0 0 0
42456- 0 0 0 0 0 0 0 0 0 0 0 0
42457- 0 0 0 0 0 0 0 0 0 0 0 0
42458- 0 0 0 0 0 0 0 0 1 0 0 0
42459- 0 0 1 0 0 0 0 0 1 0 0 0
42460- 0 0 0 0 0 0 0 0 0 0 0 0
42461- 0 0 0 0 0 0 0 0 0 0 0 0
42462- 0 0 0 0 0 0 0 0 0 0 0 0
42463- 0 0 0 0 0 0 0 0 0 0 0 0
42464- 0 0 0 0 0 0 0 0 0 14 14 14
42465- 42 42 42 94 94 94 14 14 14 101 101 101
42466-128 128 128 2 2 6 18 18 18 116 116 116
42467-118 98 46 121 92 8 121 92 8 98 78 10
42468-162 162 162 106 106 106 2 2 6 2 2 6
42469- 2 2 6 195 195 195 195 195 195 6 6 6
42470- 2 2 6 2 2 6 2 2 6 2 2 6
42471- 74 74 74 62 62 62 22 22 22 6 6 6
42472- 0 0 0 0 0 0 0 0 0 0 0 0
42473- 0 0 0 0 0 0 0 0 0 0 0 0
42474- 0 0 0 0 0 0 0 0 0 0 0 0
42475- 0 0 0 0 0 0 0 0 0 0 0 0
42476- 0 0 0 0 0 0 0 0 0 0 0 0
42477- 0 0 0 0 0 0 0 0 0 0 0 0
42478- 0 0 0 0 0 0 0 0 1 0 0 1
42479- 0 0 1 0 0 0 0 0 1 0 0 0
42480- 0 0 0 0 0 0 0 0 0 0 0 0
42481- 0 0 0 0 0 0 0 0 0 0 0 0
42482- 0 0 0 0 0 0 0 0 0 0 0 0
42483- 0 0 0 0 0 0 0 0 0 0 0 0
42484- 0 0 0 0 0 0 0 0 0 10 10 10
42485- 38 38 38 90 90 90 14 14 14 58 58 58
42486-210 210 210 26 26 26 54 38 6 154 114 10
42487-226 170 11 236 186 11 225 175 15 184 144 12
42488-215 174 15 175 146 61 37 26 9 2 2 6
42489- 70 70 70 246 246 246 138 138 138 2 2 6
42490- 2 2 6 2 2 6 2 2 6 2 2 6
42491- 70 70 70 66 66 66 26 26 26 6 6 6
42492- 0 0 0 0 0 0 0 0 0 0 0 0
42493- 0 0 0 0 0 0 0 0 0 0 0 0
42494- 0 0 0 0 0 0 0 0 0 0 0 0
42495- 0 0 0 0 0 0 0 0 0 0 0 0
42496- 0 0 0 0 0 0 0 0 0 0 0 0
42497- 0 0 0 0 0 0 0 0 0 0 0 0
42498- 0 0 0 0 0 0 0 0 0 0 0 0
42499- 0 0 0 0 0 0 0 0 0 0 0 0
42500- 0 0 0 0 0 0 0 0 0 0 0 0
42501- 0 0 0 0 0 0 0 0 0 0 0 0
42502- 0 0 0 0 0 0 0 0 0 0 0 0
42503- 0 0 0 0 0 0 0 0 0 0 0 0
42504- 0 0 0 0 0 0 0 0 0 10 10 10
42505- 38 38 38 86 86 86 14 14 14 10 10 10
42506-195 195 195 188 164 115 192 133 9 225 175 15
42507-239 182 13 234 190 10 232 195 16 232 200 30
42508-245 207 45 241 208 19 232 195 16 184 144 12
42509-218 194 134 211 206 186 42 42 42 2 2 6
42510- 2 2 6 2 2 6 2 2 6 2 2 6
42511- 50 50 50 74 74 74 30 30 30 6 6 6
42512- 0 0 0 0 0 0 0 0 0 0 0 0
42513- 0 0 0 0 0 0 0 0 0 0 0 0
42514- 0 0 0 0 0 0 0 0 0 0 0 0
42515- 0 0 0 0 0 0 0 0 0 0 0 0
42516- 0 0 0 0 0 0 0 0 0 0 0 0
42517- 0 0 0 0 0 0 0 0 0 0 0 0
42518- 0 0 0 0 0 0 0 0 0 0 0 0
42519- 0 0 0 0 0 0 0 0 0 0 0 0
42520- 0 0 0 0 0 0 0 0 0 0 0 0
42521- 0 0 0 0 0 0 0 0 0 0 0 0
42522- 0 0 0 0 0 0 0 0 0 0 0 0
42523- 0 0 0 0 0 0 0 0 0 0 0 0
42524- 0 0 0 0 0 0 0 0 0 10 10 10
42525- 34 34 34 86 86 86 14 14 14 2 2 6
42526-121 87 25 192 133 9 219 162 10 239 182 13
42527-236 186 11 232 195 16 241 208 19 244 214 54
42528-246 218 60 246 218 38 246 215 20 241 208 19
42529-241 208 19 226 184 13 121 87 25 2 2 6
42530- 2 2 6 2 2 6 2 2 6 2 2 6
42531- 50 50 50 82 82 82 34 34 34 10 10 10
42532- 0 0 0 0 0 0 0 0 0 0 0 0
42533- 0 0 0 0 0 0 0 0 0 0 0 0
42534- 0 0 0 0 0 0 0 0 0 0 0 0
42535- 0 0 0 0 0 0 0 0 0 0 0 0
42536- 0 0 0 0 0 0 0 0 0 0 0 0
42537- 0 0 0 0 0 0 0 0 0 0 0 0
42538- 0 0 0 0 0 0 0 0 0 0 0 0
42539- 0 0 0 0 0 0 0 0 0 0 0 0
42540- 0 0 0 0 0 0 0 0 0 0 0 0
42541- 0 0 0 0 0 0 0 0 0 0 0 0
42542- 0 0 0 0 0 0 0 0 0 0 0 0
42543- 0 0 0 0 0 0 0 0 0 0 0 0
42544- 0 0 0 0 0 0 0 0 0 10 10 10
42545- 34 34 34 82 82 82 30 30 30 61 42 6
42546-180 123 7 206 145 10 230 174 11 239 182 13
42547-234 190 10 238 202 15 241 208 19 246 218 74
42548-246 218 38 246 215 20 246 215 20 246 215 20
42549-226 184 13 215 174 15 184 144 12 6 6 6
42550- 2 2 6 2 2 6 2 2 6 2 2 6
42551- 26 26 26 94 94 94 42 42 42 14 14 14
42552- 0 0 0 0 0 0 0 0 0 0 0 0
42553- 0 0 0 0 0 0 0 0 0 0 0 0
42554- 0 0 0 0 0 0 0 0 0 0 0 0
42555- 0 0 0 0 0 0 0 0 0 0 0 0
42556- 0 0 0 0 0 0 0 0 0 0 0 0
42557- 0 0 0 0 0 0 0 0 0 0 0 0
42558- 0 0 0 0 0 0 0 0 0 0 0 0
42559- 0 0 0 0 0 0 0 0 0 0 0 0
42560- 0 0 0 0 0 0 0 0 0 0 0 0
42561- 0 0 0 0 0 0 0 0 0 0 0 0
42562- 0 0 0 0 0 0 0 0 0 0 0 0
42563- 0 0 0 0 0 0 0 0 0 0 0 0
42564- 0 0 0 0 0 0 0 0 0 10 10 10
42565- 30 30 30 78 78 78 50 50 50 104 69 6
42566-192 133 9 216 158 10 236 178 12 236 186 11
42567-232 195 16 241 208 19 244 214 54 245 215 43
42568-246 215 20 246 215 20 241 208 19 198 155 10
42569-200 144 11 216 158 10 156 118 10 2 2 6
42570- 2 2 6 2 2 6 2 2 6 2 2 6
42571- 6 6 6 90 90 90 54 54 54 18 18 18
42572- 6 6 6 0 0 0 0 0 0 0 0 0
42573- 0 0 0 0 0 0 0 0 0 0 0 0
42574- 0 0 0 0 0 0 0 0 0 0 0 0
42575- 0 0 0 0 0 0 0 0 0 0 0 0
42576- 0 0 0 0 0 0 0 0 0 0 0 0
42577- 0 0 0 0 0 0 0 0 0 0 0 0
42578- 0 0 0 0 0 0 0 0 0 0 0 0
42579- 0 0 0 0 0 0 0 0 0 0 0 0
42580- 0 0 0 0 0 0 0 0 0 0 0 0
42581- 0 0 0 0 0 0 0 0 0 0 0 0
42582- 0 0 0 0 0 0 0 0 0 0 0 0
42583- 0 0 0 0 0 0 0 0 0 0 0 0
42584- 0 0 0 0 0 0 0 0 0 10 10 10
42585- 30 30 30 78 78 78 46 46 46 22 22 22
42586-137 92 6 210 162 10 239 182 13 238 190 10
42587-238 202 15 241 208 19 246 215 20 246 215 20
42588-241 208 19 203 166 17 185 133 11 210 150 10
42589-216 158 10 210 150 10 102 78 10 2 2 6
42590- 6 6 6 54 54 54 14 14 14 2 2 6
42591- 2 2 6 62 62 62 74 74 74 30 30 30
42592- 10 10 10 0 0 0 0 0 0 0 0 0
42593- 0 0 0 0 0 0 0 0 0 0 0 0
42594- 0 0 0 0 0 0 0 0 0 0 0 0
42595- 0 0 0 0 0 0 0 0 0 0 0 0
42596- 0 0 0 0 0 0 0 0 0 0 0 0
42597- 0 0 0 0 0 0 0 0 0 0 0 0
42598- 0 0 0 0 0 0 0 0 0 0 0 0
42599- 0 0 0 0 0 0 0 0 0 0 0 0
42600- 0 0 0 0 0 0 0 0 0 0 0 0
42601- 0 0 0 0 0 0 0 0 0 0 0 0
42602- 0 0 0 0 0 0 0 0 0 0 0 0
42603- 0 0 0 0 0 0 0 0 0 0 0 0
42604- 0 0 0 0 0 0 0 0 0 10 10 10
42605- 34 34 34 78 78 78 50 50 50 6 6 6
42606- 94 70 30 139 102 15 190 146 13 226 184 13
42607-232 200 30 232 195 16 215 174 15 190 146 13
42608-168 122 10 192 133 9 210 150 10 213 154 11
42609-202 150 34 182 157 106 101 98 89 2 2 6
42610- 2 2 6 78 78 78 116 116 116 58 58 58
42611- 2 2 6 22 22 22 90 90 90 46 46 46
42612- 18 18 18 6 6 6 0 0 0 0 0 0
42613- 0 0 0 0 0 0 0 0 0 0 0 0
42614- 0 0 0 0 0 0 0 0 0 0 0 0
42615- 0 0 0 0 0 0 0 0 0 0 0 0
42616- 0 0 0 0 0 0 0 0 0 0 0 0
42617- 0 0 0 0 0 0 0 0 0 0 0 0
42618- 0 0 0 0 0 0 0 0 0 0 0 0
42619- 0 0 0 0 0 0 0 0 0 0 0 0
42620- 0 0 0 0 0 0 0 0 0 0 0 0
42621- 0 0 0 0 0 0 0 0 0 0 0 0
42622- 0 0 0 0 0 0 0 0 0 0 0 0
42623- 0 0 0 0 0 0 0 0 0 0 0 0
42624- 0 0 0 0 0 0 0 0 0 10 10 10
42625- 38 38 38 86 86 86 50 50 50 6 6 6
42626-128 128 128 174 154 114 156 107 11 168 122 10
42627-198 155 10 184 144 12 197 138 11 200 144 11
42628-206 145 10 206 145 10 197 138 11 188 164 115
42629-195 195 195 198 198 198 174 174 174 14 14 14
42630- 2 2 6 22 22 22 116 116 116 116 116 116
42631- 22 22 22 2 2 6 74 74 74 70 70 70
42632- 30 30 30 10 10 10 0 0 0 0 0 0
42633- 0 0 0 0 0 0 0 0 0 0 0 0
42634- 0 0 0 0 0 0 0 0 0 0 0 0
42635- 0 0 0 0 0 0 0 0 0 0 0 0
42636- 0 0 0 0 0 0 0 0 0 0 0 0
42637- 0 0 0 0 0 0 0 0 0 0 0 0
42638- 0 0 0 0 0 0 0 0 0 0 0 0
42639- 0 0 0 0 0 0 0 0 0 0 0 0
42640- 0 0 0 0 0 0 0 0 0 0 0 0
42641- 0 0 0 0 0 0 0 0 0 0 0 0
42642- 0 0 0 0 0 0 0 0 0 0 0 0
42643- 0 0 0 0 0 0 0 0 0 0 0 0
42644- 0 0 0 0 0 0 6 6 6 18 18 18
42645- 50 50 50 101 101 101 26 26 26 10 10 10
42646-138 138 138 190 190 190 174 154 114 156 107 11
42647-197 138 11 200 144 11 197 138 11 192 133 9
42648-180 123 7 190 142 34 190 178 144 187 187 187
42649-202 202 202 221 221 221 214 214 214 66 66 66
42650- 2 2 6 2 2 6 50 50 50 62 62 62
42651- 6 6 6 2 2 6 10 10 10 90 90 90
42652- 50 50 50 18 18 18 6 6 6 0 0 0
42653- 0 0 0 0 0 0 0 0 0 0 0 0
42654- 0 0 0 0 0 0 0 0 0 0 0 0
42655- 0 0 0 0 0 0 0 0 0 0 0 0
42656- 0 0 0 0 0 0 0 0 0 0 0 0
42657- 0 0 0 0 0 0 0 0 0 0 0 0
42658- 0 0 0 0 0 0 0 0 0 0 0 0
42659- 0 0 0 0 0 0 0 0 0 0 0 0
42660- 0 0 0 0 0 0 0 0 0 0 0 0
42661- 0 0 0 0 0 0 0 0 0 0 0 0
42662- 0 0 0 0 0 0 0 0 0 0 0 0
42663- 0 0 0 0 0 0 0 0 0 0 0 0
42664- 0 0 0 0 0 0 10 10 10 34 34 34
42665- 74 74 74 74 74 74 2 2 6 6 6 6
42666-144 144 144 198 198 198 190 190 190 178 166 146
42667-154 121 60 156 107 11 156 107 11 168 124 44
42668-174 154 114 187 187 187 190 190 190 210 210 210
42669-246 246 246 253 253 253 253 253 253 182 182 182
42670- 6 6 6 2 2 6 2 2 6 2 2 6
42671- 2 2 6 2 2 6 2 2 6 62 62 62
42672- 74 74 74 34 34 34 14 14 14 0 0 0
42673- 0 0 0 0 0 0 0 0 0 0 0 0
42674- 0 0 0 0 0 0 0 0 0 0 0 0
42675- 0 0 0 0 0 0 0 0 0 0 0 0
42676- 0 0 0 0 0 0 0 0 0 0 0 0
42677- 0 0 0 0 0 0 0 0 0 0 0 0
42678- 0 0 0 0 0 0 0 0 0 0 0 0
42679- 0 0 0 0 0 0 0 0 0 0 0 0
42680- 0 0 0 0 0 0 0 0 0 0 0 0
42681- 0 0 0 0 0 0 0 0 0 0 0 0
42682- 0 0 0 0 0 0 0 0 0 0 0 0
42683- 0 0 0 0 0 0 0 0 0 0 0 0
42684- 0 0 0 10 10 10 22 22 22 54 54 54
42685- 94 94 94 18 18 18 2 2 6 46 46 46
42686-234 234 234 221 221 221 190 190 190 190 190 190
42687-190 190 190 187 187 187 187 187 187 190 190 190
42688-190 190 190 195 195 195 214 214 214 242 242 242
42689-253 253 253 253 253 253 253 253 253 253 253 253
42690- 82 82 82 2 2 6 2 2 6 2 2 6
42691- 2 2 6 2 2 6 2 2 6 14 14 14
42692- 86 86 86 54 54 54 22 22 22 6 6 6
42693- 0 0 0 0 0 0 0 0 0 0 0 0
42694- 0 0 0 0 0 0 0 0 0 0 0 0
42695- 0 0 0 0 0 0 0 0 0 0 0 0
42696- 0 0 0 0 0 0 0 0 0 0 0 0
42697- 0 0 0 0 0 0 0 0 0 0 0 0
42698- 0 0 0 0 0 0 0 0 0 0 0 0
42699- 0 0 0 0 0 0 0 0 0 0 0 0
42700- 0 0 0 0 0 0 0 0 0 0 0 0
42701- 0 0 0 0 0 0 0 0 0 0 0 0
42702- 0 0 0 0 0 0 0 0 0 0 0 0
42703- 0 0 0 0 0 0 0 0 0 0 0 0
42704- 6 6 6 18 18 18 46 46 46 90 90 90
42705- 46 46 46 18 18 18 6 6 6 182 182 182
42706-253 253 253 246 246 246 206 206 206 190 190 190
42707-190 190 190 190 190 190 190 190 190 190 190 190
42708-206 206 206 231 231 231 250 250 250 253 253 253
42709-253 253 253 253 253 253 253 253 253 253 253 253
42710-202 202 202 14 14 14 2 2 6 2 2 6
42711- 2 2 6 2 2 6 2 2 6 2 2 6
42712- 42 42 42 86 86 86 42 42 42 18 18 18
42713- 6 6 6 0 0 0 0 0 0 0 0 0
42714- 0 0 0 0 0 0 0 0 0 0 0 0
42715- 0 0 0 0 0 0 0 0 0 0 0 0
42716- 0 0 0 0 0 0 0 0 0 0 0 0
42717- 0 0 0 0 0 0 0 0 0 0 0 0
42718- 0 0 0 0 0 0 0 0 0 0 0 0
42719- 0 0 0 0 0 0 0 0 0 0 0 0
42720- 0 0 0 0 0 0 0 0 0 0 0 0
42721- 0 0 0 0 0 0 0 0 0 0 0 0
42722- 0 0 0 0 0 0 0 0 0 0 0 0
42723- 0 0 0 0 0 0 0 0 0 6 6 6
42724- 14 14 14 38 38 38 74 74 74 66 66 66
42725- 2 2 6 6 6 6 90 90 90 250 250 250
42726-253 253 253 253 253 253 238 238 238 198 198 198
42727-190 190 190 190 190 190 195 195 195 221 221 221
42728-246 246 246 253 253 253 253 253 253 253 253 253
42729-253 253 253 253 253 253 253 253 253 253 253 253
42730-253 253 253 82 82 82 2 2 6 2 2 6
42731- 2 2 6 2 2 6 2 2 6 2 2 6
42732- 2 2 6 78 78 78 70 70 70 34 34 34
42733- 14 14 14 6 6 6 0 0 0 0 0 0
42734- 0 0 0 0 0 0 0 0 0 0 0 0
42735- 0 0 0 0 0 0 0 0 0 0 0 0
42736- 0 0 0 0 0 0 0 0 0 0 0 0
42737- 0 0 0 0 0 0 0 0 0 0 0 0
42738- 0 0 0 0 0 0 0 0 0 0 0 0
42739- 0 0 0 0 0 0 0 0 0 0 0 0
42740- 0 0 0 0 0 0 0 0 0 0 0 0
42741- 0 0 0 0 0 0 0 0 0 0 0 0
42742- 0 0 0 0 0 0 0 0 0 0 0 0
42743- 0 0 0 0 0 0 0 0 0 14 14 14
42744- 34 34 34 66 66 66 78 78 78 6 6 6
42745- 2 2 6 18 18 18 218 218 218 253 253 253
42746-253 253 253 253 253 253 253 253 253 246 246 246
42747-226 226 226 231 231 231 246 246 246 253 253 253
42748-253 253 253 253 253 253 253 253 253 253 253 253
42749-253 253 253 253 253 253 253 253 253 253 253 253
42750-253 253 253 178 178 178 2 2 6 2 2 6
42751- 2 2 6 2 2 6 2 2 6 2 2 6
42752- 2 2 6 18 18 18 90 90 90 62 62 62
42753- 30 30 30 10 10 10 0 0 0 0 0 0
42754- 0 0 0 0 0 0 0 0 0 0 0 0
42755- 0 0 0 0 0 0 0 0 0 0 0 0
42756- 0 0 0 0 0 0 0 0 0 0 0 0
42757- 0 0 0 0 0 0 0 0 0 0 0 0
42758- 0 0 0 0 0 0 0 0 0 0 0 0
42759- 0 0 0 0 0 0 0 0 0 0 0 0
42760- 0 0 0 0 0 0 0 0 0 0 0 0
42761- 0 0 0 0 0 0 0 0 0 0 0 0
42762- 0 0 0 0 0 0 0 0 0 0 0 0
42763- 0 0 0 0 0 0 10 10 10 26 26 26
42764- 58 58 58 90 90 90 18 18 18 2 2 6
42765- 2 2 6 110 110 110 253 253 253 253 253 253
42766-253 253 253 253 253 253 253 253 253 253 253 253
42767-250 250 250 253 253 253 253 253 253 253 253 253
42768-253 253 253 253 253 253 253 253 253 253 253 253
42769-253 253 253 253 253 253 253 253 253 253 253 253
42770-253 253 253 231 231 231 18 18 18 2 2 6
42771- 2 2 6 2 2 6 2 2 6 2 2 6
42772- 2 2 6 2 2 6 18 18 18 94 94 94
42773- 54 54 54 26 26 26 10 10 10 0 0 0
42774- 0 0 0 0 0 0 0 0 0 0 0 0
42775- 0 0 0 0 0 0 0 0 0 0 0 0
42776- 0 0 0 0 0 0 0 0 0 0 0 0
42777- 0 0 0 0 0 0 0 0 0 0 0 0
42778- 0 0 0 0 0 0 0 0 0 0 0 0
42779- 0 0 0 0 0 0 0 0 0 0 0 0
42780- 0 0 0 0 0 0 0 0 0 0 0 0
42781- 0 0 0 0 0 0 0 0 0 0 0 0
42782- 0 0 0 0 0 0 0 0 0 0 0 0
42783- 0 0 0 6 6 6 22 22 22 50 50 50
42784- 90 90 90 26 26 26 2 2 6 2 2 6
42785- 14 14 14 195 195 195 250 250 250 253 253 253
42786-253 253 253 253 253 253 253 253 253 253 253 253
42787-253 253 253 253 253 253 253 253 253 253 253 253
42788-253 253 253 253 253 253 253 253 253 253 253 253
42789-253 253 253 253 253 253 253 253 253 253 253 253
42790-250 250 250 242 242 242 54 54 54 2 2 6
42791- 2 2 6 2 2 6 2 2 6 2 2 6
42792- 2 2 6 2 2 6 2 2 6 38 38 38
42793- 86 86 86 50 50 50 22 22 22 6 6 6
42794- 0 0 0 0 0 0 0 0 0 0 0 0
42795- 0 0 0 0 0 0 0 0 0 0 0 0
42796- 0 0 0 0 0 0 0 0 0 0 0 0
42797- 0 0 0 0 0 0 0 0 0 0 0 0
42798- 0 0 0 0 0 0 0 0 0 0 0 0
42799- 0 0 0 0 0 0 0 0 0 0 0 0
42800- 0 0 0 0 0 0 0 0 0 0 0 0
42801- 0 0 0 0 0 0 0 0 0 0 0 0
42802- 0 0 0 0 0 0 0 0 0 0 0 0
42803- 6 6 6 14 14 14 38 38 38 82 82 82
42804- 34 34 34 2 2 6 2 2 6 2 2 6
42805- 42 42 42 195 195 195 246 246 246 253 253 253
42806-253 253 253 253 253 253 253 253 253 250 250 250
42807-242 242 242 242 242 242 250 250 250 253 253 253
42808-253 253 253 253 253 253 253 253 253 253 253 253
42809-253 253 253 250 250 250 246 246 246 238 238 238
42810-226 226 226 231 231 231 101 101 101 6 6 6
42811- 2 2 6 2 2 6 2 2 6 2 2 6
42812- 2 2 6 2 2 6 2 2 6 2 2 6
42813- 38 38 38 82 82 82 42 42 42 14 14 14
42814- 6 6 6 0 0 0 0 0 0 0 0 0
42815- 0 0 0 0 0 0 0 0 0 0 0 0
42816- 0 0 0 0 0 0 0 0 0 0 0 0
42817- 0 0 0 0 0 0 0 0 0 0 0 0
42818- 0 0 0 0 0 0 0 0 0 0 0 0
42819- 0 0 0 0 0 0 0 0 0 0 0 0
42820- 0 0 0 0 0 0 0 0 0 0 0 0
42821- 0 0 0 0 0 0 0 0 0 0 0 0
42822- 0 0 0 0 0 0 0 0 0 0 0 0
42823- 10 10 10 26 26 26 62 62 62 66 66 66
42824- 2 2 6 2 2 6 2 2 6 6 6 6
42825- 70 70 70 170 170 170 206 206 206 234 234 234
42826-246 246 246 250 250 250 250 250 250 238 238 238
42827-226 226 226 231 231 231 238 238 238 250 250 250
42828-250 250 250 250 250 250 246 246 246 231 231 231
42829-214 214 214 206 206 206 202 202 202 202 202 202
42830-198 198 198 202 202 202 182 182 182 18 18 18
42831- 2 2 6 2 2 6 2 2 6 2 2 6
42832- 2 2 6 2 2 6 2 2 6 2 2 6
42833- 2 2 6 62 62 62 66 66 66 30 30 30
42834- 10 10 10 0 0 0 0 0 0 0 0 0
42835- 0 0 0 0 0 0 0 0 0 0 0 0
42836- 0 0 0 0 0 0 0 0 0 0 0 0
42837- 0 0 0 0 0 0 0 0 0 0 0 0
42838- 0 0 0 0 0 0 0 0 0 0 0 0
42839- 0 0 0 0 0 0 0 0 0 0 0 0
42840- 0 0 0 0 0 0 0 0 0 0 0 0
42841- 0 0 0 0 0 0 0 0 0 0 0 0
42842- 0 0 0 0 0 0 0 0 0 0 0 0
42843- 14 14 14 42 42 42 82 82 82 18 18 18
42844- 2 2 6 2 2 6 2 2 6 10 10 10
42845- 94 94 94 182 182 182 218 218 218 242 242 242
42846-250 250 250 253 253 253 253 253 253 250 250 250
42847-234 234 234 253 253 253 253 253 253 253 253 253
42848-253 253 253 253 253 253 253 253 253 246 246 246
42849-238 238 238 226 226 226 210 210 210 202 202 202
42850-195 195 195 195 195 195 210 210 210 158 158 158
42851- 6 6 6 14 14 14 50 50 50 14 14 14
42852- 2 2 6 2 2 6 2 2 6 2 2 6
42853- 2 2 6 6 6 6 86 86 86 46 46 46
42854- 18 18 18 6 6 6 0 0 0 0 0 0
42855- 0 0 0 0 0 0 0 0 0 0 0 0
42856- 0 0 0 0 0 0 0 0 0 0 0 0
42857- 0 0 0 0 0 0 0 0 0 0 0 0
42858- 0 0 0 0 0 0 0 0 0 0 0 0
42859- 0 0 0 0 0 0 0 0 0 0 0 0
42860- 0 0 0 0 0 0 0 0 0 0 0 0
42861- 0 0 0 0 0 0 0 0 0 0 0 0
42862- 0 0 0 0 0 0 0 0 0 6 6 6
42863- 22 22 22 54 54 54 70 70 70 2 2 6
42864- 2 2 6 10 10 10 2 2 6 22 22 22
42865-166 166 166 231 231 231 250 250 250 253 253 253
42866-253 253 253 253 253 253 253 253 253 250 250 250
42867-242 242 242 253 253 253 253 253 253 253 253 253
42868-253 253 253 253 253 253 253 253 253 253 253 253
42869-253 253 253 253 253 253 253 253 253 246 246 246
42870-231 231 231 206 206 206 198 198 198 226 226 226
42871- 94 94 94 2 2 6 6 6 6 38 38 38
42872- 30 30 30 2 2 6 2 2 6 2 2 6
42873- 2 2 6 2 2 6 62 62 62 66 66 66
42874- 26 26 26 10 10 10 0 0 0 0 0 0
42875- 0 0 0 0 0 0 0 0 0 0 0 0
42876- 0 0 0 0 0 0 0 0 0 0 0 0
42877- 0 0 0 0 0 0 0 0 0 0 0 0
42878- 0 0 0 0 0 0 0 0 0 0 0 0
42879- 0 0 0 0 0 0 0 0 0 0 0 0
42880- 0 0 0 0 0 0 0 0 0 0 0 0
42881- 0 0 0 0 0 0 0 0 0 0 0 0
42882- 0 0 0 0 0 0 0 0 0 10 10 10
42883- 30 30 30 74 74 74 50 50 50 2 2 6
42884- 26 26 26 26 26 26 2 2 6 106 106 106
42885-238 238 238 253 253 253 253 253 253 253 253 253
42886-253 253 253 253 253 253 253 253 253 253 253 253
42887-253 253 253 253 253 253 253 253 253 253 253 253
42888-253 253 253 253 253 253 253 253 253 253 253 253
42889-253 253 253 253 253 253 253 253 253 253 253 253
42890-253 253 253 246 246 246 218 218 218 202 202 202
42891-210 210 210 14 14 14 2 2 6 2 2 6
42892- 30 30 30 22 22 22 2 2 6 2 2 6
42893- 2 2 6 2 2 6 18 18 18 86 86 86
42894- 42 42 42 14 14 14 0 0 0 0 0 0
42895- 0 0 0 0 0 0 0 0 0 0 0 0
42896- 0 0 0 0 0 0 0 0 0 0 0 0
42897- 0 0 0 0 0 0 0 0 0 0 0 0
42898- 0 0 0 0 0 0 0 0 0 0 0 0
42899- 0 0 0 0 0 0 0 0 0 0 0 0
42900- 0 0 0 0 0 0 0 0 0 0 0 0
42901- 0 0 0 0 0 0 0 0 0 0 0 0
42902- 0 0 0 0 0 0 0 0 0 14 14 14
42903- 42 42 42 90 90 90 22 22 22 2 2 6
42904- 42 42 42 2 2 6 18 18 18 218 218 218
42905-253 253 253 253 253 253 253 253 253 253 253 253
42906-253 253 253 253 253 253 253 253 253 253 253 253
42907-253 253 253 253 253 253 253 253 253 253 253 253
42908-253 253 253 253 253 253 253 253 253 253 253 253
42909-253 253 253 253 253 253 253 253 253 253 253 253
42910-253 253 253 253 253 253 250 250 250 221 221 221
42911-218 218 218 101 101 101 2 2 6 14 14 14
42912- 18 18 18 38 38 38 10 10 10 2 2 6
42913- 2 2 6 2 2 6 2 2 6 78 78 78
42914- 58 58 58 22 22 22 6 6 6 0 0 0
42915- 0 0 0 0 0 0 0 0 0 0 0 0
42916- 0 0 0 0 0 0 0 0 0 0 0 0
42917- 0 0 0 0 0 0 0 0 0 0 0 0
42918- 0 0 0 0 0 0 0 0 0 0 0 0
42919- 0 0 0 0 0 0 0 0 0 0 0 0
42920- 0 0 0 0 0 0 0 0 0 0 0 0
42921- 0 0 0 0 0 0 0 0 0 0 0 0
42922- 0 0 0 0 0 0 6 6 6 18 18 18
42923- 54 54 54 82 82 82 2 2 6 26 26 26
42924- 22 22 22 2 2 6 123 123 123 253 253 253
42925-253 253 253 253 253 253 253 253 253 253 253 253
42926-253 253 253 253 253 253 253 253 253 253 253 253
42927-253 253 253 253 253 253 253 253 253 253 253 253
42928-253 253 253 253 253 253 253 253 253 253 253 253
42929-253 253 253 253 253 253 253 253 253 253 253 253
42930-253 253 253 253 253 253 253 253 253 250 250 250
42931-238 238 238 198 198 198 6 6 6 38 38 38
42932- 58 58 58 26 26 26 38 38 38 2 2 6
42933- 2 2 6 2 2 6 2 2 6 46 46 46
42934- 78 78 78 30 30 30 10 10 10 0 0 0
42935- 0 0 0 0 0 0 0 0 0 0 0 0
42936- 0 0 0 0 0 0 0 0 0 0 0 0
42937- 0 0 0 0 0 0 0 0 0 0 0 0
42938- 0 0 0 0 0 0 0 0 0 0 0 0
42939- 0 0 0 0 0 0 0 0 0 0 0 0
42940- 0 0 0 0 0 0 0 0 0 0 0 0
42941- 0 0 0 0 0 0 0 0 0 0 0 0
42942- 0 0 0 0 0 0 10 10 10 30 30 30
42943- 74 74 74 58 58 58 2 2 6 42 42 42
42944- 2 2 6 22 22 22 231 231 231 253 253 253
42945-253 253 253 253 253 253 253 253 253 253 253 253
42946-253 253 253 253 253 253 253 253 253 250 250 250
42947-253 253 253 253 253 253 253 253 253 253 253 253
42948-253 253 253 253 253 253 253 253 253 253 253 253
42949-253 253 253 253 253 253 253 253 253 253 253 253
42950-253 253 253 253 253 253 253 253 253 253 253 253
42951-253 253 253 246 246 246 46 46 46 38 38 38
42952- 42 42 42 14 14 14 38 38 38 14 14 14
42953- 2 2 6 2 2 6 2 2 6 6 6 6
42954- 86 86 86 46 46 46 14 14 14 0 0 0
42955- 0 0 0 0 0 0 0 0 0 0 0 0
42956- 0 0 0 0 0 0 0 0 0 0 0 0
42957- 0 0 0 0 0 0 0 0 0 0 0 0
42958- 0 0 0 0 0 0 0 0 0 0 0 0
42959- 0 0 0 0 0 0 0 0 0 0 0 0
42960- 0 0 0 0 0 0 0 0 0 0 0 0
42961- 0 0 0 0 0 0 0 0 0 0 0 0
42962- 0 0 0 6 6 6 14 14 14 42 42 42
42963- 90 90 90 18 18 18 18 18 18 26 26 26
42964- 2 2 6 116 116 116 253 253 253 253 253 253
42965-253 253 253 253 253 253 253 253 253 253 253 253
42966-253 253 253 253 253 253 250 250 250 238 238 238
42967-253 253 253 253 253 253 253 253 253 253 253 253
42968-253 253 253 253 253 253 253 253 253 253 253 253
42969-253 253 253 253 253 253 253 253 253 253 253 253
42970-253 253 253 253 253 253 253 253 253 253 253 253
42971-253 253 253 253 253 253 94 94 94 6 6 6
42972- 2 2 6 2 2 6 10 10 10 34 34 34
42973- 2 2 6 2 2 6 2 2 6 2 2 6
42974- 74 74 74 58 58 58 22 22 22 6 6 6
42975- 0 0 0 0 0 0 0 0 0 0 0 0
42976- 0 0 0 0 0 0 0 0 0 0 0 0
42977- 0 0 0 0 0 0 0 0 0 0 0 0
42978- 0 0 0 0 0 0 0 0 0 0 0 0
42979- 0 0 0 0 0 0 0 0 0 0 0 0
42980- 0 0 0 0 0 0 0 0 0 0 0 0
42981- 0 0 0 0 0 0 0 0 0 0 0 0
42982- 0 0 0 10 10 10 26 26 26 66 66 66
42983- 82 82 82 2 2 6 38 38 38 6 6 6
42984- 14 14 14 210 210 210 253 253 253 253 253 253
42985-253 253 253 253 253 253 253 253 253 253 253 253
42986-253 253 253 253 253 253 246 246 246 242 242 242
42987-253 253 253 253 253 253 253 253 253 253 253 253
42988-253 253 253 253 253 253 253 253 253 253 253 253
42989-253 253 253 253 253 253 253 253 253 253 253 253
42990-253 253 253 253 253 253 253 253 253 253 253 253
42991-253 253 253 253 253 253 144 144 144 2 2 6
42992- 2 2 6 2 2 6 2 2 6 46 46 46
42993- 2 2 6 2 2 6 2 2 6 2 2 6
42994- 42 42 42 74 74 74 30 30 30 10 10 10
42995- 0 0 0 0 0 0 0 0 0 0 0 0
42996- 0 0 0 0 0 0 0 0 0 0 0 0
42997- 0 0 0 0 0 0 0 0 0 0 0 0
42998- 0 0 0 0 0 0 0 0 0 0 0 0
42999- 0 0 0 0 0 0 0 0 0 0 0 0
43000- 0 0 0 0 0 0 0 0 0 0 0 0
43001- 0 0 0 0 0 0 0 0 0 0 0 0
43002- 6 6 6 14 14 14 42 42 42 90 90 90
43003- 26 26 26 6 6 6 42 42 42 2 2 6
43004- 74 74 74 250 250 250 253 253 253 253 253 253
43005-253 253 253 253 253 253 253 253 253 253 253 253
43006-253 253 253 253 253 253 242 242 242 242 242 242
43007-253 253 253 253 253 253 253 253 253 253 253 253
43008-253 253 253 253 253 253 253 253 253 253 253 253
43009-253 253 253 253 253 253 253 253 253 253 253 253
43010-253 253 253 253 253 253 253 253 253 253 253 253
43011-253 253 253 253 253 253 182 182 182 2 2 6
43012- 2 2 6 2 2 6 2 2 6 46 46 46
43013- 2 2 6 2 2 6 2 2 6 2 2 6
43014- 10 10 10 86 86 86 38 38 38 10 10 10
43015- 0 0 0 0 0 0 0 0 0 0 0 0
43016- 0 0 0 0 0 0 0 0 0 0 0 0
43017- 0 0 0 0 0 0 0 0 0 0 0 0
43018- 0 0 0 0 0 0 0 0 0 0 0 0
43019- 0 0 0 0 0 0 0 0 0 0 0 0
43020- 0 0 0 0 0 0 0 0 0 0 0 0
43021- 0 0 0 0 0 0 0 0 0 0 0 0
43022- 10 10 10 26 26 26 66 66 66 82 82 82
43023- 2 2 6 22 22 22 18 18 18 2 2 6
43024-149 149 149 253 253 253 253 253 253 253 253 253
43025-253 253 253 253 253 253 253 253 253 253 253 253
43026-253 253 253 253 253 253 234 234 234 242 242 242
43027-253 253 253 253 253 253 253 253 253 253 253 253
43028-253 253 253 253 253 253 253 253 253 253 253 253
43029-253 253 253 253 253 253 253 253 253 253 253 253
43030-253 253 253 253 253 253 253 253 253 253 253 253
43031-253 253 253 253 253 253 206 206 206 2 2 6
43032- 2 2 6 2 2 6 2 2 6 38 38 38
43033- 2 2 6 2 2 6 2 2 6 2 2 6
43034- 6 6 6 86 86 86 46 46 46 14 14 14
43035- 0 0 0 0 0 0 0 0 0 0 0 0
43036- 0 0 0 0 0 0 0 0 0 0 0 0
43037- 0 0 0 0 0 0 0 0 0 0 0 0
43038- 0 0 0 0 0 0 0 0 0 0 0 0
43039- 0 0 0 0 0 0 0 0 0 0 0 0
43040- 0 0 0 0 0 0 0 0 0 0 0 0
43041- 0 0 0 0 0 0 0 0 0 6 6 6
43042- 18 18 18 46 46 46 86 86 86 18 18 18
43043- 2 2 6 34 34 34 10 10 10 6 6 6
43044-210 210 210 253 253 253 253 253 253 253 253 253
43045-253 253 253 253 253 253 253 253 253 253 253 253
43046-253 253 253 253 253 253 234 234 234 242 242 242
43047-253 253 253 253 253 253 253 253 253 253 253 253
43048-253 253 253 253 253 253 253 253 253 253 253 253
43049-253 253 253 253 253 253 253 253 253 253 253 253
43050-253 253 253 253 253 253 253 253 253 253 253 253
43051-253 253 253 253 253 253 221 221 221 6 6 6
43052- 2 2 6 2 2 6 6 6 6 30 30 30
43053- 2 2 6 2 2 6 2 2 6 2 2 6
43054- 2 2 6 82 82 82 54 54 54 18 18 18
43055- 6 6 6 0 0 0 0 0 0 0 0 0
43056- 0 0 0 0 0 0 0 0 0 0 0 0
43057- 0 0 0 0 0 0 0 0 0 0 0 0
43058- 0 0 0 0 0 0 0 0 0 0 0 0
43059- 0 0 0 0 0 0 0 0 0 0 0 0
43060- 0 0 0 0 0 0 0 0 0 0 0 0
43061- 0 0 0 0 0 0 0 0 0 10 10 10
43062- 26 26 26 66 66 66 62 62 62 2 2 6
43063- 2 2 6 38 38 38 10 10 10 26 26 26
43064-238 238 238 253 253 253 253 253 253 253 253 253
43065-253 253 253 253 253 253 253 253 253 253 253 253
43066-253 253 253 253 253 253 231 231 231 238 238 238
43067-253 253 253 253 253 253 253 253 253 253 253 253
43068-253 253 253 253 253 253 253 253 253 253 253 253
43069-253 253 253 253 253 253 253 253 253 253 253 253
43070-253 253 253 253 253 253 253 253 253 253 253 253
43071-253 253 253 253 253 253 231 231 231 6 6 6
43072- 2 2 6 2 2 6 10 10 10 30 30 30
43073- 2 2 6 2 2 6 2 2 6 2 2 6
43074- 2 2 6 66 66 66 58 58 58 22 22 22
43075- 6 6 6 0 0 0 0 0 0 0 0 0
43076- 0 0 0 0 0 0 0 0 0 0 0 0
43077- 0 0 0 0 0 0 0 0 0 0 0 0
43078- 0 0 0 0 0 0 0 0 0 0 0 0
43079- 0 0 0 0 0 0 0 0 0 0 0 0
43080- 0 0 0 0 0 0 0 0 0 0 0 0
43081- 0 0 0 0 0 0 0 0 0 10 10 10
43082- 38 38 38 78 78 78 6 6 6 2 2 6
43083- 2 2 6 46 46 46 14 14 14 42 42 42
43084-246 246 246 253 253 253 253 253 253 253 253 253
43085-253 253 253 253 253 253 253 253 253 253 253 253
43086-253 253 253 253 253 253 231 231 231 242 242 242
43087-253 253 253 253 253 253 253 253 253 253 253 253
43088-253 253 253 253 253 253 253 253 253 253 253 253
43089-253 253 253 253 253 253 253 253 253 253 253 253
43090-253 253 253 253 253 253 253 253 253 253 253 253
43091-253 253 253 253 253 253 234 234 234 10 10 10
43092- 2 2 6 2 2 6 22 22 22 14 14 14
43093- 2 2 6 2 2 6 2 2 6 2 2 6
43094- 2 2 6 66 66 66 62 62 62 22 22 22
43095- 6 6 6 0 0 0 0 0 0 0 0 0
43096- 0 0 0 0 0 0 0 0 0 0 0 0
43097- 0 0 0 0 0 0 0 0 0 0 0 0
43098- 0 0 0 0 0 0 0 0 0 0 0 0
43099- 0 0 0 0 0 0 0 0 0 0 0 0
43100- 0 0 0 0 0 0 0 0 0 0 0 0
43101- 0 0 0 0 0 0 6 6 6 18 18 18
43102- 50 50 50 74 74 74 2 2 6 2 2 6
43103- 14 14 14 70 70 70 34 34 34 62 62 62
43104-250 250 250 253 253 253 253 253 253 253 253 253
43105-253 253 253 253 253 253 253 253 253 253 253 253
43106-253 253 253 253 253 253 231 231 231 246 246 246
43107-253 253 253 253 253 253 253 253 253 253 253 253
43108-253 253 253 253 253 253 253 253 253 253 253 253
43109-253 253 253 253 253 253 253 253 253 253 253 253
43110-253 253 253 253 253 253 253 253 253 253 253 253
43111-253 253 253 253 253 253 234 234 234 14 14 14
43112- 2 2 6 2 2 6 30 30 30 2 2 6
43113- 2 2 6 2 2 6 2 2 6 2 2 6
43114- 2 2 6 66 66 66 62 62 62 22 22 22
43115- 6 6 6 0 0 0 0 0 0 0 0 0
43116- 0 0 0 0 0 0 0 0 0 0 0 0
43117- 0 0 0 0 0 0 0 0 0 0 0 0
43118- 0 0 0 0 0 0 0 0 0 0 0 0
43119- 0 0 0 0 0 0 0 0 0 0 0 0
43120- 0 0 0 0 0 0 0 0 0 0 0 0
43121- 0 0 0 0 0 0 6 6 6 18 18 18
43122- 54 54 54 62 62 62 2 2 6 2 2 6
43123- 2 2 6 30 30 30 46 46 46 70 70 70
43124-250 250 250 253 253 253 253 253 253 253 253 253
43125-253 253 253 253 253 253 253 253 253 253 253 253
43126-253 253 253 253 253 253 231 231 231 246 246 246
43127-253 253 253 253 253 253 253 253 253 253 253 253
43128-253 253 253 253 253 253 253 253 253 253 253 253
43129-253 253 253 253 253 253 253 253 253 253 253 253
43130-253 253 253 253 253 253 253 253 253 253 253 253
43131-253 253 253 253 253 253 226 226 226 10 10 10
43132- 2 2 6 6 6 6 30 30 30 2 2 6
43133- 2 2 6 2 2 6 2 2 6 2 2 6
43134- 2 2 6 66 66 66 58 58 58 22 22 22
43135- 6 6 6 0 0 0 0 0 0 0 0 0
43136- 0 0 0 0 0 0 0 0 0 0 0 0
43137- 0 0 0 0 0 0 0 0 0 0 0 0
43138- 0 0 0 0 0 0 0 0 0 0 0 0
43139- 0 0 0 0 0 0 0 0 0 0 0 0
43140- 0 0 0 0 0 0 0 0 0 0 0 0
43141- 0 0 0 0 0 0 6 6 6 22 22 22
43142- 58 58 58 62 62 62 2 2 6 2 2 6
43143- 2 2 6 2 2 6 30 30 30 78 78 78
43144-250 250 250 253 253 253 253 253 253 253 253 253
43145-253 253 253 253 253 253 253 253 253 253 253 253
43146-253 253 253 253 253 253 231 231 231 246 246 246
43147-253 253 253 253 253 253 253 253 253 253 253 253
43148-253 253 253 253 253 253 253 253 253 253 253 253
43149-253 253 253 253 253 253 253 253 253 253 253 253
43150-253 253 253 253 253 253 253 253 253 253 253 253
43151-253 253 253 253 253 253 206 206 206 2 2 6
43152- 22 22 22 34 34 34 18 14 6 22 22 22
43153- 26 26 26 18 18 18 6 6 6 2 2 6
43154- 2 2 6 82 82 82 54 54 54 18 18 18
43155- 6 6 6 0 0 0 0 0 0 0 0 0
43156- 0 0 0 0 0 0 0 0 0 0 0 0
43157- 0 0 0 0 0 0 0 0 0 0 0 0
43158- 0 0 0 0 0 0 0 0 0 0 0 0
43159- 0 0 0 0 0 0 0 0 0 0 0 0
43160- 0 0 0 0 0 0 0 0 0 0 0 0
43161- 0 0 0 0 0 0 6 6 6 26 26 26
43162- 62 62 62 106 106 106 74 54 14 185 133 11
43163-210 162 10 121 92 8 6 6 6 62 62 62
43164-238 238 238 253 253 253 253 253 253 253 253 253
43165-253 253 253 253 253 253 253 253 253 253 253 253
43166-253 253 253 253 253 253 231 231 231 246 246 246
43167-253 253 253 253 253 253 253 253 253 253 253 253
43168-253 253 253 253 253 253 253 253 253 253 253 253
43169-253 253 253 253 253 253 253 253 253 253 253 253
43170-253 253 253 253 253 253 253 253 253 253 253 253
43171-253 253 253 253 253 253 158 158 158 18 18 18
43172- 14 14 14 2 2 6 2 2 6 2 2 6
43173- 6 6 6 18 18 18 66 66 66 38 38 38
43174- 6 6 6 94 94 94 50 50 50 18 18 18
43175- 6 6 6 0 0 0 0 0 0 0 0 0
43176- 0 0 0 0 0 0 0 0 0 0 0 0
43177- 0 0 0 0 0 0 0 0 0 0 0 0
43178- 0 0 0 0 0 0 0 0 0 0 0 0
43179- 0 0 0 0 0 0 0 0 0 0 0 0
43180- 0 0 0 0 0 0 0 0 0 6 6 6
43181- 10 10 10 10 10 10 18 18 18 38 38 38
43182- 78 78 78 142 134 106 216 158 10 242 186 14
43183-246 190 14 246 190 14 156 118 10 10 10 10
43184- 90 90 90 238 238 238 253 253 253 253 253 253
43185-253 253 253 253 253 253 253 253 253 253 253 253
43186-253 253 253 253 253 253 231 231 231 250 250 250
43187-253 253 253 253 253 253 253 253 253 253 253 253
43188-253 253 253 253 253 253 253 253 253 253 253 253
43189-253 253 253 253 253 253 253 253 253 253 253 253
43190-253 253 253 253 253 253 253 253 253 246 230 190
43191-238 204 91 238 204 91 181 142 44 37 26 9
43192- 2 2 6 2 2 6 2 2 6 2 2 6
43193- 2 2 6 2 2 6 38 38 38 46 46 46
43194- 26 26 26 106 106 106 54 54 54 18 18 18
43195- 6 6 6 0 0 0 0 0 0 0 0 0
43196- 0 0 0 0 0 0 0 0 0 0 0 0
43197- 0 0 0 0 0 0 0 0 0 0 0 0
43198- 0 0 0 0 0 0 0 0 0 0 0 0
43199- 0 0 0 0 0 0 0 0 0 0 0 0
43200- 0 0 0 6 6 6 14 14 14 22 22 22
43201- 30 30 30 38 38 38 50 50 50 70 70 70
43202-106 106 106 190 142 34 226 170 11 242 186 14
43203-246 190 14 246 190 14 246 190 14 154 114 10
43204- 6 6 6 74 74 74 226 226 226 253 253 253
43205-253 253 253 253 253 253 253 253 253 253 253 253
43206-253 253 253 253 253 253 231 231 231 250 250 250
43207-253 253 253 253 253 253 253 253 253 253 253 253
43208-253 253 253 253 253 253 253 253 253 253 253 253
43209-253 253 253 253 253 253 253 253 253 253 253 253
43210-253 253 253 253 253 253 253 253 253 228 184 62
43211-241 196 14 241 208 19 232 195 16 38 30 10
43212- 2 2 6 2 2 6 2 2 6 2 2 6
43213- 2 2 6 6 6 6 30 30 30 26 26 26
43214-203 166 17 154 142 90 66 66 66 26 26 26
43215- 6 6 6 0 0 0 0 0 0 0 0 0
43216- 0 0 0 0 0 0 0 0 0 0 0 0
43217- 0 0 0 0 0 0 0 0 0 0 0 0
43218- 0 0 0 0 0 0 0 0 0 0 0 0
43219- 0 0 0 0 0 0 0 0 0 0 0 0
43220- 6 6 6 18 18 18 38 38 38 58 58 58
43221- 78 78 78 86 86 86 101 101 101 123 123 123
43222-175 146 61 210 150 10 234 174 13 246 186 14
43223-246 190 14 246 190 14 246 190 14 238 190 10
43224-102 78 10 2 2 6 46 46 46 198 198 198
43225-253 253 253 253 253 253 253 253 253 253 253 253
43226-253 253 253 253 253 253 234 234 234 242 242 242
43227-253 253 253 253 253 253 253 253 253 253 253 253
43228-253 253 253 253 253 253 253 253 253 253 253 253
43229-253 253 253 253 253 253 253 253 253 253 253 253
43230-253 253 253 253 253 253 253 253 253 224 178 62
43231-242 186 14 241 196 14 210 166 10 22 18 6
43232- 2 2 6 2 2 6 2 2 6 2 2 6
43233- 2 2 6 2 2 6 6 6 6 121 92 8
43234-238 202 15 232 195 16 82 82 82 34 34 34
43235- 10 10 10 0 0 0 0 0 0 0 0 0
43236- 0 0 0 0 0 0 0 0 0 0 0 0
43237- 0 0 0 0 0 0 0 0 0 0 0 0
43238- 0 0 0 0 0 0 0 0 0 0 0 0
43239- 0 0 0 0 0 0 0 0 0 0 0 0
43240- 14 14 14 38 38 38 70 70 70 154 122 46
43241-190 142 34 200 144 11 197 138 11 197 138 11
43242-213 154 11 226 170 11 242 186 14 246 190 14
43243-246 190 14 246 190 14 246 190 14 246 190 14
43244-225 175 15 46 32 6 2 2 6 22 22 22
43245-158 158 158 250 250 250 253 253 253 253 253 253
43246-253 253 253 253 253 253 253 253 253 253 253 253
43247-253 253 253 253 253 253 253 253 253 253 253 253
43248-253 253 253 253 253 253 253 253 253 253 253 253
43249-253 253 253 253 253 253 253 253 253 253 253 253
43250-253 253 253 250 250 250 242 242 242 224 178 62
43251-239 182 13 236 186 11 213 154 11 46 32 6
43252- 2 2 6 2 2 6 2 2 6 2 2 6
43253- 2 2 6 2 2 6 61 42 6 225 175 15
43254-238 190 10 236 186 11 112 100 78 42 42 42
43255- 14 14 14 0 0 0 0 0 0 0 0 0
43256- 0 0 0 0 0 0 0 0 0 0 0 0
43257- 0 0 0 0 0 0 0 0 0 0 0 0
43258- 0 0 0 0 0 0 0 0 0 0 0 0
43259- 0 0 0 0 0 0 0 0 0 6 6 6
43260- 22 22 22 54 54 54 154 122 46 213 154 11
43261-226 170 11 230 174 11 226 170 11 226 170 11
43262-236 178 12 242 186 14 246 190 14 246 190 14
43263-246 190 14 246 190 14 246 190 14 246 190 14
43264-241 196 14 184 144 12 10 10 10 2 2 6
43265- 6 6 6 116 116 116 242 242 242 253 253 253
43266-253 253 253 253 253 253 253 253 253 253 253 253
43267-253 253 253 253 253 253 253 253 253 253 253 253
43268-253 253 253 253 253 253 253 253 253 253 253 253
43269-253 253 253 253 253 253 253 253 253 253 253 253
43270-253 253 253 231 231 231 198 198 198 214 170 54
43271-236 178 12 236 178 12 210 150 10 137 92 6
43272- 18 14 6 2 2 6 2 2 6 2 2 6
43273- 6 6 6 70 47 6 200 144 11 236 178 12
43274-239 182 13 239 182 13 124 112 88 58 58 58
43275- 22 22 22 6 6 6 0 0 0 0 0 0
43276- 0 0 0 0 0 0 0 0 0 0 0 0
43277- 0 0 0 0 0 0 0 0 0 0 0 0
43278- 0 0 0 0 0 0 0 0 0 0 0 0
43279- 0 0 0 0 0 0 0 0 0 10 10 10
43280- 30 30 30 70 70 70 180 133 36 226 170 11
43281-239 182 13 242 186 14 242 186 14 246 186 14
43282-246 190 14 246 190 14 246 190 14 246 190 14
43283-246 190 14 246 190 14 246 190 14 246 190 14
43284-246 190 14 232 195 16 98 70 6 2 2 6
43285- 2 2 6 2 2 6 66 66 66 221 221 221
43286-253 253 253 253 253 253 253 253 253 253 253 253
43287-253 253 253 253 253 253 253 253 253 253 253 253
43288-253 253 253 253 253 253 253 253 253 253 253 253
43289-253 253 253 253 253 253 253 253 253 253 253 253
43290-253 253 253 206 206 206 198 198 198 214 166 58
43291-230 174 11 230 174 11 216 158 10 192 133 9
43292-163 110 8 116 81 8 102 78 10 116 81 8
43293-167 114 7 197 138 11 226 170 11 239 182 13
43294-242 186 14 242 186 14 162 146 94 78 78 78
43295- 34 34 34 14 14 14 6 6 6 0 0 0
43296- 0 0 0 0 0 0 0 0 0 0 0 0
43297- 0 0 0 0 0 0 0 0 0 0 0 0
43298- 0 0 0 0 0 0 0 0 0 0 0 0
43299- 0 0 0 0 0 0 0 0 0 6 6 6
43300- 30 30 30 78 78 78 190 142 34 226 170 11
43301-239 182 13 246 190 14 246 190 14 246 190 14
43302-246 190 14 246 190 14 246 190 14 246 190 14
43303-246 190 14 246 190 14 246 190 14 246 190 14
43304-246 190 14 241 196 14 203 166 17 22 18 6
43305- 2 2 6 2 2 6 2 2 6 38 38 38
43306-218 218 218 253 253 253 253 253 253 253 253 253
43307-253 253 253 253 253 253 253 253 253 253 253 253
43308-253 253 253 253 253 253 253 253 253 253 253 253
43309-253 253 253 253 253 253 253 253 253 253 253 253
43310-250 250 250 206 206 206 198 198 198 202 162 69
43311-226 170 11 236 178 12 224 166 10 210 150 10
43312-200 144 11 197 138 11 192 133 9 197 138 11
43313-210 150 10 226 170 11 242 186 14 246 190 14
43314-246 190 14 246 186 14 225 175 15 124 112 88
43315- 62 62 62 30 30 30 14 14 14 6 6 6
43316- 0 0 0 0 0 0 0 0 0 0 0 0
43317- 0 0 0 0 0 0 0 0 0 0 0 0
43318- 0 0 0 0 0 0 0 0 0 0 0 0
43319- 0 0 0 0 0 0 0 0 0 10 10 10
43320- 30 30 30 78 78 78 174 135 50 224 166 10
43321-239 182 13 246 190 14 246 190 14 246 190 14
43322-246 190 14 246 190 14 246 190 14 246 190 14
43323-246 190 14 246 190 14 246 190 14 246 190 14
43324-246 190 14 246 190 14 241 196 14 139 102 15
43325- 2 2 6 2 2 6 2 2 6 2 2 6
43326- 78 78 78 250 250 250 253 253 253 253 253 253
43327-253 253 253 253 253 253 253 253 253 253 253 253
43328-253 253 253 253 253 253 253 253 253 253 253 253
43329-253 253 253 253 253 253 253 253 253 253 253 253
43330-250 250 250 214 214 214 198 198 198 190 150 46
43331-219 162 10 236 178 12 234 174 13 224 166 10
43332-216 158 10 213 154 11 213 154 11 216 158 10
43333-226 170 11 239 182 13 246 190 14 246 190 14
43334-246 190 14 246 190 14 242 186 14 206 162 42
43335-101 101 101 58 58 58 30 30 30 14 14 14
43336- 6 6 6 0 0 0 0 0 0 0 0 0
43337- 0 0 0 0 0 0 0 0 0 0 0 0
43338- 0 0 0 0 0 0 0 0 0 0 0 0
43339- 0 0 0 0 0 0 0 0 0 10 10 10
43340- 30 30 30 74 74 74 174 135 50 216 158 10
43341-236 178 12 246 190 14 246 190 14 246 190 14
43342-246 190 14 246 190 14 246 190 14 246 190 14
43343-246 190 14 246 190 14 246 190 14 246 190 14
43344-246 190 14 246 190 14 241 196 14 226 184 13
43345- 61 42 6 2 2 6 2 2 6 2 2 6
43346- 22 22 22 238 238 238 253 253 253 253 253 253
43347-253 253 253 253 253 253 253 253 253 253 253 253
43348-253 253 253 253 253 253 253 253 253 253 253 253
43349-253 253 253 253 253 253 253 253 253 253 253 253
43350-253 253 253 226 226 226 187 187 187 180 133 36
43351-216 158 10 236 178 12 239 182 13 236 178 12
43352-230 174 11 226 170 11 226 170 11 230 174 11
43353-236 178 12 242 186 14 246 190 14 246 190 14
43354-246 190 14 246 190 14 246 186 14 239 182 13
43355-206 162 42 106 106 106 66 66 66 34 34 34
43356- 14 14 14 6 6 6 0 0 0 0 0 0
43357- 0 0 0 0 0 0 0 0 0 0 0 0
43358- 0 0 0 0 0 0 0 0 0 0 0 0
43359- 0 0 0 0 0 0 0 0 0 6 6 6
43360- 26 26 26 70 70 70 163 133 67 213 154 11
43361-236 178 12 246 190 14 246 190 14 246 190 14
43362-246 190 14 246 190 14 246 190 14 246 190 14
43363-246 190 14 246 190 14 246 190 14 246 190 14
43364-246 190 14 246 190 14 246 190 14 241 196 14
43365-190 146 13 18 14 6 2 2 6 2 2 6
43366- 46 46 46 246 246 246 253 253 253 253 253 253
43367-253 253 253 253 253 253 253 253 253 253 253 253
43368-253 253 253 253 253 253 253 253 253 253 253 253
43369-253 253 253 253 253 253 253 253 253 253 253 253
43370-253 253 253 221 221 221 86 86 86 156 107 11
43371-216 158 10 236 178 12 242 186 14 246 186 14
43372-242 186 14 239 182 13 239 182 13 242 186 14
43373-242 186 14 246 186 14 246 190 14 246 190 14
43374-246 190 14 246 190 14 246 190 14 246 190 14
43375-242 186 14 225 175 15 142 122 72 66 66 66
43376- 30 30 30 10 10 10 0 0 0 0 0 0
43377- 0 0 0 0 0 0 0 0 0 0 0 0
43378- 0 0 0 0 0 0 0 0 0 0 0 0
43379- 0 0 0 0 0 0 0 0 0 6 6 6
43380- 26 26 26 70 70 70 163 133 67 210 150 10
43381-236 178 12 246 190 14 246 190 14 246 190 14
43382-246 190 14 246 190 14 246 190 14 246 190 14
43383-246 190 14 246 190 14 246 190 14 246 190 14
43384-246 190 14 246 190 14 246 190 14 246 190 14
43385-232 195 16 121 92 8 34 34 34 106 106 106
43386-221 221 221 253 253 253 253 253 253 253 253 253
43387-253 253 253 253 253 253 253 253 253 253 253 253
43388-253 253 253 253 253 253 253 253 253 253 253 253
43389-253 253 253 253 253 253 253 253 253 253 253 253
43390-242 242 242 82 82 82 18 14 6 163 110 8
43391-216 158 10 236 178 12 242 186 14 246 190 14
43392-246 190 14 246 190 14 246 190 14 246 190 14
43393-246 190 14 246 190 14 246 190 14 246 190 14
43394-246 190 14 246 190 14 246 190 14 246 190 14
43395-246 190 14 246 190 14 242 186 14 163 133 67
43396- 46 46 46 18 18 18 6 6 6 0 0 0
43397- 0 0 0 0 0 0 0 0 0 0 0 0
43398- 0 0 0 0 0 0 0 0 0 0 0 0
43399- 0 0 0 0 0 0 0 0 0 10 10 10
43400- 30 30 30 78 78 78 163 133 67 210 150 10
43401-236 178 12 246 186 14 246 190 14 246 190 14
43402-246 190 14 246 190 14 246 190 14 246 190 14
43403-246 190 14 246 190 14 246 190 14 246 190 14
43404-246 190 14 246 190 14 246 190 14 246 190 14
43405-241 196 14 215 174 15 190 178 144 253 253 253
43406-253 253 253 253 253 253 253 253 253 253 253 253
43407-253 253 253 253 253 253 253 253 253 253 253 253
43408-253 253 253 253 253 253 253 253 253 253 253 253
43409-253 253 253 253 253 253 253 253 253 218 218 218
43410- 58 58 58 2 2 6 22 18 6 167 114 7
43411-216 158 10 236 178 12 246 186 14 246 190 14
43412-246 190 14 246 190 14 246 190 14 246 190 14
43413-246 190 14 246 190 14 246 190 14 246 190 14
43414-246 190 14 246 190 14 246 190 14 246 190 14
43415-246 190 14 246 186 14 242 186 14 190 150 46
43416- 54 54 54 22 22 22 6 6 6 0 0 0
43417- 0 0 0 0 0 0 0 0 0 0 0 0
43418- 0 0 0 0 0 0 0 0 0 0 0 0
43419- 0 0 0 0 0 0 0 0 0 14 14 14
43420- 38 38 38 86 86 86 180 133 36 213 154 11
43421-236 178 12 246 186 14 246 190 14 246 190 14
43422-246 190 14 246 190 14 246 190 14 246 190 14
43423-246 190 14 246 190 14 246 190 14 246 190 14
43424-246 190 14 246 190 14 246 190 14 246 190 14
43425-246 190 14 232 195 16 190 146 13 214 214 214
43426-253 253 253 253 253 253 253 253 253 253 253 253
43427-253 253 253 253 253 253 253 253 253 253 253 253
43428-253 253 253 253 253 253 253 253 253 253 253 253
43429-253 253 253 250 250 250 170 170 170 26 26 26
43430- 2 2 6 2 2 6 37 26 9 163 110 8
43431-219 162 10 239 182 13 246 186 14 246 190 14
43432-246 190 14 246 190 14 246 190 14 246 190 14
43433-246 190 14 246 190 14 246 190 14 246 190 14
43434-246 190 14 246 190 14 246 190 14 246 190 14
43435-246 186 14 236 178 12 224 166 10 142 122 72
43436- 46 46 46 18 18 18 6 6 6 0 0 0
43437- 0 0 0 0 0 0 0 0 0 0 0 0
43438- 0 0 0 0 0 0 0 0 0 0 0 0
43439- 0 0 0 0 0 0 6 6 6 18 18 18
43440- 50 50 50 109 106 95 192 133 9 224 166 10
43441-242 186 14 246 190 14 246 190 14 246 190 14
43442-246 190 14 246 190 14 246 190 14 246 190 14
43443-246 190 14 246 190 14 246 190 14 246 190 14
43444-246 190 14 246 190 14 246 190 14 246 190 14
43445-242 186 14 226 184 13 210 162 10 142 110 46
43446-226 226 226 253 253 253 253 253 253 253 253 253
43447-253 253 253 253 253 253 253 253 253 253 253 253
43448-253 253 253 253 253 253 253 253 253 253 253 253
43449-198 198 198 66 66 66 2 2 6 2 2 6
43450- 2 2 6 2 2 6 50 34 6 156 107 11
43451-219 162 10 239 182 13 246 186 14 246 190 14
43452-246 190 14 246 190 14 246 190 14 246 190 14
43453-246 190 14 246 190 14 246 190 14 246 190 14
43454-246 190 14 246 190 14 246 190 14 242 186 14
43455-234 174 13 213 154 11 154 122 46 66 66 66
43456- 30 30 30 10 10 10 0 0 0 0 0 0
43457- 0 0 0 0 0 0 0 0 0 0 0 0
43458- 0 0 0 0 0 0 0 0 0 0 0 0
43459- 0 0 0 0 0 0 6 6 6 22 22 22
43460- 58 58 58 154 121 60 206 145 10 234 174 13
43461-242 186 14 246 186 14 246 190 14 246 190 14
43462-246 190 14 246 190 14 246 190 14 246 190 14
43463-246 190 14 246 190 14 246 190 14 246 190 14
43464-246 190 14 246 190 14 246 190 14 246 190 14
43465-246 186 14 236 178 12 210 162 10 163 110 8
43466- 61 42 6 138 138 138 218 218 218 250 250 250
43467-253 253 253 253 253 253 253 253 253 250 250 250
43468-242 242 242 210 210 210 144 144 144 66 66 66
43469- 6 6 6 2 2 6 2 2 6 2 2 6
43470- 2 2 6 2 2 6 61 42 6 163 110 8
43471-216 158 10 236 178 12 246 190 14 246 190 14
43472-246 190 14 246 190 14 246 190 14 246 190 14
43473-246 190 14 246 190 14 246 190 14 246 190 14
43474-246 190 14 239 182 13 230 174 11 216 158 10
43475-190 142 34 124 112 88 70 70 70 38 38 38
43476- 18 18 18 6 6 6 0 0 0 0 0 0
43477- 0 0 0 0 0 0 0 0 0 0 0 0
43478- 0 0 0 0 0 0 0 0 0 0 0 0
43479- 0 0 0 0 0 0 6 6 6 22 22 22
43480- 62 62 62 168 124 44 206 145 10 224 166 10
43481-236 178 12 239 182 13 242 186 14 242 186 14
43482-246 186 14 246 190 14 246 190 14 246 190 14
43483-246 190 14 246 190 14 246 190 14 246 190 14
43484-246 190 14 246 190 14 246 190 14 246 190 14
43485-246 190 14 236 178 12 216 158 10 175 118 6
43486- 80 54 7 2 2 6 6 6 6 30 30 30
43487- 54 54 54 62 62 62 50 50 50 38 38 38
43488- 14 14 14 2 2 6 2 2 6 2 2 6
43489- 2 2 6 2 2 6 2 2 6 2 2 6
43490- 2 2 6 6 6 6 80 54 7 167 114 7
43491-213 154 11 236 178 12 246 190 14 246 190 14
43492-246 190 14 246 190 14 246 190 14 246 190 14
43493-246 190 14 242 186 14 239 182 13 239 182 13
43494-230 174 11 210 150 10 174 135 50 124 112 88
43495- 82 82 82 54 54 54 34 34 34 18 18 18
43496- 6 6 6 0 0 0 0 0 0 0 0 0
43497- 0 0 0 0 0 0 0 0 0 0 0 0
43498- 0 0 0 0 0 0 0 0 0 0 0 0
43499- 0 0 0 0 0 0 6 6 6 18 18 18
43500- 50 50 50 158 118 36 192 133 9 200 144 11
43501-216 158 10 219 162 10 224 166 10 226 170 11
43502-230 174 11 236 178 12 239 182 13 239 182 13
43503-242 186 14 246 186 14 246 190 14 246 190 14
43504-246 190 14 246 190 14 246 190 14 246 190 14
43505-246 186 14 230 174 11 210 150 10 163 110 8
43506-104 69 6 10 10 10 2 2 6 2 2 6
43507- 2 2 6 2 2 6 2 2 6 2 2 6
43508- 2 2 6 2 2 6 2 2 6 2 2 6
43509- 2 2 6 2 2 6 2 2 6 2 2 6
43510- 2 2 6 6 6 6 91 60 6 167 114 7
43511-206 145 10 230 174 11 242 186 14 246 190 14
43512-246 190 14 246 190 14 246 186 14 242 186 14
43513-239 182 13 230 174 11 224 166 10 213 154 11
43514-180 133 36 124 112 88 86 86 86 58 58 58
43515- 38 38 38 22 22 22 10 10 10 6 6 6
43516- 0 0 0 0 0 0 0 0 0 0 0 0
43517- 0 0 0 0 0 0 0 0 0 0 0 0
43518- 0 0 0 0 0 0 0 0 0 0 0 0
43519- 0 0 0 0 0 0 0 0 0 14 14 14
43520- 34 34 34 70 70 70 138 110 50 158 118 36
43521-167 114 7 180 123 7 192 133 9 197 138 11
43522-200 144 11 206 145 10 213 154 11 219 162 10
43523-224 166 10 230 174 11 239 182 13 242 186 14
43524-246 186 14 246 186 14 246 186 14 246 186 14
43525-239 182 13 216 158 10 185 133 11 152 99 6
43526-104 69 6 18 14 6 2 2 6 2 2 6
43527- 2 2 6 2 2 6 2 2 6 2 2 6
43528- 2 2 6 2 2 6 2 2 6 2 2 6
43529- 2 2 6 2 2 6 2 2 6 2 2 6
43530- 2 2 6 6 6 6 80 54 7 152 99 6
43531-192 133 9 219 162 10 236 178 12 239 182 13
43532-246 186 14 242 186 14 239 182 13 236 178 12
43533-224 166 10 206 145 10 192 133 9 154 121 60
43534- 94 94 94 62 62 62 42 42 42 22 22 22
43535- 14 14 14 6 6 6 0 0 0 0 0 0
43536- 0 0 0 0 0 0 0 0 0 0 0 0
43537- 0 0 0 0 0 0 0 0 0 0 0 0
43538- 0 0 0 0 0 0 0 0 0 0 0 0
43539- 0 0 0 0 0 0 0 0 0 6 6 6
43540- 18 18 18 34 34 34 58 58 58 78 78 78
43541-101 98 89 124 112 88 142 110 46 156 107 11
43542-163 110 8 167 114 7 175 118 6 180 123 7
43543-185 133 11 197 138 11 210 150 10 219 162 10
43544-226 170 11 236 178 12 236 178 12 234 174 13
43545-219 162 10 197 138 11 163 110 8 130 83 6
43546- 91 60 6 10 10 10 2 2 6 2 2 6
43547- 18 18 18 38 38 38 38 38 38 38 38 38
43548- 38 38 38 38 38 38 38 38 38 38 38 38
43549- 38 38 38 38 38 38 26 26 26 2 2 6
43550- 2 2 6 6 6 6 70 47 6 137 92 6
43551-175 118 6 200 144 11 219 162 10 230 174 11
43552-234 174 13 230 174 11 219 162 10 210 150 10
43553-192 133 9 163 110 8 124 112 88 82 82 82
43554- 50 50 50 30 30 30 14 14 14 6 6 6
43555- 0 0 0 0 0 0 0 0 0 0 0 0
43556- 0 0 0 0 0 0 0 0 0 0 0 0
43557- 0 0 0 0 0 0 0 0 0 0 0 0
43558- 0 0 0 0 0 0 0 0 0 0 0 0
43559- 0 0 0 0 0 0 0 0 0 0 0 0
43560- 6 6 6 14 14 14 22 22 22 34 34 34
43561- 42 42 42 58 58 58 74 74 74 86 86 86
43562-101 98 89 122 102 70 130 98 46 121 87 25
43563-137 92 6 152 99 6 163 110 8 180 123 7
43564-185 133 11 197 138 11 206 145 10 200 144 11
43565-180 123 7 156 107 11 130 83 6 104 69 6
43566- 50 34 6 54 54 54 110 110 110 101 98 89
43567- 86 86 86 82 82 82 78 78 78 78 78 78
43568- 78 78 78 78 78 78 78 78 78 78 78 78
43569- 78 78 78 82 82 82 86 86 86 94 94 94
43570-106 106 106 101 101 101 86 66 34 124 80 6
43571-156 107 11 180 123 7 192 133 9 200 144 11
43572-206 145 10 200 144 11 192 133 9 175 118 6
43573-139 102 15 109 106 95 70 70 70 42 42 42
43574- 22 22 22 10 10 10 0 0 0 0 0 0
43575- 0 0 0 0 0 0 0 0 0 0 0 0
43576- 0 0 0 0 0 0 0 0 0 0 0 0
43577- 0 0 0 0 0 0 0 0 0 0 0 0
43578- 0 0 0 0 0 0 0 0 0 0 0 0
43579- 0 0 0 0 0 0 0 0 0 0 0 0
43580- 0 0 0 0 0 0 6 6 6 10 10 10
43581- 14 14 14 22 22 22 30 30 30 38 38 38
43582- 50 50 50 62 62 62 74 74 74 90 90 90
43583-101 98 89 112 100 78 121 87 25 124 80 6
43584-137 92 6 152 99 6 152 99 6 152 99 6
43585-138 86 6 124 80 6 98 70 6 86 66 30
43586-101 98 89 82 82 82 58 58 58 46 46 46
43587- 38 38 38 34 34 34 34 34 34 34 34 34
43588- 34 34 34 34 34 34 34 34 34 34 34 34
43589- 34 34 34 34 34 34 38 38 38 42 42 42
43590- 54 54 54 82 82 82 94 86 76 91 60 6
43591-134 86 6 156 107 11 167 114 7 175 118 6
43592-175 118 6 167 114 7 152 99 6 121 87 25
43593-101 98 89 62 62 62 34 34 34 18 18 18
43594- 6 6 6 0 0 0 0 0 0 0 0 0
43595- 0 0 0 0 0 0 0 0 0 0 0 0
43596- 0 0 0 0 0 0 0 0 0 0 0 0
43597- 0 0 0 0 0 0 0 0 0 0 0 0
43598- 0 0 0 0 0 0 0 0 0 0 0 0
43599- 0 0 0 0 0 0 0 0 0 0 0 0
43600- 0 0 0 0 0 0 0 0 0 0 0 0
43601- 0 0 0 6 6 6 6 6 6 10 10 10
43602- 18 18 18 22 22 22 30 30 30 42 42 42
43603- 50 50 50 66 66 66 86 86 86 101 98 89
43604-106 86 58 98 70 6 104 69 6 104 69 6
43605-104 69 6 91 60 6 82 62 34 90 90 90
43606- 62 62 62 38 38 38 22 22 22 14 14 14
43607- 10 10 10 10 10 10 10 10 10 10 10 10
43608- 10 10 10 10 10 10 6 6 6 10 10 10
43609- 10 10 10 10 10 10 10 10 10 14 14 14
43610- 22 22 22 42 42 42 70 70 70 89 81 66
43611- 80 54 7 104 69 6 124 80 6 137 92 6
43612-134 86 6 116 81 8 100 82 52 86 86 86
43613- 58 58 58 30 30 30 14 14 14 6 6 6
43614- 0 0 0 0 0 0 0 0 0 0 0 0
43615- 0 0 0 0 0 0 0 0 0 0 0 0
43616- 0 0 0 0 0 0 0 0 0 0 0 0
43617- 0 0 0 0 0 0 0 0 0 0 0 0
43618- 0 0 0 0 0 0 0 0 0 0 0 0
43619- 0 0 0 0 0 0 0 0 0 0 0 0
43620- 0 0 0 0 0 0 0 0 0 0 0 0
43621- 0 0 0 0 0 0 0 0 0 0 0 0
43622- 0 0 0 6 6 6 10 10 10 14 14 14
43623- 18 18 18 26 26 26 38 38 38 54 54 54
43624- 70 70 70 86 86 86 94 86 76 89 81 66
43625- 89 81 66 86 86 86 74 74 74 50 50 50
43626- 30 30 30 14 14 14 6 6 6 0 0 0
43627- 0 0 0 0 0 0 0 0 0 0 0 0
43628- 0 0 0 0 0 0 0 0 0 0 0 0
43629- 0 0 0 0 0 0 0 0 0 0 0 0
43630- 6 6 6 18 18 18 34 34 34 58 58 58
43631- 82 82 82 89 81 66 89 81 66 89 81 66
43632- 94 86 66 94 86 76 74 74 74 50 50 50
43633- 26 26 26 14 14 14 6 6 6 0 0 0
43634- 0 0 0 0 0 0 0 0 0 0 0 0
43635- 0 0 0 0 0 0 0 0 0 0 0 0
43636- 0 0 0 0 0 0 0 0 0 0 0 0
43637- 0 0 0 0 0 0 0 0 0 0 0 0
43638- 0 0 0 0 0 0 0 0 0 0 0 0
43639- 0 0 0 0 0 0 0 0 0 0 0 0
43640- 0 0 0 0 0 0 0 0 0 0 0 0
43641- 0 0 0 0 0 0 0 0 0 0 0 0
43642- 0 0 0 0 0 0 0 0 0 0 0 0
43643- 6 6 6 6 6 6 14 14 14 18 18 18
43644- 30 30 30 38 38 38 46 46 46 54 54 54
43645- 50 50 50 42 42 42 30 30 30 18 18 18
43646- 10 10 10 0 0 0 0 0 0 0 0 0
43647- 0 0 0 0 0 0 0 0 0 0 0 0
43648- 0 0 0 0 0 0 0 0 0 0 0 0
43649- 0 0 0 0 0 0 0 0 0 0 0 0
43650- 0 0 0 6 6 6 14 14 14 26 26 26
43651- 38 38 38 50 50 50 58 58 58 58 58 58
43652- 54 54 54 42 42 42 30 30 30 18 18 18
43653- 10 10 10 0 0 0 0 0 0 0 0 0
43654- 0 0 0 0 0 0 0 0 0 0 0 0
43655- 0 0 0 0 0 0 0 0 0 0 0 0
43656- 0 0 0 0 0 0 0 0 0 0 0 0
43657- 0 0 0 0 0 0 0 0 0 0 0 0
43658- 0 0 0 0 0 0 0 0 0 0 0 0
43659- 0 0 0 0 0 0 0 0 0 0 0 0
43660- 0 0 0 0 0 0 0 0 0 0 0 0
43661- 0 0 0 0 0 0 0 0 0 0 0 0
43662- 0 0 0 0 0 0 0 0 0 0 0 0
43663- 0 0 0 0 0 0 0 0 0 6 6 6
43664- 6 6 6 10 10 10 14 14 14 18 18 18
43665- 18 18 18 14 14 14 10 10 10 6 6 6
43666- 0 0 0 0 0 0 0 0 0 0 0 0
43667- 0 0 0 0 0 0 0 0 0 0 0 0
43668- 0 0 0 0 0 0 0 0 0 0 0 0
43669- 0 0 0 0 0 0 0 0 0 0 0 0
43670- 0 0 0 0 0 0 0 0 0 6 6 6
43671- 14 14 14 18 18 18 22 22 22 22 22 22
43672- 18 18 18 14 14 14 10 10 10 6 6 6
43673- 0 0 0 0 0 0 0 0 0 0 0 0
43674- 0 0 0 0 0 0 0 0 0 0 0 0
43675- 0 0 0 0 0 0 0 0 0 0 0 0
43676- 0 0 0 0 0 0 0 0 0 0 0 0
43677- 0 0 0 0 0 0 0 0 0 0 0 0
43678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43691+4 4 4 4 4 4
43692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43705+4 4 4 4 4 4
43706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43719+4 4 4 4 4 4
43720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43733+4 4 4 4 4 4
43734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43747+4 4 4 4 4 4
43748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43761+4 4 4 4 4 4
43762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43766+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
43767+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
43768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43771+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
43772+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43773+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
43774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43775+4 4 4 4 4 4
43776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43780+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
43781+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
43782+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43785+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
43786+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
43787+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
43788+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43789+4 4 4 4 4 4
43790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43794+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
43795+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
43796+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43799+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
43800+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
43801+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
43802+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
43803+4 4 4 4 4 4
43804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43807+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
43808+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
43809+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
43810+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
43811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43812+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
43813+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
43814+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
43815+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
43816+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
43817+4 4 4 4 4 4
43818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43821+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
43822+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
43823+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
43824+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
43825+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43826+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
43827+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
43828+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
43829+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
43830+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
43831+4 4 4 4 4 4
43832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43835+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
43836+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
43837+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
43838+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
43839+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
43840+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
43841+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
43842+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
43843+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
43844+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
43845+4 4 4 4 4 4
43846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43848+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
43849+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
43850+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
43851+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
43852+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
43853+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
43854+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
43855+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
43856+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
43857+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
43858+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
43859+4 4 4 4 4 4
43860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43862+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
43863+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
43864+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
43865+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
43866+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
43867+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
43868+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
43869+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
43870+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
43871+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
43872+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
43873+4 4 4 4 4 4
43874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43876+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
43877+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
43878+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
43879+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
43880+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
43881+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
43882+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
43883+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
43884+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
43885+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
43886+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43887+4 4 4 4 4 4
43888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43890+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
43891+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
43892+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
43893+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
43894+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
43895+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
43896+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
43897+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
43898+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
43899+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
43900+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
43901+4 4 4 4 4 4
43902+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43903+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
43904+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
43905+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
43906+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
43907+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
43908+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
43909+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
43910+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
43911+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
43912+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
43913+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
43914+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
43915+4 4 4 4 4 4
43916+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43917+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
43918+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
43919+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
43920+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43921+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
43922+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
43923+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
43924+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
43925+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
43926+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
43927+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
43928+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
43929+0 0 0 4 4 4
43930+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
43931+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
43932+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
43933+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
43934+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
43935+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
43936+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
43937+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
43938+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
43939+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
43940+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
43941+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
43942+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
43943+2 0 0 0 0 0
43944+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
43945+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
43946+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
43947+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
43948+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
43949+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
43950+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
43951+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
43952+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
43953+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
43954+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
43955+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
43956+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
43957+37 38 37 0 0 0
43958+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
43959+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
43960+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
43961+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
43962+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
43963+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
43964+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
43965+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
43966+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
43967+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
43968+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
43969+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
43970+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
43971+85 115 134 4 0 0
43972+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
43973+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
43974+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
43975+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
43976+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
43977+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
43978+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
43979+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
43980+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
43981+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
43982+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
43983+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
43984+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
43985+60 73 81 4 0 0
43986+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
43987+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
43988+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
43989+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
43990+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
43991+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
43992+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
43993+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
43994+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
43995+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
43996+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
43997+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
43998+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
43999+16 19 21 4 0 0
44000+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
44001+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
44002+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
44003+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
44004+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
44005+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
44006+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
44007+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
44008+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
44009+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
44010+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
44011+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
44012+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
44013+4 0 0 4 3 3
44014+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
44015+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
44016+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
44017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
44018+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
44019+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
44020+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
44021+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
44022+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
44023+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
44024+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
44025+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
44026+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
44027+3 2 2 4 4 4
44028+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
44029+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
44030+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
44031+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
44032+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
44033+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
44034+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
44035+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
44036+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
44037+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
44038+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
44039+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
44040+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
44041+4 4 4 4 4 4
44042+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
44043+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
44044+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
44045+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
44046+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
44047+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
44048+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
44049+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
44050+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
44051+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
44052+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
44053+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
44054+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
44055+4 4 4 4 4 4
44056+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
44057+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
44058+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
44059+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
44060+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
44061+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
44062+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
44063+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
44064+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
44065+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
44066+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
44067+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
44068+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
44069+5 5 5 5 5 5
44070+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
44071+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
44072+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
44073+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
44074+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
44075+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44076+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
44077+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
44078+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
44079+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
44080+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
44081+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
44082+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
44083+5 5 5 4 4 4
44084+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
44085+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
44086+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
44087+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
44088+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
44089+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
44090+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
44091+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
44092+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
44093+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
44094+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
44095+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
44096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44097+4 4 4 4 4 4
44098+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
44099+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
44100+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
44101+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
44102+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
44103+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44104+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44105+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
44106+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
44107+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
44108+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
44109+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
44110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44111+4 4 4 4 4 4
44112+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
44113+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
44114+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
44115+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
44116+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
44117+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
44118+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
44119+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
44120+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
44121+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
44122+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
44123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44125+4 4 4 4 4 4
44126+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
44127+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
44128+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
44129+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
44130+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
44131+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44132+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44133+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
44134+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
44135+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
44136+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
44137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44139+4 4 4 4 4 4
44140+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
44141+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
44142+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
44143+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
44144+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
44145+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
44146+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
44147+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
44148+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
44149+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
44150+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44153+4 4 4 4 4 4
44154+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
44155+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
44156+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
44157+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
44158+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
44159+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
44160+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
44161+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
44162+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
44163+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
44164+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
44165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44167+4 4 4 4 4 4
44168+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
44169+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
44170+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
44171+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
44172+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
44173+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
44174+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
44175+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
44176+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
44177+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
44178+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
44179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44181+4 4 4 4 4 4
44182+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
44183+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
44184+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
44185+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
44186+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
44187+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
44188+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
44189+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
44190+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
44191+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
44192+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44195+4 4 4 4 4 4
44196+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
44197+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
44198+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
44199+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
44200+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44201+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
44202+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
44203+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
44204+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
44205+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
44206+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44209+4 4 4 4 4 4
44210+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
44211+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
44212+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
44213+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
44214+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44215+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
44216+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
44217+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
44218+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
44219+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
44220+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44223+4 4 4 4 4 4
44224+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
44225+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
44226+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
44227+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
44228+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44229+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
44230+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
44231+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
44232+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
44233+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44234+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44237+4 4 4 4 4 4
44238+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
44239+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
44240+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
44241+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
44242+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
44243+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
44244+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
44245+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
44246+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44247+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44248+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44251+4 4 4 4 4 4
44252+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
44253+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
44254+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
44255+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
44256+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44257+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
44258+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
44259+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
44260+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
44261+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44262+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44265+4 4 4 4 4 4
44266+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
44267+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
44268+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
44269+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
44270+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
44271+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
44272+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
44273+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
44274+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44275+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44276+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44279+4 4 4 4 4 4
44280+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
44281+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
44282+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
44283+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
44284+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
44285+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
44286+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
44287+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
44288+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
44289+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44290+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44293+4 4 4 4 4 4
44294+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
44295+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
44296+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
44297+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
44298+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
44299+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
44300+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
44301+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
44302+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44303+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44304+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44307+4 4 4 4 4 4
44308+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
44309+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
44310+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
44311+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
44312+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
44313+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
44314+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
44315+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
44316+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
44317+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44318+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44321+4 4 4 4 4 4
44322+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
44323+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
44324+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
44325+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
44326+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
44327+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
44328+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
44329+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
44330+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44331+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44332+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44335+4 4 4 4 4 4
44336+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44337+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
44338+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
44339+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
44340+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
44341+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
44342+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
44343+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
44344+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
44345+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44346+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44349+4 4 4 4 4 4
44350+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
44351+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
44352+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
44353+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
44354+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
44355+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
44356+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44357+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
44358+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44359+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44360+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44363+4 4 4 4 4 4
44364+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44365+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
44366+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
44367+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
44368+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
44369+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
44370+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44371+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
44372+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
44373+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44374+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44377+4 4 4 4 4 4
44378+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
44379+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
44380+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
44381+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
44382+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
44383+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
44384+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
44385+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
44386+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
44387+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44388+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44391+4 4 4 4 4 4
44392+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44393+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
44394+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
44395+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
44396+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
44397+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
44398+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
44399+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
44400+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
44401+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44402+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44405+4 4 4 4 4 4
44406+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
44407+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
44408+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
44409+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
44410+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
44411+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
44412+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
44413+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
44414+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
44415+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44416+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44419+4 4 4 4 4 4
44420+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44421+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
44422+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
44423+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
44424+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
44425+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
44426+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
44427+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
44428+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
44429+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44430+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44433+4 4 4 4 4 4
44434+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
44435+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
44436+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
44437+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
44438+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
44439+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
44440+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
44441+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
44442+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
44443+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
44444+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44447+4 4 4 4 4 4
44448+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
44449+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
44450+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
44451+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
44452+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
44453+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
44454+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
44455+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
44456+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
44457+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
44458+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44461+4 4 4 4 4 4
44462+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
44463+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
44464+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
44465+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
44466+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
44467+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
44468+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44469+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
44470+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
44471+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
44472+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44475+4 4 4 4 4 4
44476+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
44477+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
44478+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
44479+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
44480+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
44481+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
44482+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
44483+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
44484+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
44485+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
44486+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44489+4 4 4 4 4 4
44490+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
44491+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
44492+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
44493+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
44494+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
44495+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
44496+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
44497+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
44498+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
44499+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
44500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44502+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44503+4 4 4 4 4 4
44504+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44505+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
44506+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
44507+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
44508+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
44509+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
44510+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
44511+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
44512+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
44513+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
44514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44516+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44517+4 4 4 4 4 4
44518+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
44519+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
44520+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
44521+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
44522+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
44523+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
44524+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
44525+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
44526+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
44527+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
44528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44530+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44531+4 4 4 4 4 4
44532+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
44533+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
44534+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
44535+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
44536+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
44537+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
44538+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
44539+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
44540+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
44541+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44544+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44545+4 4 4 4 4 4
44546+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
44547+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44548+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
44549+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
44550+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
44551+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
44552+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
44553+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
44554+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
44555+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44558+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44559+4 4 4 4 4 4
44560+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
44561+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
44562+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
44563+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
44564+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
44565+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
44566+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
44567+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
44568+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
44569+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44572+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44573+4 4 4 4 4 4
44574+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
44575+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
44576+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
44577+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
44578+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
44579+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
44580+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
44581+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
44582+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44583+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44586+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44587+4 4 4 4 4 4
44588+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
44589+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
44590+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
44591+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
44592+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
44593+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
44594+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
44595+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
44596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44601+4 4 4 4 4 4
44602+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
44603+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
44604+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
44605+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
44606+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
44607+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
44608+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
44609+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
44610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44615+4 4 4 4 4 4
44616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44617+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
44618+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44619+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
44620+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
44621+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
44622+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
44623+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
44624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44629+4 4 4 4 4 4
44630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44631+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
44632+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
44633+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
44634+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
44635+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
44636+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
44637+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
44638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44643+4 4 4 4 4 4
44644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44645+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
44646+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
44647+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
44648+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
44649+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
44650+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
44651+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44657+4 4 4 4 4 4
44658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44660+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
44661+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
44662+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
44663+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
44664+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
44665+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44671+4 4 4 4 4 4
44672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44675+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44676+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
44677+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
44678+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
44679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44685+4 4 4 4 4 4
44686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44689+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
44690+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
44691+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
44692+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
44693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44699+4 4 4 4 4 4
44700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44703+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
44704+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44705+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
44706+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
44707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44713+4 4 4 4 4 4
44714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44717+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
44718+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
44719+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
44720+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
44721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44727+4 4 4 4 4 4
44728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44732+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
44733+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44734+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44741+4 4 4 4 4 4
44742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44746+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
44747+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
44748+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
44749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44755+4 4 4 4 4 4
44756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44760+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
44761+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
44762+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44769+4 4 4 4 4 4
44770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44774+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
44775+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
44776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44783+4 4 4 4 4 4
44784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44788+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
44789+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
44790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44797+4 4 4 4 4 4
44798diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
44799index 86d449e..af6a7f7 100644
44800--- a/drivers/video/udlfb.c
44801+++ b/drivers/video/udlfb.c
44802@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
44803 dlfb_urb_completion(urb);
44804
44805 error:
44806- atomic_add(bytes_sent, &dev->bytes_sent);
44807- atomic_add(bytes_identical, &dev->bytes_identical);
44808- atomic_add(width*height*2, &dev->bytes_rendered);
44809+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44810+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44811+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
44812 end_cycles = get_cycles();
44813- atomic_add(((unsigned int) ((end_cycles - start_cycles)
44814+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44815 >> 10)), /* Kcycles */
44816 &dev->cpu_kcycles_used);
44817
44818@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
44819 dlfb_urb_completion(urb);
44820
44821 error:
44822- atomic_add(bytes_sent, &dev->bytes_sent);
44823- atomic_add(bytes_identical, &dev->bytes_identical);
44824- atomic_add(bytes_rendered, &dev->bytes_rendered);
44825+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44826+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44827+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
44828 end_cycles = get_cycles();
44829- atomic_add(((unsigned int) ((end_cycles - start_cycles)
44830+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44831 >> 10)), /* Kcycles */
44832 &dev->cpu_kcycles_used);
44833 }
44834@@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
44835 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44836 struct dlfb_data *dev = fb_info->par;
44837 return snprintf(buf, PAGE_SIZE, "%u\n",
44838- atomic_read(&dev->bytes_rendered));
44839+ atomic_read_unchecked(&dev->bytes_rendered));
44840 }
44841
44842 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44843@@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44844 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44845 struct dlfb_data *dev = fb_info->par;
44846 return snprintf(buf, PAGE_SIZE, "%u\n",
44847- atomic_read(&dev->bytes_identical));
44848+ atomic_read_unchecked(&dev->bytes_identical));
44849 }
44850
44851 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44852@@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44853 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44854 struct dlfb_data *dev = fb_info->par;
44855 return snprintf(buf, PAGE_SIZE, "%u\n",
44856- atomic_read(&dev->bytes_sent));
44857+ atomic_read_unchecked(&dev->bytes_sent));
44858 }
44859
44860 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44861@@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44862 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44863 struct dlfb_data *dev = fb_info->par;
44864 return snprintf(buf, PAGE_SIZE, "%u\n",
44865- atomic_read(&dev->cpu_kcycles_used));
44866+ atomic_read_unchecked(&dev->cpu_kcycles_used));
44867 }
44868
44869 static ssize_t edid_show(
44870@@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
44871 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44872 struct dlfb_data *dev = fb_info->par;
44873
44874- atomic_set(&dev->bytes_rendered, 0);
44875- atomic_set(&dev->bytes_identical, 0);
44876- atomic_set(&dev->bytes_sent, 0);
44877- atomic_set(&dev->cpu_kcycles_used, 0);
44878+ atomic_set_unchecked(&dev->bytes_rendered, 0);
44879+ atomic_set_unchecked(&dev->bytes_identical, 0);
44880+ atomic_set_unchecked(&dev->bytes_sent, 0);
44881+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
44882
44883 return count;
44884 }
44885diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
44886index b75db01..5631c6d 100644
44887--- a/drivers/video/uvesafb.c
44888+++ b/drivers/video/uvesafb.c
44889@@ -19,6 +19,7 @@
44890 #include <linux/io.h>
44891 #include <linux/mutex.h>
44892 #include <linux/slab.h>
44893+#include <linux/moduleloader.h>
44894 #include <video/edid.h>
44895 #include <video/uvesafb.h>
44896 #ifdef CONFIG_X86
44897@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
44898 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
44899 par->pmi_setpal = par->ypan = 0;
44900 } else {
44901+
44902+#ifdef CONFIG_PAX_KERNEXEC
44903+#ifdef CONFIG_MODULES
44904+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
44905+#endif
44906+ if (!par->pmi_code) {
44907+ par->pmi_setpal = par->ypan = 0;
44908+ return 0;
44909+ }
44910+#endif
44911+
44912 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
44913 + task->t.regs.edi);
44914+
44915+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44916+ pax_open_kernel();
44917+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
44918+ pax_close_kernel();
44919+
44920+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
44921+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
44922+#else
44923 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
44924 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
44925+#endif
44926+
44927 printk(KERN_INFO "uvesafb: protected mode interface info at "
44928 "%04x:%04x\n",
44929 (u16)task->t.regs.es, (u16)task->t.regs.edi);
44930@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
44931 par->ypan = ypan;
44932
44933 if (par->pmi_setpal || par->ypan) {
44934+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
44935 if (__supported_pte_mask & _PAGE_NX) {
44936 par->pmi_setpal = par->ypan = 0;
44937 printk(KERN_WARNING "uvesafb: NX protection is actively."
44938 "We have better not to use the PMI.\n");
44939- } else {
44940+ } else
44941+#endif
44942 uvesafb_vbe_getpmi(task, par);
44943- }
44944 }
44945 #else
44946 /* The protected mode interface is not available on non-x86. */
44947@@ -1836,6 +1860,11 @@ out:
44948 if (par->vbe_modes)
44949 kfree(par->vbe_modes);
44950
44951+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44952+ if (par->pmi_code)
44953+ module_free_exec(NULL, par->pmi_code);
44954+#endif
44955+
44956 framebuffer_release(info);
44957 return err;
44958 }
44959@@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
44960 kfree(par->vbe_state_orig);
44961 if (par->vbe_state_saved)
44962 kfree(par->vbe_state_saved);
44963+
44964+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44965+ if (par->pmi_code)
44966+ module_free_exec(NULL, par->pmi_code);
44967+#endif
44968+
44969 }
44970
44971 framebuffer_release(info);
44972diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
44973index 501b340..86bd4cf 100644
44974--- a/drivers/video/vesafb.c
44975+++ b/drivers/video/vesafb.c
44976@@ -9,6 +9,7 @@
44977 */
44978
44979 #include <linux/module.h>
44980+#include <linux/moduleloader.h>
44981 #include <linux/kernel.h>
44982 #include <linux/errno.h>
44983 #include <linux/string.h>
44984@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
44985 static int vram_total __initdata; /* Set total amount of memory */
44986 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
44987 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
44988-static void (*pmi_start)(void) __read_mostly;
44989-static void (*pmi_pal) (void) __read_mostly;
44990+static void (*pmi_start)(void) __read_only;
44991+static void (*pmi_pal) (void) __read_only;
44992 static int depth __read_mostly;
44993 static int vga_compat __read_mostly;
44994 /* --------------------------------------------------------------------- */
44995@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
44996 unsigned int size_vmode;
44997 unsigned int size_remap;
44998 unsigned int size_total;
44999+ void *pmi_code = NULL;
45000
45001 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
45002 return -ENODEV;
45003@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
45004 size_remap = size_total;
45005 vesafb_fix.smem_len = size_remap;
45006
45007-#ifndef __i386__
45008- screen_info.vesapm_seg = 0;
45009-#endif
45010-
45011 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
45012 printk(KERN_WARNING
45013 "vesafb: cannot reserve video memory at 0x%lx\n",
45014@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
45015 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
45016 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
45017
45018+#ifdef __i386__
45019+
45020+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45021+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
45022+ if (!pmi_code)
45023+#elif !defined(CONFIG_PAX_KERNEXEC)
45024+ if (0)
45025+#endif
45026+
45027+#endif
45028+ screen_info.vesapm_seg = 0;
45029+
45030 if (screen_info.vesapm_seg) {
45031- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
45032- screen_info.vesapm_seg,screen_info.vesapm_off);
45033+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
45034+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
45035 }
45036
45037 if (screen_info.vesapm_seg < 0xc000)
45038@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
45039
45040 if (ypan || pmi_setpal) {
45041 unsigned short *pmi_base;
45042+
45043 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
45044- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
45045- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
45046+
45047+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45048+ pax_open_kernel();
45049+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
45050+#else
45051+ pmi_code = pmi_base;
45052+#endif
45053+
45054+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
45055+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
45056+
45057+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45058+ pmi_start = ktva_ktla(pmi_start);
45059+ pmi_pal = ktva_ktla(pmi_pal);
45060+ pax_close_kernel();
45061+#endif
45062+
45063 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
45064 if (pmi_base[3]) {
45065 printk(KERN_INFO "vesafb: pmi: ports = ");
45066@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
45067 info->node, info->fix.id);
45068 return 0;
45069 err:
45070+
45071+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45072+ module_free_exec(NULL, pmi_code);
45073+#endif
45074+
45075 if (info->screen_base)
45076 iounmap(info->screen_base);
45077 framebuffer_release(info);
45078diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
45079index 88714ae..16c2e11 100644
45080--- a/drivers/video/via/via_clock.h
45081+++ b/drivers/video/via/via_clock.h
45082@@ -56,7 +56,7 @@ struct via_clock {
45083
45084 void (*set_engine_pll_state)(u8 state);
45085 void (*set_engine_pll)(struct via_pll_config config);
45086-};
45087+} __no_const;
45088
45089
45090 static inline u32 get_pll_internal_frequency(u32 ref_freq,
45091diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
45092index fef20db..d28b1ab 100644
45093--- a/drivers/xen/xenfs/xenstored.c
45094+++ b/drivers/xen/xenfs/xenstored.c
45095@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
45096 static int xsd_kva_open(struct inode *inode, struct file *file)
45097 {
45098 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
45099+#ifdef CONFIG_GRKERNSEC_HIDESYM
45100+ NULL);
45101+#else
45102 xen_store_interface);
45103+#endif
45104+
45105 if (!file->private_data)
45106 return -ENOMEM;
45107 return 0;
45108diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
45109index 890bed5..17ae73e 100644
45110--- a/fs/9p/vfs_inode.c
45111+++ b/fs/9p/vfs_inode.c
45112@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
45113 void
45114 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
45115 {
45116- char *s = nd_get_link(nd);
45117+ const char *s = nd_get_link(nd);
45118
45119 p9_debug(P9_DEBUG_VFS, " %s %s\n",
45120 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
45121diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
45122index 0efd152..b5802ad 100644
45123--- a/fs/Kconfig.binfmt
45124+++ b/fs/Kconfig.binfmt
45125@@ -89,7 +89,7 @@ config HAVE_AOUT
45126
45127 config BINFMT_AOUT
45128 tristate "Kernel support for a.out and ECOFF binaries"
45129- depends on HAVE_AOUT
45130+ depends on HAVE_AOUT && BROKEN
45131 ---help---
45132 A.out (Assembler.OUTput) is a set of formats for libraries and
45133 executables used in the earliest versions of UNIX. Linux used
45134diff --git a/fs/aio.c b/fs/aio.c
45135index 71f613c..9d01f1f 100644
45136--- a/fs/aio.c
45137+++ b/fs/aio.c
45138@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
45139 size += sizeof(struct io_event) * nr_events;
45140 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
45141
45142- if (nr_pages < 0)
45143+ if (nr_pages <= 0)
45144 return -EINVAL;
45145
45146 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
45147@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
45148 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
45149 {
45150 ssize_t ret;
45151+ struct iovec iovstack;
45152
45153 #ifdef CONFIG_COMPAT
45154 if (compat)
45155 ret = compat_rw_copy_check_uvector(type,
45156 (struct compat_iovec __user *)kiocb->ki_buf,
45157- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
45158+ kiocb->ki_nbytes, 1, &iovstack,
45159 &kiocb->ki_iovec);
45160 else
45161 #endif
45162 ret = rw_copy_check_uvector(type,
45163 (struct iovec __user *)kiocb->ki_buf,
45164- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
45165+ kiocb->ki_nbytes, 1, &iovstack,
45166 &kiocb->ki_iovec);
45167 if (ret < 0)
45168 goto out;
45169@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
45170 if (ret < 0)
45171 goto out;
45172
45173+ if (kiocb->ki_iovec == &iovstack) {
45174+ kiocb->ki_inline_vec = iovstack;
45175+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
45176+ }
45177 kiocb->ki_nr_segs = kiocb->ki_nbytes;
45178 kiocb->ki_cur_seg = 0;
45179 /* ki_nbytes/left now reflect bytes instead of segs */
45180diff --git a/fs/attr.c b/fs/attr.c
45181index 1449adb..a2038c2 100644
45182--- a/fs/attr.c
45183+++ b/fs/attr.c
45184@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
45185 unsigned long limit;
45186
45187 limit = rlimit(RLIMIT_FSIZE);
45188+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
45189 if (limit != RLIM_INFINITY && offset > limit)
45190 goto out_sig;
45191 if (offset > inode->i_sb->s_maxbytes)
45192diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
45193index 03bc1d3..6205356 100644
45194--- a/fs/autofs4/waitq.c
45195+++ b/fs/autofs4/waitq.c
45196@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
45197 {
45198 unsigned long sigpipe, flags;
45199 mm_segment_t fs;
45200- const char *data = (const char *)addr;
45201+ const char __user *data = (const char __force_user *)addr;
45202 ssize_t wr = 0;
45203
45204 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
45205@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
45206 return 1;
45207 }
45208
45209+#ifdef CONFIG_GRKERNSEC_HIDESYM
45210+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
45211+#endif
45212+
45213 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
45214 enum autofs_notify notify)
45215 {
45216@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
45217
45218 /* If this is a direct mount request create a dummy name */
45219 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
45220+#ifdef CONFIG_GRKERNSEC_HIDESYM
45221+ /* this name does get written to userland via autofs4_write() */
45222+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
45223+#else
45224 qstr.len = sprintf(name, "%p", dentry);
45225+#endif
45226 else {
45227 qstr.len = autofs4_getpath(sbi, dentry, &name);
45228 if (!qstr.len) {
45229diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
45230index 2b3bda8..6a2d4be 100644
45231--- a/fs/befs/linuxvfs.c
45232+++ b/fs/befs/linuxvfs.c
45233@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
45234 {
45235 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
45236 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
45237- char *link = nd_get_link(nd);
45238+ const char *link = nd_get_link(nd);
45239 if (!IS_ERR(link))
45240 kfree(link);
45241 }
45242diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
45243index 6043567..16a9239 100644
45244--- a/fs/binfmt_aout.c
45245+++ b/fs/binfmt_aout.c
45246@@ -16,6 +16,7 @@
45247 #include <linux/string.h>
45248 #include <linux/fs.h>
45249 #include <linux/file.h>
45250+#include <linux/security.h>
45251 #include <linux/stat.h>
45252 #include <linux/fcntl.h>
45253 #include <linux/ptrace.h>
45254@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
45255 #endif
45256 # define START_STACK(u) ((void __user *)u.start_stack)
45257
45258+ memset(&dump, 0, sizeof(dump));
45259+
45260 fs = get_fs();
45261 set_fs(KERNEL_DS);
45262 has_dumped = 1;
45263@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
45264
45265 /* If the size of the dump file exceeds the rlimit, then see what would happen
45266 if we wrote the stack, but not the data area. */
45267+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
45268 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
45269 dump.u_dsize = 0;
45270
45271 /* Make sure we have enough room to write the stack and data areas. */
45272+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
45273 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
45274 dump.u_ssize = 0;
45275
45276@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
45277 rlim = rlimit(RLIMIT_DATA);
45278 if (rlim >= RLIM_INFINITY)
45279 rlim = ~0;
45280+
45281+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
45282 if (ex.a_data + ex.a_bss > rlim)
45283 return -ENOMEM;
45284
45285@@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
45286
45287 install_exec_creds(bprm);
45288
45289+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45290+ current->mm->pax_flags = 0UL;
45291+#endif
45292+
45293+#ifdef CONFIG_PAX_PAGEEXEC
45294+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
45295+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
45296+
45297+#ifdef CONFIG_PAX_EMUTRAMP
45298+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
45299+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
45300+#endif
45301+
45302+#ifdef CONFIG_PAX_MPROTECT
45303+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
45304+ current->mm->pax_flags |= MF_PAX_MPROTECT;
45305+#endif
45306+
45307+ }
45308+#endif
45309+
45310 if (N_MAGIC(ex) == OMAGIC) {
45311 unsigned long text_addr, map_size;
45312 loff_t pos;
45313@@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
45314 }
45315
45316 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
45317- PROT_READ | PROT_WRITE | PROT_EXEC,
45318+ PROT_READ | PROT_WRITE,
45319 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
45320 fd_offset + ex.a_text);
45321 if (error != N_DATADDR(ex)) {
45322diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
45323index 0c42cdb..f4be023 100644
45324--- a/fs/binfmt_elf.c
45325+++ b/fs/binfmt_elf.c
45326@@ -33,6 +33,7 @@
45327 #include <linux/elf.h>
45328 #include <linux/utsname.h>
45329 #include <linux/coredump.h>
45330+#include <linux/xattr.h>
45331 #include <asm/uaccess.h>
45332 #include <asm/param.h>
45333 #include <asm/page.h>
45334@@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
45335 #define elf_core_dump NULL
45336 #endif
45337
45338+#ifdef CONFIG_PAX_MPROTECT
45339+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
45340+#endif
45341+
45342 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
45343 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
45344 #else
45345@@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
45346 .load_binary = load_elf_binary,
45347 .load_shlib = load_elf_library,
45348 .core_dump = elf_core_dump,
45349+
45350+#ifdef CONFIG_PAX_MPROTECT
45351+ .handle_mprotect= elf_handle_mprotect,
45352+#endif
45353+
45354 .min_coredump = ELF_EXEC_PAGESIZE,
45355 };
45356
45357@@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
45358
45359 static int set_brk(unsigned long start, unsigned long end)
45360 {
45361+ unsigned long e = end;
45362+
45363 start = ELF_PAGEALIGN(start);
45364 end = ELF_PAGEALIGN(end);
45365 if (end > start) {
45366@@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
45367 if (BAD_ADDR(addr))
45368 return addr;
45369 }
45370- current->mm->start_brk = current->mm->brk = end;
45371+ current->mm->start_brk = current->mm->brk = e;
45372 return 0;
45373 }
45374
45375@@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
45376 elf_addr_t __user *u_rand_bytes;
45377 const char *k_platform = ELF_PLATFORM;
45378 const char *k_base_platform = ELF_BASE_PLATFORM;
45379- unsigned char k_rand_bytes[16];
45380+ u32 k_rand_bytes[4];
45381 int items;
45382 elf_addr_t *elf_info;
45383 int ei_index = 0;
45384 const struct cred *cred = current_cred();
45385 struct vm_area_struct *vma;
45386+ unsigned long saved_auxv[AT_VECTOR_SIZE];
45387
45388 /*
45389 * In some cases (e.g. Hyper-Threading), we want to avoid L1
45390@@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
45391 * Generate 16 random bytes for userspace PRNG seeding.
45392 */
45393 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
45394- u_rand_bytes = (elf_addr_t __user *)
45395- STACK_ALLOC(p, sizeof(k_rand_bytes));
45396+ srandom32(k_rand_bytes[0] ^ random32());
45397+ srandom32(k_rand_bytes[1] ^ random32());
45398+ srandom32(k_rand_bytes[2] ^ random32());
45399+ srandom32(k_rand_bytes[3] ^ random32());
45400+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
45401+ u_rand_bytes = (elf_addr_t __user *) p;
45402 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
45403 return -EFAULT;
45404
45405@@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
45406 return -EFAULT;
45407 current->mm->env_end = p;
45408
45409+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
45410+
45411 /* Put the elf_info on the stack in the right place. */
45412 sp = (elf_addr_t __user *)envp + 1;
45413- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
45414+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
45415 return -EFAULT;
45416 return 0;
45417 }
45418@@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
45419 an ELF header */
45420
45421 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45422- struct file *interpreter, unsigned long *interp_map_addr,
45423- unsigned long no_base)
45424+ struct file *interpreter, unsigned long no_base)
45425 {
45426 struct elf_phdr *elf_phdata;
45427 struct elf_phdr *eppnt;
45428- unsigned long load_addr = 0;
45429+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
45430 int load_addr_set = 0;
45431 unsigned long last_bss = 0, elf_bss = 0;
45432- unsigned long error = ~0UL;
45433+ unsigned long error = -EINVAL;
45434 unsigned long total_size;
45435 int retval, i, size;
45436
45437@@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45438 goto out_close;
45439 }
45440
45441+#ifdef CONFIG_PAX_SEGMEXEC
45442+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
45443+ pax_task_size = SEGMEXEC_TASK_SIZE;
45444+#endif
45445+
45446 eppnt = elf_phdata;
45447 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
45448 if (eppnt->p_type == PT_LOAD) {
45449@@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45450 map_addr = elf_map(interpreter, load_addr + vaddr,
45451 eppnt, elf_prot, elf_type, total_size);
45452 total_size = 0;
45453- if (!*interp_map_addr)
45454- *interp_map_addr = map_addr;
45455 error = map_addr;
45456 if (BAD_ADDR(map_addr))
45457 goto out_close;
45458@@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45459 k = load_addr + eppnt->p_vaddr;
45460 if (BAD_ADDR(k) ||
45461 eppnt->p_filesz > eppnt->p_memsz ||
45462- eppnt->p_memsz > TASK_SIZE ||
45463- TASK_SIZE - eppnt->p_memsz < k) {
45464+ eppnt->p_memsz > pax_task_size ||
45465+ pax_task_size - eppnt->p_memsz < k) {
45466 error = -ENOMEM;
45467 goto out_close;
45468 }
45469@@ -530,6 +551,315 @@ out:
45470 return error;
45471 }
45472
45473+#ifdef CONFIG_PAX_PT_PAX_FLAGS
45474+#ifdef CONFIG_PAX_SOFTMODE
45475+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
45476+{
45477+ unsigned long pax_flags = 0UL;
45478+
45479+#ifdef CONFIG_PAX_PAGEEXEC
45480+ if (elf_phdata->p_flags & PF_PAGEEXEC)
45481+ pax_flags |= MF_PAX_PAGEEXEC;
45482+#endif
45483+
45484+#ifdef CONFIG_PAX_SEGMEXEC
45485+ if (elf_phdata->p_flags & PF_SEGMEXEC)
45486+ pax_flags |= MF_PAX_SEGMEXEC;
45487+#endif
45488+
45489+#ifdef CONFIG_PAX_EMUTRAMP
45490+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
45491+ pax_flags |= MF_PAX_EMUTRAMP;
45492+#endif
45493+
45494+#ifdef CONFIG_PAX_MPROTECT
45495+ if (elf_phdata->p_flags & PF_MPROTECT)
45496+ pax_flags |= MF_PAX_MPROTECT;
45497+#endif
45498+
45499+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45500+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
45501+ pax_flags |= MF_PAX_RANDMMAP;
45502+#endif
45503+
45504+ return pax_flags;
45505+}
45506+#endif
45507+
45508+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
45509+{
45510+ unsigned long pax_flags = 0UL;
45511+
45512+#ifdef CONFIG_PAX_PAGEEXEC
45513+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
45514+ pax_flags |= MF_PAX_PAGEEXEC;
45515+#endif
45516+
45517+#ifdef CONFIG_PAX_SEGMEXEC
45518+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
45519+ pax_flags |= MF_PAX_SEGMEXEC;
45520+#endif
45521+
45522+#ifdef CONFIG_PAX_EMUTRAMP
45523+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
45524+ pax_flags |= MF_PAX_EMUTRAMP;
45525+#endif
45526+
45527+#ifdef CONFIG_PAX_MPROTECT
45528+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
45529+ pax_flags |= MF_PAX_MPROTECT;
45530+#endif
45531+
45532+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45533+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
45534+ pax_flags |= MF_PAX_RANDMMAP;
45535+#endif
45536+
45537+ return pax_flags;
45538+}
45539+#endif
45540+
45541+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
45542+#ifdef CONFIG_PAX_SOFTMODE
45543+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
45544+{
45545+ unsigned long pax_flags = 0UL;
45546+
45547+#ifdef CONFIG_PAX_PAGEEXEC
45548+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
45549+ pax_flags |= MF_PAX_PAGEEXEC;
45550+#endif
45551+
45552+#ifdef CONFIG_PAX_SEGMEXEC
45553+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
45554+ pax_flags |= MF_PAX_SEGMEXEC;
45555+#endif
45556+
45557+#ifdef CONFIG_PAX_EMUTRAMP
45558+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
45559+ pax_flags |= MF_PAX_EMUTRAMP;
45560+#endif
45561+
45562+#ifdef CONFIG_PAX_MPROTECT
45563+ if (pax_flags_softmode & MF_PAX_MPROTECT)
45564+ pax_flags |= MF_PAX_MPROTECT;
45565+#endif
45566+
45567+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45568+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
45569+ pax_flags |= MF_PAX_RANDMMAP;
45570+#endif
45571+
45572+ return pax_flags;
45573+}
45574+#endif
45575+
45576+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
45577+{
45578+ unsigned long pax_flags = 0UL;
45579+
45580+#ifdef CONFIG_PAX_PAGEEXEC
45581+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
45582+ pax_flags |= MF_PAX_PAGEEXEC;
45583+#endif
45584+
45585+#ifdef CONFIG_PAX_SEGMEXEC
45586+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
45587+ pax_flags |= MF_PAX_SEGMEXEC;
45588+#endif
45589+
45590+#ifdef CONFIG_PAX_EMUTRAMP
45591+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
45592+ pax_flags |= MF_PAX_EMUTRAMP;
45593+#endif
45594+
45595+#ifdef CONFIG_PAX_MPROTECT
45596+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
45597+ pax_flags |= MF_PAX_MPROTECT;
45598+#endif
45599+
45600+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45601+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
45602+ pax_flags |= MF_PAX_RANDMMAP;
45603+#endif
45604+
45605+ return pax_flags;
45606+}
45607+#endif
45608+
45609+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45610+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
45611+{
45612+ unsigned long pax_flags = 0UL;
45613+
45614+#ifdef CONFIG_PAX_EI_PAX
45615+
45616+#ifdef CONFIG_PAX_PAGEEXEC
45617+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
45618+ pax_flags |= MF_PAX_PAGEEXEC;
45619+#endif
45620+
45621+#ifdef CONFIG_PAX_SEGMEXEC
45622+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
45623+ pax_flags |= MF_PAX_SEGMEXEC;
45624+#endif
45625+
45626+#ifdef CONFIG_PAX_EMUTRAMP
45627+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
45628+ pax_flags |= MF_PAX_EMUTRAMP;
45629+#endif
45630+
45631+#ifdef CONFIG_PAX_MPROTECT
45632+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
45633+ pax_flags |= MF_PAX_MPROTECT;
45634+#endif
45635+
45636+#ifdef CONFIG_PAX_ASLR
45637+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
45638+ pax_flags |= MF_PAX_RANDMMAP;
45639+#endif
45640+
45641+#else
45642+
45643+#ifdef CONFIG_PAX_PAGEEXEC
45644+ pax_flags |= MF_PAX_PAGEEXEC;
45645+#endif
45646+
45647+#ifdef CONFIG_PAX_SEGMEXEC
45648+ pax_flags |= MF_PAX_SEGMEXEC;
45649+#endif
45650+
45651+#ifdef CONFIG_PAX_MPROTECT
45652+ pax_flags |= MF_PAX_MPROTECT;
45653+#endif
45654+
45655+#ifdef CONFIG_PAX_RANDMMAP
45656+ if (randomize_va_space)
45657+ pax_flags |= MF_PAX_RANDMMAP;
45658+#endif
45659+
45660+#endif
45661+
45662+ return pax_flags;
45663+}
45664+
45665+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
45666+{
45667+
45668+#ifdef CONFIG_PAX_PT_PAX_FLAGS
45669+ unsigned long i;
45670+
45671+ for (i = 0UL; i < elf_ex->e_phnum; i++)
45672+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
45673+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
45674+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
45675+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
45676+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
45677+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
45678+ return ~0UL;
45679+
45680+#ifdef CONFIG_PAX_SOFTMODE
45681+ if (pax_softmode)
45682+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
45683+ else
45684+#endif
45685+
45686+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
45687+ break;
45688+ }
45689+#endif
45690+
45691+ return ~0UL;
45692+}
45693+
45694+static unsigned long pax_parse_xattr_pax(struct file * const file)
45695+{
45696+
45697+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
45698+ ssize_t xattr_size, i;
45699+ unsigned char xattr_value[5];
45700+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
45701+
45702+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
45703+ if (xattr_size <= 0 || xattr_size > 5)
45704+ return ~0UL;
45705+
45706+ for (i = 0; i < xattr_size; i++)
45707+ switch (xattr_value[i]) {
45708+ default:
45709+ return ~0UL;
45710+
45711+#define parse_flag(option1, option2, flag) \
45712+ case option1: \
45713+ if (pax_flags_hardmode & MF_PAX_##flag) \
45714+ return ~0UL; \
45715+ pax_flags_hardmode |= MF_PAX_##flag; \
45716+ break; \
45717+ case option2: \
45718+ if (pax_flags_softmode & MF_PAX_##flag) \
45719+ return ~0UL; \
45720+ pax_flags_softmode |= MF_PAX_##flag; \
45721+ break;
45722+
45723+ parse_flag('p', 'P', PAGEEXEC);
45724+ parse_flag('e', 'E', EMUTRAMP);
45725+ parse_flag('m', 'M', MPROTECT);
45726+ parse_flag('r', 'R', RANDMMAP);
45727+ parse_flag('s', 'S', SEGMEXEC);
45728+
45729+#undef parse_flag
45730+ }
45731+
45732+ if (pax_flags_hardmode & pax_flags_softmode)
45733+ return ~0UL;
45734+
45735+#ifdef CONFIG_PAX_SOFTMODE
45736+ if (pax_softmode)
45737+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
45738+ else
45739+#endif
45740+
45741+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
45742+#else
45743+ return ~0UL;
45744+#endif
45745+
45746+}
45747+
45748+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
45749+{
45750+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
45751+
45752+ pax_flags = pax_parse_ei_pax(elf_ex);
45753+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
45754+ xattr_pax_flags = pax_parse_xattr_pax(file);
45755+
45756+ if (pt_pax_flags == ~0UL)
45757+ pt_pax_flags = xattr_pax_flags;
45758+ else if (xattr_pax_flags == ~0UL)
45759+ xattr_pax_flags = pt_pax_flags;
45760+ if (pt_pax_flags != xattr_pax_flags)
45761+ return -EINVAL;
45762+ if (pt_pax_flags != ~0UL)
45763+ pax_flags = pt_pax_flags;
45764+
45765+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
45766+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45767+ if ((__supported_pte_mask & _PAGE_NX))
45768+ pax_flags &= ~MF_PAX_SEGMEXEC;
45769+ else
45770+ pax_flags &= ~MF_PAX_PAGEEXEC;
45771+ }
45772+#endif
45773+
45774+ if (0 > pax_check_flags(&pax_flags))
45775+ return -EINVAL;
45776+
45777+ current->mm->pax_flags = pax_flags;
45778+ return 0;
45779+}
45780+#endif
45781+
45782 /*
45783 * These are the functions used to load ELF style executables and shared
45784 * libraries. There is no binary dependent code anywhere else.
45785@@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
45786 {
45787 unsigned int random_variable = 0;
45788
45789+#ifdef CONFIG_PAX_RANDUSTACK
45790+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
45791+ return stack_top - current->mm->delta_stack;
45792+#endif
45793+
45794 if ((current->flags & PF_RANDOMIZE) &&
45795 !(current->personality & ADDR_NO_RANDOMIZE)) {
45796 random_variable = get_random_int() & STACK_RND_MASK;
45797@@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
45798 unsigned long load_addr = 0, load_bias = 0;
45799 int load_addr_set = 0;
45800 char * elf_interpreter = NULL;
45801- unsigned long error;
45802+ unsigned long error = 0;
45803 struct elf_phdr *elf_ppnt, *elf_phdata;
45804 unsigned long elf_bss, elf_brk;
45805 int retval, i;
45806@@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
45807 unsigned long start_code, end_code, start_data, end_data;
45808 unsigned long reloc_func_desc __maybe_unused = 0;
45809 int executable_stack = EXSTACK_DEFAULT;
45810- unsigned long def_flags = 0;
45811 struct pt_regs *regs = current_pt_regs();
45812 struct {
45813 struct elfhdr elf_ex;
45814 struct elfhdr interp_elf_ex;
45815 } *loc;
45816+ unsigned long pax_task_size = TASK_SIZE;
45817
45818 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
45819 if (!loc) {
45820@@ -715,11 +1050,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
45821 goto out_free_dentry;
45822
45823 /* OK, This is the point of no return */
45824- current->mm->def_flags = def_flags;
45825+
45826+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45827+ current->mm->pax_flags = 0UL;
45828+#endif
45829+
45830+#ifdef CONFIG_PAX_DLRESOLVE
45831+ current->mm->call_dl_resolve = 0UL;
45832+#endif
45833+
45834+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
45835+ current->mm->call_syscall = 0UL;
45836+#endif
45837+
45838+#ifdef CONFIG_PAX_ASLR
45839+ current->mm->delta_mmap = 0UL;
45840+ current->mm->delta_stack = 0UL;
45841+#endif
45842+
45843+ current->mm->def_flags = 0;
45844+
45845+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45846+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
45847+ send_sig(SIGKILL, current, 0);
45848+ goto out_free_dentry;
45849+ }
45850+#endif
45851+
45852+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
45853+ pax_set_initial_flags(bprm);
45854+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
45855+ if (pax_set_initial_flags_func)
45856+ (pax_set_initial_flags_func)(bprm);
45857+#endif
45858+
45859+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
45860+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
45861+ current->mm->context.user_cs_limit = PAGE_SIZE;
45862+ current->mm->def_flags |= VM_PAGEEXEC;
45863+ }
45864+#endif
45865+
45866+#ifdef CONFIG_PAX_SEGMEXEC
45867+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
45868+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
45869+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
45870+ pax_task_size = SEGMEXEC_TASK_SIZE;
45871+ current->mm->def_flags |= VM_NOHUGEPAGE;
45872+ }
45873+#endif
45874+
45875+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
45876+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45877+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
45878+ put_cpu();
45879+ }
45880+#endif
45881
45882 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
45883 may depend on the personality. */
45884 SET_PERSONALITY(loc->elf_ex);
45885+
45886+#ifdef CONFIG_PAX_ASLR
45887+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45888+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
45889+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
45890+ }
45891+#endif
45892+
45893+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45894+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45895+ executable_stack = EXSTACK_DISABLE_X;
45896+ current->personality &= ~READ_IMPLIES_EXEC;
45897+ } else
45898+#endif
45899+
45900 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
45901 current->personality |= READ_IMPLIES_EXEC;
45902
45903@@ -810,6 +1215,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
45904 #else
45905 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
45906 #endif
45907+
45908+#ifdef CONFIG_PAX_RANDMMAP
45909+ /* PaX: randomize base address at the default exe base if requested */
45910+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
45911+#ifdef CONFIG_SPARC64
45912+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
45913+#else
45914+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
45915+#endif
45916+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
45917+ elf_flags |= MAP_FIXED;
45918+ }
45919+#endif
45920+
45921 }
45922
45923 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
45924@@ -842,9 +1261,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
45925 * allowed task size. Note that p_filesz must always be
45926 * <= p_memsz so it is only necessary to check p_memsz.
45927 */
45928- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45929- elf_ppnt->p_memsz > TASK_SIZE ||
45930- TASK_SIZE - elf_ppnt->p_memsz < k) {
45931+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45932+ elf_ppnt->p_memsz > pax_task_size ||
45933+ pax_task_size - elf_ppnt->p_memsz < k) {
45934 /* set_brk can never work. Avoid overflows. */
45935 send_sig(SIGKILL, current, 0);
45936 retval = -EINVAL;
45937@@ -883,17 +1302,44 @@ static int load_elf_binary(struct linux_binprm *bprm)
45938 goto out_free_dentry;
45939 }
45940 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
45941- send_sig(SIGSEGV, current, 0);
45942- retval = -EFAULT; /* Nobody gets to see this, but.. */
45943- goto out_free_dentry;
45944+ /*
45945+ * This bss-zeroing can fail if the ELF
45946+ * file specifies odd protections. So
45947+ * we don't check the return value
45948+ */
45949 }
45950
45951+#ifdef CONFIG_PAX_RANDMMAP
45952+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45953+ unsigned long start, size;
45954+
45955+ start = ELF_PAGEALIGN(elf_brk);
45956+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
45957+ down_read(&current->mm->mmap_sem);
45958+ retval = -ENOMEM;
45959+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
45960+ unsigned long prot = PROT_NONE;
45961+
45962+ up_read(&current->mm->mmap_sem);
45963+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
45964+// if (current->personality & ADDR_NO_RANDOMIZE)
45965+// prot = PROT_READ;
45966+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
45967+ retval = IS_ERR_VALUE(start) ? start : 0;
45968+ } else
45969+ up_read(&current->mm->mmap_sem);
45970+ if (retval == 0)
45971+ retval = set_brk(start + size, start + size + PAGE_SIZE);
45972+ if (retval < 0) {
45973+ send_sig(SIGKILL, current, 0);
45974+ goto out_free_dentry;
45975+ }
45976+ }
45977+#endif
45978+
45979 if (elf_interpreter) {
45980- unsigned long interp_map_addr = 0;
45981-
45982 elf_entry = load_elf_interp(&loc->interp_elf_ex,
45983 interpreter,
45984- &interp_map_addr,
45985 load_bias);
45986 if (!IS_ERR((void *)elf_entry)) {
45987 /*
45988@@ -1115,7 +1561,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
45989 * Decide what to dump of a segment, part, all or none.
45990 */
45991 static unsigned long vma_dump_size(struct vm_area_struct *vma,
45992- unsigned long mm_flags)
45993+ unsigned long mm_flags, long signr)
45994 {
45995 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
45996
45997@@ -1152,7 +1598,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
45998 if (vma->vm_file == NULL)
45999 return 0;
46000
46001- if (FILTER(MAPPED_PRIVATE))
46002+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
46003 goto whole;
46004
46005 /*
46006@@ -1374,9 +1820,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
46007 {
46008 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
46009 int i = 0;
46010- do
46011+ do {
46012 i += 2;
46013- while (auxv[i - 2] != AT_NULL);
46014+ } while (auxv[i - 2] != AT_NULL);
46015 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
46016 }
46017
46018@@ -2006,14 +2452,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
46019 }
46020
46021 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
46022- unsigned long mm_flags)
46023+ struct coredump_params *cprm)
46024 {
46025 struct vm_area_struct *vma;
46026 size_t size = 0;
46027
46028 for (vma = first_vma(current, gate_vma); vma != NULL;
46029 vma = next_vma(vma, gate_vma))
46030- size += vma_dump_size(vma, mm_flags);
46031+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
46032 return size;
46033 }
46034
46035@@ -2107,7 +2553,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46036
46037 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
46038
46039- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
46040+ offset += elf_core_vma_data_size(gate_vma, cprm);
46041 offset += elf_core_extra_data_size();
46042 e_shoff = offset;
46043
46044@@ -2121,10 +2567,12 @@ static int elf_core_dump(struct coredump_params *cprm)
46045 offset = dataoff;
46046
46047 size += sizeof(*elf);
46048+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
46049 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
46050 goto end_coredump;
46051
46052 size += sizeof(*phdr4note);
46053+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
46054 if (size > cprm->limit
46055 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
46056 goto end_coredump;
46057@@ -2138,7 +2586,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46058 phdr.p_offset = offset;
46059 phdr.p_vaddr = vma->vm_start;
46060 phdr.p_paddr = 0;
46061- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
46062+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
46063 phdr.p_memsz = vma->vm_end - vma->vm_start;
46064 offset += phdr.p_filesz;
46065 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
46066@@ -2149,6 +2597,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46067 phdr.p_align = ELF_EXEC_PAGESIZE;
46068
46069 size += sizeof(phdr);
46070+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
46071 if (size > cprm->limit
46072 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
46073 goto end_coredump;
46074@@ -2173,7 +2622,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46075 unsigned long addr;
46076 unsigned long end;
46077
46078- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
46079+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
46080
46081 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
46082 struct page *page;
46083@@ -2182,6 +2631,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46084 page = get_dump_page(addr);
46085 if (page) {
46086 void *kaddr = kmap(page);
46087+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
46088 stop = ((size += PAGE_SIZE) > cprm->limit) ||
46089 !dump_write(cprm->file, kaddr,
46090 PAGE_SIZE);
46091@@ -2199,6 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46092
46093 if (e_phnum == PN_XNUM) {
46094 size += sizeof(*shdr4extnum);
46095+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
46096 if (size > cprm->limit
46097 || !dump_write(cprm->file, shdr4extnum,
46098 sizeof(*shdr4extnum)))
46099@@ -2219,6 +2670,97 @@ out:
46100
46101 #endif /* CONFIG_ELF_CORE */
46102
46103+#ifdef CONFIG_PAX_MPROTECT
46104+/* PaX: non-PIC ELF libraries need relocations on their executable segments
46105+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
46106+ * we'll remove VM_MAYWRITE for good on RELRO segments.
46107+ *
46108+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
46109+ * basis because we want to allow the common case and not the special ones.
46110+ */
46111+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
46112+{
46113+ struct elfhdr elf_h;
46114+ struct elf_phdr elf_p;
46115+ unsigned long i;
46116+ unsigned long oldflags;
46117+ bool is_textrel_rw, is_textrel_rx, is_relro;
46118+
46119+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
46120+ return;
46121+
46122+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
46123+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
46124+
46125+#ifdef CONFIG_PAX_ELFRELOCS
46126+ /* possible TEXTREL */
46127+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
46128+ 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);
46129+#else
46130+ is_textrel_rw = false;
46131+ is_textrel_rx = false;
46132+#endif
46133+
46134+ /* possible RELRO */
46135+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
46136+
46137+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
46138+ return;
46139+
46140+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
46141+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
46142+
46143+#ifdef CONFIG_PAX_ETEXECRELOCS
46144+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
46145+#else
46146+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
46147+#endif
46148+
46149+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
46150+ !elf_check_arch(&elf_h) ||
46151+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
46152+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
46153+ return;
46154+
46155+ for (i = 0UL; i < elf_h.e_phnum; i++) {
46156+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
46157+ return;
46158+ switch (elf_p.p_type) {
46159+ case PT_DYNAMIC:
46160+ if (!is_textrel_rw && !is_textrel_rx)
46161+ continue;
46162+ i = 0UL;
46163+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
46164+ elf_dyn dyn;
46165+
46166+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
46167+ return;
46168+ if (dyn.d_tag == DT_NULL)
46169+ return;
46170+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
46171+ gr_log_textrel(vma);
46172+ if (is_textrel_rw)
46173+ vma->vm_flags |= VM_MAYWRITE;
46174+ else
46175+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
46176+ vma->vm_flags &= ~VM_MAYWRITE;
46177+ return;
46178+ }
46179+ i++;
46180+ }
46181+ return;
46182+
46183+ case PT_GNU_RELRO:
46184+ if (!is_relro)
46185+ continue;
46186+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
46187+ vma->vm_flags &= ~VM_MAYWRITE;
46188+ return;
46189+ }
46190+ }
46191+}
46192+#endif
46193+
46194 static int __init init_elf_binfmt(void)
46195 {
46196 register_binfmt(&elf_format);
46197diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
46198index b563719..3868998 100644
46199--- a/fs/binfmt_flat.c
46200+++ b/fs/binfmt_flat.c
46201@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
46202 realdatastart = (unsigned long) -ENOMEM;
46203 printk("Unable to allocate RAM for process data, errno %d\n",
46204 (int)-realdatastart);
46205+ down_write(&current->mm->mmap_sem);
46206 vm_munmap(textpos, text_len);
46207+ up_write(&current->mm->mmap_sem);
46208 ret = realdatastart;
46209 goto err;
46210 }
46211@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
46212 }
46213 if (IS_ERR_VALUE(result)) {
46214 printk("Unable to read data+bss, errno %d\n", (int)-result);
46215+ down_write(&current->mm->mmap_sem);
46216 vm_munmap(textpos, text_len);
46217 vm_munmap(realdatastart, len);
46218+ up_write(&current->mm->mmap_sem);
46219 ret = result;
46220 goto err;
46221 }
46222@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
46223 }
46224 if (IS_ERR_VALUE(result)) {
46225 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
46226+ down_write(&current->mm->mmap_sem);
46227 vm_munmap(textpos, text_len + data_len + extra +
46228 MAX_SHARED_LIBS * sizeof(unsigned long));
46229+ up_write(&current->mm->mmap_sem);
46230 ret = result;
46231 goto err;
46232 }
46233diff --git a/fs/bio.c b/fs/bio.c
46234index b96fc6c..431d628 100644
46235--- a/fs/bio.c
46236+++ b/fs/bio.c
46237@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
46238 /*
46239 * Overflow, abort
46240 */
46241- if (end < start)
46242+ if (end < start || end - start > INT_MAX - nr_pages)
46243 return ERR_PTR(-EINVAL);
46244
46245 nr_pages += end - start;
46246@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
46247 /*
46248 * Overflow, abort
46249 */
46250- if (end < start)
46251+ if (end < start || end - start > INT_MAX - nr_pages)
46252 return ERR_PTR(-EINVAL);
46253
46254 nr_pages += end - start;
46255@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
46256 const int read = bio_data_dir(bio) == READ;
46257 struct bio_map_data *bmd = bio->bi_private;
46258 int i;
46259- char *p = bmd->sgvecs[0].iov_base;
46260+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
46261
46262 __bio_for_each_segment(bvec, bio, i, 0) {
46263 char *addr = page_address(bvec->bv_page);
46264diff --git a/fs/block_dev.c b/fs/block_dev.c
46265index 172f849..6efbf24 100644
46266--- a/fs/block_dev.c
46267+++ b/fs/block_dev.c
46268@@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
46269 else if (bdev->bd_contains == bdev)
46270 return true; /* is a whole device which isn't held */
46271
46272- else if (whole->bd_holder == bd_may_claim)
46273+ else if (whole->bd_holder == (void *)bd_may_claim)
46274 return true; /* is a partition of a device that is being partitioned */
46275 else if (whole->bd_holder != NULL)
46276 return false; /* is a partition of a held device */
46277diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
46278index eea5da7..88fead70 100644
46279--- a/fs/btrfs/ctree.c
46280+++ b/fs/btrfs/ctree.c
46281@@ -1033,9 +1033,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
46282 free_extent_buffer(buf);
46283 add_root_to_dirty_list(root);
46284 } else {
46285- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
46286- parent_start = parent->start;
46287- else
46288+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
46289+ if (parent)
46290+ parent_start = parent->start;
46291+ else
46292+ parent_start = 0;
46293+ } else
46294 parent_start = 0;
46295
46296 WARN_ON(trans->transid != btrfs_header_generation(parent));
46297diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
46298index cc93b23..f3c42bf 100644
46299--- a/fs/btrfs/inode.c
46300+++ b/fs/btrfs/inode.c
46301@@ -7296,7 +7296,7 @@ fail:
46302 return -ENOMEM;
46303 }
46304
46305-static int btrfs_getattr(struct vfsmount *mnt,
46306+int btrfs_getattr(struct vfsmount *mnt,
46307 struct dentry *dentry, struct kstat *stat)
46308 {
46309 struct inode *inode = dentry->d_inode;
46310@@ -7310,6 +7310,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
46311 return 0;
46312 }
46313
46314+EXPORT_SYMBOL(btrfs_getattr);
46315+
46316+dev_t get_btrfs_dev_from_inode(struct inode *inode)
46317+{
46318+ return BTRFS_I(inode)->root->anon_dev;
46319+}
46320+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
46321+
46322 /*
46323 * If a file is moved, it will inherit the cow and compression flags of the new
46324 * directory.
46325diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
46326index 338f259..b657640 100644
46327--- a/fs/btrfs/ioctl.c
46328+++ b/fs/btrfs/ioctl.c
46329@@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
46330 for (i = 0; i < num_types; i++) {
46331 struct btrfs_space_info *tmp;
46332
46333+ /* Don't copy in more than we allocated */
46334 if (!slot_count)
46335 break;
46336
46337+ slot_count--;
46338+
46339 info = NULL;
46340 rcu_read_lock();
46341 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
46342@@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
46343 memcpy(dest, &space, sizeof(space));
46344 dest++;
46345 space_args.total_spaces++;
46346- slot_count--;
46347 }
46348- if (!slot_count)
46349- break;
46350 }
46351 up_read(&info->groups_sem);
46352 }
46353diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
46354index 300e09a..9fe4539 100644
46355--- a/fs/btrfs/relocation.c
46356+++ b/fs/btrfs/relocation.c
46357@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
46358 }
46359 spin_unlock(&rc->reloc_root_tree.lock);
46360
46361- BUG_ON((struct btrfs_root *)node->data != root);
46362+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
46363
46364 if (!del) {
46365 spin_lock(&rc->reloc_root_tree.lock);
46366diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
46367index d8982e9..29a85fa 100644
46368--- a/fs/btrfs/super.c
46369+++ b/fs/btrfs/super.c
46370@@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
46371 function, line, errstr);
46372 return;
46373 }
46374- ACCESS_ONCE(trans->transaction->aborted) = errno;
46375+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
46376 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
46377 }
46378 /*
46379diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
46380index 622f469..e8d2d55 100644
46381--- a/fs/cachefiles/bind.c
46382+++ b/fs/cachefiles/bind.c
46383@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
46384 args);
46385
46386 /* start by checking things over */
46387- ASSERT(cache->fstop_percent >= 0 &&
46388- cache->fstop_percent < cache->fcull_percent &&
46389+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
46390 cache->fcull_percent < cache->frun_percent &&
46391 cache->frun_percent < 100);
46392
46393- ASSERT(cache->bstop_percent >= 0 &&
46394- cache->bstop_percent < cache->bcull_percent &&
46395+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
46396 cache->bcull_percent < cache->brun_percent &&
46397 cache->brun_percent < 100);
46398
46399diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
46400index 0a1467b..6a53245 100644
46401--- a/fs/cachefiles/daemon.c
46402+++ b/fs/cachefiles/daemon.c
46403@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
46404 if (n > buflen)
46405 return -EMSGSIZE;
46406
46407- if (copy_to_user(_buffer, buffer, n) != 0)
46408+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
46409 return -EFAULT;
46410
46411 return n;
46412@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
46413 if (test_bit(CACHEFILES_DEAD, &cache->flags))
46414 return -EIO;
46415
46416- if (datalen < 0 || datalen > PAGE_SIZE - 1)
46417+ if (datalen > PAGE_SIZE - 1)
46418 return -EOPNOTSUPP;
46419
46420 /* drag the command string into the kernel so we can parse it */
46421@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
46422 if (args[0] != '%' || args[1] != '\0')
46423 return -EINVAL;
46424
46425- if (fstop < 0 || fstop >= cache->fcull_percent)
46426+ if (fstop >= cache->fcull_percent)
46427 return cachefiles_daemon_range_error(cache, args);
46428
46429 cache->fstop_percent = fstop;
46430@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
46431 if (args[0] != '%' || args[1] != '\0')
46432 return -EINVAL;
46433
46434- if (bstop < 0 || bstop >= cache->bcull_percent)
46435+ if (bstop >= cache->bcull_percent)
46436 return cachefiles_daemon_range_error(cache, args);
46437
46438 cache->bstop_percent = bstop;
46439diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
46440index 4938251..7e01445 100644
46441--- a/fs/cachefiles/internal.h
46442+++ b/fs/cachefiles/internal.h
46443@@ -59,7 +59,7 @@ struct cachefiles_cache {
46444 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
46445 struct rb_root active_nodes; /* active nodes (can't be culled) */
46446 rwlock_t active_lock; /* lock for active_nodes */
46447- atomic_t gravecounter; /* graveyard uniquifier */
46448+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
46449 unsigned frun_percent; /* when to stop culling (% files) */
46450 unsigned fcull_percent; /* when to start culling (% files) */
46451 unsigned fstop_percent; /* when to stop allocating (% files) */
46452@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
46453 * proc.c
46454 */
46455 #ifdef CONFIG_CACHEFILES_HISTOGRAM
46456-extern atomic_t cachefiles_lookup_histogram[HZ];
46457-extern atomic_t cachefiles_mkdir_histogram[HZ];
46458-extern atomic_t cachefiles_create_histogram[HZ];
46459+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
46460+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
46461+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
46462
46463 extern int __init cachefiles_proc_init(void);
46464 extern void cachefiles_proc_cleanup(void);
46465 static inline
46466-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
46467+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
46468 {
46469 unsigned long jif = jiffies - start_jif;
46470 if (jif >= HZ)
46471 jif = HZ - 1;
46472- atomic_inc(&histogram[jif]);
46473+ atomic_inc_unchecked(&histogram[jif]);
46474 }
46475
46476 #else
46477diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
46478index 8c01c5fc..15f982e 100644
46479--- a/fs/cachefiles/namei.c
46480+++ b/fs/cachefiles/namei.c
46481@@ -317,7 +317,7 @@ try_again:
46482 /* first step is to make up a grave dentry in the graveyard */
46483 sprintf(nbuffer, "%08x%08x",
46484 (uint32_t) get_seconds(),
46485- (uint32_t) atomic_inc_return(&cache->gravecounter));
46486+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
46487
46488 /* do the multiway lock magic */
46489 trap = lock_rename(cache->graveyard, dir);
46490diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
46491index eccd339..4c1d995 100644
46492--- a/fs/cachefiles/proc.c
46493+++ b/fs/cachefiles/proc.c
46494@@ -14,9 +14,9 @@
46495 #include <linux/seq_file.h>
46496 #include "internal.h"
46497
46498-atomic_t cachefiles_lookup_histogram[HZ];
46499-atomic_t cachefiles_mkdir_histogram[HZ];
46500-atomic_t cachefiles_create_histogram[HZ];
46501+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
46502+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
46503+atomic_unchecked_t cachefiles_create_histogram[HZ];
46504
46505 /*
46506 * display the latency histogram
46507@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
46508 return 0;
46509 default:
46510 index = (unsigned long) v - 3;
46511- x = atomic_read(&cachefiles_lookup_histogram[index]);
46512- y = atomic_read(&cachefiles_mkdir_histogram[index]);
46513- z = atomic_read(&cachefiles_create_histogram[index]);
46514+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
46515+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
46516+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
46517 if (x == 0 && y == 0 && z == 0)
46518 return 0;
46519
46520diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
46521index 4809922..aab2c39 100644
46522--- a/fs/cachefiles/rdwr.c
46523+++ b/fs/cachefiles/rdwr.c
46524@@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
46525 old_fs = get_fs();
46526 set_fs(KERNEL_DS);
46527 ret = file->f_op->write(
46528- file, (const void __user *) data, len, &pos);
46529+ file, (const void __force_user *) data, len, &pos);
46530 set_fs(old_fs);
46531 kunmap(page);
46532 if (ret != len)
46533diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
46534index 8c1aabe..bbf856a 100644
46535--- a/fs/ceph/dir.c
46536+++ b/fs/ceph/dir.c
46537@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
46538 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
46539 struct ceph_mds_client *mdsc = fsc->mdsc;
46540 unsigned frag = fpos_frag(filp->f_pos);
46541- int off = fpos_off(filp->f_pos);
46542+ unsigned int off = fpos_off(filp->f_pos);
46543 int err;
46544 u32 ftype;
46545 struct ceph_mds_reply_info_parsed *rinfo;
46546diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
46547index d9ea6ed..1e6c8ac 100644
46548--- a/fs/cifs/cifs_debug.c
46549+++ b/fs/cifs/cifs_debug.c
46550@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
46551
46552 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
46553 #ifdef CONFIG_CIFS_STATS2
46554- atomic_set(&totBufAllocCount, 0);
46555- atomic_set(&totSmBufAllocCount, 0);
46556+ atomic_set_unchecked(&totBufAllocCount, 0);
46557+ atomic_set_unchecked(&totSmBufAllocCount, 0);
46558 #endif /* CONFIG_CIFS_STATS2 */
46559 spin_lock(&cifs_tcp_ses_lock);
46560 list_for_each(tmp1, &cifs_tcp_ses_list) {
46561@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
46562 tcon = list_entry(tmp3,
46563 struct cifs_tcon,
46564 tcon_list);
46565- atomic_set(&tcon->num_smbs_sent, 0);
46566+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
46567 if (server->ops->clear_stats)
46568 server->ops->clear_stats(tcon);
46569 }
46570@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
46571 smBufAllocCount.counter, cifs_min_small);
46572 #ifdef CONFIG_CIFS_STATS2
46573 seq_printf(m, "Total Large %d Small %d Allocations\n",
46574- atomic_read(&totBufAllocCount),
46575- atomic_read(&totSmBufAllocCount));
46576+ atomic_read_unchecked(&totBufAllocCount),
46577+ atomic_read_unchecked(&totSmBufAllocCount));
46578 #endif /* CONFIG_CIFS_STATS2 */
46579
46580 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
46581@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
46582 if (tcon->need_reconnect)
46583 seq_puts(m, "\tDISCONNECTED ");
46584 seq_printf(m, "\nSMBs: %d",
46585- atomic_read(&tcon->num_smbs_sent));
46586+ atomic_read_unchecked(&tcon->num_smbs_sent));
46587 if (server->ops->print_stats)
46588 server->ops->print_stats(m, tcon);
46589 }
46590diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
46591index de7f916..6cb22a9 100644
46592--- a/fs/cifs/cifsfs.c
46593+++ b/fs/cifs/cifsfs.c
46594@@ -997,7 +997,7 @@ cifs_init_request_bufs(void)
46595 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
46596 cifs_req_cachep = kmem_cache_create("cifs_request",
46597 CIFSMaxBufSize + max_hdr_size, 0,
46598- SLAB_HWCACHE_ALIGN, NULL);
46599+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
46600 if (cifs_req_cachep == NULL)
46601 return -ENOMEM;
46602
46603@@ -1024,7 +1024,7 @@ cifs_init_request_bufs(void)
46604 efficient to alloc 1 per page off the slab compared to 17K (5page)
46605 alloc of large cifs buffers even when page debugging is on */
46606 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
46607- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
46608+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
46609 NULL);
46610 if (cifs_sm_req_cachep == NULL) {
46611 mempool_destroy(cifs_req_poolp);
46612@@ -1109,8 +1109,8 @@ init_cifs(void)
46613 atomic_set(&bufAllocCount, 0);
46614 atomic_set(&smBufAllocCount, 0);
46615 #ifdef CONFIG_CIFS_STATS2
46616- atomic_set(&totBufAllocCount, 0);
46617- atomic_set(&totSmBufAllocCount, 0);
46618+ atomic_set_unchecked(&totBufAllocCount, 0);
46619+ atomic_set_unchecked(&totSmBufAllocCount, 0);
46620 #endif /* CONFIG_CIFS_STATS2 */
46621
46622 atomic_set(&midCount, 0);
46623diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
46624index e6899ce..d6b2920 100644
46625--- a/fs/cifs/cifsglob.h
46626+++ b/fs/cifs/cifsglob.h
46627@@ -751,35 +751,35 @@ struct cifs_tcon {
46628 __u16 Flags; /* optional support bits */
46629 enum statusEnum tidStatus;
46630 #ifdef CONFIG_CIFS_STATS
46631- atomic_t num_smbs_sent;
46632+ atomic_unchecked_t num_smbs_sent;
46633 union {
46634 struct {
46635- atomic_t num_writes;
46636- atomic_t num_reads;
46637- atomic_t num_flushes;
46638- atomic_t num_oplock_brks;
46639- atomic_t num_opens;
46640- atomic_t num_closes;
46641- atomic_t num_deletes;
46642- atomic_t num_mkdirs;
46643- atomic_t num_posixopens;
46644- atomic_t num_posixmkdirs;
46645- atomic_t num_rmdirs;
46646- atomic_t num_renames;
46647- atomic_t num_t2renames;
46648- atomic_t num_ffirst;
46649- atomic_t num_fnext;
46650- atomic_t num_fclose;
46651- atomic_t num_hardlinks;
46652- atomic_t num_symlinks;
46653- atomic_t num_locks;
46654- atomic_t num_acl_get;
46655- atomic_t num_acl_set;
46656+ atomic_unchecked_t num_writes;
46657+ atomic_unchecked_t num_reads;
46658+ atomic_unchecked_t num_flushes;
46659+ atomic_unchecked_t num_oplock_brks;
46660+ atomic_unchecked_t num_opens;
46661+ atomic_unchecked_t num_closes;
46662+ atomic_unchecked_t num_deletes;
46663+ atomic_unchecked_t num_mkdirs;
46664+ atomic_unchecked_t num_posixopens;
46665+ atomic_unchecked_t num_posixmkdirs;
46666+ atomic_unchecked_t num_rmdirs;
46667+ atomic_unchecked_t num_renames;
46668+ atomic_unchecked_t num_t2renames;
46669+ atomic_unchecked_t num_ffirst;
46670+ atomic_unchecked_t num_fnext;
46671+ atomic_unchecked_t num_fclose;
46672+ atomic_unchecked_t num_hardlinks;
46673+ atomic_unchecked_t num_symlinks;
46674+ atomic_unchecked_t num_locks;
46675+ atomic_unchecked_t num_acl_get;
46676+ atomic_unchecked_t num_acl_set;
46677 } cifs_stats;
46678 #ifdef CONFIG_CIFS_SMB2
46679 struct {
46680- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
46681- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
46682+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
46683+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
46684 } smb2_stats;
46685 #endif /* CONFIG_CIFS_SMB2 */
46686 } stats;
46687@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
46688 }
46689
46690 #ifdef CONFIG_CIFS_STATS
46691-#define cifs_stats_inc atomic_inc
46692+#define cifs_stats_inc atomic_inc_unchecked
46693
46694 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
46695 unsigned int bytes)
46696@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
46697 /* Various Debug counters */
46698 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
46699 #ifdef CONFIG_CIFS_STATS2
46700-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
46701-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
46702+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
46703+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
46704 #endif
46705 GLOBAL_EXTERN atomic_t smBufAllocCount;
46706 GLOBAL_EXTERN atomic_t midCount;
46707diff --git a/fs/cifs/link.c b/fs/cifs/link.c
46708index 51dc2fb..1e12a33 100644
46709--- a/fs/cifs/link.c
46710+++ b/fs/cifs/link.c
46711@@ -616,7 +616,7 @@ symlink_exit:
46712
46713 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
46714 {
46715- char *p = nd_get_link(nd);
46716+ const char *p = nd_get_link(nd);
46717 if (!IS_ERR(p))
46718 kfree(p);
46719 }
46720diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
46721index 3a00c0d..42d901c 100644
46722--- a/fs/cifs/misc.c
46723+++ b/fs/cifs/misc.c
46724@@ -169,7 +169,7 @@ cifs_buf_get(void)
46725 memset(ret_buf, 0, buf_size + 3);
46726 atomic_inc(&bufAllocCount);
46727 #ifdef CONFIG_CIFS_STATS2
46728- atomic_inc(&totBufAllocCount);
46729+ atomic_inc_unchecked(&totBufAllocCount);
46730 #endif /* CONFIG_CIFS_STATS2 */
46731 }
46732
46733@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
46734 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
46735 atomic_inc(&smBufAllocCount);
46736 #ifdef CONFIG_CIFS_STATS2
46737- atomic_inc(&totSmBufAllocCount);
46738+ atomic_inc_unchecked(&totSmBufAllocCount);
46739 #endif /* CONFIG_CIFS_STATS2 */
46740
46741 }
46742diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
46743index 47bc5a8..10decbe 100644
46744--- a/fs/cifs/smb1ops.c
46745+++ b/fs/cifs/smb1ops.c
46746@@ -586,27 +586,27 @@ static void
46747 cifs_clear_stats(struct cifs_tcon *tcon)
46748 {
46749 #ifdef CONFIG_CIFS_STATS
46750- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
46751- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
46752- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
46753- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46754- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
46755- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
46756- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46757- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
46758- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
46759- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
46760- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
46761- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
46762- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
46763- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
46764- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
46765- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
46766- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
46767- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
46768- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
46769- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
46770- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
46771+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
46772+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
46773+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
46774+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46775+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
46776+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
46777+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46778+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
46779+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
46780+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
46781+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
46782+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
46783+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
46784+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
46785+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
46786+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
46787+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
46788+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
46789+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
46790+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
46791+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
46792 #endif
46793 }
46794
46795@@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46796 {
46797 #ifdef CONFIG_CIFS_STATS
46798 seq_printf(m, " Oplocks breaks: %d",
46799- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
46800+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
46801 seq_printf(m, "\nReads: %d Bytes: %llu",
46802- atomic_read(&tcon->stats.cifs_stats.num_reads),
46803+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
46804 (long long)(tcon->bytes_read));
46805 seq_printf(m, "\nWrites: %d Bytes: %llu",
46806- atomic_read(&tcon->stats.cifs_stats.num_writes),
46807+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
46808 (long long)(tcon->bytes_written));
46809 seq_printf(m, "\nFlushes: %d",
46810- atomic_read(&tcon->stats.cifs_stats.num_flushes));
46811+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
46812 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
46813- atomic_read(&tcon->stats.cifs_stats.num_locks),
46814- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
46815- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
46816+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
46817+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
46818+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
46819 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
46820- atomic_read(&tcon->stats.cifs_stats.num_opens),
46821- atomic_read(&tcon->stats.cifs_stats.num_closes),
46822- atomic_read(&tcon->stats.cifs_stats.num_deletes));
46823+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
46824+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
46825+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
46826 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
46827- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
46828- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
46829+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
46830+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
46831 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
46832- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
46833- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
46834+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
46835+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
46836 seq_printf(m, "\nRenames: %d T2 Renames %d",
46837- atomic_read(&tcon->stats.cifs_stats.num_renames),
46838- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
46839+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
46840+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
46841 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
46842- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
46843- atomic_read(&tcon->stats.cifs_stats.num_fnext),
46844- atomic_read(&tcon->stats.cifs_stats.num_fclose));
46845+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
46846+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
46847+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
46848 #endif
46849 }
46850
46851diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
46852index c9c7aa7..065056a 100644
46853--- a/fs/cifs/smb2ops.c
46854+++ b/fs/cifs/smb2ops.c
46855@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
46856 #ifdef CONFIG_CIFS_STATS
46857 int i;
46858 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
46859- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46860- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46861+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46862+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46863 }
46864 #endif
46865 }
46866@@ -284,66 +284,66 @@ static void
46867 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46868 {
46869 #ifdef CONFIG_CIFS_STATS
46870- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46871- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46872+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46873+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46874 seq_printf(m, "\nNegotiates: %d sent %d failed",
46875- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
46876- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
46877+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
46878+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
46879 seq_printf(m, "\nSessionSetups: %d sent %d failed",
46880- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
46881- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
46882+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
46883+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
46884 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
46885 seq_printf(m, "\nLogoffs: %d sent %d failed",
46886- atomic_read(&sent[SMB2_LOGOFF_HE]),
46887- atomic_read(&failed[SMB2_LOGOFF_HE]));
46888+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
46889+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
46890 seq_printf(m, "\nTreeConnects: %d sent %d failed",
46891- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
46892- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
46893+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
46894+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
46895 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
46896- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
46897- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
46898+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
46899+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
46900 seq_printf(m, "\nCreates: %d sent %d failed",
46901- atomic_read(&sent[SMB2_CREATE_HE]),
46902- atomic_read(&failed[SMB2_CREATE_HE]));
46903+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
46904+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
46905 seq_printf(m, "\nCloses: %d sent %d failed",
46906- atomic_read(&sent[SMB2_CLOSE_HE]),
46907- atomic_read(&failed[SMB2_CLOSE_HE]));
46908+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
46909+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
46910 seq_printf(m, "\nFlushes: %d sent %d failed",
46911- atomic_read(&sent[SMB2_FLUSH_HE]),
46912- atomic_read(&failed[SMB2_FLUSH_HE]));
46913+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
46914+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
46915 seq_printf(m, "\nReads: %d sent %d failed",
46916- atomic_read(&sent[SMB2_READ_HE]),
46917- atomic_read(&failed[SMB2_READ_HE]));
46918+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
46919+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
46920 seq_printf(m, "\nWrites: %d sent %d failed",
46921- atomic_read(&sent[SMB2_WRITE_HE]),
46922- atomic_read(&failed[SMB2_WRITE_HE]));
46923+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
46924+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
46925 seq_printf(m, "\nLocks: %d sent %d failed",
46926- atomic_read(&sent[SMB2_LOCK_HE]),
46927- atomic_read(&failed[SMB2_LOCK_HE]));
46928+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
46929+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
46930 seq_printf(m, "\nIOCTLs: %d sent %d failed",
46931- atomic_read(&sent[SMB2_IOCTL_HE]),
46932- atomic_read(&failed[SMB2_IOCTL_HE]));
46933+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
46934+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
46935 seq_printf(m, "\nCancels: %d sent %d failed",
46936- atomic_read(&sent[SMB2_CANCEL_HE]),
46937- atomic_read(&failed[SMB2_CANCEL_HE]));
46938+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
46939+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
46940 seq_printf(m, "\nEchos: %d sent %d failed",
46941- atomic_read(&sent[SMB2_ECHO_HE]),
46942- atomic_read(&failed[SMB2_ECHO_HE]));
46943+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
46944+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
46945 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
46946- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
46947- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
46948+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
46949+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
46950 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
46951- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
46952- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
46953+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
46954+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
46955 seq_printf(m, "\nQueryInfos: %d sent %d failed",
46956- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
46957- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
46958+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
46959+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
46960 seq_printf(m, "\nSetInfos: %d sent %d failed",
46961- atomic_read(&sent[SMB2_SET_INFO_HE]),
46962- atomic_read(&failed[SMB2_SET_INFO_HE]));
46963+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
46964+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
46965 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
46966- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
46967- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
46968+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
46969+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
46970 #endif
46971 }
46972
46973diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
46974index 41d9d07..dbb4772 100644
46975--- a/fs/cifs/smb2pdu.c
46976+++ b/fs/cifs/smb2pdu.c
46977@@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
46978 default:
46979 cERROR(1, "info level %u isn't supported",
46980 srch_inf->info_level);
46981- rc = -EINVAL;
46982- goto qdir_exit;
46983+ return -EINVAL;
46984 }
46985
46986 req->FileIndex = cpu_to_le32(index);
46987diff --git a/fs/coda/cache.c b/fs/coda/cache.c
46988index 958ae0e..505c9d0 100644
46989--- a/fs/coda/cache.c
46990+++ b/fs/coda/cache.c
46991@@ -24,7 +24,7 @@
46992 #include "coda_linux.h"
46993 #include "coda_cache.h"
46994
46995-static atomic_t permission_epoch = ATOMIC_INIT(0);
46996+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
46997
46998 /* replace or extend an acl cache hit */
46999 void coda_cache_enter(struct inode *inode, int mask)
47000@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
47001 struct coda_inode_info *cii = ITOC(inode);
47002
47003 spin_lock(&cii->c_lock);
47004- cii->c_cached_epoch = atomic_read(&permission_epoch);
47005+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
47006 if (cii->c_uid != current_fsuid()) {
47007 cii->c_uid = current_fsuid();
47008 cii->c_cached_perm = mask;
47009@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
47010 {
47011 struct coda_inode_info *cii = ITOC(inode);
47012 spin_lock(&cii->c_lock);
47013- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
47014+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
47015 spin_unlock(&cii->c_lock);
47016 }
47017
47018 /* remove all acl caches */
47019 void coda_cache_clear_all(struct super_block *sb)
47020 {
47021- atomic_inc(&permission_epoch);
47022+ atomic_inc_unchecked(&permission_epoch);
47023 }
47024
47025
47026@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
47027 spin_lock(&cii->c_lock);
47028 hit = (mask & cii->c_cached_perm) == mask &&
47029 cii->c_uid == current_fsuid() &&
47030- cii->c_cached_epoch == atomic_read(&permission_epoch);
47031+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
47032 spin_unlock(&cii->c_lock);
47033
47034 return hit;
47035diff --git a/fs/compat.c b/fs/compat.c
47036index 015e1e1..5ce8e54 100644
47037--- a/fs/compat.c
47038+++ b/fs/compat.c
47039@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
47040
47041 set_fs(KERNEL_DS);
47042 /* The __user pointer cast is valid because of the set_fs() */
47043- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
47044+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
47045 set_fs(oldfs);
47046 /* truncating is ok because it's a user address */
47047 if (!ret)
47048@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
47049 goto out;
47050
47051 ret = -EINVAL;
47052- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
47053+ if (nr_segs > UIO_MAXIOV)
47054 goto out;
47055 if (nr_segs > fast_segs) {
47056 ret = -ENOMEM;
47057@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
47058
47059 struct compat_readdir_callback {
47060 struct compat_old_linux_dirent __user *dirent;
47061+ struct file * file;
47062 int result;
47063 };
47064
47065@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
47066 buf->result = -EOVERFLOW;
47067 return -EOVERFLOW;
47068 }
47069+
47070+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47071+ return 0;
47072+
47073 buf->result++;
47074 dirent = buf->dirent;
47075 if (!access_ok(VERIFY_WRITE, dirent,
47076@@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
47077
47078 buf.result = 0;
47079 buf.dirent = dirent;
47080+ buf.file = f.file;
47081
47082 error = vfs_readdir(f.file, compat_fillonedir, &buf);
47083 if (buf.result)
47084@@ -897,6 +903,7 @@ struct compat_linux_dirent {
47085 struct compat_getdents_callback {
47086 struct compat_linux_dirent __user *current_dir;
47087 struct compat_linux_dirent __user *previous;
47088+ struct file * file;
47089 int count;
47090 int error;
47091 };
47092@@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
47093 buf->error = -EOVERFLOW;
47094 return -EOVERFLOW;
47095 }
47096+
47097+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47098+ return 0;
47099+
47100 dirent = buf->previous;
47101 if (dirent) {
47102 if (__put_user(offset, &dirent->d_off))
47103@@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
47104 buf.previous = NULL;
47105 buf.count = count;
47106 buf.error = 0;
47107+ buf.file = f.file;
47108
47109 error = vfs_readdir(f.file, compat_filldir, &buf);
47110 if (error >= 0)
47111@@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
47112 struct compat_getdents_callback64 {
47113 struct linux_dirent64 __user *current_dir;
47114 struct linux_dirent64 __user *previous;
47115+ struct file * file;
47116 int count;
47117 int error;
47118 };
47119@@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
47120 buf->error = -EINVAL; /* only used if we fail.. */
47121 if (reclen > buf->count)
47122 return -EINVAL;
47123+
47124+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47125+ return 0;
47126+
47127 dirent = buf->previous;
47128
47129 if (dirent) {
47130@@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
47131 buf.previous = NULL;
47132 buf.count = count;
47133 buf.error = 0;
47134+ buf.file = f.file;
47135
47136 error = vfs_readdir(f.file, compat_filldir64, &buf);
47137 if (error >= 0)
47138 error = buf.error;
47139 lastdirent = buf.previous;
47140 if (lastdirent) {
47141- typeof(lastdirent->d_off) d_off = f.file->f_pos;
47142+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
47143 if (__put_user_unaligned(d_off, &lastdirent->d_off))
47144 error = -EFAULT;
47145 else
47146diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
47147index a81147e..20bf2b5 100644
47148--- a/fs/compat_binfmt_elf.c
47149+++ b/fs/compat_binfmt_elf.c
47150@@ -30,11 +30,13 @@
47151 #undef elf_phdr
47152 #undef elf_shdr
47153 #undef elf_note
47154+#undef elf_dyn
47155 #undef elf_addr_t
47156 #define elfhdr elf32_hdr
47157 #define elf_phdr elf32_phdr
47158 #define elf_shdr elf32_shdr
47159 #define elf_note elf32_note
47160+#define elf_dyn Elf32_Dyn
47161 #define elf_addr_t Elf32_Addr
47162
47163 /*
47164diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
47165index e2f57a0..3c78771 100644
47166--- a/fs/compat_ioctl.c
47167+++ b/fs/compat_ioctl.c
47168@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
47169 return -EFAULT;
47170 if (__get_user(udata, &ss32->iomem_base))
47171 return -EFAULT;
47172- ss.iomem_base = compat_ptr(udata);
47173+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
47174 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
47175 __get_user(ss.port_high, &ss32->port_high))
47176 return -EFAULT;
47177@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
47178 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
47179 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
47180 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
47181- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
47182+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
47183 return -EFAULT;
47184
47185 return ioctl_preallocate(file, p);
47186@@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
47187 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
47188 {
47189 unsigned int a, b;
47190- a = *(unsigned int *)p;
47191- b = *(unsigned int *)q;
47192+ a = *(const unsigned int *)p;
47193+ b = *(const unsigned int *)q;
47194 if (a > b)
47195 return 1;
47196 if (a < b)
47197diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
47198index 712b10f..c33c4ca 100644
47199--- a/fs/configfs/dir.c
47200+++ b/fs/configfs/dir.c
47201@@ -1037,10 +1037,11 @@ static int configfs_dump(struct configfs_dirent *sd, int level)
47202 static int configfs_depend_prep(struct dentry *origin,
47203 struct config_item *target)
47204 {
47205- struct configfs_dirent *child_sd, *sd = origin->d_fsdata;
47206+ struct configfs_dirent *child_sd, *sd;
47207 int ret = 0;
47208
47209- BUG_ON(!origin || !sd);
47210+ BUG_ON(!origin || !origin->d_fsdata);
47211+ sd = origin->d_fsdata;
47212
47213 if (sd->s_element == target) /* Boo-yah */
47214 goto out;
47215@@ -1564,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
47216 }
47217 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
47218 struct configfs_dirent *next;
47219- const char * name;
47220+ const unsigned char * name;
47221+ char d_name[sizeof(next->s_dentry->d_iname)];
47222 int len;
47223 struct inode *inode = NULL;
47224
47225@@ -1574,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
47226 continue;
47227
47228 name = configfs_get_name(next);
47229- len = strlen(name);
47230+ if (next->s_dentry && name == next->s_dentry->d_iname) {
47231+ len = next->s_dentry->d_name.len;
47232+ memcpy(d_name, name, len);
47233+ name = d_name;
47234+ } else
47235+ len = strlen(name);
47236
47237 /*
47238 * We'll have a dentry and an inode for
47239diff --git a/fs/coredump.c b/fs/coredump.c
47240index 1774932..5812106 100644
47241--- a/fs/coredump.c
47242+++ b/fs/coredump.c
47243@@ -52,7 +52,7 @@ struct core_name {
47244 char *corename;
47245 int used, size;
47246 };
47247-static atomic_t call_count = ATOMIC_INIT(1);
47248+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
47249
47250 /* The maximal length of core_pattern is also specified in sysctl.c */
47251
47252@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
47253 {
47254 char *old_corename = cn->corename;
47255
47256- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
47257+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
47258 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
47259
47260 if (!cn->corename) {
47261@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
47262 int pid_in_pattern = 0;
47263 int err = 0;
47264
47265- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
47266+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
47267 cn->corename = kmalloc(cn->size, GFP_KERNEL);
47268 cn->used = 0;
47269
47270@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
47271 pipe = file->f_path.dentry->d_inode->i_pipe;
47272
47273 pipe_lock(pipe);
47274- pipe->readers++;
47275- pipe->writers--;
47276+ atomic_inc(&pipe->readers);
47277+ atomic_dec(&pipe->writers);
47278
47279- while ((pipe->readers > 1) && (!signal_pending(current))) {
47280+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
47281 wake_up_interruptible_sync(&pipe->wait);
47282 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47283 pipe_wait(pipe);
47284 }
47285
47286- pipe->readers--;
47287- pipe->writers++;
47288+ atomic_dec(&pipe->readers);
47289+ atomic_inc(&pipe->writers);
47290 pipe_unlock(pipe);
47291
47292 }
47293@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
47294 int ispipe;
47295 struct files_struct *displaced;
47296 bool need_nonrelative = false;
47297- static atomic_t core_dump_count = ATOMIC_INIT(0);
47298+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
47299+ long signr = siginfo->si_signo;
47300 struct coredump_params cprm = {
47301 .siginfo = siginfo,
47302 .regs = signal_pt_regs(),
47303@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
47304 .mm_flags = mm->flags,
47305 };
47306
47307- audit_core_dumps(siginfo->si_signo);
47308+ audit_core_dumps(signr);
47309+
47310+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
47311+ gr_handle_brute_attach(cprm.mm_flags);
47312
47313 binfmt = mm->binfmt;
47314 if (!binfmt || !binfmt->core_dump)
47315@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
47316 need_nonrelative = true;
47317 }
47318
47319- retval = coredump_wait(siginfo->si_signo, &core_state);
47320+ retval = coredump_wait(signr, &core_state);
47321 if (retval < 0)
47322 goto fail_creds;
47323
47324@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
47325 }
47326 cprm.limit = RLIM_INFINITY;
47327
47328- dump_count = atomic_inc_return(&core_dump_count);
47329+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
47330 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
47331 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
47332 task_tgid_vnr(current), current->comm);
47333@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
47334 } else {
47335 struct inode *inode;
47336
47337+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
47338+
47339 if (cprm.limit < binfmt->min_coredump)
47340 goto fail_unlock;
47341
47342@@ -640,7 +646,7 @@ close_fail:
47343 filp_close(cprm.file, NULL);
47344 fail_dropcount:
47345 if (ispipe)
47346- atomic_dec(&core_dump_count);
47347+ atomic_dec_unchecked(&core_dump_count);
47348 fail_unlock:
47349 kfree(cn.corename);
47350 fail_corename:
47351@@ -659,7 +665,7 @@ fail:
47352 */
47353 int dump_write(struct file *file, const void *addr, int nr)
47354 {
47355- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
47356+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
47357 }
47358 EXPORT_SYMBOL(dump_write);
47359
47360diff --git a/fs/dcache.c b/fs/dcache.c
47361index 19153a0..428c2f5 100644
47362--- a/fs/dcache.c
47363+++ b/fs/dcache.c
47364@@ -3133,7 +3133,7 @@ void __init vfs_caches_init(unsigned long mempages)
47365 mempages -= reserve;
47366
47367 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
47368- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
47369+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
47370
47371 dcache_init();
47372 inode_init();
47373diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
47374index a5f12b7..4ee8a6f 100644
47375--- a/fs/debugfs/inode.c
47376+++ b/fs/debugfs/inode.c
47377@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
47378 */
47379 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
47380 {
47381+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
47382+ return __create_file(name, S_IFDIR | S_IRWXU,
47383+#else
47384 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
47385+#endif
47386 parent, NULL, NULL);
47387 }
47388 EXPORT_SYMBOL_GPL(debugfs_create_dir);
47389diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
47390index cc7709e..7e7211f 100644
47391--- a/fs/ecryptfs/inode.c
47392+++ b/fs/ecryptfs/inode.c
47393@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
47394 old_fs = get_fs();
47395 set_fs(get_ds());
47396 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
47397- (char __user *)lower_buf,
47398+ (char __force_user *)lower_buf,
47399 PATH_MAX);
47400 set_fs(old_fs);
47401 if (rc < 0)
47402@@ -706,7 +706,7 @@ out:
47403 static void
47404 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
47405 {
47406- char *buf = nd_get_link(nd);
47407+ const char *buf = nd_get_link(nd);
47408 if (!IS_ERR(buf)) {
47409 /* Free the char* */
47410 kfree(buf);
47411diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
47412index 412e6ed..4292d22 100644
47413--- a/fs/ecryptfs/miscdev.c
47414+++ b/fs/ecryptfs/miscdev.c
47415@@ -315,7 +315,7 @@ check_list:
47416 goto out_unlock_msg_ctx;
47417 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
47418 if (msg_ctx->msg) {
47419- if (copy_to_user(&buf[i], packet_length, packet_length_size))
47420+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
47421 goto out_unlock_msg_ctx;
47422 i += packet_length_size;
47423 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
47424diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
47425index b2a34a1..162fa69 100644
47426--- a/fs/ecryptfs/read_write.c
47427+++ b/fs/ecryptfs/read_write.c
47428@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
47429 return -EIO;
47430 fs_save = get_fs();
47431 set_fs(get_ds());
47432- rc = vfs_write(lower_file, data, size, &offset);
47433+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
47434 set_fs(fs_save);
47435 mark_inode_dirty_sync(ecryptfs_inode);
47436 return rc;
47437@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
47438 return -EIO;
47439 fs_save = get_fs();
47440 set_fs(get_ds());
47441- rc = vfs_read(lower_file, data, size, &offset);
47442+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
47443 set_fs(fs_save);
47444 return rc;
47445 }
47446diff --git a/fs/exec.c b/fs/exec.c
47447index 20df02c..1dff97d 100644
47448--- a/fs/exec.c
47449+++ b/fs/exec.c
47450@@ -55,6 +55,17 @@
47451 #include <linux/pipe_fs_i.h>
47452 #include <linux/oom.h>
47453 #include <linux/compat.h>
47454+#include <linux/random.h>
47455+#include <linux/seq_file.h>
47456+#include <linux/coredump.h>
47457+#include <linux/mman.h>
47458+
47459+#ifdef CONFIG_PAX_REFCOUNT
47460+#include <linux/kallsyms.h>
47461+#include <linux/kdebug.h>
47462+#endif
47463+
47464+#include <trace/events/fs.h>
47465
47466 #include <asm/uaccess.h>
47467 #include <asm/mmu_context.h>
47468@@ -66,6 +77,18 @@
47469
47470 #include <trace/events/sched.h>
47471
47472+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
47473+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
47474+{
47475+ 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");
47476+}
47477+#endif
47478+
47479+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
47480+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
47481+EXPORT_SYMBOL(pax_set_initial_flags_func);
47482+#endif
47483+
47484 int suid_dumpable = 0;
47485
47486 static LIST_HEAD(formats);
47487@@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
47488 int write)
47489 {
47490 struct page *page;
47491- int ret;
47492
47493-#ifdef CONFIG_STACK_GROWSUP
47494- if (write) {
47495- ret = expand_downwards(bprm->vma, pos);
47496- if (ret < 0)
47497- return NULL;
47498- }
47499-#endif
47500- ret = get_user_pages(current, bprm->mm, pos,
47501- 1, write, 1, &page, NULL);
47502- if (ret <= 0)
47503+ if (0 > expand_downwards(bprm->vma, pos))
47504+ return NULL;
47505+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
47506 return NULL;
47507
47508 if (write) {
47509@@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
47510 if (size <= ARG_MAX)
47511 return page;
47512
47513+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47514+ // only allow 512KB for argv+env on suid/sgid binaries
47515+ // to prevent easy ASLR exhaustion
47516+ if (((bprm->cred->euid != current_euid()) ||
47517+ (bprm->cred->egid != current_egid())) &&
47518+ (size > (512 * 1024))) {
47519+ put_page(page);
47520+ return NULL;
47521+ }
47522+#endif
47523+
47524 /*
47525 * Limit to 1/4-th the stack size for the argv+env strings.
47526 * This ensures that:
47527@@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
47528 vma->vm_end = STACK_TOP_MAX;
47529 vma->vm_start = vma->vm_end - PAGE_SIZE;
47530 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
47531+
47532+#ifdef CONFIG_PAX_SEGMEXEC
47533+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
47534+#endif
47535+
47536 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
47537 INIT_LIST_HEAD(&vma->anon_vma_chain);
47538
47539@@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
47540 mm->stack_vm = mm->total_vm = 1;
47541 up_write(&mm->mmap_sem);
47542 bprm->p = vma->vm_end - sizeof(void *);
47543+
47544+#ifdef CONFIG_PAX_RANDUSTACK
47545+ if (randomize_va_space)
47546+ bprm->p ^= random32() & ~PAGE_MASK;
47547+#endif
47548+
47549 return 0;
47550 err:
47551 up_write(&mm->mmap_sem);
47552@@ -384,19 +421,7 @@ err:
47553 return err;
47554 }
47555
47556-struct user_arg_ptr {
47557-#ifdef CONFIG_COMPAT
47558- bool is_compat;
47559-#endif
47560- union {
47561- const char __user *const __user *native;
47562-#ifdef CONFIG_COMPAT
47563- const compat_uptr_t __user *compat;
47564-#endif
47565- } ptr;
47566-};
47567-
47568-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
47569+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
47570 {
47571 const char __user *native;
47572
47573@@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
47574 compat_uptr_t compat;
47575
47576 if (get_user(compat, argv.ptr.compat + nr))
47577- return ERR_PTR(-EFAULT);
47578+ return (const char __force_user *)ERR_PTR(-EFAULT);
47579
47580 return compat_ptr(compat);
47581 }
47582 #endif
47583
47584 if (get_user(native, argv.ptr.native + nr))
47585- return ERR_PTR(-EFAULT);
47586+ return (const char __force_user *)ERR_PTR(-EFAULT);
47587
47588 return native;
47589 }
47590@@ -431,7 +456,7 @@ static int count(struct user_arg_ptr argv, int max)
47591 if (!p)
47592 break;
47593
47594- if (IS_ERR(p))
47595+ if (IS_ERR((const char __force_kernel *)p))
47596 return -EFAULT;
47597
47598 if (i >= max)
47599@@ -466,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
47600
47601 ret = -EFAULT;
47602 str = get_user_arg_ptr(argv, argc);
47603- if (IS_ERR(str))
47604+ if (IS_ERR((const char __force_kernel *)str))
47605 goto out;
47606
47607 len = strnlen_user(str, MAX_ARG_STRLEN);
47608@@ -548,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
47609 int r;
47610 mm_segment_t oldfs = get_fs();
47611 struct user_arg_ptr argv = {
47612- .ptr.native = (const char __user *const __user *)__argv,
47613+ .ptr.native = (const char __force_user *const __force_user *)__argv,
47614 };
47615
47616 set_fs(KERNEL_DS);
47617@@ -583,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
47618 unsigned long new_end = old_end - shift;
47619 struct mmu_gather tlb;
47620
47621- BUG_ON(new_start > new_end);
47622+ if (new_start >= new_end || new_start < mmap_min_addr)
47623+ return -ENOMEM;
47624
47625 /*
47626 * ensure there are no vmas between where we want to go
47627@@ -592,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
47628 if (vma != find_vma(mm, new_start))
47629 return -EFAULT;
47630
47631+#ifdef CONFIG_PAX_SEGMEXEC
47632+ BUG_ON(pax_find_mirror_vma(vma));
47633+#endif
47634+
47635 /*
47636 * cover the whole range: [new_start, old_end)
47637 */
47638@@ -672,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
47639 stack_top = arch_align_stack(stack_top);
47640 stack_top = PAGE_ALIGN(stack_top);
47641
47642- if (unlikely(stack_top < mmap_min_addr) ||
47643- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
47644- return -ENOMEM;
47645-
47646 stack_shift = vma->vm_end - stack_top;
47647
47648 bprm->p -= stack_shift;
47649@@ -687,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
47650 bprm->exec -= stack_shift;
47651
47652 down_write(&mm->mmap_sem);
47653+
47654+ /* Move stack pages down in memory. */
47655+ if (stack_shift) {
47656+ ret = shift_arg_pages(vma, stack_shift);
47657+ if (ret)
47658+ goto out_unlock;
47659+ }
47660+
47661 vm_flags = VM_STACK_FLAGS;
47662
47663+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47664+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47665+ vm_flags &= ~VM_EXEC;
47666+
47667+#ifdef CONFIG_PAX_MPROTECT
47668+ if (mm->pax_flags & MF_PAX_MPROTECT)
47669+ vm_flags &= ~VM_MAYEXEC;
47670+#endif
47671+
47672+ }
47673+#endif
47674+
47675 /*
47676 * Adjust stack execute permissions; explicitly enable for
47677 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
47678@@ -707,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
47679 goto out_unlock;
47680 BUG_ON(prev != vma);
47681
47682- /* Move stack pages down in memory. */
47683- if (stack_shift) {
47684- ret = shift_arg_pages(vma, stack_shift);
47685- if (ret)
47686- goto out_unlock;
47687- }
47688-
47689 /* mprotect_fixup is overkill to remove the temporary stack flags */
47690 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
47691
47692@@ -737,6 +776,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
47693 #endif
47694 current->mm->start_stack = bprm->p;
47695 ret = expand_stack(vma, stack_base);
47696+
47697+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
47698+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
47699+ unsigned long size, flags, vm_flags;
47700+
47701+ size = STACK_TOP - vma->vm_end;
47702+ flags = MAP_FIXED | MAP_PRIVATE;
47703+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
47704+
47705+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
47706+
47707+#ifdef CONFIG_X86
47708+ if (!ret) {
47709+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
47710+ ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
47711+ }
47712+#endif
47713+
47714+ }
47715+#endif
47716+
47717 if (ret)
47718 ret = -EFAULT;
47719
47720@@ -772,6 +832,8 @@ struct file *open_exec(const char *name)
47721
47722 fsnotify_open(file);
47723
47724+ trace_open_exec(name);
47725+
47726 err = deny_write_access(file);
47727 if (err)
47728 goto exit;
47729@@ -795,7 +857,7 @@ int kernel_read(struct file *file, loff_t offset,
47730 old_fs = get_fs();
47731 set_fs(get_ds());
47732 /* The cast to a user pointer is valid due to the set_fs() */
47733- result = vfs_read(file, (void __user *)addr, count, &pos);
47734+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
47735 set_fs(old_fs);
47736 return result;
47737 }
47738@@ -1247,7 +1309,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
47739 }
47740 rcu_read_unlock();
47741
47742- if (p->fs->users > n_fs) {
47743+ if (atomic_read(&p->fs->users) > n_fs) {
47744 bprm->unsafe |= LSM_UNSAFE_SHARE;
47745 } else {
47746 res = -EAGAIN;
47747@@ -1447,6 +1509,28 @@ int search_binary_handler(struct linux_binprm *bprm)
47748
47749 EXPORT_SYMBOL(search_binary_handler);
47750
47751+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47752+static DEFINE_PER_CPU(u64, exec_counter);
47753+static int __init init_exec_counters(void)
47754+{
47755+ unsigned int cpu;
47756+
47757+ for_each_possible_cpu(cpu) {
47758+ per_cpu(exec_counter, cpu) = (u64)cpu;
47759+ }
47760+
47761+ return 0;
47762+}
47763+early_initcall(init_exec_counters);
47764+static inline void increment_exec_counter(void)
47765+{
47766+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
47767+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
47768+}
47769+#else
47770+static inline void increment_exec_counter(void) {}
47771+#endif
47772+
47773 /*
47774 * sys_execve() executes a new program.
47775 */
47776@@ -1454,6 +1538,11 @@ static int do_execve_common(const char *filename,
47777 struct user_arg_ptr argv,
47778 struct user_arg_ptr envp)
47779 {
47780+#ifdef CONFIG_GRKERNSEC
47781+ struct file *old_exec_file;
47782+ struct acl_subject_label *old_acl;
47783+ struct rlimit old_rlim[RLIM_NLIMITS];
47784+#endif
47785 struct linux_binprm *bprm;
47786 struct file *file;
47787 struct files_struct *displaced;
47788@@ -1461,6 +1550,8 @@ static int do_execve_common(const char *filename,
47789 int retval;
47790 const struct cred *cred = current_cred();
47791
47792+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
47793+
47794 /*
47795 * We move the actual failure in case of RLIMIT_NPROC excess from
47796 * set*uid() to execve() because too many poorly written programs
47797@@ -1501,12 +1592,27 @@ static int do_execve_common(const char *filename,
47798 if (IS_ERR(file))
47799 goto out_unmark;
47800
47801+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
47802+ retval = -EPERM;
47803+ goto out_file;
47804+ }
47805+
47806 sched_exec();
47807
47808 bprm->file = file;
47809 bprm->filename = filename;
47810 bprm->interp = filename;
47811
47812+ if (gr_process_user_ban()) {
47813+ retval = -EPERM;
47814+ goto out_file;
47815+ }
47816+
47817+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
47818+ retval = -EACCES;
47819+ goto out_file;
47820+ }
47821+
47822 retval = bprm_mm_init(bprm);
47823 if (retval)
47824 goto out_file;
47825@@ -1523,24 +1629,65 @@ static int do_execve_common(const char *filename,
47826 if (retval < 0)
47827 goto out;
47828
47829+#ifdef CONFIG_GRKERNSEC
47830+ old_acl = current->acl;
47831+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
47832+ old_exec_file = current->exec_file;
47833+ get_file(file);
47834+ current->exec_file = file;
47835+#endif
47836+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47837+ /* limit suid stack to 8MB
47838+ * we saved the old limits above and will restore them if this exec fails
47839+ */
47840+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
47841+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
47842+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
47843+#endif
47844+
47845+ if (!gr_tpe_allow(file)) {
47846+ retval = -EACCES;
47847+ goto out_fail;
47848+ }
47849+
47850+ if (gr_check_crash_exec(file)) {
47851+ retval = -EACCES;
47852+ goto out_fail;
47853+ }
47854+
47855+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
47856+ bprm->unsafe);
47857+ if (retval < 0)
47858+ goto out_fail;
47859+
47860 retval = copy_strings_kernel(1, &bprm->filename, bprm);
47861 if (retval < 0)
47862- goto out;
47863+ goto out_fail;
47864
47865 bprm->exec = bprm->p;
47866 retval = copy_strings(bprm->envc, envp, bprm);
47867 if (retval < 0)
47868- goto out;
47869+ goto out_fail;
47870
47871 retval = copy_strings(bprm->argc, argv, bprm);
47872 if (retval < 0)
47873- goto out;
47874+ goto out_fail;
47875+
47876+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
47877+
47878+ gr_handle_exec_args(bprm, argv);
47879
47880 retval = search_binary_handler(bprm);
47881 if (retval < 0)
47882- goto out;
47883+ goto out_fail;
47884+#ifdef CONFIG_GRKERNSEC
47885+ if (old_exec_file)
47886+ fput(old_exec_file);
47887+#endif
47888
47889 /* execve succeeded */
47890+
47891+ increment_exec_counter();
47892 current->fs->in_exec = 0;
47893 current->in_execve = 0;
47894 acct_update_integrals(current);
47895@@ -1549,6 +1696,14 @@ static int do_execve_common(const char *filename,
47896 put_files_struct(displaced);
47897 return retval;
47898
47899+out_fail:
47900+#ifdef CONFIG_GRKERNSEC
47901+ current->acl = old_acl;
47902+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
47903+ fput(current->exec_file);
47904+ current->exec_file = old_exec_file;
47905+#endif
47906+
47907 out:
47908 if (bprm->mm) {
47909 acct_arg_size(bprm, 0);
47910@@ -1697,3 +1852,253 @@ asmlinkage long compat_sys_execve(const char __user * filename,
47911 return error;
47912 }
47913 #endif
47914+
47915+int pax_check_flags(unsigned long *flags)
47916+{
47917+ int retval = 0;
47918+
47919+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
47920+ if (*flags & MF_PAX_SEGMEXEC)
47921+ {
47922+ *flags &= ~MF_PAX_SEGMEXEC;
47923+ retval = -EINVAL;
47924+ }
47925+#endif
47926+
47927+ if ((*flags & MF_PAX_PAGEEXEC)
47928+
47929+#ifdef CONFIG_PAX_PAGEEXEC
47930+ && (*flags & MF_PAX_SEGMEXEC)
47931+#endif
47932+
47933+ )
47934+ {
47935+ *flags &= ~MF_PAX_PAGEEXEC;
47936+ retval = -EINVAL;
47937+ }
47938+
47939+ if ((*flags & MF_PAX_MPROTECT)
47940+
47941+#ifdef CONFIG_PAX_MPROTECT
47942+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47943+#endif
47944+
47945+ )
47946+ {
47947+ *flags &= ~MF_PAX_MPROTECT;
47948+ retval = -EINVAL;
47949+ }
47950+
47951+ if ((*flags & MF_PAX_EMUTRAMP)
47952+
47953+#ifdef CONFIG_PAX_EMUTRAMP
47954+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47955+#endif
47956+
47957+ )
47958+ {
47959+ *flags &= ~MF_PAX_EMUTRAMP;
47960+ retval = -EINVAL;
47961+ }
47962+
47963+ return retval;
47964+}
47965+
47966+EXPORT_SYMBOL(pax_check_flags);
47967+
47968+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47969+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
47970+{
47971+ struct task_struct *tsk = current;
47972+ struct mm_struct *mm = current->mm;
47973+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
47974+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
47975+ char *path_exec = NULL;
47976+ char *path_fault = NULL;
47977+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
47978+ siginfo_t info = { };
47979+
47980+ if (buffer_exec && buffer_fault) {
47981+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
47982+
47983+ down_read(&mm->mmap_sem);
47984+ vma = mm->mmap;
47985+ while (vma && (!vma_exec || !vma_fault)) {
47986+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
47987+ vma_exec = vma;
47988+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
47989+ vma_fault = vma;
47990+ vma = vma->vm_next;
47991+ }
47992+ if (vma_exec) {
47993+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
47994+ if (IS_ERR(path_exec))
47995+ path_exec = "<path too long>";
47996+ else {
47997+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
47998+ if (path_exec) {
47999+ *path_exec = 0;
48000+ path_exec = buffer_exec;
48001+ } else
48002+ path_exec = "<path too long>";
48003+ }
48004+ }
48005+ if (vma_fault) {
48006+ start = vma_fault->vm_start;
48007+ end = vma_fault->vm_end;
48008+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
48009+ if (vma_fault->vm_file) {
48010+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
48011+ if (IS_ERR(path_fault))
48012+ path_fault = "<path too long>";
48013+ else {
48014+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
48015+ if (path_fault) {
48016+ *path_fault = 0;
48017+ path_fault = buffer_fault;
48018+ } else
48019+ path_fault = "<path too long>";
48020+ }
48021+ } else
48022+ path_fault = "<anonymous mapping>";
48023+ }
48024+ up_read(&mm->mmap_sem);
48025+ }
48026+ if (tsk->signal->curr_ip)
48027+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
48028+ else
48029+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
48030+ 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),
48031+ from_kuid(&init_user_ns, task_uid(tsk)), from_kuid(&init_user_ns, task_euid(tsk)), pc, sp);
48032+ free_page((unsigned long)buffer_exec);
48033+ free_page((unsigned long)buffer_fault);
48034+ pax_report_insns(regs, pc, sp);
48035+ info.si_signo = SIGKILL;
48036+ info.si_errno = 0;
48037+ info.si_code = SI_KERNEL;
48038+ info.si_pid = 0;
48039+ info.si_uid = 0;
48040+ do_coredump(&info);
48041+}
48042+#endif
48043+
48044+#ifdef CONFIG_PAX_REFCOUNT
48045+void pax_report_refcount_overflow(struct pt_regs *regs)
48046+{
48047+ if (current->signal->curr_ip)
48048+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
48049+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
48050+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
48051+ else
48052+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
48053+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
48054+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
48055+ show_regs(regs);
48056+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
48057+}
48058+#endif
48059+
48060+#ifdef CONFIG_PAX_USERCOPY
48061+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
48062+static noinline int check_stack_object(const void *obj, unsigned long len)
48063+{
48064+ const void * const stack = task_stack_page(current);
48065+ const void * const stackend = stack + THREAD_SIZE;
48066+
48067+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48068+ const void *frame = NULL;
48069+ const void *oldframe;
48070+#endif
48071+
48072+ if (obj + len < obj)
48073+ return -1;
48074+
48075+ if (obj + len <= stack || stackend <= obj)
48076+ return 0;
48077+
48078+ if (obj < stack || stackend < obj + len)
48079+ return -1;
48080+
48081+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48082+ oldframe = __builtin_frame_address(1);
48083+ if (oldframe)
48084+ frame = __builtin_frame_address(2);
48085+ /*
48086+ low ----------------------------------------------> high
48087+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
48088+ ^----------------^
48089+ allow copies only within here
48090+ */
48091+ while (stack <= frame && frame < stackend) {
48092+ /* if obj + len extends past the last frame, this
48093+ check won't pass and the next frame will be 0,
48094+ causing us to bail out and correctly report
48095+ the copy as invalid
48096+ */
48097+ if (obj + len <= frame)
48098+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
48099+ oldframe = frame;
48100+ frame = *(const void * const *)frame;
48101+ }
48102+ return -1;
48103+#else
48104+ return 1;
48105+#endif
48106+}
48107+
48108+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
48109+{
48110+ if (current->signal->curr_ip)
48111+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48112+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48113+ else
48114+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48115+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48116+ dump_stack();
48117+ gr_handle_kernel_exploit();
48118+ do_group_exit(SIGKILL);
48119+}
48120+#endif
48121+
48122+void __check_object_size(const void *ptr, unsigned long n, bool to)
48123+{
48124+
48125+#ifdef CONFIG_PAX_USERCOPY
48126+ const char *type;
48127+
48128+ if (!n)
48129+ return;
48130+
48131+ type = check_heap_object(ptr, n);
48132+ if (!type) {
48133+ if (check_stack_object(ptr, n) != -1)
48134+ return;
48135+ type = "<process stack>";
48136+ }
48137+
48138+ pax_report_usercopy(ptr, n, to, type);
48139+#endif
48140+
48141+}
48142+EXPORT_SYMBOL(__check_object_size);
48143+
48144+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
48145+void pax_track_stack(void)
48146+{
48147+ unsigned long sp = (unsigned long)&sp;
48148+ if (sp < current_thread_info()->lowest_stack &&
48149+ sp > (unsigned long)task_stack_page(current))
48150+ current_thread_info()->lowest_stack = sp;
48151+}
48152+EXPORT_SYMBOL(pax_track_stack);
48153+#endif
48154+
48155+#ifdef CONFIG_PAX_SIZE_OVERFLOW
48156+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
48157+{
48158+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
48159+ dump_stack();
48160+ do_group_exit(SIGKILL);
48161+}
48162+EXPORT_SYMBOL(report_size_overflow);
48163+#endif
48164diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
48165index 2616d0e..2ffdec9 100644
48166--- a/fs/ext2/balloc.c
48167+++ b/fs/ext2/balloc.c
48168@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
48169
48170 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48171 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48172- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48173+ if (free_blocks < root_blocks + 1 &&
48174 !uid_eq(sbi->s_resuid, current_fsuid()) &&
48175 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
48176- !in_group_p (sbi->s_resgid))) {
48177+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
48178 return 0;
48179 }
48180 return 1;
48181diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
48182index 22548f5..41521d8 100644
48183--- a/fs/ext3/balloc.c
48184+++ b/fs/ext3/balloc.c
48185@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
48186
48187 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48188 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48189- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48190+ if (free_blocks < root_blocks + 1 &&
48191 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
48192 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
48193- !in_group_p (sbi->s_resgid))) {
48194+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
48195 return 0;
48196 }
48197 return 1;
48198diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
48199index cf18217..8f6b9c3 100644
48200--- a/fs/ext4/balloc.c
48201+++ b/fs/ext4/balloc.c
48202@@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
48203 /* Hm, nope. Are (enough) root reserved clusters available? */
48204 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
48205 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
48206- capable(CAP_SYS_RESOURCE) ||
48207- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
48208+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
48209+ capable_nolog(CAP_SYS_RESOURCE)) {
48210
48211 if (free_clusters >= (nclusters + dirty_clusters))
48212 return 1;
48213diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
48214index 8462eb3..4a71af6 100644
48215--- a/fs/ext4/ext4.h
48216+++ b/fs/ext4/ext4.h
48217@@ -1265,19 +1265,19 @@ struct ext4_sb_info {
48218 unsigned long s_mb_last_start;
48219
48220 /* stats for buddy allocator */
48221- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
48222- atomic_t s_bal_success; /* we found long enough chunks */
48223- atomic_t s_bal_allocated; /* in blocks */
48224- atomic_t s_bal_ex_scanned; /* total extents scanned */
48225- atomic_t s_bal_goals; /* goal hits */
48226- atomic_t s_bal_breaks; /* too long searches */
48227- atomic_t s_bal_2orders; /* 2^order hits */
48228+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
48229+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
48230+ atomic_unchecked_t s_bal_allocated; /* in blocks */
48231+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
48232+ atomic_unchecked_t s_bal_goals; /* goal hits */
48233+ atomic_unchecked_t s_bal_breaks; /* too long searches */
48234+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
48235 spinlock_t s_bal_lock;
48236 unsigned long s_mb_buddies_generated;
48237 unsigned long long s_mb_generation_time;
48238- atomic_t s_mb_lost_chunks;
48239- atomic_t s_mb_preallocated;
48240- atomic_t s_mb_discarded;
48241+ atomic_unchecked_t s_mb_lost_chunks;
48242+ atomic_unchecked_t s_mb_preallocated;
48243+ atomic_unchecked_t s_mb_discarded;
48244 atomic_t s_lock_busy;
48245
48246 /* locality groups */
48247diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
48248index 1bf6fe7..1a5bdef 100644
48249--- a/fs/ext4/mballoc.c
48250+++ b/fs/ext4/mballoc.c
48251@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
48252 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
48253
48254 if (EXT4_SB(sb)->s_mb_stats)
48255- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
48256+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
48257
48258 break;
48259 }
48260@@ -2044,7 +2044,7 @@ repeat:
48261 ac->ac_status = AC_STATUS_CONTINUE;
48262 ac->ac_flags |= EXT4_MB_HINT_FIRST;
48263 cr = 3;
48264- atomic_inc(&sbi->s_mb_lost_chunks);
48265+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
48266 goto repeat;
48267 }
48268 }
48269@@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
48270 if (sbi->s_mb_stats) {
48271 ext4_msg(sb, KERN_INFO,
48272 "mballoc: %u blocks %u reqs (%u success)",
48273- atomic_read(&sbi->s_bal_allocated),
48274- atomic_read(&sbi->s_bal_reqs),
48275- atomic_read(&sbi->s_bal_success));
48276+ atomic_read_unchecked(&sbi->s_bal_allocated),
48277+ atomic_read_unchecked(&sbi->s_bal_reqs),
48278+ atomic_read_unchecked(&sbi->s_bal_success));
48279 ext4_msg(sb, KERN_INFO,
48280 "mballoc: %u extents scanned, %u goal hits, "
48281 "%u 2^N hits, %u breaks, %u lost",
48282- atomic_read(&sbi->s_bal_ex_scanned),
48283- atomic_read(&sbi->s_bal_goals),
48284- atomic_read(&sbi->s_bal_2orders),
48285- atomic_read(&sbi->s_bal_breaks),
48286- atomic_read(&sbi->s_mb_lost_chunks));
48287+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
48288+ atomic_read_unchecked(&sbi->s_bal_goals),
48289+ atomic_read_unchecked(&sbi->s_bal_2orders),
48290+ atomic_read_unchecked(&sbi->s_bal_breaks),
48291+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
48292 ext4_msg(sb, KERN_INFO,
48293 "mballoc: %lu generated and it took %Lu",
48294 sbi->s_mb_buddies_generated,
48295 sbi->s_mb_generation_time);
48296 ext4_msg(sb, KERN_INFO,
48297 "mballoc: %u preallocated, %u discarded",
48298- atomic_read(&sbi->s_mb_preallocated),
48299- atomic_read(&sbi->s_mb_discarded));
48300+ atomic_read_unchecked(&sbi->s_mb_preallocated),
48301+ atomic_read_unchecked(&sbi->s_mb_discarded));
48302 }
48303
48304 free_percpu(sbi->s_locality_groups);
48305@@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
48306 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
48307
48308 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
48309- atomic_inc(&sbi->s_bal_reqs);
48310- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48311+ atomic_inc_unchecked(&sbi->s_bal_reqs);
48312+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48313 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
48314- atomic_inc(&sbi->s_bal_success);
48315- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
48316+ atomic_inc_unchecked(&sbi->s_bal_success);
48317+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
48318 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
48319 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
48320- atomic_inc(&sbi->s_bal_goals);
48321+ atomic_inc_unchecked(&sbi->s_bal_goals);
48322 if (ac->ac_found > sbi->s_mb_max_to_scan)
48323- atomic_inc(&sbi->s_bal_breaks);
48324+ atomic_inc_unchecked(&sbi->s_bal_breaks);
48325 }
48326
48327 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
48328@@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
48329 trace_ext4_mb_new_inode_pa(ac, pa);
48330
48331 ext4_mb_use_inode_pa(ac, pa);
48332- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
48333+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
48334
48335 ei = EXT4_I(ac->ac_inode);
48336 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
48337@@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
48338 trace_ext4_mb_new_group_pa(ac, pa);
48339
48340 ext4_mb_use_group_pa(ac, pa);
48341- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48342+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48343
48344 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
48345 lg = ac->ac_lg;
48346@@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
48347 * from the bitmap and continue.
48348 */
48349 }
48350- atomic_add(free, &sbi->s_mb_discarded);
48351+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
48352
48353 return err;
48354 }
48355@@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
48356 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
48357 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
48358 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
48359- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
48360+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
48361 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
48362
48363 return 0;
48364diff --git a/fs/fcntl.c b/fs/fcntl.c
48365index 71a600a..20d87b1 100644
48366--- a/fs/fcntl.c
48367+++ b/fs/fcntl.c
48368@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
48369 if (err)
48370 return err;
48371
48372+ if (gr_handle_chroot_fowner(pid, type))
48373+ return -ENOENT;
48374+ if (gr_check_protected_task_fowner(pid, type))
48375+ return -EACCES;
48376+
48377 f_modown(filp, pid, type, force);
48378 return 0;
48379 }
48380diff --git a/fs/fhandle.c b/fs/fhandle.c
48381index 999ff5c..41f4109 100644
48382--- a/fs/fhandle.c
48383+++ b/fs/fhandle.c
48384@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
48385 } else
48386 retval = 0;
48387 /* copy the mount id */
48388- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
48389- sizeof(*mnt_id)) ||
48390+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
48391 copy_to_user(ufh, handle,
48392 sizeof(struct file_handle) + handle_bytes))
48393 retval = -EFAULT;
48394diff --git a/fs/fifo.c b/fs/fifo.c
48395index cf6f434..3d7942c 100644
48396--- a/fs/fifo.c
48397+++ b/fs/fifo.c
48398@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
48399 */
48400 filp->f_op = &read_pipefifo_fops;
48401 pipe->r_counter++;
48402- if (pipe->readers++ == 0)
48403+ if (atomic_inc_return(&pipe->readers) == 1)
48404 wake_up_partner(inode);
48405
48406- if (!pipe->writers) {
48407+ if (!atomic_read(&pipe->writers)) {
48408 if ((filp->f_flags & O_NONBLOCK)) {
48409 /* suppress POLLHUP until we have
48410 * seen a writer */
48411@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
48412 * errno=ENXIO when there is no process reading the FIFO.
48413 */
48414 ret = -ENXIO;
48415- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
48416+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
48417 goto err;
48418
48419 filp->f_op = &write_pipefifo_fops;
48420 pipe->w_counter++;
48421- if (!pipe->writers++)
48422+ if (atomic_inc_return(&pipe->writers) == 1)
48423 wake_up_partner(inode);
48424
48425- if (!pipe->readers) {
48426+ if (!atomic_read(&pipe->readers)) {
48427 if (wait_for_partner(inode, &pipe->r_counter))
48428 goto err_wr;
48429 }
48430@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
48431 */
48432 filp->f_op = &rdwr_pipefifo_fops;
48433
48434- pipe->readers++;
48435- pipe->writers++;
48436+ atomic_inc(&pipe->readers);
48437+ atomic_inc(&pipe->writers);
48438 pipe->r_counter++;
48439 pipe->w_counter++;
48440- if (pipe->readers == 1 || pipe->writers == 1)
48441+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
48442 wake_up_partner(inode);
48443 break;
48444
48445@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
48446 return 0;
48447
48448 err_rd:
48449- if (!--pipe->readers)
48450+ if (atomic_dec_and_test(&pipe->readers))
48451 wake_up_interruptible(&pipe->wait);
48452 ret = -ERESTARTSYS;
48453 goto err;
48454
48455 err_wr:
48456- if (!--pipe->writers)
48457+ if (atomic_dec_and_test(&pipe->writers))
48458 wake_up_interruptible(&pipe->wait);
48459 ret = -ERESTARTSYS;
48460 goto err;
48461
48462 err:
48463- if (!pipe->readers && !pipe->writers)
48464+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
48465 free_pipe_info(inode);
48466
48467 err_nocleanup:
48468diff --git a/fs/file.c b/fs/file.c
48469index 2b3570b..c57924b 100644
48470--- a/fs/file.c
48471+++ b/fs/file.c
48472@@ -16,6 +16,7 @@
48473 #include <linux/slab.h>
48474 #include <linux/vmalloc.h>
48475 #include <linux/file.h>
48476+#include <linux/security.h>
48477 #include <linux/fdtable.h>
48478 #include <linux/bitops.h>
48479 #include <linux/interrupt.h>
48480@@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
48481 if (!file)
48482 return __close_fd(files, fd);
48483
48484+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
48485 if (fd >= rlimit(RLIMIT_NOFILE))
48486 return -EBADF;
48487
48488@@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
48489 if (unlikely(oldfd == newfd))
48490 return -EINVAL;
48491
48492+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
48493 if (newfd >= rlimit(RLIMIT_NOFILE))
48494 return -EBADF;
48495
48496@@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
48497 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
48498 {
48499 int err;
48500+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
48501 if (from >= rlimit(RLIMIT_NOFILE))
48502 return -EINVAL;
48503 err = alloc_fd(from, flags);
48504diff --git a/fs/filesystems.c b/fs/filesystems.c
48505index da165f6..3671bdb 100644
48506--- a/fs/filesystems.c
48507+++ b/fs/filesystems.c
48508@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
48509 int len = dot ? dot - name : strlen(name);
48510
48511 fs = __get_fs_type(name, len);
48512+
48513+#ifdef CONFIG_GRKERNSEC_MODHARDEN
48514+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
48515+#else
48516 if (!fs && (request_module("%.*s", len, name) == 0))
48517+#endif
48518 fs = __get_fs_type(name, len);
48519
48520 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
48521diff --git a/fs/fs_struct.c b/fs/fs_struct.c
48522index fe6ca58..65318cf 100644
48523--- a/fs/fs_struct.c
48524+++ b/fs/fs_struct.c
48525@@ -4,6 +4,7 @@
48526 #include <linux/path.h>
48527 #include <linux/slab.h>
48528 #include <linux/fs_struct.h>
48529+#include <linux/grsecurity.h>
48530 #include "internal.h"
48531
48532 /*
48533@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
48534 write_seqcount_begin(&fs->seq);
48535 old_root = fs->root;
48536 fs->root = *path;
48537+ gr_set_chroot_entries(current, path);
48538 write_seqcount_end(&fs->seq);
48539 spin_unlock(&fs->lock);
48540 if (old_root.dentry)
48541@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
48542 return 1;
48543 }
48544
48545+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
48546+{
48547+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
48548+ return 0;
48549+ *p = *new;
48550+
48551+ /* This function is only called from pivot_root(). Leave our
48552+ gr_chroot_dentry and is_chrooted flags as-is, so that a
48553+ pivoted root isn't treated as a chroot
48554+ */
48555+ //gr_set_chroot_entries(task, new);
48556+
48557+ return 1;
48558+}
48559+
48560 void chroot_fs_refs(struct path *old_root, struct path *new_root)
48561 {
48562 struct task_struct *g, *p;
48563@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
48564 int hits = 0;
48565 spin_lock(&fs->lock);
48566 write_seqcount_begin(&fs->seq);
48567- hits += replace_path(&fs->root, old_root, new_root);
48568+ hits += replace_root_path(p, &fs->root, old_root, new_root);
48569 hits += replace_path(&fs->pwd, old_root, new_root);
48570 write_seqcount_end(&fs->seq);
48571 while (hits--) {
48572@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
48573 task_lock(tsk);
48574 spin_lock(&fs->lock);
48575 tsk->fs = NULL;
48576- kill = !--fs->users;
48577+ gr_clear_chroot_entries(tsk);
48578+ kill = !atomic_dec_return(&fs->users);
48579 spin_unlock(&fs->lock);
48580 task_unlock(tsk);
48581 if (kill)
48582@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
48583 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
48584 /* We don't need to lock fs - think why ;-) */
48585 if (fs) {
48586- fs->users = 1;
48587+ atomic_set(&fs->users, 1);
48588 fs->in_exec = 0;
48589 spin_lock_init(&fs->lock);
48590 seqcount_init(&fs->seq);
48591@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
48592 spin_lock(&old->lock);
48593 fs->root = old->root;
48594 path_get(&fs->root);
48595+ /* instead of calling gr_set_chroot_entries here,
48596+ we call it from every caller of this function
48597+ */
48598 fs->pwd = old->pwd;
48599 path_get(&fs->pwd);
48600 spin_unlock(&old->lock);
48601@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
48602
48603 task_lock(current);
48604 spin_lock(&fs->lock);
48605- kill = !--fs->users;
48606+ kill = !atomic_dec_return(&fs->users);
48607 current->fs = new_fs;
48608+ gr_set_chroot_entries(current, &new_fs->root);
48609 spin_unlock(&fs->lock);
48610 task_unlock(current);
48611
48612@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
48613
48614 int current_umask(void)
48615 {
48616- return current->fs->umask;
48617+ return current->fs->umask | gr_acl_umask();
48618 }
48619 EXPORT_SYMBOL(current_umask);
48620
48621 /* to be mentioned only in INIT_TASK */
48622 struct fs_struct init_fs = {
48623- .users = 1,
48624+ .users = ATOMIC_INIT(1),
48625 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
48626 .seq = SEQCNT_ZERO,
48627 .umask = 0022,
48628diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
48629index 8dcb114..b1072e2 100644
48630--- a/fs/fscache/cookie.c
48631+++ b/fs/fscache/cookie.c
48632@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
48633 parent ? (char *) parent->def->name : "<no-parent>",
48634 def->name, netfs_data);
48635
48636- fscache_stat(&fscache_n_acquires);
48637+ fscache_stat_unchecked(&fscache_n_acquires);
48638
48639 /* if there's no parent cookie, then we don't create one here either */
48640 if (!parent) {
48641- fscache_stat(&fscache_n_acquires_null);
48642+ fscache_stat_unchecked(&fscache_n_acquires_null);
48643 _leave(" [no parent]");
48644 return NULL;
48645 }
48646@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
48647 /* allocate and initialise a cookie */
48648 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
48649 if (!cookie) {
48650- fscache_stat(&fscache_n_acquires_oom);
48651+ fscache_stat_unchecked(&fscache_n_acquires_oom);
48652 _leave(" [ENOMEM]");
48653 return NULL;
48654 }
48655@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
48656
48657 switch (cookie->def->type) {
48658 case FSCACHE_COOKIE_TYPE_INDEX:
48659- fscache_stat(&fscache_n_cookie_index);
48660+ fscache_stat_unchecked(&fscache_n_cookie_index);
48661 break;
48662 case FSCACHE_COOKIE_TYPE_DATAFILE:
48663- fscache_stat(&fscache_n_cookie_data);
48664+ fscache_stat_unchecked(&fscache_n_cookie_data);
48665 break;
48666 default:
48667- fscache_stat(&fscache_n_cookie_special);
48668+ fscache_stat_unchecked(&fscache_n_cookie_special);
48669 break;
48670 }
48671
48672@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
48673 if (fscache_acquire_non_index_cookie(cookie) < 0) {
48674 atomic_dec(&parent->n_children);
48675 __fscache_cookie_put(cookie);
48676- fscache_stat(&fscache_n_acquires_nobufs);
48677+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
48678 _leave(" = NULL");
48679 return NULL;
48680 }
48681 }
48682
48683- fscache_stat(&fscache_n_acquires_ok);
48684+ fscache_stat_unchecked(&fscache_n_acquires_ok);
48685 _leave(" = %p", cookie);
48686 return cookie;
48687 }
48688@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
48689 cache = fscache_select_cache_for_object(cookie->parent);
48690 if (!cache) {
48691 up_read(&fscache_addremove_sem);
48692- fscache_stat(&fscache_n_acquires_no_cache);
48693+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
48694 _leave(" = -ENOMEDIUM [no cache]");
48695 return -ENOMEDIUM;
48696 }
48697@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
48698 object = cache->ops->alloc_object(cache, cookie);
48699 fscache_stat_d(&fscache_n_cop_alloc_object);
48700 if (IS_ERR(object)) {
48701- fscache_stat(&fscache_n_object_no_alloc);
48702+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
48703 ret = PTR_ERR(object);
48704 goto error;
48705 }
48706
48707- fscache_stat(&fscache_n_object_alloc);
48708+ fscache_stat_unchecked(&fscache_n_object_alloc);
48709
48710 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
48711
48712@@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
48713
48714 _enter("{%s}", cookie->def->name);
48715
48716- fscache_stat(&fscache_n_invalidates);
48717+ fscache_stat_unchecked(&fscache_n_invalidates);
48718
48719 /* Only permit invalidation of data files. Invalidating an index will
48720 * require the caller to release all its attachments to the tree rooted
48721@@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
48722 struct fscache_object *object;
48723 struct hlist_node *_p;
48724
48725- fscache_stat(&fscache_n_updates);
48726+ fscache_stat_unchecked(&fscache_n_updates);
48727
48728 if (!cookie) {
48729- fscache_stat(&fscache_n_updates_null);
48730+ fscache_stat_unchecked(&fscache_n_updates_null);
48731 _leave(" [no cookie]");
48732 return;
48733 }
48734@@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48735 struct fscache_object *object;
48736 unsigned long event;
48737
48738- fscache_stat(&fscache_n_relinquishes);
48739+ fscache_stat_unchecked(&fscache_n_relinquishes);
48740 if (retire)
48741- fscache_stat(&fscache_n_relinquishes_retire);
48742+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
48743
48744 if (!cookie) {
48745- fscache_stat(&fscache_n_relinquishes_null);
48746+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
48747 _leave(" [no cookie]");
48748 return;
48749 }
48750@@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48751
48752 /* wait for the cookie to finish being instantiated (or to fail) */
48753 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
48754- fscache_stat(&fscache_n_relinquishes_waitcrt);
48755+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
48756 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
48757 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
48758 }
48759diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
48760index ee38fef..0a326d4 100644
48761--- a/fs/fscache/internal.h
48762+++ b/fs/fscache/internal.h
48763@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
48764 * stats.c
48765 */
48766 #ifdef CONFIG_FSCACHE_STATS
48767-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
48768-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
48769+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
48770+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
48771
48772-extern atomic_t fscache_n_op_pend;
48773-extern atomic_t fscache_n_op_run;
48774-extern atomic_t fscache_n_op_enqueue;
48775-extern atomic_t fscache_n_op_deferred_release;
48776-extern atomic_t fscache_n_op_release;
48777-extern atomic_t fscache_n_op_gc;
48778-extern atomic_t fscache_n_op_cancelled;
48779-extern atomic_t fscache_n_op_rejected;
48780+extern atomic_unchecked_t fscache_n_op_pend;
48781+extern atomic_unchecked_t fscache_n_op_run;
48782+extern atomic_unchecked_t fscache_n_op_enqueue;
48783+extern atomic_unchecked_t fscache_n_op_deferred_release;
48784+extern atomic_unchecked_t fscache_n_op_release;
48785+extern atomic_unchecked_t fscache_n_op_gc;
48786+extern atomic_unchecked_t fscache_n_op_cancelled;
48787+extern atomic_unchecked_t fscache_n_op_rejected;
48788
48789-extern atomic_t fscache_n_attr_changed;
48790-extern atomic_t fscache_n_attr_changed_ok;
48791-extern atomic_t fscache_n_attr_changed_nobufs;
48792-extern atomic_t fscache_n_attr_changed_nomem;
48793-extern atomic_t fscache_n_attr_changed_calls;
48794+extern atomic_unchecked_t fscache_n_attr_changed;
48795+extern atomic_unchecked_t fscache_n_attr_changed_ok;
48796+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
48797+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
48798+extern atomic_unchecked_t fscache_n_attr_changed_calls;
48799
48800-extern atomic_t fscache_n_allocs;
48801-extern atomic_t fscache_n_allocs_ok;
48802-extern atomic_t fscache_n_allocs_wait;
48803-extern atomic_t fscache_n_allocs_nobufs;
48804-extern atomic_t fscache_n_allocs_intr;
48805-extern atomic_t fscache_n_allocs_object_dead;
48806-extern atomic_t fscache_n_alloc_ops;
48807-extern atomic_t fscache_n_alloc_op_waits;
48808+extern atomic_unchecked_t fscache_n_allocs;
48809+extern atomic_unchecked_t fscache_n_allocs_ok;
48810+extern atomic_unchecked_t fscache_n_allocs_wait;
48811+extern atomic_unchecked_t fscache_n_allocs_nobufs;
48812+extern atomic_unchecked_t fscache_n_allocs_intr;
48813+extern atomic_unchecked_t fscache_n_allocs_object_dead;
48814+extern atomic_unchecked_t fscache_n_alloc_ops;
48815+extern atomic_unchecked_t fscache_n_alloc_op_waits;
48816
48817-extern atomic_t fscache_n_retrievals;
48818-extern atomic_t fscache_n_retrievals_ok;
48819-extern atomic_t fscache_n_retrievals_wait;
48820-extern atomic_t fscache_n_retrievals_nodata;
48821-extern atomic_t fscache_n_retrievals_nobufs;
48822-extern atomic_t fscache_n_retrievals_intr;
48823-extern atomic_t fscache_n_retrievals_nomem;
48824-extern atomic_t fscache_n_retrievals_object_dead;
48825-extern atomic_t fscache_n_retrieval_ops;
48826-extern atomic_t fscache_n_retrieval_op_waits;
48827+extern atomic_unchecked_t fscache_n_retrievals;
48828+extern atomic_unchecked_t fscache_n_retrievals_ok;
48829+extern atomic_unchecked_t fscache_n_retrievals_wait;
48830+extern atomic_unchecked_t fscache_n_retrievals_nodata;
48831+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
48832+extern atomic_unchecked_t fscache_n_retrievals_intr;
48833+extern atomic_unchecked_t fscache_n_retrievals_nomem;
48834+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
48835+extern atomic_unchecked_t fscache_n_retrieval_ops;
48836+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
48837
48838-extern atomic_t fscache_n_stores;
48839-extern atomic_t fscache_n_stores_ok;
48840-extern atomic_t fscache_n_stores_again;
48841-extern atomic_t fscache_n_stores_nobufs;
48842-extern atomic_t fscache_n_stores_oom;
48843-extern atomic_t fscache_n_store_ops;
48844-extern atomic_t fscache_n_store_calls;
48845-extern atomic_t fscache_n_store_pages;
48846-extern atomic_t fscache_n_store_radix_deletes;
48847-extern atomic_t fscache_n_store_pages_over_limit;
48848+extern atomic_unchecked_t fscache_n_stores;
48849+extern atomic_unchecked_t fscache_n_stores_ok;
48850+extern atomic_unchecked_t fscache_n_stores_again;
48851+extern atomic_unchecked_t fscache_n_stores_nobufs;
48852+extern atomic_unchecked_t fscache_n_stores_oom;
48853+extern atomic_unchecked_t fscache_n_store_ops;
48854+extern atomic_unchecked_t fscache_n_store_calls;
48855+extern atomic_unchecked_t fscache_n_store_pages;
48856+extern atomic_unchecked_t fscache_n_store_radix_deletes;
48857+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
48858
48859-extern atomic_t fscache_n_store_vmscan_not_storing;
48860-extern atomic_t fscache_n_store_vmscan_gone;
48861-extern atomic_t fscache_n_store_vmscan_busy;
48862-extern atomic_t fscache_n_store_vmscan_cancelled;
48863-extern atomic_t fscache_n_store_vmscan_wait;
48864+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48865+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
48866+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
48867+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48868+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
48869
48870-extern atomic_t fscache_n_marks;
48871-extern atomic_t fscache_n_uncaches;
48872+extern atomic_unchecked_t fscache_n_marks;
48873+extern atomic_unchecked_t fscache_n_uncaches;
48874
48875-extern atomic_t fscache_n_acquires;
48876-extern atomic_t fscache_n_acquires_null;
48877-extern atomic_t fscache_n_acquires_no_cache;
48878-extern atomic_t fscache_n_acquires_ok;
48879-extern atomic_t fscache_n_acquires_nobufs;
48880-extern atomic_t fscache_n_acquires_oom;
48881+extern atomic_unchecked_t fscache_n_acquires;
48882+extern atomic_unchecked_t fscache_n_acquires_null;
48883+extern atomic_unchecked_t fscache_n_acquires_no_cache;
48884+extern atomic_unchecked_t fscache_n_acquires_ok;
48885+extern atomic_unchecked_t fscache_n_acquires_nobufs;
48886+extern atomic_unchecked_t fscache_n_acquires_oom;
48887
48888-extern atomic_t fscache_n_invalidates;
48889-extern atomic_t fscache_n_invalidates_run;
48890+extern atomic_unchecked_t fscache_n_invalidates;
48891+extern atomic_unchecked_t fscache_n_invalidates_run;
48892
48893-extern atomic_t fscache_n_updates;
48894-extern atomic_t fscache_n_updates_null;
48895-extern atomic_t fscache_n_updates_run;
48896+extern atomic_unchecked_t fscache_n_updates;
48897+extern atomic_unchecked_t fscache_n_updates_null;
48898+extern atomic_unchecked_t fscache_n_updates_run;
48899
48900-extern atomic_t fscache_n_relinquishes;
48901-extern atomic_t fscache_n_relinquishes_null;
48902-extern atomic_t fscache_n_relinquishes_waitcrt;
48903-extern atomic_t fscache_n_relinquishes_retire;
48904+extern atomic_unchecked_t fscache_n_relinquishes;
48905+extern atomic_unchecked_t fscache_n_relinquishes_null;
48906+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
48907+extern atomic_unchecked_t fscache_n_relinquishes_retire;
48908
48909-extern atomic_t fscache_n_cookie_index;
48910-extern atomic_t fscache_n_cookie_data;
48911-extern atomic_t fscache_n_cookie_special;
48912+extern atomic_unchecked_t fscache_n_cookie_index;
48913+extern atomic_unchecked_t fscache_n_cookie_data;
48914+extern atomic_unchecked_t fscache_n_cookie_special;
48915
48916-extern atomic_t fscache_n_object_alloc;
48917-extern atomic_t fscache_n_object_no_alloc;
48918-extern atomic_t fscache_n_object_lookups;
48919-extern atomic_t fscache_n_object_lookups_negative;
48920-extern atomic_t fscache_n_object_lookups_positive;
48921-extern atomic_t fscache_n_object_lookups_timed_out;
48922-extern atomic_t fscache_n_object_created;
48923-extern atomic_t fscache_n_object_avail;
48924-extern atomic_t fscache_n_object_dead;
48925+extern atomic_unchecked_t fscache_n_object_alloc;
48926+extern atomic_unchecked_t fscache_n_object_no_alloc;
48927+extern atomic_unchecked_t fscache_n_object_lookups;
48928+extern atomic_unchecked_t fscache_n_object_lookups_negative;
48929+extern atomic_unchecked_t fscache_n_object_lookups_positive;
48930+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
48931+extern atomic_unchecked_t fscache_n_object_created;
48932+extern atomic_unchecked_t fscache_n_object_avail;
48933+extern atomic_unchecked_t fscache_n_object_dead;
48934
48935-extern atomic_t fscache_n_checkaux_none;
48936-extern atomic_t fscache_n_checkaux_okay;
48937-extern atomic_t fscache_n_checkaux_update;
48938-extern atomic_t fscache_n_checkaux_obsolete;
48939+extern atomic_unchecked_t fscache_n_checkaux_none;
48940+extern atomic_unchecked_t fscache_n_checkaux_okay;
48941+extern atomic_unchecked_t fscache_n_checkaux_update;
48942+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
48943
48944 extern atomic_t fscache_n_cop_alloc_object;
48945 extern atomic_t fscache_n_cop_lookup_object;
48946@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
48947 atomic_inc(stat);
48948 }
48949
48950+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
48951+{
48952+ atomic_inc_unchecked(stat);
48953+}
48954+
48955 static inline void fscache_stat_d(atomic_t *stat)
48956 {
48957 atomic_dec(stat);
48958@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
48959
48960 #define __fscache_stat(stat) (NULL)
48961 #define fscache_stat(stat) do {} while (0)
48962+#define fscache_stat_unchecked(stat) do {} while (0)
48963 #define fscache_stat_d(stat) do {} while (0)
48964 #endif
48965
48966diff --git a/fs/fscache/object.c b/fs/fscache/object.c
48967index 50d41c1..10ee117 100644
48968--- a/fs/fscache/object.c
48969+++ b/fs/fscache/object.c
48970@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48971 /* Invalidate an object on disk */
48972 case FSCACHE_OBJECT_INVALIDATING:
48973 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
48974- fscache_stat(&fscache_n_invalidates_run);
48975+ fscache_stat_unchecked(&fscache_n_invalidates_run);
48976 fscache_stat(&fscache_n_cop_invalidate_object);
48977 fscache_invalidate_object(object);
48978 fscache_stat_d(&fscache_n_cop_invalidate_object);
48979@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48980 /* update the object metadata on disk */
48981 case FSCACHE_OBJECT_UPDATING:
48982 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
48983- fscache_stat(&fscache_n_updates_run);
48984+ fscache_stat_unchecked(&fscache_n_updates_run);
48985 fscache_stat(&fscache_n_cop_update_object);
48986 object->cache->ops->update_object(object);
48987 fscache_stat_d(&fscache_n_cop_update_object);
48988@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48989 spin_lock(&object->lock);
48990 object->state = FSCACHE_OBJECT_DEAD;
48991 spin_unlock(&object->lock);
48992- fscache_stat(&fscache_n_object_dead);
48993+ fscache_stat_unchecked(&fscache_n_object_dead);
48994 goto terminal_transit;
48995
48996 /* handle the parent cache of this object being withdrawn from
48997@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48998 spin_lock(&object->lock);
48999 object->state = FSCACHE_OBJECT_DEAD;
49000 spin_unlock(&object->lock);
49001- fscache_stat(&fscache_n_object_dead);
49002+ fscache_stat_unchecked(&fscache_n_object_dead);
49003 goto terminal_transit;
49004
49005 /* complain about the object being woken up once it is
49006@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
49007 parent->cookie->def->name, cookie->def->name,
49008 object->cache->tag->name);
49009
49010- fscache_stat(&fscache_n_object_lookups);
49011+ fscache_stat_unchecked(&fscache_n_object_lookups);
49012 fscache_stat(&fscache_n_cop_lookup_object);
49013 ret = object->cache->ops->lookup_object(object);
49014 fscache_stat_d(&fscache_n_cop_lookup_object);
49015@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
49016 if (ret == -ETIMEDOUT) {
49017 /* probably stuck behind another object, so move this one to
49018 * the back of the queue */
49019- fscache_stat(&fscache_n_object_lookups_timed_out);
49020+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
49021 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49022 }
49023
49024@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
49025
49026 spin_lock(&object->lock);
49027 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49028- fscache_stat(&fscache_n_object_lookups_negative);
49029+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
49030
49031 /* transit here to allow write requests to begin stacking up
49032 * and read requests to begin returning ENODATA */
49033@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
49034 * result, in which case there may be data available */
49035 spin_lock(&object->lock);
49036 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49037- fscache_stat(&fscache_n_object_lookups_positive);
49038+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
49039
49040 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
49041
49042@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
49043 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49044 } else {
49045 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
49046- fscache_stat(&fscache_n_object_created);
49047+ fscache_stat_unchecked(&fscache_n_object_created);
49048
49049 object->state = FSCACHE_OBJECT_AVAILABLE;
49050 spin_unlock(&object->lock);
49051@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
49052 fscache_enqueue_dependents(object);
49053
49054 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
49055- fscache_stat(&fscache_n_object_avail);
49056+ fscache_stat_unchecked(&fscache_n_object_avail);
49057
49058 _leave("");
49059 }
49060@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49061 enum fscache_checkaux result;
49062
49063 if (!object->cookie->def->check_aux) {
49064- fscache_stat(&fscache_n_checkaux_none);
49065+ fscache_stat_unchecked(&fscache_n_checkaux_none);
49066 return FSCACHE_CHECKAUX_OKAY;
49067 }
49068
49069@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49070 switch (result) {
49071 /* entry okay as is */
49072 case FSCACHE_CHECKAUX_OKAY:
49073- fscache_stat(&fscache_n_checkaux_okay);
49074+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
49075 break;
49076
49077 /* entry requires update */
49078 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
49079- fscache_stat(&fscache_n_checkaux_update);
49080+ fscache_stat_unchecked(&fscache_n_checkaux_update);
49081 break;
49082
49083 /* entry requires deletion */
49084 case FSCACHE_CHECKAUX_OBSOLETE:
49085- fscache_stat(&fscache_n_checkaux_obsolete);
49086+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
49087 break;
49088
49089 default:
49090diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
49091index 762a9ec..2023284 100644
49092--- a/fs/fscache/operation.c
49093+++ b/fs/fscache/operation.c
49094@@ -17,7 +17,7 @@
49095 #include <linux/slab.h>
49096 #include "internal.h"
49097
49098-atomic_t fscache_op_debug_id;
49099+atomic_unchecked_t fscache_op_debug_id;
49100 EXPORT_SYMBOL(fscache_op_debug_id);
49101
49102 /**
49103@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
49104 ASSERTCMP(atomic_read(&op->usage), >, 0);
49105 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
49106
49107- fscache_stat(&fscache_n_op_enqueue);
49108+ fscache_stat_unchecked(&fscache_n_op_enqueue);
49109 switch (op->flags & FSCACHE_OP_TYPE) {
49110 case FSCACHE_OP_ASYNC:
49111 _debug("queue async");
49112@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
49113 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
49114 if (op->processor)
49115 fscache_enqueue_operation(op);
49116- fscache_stat(&fscache_n_op_run);
49117+ fscache_stat_unchecked(&fscache_n_op_run);
49118 }
49119
49120 /*
49121@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49122 if (object->n_in_progress > 0) {
49123 atomic_inc(&op->usage);
49124 list_add_tail(&op->pend_link, &object->pending_ops);
49125- fscache_stat(&fscache_n_op_pend);
49126+ fscache_stat_unchecked(&fscache_n_op_pend);
49127 } else if (!list_empty(&object->pending_ops)) {
49128 atomic_inc(&op->usage);
49129 list_add_tail(&op->pend_link, &object->pending_ops);
49130- fscache_stat(&fscache_n_op_pend);
49131+ fscache_stat_unchecked(&fscache_n_op_pend);
49132 fscache_start_operations(object);
49133 } else {
49134 ASSERTCMP(object->n_in_progress, ==, 0);
49135@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49136 object->n_exclusive++; /* reads and writes must wait */
49137 atomic_inc(&op->usage);
49138 list_add_tail(&op->pend_link, &object->pending_ops);
49139- fscache_stat(&fscache_n_op_pend);
49140+ fscache_stat_unchecked(&fscache_n_op_pend);
49141 ret = 0;
49142 } else {
49143 /* If we're in any other state, there must have been an I/O
49144@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
49145 if (object->n_exclusive > 0) {
49146 atomic_inc(&op->usage);
49147 list_add_tail(&op->pend_link, &object->pending_ops);
49148- fscache_stat(&fscache_n_op_pend);
49149+ fscache_stat_unchecked(&fscache_n_op_pend);
49150 } else if (!list_empty(&object->pending_ops)) {
49151 atomic_inc(&op->usage);
49152 list_add_tail(&op->pend_link, &object->pending_ops);
49153- fscache_stat(&fscache_n_op_pend);
49154+ fscache_stat_unchecked(&fscache_n_op_pend);
49155 fscache_start_operations(object);
49156 } else {
49157 ASSERTCMP(object->n_exclusive, ==, 0);
49158@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
49159 object->n_ops++;
49160 atomic_inc(&op->usage);
49161 list_add_tail(&op->pend_link, &object->pending_ops);
49162- fscache_stat(&fscache_n_op_pend);
49163+ fscache_stat_unchecked(&fscache_n_op_pend);
49164 ret = 0;
49165 } else if (object->state == FSCACHE_OBJECT_DYING ||
49166 object->state == FSCACHE_OBJECT_LC_DYING ||
49167 object->state == FSCACHE_OBJECT_WITHDRAWING) {
49168- fscache_stat(&fscache_n_op_rejected);
49169+ fscache_stat_unchecked(&fscache_n_op_rejected);
49170 op->state = FSCACHE_OP_ST_CANCELLED;
49171 ret = -ENOBUFS;
49172 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
49173@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
49174 ret = -EBUSY;
49175 if (op->state == FSCACHE_OP_ST_PENDING) {
49176 ASSERT(!list_empty(&op->pend_link));
49177- fscache_stat(&fscache_n_op_cancelled);
49178+ fscache_stat_unchecked(&fscache_n_op_cancelled);
49179 list_del_init(&op->pend_link);
49180 if (do_cancel)
49181 do_cancel(op);
49182@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
49183 while (!list_empty(&object->pending_ops)) {
49184 op = list_entry(object->pending_ops.next,
49185 struct fscache_operation, pend_link);
49186- fscache_stat(&fscache_n_op_cancelled);
49187+ fscache_stat_unchecked(&fscache_n_op_cancelled);
49188 list_del_init(&op->pend_link);
49189
49190 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
49191@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
49192 op->state, ==, FSCACHE_OP_ST_CANCELLED);
49193 op->state = FSCACHE_OP_ST_DEAD;
49194
49195- fscache_stat(&fscache_n_op_release);
49196+ fscache_stat_unchecked(&fscache_n_op_release);
49197
49198 if (op->release) {
49199 op->release(op);
49200@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
49201 * lock, and defer it otherwise */
49202 if (!spin_trylock(&object->lock)) {
49203 _debug("defer put");
49204- fscache_stat(&fscache_n_op_deferred_release);
49205+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
49206
49207 cache = object->cache;
49208 spin_lock(&cache->op_gc_list_lock);
49209@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
49210
49211 _debug("GC DEFERRED REL OBJ%x OP%x",
49212 object->debug_id, op->debug_id);
49213- fscache_stat(&fscache_n_op_gc);
49214+ fscache_stat_unchecked(&fscache_n_op_gc);
49215
49216 ASSERTCMP(atomic_read(&op->usage), ==, 0);
49217 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
49218diff --git a/fs/fscache/page.c b/fs/fscache/page.c
49219index ff000e5..c44ec6d 100644
49220--- a/fs/fscache/page.c
49221+++ b/fs/fscache/page.c
49222@@ -61,7 +61,7 @@ try_again:
49223 val = radix_tree_lookup(&cookie->stores, page->index);
49224 if (!val) {
49225 rcu_read_unlock();
49226- fscache_stat(&fscache_n_store_vmscan_not_storing);
49227+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
49228 __fscache_uncache_page(cookie, page);
49229 return true;
49230 }
49231@@ -91,11 +91,11 @@ try_again:
49232 spin_unlock(&cookie->stores_lock);
49233
49234 if (xpage) {
49235- fscache_stat(&fscache_n_store_vmscan_cancelled);
49236- fscache_stat(&fscache_n_store_radix_deletes);
49237+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
49238+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49239 ASSERTCMP(xpage, ==, page);
49240 } else {
49241- fscache_stat(&fscache_n_store_vmscan_gone);
49242+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
49243 }
49244
49245 wake_up_bit(&cookie->flags, 0);
49246@@ -110,11 +110,11 @@ page_busy:
49247 * sleeping on memory allocation, so we may need to impose a timeout
49248 * too. */
49249 if (!(gfp & __GFP_WAIT)) {
49250- fscache_stat(&fscache_n_store_vmscan_busy);
49251+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
49252 return false;
49253 }
49254
49255- fscache_stat(&fscache_n_store_vmscan_wait);
49256+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
49257 __fscache_wait_on_page_write(cookie, page);
49258 gfp &= ~__GFP_WAIT;
49259 goto try_again;
49260@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
49261 FSCACHE_COOKIE_STORING_TAG);
49262 if (!radix_tree_tag_get(&cookie->stores, page->index,
49263 FSCACHE_COOKIE_PENDING_TAG)) {
49264- fscache_stat(&fscache_n_store_radix_deletes);
49265+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49266 xpage = radix_tree_delete(&cookie->stores, page->index);
49267 }
49268 spin_unlock(&cookie->stores_lock);
49269@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
49270
49271 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
49272
49273- fscache_stat(&fscache_n_attr_changed_calls);
49274+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
49275
49276 if (fscache_object_is_active(object)) {
49277 fscache_stat(&fscache_n_cop_attr_changed);
49278@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49279
49280 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49281
49282- fscache_stat(&fscache_n_attr_changed);
49283+ fscache_stat_unchecked(&fscache_n_attr_changed);
49284
49285 op = kzalloc(sizeof(*op), GFP_KERNEL);
49286 if (!op) {
49287- fscache_stat(&fscache_n_attr_changed_nomem);
49288+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
49289 _leave(" = -ENOMEM");
49290 return -ENOMEM;
49291 }
49292@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49293 if (fscache_submit_exclusive_op(object, op) < 0)
49294 goto nobufs;
49295 spin_unlock(&cookie->lock);
49296- fscache_stat(&fscache_n_attr_changed_ok);
49297+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
49298 fscache_put_operation(op);
49299 _leave(" = 0");
49300 return 0;
49301@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49302 nobufs:
49303 spin_unlock(&cookie->lock);
49304 kfree(op);
49305- fscache_stat(&fscache_n_attr_changed_nobufs);
49306+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
49307 _leave(" = %d", -ENOBUFS);
49308 return -ENOBUFS;
49309 }
49310@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
49311 /* allocate a retrieval operation and attempt to submit it */
49312 op = kzalloc(sizeof(*op), GFP_NOIO);
49313 if (!op) {
49314- fscache_stat(&fscache_n_retrievals_nomem);
49315+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49316 return NULL;
49317 }
49318
49319@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
49320 return 0;
49321 }
49322
49323- fscache_stat(&fscache_n_retrievals_wait);
49324+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
49325
49326 jif = jiffies;
49327 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
49328 fscache_wait_bit_interruptible,
49329 TASK_INTERRUPTIBLE) != 0) {
49330- fscache_stat(&fscache_n_retrievals_intr);
49331+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
49332 _leave(" = -ERESTARTSYS");
49333 return -ERESTARTSYS;
49334 }
49335@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
49336 */
49337 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49338 struct fscache_retrieval *op,
49339- atomic_t *stat_op_waits,
49340- atomic_t *stat_object_dead)
49341+ atomic_unchecked_t *stat_op_waits,
49342+ atomic_unchecked_t *stat_object_dead)
49343 {
49344 int ret;
49345
49346@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49347 goto check_if_dead;
49348
49349 _debug(">>> WT");
49350- fscache_stat(stat_op_waits);
49351+ fscache_stat_unchecked(stat_op_waits);
49352 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
49353 fscache_wait_bit_interruptible,
49354 TASK_INTERRUPTIBLE) != 0) {
49355@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49356
49357 check_if_dead:
49358 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
49359- fscache_stat(stat_object_dead);
49360+ fscache_stat_unchecked(stat_object_dead);
49361 _leave(" = -ENOBUFS [cancelled]");
49362 return -ENOBUFS;
49363 }
49364 if (unlikely(fscache_object_is_dead(object))) {
49365 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
49366 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
49367- fscache_stat(stat_object_dead);
49368+ fscache_stat_unchecked(stat_object_dead);
49369 return -ENOBUFS;
49370 }
49371 return 0;
49372@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49373
49374 _enter("%p,%p,,,", cookie, page);
49375
49376- fscache_stat(&fscache_n_retrievals);
49377+ fscache_stat_unchecked(&fscache_n_retrievals);
49378
49379 if (hlist_empty(&cookie->backing_objects))
49380 goto nobufs;
49381@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49382 goto nobufs_unlock_dec;
49383 spin_unlock(&cookie->lock);
49384
49385- fscache_stat(&fscache_n_retrieval_ops);
49386+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
49387
49388 /* pin the netfs read context in case we need to do the actual netfs
49389 * read because we've encountered a cache read failure */
49390@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49391
49392 error:
49393 if (ret == -ENOMEM)
49394- fscache_stat(&fscache_n_retrievals_nomem);
49395+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49396 else if (ret == -ERESTARTSYS)
49397- fscache_stat(&fscache_n_retrievals_intr);
49398+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
49399 else if (ret == -ENODATA)
49400- fscache_stat(&fscache_n_retrievals_nodata);
49401+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
49402 else if (ret < 0)
49403- fscache_stat(&fscache_n_retrievals_nobufs);
49404+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49405 else
49406- fscache_stat(&fscache_n_retrievals_ok);
49407+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
49408
49409 fscache_put_retrieval(op);
49410 _leave(" = %d", ret);
49411@@ -467,7 +467,7 @@ nobufs_unlock:
49412 spin_unlock(&cookie->lock);
49413 kfree(op);
49414 nobufs:
49415- fscache_stat(&fscache_n_retrievals_nobufs);
49416+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49417 _leave(" = -ENOBUFS");
49418 return -ENOBUFS;
49419 }
49420@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49421
49422 _enter("%p,,%d,,,", cookie, *nr_pages);
49423
49424- fscache_stat(&fscache_n_retrievals);
49425+ fscache_stat_unchecked(&fscache_n_retrievals);
49426
49427 if (hlist_empty(&cookie->backing_objects))
49428 goto nobufs;
49429@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49430 goto nobufs_unlock_dec;
49431 spin_unlock(&cookie->lock);
49432
49433- fscache_stat(&fscache_n_retrieval_ops);
49434+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
49435
49436 /* pin the netfs read context in case we need to do the actual netfs
49437 * read because we've encountered a cache read failure */
49438@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49439
49440 error:
49441 if (ret == -ENOMEM)
49442- fscache_stat(&fscache_n_retrievals_nomem);
49443+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49444 else if (ret == -ERESTARTSYS)
49445- fscache_stat(&fscache_n_retrievals_intr);
49446+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
49447 else if (ret == -ENODATA)
49448- fscache_stat(&fscache_n_retrievals_nodata);
49449+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
49450 else if (ret < 0)
49451- fscache_stat(&fscache_n_retrievals_nobufs);
49452+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49453 else
49454- fscache_stat(&fscache_n_retrievals_ok);
49455+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
49456
49457 fscache_put_retrieval(op);
49458 _leave(" = %d", ret);
49459@@ -591,7 +591,7 @@ nobufs_unlock:
49460 spin_unlock(&cookie->lock);
49461 kfree(op);
49462 nobufs:
49463- fscache_stat(&fscache_n_retrievals_nobufs);
49464+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49465 _leave(" = -ENOBUFS");
49466 return -ENOBUFS;
49467 }
49468@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49469
49470 _enter("%p,%p,,,", cookie, page);
49471
49472- fscache_stat(&fscache_n_allocs);
49473+ fscache_stat_unchecked(&fscache_n_allocs);
49474
49475 if (hlist_empty(&cookie->backing_objects))
49476 goto nobufs;
49477@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49478 goto nobufs_unlock;
49479 spin_unlock(&cookie->lock);
49480
49481- fscache_stat(&fscache_n_alloc_ops);
49482+ fscache_stat_unchecked(&fscache_n_alloc_ops);
49483
49484 ret = fscache_wait_for_retrieval_activation(
49485 object, op,
49486@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49487
49488 error:
49489 if (ret == -ERESTARTSYS)
49490- fscache_stat(&fscache_n_allocs_intr);
49491+ fscache_stat_unchecked(&fscache_n_allocs_intr);
49492 else if (ret < 0)
49493- fscache_stat(&fscache_n_allocs_nobufs);
49494+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
49495 else
49496- fscache_stat(&fscache_n_allocs_ok);
49497+ fscache_stat_unchecked(&fscache_n_allocs_ok);
49498
49499 fscache_put_retrieval(op);
49500 _leave(" = %d", ret);
49501@@ -677,7 +677,7 @@ nobufs_unlock:
49502 spin_unlock(&cookie->lock);
49503 kfree(op);
49504 nobufs:
49505- fscache_stat(&fscache_n_allocs_nobufs);
49506+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
49507 _leave(" = -ENOBUFS");
49508 return -ENOBUFS;
49509 }
49510@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49511
49512 spin_lock(&cookie->stores_lock);
49513
49514- fscache_stat(&fscache_n_store_calls);
49515+ fscache_stat_unchecked(&fscache_n_store_calls);
49516
49517 /* find a page to store */
49518 page = NULL;
49519@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49520 page = results[0];
49521 _debug("gang %d [%lx]", n, page->index);
49522 if (page->index > op->store_limit) {
49523- fscache_stat(&fscache_n_store_pages_over_limit);
49524+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
49525 goto superseded;
49526 }
49527
49528@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49529 spin_unlock(&cookie->stores_lock);
49530 spin_unlock(&object->lock);
49531
49532- fscache_stat(&fscache_n_store_pages);
49533+ fscache_stat_unchecked(&fscache_n_store_pages);
49534 fscache_stat(&fscache_n_cop_write_page);
49535 ret = object->cache->ops->write_page(op, page);
49536 fscache_stat_d(&fscache_n_cop_write_page);
49537@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49538 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49539 ASSERT(PageFsCache(page));
49540
49541- fscache_stat(&fscache_n_stores);
49542+ fscache_stat_unchecked(&fscache_n_stores);
49543
49544 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
49545 _leave(" = -ENOBUFS [invalidating]");
49546@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49547 spin_unlock(&cookie->stores_lock);
49548 spin_unlock(&object->lock);
49549
49550- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
49551+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
49552 op->store_limit = object->store_limit;
49553
49554 if (fscache_submit_op(object, &op->op) < 0)
49555@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49556
49557 spin_unlock(&cookie->lock);
49558 radix_tree_preload_end();
49559- fscache_stat(&fscache_n_store_ops);
49560- fscache_stat(&fscache_n_stores_ok);
49561+ fscache_stat_unchecked(&fscache_n_store_ops);
49562+ fscache_stat_unchecked(&fscache_n_stores_ok);
49563
49564 /* the work queue now carries its own ref on the object */
49565 fscache_put_operation(&op->op);
49566@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49567 return 0;
49568
49569 already_queued:
49570- fscache_stat(&fscache_n_stores_again);
49571+ fscache_stat_unchecked(&fscache_n_stores_again);
49572 already_pending:
49573 spin_unlock(&cookie->stores_lock);
49574 spin_unlock(&object->lock);
49575 spin_unlock(&cookie->lock);
49576 radix_tree_preload_end();
49577 kfree(op);
49578- fscache_stat(&fscache_n_stores_ok);
49579+ fscache_stat_unchecked(&fscache_n_stores_ok);
49580 _leave(" = 0");
49581 return 0;
49582
49583@@ -959,14 +959,14 @@ nobufs:
49584 spin_unlock(&cookie->lock);
49585 radix_tree_preload_end();
49586 kfree(op);
49587- fscache_stat(&fscache_n_stores_nobufs);
49588+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
49589 _leave(" = -ENOBUFS");
49590 return -ENOBUFS;
49591
49592 nomem_free:
49593 kfree(op);
49594 nomem:
49595- fscache_stat(&fscache_n_stores_oom);
49596+ fscache_stat_unchecked(&fscache_n_stores_oom);
49597 _leave(" = -ENOMEM");
49598 return -ENOMEM;
49599 }
49600@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
49601 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49602 ASSERTCMP(page, !=, NULL);
49603
49604- fscache_stat(&fscache_n_uncaches);
49605+ fscache_stat_unchecked(&fscache_n_uncaches);
49606
49607 /* cache withdrawal may beat us to it */
49608 if (!PageFsCache(page))
49609@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
49610 struct fscache_cookie *cookie = op->op.object->cookie;
49611
49612 #ifdef CONFIG_FSCACHE_STATS
49613- atomic_inc(&fscache_n_marks);
49614+ atomic_inc_unchecked(&fscache_n_marks);
49615 #endif
49616
49617 _debug("- mark %p{%lx}", page, page->index);
49618diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
49619index 8179e8b..5072cc7 100644
49620--- a/fs/fscache/stats.c
49621+++ b/fs/fscache/stats.c
49622@@ -18,99 +18,99 @@
49623 /*
49624 * operation counters
49625 */
49626-atomic_t fscache_n_op_pend;
49627-atomic_t fscache_n_op_run;
49628-atomic_t fscache_n_op_enqueue;
49629-atomic_t fscache_n_op_requeue;
49630-atomic_t fscache_n_op_deferred_release;
49631-atomic_t fscache_n_op_release;
49632-atomic_t fscache_n_op_gc;
49633-atomic_t fscache_n_op_cancelled;
49634-atomic_t fscache_n_op_rejected;
49635+atomic_unchecked_t fscache_n_op_pend;
49636+atomic_unchecked_t fscache_n_op_run;
49637+atomic_unchecked_t fscache_n_op_enqueue;
49638+atomic_unchecked_t fscache_n_op_requeue;
49639+atomic_unchecked_t fscache_n_op_deferred_release;
49640+atomic_unchecked_t fscache_n_op_release;
49641+atomic_unchecked_t fscache_n_op_gc;
49642+atomic_unchecked_t fscache_n_op_cancelled;
49643+atomic_unchecked_t fscache_n_op_rejected;
49644
49645-atomic_t fscache_n_attr_changed;
49646-atomic_t fscache_n_attr_changed_ok;
49647-atomic_t fscache_n_attr_changed_nobufs;
49648-atomic_t fscache_n_attr_changed_nomem;
49649-atomic_t fscache_n_attr_changed_calls;
49650+atomic_unchecked_t fscache_n_attr_changed;
49651+atomic_unchecked_t fscache_n_attr_changed_ok;
49652+atomic_unchecked_t fscache_n_attr_changed_nobufs;
49653+atomic_unchecked_t fscache_n_attr_changed_nomem;
49654+atomic_unchecked_t fscache_n_attr_changed_calls;
49655
49656-atomic_t fscache_n_allocs;
49657-atomic_t fscache_n_allocs_ok;
49658-atomic_t fscache_n_allocs_wait;
49659-atomic_t fscache_n_allocs_nobufs;
49660-atomic_t fscache_n_allocs_intr;
49661-atomic_t fscache_n_allocs_object_dead;
49662-atomic_t fscache_n_alloc_ops;
49663-atomic_t fscache_n_alloc_op_waits;
49664+atomic_unchecked_t fscache_n_allocs;
49665+atomic_unchecked_t fscache_n_allocs_ok;
49666+atomic_unchecked_t fscache_n_allocs_wait;
49667+atomic_unchecked_t fscache_n_allocs_nobufs;
49668+atomic_unchecked_t fscache_n_allocs_intr;
49669+atomic_unchecked_t fscache_n_allocs_object_dead;
49670+atomic_unchecked_t fscache_n_alloc_ops;
49671+atomic_unchecked_t fscache_n_alloc_op_waits;
49672
49673-atomic_t fscache_n_retrievals;
49674-atomic_t fscache_n_retrievals_ok;
49675-atomic_t fscache_n_retrievals_wait;
49676-atomic_t fscache_n_retrievals_nodata;
49677-atomic_t fscache_n_retrievals_nobufs;
49678-atomic_t fscache_n_retrievals_intr;
49679-atomic_t fscache_n_retrievals_nomem;
49680-atomic_t fscache_n_retrievals_object_dead;
49681-atomic_t fscache_n_retrieval_ops;
49682-atomic_t fscache_n_retrieval_op_waits;
49683+atomic_unchecked_t fscache_n_retrievals;
49684+atomic_unchecked_t fscache_n_retrievals_ok;
49685+atomic_unchecked_t fscache_n_retrievals_wait;
49686+atomic_unchecked_t fscache_n_retrievals_nodata;
49687+atomic_unchecked_t fscache_n_retrievals_nobufs;
49688+atomic_unchecked_t fscache_n_retrievals_intr;
49689+atomic_unchecked_t fscache_n_retrievals_nomem;
49690+atomic_unchecked_t fscache_n_retrievals_object_dead;
49691+atomic_unchecked_t fscache_n_retrieval_ops;
49692+atomic_unchecked_t fscache_n_retrieval_op_waits;
49693
49694-atomic_t fscache_n_stores;
49695-atomic_t fscache_n_stores_ok;
49696-atomic_t fscache_n_stores_again;
49697-atomic_t fscache_n_stores_nobufs;
49698-atomic_t fscache_n_stores_oom;
49699-atomic_t fscache_n_store_ops;
49700-atomic_t fscache_n_store_calls;
49701-atomic_t fscache_n_store_pages;
49702-atomic_t fscache_n_store_radix_deletes;
49703-atomic_t fscache_n_store_pages_over_limit;
49704+atomic_unchecked_t fscache_n_stores;
49705+atomic_unchecked_t fscache_n_stores_ok;
49706+atomic_unchecked_t fscache_n_stores_again;
49707+atomic_unchecked_t fscache_n_stores_nobufs;
49708+atomic_unchecked_t fscache_n_stores_oom;
49709+atomic_unchecked_t fscache_n_store_ops;
49710+atomic_unchecked_t fscache_n_store_calls;
49711+atomic_unchecked_t fscache_n_store_pages;
49712+atomic_unchecked_t fscache_n_store_radix_deletes;
49713+atomic_unchecked_t fscache_n_store_pages_over_limit;
49714
49715-atomic_t fscache_n_store_vmscan_not_storing;
49716-atomic_t fscache_n_store_vmscan_gone;
49717-atomic_t fscache_n_store_vmscan_busy;
49718-atomic_t fscache_n_store_vmscan_cancelled;
49719-atomic_t fscache_n_store_vmscan_wait;
49720+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
49721+atomic_unchecked_t fscache_n_store_vmscan_gone;
49722+atomic_unchecked_t fscache_n_store_vmscan_busy;
49723+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
49724+atomic_unchecked_t fscache_n_store_vmscan_wait;
49725
49726-atomic_t fscache_n_marks;
49727-atomic_t fscache_n_uncaches;
49728+atomic_unchecked_t fscache_n_marks;
49729+atomic_unchecked_t fscache_n_uncaches;
49730
49731-atomic_t fscache_n_acquires;
49732-atomic_t fscache_n_acquires_null;
49733-atomic_t fscache_n_acquires_no_cache;
49734-atomic_t fscache_n_acquires_ok;
49735-atomic_t fscache_n_acquires_nobufs;
49736-atomic_t fscache_n_acquires_oom;
49737+atomic_unchecked_t fscache_n_acquires;
49738+atomic_unchecked_t fscache_n_acquires_null;
49739+atomic_unchecked_t fscache_n_acquires_no_cache;
49740+atomic_unchecked_t fscache_n_acquires_ok;
49741+atomic_unchecked_t fscache_n_acquires_nobufs;
49742+atomic_unchecked_t fscache_n_acquires_oom;
49743
49744-atomic_t fscache_n_invalidates;
49745-atomic_t fscache_n_invalidates_run;
49746+atomic_unchecked_t fscache_n_invalidates;
49747+atomic_unchecked_t fscache_n_invalidates_run;
49748
49749-atomic_t fscache_n_updates;
49750-atomic_t fscache_n_updates_null;
49751-atomic_t fscache_n_updates_run;
49752+atomic_unchecked_t fscache_n_updates;
49753+atomic_unchecked_t fscache_n_updates_null;
49754+atomic_unchecked_t fscache_n_updates_run;
49755
49756-atomic_t fscache_n_relinquishes;
49757-atomic_t fscache_n_relinquishes_null;
49758-atomic_t fscache_n_relinquishes_waitcrt;
49759-atomic_t fscache_n_relinquishes_retire;
49760+atomic_unchecked_t fscache_n_relinquishes;
49761+atomic_unchecked_t fscache_n_relinquishes_null;
49762+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
49763+atomic_unchecked_t fscache_n_relinquishes_retire;
49764
49765-atomic_t fscache_n_cookie_index;
49766-atomic_t fscache_n_cookie_data;
49767-atomic_t fscache_n_cookie_special;
49768+atomic_unchecked_t fscache_n_cookie_index;
49769+atomic_unchecked_t fscache_n_cookie_data;
49770+atomic_unchecked_t fscache_n_cookie_special;
49771
49772-atomic_t fscache_n_object_alloc;
49773-atomic_t fscache_n_object_no_alloc;
49774-atomic_t fscache_n_object_lookups;
49775-atomic_t fscache_n_object_lookups_negative;
49776-atomic_t fscache_n_object_lookups_positive;
49777-atomic_t fscache_n_object_lookups_timed_out;
49778-atomic_t fscache_n_object_created;
49779-atomic_t fscache_n_object_avail;
49780-atomic_t fscache_n_object_dead;
49781+atomic_unchecked_t fscache_n_object_alloc;
49782+atomic_unchecked_t fscache_n_object_no_alloc;
49783+atomic_unchecked_t fscache_n_object_lookups;
49784+atomic_unchecked_t fscache_n_object_lookups_negative;
49785+atomic_unchecked_t fscache_n_object_lookups_positive;
49786+atomic_unchecked_t fscache_n_object_lookups_timed_out;
49787+atomic_unchecked_t fscache_n_object_created;
49788+atomic_unchecked_t fscache_n_object_avail;
49789+atomic_unchecked_t fscache_n_object_dead;
49790
49791-atomic_t fscache_n_checkaux_none;
49792-atomic_t fscache_n_checkaux_okay;
49793-atomic_t fscache_n_checkaux_update;
49794-atomic_t fscache_n_checkaux_obsolete;
49795+atomic_unchecked_t fscache_n_checkaux_none;
49796+atomic_unchecked_t fscache_n_checkaux_okay;
49797+atomic_unchecked_t fscache_n_checkaux_update;
49798+atomic_unchecked_t fscache_n_checkaux_obsolete;
49799
49800 atomic_t fscache_n_cop_alloc_object;
49801 atomic_t fscache_n_cop_lookup_object;
49802@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
49803 seq_puts(m, "FS-Cache statistics\n");
49804
49805 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
49806- atomic_read(&fscache_n_cookie_index),
49807- atomic_read(&fscache_n_cookie_data),
49808- atomic_read(&fscache_n_cookie_special));
49809+ atomic_read_unchecked(&fscache_n_cookie_index),
49810+ atomic_read_unchecked(&fscache_n_cookie_data),
49811+ atomic_read_unchecked(&fscache_n_cookie_special));
49812
49813 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
49814- atomic_read(&fscache_n_object_alloc),
49815- atomic_read(&fscache_n_object_no_alloc),
49816- atomic_read(&fscache_n_object_avail),
49817- atomic_read(&fscache_n_object_dead));
49818+ atomic_read_unchecked(&fscache_n_object_alloc),
49819+ atomic_read_unchecked(&fscache_n_object_no_alloc),
49820+ atomic_read_unchecked(&fscache_n_object_avail),
49821+ atomic_read_unchecked(&fscache_n_object_dead));
49822 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
49823- atomic_read(&fscache_n_checkaux_none),
49824- atomic_read(&fscache_n_checkaux_okay),
49825- atomic_read(&fscache_n_checkaux_update),
49826- atomic_read(&fscache_n_checkaux_obsolete));
49827+ atomic_read_unchecked(&fscache_n_checkaux_none),
49828+ atomic_read_unchecked(&fscache_n_checkaux_okay),
49829+ atomic_read_unchecked(&fscache_n_checkaux_update),
49830+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
49831
49832 seq_printf(m, "Pages : mrk=%u unc=%u\n",
49833- atomic_read(&fscache_n_marks),
49834- atomic_read(&fscache_n_uncaches));
49835+ atomic_read_unchecked(&fscache_n_marks),
49836+ atomic_read_unchecked(&fscache_n_uncaches));
49837
49838 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
49839 " oom=%u\n",
49840- atomic_read(&fscache_n_acquires),
49841- atomic_read(&fscache_n_acquires_null),
49842- atomic_read(&fscache_n_acquires_no_cache),
49843- atomic_read(&fscache_n_acquires_ok),
49844- atomic_read(&fscache_n_acquires_nobufs),
49845- atomic_read(&fscache_n_acquires_oom));
49846+ atomic_read_unchecked(&fscache_n_acquires),
49847+ atomic_read_unchecked(&fscache_n_acquires_null),
49848+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
49849+ atomic_read_unchecked(&fscache_n_acquires_ok),
49850+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
49851+ atomic_read_unchecked(&fscache_n_acquires_oom));
49852
49853 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
49854- atomic_read(&fscache_n_object_lookups),
49855- atomic_read(&fscache_n_object_lookups_negative),
49856- atomic_read(&fscache_n_object_lookups_positive),
49857- atomic_read(&fscache_n_object_created),
49858- atomic_read(&fscache_n_object_lookups_timed_out));
49859+ atomic_read_unchecked(&fscache_n_object_lookups),
49860+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
49861+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
49862+ atomic_read_unchecked(&fscache_n_object_created),
49863+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
49864
49865 seq_printf(m, "Invals : n=%u run=%u\n",
49866- atomic_read(&fscache_n_invalidates),
49867- atomic_read(&fscache_n_invalidates_run));
49868+ atomic_read_unchecked(&fscache_n_invalidates),
49869+ atomic_read_unchecked(&fscache_n_invalidates_run));
49870
49871 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
49872- atomic_read(&fscache_n_updates),
49873- atomic_read(&fscache_n_updates_null),
49874- atomic_read(&fscache_n_updates_run));
49875+ atomic_read_unchecked(&fscache_n_updates),
49876+ atomic_read_unchecked(&fscache_n_updates_null),
49877+ atomic_read_unchecked(&fscache_n_updates_run));
49878
49879 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
49880- atomic_read(&fscache_n_relinquishes),
49881- atomic_read(&fscache_n_relinquishes_null),
49882- atomic_read(&fscache_n_relinquishes_waitcrt),
49883- atomic_read(&fscache_n_relinquishes_retire));
49884+ atomic_read_unchecked(&fscache_n_relinquishes),
49885+ atomic_read_unchecked(&fscache_n_relinquishes_null),
49886+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
49887+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
49888
49889 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
49890- atomic_read(&fscache_n_attr_changed),
49891- atomic_read(&fscache_n_attr_changed_ok),
49892- atomic_read(&fscache_n_attr_changed_nobufs),
49893- atomic_read(&fscache_n_attr_changed_nomem),
49894- atomic_read(&fscache_n_attr_changed_calls));
49895+ atomic_read_unchecked(&fscache_n_attr_changed),
49896+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
49897+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
49898+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
49899+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
49900
49901 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
49902- atomic_read(&fscache_n_allocs),
49903- atomic_read(&fscache_n_allocs_ok),
49904- atomic_read(&fscache_n_allocs_wait),
49905- atomic_read(&fscache_n_allocs_nobufs),
49906- atomic_read(&fscache_n_allocs_intr));
49907+ atomic_read_unchecked(&fscache_n_allocs),
49908+ atomic_read_unchecked(&fscache_n_allocs_ok),
49909+ atomic_read_unchecked(&fscache_n_allocs_wait),
49910+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
49911+ atomic_read_unchecked(&fscache_n_allocs_intr));
49912 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
49913- atomic_read(&fscache_n_alloc_ops),
49914- atomic_read(&fscache_n_alloc_op_waits),
49915- atomic_read(&fscache_n_allocs_object_dead));
49916+ atomic_read_unchecked(&fscache_n_alloc_ops),
49917+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
49918+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
49919
49920 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
49921 " int=%u oom=%u\n",
49922- atomic_read(&fscache_n_retrievals),
49923- atomic_read(&fscache_n_retrievals_ok),
49924- atomic_read(&fscache_n_retrievals_wait),
49925- atomic_read(&fscache_n_retrievals_nodata),
49926- atomic_read(&fscache_n_retrievals_nobufs),
49927- atomic_read(&fscache_n_retrievals_intr),
49928- atomic_read(&fscache_n_retrievals_nomem));
49929+ atomic_read_unchecked(&fscache_n_retrievals),
49930+ atomic_read_unchecked(&fscache_n_retrievals_ok),
49931+ atomic_read_unchecked(&fscache_n_retrievals_wait),
49932+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
49933+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
49934+ atomic_read_unchecked(&fscache_n_retrievals_intr),
49935+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
49936 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
49937- atomic_read(&fscache_n_retrieval_ops),
49938- atomic_read(&fscache_n_retrieval_op_waits),
49939- atomic_read(&fscache_n_retrievals_object_dead));
49940+ atomic_read_unchecked(&fscache_n_retrieval_ops),
49941+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
49942+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
49943
49944 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
49945- atomic_read(&fscache_n_stores),
49946- atomic_read(&fscache_n_stores_ok),
49947- atomic_read(&fscache_n_stores_again),
49948- atomic_read(&fscache_n_stores_nobufs),
49949- atomic_read(&fscache_n_stores_oom));
49950+ atomic_read_unchecked(&fscache_n_stores),
49951+ atomic_read_unchecked(&fscache_n_stores_ok),
49952+ atomic_read_unchecked(&fscache_n_stores_again),
49953+ atomic_read_unchecked(&fscache_n_stores_nobufs),
49954+ atomic_read_unchecked(&fscache_n_stores_oom));
49955 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
49956- atomic_read(&fscache_n_store_ops),
49957- atomic_read(&fscache_n_store_calls),
49958- atomic_read(&fscache_n_store_pages),
49959- atomic_read(&fscache_n_store_radix_deletes),
49960- atomic_read(&fscache_n_store_pages_over_limit));
49961+ atomic_read_unchecked(&fscache_n_store_ops),
49962+ atomic_read_unchecked(&fscache_n_store_calls),
49963+ atomic_read_unchecked(&fscache_n_store_pages),
49964+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
49965+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
49966
49967 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
49968- atomic_read(&fscache_n_store_vmscan_not_storing),
49969- atomic_read(&fscache_n_store_vmscan_gone),
49970- atomic_read(&fscache_n_store_vmscan_busy),
49971- atomic_read(&fscache_n_store_vmscan_cancelled),
49972- atomic_read(&fscache_n_store_vmscan_wait));
49973+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
49974+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
49975+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
49976+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
49977+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
49978
49979 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
49980- atomic_read(&fscache_n_op_pend),
49981- atomic_read(&fscache_n_op_run),
49982- atomic_read(&fscache_n_op_enqueue),
49983- atomic_read(&fscache_n_op_cancelled),
49984- atomic_read(&fscache_n_op_rejected));
49985+ atomic_read_unchecked(&fscache_n_op_pend),
49986+ atomic_read_unchecked(&fscache_n_op_run),
49987+ atomic_read_unchecked(&fscache_n_op_enqueue),
49988+ atomic_read_unchecked(&fscache_n_op_cancelled),
49989+ atomic_read_unchecked(&fscache_n_op_rejected));
49990 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
49991- atomic_read(&fscache_n_op_deferred_release),
49992- atomic_read(&fscache_n_op_release),
49993- atomic_read(&fscache_n_op_gc));
49994+ atomic_read_unchecked(&fscache_n_op_deferred_release),
49995+ atomic_read_unchecked(&fscache_n_op_release),
49996+ atomic_read_unchecked(&fscache_n_op_gc));
49997
49998 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
49999 atomic_read(&fscache_n_cop_alloc_object),
50000diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
50001index e397b67..b0d8709 100644
50002--- a/fs/fuse/cuse.c
50003+++ b/fs/fuse/cuse.c
50004@@ -593,10 +593,12 @@ static int __init cuse_init(void)
50005 INIT_LIST_HEAD(&cuse_conntbl[i]);
50006
50007 /* inherit and extend fuse_dev_operations */
50008- cuse_channel_fops = fuse_dev_operations;
50009- cuse_channel_fops.owner = THIS_MODULE;
50010- cuse_channel_fops.open = cuse_channel_open;
50011- cuse_channel_fops.release = cuse_channel_release;
50012+ pax_open_kernel();
50013+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
50014+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
50015+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
50016+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
50017+ pax_close_kernel();
50018
50019 cuse_class = class_create(THIS_MODULE, "cuse");
50020 if (IS_ERR(cuse_class))
50021diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
50022index e83351a..41e3c9c 100644
50023--- a/fs/fuse/dev.c
50024+++ b/fs/fuse/dev.c
50025@@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
50026 ret = 0;
50027 pipe_lock(pipe);
50028
50029- if (!pipe->readers) {
50030+ if (!atomic_read(&pipe->readers)) {
50031 send_sig(SIGPIPE, current, 0);
50032 if (!ret)
50033 ret = -EPIPE;
50034diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
50035index b7c09f9..3eff736 100644
50036--- a/fs/fuse/dir.c
50037+++ b/fs/fuse/dir.c
50038@@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
50039 return link;
50040 }
50041
50042-static void free_link(char *link)
50043+static void free_link(const char *link)
50044 {
50045 if (!IS_ERR(link))
50046 free_page((unsigned long) link);
50047diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
50048index 2b6f569..fcb4d1f 100644
50049--- a/fs/gfs2/inode.c
50050+++ b/fs/gfs2/inode.c
50051@@ -1499,7 +1499,7 @@ out:
50052
50053 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
50054 {
50055- char *s = nd_get_link(nd);
50056+ const char *s = nd_get_link(nd);
50057 if (!IS_ERR(s))
50058 kfree(s);
50059 }
50060diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
50061index 78bde32..767e906 100644
50062--- a/fs/hugetlbfs/inode.c
50063+++ b/fs/hugetlbfs/inode.c
50064@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
50065 struct mm_struct *mm = current->mm;
50066 struct vm_area_struct *vma;
50067 struct hstate *h = hstate_file(file);
50068+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
50069 struct vm_unmapped_area_info info;
50070
50071 if (len & ~huge_page_mask(h))
50072@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
50073 return addr;
50074 }
50075
50076+#ifdef CONFIG_PAX_RANDMMAP
50077+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
50078+#endif
50079+
50080 if (addr) {
50081 addr = ALIGN(addr, huge_page_size(h));
50082 vma = find_vma(mm, addr);
50083- if (TASK_SIZE - len >= addr &&
50084- (!vma || addr + len <= vma->vm_start))
50085+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
50086 return addr;
50087 }
50088
50089 info.flags = 0;
50090 info.length = len;
50091 info.low_limit = TASK_UNMAPPED_BASE;
50092+
50093+#ifdef CONFIG_PAX_RANDMMAP
50094+ if (mm->pax_flags & MF_PAX_RANDMMAP)
50095+ info.low_limit += mm->delta_mmap;
50096+#endif
50097+
50098 info.high_limit = TASK_SIZE;
50099 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
50100 info.align_offset = 0;
50101@@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
50102 .kill_sb = kill_litter_super,
50103 };
50104
50105-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
50106+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
50107
50108 static int can_do_hugetlb_shm(void)
50109 {
50110diff --git a/fs/inode.c b/fs/inode.c
50111index 14084b7..29af1d9 100644
50112--- a/fs/inode.c
50113+++ b/fs/inode.c
50114@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
50115
50116 #ifdef CONFIG_SMP
50117 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
50118- static atomic_t shared_last_ino;
50119- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
50120+ static atomic_unchecked_t shared_last_ino;
50121+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
50122
50123 res = next - LAST_INO_BATCH;
50124 }
50125diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
50126index 4a6cf28..d3a29d3 100644
50127--- a/fs/jffs2/erase.c
50128+++ b/fs/jffs2/erase.c
50129@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
50130 struct jffs2_unknown_node marker = {
50131 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
50132 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50133- .totlen = cpu_to_je32(c->cleanmarker_size)
50134+ .totlen = cpu_to_je32(c->cleanmarker_size),
50135+ .hdr_crc = cpu_to_je32(0)
50136 };
50137
50138 jffs2_prealloc_raw_node_refs(c, jeb, 1);
50139diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
50140index a6597d6..41b30ec 100644
50141--- a/fs/jffs2/wbuf.c
50142+++ b/fs/jffs2/wbuf.c
50143@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
50144 {
50145 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
50146 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50147- .totlen = constant_cpu_to_je32(8)
50148+ .totlen = constant_cpu_to_je32(8),
50149+ .hdr_crc = constant_cpu_to_je32(0)
50150 };
50151
50152 /*
50153diff --git a/fs/jfs/super.c b/fs/jfs/super.c
50154index 1a543be..d803c40 100644
50155--- a/fs/jfs/super.c
50156+++ b/fs/jfs/super.c
50157@@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
50158
50159 jfs_inode_cachep =
50160 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
50161- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
50162+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
50163 init_once);
50164 if (jfs_inode_cachep == NULL)
50165 return -ENOMEM;
50166diff --git a/fs/libfs.c b/fs/libfs.c
50167index 916da8c..1588998 100644
50168--- a/fs/libfs.c
50169+++ b/fs/libfs.c
50170@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
50171
50172 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
50173 struct dentry *next;
50174+ char d_name[sizeof(next->d_iname)];
50175+ const unsigned char *name;
50176+
50177 next = list_entry(p, struct dentry, d_u.d_child);
50178 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
50179 if (!simple_positive(next)) {
50180@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
50181
50182 spin_unlock(&next->d_lock);
50183 spin_unlock(&dentry->d_lock);
50184- if (filldir(dirent, next->d_name.name,
50185+ name = next->d_name.name;
50186+ if (name == next->d_iname) {
50187+ memcpy(d_name, name, next->d_name.len);
50188+ name = d_name;
50189+ }
50190+ if (filldir(dirent, name,
50191 next->d_name.len, filp->f_pos,
50192 next->d_inode->i_ino,
50193 dt_type(next->d_inode)) < 0)
50194diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
50195index 54f9e6c..9ed908c 100644
50196--- a/fs/lockd/clntproc.c
50197+++ b/fs/lockd/clntproc.c
50198@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
50199 /*
50200 * Cookie counter for NLM requests
50201 */
50202-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
50203+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
50204
50205 void nlmclnt_next_cookie(struct nlm_cookie *c)
50206 {
50207- u32 cookie = atomic_inc_return(&nlm_cookie);
50208+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
50209
50210 memcpy(c->data, &cookie, 4);
50211 c->len=4;
50212diff --git a/fs/locks.c b/fs/locks.c
50213index a94e331..060bce3 100644
50214--- a/fs/locks.c
50215+++ b/fs/locks.c
50216@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
50217 return;
50218
50219 if (filp->f_op && filp->f_op->flock) {
50220- struct file_lock fl = {
50221+ struct file_lock flock = {
50222 .fl_pid = current->tgid,
50223 .fl_file = filp,
50224 .fl_flags = FL_FLOCK,
50225 .fl_type = F_UNLCK,
50226 .fl_end = OFFSET_MAX,
50227 };
50228- filp->f_op->flock(filp, F_SETLKW, &fl);
50229- if (fl.fl_ops && fl.fl_ops->fl_release_private)
50230- fl.fl_ops->fl_release_private(&fl);
50231+ filp->f_op->flock(filp, F_SETLKW, &flock);
50232+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
50233+ flock.fl_ops->fl_release_private(&flock);
50234 }
50235
50236 lock_flocks();
50237diff --git a/fs/namei.c b/fs/namei.c
50238index 43a97ee..117e7e4 100644
50239--- a/fs/namei.c
50240+++ b/fs/namei.c
50241@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
50242 if (ret != -EACCES)
50243 return ret;
50244
50245+#ifdef CONFIG_GRKERNSEC
50246+ /* we'll block if we have to log due to a denied capability use */
50247+ if (mask & MAY_NOT_BLOCK)
50248+ return -ECHILD;
50249+#endif
50250+
50251 if (S_ISDIR(inode->i_mode)) {
50252 /* DACs are overridable for directories */
50253- if (inode_capable(inode, CAP_DAC_OVERRIDE))
50254- return 0;
50255 if (!(mask & MAY_WRITE))
50256- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
50257+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
50258+ inode_capable(inode, CAP_DAC_READ_SEARCH))
50259 return 0;
50260+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
50261+ return 0;
50262 return -EACCES;
50263 }
50264 /*
50265+ * Searching includes executable on directories, else just read.
50266+ */
50267+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
50268+ if (mask == MAY_READ)
50269+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
50270+ inode_capable(inode, CAP_DAC_READ_SEARCH))
50271+ return 0;
50272+
50273+ /*
50274 * Read/write DACs are always overridable.
50275 * Executable DACs are overridable when there is
50276 * at least one exec bit set.
50277@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
50278 if (inode_capable(inode, CAP_DAC_OVERRIDE))
50279 return 0;
50280
50281- /*
50282- * Searching includes executable on directories, else just read.
50283- */
50284- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
50285- if (mask == MAY_READ)
50286- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
50287- return 0;
50288-
50289 return -EACCES;
50290 }
50291
50292@@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
50293 {
50294 struct dentry *dentry = link->dentry;
50295 int error;
50296- char *s;
50297+ const char *s;
50298
50299 BUG_ON(nd->flags & LOOKUP_RCU);
50300
50301@@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
50302 if (error)
50303 goto out_put_nd_path;
50304
50305+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
50306+ dentry->d_inode, dentry, nd->path.mnt)) {
50307+ error = -EACCES;
50308+ goto out_put_nd_path;
50309+ }
50310+
50311 nd->last_type = LAST_BIND;
50312 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
50313 error = PTR_ERR(*p);
50314@@ -1596,6 +1610,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
50315 break;
50316 res = walk_component(nd, path, &nd->last,
50317 nd->last_type, LOOKUP_FOLLOW);
50318+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
50319+ res = -EACCES;
50320 put_link(nd, &link, cookie);
50321 } while (res > 0);
50322
50323@@ -1694,7 +1710,7 @@ EXPORT_SYMBOL(full_name_hash);
50324 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
50325 {
50326 unsigned long a, b, adata, bdata, mask, hash, len;
50327- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
50328+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
50329
50330 hash = a = 0;
50331 len = -sizeof(unsigned long);
50332@@ -1979,6 +1995,8 @@ static int path_lookupat(int dfd, const char *name,
50333 if (err)
50334 break;
50335 err = lookup_last(nd, &path);
50336+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
50337+ err = -EACCES;
50338 put_link(nd, &link, cookie);
50339 }
50340 }
50341@@ -1986,6 +2004,21 @@ static int path_lookupat(int dfd, const char *name,
50342 if (!err)
50343 err = complete_walk(nd);
50344
50345+ if (!(nd->flags & LOOKUP_PARENT)) {
50346+#ifdef CONFIG_GRKERNSEC
50347+ if (flags & LOOKUP_RCU) {
50348+ if (!err)
50349+ path_put(&nd->path);
50350+ err = -ECHILD;
50351+ } else
50352+#endif
50353+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50354+ if (!err)
50355+ path_put(&nd->path);
50356+ err = -ENOENT;
50357+ }
50358+ }
50359+
50360 if (!err && nd->flags & LOOKUP_DIRECTORY) {
50361 if (!nd->inode->i_op->lookup) {
50362 path_put(&nd->path);
50363@@ -2013,8 +2046,17 @@ static int filename_lookup(int dfd, struct filename *name,
50364 retval = path_lookupat(dfd, name->name,
50365 flags | LOOKUP_REVAL, nd);
50366
50367- if (likely(!retval))
50368+ if (likely(!retval)) {
50369+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
50370+#ifdef CONFIG_GRKERNSEC
50371+ if (flags & LOOKUP_RCU)
50372+ return -ECHILD;
50373+#endif
50374+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
50375+ return -ENOENT;
50376+ }
50377 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
50378+ }
50379 return retval;
50380 }
50381
50382@@ -2392,6 +2434,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
50383 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
50384 return -EPERM;
50385
50386+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
50387+ return -EPERM;
50388+ if (gr_handle_rawio(inode))
50389+ return -EPERM;
50390+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
50391+ return -EACCES;
50392+
50393 return 0;
50394 }
50395
50396@@ -2613,7 +2662,7 @@ looked_up:
50397 * cleared otherwise prior to returning.
50398 */
50399 static int lookup_open(struct nameidata *nd, struct path *path,
50400- struct file *file,
50401+ struct path *link, struct file *file,
50402 const struct open_flags *op,
50403 bool got_write, int *opened)
50404 {
50405@@ -2648,6 +2697,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
50406 /* Negative dentry, just create the file */
50407 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
50408 umode_t mode = op->mode;
50409+
50410+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
50411+ error = -EACCES;
50412+ goto out_dput;
50413+ }
50414+
50415+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
50416+ error = -EACCES;
50417+ goto out_dput;
50418+ }
50419+
50420 if (!IS_POSIXACL(dir->d_inode))
50421 mode &= ~current_umask();
50422 /*
50423@@ -2669,6 +2729,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
50424 nd->flags & LOOKUP_EXCL);
50425 if (error)
50426 goto out_dput;
50427+ else
50428+ gr_handle_create(dentry, nd->path.mnt);
50429 }
50430 out_no_open:
50431 path->dentry = dentry;
50432@@ -2683,7 +2745,7 @@ out_dput:
50433 /*
50434 * Handle the last step of open()
50435 */
50436-static int do_last(struct nameidata *nd, struct path *path,
50437+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
50438 struct file *file, const struct open_flags *op,
50439 int *opened, struct filename *name)
50440 {
50441@@ -2712,16 +2774,44 @@ static int do_last(struct nameidata *nd, struct path *path,
50442 error = complete_walk(nd);
50443 if (error)
50444 return error;
50445+#ifdef CONFIG_GRKERNSEC
50446+ if (nd->flags & LOOKUP_RCU) {
50447+ error = -ECHILD;
50448+ goto out;
50449+ }
50450+#endif
50451+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50452+ error = -ENOENT;
50453+ goto out;
50454+ }
50455 audit_inode(name, nd->path.dentry, 0);
50456 if (open_flag & O_CREAT) {
50457 error = -EISDIR;
50458 goto out;
50459 }
50460+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
50461+ error = -EACCES;
50462+ goto out;
50463+ }
50464 goto finish_open;
50465 case LAST_BIND:
50466 error = complete_walk(nd);
50467 if (error)
50468 return error;
50469+#ifdef CONFIG_GRKERNSEC
50470+ if (nd->flags & LOOKUP_RCU) {
50471+ error = -ECHILD;
50472+ goto out;
50473+ }
50474+#endif
50475+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
50476+ error = -ENOENT;
50477+ goto out;
50478+ }
50479+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
50480+ error = -EACCES;
50481+ goto out;
50482+ }
50483 audit_inode(name, dir, 0);
50484 goto finish_open;
50485 }
50486@@ -2770,7 +2860,7 @@ retry_lookup:
50487 */
50488 }
50489 mutex_lock(&dir->d_inode->i_mutex);
50490- error = lookup_open(nd, path, file, op, got_write, opened);
50491+ error = lookup_open(nd, path, link, file, op, got_write, opened);
50492 mutex_unlock(&dir->d_inode->i_mutex);
50493
50494 if (error <= 0) {
50495@@ -2794,11 +2884,28 @@ retry_lookup:
50496 goto finish_open_created;
50497 }
50498
50499+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
50500+ error = -ENOENT;
50501+ goto exit_dput;
50502+ }
50503+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
50504+ error = -EACCES;
50505+ goto exit_dput;
50506+ }
50507+
50508 /*
50509 * create/update audit record if it already exists.
50510 */
50511- if (path->dentry->d_inode)
50512+ if (path->dentry->d_inode) {
50513+ /* only check if O_CREAT is specified, all other checks need to go
50514+ into may_open */
50515+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
50516+ error = -EACCES;
50517+ goto exit_dput;
50518+ }
50519+
50520 audit_inode(name, path->dentry, 0);
50521+ }
50522
50523 /*
50524 * If atomic_open() acquired write access it is dropped now due to
50525@@ -2839,6 +2946,11 @@ finish_lookup:
50526 }
50527 }
50528 BUG_ON(inode != path->dentry->d_inode);
50529+ /* if we're resolving a symlink to another symlink */
50530+ if (link && gr_handle_symlink_owner(link, inode)) {
50531+ error = -EACCES;
50532+ goto out;
50533+ }
50534 return 1;
50535 }
50536
50537@@ -2848,7 +2960,6 @@ finish_lookup:
50538 save_parent.dentry = nd->path.dentry;
50539 save_parent.mnt = mntget(path->mnt);
50540 nd->path.dentry = path->dentry;
50541-
50542 }
50543 nd->inode = inode;
50544 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
50545@@ -2857,6 +2968,22 @@ finish_lookup:
50546 path_put(&save_parent);
50547 return error;
50548 }
50549+
50550+#ifdef CONFIG_GRKERNSEC
50551+ if (nd->flags & LOOKUP_RCU) {
50552+ error = -ECHILD;
50553+ goto out;
50554+ }
50555+#endif
50556+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50557+ error = -ENOENT;
50558+ goto out;
50559+ }
50560+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
50561+ error = -EACCES;
50562+ goto out;
50563+ }
50564+
50565 error = -EISDIR;
50566 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
50567 goto out;
50568@@ -2955,7 +3082,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
50569 if (unlikely(error))
50570 goto out;
50571
50572- error = do_last(nd, &path, file, op, &opened, pathname);
50573+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
50574 while (unlikely(error > 0)) { /* trailing symlink */
50575 struct path link = path;
50576 void *cookie;
50577@@ -2973,7 +3100,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
50578 error = follow_link(&link, nd, &cookie);
50579 if (unlikely(error))
50580 break;
50581- error = do_last(nd, &path, file, op, &opened, pathname);
50582+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
50583 put_link(nd, &link, cookie);
50584 }
50585 out:
50586@@ -3073,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
50587 goto unlock;
50588
50589 error = -EEXIST;
50590- if (dentry->d_inode)
50591+ if (dentry->d_inode) {
50592+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
50593+ error = -ENOENT;
50594+ }
50595 goto fail;
50596+ }
50597 /*
50598 * Special case - lookup gave negative, but... we had foo/bar/
50599 * From the vfs_mknod() POV we just have a negative dentry -
50600@@ -3126,6 +3257,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
50601 }
50602 EXPORT_SYMBOL(user_path_create);
50603
50604+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
50605+{
50606+ struct filename *tmp = getname(pathname);
50607+ struct dentry *res;
50608+ if (IS_ERR(tmp))
50609+ return ERR_CAST(tmp);
50610+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
50611+ if (IS_ERR(res))
50612+ putname(tmp);
50613+ else
50614+ *to = tmp;
50615+ return res;
50616+}
50617+
50618 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
50619 {
50620 int error = may_create(dir, dentry);
50621@@ -3188,6 +3333,17 @@ retry:
50622
50623 if (!IS_POSIXACL(path.dentry->d_inode))
50624 mode &= ~current_umask();
50625+
50626+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
50627+ error = -EPERM;
50628+ goto out;
50629+ }
50630+
50631+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
50632+ error = -EACCES;
50633+ goto out;
50634+ }
50635+
50636 error = security_path_mknod(&path, dentry, mode, dev);
50637 if (error)
50638 goto out;
50639@@ -3204,6 +3360,8 @@ retry:
50640 break;
50641 }
50642 out:
50643+ if (!error)
50644+ gr_handle_create(dentry, path.mnt);
50645 done_path_create(&path, dentry);
50646 if (retry_estale(error, lookup_flags)) {
50647 lookup_flags |= LOOKUP_REVAL;
50648@@ -3256,9 +3414,16 @@ retry:
50649
50650 if (!IS_POSIXACL(path.dentry->d_inode))
50651 mode &= ~current_umask();
50652+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
50653+ error = -EACCES;
50654+ goto out;
50655+ }
50656 error = security_path_mkdir(&path, dentry, mode);
50657 if (!error)
50658 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
50659+ if (!error)
50660+ gr_handle_create(dentry, path.mnt);
50661+out:
50662 done_path_create(&path, dentry);
50663 if (retry_estale(error, lookup_flags)) {
50664 lookup_flags |= LOOKUP_REVAL;
50665@@ -3339,6 +3504,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
50666 struct filename *name;
50667 struct dentry *dentry;
50668 struct nameidata nd;
50669+ ino_t saved_ino = 0;
50670+ dev_t saved_dev = 0;
50671 unsigned int lookup_flags = 0;
50672 retry:
50673 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
50674@@ -3371,10 +3538,21 @@ retry:
50675 error = -ENOENT;
50676 goto exit3;
50677 }
50678+
50679+ saved_ino = dentry->d_inode->i_ino;
50680+ saved_dev = gr_get_dev_from_dentry(dentry);
50681+
50682+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
50683+ error = -EACCES;
50684+ goto exit3;
50685+ }
50686+
50687 error = security_path_rmdir(&nd.path, dentry);
50688 if (error)
50689 goto exit3;
50690 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
50691+ if (!error && (saved_dev || saved_ino))
50692+ gr_handle_delete(saved_ino, saved_dev);
50693 exit3:
50694 dput(dentry);
50695 exit2:
50696@@ -3440,6 +3618,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
50697 struct dentry *dentry;
50698 struct nameidata nd;
50699 struct inode *inode = NULL;
50700+ ino_t saved_ino = 0;
50701+ dev_t saved_dev = 0;
50702 unsigned int lookup_flags = 0;
50703 retry:
50704 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
50705@@ -3466,10 +3646,22 @@ retry:
50706 if (!inode)
50707 goto slashes;
50708 ihold(inode);
50709+
50710+ if (inode->i_nlink <= 1) {
50711+ saved_ino = inode->i_ino;
50712+ saved_dev = gr_get_dev_from_dentry(dentry);
50713+ }
50714+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
50715+ error = -EACCES;
50716+ goto exit2;
50717+ }
50718+
50719 error = security_path_unlink(&nd.path, dentry);
50720 if (error)
50721 goto exit2;
50722 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
50723+ if (!error && (saved_ino || saved_dev))
50724+ gr_handle_delete(saved_ino, saved_dev);
50725 exit2:
50726 dput(dentry);
50727 }
50728@@ -3547,9 +3739,17 @@ retry:
50729 if (IS_ERR(dentry))
50730 goto out_putname;
50731
50732+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
50733+ error = -EACCES;
50734+ goto out;
50735+ }
50736+
50737 error = security_path_symlink(&path, dentry, from->name);
50738 if (!error)
50739 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
50740+ if (!error)
50741+ gr_handle_create(dentry, path.mnt);
50742+out:
50743 done_path_create(&path, dentry);
50744 if (retry_estale(error, lookup_flags)) {
50745 lookup_flags |= LOOKUP_REVAL;
50746@@ -3623,6 +3823,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
50747 {
50748 struct dentry *new_dentry;
50749 struct path old_path, new_path;
50750+ struct filename *to = NULL;
50751 int how = 0;
50752 int error;
50753
50754@@ -3646,7 +3847,7 @@ retry:
50755 if (error)
50756 return error;
50757
50758- new_dentry = user_path_create(newdfd, newname, &new_path,
50759+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
50760 (how & LOOKUP_REVAL));
50761 error = PTR_ERR(new_dentry);
50762 if (IS_ERR(new_dentry))
50763@@ -3658,11 +3859,28 @@ retry:
50764 error = may_linkat(&old_path);
50765 if (unlikely(error))
50766 goto out_dput;
50767+
50768+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
50769+ old_path.dentry->d_inode,
50770+ old_path.dentry->d_inode->i_mode, to)) {
50771+ error = -EACCES;
50772+ goto out_dput;
50773+ }
50774+
50775+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
50776+ old_path.dentry, old_path.mnt, to)) {
50777+ error = -EACCES;
50778+ goto out_dput;
50779+ }
50780+
50781 error = security_path_link(old_path.dentry, &new_path, new_dentry);
50782 if (error)
50783 goto out_dput;
50784 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
50785+ if (!error)
50786+ gr_handle_create(new_dentry, new_path.mnt);
50787 out_dput:
50788+ putname(to);
50789 done_path_create(&new_path, new_dentry);
50790 if (retry_estale(error, how)) {
50791 how |= LOOKUP_REVAL;
50792@@ -3908,12 +4126,21 @@ retry:
50793 if (new_dentry == trap)
50794 goto exit5;
50795
50796+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
50797+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
50798+ to);
50799+ if (error)
50800+ goto exit5;
50801+
50802 error = security_path_rename(&oldnd.path, old_dentry,
50803 &newnd.path, new_dentry);
50804 if (error)
50805 goto exit5;
50806 error = vfs_rename(old_dir->d_inode, old_dentry,
50807 new_dir->d_inode, new_dentry);
50808+ if (!error)
50809+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
50810+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
50811 exit5:
50812 dput(new_dentry);
50813 exit4:
50814@@ -3945,6 +4172,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
50815
50816 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
50817 {
50818+ char tmpbuf[64];
50819+ const char *newlink;
50820 int len;
50821
50822 len = PTR_ERR(link);
50823@@ -3954,7 +4183,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
50824 len = strlen(link);
50825 if (len > (unsigned) buflen)
50826 len = buflen;
50827- if (copy_to_user(buffer, link, len))
50828+
50829+ if (len < sizeof(tmpbuf)) {
50830+ memcpy(tmpbuf, link, len);
50831+ newlink = tmpbuf;
50832+ } else
50833+ newlink = link;
50834+
50835+ if (copy_to_user(buffer, newlink, len))
50836 len = -EFAULT;
50837 out:
50838 return len;
50839diff --git a/fs/namespace.c b/fs/namespace.c
50840index 55605c5..f2908c8 100644
50841--- a/fs/namespace.c
50842+++ b/fs/namespace.c
50843@@ -1215,6 +1215,9 @@ static int do_umount(struct mount *mnt, int flags)
50844 if (!(sb->s_flags & MS_RDONLY))
50845 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
50846 up_write(&sb->s_umount);
50847+
50848+ gr_log_remount(mnt->mnt_devname, retval);
50849+
50850 return retval;
50851 }
50852
50853@@ -1234,9 +1237,20 @@ static int do_umount(struct mount *mnt, int flags)
50854 br_write_unlock(&vfsmount_lock);
50855 up_write(&namespace_sem);
50856 release_mounts(&umount_list);
50857+
50858+ gr_log_unmount(mnt->mnt_devname, retval);
50859+
50860 return retval;
50861 }
50862
50863+/*
50864+ * Is the caller allowed to modify his namespace?
50865+ */
50866+static inline bool may_mount(void)
50867+{
50868+ return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
50869+}
50870+
50871 /*
50872 * Now umount can handle mount points as well as block devices.
50873 * This is important for filesystems which use unnamed block devices.
50874@@ -1255,6 +1269,9 @@ SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
50875 if (flags & ~(MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW))
50876 return -EINVAL;
50877
50878+ if (!may_mount())
50879+ return -EPERM;
50880+
50881 if (!(flags & UMOUNT_NOFOLLOW))
50882 lookup_flags |= LOOKUP_FOLLOW;
50883
50884@@ -1268,10 +1285,6 @@ SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
50885 if (!check_mnt(mnt))
50886 goto dput_and_out;
50887
50888- retval = -EPERM;
50889- if (!ns_capable(mnt->mnt_ns->user_ns, CAP_SYS_ADMIN))
50890- goto dput_and_out;
50891-
50892 retval = do_umount(mnt, flags);
50893 dput_and_out:
50894 /* we mustn't call path_put() as that would clear mnt_expiry_mark */
50895@@ -1295,7 +1308,7 @@ SYSCALL_DEFINE1(oldumount, char __user *, name)
50896
50897 static int mount_is_safe(struct path *path)
50898 {
50899- if (ns_capable(real_mount(path->mnt)->mnt_ns->user_ns, CAP_SYS_ADMIN))
50900+ if (may_mount())
50901 return 0;
50902 return -EPERM;
50903 #ifdef notyet
50904@@ -1633,7 +1646,7 @@ static int do_change_type(struct path *path, int flag)
50905 int type;
50906 int err = 0;
50907
50908- if (!ns_capable(mnt->mnt_ns->user_ns, CAP_SYS_ADMIN))
50909+ if (!may_mount())
50910 return -EPERM;
50911
50912 if (path->dentry != path->mnt->mnt_root)
50913@@ -1797,7 +1810,7 @@ static int do_move_mount(struct path *path, const char *old_name)
50914 struct mount *p;
50915 struct mount *old;
50916 int err = 0;
50917- if (!ns_capable(real_mount(path->mnt)->mnt_ns->user_ns, CAP_SYS_ADMIN))
50918+ if (!may_mount())
50919 return -EPERM;
50920 if (!old_name || !*old_name)
50921 return -EINVAL;
50922@@ -1933,16 +1946,14 @@ static int do_new_mount(struct path *path, const char *fstype, int flags,
50923 int mnt_flags, const char *name, void *data)
50924 {
50925 struct file_system_type *type;
50926- struct user_namespace *user_ns;
50927+ struct user_namespace *user_ns = current->nsproxy->mnt_ns->user_ns;
50928 struct vfsmount *mnt;
50929 int err;
50930
50931 if (!fstype)
50932 return -EINVAL;
50933
50934- /* we need capabilities... */
50935- user_ns = real_mount(path->mnt)->mnt_ns->user_ns;
50936- if (!ns_capable(user_ns, CAP_SYS_ADMIN))
50937+ if (!may_mount())
50938 return -EPERM;
50939
50940 type = get_fs_type(fstype);
50941@@ -2282,6 +2293,16 @@ long do_mount(const char *dev_name, const char *dir_name,
50942 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
50943 MS_STRICTATIME);
50944
50945+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
50946+ retval = -EPERM;
50947+ goto dput_out;
50948+ }
50949+
50950+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
50951+ retval = -EPERM;
50952+ goto dput_out;
50953+ }
50954+
50955 if (flags & MS_REMOUNT)
50956 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
50957 data_page);
50958@@ -2296,6 +2317,9 @@ long do_mount(const char *dev_name, const char *dir_name,
50959 dev_name, data_page);
50960 dput_out:
50961 path_put(&path);
50962+
50963+ gr_log_mount(dev_name, dir_name, retval);
50964+
50965 return retval;
50966 }
50967
50968@@ -2567,7 +2591,7 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
50969 struct mount *new_mnt, *root_mnt;
50970 int error;
50971
50972- if (!ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN))
50973+ if (!may_mount())
50974 return -EPERM;
50975
50976 error = user_path_dir(new_root, &new);
50977@@ -2582,6 +2606,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
50978 if (error)
50979 goto out2;
50980
50981+ if (gr_handle_chroot_pivot()) {
50982+ error = -EPERM;
50983+ goto out2;
50984+ }
50985+
50986 get_fs_root(current->fs, &root);
50987 error = lock_mount(&old);
50988 if (error)
50989@@ -2785,7 +2814,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
50990 !nsown_capable(CAP_SYS_ADMIN))
50991 return -EPERM;
50992
50993- if (fs->users != 1)
50994+ if (atomic_read(&fs->users) != 1)
50995 return -EINVAL;
50996
50997 get_mnt_ns(mnt_ns);
50998diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
50999index ebeb94c..ff35337 100644
51000--- a/fs/nfs/inode.c
51001+++ b/fs/nfs/inode.c
51002@@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
51003 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
51004 }
51005
51006-static atomic_long_t nfs_attr_generation_counter;
51007+static atomic_long_unchecked_t nfs_attr_generation_counter;
51008
51009 static unsigned long nfs_read_attr_generation_counter(void)
51010 {
51011- return atomic_long_read(&nfs_attr_generation_counter);
51012+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
51013 }
51014
51015 unsigned long nfs_inc_attr_generation_counter(void)
51016 {
51017- return atomic_long_inc_return(&nfs_attr_generation_counter);
51018+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
51019 }
51020
51021 void nfs_fattr_init(struct nfs_fattr *fattr)
51022diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
51023index d586117..143d568 100644
51024--- a/fs/nfsd/vfs.c
51025+++ b/fs/nfsd/vfs.c
51026@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
51027 } else {
51028 oldfs = get_fs();
51029 set_fs(KERNEL_DS);
51030- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
51031+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
51032 set_fs(oldfs);
51033 }
51034
51035@@ -1025,7 +1025,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
51036
51037 /* Write the data. */
51038 oldfs = get_fs(); set_fs(KERNEL_DS);
51039- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
51040+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
51041 set_fs(oldfs);
51042 if (host_err < 0)
51043 goto out_nfserr;
51044@@ -1571,7 +1571,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
51045 */
51046
51047 oldfs = get_fs(); set_fs(KERNEL_DS);
51048- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
51049+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
51050 set_fs(oldfs);
51051
51052 if (host_err < 0)
51053diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
51054index 9ff4a5e..deb1f0f 100644
51055--- a/fs/notify/fanotify/fanotify_user.c
51056+++ b/fs/notify/fanotify/fanotify_user.c
51057@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
51058
51059 fd = fanotify_event_metadata.fd;
51060 ret = -EFAULT;
51061- if (copy_to_user(buf, &fanotify_event_metadata,
51062- fanotify_event_metadata.event_len))
51063+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
51064+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
51065 goto out_close_fd;
51066
51067 ret = prepare_for_access_response(group, event, fd);
51068diff --git a/fs/notify/notification.c b/fs/notify/notification.c
51069index 7b51b05..5ea5ef6 100644
51070--- a/fs/notify/notification.c
51071+++ b/fs/notify/notification.c
51072@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
51073 * get set to 0 so it will never get 'freed'
51074 */
51075 static struct fsnotify_event *q_overflow_event;
51076-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51077+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51078
51079 /**
51080 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
51081@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51082 */
51083 u32 fsnotify_get_cookie(void)
51084 {
51085- return atomic_inc_return(&fsnotify_sync_cookie);
51086+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
51087 }
51088 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
51089
51090diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
51091index 99e3610..02c1068 100644
51092--- a/fs/ntfs/dir.c
51093+++ b/fs/ntfs/dir.c
51094@@ -1329,7 +1329,7 @@ find_next_index_buffer:
51095 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
51096 ~(s64)(ndir->itype.index.block_size - 1)));
51097 /* Bounds checks. */
51098- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
51099+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
51100 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
51101 "inode 0x%lx or driver bug.", vdir->i_ino);
51102 goto err_out;
51103diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
51104index 5b2d4f0..c6de396 100644
51105--- a/fs/ntfs/file.c
51106+++ b/fs/ntfs/file.c
51107@@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
51108 #endif /* NTFS_RW */
51109 };
51110
51111-const struct file_operations ntfs_empty_file_ops = {};
51112+const struct file_operations ntfs_empty_file_ops __read_only;
51113
51114-const struct inode_operations ntfs_empty_inode_ops = {};
51115+const struct inode_operations ntfs_empty_inode_ops __read_only;
51116diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
51117index a9f78c7..ed8a381 100644
51118--- a/fs/ocfs2/localalloc.c
51119+++ b/fs/ocfs2/localalloc.c
51120@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
51121 goto bail;
51122 }
51123
51124- atomic_inc(&osb->alloc_stats.moves);
51125+ atomic_inc_unchecked(&osb->alloc_stats.moves);
51126
51127 bail:
51128 if (handle)
51129diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
51130index d355e6e..578d905 100644
51131--- a/fs/ocfs2/ocfs2.h
51132+++ b/fs/ocfs2/ocfs2.h
51133@@ -235,11 +235,11 @@ enum ocfs2_vol_state
51134
51135 struct ocfs2_alloc_stats
51136 {
51137- atomic_t moves;
51138- atomic_t local_data;
51139- atomic_t bitmap_data;
51140- atomic_t bg_allocs;
51141- atomic_t bg_extends;
51142+ atomic_unchecked_t moves;
51143+ atomic_unchecked_t local_data;
51144+ atomic_unchecked_t bitmap_data;
51145+ atomic_unchecked_t bg_allocs;
51146+ atomic_unchecked_t bg_extends;
51147 };
51148
51149 enum ocfs2_local_alloc_state
51150diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
51151index f169da4..9112253 100644
51152--- a/fs/ocfs2/suballoc.c
51153+++ b/fs/ocfs2/suballoc.c
51154@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
51155 mlog_errno(status);
51156 goto bail;
51157 }
51158- atomic_inc(&osb->alloc_stats.bg_extends);
51159+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
51160
51161 /* You should never ask for this much metadata */
51162 BUG_ON(bits_wanted >
51163@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
51164 mlog_errno(status);
51165 goto bail;
51166 }
51167- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51168+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51169
51170 *suballoc_loc = res.sr_bg_blkno;
51171 *suballoc_bit_start = res.sr_bit_offset;
51172@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
51173 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
51174 res->sr_bits);
51175
51176- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51177+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51178
51179 BUG_ON(res->sr_bits != 1);
51180
51181@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
51182 mlog_errno(status);
51183 goto bail;
51184 }
51185- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51186+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51187
51188 BUG_ON(res.sr_bits != 1);
51189
51190@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
51191 cluster_start,
51192 num_clusters);
51193 if (!status)
51194- atomic_inc(&osb->alloc_stats.local_data);
51195+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
51196 } else {
51197 if (min_clusters > (osb->bitmap_cpg - 1)) {
51198 /* The only paths asking for contiguousness
51199@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
51200 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
51201 res.sr_bg_blkno,
51202 res.sr_bit_offset);
51203- atomic_inc(&osb->alloc_stats.bitmap_data);
51204+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
51205 *num_clusters = res.sr_bits;
51206 }
51207 }
51208diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
51209index 0e91ec2..f4b3fc6 100644
51210--- a/fs/ocfs2/super.c
51211+++ b/fs/ocfs2/super.c
51212@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
51213 "%10s => GlobalAllocs: %d LocalAllocs: %d "
51214 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
51215 "Stats",
51216- atomic_read(&osb->alloc_stats.bitmap_data),
51217- atomic_read(&osb->alloc_stats.local_data),
51218- atomic_read(&osb->alloc_stats.bg_allocs),
51219- atomic_read(&osb->alloc_stats.moves),
51220- atomic_read(&osb->alloc_stats.bg_extends));
51221+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
51222+ atomic_read_unchecked(&osb->alloc_stats.local_data),
51223+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
51224+ atomic_read_unchecked(&osb->alloc_stats.moves),
51225+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
51226
51227 out += snprintf(buf + out, len - out,
51228 "%10s => State: %u Descriptor: %llu Size: %u bits "
51229@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
51230 spin_lock_init(&osb->osb_xattr_lock);
51231 ocfs2_init_steal_slots(osb);
51232
51233- atomic_set(&osb->alloc_stats.moves, 0);
51234- atomic_set(&osb->alloc_stats.local_data, 0);
51235- atomic_set(&osb->alloc_stats.bitmap_data, 0);
51236- atomic_set(&osb->alloc_stats.bg_allocs, 0);
51237- atomic_set(&osb->alloc_stats.bg_extends, 0);
51238+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
51239+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
51240+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
51241+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
51242+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
51243
51244 /* Copy the blockcheck stats from the superblock probe */
51245 osb->osb_ecc_stats = *stats;
51246diff --git a/fs/open.c b/fs/open.c
51247index 9b33c0c..2ffcca2 100644
51248--- a/fs/open.c
51249+++ b/fs/open.c
51250@@ -31,6 +31,8 @@
51251 #include <linux/ima.h>
51252 #include <linux/dnotify.h>
51253
51254+#define CREATE_TRACE_POINTS
51255+#include <trace/events/fs.h>
51256 #include "internal.h"
51257
51258 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
51259@@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
51260 error = locks_verify_truncate(inode, NULL, length);
51261 if (!error)
51262 error = security_path_truncate(path);
51263+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
51264+ error = -EACCES;
51265 if (!error)
51266 error = do_truncate(path->dentry, length, 0, NULL);
51267
51268@@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
51269 error = locks_verify_truncate(inode, f.file, length);
51270 if (!error)
51271 error = security_path_truncate(&f.file->f_path);
51272+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
51273+ error = -EACCES;
51274 if (!error)
51275 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
51276 sb_end_write(inode->i_sb);
51277@@ -373,6 +379,9 @@ retry:
51278 if (__mnt_is_readonly(path.mnt))
51279 res = -EROFS;
51280
51281+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
51282+ res = -EACCES;
51283+
51284 out_path_release:
51285 path_put(&path);
51286 if (retry_estale(res, lookup_flags)) {
51287@@ -404,6 +413,8 @@ retry:
51288 if (error)
51289 goto dput_and_out;
51290
51291+ gr_log_chdir(path.dentry, path.mnt);
51292+
51293 set_fs_pwd(current->fs, &path);
51294
51295 dput_and_out:
51296@@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
51297 goto out_putf;
51298
51299 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
51300+
51301+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
51302+ error = -EPERM;
51303+
51304+ if (!error)
51305+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
51306+
51307 if (!error)
51308 set_fs_pwd(current->fs, &f.file->f_path);
51309 out_putf:
51310@@ -462,7 +480,13 @@ retry:
51311 if (error)
51312 goto dput_and_out;
51313
51314+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
51315+ goto dput_and_out;
51316+
51317 set_fs_root(current->fs, &path);
51318+
51319+ gr_handle_chroot_chdir(&path);
51320+
51321 error = 0;
51322 dput_and_out:
51323 path_put(&path);
51324@@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
51325 if (error)
51326 return error;
51327 mutex_lock(&inode->i_mutex);
51328+
51329+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
51330+ error = -EACCES;
51331+ goto out_unlock;
51332+ }
51333+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
51334+ error = -EACCES;
51335+ goto out_unlock;
51336+ }
51337+
51338 error = security_path_chmod(path, mode);
51339 if (error)
51340 goto out_unlock;
51341@@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
51342 uid = make_kuid(current_user_ns(), user);
51343 gid = make_kgid(current_user_ns(), group);
51344
51345+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
51346+ return -EACCES;
51347+
51348 newattrs.ia_valid = ATTR_CTIME;
51349 if (user != (uid_t) -1) {
51350 if (!uid_valid(uid))
51351@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
51352 } else {
51353 fsnotify_open(f);
51354 fd_install(fd, f);
51355+ trace_do_sys_open(tmp->name, flags, mode);
51356 }
51357 }
51358 putname(tmp);
51359diff --git a/fs/pipe.c b/fs/pipe.c
51360index bd3479d..fb92c4d 100644
51361--- a/fs/pipe.c
51362+++ b/fs/pipe.c
51363@@ -438,9 +438,9 @@ redo:
51364 }
51365 if (bufs) /* More to do? */
51366 continue;
51367- if (!pipe->writers)
51368+ if (!atomic_read(&pipe->writers))
51369 break;
51370- if (!pipe->waiting_writers) {
51371+ if (!atomic_read(&pipe->waiting_writers)) {
51372 /* syscall merging: Usually we must not sleep
51373 * if O_NONBLOCK is set, or if we got some data.
51374 * But if a writer sleeps in kernel space, then
51375@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
51376 mutex_lock(&inode->i_mutex);
51377 pipe = inode->i_pipe;
51378
51379- if (!pipe->readers) {
51380+ if (!atomic_read(&pipe->readers)) {
51381 send_sig(SIGPIPE, current, 0);
51382 ret = -EPIPE;
51383 goto out;
51384@@ -553,7 +553,7 @@ redo1:
51385 for (;;) {
51386 int bufs;
51387
51388- if (!pipe->readers) {
51389+ if (!atomic_read(&pipe->readers)) {
51390 send_sig(SIGPIPE, current, 0);
51391 if (!ret)
51392 ret = -EPIPE;
51393@@ -644,9 +644,9 @@ redo2:
51394 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
51395 do_wakeup = 0;
51396 }
51397- pipe->waiting_writers++;
51398+ atomic_inc(&pipe->waiting_writers);
51399 pipe_wait(pipe);
51400- pipe->waiting_writers--;
51401+ atomic_dec(&pipe->waiting_writers);
51402 }
51403 out:
51404 mutex_unlock(&inode->i_mutex);
51405@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
51406 mask = 0;
51407 if (filp->f_mode & FMODE_READ) {
51408 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
51409- if (!pipe->writers && filp->f_version != pipe->w_counter)
51410+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
51411 mask |= POLLHUP;
51412 }
51413
51414@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
51415 * Most Unices do not set POLLERR for FIFOs but on Linux they
51416 * behave exactly like pipes for poll().
51417 */
51418- if (!pipe->readers)
51419+ if (!atomic_read(&pipe->readers))
51420 mask |= POLLERR;
51421 }
51422
51423@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
51424
51425 mutex_lock(&inode->i_mutex);
51426 pipe = inode->i_pipe;
51427- pipe->readers -= decr;
51428- pipe->writers -= decw;
51429+ atomic_sub(decr, &pipe->readers);
51430+ atomic_sub(decw, &pipe->writers);
51431
51432- if (!pipe->readers && !pipe->writers) {
51433+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
51434 free_pipe_info(inode);
51435 } else {
51436 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
51437@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
51438
51439 if (inode->i_pipe) {
51440 ret = 0;
51441- inode->i_pipe->readers++;
51442+ atomic_inc(&inode->i_pipe->readers);
51443 }
51444
51445 mutex_unlock(&inode->i_mutex);
51446@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
51447
51448 if (inode->i_pipe) {
51449 ret = 0;
51450- inode->i_pipe->writers++;
51451+ atomic_inc(&inode->i_pipe->writers);
51452 }
51453
51454 mutex_unlock(&inode->i_mutex);
51455@@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
51456 if (inode->i_pipe) {
51457 ret = 0;
51458 if (filp->f_mode & FMODE_READ)
51459- inode->i_pipe->readers++;
51460+ atomic_inc(&inode->i_pipe->readers);
51461 if (filp->f_mode & FMODE_WRITE)
51462- inode->i_pipe->writers++;
51463+ atomic_inc(&inode->i_pipe->writers);
51464 }
51465
51466 mutex_unlock(&inode->i_mutex);
51467@@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
51468 inode->i_pipe = NULL;
51469 }
51470
51471-static struct vfsmount *pipe_mnt __read_mostly;
51472+struct vfsmount *pipe_mnt __read_mostly;
51473
51474 /*
51475 * pipefs_dname() is called from d_path().
51476@@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
51477 goto fail_iput;
51478 inode->i_pipe = pipe;
51479
51480- pipe->readers = pipe->writers = 1;
51481+ atomic_set(&pipe->readers, 1);
51482+ atomic_set(&pipe->writers, 1);
51483 inode->i_fop = &rdwr_pipefifo_fops;
51484
51485 /*
51486diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
51487index 15af622..0e9f4467 100644
51488--- a/fs/proc/Kconfig
51489+++ b/fs/proc/Kconfig
51490@@ -30,12 +30,12 @@ config PROC_FS
51491
51492 config PROC_KCORE
51493 bool "/proc/kcore support" if !ARM
51494- depends on PROC_FS && MMU
51495+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
51496
51497 config PROC_VMCORE
51498 bool "/proc/vmcore support"
51499- depends on PROC_FS && CRASH_DUMP
51500- default y
51501+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
51502+ default n
51503 help
51504 Exports the dump image of crashed kernel in ELF format.
51505
51506@@ -59,8 +59,8 @@ config PROC_SYSCTL
51507 limited in memory.
51508
51509 config PROC_PAGE_MONITOR
51510- default y
51511- depends on PROC_FS && MMU
51512+ default n
51513+ depends on PROC_FS && MMU && !GRKERNSEC
51514 bool "Enable /proc page monitoring" if EXPERT
51515 help
51516 Various /proc files exist to monitor process memory utilization:
51517diff --git a/fs/proc/array.c b/fs/proc/array.c
51518index 6a91e6f..e54dbc14 100644
51519--- a/fs/proc/array.c
51520+++ b/fs/proc/array.c
51521@@ -60,6 +60,7 @@
51522 #include <linux/tty.h>
51523 #include <linux/string.h>
51524 #include <linux/mman.h>
51525+#include <linux/grsecurity.h>
51526 #include <linux/proc_fs.h>
51527 #include <linux/ioport.h>
51528 #include <linux/uaccess.h>
51529@@ -362,6 +363,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
51530 seq_putc(m, '\n');
51531 }
51532
51533+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
51534+static inline void task_pax(struct seq_file *m, struct task_struct *p)
51535+{
51536+ if (p->mm)
51537+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
51538+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
51539+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
51540+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
51541+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
51542+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
51543+ else
51544+ seq_printf(m, "PaX:\t-----\n");
51545+}
51546+#endif
51547+
51548 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51549 struct pid *pid, struct task_struct *task)
51550 {
51551@@ -380,9 +396,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51552 task_cpus_allowed(m, task);
51553 cpuset_task_status_allowed(m, task);
51554 task_context_switch_counts(m, task);
51555+
51556+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
51557+ task_pax(m, task);
51558+#endif
51559+
51560+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
51561+ task_grsec_rbac(m, task);
51562+#endif
51563+
51564 return 0;
51565 }
51566
51567+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51568+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51569+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
51570+ _mm->pax_flags & MF_PAX_SEGMEXEC))
51571+#endif
51572+
51573 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51574 struct pid *pid, struct task_struct *task, int whole)
51575 {
51576@@ -404,6 +435,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51577 char tcomm[sizeof(task->comm)];
51578 unsigned long flags;
51579
51580+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51581+ if (current->exec_id != m->exec_id) {
51582+ gr_log_badprocpid("stat");
51583+ return 0;
51584+ }
51585+#endif
51586+
51587 state = *get_task_state(task);
51588 vsize = eip = esp = 0;
51589 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
51590@@ -475,6 +513,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51591 gtime = task->gtime;
51592 }
51593
51594+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51595+ if (PAX_RAND_FLAGS(mm)) {
51596+ eip = 0;
51597+ esp = 0;
51598+ wchan = 0;
51599+ }
51600+#endif
51601+#ifdef CONFIG_GRKERNSEC_HIDESYM
51602+ wchan = 0;
51603+ eip =0;
51604+ esp =0;
51605+#endif
51606+
51607 /* scale priority and nice values from timeslices to -20..20 */
51608 /* to make it look like a "normal" Unix priority/nice value */
51609 priority = task_prio(task);
51610@@ -511,9 +562,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51611 seq_put_decimal_ull(m, ' ', vsize);
51612 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
51613 seq_put_decimal_ull(m, ' ', rsslim);
51614+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51615+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
51616+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
51617+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
51618+#else
51619 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
51620 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
51621 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
51622+#endif
51623 seq_put_decimal_ull(m, ' ', esp);
51624 seq_put_decimal_ull(m, ' ', eip);
51625 /* The signal information here is obsolete.
51626@@ -535,7 +592,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51627 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
51628 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
51629
51630- if (mm && permitted) {
51631+ if (mm && permitted
51632+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51633+ && !PAX_RAND_FLAGS(mm)
51634+#endif
51635+ ) {
51636 seq_put_decimal_ull(m, ' ', mm->start_data);
51637 seq_put_decimal_ull(m, ' ', mm->end_data);
51638 seq_put_decimal_ull(m, ' ', mm->start_brk);
51639@@ -573,8 +634,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51640 struct pid *pid, struct task_struct *task)
51641 {
51642 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
51643- struct mm_struct *mm = get_task_mm(task);
51644+ struct mm_struct *mm;
51645
51646+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51647+ if (current->exec_id != m->exec_id) {
51648+ gr_log_badprocpid("statm");
51649+ return 0;
51650+ }
51651+#endif
51652+ mm = get_task_mm(task);
51653 if (mm) {
51654 size = task_statm(mm, &shared, &text, &data, &resident);
51655 mmput(mm);
51656@@ -597,6 +665,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51657 return 0;
51658 }
51659
51660+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51661+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
51662+{
51663+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
51664+}
51665+#endif
51666+
51667 #ifdef CONFIG_CHECKPOINT_RESTORE
51668 static struct pid *
51669 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
51670diff --git a/fs/proc/base.c b/fs/proc/base.c
51671index 9b43ff77..3d6a99f 100644
51672--- a/fs/proc/base.c
51673+++ b/fs/proc/base.c
51674@@ -111,6 +111,14 @@ struct pid_entry {
51675 union proc_op op;
51676 };
51677
51678+struct getdents_callback {
51679+ struct linux_dirent __user * current_dir;
51680+ struct linux_dirent __user * previous;
51681+ struct file * file;
51682+ int count;
51683+ int error;
51684+};
51685+
51686 #define NOD(NAME, MODE, IOP, FOP, OP) { \
51687 .name = (NAME), \
51688 .len = sizeof(NAME) - 1, \
51689@@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
51690 if (!mm->arg_end)
51691 goto out_mm; /* Shh! No looking before we're done */
51692
51693+ if (gr_acl_handle_procpidmem(task))
51694+ goto out_mm;
51695+
51696 len = mm->arg_end - mm->arg_start;
51697
51698 if (len > PAGE_SIZE)
51699@@ -235,12 +246,28 @@ out:
51700 return res;
51701 }
51702
51703+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51704+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51705+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
51706+ _mm->pax_flags & MF_PAX_SEGMEXEC))
51707+#endif
51708+
51709 static int proc_pid_auxv(struct task_struct *task, char *buffer)
51710 {
51711 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
51712 int res = PTR_ERR(mm);
51713 if (mm && !IS_ERR(mm)) {
51714 unsigned int nwords = 0;
51715+
51716+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51717+ /* allow if we're currently ptracing this task */
51718+ if (PAX_RAND_FLAGS(mm) &&
51719+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
51720+ mmput(mm);
51721+ return 0;
51722+ }
51723+#endif
51724+
51725 do {
51726 nwords += 2;
51727 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
51728@@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
51729 }
51730
51731
51732-#ifdef CONFIG_KALLSYMS
51733+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51734 /*
51735 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
51736 * Returns the resolved symbol. If that fails, simply return the address.
51737@@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
51738 mutex_unlock(&task->signal->cred_guard_mutex);
51739 }
51740
51741-#ifdef CONFIG_STACKTRACE
51742+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51743
51744 #define MAX_STACK_TRACE_DEPTH 64
51745
51746@@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
51747 return count;
51748 }
51749
51750-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51751+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51752 static int proc_pid_syscall(struct task_struct *task, char *buffer)
51753 {
51754 long nr;
51755@@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
51756 /************************************************************************/
51757
51758 /* permission checks */
51759-static int proc_fd_access_allowed(struct inode *inode)
51760+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
51761 {
51762 struct task_struct *task;
51763 int allowed = 0;
51764@@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
51765 */
51766 task = get_proc_task(inode);
51767 if (task) {
51768- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
51769+ if (log)
51770+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
51771+ else
51772+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
51773 put_task_struct(task);
51774 }
51775 return allowed;
51776@@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
51777 struct task_struct *task,
51778 int hide_pid_min)
51779 {
51780+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51781+ return false;
51782+
51783+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51784+ rcu_read_lock();
51785+ {
51786+ const struct cred *tmpcred = current_cred();
51787+ const struct cred *cred = __task_cred(task);
51788+
51789+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
51790+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51791+ || in_group_p(grsec_proc_gid)
51792+#endif
51793+ ) {
51794+ rcu_read_unlock();
51795+ return true;
51796+ }
51797+ }
51798+ rcu_read_unlock();
51799+
51800+ if (!pid->hide_pid)
51801+ return false;
51802+#endif
51803+
51804 if (pid->hide_pid < hide_pid_min)
51805 return true;
51806 if (in_group_p(pid->pid_gid))
51807 return true;
51808+
51809 return ptrace_may_access(task, PTRACE_MODE_READ);
51810 }
51811
51812@@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
51813 put_task_struct(task);
51814
51815 if (!has_perms) {
51816+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51817+ {
51818+#else
51819 if (pid->hide_pid == 2) {
51820+#endif
51821 /*
51822 * Let's make getdents(), stat(), and open()
51823 * consistent with each other. If a process
51824@@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
51825 if (!task)
51826 return -ESRCH;
51827
51828+ if (gr_acl_handle_procpidmem(task)) {
51829+ put_task_struct(task);
51830+ return -EPERM;
51831+ }
51832+
51833 mm = mm_access(task, mode);
51834 put_task_struct(task);
51835
51836@@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
51837
51838 file->private_data = mm;
51839
51840+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51841+ file->f_version = current->exec_id;
51842+#endif
51843+
51844 return 0;
51845 }
51846
51847@@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
51848 ssize_t copied;
51849 char *page;
51850
51851+#ifdef CONFIG_GRKERNSEC
51852+ if (write)
51853+ return -EPERM;
51854+#endif
51855+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51856+ if (file->f_version != current->exec_id) {
51857+ gr_log_badprocpid("mem");
51858+ return 0;
51859+ }
51860+#endif
51861+
51862 if (!mm)
51863 return 0;
51864
51865@@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
51866 if (!mm)
51867 return 0;
51868
51869+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51870+ if (file->f_version != current->exec_id) {
51871+ gr_log_badprocpid("environ");
51872+ return 0;
51873+ }
51874+#endif
51875+
51876 page = (char *)__get_free_page(GFP_TEMPORARY);
51877 if (!page)
51878 return -ENOMEM;
51879@@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
51880 int error = -EACCES;
51881
51882 /* Are we allowed to snoop on the tasks file descriptors? */
51883- if (!proc_fd_access_allowed(inode))
51884+ if (!proc_fd_access_allowed(inode, 0))
51885 goto out;
51886
51887 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51888@@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
51889 struct path path;
51890
51891 /* Are we allowed to snoop on the tasks file descriptors? */
51892- if (!proc_fd_access_allowed(inode))
51893- goto out;
51894+ /* logging this is needed for learning on chromium to work properly,
51895+ but we don't want to flood the logs from 'ps' which does a readlink
51896+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
51897+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
51898+ */
51899+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
51900+ if (!proc_fd_access_allowed(inode,0))
51901+ goto out;
51902+ } else {
51903+ if (!proc_fd_access_allowed(inode,1))
51904+ goto out;
51905+ }
51906
51907 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51908 if (error)
51909@@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
51910 rcu_read_lock();
51911 cred = __task_cred(task);
51912 inode->i_uid = cred->euid;
51913+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51914+ inode->i_gid = grsec_proc_gid;
51915+#else
51916 inode->i_gid = cred->egid;
51917+#endif
51918 rcu_read_unlock();
51919 }
51920 security_task_to_inode(task, inode);
51921@@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
51922 return -ENOENT;
51923 }
51924 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51925+#ifdef CONFIG_GRKERNSEC_PROC_USER
51926+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51927+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51928+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51929+#endif
51930 task_dumpable(task)) {
51931 cred = __task_cred(task);
51932 stat->uid = cred->euid;
51933+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51934+ stat->gid = grsec_proc_gid;
51935+#else
51936 stat->gid = cred->egid;
51937+#endif
51938 }
51939 }
51940 rcu_read_unlock();
51941@@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
51942
51943 if (task) {
51944 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51945+#ifdef CONFIG_GRKERNSEC_PROC_USER
51946+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51947+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51948+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51949+#endif
51950 task_dumpable(task)) {
51951 rcu_read_lock();
51952 cred = __task_cred(task);
51953 inode->i_uid = cred->euid;
51954+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51955+ inode->i_gid = grsec_proc_gid;
51956+#else
51957 inode->i_gid = cred->egid;
51958+#endif
51959 rcu_read_unlock();
51960 } else {
51961 inode->i_uid = GLOBAL_ROOT_UID;
51962@@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
51963 if (!task)
51964 goto out_no_task;
51965
51966+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51967+ goto out;
51968+
51969 /*
51970 * Yes, it does not scale. And it should not. Don't add
51971 * new entries into /proc/<tgid>/ without very good reasons.
51972@@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
51973 if (!task)
51974 goto out_no_task;
51975
51976+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51977+ goto out;
51978+
51979 ret = 0;
51980 i = filp->f_pos;
51981 switch (i) {
51982@@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
51983 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
51984 #endif
51985 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51986-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51987+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51988 INF("syscall", S_IRUGO, proc_pid_syscall),
51989 #endif
51990 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51991@@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
51992 #ifdef CONFIG_SECURITY
51993 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51994 #endif
51995-#ifdef CONFIG_KALLSYMS
51996+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51997 INF("wchan", S_IRUGO, proc_pid_wchan),
51998 #endif
51999-#ifdef CONFIG_STACKTRACE
52000+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52001 ONE("stack", S_IRUGO, proc_pid_stack),
52002 #endif
52003 #ifdef CONFIG_SCHEDSTATS
52004@@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
52005 #ifdef CONFIG_HARDWALL
52006 INF("hardwall", S_IRUGO, proc_pid_hardwall),
52007 #endif
52008+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52009+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
52010+#endif
52011 #ifdef CONFIG_USER_NS
52012 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
52013 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
52014@@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
52015 if (!inode)
52016 goto out;
52017
52018+#ifdef CONFIG_GRKERNSEC_PROC_USER
52019+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
52020+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52021+ inode->i_gid = grsec_proc_gid;
52022+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
52023+#else
52024 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
52025+#endif
52026 inode->i_op = &proc_tgid_base_inode_operations;
52027 inode->i_fop = &proc_tgid_base_operations;
52028 inode->i_flags|=S_IMMUTABLE;
52029@@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
52030 if (!task)
52031 goto out;
52032
52033+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
52034+ goto out_put_task;
52035+
52036 result = proc_pid_instantiate(dir, dentry, task, NULL);
52037+out_put_task:
52038 put_task_struct(task);
52039 out:
52040 return result;
52041@@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
52042 static int fake_filldir(void *buf, const char *name, int namelen,
52043 loff_t offset, u64 ino, unsigned d_type)
52044 {
52045+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
52046+ __buf->error = -EINVAL;
52047 return 0;
52048 }
52049
52050@@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
52051 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
52052 #endif
52053 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
52054-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
52055+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52056 INF("syscall", S_IRUGO, proc_pid_syscall),
52057 #endif
52058 INF("cmdline", S_IRUGO, proc_pid_cmdline),
52059@@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
52060 #ifdef CONFIG_SECURITY
52061 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
52062 #endif
52063-#ifdef CONFIG_KALLSYMS
52064+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52065 INF("wchan", S_IRUGO, proc_pid_wchan),
52066 #endif
52067-#ifdef CONFIG_STACKTRACE
52068+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52069 ONE("stack", S_IRUGO, proc_pid_stack),
52070 #endif
52071 #ifdef CONFIG_SCHEDSTATS
52072diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
52073index 82676e3..5f8518a 100644
52074--- a/fs/proc/cmdline.c
52075+++ b/fs/proc/cmdline.c
52076@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
52077
52078 static int __init proc_cmdline_init(void)
52079 {
52080+#ifdef CONFIG_GRKERNSEC_PROC_ADD
52081+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
52082+#else
52083 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
52084+#endif
52085 return 0;
52086 }
52087 module_init(proc_cmdline_init);
52088diff --git a/fs/proc/devices.c b/fs/proc/devices.c
52089index b143471..bb105e5 100644
52090--- a/fs/proc/devices.c
52091+++ b/fs/proc/devices.c
52092@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
52093
52094 static int __init proc_devices_init(void)
52095 {
52096+#ifdef CONFIG_GRKERNSEC_PROC_ADD
52097+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
52098+#else
52099 proc_create("devices", 0, NULL, &proc_devinfo_operations);
52100+#endif
52101 return 0;
52102 }
52103 module_init(proc_devices_init);
52104diff --git a/fs/proc/fd.c b/fs/proc/fd.c
52105index d7a4a28..0201742 100644
52106--- a/fs/proc/fd.c
52107+++ b/fs/proc/fd.c
52108@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
52109 if (!task)
52110 return -ENOENT;
52111
52112- files = get_files_struct(task);
52113+ if (!gr_acl_handle_procpidmem(task))
52114+ files = get_files_struct(task);
52115 put_task_struct(task);
52116
52117 if (files) {
52118@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
52119 */
52120 int proc_fd_permission(struct inode *inode, int mask)
52121 {
52122+ struct task_struct *task;
52123 int rv = generic_permission(inode, mask);
52124- if (rv == 0)
52125- return 0;
52126+
52127 if (task_pid(current) == proc_pid(inode))
52128 rv = 0;
52129+
52130+ task = get_proc_task(inode);
52131+ if (task == NULL)
52132+ return rv;
52133+
52134+ if (gr_acl_handle_procpidmem(task))
52135+ rv = -EACCES;
52136+
52137+ put_task_struct(task);
52138+
52139 return rv;
52140 }
52141
52142diff --git a/fs/proc/inode.c b/fs/proc/inode.c
52143index 439ae688..c21ac36 100644
52144--- a/fs/proc/inode.c
52145+++ b/fs/proc/inode.c
52146@@ -21,11 +21,17 @@
52147 #include <linux/seq_file.h>
52148 #include <linux/slab.h>
52149 #include <linux/mount.h>
52150+#include <linux/grsecurity.h>
52151
52152 #include <asm/uaccess.h>
52153
52154 #include "internal.h"
52155
52156+#ifdef CONFIG_PROC_SYSCTL
52157+extern const struct inode_operations proc_sys_inode_operations;
52158+extern const struct inode_operations proc_sys_dir_operations;
52159+#endif
52160+
52161 static void proc_evict_inode(struct inode *inode)
52162 {
52163 struct proc_dir_entry *de;
52164@@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
52165 ns = PROC_I(inode)->ns;
52166 if (ns_ops && ns)
52167 ns_ops->put(ns);
52168+
52169+#ifdef CONFIG_PROC_SYSCTL
52170+ if (inode->i_op == &proc_sys_inode_operations ||
52171+ inode->i_op == &proc_sys_dir_operations)
52172+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
52173+#endif
52174+
52175 }
52176
52177 static struct kmem_cache * proc_inode_cachep;
52178@@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
52179 if (de->mode) {
52180 inode->i_mode = de->mode;
52181 inode->i_uid = de->uid;
52182+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52183+ inode->i_gid = grsec_proc_gid;
52184+#else
52185 inode->i_gid = de->gid;
52186+#endif
52187 }
52188 if (de->size)
52189 inode->i_size = de->size;
52190diff --git a/fs/proc/internal.h b/fs/proc/internal.h
52191index 252544c..04395b9 100644
52192--- a/fs/proc/internal.h
52193+++ b/fs/proc/internal.h
52194@@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52195 struct pid *pid, struct task_struct *task);
52196 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
52197 struct pid *pid, struct task_struct *task);
52198+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52199+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
52200+#endif
52201 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
52202
52203 extern const struct file_operations proc_tid_children_operations;
52204diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
52205index e96d4f1..8b116ed 100644
52206--- a/fs/proc/kcore.c
52207+++ b/fs/proc/kcore.c
52208@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52209 * the addresses in the elf_phdr on our list.
52210 */
52211 start = kc_offset_to_vaddr(*fpos - elf_buflen);
52212- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
52213+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
52214+ if (tsz > buflen)
52215 tsz = buflen;
52216-
52217+
52218 while (buflen) {
52219 struct kcore_list *m;
52220
52221@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52222 kfree(elf_buf);
52223 } else {
52224 if (kern_addr_valid(start)) {
52225- unsigned long n;
52226+ char *elf_buf;
52227+ mm_segment_t oldfs;
52228
52229- n = copy_to_user(buffer, (char *)start, tsz);
52230- /*
52231- * We cannot distinguish between fault on source
52232- * and fault on destination. When this happens
52233- * we clear too and hope it will trigger the
52234- * EFAULT again.
52235- */
52236- if (n) {
52237- if (clear_user(buffer + tsz - n,
52238- n))
52239+ elf_buf = kmalloc(tsz, GFP_KERNEL);
52240+ if (!elf_buf)
52241+ return -ENOMEM;
52242+ oldfs = get_fs();
52243+ set_fs(KERNEL_DS);
52244+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
52245+ set_fs(oldfs);
52246+ if (copy_to_user(buffer, elf_buf, tsz)) {
52247+ kfree(elf_buf);
52248 return -EFAULT;
52249+ }
52250 }
52251+ set_fs(oldfs);
52252+ kfree(elf_buf);
52253 } else {
52254 if (clear_user(buffer, tsz))
52255 return -EFAULT;
52256@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52257
52258 static int open_kcore(struct inode *inode, struct file *filp)
52259 {
52260+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
52261+ return -EPERM;
52262+#endif
52263 if (!capable(CAP_SYS_RAWIO))
52264 return -EPERM;
52265 if (kcore_need_update)
52266diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
52267index 80e4645..53e5fcf 100644
52268--- a/fs/proc/meminfo.c
52269+++ b/fs/proc/meminfo.c
52270@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
52271 vmi.used >> 10,
52272 vmi.largest_chunk >> 10
52273 #ifdef CONFIG_MEMORY_FAILURE
52274- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
52275+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
52276 #endif
52277 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
52278 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
52279diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
52280index b1822dd..df622cb 100644
52281--- a/fs/proc/nommu.c
52282+++ b/fs/proc/nommu.c
52283@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
52284 if (len < 1)
52285 len = 1;
52286 seq_printf(m, "%*c", len, ' ');
52287- seq_path(m, &file->f_path, "");
52288+ seq_path(m, &file->f_path, "\n\\");
52289 }
52290
52291 seq_putc(m, '\n');
52292diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
52293index fe72cd0..cb9b67d 100644
52294--- a/fs/proc/proc_net.c
52295+++ b/fs/proc/proc_net.c
52296@@ -23,6 +23,7 @@
52297 #include <linux/nsproxy.h>
52298 #include <net/net_namespace.h>
52299 #include <linux/seq_file.h>
52300+#include <linux/grsecurity.h>
52301
52302 #include "internal.h"
52303
52304@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
52305 struct task_struct *task;
52306 struct nsproxy *ns;
52307 struct net *net = NULL;
52308+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52309+ const struct cred *cred = current_cred();
52310+#endif
52311+
52312+#ifdef CONFIG_GRKERNSEC_PROC_USER
52313+ if (cred->fsuid)
52314+ return net;
52315+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52316+ if (cred->fsuid && !in_group_p(grsec_proc_gid))
52317+ return net;
52318+#endif
52319
52320 rcu_read_lock();
52321 task = pid_task(proc_pid(dir), PIDTYPE_PID);
52322diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
52323index 1827d88..9a60b01 100644
52324--- a/fs/proc/proc_sysctl.c
52325+++ b/fs/proc/proc_sysctl.c
52326@@ -12,11 +12,15 @@
52327 #include <linux/module.h>
52328 #include "internal.h"
52329
52330+extern int gr_handle_chroot_sysctl(const int op);
52331+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
52332+ const int op);
52333+
52334 static const struct dentry_operations proc_sys_dentry_operations;
52335 static const struct file_operations proc_sys_file_operations;
52336-static const struct inode_operations proc_sys_inode_operations;
52337+const struct inode_operations proc_sys_inode_operations;
52338 static const struct file_operations proc_sys_dir_file_operations;
52339-static const struct inode_operations proc_sys_dir_operations;
52340+const struct inode_operations proc_sys_dir_operations;
52341
52342 void proc_sys_poll_notify(struct ctl_table_poll *poll)
52343 {
52344@@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
52345
52346 err = NULL;
52347 d_set_d_op(dentry, &proc_sys_dentry_operations);
52348+
52349+ gr_handle_proc_create(dentry, inode);
52350+
52351 d_add(dentry, inode);
52352
52353 out:
52354@@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52355 struct inode *inode = filp->f_path.dentry->d_inode;
52356 struct ctl_table_header *head = grab_header(inode);
52357 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
52358+ int op = write ? MAY_WRITE : MAY_READ;
52359 ssize_t error;
52360 size_t res;
52361
52362@@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52363 * and won't be until we finish.
52364 */
52365 error = -EPERM;
52366- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
52367+ if (sysctl_perm(head, table, op))
52368 goto out;
52369
52370 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
52371@@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52372 if (!table->proc_handler)
52373 goto out;
52374
52375+#ifdef CONFIG_GRKERNSEC
52376+ error = -EPERM;
52377+ if (gr_handle_chroot_sysctl(op))
52378+ goto out;
52379+ dget(filp->f_path.dentry);
52380+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
52381+ dput(filp->f_path.dentry);
52382+ goto out;
52383+ }
52384+ dput(filp->f_path.dentry);
52385+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
52386+ goto out;
52387+ if (write && !capable(CAP_SYS_ADMIN))
52388+ goto out;
52389+#endif
52390+
52391 /* careful: calling conventions are nasty here */
52392 res = count;
52393 error = table->proc_handler(table, write, buf, &res, ppos);
52394@@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
52395 return -ENOMEM;
52396 } else {
52397 d_set_d_op(child, &proc_sys_dentry_operations);
52398+
52399+ gr_handle_proc_create(child, inode);
52400+
52401 d_add(child, inode);
52402 }
52403 } else {
52404@@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
52405 if ((*pos)++ < file->f_pos)
52406 return 0;
52407
52408+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
52409+ return 0;
52410+
52411 if (unlikely(S_ISLNK(table->mode)))
52412 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
52413 else
52414@@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
52415 if (IS_ERR(head))
52416 return PTR_ERR(head);
52417
52418+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
52419+ return -ENOENT;
52420+
52421 generic_fillattr(inode, stat);
52422 if (table)
52423 stat->mode = (stat->mode & S_IFMT) | table->mode;
52424@@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
52425 .llseek = generic_file_llseek,
52426 };
52427
52428-static const struct inode_operations proc_sys_inode_operations = {
52429+const struct inode_operations proc_sys_inode_operations = {
52430 .permission = proc_sys_permission,
52431 .setattr = proc_sys_setattr,
52432 .getattr = proc_sys_getattr,
52433 };
52434
52435-static const struct inode_operations proc_sys_dir_operations = {
52436+const struct inode_operations proc_sys_dir_operations = {
52437 .lookup = proc_sys_lookup,
52438 .permission = proc_sys_permission,
52439 .setattr = proc_sys_setattr,
52440diff --git a/fs/proc/root.c b/fs/proc/root.c
52441index c6e9fac..a740964 100644
52442--- a/fs/proc/root.c
52443+++ b/fs/proc/root.c
52444@@ -176,7 +176,15 @@ void __init proc_root_init(void)
52445 #ifdef CONFIG_PROC_DEVICETREE
52446 proc_device_tree_init();
52447 #endif
52448+#ifdef CONFIG_GRKERNSEC_PROC_ADD
52449+#ifdef CONFIG_GRKERNSEC_PROC_USER
52450+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
52451+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52452+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
52453+#endif
52454+#else
52455 proc_mkdir("bus", NULL);
52456+#endif
52457 proc_sys_init();
52458 }
52459
52460diff --git a/fs/proc/self.c b/fs/proc/self.c
52461index aa5cc3b..c91a5d0 100644
52462--- a/fs/proc/self.c
52463+++ b/fs/proc/self.c
52464@@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
52465 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
52466 void *cookie)
52467 {
52468- char *s = nd_get_link(nd);
52469+ const char *s = nd_get_link(nd);
52470 if (!IS_ERR(s))
52471 kfree(s);
52472 }
52473diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
52474index ca5ce7f..02c1cf0 100644
52475--- a/fs/proc/task_mmu.c
52476+++ b/fs/proc/task_mmu.c
52477@@ -11,12 +11,19 @@
52478 #include <linux/rmap.h>
52479 #include <linux/swap.h>
52480 #include <linux/swapops.h>
52481+#include <linux/grsecurity.h>
52482
52483 #include <asm/elf.h>
52484 #include <asm/uaccess.h>
52485 #include <asm/tlbflush.h>
52486 #include "internal.h"
52487
52488+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52489+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
52490+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
52491+ _mm->pax_flags & MF_PAX_SEGMEXEC))
52492+#endif
52493+
52494 void task_mem(struct seq_file *m, struct mm_struct *mm)
52495 {
52496 unsigned long data, text, lib, swap;
52497@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52498 "VmExe:\t%8lu kB\n"
52499 "VmLib:\t%8lu kB\n"
52500 "VmPTE:\t%8lu kB\n"
52501- "VmSwap:\t%8lu kB\n",
52502- hiwater_vm << (PAGE_SHIFT-10),
52503+ "VmSwap:\t%8lu kB\n"
52504+
52505+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52506+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
52507+#endif
52508+
52509+ ,hiwater_vm << (PAGE_SHIFT-10),
52510 total_vm << (PAGE_SHIFT-10),
52511 mm->locked_vm << (PAGE_SHIFT-10),
52512 mm->pinned_vm << (PAGE_SHIFT-10),
52513@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52514 data << (PAGE_SHIFT-10),
52515 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
52516 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
52517- swap << (PAGE_SHIFT-10));
52518+ swap << (PAGE_SHIFT-10)
52519+
52520+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52521+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52522+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
52523+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
52524+#else
52525+ , mm->context.user_cs_base
52526+ , mm->context.user_cs_limit
52527+#endif
52528+#endif
52529+
52530+ );
52531 }
52532
52533 unsigned long task_vsize(struct mm_struct *mm)
52534@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52535 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
52536 }
52537
52538- /* We don't show the stack guard page in /proc/maps */
52539+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52540+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
52541+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
52542+#else
52543 start = vma->vm_start;
52544- if (stack_guard_page_start(vma, start))
52545- start += PAGE_SIZE;
52546 end = vma->vm_end;
52547- if (stack_guard_page_end(vma, end))
52548- end -= PAGE_SIZE;
52549+#endif
52550
52551 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
52552 start,
52553@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52554 flags & VM_WRITE ? 'w' : '-',
52555 flags & VM_EXEC ? 'x' : '-',
52556 flags & VM_MAYSHARE ? 's' : 'p',
52557+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52558+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
52559+#else
52560 pgoff,
52561+#endif
52562 MAJOR(dev), MINOR(dev), ino, &len);
52563
52564 /*
52565@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52566 */
52567 if (file) {
52568 pad_len_spaces(m, len);
52569- seq_path(m, &file->f_path, "\n");
52570+ seq_path(m, &file->f_path, "\n\\");
52571 goto done;
52572 }
52573
52574@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52575 * Thread stack in /proc/PID/task/TID/maps or
52576 * the main process stack.
52577 */
52578- if (!is_pid || (vma->vm_start <= mm->start_stack &&
52579- vma->vm_end >= mm->start_stack)) {
52580+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
52581+ (vma->vm_start <= mm->start_stack &&
52582+ vma->vm_end >= mm->start_stack)) {
52583 name = "[stack]";
52584 } else {
52585 /* Thread stack in /proc/PID/maps */
52586@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
52587 struct proc_maps_private *priv = m->private;
52588 struct task_struct *task = priv->task;
52589
52590+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52591+ if (current->exec_id != m->exec_id) {
52592+ gr_log_badprocpid("maps");
52593+ return 0;
52594+ }
52595+#endif
52596+
52597 show_map_vma(m, vma, is_pid);
52598
52599 if (m->count < m->size) /* vma is copied successfully */
52600@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
52601 .private = &mss,
52602 };
52603
52604+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52605+ if (current->exec_id != m->exec_id) {
52606+ gr_log_badprocpid("smaps");
52607+ return 0;
52608+ }
52609+#endif
52610 memset(&mss, 0, sizeof mss);
52611- mss.vma = vma;
52612- /* mmap_sem is held in m_start */
52613- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
52614- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
52615-
52616+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52617+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
52618+#endif
52619+ mss.vma = vma;
52620+ /* mmap_sem is held in m_start */
52621+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
52622+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
52623+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52624+ }
52625+#endif
52626 show_map_vma(m, vma, is_pid);
52627
52628 seq_printf(m,
52629@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
52630 "KernelPageSize: %8lu kB\n"
52631 "MMUPageSize: %8lu kB\n"
52632 "Locked: %8lu kB\n",
52633+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52634+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
52635+#else
52636 (vma->vm_end - vma->vm_start) >> 10,
52637+#endif
52638 mss.resident >> 10,
52639 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
52640 mss.shared_clean >> 10,
52641@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
52642 int n;
52643 char buffer[50];
52644
52645+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52646+ if (current->exec_id != m->exec_id) {
52647+ gr_log_badprocpid("numa_maps");
52648+ return 0;
52649+ }
52650+#endif
52651+
52652 if (!mm)
52653 return 0;
52654
52655@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
52656 mpol_to_str(buffer, sizeof(buffer), pol);
52657 mpol_cond_put(pol);
52658
52659+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52660+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
52661+#else
52662 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
52663+#endif
52664
52665 if (file) {
52666 seq_printf(m, " file=");
52667- seq_path(m, &file->f_path, "\n\t= ");
52668+ seq_path(m, &file->f_path, "\n\t\\= ");
52669 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
52670 seq_printf(m, " heap");
52671 } else {
52672diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
52673index 1ccfa53..0848f95 100644
52674--- a/fs/proc/task_nommu.c
52675+++ b/fs/proc/task_nommu.c
52676@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52677 else
52678 bytes += kobjsize(mm);
52679
52680- if (current->fs && current->fs->users > 1)
52681+ if (current->fs && atomic_read(&current->fs->users) > 1)
52682 sbytes += kobjsize(current->fs);
52683 else
52684 bytes += kobjsize(current->fs);
52685@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
52686
52687 if (file) {
52688 pad_len_spaces(m, len);
52689- seq_path(m, &file->f_path, "");
52690+ seq_path(m, &file->f_path, "\n\\");
52691 } else if (mm) {
52692 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
52693
52694diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
52695index 16e8abb..2dcf914 100644
52696--- a/fs/quota/netlink.c
52697+++ b/fs/quota/netlink.c
52698@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
52699 void quota_send_warning(struct kqid qid, dev_t dev,
52700 const char warntype)
52701 {
52702- static atomic_t seq;
52703+ static atomic_unchecked_t seq;
52704 struct sk_buff *skb;
52705 void *msg_head;
52706 int ret;
52707@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
52708 "VFS: Not enough memory to send quota warning.\n");
52709 return;
52710 }
52711- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
52712+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
52713 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
52714 if (!msg_head) {
52715 printk(KERN_ERR
52716diff --git a/fs/readdir.c b/fs/readdir.c
52717index 5e69ef5..e5d9099 100644
52718--- a/fs/readdir.c
52719+++ b/fs/readdir.c
52720@@ -17,6 +17,7 @@
52721 #include <linux/security.h>
52722 #include <linux/syscalls.h>
52723 #include <linux/unistd.h>
52724+#include <linux/namei.h>
52725
52726 #include <asm/uaccess.h>
52727
52728@@ -67,6 +68,7 @@ struct old_linux_dirent {
52729
52730 struct readdir_callback {
52731 struct old_linux_dirent __user * dirent;
52732+ struct file * file;
52733 int result;
52734 };
52735
52736@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
52737 buf->result = -EOVERFLOW;
52738 return -EOVERFLOW;
52739 }
52740+
52741+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52742+ return 0;
52743+
52744 buf->result++;
52745 dirent = buf->dirent;
52746 if (!access_ok(VERIFY_WRITE, dirent,
52747@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
52748
52749 buf.result = 0;
52750 buf.dirent = dirent;
52751+ buf.file = f.file;
52752
52753 error = vfs_readdir(f.file, fillonedir, &buf);
52754 if (buf.result)
52755@@ -139,6 +146,7 @@ struct linux_dirent {
52756 struct getdents_callback {
52757 struct linux_dirent __user * current_dir;
52758 struct linux_dirent __user * previous;
52759+ struct file * file;
52760 int count;
52761 int error;
52762 };
52763@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
52764 buf->error = -EOVERFLOW;
52765 return -EOVERFLOW;
52766 }
52767+
52768+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52769+ return 0;
52770+
52771 dirent = buf->previous;
52772 if (dirent) {
52773 if (__put_user(offset, &dirent->d_off))
52774@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
52775 buf.previous = NULL;
52776 buf.count = count;
52777 buf.error = 0;
52778+ buf.file = f.file;
52779
52780 error = vfs_readdir(f.file, filldir, &buf);
52781 if (error >= 0)
52782@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
52783 struct getdents_callback64 {
52784 struct linux_dirent64 __user * current_dir;
52785 struct linux_dirent64 __user * previous;
52786+ struct file *file;
52787 int count;
52788 int error;
52789 };
52790@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
52791 buf->error = -EINVAL; /* only used if we fail.. */
52792 if (reclen > buf->count)
52793 return -EINVAL;
52794+
52795+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52796+ return 0;
52797+
52798 dirent = buf->previous;
52799 if (dirent) {
52800 if (__put_user(offset, &dirent->d_off))
52801@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
52802
52803 buf.current_dir = dirent;
52804 buf.previous = NULL;
52805+ buf.file = f.file;
52806 buf.count = count;
52807 buf.error = 0;
52808
52809@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
52810 error = buf.error;
52811 lastdirent = buf.previous;
52812 if (lastdirent) {
52813- typeof(lastdirent->d_off) d_off = f.file->f_pos;
52814+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
52815 if (__put_user(d_off, &lastdirent->d_off))
52816 error = -EFAULT;
52817 else
52818diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
52819index 2b7882b..1c5ef48 100644
52820--- a/fs/reiserfs/do_balan.c
52821+++ b/fs/reiserfs/do_balan.c
52822@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
52823 return;
52824 }
52825
52826- atomic_inc(&(fs_generation(tb->tb_sb)));
52827+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
52828 do_balance_starts(tb);
52829
52830 /* balance leaf returns 0 except if combining L R and S into
52831diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
52832index e60e870..f40ac16 100644
52833--- a/fs/reiserfs/procfs.c
52834+++ b/fs/reiserfs/procfs.c
52835@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
52836 "SMALL_TAILS " : "NO_TAILS ",
52837 replay_only(sb) ? "REPLAY_ONLY " : "",
52838 convert_reiserfs(sb) ? "CONV " : "",
52839- atomic_read(&r->s_generation_counter),
52840+ atomic_read_unchecked(&r->s_generation_counter),
52841 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
52842 SF(s_do_balance), SF(s_unneeded_left_neighbor),
52843 SF(s_good_search_by_key_reada), SF(s_bmaps),
52844diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
52845index 157e474..65a6114 100644
52846--- a/fs/reiserfs/reiserfs.h
52847+++ b/fs/reiserfs/reiserfs.h
52848@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
52849 /* Comment? -Hans */
52850 wait_queue_head_t s_wait;
52851 /* To be obsoleted soon by per buffer seals.. -Hans */
52852- atomic_t s_generation_counter; // increased by one every time the
52853+ atomic_unchecked_t s_generation_counter; // increased by one every time the
52854 // tree gets re-balanced
52855 unsigned long s_properties; /* File system properties. Currently holds
52856 on-disk FS format */
52857@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
52858 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
52859
52860 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
52861-#define get_generation(s) atomic_read (&fs_generation(s))
52862+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
52863 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
52864 #define __fs_changed(gen,s) (gen != get_generation (s))
52865 #define fs_changed(gen,s) \
52866diff --git a/fs/select.c b/fs/select.c
52867index 2ef72d9..f213b17 100644
52868--- a/fs/select.c
52869+++ b/fs/select.c
52870@@ -20,6 +20,7 @@
52871 #include <linux/export.h>
52872 #include <linux/slab.h>
52873 #include <linux/poll.h>
52874+#include <linux/security.h>
52875 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
52876 #include <linux/file.h>
52877 #include <linux/fdtable.h>
52878@@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
52879 struct poll_list *walk = head;
52880 unsigned long todo = nfds;
52881
52882+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
52883 if (nfds > rlimit(RLIMIT_NOFILE))
52884 return -EINVAL;
52885
52886diff --git a/fs/seq_file.c b/fs/seq_file.c
52887index f2bc3df..239d4f6 100644
52888--- a/fs/seq_file.c
52889+++ b/fs/seq_file.c
52890@@ -10,6 +10,7 @@
52891 #include <linux/seq_file.h>
52892 #include <linux/slab.h>
52893 #include <linux/cred.h>
52894+#include <linux/sched.h>
52895
52896 #include <asm/uaccess.h>
52897 #include <asm/page.h>
52898@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
52899 #ifdef CONFIG_USER_NS
52900 p->user_ns = file->f_cred->user_ns;
52901 #endif
52902+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52903+ p->exec_id = current->exec_id;
52904+#endif
52905
52906 /*
52907 * Wrappers around seq_open(e.g. swaps_open) need to be
52908@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52909 return 0;
52910 }
52911 if (!m->buf) {
52912- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52913+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52914 if (!m->buf)
52915 return -ENOMEM;
52916 }
52917@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52918 Eoverflow:
52919 m->op->stop(m, p);
52920 kfree(m->buf);
52921- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52922+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52923 return !m->buf ? -ENOMEM : -EAGAIN;
52924 }
52925
52926@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52927
52928 /* grab buffer if we didn't have one */
52929 if (!m->buf) {
52930- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52931+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52932 if (!m->buf)
52933 goto Enomem;
52934 }
52935@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52936 goto Fill;
52937 m->op->stop(m, p);
52938 kfree(m->buf);
52939- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52940+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52941 if (!m->buf)
52942 goto Enomem;
52943 m->count = 0;
52944@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
52945 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
52946 void *data)
52947 {
52948- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
52949+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
52950 int res = -ENOMEM;
52951
52952 if (op) {
52953diff --git a/fs/splice.c b/fs/splice.c
52954index 6909d89..5b2e8f9 100644
52955--- a/fs/splice.c
52956+++ b/fs/splice.c
52957@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52958 pipe_lock(pipe);
52959
52960 for (;;) {
52961- if (!pipe->readers) {
52962+ if (!atomic_read(&pipe->readers)) {
52963 send_sig(SIGPIPE, current, 0);
52964 if (!ret)
52965 ret = -EPIPE;
52966@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52967 do_wakeup = 0;
52968 }
52969
52970- pipe->waiting_writers++;
52971+ atomic_inc(&pipe->waiting_writers);
52972 pipe_wait(pipe);
52973- pipe->waiting_writers--;
52974+ atomic_dec(&pipe->waiting_writers);
52975 }
52976
52977 pipe_unlock(pipe);
52978@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
52979 old_fs = get_fs();
52980 set_fs(get_ds());
52981 /* The cast to a user pointer is valid due to the set_fs() */
52982- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
52983+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
52984 set_fs(old_fs);
52985
52986 return res;
52987@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
52988 old_fs = get_fs();
52989 set_fs(get_ds());
52990 /* The cast to a user pointer is valid due to the set_fs() */
52991- res = vfs_write(file, (const char __user *)buf, count, &pos);
52992+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
52993 set_fs(old_fs);
52994
52995 return res;
52996@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
52997 goto err;
52998
52999 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
53000- vec[i].iov_base = (void __user *) page_address(page);
53001+ vec[i].iov_base = (void __force_user *) page_address(page);
53002 vec[i].iov_len = this_len;
53003 spd.pages[i] = page;
53004 spd.nr_pages++;
53005@@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
53006 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
53007 {
53008 while (!pipe->nrbufs) {
53009- if (!pipe->writers)
53010+ if (!atomic_read(&pipe->writers))
53011 return 0;
53012
53013- if (!pipe->waiting_writers && sd->num_spliced)
53014+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
53015 return 0;
53016
53017 if (sd->flags & SPLICE_F_NONBLOCK)
53018@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
53019 * out of the pipe right after the splice_to_pipe(). So set
53020 * PIPE_READERS appropriately.
53021 */
53022- pipe->readers = 1;
53023+ atomic_set(&pipe->readers, 1);
53024
53025 current->splice_pipe = pipe;
53026 }
53027@@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53028 ret = -ERESTARTSYS;
53029 break;
53030 }
53031- if (!pipe->writers)
53032+ if (!atomic_read(&pipe->writers))
53033 break;
53034- if (!pipe->waiting_writers) {
53035+ if (!atomic_read(&pipe->waiting_writers)) {
53036 if (flags & SPLICE_F_NONBLOCK) {
53037 ret = -EAGAIN;
53038 break;
53039@@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53040 pipe_lock(pipe);
53041
53042 while (pipe->nrbufs >= pipe->buffers) {
53043- if (!pipe->readers) {
53044+ if (!atomic_read(&pipe->readers)) {
53045 send_sig(SIGPIPE, current, 0);
53046 ret = -EPIPE;
53047 break;
53048@@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53049 ret = -ERESTARTSYS;
53050 break;
53051 }
53052- pipe->waiting_writers++;
53053+ atomic_inc(&pipe->waiting_writers);
53054 pipe_wait(pipe);
53055- pipe->waiting_writers--;
53056+ atomic_dec(&pipe->waiting_writers);
53057 }
53058
53059 pipe_unlock(pipe);
53060@@ -1823,14 +1823,14 @@ retry:
53061 pipe_double_lock(ipipe, opipe);
53062
53063 do {
53064- if (!opipe->readers) {
53065+ if (!atomic_read(&opipe->readers)) {
53066 send_sig(SIGPIPE, current, 0);
53067 if (!ret)
53068 ret = -EPIPE;
53069 break;
53070 }
53071
53072- if (!ipipe->nrbufs && !ipipe->writers)
53073+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
53074 break;
53075
53076 /*
53077@@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
53078 pipe_double_lock(ipipe, opipe);
53079
53080 do {
53081- if (!opipe->readers) {
53082+ if (!atomic_read(&opipe->readers)) {
53083 send_sig(SIGPIPE, current, 0);
53084 if (!ret)
53085 ret = -EPIPE;
53086@@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
53087 * return EAGAIN if we have the potential of some data in the
53088 * future, otherwise just return 0
53089 */
53090- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
53091+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
53092 ret = -EAGAIN;
53093
53094 pipe_unlock(ipipe);
53095diff --git a/fs/stat.c b/fs/stat.c
53096index 14f4545..9b7f55b 100644
53097--- a/fs/stat.c
53098+++ b/fs/stat.c
53099@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
53100 stat->gid = inode->i_gid;
53101 stat->rdev = inode->i_rdev;
53102 stat->size = i_size_read(inode);
53103- stat->atime = inode->i_atime;
53104- stat->mtime = inode->i_mtime;
53105+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
53106+ stat->atime = inode->i_ctime;
53107+ stat->mtime = inode->i_ctime;
53108+ } else {
53109+ stat->atime = inode->i_atime;
53110+ stat->mtime = inode->i_mtime;
53111+ }
53112 stat->ctime = inode->i_ctime;
53113 stat->blksize = (1 << inode->i_blkbits);
53114 stat->blocks = inode->i_blocks;
53115@@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
53116 if (retval)
53117 return retval;
53118
53119- if (inode->i_op->getattr)
53120- return inode->i_op->getattr(mnt, dentry, stat);
53121+ if (inode->i_op->getattr) {
53122+ retval = inode->i_op->getattr(mnt, dentry, stat);
53123+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
53124+ stat->atime = stat->ctime;
53125+ stat->mtime = stat->ctime;
53126+ }
53127+ return retval;
53128+ }
53129
53130 generic_fillattr(inode, stat);
53131 return 0;
53132diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
53133index 2fbdff6..5530a61 100644
53134--- a/fs/sysfs/dir.c
53135+++ b/fs/sysfs/dir.c
53136@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
53137 struct sysfs_dirent *sd;
53138 int rc;
53139
53140+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
53141+ const char *parent_name = parent_sd->s_name;
53142+
53143+ mode = S_IFDIR | S_IRWXU;
53144+
53145+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
53146+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
53147+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
53148+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
53149+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
53150+#endif
53151+
53152 /* allocate */
53153 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
53154 if (!sd)
53155diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
53156index 602f56d..6853db8 100644
53157--- a/fs/sysfs/file.c
53158+++ b/fs/sysfs/file.c
53159@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
53160
53161 struct sysfs_open_dirent {
53162 atomic_t refcnt;
53163- atomic_t event;
53164+ atomic_unchecked_t event;
53165 wait_queue_head_t poll;
53166 struct list_head buffers; /* goes through sysfs_buffer.list */
53167 };
53168@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
53169 if (!sysfs_get_active(attr_sd))
53170 return -ENODEV;
53171
53172- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
53173+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
53174 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
53175
53176 sysfs_put_active(attr_sd);
53177@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
53178 return -ENOMEM;
53179
53180 atomic_set(&new_od->refcnt, 0);
53181- atomic_set(&new_od->event, 1);
53182+ atomic_set_unchecked(&new_od->event, 1);
53183 init_waitqueue_head(&new_od->poll);
53184 INIT_LIST_HEAD(&new_od->buffers);
53185 goto retry;
53186@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
53187
53188 sysfs_put_active(attr_sd);
53189
53190- if (buffer->event != atomic_read(&od->event))
53191+ if (buffer->event != atomic_read_unchecked(&od->event))
53192 goto trigger;
53193
53194 return DEFAULT_POLLMASK;
53195@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
53196
53197 od = sd->s_attr.open;
53198 if (od) {
53199- atomic_inc(&od->event);
53200+ atomic_inc_unchecked(&od->event);
53201 wake_up_interruptible(&od->poll);
53202 }
53203
53204diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
53205index 3c9eb56..9dea5be 100644
53206--- a/fs/sysfs/symlink.c
53207+++ b/fs/sysfs/symlink.c
53208@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
53209
53210 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
53211 {
53212- char *page = nd_get_link(nd);
53213+ const char *page = nd_get_link(nd);
53214 if (!IS_ERR(page))
53215 free_page((unsigned long)page);
53216 }
53217diff --git a/fs/udf/misc.c b/fs/udf/misc.c
53218index c175b4d..8f36a16 100644
53219--- a/fs/udf/misc.c
53220+++ b/fs/udf/misc.c
53221@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
53222
53223 u8 udf_tag_checksum(const struct tag *t)
53224 {
53225- u8 *data = (u8 *)t;
53226+ const u8 *data = (const u8 *)t;
53227 u8 checksum = 0;
53228 int i;
53229 for (i = 0; i < sizeof(struct tag); ++i)
53230diff --git a/fs/utimes.c b/fs/utimes.c
53231index f4fb7ec..3fe03c0 100644
53232--- a/fs/utimes.c
53233+++ b/fs/utimes.c
53234@@ -1,6 +1,7 @@
53235 #include <linux/compiler.h>
53236 #include <linux/file.h>
53237 #include <linux/fs.h>
53238+#include <linux/security.h>
53239 #include <linux/linkage.h>
53240 #include <linux/mount.h>
53241 #include <linux/namei.h>
53242@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
53243 goto mnt_drop_write_and_out;
53244 }
53245 }
53246+
53247+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
53248+ error = -EACCES;
53249+ goto mnt_drop_write_and_out;
53250+ }
53251+
53252 mutex_lock(&inode->i_mutex);
53253 error = notify_change(path->dentry, &newattrs);
53254 mutex_unlock(&inode->i_mutex);
53255diff --git a/fs/xattr.c b/fs/xattr.c
53256index 3377dff..4feded6 100644
53257--- a/fs/xattr.c
53258+++ b/fs/xattr.c
53259@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
53260 * Extended attribute SET operations
53261 */
53262 static long
53263-setxattr(struct dentry *d, const char __user *name, const void __user *value,
53264+setxattr(struct path *path, const char __user *name, const void __user *value,
53265 size_t size, int flags)
53266 {
53267 int error;
53268@@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
53269 posix_acl_fix_xattr_from_user(kvalue, size);
53270 }
53271
53272- error = vfs_setxattr(d, kname, kvalue, size, flags);
53273+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
53274+ error = -EACCES;
53275+ goto out;
53276+ }
53277+
53278+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
53279 out:
53280 if (vvalue)
53281 vfree(vvalue);
53282@@ -377,7 +382,7 @@ retry:
53283 return error;
53284 error = mnt_want_write(path.mnt);
53285 if (!error) {
53286- error = setxattr(path.dentry, name, value, size, flags);
53287+ error = setxattr(&path, name, value, size, flags);
53288 mnt_drop_write(path.mnt);
53289 }
53290 path_put(&path);
53291@@ -401,7 +406,7 @@ retry:
53292 return error;
53293 error = mnt_want_write(path.mnt);
53294 if (!error) {
53295- error = setxattr(path.dentry, name, value, size, flags);
53296+ error = setxattr(&path, name, value, size, flags);
53297 mnt_drop_write(path.mnt);
53298 }
53299 path_put(&path);
53300@@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
53301 const void __user *,value, size_t, size, int, flags)
53302 {
53303 struct fd f = fdget(fd);
53304- struct dentry *dentry;
53305 int error = -EBADF;
53306
53307 if (!f.file)
53308 return error;
53309- dentry = f.file->f_path.dentry;
53310- audit_inode(NULL, dentry, 0);
53311+ audit_inode(NULL, f.file->f_path.dentry, 0);
53312 error = mnt_want_write_file(f.file);
53313 if (!error) {
53314- error = setxattr(dentry, name, value, size, flags);
53315+ error = setxattr(&f.file->f_path, name, value, size, flags);
53316 mnt_drop_write_file(f.file);
53317 }
53318 fdput(f);
53319diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
53320index 9fbea87..6b19972 100644
53321--- a/fs/xattr_acl.c
53322+++ b/fs/xattr_acl.c
53323@@ -76,8 +76,8 @@ struct posix_acl *
53324 posix_acl_from_xattr(struct user_namespace *user_ns,
53325 const void *value, size_t size)
53326 {
53327- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
53328- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
53329+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
53330+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
53331 int count;
53332 struct posix_acl *acl;
53333 struct posix_acl_entry *acl_e;
53334diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
53335index cdb2d33..704ce7f 100644
53336--- a/fs/xfs/xfs_bmap.c
53337+++ b/fs/xfs/xfs_bmap.c
53338@@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
53339 int nmap,
53340 int ret_nmap);
53341 #else
53342-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
53343+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
53344 #endif /* DEBUG */
53345
53346 STATIC int
53347diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
53348index 1b9fc3e..e1bdde0 100644
53349--- a/fs/xfs/xfs_dir2_sf.c
53350+++ b/fs/xfs/xfs_dir2_sf.c
53351@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
53352 }
53353
53354 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
53355- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
53356+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
53357+ char name[sfep->namelen];
53358+ memcpy(name, sfep->name, sfep->namelen);
53359+ if (filldir(dirent, name, sfep->namelen,
53360+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
53361+ *offset = off & 0x7fffffff;
53362+ return 0;
53363+ }
53364+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
53365 off & 0x7fffffff, ino, DT_UNKNOWN)) {
53366 *offset = off & 0x7fffffff;
53367 return 0;
53368diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
53369index c1c3ef8..0952438 100644
53370--- a/fs/xfs/xfs_ioctl.c
53371+++ b/fs/xfs/xfs_ioctl.c
53372@@ -127,7 +127,7 @@ xfs_find_handle(
53373 }
53374
53375 error = -EFAULT;
53376- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
53377+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
53378 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
53379 goto out_put;
53380
53381diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
53382index d82efaa..0904a8e 100644
53383--- a/fs/xfs/xfs_iops.c
53384+++ b/fs/xfs/xfs_iops.c
53385@@ -395,7 +395,7 @@ xfs_vn_put_link(
53386 struct nameidata *nd,
53387 void *p)
53388 {
53389- char *s = nd_get_link(nd);
53390+ const char *s = nd_get_link(nd);
53391
53392 if (!IS_ERR(s))
53393 kfree(s);
53394diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
53395new file mode 100644
53396index 0000000..92247e4
53397--- /dev/null
53398+++ b/grsecurity/Kconfig
53399@@ -0,0 +1,1021 @@
53400+#
53401+# grecurity configuration
53402+#
53403+menu "Memory Protections"
53404+depends on GRKERNSEC
53405+
53406+config GRKERNSEC_KMEM
53407+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
53408+ default y if GRKERNSEC_CONFIG_AUTO
53409+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
53410+ help
53411+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
53412+ be written to or read from to modify or leak the contents of the running
53413+ kernel. /dev/port will also not be allowed to be opened and support
53414+ for /dev/cpu/*/msr will be removed. If you have module
53415+ support disabled, enabling this will close up five ways that are
53416+ currently used to insert malicious code into the running kernel.
53417+
53418+ Even with all these features enabled, we still highly recommend that
53419+ you use the RBAC system, as it is still possible for an attacker to
53420+ modify the running kernel through privileged I/O granted by ioperm/iopl.
53421+
53422+ If you are not using XFree86, you may be able to stop this additional
53423+ case by enabling the 'Disable privileged I/O' option. Though nothing
53424+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
53425+ but only to video memory, which is the only writing we allow in this
53426+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
53427+ not be allowed to mprotect it with PROT_WRITE later.
53428+ Enabling this feature will prevent the "cpupower" and "powertop" tools
53429+ from working.
53430+
53431+ It is highly recommended that you say Y here if you meet all the
53432+ conditions above.
53433+
53434+config GRKERNSEC_VM86
53435+ bool "Restrict VM86 mode"
53436+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53437+ depends on X86_32
53438+
53439+ help
53440+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
53441+ make use of a special execution mode on 32bit x86 processors called
53442+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
53443+ video cards and will still work with this option enabled. The purpose
53444+ of the option is to prevent exploitation of emulation errors in
53445+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
53446+ Nearly all users should be able to enable this option.
53447+
53448+config GRKERNSEC_IO
53449+ bool "Disable privileged I/O"
53450+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53451+ depends on X86
53452+ select RTC_CLASS
53453+ select RTC_INTF_DEV
53454+ select RTC_DRV_CMOS
53455+
53456+ help
53457+ If you say Y here, all ioperm and iopl calls will return an error.
53458+ Ioperm and iopl can be used to modify the running kernel.
53459+ Unfortunately, some programs need this access to operate properly,
53460+ the most notable of which are XFree86 and hwclock. hwclock can be
53461+ remedied by having RTC support in the kernel, so real-time
53462+ clock support is enabled if this option is enabled, to ensure
53463+ that hwclock operates correctly. XFree86 still will not
53464+ operate correctly with this option enabled, so DO NOT CHOOSE Y
53465+ IF YOU USE XFree86. If you use XFree86 and you still want to
53466+ protect your kernel against modification, use the RBAC system.
53467+
53468+config GRKERNSEC_JIT_HARDEN
53469+ bool "Harden BPF JIT against spray attacks"
53470+ default y if GRKERNSEC_CONFIG_AUTO
53471+ depends on BPF_JIT
53472+ help
53473+ If you say Y here, the native code generated by the kernel's Berkeley
53474+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
53475+ attacks that attempt to fit attacker-beneficial instructions in
53476+ 32bit immediate fields of JIT-generated native instructions. The
53477+ attacker will generally aim to cause an unintended instruction sequence
53478+ of JIT-generated native code to execute by jumping into the middle of
53479+ a generated instruction. This feature effectively randomizes the 32bit
53480+ immediate constants present in the generated code to thwart such attacks.
53481+
53482+ If you're using KERNEXEC, it's recommended that you enable this option
53483+ to supplement the hardening of the kernel.
53484+
53485+config GRKERNSEC_RAND_THREADSTACK
53486+ bool "Insert random gaps between thread stacks"
53487+ default y if GRKERNSEC_CONFIG_AUTO
53488+ depends on PAX_RANDMMAP && !PPC
53489+ help
53490+ If you say Y here, a random-sized gap will be enforced between allocated
53491+ thread stacks. Glibc's NPTL and other threading libraries that
53492+ pass MAP_STACK to the kernel for thread stack allocation are supported.
53493+ The implementation currently provides 8 bits of entropy for the gap.
53494+
53495+ Many distributions do not compile threaded remote services with the
53496+ -fstack-check argument to GCC, causing the variable-sized stack-based
53497+ allocator, alloca(), to not probe the stack on allocation. This
53498+ permits an unbounded alloca() to skip over any guard page and potentially
53499+ modify another thread's stack reliably. An enforced random gap
53500+ reduces the reliability of such an attack and increases the chance
53501+ that such a read/write to another thread's stack instead lands in
53502+ an unmapped area, causing a crash and triggering grsecurity's
53503+ anti-bruteforcing logic.
53504+
53505+config GRKERNSEC_PROC_MEMMAP
53506+ bool "Harden ASLR against information leaks and entropy reduction"
53507+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
53508+ depends on PAX_NOEXEC || PAX_ASLR
53509+ help
53510+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
53511+ give no information about the addresses of its mappings if
53512+ PaX features that rely on random addresses are enabled on the task.
53513+ In addition to sanitizing this information and disabling other
53514+ dangerous sources of information, this option causes reads of sensitive
53515+ /proc/<pid> entries where the file descriptor was opened in a different
53516+ task than the one performing the read. Such attempts are logged.
53517+ This option also limits argv/env strings for suid/sgid binaries
53518+ to 512KB to prevent a complete exhaustion of the stack entropy provided
53519+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
53520+ binaries to prevent alternative mmap layouts from being abused.
53521+
53522+ If you use PaX it is essential that you say Y here as it closes up
53523+ several holes that make full ASLR useless locally.
53524+
53525+config GRKERNSEC_BRUTE
53526+ bool "Deter exploit bruteforcing"
53527+ default y if GRKERNSEC_CONFIG_AUTO
53528+ help
53529+ If you say Y here, attempts to bruteforce exploits against forking
53530+ daemons such as apache or sshd, as well as against suid/sgid binaries
53531+ will be deterred. When a child of a forking daemon is killed by PaX
53532+ or crashes due to an illegal instruction or other suspicious signal,
53533+ the parent process will be delayed 30 seconds upon every subsequent
53534+ fork until the administrator is able to assess the situation and
53535+ restart the daemon.
53536+ In the suid/sgid case, the attempt is logged, the user has all their
53537+ processes terminated, and they are prevented from executing any further
53538+ processes for 15 minutes.
53539+ It is recommended that you also enable signal logging in the auditing
53540+ section so that logs are generated when a process triggers a suspicious
53541+ signal.
53542+ If the sysctl option is enabled, a sysctl option with name
53543+ "deter_bruteforce" is created.
53544+
53545+
53546+config GRKERNSEC_MODHARDEN
53547+ bool "Harden module auto-loading"
53548+ default y if GRKERNSEC_CONFIG_AUTO
53549+ depends on MODULES
53550+ help
53551+ If you say Y here, module auto-loading in response to use of some
53552+ feature implemented by an unloaded module will be restricted to
53553+ root users. Enabling this option helps defend against attacks
53554+ by unprivileged users who abuse the auto-loading behavior to
53555+ cause a vulnerable module to load that is then exploited.
53556+
53557+ If this option prevents a legitimate use of auto-loading for a
53558+ non-root user, the administrator can execute modprobe manually
53559+ with the exact name of the module mentioned in the alert log.
53560+ Alternatively, the administrator can add the module to the list
53561+ of modules loaded at boot by modifying init scripts.
53562+
53563+ Modification of init scripts will most likely be needed on
53564+ Ubuntu servers with encrypted home directory support enabled,
53565+ as the first non-root user logging in will cause the ecb(aes),
53566+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
53567+
53568+config GRKERNSEC_HIDESYM
53569+ bool "Hide kernel symbols"
53570+ default y if GRKERNSEC_CONFIG_AUTO
53571+ select PAX_USERCOPY_SLABS
53572+ help
53573+ If you say Y here, getting information on loaded modules, and
53574+ displaying all kernel symbols through a syscall will be restricted
53575+ to users with CAP_SYS_MODULE. For software compatibility reasons,
53576+ /proc/kallsyms will be restricted to the root user. The RBAC
53577+ system can hide that entry even from root.
53578+
53579+ This option also prevents leaking of kernel addresses through
53580+ several /proc entries.
53581+
53582+ Note that this option is only effective provided the following
53583+ conditions are met:
53584+ 1) The kernel using grsecurity is not precompiled by some distribution
53585+ 2) You have also enabled GRKERNSEC_DMESG
53586+ 3) You are using the RBAC system and hiding other files such as your
53587+ kernel image and System.map. Alternatively, enabling this option
53588+ causes the permissions on /boot, /lib/modules, and the kernel
53589+ source directory to change at compile time to prevent
53590+ reading by non-root users.
53591+ If the above conditions are met, this option will aid in providing a
53592+ useful protection against local kernel exploitation of overflows
53593+ and arbitrary read/write vulnerabilities.
53594+
53595+config GRKERNSEC_KERN_LOCKOUT
53596+ bool "Active kernel exploit response"
53597+ default y if GRKERNSEC_CONFIG_AUTO
53598+ depends on X86 || ARM || PPC || SPARC
53599+ help
53600+ If you say Y here, when a PaX alert is triggered due to suspicious
53601+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
53602+ or an OOPS occurs due to bad memory accesses, instead of just
53603+ terminating the offending process (and potentially allowing
53604+ a subsequent exploit from the same user), we will take one of two
53605+ actions:
53606+ If the user was root, we will panic the system
53607+ If the user was non-root, we will log the attempt, terminate
53608+ all processes owned by the user, then prevent them from creating
53609+ any new processes until the system is restarted
53610+ This deters repeated kernel exploitation/bruteforcing attempts
53611+ and is useful for later forensics.
53612+
53613+endmenu
53614+menu "Role Based Access Control Options"
53615+depends on GRKERNSEC
53616+
53617+config GRKERNSEC_RBAC_DEBUG
53618+ bool
53619+
53620+config GRKERNSEC_NO_RBAC
53621+ bool "Disable RBAC system"
53622+ help
53623+ If you say Y here, the /dev/grsec device will be removed from the kernel,
53624+ preventing the RBAC system from being enabled. You should only say Y
53625+ here if you have no intention of using the RBAC system, so as to prevent
53626+ an attacker with root access from misusing the RBAC system to hide files
53627+ and processes when loadable module support and /dev/[k]mem have been
53628+ locked down.
53629+
53630+config GRKERNSEC_ACL_HIDEKERN
53631+ bool "Hide kernel processes"
53632+ help
53633+ If you say Y here, all kernel threads will be hidden to all
53634+ processes but those whose subject has the "view hidden processes"
53635+ flag.
53636+
53637+config GRKERNSEC_ACL_MAXTRIES
53638+ int "Maximum tries before password lockout"
53639+ default 3
53640+ help
53641+ This option enforces the maximum number of times a user can attempt
53642+ to authorize themselves with the grsecurity RBAC system before being
53643+ denied the ability to attempt authorization again for a specified time.
53644+ The lower the number, the harder it will be to brute-force a password.
53645+
53646+config GRKERNSEC_ACL_TIMEOUT
53647+ int "Time to wait after max password tries, in seconds"
53648+ default 30
53649+ help
53650+ This option specifies the time the user must wait after attempting to
53651+ authorize to the RBAC system with the maximum number of invalid
53652+ passwords. The higher the number, the harder it will be to brute-force
53653+ a password.
53654+
53655+endmenu
53656+menu "Filesystem Protections"
53657+depends on GRKERNSEC
53658+
53659+config GRKERNSEC_PROC
53660+ bool "Proc restrictions"
53661+ default y if GRKERNSEC_CONFIG_AUTO
53662+ help
53663+ If you say Y here, the permissions of the /proc filesystem
53664+ will be altered to enhance system security and privacy. You MUST
53665+ choose either a user only restriction or a user and group restriction.
53666+ Depending upon the option you choose, you can either restrict users to
53667+ see only the processes they themselves run, or choose a group that can
53668+ view all processes and files normally restricted to root if you choose
53669+ the "restrict to user only" option. NOTE: If you're running identd or
53670+ ntpd as a non-root user, you will have to run it as the group you
53671+ specify here.
53672+
53673+config GRKERNSEC_PROC_USER
53674+ bool "Restrict /proc to user only"
53675+ depends on GRKERNSEC_PROC
53676+ help
53677+ If you say Y here, non-root users will only be able to view their own
53678+ processes, and restricts them from viewing network-related information,
53679+ and viewing kernel symbol and module information.
53680+
53681+config GRKERNSEC_PROC_USERGROUP
53682+ bool "Allow special group"
53683+ default y if GRKERNSEC_CONFIG_AUTO
53684+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
53685+ help
53686+ If you say Y here, you will be able to select a group that will be
53687+ able to view all processes and network-related information. If you've
53688+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
53689+ remain hidden. This option is useful if you want to run identd as
53690+ a non-root user. The group you select may also be chosen at boot time
53691+ via "grsec_proc_gid=" on the kernel commandline.
53692+
53693+config GRKERNSEC_PROC_GID
53694+ int "GID for special group"
53695+ depends on GRKERNSEC_PROC_USERGROUP
53696+ default 1001
53697+
53698+config GRKERNSEC_PROC_ADD
53699+ bool "Additional restrictions"
53700+ default y if GRKERNSEC_CONFIG_AUTO
53701+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
53702+ help
53703+ If you say Y here, additional restrictions will be placed on
53704+ /proc that keep normal users from viewing device information and
53705+ slabinfo information that could be useful for exploits.
53706+
53707+config GRKERNSEC_LINK
53708+ bool "Linking restrictions"
53709+ default y if GRKERNSEC_CONFIG_AUTO
53710+ help
53711+ If you say Y here, /tmp race exploits will be prevented, since users
53712+ will no longer be able to follow symlinks owned by other users in
53713+ world-writable +t directories (e.g. /tmp), unless the owner of the
53714+ symlink is the owner of the directory. users will also not be
53715+ able to hardlink to files they do not own. If the sysctl option is
53716+ enabled, a sysctl option with name "linking_restrictions" is created.
53717+
53718+config GRKERNSEC_SYMLINKOWN
53719+ bool "Kernel-enforced SymlinksIfOwnerMatch"
53720+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
53721+ help
53722+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
53723+ that prevents it from being used as a security feature. As Apache
53724+ verifies the symlink by performing a stat() against the target of
53725+ the symlink before it is followed, an attacker can setup a symlink
53726+ to point to a same-owned file, then replace the symlink with one
53727+ that targets another user's file just after Apache "validates" the
53728+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
53729+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
53730+ will be in place for the group you specify. If the sysctl option
53731+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
53732+ created.
53733+
53734+config GRKERNSEC_SYMLINKOWN_GID
53735+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
53736+ depends on GRKERNSEC_SYMLINKOWN
53737+ default 1006
53738+ help
53739+ Setting this GID determines what group kernel-enforced
53740+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
53741+ is enabled, a sysctl option with name "symlinkown_gid" is created.
53742+
53743+config GRKERNSEC_FIFO
53744+ bool "FIFO restrictions"
53745+ default y if GRKERNSEC_CONFIG_AUTO
53746+ help
53747+ If you say Y here, users will not be able to write to FIFOs they don't
53748+ own in world-writable +t directories (e.g. /tmp), unless the owner of
53749+ the FIFO is the same owner of the directory it's held in. If the sysctl
53750+ option is enabled, a sysctl option with name "fifo_restrictions" is
53751+ created.
53752+
53753+config GRKERNSEC_SYSFS_RESTRICT
53754+ bool "Sysfs/debugfs restriction"
53755+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53756+ depends on SYSFS
53757+ help
53758+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
53759+ any filesystem normally mounted under it (e.g. debugfs) will be
53760+ mostly accessible only by root. These filesystems generally provide access
53761+ to hardware and debug information that isn't appropriate for unprivileged
53762+ users of the system. Sysfs and debugfs have also become a large source
53763+ of new vulnerabilities, ranging from infoleaks to local compromise.
53764+ There has been very little oversight with an eye toward security involved
53765+ in adding new exporters of information to these filesystems, so their
53766+ use is discouraged.
53767+ For reasons of compatibility, a few directories have been whitelisted
53768+ for access by non-root users:
53769+ /sys/fs/selinux
53770+ /sys/fs/fuse
53771+ /sys/devices/system/cpu
53772+
53773+config GRKERNSEC_ROFS
53774+ bool "Runtime read-only mount protection"
53775+ help
53776+ If you say Y here, a sysctl option with name "romount_protect" will
53777+ be created. By setting this option to 1 at runtime, filesystems
53778+ will be protected in the following ways:
53779+ * No new writable mounts will be allowed
53780+ * Existing read-only mounts won't be able to be remounted read/write
53781+ * Write operations will be denied on all block devices
53782+ This option acts independently of grsec_lock: once it is set to 1,
53783+ it cannot be turned off. Therefore, please be mindful of the resulting
53784+ behavior if this option is enabled in an init script on a read-only
53785+ filesystem. This feature is mainly intended for secure embedded systems.
53786+
53787+config GRKERNSEC_DEVICE_SIDECHANNEL
53788+ bool "Eliminate stat/notify-based device sidechannels"
53789+ default y if GRKERNSEC_CONFIG_AUTO
53790+ help
53791+ If you say Y here, timing analyses on block or character
53792+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
53793+ will be thwarted for unprivileged users. If a process without
53794+ CAP_MKNOD stats such a device, the last access and last modify times
53795+ will match the device's create time. No access or modify events
53796+ will be triggered through inotify/dnotify/fanotify for such devices.
53797+ This feature will prevent attacks that may at a minimum
53798+ allow an attacker to determine the administrator's password length.
53799+
53800+config GRKERNSEC_CHROOT
53801+ bool "Chroot jail restrictions"
53802+ default y if GRKERNSEC_CONFIG_AUTO
53803+ help
53804+ If you say Y here, you will be able to choose several options that will
53805+ make breaking out of a chrooted jail much more difficult. If you
53806+ encounter no software incompatibilities with the following options, it
53807+ is recommended that you enable each one.
53808+
53809+config GRKERNSEC_CHROOT_MOUNT
53810+ bool "Deny mounts"
53811+ default y if GRKERNSEC_CONFIG_AUTO
53812+ depends on GRKERNSEC_CHROOT
53813+ help
53814+ If you say Y here, processes inside a chroot will not be able to
53815+ mount or remount filesystems. If the sysctl option is enabled, a
53816+ sysctl option with name "chroot_deny_mount" is created.
53817+
53818+config GRKERNSEC_CHROOT_DOUBLE
53819+ bool "Deny double-chroots"
53820+ default y if GRKERNSEC_CONFIG_AUTO
53821+ depends on GRKERNSEC_CHROOT
53822+ help
53823+ If you say Y here, processes inside a chroot will not be able to chroot
53824+ again outside the chroot. This is a widely used method of breaking
53825+ out of a chroot jail and should not be allowed. If the sysctl
53826+ option is enabled, a sysctl option with name
53827+ "chroot_deny_chroot" is created.
53828+
53829+config GRKERNSEC_CHROOT_PIVOT
53830+ bool "Deny pivot_root in chroot"
53831+ default y if GRKERNSEC_CONFIG_AUTO
53832+ depends on GRKERNSEC_CHROOT
53833+ help
53834+ If you say Y here, processes inside a chroot will not be able to use
53835+ a function called pivot_root() that was introduced in Linux 2.3.41. It
53836+ works similar to chroot in that it changes the root filesystem. This
53837+ function could be misused in a chrooted process to attempt to break out
53838+ of the chroot, and therefore should not be allowed. If the sysctl
53839+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
53840+ created.
53841+
53842+config GRKERNSEC_CHROOT_CHDIR
53843+ bool "Enforce chdir(\"/\") on all chroots"
53844+ default y if GRKERNSEC_CONFIG_AUTO
53845+ depends on GRKERNSEC_CHROOT
53846+ help
53847+ If you say Y here, the current working directory of all newly-chrooted
53848+ applications will be set to the the root directory of the chroot.
53849+ The man page on chroot(2) states:
53850+ Note that this call does not change the current working
53851+ directory, so that `.' can be outside the tree rooted at
53852+ `/'. In particular, the super-user can escape from a
53853+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
53854+
53855+ It is recommended that you say Y here, since it's not known to break
53856+ any software. If the sysctl option is enabled, a sysctl option with
53857+ name "chroot_enforce_chdir" is created.
53858+
53859+config GRKERNSEC_CHROOT_CHMOD
53860+ bool "Deny (f)chmod +s"
53861+ default y if GRKERNSEC_CONFIG_AUTO
53862+ depends on GRKERNSEC_CHROOT
53863+ help
53864+ If you say Y here, processes inside a chroot will not be able to chmod
53865+ or fchmod files to make them have suid or sgid bits. This protects
53866+ against another published method of breaking a chroot. If the sysctl
53867+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
53868+ created.
53869+
53870+config GRKERNSEC_CHROOT_FCHDIR
53871+ bool "Deny fchdir out of chroot"
53872+ default y if GRKERNSEC_CONFIG_AUTO
53873+ depends on GRKERNSEC_CHROOT
53874+ help
53875+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
53876+ to a file descriptor of the chrooting process that points to a directory
53877+ outside the filesystem will be stopped. If the sysctl option
53878+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
53879+
53880+config GRKERNSEC_CHROOT_MKNOD
53881+ bool "Deny mknod"
53882+ default y if GRKERNSEC_CONFIG_AUTO
53883+ depends on GRKERNSEC_CHROOT
53884+ help
53885+ If you say Y here, processes inside a chroot will not be allowed to
53886+ mknod. The problem with using mknod inside a chroot is that it
53887+ would allow an attacker to create a device entry that is the same
53888+ as one on the physical root of your system, which could range from
53889+ anything from the console device to a device for your harddrive (which
53890+ they could then use to wipe the drive or steal data). It is recommended
53891+ that you say Y here, unless you run into software incompatibilities.
53892+ If the sysctl option is enabled, a sysctl option with name
53893+ "chroot_deny_mknod" is created.
53894+
53895+config GRKERNSEC_CHROOT_SHMAT
53896+ bool "Deny shmat() out of chroot"
53897+ default y if GRKERNSEC_CONFIG_AUTO
53898+ depends on GRKERNSEC_CHROOT
53899+ help
53900+ If you say Y here, processes inside a chroot will not be able to attach
53901+ to shared memory segments that were created outside of the chroot jail.
53902+ It is recommended that you say Y here. If the sysctl option is enabled,
53903+ a sysctl option with name "chroot_deny_shmat" is created.
53904+
53905+config GRKERNSEC_CHROOT_UNIX
53906+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
53907+ default y if GRKERNSEC_CONFIG_AUTO
53908+ depends on GRKERNSEC_CHROOT
53909+ help
53910+ If you say Y here, processes inside a chroot will not be able to
53911+ connect to abstract (meaning not belonging to a filesystem) Unix
53912+ domain sockets that were bound outside of a chroot. It is recommended
53913+ that you say Y here. If the sysctl option is enabled, a sysctl option
53914+ with name "chroot_deny_unix" is created.
53915+
53916+config GRKERNSEC_CHROOT_FINDTASK
53917+ bool "Protect outside processes"
53918+ default y if GRKERNSEC_CONFIG_AUTO
53919+ depends on GRKERNSEC_CHROOT
53920+ help
53921+ If you say Y here, processes inside a chroot will not be able to
53922+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
53923+ getsid, or view any process outside of the chroot. If the sysctl
53924+ option is enabled, a sysctl option with name "chroot_findtask" is
53925+ created.
53926+
53927+config GRKERNSEC_CHROOT_NICE
53928+ bool "Restrict priority changes"
53929+ default y if GRKERNSEC_CONFIG_AUTO
53930+ depends on GRKERNSEC_CHROOT
53931+ help
53932+ If you say Y here, processes inside a chroot will not be able to raise
53933+ the priority of processes in the chroot, or alter the priority of
53934+ processes outside the chroot. This provides more security than simply
53935+ removing CAP_SYS_NICE from the process' capability set. If the
53936+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
53937+ is created.
53938+
53939+config GRKERNSEC_CHROOT_SYSCTL
53940+ bool "Deny sysctl writes"
53941+ default y if GRKERNSEC_CONFIG_AUTO
53942+ depends on GRKERNSEC_CHROOT
53943+ help
53944+ If you say Y here, an attacker in a chroot will not be able to
53945+ write to sysctl entries, either by sysctl(2) or through a /proc
53946+ interface. It is strongly recommended that you say Y here. If the
53947+ sysctl option is enabled, a sysctl option with name
53948+ "chroot_deny_sysctl" is created.
53949+
53950+config GRKERNSEC_CHROOT_CAPS
53951+ bool "Capability restrictions"
53952+ default y if GRKERNSEC_CONFIG_AUTO
53953+ depends on GRKERNSEC_CHROOT
53954+ help
53955+ If you say Y here, the capabilities on all processes within a
53956+ chroot jail will be lowered to stop module insertion, raw i/o,
53957+ system and net admin tasks, rebooting the system, modifying immutable
53958+ files, modifying IPC owned by another, and changing the system time.
53959+ This is left an option because it can break some apps. Disable this
53960+ if your chrooted apps are having problems performing those kinds of
53961+ tasks. If the sysctl option is enabled, a sysctl option with
53962+ name "chroot_caps" is created.
53963+
53964+endmenu
53965+menu "Kernel Auditing"
53966+depends on GRKERNSEC
53967+
53968+config GRKERNSEC_AUDIT_GROUP
53969+ bool "Single group for auditing"
53970+ help
53971+ If you say Y here, the exec and chdir logging features will only operate
53972+ on a group you specify. This option is recommended if you only want to
53973+ watch certain users instead of having a large amount of logs from the
53974+ entire system. If the sysctl option is enabled, a sysctl option with
53975+ name "audit_group" is created.
53976+
53977+config GRKERNSEC_AUDIT_GID
53978+ int "GID for auditing"
53979+ depends on GRKERNSEC_AUDIT_GROUP
53980+ default 1007
53981+
53982+config GRKERNSEC_EXECLOG
53983+ bool "Exec logging"
53984+ help
53985+ If you say Y here, all execve() calls will be logged (since the
53986+ other exec*() calls are frontends to execve(), all execution
53987+ will be logged). Useful for shell-servers that like to keep track
53988+ of their users. If the sysctl option is enabled, a sysctl option with
53989+ name "exec_logging" is created.
53990+ WARNING: This option when enabled will produce a LOT of logs, especially
53991+ on an active system.
53992+
53993+config GRKERNSEC_RESLOG
53994+ bool "Resource logging"
53995+ default y if GRKERNSEC_CONFIG_AUTO
53996+ help
53997+ If you say Y here, all attempts to overstep resource limits will
53998+ be logged with the resource name, the requested size, and the current
53999+ limit. It is highly recommended that you say Y here. If the sysctl
54000+ option is enabled, a sysctl option with name "resource_logging" is
54001+ created. If the RBAC system is enabled, the sysctl value is ignored.
54002+
54003+config GRKERNSEC_CHROOT_EXECLOG
54004+ bool "Log execs within chroot"
54005+ help
54006+ If you say Y here, all executions inside a chroot jail will be logged
54007+ to syslog. This can cause a large amount of logs if certain
54008+ applications (eg. djb's daemontools) are installed on the system, and
54009+ is therefore left as an option. If the sysctl option is enabled, a
54010+ sysctl option with name "chroot_execlog" is created.
54011+
54012+config GRKERNSEC_AUDIT_PTRACE
54013+ bool "Ptrace logging"
54014+ help
54015+ If you say Y here, all attempts to attach to a process via ptrace
54016+ will be logged. If the sysctl option is enabled, a sysctl option
54017+ with name "audit_ptrace" is created.
54018+
54019+config GRKERNSEC_AUDIT_CHDIR
54020+ bool "Chdir logging"
54021+ help
54022+ If you say Y here, all chdir() calls will be logged. If the sysctl
54023+ option is enabled, a sysctl option with name "audit_chdir" is created.
54024+
54025+config GRKERNSEC_AUDIT_MOUNT
54026+ bool "(Un)Mount logging"
54027+ help
54028+ If you say Y here, all mounts and unmounts will be logged. If the
54029+ sysctl option is enabled, a sysctl option with name "audit_mount" is
54030+ created.
54031+
54032+config GRKERNSEC_SIGNAL
54033+ bool "Signal logging"
54034+ default y if GRKERNSEC_CONFIG_AUTO
54035+ help
54036+ If you say Y here, certain important signals will be logged, such as
54037+ SIGSEGV, which will as a result inform you of when a error in a program
54038+ occurred, which in some cases could mean a possible exploit attempt.
54039+ If the sysctl option is enabled, a sysctl option with name
54040+ "signal_logging" is created.
54041+
54042+config GRKERNSEC_FORKFAIL
54043+ bool "Fork failure logging"
54044+ help
54045+ If you say Y here, all failed fork() attempts will be logged.
54046+ This could suggest a fork bomb, or someone attempting to overstep
54047+ their process limit. If the sysctl option is enabled, a sysctl option
54048+ with name "forkfail_logging" is created.
54049+
54050+config GRKERNSEC_TIME
54051+ bool "Time change logging"
54052+ default y if GRKERNSEC_CONFIG_AUTO
54053+ help
54054+ If you say Y here, any changes of the system clock will be logged.
54055+ If the sysctl option is enabled, a sysctl option with name
54056+ "timechange_logging" is created.
54057+
54058+config GRKERNSEC_PROC_IPADDR
54059+ bool "/proc/<pid>/ipaddr support"
54060+ default y if GRKERNSEC_CONFIG_AUTO
54061+ help
54062+ If you say Y here, a new entry will be added to each /proc/<pid>
54063+ directory that contains the IP address of the person using the task.
54064+ The IP is carried across local TCP and AF_UNIX stream sockets.
54065+ This information can be useful for IDS/IPSes to perform remote response
54066+ to a local attack. The entry is readable by only the owner of the
54067+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
54068+ the RBAC system), and thus does not create privacy concerns.
54069+
54070+config GRKERNSEC_RWXMAP_LOG
54071+ bool 'Denied RWX mmap/mprotect logging'
54072+ default y if GRKERNSEC_CONFIG_AUTO
54073+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
54074+ help
54075+ If you say Y here, calls to mmap() and mprotect() with explicit
54076+ usage of PROT_WRITE and PROT_EXEC together will be logged when
54077+ denied by the PAX_MPROTECT feature. If the sysctl option is
54078+ enabled, a sysctl option with name "rwxmap_logging" is created.
54079+
54080+config GRKERNSEC_AUDIT_TEXTREL
54081+ bool 'ELF text relocations logging (READ HELP)'
54082+ depends on PAX_MPROTECT
54083+ help
54084+ If you say Y here, text relocations will be logged with the filename
54085+ of the offending library or binary. The purpose of the feature is
54086+ to help Linux distribution developers get rid of libraries and
54087+ binaries that need text relocations which hinder the future progress
54088+ of PaX. Only Linux distribution developers should say Y here, and
54089+ never on a production machine, as this option creates an information
54090+ leak that could aid an attacker in defeating the randomization of
54091+ a single memory region. If the sysctl option is enabled, a sysctl
54092+ option with name "audit_textrel" is created.
54093+
54094+endmenu
54095+
54096+menu "Executable Protections"
54097+depends on GRKERNSEC
54098+
54099+config GRKERNSEC_DMESG
54100+ bool "Dmesg(8) restriction"
54101+ default y if GRKERNSEC_CONFIG_AUTO
54102+ help
54103+ If you say Y here, non-root users will not be able to use dmesg(8)
54104+ to view the contents of the kernel's circular log buffer.
54105+ The kernel's log buffer often contains kernel addresses and other
54106+ identifying information useful to an attacker in fingerprinting a
54107+ system for a targeted exploit.
54108+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
54109+ created.
54110+
54111+config GRKERNSEC_HARDEN_PTRACE
54112+ bool "Deter ptrace-based process snooping"
54113+ default y if GRKERNSEC_CONFIG_AUTO
54114+ help
54115+ If you say Y here, TTY sniffers and other malicious monitoring
54116+ programs implemented through ptrace will be defeated. If you
54117+ have been using the RBAC system, this option has already been
54118+ enabled for several years for all users, with the ability to make
54119+ fine-grained exceptions.
54120+
54121+ This option only affects the ability of non-root users to ptrace
54122+ processes that are not a descendent of the ptracing process.
54123+ This means that strace ./binary and gdb ./binary will still work,
54124+ but attaching to arbitrary processes will not. If the sysctl
54125+ option is enabled, a sysctl option with name "harden_ptrace" is
54126+ created.
54127+
54128+config GRKERNSEC_PTRACE_READEXEC
54129+ bool "Require read access to ptrace sensitive binaries"
54130+ default y if GRKERNSEC_CONFIG_AUTO
54131+ help
54132+ If you say Y here, unprivileged users will not be able to ptrace unreadable
54133+ binaries. This option is useful in environments that
54134+ remove the read bits (e.g. file mode 4711) from suid binaries to
54135+ prevent infoleaking of their contents. This option adds
54136+ consistency to the use of that file mode, as the binary could normally
54137+ be read out when run without privileges while ptracing.
54138+
54139+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
54140+ is created.
54141+
54142+config GRKERNSEC_SETXID
54143+ bool "Enforce consistent multithreaded privileges"
54144+ default y if GRKERNSEC_CONFIG_AUTO
54145+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
54146+ help
54147+ If you say Y here, a change from a root uid to a non-root uid
54148+ in a multithreaded application will cause the resulting uids,
54149+ gids, supplementary groups, and capabilities in that thread
54150+ to be propagated to the other threads of the process. In most
54151+ cases this is unnecessary, as glibc will emulate this behavior
54152+ on behalf of the application. Other libcs do not act in the
54153+ same way, allowing the other threads of the process to continue
54154+ running with root privileges. If the sysctl option is enabled,
54155+ a sysctl option with name "consistent_setxid" is created.
54156+
54157+config GRKERNSEC_TPE
54158+ bool "Trusted Path Execution (TPE)"
54159+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
54160+ help
54161+ If you say Y here, you will be able to choose a gid to add to the
54162+ supplementary groups of users you want to mark as "untrusted."
54163+ These users will not be able to execute any files that are not in
54164+ root-owned directories writable only by root. If the sysctl option
54165+ is enabled, a sysctl option with name "tpe" is created.
54166+
54167+config GRKERNSEC_TPE_ALL
54168+ bool "Partially restrict all non-root users"
54169+ depends on GRKERNSEC_TPE
54170+ help
54171+ If you say Y here, all non-root users will be covered under
54172+ a weaker TPE restriction. This is separate from, and in addition to,
54173+ the main TPE options that you have selected elsewhere. Thus, if a
54174+ "trusted" GID is chosen, this restriction applies to even that GID.
54175+ Under this restriction, all non-root users will only be allowed to
54176+ execute files in directories they own that are not group or
54177+ world-writable, or in directories owned by root and writable only by
54178+ root. If the sysctl option is enabled, a sysctl option with name
54179+ "tpe_restrict_all" is created.
54180+
54181+config GRKERNSEC_TPE_INVERT
54182+ bool "Invert GID option"
54183+ depends on GRKERNSEC_TPE
54184+ help
54185+ If you say Y here, the group you specify in the TPE configuration will
54186+ decide what group TPE restrictions will be *disabled* for. This
54187+ option is useful if you want TPE restrictions to be applied to most
54188+ users on the system. If the sysctl option is enabled, a sysctl option
54189+ with name "tpe_invert" is created. Unlike other sysctl options, this
54190+ entry will default to on for backward-compatibility.
54191+
54192+config GRKERNSEC_TPE_GID
54193+ int
54194+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
54195+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
54196+
54197+config GRKERNSEC_TPE_UNTRUSTED_GID
54198+ int "GID for TPE-untrusted users"
54199+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
54200+ default 1005
54201+ help
54202+ Setting this GID determines what group TPE restrictions will be
54203+ *enabled* for. If the sysctl option is enabled, a sysctl option
54204+ with name "tpe_gid" is created.
54205+
54206+config GRKERNSEC_TPE_TRUSTED_GID
54207+ int "GID for TPE-trusted users"
54208+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
54209+ default 1005
54210+ help
54211+ Setting this GID determines what group TPE restrictions will be
54212+ *disabled* for. If the sysctl option is enabled, a sysctl option
54213+ with name "tpe_gid" is created.
54214+
54215+endmenu
54216+menu "Network Protections"
54217+depends on GRKERNSEC
54218+
54219+config GRKERNSEC_RANDNET
54220+ bool "Larger entropy pools"
54221+ default y if GRKERNSEC_CONFIG_AUTO
54222+ help
54223+ If you say Y here, the entropy pools used for many features of Linux
54224+ and grsecurity will be doubled in size. Since several grsecurity
54225+ features use additional randomness, it is recommended that you say Y
54226+ here. Saying Y here has a similar effect as modifying
54227+ /proc/sys/kernel/random/poolsize.
54228+
54229+config GRKERNSEC_BLACKHOLE
54230+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
54231+ default y if GRKERNSEC_CONFIG_AUTO
54232+ depends on NET
54233+ help
54234+ If you say Y here, neither TCP resets nor ICMP
54235+ destination-unreachable packets will be sent in response to packets
54236+ sent to ports for which no associated listening process exists.
54237+ This feature supports both IPV4 and IPV6 and exempts the
54238+ loopback interface from blackholing. Enabling this feature
54239+ makes a host more resilient to DoS attacks and reduces network
54240+ visibility against scanners.
54241+
54242+ The blackhole feature as-implemented is equivalent to the FreeBSD
54243+ blackhole feature, as it prevents RST responses to all packets, not
54244+ just SYNs. Under most application behavior this causes no
54245+ problems, but applications (like haproxy) may not close certain
54246+ connections in a way that cleanly terminates them on the remote
54247+ end, leaving the remote host in LAST_ACK state. Because of this
54248+ side-effect and to prevent intentional LAST_ACK DoSes, this
54249+ feature also adds automatic mitigation against such attacks.
54250+ The mitigation drastically reduces the amount of time a socket
54251+ can spend in LAST_ACK state. If you're using haproxy and not
54252+ all servers it connects to have this option enabled, consider
54253+ disabling this feature on the haproxy host.
54254+
54255+ If the sysctl option is enabled, two sysctl options with names
54256+ "ip_blackhole" and "lastack_retries" will be created.
54257+ While "ip_blackhole" takes the standard zero/non-zero on/off
54258+ toggle, "lastack_retries" uses the same kinds of values as
54259+ "tcp_retries1" and "tcp_retries2". The default value of 4
54260+ prevents a socket from lasting more than 45 seconds in LAST_ACK
54261+ state.
54262+
54263+config GRKERNSEC_NO_SIMULT_CONNECT
54264+ bool "Disable TCP Simultaneous Connect"
54265+ default y if GRKERNSEC_CONFIG_AUTO
54266+ depends on NET
54267+ help
54268+ If you say Y here, a feature by Willy Tarreau will be enabled that
54269+ removes a weakness in Linux's strict implementation of TCP that
54270+ allows two clients to connect to each other without either entering
54271+ a listening state. The weakness allows an attacker to easily prevent
54272+ a client from connecting to a known server provided the source port
54273+ for the connection is guessed correctly.
54274+
54275+ As the weakness could be used to prevent an antivirus or IPS from
54276+ fetching updates, or prevent an SSL gateway from fetching a CRL,
54277+ it should be eliminated by enabling this option. Though Linux is
54278+ one of few operating systems supporting simultaneous connect, it
54279+ has no legitimate use in practice and is rarely supported by firewalls.
54280+
54281+config GRKERNSEC_SOCKET
54282+ bool "Socket restrictions"
54283+ depends on NET
54284+ help
54285+ If you say Y here, you will be able to choose from several options.
54286+ If you assign a GID on your system and add it to the supplementary
54287+ groups of users you want to restrict socket access to, this patch
54288+ will perform up to three things, based on the option(s) you choose.
54289+
54290+config GRKERNSEC_SOCKET_ALL
54291+ bool "Deny any sockets to group"
54292+ depends on GRKERNSEC_SOCKET
54293+ help
54294+ If you say Y here, you will be able to choose a GID of whose users will
54295+ be unable to connect to other hosts from your machine or run server
54296+ applications from your machine. If the sysctl option is enabled, a
54297+ sysctl option with name "socket_all" is created.
54298+
54299+config GRKERNSEC_SOCKET_ALL_GID
54300+ int "GID to deny all sockets for"
54301+ depends on GRKERNSEC_SOCKET_ALL
54302+ default 1004
54303+ help
54304+ Here you can choose the GID to disable socket access for. Remember to
54305+ add the users you want socket access disabled for to the GID
54306+ specified here. If the sysctl option is enabled, a sysctl option
54307+ with name "socket_all_gid" is created.
54308+
54309+config GRKERNSEC_SOCKET_CLIENT
54310+ bool "Deny client sockets to group"
54311+ depends on GRKERNSEC_SOCKET
54312+ help
54313+ If you say Y here, you will be able to choose a GID of whose users will
54314+ be unable to connect to other hosts from your machine, but will be
54315+ able to run servers. If this option is enabled, all users in the group
54316+ you specify will have to use passive mode when initiating ftp transfers
54317+ from the shell on your machine. If the sysctl option is enabled, a
54318+ sysctl option with name "socket_client" is created.
54319+
54320+config GRKERNSEC_SOCKET_CLIENT_GID
54321+ int "GID to deny client sockets for"
54322+ depends on GRKERNSEC_SOCKET_CLIENT
54323+ default 1003
54324+ help
54325+ Here you can choose the GID to disable client socket access for.
54326+ Remember to add the users you want client socket access disabled for to
54327+ the GID specified here. If the sysctl option is enabled, a sysctl
54328+ option with name "socket_client_gid" is created.
54329+
54330+config GRKERNSEC_SOCKET_SERVER
54331+ bool "Deny server sockets to group"
54332+ depends on GRKERNSEC_SOCKET
54333+ help
54334+ If you say Y here, you will be able to choose a GID of whose users will
54335+ be unable to run server applications from your machine. If the sysctl
54336+ option is enabled, a sysctl option with name "socket_server" is created.
54337+
54338+config GRKERNSEC_SOCKET_SERVER_GID
54339+ int "GID to deny server sockets for"
54340+ depends on GRKERNSEC_SOCKET_SERVER
54341+ default 1002
54342+ help
54343+ Here you can choose the GID to disable server socket access for.
54344+ Remember to add the users you want server socket access disabled for to
54345+ the GID specified here. If the sysctl option is enabled, a sysctl
54346+ option with name "socket_server_gid" is created.
54347+
54348+endmenu
54349+menu "Sysctl Support"
54350+depends on GRKERNSEC && SYSCTL
54351+
54352+config GRKERNSEC_SYSCTL
54353+ bool "Sysctl support"
54354+ default y if GRKERNSEC_CONFIG_AUTO
54355+ help
54356+ If you say Y here, you will be able to change the options that
54357+ grsecurity runs with at bootup, without having to recompile your
54358+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
54359+ to enable (1) or disable (0) various features. All the sysctl entries
54360+ are mutable until the "grsec_lock" entry is set to a non-zero value.
54361+ All features enabled in the kernel configuration are disabled at boot
54362+ if you do not say Y to the "Turn on features by default" option.
54363+ All options should be set at startup, and the grsec_lock entry should
54364+ be set to a non-zero value after all the options are set.
54365+ *THIS IS EXTREMELY IMPORTANT*
54366+
54367+config GRKERNSEC_SYSCTL_DISTRO
54368+ bool "Extra sysctl support for distro makers (READ HELP)"
54369+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
54370+ help
54371+ If you say Y here, additional sysctl options will be created
54372+ for features that affect processes running as root. Therefore,
54373+ it is critical when using this option that the grsec_lock entry be
54374+ enabled after boot. Only distros with prebuilt kernel packages
54375+ with this option enabled that can ensure grsec_lock is enabled
54376+ after boot should use this option.
54377+ *Failure to set grsec_lock after boot makes all grsec features
54378+ this option covers useless*
54379+
54380+ Currently this option creates the following sysctl entries:
54381+ "Disable Privileged I/O": "disable_priv_io"
54382+
54383+config GRKERNSEC_SYSCTL_ON
54384+ bool "Turn on features by default"
54385+ default y if GRKERNSEC_CONFIG_AUTO
54386+ depends on GRKERNSEC_SYSCTL
54387+ help
54388+ If you say Y here, instead of having all features enabled in the
54389+ kernel configuration disabled at boot time, the features will be
54390+ enabled at boot time. It is recommended you say Y here unless
54391+ there is some reason you would want all sysctl-tunable features to
54392+ be disabled by default. As mentioned elsewhere, it is important
54393+ to enable the grsec_lock entry once you have finished modifying
54394+ the sysctl entries.
54395+
54396+endmenu
54397+menu "Logging Options"
54398+depends on GRKERNSEC
54399+
54400+config GRKERNSEC_FLOODTIME
54401+ int "Seconds in between log messages (minimum)"
54402+ default 10
54403+ help
54404+ This option allows you to enforce the number of seconds between
54405+ grsecurity log messages. The default should be suitable for most
54406+ people, however, if you choose to change it, choose a value small enough
54407+ to allow informative logs to be produced, but large enough to
54408+ prevent flooding.
54409+
54410+config GRKERNSEC_FLOODBURST
54411+ int "Number of messages in a burst (maximum)"
54412+ default 6
54413+ help
54414+ This option allows you to choose the maximum number of messages allowed
54415+ within the flood time interval you chose in a separate option. The
54416+ default should be suitable for most people, however if you find that
54417+ many of your logs are being interpreted as flooding, you may want to
54418+ raise this value.
54419+
54420+endmenu
54421diff --git a/grsecurity/Makefile b/grsecurity/Makefile
54422new file mode 100644
54423index 0000000..1b9afa9
54424--- /dev/null
54425+++ b/grsecurity/Makefile
54426@@ -0,0 +1,38 @@
54427+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
54428+# during 2001-2009 it has been completely redesigned by Brad Spengler
54429+# into an RBAC system
54430+#
54431+# All code in this directory and various hooks inserted throughout the kernel
54432+# are copyright Brad Spengler - Open Source Security, Inc., and released
54433+# under the GPL v2 or higher
54434+
54435+KBUILD_CFLAGS += -Werror
54436+
54437+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
54438+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
54439+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
54440+
54441+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
54442+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
54443+ gracl_learn.o grsec_log.o
54444+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
54445+
54446+ifdef CONFIG_NET
54447+obj-y += grsec_sock.o
54448+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
54449+endif
54450+
54451+ifndef CONFIG_GRKERNSEC
54452+obj-y += grsec_disabled.o
54453+endif
54454+
54455+ifdef CONFIG_GRKERNSEC_HIDESYM
54456+extra-y := grsec_hidesym.o
54457+$(obj)/grsec_hidesym.o:
54458+ @-chmod -f 500 /boot
54459+ @-chmod -f 500 /lib/modules
54460+ @-chmod -f 500 /lib64/modules
54461+ @-chmod -f 500 /lib32/modules
54462+ @-chmod -f 700 .
54463+ @echo ' grsec: protected kernel image paths'
54464+endif
54465diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
54466new file mode 100644
54467index 0000000..69e1320
54468--- /dev/null
54469+++ b/grsecurity/gracl.c
54470@@ -0,0 +1,4019 @@
54471+#include <linux/kernel.h>
54472+#include <linux/module.h>
54473+#include <linux/sched.h>
54474+#include <linux/mm.h>
54475+#include <linux/file.h>
54476+#include <linux/fs.h>
54477+#include <linux/namei.h>
54478+#include <linux/mount.h>
54479+#include <linux/tty.h>
54480+#include <linux/proc_fs.h>
54481+#include <linux/lglock.h>
54482+#include <linux/slab.h>
54483+#include <linux/vmalloc.h>
54484+#include <linux/types.h>
54485+#include <linux/sysctl.h>
54486+#include <linux/netdevice.h>
54487+#include <linux/ptrace.h>
54488+#include <linux/gracl.h>
54489+#include <linux/gralloc.h>
54490+#include <linux/security.h>
54491+#include <linux/grinternal.h>
54492+#include <linux/pid_namespace.h>
54493+#include <linux/stop_machine.h>
54494+#include <linux/fdtable.h>
54495+#include <linux/percpu.h>
54496+#include <linux/lglock.h>
54497+#include <linux/hugetlb.h>
54498+#include "../fs/mount.h"
54499+
54500+#include <asm/uaccess.h>
54501+#include <asm/errno.h>
54502+#include <asm/mman.h>
54503+
54504+extern struct lglock vfsmount_lock;
54505+
54506+static struct acl_role_db acl_role_set;
54507+static struct name_db name_set;
54508+static struct inodev_db inodev_set;
54509+
54510+/* for keeping track of userspace pointers used for subjects, so we
54511+ can share references in the kernel as well
54512+*/
54513+
54514+static struct path real_root;
54515+
54516+static struct acl_subj_map_db subj_map_set;
54517+
54518+static struct acl_role_label *default_role;
54519+
54520+static struct acl_role_label *role_list;
54521+
54522+static u16 acl_sp_role_value;
54523+
54524+extern char *gr_shared_page[4];
54525+static DEFINE_MUTEX(gr_dev_mutex);
54526+DEFINE_RWLOCK(gr_inode_lock);
54527+
54528+struct gr_arg *gr_usermode;
54529+
54530+static unsigned int gr_status __read_only = GR_STATUS_INIT;
54531+
54532+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
54533+extern void gr_clear_learn_entries(void);
54534+
54535+unsigned char *gr_system_salt;
54536+unsigned char *gr_system_sum;
54537+
54538+static struct sprole_pw **acl_special_roles = NULL;
54539+static __u16 num_sprole_pws = 0;
54540+
54541+static struct acl_role_label *kernel_role = NULL;
54542+
54543+static unsigned int gr_auth_attempts = 0;
54544+static unsigned long gr_auth_expires = 0UL;
54545+
54546+#ifdef CONFIG_NET
54547+extern struct vfsmount *sock_mnt;
54548+#endif
54549+
54550+extern struct vfsmount *pipe_mnt;
54551+extern struct vfsmount *shm_mnt;
54552+
54553+#ifdef CONFIG_HUGETLBFS
54554+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
54555+#endif
54556+
54557+static struct acl_object_label *fakefs_obj_rw;
54558+static struct acl_object_label *fakefs_obj_rwx;
54559+
54560+extern int gr_init_uidset(void);
54561+extern void gr_free_uidset(void);
54562+extern void gr_remove_uid(uid_t uid);
54563+extern int gr_find_uid(uid_t uid);
54564+
54565+__inline__ int
54566+gr_acl_is_enabled(void)
54567+{
54568+ return (gr_status & GR_READY);
54569+}
54570+
54571+#ifdef CONFIG_BTRFS_FS
54572+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
54573+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
54574+#endif
54575+
54576+static inline dev_t __get_dev(const struct dentry *dentry)
54577+{
54578+#ifdef CONFIG_BTRFS_FS
54579+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
54580+ return get_btrfs_dev_from_inode(dentry->d_inode);
54581+ else
54582+#endif
54583+ return dentry->d_inode->i_sb->s_dev;
54584+}
54585+
54586+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
54587+{
54588+ return __get_dev(dentry);
54589+}
54590+
54591+static char gr_task_roletype_to_char(struct task_struct *task)
54592+{
54593+ switch (task->role->roletype &
54594+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
54595+ GR_ROLE_SPECIAL)) {
54596+ case GR_ROLE_DEFAULT:
54597+ return 'D';
54598+ case GR_ROLE_USER:
54599+ return 'U';
54600+ case GR_ROLE_GROUP:
54601+ return 'G';
54602+ case GR_ROLE_SPECIAL:
54603+ return 'S';
54604+ }
54605+
54606+ return 'X';
54607+}
54608+
54609+char gr_roletype_to_char(void)
54610+{
54611+ return gr_task_roletype_to_char(current);
54612+}
54613+
54614+__inline__ int
54615+gr_acl_tpe_check(void)
54616+{
54617+ if (unlikely(!(gr_status & GR_READY)))
54618+ return 0;
54619+ if (current->role->roletype & GR_ROLE_TPE)
54620+ return 1;
54621+ else
54622+ return 0;
54623+}
54624+
54625+int
54626+gr_handle_rawio(const struct inode *inode)
54627+{
54628+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54629+ if (inode && S_ISBLK(inode->i_mode) &&
54630+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
54631+ !capable(CAP_SYS_RAWIO))
54632+ return 1;
54633+#endif
54634+ return 0;
54635+}
54636+
54637+static int
54638+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
54639+{
54640+ if (likely(lena != lenb))
54641+ return 0;
54642+
54643+ return !memcmp(a, b, lena);
54644+}
54645+
54646+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
54647+{
54648+ *buflen -= namelen;
54649+ if (*buflen < 0)
54650+ return -ENAMETOOLONG;
54651+ *buffer -= namelen;
54652+ memcpy(*buffer, str, namelen);
54653+ return 0;
54654+}
54655+
54656+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
54657+{
54658+ return prepend(buffer, buflen, name->name, name->len);
54659+}
54660+
54661+static int prepend_path(const struct path *path, struct path *root,
54662+ char **buffer, int *buflen)
54663+{
54664+ struct dentry *dentry = path->dentry;
54665+ struct vfsmount *vfsmnt = path->mnt;
54666+ struct mount *mnt = real_mount(vfsmnt);
54667+ bool slash = false;
54668+ int error = 0;
54669+
54670+ while (dentry != root->dentry || vfsmnt != root->mnt) {
54671+ struct dentry * parent;
54672+
54673+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
54674+ /* Global root? */
54675+ if (!mnt_has_parent(mnt)) {
54676+ goto out;
54677+ }
54678+ dentry = mnt->mnt_mountpoint;
54679+ mnt = mnt->mnt_parent;
54680+ vfsmnt = &mnt->mnt;
54681+ continue;
54682+ }
54683+ parent = dentry->d_parent;
54684+ prefetch(parent);
54685+ spin_lock(&dentry->d_lock);
54686+ error = prepend_name(buffer, buflen, &dentry->d_name);
54687+ spin_unlock(&dentry->d_lock);
54688+ if (!error)
54689+ error = prepend(buffer, buflen, "/", 1);
54690+ if (error)
54691+ break;
54692+
54693+ slash = true;
54694+ dentry = parent;
54695+ }
54696+
54697+out:
54698+ if (!error && !slash)
54699+ error = prepend(buffer, buflen, "/", 1);
54700+
54701+ return error;
54702+}
54703+
54704+/* this must be called with vfsmount_lock and rename_lock held */
54705+
54706+static char *__our_d_path(const struct path *path, struct path *root,
54707+ char *buf, int buflen)
54708+{
54709+ char *res = buf + buflen;
54710+ int error;
54711+
54712+ prepend(&res, &buflen, "\0", 1);
54713+ error = prepend_path(path, root, &res, &buflen);
54714+ if (error)
54715+ return ERR_PTR(error);
54716+
54717+ return res;
54718+}
54719+
54720+static char *
54721+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
54722+{
54723+ char *retval;
54724+
54725+ retval = __our_d_path(path, root, buf, buflen);
54726+ if (unlikely(IS_ERR(retval)))
54727+ retval = strcpy(buf, "<path too long>");
54728+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
54729+ retval[1] = '\0';
54730+
54731+ return retval;
54732+}
54733+
54734+static char *
54735+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
54736+ char *buf, int buflen)
54737+{
54738+ struct path path;
54739+ char *res;
54740+
54741+ path.dentry = (struct dentry *)dentry;
54742+ path.mnt = (struct vfsmount *)vfsmnt;
54743+
54744+ /* we can use real_root.dentry, real_root.mnt, because this is only called
54745+ by the RBAC system */
54746+ res = gen_full_path(&path, &real_root, buf, buflen);
54747+
54748+ return res;
54749+}
54750+
54751+static char *
54752+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
54753+ char *buf, int buflen)
54754+{
54755+ char *res;
54756+ struct path path;
54757+ struct path root;
54758+ struct task_struct *reaper = init_pid_ns.child_reaper;
54759+
54760+ path.dentry = (struct dentry *)dentry;
54761+ path.mnt = (struct vfsmount *)vfsmnt;
54762+
54763+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
54764+ get_fs_root(reaper->fs, &root);
54765+
54766+ write_seqlock(&rename_lock);
54767+ br_read_lock(&vfsmount_lock);
54768+ res = gen_full_path(&path, &root, buf, buflen);
54769+ br_read_unlock(&vfsmount_lock);
54770+ write_sequnlock(&rename_lock);
54771+
54772+ path_put(&root);
54773+ return res;
54774+}
54775+
54776+static char *
54777+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
54778+{
54779+ char *ret;
54780+ write_seqlock(&rename_lock);
54781+ br_read_lock(&vfsmount_lock);
54782+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
54783+ PAGE_SIZE);
54784+ br_read_unlock(&vfsmount_lock);
54785+ write_sequnlock(&rename_lock);
54786+ return ret;
54787+}
54788+
54789+static char *
54790+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
54791+{
54792+ char *ret;
54793+ char *buf;
54794+ int buflen;
54795+
54796+ write_seqlock(&rename_lock);
54797+ br_read_lock(&vfsmount_lock);
54798+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54799+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
54800+ buflen = (int)(ret - buf);
54801+ if (buflen >= 5)
54802+ prepend(&ret, &buflen, "/proc", 5);
54803+ else
54804+ ret = strcpy(buf, "<path too long>");
54805+ br_read_unlock(&vfsmount_lock);
54806+ write_sequnlock(&rename_lock);
54807+ return ret;
54808+}
54809+
54810+char *
54811+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
54812+{
54813+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
54814+ PAGE_SIZE);
54815+}
54816+
54817+char *
54818+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
54819+{
54820+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54821+ PAGE_SIZE);
54822+}
54823+
54824+char *
54825+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
54826+{
54827+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
54828+ PAGE_SIZE);
54829+}
54830+
54831+char *
54832+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
54833+{
54834+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
54835+ PAGE_SIZE);
54836+}
54837+
54838+char *
54839+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
54840+{
54841+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
54842+ PAGE_SIZE);
54843+}
54844+
54845+__inline__ __u32
54846+to_gr_audit(const __u32 reqmode)
54847+{
54848+ /* masks off auditable permission flags, then shifts them to create
54849+ auditing flags, and adds the special case of append auditing if
54850+ we're requesting write */
54851+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
54852+}
54853+
54854+struct acl_subject_label *
54855+lookup_subject_map(const struct acl_subject_label *userp)
54856+{
54857+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
54858+ struct subject_map *match;
54859+
54860+ match = subj_map_set.s_hash[index];
54861+
54862+ while (match && match->user != userp)
54863+ match = match->next;
54864+
54865+ if (match != NULL)
54866+ return match->kernel;
54867+ else
54868+ return NULL;
54869+}
54870+
54871+static void
54872+insert_subj_map_entry(struct subject_map *subjmap)
54873+{
54874+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
54875+ struct subject_map **curr;
54876+
54877+ subjmap->prev = NULL;
54878+
54879+ curr = &subj_map_set.s_hash[index];
54880+ if (*curr != NULL)
54881+ (*curr)->prev = subjmap;
54882+
54883+ subjmap->next = *curr;
54884+ *curr = subjmap;
54885+
54886+ return;
54887+}
54888+
54889+static struct acl_role_label *
54890+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
54891+ const gid_t gid)
54892+{
54893+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
54894+ struct acl_role_label *match;
54895+ struct role_allowed_ip *ipp;
54896+ unsigned int x;
54897+ u32 curr_ip = task->signal->curr_ip;
54898+
54899+ task->signal->saved_ip = curr_ip;
54900+
54901+ match = acl_role_set.r_hash[index];
54902+
54903+ while (match) {
54904+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
54905+ for (x = 0; x < match->domain_child_num; x++) {
54906+ if (match->domain_children[x] == uid)
54907+ goto found;
54908+ }
54909+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
54910+ break;
54911+ match = match->next;
54912+ }
54913+found:
54914+ if (match == NULL) {
54915+ try_group:
54916+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
54917+ match = acl_role_set.r_hash[index];
54918+
54919+ while (match) {
54920+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
54921+ for (x = 0; x < match->domain_child_num; x++) {
54922+ if (match->domain_children[x] == gid)
54923+ goto found2;
54924+ }
54925+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
54926+ break;
54927+ match = match->next;
54928+ }
54929+found2:
54930+ if (match == NULL)
54931+ match = default_role;
54932+ if (match->allowed_ips == NULL)
54933+ return match;
54934+ else {
54935+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54936+ if (likely
54937+ ((ntohl(curr_ip) & ipp->netmask) ==
54938+ (ntohl(ipp->addr) & ipp->netmask)))
54939+ return match;
54940+ }
54941+ match = default_role;
54942+ }
54943+ } else if (match->allowed_ips == NULL) {
54944+ return match;
54945+ } else {
54946+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54947+ if (likely
54948+ ((ntohl(curr_ip) & ipp->netmask) ==
54949+ (ntohl(ipp->addr) & ipp->netmask)))
54950+ return match;
54951+ }
54952+ goto try_group;
54953+ }
54954+
54955+ return match;
54956+}
54957+
54958+struct acl_subject_label *
54959+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
54960+ const struct acl_role_label *role)
54961+{
54962+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54963+ struct acl_subject_label *match;
54964+
54965+ match = role->subj_hash[index];
54966+
54967+ while (match && (match->inode != ino || match->device != dev ||
54968+ (match->mode & GR_DELETED))) {
54969+ match = match->next;
54970+ }
54971+
54972+ if (match && !(match->mode & GR_DELETED))
54973+ return match;
54974+ else
54975+ return NULL;
54976+}
54977+
54978+struct acl_subject_label *
54979+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
54980+ const struct acl_role_label *role)
54981+{
54982+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54983+ struct acl_subject_label *match;
54984+
54985+ match = role->subj_hash[index];
54986+
54987+ while (match && (match->inode != ino || match->device != dev ||
54988+ !(match->mode & GR_DELETED))) {
54989+ match = match->next;
54990+ }
54991+
54992+ if (match && (match->mode & GR_DELETED))
54993+ return match;
54994+ else
54995+ return NULL;
54996+}
54997+
54998+static struct acl_object_label *
54999+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
55000+ const struct acl_subject_label *subj)
55001+{
55002+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
55003+ struct acl_object_label *match;
55004+
55005+ match = subj->obj_hash[index];
55006+
55007+ while (match && (match->inode != ino || match->device != dev ||
55008+ (match->mode & GR_DELETED))) {
55009+ match = match->next;
55010+ }
55011+
55012+ if (match && !(match->mode & GR_DELETED))
55013+ return match;
55014+ else
55015+ return NULL;
55016+}
55017+
55018+static struct acl_object_label *
55019+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
55020+ const struct acl_subject_label *subj)
55021+{
55022+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
55023+ struct acl_object_label *match;
55024+
55025+ match = subj->obj_hash[index];
55026+
55027+ while (match && (match->inode != ino || match->device != dev ||
55028+ !(match->mode & GR_DELETED))) {
55029+ match = match->next;
55030+ }
55031+
55032+ if (match && (match->mode & GR_DELETED))
55033+ return match;
55034+
55035+ match = subj->obj_hash[index];
55036+
55037+ while (match && (match->inode != ino || match->device != dev ||
55038+ (match->mode & GR_DELETED))) {
55039+ match = match->next;
55040+ }
55041+
55042+ if (match && !(match->mode & GR_DELETED))
55043+ return match;
55044+ else
55045+ return NULL;
55046+}
55047+
55048+static struct name_entry *
55049+lookup_name_entry(const char *name)
55050+{
55051+ unsigned int len = strlen(name);
55052+ unsigned int key = full_name_hash(name, len);
55053+ unsigned int index = key % name_set.n_size;
55054+ struct name_entry *match;
55055+
55056+ match = name_set.n_hash[index];
55057+
55058+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
55059+ match = match->next;
55060+
55061+ return match;
55062+}
55063+
55064+static struct name_entry *
55065+lookup_name_entry_create(const char *name)
55066+{
55067+ unsigned int len = strlen(name);
55068+ unsigned int key = full_name_hash(name, len);
55069+ unsigned int index = key % name_set.n_size;
55070+ struct name_entry *match;
55071+
55072+ match = name_set.n_hash[index];
55073+
55074+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
55075+ !match->deleted))
55076+ match = match->next;
55077+
55078+ if (match && match->deleted)
55079+ return match;
55080+
55081+ match = name_set.n_hash[index];
55082+
55083+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
55084+ match->deleted))
55085+ match = match->next;
55086+
55087+ if (match && !match->deleted)
55088+ return match;
55089+ else
55090+ return NULL;
55091+}
55092+
55093+static struct inodev_entry *
55094+lookup_inodev_entry(const ino_t ino, const dev_t dev)
55095+{
55096+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
55097+ struct inodev_entry *match;
55098+
55099+ match = inodev_set.i_hash[index];
55100+
55101+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
55102+ match = match->next;
55103+
55104+ return match;
55105+}
55106+
55107+static void
55108+insert_inodev_entry(struct inodev_entry *entry)
55109+{
55110+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
55111+ inodev_set.i_size);
55112+ struct inodev_entry **curr;
55113+
55114+ entry->prev = NULL;
55115+
55116+ curr = &inodev_set.i_hash[index];
55117+ if (*curr != NULL)
55118+ (*curr)->prev = entry;
55119+
55120+ entry->next = *curr;
55121+ *curr = entry;
55122+
55123+ return;
55124+}
55125+
55126+static void
55127+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
55128+{
55129+ unsigned int index =
55130+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
55131+ struct acl_role_label **curr;
55132+ struct acl_role_label *tmp, *tmp2;
55133+
55134+ curr = &acl_role_set.r_hash[index];
55135+
55136+ /* simple case, slot is empty, just set it to our role */
55137+ if (*curr == NULL) {
55138+ *curr = role;
55139+ } else {
55140+ /* example:
55141+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
55142+ 2 -> 3
55143+ */
55144+ /* first check to see if we can already be reached via this slot */
55145+ tmp = *curr;
55146+ while (tmp && tmp != role)
55147+ tmp = tmp->next;
55148+ if (tmp == role) {
55149+ /* we don't need to add ourselves to this slot's chain */
55150+ return;
55151+ }
55152+ /* we need to add ourselves to this chain, two cases */
55153+ if (role->next == NULL) {
55154+ /* simple case, append the current chain to our role */
55155+ role->next = *curr;
55156+ *curr = role;
55157+ } else {
55158+ /* 1 -> 2 -> 3 -> 4
55159+ 2 -> 3 -> 4
55160+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
55161+ */
55162+ /* trickier case: walk our role's chain until we find
55163+ the role for the start of the current slot's chain */
55164+ tmp = role;
55165+ tmp2 = *curr;
55166+ while (tmp->next && tmp->next != tmp2)
55167+ tmp = tmp->next;
55168+ if (tmp->next == tmp2) {
55169+ /* from example above, we found 3, so just
55170+ replace this slot's chain with ours */
55171+ *curr = role;
55172+ } else {
55173+ /* we didn't find a subset of our role's chain
55174+ in the current slot's chain, so append their
55175+ chain to ours, and set us as the first role in
55176+ the slot's chain
55177+
55178+ we could fold this case with the case above,
55179+ but making it explicit for clarity
55180+ */
55181+ tmp->next = tmp2;
55182+ *curr = role;
55183+ }
55184+ }
55185+ }
55186+
55187+ return;
55188+}
55189+
55190+static void
55191+insert_acl_role_label(struct acl_role_label *role)
55192+{
55193+ int i;
55194+
55195+ if (role_list == NULL) {
55196+ role_list = role;
55197+ role->prev = NULL;
55198+ } else {
55199+ role->prev = role_list;
55200+ role_list = role;
55201+ }
55202+
55203+ /* used for hash chains */
55204+ role->next = NULL;
55205+
55206+ if (role->roletype & GR_ROLE_DOMAIN) {
55207+ for (i = 0; i < role->domain_child_num; i++)
55208+ __insert_acl_role_label(role, role->domain_children[i]);
55209+ } else
55210+ __insert_acl_role_label(role, role->uidgid);
55211+}
55212+
55213+static int
55214+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
55215+{
55216+ struct name_entry **curr, *nentry;
55217+ struct inodev_entry *ientry;
55218+ unsigned int len = strlen(name);
55219+ unsigned int key = full_name_hash(name, len);
55220+ unsigned int index = key % name_set.n_size;
55221+
55222+ curr = &name_set.n_hash[index];
55223+
55224+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
55225+ curr = &((*curr)->next);
55226+
55227+ if (*curr != NULL)
55228+ return 1;
55229+
55230+ nentry = acl_alloc(sizeof (struct name_entry));
55231+ if (nentry == NULL)
55232+ return 0;
55233+ ientry = acl_alloc(sizeof (struct inodev_entry));
55234+ if (ientry == NULL)
55235+ return 0;
55236+ ientry->nentry = nentry;
55237+
55238+ nentry->key = key;
55239+ nentry->name = name;
55240+ nentry->inode = inode;
55241+ nentry->device = device;
55242+ nentry->len = len;
55243+ nentry->deleted = deleted;
55244+
55245+ nentry->prev = NULL;
55246+ curr = &name_set.n_hash[index];
55247+ if (*curr != NULL)
55248+ (*curr)->prev = nentry;
55249+ nentry->next = *curr;
55250+ *curr = nentry;
55251+
55252+ /* insert us into the table searchable by inode/dev */
55253+ insert_inodev_entry(ientry);
55254+
55255+ return 1;
55256+}
55257+
55258+static void
55259+insert_acl_obj_label(struct acl_object_label *obj,
55260+ struct acl_subject_label *subj)
55261+{
55262+ unsigned int index =
55263+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
55264+ struct acl_object_label **curr;
55265+
55266+
55267+ obj->prev = NULL;
55268+
55269+ curr = &subj->obj_hash[index];
55270+ if (*curr != NULL)
55271+ (*curr)->prev = obj;
55272+
55273+ obj->next = *curr;
55274+ *curr = obj;
55275+
55276+ return;
55277+}
55278+
55279+static void
55280+insert_acl_subj_label(struct acl_subject_label *obj,
55281+ struct acl_role_label *role)
55282+{
55283+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
55284+ struct acl_subject_label **curr;
55285+
55286+ obj->prev = NULL;
55287+
55288+ curr = &role->subj_hash[index];
55289+ if (*curr != NULL)
55290+ (*curr)->prev = obj;
55291+
55292+ obj->next = *curr;
55293+ *curr = obj;
55294+
55295+ return;
55296+}
55297+
55298+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
55299+
55300+static void *
55301+create_table(__u32 * len, int elementsize)
55302+{
55303+ unsigned int table_sizes[] = {
55304+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
55305+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
55306+ 4194301, 8388593, 16777213, 33554393, 67108859
55307+ };
55308+ void *newtable = NULL;
55309+ unsigned int pwr = 0;
55310+
55311+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
55312+ table_sizes[pwr] <= *len)
55313+ pwr++;
55314+
55315+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
55316+ return newtable;
55317+
55318+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
55319+ newtable =
55320+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
55321+ else
55322+ newtable = vmalloc(table_sizes[pwr] * elementsize);
55323+
55324+ *len = table_sizes[pwr];
55325+
55326+ return newtable;
55327+}
55328+
55329+static int
55330+init_variables(const struct gr_arg *arg)
55331+{
55332+ struct task_struct *reaper = init_pid_ns.child_reaper;
55333+ unsigned int stacksize;
55334+
55335+ subj_map_set.s_size = arg->role_db.num_subjects;
55336+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
55337+ name_set.n_size = arg->role_db.num_objects;
55338+ inodev_set.i_size = arg->role_db.num_objects;
55339+
55340+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
55341+ !name_set.n_size || !inodev_set.i_size)
55342+ return 1;
55343+
55344+ if (!gr_init_uidset())
55345+ return 1;
55346+
55347+ /* set up the stack that holds allocation info */
55348+
55349+ stacksize = arg->role_db.num_pointers + 5;
55350+
55351+ if (!acl_alloc_stack_init(stacksize))
55352+ return 1;
55353+
55354+ /* grab reference for the real root dentry and vfsmount */
55355+ get_fs_root(reaper->fs, &real_root);
55356+
55357+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55358+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
55359+#endif
55360+
55361+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
55362+ if (fakefs_obj_rw == NULL)
55363+ return 1;
55364+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
55365+
55366+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
55367+ if (fakefs_obj_rwx == NULL)
55368+ return 1;
55369+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
55370+
55371+ subj_map_set.s_hash =
55372+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
55373+ acl_role_set.r_hash =
55374+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
55375+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
55376+ inodev_set.i_hash =
55377+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
55378+
55379+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
55380+ !name_set.n_hash || !inodev_set.i_hash)
55381+ return 1;
55382+
55383+ memset(subj_map_set.s_hash, 0,
55384+ sizeof(struct subject_map *) * subj_map_set.s_size);
55385+ memset(acl_role_set.r_hash, 0,
55386+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
55387+ memset(name_set.n_hash, 0,
55388+ sizeof (struct name_entry *) * name_set.n_size);
55389+ memset(inodev_set.i_hash, 0,
55390+ sizeof (struct inodev_entry *) * inodev_set.i_size);
55391+
55392+ return 0;
55393+}
55394+
55395+/* free information not needed after startup
55396+ currently contains user->kernel pointer mappings for subjects
55397+*/
55398+
55399+static void
55400+free_init_variables(void)
55401+{
55402+ __u32 i;
55403+
55404+ if (subj_map_set.s_hash) {
55405+ for (i = 0; i < subj_map_set.s_size; i++) {
55406+ if (subj_map_set.s_hash[i]) {
55407+ kfree(subj_map_set.s_hash[i]);
55408+ subj_map_set.s_hash[i] = NULL;
55409+ }
55410+ }
55411+
55412+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
55413+ PAGE_SIZE)
55414+ kfree(subj_map_set.s_hash);
55415+ else
55416+ vfree(subj_map_set.s_hash);
55417+ }
55418+
55419+ return;
55420+}
55421+
55422+static void
55423+free_variables(void)
55424+{
55425+ struct acl_subject_label *s;
55426+ struct acl_role_label *r;
55427+ struct task_struct *task, *task2;
55428+ unsigned int x;
55429+
55430+ gr_clear_learn_entries();
55431+
55432+ read_lock(&tasklist_lock);
55433+ do_each_thread(task2, task) {
55434+ task->acl_sp_role = 0;
55435+ task->acl_role_id = 0;
55436+ task->acl = NULL;
55437+ task->role = NULL;
55438+ } while_each_thread(task2, task);
55439+ read_unlock(&tasklist_lock);
55440+
55441+ /* release the reference to the real root dentry and vfsmount */
55442+ path_put(&real_root);
55443+ memset(&real_root, 0, sizeof(real_root));
55444+
55445+ /* free all object hash tables */
55446+
55447+ FOR_EACH_ROLE_START(r)
55448+ if (r->subj_hash == NULL)
55449+ goto next_role;
55450+ FOR_EACH_SUBJECT_START(r, s, x)
55451+ if (s->obj_hash == NULL)
55452+ break;
55453+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
55454+ kfree(s->obj_hash);
55455+ else
55456+ vfree(s->obj_hash);
55457+ FOR_EACH_SUBJECT_END(s, x)
55458+ FOR_EACH_NESTED_SUBJECT_START(r, s)
55459+ if (s->obj_hash == NULL)
55460+ break;
55461+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
55462+ kfree(s->obj_hash);
55463+ else
55464+ vfree(s->obj_hash);
55465+ FOR_EACH_NESTED_SUBJECT_END(s)
55466+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
55467+ kfree(r->subj_hash);
55468+ else
55469+ vfree(r->subj_hash);
55470+ r->subj_hash = NULL;
55471+next_role:
55472+ FOR_EACH_ROLE_END(r)
55473+
55474+ acl_free_all();
55475+
55476+ if (acl_role_set.r_hash) {
55477+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
55478+ PAGE_SIZE)
55479+ kfree(acl_role_set.r_hash);
55480+ else
55481+ vfree(acl_role_set.r_hash);
55482+ }
55483+ if (name_set.n_hash) {
55484+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
55485+ PAGE_SIZE)
55486+ kfree(name_set.n_hash);
55487+ else
55488+ vfree(name_set.n_hash);
55489+ }
55490+
55491+ if (inodev_set.i_hash) {
55492+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
55493+ PAGE_SIZE)
55494+ kfree(inodev_set.i_hash);
55495+ else
55496+ vfree(inodev_set.i_hash);
55497+ }
55498+
55499+ gr_free_uidset();
55500+
55501+ memset(&name_set, 0, sizeof (struct name_db));
55502+ memset(&inodev_set, 0, sizeof (struct inodev_db));
55503+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
55504+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
55505+
55506+ default_role = NULL;
55507+ kernel_role = NULL;
55508+ role_list = NULL;
55509+
55510+ return;
55511+}
55512+
55513+static __u32
55514+count_user_objs(struct acl_object_label *userp)
55515+{
55516+ struct acl_object_label o_tmp;
55517+ __u32 num = 0;
55518+
55519+ while (userp) {
55520+ if (copy_from_user(&o_tmp, userp,
55521+ sizeof (struct acl_object_label)))
55522+ break;
55523+
55524+ userp = o_tmp.prev;
55525+ num++;
55526+ }
55527+
55528+ return num;
55529+}
55530+
55531+static struct acl_subject_label *
55532+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
55533+
55534+static int
55535+copy_user_glob(struct acl_object_label *obj)
55536+{
55537+ struct acl_object_label *g_tmp, **guser;
55538+ unsigned int len;
55539+ char *tmp;
55540+
55541+ if (obj->globbed == NULL)
55542+ return 0;
55543+
55544+ guser = &obj->globbed;
55545+ while (*guser) {
55546+ g_tmp = (struct acl_object_label *)
55547+ acl_alloc(sizeof (struct acl_object_label));
55548+ if (g_tmp == NULL)
55549+ return -ENOMEM;
55550+
55551+ if (copy_from_user(g_tmp, *guser,
55552+ sizeof (struct acl_object_label)))
55553+ return -EFAULT;
55554+
55555+ len = strnlen_user(g_tmp->filename, PATH_MAX);
55556+
55557+ if (!len || len >= PATH_MAX)
55558+ return -EINVAL;
55559+
55560+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55561+ return -ENOMEM;
55562+
55563+ if (copy_from_user(tmp, g_tmp->filename, len))
55564+ return -EFAULT;
55565+ tmp[len-1] = '\0';
55566+ g_tmp->filename = tmp;
55567+
55568+ *guser = g_tmp;
55569+ guser = &(g_tmp->next);
55570+ }
55571+
55572+ return 0;
55573+}
55574+
55575+static int
55576+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
55577+ struct acl_role_label *role)
55578+{
55579+ struct acl_object_label *o_tmp;
55580+ unsigned int len;
55581+ int ret;
55582+ char *tmp;
55583+
55584+ while (userp) {
55585+ if ((o_tmp = (struct acl_object_label *)
55586+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
55587+ return -ENOMEM;
55588+
55589+ if (copy_from_user(o_tmp, userp,
55590+ sizeof (struct acl_object_label)))
55591+ return -EFAULT;
55592+
55593+ userp = o_tmp->prev;
55594+
55595+ len = strnlen_user(o_tmp->filename, PATH_MAX);
55596+
55597+ if (!len || len >= PATH_MAX)
55598+ return -EINVAL;
55599+
55600+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55601+ return -ENOMEM;
55602+
55603+ if (copy_from_user(tmp, o_tmp->filename, len))
55604+ return -EFAULT;
55605+ tmp[len-1] = '\0';
55606+ o_tmp->filename = tmp;
55607+
55608+ insert_acl_obj_label(o_tmp, subj);
55609+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
55610+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
55611+ return -ENOMEM;
55612+
55613+ ret = copy_user_glob(o_tmp);
55614+ if (ret)
55615+ return ret;
55616+
55617+ if (o_tmp->nested) {
55618+ int already_copied;
55619+
55620+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
55621+ if (IS_ERR(o_tmp->nested))
55622+ return PTR_ERR(o_tmp->nested);
55623+
55624+ /* insert into nested subject list if we haven't copied this one yet
55625+ to prevent duplicate entries */
55626+ if (!already_copied) {
55627+ o_tmp->nested->next = role->hash->first;
55628+ role->hash->first = o_tmp->nested;
55629+ }
55630+ }
55631+ }
55632+
55633+ return 0;
55634+}
55635+
55636+static __u32
55637+count_user_subjs(struct acl_subject_label *userp)
55638+{
55639+ struct acl_subject_label s_tmp;
55640+ __u32 num = 0;
55641+
55642+ while (userp) {
55643+ if (copy_from_user(&s_tmp, userp,
55644+ sizeof (struct acl_subject_label)))
55645+ break;
55646+
55647+ userp = s_tmp.prev;
55648+ }
55649+
55650+ return num;
55651+}
55652+
55653+static int
55654+copy_user_allowedips(struct acl_role_label *rolep)
55655+{
55656+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
55657+
55658+ ruserip = rolep->allowed_ips;
55659+
55660+ while (ruserip) {
55661+ rlast = rtmp;
55662+
55663+ if ((rtmp = (struct role_allowed_ip *)
55664+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
55665+ return -ENOMEM;
55666+
55667+ if (copy_from_user(rtmp, ruserip,
55668+ sizeof (struct role_allowed_ip)))
55669+ return -EFAULT;
55670+
55671+ ruserip = rtmp->prev;
55672+
55673+ if (!rlast) {
55674+ rtmp->prev = NULL;
55675+ rolep->allowed_ips = rtmp;
55676+ } else {
55677+ rlast->next = rtmp;
55678+ rtmp->prev = rlast;
55679+ }
55680+
55681+ if (!ruserip)
55682+ rtmp->next = NULL;
55683+ }
55684+
55685+ return 0;
55686+}
55687+
55688+static int
55689+copy_user_transitions(struct acl_role_label *rolep)
55690+{
55691+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
55692+
55693+ unsigned int len;
55694+ char *tmp;
55695+
55696+ rusertp = rolep->transitions;
55697+
55698+ while (rusertp) {
55699+ rlast = rtmp;
55700+
55701+ if ((rtmp = (struct role_transition *)
55702+ acl_alloc(sizeof (struct role_transition))) == NULL)
55703+ return -ENOMEM;
55704+
55705+ if (copy_from_user(rtmp, rusertp,
55706+ sizeof (struct role_transition)))
55707+ return -EFAULT;
55708+
55709+ rusertp = rtmp->prev;
55710+
55711+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
55712+
55713+ if (!len || len >= GR_SPROLE_LEN)
55714+ return -EINVAL;
55715+
55716+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55717+ return -ENOMEM;
55718+
55719+ if (copy_from_user(tmp, rtmp->rolename, len))
55720+ return -EFAULT;
55721+ tmp[len-1] = '\0';
55722+ rtmp->rolename = tmp;
55723+
55724+ if (!rlast) {
55725+ rtmp->prev = NULL;
55726+ rolep->transitions = rtmp;
55727+ } else {
55728+ rlast->next = rtmp;
55729+ rtmp->prev = rlast;
55730+ }
55731+
55732+ if (!rusertp)
55733+ rtmp->next = NULL;
55734+ }
55735+
55736+ return 0;
55737+}
55738+
55739+static struct acl_subject_label *
55740+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
55741+{
55742+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
55743+ unsigned int len;
55744+ char *tmp;
55745+ __u32 num_objs;
55746+ struct acl_ip_label **i_tmp, *i_utmp2;
55747+ struct gr_hash_struct ghash;
55748+ struct subject_map *subjmap;
55749+ unsigned int i_num;
55750+ int err;
55751+
55752+ if (already_copied != NULL)
55753+ *already_copied = 0;
55754+
55755+ s_tmp = lookup_subject_map(userp);
55756+
55757+ /* we've already copied this subject into the kernel, just return
55758+ the reference to it, and don't copy it over again
55759+ */
55760+ if (s_tmp) {
55761+ if (already_copied != NULL)
55762+ *already_copied = 1;
55763+ return(s_tmp);
55764+ }
55765+
55766+ if ((s_tmp = (struct acl_subject_label *)
55767+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
55768+ return ERR_PTR(-ENOMEM);
55769+
55770+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
55771+ if (subjmap == NULL)
55772+ return ERR_PTR(-ENOMEM);
55773+
55774+ subjmap->user = userp;
55775+ subjmap->kernel = s_tmp;
55776+ insert_subj_map_entry(subjmap);
55777+
55778+ if (copy_from_user(s_tmp, userp,
55779+ sizeof (struct acl_subject_label)))
55780+ return ERR_PTR(-EFAULT);
55781+
55782+ len = strnlen_user(s_tmp->filename, PATH_MAX);
55783+
55784+ if (!len || len >= PATH_MAX)
55785+ return ERR_PTR(-EINVAL);
55786+
55787+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55788+ return ERR_PTR(-ENOMEM);
55789+
55790+ if (copy_from_user(tmp, s_tmp->filename, len))
55791+ return ERR_PTR(-EFAULT);
55792+ tmp[len-1] = '\0';
55793+ s_tmp->filename = tmp;
55794+
55795+ if (!strcmp(s_tmp->filename, "/"))
55796+ role->root_label = s_tmp;
55797+
55798+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
55799+ return ERR_PTR(-EFAULT);
55800+
55801+ /* copy user and group transition tables */
55802+
55803+ if (s_tmp->user_trans_num) {
55804+ uid_t *uidlist;
55805+
55806+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
55807+ if (uidlist == NULL)
55808+ return ERR_PTR(-ENOMEM);
55809+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
55810+ return ERR_PTR(-EFAULT);
55811+
55812+ s_tmp->user_transitions = uidlist;
55813+ }
55814+
55815+ if (s_tmp->group_trans_num) {
55816+ gid_t *gidlist;
55817+
55818+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
55819+ if (gidlist == NULL)
55820+ return ERR_PTR(-ENOMEM);
55821+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
55822+ return ERR_PTR(-EFAULT);
55823+
55824+ s_tmp->group_transitions = gidlist;
55825+ }
55826+
55827+ /* set up object hash table */
55828+ num_objs = count_user_objs(ghash.first);
55829+
55830+ s_tmp->obj_hash_size = num_objs;
55831+ s_tmp->obj_hash =
55832+ (struct acl_object_label **)
55833+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
55834+
55835+ if (!s_tmp->obj_hash)
55836+ return ERR_PTR(-ENOMEM);
55837+
55838+ memset(s_tmp->obj_hash, 0,
55839+ s_tmp->obj_hash_size *
55840+ sizeof (struct acl_object_label *));
55841+
55842+ /* add in objects */
55843+ err = copy_user_objs(ghash.first, s_tmp, role);
55844+
55845+ if (err)
55846+ return ERR_PTR(err);
55847+
55848+ /* set pointer for parent subject */
55849+ if (s_tmp->parent_subject) {
55850+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
55851+
55852+ if (IS_ERR(s_tmp2))
55853+ return s_tmp2;
55854+
55855+ s_tmp->parent_subject = s_tmp2;
55856+ }
55857+
55858+ /* add in ip acls */
55859+
55860+ if (!s_tmp->ip_num) {
55861+ s_tmp->ips = NULL;
55862+ goto insert;
55863+ }
55864+
55865+ i_tmp =
55866+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
55867+ sizeof (struct acl_ip_label *));
55868+
55869+ if (!i_tmp)
55870+ return ERR_PTR(-ENOMEM);
55871+
55872+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
55873+ *(i_tmp + i_num) =
55874+ (struct acl_ip_label *)
55875+ acl_alloc(sizeof (struct acl_ip_label));
55876+ if (!*(i_tmp + i_num))
55877+ return ERR_PTR(-ENOMEM);
55878+
55879+ if (copy_from_user
55880+ (&i_utmp2, s_tmp->ips + i_num,
55881+ sizeof (struct acl_ip_label *)))
55882+ return ERR_PTR(-EFAULT);
55883+
55884+ if (copy_from_user
55885+ (*(i_tmp + i_num), i_utmp2,
55886+ sizeof (struct acl_ip_label)))
55887+ return ERR_PTR(-EFAULT);
55888+
55889+ if ((*(i_tmp + i_num))->iface == NULL)
55890+ continue;
55891+
55892+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
55893+ if (!len || len >= IFNAMSIZ)
55894+ return ERR_PTR(-EINVAL);
55895+ tmp = acl_alloc(len);
55896+ if (tmp == NULL)
55897+ return ERR_PTR(-ENOMEM);
55898+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
55899+ return ERR_PTR(-EFAULT);
55900+ (*(i_tmp + i_num))->iface = tmp;
55901+ }
55902+
55903+ s_tmp->ips = i_tmp;
55904+
55905+insert:
55906+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
55907+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
55908+ return ERR_PTR(-ENOMEM);
55909+
55910+ return s_tmp;
55911+}
55912+
55913+static int
55914+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
55915+{
55916+ struct acl_subject_label s_pre;
55917+ struct acl_subject_label * ret;
55918+ int err;
55919+
55920+ while (userp) {
55921+ if (copy_from_user(&s_pre, userp,
55922+ sizeof (struct acl_subject_label)))
55923+ return -EFAULT;
55924+
55925+ ret = do_copy_user_subj(userp, role, NULL);
55926+
55927+ err = PTR_ERR(ret);
55928+ if (IS_ERR(ret))
55929+ return err;
55930+
55931+ insert_acl_subj_label(ret, role);
55932+
55933+ userp = s_pre.prev;
55934+ }
55935+
55936+ return 0;
55937+}
55938+
55939+static int
55940+copy_user_acl(struct gr_arg *arg)
55941+{
55942+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
55943+ struct acl_subject_label *subj_list;
55944+ struct sprole_pw *sptmp;
55945+ struct gr_hash_struct *ghash;
55946+ uid_t *domainlist;
55947+ unsigned int r_num;
55948+ unsigned int len;
55949+ char *tmp;
55950+ int err = 0;
55951+ __u16 i;
55952+ __u32 num_subjs;
55953+
55954+ /* we need a default and kernel role */
55955+ if (arg->role_db.num_roles < 2)
55956+ return -EINVAL;
55957+
55958+ /* copy special role authentication info from userspace */
55959+
55960+ num_sprole_pws = arg->num_sprole_pws;
55961+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
55962+
55963+ if (!acl_special_roles && num_sprole_pws)
55964+ return -ENOMEM;
55965+
55966+ for (i = 0; i < num_sprole_pws; i++) {
55967+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
55968+ if (!sptmp)
55969+ return -ENOMEM;
55970+ if (copy_from_user(sptmp, arg->sprole_pws + i,
55971+ sizeof (struct sprole_pw)))
55972+ return -EFAULT;
55973+
55974+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
55975+
55976+ if (!len || len >= GR_SPROLE_LEN)
55977+ return -EINVAL;
55978+
55979+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55980+ return -ENOMEM;
55981+
55982+ if (copy_from_user(tmp, sptmp->rolename, len))
55983+ return -EFAULT;
55984+
55985+ tmp[len-1] = '\0';
55986+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55987+ printk(KERN_ALERT "Copying special role %s\n", tmp);
55988+#endif
55989+ sptmp->rolename = tmp;
55990+ acl_special_roles[i] = sptmp;
55991+ }
55992+
55993+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
55994+
55995+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
55996+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
55997+
55998+ if (!r_tmp)
55999+ return -ENOMEM;
56000+
56001+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
56002+ sizeof (struct acl_role_label *)))
56003+ return -EFAULT;
56004+
56005+ if (copy_from_user(r_tmp, r_utmp2,
56006+ sizeof (struct acl_role_label)))
56007+ return -EFAULT;
56008+
56009+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
56010+
56011+ if (!len || len >= PATH_MAX)
56012+ return -EINVAL;
56013+
56014+ if ((tmp = (char *) acl_alloc(len)) == NULL)
56015+ return -ENOMEM;
56016+
56017+ if (copy_from_user(tmp, r_tmp->rolename, len))
56018+ return -EFAULT;
56019+
56020+ tmp[len-1] = '\0';
56021+ r_tmp->rolename = tmp;
56022+
56023+ if (!strcmp(r_tmp->rolename, "default")
56024+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
56025+ default_role = r_tmp;
56026+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
56027+ kernel_role = r_tmp;
56028+ }
56029+
56030+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
56031+ return -ENOMEM;
56032+
56033+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
56034+ return -EFAULT;
56035+
56036+ r_tmp->hash = ghash;
56037+
56038+ num_subjs = count_user_subjs(r_tmp->hash->first);
56039+
56040+ r_tmp->subj_hash_size = num_subjs;
56041+ r_tmp->subj_hash =
56042+ (struct acl_subject_label **)
56043+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
56044+
56045+ if (!r_tmp->subj_hash)
56046+ return -ENOMEM;
56047+
56048+ err = copy_user_allowedips(r_tmp);
56049+ if (err)
56050+ return err;
56051+
56052+ /* copy domain info */
56053+ if (r_tmp->domain_children != NULL) {
56054+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
56055+ if (domainlist == NULL)
56056+ return -ENOMEM;
56057+
56058+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
56059+ return -EFAULT;
56060+
56061+ r_tmp->domain_children = domainlist;
56062+ }
56063+
56064+ err = copy_user_transitions(r_tmp);
56065+ if (err)
56066+ return err;
56067+
56068+ memset(r_tmp->subj_hash, 0,
56069+ r_tmp->subj_hash_size *
56070+ sizeof (struct acl_subject_label *));
56071+
56072+ /* acquire the list of subjects, then NULL out
56073+ the list prior to parsing the subjects for this role,
56074+ as during this parsing the list is replaced with a list
56075+ of *nested* subjects for the role
56076+ */
56077+ subj_list = r_tmp->hash->first;
56078+
56079+ /* set nested subject list to null */
56080+ r_tmp->hash->first = NULL;
56081+
56082+ err = copy_user_subjs(subj_list, r_tmp);
56083+
56084+ if (err)
56085+ return err;
56086+
56087+ insert_acl_role_label(r_tmp);
56088+ }
56089+
56090+ if (default_role == NULL || kernel_role == NULL)
56091+ return -EINVAL;
56092+
56093+ return err;
56094+}
56095+
56096+static int
56097+gracl_init(struct gr_arg *args)
56098+{
56099+ int error = 0;
56100+
56101+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
56102+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
56103+
56104+ if (init_variables(args)) {
56105+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
56106+ error = -ENOMEM;
56107+ free_variables();
56108+ goto out;
56109+ }
56110+
56111+ error = copy_user_acl(args);
56112+ free_init_variables();
56113+ if (error) {
56114+ free_variables();
56115+ goto out;
56116+ }
56117+
56118+ if ((error = gr_set_acls(0))) {
56119+ free_variables();
56120+ goto out;
56121+ }
56122+
56123+ pax_open_kernel();
56124+ gr_status |= GR_READY;
56125+ pax_close_kernel();
56126+
56127+ out:
56128+ return error;
56129+}
56130+
56131+/* derived from glibc fnmatch() 0: match, 1: no match*/
56132+
56133+static int
56134+glob_match(const char *p, const char *n)
56135+{
56136+ char c;
56137+
56138+ while ((c = *p++) != '\0') {
56139+ switch (c) {
56140+ case '?':
56141+ if (*n == '\0')
56142+ return 1;
56143+ else if (*n == '/')
56144+ return 1;
56145+ break;
56146+ case '\\':
56147+ if (*n != c)
56148+ return 1;
56149+ break;
56150+ case '*':
56151+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
56152+ if (*n == '/')
56153+ return 1;
56154+ else if (c == '?') {
56155+ if (*n == '\0')
56156+ return 1;
56157+ else
56158+ ++n;
56159+ }
56160+ }
56161+ if (c == '\0') {
56162+ return 0;
56163+ } else {
56164+ const char *endp;
56165+
56166+ if ((endp = strchr(n, '/')) == NULL)
56167+ endp = n + strlen(n);
56168+
56169+ if (c == '[') {
56170+ for (--p; n < endp; ++n)
56171+ if (!glob_match(p, n))
56172+ return 0;
56173+ } else if (c == '/') {
56174+ while (*n != '\0' && *n != '/')
56175+ ++n;
56176+ if (*n == '/' && !glob_match(p, n + 1))
56177+ return 0;
56178+ } else {
56179+ for (--p; n < endp; ++n)
56180+ if (*n == c && !glob_match(p, n))
56181+ return 0;
56182+ }
56183+
56184+ return 1;
56185+ }
56186+ case '[':
56187+ {
56188+ int not;
56189+ char cold;
56190+
56191+ if (*n == '\0' || *n == '/')
56192+ return 1;
56193+
56194+ not = (*p == '!' || *p == '^');
56195+ if (not)
56196+ ++p;
56197+
56198+ c = *p++;
56199+ for (;;) {
56200+ unsigned char fn = (unsigned char)*n;
56201+
56202+ if (c == '\0')
56203+ return 1;
56204+ else {
56205+ if (c == fn)
56206+ goto matched;
56207+ cold = c;
56208+ c = *p++;
56209+
56210+ if (c == '-' && *p != ']') {
56211+ unsigned char cend = *p++;
56212+
56213+ if (cend == '\0')
56214+ return 1;
56215+
56216+ if (cold <= fn && fn <= cend)
56217+ goto matched;
56218+
56219+ c = *p++;
56220+ }
56221+ }
56222+
56223+ if (c == ']')
56224+ break;
56225+ }
56226+ if (!not)
56227+ return 1;
56228+ break;
56229+ matched:
56230+ while (c != ']') {
56231+ if (c == '\0')
56232+ return 1;
56233+
56234+ c = *p++;
56235+ }
56236+ if (not)
56237+ return 1;
56238+ }
56239+ break;
56240+ default:
56241+ if (c != *n)
56242+ return 1;
56243+ }
56244+
56245+ ++n;
56246+ }
56247+
56248+ if (*n == '\0')
56249+ return 0;
56250+
56251+ if (*n == '/')
56252+ return 0;
56253+
56254+ return 1;
56255+}
56256+
56257+static struct acl_object_label *
56258+chk_glob_label(struct acl_object_label *globbed,
56259+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
56260+{
56261+ struct acl_object_label *tmp;
56262+
56263+ if (*path == NULL)
56264+ *path = gr_to_filename_nolock(dentry, mnt);
56265+
56266+ tmp = globbed;
56267+
56268+ while (tmp) {
56269+ if (!glob_match(tmp->filename, *path))
56270+ return tmp;
56271+ tmp = tmp->next;
56272+ }
56273+
56274+ return NULL;
56275+}
56276+
56277+static struct acl_object_label *
56278+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
56279+ const ino_t curr_ino, const dev_t curr_dev,
56280+ const struct acl_subject_label *subj, char **path, const int checkglob)
56281+{
56282+ struct acl_subject_label *tmpsubj;
56283+ struct acl_object_label *retval;
56284+ struct acl_object_label *retval2;
56285+
56286+ tmpsubj = (struct acl_subject_label *) subj;
56287+ read_lock(&gr_inode_lock);
56288+ do {
56289+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
56290+ if (retval) {
56291+ if (checkglob && retval->globbed) {
56292+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
56293+ if (retval2)
56294+ retval = retval2;
56295+ }
56296+ break;
56297+ }
56298+ } while ((tmpsubj = tmpsubj->parent_subject));
56299+ read_unlock(&gr_inode_lock);
56300+
56301+ return retval;
56302+}
56303+
56304+static __inline__ struct acl_object_label *
56305+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
56306+ struct dentry *curr_dentry,
56307+ const struct acl_subject_label *subj, char **path, const int checkglob)
56308+{
56309+ int newglob = checkglob;
56310+ ino_t inode;
56311+ dev_t device;
56312+
56313+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
56314+ as we don't want a / * rule to match instead of the / object
56315+ don't do this for create lookups that call this function though, since they're looking up
56316+ on the parent and thus need globbing checks on all paths
56317+ */
56318+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
56319+ newglob = GR_NO_GLOB;
56320+
56321+ spin_lock(&curr_dentry->d_lock);
56322+ inode = curr_dentry->d_inode->i_ino;
56323+ device = __get_dev(curr_dentry);
56324+ spin_unlock(&curr_dentry->d_lock);
56325+
56326+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
56327+}
56328+
56329+#ifdef CONFIG_HUGETLBFS
56330+static inline bool
56331+is_hugetlbfs_mnt(const struct vfsmount *mnt)
56332+{
56333+ int i;
56334+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
56335+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
56336+ return true;
56337+ }
56338+
56339+ return false;
56340+}
56341+#endif
56342+
56343+static struct acl_object_label *
56344+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56345+ const struct acl_subject_label *subj, char *path, const int checkglob)
56346+{
56347+ struct dentry *dentry = (struct dentry *) l_dentry;
56348+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
56349+ struct mount *real_mnt = real_mount(mnt);
56350+ struct acl_object_label *retval;
56351+ struct dentry *parent;
56352+
56353+ write_seqlock(&rename_lock);
56354+ br_read_lock(&vfsmount_lock);
56355+
56356+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
56357+#ifdef CONFIG_NET
56358+ mnt == sock_mnt ||
56359+#endif
56360+#ifdef CONFIG_HUGETLBFS
56361+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
56362+#endif
56363+ /* ignore Eric Biederman */
56364+ IS_PRIVATE(l_dentry->d_inode))) {
56365+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
56366+ goto out;
56367+ }
56368+
56369+ for (;;) {
56370+ if (dentry == real_root.dentry && mnt == real_root.mnt)
56371+ break;
56372+
56373+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
56374+ if (!mnt_has_parent(real_mnt))
56375+ break;
56376+
56377+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56378+ if (retval != NULL)
56379+ goto out;
56380+
56381+ dentry = real_mnt->mnt_mountpoint;
56382+ real_mnt = real_mnt->mnt_parent;
56383+ mnt = &real_mnt->mnt;
56384+ continue;
56385+ }
56386+
56387+ parent = dentry->d_parent;
56388+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56389+ if (retval != NULL)
56390+ goto out;
56391+
56392+ dentry = parent;
56393+ }
56394+
56395+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56396+
56397+ /* real_root is pinned so we don't have to hold a reference */
56398+ if (retval == NULL)
56399+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
56400+out:
56401+ br_read_unlock(&vfsmount_lock);
56402+ write_sequnlock(&rename_lock);
56403+
56404+ BUG_ON(retval == NULL);
56405+
56406+ return retval;
56407+}
56408+
56409+static __inline__ struct acl_object_label *
56410+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56411+ const struct acl_subject_label *subj)
56412+{
56413+ char *path = NULL;
56414+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
56415+}
56416+
56417+static __inline__ struct acl_object_label *
56418+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56419+ const struct acl_subject_label *subj)
56420+{
56421+ char *path = NULL;
56422+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
56423+}
56424+
56425+static __inline__ struct acl_object_label *
56426+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56427+ const struct acl_subject_label *subj, char *path)
56428+{
56429+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
56430+}
56431+
56432+static struct acl_subject_label *
56433+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56434+ const struct acl_role_label *role)
56435+{
56436+ struct dentry *dentry = (struct dentry *) l_dentry;
56437+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
56438+ struct mount *real_mnt = real_mount(mnt);
56439+ struct acl_subject_label *retval;
56440+ struct dentry *parent;
56441+
56442+ write_seqlock(&rename_lock);
56443+ br_read_lock(&vfsmount_lock);
56444+
56445+ for (;;) {
56446+ if (dentry == real_root.dentry && mnt == real_root.mnt)
56447+ break;
56448+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
56449+ if (!mnt_has_parent(real_mnt))
56450+ break;
56451+
56452+ spin_lock(&dentry->d_lock);
56453+ read_lock(&gr_inode_lock);
56454+ retval =
56455+ lookup_acl_subj_label(dentry->d_inode->i_ino,
56456+ __get_dev(dentry), role);
56457+ read_unlock(&gr_inode_lock);
56458+ spin_unlock(&dentry->d_lock);
56459+ if (retval != NULL)
56460+ goto out;
56461+
56462+ dentry = real_mnt->mnt_mountpoint;
56463+ real_mnt = real_mnt->mnt_parent;
56464+ mnt = &real_mnt->mnt;
56465+ continue;
56466+ }
56467+
56468+ spin_lock(&dentry->d_lock);
56469+ read_lock(&gr_inode_lock);
56470+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
56471+ __get_dev(dentry), role);
56472+ read_unlock(&gr_inode_lock);
56473+ parent = dentry->d_parent;
56474+ spin_unlock(&dentry->d_lock);
56475+
56476+ if (retval != NULL)
56477+ goto out;
56478+
56479+ dentry = parent;
56480+ }
56481+
56482+ spin_lock(&dentry->d_lock);
56483+ read_lock(&gr_inode_lock);
56484+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
56485+ __get_dev(dentry), role);
56486+ read_unlock(&gr_inode_lock);
56487+ spin_unlock(&dentry->d_lock);
56488+
56489+ if (unlikely(retval == NULL)) {
56490+ /* real_root is pinned, we don't need to hold a reference */
56491+ read_lock(&gr_inode_lock);
56492+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
56493+ __get_dev(real_root.dentry), role);
56494+ read_unlock(&gr_inode_lock);
56495+ }
56496+out:
56497+ br_read_unlock(&vfsmount_lock);
56498+ write_sequnlock(&rename_lock);
56499+
56500+ BUG_ON(retval == NULL);
56501+
56502+ return retval;
56503+}
56504+
56505+static void
56506+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
56507+{
56508+ struct task_struct *task = current;
56509+ const struct cred *cred = current_cred();
56510+
56511+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
56512+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
56513+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
56514+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
56515+
56516+ return;
56517+}
56518+
56519+static void
56520+gr_log_learn_id_change(const char type, const unsigned int real,
56521+ const unsigned int effective, const unsigned int fs)
56522+{
56523+ struct task_struct *task = current;
56524+ const struct cred *cred = current_cred();
56525+
56526+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
56527+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
56528+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
56529+ type, real, effective, fs, &task->signal->saved_ip);
56530+
56531+ return;
56532+}
56533+
56534+__u32
56535+gr_search_file(const struct dentry * dentry, const __u32 mode,
56536+ const struct vfsmount * mnt)
56537+{
56538+ __u32 retval = mode;
56539+ struct acl_subject_label *curracl;
56540+ struct acl_object_label *currobj;
56541+
56542+ if (unlikely(!(gr_status & GR_READY)))
56543+ return (mode & ~GR_AUDITS);
56544+
56545+ curracl = current->acl;
56546+
56547+ currobj = chk_obj_label(dentry, mnt, curracl);
56548+ retval = currobj->mode & mode;
56549+
56550+ /* if we're opening a specified transfer file for writing
56551+ (e.g. /dev/initctl), then transfer our role to init
56552+ */
56553+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
56554+ current->role->roletype & GR_ROLE_PERSIST)) {
56555+ struct task_struct *task = init_pid_ns.child_reaper;
56556+
56557+ if (task->role != current->role) {
56558+ task->acl_sp_role = 0;
56559+ task->acl_role_id = current->acl_role_id;
56560+ task->role = current->role;
56561+ rcu_read_lock();
56562+ read_lock(&grsec_exec_file_lock);
56563+ gr_apply_subject_to_task(task);
56564+ read_unlock(&grsec_exec_file_lock);
56565+ rcu_read_unlock();
56566+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
56567+ }
56568+ }
56569+
56570+ if (unlikely
56571+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
56572+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
56573+ __u32 new_mode = mode;
56574+
56575+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
56576+
56577+ retval = new_mode;
56578+
56579+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
56580+ new_mode |= GR_INHERIT;
56581+
56582+ if (!(mode & GR_NOLEARN))
56583+ gr_log_learn(dentry, mnt, new_mode);
56584+ }
56585+
56586+ return retval;
56587+}
56588+
56589+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
56590+ const struct dentry *parent,
56591+ const struct vfsmount *mnt)
56592+{
56593+ struct name_entry *match;
56594+ struct acl_object_label *matchpo;
56595+ struct acl_subject_label *curracl;
56596+ char *path;
56597+
56598+ if (unlikely(!(gr_status & GR_READY)))
56599+ return NULL;
56600+
56601+ preempt_disable();
56602+ path = gr_to_filename_rbac(new_dentry, mnt);
56603+ match = lookup_name_entry_create(path);
56604+
56605+ curracl = current->acl;
56606+
56607+ if (match) {
56608+ read_lock(&gr_inode_lock);
56609+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
56610+ read_unlock(&gr_inode_lock);
56611+
56612+ if (matchpo) {
56613+ preempt_enable();
56614+ return matchpo;
56615+ }
56616+ }
56617+
56618+ // lookup parent
56619+
56620+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
56621+
56622+ preempt_enable();
56623+ return matchpo;
56624+}
56625+
56626+__u32
56627+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
56628+ const struct vfsmount * mnt, const __u32 mode)
56629+{
56630+ struct acl_object_label *matchpo;
56631+ __u32 retval;
56632+
56633+ if (unlikely(!(gr_status & GR_READY)))
56634+ return (mode & ~GR_AUDITS);
56635+
56636+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
56637+
56638+ retval = matchpo->mode & mode;
56639+
56640+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
56641+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
56642+ __u32 new_mode = mode;
56643+
56644+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
56645+
56646+ gr_log_learn(new_dentry, mnt, new_mode);
56647+ return new_mode;
56648+ }
56649+
56650+ return retval;
56651+}
56652+
56653+__u32
56654+gr_check_link(const struct dentry * new_dentry,
56655+ const struct dentry * parent_dentry,
56656+ const struct vfsmount * parent_mnt,
56657+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
56658+{
56659+ struct acl_object_label *obj;
56660+ __u32 oldmode, newmode;
56661+ __u32 needmode;
56662+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
56663+ GR_DELETE | GR_INHERIT;
56664+
56665+ if (unlikely(!(gr_status & GR_READY)))
56666+ return (GR_CREATE | GR_LINK);
56667+
56668+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
56669+ oldmode = obj->mode;
56670+
56671+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
56672+ newmode = obj->mode;
56673+
56674+ needmode = newmode & checkmodes;
56675+
56676+ // old name for hardlink must have at least the permissions of the new name
56677+ if ((oldmode & needmode) != needmode)
56678+ goto bad;
56679+
56680+ // if old name had restrictions/auditing, make sure the new name does as well
56681+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
56682+
56683+ // don't allow hardlinking of suid/sgid/fcapped files without permission
56684+ if (is_privileged_binary(old_dentry))
56685+ needmode |= GR_SETID;
56686+
56687+ if ((newmode & needmode) != needmode)
56688+ goto bad;
56689+
56690+ // enforce minimum permissions
56691+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
56692+ return newmode;
56693+bad:
56694+ needmode = oldmode;
56695+ if (is_privileged_binary(old_dentry))
56696+ needmode |= GR_SETID;
56697+
56698+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
56699+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
56700+ return (GR_CREATE | GR_LINK);
56701+ } else if (newmode & GR_SUPPRESS)
56702+ return GR_SUPPRESS;
56703+ else
56704+ return 0;
56705+}
56706+
56707+int
56708+gr_check_hidden_task(const struct task_struct *task)
56709+{
56710+ if (unlikely(!(gr_status & GR_READY)))
56711+ return 0;
56712+
56713+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
56714+ return 1;
56715+
56716+ return 0;
56717+}
56718+
56719+int
56720+gr_check_protected_task(const struct task_struct *task)
56721+{
56722+ if (unlikely(!(gr_status & GR_READY) || !task))
56723+ return 0;
56724+
56725+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
56726+ task->acl != current->acl)
56727+ return 1;
56728+
56729+ return 0;
56730+}
56731+
56732+int
56733+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
56734+{
56735+ struct task_struct *p;
56736+ int ret = 0;
56737+
56738+ if (unlikely(!(gr_status & GR_READY) || !pid))
56739+ return ret;
56740+
56741+ read_lock(&tasklist_lock);
56742+ do_each_pid_task(pid, type, p) {
56743+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
56744+ p->acl != current->acl) {
56745+ ret = 1;
56746+ goto out;
56747+ }
56748+ } while_each_pid_task(pid, type, p);
56749+out:
56750+ read_unlock(&tasklist_lock);
56751+
56752+ return ret;
56753+}
56754+
56755+void
56756+gr_copy_label(struct task_struct *tsk)
56757+{
56758+ tsk->signal->used_accept = 0;
56759+ tsk->acl_sp_role = 0;
56760+ tsk->acl_role_id = current->acl_role_id;
56761+ tsk->acl = current->acl;
56762+ tsk->role = current->role;
56763+ tsk->signal->curr_ip = current->signal->curr_ip;
56764+ tsk->signal->saved_ip = current->signal->saved_ip;
56765+ if (current->exec_file)
56766+ get_file(current->exec_file);
56767+ tsk->exec_file = current->exec_file;
56768+ tsk->is_writable = current->is_writable;
56769+ if (unlikely(current->signal->used_accept)) {
56770+ current->signal->curr_ip = 0;
56771+ current->signal->saved_ip = 0;
56772+ }
56773+
56774+ return;
56775+}
56776+
56777+static void
56778+gr_set_proc_res(struct task_struct *task)
56779+{
56780+ struct acl_subject_label *proc;
56781+ unsigned short i;
56782+
56783+ proc = task->acl;
56784+
56785+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
56786+ return;
56787+
56788+ for (i = 0; i < RLIM_NLIMITS; i++) {
56789+ if (!(proc->resmask & (1 << i)))
56790+ continue;
56791+
56792+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
56793+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
56794+ }
56795+
56796+ return;
56797+}
56798+
56799+extern int __gr_process_user_ban(struct user_struct *user);
56800+
56801+int
56802+gr_check_user_change(int real, int effective, int fs)
56803+{
56804+ unsigned int i;
56805+ __u16 num;
56806+ uid_t *uidlist;
56807+ int curuid;
56808+ int realok = 0;
56809+ int effectiveok = 0;
56810+ int fsok = 0;
56811+
56812+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56813+ struct user_struct *user;
56814+
56815+ if (real == -1)
56816+ goto skipit;
56817+
56818+ user = find_user(real);
56819+ if (user == NULL)
56820+ goto skipit;
56821+
56822+ if (__gr_process_user_ban(user)) {
56823+ /* for find_user */
56824+ free_uid(user);
56825+ return 1;
56826+ }
56827+
56828+ /* for find_user */
56829+ free_uid(user);
56830+
56831+skipit:
56832+#endif
56833+
56834+ if (unlikely(!(gr_status & GR_READY)))
56835+ return 0;
56836+
56837+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56838+ gr_log_learn_id_change('u', real, effective, fs);
56839+
56840+ num = current->acl->user_trans_num;
56841+ uidlist = current->acl->user_transitions;
56842+
56843+ if (uidlist == NULL)
56844+ return 0;
56845+
56846+ if (real == -1)
56847+ realok = 1;
56848+ if (effective == -1)
56849+ effectiveok = 1;
56850+ if (fs == -1)
56851+ fsok = 1;
56852+
56853+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
56854+ for (i = 0; i < num; i++) {
56855+ curuid = (int)uidlist[i];
56856+ if (real == curuid)
56857+ realok = 1;
56858+ if (effective == curuid)
56859+ effectiveok = 1;
56860+ if (fs == curuid)
56861+ fsok = 1;
56862+ }
56863+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
56864+ for (i = 0; i < num; i++) {
56865+ curuid = (int)uidlist[i];
56866+ if (real == curuid)
56867+ break;
56868+ if (effective == curuid)
56869+ break;
56870+ if (fs == curuid)
56871+ break;
56872+ }
56873+ /* not in deny list */
56874+ if (i == num) {
56875+ realok = 1;
56876+ effectiveok = 1;
56877+ fsok = 1;
56878+ }
56879+ }
56880+
56881+ if (realok && effectiveok && fsok)
56882+ return 0;
56883+ else {
56884+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56885+ return 1;
56886+ }
56887+}
56888+
56889+int
56890+gr_check_group_change(int real, int effective, int fs)
56891+{
56892+ unsigned int i;
56893+ __u16 num;
56894+ gid_t *gidlist;
56895+ int curgid;
56896+ int realok = 0;
56897+ int effectiveok = 0;
56898+ int fsok = 0;
56899+
56900+ if (unlikely(!(gr_status & GR_READY)))
56901+ return 0;
56902+
56903+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56904+ gr_log_learn_id_change('g', real, effective, fs);
56905+
56906+ num = current->acl->group_trans_num;
56907+ gidlist = current->acl->group_transitions;
56908+
56909+ if (gidlist == NULL)
56910+ return 0;
56911+
56912+ if (real == -1)
56913+ realok = 1;
56914+ if (effective == -1)
56915+ effectiveok = 1;
56916+ if (fs == -1)
56917+ fsok = 1;
56918+
56919+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
56920+ for (i = 0; i < num; i++) {
56921+ curgid = (int)gidlist[i];
56922+ if (real == curgid)
56923+ realok = 1;
56924+ if (effective == curgid)
56925+ effectiveok = 1;
56926+ if (fs == curgid)
56927+ fsok = 1;
56928+ }
56929+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
56930+ for (i = 0; i < num; i++) {
56931+ curgid = (int)gidlist[i];
56932+ if (real == curgid)
56933+ break;
56934+ if (effective == curgid)
56935+ break;
56936+ if (fs == curgid)
56937+ break;
56938+ }
56939+ /* not in deny list */
56940+ if (i == num) {
56941+ realok = 1;
56942+ effectiveok = 1;
56943+ fsok = 1;
56944+ }
56945+ }
56946+
56947+ if (realok && effectiveok && fsok)
56948+ return 0;
56949+ else {
56950+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56951+ return 1;
56952+ }
56953+}
56954+
56955+extern int gr_acl_is_capable(const int cap);
56956+
56957+void
56958+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
56959+{
56960+ struct acl_role_label *role = task->role;
56961+ struct acl_subject_label *subj = NULL;
56962+ struct acl_object_label *obj;
56963+ struct file *filp;
56964+
56965+ if (unlikely(!(gr_status & GR_READY)))
56966+ return;
56967+
56968+ filp = task->exec_file;
56969+
56970+ /* kernel process, we'll give them the kernel role */
56971+ if (unlikely(!filp)) {
56972+ task->role = kernel_role;
56973+ task->acl = kernel_role->root_label;
56974+ return;
56975+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
56976+ role = lookup_acl_role_label(task, uid, gid);
56977+
56978+ /* don't change the role if we're not a privileged process */
56979+ if (role && task->role != role &&
56980+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
56981+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
56982+ return;
56983+
56984+ /* perform subject lookup in possibly new role
56985+ we can use this result below in the case where role == task->role
56986+ */
56987+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
56988+
56989+ /* if we changed uid/gid, but result in the same role
56990+ and are using inheritance, don't lose the inherited subject
56991+ if current subject is other than what normal lookup
56992+ would result in, we arrived via inheritance, don't
56993+ lose subject
56994+ */
56995+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
56996+ (subj == task->acl)))
56997+ task->acl = subj;
56998+
56999+ task->role = role;
57000+
57001+ task->is_writable = 0;
57002+
57003+ /* ignore additional mmap checks for processes that are writable
57004+ by the default ACL */
57005+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57006+ if (unlikely(obj->mode & GR_WRITE))
57007+ task->is_writable = 1;
57008+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
57009+ if (unlikely(obj->mode & GR_WRITE))
57010+ task->is_writable = 1;
57011+
57012+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57013+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57014+#endif
57015+
57016+ gr_set_proc_res(task);
57017+
57018+ return;
57019+}
57020+
57021+int
57022+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57023+ const int unsafe_flags)
57024+{
57025+ struct task_struct *task = current;
57026+ struct acl_subject_label *newacl;
57027+ struct acl_object_label *obj;
57028+ __u32 retmode;
57029+
57030+ if (unlikely(!(gr_status & GR_READY)))
57031+ return 0;
57032+
57033+ newacl = chk_subj_label(dentry, mnt, task->role);
57034+
57035+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
57036+ did an exec
57037+ */
57038+ rcu_read_lock();
57039+ read_lock(&tasklist_lock);
57040+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
57041+ (task->parent->acl->mode & GR_POVERRIDE))) {
57042+ read_unlock(&tasklist_lock);
57043+ rcu_read_unlock();
57044+ goto skip_check;
57045+ }
57046+ read_unlock(&tasklist_lock);
57047+ rcu_read_unlock();
57048+
57049+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
57050+ !(task->role->roletype & GR_ROLE_GOD) &&
57051+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
57052+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
57053+ if (unsafe_flags & LSM_UNSAFE_SHARE)
57054+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
57055+ else
57056+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
57057+ return -EACCES;
57058+ }
57059+
57060+skip_check:
57061+
57062+ obj = chk_obj_label(dentry, mnt, task->acl);
57063+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
57064+
57065+ if (!(task->acl->mode & GR_INHERITLEARN) &&
57066+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
57067+ if (obj->nested)
57068+ task->acl = obj->nested;
57069+ else
57070+ task->acl = newacl;
57071+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
57072+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
57073+
57074+ task->is_writable = 0;
57075+
57076+ /* ignore additional mmap checks for processes that are writable
57077+ by the default ACL */
57078+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
57079+ if (unlikely(obj->mode & GR_WRITE))
57080+ task->is_writable = 1;
57081+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
57082+ if (unlikely(obj->mode & GR_WRITE))
57083+ task->is_writable = 1;
57084+
57085+ gr_set_proc_res(task);
57086+
57087+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57088+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57089+#endif
57090+ return 0;
57091+}
57092+
57093+/* always called with valid inodev ptr */
57094+static void
57095+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
57096+{
57097+ struct acl_object_label *matchpo;
57098+ struct acl_subject_label *matchps;
57099+ struct acl_subject_label *subj;
57100+ struct acl_role_label *role;
57101+ unsigned int x;
57102+
57103+ FOR_EACH_ROLE_START(role)
57104+ FOR_EACH_SUBJECT_START(role, subj, x)
57105+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
57106+ matchpo->mode |= GR_DELETED;
57107+ FOR_EACH_SUBJECT_END(subj,x)
57108+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
57109+ /* nested subjects aren't in the role's subj_hash table */
57110+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
57111+ matchpo->mode |= GR_DELETED;
57112+ FOR_EACH_NESTED_SUBJECT_END(subj)
57113+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
57114+ matchps->mode |= GR_DELETED;
57115+ FOR_EACH_ROLE_END(role)
57116+
57117+ inodev->nentry->deleted = 1;
57118+
57119+ return;
57120+}
57121+
57122+void
57123+gr_handle_delete(const ino_t ino, const dev_t dev)
57124+{
57125+ struct inodev_entry *inodev;
57126+
57127+ if (unlikely(!(gr_status & GR_READY)))
57128+ return;
57129+
57130+ write_lock(&gr_inode_lock);
57131+ inodev = lookup_inodev_entry(ino, dev);
57132+ if (inodev != NULL)
57133+ do_handle_delete(inodev, ino, dev);
57134+ write_unlock(&gr_inode_lock);
57135+
57136+ return;
57137+}
57138+
57139+static void
57140+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
57141+ const ino_t newinode, const dev_t newdevice,
57142+ struct acl_subject_label *subj)
57143+{
57144+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
57145+ struct acl_object_label *match;
57146+
57147+ match = subj->obj_hash[index];
57148+
57149+ while (match && (match->inode != oldinode ||
57150+ match->device != olddevice ||
57151+ !(match->mode & GR_DELETED)))
57152+ match = match->next;
57153+
57154+ if (match && (match->inode == oldinode)
57155+ && (match->device == olddevice)
57156+ && (match->mode & GR_DELETED)) {
57157+ if (match->prev == NULL) {
57158+ subj->obj_hash[index] = match->next;
57159+ if (match->next != NULL)
57160+ match->next->prev = NULL;
57161+ } else {
57162+ match->prev->next = match->next;
57163+ if (match->next != NULL)
57164+ match->next->prev = match->prev;
57165+ }
57166+ match->prev = NULL;
57167+ match->next = NULL;
57168+ match->inode = newinode;
57169+ match->device = newdevice;
57170+ match->mode &= ~GR_DELETED;
57171+
57172+ insert_acl_obj_label(match, subj);
57173+ }
57174+
57175+ return;
57176+}
57177+
57178+static void
57179+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
57180+ const ino_t newinode, const dev_t newdevice,
57181+ struct acl_role_label *role)
57182+{
57183+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
57184+ struct acl_subject_label *match;
57185+
57186+ match = role->subj_hash[index];
57187+
57188+ while (match && (match->inode != oldinode ||
57189+ match->device != olddevice ||
57190+ !(match->mode & GR_DELETED)))
57191+ match = match->next;
57192+
57193+ if (match && (match->inode == oldinode)
57194+ && (match->device == olddevice)
57195+ && (match->mode & GR_DELETED)) {
57196+ if (match->prev == NULL) {
57197+ role->subj_hash[index] = match->next;
57198+ if (match->next != NULL)
57199+ match->next->prev = NULL;
57200+ } else {
57201+ match->prev->next = match->next;
57202+ if (match->next != NULL)
57203+ match->next->prev = match->prev;
57204+ }
57205+ match->prev = NULL;
57206+ match->next = NULL;
57207+ match->inode = newinode;
57208+ match->device = newdevice;
57209+ match->mode &= ~GR_DELETED;
57210+
57211+ insert_acl_subj_label(match, role);
57212+ }
57213+
57214+ return;
57215+}
57216+
57217+static void
57218+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
57219+ const ino_t newinode, const dev_t newdevice)
57220+{
57221+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
57222+ struct inodev_entry *match;
57223+
57224+ match = inodev_set.i_hash[index];
57225+
57226+ while (match && (match->nentry->inode != oldinode ||
57227+ match->nentry->device != olddevice || !match->nentry->deleted))
57228+ match = match->next;
57229+
57230+ if (match && (match->nentry->inode == oldinode)
57231+ && (match->nentry->device == olddevice) &&
57232+ match->nentry->deleted) {
57233+ if (match->prev == NULL) {
57234+ inodev_set.i_hash[index] = match->next;
57235+ if (match->next != NULL)
57236+ match->next->prev = NULL;
57237+ } else {
57238+ match->prev->next = match->next;
57239+ if (match->next != NULL)
57240+ match->next->prev = match->prev;
57241+ }
57242+ match->prev = NULL;
57243+ match->next = NULL;
57244+ match->nentry->inode = newinode;
57245+ match->nentry->device = newdevice;
57246+ match->nentry->deleted = 0;
57247+
57248+ insert_inodev_entry(match);
57249+ }
57250+
57251+ return;
57252+}
57253+
57254+static void
57255+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
57256+{
57257+ struct acl_subject_label *subj;
57258+ struct acl_role_label *role;
57259+ unsigned int x;
57260+
57261+ FOR_EACH_ROLE_START(role)
57262+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
57263+
57264+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
57265+ if ((subj->inode == ino) && (subj->device == dev)) {
57266+ subj->inode = ino;
57267+ subj->device = dev;
57268+ }
57269+ /* nested subjects aren't in the role's subj_hash table */
57270+ update_acl_obj_label(matchn->inode, matchn->device,
57271+ ino, dev, subj);
57272+ FOR_EACH_NESTED_SUBJECT_END(subj)
57273+ FOR_EACH_SUBJECT_START(role, subj, x)
57274+ update_acl_obj_label(matchn->inode, matchn->device,
57275+ ino, dev, subj);
57276+ FOR_EACH_SUBJECT_END(subj,x)
57277+ FOR_EACH_ROLE_END(role)
57278+
57279+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
57280+
57281+ return;
57282+}
57283+
57284+static void
57285+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
57286+ const struct vfsmount *mnt)
57287+{
57288+ ino_t ino = dentry->d_inode->i_ino;
57289+ dev_t dev = __get_dev(dentry);
57290+
57291+ __do_handle_create(matchn, ino, dev);
57292+
57293+ return;
57294+}
57295+
57296+void
57297+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57298+{
57299+ struct name_entry *matchn;
57300+
57301+ if (unlikely(!(gr_status & GR_READY)))
57302+ return;
57303+
57304+ preempt_disable();
57305+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
57306+
57307+ if (unlikely((unsigned long)matchn)) {
57308+ write_lock(&gr_inode_lock);
57309+ do_handle_create(matchn, dentry, mnt);
57310+ write_unlock(&gr_inode_lock);
57311+ }
57312+ preempt_enable();
57313+
57314+ return;
57315+}
57316+
57317+void
57318+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57319+{
57320+ struct name_entry *matchn;
57321+
57322+ if (unlikely(!(gr_status & GR_READY)))
57323+ return;
57324+
57325+ preempt_disable();
57326+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
57327+
57328+ if (unlikely((unsigned long)matchn)) {
57329+ write_lock(&gr_inode_lock);
57330+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
57331+ write_unlock(&gr_inode_lock);
57332+ }
57333+ preempt_enable();
57334+
57335+ return;
57336+}
57337+
57338+void
57339+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57340+ struct dentry *old_dentry,
57341+ struct dentry *new_dentry,
57342+ struct vfsmount *mnt, const __u8 replace)
57343+{
57344+ struct name_entry *matchn;
57345+ struct inodev_entry *inodev;
57346+ struct inode *inode = new_dentry->d_inode;
57347+ ino_t old_ino = old_dentry->d_inode->i_ino;
57348+ dev_t old_dev = __get_dev(old_dentry);
57349+
57350+ /* vfs_rename swaps the name and parent link for old_dentry and
57351+ new_dentry
57352+ at this point, old_dentry has the new name, parent link, and inode
57353+ for the renamed file
57354+ if a file is being replaced by a rename, new_dentry has the inode
57355+ and name for the replaced file
57356+ */
57357+
57358+ if (unlikely(!(gr_status & GR_READY)))
57359+ return;
57360+
57361+ preempt_disable();
57362+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
57363+
57364+ /* we wouldn't have to check d_inode if it weren't for
57365+ NFS silly-renaming
57366+ */
57367+
57368+ write_lock(&gr_inode_lock);
57369+ if (unlikely(replace && inode)) {
57370+ ino_t new_ino = inode->i_ino;
57371+ dev_t new_dev = __get_dev(new_dentry);
57372+
57373+ inodev = lookup_inodev_entry(new_ino, new_dev);
57374+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
57375+ do_handle_delete(inodev, new_ino, new_dev);
57376+ }
57377+
57378+ inodev = lookup_inodev_entry(old_ino, old_dev);
57379+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
57380+ do_handle_delete(inodev, old_ino, old_dev);
57381+
57382+ if (unlikely((unsigned long)matchn))
57383+ do_handle_create(matchn, old_dentry, mnt);
57384+
57385+ write_unlock(&gr_inode_lock);
57386+ preempt_enable();
57387+
57388+ return;
57389+}
57390+
57391+static int
57392+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
57393+ unsigned char **sum)
57394+{
57395+ struct acl_role_label *r;
57396+ struct role_allowed_ip *ipp;
57397+ struct role_transition *trans;
57398+ unsigned int i;
57399+ int found = 0;
57400+ u32 curr_ip = current->signal->curr_ip;
57401+
57402+ current->signal->saved_ip = curr_ip;
57403+
57404+ /* check transition table */
57405+
57406+ for (trans = current->role->transitions; trans; trans = trans->next) {
57407+ if (!strcmp(rolename, trans->rolename)) {
57408+ found = 1;
57409+ break;
57410+ }
57411+ }
57412+
57413+ if (!found)
57414+ return 0;
57415+
57416+ /* handle special roles that do not require authentication
57417+ and check ip */
57418+
57419+ FOR_EACH_ROLE_START(r)
57420+ if (!strcmp(rolename, r->rolename) &&
57421+ (r->roletype & GR_ROLE_SPECIAL)) {
57422+ found = 0;
57423+ if (r->allowed_ips != NULL) {
57424+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
57425+ if ((ntohl(curr_ip) & ipp->netmask) ==
57426+ (ntohl(ipp->addr) & ipp->netmask))
57427+ found = 1;
57428+ }
57429+ } else
57430+ found = 2;
57431+ if (!found)
57432+ return 0;
57433+
57434+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
57435+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
57436+ *salt = NULL;
57437+ *sum = NULL;
57438+ return 1;
57439+ }
57440+ }
57441+ FOR_EACH_ROLE_END(r)
57442+
57443+ for (i = 0; i < num_sprole_pws; i++) {
57444+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
57445+ *salt = acl_special_roles[i]->salt;
57446+ *sum = acl_special_roles[i]->sum;
57447+ return 1;
57448+ }
57449+ }
57450+
57451+ return 0;
57452+}
57453+
57454+static void
57455+assign_special_role(char *rolename)
57456+{
57457+ struct acl_object_label *obj;
57458+ struct acl_role_label *r;
57459+ struct acl_role_label *assigned = NULL;
57460+ struct task_struct *tsk;
57461+ struct file *filp;
57462+
57463+ FOR_EACH_ROLE_START(r)
57464+ if (!strcmp(rolename, r->rolename) &&
57465+ (r->roletype & GR_ROLE_SPECIAL)) {
57466+ assigned = r;
57467+ break;
57468+ }
57469+ FOR_EACH_ROLE_END(r)
57470+
57471+ if (!assigned)
57472+ return;
57473+
57474+ read_lock(&tasklist_lock);
57475+ read_lock(&grsec_exec_file_lock);
57476+
57477+ tsk = current->real_parent;
57478+ if (tsk == NULL)
57479+ goto out_unlock;
57480+
57481+ filp = tsk->exec_file;
57482+ if (filp == NULL)
57483+ goto out_unlock;
57484+
57485+ tsk->is_writable = 0;
57486+
57487+ tsk->acl_sp_role = 1;
57488+ tsk->acl_role_id = ++acl_sp_role_value;
57489+ tsk->role = assigned;
57490+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
57491+
57492+ /* ignore additional mmap checks for processes that are writable
57493+ by the default ACL */
57494+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57495+ if (unlikely(obj->mode & GR_WRITE))
57496+ tsk->is_writable = 1;
57497+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
57498+ if (unlikely(obj->mode & GR_WRITE))
57499+ tsk->is_writable = 1;
57500+
57501+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57502+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
57503+#endif
57504+
57505+out_unlock:
57506+ read_unlock(&grsec_exec_file_lock);
57507+ read_unlock(&tasklist_lock);
57508+ return;
57509+}
57510+
57511+int gr_check_secure_terminal(struct task_struct *task)
57512+{
57513+ struct task_struct *p, *p2, *p3;
57514+ struct files_struct *files;
57515+ struct fdtable *fdt;
57516+ struct file *our_file = NULL, *file;
57517+ int i;
57518+
57519+ if (task->signal->tty == NULL)
57520+ return 1;
57521+
57522+ files = get_files_struct(task);
57523+ if (files != NULL) {
57524+ rcu_read_lock();
57525+ fdt = files_fdtable(files);
57526+ for (i=0; i < fdt->max_fds; i++) {
57527+ file = fcheck_files(files, i);
57528+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
57529+ get_file(file);
57530+ our_file = file;
57531+ }
57532+ }
57533+ rcu_read_unlock();
57534+ put_files_struct(files);
57535+ }
57536+
57537+ if (our_file == NULL)
57538+ return 1;
57539+
57540+ read_lock(&tasklist_lock);
57541+ do_each_thread(p2, p) {
57542+ files = get_files_struct(p);
57543+ if (files == NULL ||
57544+ (p->signal && p->signal->tty == task->signal->tty)) {
57545+ if (files != NULL)
57546+ put_files_struct(files);
57547+ continue;
57548+ }
57549+ rcu_read_lock();
57550+ fdt = files_fdtable(files);
57551+ for (i=0; i < fdt->max_fds; i++) {
57552+ file = fcheck_files(files, i);
57553+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
57554+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
57555+ p3 = task;
57556+ while (p3->pid > 0) {
57557+ if (p3 == p)
57558+ break;
57559+ p3 = p3->real_parent;
57560+ }
57561+ if (p3 == p)
57562+ break;
57563+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
57564+ gr_handle_alertkill(p);
57565+ rcu_read_unlock();
57566+ put_files_struct(files);
57567+ read_unlock(&tasklist_lock);
57568+ fput(our_file);
57569+ return 0;
57570+ }
57571+ }
57572+ rcu_read_unlock();
57573+ put_files_struct(files);
57574+ } while_each_thread(p2, p);
57575+ read_unlock(&tasklist_lock);
57576+
57577+ fput(our_file);
57578+ return 1;
57579+}
57580+
57581+static int gr_rbac_disable(void *unused)
57582+{
57583+ pax_open_kernel();
57584+ gr_status &= ~GR_READY;
57585+ pax_close_kernel();
57586+
57587+ return 0;
57588+}
57589+
57590+ssize_t
57591+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
57592+{
57593+ struct gr_arg_wrapper uwrap;
57594+ unsigned char *sprole_salt = NULL;
57595+ unsigned char *sprole_sum = NULL;
57596+ int error = sizeof (struct gr_arg_wrapper);
57597+ int error2 = 0;
57598+
57599+ mutex_lock(&gr_dev_mutex);
57600+
57601+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
57602+ error = -EPERM;
57603+ goto out;
57604+ }
57605+
57606+ if (count != sizeof (struct gr_arg_wrapper)) {
57607+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
57608+ error = -EINVAL;
57609+ goto out;
57610+ }
57611+
57612+
57613+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
57614+ gr_auth_expires = 0;
57615+ gr_auth_attempts = 0;
57616+ }
57617+
57618+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
57619+ error = -EFAULT;
57620+ goto out;
57621+ }
57622+
57623+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
57624+ error = -EINVAL;
57625+ goto out;
57626+ }
57627+
57628+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
57629+ error = -EFAULT;
57630+ goto out;
57631+ }
57632+
57633+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
57634+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
57635+ time_after(gr_auth_expires, get_seconds())) {
57636+ error = -EBUSY;
57637+ goto out;
57638+ }
57639+
57640+ /* if non-root trying to do anything other than use a special role,
57641+ do not attempt authentication, do not count towards authentication
57642+ locking
57643+ */
57644+
57645+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
57646+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
57647+ !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
57648+ error = -EPERM;
57649+ goto out;
57650+ }
57651+
57652+ /* ensure pw and special role name are null terminated */
57653+
57654+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
57655+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
57656+
57657+ /* Okay.
57658+ * We have our enough of the argument structure..(we have yet
57659+ * to copy_from_user the tables themselves) . Copy the tables
57660+ * only if we need them, i.e. for loading operations. */
57661+
57662+ switch (gr_usermode->mode) {
57663+ case GR_STATUS:
57664+ if (gr_status & GR_READY) {
57665+ error = 1;
57666+ if (!gr_check_secure_terminal(current))
57667+ error = 3;
57668+ } else
57669+ error = 2;
57670+ goto out;
57671+ case GR_SHUTDOWN:
57672+ if ((gr_status & GR_READY)
57673+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57674+ stop_machine(gr_rbac_disable, NULL, NULL);
57675+ free_variables();
57676+ memset(gr_usermode, 0, sizeof (struct gr_arg));
57677+ memset(gr_system_salt, 0, GR_SALT_LEN);
57678+ memset(gr_system_sum, 0, GR_SHA_LEN);
57679+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
57680+ } else if (gr_status & GR_READY) {
57681+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
57682+ error = -EPERM;
57683+ } else {
57684+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
57685+ error = -EAGAIN;
57686+ }
57687+ break;
57688+ case GR_ENABLE:
57689+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
57690+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
57691+ else {
57692+ if (gr_status & GR_READY)
57693+ error = -EAGAIN;
57694+ else
57695+ error = error2;
57696+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
57697+ }
57698+ break;
57699+ case GR_RELOAD:
57700+ if (!(gr_status & GR_READY)) {
57701+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
57702+ error = -EAGAIN;
57703+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57704+ stop_machine(gr_rbac_disable, NULL, NULL);
57705+ free_variables();
57706+ error2 = gracl_init(gr_usermode);
57707+ if (!error2)
57708+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
57709+ else {
57710+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
57711+ error = error2;
57712+ }
57713+ } else {
57714+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
57715+ error = -EPERM;
57716+ }
57717+ break;
57718+ case GR_SEGVMOD:
57719+ if (unlikely(!(gr_status & GR_READY))) {
57720+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
57721+ error = -EAGAIN;
57722+ break;
57723+ }
57724+
57725+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57726+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
57727+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
57728+ struct acl_subject_label *segvacl;
57729+ segvacl =
57730+ lookup_acl_subj_label(gr_usermode->segv_inode,
57731+ gr_usermode->segv_device,
57732+ current->role);
57733+ if (segvacl) {
57734+ segvacl->crashes = 0;
57735+ segvacl->expires = 0;
57736+ }
57737+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
57738+ gr_remove_uid(gr_usermode->segv_uid);
57739+ }
57740+ } else {
57741+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
57742+ error = -EPERM;
57743+ }
57744+ break;
57745+ case GR_SPROLE:
57746+ case GR_SPROLEPAM:
57747+ if (unlikely(!(gr_status & GR_READY))) {
57748+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
57749+ error = -EAGAIN;
57750+ break;
57751+ }
57752+
57753+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
57754+ current->role->expires = 0;
57755+ current->role->auth_attempts = 0;
57756+ }
57757+
57758+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
57759+ time_after(current->role->expires, get_seconds())) {
57760+ error = -EBUSY;
57761+ goto out;
57762+ }
57763+
57764+ if (lookup_special_role_auth
57765+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
57766+ && ((!sprole_salt && !sprole_sum)
57767+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
57768+ char *p = "";
57769+ assign_special_role(gr_usermode->sp_role);
57770+ read_lock(&tasklist_lock);
57771+ if (current->real_parent)
57772+ p = current->real_parent->role->rolename;
57773+ read_unlock(&tasklist_lock);
57774+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
57775+ p, acl_sp_role_value);
57776+ } else {
57777+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
57778+ error = -EPERM;
57779+ if(!(current->role->auth_attempts++))
57780+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
57781+
57782+ goto out;
57783+ }
57784+ break;
57785+ case GR_UNSPROLE:
57786+ if (unlikely(!(gr_status & GR_READY))) {
57787+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
57788+ error = -EAGAIN;
57789+ break;
57790+ }
57791+
57792+ if (current->role->roletype & GR_ROLE_SPECIAL) {
57793+ char *p = "";
57794+ int i = 0;
57795+
57796+ read_lock(&tasklist_lock);
57797+ if (current->real_parent) {
57798+ p = current->real_parent->role->rolename;
57799+ i = current->real_parent->acl_role_id;
57800+ }
57801+ read_unlock(&tasklist_lock);
57802+
57803+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
57804+ gr_set_acls(1);
57805+ } else {
57806+ error = -EPERM;
57807+ goto out;
57808+ }
57809+ break;
57810+ default:
57811+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
57812+ error = -EINVAL;
57813+ break;
57814+ }
57815+
57816+ if (error != -EPERM)
57817+ goto out;
57818+
57819+ if(!(gr_auth_attempts++))
57820+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
57821+
57822+ out:
57823+ mutex_unlock(&gr_dev_mutex);
57824+ return error;
57825+}
57826+
57827+/* must be called with
57828+ rcu_read_lock();
57829+ read_lock(&tasklist_lock);
57830+ read_lock(&grsec_exec_file_lock);
57831+*/
57832+int gr_apply_subject_to_task(struct task_struct *task)
57833+{
57834+ struct acl_object_label *obj;
57835+ char *tmpname;
57836+ struct acl_subject_label *tmpsubj;
57837+ struct file *filp;
57838+ struct name_entry *nmatch;
57839+
57840+ filp = task->exec_file;
57841+ if (filp == NULL)
57842+ return 0;
57843+
57844+ /* the following is to apply the correct subject
57845+ on binaries running when the RBAC system
57846+ is enabled, when the binaries have been
57847+ replaced or deleted since their execution
57848+ -----
57849+ when the RBAC system starts, the inode/dev
57850+ from exec_file will be one the RBAC system
57851+ is unaware of. It only knows the inode/dev
57852+ of the present file on disk, or the absence
57853+ of it.
57854+ */
57855+ preempt_disable();
57856+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
57857+
57858+ nmatch = lookup_name_entry(tmpname);
57859+ preempt_enable();
57860+ tmpsubj = NULL;
57861+ if (nmatch) {
57862+ if (nmatch->deleted)
57863+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
57864+ else
57865+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
57866+ if (tmpsubj != NULL)
57867+ task->acl = tmpsubj;
57868+ }
57869+ if (tmpsubj == NULL)
57870+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
57871+ task->role);
57872+ if (task->acl) {
57873+ task->is_writable = 0;
57874+ /* ignore additional mmap checks for processes that are writable
57875+ by the default ACL */
57876+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57877+ if (unlikely(obj->mode & GR_WRITE))
57878+ task->is_writable = 1;
57879+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
57880+ if (unlikely(obj->mode & GR_WRITE))
57881+ task->is_writable = 1;
57882+
57883+ gr_set_proc_res(task);
57884+
57885+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57886+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57887+#endif
57888+ } else {
57889+ return 1;
57890+ }
57891+
57892+ return 0;
57893+}
57894+
57895+int
57896+gr_set_acls(const int type)
57897+{
57898+ struct task_struct *task, *task2;
57899+ struct acl_role_label *role = current->role;
57900+ __u16 acl_role_id = current->acl_role_id;
57901+ const struct cred *cred;
57902+ int ret;
57903+
57904+ rcu_read_lock();
57905+ read_lock(&tasklist_lock);
57906+ read_lock(&grsec_exec_file_lock);
57907+ do_each_thread(task2, task) {
57908+ /* check to see if we're called from the exit handler,
57909+ if so, only replace ACLs that have inherited the admin
57910+ ACL */
57911+
57912+ if (type && (task->role != role ||
57913+ task->acl_role_id != acl_role_id))
57914+ continue;
57915+
57916+ task->acl_role_id = 0;
57917+ task->acl_sp_role = 0;
57918+
57919+ if (task->exec_file) {
57920+ cred = __task_cred(task);
57921+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
57922+ ret = gr_apply_subject_to_task(task);
57923+ if (ret) {
57924+ read_unlock(&grsec_exec_file_lock);
57925+ read_unlock(&tasklist_lock);
57926+ rcu_read_unlock();
57927+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
57928+ return ret;
57929+ }
57930+ } else {
57931+ // it's a kernel process
57932+ task->role = kernel_role;
57933+ task->acl = kernel_role->root_label;
57934+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
57935+ task->acl->mode &= ~GR_PROCFIND;
57936+#endif
57937+ }
57938+ } while_each_thread(task2, task);
57939+ read_unlock(&grsec_exec_file_lock);
57940+ read_unlock(&tasklist_lock);
57941+ rcu_read_unlock();
57942+
57943+ return 0;
57944+}
57945+
57946+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
57947+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
57948+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
57949+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
57950+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
57951+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
57952+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
57953+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
57954+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
57955+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
57956+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
57957+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
57958+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
57959+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
57960+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
57961+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
57962+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
57963+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
57964+};
57965+
57966+void
57967+gr_learn_resource(const struct task_struct *task,
57968+ const int res, const unsigned long wanted, const int gt)
57969+{
57970+ struct acl_subject_label *acl;
57971+ const struct cred *cred;
57972+
57973+ if (unlikely((gr_status & GR_READY) &&
57974+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
57975+ goto skip_reslog;
57976+
57977+ gr_log_resource(task, res, wanted, gt);
57978+skip_reslog:
57979+
57980+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
57981+ return;
57982+
57983+ acl = task->acl;
57984+
57985+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
57986+ !(acl->resmask & (1 << (unsigned short) res))))
57987+ return;
57988+
57989+ if (wanted >= acl->res[res].rlim_cur) {
57990+ unsigned long res_add;
57991+
57992+ res_add = wanted + res_learn_bumps[res];
57993+
57994+ acl->res[res].rlim_cur = res_add;
57995+
57996+ if (wanted > acl->res[res].rlim_max)
57997+ acl->res[res].rlim_max = res_add;
57998+
57999+ /* only log the subject filename, since resource logging is supported for
58000+ single-subject learning only */
58001+ rcu_read_lock();
58002+ cred = __task_cred(task);
58003+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
58004+ task->role->roletype, cred->uid, cred->gid, acl->filename,
58005+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
58006+ "", (unsigned long) res, &task->signal->saved_ip);
58007+ rcu_read_unlock();
58008+ }
58009+
58010+ return;
58011+}
58012+EXPORT_SYMBOL(gr_learn_resource);
58013+#endif
58014+
58015+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
58016+void
58017+pax_set_initial_flags(struct linux_binprm *bprm)
58018+{
58019+ struct task_struct *task = current;
58020+ struct acl_subject_label *proc;
58021+ unsigned long flags;
58022+
58023+ if (unlikely(!(gr_status & GR_READY)))
58024+ return;
58025+
58026+ flags = pax_get_flags(task);
58027+
58028+ proc = task->acl;
58029+
58030+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
58031+ flags &= ~MF_PAX_PAGEEXEC;
58032+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
58033+ flags &= ~MF_PAX_SEGMEXEC;
58034+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
58035+ flags &= ~MF_PAX_RANDMMAP;
58036+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
58037+ flags &= ~MF_PAX_EMUTRAMP;
58038+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
58039+ flags &= ~MF_PAX_MPROTECT;
58040+
58041+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
58042+ flags |= MF_PAX_PAGEEXEC;
58043+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
58044+ flags |= MF_PAX_SEGMEXEC;
58045+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
58046+ flags |= MF_PAX_RANDMMAP;
58047+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
58048+ flags |= MF_PAX_EMUTRAMP;
58049+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
58050+ flags |= MF_PAX_MPROTECT;
58051+
58052+ pax_set_flags(task, flags);
58053+
58054+ return;
58055+}
58056+#endif
58057+
58058+int
58059+gr_handle_proc_ptrace(struct task_struct *task)
58060+{
58061+ struct file *filp;
58062+ struct task_struct *tmp = task;
58063+ struct task_struct *curtemp = current;
58064+ __u32 retmode;
58065+
58066+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
58067+ if (unlikely(!(gr_status & GR_READY)))
58068+ return 0;
58069+#endif
58070+
58071+ read_lock(&tasklist_lock);
58072+ read_lock(&grsec_exec_file_lock);
58073+ filp = task->exec_file;
58074+
58075+ while (tmp->pid > 0) {
58076+ if (tmp == curtemp)
58077+ break;
58078+ tmp = tmp->real_parent;
58079+ }
58080+
58081+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
58082+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
58083+ read_unlock(&grsec_exec_file_lock);
58084+ read_unlock(&tasklist_lock);
58085+ return 1;
58086+ }
58087+
58088+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58089+ if (!(gr_status & GR_READY)) {
58090+ read_unlock(&grsec_exec_file_lock);
58091+ read_unlock(&tasklist_lock);
58092+ return 0;
58093+ }
58094+#endif
58095+
58096+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
58097+ read_unlock(&grsec_exec_file_lock);
58098+ read_unlock(&tasklist_lock);
58099+
58100+ if (retmode & GR_NOPTRACE)
58101+ return 1;
58102+
58103+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
58104+ && (current->acl != task->acl || (current->acl != current->role->root_label
58105+ && current->pid != task->pid)))
58106+ return 1;
58107+
58108+ return 0;
58109+}
58110+
58111+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
58112+{
58113+ if (unlikely(!(gr_status & GR_READY)))
58114+ return;
58115+
58116+ if (!(current->role->roletype & GR_ROLE_GOD))
58117+ return;
58118+
58119+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
58120+ p->role->rolename, gr_task_roletype_to_char(p),
58121+ p->acl->filename);
58122+}
58123+
58124+int
58125+gr_handle_ptrace(struct task_struct *task, const long request)
58126+{
58127+ struct task_struct *tmp = task;
58128+ struct task_struct *curtemp = current;
58129+ __u32 retmode;
58130+
58131+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
58132+ if (unlikely(!(gr_status & GR_READY)))
58133+ return 0;
58134+#endif
58135+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
58136+ read_lock(&tasklist_lock);
58137+ while (tmp->pid > 0) {
58138+ if (tmp == curtemp)
58139+ break;
58140+ tmp = tmp->real_parent;
58141+ }
58142+
58143+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
58144+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
58145+ read_unlock(&tasklist_lock);
58146+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58147+ return 1;
58148+ }
58149+ read_unlock(&tasklist_lock);
58150+ }
58151+
58152+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58153+ if (!(gr_status & GR_READY))
58154+ return 0;
58155+#endif
58156+
58157+ read_lock(&grsec_exec_file_lock);
58158+ if (unlikely(!task->exec_file)) {
58159+ read_unlock(&grsec_exec_file_lock);
58160+ return 0;
58161+ }
58162+
58163+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
58164+ read_unlock(&grsec_exec_file_lock);
58165+
58166+ if (retmode & GR_NOPTRACE) {
58167+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58168+ return 1;
58169+ }
58170+
58171+ if (retmode & GR_PTRACERD) {
58172+ switch (request) {
58173+ case PTRACE_SEIZE:
58174+ case PTRACE_POKETEXT:
58175+ case PTRACE_POKEDATA:
58176+ case PTRACE_POKEUSR:
58177+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
58178+ case PTRACE_SETREGS:
58179+ case PTRACE_SETFPREGS:
58180+#endif
58181+#ifdef CONFIG_X86
58182+ case PTRACE_SETFPXREGS:
58183+#endif
58184+#ifdef CONFIG_ALTIVEC
58185+ case PTRACE_SETVRREGS:
58186+#endif
58187+ return 1;
58188+ default:
58189+ return 0;
58190+ }
58191+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
58192+ !(current->role->roletype & GR_ROLE_GOD) &&
58193+ (current->acl != task->acl)) {
58194+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58195+ return 1;
58196+ }
58197+
58198+ return 0;
58199+}
58200+
58201+static int is_writable_mmap(const struct file *filp)
58202+{
58203+ struct task_struct *task = current;
58204+ struct acl_object_label *obj, *obj2;
58205+
58206+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
58207+ !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))) {
58208+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
58209+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
58210+ task->role->root_label);
58211+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
58212+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
58213+ return 1;
58214+ }
58215+ }
58216+ return 0;
58217+}
58218+
58219+int
58220+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
58221+{
58222+ __u32 mode;
58223+
58224+ if (unlikely(!file || !(prot & PROT_EXEC)))
58225+ return 1;
58226+
58227+ if (is_writable_mmap(file))
58228+ return 0;
58229+
58230+ mode =
58231+ gr_search_file(file->f_path.dentry,
58232+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
58233+ file->f_path.mnt);
58234+
58235+ if (!gr_tpe_allow(file))
58236+ return 0;
58237+
58238+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
58239+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58240+ return 0;
58241+ } else if (unlikely(!(mode & GR_EXEC))) {
58242+ return 0;
58243+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
58244+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58245+ return 1;
58246+ }
58247+
58248+ return 1;
58249+}
58250+
58251+int
58252+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58253+{
58254+ __u32 mode;
58255+
58256+ if (unlikely(!file || !(prot & PROT_EXEC)))
58257+ return 1;
58258+
58259+ if (is_writable_mmap(file))
58260+ return 0;
58261+
58262+ mode =
58263+ gr_search_file(file->f_path.dentry,
58264+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
58265+ file->f_path.mnt);
58266+
58267+ if (!gr_tpe_allow(file))
58268+ return 0;
58269+
58270+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
58271+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58272+ return 0;
58273+ } else if (unlikely(!(mode & GR_EXEC))) {
58274+ return 0;
58275+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
58276+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58277+ return 1;
58278+ }
58279+
58280+ return 1;
58281+}
58282+
58283+void
58284+gr_acl_handle_psacct(struct task_struct *task, const long code)
58285+{
58286+ unsigned long runtime;
58287+ unsigned long cputime;
58288+ unsigned int wday, cday;
58289+ __u8 whr, chr;
58290+ __u8 wmin, cmin;
58291+ __u8 wsec, csec;
58292+ struct timespec timeval;
58293+
58294+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
58295+ !(task->acl->mode & GR_PROCACCT)))
58296+ return;
58297+
58298+ do_posix_clock_monotonic_gettime(&timeval);
58299+ runtime = timeval.tv_sec - task->start_time.tv_sec;
58300+ wday = runtime / (3600 * 24);
58301+ runtime -= wday * (3600 * 24);
58302+ whr = runtime / 3600;
58303+ runtime -= whr * 3600;
58304+ wmin = runtime / 60;
58305+ runtime -= wmin * 60;
58306+ wsec = runtime;
58307+
58308+ cputime = (task->utime + task->stime) / HZ;
58309+ cday = cputime / (3600 * 24);
58310+ cputime -= cday * (3600 * 24);
58311+ chr = cputime / 3600;
58312+ cputime -= chr * 3600;
58313+ cmin = cputime / 60;
58314+ cputime -= cmin * 60;
58315+ csec = cputime;
58316+
58317+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
58318+
58319+ return;
58320+}
58321+
58322+void gr_set_kernel_label(struct task_struct *task)
58323+{
58324+ if (gr_status & GR_READY) {
58325+ task->role = kernel_role;
58326+ task->acl = kernel_role->root_label;
58327+ }
58328+ return;
58329+}
58330+
58331+#ifdef CONFIG_TASKSTATS
58332+int gr_is_taskstats_denied(int pid)
58333+{
58334+ struct task_struct *task;
58335+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58336+ const struct cred *cred;
58337+#endif
58338+ int ret = 0;
58339+
58340+ /* restrict taskstats viewing to un-chrooted root users
58341+ who have the 'view' subject flag if the RBAC system is enabled
58342+ */
58343+
58344+ rcu_read_lock();
58345+ read_lock(&tasklist_lock);
58346+ task = find_task_by_vpid(pid);
58347+ if (task) {
58348+#ifdef CONFIG_GRKERNSEC_CHROOT
58349+ if (proc_is_chrooted(task))
58350+ ret = -EACCES;
58351+#endif
58352+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58353+ cred = __task_cred(task);
58354+#ifdef CONFIG_GRKERNSEC_PROC_USER
58355+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
58356+ ret = -EACCES;
58357+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58358+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
58359+ ret = -EACCES;
58360+#endif
58361+#endif
58362+ if (gr_status & GR_READY) {
58363+ if (!(task->acl->mode & GR_VIEW))
58364+ ret = -EACCES;
58365+ }
58366+ } else
58367+ ret = -ENOENT;
58368+
58369+ read_unlock(&tasklist_lock);
58370+ rcu_read_unlock();
58371+
58372+ return ret;
58373+}
58374+#endif
58375+
58376+/* AUXV entries are filled via a descendant of search_binary_handler
58377+ after we've already applied the subject for the target
58378+*/
58379+int gr_acl_enable_at_secure(void)
58380+{
58381+ if (unlikely(!(gr_status & GR_READY)))
58382+ return 0;
58383+
58384+ if (current->acl->mode & GR_ATSECURE)
58385+ return 1;
58386+
58387+ return 0;
58388+}
58389+
58390+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
58391+{
58392+ struct task_struct *task = current;
58393+ struct dentry *dentry = file->f_path.dentry;
58394+ struct vfsmount *mnt = file->f_path.mnt;
58395+ struct acl_object_label *obj, *tmp;
58396+ struct acl_subject_label *subj;
58397+ unsigned int bufsize;
58398+ int is_not_root;
58399+ char *path;
58400+ dev_t dev = __get_dev(dentry);
58401+
58402+ if (unlikely(!(gr_status & GR_READY)))
58403+ return 1;
58404+
58405+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
58406+ return 1;
58407+
58408+ /* ignore Eric Biederman */
58409+ if (IS_PRIVATE(dentry->d_inode))
58410+ return 1;
58411+
58412+ subj = task->acl;
58413+ read_lock(&gr_inode_lock);
58414+ do {
58415+ obj = lookup_acl_obj_label(ino, dev, subj);
58416+ if (obj != NULL) {
58417+ read_unlock(&gr_inode_lock);
58418+ return (obj->mode & GR_FIND) ? 1 : 0;
58419+ }
58420+ } while ((subj = subj->parent_subject));
58421+ read_unlock(&gr_inode_lock);
58422+
58423+ /* this is purely an optimization since we're looking for an object
58424+ for the directory we're doing a readdir on
58425+ if it's possible for any globbed object to match the entry we're
58426+ filling into the directory, then the object we find here will be
58427+ an anchor point with attached globbed objects
58428+ */
58429+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
58430+ if (obj->globbed == NULL)
58431+ return (obj->mode & GR_FIND) ? 1 : 0;
58432+
58433+ is_not_root = ((obj->filename[0] == '/') &&
58434+ (obj->filename[1] == '\0')) ? 0 : 1;
58435+ bufsize = PAGE_SIZE - namelen - is_not_root;
58436+
58437+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
58438+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
58439+ return 1;
58440+
58441+ preempt_disable();
58442+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
58443+ bufsize);
58444+
58445+ bufsize = strlen(path);
58446+
58447+ /* if base is "/", don't append an additional slash */
58448+ if (is_not_root)
58449+ *(path + bufsize) = '/';
58450+ memcpy(path + bufsize + is_not_root, name, namelen);
58451+ *(path + bufsize + namelen + is_not_root) = '\0';
58452+
58453+ tmp = obj->globbed;
58454+ while (tmp) {
58455+ if (!glob_match(tmp->filename, path)) {
58456+ preempt_enable();
58457+ return (tmp->mode & GR_FIND) ? 1 : 0;
58458+ }
58459+ tmp = tmp->next;
58460+ }
58461+ preempt_enable();
58462+ return (obj->mode & GR_FIND) ? 1 : 0;
58463+}
58464+
58465+void gr_put_exec_file(struct task_struct *task)
58466+{
58467+ struct file *filp;
58468+
58469+ write_lock(&grsec_exec_file_lock);
58470+ filp = task->exec_file;
58471+ task->exec_file = NULL;
58472+ write_unlock(&grsec_exec_file_lock);
58473+
58474+ if (filp)
58475+ fput(filp);
58476+
58477+ return;
58478+}
58479+
58480+
58481+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
58482+EXPORT_SYMBOL(gr_acl_is_enabled);
58483+#endif
58484+EXPORT_SYMBOL(gr_set_kernel_label);
58485+#ifdef CONFIG_SECURITY
58486+EXPORT_SYMBOL(gr_check_user_change);
58487+EXPORT_SYMBOL(gr_check_group_change);
58488+#endif
58489+
58490diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
58491new file mode 100644
58492index 0000000..34fefda
58493--- /dev/null
58494+++ b/grsecurity/gracl_alloc.c
58495@@ -0,0 +1,105 @@
58496+#include <linux/kernel.h>
58497+#include <linux/mm.h>
58498+#include <linux/slab.h>
58499+#include <linux/vmalloc.h>
58500+#include <linux/gracl.h>
58501+#include <linux/grsecurity.h>
58502+
58503+static unsigned long alloc_stack_next = 1;
58504+static unsigned long alloc_stack_size = 1;
58505+static void **alloc_stack;
58506+
58507+static __inline__ int
58508+alloc_pop(void)
58509+{
58510+ if (alloc_stack_next == 1)
58511+ return 0;
58512+
58513+ kfree(alloc_stack[alloc_stack_next - 2]);
58514+
58515+ alloc_stack_next--;
58516+
58517+ return 1;
58518+}
58519+
58520+static __inline__ int
58521+alloc_push(void *buf)
58522+{
58523+ if (alloc_stack_next >= alloc_stack_size)
58524+ return 1;
58525+
58526+ alloc_stack[alloc_stack_next - 1] = buf;
58527+
58528+ alloc_stack_next++;
58529+
58530+ return 0;
58531+}
58532+
58533+void *
58534+acl_alloc(unsigned long len)
58535+{
58536+ void *ret = NULL;
58537+
58538+ if (!len || len > PAGE_SIZE)
58539+ goto out;
58540+
58541+ ret = kmalloc(len, GFP_KERNEL);
58542+
58543+ if (ret) {
58544+ if (alloc_push(ret)) {
58545+ kfree(ret);
58546+ ret = NULL;
58547+ }
58548+ }
58549+
58550+out:
58551+ return ret;
58552+}
58553+
58554+void *
58555+acl_alloc_num(unsigned long num, unsigned long len)
58556+{
58557+ if (!len || (num > (PAGE_SIZE / len)))
58558+ return NULL;
58559+
58560+ return acl_alloc(num * len);
58561+}
58562+
58563+void
58564+acl_free_all(void)
58565+{
58566+ if (gr_acl_is_enabled() || !alloc_stack)
58567+ return;
58568+
58569+ while (alloc_pop()) ;
58570+
58571+ if (alloc_stack) {
58572+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
58573+ kfree(alloc_stack);
58574+ else
58575+ vfree(alloc_stack);
58576+ }
58577+
58578+ alloc_stack = NULL;
58579+ alloc_stack_size = 1;
58580+ alloc_stack_next = 1;
58581+
58582+ return;
58583+}
58584+
58585+int
58586+acl_alloc_stack_init(unsigned long size)
58587+{
58588+ if ((size * sizeof (void *)) <= PAGE_SIZE)
58589+ alloc_stack =
58590+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
58591+ else
58592+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
58593+
58594+ alloc_stack_size = size;
58595+
58596+ if (!alloc_stack)
58597+ return 0;
58598+ else
58599+ return 1;
58600+}
58601diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
58602new file mode 100644
58603index 0000000..6d21049
58604--- /dev/null
58605+++ b/grsecurity/gracl_cap.c
58606@@ -0,0 +1,110 @@
58607+#include <linux/kernel.h>
58608+#include <linux/module.h>
58609+#include <linux/sched.h>
58610+#include <linux/gracl.h>
58611+#include <linux/grsecurity.h>
58612+#include <linux/grinternal.h>
58613+
58614+extern const char *captab_log[];
58615+extern int captab_log_entries;
58616+
58617+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58618+{
58619+ struct acl_subject_label *curracl;
58620+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
58621+ kernel_cap_t cap_audit = __cap_empty_set;
58622+
58623+ if (!gr_acl_is_enabled())
58624+ return 1;
58625+
58626+ curracl = task->acl;
58627+
58628+ cap_drop = curracl->cap_lower;
58629+ cap_mask = curracl->cap_mask;
58630+ cap_audit = curracl->cap_invert_audit;
58631+
58632+ while ((curracl = curracl->parent_subject)) {
58633+ /* if the cap isn't specified in the current computed mask but is specified in the
58634+ current level subject, and is lowered in the current level subject, then add
58635+ it to the set of dropped capabilities
58636+ otherwise, add the current level subject's mask to the current computed mask
58637+ */
58638+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
58639+ cap_raise(cap_mask, cap);
58640+ if (cap_raised(curracl->cap_lower, cap))
58641+ cap_raise(cap_drop, cap);
58642+ if (cap_raised(curracl->cap_invert_audit, cap))
58643+ cap_raise(cap_audit, cap);
58644+ }
58645+ }
58646+
58647+ if (!cap_raised(cap_drop, cap)) {
58648+ if (cap_raised(cap_audit, cap))
58649+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
58650+ return 1;
58651+ }
58652+
58653+ curracl = task->acl;
58654+
58655+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
58656+ && cap_raised(cred->cap_effective, cap)) {
58657+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
58658+ task->role->roletype, cred->uid,
58659+ cred->gid, task->exec_file ?
58660+ gr_to_filename(task->exec_file->f_path.dentry,
58661+ task->exec_file->f_path.mnt) : curracl->filename,
58662+ curracl->filename, 0UL,
58663+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
58664+ return 1;
58665+ }
58666+
58667+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
58668+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
58669+
58670+ return 0;
58671+}
58672+
58673+int
58674+gr_acl_is_capable(const int cap)
58675+{
58676+ return gr_task_acl_is_capable(current, current_cred(), cap);
58677+}
58678+
58679+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
58680+{
58681+ struct acl_subject_label *curracl;
58682+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
58683+
58684+ if (!gr_acl_is_enabled())
58685+ return 1;
58686+
58687+ curracl = task->acl;
58688+
58689+ cap_drop = curracl->cap_lower;
58690+ cap_mask = curracl->cap_mask;
58691+
58692+ while ((curracl = curracl->parent_subject)) {
58693+ /* if the cap isn't specified in the current computed mask but is specified in the
58694+ current level subject, and is lowered in the current level subject, then add
58695+ it to the set of dropped capabilities
58696+ otherwise, add the current level subject's mask to the current computed mask
58697+ */
58698+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
58699+ cap_raise(cap_mask, cap);
58700+ if (cap_raised(curracl->cap_lower, cap))
58701+ cap_raise(cap_drop, cap);
58702+ }
58703+ }
58704+
58705+ if (!cap_raised(cap_drop, cap))
58706+ return 1;
58707+
58708+ return 0;
58709+}
58710+
58711+int
58712+gr_acl_is_capable_nolog(const int cap)
58713+{
58714+ return gr_task_acl_is_capable_nolog(current, cap);
58715+}
58716+
58717diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
58718new file mode 100644
58719index 0000000..a340c17
58720--- /dev/null
58721+++ b/grsecurity/gracl_fs.c
58722@@ -0,0 +1,431 @@
58723+#include <linux/kernel.h>
58724+#include <linux/sched.h>
58725+#include <linux/types.h>
58726+#include <linux/fs.h>
58727+#include <linux/file.h>
58728+#include <linux/stat.h>
58729+#include <linux/grsecurity.h>
58730+#include <linux/grinternal.h>
58731+#include <linux/gracl.h>
58732+
58733+umode_t
58734+gr_acl_umask(void)
58735+{
58736+ if (unlikely(!gr_acl_is_enabled()))
58737+ return 0;
58738+
58739+ return current->role->umask;
58740+}
58741+
58742+__u32
58743+gr_acl_handle_hidden_file(const struct dentry * dentry,
58744+ const struct vfsmount * mnt)
58745+{
58746+ __u32 mode;
58747+
58748+ if (unlikely(!dentry->d_inode))
58749+ return GR_FIND;
58750+
58751+ mode =
58752+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
58753+
58754+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
58755+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
58756+ return mode;
58757+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
58758+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
58759+ return 0;
58760+ } else if (unlikely(!(mode & GR_FIND)))
58761+ return 0;
58762+
58763+ return GR_FIND;
58764+}
58765+
58766+__u32
58767+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58768+ int acc_mode)
58769+{
58770+ __u32 reqmode = GR_FIND;
58771+ __u32 mode;
58772+
58773+ if (unlikely(!dentry->d_inode))
58774+ return reqmode;
58775+
58776+ if (acc_mode & MAY_APPEND)
58777+ reqmode |= GR_APPEND;
58778+ else if (acc_mode & MAY_WRITE)
58779+ reqmode |= GR_WRITE;
58780+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
58781+ reqmode |= GR_READ;
58782+
58783+ mode =
58784+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
58785+ mnt);
58786+
58787+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58788+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
58789+ reqmode & GR_READ ? " reading" : "",
58790+ reqmode & GR_WRITE ? " writing" : reqmode &
58791+ GR_APPEND ? " appending" : "");
58792+ return reqmode;
58793+ } else
58794+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58795+ {
58796+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
58797+ reqmode & GR_READ ? " reading" : "",
58798+ reqmode & GR_WRITE ? " writing" : reqmode &
58799+ GR_APPEND ? " appending" : "");
58800+ return 0;
58801+ } else if (unlikely((mode & reqmode) != reqmode))
58802+ return 0;
58803+
58804+ return reqmode;
58805+}
58806+
58807+__u32
58808+gr_acl_handle_creat(const struct dentry * dentry,
58809+ const struct dentry * p_dentry,
58810+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58811+ const int imode)
58812+{
58813+ __u32 reqmode = GR_WRITE | GR_CREATE;
58814+ __u32 mode;
58815+
58816+ if (acc_mode & MAY_APPEND)
58817+ reqmode |= GR_APPEND;
58818+ // if a directory was required or the directory already exists, then
58819+ // don't count this open as a read
58820+ if ((acc_mode & MAY_READ) &&
58821+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
58822+ reqmode |= GR_READ;
58823+ if ((open_flags & O_CREAT) &&
58824+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
58825+ reqmode |= GR_SETID;
58826+
58827+ mode =
58828+ gr_check_create(dentry, p_dentry, p_mnt,
58829+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
58830+
58831+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58832+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
58833+ reqmode & GR_READ ? " reading" : "",
58834+ reqmode & GR_WRITE ? " writing" : reqmode &
58835+ GR_APPEND ? " appending" : "");
58836+ return reqmode;
58837+ } else
58838+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58839+ {
58840+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
58841+ reqmode & GR_READ ? " reading" : "",
58842+ reqmode & GR_WRITE ? " writing" : reqmode &
58843+ GR_APPEND ? " appending" : "");
58844+ return 0;
58845+ } else if (unlikely((mode & reqmode) != reqmode))
58846+ return 0;
58847+
58848+ return reqmode;
58849+}
58850+
58851+__u32
58852+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
58853+ const int fmode)
58854+{
58855+ __u32 mode, reqmode = GR_FIND;
58856+
58857+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
58858+ reqmode |= GR_EXEC;
58859+ if (fmode & S_IWOTH)
58860+ reqmode |= GR_WRITE;
58861+ if (fmode & S_IROTH)
58862+ reqmode |= GR_READ;
58863+
58864+ mode =
58865+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
58866+ mnt);
58867+
58868+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58869+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58870+ reqmode & GR_READ ? " reading" : "",
58871+ reqmode & GR_WRITE ? " writing" : "",
58872+ reqmode & GR_EXEC ? " executing" : "");
58873+ return reqmode;
58874+ } else
58875+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58876+ {
58877+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58878+ reqmode & GR_READ ? " reading" : "",
58879+ reqmode & GR_WRITE ? " writing" : "",
58880+ reqmode & GR_EXEC ? " executing" : "");
58881+ return 0;
58882+ } else if (unlikely((mode & reqmode) != reqmode))
58883+ return 0;
58884+
58885+ return reqmode;
58886+}
58887+
58888+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
58889+{
58890+ __u32 mode;
58891+
58892+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
58893+
58894+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58895+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
58896+ return mode;
58897+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58898+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
58899+ return 0;
58900+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
58901+ return 0;
58902+
58903+ return (reqmode);
58904+}
58905+
58906+__u32
58907+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58908+{
58909+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
58910+}
58911+
58912+__u32
58913+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
58914+{
58915+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
58916+}
58917+
58918+__u32
58919+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
58920+{
58921+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
58922+}
58923+
58924+__u32
58925+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
58926+{
58927+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
58928+}
58929+
58930+__u32
58931+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
58932+ umode_t *modeptr)
58933+{
58934+ umode_t mode;
58935+
58936+ *modeptr &= ~gr_acl_umask();
58937+ mode = *modeptr;
58938+
58939+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
58940+ return 1;
58941+
58942+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
58943+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
58944+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
58945+ GR_CHMOD_ACL_MSG);
58946+ } else {
58947+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
58948+ }
58949+}
58950+
58951+__u32
58952+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
58953+{
58954+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
58955+}
58956+
58957+__u32
58958+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
58959+{
58960+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
58961+}
58962+
58963+__u32
58964+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
58965+{
58966+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
58967+}
58968+
58969+__u32
58970+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
58971+{
58972+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
58973+ GR_UNIXCONNECT_ACL_MSG);
58974+}
58975+
58976+/* hardlinks require at minimum create and link permission,
58977+ any additional privilege required is based on the
58978+ privilege of the file being linked to
58979+*/
58980+__u32
58981+gr_acl_handle_link(const struct dentry * new_dentry,
58982+ const struct dentry * parent_dentry,
58983+ const struct vfsmount * parent_mnt,
58984+ const struct dentry * old_dentry,
58985+ const struct vfsmount * old_mnt, const struct filename *to)
58986+{
58987+ __u32 mode;
58988+ __u32 needmode = GR_CREATE | GR_LINK;
58989+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
58990+
58991+ mode =
58992+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
58993+ old_mnt);
58994+
58995+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
58996+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58997+ return mode;
58998+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58999+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
59000+ return 0;
59001+ } else if (unlikely((mode & needmode) != needmode))
59002+ return 0;
59003+
59004+ return 1;
59005+}
59006+
59007+__u32
59008+gr_acl_handle_symlink(const struct dentry * new_dentry,
59009+ const struct dentry * parent_dentry,
59010+ const struct vfsmount * parent_mnt, const struct filename *from)
59011+{
59012+ __u32 needmode = GR_WRITE | GR_CREATE;
59013+ __u32 mode;
59014+
59015+ mode =
59016+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
59017+ GR_CREATE | GR_AUDIT_CREATE |
59018+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
59019+
59020+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
59021+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
59022+ return mode;
59023+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
59024+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
59025+ return 0;
59026+ } else if (unlikely((mode & needmode) != needmode))
59027+ return 0;
59028+
59029+ return (GR_WRITE | GR_CREATE);
59030+}
59031+
59032+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)
59033+{
59034+ __u32 mode;
59035+
59036+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
59037+
59038+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
59039+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
59040+ return mode;
59041+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
59042+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
59043+ return 0;
59044+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
59045+ return 0;
59046+
59047+ return (reqmode);
59048+}
59049+
59050+__u32
59051+gr_acl_handle_mknod(const struct dentry * new_dentry,
59052+ const struct dentry * parent_dentry,
59053+ const struct vfsmount * parent_mnt,
59054+ const int mode)
59055+{
59056+ __u32 reqmode = GR_WRITE | GR_CREATE;
59057+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
59058+ reqmode |= GR_SETID;
59059+
59060+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
59061+ reqmode, GR_MKNOD_ACL_MSG);
59062+}
59063+
59064+__u32
59065+gr_acl_handle_mkdir(const struct dentry *new_dentry,
59066+ const struct dentry *parent_dentry,
59067+ const struct vfsmount *parent_mnt)
59068+{
59069+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
59070+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
59071+}
59072+
59073+#define RENAME_CHECK_SUCCESS(old, new) \
59074+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
59075+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
59076+
59077+int
59078+gr_acl_handle_rename(struct dentry *new_dentry,
59079+ struct dentry *parent_dentry,
59080+ const struct vfsmount *parent_mnt,
59081+ struct dentry *old_dentry,
59082+ struct inode *old_parent_inode,
59083+ struct vfsmount *old_mnt, const struct filename *newname)
59084+{
59085+ __u32 comp1, comp2;
59086+ int error = 0;
59087+
59088+ if (unlikely(!gr_acl_is_enabled()))
59089+ return 0;
59090+
59091+ if (!new_dentry->d_inode) {
59092+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
59093+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
59094+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
59095+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
59096+ GR_DELETE | GR_AUDIT_DELETE |
59097+ GR_AUDIT_READ | GR_AUDIT_WRITE |
59098+ GR_SUPPRESS, old_mnt);
59099+ } else {
59100+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
59101+ GR_CREATE | GR_DELETE |
59102+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
59103+ GR_AUDIT_READ | GR_AUDIT_WRITE |
59104+ GR_SUPPRESS, parent_mnt);
59105+ comp2 =
59106+ gr_search_file(old_dentry,
59107+ GR_READ | GR_WRITE | GR_AUDIT_READ |
59108+ GR_DELETE | GR_AUDIT_DELETE |
59109+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
59110+ }
59111+
59112+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
59113+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
59114+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
59115+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
59116+ && !(comp2 & GR_SUPPRESS)) {
59117+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
59118+ error = -EACCES;
59119+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
59120+ error = -EACCES;
59121+
59122+ return error;
59123+}
59124+
59125+void
59126+gr_acl_handle_exit(void)
59127+{
59128+ u16 id;
59129+ char *rolename;
59130+
59131+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
59132+ !(current->role->roletype & GR_ROLE_PERSIST))) {
59133+ id = current->acl_role_id;
59134+ rolename = current->role->rolename;
59135+ gr_set_acls(1);
59136+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
59137+ }
59138+
59139+ gr_put_exec_file(current);
59140+ return;
59141+}
59142+
59143+int
59144+gr_acl_handle_procpidmem(const struct task_struct *task)
59145+{
59146+ if (unlikely(!gr_acl_is_enabled()))
59147+ return 0;
59148+
59149+ if (task != current && task->acl->mode & GR_PROTPROCFD)
59150+ return -EACCES;
59151+
59152+ return 0;
59153+}
59154diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
59155new file mode 100644
59156index 0000000..58800a7
59157--- /dev/null
59158+++ b/grsecurity/gracl_ip.c
59159@@ -0,0 +1,384 @@
59160+#include <linux/kernel.h>
59161+#include <asm/uaccess.h>
59162+#include <asm/errno.h>
59163+#include <net/sock.h>
59164+#include <linux/file.h>
59165+#include <linux/fs.h>
59166+#include <linux/net.h>
59167+#include <linux/in.h>
59168+#include <linux/skbuff.h>
59169+#include <linux/ip.h>
59170+#include <linux/udp.h>
59171+#include <linux/types.h>
59172+#include <linux/sched.h>
59173+#include <linux/netdevice.h>
59174+#include <linux/inetdevice.h>
59175+#include <linux/gracl.h>
59176+#include <linux/grsecurity.h>
59177+#include <linux/grinternal.h>
59178+
59179+#define GR_BIND 0x01
59180+#define GR_CONNECT 0x02
59181+#define GR_INVERT 0x04
59182+#define GR_BINDOVERRIDE 0x08
59183+#define GR_CONNECTOVERRIDE 0x10
59184+#define GR_SOCK_FAMILY 0x20
59185+
59186+static const char * gr_protocols[IPPROTO_MAX] = {
59187+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
59188+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
59189+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
59190+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
59191+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
59192+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
59193+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
59194+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
59195+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
59196+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
59197+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
59198+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
59199+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
59200+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
59201+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
59202+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
59203+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
59204+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
59205+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
59206+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
59207+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
59208+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
59209+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
59210+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
59211+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
59212+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
59213+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
59214+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
59215+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
59216+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
59217+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
59218+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
59219+ };
59220+
59221+static const char * gr_socktypes[SOCK_MAX] = {
59222+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
59223+ "unknown:7", "unknown:8", "unknown:9", "packet"
59224+ };
59225+
59226+static const char * gr_sockfamilies[AF_MAX+1] = {
59227+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
59228+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
59229+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
59230+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
59231+ };
59232+
59233+const char *
59234+gr_proto_to_name(unsigned char proto)
59235+{
59236+ return gr_protocols[proto];
59237+}
59238+
59239+const char *
59240+gr_socktype_to_name(unsigned char type)
59241+{
59242+ return gr_socktypes[type];
59243+}
59244+
59245+const char *
59246+gr_sockfamily_to_name(unsigned char family)
59247+{
59248+ return gr_sockfamilies[family];
59249+}
59250+
59251+int
59252+gr_search_socket(const int domain, const int type, const int protocol)
59253+{
59254+ struct acl_subject_label *curr;
59255+ const struct cred *cred = current_cred();
59256+
59257+ if (unlikely(!gr_acl_is_enabled()))
59258+ goto exit;
59259+
59260+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
59261+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
59262+ goto exit; // let the kernel handle it
59263+
59264+ curr = current->acl;
59265+
59266+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
59267+ /* the family is allowed, if this is PF_INET allow it only if
59268+ the extra sock type/protocol checks pass */
59269+ if (domain == PF_INET)
59270+ goto inet_check;
59271+ goto exit;
59272+ } else {
59273+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59274+ __u32 fakeip = 0;
59275+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59276+ current->role->roletype, cred->uid,
59277+ cred->gid, current->exec_file ?
59278+ gr_to_filename(current->exec_file->f_path.dentry,
59279+ current->exec_file->f_path.mnt) :
59280+ curr->filename, curr->filename,
59281+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
59282+ &current->signal->saved_ip);
59283+ goto exit;
59284+ }
59285+ goto exit_fail;
59286+ }
59287+
59288+inet_check:
59289+ /* the rest of this checking is for IPv4 only */
59290+ if (!curr->ips)
59291+ goto exit;
59292+
59293+ if ((curr->ip_type & (1 << type)) &&
59294+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
59295+ goto exit;
59296+
59297+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59298+ /* we don't place acls on raw sockets , and sometimes
59299+ dgram/ip sockets are opened for ioctl and not
59300+ bind/connect, so we'll fake a bind learn log */
59301+ if (type == SOCK_RAW || type == SOCK_PACKET) {
59302+ __u32 fakeip = 0;
59303+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59304+ current->role->roletype, cred->uid,
59305+ cred->gid, current->exec_file ?
59306+ gr_to_filename(current->exec_file->f_path.dentry,
59307+ current->exec_file->f_path.mnt) :
59308+ curr->filename, curr->filename,
59309+ &fakeip, 0, type,
59310+ protocol, GR_CONNECT, &current->signal->saved_ip);
59311+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
59312+ __u32 fakeip = 0;
59313+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59314+ current->role->roletype, cred->uid,
59315+ cred->gid, current->exec_file ?
59316+ gr_to_filename(current->exec_file->f_path.dentry,
59317+ current->exec_file->f_path.mnt) :
59318+ curr->filename, curr->filename,
59319+ &fakeip, 0, type,
59320+ protocol, GR_BIND, &current->signal->saved_ip);
59321+ }
59322+ /* we'll log when they use connect or bind */
59323+ goto exit;
59324+ }
59325+
59326+exit_fail:
59327+ if (domain == PF_INET)
59328+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
59329+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
59330+ else
59331+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
59332+ gr_socktype_to_name(type), protocol);
59333+
59334+ return 0;
59335+exit:
59336+ return 1;
59337+}
59338+
59339+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)
59340+{
59341+ if ((ip->mode & mode) &&
59342+ (ip_port >= ip->low) &&
59343+ (ip_port <= ip->high) &&
59344+ ((ntohl(ip_addr) & our_netmask) ==
59345+ (ntohl(our_addr) & our_netmask))
59346+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
59347+ && (ip->type & (1 << type))) {
59348+ if (ip->mode & GR_INVERT)
59349+ return 2; // specifically denied
59350+ else
59351+ return 1; // allowed
59352+ }
59353+
59354+ return 0; // not specifically allowed, may continue parsing
59355+}
59356+
59357+static int
59358+gr_search_connectbind(const int full_mode, struct sock *sk,
59359+ struct sockaddr_in *addr, const int type)
59360+{
59361+ char iface[IFNAMSIZ] = {0};
59362+ struct acl_subject_label *curr;
59363+ struct acl_ip_label *ip;
59364+ struct inet_sock *isk;
59365+ struct net_device *dev;
59366+ struct in_device *idev;
59367+ unsigned long i;
59368+ int ret;
59369+ int mode = full_mode & (GR_BIND | GR_CONNECT);
59370+ __u32 ip_addr = 0;
59371+ __u32 our_addr;
59372+ __u32 our_netmask;
59373+ char *p;
59374+ __u16 ip_port = 0;
59375+ const struct cred *cred = current_cred();
59376+
59377+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
59378+ return 0;
59379+
59380+ curr = current->acl;
59381+ isk = inet_sk(sk);
59382+
59383+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
59384+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
59385+ addr->sin_addr.s_addr = curr->inaddr_any_override;
59386+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
59387+ struct sockaddr_in saddr;
59388+ int err;
59389+
59390+ saddr.sin_family = AF_INET;
59391+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
59392+ saddr.sin_port = isk->inet_sport;
59393+
59394+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
59395+ if (err)
59396+ return err;
59397+
59398+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
59399+ if (err)
59400+ return err;
59401+ }
59402+
59403+ if (!curr->ips)
59404+ return 0;
59405+
59406+ ip_addr = addr->sin_addr.s_addr;
59407+ ip_port = ntohs(addr->sin_port);
59408+
59409+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59410+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59411+ current->role->roletype, cred->uid,
59412+ cred->gid, current->exec_file ?
59413+ gr_to_filename(current->exec_file->f_path.dentry,
59414+ current->exec_file->f_path.mnt) :
59415+ curr->filename, curr->filename,
59416+ &ip_addr, ip_port, type,
59417+ sk->sk_protocol, mode, &current->signal->saved_ip);
59418+ return 0;
59419+ }
59420+
59421+ for (i = 0; i < curr->ip_num; i++) {
59422+ ip = *(curr->ips + i);
59423+ if (ip->iface != NULL) {
59424+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
59425+ p = strchr(iface, ':');
59426+ if (p != NULL)
59427+ *p = '\0';
59428+ dev = dev_get_by_name(sock_net(sk), iface);
59429+ if (dev == NULL)
59430+ continue;
59431+ idev = in_dev_get(dev);
59432+ if (idev == NULL) {
59433+ dev_put(dev);
59434+ continue;
59435+ }
59436+ rcu_read_lock();
59437+ for_ifa(idev) {
59438+ if (!strcmp(ip->iface, ifa->ifa_label)) {
59439+ our_addr = ifa->ifa_address;
59440+ our_netmask = 0xffffffff;
59441+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
59442+ if (ret == 1) {
59443+ rcu_read_unlock();
59444+ in_dev_put(idev);
59445+ dev_put(dev);
59446+ return 0;
59447+ } else if (ret == 2) {
59448+ rcu_read_unlock();
59449+ in_dev_put(idev);
59450+ dev_put(dev);
59451+ goto denied;
59452+ }
59453+ }
59454+ } endfor_ifa(idev);
59455+ rcu_read_unlock();
59456+ in_dev_put(idev);
59457+ dev_put(dev);
59458+ } else {
59459+ our_addr = ip->addr;
59460+ our_netmask = ip->netmask;
59461+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
59462+ if (ret == 1)
59463+ return 0;
59464+ else if (ret == 2)
59465+ goto denied;
59466+ }
59467+ }
59468+
59469+denied:
59470+ if (mode == GR_BIND)
59471+ 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));
59472+ else if (mode == GR_CONNECT)
59473+ 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));
59474+
59475+ return -EACCES;
59476+}
59477+
59478+int
59479+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
59480+{
59481+ /* always allow disconnection of dgram sockets with connect */
59482+ if (addr->sin_family == AF_UNSPEC)
59483+ return 0;
59484+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
59485+}
59486+
59487+int
59488+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
59489+{
59490+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
59491+}
59492+
59493+int gr_search_listen(struct socket *sock)
59494+{
59495+ struct sock *sk = sock->sk;
59496+ struct sockaddr_in addr;
59497+
59498+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
59499+ addr.sin_port = inet_sk(sk)->inet_sport;
59500+
59501+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
59502+}
59503+
59504+int gr_search_accept(struct socket *sock)
59505+{
59506+ struct sock *sk = sock->sk;
59507+ struct sockaddr_in addr;
59508+
59509+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
59510+ addr.sin_port = inet_sk(sk)->inet_sport;
59511+
59512+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
59513+}
59514+
59515+int
59516+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
59517+{
59518+ if (addr)
59519+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
59520+ else {
59521+ struct sockaddr_in sin;
59522+ const struct inet_sock *inet = inet_sk(sk);
59523+
59524+ sin.sin_addr.s_addr = inet->inet_daddr;
59525+ sin.sin_port = inet->inet_dport;
59526+
59527+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
59528+ }
59529+}
59530+
59531+int
59532+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
59533+{
59534+ struct sockaddr_in sin;
59535+
59536+ if (unlikely(skb->len < sizeof (struct udphdr)))
59537+ return 0; // skip this packet
59538+
59539+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
59540+ sin.sin_port = udp_hdr(skb)->source;
59541+
59542+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
59543+}
59544diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
59545new file mode 100644
59546index 0000000..25f54ef
59547--- /dev/null
59548+++ b/grsecurity/gracl_learn.c
59549@@ -0,0 +1,207 @@
59550+#include <linux/kernel.h>
59551+#include <linux/mm.h>
59552+#include <linux/sched.h>
59553+#include <linux/poll.h>
59554+#include <linux/string.h>
59555+#include <linux/file.h>
59556+#include <linux/types.h>
59557+#include <linux/vmalloc.h>
59558+#include <linux/grinternal.h>
59559+
59560+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
59561+ size_t count, loff_t *ppos);
59562+extern int gr_acl_is_enabled(void);
59563+
59564+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
59565+static int gr_learn_attached;
59566+
59567+/* use a 512k buffer */
59568+#define LEARN_BUFFER_SIZE (512 * 1024)
59569+
59570+static DEFINE_SPINLOCK(gr_learn_lock);
59571+static DEFINE_MUTEX(gr_learn_user_mutex);
59572+
59573+/* we need to maintain two buffers, so that the kernel context of grlearn
59574+ uses a semaphore around the userspace copying, and the other kernel contexts
59575+ use a spinlock when copying into the buffer, since they cannot sleep
59576+*/
59577+static char *learn_buffer;
59578+static char *learn_buffer_user;
59579+static int learn_buffer_len;
59580+static int learn_buffer_user_len;
59581+
59582+static ssize_t
59583+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
59584+{
59585+ DECLARE_WAITQUEUE(wait, current);
59586+ ssize_t retval = 0;
59587+
59588+ add_wait_queue(&learn_wait, &wait);
59589+ set_current_state(TASK_INTERRUPTIBLE);
59590+ do {
59591+ mutex_lock(&gr_learn_user_mutex);
59592+ spin_lock(&gr_learn_lock);
59593+ if (learn_buffer_len)
59594+ break;
59595+ spin_unlock(&gr_learn_lock);
59596+ mutex_unlock(&gr_learn_user_mutex);
59597+ if (file->f_flags & O_NONBLOCK) {
59598+ retval = -EAGAIN;
59599+ goto out;
59600+ }
59601+ if (signal_pending(current)) {
59602+ retval = -ERESTARTSYS;
59603+ goto out;
59604+ }
59605+
59606+ schedule();
59607+ } while (1);
59608+
59609+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
59610+ learn_buffer_user_len = learn_buffer_len;
59611+ retval = learn_buffer_len;
59612+ learn_buffer_len = 0;
59613+
59614+ spin_unlock(&gr_learn_lock);
59615+
59616+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
59617+ retval = -EFAULT;
59618+
59619+ mutex_unlock(&gr_learn_user_mutex);
59620+out:
59621+ set_current_state(TASK_RUNNING);
59622+ remove_wait_queue(&learn_wait, &wait);
59623+ return retval;
59624+}
59625+
59626+static unsigned int
59627+poll_learn(struct file * file, poll_table * wait)
59628+{
59629+ poll_wait(file, &learn_wait, wait);
59630+
59631+ if (learn_buffer_len)
59632+ return (POLLIN | POLLRDNORM);
59633+
59634+ return 0;
59635+}
59636+
59637+void
59638+gr_clear_learn_entries(void)
59639+{
59640+ char *tmp;
59641+
59642+ mutex_lock(&gr_learn_user_mutex);
59643+ spin_lock(&gr_learn_lock);
59644+ tmp = learn_buffer;
59645+ learn_buffer = NULL;
59646+ spin_unlock(&gr_learn_lock);
59647+ if (tmp)
59648+ vfree(tmp);
59649+ if (learn_buffer_user != NULL) {
59650+ vfree(learn_buffer_user);
59651+ learn_buffer_user = NULL;
59652+ }
59653+ learn_buffer_len = 0;
59654+ mutex_unlock(&gr_learn_user_mutex);
59655+
59656+ return;
59657+}
59658+
59659+void
59660+gr_add_learn_entry(const char *fmt, ...)
59661+{
59662+ va_list args;
59663+ unsigned int len;
59664+
59665+ if (!gr_learn_attached)
59666+ return;
59667+
59668+ spin_lock(&gr_learn_lock);
59669+
59670+ /* leave a gap at the end so we know when it's "full" but don't have to
59671+ compute the exact length of the string we're trying to append
59672+ */
59673+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
59674+ spin_unlock(&gr_learn_lock);
59675+ wake_up_interruptible(&learn_wait);
59676+ return;
59677+ }
59678+ if (learn_buffer == NULL) {
59679+ spin_unlock(&gr_learn_lock);
59680+ return;
59681+ }
59682+
59683+ va_start(args, fmt);
59684+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
59685+ va_end(args);
59686+
59687+ learn_buffer_len += len + 1;
59688+
59689+ spin_unlock(&gr_learn_lock);
59690+ wake_up_interruptible(&learn_wait);
59691+
59692+ return;
59693+}
59694+
59695+static int
59696+open_learn(struct inode *inode, struct file *file)
59697+{
59698+ if (file->f_mode & FMODE_READ && gr_learn_attached)
59699+ return -EBUSY;
59700+ if (file->f_mode & FMODE_READ) {
59701+ int retval = 0;
59702+ mutex_lock(&gr_learn_user_mutex);
59703+ if (learn_buffer == NULL)
59704+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
59705+ if (learn_buffer_user == NULL)
59706+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
59707+ if (learn_buffer == NULL) {
59708+ retval = -ENOMEM;
59709+ goto out_error;
59710+ }
59711+ if (learn_buffer_user == NULL) {
59712+ retval = -ENOMEM;
59713+ goto out_error;
59714+ }
59715+ learn_buffer_len = 0;
59716+ learn_buffer_user_len = 0;
59717+ gr_learn_attached = 1;
59718+out_error:
59719+ mutex_unlock(&gr_learn_user_mutex);
59720+ return retval;
59721+ }
59722+ return 0;
59723+}
59724+
59725+static int
59726+close_learn(struct inode *inode, struct file *file)
59727+{
59728+ if (file->f_mode & FMODE_READ) {
59729+ char *tmp = NULL;
59730+ mutex_lock(&gr_learn_user_mutex);
59731+ spin_lock(&gr_learn_lock);
59732+ tmp = learn_buffer;
59733+ learn_buffer = NULL;
59734+ spin_unlock(&gr_learn_lock);
59735+ if (tmp)
59736+ vfree(tmp);
59737+ if (learn_buffer_user != NULL) {
59738+ vfree(learn_buffer_user);
59739+ learn_buffer_user = NULL;
59740+ }
59741+ learn_buffer_len = 0;
59742+ learn_buffer_user_len = 0;
59743+ gr_learn_attached = 0;
59744+ mutex_unlock(&gr_learn_user_mutex);
59745+ }
59746+
59747+ return 0;
59748+}
59749+
59750+const struct file_operations grsec_fops = {
59751+ .read = read_learn,
59752+ .write = write_grsec_handler,
59753+ .open = open_learn,
59754+ .release = close_learn,
59755+ .poll = poll_learn,
59756+};
59757diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
59758new file mode 100644
59759index 0000000..39645c9
59760--- /dev/null
59761+++ b/grsecurity/gracl_res.c
59762@@ -0,0 +1,68 @@
59763+#include <linux/kernel.h>
59764+#include <linux/sched.h>
59765+#include <linux/gracl.h>
59766+#include <linux/grinternal.h>
59767+
59768+static const char *restab_log[] = {
59769+ [RLIMIT_CPU] = "RLIMIT_CPU",
59770+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
59771+ [RLIMIT_DATA] = "RLIMIT_DATA",
59772+ [RLIMIT_STACK] = "RLIMIT_STACK",
59773+ [RLIMIT_CORE] = "RLIMIT_CORE",
59774+ [RLIMIT_RSS] = "RLIMIT_RSS",
59775+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
59776+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
59777+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
59778+ [RLIMIT_AS] = "RLIMIT_AS",
59779+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
59780+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
59781+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
59782+ [RLIMIT_NICE] = "RLIMIT_NICE",
59783+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
59784+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
59785+ [GR_CRASH_RES] = "RLIMIT_CRASH"
59786+};
59787+
59788+void
59789+gr_log_resource(const struct task_struct *task,
59790+ const int res, const unsigned long wanted, const int gt)
59791+{
59792+ const struct cred *cred;
59793+ unsigned long rlim;
59794+
59795+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
59796+ return;
59797+
59798+ // not yet supported resource
59799+ if (unlikely(!restab_log[res]))
59800+ return;
59801+
59802+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
59803+ rlim = task_rlimit_max(task, res);
59804+ else
59805+ rlim = task_rlimit(task, res);
59806+
59807+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
59808+ return;
59809+
59810+ rcu_read_lock();
59811+ cred = __task_cred(task);
59812+
59813+ if (res == RLIMIT_NPROC &&
59814+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
59815+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
59816+ goto out_rcu_unlock;
59817+ else if (res == RLIMIT_MEMLOCK &&
59818+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
59819+ goto out_rcu_unlock;
59820+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
59821+ goto out_rcu_unlock;
59822+ rcu_read_unlock();
59823+
59824+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
59825+
59826+ return;
59827+out_rcu_unlock:
59828+ rcu_read_unlock();
59829+ return;
59830+}
59831diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
59832new file mode 100644
59833index 0000000..25197e9
59834--- /dev/null
59835+++ b/grsecurity/gracl_segv.c
59836@@ -0,0 +1,299 @@
59837+#include <linux/kernel.h>
59838+#include <linux/mm.h>
59839+#include <asm/uaccess.h>
59840+#include <asm/errno.h>
59841+#include <asm/mman.h>
59842+#include <net/sock.h>
59843+#include <linux/file.h>
59844+#include <linux/fs.h>
59845+#include <linux/net.h>
59846+#include <linux/in.h>
59847+#include <linux/slab.h>
59848+#include <linux/types.h>
59849+#include <linux/sched.h>
59850+#include <linux/timer.h>
59851+#include <linux/gracl.h>
59852+#include <linux/grsecurity.h>
59853+#include <linux/grinternal.h>
59854+
59855+static struct crash_uid *uid_set;
59856+static unsigned short uid_used;
59857+static DEFINE_SPINLOCK(gr_uid_lock);
59858+extern rwlock_t gr_inode_lock;
59859+extern struct acl_subject_label *
59860+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
59861+ struct acl_role_label *role);
59862+
59863+#ifdef CONFIG_BTRFS_FS
59864+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
59865+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
59866+#endif
59867+
59868+static inline dev_t __get_dev(const struct dentry *dentry)
59869+{
59870+#ifdef CONFIG_BTRFS_FS
59871+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
59872+ return get_btrfs_dev_from_inode(dentry->d_inode);
59873+ else
59874+#endif
59875+ return dentry->d_inode->i_sb->s_dev;
59876+}
59877+
59878+int
59879+gr_init_uidset(void)
59880+{
59881+ uid_set =
59882+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
59883+ uid_used = 0;
59884+
59885+ return uid_set ? 1 : 0;
59886+}
59887+
59888+void
59889+gr_free_uidset(void)
59890+{
59891+ if (uid_set)
59892+ kfree(uid_set);
59893+
59894+ return;
59895+}
59896+
59897+int
59898+gr_find_uid(const uid_t uid)
59899+{
59900+ struct crash_uid *tmp = uid_set;
59901+ uid_t buid;
59902+ int low = 0, high = uid_used - 1, mid;
59903+
59904+ while (high >= low) {
59905+ mid = (low + high) >> 1;
59906+ buid = tmp[mid].uid;
59907+ if (buid == uid)
59908+ return mid;
59909+ if (buid > uid)
59910+ high = mid - 1;
59911+ if (buid < uid)
59912+ low = mid + 1;
59913+ }
59914+
59915+ return -1;
59916+}
59917+
59918+static __inline__ void
59919+gr_insertsort(void)
59920+{
59921+ unsigned short i, j;
59922+ struct crash_uid index;
59923+
59924+ for (i = 1; i < uid_used; i++) {
59925+ index = uid_set[i];
59926+ j = i;
59927+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
59928+ uid_set[j] = uid_set[j - 1];
59929+ j--;
59930+ }
59931+ uid_set[j] = index;
59932+ }
59933+
59934+ return;
59935+}
59936+
59937+static __inline__ void
59938+gr_insert_uid(const uid_t uid, const unsigned long expires)
59939+{
59940+ int loc;
59941+
59942+ if (uid_used == GR_UIDTABLE_MAX)
59943+ return;
59944+
59945+ loc = gr_find_uid(uid);
59946+
59947+ if (loc >= 0) {
59948+ uid_set[loc].expires = expires;
59949+ return;
59950+ }
59951+
59952+ uid_set[uid_used].uid = uid;
59953+ uid_set[uid_used].expires = expires;
59954+ uid_used++;
59955+
59956+ gr_insertsort();
59957+
59958+ return;
59959+}
59960+
59961+void
59962+gr_remove_uid(const unsigned short loc)
59963+{
59964+ unsigned short i;
59965+
59966+ for (i = loc + 1; i < uid_used; i++)
59967+ uid_set[i - 1] = uid_set[i];
59968+
59969+ uid_used--;
59970+
59971+ return;
59972+}
59973+
59974+int
59975+gr_check_crash_uid(const uid_t uid)
59976+{
59977+ int loc;
59978+ int ret = 0;
59979+
59980+ if (unlikely(!gr_acl_is_enabled()))
59981+ return 0;
59982+
59983+ spin_lock(&gr_uid_lock);
59984+ loc = gr_find_uid(uid);
59985+
59986+ if (loc < 0)
59987+ goto out_unlock;
59988+
59989+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
59990+ gr_remove_uid(loc);
59991+ else
59992+ ret = 1;
59993+
59994+out_unlock:
59995+ spin_unlock(&gr_uid_lock);
59996+ return ret;
59997+}
59998+
59999+static __inline__ int
60000+proc_is_setxid(const struct cred *cred)
60001+{
60002+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
60003+ !uid_eq(cred->uid, cred->fsuid))
60004+ return 1;
60005+ if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
60006+ !uid_eq(cred->gid, cred->fsgid))
60007+ return 1;
60008+
60009+ return 0;
60010+}
60011+
60012+extern int gr_fake_force_sig(int sig, struct task_struct *t);
60013+
60014+void
60015+gr_handle_crash(struct task_struct *task, const int sig)
60016+{
60017+ struct acl_subject_label *curr;
60018+ struct task_struct *tsk, *tsk2;
60019+ const struct cred *cred;
60020+ const struct cred *cred2;
60021+
60022+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
60023+ return;
60024+
60025+ if (unlikely(!gr_acl_is_enabled()))
60026+ return;
60027+
60028+ curr = task->acl;
60029+
60030+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
60031+ return;
60032+
60033+ if (time_before_eq(curr->expires, get_seconds())) {
60034+ curr->expires = 0;
60035+ curr->crashes = 0;
60036+ }
60037+
60038+ curr->crashes++;
60039+
60040+ if (!curr->expires)
60041+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
60042+
60043+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
60044+ time_after(curr->expires, get_seconds())) {
60045+ rcu_read_lock();
60046+ cred = __task_cred(task);
60047+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
60048+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
60049+ spin_lock(&gr_uid_lock);
60050+ gr_insert_uid(cred->uid, curr->expires);
60051+ spin_unlock(&gr_uid_lock);
60052+ curr->expires = 0;
60053+ curr->crashes = 0;
60054+ read_lock(&tasklist_lock);
60055+ do_each_thread(tsk2, tsk) {
60056+ cred2 = __task_cred(tsk);
60057+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
60058+ gr_fake_force_sig(SIGKILL, tsk);
60059+ } while_each_thread(tsk2, tsk);
60060+ read_unlock(&tasklist_lock);
60061+ } else {
60062+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
60063+ read_lock(&tasklist_lock);
60064+ read_lock(&grsec_exec_file_lock);
60065+ do_each_thread(tsk2, tsk) {
60066+ if (likely(tsk != task)) {
60067+ // if this thread has the same subject as the one that triggered
60068+ // RES_CRASH and it's the same binary, kill it
60069+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
60070+ gr_fake_force_sig(SIGKILL, tsk);
60071+ }
60072+ } while_each_thread(tsk2, tsk);
60073+ read_unlock(&grsec_exec_file_lock);
60074+ read_unlock(&tasklist_lock);
60075+ }
60076+ rcu_read_unlock();
60077+ }
60078+
60079+ return;
60080+}
60081+
60082+int
60083+gr_check_crash_exec(const struct file *filp)
60084+{
60085+ struct acl_subject_label *curr;
60086+
60087+ if (unlikely(!gr_acl_is_enabled()))
60088+ return 0;
60089+
60090+ read_lock(&gr_inode_lock);
60091+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
60092+ __get_dev(filp->f_path.dentry),
60093+ current->role);
60094+ read_unlock(&gr_inode_lock);
60095+
60096+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
60097+ (!curr->crashes && !curr->expires))
60098+ return 0;
60099+
60100+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
60101+ time_after(curr->expires, get_seconds()))
60102+ return 1;
60103+ else if (time_before_eq(curr->expires, get_seconds())) {
60104+ curr->crashes = 0;
60105+ curr->expires = 0;
60106+ }
60107+
60108+ return 0;
60109+}
60110+
60111+void
60112+gr_handle_alertkill(struct task_struct *task)
60113+{
60114+ struct acl_subject_label *curracl;
60115+ __u32 curr_ip;
60116+ struct task_struct *p, *p2;
60117+
60118+ if (unlikely(!gr_acl_is_enabled()))
60119+ return;
60120+
60121+ curracl = task->acl;
60122+ curr_ip = task->signal->curr_ip;
60123+
60124+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
60125+ read_lock(&tasklist_lock);
60126+ do_each_thread(p2, p) {
60127+ if (p->signal->curr_ip == curr_ip)
60128+ gr_fake_force_sig(SIGKILL, p);
60129+ } while_each_thread(p2, p);
60130+ read_unlock(&tasklist_lock);
60131+ } else if (curracl->mode & GR_KILLPROC)
60132+ gr_fake_force_sig(SIGKILL, task);
60133+
60134+ return;
60135+}
60136diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
60137new file mode 100644
60138index 0000000..9d83a69
60139--- /dev/null
60140+++ b/grsecurity/gracl_shm.c
60141@@ -0,0 +1,40 @@
60142+#include <linux/kernel.h>
60143+#include <linux/mm.h>
60144+#include <linux/sched.h>
60145+#include <linux/file.h>
60146+#include <linux/ipc.h>
60147+#include <linux/gracl.h>
60148+#include <linux/grsecurity.h>
60149+#include <linux/grinternal.h>
60150+
60151+int
60152+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60153+ const time_t shm_createtime, const uid_t cuid, const int shmid)
60154+{
60155+ struct task_struct *task;
60156+
60157+ if (!gr_acl_is_enabled())
60158+ return 1;
60159+
60160+ rcu_read_lock();
60161+ read_lock(&tasklist_lock);
60162+
60163+ task = find_task_by_vpid(shm_cprid);
60164+
60165+ if (unlikely(!task))
60166+ task = find_task_by_vpid(shm_lapid);
60167+
60168+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
60169+ (task->pid == shm_lapid)) &&
60170+ (task->acl->mode & GR_PROTSHM) &&
60171+ (task->acl != current->acl))) {
60172+ read_unlock(&tasklist_lock);
60173+ rcu_read_unlock();
60174+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
60175+ return 0;
60176+ }
60177+ read_unlock(&tasklist_lock);
60178+ rcu_read_unlock();
60179+
60180+ return 1;
60181+}
60182diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
60183new file mode 100644
60184index 0000000..bc0be01
60185--- /dev/null
60186+++ b/grsecurity/grsec_chdir.c
60187@@ -0,0 +1,19 @@
60188+#include <linux/kernel.h>
60189+#include <linux/sched.h>
60190+#include <linux/fs.h>
60191+#include <linux/file.h>
60192+#include <linux/grsecurity.h>
60193+#include <linux/grinternal.h>
60194+
60195+void
60196+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
60197+{
60198+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60199+ if ((grsec_enable_chdir && grsec_enable_group &&
60200+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
60201+ !grsec_enable_group)) {
60202+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
60203+ }
60204+#endif
60205+ return;
60206+}
60207diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
60208new file mode 100644
60209index 0000000..70fe0ae
60210--- /dev/null
60211+++ b/grsecurity/grsec_chroot.c
60212@@ -0,0 +1,357 @@
60213+#include <linux/kernel.h>
60214+#include <linux/module.h>
60215+#include <linux/sched.h>
60216+#include <linux/file.h>
60217+#include <linux/fs.h>
60218+#include <linux/mount.h>
60219+#include <linux/types.h>
60220+#include "../fs/mount.h"
60221+#include <linux/grsecurity.h>
60222+#include <linux/grinternal.h>
60223+
60224+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
60225+{
60226+#ifdef CONFIG_GRKERNSEC
60227+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
60228+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
60229+ task->gr_is_chrooted = 1;
60230+ else
60231+ task->gr_is_chrooted = 0;
60232+
60233+ task->gr_chroot_dentry = path->dentry;
60234+#endif
60235+ return;
60236+}
60237+
60238+void gr_clear_chroot_entries(struct task_struct *task)
60239+{
60240+#ifdef CONFIG_GRKERNSEC
60241+ task->gr_is_chrooted = 0;
60242+ task->gr_chroot_dentry = NULL;
60243+#endif
60244+ return;
60245+}
60246+
60247+int
60248+gr_handle_chroot_unix(const pid_t pid)
60249+{
60250+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60251+ struct task_struct *p;
60252+
60253+ if (unlikely(!grsec_enable_chroot_unix))
60254+ return 1;
60255+
60256+ if (likely(!proc_is_chrooted(current)))
60257+ return 1;
60258+
60259+ rcu_read_lock();
60260+ read_lock(&tasklist_lock);
60261+ p = find_task_by_vpid_unrestricted(pid);
60262+ if (unlikely(p && !have_same_root(current, p))) {
60263+ read_unlock(&tasklist_lock);
60264+ rcu_read_unlock();
60265+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
60266+ return 0;
60267+ }
60268+ read_unlock(&tasklist_lock);
60269+ rcu_read_unlock();
60270+#endif
60271+ return 1;
60272+}
60273+
60274+int
60275+gr_handle_chroot_nice(void)
60276+{
60277+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60278+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
60279+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
60280+ return -EPERM;
60281+ }
60282+#endif
60283+ return 0;
60284+}
60285+
60286+int
60287+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
60288+{
60289+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60290+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
60291+ && proc_is_chrooted(current)) {
60292+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
60293+ return -EACCES;
60294+ }
60295+#endif
60296+ return 0;
60297+}
60298+
60299+int
60300+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
60301+{
60302+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60303+ struct task_struct *p;
60304+ int ret = 0;
60305+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
60306+ return ret;
60307+
60308+ read_lock(&tasklist_lock);
60309+ do_each_pid_task(pid, type, p) {
60310+ if (!have_same_root(current, p)) {
60311+ ret = 1;
60312+ goto out;
60313+ }
60314+ } while_each_pid_task(pid, type, p);
60315+out:
60316+ read_unlock(&tasklist_lock);
60317+ return ret;
60318+#endif
60319+ return 0;
60320+}
60321+
60322+int
60323+gr_pid_is_chrooted(struct task_struct *p)
60324+{
60325+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60326+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
60327+ return 0;
60328+
60329+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
60330+ !have_same_root(current, p)) {
60331+ return 1;
60332+ }
60333+#endif
60334+ return 0;
60335+}
60336+
60337+EXPORT_SYMBOL(gr_pid_is_chrooted);
60338+
60339+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
60340+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
60341+{
60342+ struct path path, currentroot;
60343+ int ret = 0;
60344+
60345+ path.dentry = (struct dentry *)u_dentry;
60346+ path.mnt = (struct vfsmount *)u_mnt;
60347+ get_fs_root(current->fs, &currentroot);
60348+ if (path_is_under(&path, &currentroot))
60349+ ret = 1;
60350+ path_put(&currentroot);
60351+
60352+ return ret;
60353+}
60354+#endif
60355+
60356+int
60357+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
60358+{
60359+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60360+ if (!grsec_enable_chroot_fchdir)
60361+ return 1;
60362+
60363+ if (!proc_is_chrooted(current))
60364+ return 1;
60365+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
60366+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
60367+ return 0;
60368+ }
60369+#endif
60370+ return 1;
60371+}
60372+
60373+int
60374+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60375+ const time_t shm_createtime)
60376+{
60377+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60378+ struct task_struct *p;
60379+ time_t starttime;
60380+
60381+ if (unlikely(!grsec_enable_chroot_shmat))
60382+ return 1;
60383+
60384+ if (likely(!proc_is_chrooted(current)))
60385+ return 1;
60386+
60387+ rcu_read_lock();
60388+ read_lock(&tasklist_lock);
60389+
60390+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
60391+ starttime = p->start_time.tv_sec;
60392+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
60393+ if (have_same_root(current, p)) {
60394+ goto allow;
60395+ } else {
60396+ read_unlock(&tasklist_lock);
60397+ rcu_read_unlock();
60398+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
60399+ return 0;
60400+ }
60401+ }
60402+ /* creator exited, pid reuse, fall through to next check */
60403+ }
60404+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
60405+ if (unlikely(!have_same_root(current, p))) {
60406+ read_unlock(&tasklist_lock);
60407+ rcu_read_unlock();
60408+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
60409+ return 0;
60410+ }
60411+ }
60412+
60413+allow:
60414+ read_unlock(&tasklist_lock);
60415+ rcu_read_unlock();
60416+#endif
60417+ return 1;
60418+}
60419+
60420+void
60421+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
60422+{
60423+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60424+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
60425+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
60426+#endif
60427+ return;
60428+}
60429+
60430+int
60431+gr_handle_chroot_mknod(const struct dentry *dentry,
60432+ const struct vfsmount *mnt, const int mode)
60433+{
60434+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60435+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
60436+ proc_is_chrooted(current)) {
60437+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
60438+ return -EPERM;
60439+ }
60440+#endif
60441+ return 0;
60442+}
60443+
60444+int
60445+gr_handle_chroot_mount(const struct dentry *dentry,
60446+ const struct vfsmount *mnt, const char *dev_name)
60447+{
60448+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60449+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
60450+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
60451+ return -EPERM;
60452+ }
60453+#endif
60454+ return 0;
60455+}
60456+
60457+int
60458+gr_handle_chroot_pivot(void)
60459+{
60460+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60461+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
60462+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
60463+ return -EPERM;
60464+ }
60465+#endif
60466+ return 0;
60467+}
60468+
60469+int
60470+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
60471+{
60472+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60473+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
60474+ !gr_is_outside_chroot(dentry, mnt)) {
60475+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
60476+ return -EPERM;
60477+ }
60478+#endif
60479+ return 0;
60480+}
60481+
60482+extern const char *captab_log[];
60483+extern int captab_log_entries;
60484+
60485+int
60486+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60487+{
60488+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60489+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
60490+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
60491+ if (cap_raised(chroot_caps, cap)) {
60492+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
60493+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
60494+ }
60495+ return 0;
60496+ }
60497+ }
60498+#endif
60499+ return 1;
60500+}
60501+
60502+int
60503+gr_chroot_is_capable(const int cap)
60504+{
60505+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60506+ return gr_task_chroot_is_capable(current, current_cred(), cap);
60507+#endif
60508+ return 1;
60509+}
60510+
60511+int
60512+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
60513+{
60514+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60515+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
60516+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
60517+ if (cap_raised(chroot_caps, cap)) {
60518+ return 0;
60519+ }
60520+ }
60521+#endif
60522+ return 1;
60523+}
60524+
60525+int
60526+gr_chroot_is_capable_nolog(const int cap)
60527+{
60528+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60529+ return gr_task_chroot_is_capable_nolog(current, cap);
60530+#endif
60531+ return 1;
60532+}
60533+
60534+int
60535+gr_handle_chroot_sysctl(const int op)
60536+{
60537+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60538+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
60539+ proc_is_chrooted(current))
60540+ return -EACCES;
60541+#endif
60542+ return 0;
60543+}
60544+
60545+void
60546+gr_handle_chroot_chdir(struct path *path)
60547+{
60548+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60549+ if (grsec_enable_chroot_chdir)
60550+ set_fs_pwd(current->fs, path);
60551+#endif
60552+ return;
60553+}
60554+
60555+int
60556+gr_handle_chroot_chmod(const struct dentry *dentry,
60557+ const struct vfsmount *mnt, const int mode)
60558+{
60559+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60560+ /* allow chmod +s on directories, but not files */
60561+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
60562+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
60563+ proc_is_chrooted(current)) {
60564+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
60565+ return -EPERM;
60566+ }
60567+#endif
60568+ return 0;
60569+}
60570diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
60571new file mode 100644
60572index 0000000..e6796b3
60573--- /dev/null
60574+++ b/grsecurity/grsec_disabled.c
60575@@ -0,0 +1,434 @@
60576+#include <linux/kernel.h>
60577+#include <linux/module.h>
60578+#include <linux/sched.h>
60579+#include <linux/file.h>
60580+#include <linux/fs.h>
60581+#include <linux/kdev_t.h>
60582+#include <linux/net.h>
60583+#include <linux/in.h>
60584+#include <linux/ip.h>
60585+#include <linux/skbuff.h>
60586+#include <linux/sysctl.h>
60587+
60588+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60589+void
60590+pax_set_initial_flags(struct linux_binprm *bprm)
60591+{
60592+ return;
60593+}
60594+#endif
60595+
60596+#ifdef CONFIG_SYSCTL
60597+__u32
60598+gr_handle_sysctl(const struct ctl_table * table, const int op)
60599+{
60600+ return 0;
60601+}
60602+#endif
60603+
60604+#ifdef CONFIG_TASKSTATS
60605+int gr_is_taskstats_denied(int pid)
60606+{
60607+ return 0;
60608+}
60609+#endif
60610+
60611+int
60612+gr_acl_is_enabled(void)
60613+{
60614+ return 0;
60615+}
60616+
60617+void
60618+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
60619+{
60620+ return;
60621+}
60622+
60623+int
60624+gr_handle_rawio(const struct inode *inode)
60625+{
60626+ return 0;
60627+}
60628+
60629+void
60630+gr_acl_handle_psacct(struct task_struct *task, const long code)
60631+{
60632+ return;
60633+}
60634+
60635+int
60636+gr_handle_ptrace(struct task_struct *task, const long request)
60637+{
60638+ return 0;
60639+}
60640+
60641+int
60642+gr_handle_proc_ptrace(struct task_struct *task)
60643+{
60644+ return 0;
60645+}
60646+
60647+int
60648+gr_set_acls(const int type)
60649+{
60650+ return 0;
60651+}
60652+
60653+int
60654+gr_check_hidden_task(const struct task_struct *tsk)
60655+{
60656+ return 0;
60657+}
60658+
60659+int
60660+gr_check_protected_task(const struct task_struct *task)
60661+{
60662+ return 0;
60663+}
60664+
60665+int
60666+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
60667+{
60668+ return 0;
60669+}
60670+
60671+void
60672+gr_copy_label(struct task_struct *tsk)
60673+{
60674+ return;
60675+}
60676+
60677+void
60678+gr_set_pax_flags(struct task_struct *task)
60679+{
60680+ return;
60681+}
60682+
60683+int
60684+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
60685+ const int unsafe_share)
60686+{
60687+ return 0;
60688+}
60689+
60690+void
60691+gr_handle_delete(const ino_t ino, const dev_t dev)
60692+{
60693+ return;
60694+}
60695+
60696+void
60697+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
60698+{
60699+ return;
60700+}
60701+
60702+void
60703+gr_handle_crash(struct task_struct *task, const int sig)
60704+{
60705+ return;
60706+}
60707+
60708+int
60709+gr_check_crash_exec(const struct file *filp)
60710+{
60711+ return 0;
60712+}
60713+
60714+int
60715+gr_check_crash_uid(const uid_t uid)
60716+{
60717+ return 0;
60718+}
60719+
60720+void
60721+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
60722+ struct dentry *old_dentry,
60723+ struct dentry *new_dentry,
60724+ struct vfsmount *mnt, const __u8 replace)
60725+{
60726+ return;
60727+}
60728+
60729+int
60730+gr_search_socket(const int family, const int type, const int protocol)
60731+{
60732+ return 1;
60733+}
60734+
60735+int
60736+gr_search_connectbind(const int mode, const struct socket *sock,
60737+ const struct sockaddr_in *addr)
60738+{
60739+ return 0;
60740+}
60741+
60742+void
60743+gr_handle_alertkill(struct task_struct *task)
60744+{
60745+ return;
60746+}
60747+
60748+__u32
60749+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
60750+{
60751+ return 1;
60752+}
60753+
60754+__u32
60755+gr_acl_handle_hidden_file(const struct dentry * dentry,
60756+ const struct vfsmount * mnt)
60757+{
60758+ return 1;
60759+}
60760+
60761+__u32
60762+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
60763+ int acc_mode)
60764+{
60765+ return 1;
60766+}
60767+
60768+__u32
60769+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
60770+{
60771+ return 1;
60772+}
60773+
60774+__u32
60775+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
60776+{
60777+ return 1;
60778+}
60779+
60780+int
60781+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
60782+ unsigned int *vm_flags)
60783+{
60784+ return 1;
60785+}
60786+
60787+__u32
60788+gr_acl_handle_truncate(const struct dentry * dentry,
60789+ const struct vfsmount * mnt)
60790+{
60791+ return 1;
60792+}
60793+
60794+__u32
60795+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
60796+{
60797+ return 1;
60798+}
60799+
60800+__u32
60801+gr_acl_handle_access(const struct dentry * dentry,
60802+ const struct vfsmount * mnt, const int fmode)
60803+{
60804+ return 1;
60805+}
60806+
60807+__u32
60808+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
60809+ umode_t *mode)
60810+{
60811+ return 1;
60812+}
60813+
60814+__u32
60815+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
60816+{
60817+ return 1;
60818+}
60819+
60820+__u32
60821+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
60822+{
60823+ return 1;
60824+}
60825+
60826+void
60827+grsecurity_init(void)
60828+{
60829+ return;
60830+}
60831+
60832+umode_t gr_acl_umask(void)
60833+{
60834+ return 0;
60835+}
60836+
60837+__u32
60838+gr_acl_handle_mknod(const struct dentry * new_dentry,
60839+ const struct dentry * parent_dentry,
60840+ const struct vfsmount * parent_mnt,
60841+ const int mode)
60842+{
60843+ return 1;
60844+}
60845+
60846+__u32
60847+gr_acl_handle_mkdir(const struct dentry * new_dentry,
60848+ const struct dentry * parent_dentry,
60849+ const struct vfsmount * parent_mnt)
60850+{
60851+ return 1;
60852+}
60853+
60854+__u32
60855+gr_acl_handle_symlink(const struct dentry * new_dentry,
60856+ const struct dentry * parent_dentry,
60857+ const struct vfsmount * parent_mnt, const struct filename *from)
60858+{
60859+ return 1;
60860+}
60861+
60862+__u32
60863+gr_acl_handle_link(const struct dentry * new_dentry,
60864+ const struct dentry * parent_dentry,
60865+ const struct vfsmount * parent_mnt,
60866+ const struct dentry * old_dentry,
60867+ const struct vfsmount * old_mnt, const struct filename *to)
60868+{
60869+ return 1;
60870+}
60871+
60872+int
60873+gr_acl_handle_rename(const struct dentry *new_dentry,
60874+ const struct dentry *parent_dentry,
60875+ const struct vfsmount *parent_mnt,
60876+ const struct dentry *old_dentry,
60877+ const struct inode *old_parent_inode,
60878+ const struct vfsmount *old_mnt, const struct filename *newname)
60879+{
60880+ return 0;
60881+}
60882+
60883+int
60884+gr_acl_handle_filldir(const struct file *file, const char *name,
60885+ const int namelen, const ino_t ino)
60886+{
60887+ return 1;
60888+}
60889+
60890+int
60891+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60892+ const time_t shm_createtime, const uid_t cuid, const int shmid)
60893+{
60894+ return 1;
60895+}
60896+
60897+int
60898+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
60899+{
60900+ return 0;
60901+}
60902+
60903+int
60904+gr_search_accept(const struct socket *sock)
60905+{
60906+ return 0;
60907+}
60908+
60909+int
60910+gr_search_listen(const struct socket *sock)
60911+{
60912+ return 0;
60913+}
60914+
60915+int
60916+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
60917+{
60918+ return 0;
60919+}
60920+
60921+__u32
60922+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
60923+{
60924+ return 1;
60925+}
60926+
60927+__u32
60928+gr_acl_handle_creat(const struct dentry * dentry,
60929+ const struct dentry * p_dentry,
60930+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
60931+ const int imode)
60932+{
60933+ return 1;
60934+}
60935+
60936+void
60937+gr_acl_handle_exit(void)
60938+{
60939+ return;
60940+}
60941+
60942+int
60943+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
60944+{
60945+ return 1;
60946+}
60947+
60948+void
60949+gr_set_role_label(const uid_t uid, const gid_t gid)
60950+{
60951+ return;
60952+}
60953+
60954+int
60955+gr_acl_handle_procpidmem(const struct task_struct *task)
60956+{
60957+ return 0;
60958+}
60959+
60960+int
60961+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
60962+{
60963+ return 0;
60964+}
60965+
60966+int
60967+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
60968+{
60969+ return 0;
60970+}
60971+
60972+void
60973+gr_set_kernel_label(struct task_struct *task)
60974+{
60975+ return;
60976+}
60977+
60978+int
60979+gr_check_user_change(int real, int effective, int fs)
60980+{
60981+ return 0;
60982+}
60983+
60984+int
60985+gr_check_group_change(int real, int effective, int fs)
60986+{
60987+ return 0;
60988+}
60989+
60990+int gr_acl_enable_at_secure(void)
60991+{
60992+ return 0;
60993+}
60994+
60995+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
60996+{
60997+ return dentry->d_inode->i_sb->s_dev;
60998+}
60999+
61000+void gr_put_exec_file(struct task_struct *task)
61001+{
61002+ return;
61003+}
61004+
61005+EXPORT_SYMBOL(gr_set_kernel_label);
61006+#ifdef CONFIG_SECURITY
61007+EXPORT_SYMBOL(gr_check_user_change);
61008+EXPORT_SYMBOL(gr_check_group_change);
61009+#endif
61010diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
61011new file mode 100644
61012index 0000000..abfa971
61013--- /dev/null
61014+++ b/grsecurity/grsec_exec.c
61015@@ -0,0 +1,174 @@
61016+#include <linux/kernel.h>
61017+#include <linux/sched.h>
61018+#include <linux/file.h>
61019+#include <linux/binfmts.h>
61020+#include <linux/fs.h>
61021+#include <linux/types.h>
61022+#include <linux/grdefs.h>
61023+#include <linux/grsecurity.h>
61024+#include <linux/grinternal.h>
61025+#include <linux/capability.h>
61026+#include <linux/module.h>
61027+
61028+#include <asm/uaccess.h>
61029+
61030+#ifdef CONFIG_GRKERNSEC_EXECLOG
61031+static char gr_exec_arg_buf[132];
61032+static DEFINE_MUTEX(gr_exec_arg_mutex);
61033+#endif
61034+
61035+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
61036+
61037+void
61038+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
61039+{
61040+#ifdef CONFIG_GRKERNSEC_EXECLOG
61041+ char *grarg = gr_exec_arg_buf;
61042+ unsigned int i, x, execlen = 0;
61043+ char c;
61044+
61045+ if (!((grsec_enable_execlog && grsec_enable_group &&
61046+ in_group_p(grsec_audit_gid))
61047+ || (grsec_enable_execlog && !grsec_enable_group)))
61048+ return;
61049+
61050+ mutex_lock(&gr_exec_arg_mutex);
61051+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
61052+
61053+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
61054+ const char __user *p;
61055+ unsigned int len;
61056+
61057+ p = get_user_arg_ptr(argv, i);
61058+ if (IS_ERR(p))
61059+ goto log;
61060+
61061+ len = strnlen_user(p, 128 - execlen);
61062+ if (len > 128 - execlen)
61063+ len = 128 - execlen;
61064+ else if (len > 0)
61065+ len--;
61066+ if (copy_from_user(grarg + execlen, p, len))
61067+ goto log;
61068+
61069+ /* rewrite unprintable characters */
61070+ for (x = 0; x < len; x++) {
61071+ c = *(grarg + execlen + x);
61072+ if (c < 32 || c > 126)
61073+ *(grarg + execlen + x) = ' ';
61074+ }
61075+
61076+ execlen += len;
61077+ *(grarg + execlen) = ' ';
61078+ *(grarg + execlen + 1) = '\0';
61079+ execlen++;
61080+ }
61081+
61082+ log:
61083+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
61084+ bprm->file->f_path.mnt, grarg);
61085+ mutex_unlock(&gr_exec_arg_mutex);
61086+#endif
61087+ return;
61088+}
61089+
61090+#ifdef CONFIG_GRKERNSEC
61091+extern int gr_acl_is_capable(const int cap);
61092+extern int gr_acl_is_capable_nolog(const int cap);
61093+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61094+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
61095+extern int gr_chroot_is_capable(const int cap);
61096+extern int gr_chroot_is_capable_nolog(const int cap);
61097+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61098+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
61099+#endif
61100+
61101+const char *captab_log[] = {
61102+ "CAP_CHOWN",
61103+ "CAP_DAC_OVERRIDE",
61104+ "CAP_DAC_READ_SEARCH",
61105+ "CAP_FOWNER",
61106+ "CAP_FSETID",
61107+ "CAP_KILL",
61108+ "CAP_SETGID",
61109+ "CAP_SETUID",
61110+ "CAP_SETPCAP",
61111+ "CAP_LINUX_IMMUTABLE",
61112+ "CAP_NET_BIND_SERVICE",
61113+ "CAP_NET_BROADCAST",
61114+ "CAP_NET_ADMIN",
61115+ "CAP_NET_RAW",
61116+ "CAP_IPC_LOCK",
61117+ "CAP_IPC_OWNER",
61118+ "CAP_SYS_MODULE",
61119+ "CAP_SYS_RAWIO",
61120+ "CAP_SYS_CHROOT",
61121+ "CAP_SYS_PTRACE",
61122+ "CAP_SYS_PACCT",
61123+ "CAP_SYS_ADMIN",
61124+ "CAP_SYS_BOOT",
61125+ "CAP_SYS_NICE",
61126+ "CAP_SYS_RESOURCE",
61127+ "CAP_SYS_TIME",
61128+ "CAP_SYS_TTY_CONFIG",
61129+ "CAP_MKNOD",
61130+ "CAP_LEASE",
61131+ "CAP_AUDIT_WRITE",
61132+ "CAP_AUDIT_CONTROL",
61133+ "CAP_SETFCAP",
61134+ "CAP_MAC_OVERRIDE",
61135+ "CAP_MAC_ADMIN",
61136+ "CAP_SYSLOG",
61137+ "CAP_WAKE_ALARM"
61138+};
61139+
61140+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
61141+
61142+int gr_is_capable(const int cap)
61143+{
61144+#ifdef CONFIG_GRKERNSEC
61145+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
61146+ return 1;
61147+ return 0;
61148+#else
61149+ return 1;
61150+#endif
61151+}
61152+
61153+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
61154+{
61155+#ifdef CONFIG_GRKERNSEC
61156+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
61157+ return 1;
61158+ return 0;
61159+#else
61160+ return 1;
61161+#endif
61162+}
61163+
61164+int gr_is_capable_nolog(const int cap)
61165+{
61166+#ifdef CONFIG_GRKERNSEC
61167+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
61168+ return 1;
61169+ return 0;
61170+#else
61171+ return 1;
61172+#endif
61173+}
61174+
61175+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
61176+{
61177+#ifdef CONFIG_GRKERNSEC
61178+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
61179+ return 1;
61180+ return 0;
61181+#else
61182+ return 1;
61183+#endif
61184+}
61185+
61186+EXPORT_SYMBOL(gr_is_capable);
61187+EXPORT_SYMBOL(gr_is_capable_nolog);
61188+EXPORT_SYMBOL(gr_task_is_capable);
61189+EXPORT_SYMBOL(gr_task_is_capable_nolog);
61190diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
61191new file mode 100644
61192index 0000000..d3ee748
61193--- /dev/null
61194+++ b/grsecurity/grsec_fifo.c
61195@@ -0,0 +1,24 @@
61196+#include <linux/kernel.h>
61197+#include <linux/sched.h>
61198+#include <linux/fs.h>
61199+#include <linux/file.h>
61200+#include <linux/grinternal.h>
61201+
61202+int
61203+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
61204+ const struct dentry *dir, const int flag, const int acc_mode)
61205+{
61206+#ifdef CONFIG_GRKERNSEC_FIFO
61207+ const struct cred *cred = current_cred();
61208+
61209+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
61210+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
61211+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
61212+ (cred->fsuid != dentry->d_inode->i_uid)) {
61213+ if (!inode_permission(dentry->d_inode, acc_mode))
61214+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
61215+ return -EACCES;
61216+ }
61217+#endif
61218+ return 0;
61219+}
61220diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
61221new file mode 100644
61222index 0000000..8ca18bf
61223--- /dev/null
61224+++ b/grsecurity/grsec_fork.c
61225@@ -0,0 +1,23 @@
61226+#include <linux/kernel.h>
61227+#include <linux/sched.h>
61228+#include <linux/grsecurity.h>
61229+#include <linux/grinternal.h>
61230+#include <linux/errno.h>
61231+
61232+void
61233+gr_log_forkfail(const int retval)
61234+{
61235+#ifdef CONFIG_GRKERNSEC_FORKFAIL
61236+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
61237+ switch (retval) {
61238+ case -EAGAIN:
61239+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
61240+ break;
61241+ case -ENOMEM:
61242+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
61243+ break;
61244+ }
61245+ }
61246+#endif
61247+ return;
61248+}
61249diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
61250new file mode 100644
61251index 0000000..05a6015
61252--- /dev/null
61253+++ b/grsecurity/grsec_init.c
61254@@ -0,0 +1,283 @@
61255+#include <linux/kernel.h>
61256+#include <linux/sched.h>
61257+#include <linux/mm.h>
61258+#include <linux/gracl.h>
61259+#include <linux/slab.h>
61260+#include <linux/vmalloc.h>
61261+#include <linux/percpu.h>
61262+#include <linux/module.h>
61263+
61264+int grsec_enable_ptrace_readexec;
61265+int grsec_enable_setxid;
61266+int grsec_enable_symlinkown;
61267+int grsec_symlinkown_gid;
61268+int grsec_enable_brute;
61269+int grsec_enable_link;
61270+int grsec_enable_dmesg;
61271+int grsec_enable_harden_ptrace;
61272+int grsec_enable_fifo;
61273+int grsec_enable_execlog;
61274+int grsec_enable_signal;
61275+int grsec_enable_forkfail;
61276+int grsec_enable_audit_ptrace;
61277+int grsec_enable_time;
61278+int grsec_enable_audit_textrel;
61279+int grsec_enable_group;
61280+int grsec_audit_gid;
61281+int grsec_enable_chdir;
61282+int grsec_enable_mount;
61283+int grsec_enable_rofs;
61284+int grsec_enable_chroot_findtask;
61285+int grsec_enable_chroot_mount;
61286+int grsec_enable_chroot_shmat;
61287+int grsec_enable_chroot_fchdir;
61288+int grsec_enable_chroot_double;
61289+int grsec_enable_chroot_pivot;
61290+int grsec_enable_chroot_chdir;
61291+int grsec_enable_chroot_chmod;
61292+int grsec_enable_chroot_mknod;
61293+int grsec_enable_chroot_nice;
61294+int grsec_enable_chroot_execlog;
61295+int grsec_enable_chroot_caps;
61296+int grsec_enable_chroot_sysctl;
61297+int grsec_enable_chroot_unix;
61298+int grsec_enable_tpe;
61299+int grsec_tpe_gid;
61300+int grsec_enable_blackhole;
61301+#ifdef CONFIG_IPV6_MODULE
61302+EXPORT_SYMBOL(grsec_enable_blackhole);
61303+#endif
61304+int grsec_lastack_retries;
61305+int grsec_enable_tpe_all;
61306+int grsec_enable_tpe_invert;
61307+int grsec_enable_socket_all;
61308+int grsec_socket_all_gid;
61309+int grsec_enable_socket_client;
61310+int grsec_socket_client_gid;
61311+int grsec_enable_socket_server;
61312+int grsec_socket_server_gid;
61313+int grsec_resource_logging;
61314+int grsec_disable_privio;
61315+int grsec_enable_log_rwxmaps;
61316+int grsec_lock;
61317+
61318+DEFINE_SPINLOCK(grsec_alert_lock);
61319+unsigned long grsec_alert_wtime = 0;
61320+unsigned long grsec_alert_fyet = 0;
61321+
61322+DEFINE_SPINLOCK(grsec_audit_lock);
61323+
61324+DEFINE_RWLOCK(grsec_exec_file_lock);
61325+
61326+char *gr_shared_page[4];
61327+
61328+char *gr_alert_log_fmt;
61329+char *gr_audit_log_fmt;
61330+char *gr_alert_log_buf;
61331+char *gr_audit_log_buf;
61332+
61333+extern struct gr_arg *gr_usermode;
61334+extern unsigned char *gr_system_salt;
61335+extern unsigned char *gr_system_sum;
61336+
61337+void __init
61338+grsecurity_init(void)
61339+{
61340+ int j;
61341+ /* create the per-cpu shared pages */
61342+
61343+#ifdef CONFIG_X86
61344+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
61345+#endif
61346+
61347+ for (j = 0; j < 4; j++) {
61348+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
61349+ if (gr_shared_page[j] == NULL) {
61350+ panic("Unable to allocate grsecurity shared page");
61351+ return;
61352+ }
61353+ }
61354+
61355+ /* allocate log buffers */
61356+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
61357+ if (!gr_alert_log_fmt) {
61358+ panic("Unable to allocate grsecurity alert log format buffer");
61359+ return;
61360+ }
61361+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
61362+ if (!gr_audit_log_fmt) {
61363+ panic("Unable to allocate grsecurity audit log format buffer");
61364+ return;
61365+ }
61366+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
61367+ if (!gr_alert_log_buf) {
61368+ panic("Unable to allocate grsecurity alert log buffer");
61369+ return;
61370+ }
61371+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
61372+ if (!gr_audit_log_buf) {
61373+ panic("Unable to allocate grsecurity audit log buffer");
61374+ return;
61375+ }
61376+
61377+ /* allocate memory for authentication structure */
61378+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
61379+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
61380+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
61381+
61382+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
61383+ panic("Unable to allocate grsecurity authentication structure");
61384+ return;
61385+ }
61386+
61387+
61388+#ifdef CONFIG_GRKERNSEC_IO
61389+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
61390+ grsec_disable_privio = 1;
61391+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
61392+ grsec_disable_privio = 1;
61393+#else
61394+ grsec_disable_privio = 0;
61395+#endif
61396+#endif
61397+
61398+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
61399+ /* for backward compatibility, tpe_invert always defaults to on if
61400+ enabled in the kernel
61401+ */
61402+ grsec_enable_tpe_invert = 1;
61403+#endif
61404+
61405+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
61406+#ifndef CONFIG_GRKERNSEC_SYSCTL
61407+ grsec_lock = 1;
61408+#endif
61409+
61410+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61411+ grsec_enable_audit_textrel = 1;
61412+#endif
61413+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61414+ grsec_enable_log_rwxmaps = 1;
61415+#endif
61416+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
61417+ grsec_enable_group = 1;
61418+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
61419+#endif
61420+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61421+ grsec_enable_ptrace_readexec = 1;
61422+#endif
61423+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
61424+ grsec_enable_chdir = 1;
61425+#endif
61426+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61427+ grsec_enable_harden_ptrace = 1;
61428+#endif
61429+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61430+ grsec_enable_mount = 1;
61431+#endif
61432+#ifdef CONFIG_GRKERNSEC_LINK
61433+ grsec_enable_link = 1;
61434+#endif
61435+#ifdef CONFIG_GRKERNSEC_BRUTE
61436+ grsec_enable_brute = 1;
61437+#endif
61438+#ifdef CONFIG_GRKERNSEC_DMESG
61439+ grsec_enable_dmesg = 1;
61440+#endif
61441+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
61442+ grsec_enable_blackhole = 1;
61443+ grsec_lastack_retries = 4;
61444+#endif
61445+#ifdef CONFIG_GRKERNSEC_FIFO
61446+ grsec_enable_fifo = 1;
61447+#endif
61448+#ifdef CONFIG_GRKERNSEC_EXECLOG
61449+ grsec_enable_execlog = 1;
61450+#endif
61451+#ifdef CONFIG_GRKERNSEC_SETXID
61452+ grsec_enable_setxid = 1;
61453+#endif
61454+#ifdef CONFIG_GRKERNSEC_SIGNAL
61455+ grsec_enable_signal = 1;
61456+#endif
61457+#ifdef CONFIG_GRKERNSEC_FORKFAIL
61458+ grsec_enable_forkfail = 1;
61459+#endif
61460+#ifdef CONFIG_GRKERNSEC_TIME
61461+ grsec_enable_time = 1;
61462+#endif
61463+#ifdef CONFIG_GRKERNSEC_RESLOG
61464+ grsec_resource_logging = 1;
61465+#endif
61466+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61467+ grsec_enable_chroot_findtask = 1;
61468+#endif
61469+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61470+ grsec_enable_chroot_unix = 1;
61471+#endif
61472+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61473+ grsec_enable_chroot_mount = 1;
61474+#endif
61475+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61476+ grsec_enable_chroot_fchdir = 1;
61477+#endif
61478+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61479+ grsec_enable_chroot_shmat = 1;
61480+#endif
61481+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61482+ grsec_enable_audit_ptrace = 1;
61483+#endif
61484+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61485+ grsec_enable_chroot_double = 1;
61486+#endif
61487+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61488+ grsec_enable_chroot_pivot = 1;
61489+#endif
61490+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61491+ grsec_enable_chroot_chdir = 1;
61492+#endif
61493+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61494+ grsec_enable_chroot_chmod = 1;
61495+#endif
61496+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61497+ grsec_enable_chroot_mknod = 1;
61498+#endif
61499+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61500+ grsec_enable_chroot_nice = 1;
61501+#endif
61502+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61503+ grsec_enable_chroot_execlog = 1;
61504+#endif
61505+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61506+ grsec_enable_chroot_caps = 1;
61507+#endif
61508+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
61509+ grsec_enable_chroot_sysctl = 1;
61510+#endif
61511+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61512+ grsec_enable_symlinkown = 1;
61513+ grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
61514+#endif
61515+#ifdef CONFIG_GRKERNSEC_TPE
61516+ grsec_enable_tpe = 1;
61517+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
61518+#ifdef CONFIG_GRKERNSEC_TPE_ALL
61519+ grsec_enable_tpe_all = 1;
61520+#endif
61521+#endif
61522+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61523+ grsec_enable_socket_all = 1;
61524+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
61525+#endif
61526+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61527+ grsec_enable_socket_client = 1;
61528+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
61529+#endif
61530+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61531+ grsec_enable_socket_server = 1;
61532+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
61533+#endif
61534+#endif
61535+
61536+ return;
61537+}
61538diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
61539new file mode 100644
61540index 0000000..6095407
61541--- /dev/null
61542+++ b/grsecurity/grsec_link.c
61543@@ -0,0 +1,58 @@
61544+#include <linux/kernel.h>
61545+#include <linux/sched.h>
61546+#include <linux/fs.h>
61547+#include <linux/file.h>
61548+#include <linux/grinternal.h>
61549+
61550+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
61551+{
61552+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61553+ const struct inode *link_inode = link->dentry->d_inode;
61554+
61555+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
61556+ /* ignore root-owned links, e.g. /proc/self */
61557+ !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
61558+ !uid_eq(link_inode->i_uid, target->i_uid)) {
61559+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
61560+ return 1;
61561+ }
61562+#endif
61563+ return 0;
61564+}
61565+
61566+int
61567+gr_handle_follow_link(const struct inode *parent,
61568+ const struct inode *inode,
61569+ const struct dentry *dentry, const struct vfsmount *mnt)
61570+{
61571+#ifdef CONFIG_GRKERNSEC_LINK
61572+ const struct cred *cred = current_cred();
61573+
61574+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
61575+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
61576+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
61577+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
61578+ return -EACCES;
61579+ }
61580+#endif
61581+ return 0;
61582+}
61583+
61584+int
61585+gr_handle_hardlink(const struct dentry *dentry,
61586+ const struct vfsmount *mnt,
61587+ struct inode *inode, const int mode, const struct filename *to)
61588+{
61589+#ifdef CONFIG_GRKERNSEC_LINK
61590+ const struct cred *cred = current_cred();
61591+
61592+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
61593+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
61594+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
61595+ !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
61596+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
61597+ return -EPERM;
61598+ }
61599+#endif
61600+ return 0;
61601+}
61602diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
61603new file mode 100644
61604index 0000000..7bd6c2b
61605--- /dev/null
61606+++ b/grsecurity/grsec_log.c
61607@@ -0,0 +1,329 @@
61608+#include <linux/kernel.h>
61609+#include <linux/sched.h>
61610+#include <linux/file.h>
61611+#include <linux/tty.h>
61612+#include <linux/fs.h>
61613+#include <linux/grinternal.h>
61614+
61615+#ifdef CONFIG_TREE_PREEMPT_RCU
61616+#define DISABLE_PREEMPT() preempt_disable()
61617+#define ENABLE_PREEMPT() preempt_enable()
61618+#else
61619+#define DISABLE_PREEMPT()
61620+#define ENABLE_PREEMPT()
61621+#endif
61622+
61623+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
61624+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
61625+
61626+#define BEGIN_LOCKS(x) \
61627+ DISABLE_PREEMPT(); \
61628+ rcu_read_lock(); \
61629+ read_lock(&tasklist_lock); \
61630+ read_lock(&grsec_exec_file_lock); \
61631+ if (x != GR_DO_AUDIT) \
61632+ spin_lock(&grsec_alert_lock); \
61633+ else \
61634+ spin_lock(&grsec_audit_lock)
61635+
61636+#define END_LOCKS(x) \
61637+ if (x != GR_DO_AUDIT) \
61638+ spin_unlock(&grsec_alert_lock); \
61639+ else \
61640+ spin_unlock(&grsec_audit_lock); \
61641+ read_unlock(&grsec_exec_file_lock); \
61642+ read_unlock(&tasklist_lock); \
61643+ rcu_read_unlock(); \
61644+ ENABLE_PREEMPT(); \
61645+ if (x == GR_DONT_AUDIT) \
61646+ gr_handle_alertkill(current)
61647+
61648+enum {
61649+ FLOODING,
61650+ NO_FLOODING
61651+};
61652+
61653+extern char *gr_alert_log_fmt;
61654+extern char *gr_audit_log_fmt;
61655+extern char *gr_alert_log_buf;
61656+extern char *gr_audit_log_buf;
61657+
61658+static int gr_log_start(int audit)
61659+{
61660+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
61661+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
61662+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61663+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
61664+ unsigned long curr_secs = get_seconds();
61665+
61666+ if (audit == GR_DO_AUDIT)
61667+ goto set_fmt;
61668+
61669+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
61670+ grsec_alert_wtime = curr_secs;
61671+ grsec_alert_fyet = 0;
61672+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
61673+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
61674+ grsec_alert_fyet++;
61675+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
61676+ grsec_alert_wtime = curr_secs;
61677+ grsec_alert_fyet++;
61678+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
61679+ return FLOODING;
61680+ }
61681+ else return FLOODING;
61682+
61683+set_fmt:
61684+#endif
61685+ memset(buf, 0, PAGE_SIZE);
61686+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
61687+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
61688+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
61689+ } else if (current->signal->curr_ip) {
61690+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
61691+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
61692+ } else if (gr_acl_is_enabled()) {
61693+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
61694+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
61695+ } else {
61696+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
61697+ strcpy(buf, fmt);
61698+ }
61699+
61700+ return NO_FLOODING;
61701+}
61702+
61703+static void gr_log_middle(int audit, const char *msg, va_list ap)
61704+ __attribute__ ((format (printf, 2, 0)));
61705+
61706+static void gr_log_middle(int audit, const char *msg, va_list ap)
61707+{
61708+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61709+ unsigned int len = strlen(buf);
61710+
61711+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
61712+
61713+ return;
61714+}
61715+
61716+static void gr_log_middle_varargs(int audit, const char *msg, ...)
61717+ __attribute__ ((format (printf, 2, 3)));
61718+
61719+static void gr_log_middle_varargs(int audit, const char *msg, ...)
61720+{
61721+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61722+ unsigned int len = strlen(buf);
61723+ va_list ap;
61724+
61725+ va_start(ap, msg);
61726+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
61727+ va_end(ap);
61728+
61729+ return;
61730+}
61731+
61732+static void gr_log_end(int audit, int append_default)
61733+{
61734+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61735+ if (append_default) {
61736+ struct task_struct *task = current;
61737+ struct task_struct *parent = task->real_parent;
61738+ const struct cred *cred = __task_cred(task);
61739+ const struct cred *pcred = __task_cred(parent);
61740+ unsigned int len = strlen(buf);
61741+
61742+ 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));
61743+ }
61744+
61745+ printk("%s\n", buf);
61746+
61747+ return;
61748+}
61749+
61750+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
61751+{
61752+ int logtype;
61753+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
61754+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
61755+ void *voidptr = NULL;
61756+ int num1 = 0, num2 = 0;
61757+ unsigned long ulong1 = 0, ulong2 = 0;
61758+ struct dentry *dentry = NULL;
61759+ struct vfsmount *mnt = NULL;
61760+ struct file *file = NULL;
61761+ struct task_struct *task = NULL;
61762+ const struct cred *cred, *pcred;
61763+ va_list ap;
61764+
61765+ BEGIN_LOCKS(audit);
61766+ logtype = gr_log_start(audit);
61767+ if (logtype == FLOODING) {
61768+ END_LOCKS(audit);
61769+ return;
61770+ }
61771+ va_start(ap, argtypes);
61772+ switch (argtypes) {
61773+ case GR_TTYSNIFF:
61774+ task = va_arg(ap, struct task_struct *);
61775+ 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));
61776+ break;
61777+ case GR_SYSCTL_HIDDEN:
61778+ str1 = va_arg(ap, char *);
61779+ gr_log_middle_varargs(audit, msg, result, str1);
61780+ break;
61781+ case GR_RBAC:
61782+ dentry = va_arg(ap, struct dentry *);
61783+ mnt = va_arg(ap, struct vfsmount *);
61784+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
61785+ break;
61786+ case GR_RBAC_STR:
61787+ dentry = va_arg(ap, struct dentry *);
61788+ mnt = va_arg(ap, struct vfsmount *);
61789+ str1 = va_arg(ap, char *);
61790+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
61791+ break;
61792+ case GR_STR_RBAC:
61793+ str1 = va_arg(ap, char *);
61794+ dentry = va_arg(ap, struct dentry *);
61795+ mnt = va_arg(ap, struct vfsmount *);
61796+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
61797+ break;
61798+ case GR_RBAC_MODE2:
61799+ dentry = va_arg(ap, struct dentry *);
61800+ mnt = va_arg(ap, struct vfsmount *);
61801+ str1 = va_arg(ap, char *);
61802+ str2 = va_arg(ap, char *);
61803+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
61804+ break;
61805+ case GR_RBAC_MODE3:
61806+ dentry = va_arg(ap, struct dentry *);
61807+ mnt = va_arg(ap, struct vfsmount *);
61808+ str1 = va_arg(ap, char *);
61809+ str2 = va_arg(ap, char *);
61810+ str3 = va_arg(ap, char *);
61811+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
61812+ break;
61813+ case GR_FILENAME:
61814+ dentry = va_arg(ap, struct dentry *);
61815+ mnt = va_arg(ap, struct vfsmount *);
61816+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
61817+ break;
61818+ case GR_STR_FILENAME:
61819+ str1 = va_arg(ap, char *);
61820+ dentry = va_arg(ap, struct dentry *);
61821+ mnt = va_arg(ap, struct vfsmount *);
61822+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
61823+ break;
61824+ case GR_FILENAME_STR:
61825+ dentry = va_arg(ap, struct dentry *);
61826+ mnt = va_arg(ap, struct vfsmount *);
61827+ str1 = va_arg(ap, char *);
61828+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
61829+ break;
61830+ case GR_FILENAME_TWO_INT:
61831+ dentry = va_arg(ap, struct dentry *);
61832+ mnt = va_arg(ap, struct vfsmount *);
61833+ num1 = va_arg(ap, int);
61834+ num2 = va_arg(ap, int);
61835+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
61836+ break;
61837+ case GR_FILENAME_TWO_INT_STR:
61838+ dentry = va_arg(ap, struct dentry *);
61839+ mnt = va_arg(ap, struct vfsmount *);
61840+ num1 = va_arg(ap, int);
61841+ num2 = va_arg(ap, int);
61842+ str1 = va_arg(ap, char *);
61843+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
61844+ break;
61845+ case GR_TEXTREL:
61846+ file = va_arg(ap, struct file *);
61847+ ulong1 = va_arg(ap, unsigned long);
61848+ ulong2 = va_arg(ap, unsigned long);
61849+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
61850+ break;
61851+ case GR_PTRACE:
61852+ task = va_arg(ap, struct task_struct *);
61853+ 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));
61854+ break;
61855+ case GR_RESOURCE:
61856+ task = va_arg(ap, struct task_struct *);
61857+ cred = __task_cred(task);
61858+ pcred = __task_cred(task->real_parent);
61859+ ulong1 = va_arg(ap, unsigned long);
61860+ str1 = va_arg(ap, char *);
61861+ ulong2 = va_arg(ap, unsigned long);
61862+ 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));
61863+ break;
61864+ case GR_CAP:
61865+ task = va_arg(ap, struct task_struct *);
61866+ cred = __task_cred(task);
61867+ pcred = __task_cred(task->real_parent);
61868+ str1 = va_arg(ap, char *);
61869+ 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));
61870+ break;
61871+ case GR_SIG:
61872+ str1 = va_arg(ap, char *);
61873+ voidptr = va_arg(ap, void *);
61874+ gr_log_middle_varargs(audit, msg, str1, voidptr);
61875+ break;
61876+ case GR_SIG2:
61877+ task = va_arg(ap, struct task_struct *);
61878+ cred = __task_cred(task);
61879+ pcred = __task_cred(task->real_parent);
61880+ num1 = va_arg(ap, int);
61881+ 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));
61882+ break;
61883+ case GR_CRASH1:
61884+ task = va_arg(ap, struct task_struct *);
61885+ cred = __task_cred(task);
61886+ pcred = __task_cred(task->real_parent);
61887+ ulong1 = va_arg(ap, unsigned long);
61888+ 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);
61889+ break;
61890+ case GR_CRASH2:
61891+ task = va_arg(ap, struct task_struct *);
61892+ cred = __task_cred(task);
61893+ pcred = __task_cred(task->real_parent);
61894+ ulong1 = va_arg(ap, unsigned long);
61895+ 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);
61896+ break;
61897+ case GR_RWXMAP:
61898+ file = va_arg(ap, struct file *);
61899+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
61900+ break;
61901+ case GR_PSACCT:
61902+ {
61903+ unsigned int wday, cday;
61904+ __u8 whr, chr;
61905+ __u8 wmin, cmin;
61906+ __u8 wsec, csec;
61907+ char cur_tty[64] = { 0 };
61908+ char parent_tty[64] = { 0 };
61909+
61910+ task = va_arg(ap, struct task_struct *);
61911+ wday = va_arg(ap, unsigned int);
61912+ cday = va_arg(ap, unsigned int);
61913+ whr = va_arg(ap, int);
61914+ chr = va_arg(ap, int);
61915+ wmin = va_arg(ap, int);
61916+ cmin = va_arg(ap, int);
61917+ wsec = va_arg(ap, int);
61918+ csec = va_arg(ap, int);
61919+ ulong1 = va_arg(ap, unsigned long);
61920+ cred = __task_cred(task);
61921+ pcred = __task_cred(task->real_parent);
61922+
61923+ 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));
61924+ }
61925+ break;
61926+ default:
61927+ gr_log_middle(audit, msg, ap);
61928+ }
61929+ va_end(ap);
61930+ // these don't need DEFAULTSECARGS printed on the end
61931+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
61932+ gr_log_end(audit, 0);
61933+ else
61934+ gr_log_end(audit, 1);
61935+ END_LOCKS(audit);
61936+}
61937diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
61938new file mode 100644
61939index 0000000..f536303
61940--- /dev/null
61941+++ b/grsecurity/grsec_mem.c
61942@@ -0,0 +1,40 @@
61943+#include <linux/kernel.h>
61944+#include <linux/sched.h>
61945+#include <linux/mm.h>
61946+#include <linux/mman.h>
61947+#include <linux/grinternal.h>
61948+
61949+void
61950+gr_handle_ioperm(void)
61951+{
61952+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
61953+ return;
61954+}
61955+
61956+void
61957+gr_handle_iopl(void)
61958+{
61959+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
61960+ return;
61961+}
61962+
61963+void
61964+gr_handle_mem_readwrite(u64 from, u64 to)
61965+{
61966+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
61967+ return;
61968+}
61969+
61970+void
61971+gr_handle_vm86(void)
61972+{
61973+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
61974+ return;
61975+}
61976+
61977+void
61978+gr_log_badprocpid(const char *entry)
61979+{
61980+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
61981+ return;
61982+}
61983diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
61984new file mode 100644
61985index 0000000..2131422
61986--- /dev/null
61987+++ b/grsecurity/grsec_mount.c
61988@@ -0,0 +1,62 @@
61989+#include <linux/kernel.h>
61990+#include <linux/sched.h>
61991+#include <linux/mount.h>
61992+#include <linux/grsecurity.h>
61993+#include <linux/grinternal.h>
61994+
61995+void
61996+gr_log_remount(const char *devname, const int retval)
61997+{
61998+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61999+ if (grsec_enable_mount && (retval >= 0))
62000+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
62001+#endif
62002+ return;
62003+}
62004+
62005+void
62006+gr_log_unmount(const char *devname, const int retval)
62007+{
62008+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62009+ if (grsec_enable_mount && (retval >= 0))
62010+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
62011+#endif
62012+ return;
62013+}
62014+
62015+void
62016+gr_log_mount(const char *from, const char *to, const int retval)
62017+{
62018+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62019+ if (grsec_enable_mount && (retval >= 0))
62020+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
62021+#endif
62022+ return;
62023+}
62024+
62025+int
62026+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
62027+{
62028+#ifdef CONFIG_GRKERNSEC_ROFS
62029+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
62030+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
62031+ return -EPERM;
62032+ } else
62033+ return 0;
62034+#endif
62035+ return 0;
62036+}
62037+
62038+int
62039+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
62040+{
62041+#ifdef CONFIG_GRKERNSEC_ROFS
62042+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
62043+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
62044+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
62045+ return -EPERM;
62046+ } else
62047+ return 0;
62048+#endif
62049+ return 0;
62050+}
62051diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
62052new file mode 100644
62053index 0000000..a3b12a0
62054--- /dev/null
62055+++ b/grsecurity/grsec_pax.c
62056@@ -0,0 +1,36 @@
62057+#include <linux/kernel.h>
62058+#include <linux/sched.h>
62059+#include <linux/mm.h>
62060+#include <linux/file.h>
62061+#include <linux/grinternal.h>
62062+#include <linux/grsecurity.h>
62063+
62064+void
62065+gr_log_textrel(struct vm_area_struct * vma)
62066+{
62067+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
62068+ if (grsec_enable_audit_textrel)
62069+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
62070+#endif
62071+ return;
62072+}
62073+
62074+void
62075+gr_log_rwxmmap(struct file *file)
62076+{
62077+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62078+ if (grsec_enable_log_rwxmaps)
62079+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
62080+#endif
62081+ return;
62082+}
62083+
62084+void
62085+gr_log_rwxmprotect(struct file *file)
62086+{
62087+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62088+ if (grsec_enable_log_rwxmaps)
62089+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
62090+#endif
62091+ return;
62092+}
62093diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
62094new file mode 100644
62095index 0000000..f7f29aa
62096--- /dev/null
62097+++ b/grsecurity/grsec_ptrace.c
62098@@ -0,0 +1,30 @@
62099+#include <linux/kernel.h>
62100+#include <linux/sched.h>
62101+#include <linux/grinternal.h>
62102+#include <linux/security.h>
62103+
62104+void
62105+gr_audit_ptrace(struct task_struct *task)
62106+{
62107+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
62108+ if (grsec_enable_audit_ptrace)
62109+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
62110+#endif
62111+ return;
62112+}
62113+
62114+int
62115+gr_ptrace_readexec(struct file *file, int unsafe_flags)
62116+{
62117+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
62118+ const struct dentry *dentry = file->f_path.dentry;
62119+ const struct vfsmount *mnt = file->f_path.mnt;
62120+
62121+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
62122+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
62123+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
62124+ return -EACCES;
62125+ }
62126+#endif
62127+ return 0;
62128+}
62129diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
62130new file mode 100644
62131index 0000000..5c00416
62132--- /dev/null
62133+++ b/grsecurity/grsec_sig.c
62134@@ -0,0 +1,222 @@
62135+#include <linux/kernel.h>
62136+#include <linux/sched.h>
62137+#include <linux/delay.h>
62138+#include <linux/grsecurity.h>
62139+#include <linux/grinternal.h>
62140+#include <linux/hardirq.h>
62141+
62142+char *signames[] = {
62143+ [SIGSEGV] = "Segmentation fault",
62144+ [SIGILL] = "Illegal instruction",
62145+ [SIGABRT] = "Abort",
62146+ [SIGBUS] = "Invalid alignment/Bus error"
62147+};
62148+
62149+void
62150+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
62151+{
62152+#ifdef CONFIG_GRKERNSEC_SIGNAL
62153+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
62154+ (sig == SIGABRT) || (sig == SIGBUS))) {
62155+ if (t->pid == current->pid) {
62156+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
62157+ } else {
62158+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
62159+ }
62160+ }
62161+#endif
62162+ return;
62163+}
62164+
62165+int
62166+gr_handle_signal(const struct task_struct *p, const int sig)
62167+{
62168+#ifdef CONFIG_GRKERNSEC
62169+ /* ignore the 0 signal for protected task checks */
62170+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
62171+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
62172+ return -EPERM;
62173+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
62174+ return -EPERM;
62175+ }
62176+#endif
62177+ return 0;
62178+}
62179+
62180+#ifdef CONFIG_GRKERNSEC
62181+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
62182+
62183+int gr_fake_force_sig(int sig, struct task_struct *t)
62184+{
62185+ unsigned long int flags;
62186+ int ret, blocked, ignored;
62187+ struct k_sigaction *action;
62188+
62189+ spin_lock_irqsave(&t->sighand->siglock, flags);
62190+ action = &t->sighand->action[sig-1];
62191+ ignored = action->sa.sa_handler == SIG_IGN;
62192+ blocked = sigismember(&t->blocked, sig);
62193+ if (blocked || ignored) {
62194+ action->sa.sa_handler = SIG_DFL;
62195+ if (blocked) {
62196+ sigdelset(&t->blocked, sig);
62197+ recalc_sigpending_and_wake(t);
62198+ }
62199+ }
62200+ if (action->sa.sa_handler == SIG_DFL)
62201+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
62202+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
62203+
62204+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
62205+
62206+ return ret;
62207+}
62208+#endif
62209+
62210+#ifdef CONFIG_GRKERNSEC_BRUTE
62211+#define GR_USER_BAN_TIME (15 * 60)
62212+#define GR_DAEMON_BRUTE_TIME (30 * 60)
62213+
62214+static int __get_dumpable(unsigned long mm_flags)
62215+{
62216+ int ret;
62217+
62218+ ret = mm_flags & MMF_DUMPABLE_MASK;
62219+ return (ret >= 2) ? 2 : ret;
62220+}
62221+#endif
62222+
62223+void gr_handle_brute_attach(unsigned long mm_flags)
62224+{
62225+#ifdef CONFIG_GRKERNSEC_BRUTE
62226+ struct task_struct *p = current;
62227+ kuid_t uid = GLOBAL_ROOT_UID;
62228+ int daemon = 0;
62229+
62230+ if (!grsec_enable_brute)
62231+ return;
62232+
62233+ rcu_read_lock();
62234+ read_lock(&tasklist_lock);
62235+ read_lock(&grsec_exec_file_lock);
62236+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
62237+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
62238+ p->real_parent->brute = 1;
62239+ daemon = 1;
62240+ } else {
62241+ const struct cred *cred = __task_cred(p), *cred2;
62242+ struct task_struct *tsk, *tsk2;
62243+
62244+ if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
62245+ struct user_struct *user;
62246+
62247+ uid = cred->uid;
62248+
62249+ /* this is put upon execution past expiration */
62250+ user = find_user(uid);
62251+ if (user == NULL)
62252+ goto unlock;
62253+ user->banned = 1;
62254+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
62255+ if (user->ban_expires == ~0UL)
62256+ user->ban_expires--;
62257+
62258+ do_each_thread(tsk2, tsk) {
62259+ cred2 = __task_cred(tsk);
62260+ if (tsk != p && uid_eq(cred2->uid, uid))
62261+ gr_fake_force_sig(SIGKILL, tsk);
62262+ } while_each_thread(tsk2, tsk);
62263+ }
62264+ }
62265+unlock:
62266+ read_unlock(&grsec_exec_file_lock);
62267+ read_unlock(&tasklist_lock);
62268+ rcu_read_unlock();
62269+
62270+ if (!uid_eq(uid, GLOBAL_ROOT_UID))
62271+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
62272+ from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
62273+ else if (daemon)
62274+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
62275+
62276+#endif
62277+ return;
62278+}
62279+
62280+void gr_handle_brute_check(void)
62281+{
62282+#ifdef CONFIG_GRKERNSEC_BRUTE
62283+ struct task_struct *p = current;
62284+
62285+ if (unlikely(p->brute)) {
62286+ if (!grsec_enable_brute)
62287+ p->brute = 0;
62288+ else if (time_before(get_seconds(), p->brute_expires))
62289+ msleep(30 * 1000);
62290+ }
62291+#endif
62292+ return;
62293+}
62294+
62295+void gr_handle_kernel_exploit(void)
62296+{
62297+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
62298+ const struct cred *cred;
62299+ struct task_struct *tsk, *tsk2;
62300+ struct user_struct *user;
62301+ kuid_t uid;
62302+
62303+ if (in_irq() || in_serving_softirq() || in_nmi())
62304+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
62305+
62306+ uid = current_uid();
62307+
62308+ if (uid_eq(uid, GLOBAL_ROOT_UID))
62309+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
62310+ else {
62311+ /* kill all the processes of this user, hold a reference
62312+ to their creds struct, and prevent them from creating
62313+ another process until system reset
62314+ */
62315+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
62316+ from_kuid_munged(&init_user_ns, uid));
62317+ /* we intentionally leak this ref */
62318+ user = get_uid(current->cred->user);
62319+ if (user) {
62320+ user->banned = 1;
62321+ user->ban_expires = ~0UL;
62322+ }
62323+
62324+ read_lock(&tasklist_lock);
62325+ do_each_thread(tsk2, tsk) {
62326+ cred = __task_cred(tsk);
62327+ if (uid_eq(cred->uid, uid))
62328+ gr_fake_force_sig(SIGKILL, tsk);
62329+ } while_each_thread(tsk2, tsk);
62330+ read_unlock(&tasklist_lock);
62331+ }
62332+#endif
62333+}
62334+
62335+int __gr_process_user_ban(struct user_struct *user)
62336+{
62337+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62338+ if (unlikely(user->banned)) {
62339+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
62340+ user->banned = 0;
62341+ user->ban_expires = 0;
62342+ free_uid(user);
62343+ } else
62344+ return -EPERM;
62345+ }
62346+#endif
62347+ return 0;
62348+}
62349+
62350+int gr_process_user_ban(void)
62351+{
62352+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62353+ return __gr_process_user_ban(current->cred->user);
62354+#endif
62355+ return 0;
62356+}
62357diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
62358new file mode 100644
62359index 0000000..4030d57
62360--- /dev/null
62361+++ b/grsecurity/grsec_sock.c
62362@@ -0,0 +1,244 @@
62363+#include <linux/kernel.h>
62364+#include <linux/module.h>
62365+#include <linux/sched.h>
62366+#include <linux/file.h>
62367+#include <linux/net.h>
62368+#include <linux/in.h>
62369+#include <linux/ip.h>
62370+#include <net/sock.h>
62371+#include <net/inet_sock.h>
62372+#include <linux/grsecurity.h>
62373+#include <linux/grinternal.h>
62374+#include <linux/gracl.h>
62375+
62376+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
62377+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
62378+
62379+EXPORT_SYMBOL(gr_search_udp_recvmsg);
62380+EXPORT_SYMBOL(gr_search_udp_sendmsg);
62381+
62382+#ifdef CONFIG_UNIX_MODULE
62383+EXPORT_SYMBOL(gr_acl_handle_unix);
62384+EXPORT_SYMBOL(gr_acl_handle_mknod);
62385+EXPORT_SYMBOL(gr_handle_chroot_unix);
62386+EXPORT_SYMBOL(gr_handle_create);
62387+#endif
62388+
62389+#ifdef CONFIG_GRKERNSEC
62390+#define gr_conn_table_size 32749
62391+struct conn_table_entry {
62392+ struct conn_table_entry *next;
62393+ struct signal_struct *sig;
62394+};
62395+
62396+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
62397+DEFINE_SPINLOCK(gr_conn_table_lock);
62398+
62399+extern const char * gr_socktype_to_name(unsigned char type);
62400+extern const char * gr_proto_to_name(unsigned char proto);
62401+extern const char * gr_sockfamily_to_name(unsigned char family);
62402+
62403+static __inline__ int
62404+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
62405+{
62406+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
62407+}
62408+
62409+static __inline__ int
62410+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
62411+ __u16 sport, __u16 dport)
62412+{
62413+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
62414+ sig->gr_sport == sport && sig->gr_dport == dport))
62415+ return 1;
62416+ else
62417+ return 0;
62418+}
62419+
62420+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
62421+{
62422+ struct conn_table_entry **match;
62423+ unsigned int index;
62424+
62425+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
62426+ sig->gr_sport, sig->gr_dport,
62427+ gr_conn_table_size);
62428+
62429+ newent->sig = sig;
62430+
62431+ match = &gr_conn_table[index];
62432+ newent->next = *match;
62433+ *match = newent;
62434+
62435+ return;
62436+}
62437+
62438+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
62439+{
62440+ struct conn_table_entry *match, *last = NULL;
62441+ unsigned int index;
62442+
62443+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
62444+ sig->gr_sport, sig->gr_dport,
62445+ gr_conn_table_size);
62446+
62447+ match = gr_conn_table[index];
62448+ while (match && !conn_match(match->sig,
62449+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
62450+ sig->gr_dport)) {
62451+ last = match;
62452+ match = match->next;
62453+ }
62454+
62455+ if (match) {
62456+ if (last)
62457+ last->next = match->next;
62458+ else
62459+ gr_conn_table[index] = NULL;
62460+ kfree(match);
62461+ }
62462+
62463+ return;
62464+}
62465+
62466+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
62467+ __u16 sport, __u16 dport)
62468+{
62469+ struct conn_table_entry *match;
62470+ unsigned int index;
62471+
62472+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
62473+
62474+ match = gr_conn_table[index];
62475+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
62476+ match = match->next;
62477+
62478+ if (match)
62479+ return match->sig;
62480+ else
62481+ return NULL;
62482+}
62483+
62484+#endif
62485+
62486+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
62487+{
62488+#ifdef CONFIG_GRKERNSEC
62489+ struct signal_struct *sig = task->signal;
62490+ struct conn_table_entry *newent;
62491+
62492+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
62493+ if (newent == NULL)
62494+ return;
62495+ /* no bh lock needed since we are called with bh disabled */
62496+ spin_lock(&gr_conn_table_lock);
62497+ gr_del_task_from_ip_table_nolock(sig);
62498+ sig->gr_saddr = inet->inet_rcv_saddr;
62499+ sig->gr_daddr = inet->inet_daddr;
62500+ sig->gr_sport = inet->inet_sport;
62501+ sig->gr_dport = inet->inet_dport;
62502+ gr_add_to_task_ip_table_nolock(sig, newent);
62503+ spin_unlock(&gr_conn_table_lock);
62504+#endif
62505+ return;
62506+}
62507+
62508+void gr_del_task_from_ip_table(struct task_struct *task)
62509+{
62510+#ifdef CONFIG_GRKERNSEC
62511+ spin_lock_bh(&gr_conn_table_lock);
62512+ gr_del_task_from_ip_table_nolock(task->signal);
62513+ spin_unlock_bh(&gr_conn_table_lock);
62514+#endif
62515+ return;
62516+}
62517+
62518+void
62519+gr_attach_curr_ip(const struct sock *sk)
62520+{
62521+#ifdef CONFIG_GRKERNSEC
62522+ struct signal_struct *p, *set;
62523+ const struct inet_sock *inet = inet_sk(sk);
62524+
62525+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
62526+ return;
62527+
62528+ set = current->signal;
62529+
62530+ spin_lock_bh(&gr_conn_table_lock);
62531+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
62532+ inet->inet_dport, inet->inet_sport);
62533+ if (unlikely(p != NULL)) {
62534+ set->curr_ip = p->curr_ip;
62535+ set->used_accept = 1;
62536+ gr_del_task_from_ip_table_nolock(p);
62537+ spin_unlock_bh(&gr_conn_table_lock);
62538+ return;
62539+ }
62540+ spin_unlock_bh(&gr_conn_table_lock);
62541+
62542+ set->curr_ip = inet->inet_daddr;
62543+ set->used_accept = 1;
62544+#endif
62545+ return;
62546+}
62547+
62548+int
62549+gr_handle_sock_all(const int family, const int type, const int protocol)
62550+{
62551+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62552+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
62553+ (family != AF_UNIX)) {
62554+ if (family == AF_INET)
62555+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
62556+ else
62557+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
62558+ return -EACCES;
62559+ }
62560+#endif
62561+ return 0;
62562+}
62563+
62564+int
62565+gr_handle_sock_server(const struct sockaddr *sck)
62566+{
62567+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62568+ if (grsec_enable_socket_server &&
62569+ in_group_p(grsec_socket_server_gid) &&
62570+ sck && (sck->sa_family != AF_UNIX) &&
62571+ (sck->sa_family != AF_LOCAL)) {
62572+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
62573+ return -EACCES;
62574+ }
62575+#endif
62576+ return 0;
62577+}
62578+
62579+int
62580+gr_handle_sock_server_other(const struct sock *sck)
62581+{
62582+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62583+ if (grsec_enable_socket_server &&
62584+ in_group_p(grsec_socket_server_gid) &&
62585+ sck && (sck->sk_family != AF_UNIX) &&
62586+ (sck->sk_family != AF_LOCAL)) {
62587+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
62588+ return -EACCES;
62589+ }
62590+#endif
62591+ return 0;
62592+}
62593+
62594+int
62595+gr_handle_sock_client(const struct sockaddr *sck)
62596+{
62597+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62598+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
62599+ sck && (sck->sa_family != AF_UNIX) &&
62600+ (sck->sa_family != AF_LOCAL)) {
62601+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
62602+ return -EACCES;
62603+ }
62604+#endif
62605+ return 0;
62606+}
62607diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
62608new file mode 100644
62609index 0000000..f55ef0f
62610--- /dev/null
62611+++ b/grsecurity/grsec_sysctl.c
62612@@ -0,0 +1,469 @@
62613+#include <linux/kernel.h>
62614+#include <linux/sched.h>
62615+#include <linux/sysctl.h>
62616+#include <linux/grsecurity.h>
62617+#include <linux/grinternal.h>
62618+
62619+int
62620+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
62621+{
62622+#ifdef CONFIG_GRKERNSEC_SYSCTL
62623+ if (dirname == NULL || name == NULL)
62624+ return 0;
62625+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
62626+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
62627+ return -EACCES;
62628+ }
62629+#endif
62630+ return 0;
62631+}
62632+
62633+#ifdef CONFIG_GRKERNSEC_ROFS
62634+static int __maybe_unused one = 1;
62635+#endif
62636+
62637+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
62638+struct ctl_table grsecurity_table[] = {
62639+#ifdef CONFIG_GRKERNSEC_SYSCTL
62640+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
62641+#ifdef CONFIG_GRKERNSEC_IO
62642+ {
62643+ .procname = "disable_priv_io",
62644+ .data = &grsec_disable_privio,
62645+ .maxlen = sizeof(int),
62646+ .mode = 0600,
62647+ .proc_handler = &proc_dointvec,
62648+ },
62649+#endif
62650+#endif
62651+#ifdef CONFIG_GRKERNSEC_LINK
62652+ {
62653+ .procname = "linking_restrictions",
62654+ .data = &grsec_enable_link,
62655+ .maxlen = sizeof(int),
62656+ .mode = 0600,
62657+ .proc_handler = &proc_dointvec,
62658+ },
62659+#endif
62660+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
62661+ {
62662+ .procname = "enforce_symlinksifowner",
62663+ .data = &grsec_enable_symlinkown,
62664+ .maxlen = sizeof(int),
62665+ .mode = 0600,
62666+ .proc_handler = &proc_dointvec,
62667+ },
62668+ {
62669+ .procname = "symlinkown_gid",
62670+ .data = &grsec_symlinkown_gid,
62671+ .maxlen = sizeof(int),
62672+ .mode = 0600,
62673+ .proc_handler = &proc_dointvec,
62674+ },
62675+#endif
62676+#ifdef CONFIG_GRKERNSEC_BRUTE
62677+ {
62678+ .procname = "deter_bruteforce",
62679+ .data = &grsec_enable_brute,
62680+ .maxlen = sizeof(int),
62681+ .mode = 0600,
62682+ .proc_handler = &proc_dointvec,
62683+ },
62684+#endif
62685+#ifdef CONFIG_GRKERNSEC_FIFO
62686+ {
62687+ .procname = "fifo_restrictions",
62688+ .data = &grsec_enable_fifo,
62689+ .maxlen = sizeof(int),
62690+ .mode = 0600,
62691+ .proc_handler = &proc_dointvec,
62692+ },
62693+#endif
62694+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
62695+ {
62696+ .procname = "ptrace_readexec",
62697+ .data = &grsec_enable_ptrace_readexec,
62698+ .maxlen = sizeof(int),
62699+ .mode = 0600,
62700+ .proc_handler = &proc_dointvec,
62701+ },
62702+#endif
62703+#ifdef CONFIG_GRKERNSEC_SETXID
62704+ {
62705+ .procname = "consistent_setxid",
62706+ .data = &grsec_enable_setxid,
62707+ .maxlen = sizeof(int),
62708+ .mode = 0600,
62709+ .proc_handler = &proc_dointvec,
62710+ },
62711+#endif
62712+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
62713+ {
62714+ .procname = "ip_blackhole",
62715+ .data = &grsec_enable_blackhole,
62716+ .maxlen = sizeof(int),
62717+ .mode = 0600,
62718+ .proc_handler = &proc_dointvec,
62719+ },
62720+ {
62721+ .procname = "lastack_retries",
62722+ .data = &grsec_lastack_retries,
62723+ .maxlen = sizeof(int),
62724+ .mode = 0600,
62725+ .proc_handler = &proc_dointvec,
62726+ },
62727+#endif
62728+#ifdef CONFIG_GRKERNSEC_EXECLOG
62729+ {
62730+ .procname = "exec_logging",
62731+ .data = &grsec_enable_execlog,
62732+ .maxlen = sizeof(int),
62733+ .mode = 0600,
62734+ .proc_handler = &proc_dointvec,
62735+ },
62736+#endif
62737+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62738+ {
62739+ .procname = "rwxmap_logging",
62740+ .data = &grsec_enable_log_rwxmaps,
62741+ .maxlen = sizeof(int),
62742+ .mode = 0600,
62743+ .proc_handler = &proc_dointvec,
62744+ },
62745+#endif
62746+#ifdef CONFIG_GRKERNSEC_SIGNAL
62747+ {
62748+ .procname = "signal_logging",
62749+ .data = &grsec_enable_signal,
62750+ .maxlen = sizeof(int),
62751+ .mode = 0600,
62752+ .proc_handler = &proc_dointvec,
62753+ },
62754+#endif
62755+#ifdef CONFIG_GRKERNSEC_FORKFAIL
62756+ {
62757+ .procname = "forkfail_logging",
62758+ .data = &grsec_enable_forkfail,
62759+ .maxlen = sizeof(int),
62760+ .mode = 0600,
62761+ .proc_handler = &proc_dointvec,
62762+ },
62763+#endif
62764+#ifdef CONFIG_GRKERNSEC_TIME
62765+ {
62766+ .procname = "timechange_logging",
62767+ .data = &grsec_enable_time,
62768+ .maxlen = sizeof(int),
62769+ .mode = 0600,
62770+ .proc_handler = &proc_dointvec,
62771+ },
62772+#endif
62773+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
62774+ {
62775+ .procname = "chroot_deny_shmat",
62776+ .data = &grsec_enable_chroot_shmat,
62777+ .maxlen = sizeof(int),
62778+ .mode = 0600,
62779+ .proc_handler = &proc_dointvec,
62780+ },
62781+#endif
62782+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
62783+ {
62784+ .procname = "chroot_deny_unix",
62785+ .data = &grsec_enable_chroot_unix,
62786+ .maxlen = sizeof(int),
62787+ .mode = 0600,
62788+ .proc_handler = &proc_dointvec,
62789+ },
62790+#endif
62791+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
62792+ {
62793+ .procname = "chroot_deny_mount",
62794+ .data = &grsec_enable_chroot_mount,
62795+ .maxlen = sizeof(int),
62796+ .mode = 0600,
62797+ .proc_handler = &proc_dointvec,
62798+ },
62799+#endif
62800+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
62801+ {
62802+ .procname = "chroot_deny_fchdir",
62803+ .data = &grsec_enable_chroot_fchdir,
62804+ .maxlen = sizeof(int),
62805+ .mode = 0600,
62806+ .proc_handler = &proc_dointvec,
62807+ },
62808+#endif
62809+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
62810+ {
62811+ .procname = "chroot_deny_chroot",
62812+ .data = &grsec_enable_chroot_double,
62813+ .maxlen = sizeof(int),
62814+ .mode = 0600,
62815+ .proc_handler = &proc_dointvec,
62816+ },
62817+#endif
62818+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
62819+ {
62820+ .procname = "chroot_deny_pivot",
62821+ .data = &grsec_enable_chroot_pivot,
62822+ .maxlen = sizeof(int),
62823+ .mode = 0600,
62824+ .proc_handler = &proc_dointvec,
62825+ },
62826+#endif
62827+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
62828+ {
62829+ .procname = "chroot_enforce_chdir",
62830+ .data = &grsec_enable_chroot_chdir,
62831+ .maxlen = sizeof(int),
62832+ .mode = 0600,
62833+ .proc_handler = &proc_dointvec,
62834+ },
62835+#endif
62836+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62837+ {
62838+ .procname = "chroot_deny_chmod",
62839+ .data = &grsec_enable_chroot_chmod,
62840+ .maxlen = sizeof(int),
62841+ .mode = 0600,
62842+ .proc_handler = &proc_dointvec,
62843+ },
62844+#endif
62845+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
62846+ {
62847+ .procname = "chroot_deny_mknod",
62848+ .data = &grsec_enable_chroot_mknod,
62849+ .maxlen = sizeof(int),
62850+ .mode = 0600,
62851+ .proc_handler = &proc_dointvec,
62852+ },
62853+#endif
62854+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62855+ {
62856+ .procname = "chroot_restrict_nice",
62857+ .data = &grsec_enable_chroot_nice,
62858+ .maxlen = sizeof(int),
62859+ .mode = 0600,
62860+ .proc_handler = &proc_dointvec,
62861+ },
62862+#endif
62863+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62864+ {
62865+ .procname = "chroot_execlog",
62866+ .data = &grsec_enable_chroot_execlog,
62867+ .maxlen = sizeof(int),
62868+ .mode = 0600,
62869+ .proc_handler = &proc_dointvec,
62870+ },
62871+#endif
62872+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62873+ {
62874+ .procname = "chroot_caps",
62875+ .data = &grsec_enable_chroot_caps,
62876+ .maxlen = sizeof(int),
62877+ .mode = 0600,
62878+ .proc_handler = &proc_dointvec,
62879+ },
62880+#endif
62881+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62882+ {
62883+ .procname = "chroot_deny_sysctl",
62884+ .data = &grsec_enable_chroot_sysctl,
62885+ .maxlen = sizeof(int),
62886+ .mode = 0600,
62887+ .proc_handler = &proc_dointvec,
62888+ },
62889+#endif
62890+#ifdef CONFIG_GRKERNSEC_TPE
62891+ {
62892+ .procname = "tpe",
62893+ .data = &grsec_enable_tpe,
62894+ .maxlen = sizeof(int),
62895+ .mode = 0600,
62896+ .proc_handler = &proc_dointvec,
62897+ },
62898+ {
62899+ .procname = "tpe_gid",
62900+ .data = &grsec_tpe_gid,
62901+ .maxlen = sizeof(int),
62902+ .mode = 0600,
62903+ .proc_handler = &proc_dointvec,
62904+ },
62905+#endif
62906+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62907+ {
62908+ .procname = "tpe_invert",
62909+ .data = &grsec_enable_tpe_invert,
62910+ .maxlen = sizeof(int),
62911+ .mode = 0600,
62912+ .proc_handler = &proc_dointvec,
62913+ },
62914+#endif
62915+#ifdef CONFIG_GRKERNSEC_TPE_ALL
62916+ {
62917+ .procname = "tpe_restrict_all",
62918+ .data = &grsec_enable_tpe_all,
62919+ .maxlen = sizeof(int),
62920+ .mode = 0600,
62921+ .proc_handler = &proc_dointvec,
62922+ },
62923+#endif
62924+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62925+ {
62926+ .procname = "socket_all",
62927+ .data = &grsec_enable_socket_all,
62928+ .maxlen = sizeof(int),
62929+ .mode = 0600,
62930+ .proc_handler = &proc_dointvec,
62931+ },
62932+ {
62933+ .procname = "socket_all_gid",
62934+ .data = &grsec_socket_all_gid,
62935+ .maxlen = sizeof(int),
62936+ .mode = 0600,
62937+ .proc_handler = &proc_dointvec,
62938+ },
62939+#endif
62940+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62941+ {
62942+ .procname = "socket_client",
62943+ .data = &grsec_enable_socket_client,
62944+ .maxlen = sizeof(int),
62945+ .mode = 0600,
62946+ .proc_handler = &proc_dointvec,
62947+ },
62948+ {
62949+ .procname = "socket_client_gid",
62950+ .data = &grsec_socket_client_gid,
62951+ .maxlen = sizeof(int),
62952+ .mode = 0600,
62953+ .proc_handler = &proc_dointvec,
62954+ },
62955+#endif
62956+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62957+ {
62958+ .procname = "socket_server",
62959+ .data = &grsec_enable_socket_server,
62960+ .maxlen = sizeof(int),
62961+ .mode = 0600,
62962+ .proc_handler = &proc_dointvec,
62963+ },
62964+ {
62965+ .procname = "socket_server_gid",
62966+ .data = &grsec_socket_server_gid,
62967+ .maxlen = sizeof(int),
62968+ .mode = 0600,
62969+ .proc_handler = &proc_dointvec,
62970+ },
62971+#endif
62972+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
62973+ {
62974+ .procname = "audit_group",
62975+ .data = &grsec_enable_group,
62976+ .maxlen = sizeof(int),
62977+ .mode = 0600,
62978+ .proc_handler = &proc_dointvec,
62979+ },
62980+ {
62981+ .procname = "audit_gid",
62982+ .data = &grsec_audit_gid,
62983+ .maxlen = sizeof(int),
62984+ .mode = 0600,
62985+ .proc_handler = &proc_dointvec,
62986+ },
62987+#endif
62988+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62989+ {
62990+ .procname = "audit_chdir",
62991+ .data = &grsec_enable_chdir,
62992+ .maxlen = sizeof(int),
62993+ .mode = 0600,
62994+ .proc_handler = &proc_dointvec,
62995+ },
62996+#endif
62997+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62998+ {
62999+ .procname = "audit_mount",
63000+ .data = &grsec_enable_mount,
63001+ .maxlen = sizeof(int),
63002+ .mode = 0600,
63003+ .proc_handler = &proc_dointvec,
63004+ },
63005+#endif
63006+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
63007+ {
63008+ .procname = "audit_textrel",
63009+ .data = &grsec_enable_audit_textrel,
63010+ .maxlen = sizeof(int),
63011+ .mode = 0600,
63012+ .proc_handler = &proc_dointvec,
63013+ },
63014+#endif
63015+#ifdef CONFIG_GRKERNSEC_DMESG
63016+ {
63017+ .procname = "dmesg",
63018+ .data = &grsec_enable_dmesg,
63019+ .maxlen = sizeof(int),
63020+ .mode = 0600,
63021+ .proc_handler = &proc_dointvec,
63022+ },
63023+#endif
63024+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63025+ {
63026+ .procname = "chroot_findtask",
63027+ .data = &grsec_enable_chroot_findtask,
63028+ .maxlen = sizeof(int),
63029+ .mode = 0600,
63030+ .proc_handler = &proc_dointvec,
63031+ },
63032+#endif
63033+#ifdef CONFIG_GRKERNSEC_RESLOG
63034+ {
63035+ .procname = "resource_logging",
63036+ .data = &grsec_resource_logging,
63037+ .maxlen = sizeof(int),
63038+ .mode = 0600,
63039+ .proc_handler = &proc_dointvec,
63040+ },
63041+#endif
63042+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
63043+ {
63044+ .procname = "audit_ptrace",
63045+ .data = &grsec_enable_audit_ptrace,
63046+ .maxlen = sizeof(int),
63047+ .mode = 0600,
63048+ .proc_handler = &proc_dointvec,
63049+ },
63050+#endif
63051+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
63052+ {
63053+ .procname = "harden_ptrace",
63054+ .data = &grsec_enable_harden_ptrace,
63055+ .maxlen = sizeof(int),
63056+ .mode = 0600,
63057+ .proc_handler = &proc_dointvec,
63058+ },
63059+#endif
63060+ {
63061+ .procname = "grsec_lock",
63062+ .data = &grsec_lock,
63063+ .maxlen = sizeof(int),
63064+ .mode = 0600,
63065+ .proc_handler = &proc_dointvec,
63066+ },
63067+#endif
63068+#ifdef CONFIG_GRKERNSEC_ROFS
63069+ {
63070+ .procname = "romount_protect",
63071+ .data = &grsec_enable_rofs,
63072+ .maxlen = sizeof(int),
63073+ .mode = 0600,
63074+ .proc_handler = &proc_dointvec_minmax,
63075+ .extra1 = &one,
63076+ .extra2 = &one,
63077+ },
63078+#endif
63079+ { }
63080+};
63081+#endif
63082diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
63083new file mode 100644
63084index 0000000..0dc13c3
63085--- /dev/null
63086+++ b/grsecurity/grsec_time.c
63087@@ -0,0 +1,16 @@
63088+#include <linux/kernel.h>
63089+#include <linux/sched.h>
63090+#include <linux/grinternal.h>
63091+#include <linux/module.h>
63092+
63093+void
63094+gr_log_timechange(void)
63095+{
63096+#ifdef CONFIG_GRKERNSEC_TIME
63097+ if (grsec_enable_time)
63098+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
63099+#endif
63100+ return;
63101+}
63102+
63103+EXPORT_SYMBOL(gr_log_timechange);
63104diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
63105new file mode 100644
63106index 0000000..07e0dc0
63107--- /dev/null
63108+++ b/grsecurity/grsec_tpe.c
63109@@ -0,0 +1,73 @@
63110+#include <linux/kernel.h>
63111+#include <linux/sched.h>
63112+#include <linux/file.h>
63113+#include <linux/fs.h>
63114+#include <linux/grinternal.h>
63115+
63116+extern int gr_acl_tpe_check(void);
63117+
63118+int
63119+gr_tpe_allow(const struct file *file)
63120+{
63121+#ifdef CONFIG_GRKERNSEC
63122+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
63123+ const struct cred *cred = current_cred();
63124+ char *msg = NULL;
63125+ char *msg2 = NULL;
63126+
63127+ // never restrict root
63128+ if (!cred->uid)
63129+ return 1;
63130+
63131+ if (grsec_enable_tpe) {
63132+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
63133+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
63134+ msg = "not being in trusted group";
63135+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
63136+ msg = "being in untrusted group";
63137+#else
63138+ if (in_group_p(grsec_tpe_gid))
63139+ msg = "being in untrusted group";
63140+#endif
63141+ }
63142+ if (!msg && gr_acl_tpe_check())
63143+ msg = "being in untrusted role";
63144+
63145+ // not in any affected group/role
63146+ if (!msg)
63147+ goto next_check;
63148+
63149+ if (inode->i_uid)
63150+ msg2 = "file in non-root-owned directory";
63151+ else if (inode->i_mode & S_IWOTH)
63152+ msg2 = "file in world-writable directory";
63153+ else if (inode->i_mode & S_IWGRP)
63154+ msg2 = "file in group-writable directory";
63155+
63156+ if (msg && msg2) {
63157+ char fullmsg[70] = {0};
63158+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
63159+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
63160+ return 0;
63161+ }
63162+ msg = NULL;
63163+next_check:
63164+#ifdef CONFIG_GRKERNSEC_TPE_ALL
63165+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
63166+ return 1;
63167+
63168+ if (inode->i_uid && (inode->i_uid != cred->uid))
63169+ msg = "directory not owned by user";
63170+ else if (inode->i_mode & S_IWOTH)
63171+ msg = "file in world-writable directory";
63172+ else if (inode->i_mode & S_IWGRP)
63173+ msg = "file in group-writable directory";
63174+
63175+ if (msg) {
63176+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
63177+ return 0;
63178+ }
63179+#endif
63180+#endif
63181+ return 1;
63182+}
63183diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
63184new file mode 100644
63185index 0000000..9f7b1ac
63186--- /dev/null
63187+++ b/grsecurity/grsum.c
63188@@ -0,0 +1,61 @@
63189+#include <linux/err.h>
63190+#include <linux/kernel.h>
63191+#include <linux/sched.h>
63192+#include <linux/mm.h>
63193+#include <linux/scatterlist.h>
63194+#include <linux/crypto.h>
63195+#include <linux/gracl.h>
63196+
63197+
63198+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
63199+#error "crypto and sha256 must be built into the kernel"
63200+#endif
63201+
63202+int
63203+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
63204+{
63205+ char *p;
63206+ struct crypto_hash *tfm;
63207+ struct hash_desc desc;
63208+ struct scatterlist sg;
63209+ unsigned char temp_sum[GR_SHA_LEN];
63210+ volatile int retval = 0;
63211+ volatile int dummy = 0;
63212+ unsigned int i;
63213+
63214+ sg_init_table(&sg, 1);
63215+
63216+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
63217+ if (IS_ERR(tfm)) {
63218+ /* should never happen, since sha256 should be built in */
63219+ return 1;
63220+ }
63221+
63222+ desc.tfm = tfm;
63223+ desc.flags = 0;
63224+
63225+ crypto_hash_init(&desc);
63226+
63227+ p = salt;
63228+ sg_set_buf(&sg, p, GR_SALT_LEN);
63229+ crypto_hash_update(&desc, &sg, sg.length);
63230+
63231+ p = entry->pw;
63232+ sg_set_buf(&sg, p, strlen(p));
63233+
63234+ crypto_hash_update(&desc, &sg, sg.length);
63235+
63236+ crypto_hash_final(&desc, temp_sum);
63237+
63238+ memset(entry->pw, 0, GR_PW_LEN);
63239+
63240+ for (i = 0; i < GR_SHA_LEN; i++)
63241+ if (sum[i] != temp_sum[i])
63242+ retval = 1;
63243+ else
63244+ dummy = 1; // waste a cycle
63245+
63246+ crypto_free_hash(tfm);
63247+
63248+ return retval;
63249+}
63250diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
63251index 77ff547..181834f 100644
63252--- a/include/asm-generic/4level-fixup.h
63253+++ b/include/asm-generic/4level-fixup.h
63254@@ -13,8 +13,10 @@
63255 #define pmd_alloc(mm, pud, address) \
63256 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
63257 NULL: pmd_offset(pud, address))
63258+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
63259
63260 #define pud_alloc(mm, pgd, address) (pgd)
63261+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
63262 #define pud_offset(pgd, start) (pgd)
63263 #define pud_none(pud) 0
63264 #define pud_bad(pud) 0
63265diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
63266index b7babf0..04ad282 100644
63267--- a/include/asm-generic/atomic-long.h
63268+++ b/include/asm-generic/atomic-long.h
63269@@ -22,6 +22,12 @@
63270
63271 typedef atomic64_t atomic_long_t;
63272
63273+#ifdef CONFIG_PAX_REFCOUNT
63274+typedef atomic64_unchecked_t atomic_long_unchecked_t;
63275+#else
63276+typedef atomic64_t atomic_long_unchecked_t;
63277+#endif
63278+
63279 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
63280
63281 static inline long atomic_long_read(atomic_long_t *l)
63282@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
63283 return (long)atomic64_read(v);
63284 }
63285
63286+#ifdef CONFIG_PAX_REFCOUNT
63287+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
63288+{
63289+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63290+
63291+ return (long)atomic64_read_unchecked(v);
63292+}
63293+#endif
63294+
63295 static inline void atomic_long_set(atomic_long_t *l, long i)
63296 {
63297 atomic64_t *v = (atomic64_t *)l;
63298@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
63299 atomic64_set(v, i);
63300 }
63301
63302+#ifdef CONFIG_PAX_REFCOUNT
63303+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
63304+{
63305+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63306+
63307+ atomic64_set_unchecked(v, i);
63308+}
63309+#endif
63310+
63311 static inline void atomic_long_inc(atomic_long_t *l)
63312 {
63313 atomic64_t *v = (atomic64_t *)l;
63314@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
63315 atomic64_inc(v);
63316 }
63317
63318+#ifdef CONFIG_PAX_REFCOUNT
63319+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
63320+{
63321+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63322+
63323+ atomic64_inc_unchecked(v);
63324+}
63325+#endif
63326+
63327 static inline void atomic_long_dec(atomic_long_t *l)
63328 {
63329 atomic64_t *v = (atomic64_t *)l;
63330@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
63331 atomic64_dec(v);
63332 }
63333
63334+#ifdef CONFIG_PAX_REFCOUNT
63335+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
63336+{
63337+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63338+
63339+ atomic64_dec_unchecked(v);
63340+}
63341+#endif
63342+
63343 static inline void atomic_long_add(long i, atomic_long_t *l)
63344 {
63345 atomic64_t *v = (atomic64_t *)l;
63346@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
63347 atomic64_add(i, v);
63348 }
63349
63350+#ifdef CONFIG_PAX_REFCOUNT
63351+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
63352+{
63353+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63354+
63355+ atomic64_add_unchecked(i, v);
63356+}
63357+#endif
63358+
63359 static inline void atomic_long_sub(long i, atomic_long_t *l)
63360 {
63361 atomic64_t *v = (atomic64_t *)l;
63362@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
63363 atomic64_sub(i, v);
63364 }
63365
63366+#ifdef CONFIG_PAX_REFCOUNT
63367+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
63368+{
63369+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63370+
63371+ atomic64_sub_unchecked(i, v);
63372+}
63373+#endif
63374+
63375 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
63376 {
63377 atomic64_t *v = (atomic64_t *)l;
63378@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
63379 return (long)atomic64_add_return(i, v);
63380 }
63381
63382+#ifdef CONFIG_PAX_REFCOUNT
63383+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
63384+{
63385+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63386+
63387+ return (long)atomic64_add_return_unchecked(i, v);
63388+}
63389+#endif
63390+
63391 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
63392 {
63393 atomic64_t *v = (atomic64_t *)l;
63394@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
63395 return (long)atomic64_inc_return(v);
63396 }
63397
63398+#ifdef CONFIG_PAX_REFCOUNT
63399+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
63400+{
63401+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63402+
63403+ return (long)atomic64_inc_return_unchecked(v);
63404+}
63405+#endif
63406+
63407 static inline long atomic_long_dec_return(atomic_long_t *l)
63408 {
63409 atomic64_t *v = (atomic64_t *)l;
63410@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
63411
63412 typedef atomic_t atomic_long_t;
63413
63414+#ifdef CONFIG_PAX_REFCOUNT
63415+typedef atomic_unchecked_t atomic_long_unchecked_t;
63416+#else
63417+typedef atomic_t atomic_long_unchecked_t;
63418+#endif
63419+
63420 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
63421 static inline long atomic_long_read(atomic_long_t *l)
63422 {
63423@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
63424 return (long)atomic_read(v);
63425 }
63426
63427+#ifdef CONFIG_PAX_REFCOUNT
63428+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
63429+{
63430+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63431+
63432+ return (long)atomic_read_unchecked(v);
63433+}
63434+#endif
63435+
63436 static inline void atomic_long_set(atomic_long_t *l, long i)
63437 {
63438 atomic_t *v = (atomic_t *)l;
63439@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
63440 atomic_set(v, i);
63441 }
63442
63443+#ifdef CONFIG_PAX_REFCOUNT
63444+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
63445+{
63446+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63447+
63448+ atomic_set_unchecked(v, i);
63449+}
63450+#endif
63451+
63452 static inline void atomic_long_inc(atomic_long_t *l)
63453 {
63454 atomic_t *v = (atomic_t *)l;
63455@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
63456 atomic_inc(v);
63457 }
63458
63459+#ifdef CONFIG_PAX_REFCOUNT
63460+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
63461+{
63462+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63463+
63464+ atomic_inc_unchecked(v);
63465+}
63466+#endif
63467+
63468 static inline void atomic_long_dec(atomic_long_t *l)
63469 {
63470 atomic_t *v = (atomic_t *)l;
63471@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
63472 atomic_dec(v);
63473 }
63474
63475+#ifdef CONFIG_PAX_REFCOUNT
63476+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
63477+{
63478+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63479+
63480+ atomic_dec_unchecked(v);
63481+}
63482+#endif
63483+
63484 static inline void atomic_long_add(long i, atomic_long_t *l)
63485 {
63486 atomic_t *v = (atomic_t *)l;
63487@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
63488 atomic_add(i, v);
63489 }
63490
63491+#ifdef CONFIG_PAX_REFCOUNT
63492+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
63493+{
63494+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63495+
63496+ atomic_add_unchecked(i, v);
63497+}
63498+#endif
63499+
63500 static inline void atomic_long_sub(long i, atomic_long_t *l)
63501 {
63502 atomic_t *v = (atomic_t *)l;
63503@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
63504 atomic_sub(i, v);
63505 }
63506
63507+#ifdef CONFIG_PAX_REFCOUNT
63508+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
63509+{
63510+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63511+
63512+ atomic_sub_unchecked(i, v);
63513+}
63514+#endif
63515+
63516 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
63517 {
63518 atomic_t *v = (atomic_t *)l;
63519@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
63520 return (long)atomic_add_return(i, v);
63521 }
63522
63523+#ifdef CONFIG_PAX_REFCOUNT
63524+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
63525+{
63526+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63527+
63528+ return (long)atomic_add_return_unchecked(i, v);
63529+}
63530+
63531+#endif
63532+
63533 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
63534 {
63535 atomic_t *v = (atomic_t *)l;
63536@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
63537 return (long)atomic_inc_return(v);
63538 }
63539
63540+#ifdef CONFIG_PAX_REFCOUNT
63541+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
63542+{
63543+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63544+
63545+ return (long)atomic_inc_return_unchecked(v);
63546+}
63547+#endif
63548+
63549 static inline long atomic_long_dec_return(atomic_long_t *l)
63550 {
63551 atomic_t *v = (atomic_t *)l;
63552@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
63553
63554 #endif /* BITS_PER_LONG == 64 */
63555
63556+#ifdef CONFIG_PAX_REFCOUNT
63557+static inline void pax_refcount_needs_these_functions(void)
63558+{
63559+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
63560+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
63561+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
63562+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
63563+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
63564+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
63565+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
63566+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
63567+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
63568+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
63569+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
63570+#ifdef CONFIG_X86
63571+ atomic_clear_mask_unchecked(0, NULL);
63572+ atomic_set_mask_unchecked(0, NULL);
63573+#endif
63574+
63575+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
63576+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
63577+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
63578+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
63579+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
63580+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
63581+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
63582+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
63583+}
63584+#else
63585+#define atomic_read_unchecked(v) atomic_read(v)
63586+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
63587+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
63588+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
63589+#define atomic_inc_unchecked(v) atomic_inc(v)
63590+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
63591+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
63592+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
63593+#define atomic_dec_unchecked(v) atomic_dec(v)
63594+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
63595+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
63596+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
63597+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
63598+
63599+#define atomic_long_read_unchecked(v) atomic_long_read(v)
63600+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
63601+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
63602+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
63603+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
63604+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
63605+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
63606+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
63607+#endif
63608+
63609 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
63610diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
63611index 1ced641..c896ee8 100644
63612--- a/include/asm-generic/atomic.h
63613+++ b/include/asm-generic/atomic.h
63614@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
63615 * Atomically clears the bits set in @mask from @v
63616 */
63617 #ifndef atomic_clear_mask
63618-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
63619+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
63620 {
63621 unsigned long flags;
63622
63623diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
63624index b18ce4f..2ee2843 100644
63625--- a/include/asm-generic/atomic64.h
63626+++ b/include/asm-generic/atomic64.h
63627@@ -16,6 +16,8 @@ typedef struct {
63628 long long counter;
63629 } atomic64_t;
63630
63631+typedef atomic64_t atomic64_unchecked_t;
63632+
63633 #define ATOMIC64_INIT(i) { (i) }
63634
63635 extern long long atomic64_read(const atomic64_t *v);
63636@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
63637 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
63638 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
63639
63640+#define atomic64_read_unchecked(v) atomic64_read(v)
63641+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
63642+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
63643+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
63644+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
63645+#define atomic64_inc_unchecked(v) atomic64_inc(v)
63646+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
63647+#define atomic64_dec_unchecked(v) atomic64_dec(v)
63648+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
63649+
63650 #endif /* _ASM_GENERIC_ATOMIC64_H */
63651diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
63652index 1bfcfe5..e04c5c9 100644
63653--- a/include/asm-generic/cache.h
63654+++ b/include/asm-generic/cache.h
63655@@ -6,7 +6,7 @@
63656 * cache lines need to provide their own cache.h.
63657 */
63658
63659-#define L1_CACHE_SHIFT 5
63660-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
63661+#define L1_CACHE_SHIFT 5UL
63662+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
63663
63664 #endif /* __ASM_GENERIC_CACHE_H */
63665diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
63666index 0d68a1e..b74a761 100644
63667--- a/include/asm-generic/emergency-restart.h
63668+++ b/include/asm-generic/emergency-restart.h
63669@@ -1,7 +1,7 @@
63670 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
63671 #define _ASM_GENERIC_EMERGENCY_RESTART_H
63672
63673-static inline void machine_emergency_restart(void)
63674+static inline __noreturn void machine_emergency_restart(void)
63675 {
63676 machine_restart(NULL);
63677 }
63678diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
63679index 90f99c7..00ce236 100644
63680--- a/include/asm-generic/kmap_types.h
63681+++ b/include/asm-generic/kmap_types.h
63682@@ -2,9 +2,9 @@
63683 #define _ASM_GENERIC_KMAP_TYPES_H
63684
63685 #ifdef __WITH_KM_FENCE
63686-# define KM_TYPE_NR 41
63687+# define KM_TYPE_NR 42
63688 #else
63689-# define KM_TYPE_NR 20
63690+# define KM_TYPE_NR 21
63691 #endif
63692
63693 #endif
63694diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
63695index 9ceb03b..62b0b8f 100644
63696--- a/include/asm-generic/local.h
63697+++ b/include/asm-generic/local.h
63698@@ -23,24 +23,37 @@ typedef struct
63699 atomic_long_t a;
63700 } local_t;
63701
63702+typedef struct {
63703+ atomic_long_unchecked_t a;
63704+} local_unchecked_t;
63705+
63706 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
63707
63708 #define local_read(l) atomic_long_read(&(l)->a)
63709+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
63710 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
63711+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
63712 #define local_inc(l) atomic_long_inc(&(l)->a)
63713+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
63714 #define local_dec(l) atomic_long_dec(&(l)->a)
63715+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
63716 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
63717+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
63718 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
63719+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
63720
63721 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
63722 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
63723 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
63724 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
63725 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
63726+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
63727 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
63728 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
63729+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
63730
63731 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
63732+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
63733 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
63734 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
63735 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
63736diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
63737index 725612b..9cc513a 100644
63738--- a/include/asm-generic/pgtable-nopmd.h
63739+++ b/include/asm-generic/pgtable-nopmd.h
63740@@ -1,14 +1,19 @@
63741 #ifndef _PGTABLE_NOPMD_H
63742 #define _PGTABLE_NOPMD_H
63743
63744-#ifndef __ASSEMBLY__
63745-
63746 #include <asm-generic/pgtable-nopud.h>
63747
63748-struct mm_struct;
63749-
63750 #define __PAGETABLE_PMD_FOLDED
63751
63752+#define PMD_SHIFT PUD_SHIFT
63753+#define PTRS_PER_PMD 1
63754+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
63755+#define PMD_MASK (~(PMD_SIZE-1))
63756+
63757+#ifndef __ASSEMBLY__
63758+
63759+struct mm_struct;
63760+
63761 /*
63762 * Having the pmd type consist of a pud gets the size right, and allows
63763 * us to conceptually access the pud entry that this pmd is folded into
63764@@ -16,11 +21,6 @@ struct mm_struct;
63765 */
63766 typedef struct { pud_t pud; } pmd_t;
63767
63768-#define PMD_SHIFT PUD_SHIFT
63769-#define PTRS_PER_PMD 1
63770-#define PMD_SIZE (1UL << PMD_SHIFT)
63771-#define PMD_MASK (~(PMD_SIZE-1))
63772-
63773 /*
63774 * The "pud_xxx()" functions here are trivial for a folded two-level
63775 * setup: the pmd is never bad, and a pmd always exists (as it's folded
63776diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
63777index 810431d..0ec4804f 100644
63778--- a/include/asm-generic/pgtable-nopud.h
63779+++ b/include/asm-generic/pgtable-nopud.h
63780@@ -1,10 +1,15 @@
63781 #ifndef _PGTABLE_NOPUD_H
63782 #define _PGTABLE_NOPUD_H
63783
63784-#ifndef __ASSEMBLY__
63785-
63786 #define __PAGETABLE_PUD_FOLDED
63787
63788+#define PUD_SHIFT PGDIR_SHIFT
63789+#define PTRS_PER_PUD 1
63790+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
63791+#define PUD_MASK (~(PUD_SIZE-1))
63792+
63793+#ifndef __ASSEMBLY__
63794+
63795 /*
63796 * Having the pud type consist of a pgd gets the size right, and allows
63797 * us to conceptually access the pgd entry that this pud is folded into
63798@@ -12,11 +17,6 @@
63799 */
63800 typedef struct { pgd_t pgd; } pud_t;
63801
63802-#define PUD_SHIFT PGDIR_SHIFT
63803-#define PTRS_PER_PUD 1
63804-#define PUD_SIZE (1UL << PUD_SHIFT)
63805-#define PUD_MASK (~(PUD_SIZE-1))
63806-
63807 /*
63808 * The "pgd_xxx()" functions here are trivial for a folded two-level
63809 * setup: the pud is never bad, and a pud always exists (as it's folded
63810@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
63811 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
63812
63813 #define pgd_populate(mm, pgd, pud) do { } while (0)
63814+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
63815 /*
63816 * (puds are folded into pgds so this doesn't get actually called,
63817 * but the define is needed for a generic inline function.)
63818diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
63819index 5cf680a..4b74d62 100644
63820--- a/include/asm-generic/pgtable.h
63821+++ b/include/asm-generic/pgtable.h
63822@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
63823 }
63824 #endif /* CONFIG_NUMA_BALANCING */
63825
63826+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
63827+static inline unsigned long pax_open_kernel(void) { return 0; }
63828+#endif
63829+
63830+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
63831+static inline unsigned long pax_close_kernel(void) { return 0; }
63832+#endif
63833+
63834 #endif /* CONFIG_MMU */
63835
63836 #endif /* !__ASSEMBLY__ */
63837diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
63838index d1ea7ce..b1ebf2a 100644
63839--- a/include/asm-generic/vmlinux.lds.h
63840+++ b/include/asm-generic/vmlinux.lds.h
63841@@ -218,6 +218,7 @@
63842 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
63843 VMLINUX_SYMBOL(__start_rodata) = .; \
63844 *(.rodata) *(.rodata.*) \
63845+ *(.data..read_only) \
63846 *(__vermagic) /* Kernel version magic */ \
63847 . = ALIGN(8); \
63848 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
63849@@ -725,17 +726,18 @@
63850 * section in the linker script will go there too. @phdr should have
63851 * a leading colon.
63852 *
63853- * Note that this macros defines __per_cpu_load as an absolute symbol.
63854+ * Note that this macros defines per_cpu_load as an absolute symbol.
63855 * If there is no need to put the percpu section at a predetermined
63856 * address, use PERCPU_SECTION.
63857 */
63858 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
63859- VMLINUX_SYMBOL(__per_cpu_load) = .; \
63860- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
63861+ per_cpu_load = .; \
63862+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
63863 - LOAD_OFFSET) { \
63864+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
63865 PERCPU_INPUT(cacheline) \
63866 } phdr \
63867- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
63868+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
63869
63870 /**
63871 * PERCPU_SECTION - define output section for percpu area, simple version
63872diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
63873index 418d270..bfd2794 100644
63874--- a/include/crypto/algapi.h
63875+++ b/include/crypto/algapi.h
63876@@ -34,7 +34,7 @@ struct crypto_type {
63877 unsigned int maskclear;
63878 unsigned int maskset;
63879 unsigned int tfmsize;
63880-};
63881+} __do_const;
63882
63883 struct crypto_instance {
63884 struct crypto_alg alg;
63885diff --git a/include/drm/drmP.h b/include/drm/drmP.h
63886index fad21c9..3fff955 100644
63887--- a/include/drm/drmP.h
63888+++ b/include/drm/drmP.h
63889@@ -72,6 +72,7 @@
63890 #include <linux/workqueue.h>
63891 #include <linux/poll.h>
63892 #include <asm/pgalloc.h>
63893+#include <asm/local.h>
63894 #include <drm/drm.h>
63895 #include <drm/drm_sarea.h>
63896
63897@@ -1068,7 +1069,7 @@ struct drm_device {
63898
63899 /** \name Usage Counters */
63900 /*@{ */
63901- int open_count; /**< Outstanding files open */
63902+ local_t open_count; /**< Outstanding files open */
63903 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
63904 atomic_t vma_count; /**< Outstanding vma areas open */
63905 int buf_use; /**< Buffers in use -- cannot alloc */
63906@@ -1079,7 +1080,7 @@ struct drm_device {
63907 /*@{ */
63908 unsigned long counters;
63909 enum drm_stat_type types[15];
63910- atomic_t counts[15];
63911+ atomic_unchecked_t counts[15];
63912 /*@} */
63913
63914 struct list_head filelist;
63915diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
63916index f43d556..94d9343 100644
63917--- a/include/drm/drm_crtc_helper.h
63918+++ b/include/drm/drm_crtc_helper.h
63919@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
63920 struct drm_connector *connector);
63921 /* disable encoder when not in use - more explicit than dpms off */
63922 void (*disable)(struct drm_encoder *encoder);
63923-};
63924+} __no_const;
63925
63926 /**
63927 * drm_connector_helper_funcs - helper operations for connectors
63928diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
63929index 72dcbe8..8db58d7 100644
63930--- a/include/drm/ttm/ttm_memory.h
63931+++ b/include/drm/ttm/ttm_memory.h
63932@@ -48,7 +48,7 @@
63933
63934 struct ttm_mem_shrink {
63935 int (*do_shrink) (struct ttm_mem_shrink *);
63936-};
63937+} __no_const;
63938
63939 /**
63940 * struct ttm_mem_global - Global memory accounting structure.
63941diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
63942index c1da539..4db35ec 100644
63943--- a/include/linux/atmdev.h
63944+++ b/include/linux/atmdev.h
63945@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
63946 #endif
63947
63948 struct k_atm_aal_stats {
63949-#define __HANDLE_ITEM(i) atomic_t i
63950+#define __HANDLE_ITEM(i) atomic_unchecked_t i
63951 __AAL_STAT_ITEMS
63952 #undef __HANDLE_ITEM
63953 };
63954diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
63955index 0530b98..b127a9e 100644
63956--- a/include/linux/binfmts.h
63957+++ b/include/linux/binfmts.h
63958@@ -73,6 +73,7 @@ struct linux_binfmt {
63959 int (*load_binary)(struct linux_binprm *);
63960 int (*load_shlib)(struct file *);
63961 int (*core_dump)(struct coredump_params *cprm);
63962+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
63963 unsigned long min_coredump; /* minimal dump size */
63964 };
63965
63966diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
63967index f94bc83..62b9cfe 100644
63968--- a/include/linux/blkdev.h
63969+++ b/include/linux/blkdev.h
63970@@ -1498,7 +1498,7 @@ struct block_device_operations {
63971 /* this callback is with swap_lock and sometimes page table lock held */
63972 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
63973 struct module *owner;
63974-};
63975+} __do_const;
63976
63977 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
63978 unsigned long);
63979diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
63980index 7c2e030..b72475d 100644
63981--- a/include/linux/blktrace_api.h
63982+++ b/include/linux/blktrace_api.h
63983@@ -23,7 +23,7 @@ struct blk_trace {
63984 struct dentry *dir;
63985 struct dentry *dropped_file;
63986 struct dentry *msg_file;
63987- atomic_t dropped;
63988+ atomic_unchecked_t dropped;
63989 };
63990
63991 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
63992diff --git a/include/linux/cache.h b/include/linux/cache.h
63993index 4c57065..4307975 100644
63994--- a/include/linux/cache.h
63995+++ b/include/linux/cache.h
63996@@ -16,6 +16,10 @@
63997 #define __read_mostly
63998 #endif
63999
64000+#ifndef __read_only
64001+#define __read_only __read_mostly
64002+#endif
64003+
64004 #ifndef ____cacheline_aligned
64005 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
64006 #endif
64007diff --git a/include/linux/capability.h b/include/linux/capability.h
64008index 98503b7..cc36d18 100644
64009--- a/include/linux/capability.h
64010+++ b/include/linux/capability.h
64011@@ -211,8 +211,13 @@ extern bool capable(int cap);
64012 extern bool ns_capable(struct user_namespace *ns, int cap);
64013 extern bool nsown_capable(int cap);
64014 extern bool inode_capable(const struct inode *inode, int cap);
64015+extern bool capable_nolog(int cap);
64016+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
64017+extern bool inode_capable_nolog(const struct inode *inode, int cap);
64018
64019 /* audit system wants to get cap info from files as well */
64020 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
64021
64022+extern int is_privileged_binary(const struct dentry *dentry);
64023+
64024 #endif /* !_LINUX_CAPABILITY_H */
64025diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
64026index 8609d57..86e4d79 100644
64027--- a/include/linux/cdrom.h
64028+++ b/include/linux/cdrom.h
64029@@ -87,7 +87,6 @@ struct cdrom_device_ops {
64030
64031 /* driver specifications */
64032 const int capability; /* capability flags */
64033- int n_minors; /* number of active minor devices */
64034 /* handle uniform packets for scsi type devices (scsi,atapi) */
64035 int (*generic_packet) (struct cdrom_device_info *,
64036 struct packet_command *);
64037diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
64038index 42e55de..1cd0e66 100644
64039--- a/include/linux/cleancache.h
64040+++ b/include/linux/cleancache.h
64041@@ -31,7 +31,7 @@ struct cleancache_ops {
64042 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
64043 void (*invalidate_inode)(int, struct cleancache_filekey);
64044 void (*invalidate_fs)(int);
64045-};
64046+} __no_const;
64047
64048 extern struct cleancache_ops
64049 cleancache_register_ops(struct cleancache_ops *ops);
64050diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
64051index 662fd1b..e801992 100644
64052--- a/include/linux/compiler-gcc4.h
64053+++ b/include/linux/compiler-gcc4.h
64054@@ -34,6 +34,21 @@
64055 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
64056
64057 #if __GNUC_MINOR__ >= 5
64058+
64059+#ifdef CONSTIFY_PLUGIN
64060+#define __no_const __attribute__((no_const))
64061+#define __do_const __attribute__((do_const))
64062+#endif
64063+
64064+#ifdef SIZE_OVERFLOW_PLUGIN
64065+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
64066+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
64067+#endif
64068+
64069+#ifdef LATENT_ENTROPY_PLUGIN
64070+#define __latent_entropy __attribute__((latent_entropy))
64071+#endif
64072+
64073 /*
64074 * Mark a position in code as unreachable. This can be used to
64075 * suppress control flow warnings after asm blocks that transfer
64076@@ -49,6 +64,11 @@
64077 #define __noclone __attribute__((__noclone__))
64078
64079 #endif
64080+
64081+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
64082+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
64083+#define __bos0(ptr) __bos((ptr), 0)
64084+#define __bos1(ptr) __bos((ptr), 1)
64085 #endif
64086
64087 #if __GNUC_MINOR__ >= 6
64088diff --git a/include/linux/compiler.h b/include/linux/compiler.h
64089index dd852b7..72924c0 100644
64090--- a/include/linux/compiler.h
64091+++ b/include/linux/compiler.h
64092@@ -5,11 +5,14 @@
64093
64094 #ifdef __CHECKER__
64095 # define __user __attribute__((noderef, address_space(1)))
64096+# define __force_user __force __user
64097 # define __kernel __attribute__((address_space(0)))
64098+# define __force_kernel __force __kernel
64099 # define __safe __attribute__((safe))
64100 # define __force __attribute__((force))
64101 # define __nocast __attribute__((nocast))
64102 # define __iomem __attribute__((noderef, address_space(2)))
64103+# define __force_iomem __force __iomem
64104 # define __must_hold(x) __attribute__((context(x,1,1)))
64105 # define __acquires(x) __attribute__((context(x,0,1)))
64106 # define __releases(x) __attribute__((context(x,1,0)))
64107@@ -17,20 +20,48 @@
64108 # define __release(x) __context__(x,-1)
64109 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
64110 # define __percpu __attribute__((noderef, address_space(3)))
64111+# define __force_percpu __force __percpu
64112 #ifdef CONFIG_SPARSE_RCU_POINTER
64113 # define __rcu __attribute__((noderef, address_space(4)))
64114+# define __force_rcu __force __rcu
64115 #else
64116 # define __rcu
64117+# define __force_rcu
64118 #endif
64119 extern void __chk_user_ptr(const volatile void __user *);
64120 extern void __chk_io_ptr(const volatile void __iomem *);
64121+#elif defined(CHECKER_PLUGIN)
64122+//# define __user
64123+//# define __force_user
64124+//# define __kernel
64125+//# define __force_kernel
64126+# define __safe
64127+# define __force
64128+# define __nocast
64129+# define __iomem
64130+# define __force_iomem
64131+# define __chk_user_ptr(x) (void)0
64132+# define __chk_io_ptr(x) (void)0
64133+# define __builtin_warning(x, y...) (1)
64134+# define __acquires(x)
64135+# define __releases(x)
64136+# define __acquire(x) (void)0
64137+# define __release(x) (void)0
64138+# define __cond_lock(x,c) (c)
64139+# define __percpu
64140+# define __force_percpu
64141+# define __rcu
64142+# define __force_rcu
64143 #else
64144 # define __user
64145+# define __force_user
64146 # define __kernel
64147+# define __force_kernel
64148 # define __safe
64149 # define __force
64150 # define __nocast
64151 # define __iomem
64152+# define __force_iomem
64153 # define __chk_user_ptr(x) (void)0
64154 # define __chk_io_ptr(x) (void)0
64155 # define __builtin_warning(x, y...) (1)
64156@@ -41,7 +72,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
64157 # define __release(x) (void)0
64158 # define __cond_lock(x,c) (c)
64159 # define __percpu
64160+# define __force_percpu
64161 # define __rcu
64162+# define __force_rcu
64163 #endif
64164
64165 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
64166@@ -275,6 +308,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64167 # define __attribute_const__ /* unimplemented */
64168 #endif
64169
64170+#ifndef __no_const
64171+# define __no_const
64172+#endif
64173+
64174+#ifndef __do_const
64175+# define __do_const
64176+#endif
64177+
64178+#ifndef __size_overflow
64179+# define __size_overflow(...)
64180+#endif
64181+
64182+#ifndef __intentional_overflow
64183+# define __intentional_overflow(...)
64184+#endif
64185+
64186+#ifndef __latent_entropy
64187+# define __latent_entropy
64188+#endif
64189+
64190 /*
64191 * Tell gcc if a function is cold. The compiler will assume any path
64192 * directly leading to the call is unlikely.
64193@@ -284,6 +337,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64194 #define __cold
64195 #endif
64196
64197+#ifndef __alloc_size
64198+#define __alloc_size(...)
64199+#endif
64200+
64201+#ifndef __bos
64202+#define __bos(ptr, arg)
64203+#endif
64204+
64205+#ifndef __bos0
64206+#define __bos0(ptr)
64207+#endif
64208+
64209+#ifndef __bos1
64210+#define __bos1(ptr)
64211+#endif
64212+
64213 /* Simple shorthand for a section definition */
64214 #ifndef __section
64215 # define __section(S) __attribute__ ((__section__(#S)))
64216@@ -323,6 +392,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64217 * use is to mediate communication between process-level code and irq/NMI
64218 * handlers, all running on the same CPU.
64219 */
64220-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
64221+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
64222+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
64223
64224 #endif /* __LINUX_COMPILER_H */
64225diff --git a/include/linux/cpu.h b/include/linux/cpu.h
64226index ce7a074..01ab8ac 100644
64227--- a/include/linux/cpu.h
64228+++ b/include/linux/cpu.h
64229@@ -115,7 +115,7 @@ enum {
64230 /* Need to know about CPUs going up/down? */
64231 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
64232 #define cpu_notifier(fn, pri) { \
64233- static struct notifier_block fn##_nb __cpuinitdata = \
64234+ static struct notifier_block fn##_nb = \
64235 { .notifier_call = fn, .priority = pri }; \
64236 register_cpu_notifier(&fn##_nb); \
64237 }
64238diff --git a/include/linux/cred.h b/include/linux/cred.h
64239index 04421e8..6bce4ef 100644
64240--- a/include/linux/cred.h
64241+++ b/include/linux/cred.h
64242@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
64243 static inline void validate_process_creds(void)
64244 {
64245 }
64246+static inline void validate_task_creds(struct task_struct *task)
64247+{
64248+}
64249 #endif
64250
64251 /**
64252diff --git a/include/linux/crypto.h b/include/linux/crypto.h
64253index b92eadf..b4ecdc1 100644
64254--- a/include/linux/crypto.h
64255+++ b/include/linux/crypto.h
64256@@ -373,7 +373,7 @@ struct cipher_tfm {
64257 const u8 *key, unsigned int keylen);
64258 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
64259 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
64260-};
64261+} __no_const;
64262
64263 struct hash_tfm {
64264 int (*init)(struct hash_desc *desc);
64265@@ -394,13 +394,13 @@ struct compress_tfm {
64266 int (*cot_decompress)(struct crypto_tfm *tfm,
64267 const u8 *src, unsigned int slen,
64268 u8 *dst, unsigned int *dlen);
64269-};
64270+} __no_const;
64271
64272 struct rng_tfm {
64273 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
64274 unsigned int dlen);
64275 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
64276-};
64277+} __no_const;
64278
64279 #define crt_ablkcipher crt_u.ablkcipher
64280 #define crt_aead crt_u.aead
64281diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
64282index 7925bf0..d5143d2 100644
64283--- a/include/linux/decompress/mm.h
64284+++ b/include/linux/decompress/mm.h
64285@@ -77,7 +77,7 @@ static void free(void *where)
64286 * warnings when not needed (indeed large_malloc / large_free are not
64287 * needed by inflate */
64288
64289-#define malloc(a) kmalloc(a, GFP_KERNEL)
64290+#define malloc(a) kmalloc((a), GFP_KERNEL)
64291 #define free(a) kfree(a)
64292
64293 #define large_malloc(a) vmalloc(a)
64294diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
64295index 94af418..b1ca7a2 100644
64296--- a/include/linux/dma-mapping.h
64297+++ b/include/linux/dma-mapping.h
64298@@ -54,7 +54,7 @@ struct dma_map_ops {
64299 u64 (*get_required_mask)(struct device *dev);
64300 #endif
64301 int is_phys;
64302-};
64303+} __do_const;
64304
64305 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
64306
64307diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
64308index d3201e4..8281e63 100644
64309--- a/include/linux/dmaengine.h
64310+++ b/include/linux/dmaengine.h
64311@@ -1018,9 +1018,9 @@ struct dma_pinned_list {
64312 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
64313 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
64314
64315-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
64316+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
64317 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
64318-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
64319+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
64320 struct dma_pinned_list *pinned_list, struct page *page,
64321 unsigned int offset, size_t len);
64322
64323diff --git a/include/linux/efi.h b/include/linux/efi.h
64324index 7a9498a..155713d 100644
64325--- a/include/linux/efi.h
64326+++ b/include/linux/efi.h
64327@@ -733,6 +733,7 @@ struct efivar_operations {
64328 efi_set_variable_t *set_variable;
64329 efi_query_variable_info_t *query_variable_info;
64330 };
64331+typedef struct efivar_operations __no_const efivar_operations_no_const;
64332
64333 struct efivars {
64334 /*
64335diff --git a/include/linux/elf.h b/include/linux/elf.h
64336index 8c9048e..16a4665 100644
64337--- a/include/linux/elf.h
64338+++ b/include/linux/elf.h
64339@@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
64340 #define elf_note elf32_note
64341 #define elf_addr_t Elf32_Off
64342 #define Elf_Half Elf32_Half
64343+#define elf_dyn Elf32_Dyn
64344
64345 #else
64346
64347@@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
64348 #define elf_note elf64_note
64349 #define elf_addr_t Elf64_Off
64350 #define Elf_Half Elf64_Half
64351+#define elf_dyn Elf64_Dyn
64352
64353 #endif
64354
64355diff --git a/include/linux/filter.h b/include/linux/filter.h
64356index c45eabc..baa0be5 100644
64357--- a/include/linux/filter.h
64358+++ b/include/linux/filter.h
64359@@ -20,6 +20,7 @@ struct compat_sock_fprog {
64360
64361 struct sk_buff;
64362 struct sock;
64363+struct bpf_jit_work;
64364
64365 struct sk_filter
64366 {
64367@@ -27,6 +28,9 @@ struct sk_filter
64368 unsigned int len; /* Number of filter blocks */
64369 unsigned int (*bpf_func)(const struct sk_buff *skb,
64370 const struct sock_filter *filter);
64371+#ifdef CONFIG_BPF_JIT
64372+ struct bpf_jit_work *work;
64373+#endif
64374 struct rcu_head rcu;
64375 struct sock_filter insns[0];
64376 };
64377diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
64378index 3044254..9767f41 100644
64379--- a/include/linux/frontswap.h
64380+++ b/include/linux/frontswap.h
64381@@ -11,7 +11,7 @@ struct frontswap_ops {
64382 int (*load)(unsigned, pgoff_t, struct page *);
64383 void (*invalidate_page)(unsigned, pgoff_t);
64384 void (*invalidate_area)(unsigned);
64385-};
64386+} __no_const;
64387
64388 extern bool frontswap_enabled;
64389 extern struct frontswap_ops
64390diff --git a/include/linux/fs.h b/include/linux/fs.h
64391index 7617ee0..b575199 100644
64392--- a/include/linux/fs.h
64393+++ b/include/linux/fs.h
64394@@ -1541,7 +1541,8 @@ struct file_operations {
64395 long (*fallocate)(struct file *file, int mode, loff_t offset,
64396 loff_t len);
64397 int (*show_fdinfo)(struct seq_file *m, struct file *f);
64398-};
64399+} __do_const;
64400+typedef struct file_operations __no_const file_operations_no_const;
64401
64402 struct inode_operations {
64403 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
64404@@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
64405 inode->i_flags |= S_NOSEC;
64406 }
64407
64408+static inline bool is_sidechannel_device(const struct inode *inode)
64409+{
64410+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
64411+ umode_t mode = inode->i_mode;
64412+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
64413+#else
64414+ return false;
64415+#endif
64416+}
64417+
64418 #endif /* _LINUX_FS_H */
64419diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
64420index d0ae3a8..0244b34 100644
64421--- a/include/linux/fs_struct.h
64422+++ b/include/linux/fs_struct.h
64423@@ -6,7 +6,7 @@
64424 #include <linux/seqlock.h>
64425
64426 struct fs_struct {
64427- int users;
64428+ atomic_t users;
64429 spinlock_t lock;
64430 seqcount_t seq;
64431 int umask;
64432diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
64433index 5dfa0aa..6acf322 100644
64434--- a/include/linux/fscache-cache.h
64435+++ b/include/linux/fscache-cache.h
64436@@ -112,7 +112,7 @@ struct fscache_operation {
64437 fscache_operation_release_t release;
64438 };
64439
64440-extern atomic_t fscache_op_debug_id;
64441+extern atomic_unchecked_t fscache_op_debug_id;
64442 extern void fscache_op_work_func(struct work_struct *work);
64443
64444 extern void fscache_enqueue_operation(struct fscache_operation *);
64445@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
64446 INIT_WORK(&op->work, fscache_op_work_func);
64447 atomic_set(&op->usage, 1);
64448 op->state = FSCACHE_OP_ST_INITIALISED;
64449- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
64450+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
64451 op->processor = processor;
64452 op->release = release;
64453 INIT_LIST_HEAD(&op->pend_link);
64454diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
64455index 0fbfb46..508eb0d 100644
64456--- a/include/linux/fsnotify.h
64457+++ b/include/linux/fsnotify.h
64458@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
64459 struct inode *inode = path->dentry->d_inode;
64460 __u32 mask = FS_ACCESS;
64461
64462+ if (is_sidechannel_device(inode))
64463+ return;
64464+
64465 if (S_ISDIR(inode->i_mode))
64466 mask |= FS_ISDIR;
64467
64468@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
64469 struct inode *inode = path->dentry->d_inode;
64470 __u32 mask = FS_MODIFY;
64471
64472+ if (is_sidechannel_device(inode))
64473+ return;
64474+
64475 if (S_ISDIR(inode->i_mode))
64476 mask |= FS_ISDIR;
64477
64478@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
64479 */
64480 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
64481 {
64482- return kstrdup(name, GFP_KERNEL);
64483+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
64484 }
64485
64486 /*
64487diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
64488index a3d4895..ddd2a50 100644
64489--- a/include/linux/ftrace_event.h
64490+++ b/include/linux/ftrace_event.h
64491@@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
64492 extern int trace_add_event_call(struct ftrace_event_call *call);
64493 extern void trace_remove_event_call(struct ftrace_event_call *call);
64494
64495-#define is_signed_type(type) (((type)(-1)) < 0)
64496+#define is_signed_type(type) (((type)(-1)) < (type)1)
64497
64498 int trace_set_clr_event(const char *system, const char *event, int set);
64499
64500diff --git a/include/linux/genhd.h b/include/linux/genhd.h
64501index 79b8bba..86b539e 100644
64502--- a/include/linux/genhd.h
64503+++ b/include/linux/genhd.h
64504@@ -194,7 +194,7 @@ struct gendisk {
64505 struct kobject *slave_dir;
64506
64507 struct timer_rand_state *random;
64508- atomic_t sync_io; /* RAID */
64509+ atomic_unchecked_t sync_io; /* RAID */
64510 struct disk_events *ev;
64511 #ifdef CONFIG_BLK_DEV_INTEGRITY
64512 struct blk_integrity *integrity;
64513diff --git a/include/linux/gfp.h b/include/linux/gfp.h
64514index 0f615eb..5c3832f 100644
64515--- a/include/linux/gfp.h
64516+++ b/include/linux/gfp.h
64517@@ -35,6 +35,13 @@ struct vm_area_struct;
64518 #define ___GFP_NO_KSWAPD 0x400000u
64519 #define ___GFP_OTHER_NODE 0x800000u
64520 #define ___GFP_WRITE 0x1000000u
64521+
64522+#ifdef CONFIG_PAX_USERCOPY_SLABS
64523+#define ___GFP_USERCOPY 0x2000000u
64524+#else
64525+#define ___GFP_USERCOPY 0
64526+#endif
64527+
64528 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
64529
64530 /*
64531@@ -92,6 +99,7 @@ struct vm_area_struct;
64532 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
64533 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
64534 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
64535+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
64536
64537 /*
64538 * This may seem redundant, but it's a way of annotating false positives vs.
64539@@ -99,7 +107,7 @@ struct vm_area_struct;
64540 */
64541 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
64542
64543-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
64544+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
64545 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
64546
64547 /* This equals 0, but use constants in case they ever change */
64548@@ -153,6 +161,8 @@ struct vm_area_struct;
64549 /* 4GB DMA on some platforms */
64550 #define GFP_DMA32 __GFP_DMA32
64551
64552+#define GFP_USERCOPY __GFP_USERCOPY
64553+
64554 /* Convert GFP flags to their corresponding migrate type */
64555 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
64556 {
64557diff --git a/include/linux/gracl.h b/include/linux/gracl.h
64558new file mode 100644
64559index 0000000..ebe6d72
64560--- /dev/null
64561+++ b/include/linux/gracl.h
64562@@ -0,0 +1,319 @@
64563+#ifndef GR_ACL_H
64564+#define GR_ACL_H
64565+
64566+#include <linux/grdefs.h>
64567+#include <linux/resource.h>
64568+#include <linux/capability.h>
64569+#include <linux/dcache.h>
64570+#include <asm/resource.h>
64571+
64572+/* Major status information */
64573+
64574+#define GR_VERSION "grsecurity 2.9.1"
64575+#define GRSECURITY_VERSION 0x2901
64576+
64577+enum {
64578+ GR_SHUTDOWN = 0,
64579+ GR_ENABLE = 1,
64580+ GR_SPROLE = 2,
64581+ GR_RELOAD = 3,
64582+ GR_SEGVMOD = 4,
64583+ GR_STATUS = 5,
64584+ GR_UNSPROLE = 6,
64585+ GR_PASSSET = 7,
64586+ GR_SPROLEPAM = 8,
64587+};
64588+
64589+/* Password setup definitions
64590+ * kernel/grhash.c */
64591+enum {
64592+ GR_PW_LEN = 128,
64593+ GR_SALT_LEN = 16,
64594+ GR_SHA_LEN = 32,
64595+};
64596+
64597+enum {
64598+ GR_SPROLE_LEN = 64,
64599+};
64600+
64601+enum {
64602+ GR_NO_GLOB = 0,
64603+ GR_REG_GLOB,
64604+ GR_CREATE_GLOB
64605+};
64606+
64607+#define GR_NLIMITS 32
64608+
64609+/* Begin Data Structures */
64610+
64611+struct sprole_pw {
64612+ unsigned char *rolename;
64613+ unsigned char salt[GR_SALT_LEN];
64614+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
64615+};
64616+
64617+struct name_entry {
64618+ __u32 key;
64619+ ino_t inode;
64620+ dev_t device;
64621+ char *name;
64622+ __u16 len;
64623+ __u8 deleted;
64624+ struct name_entry *prev;
64625+ struct name_entry *next;
64626+};
64627+
64628+struct inodev_entry {
64629+ struct name_entry *nentry;
64630+ struct inodev_entry *prev;
64631+ struct inodev_entry *next;
64632+};
64633+
64634+struct acl_role_db {
64635+ struct acl_role_label **r_hash;
64636+ __u32 r_size;
64637+};
64638+
64639+struct inodev_db {
64640+ struct inodev_entry **i_hash;
64641+ __u32 i_size;
64642+};
64643+
64644+struct name_db {
64645+ struct name_entry **n_hash;
64646+ __u32 n_size;
64647+};
64648+
64649+struct crash_uid {
64650+ uid_t uid;
64651+ unsigned long expires;
64652+};
64653+
64654+struct gr_hash_struct {
64655+ void **table;
64656+ void **nametable;
64657+ void *first;
64658+ __u32 table_size;
64659+ __u32 used_size;
64660+ int type;
64661+};
64662+
64663+/* Userspace Grsecurity ACL data structures */
64664+
64665+struct acl_subject_label {
64666+ char *filename;
64667+ ino_t inode;
64668+ dev_t device;
64669+ __u32 mode;
64670+ kernel_cap_t cap_mask;
64671+ kernel_cap_t cap_lower;
64672+ kernel_cap_t cap_invert_audit;
64673+
64674+ struct rlimit res[GR_NLIMITS];
64675+ __u32 resmask;
64676+
64677+ __u8 user_trans_type;
64678+ __u8 group_trans_type;
64679+ uid_t *user_transitions;
64680+ gid_t *group_transitions;
64681+ __u16 user_trans_num;
64682+ __u16 group_trans_num;
64683+
64684+ __u32 sock_families[2];
64685+ __u32 ip_proto[8];
64686+ __u32 ip_type;
64687+ struct acl_ip_label **ips;
64688+ __u32 ip_num;
64689+ __u32 inaddr_any_override;
64690+
64691+ __u32 crashes;
64692+ unsigned long expires;
64693+
64694+ struct acl_subject_label *parent_subject;
64695+ struct gr_hash_struct *hash;
64696+ struct acl_subject_label *prev;
64697+ struct acl_subject_label *next;
64698+
64699+ struct acl_object_label **obj_hash;
64700+ __u32 obj_hash_size;
64701+ __u16 pax_flags;
64702+};
64703+
64704+struct role_allowed_ip {
64705+ __u32 addr;
64706+ __u32 netmask;
64707+
64708+ struct role_allowed_ip *prev;
64709+ struct role_allowed_ip *next;
64710+};
64711+
64712+struct role_transition {
64713+ char *rolename;
64714+
64715+ struct role_transition *prev;
64716+ struct role_transition *next;
64717+};
64718+
64719+struct acl_role_label {
64720+ char *rolename;
64721+ uid_t uidgid;
64722+ __u16 roletype;
64723+
64724+ __u16 auth_attempts;
64725+ unsigned long expires;
64726+
64727+ struct acl_subject_label *root_label;
64728+ struct gr_hash_struct *hash;
64729+
64730+ struct acl_role_label *prev;
64731+ struct acl_role_label *next;
64732+
64733+ struct role_transition *transitions;
64734+ struct role_allowed_ip *allowed_ips;
64735+ uid_t *domain_children;
64736+ __u16 domain_child_num;
64737+
64738+ umode_t umask;
64739+
64740+ struct acl_subject_label **subj_hash;
64741+ __u32 subj_hash_size;
64742+};
64743+
64744+struct user_acl_role_db {
64745+ struct acl_role_label **r_table;
64746+ __u32 num_pointers; /* Number of allocations to track */
64747+ __u32 num_roles; /* Number of roles */
64748+ __u32 num_domain_children; /* Number of domain children */
64749+ __u32 num_subjects; /* Number of subjects */
64750+ __u32 num_objects; /* Number of objects */
64751+};
64752+
64753+struct acl_object_label {
64754+ char *filename;
64755+ ino_t inode;
64756+ dev_t device;
64757+ __u32 mode;
64758+
64759+ struct acl_subject_label *nested;
64760+ struct acl_object_label *globbed;
64761+
64762+ /* next two structures not used */
64763+
64764+ struct acl_object_label *prev;
64765+ struct acl_object_label *next;
64766+};
64767+
64768+struct acl_ip_label {
64769+ char *iface;
64770+ __u32 addr;
64771+ __u32 netmask;
64772+ __u16 low, high;
64773+ __u8 mode;
64774+ __u32 type;
64775+ __u32 proto[8];
64776+
64777+ /* next two structures not used */
64778+
64779+ struct acl_ip_label *prev;
64780+ struct acl_ip_label *next;
64781+};
64782+
64783+struct gr_arg {
64784+ struct user_acl_role_db role_db;
64785+ unsigned char pw[GR_PW_LEN];
64786+ unsigned char salt[GR_SALT_LEN];
64787+ unsigned char sum[GR_SHA_LEN];
64788+ unsigned char sp_role[GR_SPROLE_LEN];
64789+ struct sprole_pw *sprole_pws;
64790+ dev_t segv_device;
64791+ ino_t segv_inode;
64792+ uid_t segv_uid;
64793+ __u16 num_sprole_pws;
64794+ __u16 mode;
64795+};
64796+
64797+struct gr_arg_wrapper {
64798+ struct gr_arg *arg;
64799+ __u32 version;
64800+ __u32 size;
64801+};
64802+
64803+struct subject_map {
64804+ struct acl_subject_label *user;
64805+ struct acl_subject_label *kernel;
64806+ struct subject_map *prev;
64807+ struct subject_map *next;
64808+};
64809+
64810+struct acl_subj_map_db {
64811+ struct subject_map **s_hash;
64812+ __u32 s_size;
64813+};
64814+
64815+/* End Data Structures Section */
64816+
64817+/* Hash functions generated by empirical testing by Brad Spengler
64818+ Makes good use of the low bits of the inode. Generally 0-1 times
64819+ in loop for successful match. 0-3 for unsuccessful match.
64820+ Shift/add algorithm with modulus of table size and an XOR*/
64821+
64822+static __inline__ unsigned int
64823+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
64824+{
64825+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
64826+}
64827+
64828+ static __inline__ unsigned int
64829+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
64830+{
64831+ return ((const unsigned long)userp % sz);
64832+}
64833+
64834+static __inline__ unsigned int
64835+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
64836+{
64837+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
64838+}
64839+
64840+static __inline__ unsigned int
64841+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
64842+{
64843+ return full_name_hash((const unsigned char *)name, len) % sz;
64844+}
64845+
64846+#define FOR_EACH_ROLE_START(role) \
64847+ role = role_list; \
64848+ while (role) {
64849+
64850+#define FOR_EACH_ROLE_END(role) \
64851+ role = role->prev; \
64852+ }
64853+
64854+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
64855+ subj = NULL; \
64856+ iter = 0; \
64857+ while (iter < role->subj_hash_size) { \
64858+ if (subj == NULL) \
64859+ subj = role->subj_hash[iter]; \
64860+ if (subj == NULL) { \
64861+ iter++; \
64862+ continue; \
64863+ }
64864+
64865+#define FOR_EACH_SUBJECT_END(subj,iter) \
64866+ subj = subj->next; \
64867+ if (subj == NULL) \
64868+ iter++; \
64869+ }
64870+
64871+
64872+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
64873+ subj = role->hash->first; \
64874+ while (subj != NULL) {
64875+
64876+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
64877+ subj = subj->next; \
64878+ }
64879+
64880+#endif
64881+
64882diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
64883new file mode 100644
64884index 0000000..323ecf2
64885--- /dev/null
64886+++ b/include/linux/gralloc.h
64887@@ -0,0 +1,9 @@
64888+#ifndef __GRALLOC_H
64889+#define __GRALLOC_H
64890+
64891+void acl_free_all(void);
64892+int acl_alloc_stack_init(unsigned long size);
64893+void *acl_alloc(unsigned long len);
64894+void *acl_alloc_num(unsigned long num, unsigned long len);
64895+
64896+#endif
64897diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
64898new file mode 100644
64899index 0000000..be66033
64900--- /dev/null
64901+++ b/include/linux/grdefs.h
64902@@ -0,0 +1,140 @@
64903+#ifndef GRDEFS_H
64904+#define GRDEFS_H
64905+
64906+/* Begin grsecurity status declarations */
64907+
64908+enum {
64909+ GR_READY = 0x01,
64910+ GR_STATUS_INIT = 0x00 // disabled state
64911+};
64912+
64913+/* Begin ACL declarations */
64914+
64915+/* Role flags */
64916+
64917+enum {
64918+ GR_ROLE_USER = 0x0001,
64919+ GR_ROLE_GROUP = 0x0002,
64920+ GR_ROLE_DEFAULT = 0x0004,
64921+ GR_ROLE_SPECIAL = 0x0008,
64922+ GR_ROLE_AUTH = 0x0010,
64923+ GR_ROLE_NOPW = 0x0020,
64924+ GR_ROLE_GOD = 0x0040,
64925+ GR_ROLE_LEARN = 0x0080,
64926+ GR_ROLE_TPE = 0x0100,
64927+ GR_ROLE_DOMAIN = 0x0200,
64928+ GR_ROLE_PAM = 0x0400,
64929+ GR_ROLE_PERSIST = 0x0800
64930+};
64931+
64932+/* ACL Subject and Object mode flags */
64933+enum {
64934+ GR_DELETED = 0x80000000
64935+};
64936+
64937+/* ACL Object-only mode flags */
64938+enum {
64939+ GR_READ = 0x00000001,
64940+ GR_APPEND = 0x00000002,
64941+ GR_WRITE = 0x00000004,
64942+ GR_EXEC = 0x00000008,
64943+ GR_FIND = 0x00000010,
64944+ GR_INHERIT = 0x00000020,
64945+ GR_SETID = 0x00000040,
64946+ GR_CREATE = 0x00000080,
64947+ GR_DELETE = 0x00000100,
64948+ GR_LINK = 0x00000200,
64949+ GR_AUDIT_READ = 0x00000400,
64950+ GR_AUDIT_APPEND = 0x00000800,
64951+ GR_AUDIT_WRITE = 0x00001000,
64952+ GR_AUDIT_EXEC = 0x00002000,
64953+ GR_AUDIT_FIND = 0x00004000,
64954+ GR_AUDIT_INHERIT= 0x00008000,
64955+ GR_AUDIT_SETID = 0x00010000,
64956+ GR_AUDIT_CREATE = 0x00020000,
64957+ GR_AUDIT_DELETE = 0x00040000,
64958+ GR_AUDIT_LINK = 0x00080000,
64959+ GR_PTRACERD = 0x00100000,
64960+ GR_NOPTRACE = 0x00200000,
64961+ GR_SUPPRESS = 0x00400000,
64962+ GR_NOLEARN = 0x00800000,
64963+ GR_INIT_TRANSFER= 0x01000000
64964+};
64965+
64966+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
64967+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
64968+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
64969+
64970+/* ACL subject-only mode flags */
64971+enum {
64972+ GR_KILL = 0x00000001,
64973+ GR_VIEW = 0x00000002,
64974+ GR_PROTECTED = 0x00000004,
64975+ GR_LEARN = 0x00000008,
64976+ GR_OVERRIDE = 0x00000010,
64977+ /* just a placeholder, this mode is only used in userspace */
64978+ GR_DUMMY = 0x00000020,
64979+ GR_PROTSHM = 0x00000040,
64980+ GR_KILLPROC = 0x00000080,
64981+ GR_KILLIPPROC = 0x00000100,
64982+ /* just a placeholder, this mode is only used in userspace */
64983+ GR_NOTROJAN = 0x00000200,
64984+ GR_PROTPROCFD = 0x00000400,
64985+ GR_PROCACCT = 0x00000800,
64986+ GR_RELAXPTRACE = 0x00001000,
64987+ //GR_NESTED = 0x00002000,
64988+ GR_INHERITLEARN = 0x00004000,
64989+ GR_PROCFIND = 0x00008000,
64990+ GR_POVERRIDE = 0x00010000,
64991+ GR_KERNELAUTH = 0x00020000,
64992+ GR_ATSECURE = 0x00040000,
64993+ GR_SHMEXEC = 0x00080000
64994+};
64995+
64996+enum {
64997+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
64998+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
64999+ GR_PAX_ENABLE_MPROTECT = 0x0004,
65000+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
65001+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
65002+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
65003+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
65004+ GR_PAX_DISABLE_MPROTECT = 0x0400,
65005+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
65006+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
65007+};
65008+
65009+enum {
65010+ GR_ID_USER = 0x01,
65011+ GR_ID_GROUP = 0x02,
65012+};
65013+
65014+enum {
65015+ GR_ID_ALLOW = 0x01,
65016+ GR_ID_DENY = 0x02,
65017+};
65018+
65019+#define GR_CRASH_RES 31
65020+#define GR_UIDTABLE_MAX 500
65021+
65022+/* begin resource learning section */
65023+enum {
65024+ GR_RLIM_CPU_BUMP = 60,
65025+ GR_RLIM_FSIZE_BUMP = 50000,
65026+ GR_RLIM_DATA_BUMP = 10000,
65027+ GR_RLIM_STACK_BUMP = 1000,
65028+ GR_RLIM_CORE_BUMP = 10000,
65029+ GR_RLIM_RSS_BUMP = 500000,
65030+ GR_RLIM_NPROC_BUMP = 1,
65031+ GR_RLIM_NOFILE_BUMP = 5,
65032+ GR_RLIM_MEMLOCK_BUMP = 50000,
65033+ GR_RLIM_AS_BUMP = 500000,
65034+ GR_RLIM_LOCKS_BUMP = 2,
65035+ GR_RLIM_SIGPENDING_BUMP = 5,
65036+ GR_RLIM_MSGQUEUE_BUMP = 10000,
65037+ GR_RLIM_NICE_BUMP = 1,
65038+ GR_RLIM_RTPRIO_BUMP = 1,
65039+ GR_RLIM_RTTIME_BUMP = 1000000
65040+};
65041+
65042+#endif
65043diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
65044new file mode 100644
65045index 0000000..baa6e96
65046--- /dev/null
65047+++ b/include/linux/grinternal.h
65048@@ -0,0 +1,215 @@
65049+#ifndef __GRINTERNAL_H
65050+#define __GRINTERNAL_H
65051+
65052+#ifdef CONFIG_GRKERNSEC
65053+
65054+#include <linux/fs.h>
65055+#include <linux/mnt_namespace.h>
65056+#include <linux/nsproxy.h>
65057+#include <linux/gracl.h>
65058+#include <linux/grdefs.h>
65059+#include <linux/grmsg.h>
65060+
65061+void gr_add_learn_entry(const char *fmt, ...)
65062+ __attribute__ ((format (printf, 1, 2)));
65063+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
65064+ const struct vfsmount *mnt);
65065+__u32 gr_check_create(const struct dentry *new_dentry,
65066+ const struct dentry *parent,
65067+ const struct vfsmount *mnt, const __u32 mode);
65068+int gr_check_protected_task(const struct task_struct *task);
65069+__u32 to_gr_audit(const __u32 reqmode);
65070+int gr_set_acls(const int type);
65071+int gr_apply_subject_to_task(struct task_struct *task);
65072+int gr_acl_is_enabled(void);
65073+char gr_roletype_to_char(void);
65074+
65075+void gr_handle_alertkill(struct task_struct *task);
65076+char *gr_to_filename(const struct dentry *dentry,
65077+ const struct vfsmount *mnt);
65078+char *gr_to_filename1(const struct dentry *dentry,
65079+ const struct vfsmount *mnt);
65080+char *gr_to_filename2(const struct dentry *dentry,
65081+ const struct vfsmount *mnt);
65082+char *gr_to_filename3(const struct dentry *dentry,
65083+ const struct vfsmount *mnt);
65084+
65085+extern int grsec_enable_ptrace_readexec;
65086+extern int grsec_enable_harden_ptrace;
65087+extern int grsec_enable_link;
65088+extern int grsec_enable_fifo;
65089+extern int grsec_enable_execve;
65090+extern int grsec_enable_shm;
65091+extern int grsec_enable_execlog;
65092+extern int grsec_enable_signal;
65093+extern int grsec_enable_audit_ptrace;
65094+extern int grsec_enable_forkfail;
65095+extern int grsec_enable_time;
65096+extern int grsec_enable_rofs;
65097+extern int grsec_enable_chroot_shmat;
65098+extern int grsec_enable_chroot_mount;
65099+extern int grsec_enable_chroot_double;
65100+extern int grsec_enable_chroot_pivot;
65101+extern int grsec_enable_chroot_chdir;
65102+extern int grsec_enable_chroot_chmod;
65103+extern int grsec_enable_chroot_mknod;
65104+extern int grsec_enable_chroot_fchdir;
65105+extern int grsec_enable_chroot_nice;
65106+extern int grsec_enable_chroot_execlog;
65107+extern int grsec_enable_chroot_caps;
65108+extern int grsec_enable_chroot_sysctl;
65109+extern int grsec_enable_chroot_unix;
65110+extern int grsec_enable_symlinkown;
65111+extern int grsec_symlinkown_gid;
65112+extern int grsec_enable_tpe;
65113+extern int grsec_tpe_gid;
65114+extern int grsec_enable_tpe_all;
65115+extern int grsec_enable_tpe_invert;
65116+extern int grsec_enable_socket_all;
65117+extern int grsec_socket_all_gid;
65118+extern int grsec_enable_socket_client;
65119+extern int grsec_socket_client_gid;
65120+extern int grsec_enable_socket_server;
65121+extern int grsec_socket_server_gid;
65122+extern int grsec_audit_gid;
65123+extern int grsec_enable_group;
65124+extern int grsec_enable_audit_textrel;
65125+extern int grsec_enable_log_rwxmaps;
65126+extern int grsec_enable_mount;
65127+extern int grsec_enable_chdir;
65128+extern int grsec_resource_logging;
65129+extern int grsec_enable_blackhole;
65130+extern int grsec_lastack_retries;
65131+extern int grsec_enable_brute;
65132+extern int grsec_lock;
65133+
65134+extern spinlock_t grsec_alert_lock;
65135+extern unsigned long grsec_alert_wtime;
65136+extern unsigned long grsec_alert_fyet;
65137+
65138+extern spinlock_t grsec_audit_lock;
65139+
65140+extern rwlock_t grsec_exec_file_lock;
65141+
65142+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
65143+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
65144+ (tsk)->exec_file->f_vfsmnt) : "/")
65145+
65146+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
65147+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
65148+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
65149+
65150+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
65151+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
65152+ (tsk)->exec_file->f_vfsmnt) : "/")
65153+
65154+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
65155+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
65156+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
65157+
65158+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
65159+
65160+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
65161+
65162+#define GR_CHROOT_CAPS {{ \
65163+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
65164+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
65165+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
65166+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
65167+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
65168+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
65169+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
65170+
65171+#define security_learn(normal_msg,args...) \
65172+({ \
65173+ read_lock(&grsec_exec_file_lock); \
65174+ gr_add_learn_entry(normal_msg "\n", ## args); \
65175+ read_unlock(&grsec_exec_file_lock); \
65176+})
65177+
65178+enum {
65179+ GR_DO_AUDIT,
65180+ GR_DONT_AUDIT,
65181+ /* used for non-audit messages that we shouldn't kill the task on */
65182+ GR_DONT_AUDIT_GOOD
65183+};
65184+
65185+enum {
65186+ GR_TTYSNIFF,
65187+ GR_RBAC,
65188+ GR_RBAC_STR,
65189+ GR_STR_RBAC,
65190+ GR_RBAC_MODE2,
65191+ GR_RBAC_MODE3,
65192+ GR_FILENAME,
65193+ GR_SYSCTL_HIDDEN,
65194+ GR_NOARGS,
65195+ GR_ONE_INT,
65196+ GR_ONE_INT_TWO_STR,
65197+ GR_ONE_STR,
65198+ GR_STR_INT,
65199+ GR_TWO_STR_INT,
65200+ GR_TWO_INT,
65201+ GR_TWO_U64,
65202+ GR_THREE_INT,
65203+ GR_FIVE_INT_TWO_STR,
65204+ GR_TWO_STR,
65205+ GR_THREE_STR,
65206+ GR_FOUR_STR,
65207+ GR_STR_FILENAME,
65208+ GR_FILENAME_STR,
65209+ GR_FILENAME_TWO_INT,
65210+ GR_FILENAME_TWO_INT_STR,
65211+ GR_TEXTREL,
65212+ GR_PTRACE,
65213+ GR_RESOURCE,
65214+ GR_CAP,
65215+ GR_SIG,
65216+ GR_SIG2,
65217+ GR_CRASH1,
65218+ GR_CRASH2,
65219+ GR_PSACCT,
65220+ GR_RWXMAP
65221+};
65222+
65223+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
65224+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
65225+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
65226+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
65227+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
65228+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
65229+#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)
65230+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
65231+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
65232+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
65233+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
65234+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
65235+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
65236+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
65237+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
65238+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
65239+#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)
65240+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
65241+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
65242+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
65243+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
65244+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
65245+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
65246+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
65247+#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)
65248+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
65249+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
65250+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
65251+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
65252+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
65253+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
65254+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
65255+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
65256+#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)
65257+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
65258+
65259+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
65260+
65261+#endif
65262+
65263+#endif
65264diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
65265new file mode 100644
65266index 0000000..2bd4c8d
65267--- /dev/null
65268+++ b/include/linux/grmsg.h
65269@@ -0,0 +1,111 @@
65270+#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"
65271+#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"
65272+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
65273+#define GR_STOPMOD_MSG "denied modification of module state by "
65274+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
65275+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
65276+#define GR_IOPERM_MSG "denied use of ioperm() by "
65277+#define GR_IOPL_MSG "denied use of iopl() by "
65278+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
65279+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
65280+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
65281+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
65282+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
65283+#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"
65284+#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"
65285+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
65286+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
65287+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
65288+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
65289+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
65290+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
65291+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
65292+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
65293+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
65294+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
65295+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
65296+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
65297+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
65298+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
65299+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
65300+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
65301+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
65302+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
65303+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
65304+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
65305+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
65306+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
65307+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
65308+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
65309+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
65310+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
65311+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
65312+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
65313+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
65314+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
65315+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
65316+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
65317+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
65318+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
65319+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
65320+#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"
65321+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
65322+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
65323+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
65324+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
65325+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
65326+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
65327+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
65328+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
65329+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
65330+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
65331+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
65332+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
65333+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
65334+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
65335+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
65336+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
65337+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
65338+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
65339+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
65340+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
65341+#define GR_FAILFORK_MSG "failed fork with errno %s by "
65342+#define GR_NICE_CHROOT_MSG "denied priority change by "
65343+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
65344+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
65345+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
65346+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
65347+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
65348+#define GR_TIME_MSG "time set by "
65349+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
65350+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
65351+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
65352+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
65353+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
65354+#define GR_BIND_MSG "denied bind() by "
65355+#define GR_CONNECT_MSG "denied connect() by "
65356+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
65357+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
65358+#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"
65359+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
65360+#define GR_CAP_ACL_MSG "use of %s denied for "
65361+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
65362+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
65363+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
65364+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
65365+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
65366+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
65367+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
65368+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
65369+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
65370+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
65371+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
65372+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
65373+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
65374+#define GR_VM86_MSG "denied use of vm86 by "
65375+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
65376+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
65377+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
65378+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
65379+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
65380+#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 "
65381diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
65382new file mode 100644
65383index 0000000..c5e5913
65384--- /dev/null
65385+++ b/include/linux/grsecurity.h
65386@@ -0,0 +1,257 @@
65387+#ifndef GR_SECURITY_H
65388+#define GR_SECURITY_H
65389+#include <linux/fs.h>
65390+#include <linux/fs_struct.h>
65391+#include <linux/binfmts.h>
65392+#include <linux/gracl.h>
65393+
65394+/* notify of brain-dead configs */
65395+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65396+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
65397+#endif
65398+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
65399+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
65400+#endif
65401+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
65402+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
65403+#endif
65404+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
65405+#error "CONFIG_PAX enabled, but no PaX options are enabled."
65406+#endif
65407+
65408+#include <linux/compat.h>
65409+
65410+struct user_arg_ptr {
65411+#ifdef CONFIG_COMPAT
65412+ bool is_compat;
65413+#endif
65414+ union {
65415+ const char __user *const __user *native;
65416+#ifdef CONFIG_COMPAT
65417+ const compat_uptr_t __user *compat;
65418+#endif
65419+ } ptr;
65420+};
65421+
65422+void gr_handle_brute_attach(unsigned long mm_flags);
65423+void gr_handle_brute_check(void);
65424+void gr_handle_kernel_exploit(void);
65425+int gr_process_user_ban(void);
65426+
65427+char gr_roletype_to_char(void);
65428+
65429+int gr_acl_enable_at_secure(void);
65430+
65431+int gr_check_user_change(int real, int effective, int fs);
65432+int gr_check_group_change(int real, int effective, int fs);
65433+
65434+void gr_del_task_from_ip_table(struct task_struct *p);
65435+
65436+int gr_pid_is_chrooted(struct task_struct *p);
65437+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
65438+int gr_handle_chroot_nice(void);
65439+int gr_handle_chroot_sysctl(const int op);
65440+int gr_handle_chroot_setpriority(struct task_struct *p,
65441+ const int niceval);
65442+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
65443+int gr_handle_chroot_chroot(const struct dentry *dentry,
65444+ const struct vfsmount *mnt);
65445+void gr_handle_chroot_chdir(struct path *path);
65446+int gr_handle_chroot_chmod(const struct dentry *dentry,
65447+ const struct vfsmount *mnt, const int mode);
65448+int gr_handle_chroot_mknod(const struct dentry *dentry,
65449+ const struct vfsmount *mnt, const int mode);
65450+int gr_handle_chroot_mount(const struct dentry *dentry,
65451+ const struct vfsmount *mnt,
65452+ const char *dev_name);
65453+int gr_handle_chroot_pivot(void);
65454+int gr_handle_chroot_unix(const pid_t pid);
65455+
65456+int gr_handle_rawio(const struct inode *inode);
65457+
65458+void gr_handle_ioperm(void);
65459+void gr_handle_iopl(void);
65460+
65461+umode_t gr_acl_umask(void);
65462+
65463+int gr_tpe_allow(const struct file *file);
65464+
65465+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
65466+void gr_clear_chroot_entries(struct task_struct *task);
65467+
65468+void gr_log_forkfail(const int retval);
65469+void gr_log_timechange(void);
65470+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
65471+void gr_log_chdir(const struct dentry *dentry,
65472+ const struct vfsmount *mnt);
65473+void gr_log_chroot_exec(const struct dentry *dentry,
65474+ const struct vfsmount *mnt);
65475+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
65476+void gr_log_remount(const char *devname, const int retval);
65477+void gr_log_unmount(const char *devname, const int retval);
65478+void gr_log_mount(const char *from, const char *to, const int retval);
65479+void gr_log_textrel(struct vm_area_struct *vma);
65480+void gr_log_rwxmmap(struct file *file);
65481+void gr_log_rwxmprotect(struct file *file);
65482+
65483+int gr_handle_follow_link(const struct inode *parent,
65484+ const struct inode *inode,
65485+ const struct dentry *dentry,
65486+ const struct vfsmount *mnt);
65487+int gr_handle_fifo(const struct dentry *dentry,
65488+ const struct vfsmount *mnt,
65489+ const struct dentry *dir, const int flag,
65490+ const int acc_mode);
65491+int gr_handle_hardlink(const struct dentry *dentry,
65492+ const struct vfsmount *mnt,
65493+ struct inode *inode,
65494+ const int mode, const struct filename *to);
65495+
65496+int gr_is_capable(const int cap);
65497+int gr_is_capable_nolog(const int cap);
65498+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
65499+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
65500+
65501+void gr_copy_label(struct task_struct *tsk);
65502+void gr_handle_crash(struct task_struct *task, const int sig);
65503+int gr_handle_signal(const struct task_struct *p, const int sig);
65504+int gr_check_crash_uid(const uid_t uid);
65505+int gr_check_protected_task(const struct task_struct *task);
65506+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
65507+int gr_acl_handle_mmap(const struct file *file,
65508+ const unsigned long prot);
65509+int gr_acl_handle_mprotect(const struct file *file,
65510+ const unsigned long prot);
65511+int gr_check_hidden_task(const struct task_struct *tsk);
65512+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
65513+ const struct vfsmount *mnt);
65514+__u32 gr_acl_handle_utime(const struct dentry *dentry,
65515+ const struct vfsmount *mnt);
65516+__u32 gr_acl_handle_access(const struct dentry *dentry,
65517+ const struct vfsmount *mnt, const int fmode);
65518+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
65519+ const struct vfsmount *mnt, umode_t *mode);
65520+__u32 gr_acl_handle_chown(const struct dentry *dentry,
65521+ const struct vfsmount *mnt);
65522+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
65523+ const struct vfsmount *mnt);
65524+int gr_handle_ptrace(struct task_struct *task, const long request);
65525+int gr_handle_proc_ptrace(struct task_struct *task);
65526+__u32 gr_acl_handle_execve(const struct dentry *dentry,
65527+ const struct vfsmount *mnt);
65528+int gr_check_crash_exec(const struct file *filp);
65529+int gr_acl_is_enabled(void);
65530+void gr_set_kernel_label(struct task_struct *task);
65531+void gr_set_role_label(struct task_struct *task, const uid_t uid,
65532+ const gid_t gid);
65533+int gr_set_proc_label(const struct dentry *dentry,
65534+ const struct vfsmount *mnt,
65535+ const int unsafe_flags);
65536+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
65537+ const struct vfsmount *mnt);
65538+__u32 gr_acl_handle_open(const struct dentry *dentry,
65539+ const struct vfsmount *mnt, int acc_mode);
65540+__u32 gr_acl_handle_creat(const struct dentry *dentry,
65541+ const struct dentry *p_dentry,
65542+ const struct vfsmount *p_mnt,
65543+ int open_flags, int acc_mode, const int imode);
65544+void gr_handle_create(const struct dentry *dentry,
65545+ const struct vfsmount *mnt);
65546+void gr_handle_proc_create(const struct dentry *dentry,
65547+ const struct inode *inode);
65548+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
65549+ const struct dentry *parent_dentry,
65550+ const struct vfsmount *parent_mnt,
65551+ const int mode);
65552+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
65553+ const struct dentry *parent_dentry,
65554+ const struct vfsmount *parent_mnt);
65555+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
65556+ const struct vfsmount *mnt);
65557+void gr_handle_delete(const ino_t ino, const dev_t dev);
65558+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
65559+ const struct vfsmount *mnt);
65560+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
65561+ const struct dentry *parent_dentry,
65562+ const struct vfsmount *parent_mnt,
65563+ const struct filename *from);
65564+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
65565+ const struct dentry *parent_dentry,
65566+ const struct vfsmount *parent_mnt,
65567+ const struct dentry *old_dentry,
65568+ const struct vfsmount *old_mnt, const struct filename *to);
65569+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
65570+int gr_acl_handle_rename(struct dentry *new_dentry,
65571+ struct dentry *parent_dentry,
65572+ const struct vfsmount *parent_mnt,
65573+ struct dentry *old_dentry,
65574+ struct inode *old_parent_inode,
65575+ struct vfsmount *old_mnt, const struct filename *newname);
65576+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65577+ struct dentry *old_dentry,
65578+ struct dentry *new_dentry,
65579+ struct vfsmount *mnt, const __u8 replace);
65580+__u32 gr_check_link(const struct dentry *new_dentry,
65581+ const struct dentry *parent_dentry,
65582+ const struct vfsmount *parent_mnt,
65583+ const struct dentry *old_dentry,
65584+ const struct vfsmount *old_mnt);
65585+int gr_acl_handle_filldir(const struct file *file, const char *name,
65586+ const unsigned int namelen, const ino_t ino);
65587+
65588+__u32 gr_acl_handle_unix(const struct dentry *dentry,
65589+ const struct vfsmount *mnt);
65590+void gr_acl_handle_exit(void);
65591+void gr_acl_handle_psacct(struct task_struct *task, const long code);
65592+int gr_acl_handle_procpidmem(const struct task_struct *task);
65593+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
65594+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
65595+void gr_audit_ptrace(struct task_struct *task);
65596+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
65597+void gr_put_exec_file(struct task_struct *task);
65598+
65599+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
65600+
65601+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
65602+extern void gr_learn_resource(const struct task_struct *task, const int res,
65603+ const unsigned long wanted, const int gt);
65604+#else
65605+static inline void gr_learn_resource(const struct task_struct *task, const int res,
65606+ const unsigned long wanted, const int gt)
65607+{
65608+}
65609+#endif
65610+
65611+#ifdef CONFIG_GRKERNSEC_RESLOG
65612+extern void gr_log_resource(const struct task_struct *task, const int res,
65613+ const unsigned long wanted, const int gt);
65614+#else
65615+static inline void gr_log_resource(const struct task_struct *task, const int res,
65616+ const unsigned long wanted, const int gt)
65617+{
65618+}
65619+#endif
65620+
65621+#ifdef CONFIG_GRKERNSEC
65622+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
65623+void gr_handle_vm86(void);
65624+void gr_handle_mem_readwrite(u64 from, u64 to);
65625+
65626+void gr_log_badprocpid(const char *entry);
65627+
65628+extern int grsec_enable_dmesg;
65629+extern int grsec_disable_privio;
65630+
65631+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65632+extern int grsec_proc_gid;
65633+#endif
65634+
65635+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65636+extern int grsec_enable_chroot_findtask;
65637+#endif
65638+#ifdef CONFIG_GRKERNSEC_SETXID
65639+extern int grsec_enable_setxid;
65640+#endif
65641+#endif
65642+
65643+#endif
65644diff --git a/include/linux/grsock.h b/include/linux/grsock.h
65645new file mode 100644
65646index 0000000..e7ffaaf
65647--- /dev/null
65648+++ b/include/linux/grsock.h
65649@@ -0,0 +1,19 @@
65650+#ifndef __GRSOCK_H
65651+#define __GRSOCK_H
65652+
65653+extern void gr_attach_curr_ip(const struct sock *sk);
65654+extern int gr_handle_sock_all(const int family, const int type,
65655+ const int protocol);
65656+extern int gr_handle_sock_server(const struct sockaddr *sck);
65657+extern int gr_handle_sock_server_other(const struct sock *sck);
65658+extern int gr_handle_sock_client(const struct sockaddr *sck);
65659+extern int gr_search_connect(struct socket * sock,
65660+ struct sockaddr_in * addr);
65661+extern int gr_search_bind(struct socket * sock,
65662+ struct sockaddr_in * addr);
65663+extern int gr_search_listen(struct socket * sock);
65664+extern int gr_search_accept(struct socket * sock);
65665+extern int gr_search_socket(const int domain, const int type,
65666+ const int protocol);
65667+
65668+#endif
65669diff --git a/include/linux/highmem.h b/include/linux/highmem.h
65670index ef788b5..ac41b7b 100644
65671--- a/include/linux/highmem.h
65672+++ b/include/linux/highmem.h
65673@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
65674 kunmap_atomic(kaddr);
65675 }
65676
65677+static inline void sanitize_highpage(struct page *page)
65678+{
65679+ void *kaddr;
65680+ unsigned long flags;
65681+
65682+ local_irq_save(flags);
65683+ kaddr = kmap_atomic(page);
65684+ clear_page(kaddr);
65685+ kunmap_atomic(kaddr);
65686+ local_irq_restore(flags);
65687+}
65688+
65689 static inline void zero_user_segments(struct page *page,
65690 unsigned start1, unsigned end1,
65691 unsigned start2, unsigned end2)
65692diff --git a/include/linux/i2c.h b/include/linux/i2c.h
65693index d0c4db7..61b3577 100644
65694--- a/include/linux/i2c.h
65695+++ b/include/linux/i2c.h
65696@@ -369,6 +369,7 @@ struct i2c_algorithm {
65697 /* To determine what the adapter supports */
65698 u32 (*functionality) (struct i2c_adapter *);
65699 };
65700+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
65701
65702 /*
65703 * i2c_adapter is the structure used to identify a physical i2c bus along
65704diff --git a/include/linux/i2o.h b/include/linux/i2o.h
65705index d23c3c2..eb63c81 100644
65706--- a/include/linux/i2o.h
65707+++ b/include/linux/i2o.h
65708@@ -565,7 +565,7 @@ struct i2o_controller {
65709 struct i2o_device *exec; /* Executive */
65710 #if BITS_PER_LONG == 64
65711 spinlock_t context_list_lock; /* lock for context_list */
65712- atomic_t context_list_counter; /* needed for unique contexts */
65713+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
65714 struct list_head context_list; /* list of context id's
65715 and pointers */
65716 #endif
65717diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
65718index aff7ad8..3942bbd 100644
65719--- a/include/linux/if_pppox.h
65720+++ b/include/linux/if_pppox.h
65721@@ -76,7 +76,7 @@ struct pppox_proto {
65722 int (*ioctl)(struct socket *sock, unsigned int cmd,
65723 unsigned long arg);
65724 struct module *owner;
65725-};
65726+} __do_const;
65727
65728 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
65729 extern void unregister_pppox_proto(int proto_num);
65730diff --git a/include/linux/init.h b/include/linux/init.h
65731index 10ed4f4..8e8490d 100644
65732--- a/include/linux/init.h
65733+++ b/include/linux/init.h
65734@@ -39,9 +39,36 @@
65735 * Also note, that this data cannot be "const".
65736 */
65737
65738+#ifdef MODULE
65739+#define add_init_latent_entropy
65740+#define add_devinit_latent_entropy
65741+#define add_cpuinit_latent_entropy
65742+#define add_meminit_latent_entropy
65743+#else
65744+#define add_init_latent_entropy __latent_entropy
65745+
65746+#ifdef CONFIG_HOTPLUG
65747+#define add_devinit_latent_entropy
65748+#else
65749+#define add_devinit_latent_entropy __latent_entropy
65750+#endif
65751+
65752+#ifdef CONFIG_HOTPLUG_CPU
65753+#define add_cpuinit_latent_entropy
65754+#else
65755+#define add_cpuinit_latent_entropy __latent_entropy
65756+#endif
65757+
65758+#ifdef CONFIG_MEMORY_HOTPLUG
65759+#define add_meminit_latent_entropy
65760+#else
65761+#define add_meminit_latent_entropy __latent_entropy
65762+#endif
65763+#endif
65764+
65765 /* These are for everybody (although not all archs will actually
65766 discard it in modules) */
65767-#define __init __section(.init.text) __cold notrace
65768+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
65769 #define __initdata __section(.init.data)
65770 #define __initconst __constsection(.init.rodata)
65771 #define __exitdata __section(.exit.data)
65772@@ -94,7 +121,7 @@
65773 #define __exit __section(.exit.text) __exitused __cold notrace
65774
65775 /* Used for HOTPLUG_CPU */
65776-#define __cpuinit __section(.cpuinit.text) __cold notrace
65777+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
65778 #define __cpuinitdata __section(.cpuinit.data)
65779 #define __cpuinitconst __constsection(.cpuinit.rodata)
65780 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
65781@@ -102,7 +129,7 @@
65782 #define __cpuexitconst __constsection(.cpuexit.rodata)
65783
65784 /* Used for MEMORY_HOTPLUG */
65785-#define __meminit __section(.meminit.text) __cold notrace
65786+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
65787 #define __meminitdata __section(.meminit.data)
65788 #define __meminitconst __constsection(.meminit.rodata)
65789 #define __memexit __section(.memexit.text) __exitused __cold notrace
65790diff --git a/include/linux/init_task.h b/include/linux/init_task.h
65791index 6d087c5..401cab8 100644
65792--- a/include/linux/init_task.h
65793+++ b/include/linux/init_task.h
65794@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
65795
65796 #define INIT_TASK_COMM "swapper"
65797
65798+#ifdef CONFIG_X86
65799+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
65800+#else
65801+#define INIT_TASK_THREAD_INFO
65802+#endif
65803+
65804 /*
65805 * INIT_TASK is used to set up the first task table, touch at
65806 * your own risk!. Base=0, limit=0x1fffff (=2MB)
65807@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
65808 RCU_POINTER_INITIALIZER(cred, &init_cred), \
65809 .comm = INIT_TASK_COMM, \
65810 .thread = INIT_THREAD, \
65811+ INIT_TASK_THREAD_INFO \
65812 .fs = &init_fs, \
65813 .files = &init_files, \
65814 .signal = &init_signals, \
65815diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
65816index 5fa5afe..ac55b25 100644
65817--- a/include/linux/interrupt.h
65818+++ b/include/linux/interrupt.h
65819@@ -430,7 +430,7 @@ enum
65820 /* map softirq index to softirq name. update 'softirq_to_name' in
65821 * kernel/softirq.c when adding a new softirq.
65822 */
65823-extern char *softirq_to_name[NR_SOFTIRQS];
65824+extern const char * const softirq_to_name[NR_SOFTIRQS];
65825
65826 /* softirq mask and active fields moved to irq_cpustat_t in
65827 * asm/hardirq.h to get better cache usage. KAO
65828@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
65829
65830 struct softirq_action
65831 {
65832- void (*action)(struct softirq_action *);
65833-};
65834+ void (*action)(void);
65835+} __no_const;
65836
65837 asmlinkage void do_softirq(void);
65838 asmlinkage void __do_softirq(void);
65839-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
65840+extern void open_softirq(int nr, void (*action)(void));
65841 extern void softirq_init(void);
65842 extern void __raise_softirq_irqoff(unsigned int nr);
65843
65844diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
65845index 6883e19..06992b1 100644
65846--- a/include/linux/kallsyms.h
65847+++ b/include/linux/kallsyms.h
65848@@ -15,7 +15,8 @@
65849
65850 struct module;
65851
65852-#ifdef CONFIG_KALLSYMS
65853+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
65854+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65855 /* Lookup the address for a symbol. Returns 0 if not found. */
65856 unsigned long kallsyms_lookup_name(const char *name);
65857
65858@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
65859 /* Stupid that this does nothing, but I didn't create this mess. */
65860 #define __print_symbol(fmt, addr)
65861 #endif /*CONFIG_KALLSYMS*/
65862+#else /* when included by kallsyms.c, vsnprintf.c, or
65863+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
65864+extern void __print_symbol(const char *fmt, unsigned long address);
65865+extern int sprint_backtrace(char *buffer, unsigned long address);
65866+extern int sprint_symbol(char *buffer, unsigned long address);
65867+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
65868+const char *kallsyms_lookup(unsigned long addr,
65869+ unsigned long *symbolsize,
65870+ unsigned long *offset,
65871+ char **modname, char *namebuf);
65872+#endif
65873
65874 /* This macro allows us to keep printk typechecking */
65875 static __printf(1, 2)
65876diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
65877index 4dff0c6..1ca9b72 100644
65878--- a/include/linux/kgdb.h
65879+++ b/include/linux/kgdb.h
65880@@ -53,7 +53,7 @@ extern int kgdb_connected;
65881 extern int kgdb_io_module_registered;
65882
65883 extern atomic_t kgdb_setting_breakpoint;
65884-extern atomic_t kgdb_cpu_doing_single_step;
65885+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
65886
65887 extern struct task_struct *kgdb_usethread;
65888 extern struct task_struct *kgdb_contthread;
65889@@ -255,7 +255,7 @@ struct kgdb_arch {
65890 void (*correct_hw_break)(void);
65891
65892 void (*enable_nmi)(bool on);
65893-};
65894+} __do_const;
65895
65896 /**
65897 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
65898@@ -280,7 +280,7 @@ struct kgdb_io {
65899 void (*pre_exception) (void);
65900 void (*post_exception) (void);
65901 int is_console;
65902-};
65903+} __do_const;
65904
65905 extern struct kgdb_arch arch_kgdb_ops;
65906
65907diff --git a/include/linux/kmod.h b/include/linux/kmod.h
65908index 5398d58..5883a34 100644
65909--- a/include/linux/kmod.h
65910+++ b/include/linux/kmod.h
65911@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
65912 * usually useless though. */
65913 extern __printf(2, 3)
65914 int __request_module(bool wait, const char *name, ...);
65915+extern __printf(3, 4)
65916+int ___request_module(bool wait, char *param_name, const char *name, ...);
65917 #define request_module(mod...) __request_module(true, mod)
65918 #define request_module_nowait(mod...) __request_module(false, mod)
65919 #define try_then_request_module(x, mod...) \
65920diff --git a/include/linux/kobject.h b/include/linux/kobject.h
65921index 939b112..90b7f44 100644
65922--- a/include/linux/kobject.h
65923+++ b/include/linux/kobject.h
65924@@ -111,7 +111,7 @@ struct kobj_type {
65925 struct attribute **default_attrs;
65926 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
65927 const void *(*namespace)(struct kobject *kobj);
65928-};
65929+} __do_const;
65930
65931 struct kobj_uevent_env {
65932 char *envp[UEVENT_NUM_ENVP];
65933diff --git a/include/linux/kref.h b/include/linux/kref.h
65934index 4972e6e..de4d19b 100644
65935--- a/include/linux/kref.h
65936+++ b/include/linux/kref.h
65937@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
65938 static inline int kref_sub(struct kref *kref, unsigned int count,
65939 void (*release)(struct kref *kref))
65940 {
65941- WARN_ON(release == NULL);
65942+ BUG_ON(release == NULL);
65943
65944 if (atomic_sub_and_test((int) count, &kref->refcount)) {
65945 release(kref);
65946diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
65947index 2c497ab..afe32f5 100644
65948--- a/include/linux/kvm_host.h
65949+++ b/include/linux/kvm_host.h
65950@@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
65951 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
65952 void vcpu_put(struct kvm_vcpu *vcpu);
65953
65954-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65955+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65956 struct module *module);
65957 void kvm_exit(void);
65958
65959@@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
65960 struct kvm_guest_debug *dbg);
65961 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
65962
65963-int kvm_arch_init(void *opaque);
65964+int kvm_arch_init(const void *opaque);
65965 void kvm_arch_exit(void);
65966
65967 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
65968diff --git a/include/linux/libata.h b/include/linux/libata.h
65969index 649e5f8..ead5194 100644
65970--- a/include/linux/libata.h
65971+++ b/include/linux/libata.h
65972@@ -915,7 +915,7 @@ struct ata_port_operations {
65973 * fields must be pointers.
65974 */
65975 const struct ata_port_operations *inherits;
65976-};
65977+} __do_const;
65978
65979 struct ata_port_info {
65980 unsigned long flags;
65981diff --git a/include/linux/list.h b/include/linux/list.h
65982index cc6d2aa..71febca 100644
65983--- a/include/linux/list.h
65984+++ b/include/linux/list.h
65985@@ -112,6 +112,9 @@ extern void __list_del_entry(struct list_head *entry);
65986 extern void list_del(struct list_head *entry);
65987 #endif
65988
65989+extern void pax_list_add_tail(struct list_head *new, struct list_head *head);
65990+extern void pax_list_del(struct list_head *entry);
65991+
65992 /**
65993 * list_replace - replace old entry by new one
65994 * @old : the element to be replaced
65995diff --git a/include/linux/mm.h b/include/linux/mm.h
65996index 66e2f7c..ea88001 100644
65997--- a/include/linux/mm.h
65998+++ b/include/linux/mm.h
65999@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
66000 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
66001 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
66002 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
66003+
66004+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
66005+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
66006+#endif
66007+
66008 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
66009
66010 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
66011@@ -231,6 +236,7 @@ struct vm_operations_struct {
66012 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
66013 unsigned long size, pgoff_t pgoff);
66014 };
66015+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
66016
66017 struct mmu_gather;
66018 struct inode;
66019@@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
66020 int set_page_dirty_lock(struct page *page);
66021 int clear_page_dirty_for_io(struct page *page);
66022
66023-/* Is the vma a continuation of the stack vma above it? */
66024-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
66025-{
66026- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
66027-}
66028-
66029-static inline int stack_guard_page_start(struct vm_area_struct *vma,
66030- unsigned long addr)
66031-{
66032- return (vma->vm_flags & VM_GROWSDOWN) &&
66033- (vma->vm_start == addr) &&
66034- !vma_growsdown(vma->vm_prev, addr);
66035-}
66036-
66037-/* Is the vma a continuation of the stack vma below it? */
66038-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
66039-{
66040- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
66041-}
66042-
66043-static inline int stack_guard_page_end(struct vm_area_struct *vma,
66044- unsigned long addr)
66045-{
66046- return (vma->vm_flags & VM_GROWSUP) &&
66047- (vma->vm_end == addr) &&
66048- !vma_growsup(vma->vm_next, addr);
66049-}
66050-
66051 extern pid_t
66052 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
66053
66054@@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
66055 }
66056 #endif
66057
66058+#ifdef CONFIG_MMU
66059+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
66060+#else
66061+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
66062+{
66063+ return __pgprot(0);
66064+}
66065+#endif
66066+
66067 int vma_wants_writenotify(struct vm_area_struct *vma);
66068
66069 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
66070@@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
66071 {
66072 return 0;
66073 }
66074+
66075+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
66076+ unsigned long address)
66077+{
66078+ return 0;
66079+}
66080 #else
66081 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
66082+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
66083 #endif
66084
66085 #ifdef __PAGETABLE_PMD_FOLDED
66086@@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
66087 {
66088 return 0;
66089 }
66090+
66091+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
66092+ unsigned long address)
66093+{
66094+ return 0;
66095+}
66096 #else
66097 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
66098+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
66099 #endif
66100
66101 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
66102@@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
66103 NULL: pud_offset(pgd, address);
66104 }
66105
66106+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
66107+{
66108+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
66109+ NULL: pud_offset(pgd, address);
66110+}
66111+
66112 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
66113 {
66114 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
66115 NULL: pmd_offset(pud, address);
66116 }
66117+
66118+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
66119+{
66120+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
66121+ NULL: pmd_offset(pud, address);
66122+}
66123 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
66124
66125 #if USE_SPLIT_PTLOCKS
66126@@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
66127 unsigned long, unsigned long,
66128 unsigned long, unsigned long);
66129 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
66130+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
66131
66132 /* These take the mm semaphore themselves */
66133 extern unsigned long vm_brk(unsigned long, unsigned long);
66134@@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
66135 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
66136 struct vm_area_struct **pprev);
66137
66138+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
66139+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
66140+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
66141+
66142 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
66143 NULL if none. Assume start_addr < end_addr. */
66144 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
66145@@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
66146 return vma;
66147 }
66148
66149-#ifdef CONFIG_MMU
66150-pgprot_t vm_get_page_prot(unsigned long vm_flags);
66151-#else
66152-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
66153-{
66154- return __pgprot(0);
66155-}
66156-#endif
66157-
66158 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
66159 unsigned long change_prot_numa(struct vm_area_struct *vma,
66160 unsigned long start, unsigned long end);
66161@@ -1721,7 +1730,7 @@ extern int unpoison_memory(unsigned long pfn);
66162 extern int sysctl_memory_failure_early_kill;
66163 extern int sysctl_memory_failure_recovery;
66164 extern void shake_page(struct page *p, int access);
66165-extern atomic_long_t mce_bad_pages;
66166+extern atomic_long_unchecked_t mce_bad_pages;
66167 extern int soft_offline_page(struct page *page, int flags);
66168
66169 extern void dump_page(struct page *page);
66170@@ -1752,5 +1761,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
66171 static inline bool page_is_guard(struct page *page) { return false; }
66172 #endif /* CONFIG_DEBUG_PAGEALLOC */
66173
66174+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
66175+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
66176+#else
66177+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
66178+#endif
66179+
66180 #endif /* __KERNEL__ */
66181 #endif /* _LINUX_MM_H */
66182diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
66183index f8f5162..6276a36 100644
66184--- a/include/linux/mm_types.h
66185+++ b/include/linux/mm_types.h
66186@@ -288,6 +288,8 @@ struct vm_area_struct {
66187 #ifdef CONFIG_NUMA
66188 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
66189 #endif
66190+
66191+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
66192 };
66193
66194 struct core_thread {
66195@@ -362,7 +364,7 @@ struct mm_struct {
66196 unsigned long def_flags;
66197 unsigned long nr_ptes; /* Page table pages */
66198 unsigned long start_code, end_code, start_data, end_data;
66199- unsigned long start_brk, brk, start_stack;
66200+ unsigned long brk_gap, start_brk, brk, start_stack;
66201 unsigned long arg_start, arg_end, env_start, env_end;
66202
66203 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
66204@@ -436,6 +438,24 @@ struct mm_struct {
66205 int first_nid;
66206 #endif
66207 struct uprobes_state uprobes_state;
66208+
66209+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66210+ unsigned long pax_flags;
66211+#endif
66212+
66213+#ifdef CONFIG_PAX_DLRESOLVE
66214+ unsigned long call_dl_resolve;
66215+#endif
66216+
66217+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
66218+ unsigned long call_syscall;
66219+#endif
66220+
66221+#ifdef CONFIG_PAX_ASLR
66222+ unsigned long delta_mmap; /* randomized offset */
66223+ unsigned long delta_stack; /* randomized offset */
66224+#endif
66225+
66226 };
66227
66228 /* first nid will either be a valid NID or one of these values */
66229diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
66230index c5d5278..f0b68c8 100644
66231--- a/include/linux/mmiotrace.h
66232+++ b/include/linux/mmiotrace.h
66233@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
66234 /* Called from ioremap.c */
66235 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
66236 void __iomem *addr);
66237-extern void mmiotrace_iounmap(volatile void __iomem *addr);
66238+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
66239
66240 /* For anyone to insert markers. Remember trailing newline. */
66241 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
66242@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
66243 {
66244 }
66245
66246-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
66247+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
66248 {
66249 }
66250
66251diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
66252index 73b64a3..6562925 100644
66253--- a/include/linux/mmzone.h
66254+++ b/include/linux/mmzone.h
66255@@ -412,7 +412,7 @@ struct zone {
66256 unsigned long flags; /* zone flags, see below */
66257
66258 /* Zone statistics */
66259- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66260+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66261
66262 /*
66263 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
66264diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
66265index fed3def..7cc3f93 100644
66266--- a/include/linux/mod_devicetable.h
66267+++ b/include/linux/mod_devicetable.h
66268@@ -12,7 +12,7 @@
66269 typedef unsigned long kernel_ulong_t;
66270 #endif
66271
66272-#define PCI_ANY_ID (~0)
66273+#define PCI_ANY_ID ((__u16)~0)
66274
66275 struct pci_device_id {
66276 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
66277@@ -139,7 +139,7 @@ struct usb_device_id {
66278 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
66279 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
66280
66281-#define HID_ANY_ID (~0)
66282+#define HID_ANY_ID (~0U)
66283 #define HID_BUS_ANY 0xffff
66284 #define HID_GROUP_ANY 0x0000
66285
66286diff --git a/include/linux/module.h b/include/linux/module.h
66287index 1375ee3..d631af0 100644
66288--- a/include/linux/module.h
66289+++ b/include/linux/module.h
66290@@ -17,9 +17,11 @@
66291 #include <linux/moduleparam.h>
66292 #include <linux/tracepoint.h>
66293 #include <linux/export.h>
66294+#include <linux/fs.h>
66295
66296 #include <linux/percpu.h>
66297 #include <asm/module.h>
66298+#include <asm/pgtable.h>
66299
66300 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
66301 #define MODULE_SIG_STRING "~Module signature appended~\n"
66302@@ -281,19 +283,16 @@ struct module
66303 int (*init)(void);
66304
66305 /* If this is non-NULL, vfree after init() returns */
66306- void *module_init;
66307+ void *module_init_rx, *module_init_rw;
66308
66309 /* Here is the actual code + data, vfree'd on unload. */
66310- void *module_core;
66311+ void *module_core_rx, *module_core_rw;
66312
66313 /* Here are the sizes of the init and core sections */
66314- unsigned int init_size, core_size;
66315+ unsigned int init_size_rw, core_size_rw;
66316
66317 /* The size of the executable code in each section. */
66318- unsigned int init_text_size, core_text_size;
66319-
66320- /* Size of RO sections of the module (text+rodata) */
66321- unsigned int init_ro_size, core_ro_size;
66322+ unsigned int init_size_rx, core_size_rx;
66323
66324 /* Arch-specific module values */
66325 struct mod_arch_specific arch;
66326@@ -349,6 +348,10 @@ struct module
66327 #ifdef CONFIG_EVENT_TRACING
66328 struct ftrace_event_call **trace_events;
66329 unsigned int num_trace_events;
66330+ struct file_operations trace_id;
66331+ struct file_operations trace_enable;
66332+ struct file_operations trace_format;
66333+ struct file_operations trace_filter;
66334 #endif
66335 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
66336 unsigned int num_ftrace_callsites;
66337@@ -396,16 +399,46 @@ bool is_module_address(unsigned long addr);
66338 bool is_module_percpu_address(unsigned long addr);
66339 bool is_module_text_address(unsigned long addr);
66340
66341+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
66342+{
66343+
66344+#ifdef CONFIG_PAX_KERNEXEC
66345+ if (ktla_ktva(addr) >= (unsigned long)start &&
66346+ ktla_ktva(addr) < (unsigned long)start + size)
66347+ return 1;
66348+#endif
66349+
66350+ return ((void *)addr >= start && (void *)addr < start + size);
66351+}
66352+
66353+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
66354+{
66355+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
66356+}
66357+
66358+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
66359+{
66360+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
66361+}
66362+
66363+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
66364+{
66365+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
66366+}
66367+
66368+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
66369+{
66370+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
66371+}
66372+
66373 static inline int within_module_core(unsigned long addr, struct module *mod)
66374 {
66375- return (unsigned long)mod->module_core <= addr &&
66376- addr < (unsigned long)mod->module_core + mod->core_size;
66377+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
66378 }
66379
66380 static inline int within_module_init(unsigned long addr, struct module *mod)
66381 {
66382- return (unsigned long)mod->module_init <= addr &&
66383- addr < (unsigned long)mod->module_init + mod->init_size;
66384+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
66385 }
66386
66387 /* Search for module by name: must hold module_mutex. */
66388diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
66389index 560ca53..5ee8d73 100644
66390--- a/include/linux/moduleloader.h
66391+++ b/include/linux/moduleloader.h
66392@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
66393
66394 /* Allocator used for allocating struct module, core sections and init
66395 sections. Returns NULL on failure. */
66396-void *module_alloc(unsigned long size);
66397+void *module_alloc(unsigned long size) __size_overflow(1);
66398+
66399+#ifdef CONFIG_PAX_KERNEXEC
66400+void *module_alloc_exec(unsigned long size) __size_overflow(1);
66401+#else
66402+#define module_alloc_exec(x) module_alloc(x)
66403+#endif
66404
66405 /* Free memory returned from module_alloc. */
66406 void module_free(struct module *mod, void *module_region);
66407
66408+#ifdef CONFIG_PAX_KERNEXEC
66409+void module_free_exec(struct module *mod, void *module_region);
66410+#else
66411+#define module_free_exec(x, y) module_free((x), (y))
66412+#endif
66413+
66414 /*
66415 * Apply the given relocation to the (simplified) ELF. Return -error
66416 * or 0.
66417@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
66418 unsigned int relsec,
66419 struct module *me)
66420 {
66421+#ifdef CONFIG_MODULES
66422 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
66423+#endif
66424 return -ENOEXEC;
66425 }
66426 #endif
66427@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
66428 unsigned int relsec,
66429 struct module *me)
66430 {
66431+#ifdef CONFIG_MODULES
66432 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
66433+#endif
66434 return -ENOEXEC;
66435 }
66436 #endif
66437diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
66438index 137b419..fe663ec 100644
66439--- a/include/linux/moduleparam.h
66440+++ b/include/linux/moduleparam.h
66441@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
66442 * @len is usually just sizeof(string).
66443 */
66444 #define module_param_string(name, string, len, perm) \
66445- static const struct kparam_string __param_string_##name \
66446+ static const struct kparam_string __param_string_##name __used \
66447 = { len, string }; \
66448 __module_param_call(MODULE_PARAM_PREFIX, name, \
66449 &param_ops_string, \
66450@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
66451 */
66452 #define module_param_array_named(name, array, type, nump, perm) \
66453 param_check_##type(name, &(array)[0]); \
66454- static const struct kparam_array __param_arr_##name \
66455+ static const struct kparam_array __param_arr_##name __used \
66456 = { .max = ARRAY_SIZE(array), .num = nump, \
66457 .ops = &param_ops_##type, \
66458 .elemsize = sizeof(array[0]), .elem = array }; \
66459diff --git a/include/linux/namei.h b/include/linux/namei.h
66460index 5a5ff57..5ae5070 100644
66461--- a/include/linux/namei.h
66462+++ b/include/linux/namei.h
66463@@ -19,7 +19,7 @@ struct nameidata {
66464 unsigned seq;
66465 int last_type;
66466 unsigned depth;
66467- char *saved_names[MAX_NESTED_LINKS + 1];
66468+ const char *saved_names[MAX_NESTED_LINKS + 1];
66469 };
66470
66471 /*
66472@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
66473
66474 extern void nd_jump_link(struct nameidata *nd, struct path *path);
66475
66476-static inline void nd_set_link(struct nameidata *nd, char *path)
66477+static inline void nd_set_link(struct nameidata *nd, const char *path)
66478 {
66479 nd->saved_names[nd->depth] = path;
66480 }
66481
66482-static inline char *nd_get_link(struct nameidata *nd)
66483+static inline const char *nd_get_link(const struct nameidata *nd)
66484 {
66485 return nd->saved_names[nd->depth];
66486 }
66487diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
66488index 9ef07d0..130a5d9 100644
66489--- a/include/linux/netdevice.h
66490+++ b/include/linux/netdevice.h
66491@@ -1012,6 +1012,7 @@ struct net_device_ops {
66492 u32 pid, u32 seq,
66493 struct net_device *dev);
66494 };
66495+typedef struct net_device_ops __no_const net_device_ops_no_const;
66496
66497 /*
66498 * The DEVICE structure.
66499@@ -1078,7 +1079,7 @@ struct net_device {
66500 int iflink;
66501
66502 struct net_device_stats stats;
66503- atomic_long_t rx_dropped; /* dropped packets by core network
66504+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
66505 * Do not use this in drivers.
66506 */
66507
66508diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
66509index 7958e84..ed74d7a 100644
66510--- a/include/linux/netfilter/ipset/ip_set.h
66511+++ b/include/linux/netfilter/ipset/ip_set.h
66512@@ -98,7 +98,7 @@ struct ip_set_type_variant {
66513 /* Return true if "b" set is the same as "a"
66514 * according to the create set parameters */
66515 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
66516-};
66517+} __do_const;
66518
66519 /* The core set type structure */
66520 struct ip_set_type {
66521diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
66522index 4966dde..7d8ce06 100644
66523--- a/include/linux/netfilter/nfnetlink.h
66524+++ b/include/linux/netfilter/nfnetlink.h
66525@@ -16,7 +16,7 @@ struct nfnl_callback {
66526 const struct nlattr * const cda[]);
66527 const struct nla_policy *policy; /* netlink attribute policy */
66528 const u_int16_t attr_count; /* number of nlattr's */
66529-};
66530+} __do_const;
66531
66532 struct nfnetlink_subsystem {
66533 const char *name;
66534diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
66535new file mode 100644
66536index 0000000..33f4af8
66537--- /dev/null
66538+++ b/include/linux/netfilter/xt_gradm.h
66539@@ -0,0 +1,9 @@
66540+#ifndef _LINUX_NETFILTER_XT_GRADM_H
66541+#define _LINUX_NETFILTER_XT_GRADM_H 1
66542+
66543+struct xt_gradm_mtinfo {
66544+ __u16 flags;
66545+ __u16 invflags;
66546+};
66547+
66548+#endif
66549diff --git a/include/linux/notifier.h b/include/linux/notifier.h
66550index d65746e..62e72c2 100644
66551--- a/include/linux/notifier.h
66552+++ b/include/linux/notifier.h
66553@@ -51,7 +51,8 @@ struct notifier_block {
66554 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
66555 struct notifier_block __rcu *next;
66556 int priority;
66557-};
66558+} __do_const;
66559+typedef struct notifier_block __no_const notifier_block_no_const;
66560
66561 struct atomic_notifier_head {
66562 spinlock_t lock;
66563diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
66564index a4c5624..79d6d88 100644
66565--- a/include/linux/oprofile.h
66566+++ b/include/linux/oprofile.h
66567@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
66568 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
66569 char const * name, ulong * val);
66570
66571-/** Create a file for read-only access to an atomic_t. */
66572+/** Create a file for read-only access to an atomic_unchecked_t. */
66573 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
66574- char const * name, atomic_t * val);
66575+ char const * name, atomic_unchecked_t * val);
66576
66577 /** create a directory */
66578 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
66579diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
66580index 6bfb2faa..e5bc5e5 100644
66581--- a/include/linux/perf_event.h
66582+++ b/include/linux/perf_event.h
66583@@ -328,8 +328,8 @@ struct perf_event {
66584
66585 enum perf_event_active_state state;
66586 unsigned int attach_state;
66587- local64_t count;
66588- atomic64_t child_count;
66589+ local64_t count; /* PaX: fix it one day */
66590+ atomic64_unchecked_t child_count;
66591
66592 /*
66593 * These are the total time in nanoseconds that the event
66594@@ -380,8 +380,8 @@ struct perf_event {
66595 * These accumulate total time (in nanoseconds) that children
66596 * events have been enabled and running, respectively.
66597 */
66598- atomic64_t child_total_time_enabled;
66599- atomic64_t child_total_time_running;
66600+ atomic64_unchecked_t child_total_time_enabled;
66601+ atomic64_unchecked_t child_total_time_running;
66602
66603 /*
66604 * Protect attach/detach and child_list:
66605@@ -801,7 +801,7 @@ static inline void perf_event_task_tick(void) { }
66606 */
66607 #define perf_cpu_notifier(fn) \
66608 do { \
66609- static struct notifier_block fn##_nb __cpuinitdata = \
66610+ static struct notifier_block fn##_nb = \
66611 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
66612 unsigned long cpu = smp_processor_id(); \
66613 unsigned long flags; \
66614diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
66615index ad1a427..6419649 100644
66616--- a/include/linux/pipe_fs_i.h
66617+++ b/include/linux/pipe_fs_i.h
66618@@ -45,9 +45,9 @@ struct pipe_buffer {
66619 struct pipe_inode_info {
66620 wait_queue_head_t wait;
66621 unsigned int nrbufs, curbuf, buffers;
66622- unsigned int readers;
66623- unsigned int writers;
66624- unsigned int waiting_writers;
66625+ atomic_t readers;
66626+ atomic_t writers;
66627+ atomic_t waiting_writers;
66628 unsigned int r_counter;
66629 unsigned int w_counter;
66630 struct page *tmp_page;
66631diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
66632index 5f28cae..3d23723 100644
66633--- a/include/linux/platform_data/usb-ehci-s5p.h
66634+++ b/include/linux/platform_data/usb-ehci-s5p.h
66635@@ -14,7 +14,7 @@
66636 struct s5p_ehci_platdata {
66637 int (*phy_init)(struct platform_device *pdev, int type);
66638 int (*phy_exit)(struct platform_device *pdev, int type);
66639-};
66640+} __no_const;
66641
66642 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
66643
66644diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
66645index f271860..6b3bec5 100644
66646--- a/include/linux/pm_runtime.h
66647+++ b/include/linux/pm_runtime.h
66648@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
66649
66650 static inline void pm_runtime_mark_last_busy(struct device *dev)
66651 {
66652- ACCESS_ONCE(dev->power.last_busy) = jiffies;
66653+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
66654 }
66655
66656 #else /* !CONFIG_PM_RUNTIME */
66657diff --git a/include/linux/poison.h b/include/linux/poison.h
66658index 2110a81..13a11bb 100644
66659--- a/include/linux/poison.h
66660+++ b/include/linux/poison.h
66661@@ -19,8 +19,8 @@
66662 * under normal circumstances, used to verify that nobody uses
66663 * non-initialized list entries.
66664 */
66665-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
66666-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
66667+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
66668+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
66669
66670 /********** include/linux/timer.h **********/
66671 /*
66672diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
66673index c0f44c2..1572583 100644
66674--- a/include/linux/power/smartreflex.h
66675+++ b/include/linux/power/smartreflex.h
66676@@ -238,7 +238,7 @@ struct omap_sr_class_data {
66677 int (*notify)(struct omap_sr *sr, u32 status);
66678 u8 notify_flags;
66679 u8 class_type;
66680-};
66681+} __do_const;
66682
66683 /**
66684 * struct omap_sr_nvalue_table - Smartreflex n-target value info
66685diff --git a/include/linux/printk.h b/include/linux/printk.h
66686index 9afc01e..92c32e8 100644
66687--- a/include/linux/printk.h
66688+++ b/include/linux/printk.h
66689@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
66690 extern int printk_needs_cpu(int cpu);
66691 extern void printk_tick(void);
66692
66693+extern int kptr_restrict;
66694+
66695 #ifdef CONFIG_PRINTK
66696 asmlinkage __printf(5, 0)
66697 int vprintk_emit(int facility, int level,
66698@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
66699
66700 extern int printk_delay_msec;
66701 extern int dmesg_restrict;
66702-extern int kptr_restrict;
66703
66704 void log_buf_kexec_setup(void);
66705 void __init setup_log_buf(int early);
66706diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
66707index 32676b3..8f7a182 100644
66708--- a/include/linux/proc_fs.h
66709+++ b/include/linux/proc_fs.h
66710@@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
66711 return proc_create_data(name, mode, parent, proc_fops, NULL);
66712 }
66713
66714+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
66715+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
66716+{
66717+#ifdef CONFIG_GRKERNSEC_PROC_USER
66718+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
66719+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66720+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
66721+#else
66722+ return proc_create_data(name, mode, parent, proc_fops, NULL);
66723+#endif
66724+}
66725+
66726 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
66727 umode_t mode, struct proc_dir_entry *base,
66728 read_proc_t *read_proc, void * data)
66729diff --git a/include/linux/random.h b/include/linux/random.h
66730index d984608..d6f0042 100644
66731--- a/include/linux/random.h
66732+++ b/include/linux/random.h
66733@@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
66734 u32 prandom_u32_state(struct rnd_state *);
66735 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
66736
66737+static inline unsigned long pax_get_random_long(void)
66738+{
66739+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
66740+}
66741+
66742 /*
66743 * Handle minimum values for seeds
66744 */
66745diff --git a/include/linux/reboot.h b/include/linux/reboot.h
66746index 23b3630..e1bc12b 100644
66747--- a/include/linux/reboot.h
66748+++ b/include/linux/reboot.h
66749@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
66750 * Architecture-specific implementations of sys_reboot commands.
66751 */
66752
66753-extern void machine_restart(char *cmd);
66754-extern void machine_halt(void);
66755-extern void machine_power_off(void);
66756+extern void machine_restart(char *cmd) __noreturn;
66757+extern void machine_halt(void) __noreturn;
66758+extern void machine_power_off(void) __noreturn;
66759
66760 extern void machine_shutdown(void);
66761 struct pt_regs;
66762@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
66763 */
66764
66765 extern void kernel_restart_prepare(char *cmd);
66766-extern void kernel_restart(char *cmd);
66767-extern void kernel_halt(void);
66768-extern void kernel_power_off(void);
66769+extern void kernel_restart(char *cmd) __noreturn;
66770+extern void kernel_halt(void) __noreturn;
66771+extern void kernel_power_off(void) __noreturn;
66772
66773 extern int C_A_D; /* for sysctl */
66774 void ctrl_alt_del(void);
66775@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
66776 * Emergency restart, callable from an interrupt handler.
66777 */
66778
66779-extern void emergency_restart(void);
66780+extern void emergency_restart(void) __noreturn;
66781 #include <asm/emergency-restart.h>
66782
66783 #endif /* _LINUX_REBOOT_H */
66784diff --git a/include/linux/regset.h b/include/linux/regset.h
66785index 8e0c9fe..ac4d221 100644
66786--- a/include/linux/regset.h
66787+++ b/include/linux/regset.h
66788@@ -161,7 +161,8 @@ struct user_regset {
66789 unsigned int align;
66790 unsigned int bias;
66791 unsigned int core_note_type;
66792-};
66793+} __do_const;
66794+typedef struct user_regset __no_const user_regset_no_const;
66795
66796 /**
66797 * struct user_regset_view - available regsets
66798diff --git a/include/linux/relay.h b/include/linux/relay.h
66799index 91cacc3..b55ff74 100644
66800--- a/include/linux/relay.h
66801+++ b/include/linux/relay.h
66802@@ -160,7 +160,7 @@ struct rchan_callbacks
66803 * The callback should return 0 if successful, negative if not.
66804 */
66805 int (*remove_buf_file)(struct dentry *dentry);
66806-};
66807+} __no_const;
66808
66809 /*
66810 * CONFIG_RELAY kernel API, kernel/relay.c
66811diff --git a/include/linux/rio.h b/include/linux/rio.h
66812index a3e7842..d973ca6 100644
66813--- a/include/linux/rio.h
66814+++ b/include/linux/rio.h
66815@@ -339,7 +339,7 @@ struct rio_ops {
66816 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
66817 u64 rstart, u32 size, u32 flags);
66818 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
66819-};
66820+} __no_const;
66821
66822 #define RIO_RESOURCE_MEM 0x00000100
66823 #define RIO_RESOURCE_DOORBELL 0x00000200
66824diff --git a/include/linux/rmap.h b/include/linux/rmap.h
66825index c20635c..2f5def4 100644
66826--- a/include/linux/rmap.h
66827+++ b/include/linux/rmap.h
66828@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
66829 void anon_vma_init(void); /* create anon_vma_cachep */
66830 int anon_vma_prepare(struct vm_area_struct *);
66831 void unlink_anon_vmas(struct vm_area_struct *);
66832-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
66833-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
66834+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
66835+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
66836
66837 static inline void anon_vma_merge(struct vm_area_struct *vma,
66838 struct vm_area_struct *next)
66839diff --git a/include/linux/sched.h b/include/linux/sched.h
66840index d211247..d64a165 100644
66841--- a/include/linux/sched.h
66842+++ b/include/linux/sched.h
66843@@ -61,6 +61,7 @@ struct bio_list;
66844 struct fs_struct;
66845 struct perf_event_context;
66846 struct blk_plug;
66847+struct linux_binprm;
66848
66849 /*
66850 * List of flags we want to share for kernel threads,
66851@@ -354,10 +355,23 @@ struct user_namespace;
66852 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
66853
66854 extern int sysctl_max_map_count;
66855+extern unsigned long sysctl_heap_stack_gap;
66856
66857 #include <linux/aio.h>
66858
66859 #ifdef CONFIG_MMU
66860+
66861+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
66862+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
66863+#else
66864+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
66865+{
66866+ return 0;
66867+}
66868+#endif
66869+
66870+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
66871+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
66872 extern void arch_pick_mmap_layout(struct mm_struct *mm);
66873 extern unsigned long
66874 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
66875@@ -639,6 +653,17 @@ struct signal_struct {
66876 #ifdef CONFIG_TASKSTATS
66877 struct taskstats *stats;
66878 #endif
66879+
66880+#ifdef CONFIG_GRKERNSEC
66881+ u32 curr_ip;
66882+ u32 saved_ip;
66883+ u32 gr_saddr;
66884+ u32 gr_daddr;
66885+ u16 gr_sport;
66886+ u16 gr_dport;
66887+ u8 used_accept:1;
66888+#endif
66889+
66890 #ifdef CONFIG_AUDIT
66891 unsigned audit_tty;
66892 struct tty_audit_buf *tty_audit_buf;
66893@@ -717,6 +742,11 @@ struct user_struct {
66894 struct key *session_keyring; /* UID's default session keyring */
66895 #endif
66896
66897+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66898+ unsigned int banned;
66899+ unsigned long ban_expires;
66900+#endif
66901+
66902 /* Hash table maintenance information */
66903 struct hlist_node uidhash_node;
66904 kuid_t uid;
66905@@ -1360,8 +1390,8 @@ struct task_struct {
66906 struct list_head thread_group;
66907
66908 struct completion *vfork_done; /* for vfork() */
66909- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
66910- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66911+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
66912+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66913
66914 cputime_t utime, stime, utimescaled, stimescaled;
66915 cputime_t gtime;
66916@@ -1377,11 +1407,6 @@ struct task_struct {
66917 struct task_cputime cputime_expires;
66918 struct list_head cpu_timers[3];
66919
66920-/* process credentials */
66921- const struct cred __rcu *real_cred; /* objective and real subjective task
66922- * credentials (COW) */
66923- const struct cred __rcu *cred; /* effective (overridable) subjective task
66924- * credentials (COW) */
66925 char comm[TASK_COMM_LEN]; /* executable name excluding path
66926 - access with [gs]et_task_comm (which lock
66927 it with task_lock())
66928@@ -1398,6 +1423,10 @@ struct task_struct {
66929 #endif
66930 /* CPU-specific state of this task */
66931 struct thread_struct thread;
66932+/* thread_info moved to task_struct */
66933+#ifdef CONFIG_X86
66934+ struct thread_info tinfo;
66935+#endif
66936 /* filesystem information */
66937 struct fs_struct *fs;
66938 /* open file information */
66939@@ -1471,6 +1500,10 @@ struct task_struct {
66940 gfp_t lockdep_reclaim_gfp;
66941 #endif
66942
66943+/* process credentials */
66944+ const struct cred __rcu *real_cred; /* objective and real subjective task
66945+ * credentials (COW) */
66946+
66947 /* journalling filesystem info */
66948 void *journal_info;
66949
66950@@ -1509,6 +1542,10 @@ struct task_struct {
66951 /* cg_list protected by css_set_lock and tsk->alloc_lock */
66952 struct list_head cg_list;
66953 #endif
66954+
66955+ const struct cred __rcu *cred; /* effective (overridable) subjective task
66956+ * credentials (COW) */
66957+
66958 #ifdef CONFIG_FUTEX
66959 struct robust_list_head __user *robust_list;
66960 #ifdef CONFIG_COMPAT
66961@@ -1605,8 +1642,74 @@ struct task_struct {
66962 #ifdef CONFIG_UPROBES
66963 struct uprobe_task *utask;
66964 #endif
66965+
66966+#ifdef CONFIG_GRKERNSEC
66967+ /* grsecurity */
66968+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66969+ u64 exec_id;
66970+#endif
66971+#ifdef CONFIG_GRKERNSEC_SETXID
66972+ const struct cred *delayed_cred;
66973+#endif
66974+ struct dentry *gr_chroot_dentry;
66975+ struct acl_subject_label *acl;
66976+ struct acl_role_label *role;
66977+ struct file *exec_file;
66978+ unsigned long brute_expires;
66979+ u16 acl_role_id;
66980+ /* is this the task that authenticated to the special role */
66981+ u8 acl_sp_role;
66982+ u8 is_writable;
66983+ u8 brute;
66984+ u8 gr_is_chrooted;
66985+#endif
66986+
66987 };
66988
66989+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
66990+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
66991+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
66992+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
66993+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
66994+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
66995+
66996+#ifdef CONFIG_PAX_SOFTMODE
66997+extern int pax_softmode;
66998+#endif
66999+
67000+extern int pax_check_flags(unsigned long *);
67001+
67002+/* if tsk != current then task_lock must be held on it */
67003+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
67004+static inline unsigned long pax_get_flags(struct task_struct *tsk)
67005+{
67006+ if (likely(tsk->mm))
67007+ return tsk->mm->pax_flags;
67008+ else
67009+ return 0UL;
67010+}
67011+
67012+/* if tsk != current then task_lock must be held on it */
67013+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
67014+{
67015+ if (likely(tsk->mm)) {
67016+ tsk->mm->pax_flags = flags;
67017+ return 0;
67018+ }
67019+ return -EINVAL;
67020+}
67021+#endif
67022+
67023+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
67024+extern void pax_set_initial_flags(struct linux_binprm *bprm);
67025+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
67026+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
67027+#endif
67028+
67029+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
67030+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
67031+extern void pax_report_refcount_overflow(struct pt_regs *regs);
67032+
67033 /* Future-safe accessor for struct task_struct's cpus_allowed. */
67034 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
67035
67036@@ -2155,7 +2258,9 @@ void yield(void);
67037 extern struct exec_domain default_exec_domain;
67038
67039 union thread_union {
67040+#ifndef CONFIG_X86
67041 struct thread_info thread_info;
67042+#endif
67043 unsigned long stack[THREAD_SIZE/sizeof(long)];
67044 };
67045
67046@@ -2188,6 +2293,7 @@ extern struct pid_namespace init_pid_ns;
67047 */
67048
67049 extern struct task_struct *find_task_by_vpid(pid_t nr);
67050+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
67051 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
67052 struct pid_namespace *ns);
67053
67054@@ -2344,7 +2450,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
67055 extern void exit_itimers(struct signal_struct *);
67056 extern void flush_itimer_signals(void);
67057
67058-extern void do_group_exit(int);
67059+extern __noreturn void do_group_exit(int);
67060
67061 extern int allow_signal(int);
67062 extern int disallow_signal(int);
67063@@ -2545,9 +2651,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
67064
67065 #endif
67066
67067-static inline int object_is_on_stack(void *obj)
67068+static inline int object_starts_on_stack(void *obj)
67069 {
67070- void *stack = task_stack_page(current);
67071+ const void *stack = task_stack_page(current);
67072
67073 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
67074 }
67075diff --git a/include/linux/security.h b/include/linux/security.h
67076index eee7478..290f7ba 100644
67077--- a/include/linux/security.h
67078+++ b/include/linux/security.h
67079@@ -26,6 +26,7 @@
67080 #include <linux/capability.h>
67081 #include <linux/slab.h>
67082 #include <linux/err.h>
67083+#include <linux/grsecurity.h>
67084
67085 struct linux_binprm;
67086 struct cred;
67087diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
67088index 68a04a3..866e6a1 100644
67089--- a/include/linux/seq_file.h
67090+++ b/include/linux/seq_file.h
67091@@ -26,6 +26,9 @@ struct seq_file {
67092 struct mutex lock;
67093 const struct seq_operations *op;
67094 int poll_event;
67095+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67096+ u64 exec_id;
67097+#endif
67098 #ifdef CONFIG_USER_NS
67099 struct user_namespace *user_ns;
67100 #endif
67101@@ -38,6 +41,7 @@ struct seq_operations {
67102 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
67103 int (*show) (struct seq_file *m, void *v);
67104 };
67105+typedef struct seq_operations __no_const seq_operations_no_const;
67106
67107 #define SEQ_SKIP 1
67108
67109diff --git a/include/linux/shm.h b/include/linux/shm.h
67110index 429c199..4d42e38 100644
67111--- a/include/linux/shm.h
67112+++ b/include/linux/shm.h
67113@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
67114
67115 /* The task created the shm object. NULL if the task is dead. */
67116 struct task_struct *shm_creator;
67117+#ifdef CONFIG_GRKERNSEC
67118+ time_t shm_createtime;
67119+ pid_t shm_lapid;
67120+#endif
67121 };
67122
67123 /* shm_mode upper byte flags */
67124diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
67125index 320e976..fd52553 100644
67126--- a/include/linux/skbuff.h
67127+++ b/include/linux/skbuff.h
67128@@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
67129 extern struct sk_buff *__alloc_skb(unsigned int size,
67130 gfp_t priority, int flags, int node);
67131 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
67132-static inline struct sk_buff *alloc_skb(unsigned int size,
67133+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
67134 gfp_t priority)
67135 {
67136 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
67137@@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
67138 */
67139 static inline int skb_queue_empty(const struct sk_buff_head *list)
67140 {
67141- return list->next == (struct sk_buff *)list;
67142+ return list->next == (const struct sk_buff *)list;
67143 }
67144
67145 /**
67146@@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
67147 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
67148 const struct sk_buff *skb)
67149 {
67150- return skb->next == (struct sk_buff *)list;
67151+ return skb->next == (const struct sk_buff *)list;
67152 }
67153
67154 /**
67155@@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
67156 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
67157 const struct sk_buff *skb)
67158 {
67159- return skb->prev == (struct sk_buff *)list;
67160+ return skb->prev == (const struct sk_buff *)list;
67161 }
67162
67163 /**
67164@@ -1722,7 +1722,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
67165 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
67166 */
67167 #ifndef NET_SKB_PAD
67168-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
67169+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
67170 #endif
67171
67172 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
67173@@ -2300,7 +2300,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
67174 int noblock, int *err);
67175 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
67176 struct poll_table_struct *wait);
67177-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
67178+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
67179 int offset, struct iovec *to,
67180 int size);
67181 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
67182diff --git a/include/linux/slab.h b/include/linux/slab.h
67183index 5d168d7..720bff3 100644
67184--- a/include/linux/slab.h
67185+++ b/include/linux/slab.h
67186@@ -12,13 +12,20 @@
67187 #include <linux/gfp.h>
67188 #include <linux/types.h>
67189 #include <linux/workqueue.h>
67190-
67191+#include <linux/err.h>
67192
67193 /*
67194 * Flags to pass to kmem_cache_create().
67195 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
67196 */
67197 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
67198+
67199+#ifdef CONFIG_PAX_USERCOPY_SLABS
67200+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
67201+#else
67202+#define SLAB_USERCOPY 0x00000000UL
67203+#endif
67204+
67205 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
67206 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
67207 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
67208@@ -89,10 +96,13 @@
67209 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
67210 * Both make kfree a no-op.
67211 */
67212-#define ZERO_SIZE_PTR ((void *)16)
67213+#define ZERO_SIZE_PTR \
67214+({ \
67215+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
67216+ (void *)(-MAX_ERRNO-1L); \
67217+})
67218
67219-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
67220- (unsigned long)ZERO_SIZE_PTR)
67221+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
67222
67223 /*
67224 * Common fields provided in kmem_cache by all slab allocators
67225@@ -112,7 +122,7 @@ struct kmem_cache {
67226 unsigned int align; /* Alignment as calculated */
67227 unsigned long flags; /* Active flags on the slab */
67228 const char *name; /* Slab name for sysfs */
67229- int refcount; /* Use counter */
67230+ atomic_t refcount; /* Use counter */
67231 void (*ctor)(void *); /* Called on object slot creation */
67232 struct list_head list; /* List of all slab caches on the system */
67233 };
67234@@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
67235 void kfree(const void *);
67236 void kzfree(const void *);
67237 size_t ksize(const void *);
67238+const char *check_heap_object(const void *ptr, unsigned long n);
67239+bool is_usercopy_object(const void *ptr);
67240
67241 /*
67242 * Allocator specific definitions. These are mainly used to establish optimized
67243@@ -311,6 +323,7 @@ size_t ksize(const void *);
67244 * for general use, and so are not documented here. For a full list of
67245 * potential flags, always refer to linux/gfp.h.
67246 */
67247+
67248 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
67249 {
67250 if (size != 0 && n > SIZE_MAX / size)
67251@@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
67252 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
67253 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
67254 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
67255-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
67256+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
67257 #define kmalloc_track_caller(size, flags) \
67258 __kmalloc_track_caller(size, flags, _RET_IP_)
67259 #else
67260@@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
67261 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
67262 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
67263 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
67264-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
67265+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
67266 #define kmalloc_node_track_caller(size, flags, node) \
67267 __kmalloc_node_track_caller(size, flags, node, \
67268 _RET_IP_)
67269diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
67270index 8bb6e0e..8eb0dbe 100644
67271--- a/include/linux/slab_def.h
67272+++ b/include/linux/slab_def.h
67273@@ -52,7 +52,7 @@ struct kmem_cache {
67274 /* 4) cache creation/removal */
67275 const char *name;
67276 struct list_head list;
67277- int refcount;
67278+ atomic_t refcount;
67279 int object_size;
67280 int align;
67281
67282@@ -68,10 +68,10 @@ struct kmem_cache {
67283 unsigned long node_allocs;
67284 unsigned long node_frees;
67285 unsigned long node_overflow;
67286- atomic_t allochit;
67287- atomic_t allocmiss;
67288- atomic_t freehit;
67289- atomic_t freemiss;
67290+ atomic_unchecked_t allochit;
67291+ atomic_unchecked_t allocmiss;
67292+ atomic_unchecked_t freehit;
67293+ atomic_unchecked_t freemiss;
67294
67295 /*
67296 * If debugging is enabled, then the allocator can add additional
67297@@ -111,11 +111,16 @@ struct cache_sizes {
67298 #ifdef CONFIG_ZONE_DMA
67299 struct kmem_cache *cs_dmacachep;
67300 #endif
67301+
67302+#ifdef CONFIG_PAX_USERCOPY_SLABS
67303+ struct kmem_cache *cs_usercopycachep;
67304+#endif
67305+
67306 };
67307 extern struct cache_sizes malloc_sizes[];
67308
67309 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
67310-void *__kmalloc(size_t size, gfp_t flags);
67311+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
67312
67313 #ifdef CONFIG_TRACING
67314 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
67315@@ -152,6 +157,13 @@ found:
67316 cachep = malloc_sizes[i].cs_dmacachep;
67317 else
67318 #endif
67319+
67320+#ifdef CONFIG_PAX_USERCOPY_SLABS
67321+ if (flags & GFP_USERCOPY)
67322+ cachep = malloc_sizes[i].cs_usercopycachep;
67323+ else
67324+#endif
67325+
67326 cachep = malloc_sizes[i].cs_cachep;
67327
67328 ret = kmem_cache_alloc_trace(cachep, flags, size);
67329@@ -162,7 +174,7 @@ found:
67330 }
67331
67332 #ifdef CONFIG_NUMA
67333-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
67334+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67335 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
67336
67337 #ifdef CONFIG_TRACING
67338@@ -205,6 +217,13 @@ found:
67339 cachep = malloc_sizes[i].cs_dmacachep;
67340 else
67341 #endif
67342+
67343+#ifdef CONFIG_PAX_USERCOPY_SLABS
67344+ if (flags & GFP_USERCOPY)
67345+ cachep = malloc_sizes[i].cs_usercopycachep;
67346+ else
67347+#endif
67348+
67349 cachep = malloc_sizes[i].cs_cachep;
67350
67351 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
67352diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
67353index f28e14a..7831211 100644
67354--- a/include/linux/slob_def.h
67355+++ b/include/linux/slob_def.h
67356@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
67357 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
67358 }
67359
67360-void *__kmalloc_node(size_t size, gfp_t flags, int node);
67361+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67362
67363 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
67364 {
67365@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
67366 return __kmalloc_node(size, flags, NUMA_NO_NODE);
67367 }
67368
67369-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
67370+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
67371 {
67372 return kmalloc(size, flags);
67373 }
67374diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
67375index 9db4825..ed42fb5 100644
67376--- a/include/linux/slub_def.h
67377+++ b/include/linux/slub_def.h
67378@@ -91,7 +91,7 @@ struct kmem_cache {
67379 struct kmem_cache_order_objects max;
67380 struct kmem_cache_order_objects min;
67381 gfp_t allocflags; /* gfp flags to use on each alloc */
67382- int refcount; /* Refcount for slab cache destroy */
67383+ atomic_t refcount; /* Refcount for slab cache destroy */
67384 void (*ctor)(void *);
67385 int inuse; /* Offset to metadata */
67386 int align; /* Alignment */
67387@@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
67388 * Sorry that the following has to be that ugly but some versions of GCC
67389 * have trouble with constant propagation and loops.
67390 */
67391-static __always_inline int kmalloc_index(size_t size)
67392+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
67393 {
67394 if (!size)
67395 return 0;
67396@@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
67397 }
67398
67399 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
67400-void *__kmalloc(size_t size, gfp_t flags);
67401+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
67402
67403 static __always_inline void *
67404 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
67405@@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
67406 }
67407 #endif
67408
67409-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
67410+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
67411 {
67412 unsigned int order = get_order(size);
67413 return kmalloc_order_trace(size, flags, order);
67414@@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
67415 }
67416
67417 #ifdef CONFIG_NUMA
67418-void *__kmalloc_node(size_t size, gfp_t flags, int node);
67419+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67420 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
67421
67422 #ifdef CONFIG_TRACING
67423diff --git a/include/linux/sonet.h b/include/linux/sonet.h
67424index 680f9a3..f13aeb0 100644
67425--- a/include/linux/sonet.h
67426+++ b/include/linux/sonet.h
67427@@ -7,7 +7,7 @@
67428 #include <uapi/linux/sonet.h>
67429
67430 struct k_sonet_stats {
67431-#define __HANDLE_ITEM(i) atomic_t i
67432+#define __HANDLE_ITEM(i) atomic_unchecked_t i
67433 __SONET_ITEMS
67434 #undef __HANDLE_ITEM
67435 };
67436diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
67437index 34206b8..f019e06 100644
67438--- a/include/linux/sunrpc/clnt.h
67439+++ b/include/linux/sunrpc/clnt.h
67440@@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
67441 {
67442 switch (sap->sa_family) {
67443 case AF_INET:
67444- return ntohs(((struct sockaddr_in *)sap)->sin_port);
67445+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
67446 case AF_INET6:
67447- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
67448+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
67449 }
67450 return 0;
67451 }
67452@@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
67453 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
67454 const struct sockaddr *src)
67455 {
67456- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
67457+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
67458 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
67459
67460 dsin->sin_family = ssin->sin_family;
67461@@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
67462 if (sa->sa_family != AF_INET6)
67463 return 0;
67464
67465- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
67466+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
67467 }
67468
67469 #endif /* __KERNEL__ */
67470diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
67471index 0b8e3e6..33e0a01 100644
67472--- a/include/linux/sunrpc/svc_rdma.h
67473+++ b/include/linux/sunrpc/svc_rdma.h
67474@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
67475 extern unsigned int svcrdma_max_requests;
67476 extern unsigned int svcrdma_max_req_size;
67477
67478-extern atomic_t rdma_stat_recv;
67479-extern atomic_t rdma_stat_read;
67480-extern atomic_t rdma_stat_write;
67481-extern atomic_t rdma_stat_sq_starve;
67482-extern atomic_t rdma_stat_rq_starve;
67483-extern atomic_t rdma_stat_rq_poll;
67484-extern atomic_t rdma_stat_rq_prod;
67485-extern atomic_t rdma_stat_sq_poll;
67486-extern atomic_t rdma_stat_sq_prod;
67487+extern atomic_unchecked_t rdma_stat_recv;
67488+extern atomic_unchecked_t rdma_stat_read;
67489+extern atomic_unchecked_t rdma_stat_write;
67490+extern atomic_unchecked_t rdma_stat_sq_starve;
67491+extern atomic_unchecked_t rdma_stat_rq_starve;
67492+extern atomic_unchecked_t rdma_stat_rq_poll;
67493+extern atomic_unchecked_t rdma_stat_rq_prod;
67494+extern atomic_unchecked_t rdma_stat_sq_poll;
67495+extern atomic_unchecked_t rdma_stat_sq_prod;
67496
67497 #define RPCRDMA_VERSION 1
67498
67499diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
67500index 14a8ff2..21fe4c7 100644
67501--- a/include/linux/sysctl.h
67502+++ b/include/linux/sysctl.h
67503@@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
67504
67505 extern int proc_dostring(struct ctl_table *, int,
67506 void __user *, size_t *, loff_t *);
67507+extern int proc_dostring_modpriv(struct ctl_table *, int,
67508+ void __user *, size_t *, loff_t *);
67509 extern int proc_dointvec(struct ctl_table *, int,
67510 void __user *, size_t *, loff_t *);
67511 extern int proc_dointvec_minmax(struct ctl_table *, int,
67512diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
67513index 7faf933..eb6f5e3 100644
67514--- a/include/linux/sysrq.h
67515+++ b/include/linux/sysrq.h
67516@@ -36,7 +36,7 @@ struct sysrq_key_op {
67517 char *help_msg;
67518 char *action_msg;
67519 int enable_mask;
67520-};
67521+} __do_const;
67522
67523 #ifdef CONFIG_MAGIC_SYSRQ
67524
67525diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
67526index e7e0473..39b7b52 100644
67527--- a/include/linux/thread_info.h
67528+++ b/include/linux/thread_info.h
67529@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
67530 #error "no set_restore_sigmask() provided and default one won't work"
67531 #endif
67532
67533+extern void __check_object_size(const void *ptr, unsigned long n, bool to);
67534+static inline void check_object_size(const void *ptr, unsigned long n, bool to)
67535+{
67536+#ifndef CONFIG_PAX_USERCOPY_DEBUG
67537+ if (!__builtin_constant_p(n))
67538+#endif
67539+ __check_object_size(ptr, n, to);
67540+}
67541+
67542 #endif /* __KERNEL__ */
67543
67544 #endif /* _LINUX_THREAD_INFO_H */
67545diff --git a/include/linux/tty.h b/include/linux/tty.h
67546index 8db1b56..c16a040 100644
67547--- a/include/linux/tty.h
67548+++ b/include/linux/tty.h
67549@@ -194,7 +194,7 @@ struct tty_port {
67550 const struct tty_port_operations *ops; /* Port operations */
67551 spinlock_t lock; /* Lock protecting tty field */
67552 int blocked_open; /* Waiting to open */
67553- int count; /* Usage count */
67554+ atomic_t count; /* Usage count */
67555 wait_queue_head_t open_wait; /* Open waiters */
67556 wait_queue_head_t close_wait; /* Close waiters */
67557 wait_queue_head_t delta_msr_wait; /* Modem status change */
67558@@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
67559 struct tty_struct *tty, struct file *filp);
67560 static inline int tty_port_users(struct tty_port *port)
67561 {
67562- return port->count + port->blocked_open;
67563+ return atomic_read(&port->count) + port->blocked_open;
67564 }
67565
67566 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
67567diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
67568index dd976cf..e272742 100644
67569--- a/include/linux/tty_driver.h
67570+++ b/include/linux/tty_driver.h
67571@@ -284,7 +284,7 @@ struct tty_operations {
67572 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
67573 #endif
67574 const struct file_operations *proc_fops;
67575-};
67576+} __do_const;
67577
67578 struct tty_driver {
67579 int magic; /* magic number for this structure */
67580diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
67581index fb79dd8d..07d4773 100644
67582--- a/include/linux/tty_ldisc.h
67583+++ b/include/linux/tty_ldisc.h
67584@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
67585
67586 struct module *owner;
67587
67588- int refcount;
67589+ atomic_t refcount;
67590 };
67591
67592 struct tty_ldisc {
67593diff --git a/include/linux/types.h b/include/linux/types.h
67594index 4d118ba..c3ee9bf 100644
67595--- a/include/linux/types.h
67596+++ b/include/linux/types.h
67597@@ -176,10 +176,26 @@ typedef struct {
67598 int counter;
67599 } atomic_t;
67600
67601+#ifdef CONFIG_PAX_REFCOUNT
67602+typedef struct {
67603+ int counter;
67604+} atomic_unchecked_t;
67605+#else
67606+typedef atomic_t atomic_unchecked_t;
67607+#endif
67608+
67609 #ifdef CONFIG_64BIT
67610 typedef struct {
67611 long counter;
67612 } atomic64_t;
67613+
67614+#ifdef CONFIG_PAX_REFCOUNT
67615+typedef struct {
67616+ long counter;
67617+} atomic64_unchecked_t;
67618+#else
67619+typedef atomic64_t atomic64_unchecked_t;
67620+#endif
67621 #endif
67622
67623 struct list_head {
67624diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
67625index 5ca0951..ab496a5 100644
67626--- a/include/linux/uaccess.h
67627+++ b/include/linux/uaccess.h
67628@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
67629 long ret; \
67630 mm_segment_t old_fs = get_fs(); \
67631 \
67632- set_fs(KERNEL_DS); \
67633 pagefault_disable(); \
67634- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
67635- pagefault_enable(); \
67636+ set_fs(KERNEL_DS); \
67637+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
67638 set_fs(old_fs); \
67639+ pagefault_enable(); \
67640 ret; \
67641 })
67642
67643diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
67644index 99c1b4d..bb94261 100644
67645--- a/include/linux/unaligned/access_ok.h
67646+++ b/include/linux/unaligned/access_ok.h
67647@@ -6,32 +6,32 @@
67648
67649 static inline u16 get_unaligned_le16(const void *p)
67650 {
67651- return le16_to_cpup((__le16 *)p);
67652+ return le16_to_cpup((const __le16 *)p);
67653 }
67654
67655 static inline u32 get_unaligned_le32(const void *p)
67656 {
67657- return le32_to_cpup((__le32 *)p);
67658+ return le32_to_cpup((const __le32 *)p);
67659 }
67660
67661 static inline u64 get_unaligned_le64(const void *p)
67662 {
67663- return le64_to_cpup((__le64 *)p);
67664+ return le64_to_cpup((const __le64 *)p);
67665 }
67666
67667 static inline u16 get_unaligned_be16(const void *p)
67668 {
67669- return be16_to_cpup((__be16 *)p);
67670+ return be16_to_cpup((const __be16 *)p);
67671 }
67672
67673 static inline u32 get_unaligned_be32(const void *p)
67674 {
67675- return be32_to_cpup((__be32 *)p);
67676+ return be32_to_cpup((const __be32 *)p);
67677 }
67678
67679 static inline u64 get_unaligned_be64(const void *p)
67680 {
67681- return be64_to_cpup((__be64 *)p);
67682+ return be64_to_cpup((const __be64 *)p);
67683 }
67684
67685 static inline void put_unaligned_le16(u16 val, void *p)
67686diff --git a/include/linux/usb.h b/include/linux/usb.h
67687index 4d22d0f..ac43c2f 100644
67688--- a/include/linux/usb.h
67689+++ b/include/linux/usb.h
67690@@ -554,7 +554,7 @@ struct usb_device {
67691 int maxchild;
67692
67693 u32 quirks;
67694- atomic_t urbnum;
67695+ atomic_unchecked_t urbnum;
67696
67697 unsigned long active_duration;
67698
67699diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
67700index c5d36c6..108f4f9 100644
67701--- a/include/linux/usb/renesas_usbhs.h
67702+++ b/include/linux/usb/renesas_usbhs.h
67703@@ -39,7 +39,7 @@ enum {
67704 */
67705 struct renesas_usbhs_driver_callback {
67706 int (*notify_hotplug)(struct platform_device *pdev);
67707-};
67708+} __no_const;
67709
67710 /*
67711 * callback functions for platform
67712diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
67713index b9bd2e6..4ce0093 100644
67714--- a/include/linux/user_namespace.h
67715+++ b/include/linux/user_namespace.h
67716@@ -21,7 +21,7 @@ struct user_namespace {
67717 struct uid_gid_map uid_map;
67718 struct uid_gid_map gid_map;
67719 struct uid_gid_map projid_map;
67720- struct kref kref;
67721+ atomic_t count;
67722 struct user_namespace *parent;
67723 kuid_t owner;
67724 kgid_t group;
67725@@ -35,18 +35,18 @@ extern struct user_namespace init_user_ns;
67726 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
67727 {
67728 if (ns)
67729- kref_get(&ns->kref);
67730+ atomic_inc(&ns->count);
67731 return ns;
67732 }
67733
67734 extern int create_user_ns(struct cred *new);
67735 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
67736-extern void free_user_ns(struct kref *kref);
67737+extern void free_user_ns(struct user_namespace *ns);
67738
67739 static inline void put_user_ns(struct user_namespace *ns)
67740 {
67741- if (ns)
67742- kref_put(&ns->kref, free_user_ns);
67743+ if (ns && atomic_dec_and_test(&ns->count))
67744+ free_user_ns(ns);
67745 }
67746
67747 struct seq_operations;
67748diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
67749index 6f8fbcf..8259001 100644
67750--- a/include/linux/vermagic.h
67751+++ b/include/linux/vermagic.h
67752@@ -25,9 +25,35 @@
67753 #define MODULE_ARCH_VERMAGIC ""
67754 #endif
67755
67756+#ifdef CONFIG_PAX_REFCOUNT
67757+#define MODULE_PAX_REFCOUNT "REFCOUNT "
67758+#else
67759+#define MODULE_PAX_REFCOUNT ""
67760+#endif
67761+
67762+#ifdef CONSTIFY_PLUGIN
67763+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
67764+#else
67765+#define MODULE_CONSTIFY_PLUGIN ""
67766+#endif
67767+
67768+#ifdef STACKLEAK_PLUGIN
67769+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
67770+#else
67771+#define MODULE_STACKLEAK_PLUGIN ""
67772+#endif
67773+
67774+#ifdef CONFIG_GRKERNSEC
67775+#define MODULE_GRSEC "GRSEC "
67776+#else
67777+#define MODULE_GRSEC ""
67778+#endif
67779+
67780 #define VERMAGIC_STRING \
67781 UTS_RELEASE " " \
67782 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
67783 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
67784- MODULE_ARCH_VERMAGIC
67785+ MODULE_ARCH_VERMAGIC \
67786+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
67787+ MODULE_GRSEC
67788
67789diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
67790index 6071e91..ca6a489 100644
67791--- a/include/linux/vmalloc.h
67792+++ b/include/linux/vmalloc.h
67793@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
67794 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
67795 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
67796 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
67797+
67798+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
67799+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
67800+#endif
67801+
67802 /* bits [20..32] reserved for arch specific ioremap internals */
67803
67804 /*
67805@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
67806 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
67807 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
67808 unsigned long start, unsigned long end, gfp_t gfp_mask,
67809- pgprot_t prot, int node, const void *caller);
67810+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
67811 extern void vfree(const void *addr);
67812
67813 extern void *vmap(struct page **pages, unsigned int count,
67814@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
67815 extern void free_vm_area(struct vm_struct *area);
67816
67817 /* for /dev/kmem */
67818-extern long vread(char *buf, char *addr, unsigned long count);
67819-extern long vwrite(char *buf, char *addr, unsigned long count);
67820+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
67821+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
67822
67823 /*
67824 * Internals. Dont't use..
67825diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
67826index a13291f..af51fa3 100644
67827--- a/include/linux/vmstat.h
67828+++ b/include/linux/vmstat.h
67829@@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
67830 /*
67831 * Zone based page accounting with per cpu differentials.
67832 */
67833-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67834+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67835
67836 static inline void zone_page_state_add(long x, struct zone *zone,
67837 enum zone_stat_item item)
67838 {
67839- atomic_long_add(x, &zone->vm_stat[item]);
67840- atomic_long_add(x, &vm_stat[item]);
67841+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
67842+ atomic_long_add_unchecked(x, &vm_stat[item]);
67843 }
67844
67845 static inline unsigned long global_page_state(enum zone_stat_item item)
67846 {
67847- long x = atomic_long_read(&vm_stat[item]);
67848+ long x = atomic_long_read_unchecked(&vm_stat[item]);
67849 #ifdef CONFIG_SMP
67850 if (x < 0)
67851 x = 0;
67852@@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
67853 static inline unsigned long zone_page_state(struct zone *zone,
67854 enum zone_stat_item item)
67855 {
67856- long x = atomic_long_read(&zone->vm_stat[item]);
67857+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
67858 #ifdef CONFIG_SMP
67859 if (x < 0)
67860 x = 0;
67861@@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
67862 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
67863 enum zone_stat_item item)
67864 {
67865- long x = atomic_long_read(&zone->vm_stat[item]);
67866+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
67867
67868 #ifdef CONFIG_SMP
67869 int cpu;
67870@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
67871
67872 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
67873 {
67874- atomic_long_inc(&zone->vm_stat[item]);
67875- atomic_long_inc(&vm_stat[item]);
67876+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
67877+ atomic_long_inc_unchecked(&vm_stat[item]);
67878 }
67879
67880 static inline void __inc_zone_page_state(struct page *page,
67881@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
67882
67883 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
67884 {
67885- atomic_long_dec(&zone->vm_stat[item]);
67886- atomic_long_dec(&vm_stat[item]);
67887+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
67888+ atomic_long_dec_unchecked(&vm_stat[item]);
67889 }
67890
67891 static inline void __dec_zone_page_state(struct page *page,
67892diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
67893index 95d1c91..6798cca 100644
67894--- a/include/media/v4l2-dev.h
67895+++ b/include/media/v4l2-dev.h
67896@@ -76,7 +76,7 @@ struct v4l2_file_operations {
67897 int (*mmap) (struct file *, struct vm_area_struct *);
67898 int (*open) (struct file *);
67899 int (*release) (struct file *);
67900-};
67901+} __do_const;
67902
67903 /*
67904 * Newer version of video_device, handled by videodev2.c
67905diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
67906index 4118ad1..cb7e25f 100644
67907--- a/include/media/v4l2-ioctl.h
67908+++ b/include/media/v4l2-ioctl.h
67909@@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
67910 bool valid_prio, int cmd, void *arg);
67911 };
67912
67913-
67914 /* v4l debugging and diagnostics */
67915
67916 /* Debug bitmask flags to be used on V4L2 */
67917diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
67918index 9e5425b..8136ffc 100644
67919--- a/include/net/caif/cfctrl.h
67920+++ b/include/net/caif/cfctrl.h
67921@@ -52,7 +52,7 @@ struct cfctrl_rsp {
67922 void (*radioset_rsp)(void);
67923 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
67924 struct cflayer *client_layer);
67925-};
67926+} __no_const;
67927
67928 /* Link Setup Parameters for CAIF-Links. */
67929 struct cfctrl_link_param {
67930@@ -101,8 +101,8 @@ struct cfctrl_request_info {
67931 struct cfctrl {
67932 struct cfsrvl serv;
67933 struct cfctrl_rsp res;
67934- atomic_t req_seq_no;
67935- atomic_t rsp_seq_no;
67936+ atomic_unchecked_t req_seq_no;
67937+ atomic_unchecked_t rsp_seq_no;
67938 struct list_head list;
67939 /* Protects from simultaneous access to first_req list */
67940 spinlock_t info_list_lock;
67941diff --git a/include/net/flow.h b/include/net/flow.h
67942index 628e11b..4c475df 100644
67943--- a/include/net/flow.h
67944+++ b/include/net/flow.h
67945@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
67946
67947 extern void flow_cache_flush(void);
67948 extern void flow_cache_flush_deferred(void);
67949-extern atomic_t flow_cache_genid;
67950+extern atomic_unchecked_t flow_cache_genid;
67951
67952 #endif
67953diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
67954index e5062c9..48a9a4b 100644
67955--- a/include/net/gro_cells.h
67956+++ b/include/net/gro_cells.h
67957@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
67958 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
67959
67960 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
67961- atomic_long_inc(&dev->rx_dropped);
67962+ atomic_long_inc_unchecked(&dev->rx_dropped);
67963 kfree_skb(skb);
67964 return;
67965 }
67966@@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
67967 int i;
67968
67969 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
67970- gcells->cells = kcalloc(sizeof(struct gro_cell),
67971- gcells->gro_cells_mask + 1,
67972+ gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
67973+ sizeof(struct gro_cell),
67974 GFP_KERNEL);
67975 if (!gcells->cells)
67976 return -ENOMEM;
67977diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
67978index 1832927..ce39aea 100644
67979--- a/include/net/inet_connection_sock.h
67980+++ b/include/net/inet_connection_sock.h
67981@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
67982 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
67983 int (*bind_conflict)(const struct sock *sk,
67984 const struct inet_bind_bucket *tb, bool relax);
67985-};
67986+} __do_const;
67987
67988 /** inet_connection_sock - INET connection oriented sock
67989 *
67990diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
67991index 53f464d..ba76aaa 100644
67992--- a/include/net/inetpeer.h
67993+++ b/include/net/inetpeer.h
67994@@ -47,8 +47,8 @@ struct inet_peer {
67995 */
67996 union {
67997 struct {
67998- atomic_t rid; /* Frag reception counter */
67999- atomic_t ip_id_count; /* IP ID for the next packet */
68000+ atomic_unchecked_t rid; /* Frag reception counter */
68001+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
68002 };
68003 struct rcu_head rcu;
68004 struct inet_peer *gc_next;
68005@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
68006 more++;
68007 inet_peer_refcheck(p);
68008 do {
68009- old = atomic_read(&p->ip_id_count);
68010+ old = atomic_read_unchecked(&p->ip_id_count);
68011 new = old + more;
68012 if (!new)
68013 new = 1;
68014- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
68015+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
68016 return new;
68017 }
68018
68019diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
68020index 9497be1..5a4fafe 100644
68021--- a/include/net/ip_fib.h
68022+++ b/include/net/ip_fib.h
68023@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
68024
68025 #define FIB_RES_SADDR(net, res) \
68026 ((FIB_RES_NH(res).nh_saddr_genid == \
68027- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
68028+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
68029 FIB_RES_NH(res).nh_saddr : \
68030 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
68031 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
68032diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
68033index 68c69d5..2ee192b 100644
68034--- a/include/net/ip_vs.h
68035+++ b/include/net/ip_vs.h
68036@@ -599,7 +599,7 @@ struct ip_vs_conn {
68037 struct ip_vs_conn *control; /* Master control connection */
68038 atomic_t n_control; /* Number of controlled ones */
68039 struct ip_vs_dest *dest; /* real server */
68040- atomic_t in_pkts; /* incoming packet counter */
68041+ atomic_unchecked_t in_pkts; /* incoming packet counter */
68042
68043 /* packet transmitter for different forwarding methods. If it
68044 mangles the packet, it must return NF_DROP or better NF_STOLEN,
68045@@ -737,7 +737,7 @@ struct ip_vs_dest {
68046 __be16 port; /* port number of the server */
68047 union nf_inet_addr addr; /* IP address of the server */
68048 volatile unsigned int flags; /* dest status flags */
68049- atomic_t conn_flags; /* flags to copy to conn */
68050+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
68051 atomic_t weight; /* server weight */
68052
68053 atomic_t refcnt; /* reference counter */
68054diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
68055index 80ffde3..968b0f4 100644
68056--- a/include/net/irda/ircomm_tty.h
68057+++ b/include/net/irda/ircomm_tty.h
68058@@ -35,6 +35,7 @@
68059 #include <linux/termios.h>
68060 #include <linux/timer.h>
68061 #include <linux/tty.h> /* struct tty_struct */
68062+#include <asm/local.h>
68063
68064 #include <net/irda/irias_object.h>
68065 #include <net/irda/ircomm_core.h>
68066diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
68067index cc7c197..9f2da2a 100644
68068--- a/include/net/iucv/af_iucv.h
68069+++ b/include/net/iucv/af_iucv.h
68070@@ -141,7 +141,7 @@ struct iucv_sock {
68071 struct iucv_sock_list {
68072 struct hlist_head head;
68073 rwlock_t lock;
68074- atomic_t autobind_name;
68075+ atomic_unchecked_t autobind_name;
68076 };
68077
68078 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
68079diff --git a/include/net/neighbour.h b/include/net/neighbour.h
68080index 0dab173..1b76af0 100644
68081--- a/include/net/neighbour.h
68082+++ b/include/net/neighbour.h
68083@@ -123,7 +123,7 @@ struct neigh_ops {
68084 void (*error_report)(struct neighbour *, struct sk_buff *);
68085 int (*output)(struct neighbour *, struct sk_buff *);
68086 int (*connected_output)(struct neighbour *, struct sk_buff *);
68087-};
68088+} __do_const;
68089
68090 struct pneigh_entry {
68091 struct pneigh_entry *next;
68092diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
68093index de644bc..666aed3 100644
68094--- a/include/net/net_namespace.h
68095+++ b/include/net/net_namespace.h
68096@@ -115,7 +115,7 @@ struct net {
68097 #endif
68098 struct netns_ipvs *ipvs;
68099 struct sock *diag_nlsk;
68100- atomic_t rt_genid;
68101+ atomic_unchecked_t rt_genid;
68102 };
68103
68104 /*
68105@@ -330,12 +330,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
68106
68107 static inline int rt_genid(struct net *net)
68108 {
68109- return atomic_read(&net->rt_genid);
68110+ return atomic_read_unchecked(&net->rt_genid);
68111 }
68112
68113 static inline void rt_genid_bump(struct net *net)
68114 {
68115- atomic_inc(&net->rt_genid);
68116+ atomic_inc_unchecked(&net->rt_genid);
68117 }
68118
68119 #endif /* __NET_NET_NAMESPACE_H */
68120diff --git a/include/net/netdma.h b/include/net/netdma.h
68121index 8ba8ce2..99b7fff 100644
68122--- a/include/net/netdma.h
68123+++ b/include/net/netdma.h
68124@@ -24,7 +24,7 @@
68125 #include <linux/dmaengine.h>
68126 #include <linux/skbuff.h>
68127
68128-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
68129+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
68130 struct sk_buff *skb, int offset, struct iovec *to,
68131 size_t len, struct dma_pinned_list *pinned_list);
68132
68133diff --git a/include/net/netlink.h b/include/net/netlink.h
68134index 9690b0f..87aded7 100644
68135--- a/include/net/netlink.h
68136+++ b/include/net/netlink.h
68137@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
68138 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
68139 {
68140 if (mark)
68141- skb_trim(skb, (unsigned char *) mark - skb->data);
68142+ skb_trim(skb, (const unsigned char *) mark - skb->data);
68143 }
68144
68145 /**
68146diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
68147index 2ae2b83..dbdc85e 100644
68148--- a/include/net/netns/ipv4.h
68149+++ b/include/net/netns/ipv4.h
68150@@ -64,7 +64,7 @@ struct netns_ipv4 {
68151 kgid_t sysctl_ping_group_range[2];
68152 long sysctl_tcp_mem[3];
68153
68154- atomic_t dev_addr_genid;
68155+ atomic_unchecked_t dev_addr_genid;
68156
68157 #ifdef CONFIG_IP_MROUTE
68158 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
68159diff --git a/include/net/protocol.h b/include/net/protocol.h
68160index 047c047..b9dad15 100644
68161--- a/include/net/protocol.h
68162+++ b/include/net/protocol.h
68163@@ -44,7 +44,7 @@ struct net_protocol {
68164 void (*err_handler)(struct sk_buff *skb, u32 info);
68165 unsigned int no_policy:1,
68166 netns_ok:1;
68167-};
68168+} __do_const;
68169
68170 #if IS_ENABLED(CONFIG_IPV6)
68171 struct inet6_protocol {
68172@@ -57,7 +57,7 @@ struct inet6_protocol {
68173 u8 type, u8 code, int offset,
68174 __be32 info);
68175 unsigned int flags; /* INET6_PROTO_xxx */
68176-};
68177+} __do_const;
68178
68179 #define INET6_PROTO_NOPOLICY 0x1
68180 #define INET6_PROTO_FINAL 0x2
68181diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
68182index 7fdf298..197e9f7 100644
68183--- a/include/net/sctp/sctp.h
68184+++ b/include/net/sctp/sctp.h
68185@@ -330,9 +330,9 @@ do { \
68186
68187 #else /* SCTP_DEBUG */
68188
68189-#define SCTP_DEBUG_PRINTK(whatever...)
68190-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
68191-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
68192+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
68193+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
68194+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
68195 #define SCTP_ENABLE_DEBUG
68196 #define SCTP_DISABLE_DEBUG
68197 #define SCTP_ASSERT(expr, str, func)
68198diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
68199index fdeb85a..0c554d5 100644
68200--- a/include/net/sctp/structs.h
68201+++ b/include/net/sctp/structs.h
68202@@ -497,7 +497,7 @@ struct sctp_af {
68203 int sockaddr_len;
68204 sa_family_t sa_family;
68205 struct list_head list;
68206-};
68207+} __do_const;
68208
68209 struct sctp_af *sctp_get_af_specific(sa_family_t);
68210 int sctp_register_af(struct sctp_af *);
68211@@ -517,7 +517,7 @@ struct sctp_pf {
68212 struct sctp_association *asoc);
68213 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
68214 struct sctp_af *af;
68215-};
68216+} __do_const;
68217
68218
68219 /* Structure to track chunk fragments that have been acked, but peer
68220diff --git a/include/net/sock.h b/include/net/sock.h
68221index 182ca99..b7dc290 100644
68222--- a/include/net/sock.h
68223+++ b/include/net/sock.h
68224@@ -322,7 +322,7 @@ struct sock {
68225 #ifdef CONFIG_RPS
68226 __u32 sk_rxhash;
68227 #endif
68228- atomic_t sk_drops;
68229+ atomic_unchecked_t sk_drops;
68230 int sk_rcvbuf;
68231
68232 struct sk_filter __rcu *sk_filter;
68233@@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
68234 }
68235
68236 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
68237- char __user *from, char *to,
68238+ char __user *from, unsigned char *to,
68239 int copy, int offset)
68240 {
68241 if (skb->ip_summed == CHECKSUM_NONE) {
68242@@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
68243 }
68244 }
68245
68246-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
68247+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
68248
68249 /**
68250 * sk_page_frag - return an appropriate page_frag
68251diff --git a/include/net/tcp.h b/include/net/tcp.h
68252index aed42c7..43890c6 100644
68253--- a/include/net/tcp.h
68254+++ b/include/net/tcp.h
68255@@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
68256 extern void tcp_xmit_retransmit_queue(struct sock *);
68257 extern void tcp_simple_retransmit(struct sock *);
68258 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
68259-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
68260+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
68261
68262 extern void tcp_send_probe0(struct sock *);
68263 extern void tcp_send_partial(struct sock *);
68264@@ -701,8 +701,8 @@ struct tcp_skb_cb {
68265 struct inet6_skb_parm h6;
68266 #endif
68267 } header; /* For incoming frames */
68268- __u32 seq; /* Starting sequence number */
68269- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
68270+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
68271+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
68272 __u32 when; /* used to compute rtt's */
68273 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
68274
68275@@ -716,7 +716,7 @@ struct tcp_skb_cb {
68276
68277 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
68278 /* 1 byte hole */
68279- __u32 ack_seq; /* Sequence number ACK'd */
68280+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
68281 };
68282
68283 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
68284diff --git a/include/net/xfrm.h b/include/net/xfrm.h
68285index 63445ed..74ef61d 100644
68286--- a/include/net/xfrm.h
68287+++ b/include/net/xfrm.h
68288@@ -423,7 +423,7 @@ struct xfrm_mode {
68289 struct module *owner;
68290 unsigned int encap;
68291 int flags;
68292-};
68293+} __do_const;
68294
68295 /* Flags for xfrm_mode. */
68296 enum {
68297@@ -514,7 +514,7 @@ struct xfrm_policy {
68298 struct timer_list timer;
68299
68300 struct flow_cache_object flo;
68301- atomic_t genid;
68302+ atomic_unchecked_t genid;
68303 u32 priority;
68304 u32 index;
68305 struct xfrm_mark mark;
68306diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
68307index 1a046b1..ee0bef0 100644
68308--- a/include/rdma/iw_cm.h
68309+++ b/include/rdma/iw_cm.h
68310@@ -122,7 +122,7 @@ struct iw_cm_verbs {
68311 int backlog);
68312
68313 int (*destroy_listen)(struct iw_cm_id *cm_id);
68314-};
68315+} __no_const;
68316
68317 /**
68318 * iw_create_cm_id - Create an IW CM identifier.
68319diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
68320index 399162b..b337f1a 100644
68321--- a/include/scsi/libfc.h
68322+++ b/include/scsi/libfc.h
68323@@ -762,6 +762,7 @@ struct libfc_function_template {
68324 */
68325 void (*disc_stop_final) (struct fc_lport *);
68326 };
68327+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
68328
68329 /**
68330 * struct fc_disc - Discovery context
68331@@ -866,7 +867,7 @@ struct fc_lport {
68332 struct fc_vport *vport;
68333
68334 /* Operational Information */
68335- struct libfc_function_template tt;
68336+ libfc_function_template_no_const tt;
68337 u8 link_up;
68338 u8 qfull;
68339 enum fc_lport_state state;
68340diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
68341index e65c62e..aa2e5a2 100644
68342--- a/include/scsi/scsi_device.h
68343+++ b/include/scsi/scsi_device.h
68344@@ -170,9 +170,9 @@ struct scsi_device {
68345 unsigned int max_device_blocked; /* what device_blocked counts down from */
68346 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
68347
68348- atomic_t iorequest_cnt;
68349- atomic_t iodone_cnt;
68350- atomic_t ioerr_cnt;
68351+ atomic_unchecked_t iorequest_cnt;
68352+ atomic_unchecked_t iodone_cnt;
68353+ atomic_unchecked_t ioerr_cnt;
68354
68355 struct device sdev_gendev,
68356 sdev_dev;
68357diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
68358index b797e8f..8e2c3aa 100644
68359--- a/include/scsi/scsi_transport_fc.h
68360+++ b/include/scsi/scsi_transport_fc.h
68361@@ -751,7 +751,8 @@ struct fc_function_template {
68362 unsigned long show_host_system_hostname:1;
68363
68364 unsigned long disable_target_scan:1;
68365-};
68366+} __do_const;
68367+typedef struct fc_function_template __no_const fc_function_template_no_const;
68368
68369
68370 /**
68371diff --git a/include/sound/soc.h b/include/sound/soc.h
68372index bc56738..a4be132 100644
68373--- a/include/sound/soc.h
68374+++ b/include/sound/soc.h
68375@@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
68376 /* probe ordering - for components with runtime dependencies */
68377 int probe_order;
68378 int remove_order;
68379-};
68380+} __do_const;
68381
68382 /* SoC platform interface */
68383 struct snd_soc_platform_driver {
68384@@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
68385 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
68386 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
68387 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
68388-};
68389+} __do_const;
68390
68391 struct snd_soc_platform {
68392 const char *name;
68393diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
68394index 663e34a..91b306a 100644
68395--- a/include/target/target_core_base.h
68396+++ b/include/target/target_core_base.h
68397@@ -654,7 +654,7 @@ struct se_device {
68398 spinlock_t stats_lock;
68399 /* Active commands on this virtual SE device */
68400 atomic_t simple_cmds;
68401- atomic_t dev_ordered_id;
68402+ atomic_unchecked_t dev_ordered_id;
68403 atomic_t dev_ordered_sync;
68404 atomic_t dev_qf_count;
68405 int export_count;
68406diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
68407new file mode 100644
68408index 0000000..fb634b7
68409--- /dev/null
68410+++ b/include/trace/events/fs.h
68411@@ -0,0 +1,53 @@
68412+#undef TRACE_SYSTEM
68413+#define TRACE_SYSTEM fs
68414+
68415+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
68416+#define _TRACE_FS_H
68417+
68418+#include <linux/fs.h>
68419+#include <linux/tracepoint.h>
68420+
68421+TRACE_EVENT(do_sys_open,
68422+
68423+ TP_PROTO(const char *filename, int flags, int mode),
68424+
68425+ TP_ARGS(filename, flags, mode),
68426+
68427+ TP_STRUCT__entry(
68428+ __string( filename, filename )
68429+ __field( int, flags )
68430+ __field( int, mode )
68431+ ),
68432+
68433+ TP_fast_assign(
68434+ __assign_str(filename, filename);
68435+ __entry->flags = flags;
68436+ __entry->mode = mode;
68437+ ),
68438+
68439+ TP_printk("\"%s\" %x %o",
68440+ __get_str(filename), __entry->flags, __entry->mode)
68441+);
68442+
68443+TRACE_EVENT(open_exec,
68444+
68445+ TP_PROTO(const char *filename),
68446+
68447+ TP_ARGS(filename),
68448+
68449+ TP_STRUCT__entry(
68450+ __string( filename, filename )
68451+ ),
68452+
68453+ TP_fast_assign(
68454+ __assign_str(filename, filename);
68455+ ),
68456+
68457+ TP_printk("\"%s\"",
68458+ __get_str(filename))
68459+);
68460+
68461+#endif /* _TRACE_FS_H */
68462+
68463+/* This part must be outside protection */
68464+#include <trace/define_trace.h>
68465diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
68466index 1c09820..7f5ec79 100644
68467--- a/include/trace/events/irq.h
68468+++ b/include/trace/events/irq.h
68469@@ -36,7 +36,7 @@ struct softirq_action;
68470 */
68471 TRACE_EVENT(irq_handler_entry,
68472
68473- TP_PROTO(int irq, struct irqaction *action),
68474+ TP_PROTO(int irq, const struct irqaction *action),
68475
68476 TP_ARGS(irq, action),
68477
68478@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
68479 */
68480 TRACE_EVENT(irq_handler_exit,
68481
68482- TP_PROTO(int irq, struct irqaction *action, int ret),
68483+ TP_PROTO(int irq, const struct irqaction *action, int ret),
68484
68485 TP_ARGS(irq, action, ret),
68486
68487diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
68488index 7caf44c..23c6f27 100644
68489--- a/include/uapi/linux/a.out.h
68490+++ b/include/uapi/linux/a.out.h
68491@@ -39,6 +39,14 @@ enum machine_type {
68492 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
68493 };
68494
68495+/* Constants for the N_FLAGS field */
68496+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
68497+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
68498+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
68499+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
68500+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
68501+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
68502+
68503 #if !defined (N_MAGIC)
68504 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
68505 #endif
68506diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
68507index d876736..b36014e 100644
68508--- a/include/uapi/linux/byteorder/little_endian.h
68509+++ b/include/uapi/linux/byteorder/little_endian.h
68510@@ -42,51 +42,51 @@
68511
68512 static inline __le64 __cpu_to_le64p(const __u64 *p)
68513 {
68514- return (__force __le64)*p;
68515+ return (__force const __le64)*p;
68516 }
68517 static inline __u64 __le64_to_cpup(const __le64 *p)
68518 {
68519- return (__force __u64)*p;
68520+ return (__force const __u64)*p;
68521 }
68522 static inline __le32 __cpu_to_le32p(const __u32 *p)
68523 {
68524- return (__force __le32)*p;
68525+ return (__force const __le32)*p;
68526 }
68527 static inline __u32 __le32_to_cpup(const __le32 *p)
68528 {
68529- return (__force __u32)*p;
68530+ return (__force const __u32)*p;
68531 }
68532 static inline __le16 __cpu_to_le16p(const __u16 *p)
68533 {
68534- return (__force __le16)*p;
68535+ return (__force const __le16)*p;
68536 }
68537 static inline __u16 __le16_to_cpup(const __le16 *p)
68538 {
68539- return (__force __u16)*p;
68540+ return (__force const __u16)*p;
68541 }
68542 static inline __be64 __cpu_to_be64p(const __u64 *p)
68543 {
68544- return (__force __be64)__swab64p(p);
68545+ return (__force const __be64)__swab64p(p);
68546 }
68547 static inline __u64 __be64_to_cpup(const __be64 *p)
68548 {
68549- return __swab64p((__u64 *)p);
68550+ return __swab64p((const __u64 *)p);
68551 }
68552 static inline __be32 __cpu_to_be32p(const __u32 *p)
68553 {
68554- return (__force __be32)__swab32p(p);
68555+ return (__force const __be32)__swab32p(p);
68556 }
68557 static inline __u32 __be32_to_cpup(const __be32 *p)
68558 {
68559- return __swab32p((__u32 *)p);
68560+ return __swab32p((const __u32 *)p);
68561 }
68562 static inline __be16 __cpu_to_be16p(const __u16 *p)
68563 {
68564- return (__force __be16)__swab16p(p);
68565+ return (__force const __be16)__swab16p(p);
68566 }
68567 static inline __u16 __be16_to_cpup(const __be16 *p)
68568 {
68569- return __swab16p((__u16 *)p);
68570+ return __swab16p((const __u16 *)p);
68571 }
68572 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
68573 #define __le64_to_cpus(x) do { (void)(x); } while (0)
68574diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
68575index 126a817..d522bd1 100644
68576--- a/include/uapi/linux/elf.h
68577+++ b/include/uapi/linux/elf.h
68578@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
68579 #define PT_GNU_EH_FRAME 0x6474e550
68580
68581 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
68582+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
68583+
68584+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
68585+
68586+/* Constants for the e_flags field */
68587+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
68588+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
68589+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
68590+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
68591+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
68592+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
68593
68594 /*
68595 * Extended Numbering
68596@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
68597 #define DT_DEBUG 21
68598 #define DT_TEXTREL 22
68599 #define DT_JMPREL 23
68600+#define DT_FLAGS 30
68601+ #define DF_TEXTREL 0x00000004
68602 #define DT_ENCODING 32
68603 #define OLD_DT_LOOS 0x60000000
68604 #define DT_LOOS 0x6000000d
68605@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
68606 #define PF_W 0x2
68607 #define PF_X 0x1
68608
68609+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
68610+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
68611+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
68612+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
68613+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
68614+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
68615+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
68616+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
68617+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
68618+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
68619+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
68620+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
68621+
68622 typedef struct elf32_phdr{
68623 Elf32_Word p_type;
68624 Elf32_Off p_offset;
68625@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
68626 #define EI_OSABI 7
68627 #define EI_PAD 8
68628
68629+#define EI_PAX 14
68630+
68631 #define ELFMAG0 0x7f /* EI_MAG */
68632 #define ELFMAG1 'E'
68633 #define ELFMAG2 'L'
68634diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
68635index aa169c4..6a2771d 100644
68636--- a/include/uapi/linux/personality.h
68637+++ b/include/uapi/linux/personality.h
68638@@ -30,6 +30,7 @@ enum {
68639 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
68640 ADDR_NO_RANDOMIZE | \
68641 ADDR_COMPAT_LAYOUT | \
68642+ ADDR_LIMIT_3GB | \
68643 MMAP_PAGE_ZERO)
68644
68645 /*
68646diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
68647index 7530e74..e714828 100644
68648--- a/include/uapi/linux/screen_info.h
68649+++ b/include/uapi/linux/screen_info.h
68650@@ -43,7 +43,8 @@ struct screen_info {
68651 __u16 pages; /* 0x32 */
68652 __u16 vesa_attributes; /* 0x34 */
68653 __u32 capabilities; /* 0x36 */
68654- __u8 _reserved[6]; /* 0x3a */
68655+ __u16 vesapm_size; /* 0x3a */
68656+ __u8 _reserved[4]; /* 0x3c */
68657 } __attribute__((packed));
68658
68659 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
68660diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
68661index 6d67213..8dab561 100644
68662--- a/include/uapi/linux/sysctl.h
68663+++ b/include/uapi/linux/sysctl.h
68664@@ -155,7 +155,11 @@ enum
68665 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
68666 };
68667
68668-
68669+#ifdef CONFIG_PAX_SOFTMODE
68670+enum {
68671+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
68672+};
68673+#endif
68674
68675 /* CTL_VM names: */
68676 enum
68677diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
68678index 26607bd..588b65f 100644
68679--- a/include/uapi/linux/xattr.h
68680+++ b/include/uapi/linux/xattr.h
68681@@ -60,5 +60,9 @@
68682 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
68683 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
68684
68685+/* User namespace */
68686+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
68687+#define XATTR_PAX_FLAGS_SUFFIX "flags"
68688+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
68689
68690 #endif /* _UAPI_LINUX_XATTR_H */
68691diff --git a/include/video/udlfb.h b/include/video/udlfb.h
68692index f9466fa..f4e2b81 100644
68693--- a/include/video/udlfb.h
68694+++ b/include/video/udlfb.h
68695@@ -53,10 +53,10 @@ struct dlfb_data {
68696 u32 pseudo_palette[256];
68697 int blank_mode; /*one of FB_BLANK_ */
68698 /* blit-only rendering path metrics, exposed through sysfs */
68699- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
68700- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
68701- atomic_t bytes_sent; /* to usb, after compression including overhead */
68702- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
68703+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
68704+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
68705+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
68706+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
68707 };
68708
68709 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
68710diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
68711index 0993a22..32ba2fe 100644
68712--- a/include/video/uvesafb.h
68713+++ b/include/video/uvesafb.h
68714@@ -177,6 +177,7 @@ struct uvesafb_par {
68715 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
68716 u8 pmi_setpal; /* PMI for palette changes */
68717 u16 *pmi_base; /* protected mode interface location */
68718+ u8 *pmi_code; /* protected mode code location */
68719 void *pmi_start;
68720 void *pmi_pal;
68721 u8 *vbe_state_orig; /*
68722diff --git a/init/Kconfig b/init/Kconfig
68723index be8b7f5..b13cb62 100644
68724--- a/init/Kconfig
68725+++ b/init/Kconfig
68726@@ -990,6 +990,7 @@ endif # CGROUPS
68727
68728 config CHECKPOINT_RESTORE
68729 bool "Checkpoint/restore support" if EXPERT
68730+ depends on !GRKERNSEC
68731 default n
68732 help
68733 Enables additional kernel features in a sake of checkpoint/restore.
68734@@ -1079,6 +1080,8 @@ config UIDGID_CONVERTED
68735 depends on OCFS2_FS = n
68736 depends on XFS_FS = n
68737
68738+ depends on GRKERNSEC = n
68739+
68740 config UIDGID_STRICT_TYPE_CHECKS
68741 bool "Require conversions between uid/gids and their internal representation"
68742 depends on UIDGID_CONVERTED
68743@@ -1468,7 +1471,7 @@ config SLUB_DEBUG
68744
68745 config COMPAT_BRK
68746 bool "Disable heap randomization"
68747- default y
68748+ default n
68749 help
68750 Randomizing heap placement makes heap exploits harder, but it
68751 also breaks ancient binaries (including anything libc5 based).
68752@@ -1711,7 +1714,7 @@ config INIT_ALL_POSSIBLE
68753 config STOP_MACHINE
68754 bool
68755 default y
68756- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
68757+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
68758 help
68759 Need stop_machine() primitive.
68760
68761diff --git a/init/Makefile b/init/Makefile
68762index 7bc47ee..6da2dc7 100644
68763--- a/init/Makefile
68764+++ b/init/Makefile
68765@@ -2,6 +2,9 @@
68766 # Makefile for the linux kernel.
68767 #
68768
68769+ccflags-y := $(GCC_PLUGINS_CFLAGS)
68770+asflags-y := $(GCC_PLUGINS_AFLAGS)
68771+
68772 obj-y := main.o version.o mounts.o
68773 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
68774 obj-y += noinitramfs.o
68775diff --git a/init/do_mounts.c b/init/do_mounts.c
68776index 1d1b634..a1c810f 100644
68777--- a/init/do_mounts.c
68778+++ b/init/do_mounts.c
68779@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
68780 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
68781 {
68782 struct super_block *s;
68783- int err = sys_mount(name, "/root", fs, flags, data);
68784+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
68785 if (err)
68786 return err;
68787
68788- sys_chdir("/root");
68789+ sys_chdir((const char __force_user *)"/root");
68790 s = current->fs->pwd.dentry->d_sb;
68791 ROOT_DEV = s->s_dev;
68792 printk(KERN_INFO
68793@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
68794 va_start(args, fmt);
68795 vsprintf(buf, fmt, args);
68796 va_end(args);
68797- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
68798+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
68799 if (fd >= 0) {
68800 sys_ioctl(fd, FDEJECT, 0);
68801 sys_close(fd);
68802 }
68803 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
68804- fd = sys_open("/dev/console", O_RDWR, 0);
68805+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
68806 if (fd >= 0) {
68807 sys_ioctl(fd, TCGETS, (long)&termios);
68808 termios.c_lflag &= ~ICANON;
68809 sys_ioctl(fd, TCSETSF, (long)&termios);
68810- sys_read(fd, &c, 1);
68811+ sys_read(fd, (char __user *)&c, 1);
68812 termios.c_lflag |= ICANON;
68813 sys_ioctl(fd, TCSETSF, (long)&termios);
68814 sys_close(fd);
68815@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
68816 mount_root();
68817 out:
68818 devtmpfs_mount("dev");
68819- sys_mount(".", "/", NULL, MS_MOVE, NULL);
68820- sys_chroot(".");
68821+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
68822+ sys_chroot((const char __force_user *)".");
68823 }
68824diff --git a/init/do_mounts.h b/init/do_mounts.h
68825index f5b978a..69dbfe8 100644
68826--- a/init/do_mounts.h
68827+++ b/init/do_mounts.h
68828@@ -15,15 +15,15 @@ extern int root_mountflags;
68829
68830 static inline int create_dev(char *name, dev_t dev)
68831 {
68832- sys_unlink(name);
68833- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
68834+ sys_unlink((char __force_user *)name);
68835+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
68836 }
68837
68838 #if BITS_PER_LONG == 32
68839 static inline u32 bstat(char *name)
68840 {
68841 struct stat64 stat;
68842- if (sys_stat64(name, &stat) != 0)
68843+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
68844 return 0;
68845 if (!S_ISBLK(stat.st_mode))
68846 return 0;
68847@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
68848 static inline u32 bstat(char *name)
68849 {
68850 struct stat stat;
68851- if (sys_newstat(name, &stat) != 0)
68852+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
68853 return 0;
68854 if (!S_ISBLK(stat.st_mode))
68855 return 0;
68856diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
68857index f9acf71..1e19144 100644
68858--- a/init/do_mounts_initrd.c
68859+++ b/init/do_mounts_initrd.c
68860@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
68861 create_dev("/dev/root.old", Root_RAM0);
68862 /* mount initrd on rootfs' /root */
68863 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
68864- sys_mkdir("/old", 0700);
68865- sys_chdir("/old");
68866+ sys_mkdir((const char __force_user *)"/old", 0700);
68867+ sys_chdir((const char __force_user *)"/old");
68868
68869 /*
68870 * In case that a resume from disk is carried out by linuxrc or one of
68871@@ -73,31 +73,31 @@ static void __init handle_initrd(void)
68872 current->flags &= ~PF_FREEZER_SKIP;
68873
68874 /* move initrd to rootfs' /old */
68875- sys_mount("..", ".", NULL, MS_MOVE, NULL);
68876+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
68877 /* switch root and cwd back to / of rootfs */
68878- sys_chroot("..");
68879+ sys_chroot((const char __force_user *)"..");
68880
68881 if (new_decode_dev(real_root_dev) == Root_RAM0) {
68882- sys_chdir("/old");
68883+ sys_chdir((const char __force_user *)"/old");
68884 return;
68885 }
68886
68887- sys_chdir("/");
68888+ sys_chdir((const char __force_user *)"/");
68889 ROOT_DEV = new_decode_dev(real_root_dev);
68890 mount_root();
68891
68892 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
68893- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
68894+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
68895 if (!error)
68896 printk("okay\n");
68897 else {
68898- int fd = sys_open("/dev/root.old", O_RDWR, 0);
68899+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
68900 if (error == -ENOENT)
68901 printk("/initrd does not exist. Ignored.\n");
68902 else
68903 printk("failed\n");
68904 printk(KERN_NOTICE "Unmounting old root\n");
68905- sys_umount("/old", MNT_DETACH);
68906+ sys_umount((char __force_user *)"/old", MNT_DETACH);
68907 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
68908 if (fd < 0) {
68909 error = fd;
68910@@ -120,11 +120,11 @@ int __init initrd_load(void)
68911 * mounted in the normal path.
68912 */
68913 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
68914- sys_unlink("/initrd.image");
68915+ sys_unlink((const char __force_user *)"/initrd.image");
68916 handle_initrd();
68917 return 1;
68918 }
68919 }
68920- sys_unlink("/initrd.image");
68921+ sys_unlink((const char __force_user *)"/initrd.image");
68922 return 0;
68923 }
68924diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
68925index 8cb6db5..d729f50 100644
68926--- a/init/do_mounts_md.c
68927+++ b/init/do_mounts_md.c
68928@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
68929 partitioned ? "_d" : "", minor,
68930 md_setup_args[ent].device_names);
68931
68932- fd = sys_open(name, 0, 0);
68933+ fd = sys_open((char __force_user *)name, 0, 0);
68934 if (fd < 0) {
68935 printk(KERN_ERR "md: open failed - cannot start "
68936 "array %s\n", name);
68937@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
68938 * array without it
68939 */
68940 sys_close(fd);
68941- fd = sys_open(name, 0, 0);
68942+ fd = sys_open((char __force_user *)name, 0, 0);
68943 sys_ioctl(fd, BLKRRPART, 0);
68944 }
68945 sys_close(fd);
68946@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
68947
68948 wait_for_device_probe();
68949
68950- fd = sys_open("/dev/md0", 0, 0);
68951+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
68952 if (fd >= 0) {
68953 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
68954 sys_close(fd);
68955diff --git a/init/init_task.c b/init/init_task.c
68956index 8b2f399..f0797c9 100644
68957--- a/init/init_task.c
68958+++ b/init/init_task.c
68959@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
68960 * Initial thread structure. Alignment of this is handled by a special
68961 * linker map entry.
68962 */
68963+#ifdef CONFIG_X86
68964+union thread_union init_thread_union __init_task_data;
68965+#else
68966 union thread_union init_thread_union __init_task_data =
68967 { INIT_THREAD_INFO(init_task) };
68968+#endif
68969diff --git a/init/initramfs.c b/init/initramfs.c
68970index 84c6bf1..8899338 100644
68971--- a/init/initramfs.c
68972+++ b/init/initramfs.c
68973@@ -84,7 +84,7 @@ static void __init free_hash(void)
68974 }
68975 }
68976
68977-static long __init do_utime(char *filename, time_t mtime)
68978+static long __init do_utime(char __force_user *filename, time_t mtime)
68979 {
68980 struct timespec t[2];
68981
68982@@ -119,7 +119,7 @@ static void __init dir_utime(void)
68983 struct dir_entry *de, *tmp;
68984 list_for_each_entry_safe(de, tmp, &dir_list, list) {
68985 list_del(&de->list);
68986- do_utime(de->name, de->mtime);
68987+ do_utime((char __force_user *)de->name, de->mtime);
68988 kfree(de->name);
68989 kfree(de);
68990 }
68991@@ -281,7 +281,7 @@ static int __init maybe_link(void)
68992 if (nlink >= 2) {
68993 char *old = find_link(major, minor, ino, mode, collected);
68994 if (old)
68995- return (sys_link(old, collected) < 0) ? -1 : 1;
68996+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
68997 }
68998 return 0;
68999 }
69000@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
69001 {
69002 struct stat st;
69003
69004- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
69005+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
69006 if (S_ISDIR(st.st_mode))
69007- sys_rmdir(path);
69008+ sys_rmdir((char __force_user *)path);
69009 else
69010- sys_unlink(path);
69011+ sys_unlink((char __force_user *)path);
69012 }
69013 }
69014
69015@@ -315,7 +315,7 @@ static int __init do_name(void)
69016 int openflags = O_WRONLY|O_CREAT;
69017 if (ml != 1)
69018 openflags |= O_TRUNC;
69019- wfd = sys_open(collected, openflags, mode);
69020+ wfd = sys_open((char __force_user *)collected, openflags, mode);
69021
69022 if (wfd >= 0) {
69023 sys_fchown(wfd, uid, gid);
69024@@ -327,17 +327,17 @@ static int __init do_name(void)
69025 }
69026 }
69027 } else if (S_ISDIR(mode)) {
69028- sys_mkdir(collected, mode);
69029- sys_chown(collected, uid, gid);
69030- sys_chmod(collected, mode);
69031+ sys_mkdir((char __force_user *)collected, mode);
69032+ sys_chown((char __force_user *)collected, uid, gid);
69033+ sys_chmod((char __force_user *)collected, mode);
69034 dir_add(collected, mtime);
69035 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
69036 S_ISFIFO(mode) || S_ISSOCK(mode)) {
69037 if (maybe_link() == 0) {
69038- sys_mknod(collected, mode, rdev);
69039- sys_chown(collected, uid, gid);
69040- sys_chmod(collected, mode);
69041- do_utime(collected, mtime);
69042+ sys_mknod((char __force_user *)collected, mode, rdev);
69043+ sys_chown((char __force_user *)collected, uid, gid);
69044+ sys_chmod((char __force_user *)collected, mode);
69045+ do_utime((char __force_user *)collected, mtime);
69046 }
69047 }
69048 return 0;
69049@@ -346,15 +346,15 @@ static int __init do_name(void)
69050 static int __init do_copy(void)
69051 {
69052 if (count >= body_len) {
69053- sys_write(wfd, victim, body_len);
69054+ sys_write(wfd, (char __force_user *)victim, body_len);
69055 sys_close(wfd);
69056- do_utime(vcollected, mtime);
69057+ do_utime((char __force_user *)vcollected, mtime);
69058 kfree(vcollected);
69059 eat(body_len);
69060 state = SkipIt;
69061 return 0;
69062 } else {
69063- sys_write(wfd, victim, count);
69064+ sys_write(wfd, (char __force_user *)victim, count);
69065 body_len -= count;
69066 eat(count);
69067 return 1;
69068@@ -365,9 +365,9 @@ static int __init do_symlink(void)
69069 {
69070 collected[N_ALIGN(name_len) + body_len] = '\0';
69071 clean_path(collected, 0);
69072- sys_symlink(collected + N_ALIGN(name_len), collected);
69073- sys_lchown(collected, uid, gid);
69074- do_utime(collected, mtime);
69075+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
69076+ sys_lchown((char __force_user *)collected, uid, gid);
69077+ do_utime((char __force_user *)collected, mtime);
69078 state = SkipIt;
69079 next_state = Reset;
69080 return 0;
69081diff --git a/init/main.c b/init/main.c
69082index cee4b5c..47f445e 100644
69083--- a/init/main.c
69084+++ b/init/main.c
69085@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
69086 extern void tc_init(void);
69087 #endif
69088
69089+extern void grsecurity_init(void);
69090+
69091 /*
69092 * Debug helper: via this flag we know that we are in 'early bootup code'
69093 * where only the boot processor is running with IRQ disabled. This means
69094@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
69095
69096 __setup("reset_devices", set_reset_devices);
69097
69098+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
69099+int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
69100+static int __init setup_grsec_proc_gid(char *str)
69101+{
69102+ grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
69103+ return 1;
69104+}
69105+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
69106+#endif
69107+
69108+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
69109+extern char pax_enter_kernel_user[];
69110+extern char pax_exit_kernel_user[];
69111+extern pgdval_t clone_pgd_mask;
69112+#endif
69113+
69114+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
69115+static int __init setup_pax_nouderef(char *str)
69116+{
69117+#ifdef CONFIG_X86_32
69118+ unsigned int cpu;
69119+ struct desc_struct *gdt;
69120+
69121+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
69122+ gdt = get_cpu_gdt_table(cpu);
69123+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
69124+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
69125+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
69126+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
69127+ }
69128+ loadsegment(ds, __KERNEL_DS);
69129+ loadsegment(es, __KERNEL_DS);
69130+ loadsegment(ss, __KERNEL_DS);
69131+#else
69132+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
69133+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
69134+ clone_pgd_mask = ~(pgdval_t)0UL;
69135+#endif
69136+
69137+ return 0;
69138+}
69139+early_param("pax_nouderef", setup_pax_nouderef);
69140+#endif
69141+
69142+#ifdef CONFIG_PAX_SOFTMODE
69143+int pax_softmode;
69144+
69145+static int __init setup_pax_softmode(char *str)
69146+{
69147+ get_option(&str, &pax_softmode);
69148+ return 1;
69149+}
69150+__setup("pax_softmode=", setup_pax_softmode);
69151+#endif
69152+
69153 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
69154 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
69155 static const char *panic_later, *panic_param;
69156@@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
69157 {
69158 int count = preempt_count();
69159 int ret;
69160+ const char *msg1 = "", *msg2 = "";
69161
69162 if (initcall_debug)
69163 ret = do_one_initcall_debug(fn);
69164@@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
69165 sprintf(msgbuf, "error code %d ", ret);
69166
69167 if (preempt_count() != count) {
69168- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
69169+ msg1 = " preemption imbalance";
69170 preempt_count() = count;
69171 }
69172 if (irqs_disabled()) {
69173- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
69174+ msg2 = " disabled interrupts";
69175 local_irq_enable();
69176 }
69177- if (msgbuf[0]) {
69178- printk("initcall %pF returned with %s\n", fn, msgbuf);
69179+ if (msgbuf[0] || *msg1 || *msg2) {
69180+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
69181 }
69182
69183 return ret;
69184@@ -743,6 +801,10 @@ static char *initcall_level_names[] __initdata = {
69185 "late",
69186 };
69187
69188+#ifdef CONFIG_PAX_LATENT_ENTROPY
69189+u64 latent_entropy;
69190+#endif
69191+
69192 static void __init do_initcall_level(int level)
69193 {
69194 extern const struct kernel_param __start___param[], __stop___param[];
69195@@ -755,8 +817,14 @@ static void __init do_initcall_level(int level)
69196 level, level,
69197 &repair_env_string);
69198
69199- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
69200+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
69201 do_one_initcall(*fn);
69202+
69203+#ifdef CONFIG_PAX_LATENT_ENTROPY
69204+ add_device_randomness(&latent_entropy, sizeof(latent_entropy));
69205+#endif
69206+
69207+ }
69208 }
69209
69210 static void __init do_initcalls(void)
69211@@ -790,8 +858,14 @@ static void __init do_pre_smp_initcalls(void)
69212 {
69213 initcall_t *fn;
69214
69215- for (fn = __initcall_start; fn < __initcall0_start; fn++)
69216+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
69217 do_one_initcall(*fn);
69218+
69219+#ifdef CONFIG_PAX_LATENT_ENTROPY
69220+ add_device_randomness(&latent_entropy, sizeof(latent_entropy));
69221+#endif
69222+
69223+ }
69224 }
69225
69226 static int run_init_process(const char *init_filename)
69227@@ -877,7 +951,7 @@ static noinline void __init kernel_init_freeable(void)
69228 do_basic_setup();
69229
69230 /* Open the /dev/console on the rootfs, this should never fail */
69231- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
69232+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
69233 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
69234
69235 (void) sys_dup(0);
69236@@ -890,11 +964,13 @@ static noinline void __init kernel_init_freeable(void)
69237 if (!ramdisk_execute_command)
69238 ramdisk_execute_command = "/init";
69239
69240- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
69241+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
69242 ramdisk_execute_command = NULL;
69243 prepare_namespace();
69244 }
69245
69246+ grsecurity_init();
69247+
69248 /*
69249 * Ok, we have completed the initial bootup, and
69250 * we're essentially up and running. Get rid of the
69251diff --git a/ipc/mqueue.c b/ipc/mqueue.c
69252index 71a3ca1..cc330ee 100644
69253--- a/ipc/mqueue.c
69254+++ b/ipc/mqueue.c
69255@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
69256 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
69257 info->attr.mq_msgsize);
69258
69259+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
69260 spin_lock(&mq_lock);
69261 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
69262 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
69263diff --git a/ipc/msg.c b/ipc/msg.c
69264index 950572f..266c15f 100644
69265--- a/ipc/msg.c
69266+++ b/ipc/msg.c
69267@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
69268 return security_msg_queue_associate(msq, msgflg);
69269 }
69270
69271+static struct ipc_ops msg_ops = {
69272+ .getnew = newque,
69273+ .associate = msg_security,
69274+ .more_checks = NULL
69275+};
69276+
69277 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
69278 {
69279 struct ipc_namespace *ns;
69280- struct ipc_ops msg_ops;
69281 struct ipc_params msg_params;
69282
69283 ns = current->nsproxy->ipc_ns;
69284
69285- msg_ops.getnew = newque;
69286- msg_ops.associate = msg_security;
69287- msg_ops.more_checks = NULL;
69288-
69289 msg_params.key = key;
69290 msg_params.flg = msgflg;
69291
69292diff --git a/ipc/sem.c b/ipc/sem.c
69293index 58d31f1..cce7a55 100644
69294--- a/ipc/sem.c
69295+++ b/ipc/sem.c
69296@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
69297 return 0;
69298 }
69299
69300+static struct ipc_ops sem_ops = {
69301+ .getnew = newary,
69302+ .associate = sem_security,
69303+ .more_checks = sem_more_checks
69304+};
69305+
69306 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
69307 {
69308 struct ipc_namespace *ns;
69309- struct ipc_ops sem_ops;
69310 struct ipc_params sem_params;
69311
69312 ns = current->nsproxy->ipc_ns;
69313@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
69314 if (nsems < 0 || nsems > ns->sc_semmsl)
69315 return -EINVAL;
69316
69317- sem_ops.getnew = newary;
69318- sem_ops.associate = sem_security;
69319- sem_ops.more_checks = sem_more_checks;
69320-
69321 sem_params.key = key;
69322 sem_params.flg = semflg;
69323 sem_params.u.nsems = nsems;
69324diff --git a/ipc/shm.c b/ipc/shm.c
69325index 4fa6d8f..38dfd0c 100644
69326--- a/ipc/shm.c
69327+++ b/ipc/shm.c
69328@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
69329 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
69330 #endif
69331
69332+#ifdef CONFIG_GRKERNSEC
69333+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69334+ const time_t shm_createtime, const uid_t cuid,
69335+ const int shmid);
69336+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69337+ const time_t shm_createtime);
69338+#endif
69339+
69340 void shm_init_ns(struct ipc_namespace *ns)
69341 {
69342 ns->shm_ctlmax = SHMMAX;
69343@@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
69344 shp->shm_lprid = 0;
69345 shp->shm_atim = shp->shm_dtim = 0;
69346 shp->shm_ctim = get_seconds();
69347+#ifdef CONFIG_GRKERNSEC
69348+ {
69349+ struct timespec timeval;
69350+ do_posix_clock_monotonic_gettime(&timeval);
69351+
69352+ shp->shm_createtime = timeval.tv_sec;
69353+ }
69354+#endif
69355 shp->shm_segsz = size;
69356 shp->shm_nattch = 0;
69357 shp->shm_file = file;
69358@@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
69359 return 0;
69360 }
69361
69362+static struct ipc_ops shm_ops = {
69363+ .getnew = newseg,
69364+ .associate = shm_security,
69365+ .more_checks = shm_more_checks
69366+};
69367+
69368 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
69369 {
69370 struct ipc_namespace *ns;
69371- struct ipc_ops shm_ops;
69372 struct ipc_params shm_params;
69373
69374 ns = current->nsproxy->ipc_ns;
69375
69376- shm_ops.getnew = newseg;
69377- shm_ops.associate = shm_security;
69378- shm_ops.more_checks = shm_more_checks;
69379-
69380 shm_params.key = key;
69381 shm_params.flg = shmflg;
69382 shm_params.u.size = size;
69383@@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
69384 f_mode = FMODE_READ | FMODE_WRITE;
69385 }
69386 if (shmflg & SHM_EXEC) {
69387+
69388+#ifdef CONFIG_PAX_MPROTECT
69389+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
69390+ goto out;
69391+#endif
69392+
69393 prot |= PROT_EXEC;
69394 acc_mode |= S_IXUGO;
69395 }
69396@@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
69397 if (err)
69398 goto out_unlock;
69399
69400+#ifdef CONFIG_GRKERNSEC
69401+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
69402+ shp->shm_perm.cuid, shmid) ||
69403+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
69404+ err = -EACCES;
69405+ goto out_unlock;
69406+ }
69407+#endif
69408+
69409 path = shp->shm_file->f_path;
69410 path_get(&path);
69411 shp->shm_nattch++;
69412+#ifdef CONFIG_GRKERNSEC
69413+ shp->shm_lapid = current->pid;
69414+#endif
69415 size = i_size_read(path.dentry->d_inode);
69416 shm_unlock(shp);
69417
69418diff --git a/kernel/acct.c b/kernel/acct.c
69419index 051e071..15e0920 100644
69420--- a/kernel/acct.c
69421+++ b/kernel/acct.c
69422@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
69423 */
69424 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
69425 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
69426- file->f_op->write(file, (char *)&ac,
69427+ file->f_op->write(file, (char __force_user *)&ac,
69428 sizeof(acct_t), &file->f_pos);
69429 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
69430 set_fs(fs);
69431diff --git a/kernel/audit.c b/kernel/audit.c
69432index d596e53..dbef3c3 100644
69433--- a/kernel/audit.c
69434+++ b/kernel/audit.c
69435@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
69436 3) suppressed due to audit_rate_limit
69437 4) suppressed due to audit_backlog_limit
69438 */
69439-static atomic_t audit_lost = ATOMIC_INIT(0);
69440+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
69441
69442 /* The netlink socket. */
69443 static struct sock *audit_sock;
69444@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
69445 unsigned long now;
69446 int print;
69447
69448- atomic_inc(&audit_lost);
69449+ atomic_inc_unchecked(&audit_lost);
69450
69451 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
69452
69453@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
69454 printk(KERN_WARNING
69455 "audit: audit_lost=%d audit_rate_limit=%d "
69456 "audit_backlog_limit=%d\n",
69457- atomic_read(&audit_lost),
69458+ atomic_read_unchecked(&audit_lost),
69459 audit_rate_limit,
69460 audit_backlog_limit);
69461 audit_panic(message);
69462@@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
69463 status_set.pid = audit_pid;
69464 status_set.rate_limit = audit_rate_limit;
69465 status_set.backlog_limit = audit_backlog_limit;
69466- status_set.lost = atomic_read(&audit_lost);
69467+ status_set.lost = atomic_read_unchecked(&audit_lost);
69468 status_set.backlog = skb_queue_len(&audit_skb_queue);
69469 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
69470 &status_set, sizeof(status_set));
69471diff --git a/kernel/auditsc.c b/kernel/auditsc.c
69472index a371f85..da826c1 100644
69473--- a/kernel/auditsc.c
69474+++ b/kernel/auditsc.c
69475@@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
69476 }
69477
69478 /* global counter which is incremented every time something logs in */
69479-static atomic_t session_id = ATOMIC_INIT(0);
69480+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
69481
69482 /**
69483 * audit_set_loginuid - set current task's audit_context loginuid
69484@@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
69485 return -EPERM;
69486 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
69487
69488- sessionid = atomic_inc_return(&session_id);
69489+ sessionid = atomic_inc_return_unchecked(&session_id);
69490 if (context && context->in_syscall) {
69491 struct audit_buffer *ab;
69492
69493diff --git a/kernel/capability.c b/kernel/capability.c
69494index 493d972..f87dfbd 100644
69495--- a/kernel/capability.c
69496+++ b/kernel/capability.c
69497@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
69498 * before modification is attempted and the application
69499 * fails.
69500 */
69501+ if (tocopy > ARRAY_SIZE(kdata))
69502+ return -EFAULT;
69503+
69504 if (copy_to_user(dataptr, kdata, tocopy
69505 * sizeof(struct __user_cap_data_struct))) {
69506 return -EFAULT;
69507@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
69508 int ret;
69509
69510 rcu_read_lock();
69511- ret = security_capable(__task_cred(t), ns, cap);
69512+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
69513+ gr_task_is_capable(t, __task_cred(t), cap);
69514 rcu_read_unlock();
69515
69516- return (ret == 0);
69517+ return ret;
69518 }
69519
69520 /**
69521@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
69522 int ret;
69523
69524 rcu_read_lock();
69525- ret = security_capable_noaudit(__task_cred(t), ns, cap);
69526+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
69527 rcu_read_unlock();
69528
69529- return (ret == 0);
69530+ return ret;
69531 }
69532
69533 /**
69534@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
69535 BUG();
69536 }
69537
69538- if (security_capable(current_cred(), ns, cap) == 0) {
69539+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
69540 current->flags |= PF_SUPERPRIV;
69541 return true;
69542 }
69543@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
69544 }
69545 EXPORT_SYMBOL(ns_capable);
69546
69547+bool ns_capable_nolog(struct user_namespace *ns, int cap)
69548+{
69549+ if (unlikely(!cap_valid(cap))) {
69550+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
69551+ BUG();
69552+ }
69553+
69554+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
69555+ current->flags |= PF_SUPERPRIV;
69556+ return true;
69557+ }
69558+ return false;
69559+}
69560+EXPORT_SYMBOL(ns_capable_nolog);
69561+
69562 /**
69563 * capable - Determine if the current task has a superior capability in effect
69564 * @cap: The capability to be tested for
69565@@ -408,6 +427,12 @@ bool capable(int cap)
69566 }
69567 EXPORT_SYMBOL(capable);
69568
69569+bool capable_nolog(int cap)
69570+{
69571+ return ns_capable_nolog(&init_user_ns, cap);
69572+}
69573+EXPORT_SYMBOL(capable_nolog);
69574+
69575 /**
69576 * nsown_capable - Check superior capability to one's own user_ns
69577 * @cap: The capability in question
69578@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
69579
69580 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
69581 }
69582+
69583+bool inode_capable_nolog(const struct inode *inode, int cap)
69584+{
69585+ struct user_namespace *ns = current_user_ns();
69586+
69587+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
69588+}
69589diff --git a/kernel/cgroup.c b/kernel/cgroup.c
69590index 4855892..30d23b4 100644
69591--- a/kernel/cgroup.c
69592+++ b/kernel/cgroup.c
69593@@ -5535,7 +5535,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
69594 struct css_set *cg = link->cg;
69595 struct task_struct *task;
69596 int count = 0;
69597- seq_printf(seq, "css_set %p\n", cg);
69598+ seq_printf(seq, "css_set %pK\n", cg);
69599 list_for_each_entry(task, &cg->tasks, cg_list) {
69600 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
69601 seq_puts(seq, " ...\n");
69602diff --git a/kernel/compat.c b/kernel/compat.c
69603index 36700e9..73d770c 100644
69604--- a/kernel/compat.c
69605+++ b/kernel/compat.c
69606@@ -13,6 +13,7 @@
69607
69608 #include <linux/linkage.h>
69609 #include <linux/compat.h>
69610+#include <linux/module.h>
69611 #include <linux/errno.h>
69612 #include <linux/time.h>
69613 #include <linux/signal.h>
69614@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
69615 mm_segment_t oldfs;
69616 long ret;
69617
69618- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
69619+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
69620 oldfs = get_fs();
69621 set_fs(KERNEL_DS);
69622 ret = hrtimer_nanosleep_restart(restart);
69623@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
69624 oldfs = get_fs();
69625 set_fs(KERNEL_DS);
69626 ret = hrtimer_nanosleep(&tu,
69627- rmtp ? (struct timespec __user *)&rmt : NULL,
69628+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
69629 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
69630 set_fs(oldfs);
69631
69632@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
69633 mm_segment_t old_fs = get_fs();
69634
69635 set_fs(KERNEL_DS);
69636- ret = sys_sigpending((old_sigset_t __user *) &s);
69637+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
69638 set_fs(old_fs);
69639 if (ret == 0)
69640 ret = put_user(s, set);
69641@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
69642 mm_segment_t old_fs = get_fs();
69643
69644 set_fs(KERNEL_DS);
69645- ret = sys_old_getrlimit(resource, &r);
69646+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
69647 set_fs(old_fs);
69648
69649 if (!ret) {
69650@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
69651 mm_segment_t old_fs = get_fs();
69652
69653 set_fs(KERNEL_DS);
69654- ret = sys_getrusage(who, (struct rusage __user *) &r);
69655+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
69656 set_fs(old_fs);
69657
69658 if (ret)
69659@@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
69660 set_fs (KERNEL_DS);
69661 ret = sys_wait4(pid,
69662 (stat_addr ?
69663- (unsigned int __user *) &status : NULL),
69664- options, (struct rusage __user *) &r);
69665+ (unsigned int __force_user *) &status : NULL),
69666+ options, (struct rusage __force_user *) &r);
69667 set_fs (old_fs);
69668
69669 if (ret > 0) {
69670@@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
69671 memset(&info, 0, sizeof(info));
69672
69673 set_fs(KERNEL_DS);
69674- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
69675- uru ? (struct rusage __user *)&ru : NULL);
69676+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
69677+ uru ? (struct rusage __force_user *)&ru : NULL);
69678 set_fs(old_fs);
69679
69680 if ((ret < 0) || (info.si_signo == 0))
69681@@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
69682 oldfs = get_fs();
69683 set_fs(KERNEL_DS);
69684 err = sys_timer_settime(timer_id, flags,
69685- (struct itimerspec __user *) &newts,
69686- (struct itimerspec __user *) &oldts);
69687+ (struct itimerspec __force_user *) &newts,
69688+ (struct itimerspec __force_user *) &oldts);
69689 set_fs(oldfs);
69690 if (!err && old && put_compat_itimerspec(old, &oldts))
69691 return -EFAULT;
69692@@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
69693 oldfs = get_fs();
69694 set_fs(KERNEL_DS);
69695 err = sys_timer_gettime(timer_id,
69696- (struct itimerspec __user *) &ts);
69697+ (struct itimerspec __force_user *) &ts);
69698 set_fs(oldfs);
69699 if (!err && put_compat_itimerspec(setting, &ts))
69700 return -EFAULT;
69701@@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
69702 oldfs = get_fs();
69703 set_fs(KERNEL_DS);
69704 err = sys_clock_settime(which_clock,
69705- (struct timespec __user *) &ts);
69706+ (struct timespec __force_user *) &ts);
69707 set_fs(oldfs);
69708 return err;
69709 }
69710@@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
69711 oldfs = get_fs();
69712 set_fs(KERNEL_DS);
69713 err = sys_clock_gettime(which_clock,
69714- (struct timespec __user *) &ts);
69715+ (struct timespec __force_user *) &ts);
69716 set_fs(oldfs);
69717 if (!err && put_compat_timespec(&ts, tp))
69718 return -EFAULT;
69719@@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
69720
69721 oldfs = get_fs();
69722 set_fs(KERNEL_DS);
69723- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
69724+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
69725 set_fs(oldfs);
69726
69727 err = compat_put_timex(utp, &txc);
69728@@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
69729 oldfs = get_fs();
69730 set_fs(KERNEL_DS);
69731 err = sys_clock_getres(which_clock,
69732- (struct timespec __user *) &ts);
69733+ (struct timespec __force_user *) &ts);
69734 set_fs(oldfs);
69735 if (!err && tp && put_compat_timespec(&ts, tp))
69736 return -EFAULT;
69737@@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
69738 long err;
69739 mm_segment_t oldfs;
69740 struct timespec tu;
69741- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
69742+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
69743
69744- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
69745+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
69746 oldfs = get_fs();
69747 set_fs(KERNEL_DS);
69748 err = clock_nanosleep_restart(restart);
69749@@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
69750 oldfs = get_fs();
69751 set_fs(KERNEL_DS);
69752 err = sys_clock_nanosleep(which_clock, flags,
69753- (struct timespec __user *) &in,
69754- (struct timespec __user *) &out);
69755+ (struct timespec __force_user *) &in,
69756+ (struct timespec __force_user *) &out);
69757 set_fs(oldfs);
69758
69759 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
69760diff --git a/kernel/configs.c b/kernel/configs.c
69761index 42e8fa0..9e7406b 100644
69762--- a/kernel/configs.c
69763+++ b/kernel/configs.c
69764@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
69765 struct proc_dir_entry *entry;
69766
69767 /* create the current config file */
69768+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
69769+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
69770+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
69771+ &ikconfig_file_ops);
69772+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69773+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
69774+ &ikconfig_file_ops);
69775+#endif
69776+#else
69777 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
69778 &ikconfig_file_ops);
69779+#endif
69780+
69781 if (!entry)
69782 return -ENOMEM;
69783
69784diff --git a/kernel/cred.c b/kernel/cred.c
69785index e0573a4..eefe488 100644
69786--- a/kernel/cred.c
69787+++ b/kernel/cred.c
69788@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
69789 validate_creds(cred);
69790 alter_cred_subscribers(cred, -1);
69791 put_cred(cred);
69792+
69793+#ifdef CONFIG_GRKERNSEC_SETXID
69794+ cred = (struct cred *) tsk->delayed_cred;
69795+ if (cred != NULL) {
69796+ tsk->delayed_cred = NULL;
69797+ validate_creds(cred);
69798+ alter_cred_subscribers(cred, -1);
69799+ put_cred(cred);
69800+ }
69801+#endif
69802 }
69803
69804 /**
69805@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
69806 * Always returns 0 thus allowing this function to be tail-called at the end
69807 * of, say, sys_setgid().
69808 */
69809-int commit_creds(struct cred *new)
69810+static int __commit_creds(struct cred *new)
69811 {
69812 struct task_struct *task = current;
69813 const struct cred *old = task->real_cred;
69814@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
69815
69816 get_cred(new); /* we will require a ref for the subj creds too */
69817
69818+ gr_set_role_label(task, new->uid, new->gid);
69819+
69820 /* dumpability changes */
69821 if (!uid_eq(old->euid, new->euid) ||
69822 !gid_eq(old->egid, new->egid) ||
69823@@ -479,6 +491,101 @@ int commit_creds(struct cred *new)
69824 put_cred(old);
69825 return 0;
69826 }
69827+#ifdef CONFIG_GRKERNSEC_SETXID
69828+extern int set_user(struct cred *new);
69829+
69830+void gr_delayed_cred_worker(void)
69831+{
69832+ const struct cred *new = current->delayed_cred;
69833+ struct cred *ncred;
69834+
69835+ current->delayed_cred = NULL;
69836+
69837+ if (current_uid() && new != NULL) {
69838+ // from doing get_cred on it when queueing this
69839+ put_cred(new);
69840+ return;
69841+ } else if (new == NULL)
69842+ return;
69843+
69844+ ncred = prepare_creds();
69845+ if (!ncred)
69846+ goto die;
69847+ // uids
69848+ ncred->uid = new->uid;
69849+ ncred->euid = new->euid;
69850+ ncred->suid = new->suid;
69851+ ncred->fsuid = new->fsuid;
69852+ // gids
69853+ ncred->gid = new->gid;
69854+ ncred->egid = new->egid;
69855+ ncred->sgid = new->sgid;
69856+ ncred->fsgid = new->fsgid;
69857+ // groups
69858+ if (set_groups(ncred, new->group_info) < 0) {
69859+ abort_creds(ncred);
69860+ goto die;
69861+ }
69862+ // caps
69863+ ncred->securebits = new->securebits;
69864+ ncred->cap_inheritable = new->cap_inheritable;
69865+ ncred->cap_permitted = new->cap_permitted;
69866+ ncred->cap_effective = new->cap_effective;
69867+ ncred->cap_bset = new->cap_bset;
69868+
69869+ if (set_user(ncred)) {
69870+ abort_creds(ncred);
69871+ goto die;
69872+ }
69873+
69874+ // from doing get_cred on it when queueing this
69875+ put_cred(new);
69876+
69877+ __commit_creds(ncred);
69878+ return;
69879+die:
69880+ // from doing get_cred on it when queueing this
69881+ put_cred(new);
69882+ do_group_exit(SIGKILL);
69883+}
69884+#endif
69885+
69886+int commit_creds(struct cred *new)
69887+{
69888+#ifdef CONFIG_GRKERNSEC_SETXID
69889+ int ret;
69890+ int schedule_it = 0;
69891+ struct task_struct *t;
69892+
69893+ /* we won't get called with tasklist_lock held for writing
69894+ and interrupts disabled as the cred struct in that case is
69895+ init_cred
69896+ */
69897+ if (grsec_enable_setxid && !current_is_single_threaded() &&
69898+ !current_uid() && new->uid) {
69899+ schedule_it = 1;
69900+ }
69901+ ret = __commit_creds(new);
69902+ if (schedule_it) {
69903+ rcu_read_lock();
69904+ read_lock(&tasklist_lock);
69905+ for (t = next_thread(current); t != current;
69906+ t = next_thread(t)) {
69907+ if (t->delayed_cred == NULL) {
69908+ t->delayed_cred = get_cred(new);
69909+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
69910+ set_tsk_need_resched(t);
69911+ }
69912+ }
69913+ read_unlock(&tasklist_lock);
69914+ rcu_read_unlock();
69915+ }
69916+ return ret;
69917+#else
69918+ return __commit_creds(new);
69919+#endif
69920+}
69921+
69922 EXPORT_SYMBOL(commit_creds);
69923
69924 /**
69925diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
69926index 9a61738..c5c8f3a 100644
69927--- a/kernel/debug/debug_core.c
69928+++ b/kernel/debug/debug_core.c
69929@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
69930 */
69931 static atomic_t masters_in_kgdb;
69932 static atomic_t slaves_in_kgdb;
69933-static atomic_t kgdb_break_tasklet_var;
69934+static atomic_unchecked_t kgdb_break_tasklet_var;
69935 atomic_t kgdb_setting_breakpoint;
69936
69937 struct task_struct *kgdb_usethread;
69938@@ -132,7 +132,7 @@ int kgdb_single_step;
69939 static pid_t kgdb_sstep_pid;
69940
69941 /* to keep track of the CPU which is doing the single stepping*/
69942-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69943+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69944
69945 /*
69946 * If you are debugging a problem where roundup (the collection of
69947@@ -540,7 +540,7 @@ return_normal:
69948 * kernel will only try for the value of sstep_tries before
69949 * giving up and continuing on.
69950 */
69951- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
69952+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
69953 (kgdb_info[cpu].task &&
69954 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
69955 atomic_set(&kgdb_active, -1);
69956@@ -634,8 +634,8 @@ cpu_master_loop:
69957 }
69958
69959 kgdb_restore:
69960- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
69961- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
69962+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
69963+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
69964 if (kgdb_info[sstep_cpu].task)
69965 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
69966 else
69967@@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
69968 static void kgdb_tasklet_bpt(unsigned long ing)
69969 {
69970 kgdb_breakpoint();
69971- atomic_set(&kgdb_break_tasklet_var, 0);
69972+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
69973 }
69974
69975 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
69976
69977 void kgdb_schedule_breakpoint(void)
69978 {
69979- if (atomic_read(&kgdb_break_tasklet_var) ||
69980+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
69981 atomic_read(&kgdb_active) != -1 ||
69982 atomic_read(&kgdb_setting_breakpoint))
69983 return;
69984- atomic_inc(&kgdb_break_tasklet_var);
69985+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
69986 tasklet_schedule(&kgdb_tasklet_breakpoint);
69987 }
69988 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
69989diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
69990index 8875254..7cf4928 100644
69991--- a/kernel/debug/kdb/kdb_main.c
69992+++ b/kernel/debug/kdb/kdb_main.c
69993@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
69994 continue;
69995
69996 kdb_printf("%-20s%8u 0x%p ", mod->name,
69997- mod->core_size, (void *)mod);
69998+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
69999 #ifdef CONFIG_MODULE_UNLOAD
70000 kdb_printf("%4ld ", module_refcount(mod));
70001 #endif
70002@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
70003 kdb_printf(" (Loading)");
70004 else
70005 kdb_printf(" (Live)");
70006- kdb_printf(" 0x%p", mod->module_core);
70007+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
70008
70009 #ifdef CONFIG_MODULE_UNLOAD
70010 {
70011diff --git a/kernel/events/core.c b/kernel/events/core.c
70012index 7b6646a..3cb1135 100644
70013--- a/kernel/events/core.c
70014+++ b/kernel/events/core.c
70015@@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
70016 return 0;
70017 }
70018
70019-static atomic64_t perf_event_id;
70020+static atomic64_unchecked_t perf_event_id;
70021
70022 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
70023 enum event_type_t event_type);
70024@@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
70025
70026 static inline u64 perf_event_count(struct perf_event *event)
70027 {
70028- return local64_read(&event->count) + atomic64_read(&event->child_count);
70029+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
70030 }
70031
70032 static u64 perf_event_read(struct perf_event *event)
70033@@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
70034 mutex_lock(&event->child_mutex);
70035 total += perf_event_read(event);
70036 *enabled += event->total_time_enabled +
70037- atomic64_read(&event->child_total_time_enabled);
70038+ atomic64_read_unchecked(&event->child_total_time_enabled);
70039 *running += event->total_time_running +
70040- atomic64_read(&event->child_total_time_running);
70041+ atomic64_read_unchecked(&event->child_total_time_running);
70042
70043 list_for_each_entry(child, &event->child_list, child_list) {
70044 total += perf_event_read(child);
70045@@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
70046 userpg->offset -= local64_read(&event->hw.prev_count);
70047
70048 userpg->time_enabled = enabled +
70049- atomic64_read(&event->child_total_time_enabled);
70050+ atomic64_read_unchecked(&event->child_total_time_enabled);
70051
70052 userpg->time_running = running +
70053- atomic64_read(&event->child_total_time_running);
70054+ atomic64_read_unchecked(&event->child_total_time_running);
70055
70056 arch_perf_update_userpage(userpg, now);
70057
70058@@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
70059 values[n++] = perf_event_count(event);
70060 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
70061 values[n++] = enabled +
70062- atomic64_read(&event->child_total_time_enabled);
70063+ atomic64_read_unchecked(&event->child_total_time_enabled);
70064 }
70065 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
70066 values[n++] = running +
70067- atomic64_read(&event->child_total_time_running);
70068+ atomic64_read_unchecked(&event->child_total_time_running);
70069 }
70070 if (read_format & PERF_FORMAT_ID)
70071 values[n++] = primary_event_id(event);
70072@@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
70073 * need to add enough zero bytes after the string to handle
70074 * the 64bit alignment we do later.
70075 */
70076- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
70077+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
70078 if (!buf) {
70079 name = strncpy(tmp, "//enomem", sizeof(tmp));
70080 goto got_name;
70081 }
70082- name = d_path(&file->f_path, buf, PATH_MAX);
70083+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
70084 if (IS_ERR(name)) {
70085 name = strncpy(tmp, "//toolong", sizeof(tmp));
70086 goto got_name;
70087@@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
70088 event->parent = parent_event;
70089
70090 event->ns = get_pid_ns(task_active_pid_ns(current));
70091- event->id = atomic64_inc_return(&perf_event_id);
70092+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
70093
70094 event->state = PERF_EVENT_STATE_INACTIVE;
70095
70096@@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
70097 /*
70098 * Add back the child's count to the parent's count:
70099 */
70100- atomic64_add(child_val, &parent_event->child_count);
70101- atomic64_add(child_event->total_time_enabled,
70102+ atomic64_add_unchecked(child_val, &parent_event->child_count);
70103+ atomic64_add_unchecked(child_event->total_time_enabled,
70104 &parent_event->child_total_time_enabled);
70105- atomic64_add(child_event->total_time_running,
70106+ atomic64_add_unchecked(child_event->total_time_running,
70107 &parent_event->child_total_time_running);
70108
70109 /*
70110diff --git a/kernel/exit.c b/kernel/exit.c
70111index b4df219..f13c02d 100644
70112--- a/kernel/exit.c
70113+++ b/kernel/exit.c
70114@@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
70115 struct task_struct *leader;
70116 int zap_leader;
70117 repeat:
70118+#ifdef CONFIG_NET
70119+ gr_del_task_from_ip_table(p);
70120+#endif
70121+
70122 /* don't need to get the RCU readlock here - the process is dead and
70123 * can't be modifying its own credentials. But shut RCU-lockdep up */
70124 rcu_read_lock();
70125@@ -338,7 +342,7 @@ int allow_signal(int sig)
70126 * know it'll be handled, so that they don't get converted to
70127 * SIGKILL or just silently dropped.
70128 */
70129- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
70130+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
70131 recalc_sigpending();
70132 spin_unlock_irq(&current->sighand->siglock);
70133 return 0;
70134@@ -708,6 +712,8 @@ void do_exit(long code)
70135 struct task_struct *tsk = current;
70136 int group_dead;
70137
70138+ set_fs(USER_DS);
70139+
70140 profile_task_exit(tsk);
70141
70142 WARN_ON(blk_needs_flush_plug(tsk));
70143@@ -724,7 +730,6 @@ void do_exit(long code)
70144 * mm_release()->clear_child_tid() from writing to a user-controlled
70145 * kernel address.
70146 */
70147- set_fs(USER_DS);
70148
70149 ptrace_event(PTRACE_EVENT_EXIT, code);
70150
70151@@ -783,6 +788,9 @@ void do_exit(long code)
70152 tsk->exit_code = code;
70153 taskstats_exit(tsk, group_dead);
70154
70155+ gr_acl_handle_psacct(tsk, code);
70156+ gr_acl_handle_exit();
70157+
70158 exit_mm(tsk);
70159
70160 if (group_dead)
70161@@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
70162 * Take down every thread in the group. This is called by fatal signals
70163 * as well as by sys_exit_group (below).
70164 */
70165-void
70166+__noreturn void
70167 do_group_exit(int exit_code)
70168 {
70169 struct signal_struct *sig = current->signal;
70170diff --git a/kernel/fork.c b/kernel/fork.c
70171index c535f33..1d768f9 100644
70172--- a/kernel/fork.c
70173+++ b/kernel/fork.c
70174@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
70175 *stackend = STACK_END_MAGIC; /* for overflow detection */
70176
70177 #ifdef CONFIG_CC_STACKPROTECTOR
70178- tsk->stack_canary = get_random_int();
70179+ tsk->stack_canary = pax_get_random_long();
70180 #endif
70181
70182 /*
70183@@ -344,13 +344,81 @@ free_tsk:
70184 }
70185
70186 #ifdef CONFIG_MMU
70187+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
70188+{
70189+ struct vm_area_struct *tmp;
70190+ unsigned long charge;
70191+ struct mempolicy *pol;
70192+ struct file *file;
70193+
70194+ charge = 0;
70195+ if (mpnt->vm_flags & VM_ACCOUNT) {
70196+ unsigned long len = vma_pages(mpnt);
70197+
70198+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
70199+ goto fail_nomem;
70200+ charge = len;
70201+ }
70202+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
70203+ if (!tmp)
70204+ goto fail_nomem;
70205+ *tmp = *mpnt;
70206+ tmp->vm_mm = mm;
70207+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
70208+ pol = mpol_dup(vma_policy(mpnt));
70209+ if (IS_ERR(pol))
70210+ goto fail_nomem_policy;
70211+ vma_set_policy(tmp, pol);
70212+ if (anon_vma_fork(tmp, mpnt))
70213+ goto fail_nomem_anon_vma_fork;
70214+ tmp->vm_flags &= ~VM_LOCKED;
70215+ tmp->vm_next = tmp->vm_prev = NULL;
70216+ tmp->vm_mirror = NULL;
70217+ file = tmp->vm_file;
70218+ if (file) {
70219+ struct inode *inode = file->f_path.dentry->d_inode;
70220+ struct address_space *mapping = file->f_mapping;
70221+
70222+ get_file(file);
70223+ if (tmp->vm_flags & VM_DENYWRITE)
70224+ atomic_dec(&inode->i_writecount);
70225+ mutex_lock(&mapping->i_mmap_mutex);
70226+ if (tmp->vm_flags & VM_SHARED)
70227+ mapping->i_mmap_writable++;
70228+ flush_dcache_mmap_lock(mapping);
70229+ /* insert tmp into the share list, just after mpnt */
70230+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
70231+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
70232+ else
70233+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
70234+ flush_dcache_mmap_unlock(mapping);
70235+ mutex_unlock(&mapping->i_mmap_mutex);
70236+ }
70237+
70238+ /*
70239+ * Clear hugetlb-related page reserves for children. This only
70240+ * affects MAP_PRIVATE mappings. Faults generated by the child
70241+ * are not guaranteed to succeed, even if read-only
70242+ */
70243+ if (is_vm_hugetlb_page(tmp))
70244+ reset_vma_resv_huge_pages(tmp);
70245+
70246+ return tmp;
70247+
70248+fail_nomem_anon_vma_fork:
70249+ mpol_put(pol);
70250+fail_nomem_policy:
70251+ kmem_cache_free(vm_area_cachep, tmp);
70252+fail_nomem:
70253+ vm_unacct_memory(charge);
70254+ return NULL;
70255+}
70256+
70257 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70258 {
70259 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
70260 struct rb_node **rb_link, *rb_parent;
70261 int retval;
70262- unsigned long charge;
70263- struct mempolicy *pol;
70264
70265 uprobe_start_dup_mmap();
70266 down_write(&oldmm->mmap_sem);
70267@@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70268 mm->locked_vm = 0;
70269 mm->mmap = NULL;
70270 mm->mmap_cache = NULL;
70271- mm->free_area_cache = oldmm->mmap_base;
70272- mm->cached_hole_size = ~0UL;
70273+ mm->free_area_cache = oldmm->free_area_cache;
70274+ mm->cached_hole_size = oldmm->cached_hole_size;
70275 mm->map_count = 0;
70276 cpumask_clear(mm_cpumask(mm));
70277 mm->mm_rb = RB_ROOT;
70278@@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70279
70280 prev = NULL;
70281 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
70282- struct file *file;
70283-
70284 if (mpnt->vm_flags & VM_DONTCOPY) {
70285 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
70286 -vma_pages(mpnt));
70287 continue;
70288 }
70289- charge = 0;
70290- if (mpnt->vm_flags & VM_ACCOUNT) {
70291- unsigned long len = vma_pages(mpnt);
70292-
70293- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
70294- goto fail_nomem;
70295- charge = len;
70296- }
70297- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
70298- if (!tmp)
70299- goto fail_nomem;
70300- *tmp = *mpnt;
70301- INIT_LIST_HEAD(&tmp->anon_vma_chain);
70302- pol = mpol_dup(vma_policy(mpnt));
70303- retval = PTR_ERR(pol);
70304- if (IS_ERR(pol))
70305- goto fail_nomem_policy;
70306- vma_set_policy(tmp, pol);
70307- tmp->vm_mm = mm;
70308- if (anon_vma_fork(tmp, mpnt))
70309- goto fail_nomem_anon_vma_fork;
70310- tmp->vm_flags &= ~VM_LOCKED;
70311- tmp->vm_next = tmp->vm_prev = NULL;
70312- file = tmp->vm_file;
70313- if (file) {
70314- struct inode *inode = file->f_path.dentry->d_inode;
70315- struct address_space *mapping = file->f_mapping;
70316-
70317- get_file(file);
70318- if (tmp->vm_flags & VM_DENYWRITE)
70319- atomic_dec(&inode->i_writecount);
70320- mutex_lock(&mapping->i_mmap_mutex);
70321- if (tmp->vm_flags & VM_SHARED)
70322- mapping->i_mmap_writable++;
70323- flush_dcache_mmap_lock(mapping);
70324- /* insert tmp into the share list, just after mpnt */
70325- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
70326- vma_nonlinear_insert(tmp,
70327- &mapping->i_mmap_nonlinear);
70328- else
70329- vma_interval_tree_insert_after(tmp, mpnt,
70330- &mapping->i_mmap);
70331- flush_dcache_mmap_unlock(mapping);
70332- mutex_unlock(&mapping->i_mmap_mutex);
70333+ tmp = dup_vma(mm, oldmm, mpnt);
70334+ if (!tmp) {
70335+ retval = -ENOMEM;
70336+ goto out;
70337 }
70338
70339 /*
70340@@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70341 if (retval)
70342 goto out;
70343 }
70344+
70345+#ifdef CONFIG_PAX_SEGMEXEC
70346+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
70347+ struct vm_area_struct *mpnt_m;
70348+
70349+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
70350+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
70351+
70352+ if (!mpnt->vm_mirror)
70353+ continue;
70354+
70355+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
70356+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
70357+ mpnt->vm_mirror = mpnt_m;
70358+ } else {
70359+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
70360+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
70361+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
70362+ mpnt->vm_mirror->vm_mirror = mpnt;
70363+ }
70364+ }
70365+ BUG_ON(mpnt_m);
70366+ }
70367+#endif
70368+
70369 /* a new mm has just been created */
70370 arch_dup_mmap(oldmm, mm);
70371 retval = 0;
70372@@ -472,14 +523,6 @@ out:
70373 up_write(&oldmm->mmap_sem);
70374 uprobe_end_dup_mmap();
70375 return retval;
70376-fail_nomem_anon_vma_fork:
70377- mpol_put(pol);
70378-fail_nomem_policy:
70379- kmem_cache_free(vm_area_cachep, tmp);
70380-fail_nomem:
70381- retval = -ENOMEM;
70382- vm_unacct_memory(charge);
70383- goto out;
70384 }
70385
70386 static inline int mm_alloc_pgd(struct mm_struct *mm)
70387@@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
70388 return ERR_PTR(err);
70389
70390 mm = get_task_mm(task);
70391- if (mm && mm != current->mm &&
70392- !ptrace_may_access(task, mode)) {
70393+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
70394+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
70395 mmput(mm);
70396 mm = ERR_PTR(-EACCES);
70397 }
70398@@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
70399 spin_unlock(&fs->lock);
70400 return -EAGAIN;
70401 }
70402- fs->users++;
70403+ atomic_inc(&fs->users);
70404 spin_unlock(&fs->lock);
70405 return 0;
70406 }
70407 tsk->fs = copy_fs_struct(fs);
70408 if (!tsk->fs)
70409 return -ENOMEM;
70410+ /* Carry through gr_chroot_dentry and is_chrooted instead
70411+ of recomputing it here. Already copied when the task struct
70412+ is duplicated. This allows pivot_root to not be treated as
70413+ a chroot
70414+ */
70415+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
70416+
70417 return 0;
70418 }
70419
70420@@ -1193,6 +1243,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
70421 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
70422 #endif
70423 retval = -EAGAIN;
70424+
70425+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
70426+
70427 if (atomic_read(&p->real_cred->user->processes) >=
70428 task_rlimit(p, RLIMIT_NPROC)) {
70429 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
70430@@ -1432,6 +1485,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
70431 goto bad_fork_free_pid;
70432 }
70433
70434+ /* synchronizes with gr_set_acls()
70435+ we need to call this past the point of no return for fork()
70436+ */
70437+ gr_copy_label(p);
70438+
70439 if (clone_flags & CLONE_THREAD) {
70440 current->signal->nr_threads++;
70441 atomic_inc(&current->signal->live);
70442@@ -1515,6 +1573,8 @@ bad_fork_cleanup_count:
70443 bad_fork_free:
70444 free_task(p);
70445 fork_out:
70446+ gr_log_forkfail(retval);
70447+
70448 return ERR_PTR(retval);
70449 }
70450
70451@@ -1565,6 +1625,23 @@ long do_fork(unsigned long clone_flags,
70452 return -EINVAL;
70453 }
70454
70455+#ifdef CONFIG_GRKERNSEC
70456+ if (clone_flags & CLONE_NEWUSER) {
70457+ /*
70458+ * This doesn't really inspire confidence:
70459+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
70460+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
70461+ * Increases kernel attack surface in areas developers
70462+ * previously cared little about ("low importance due
70463+ * to requiring "root" capability")
70464+ * To be removed when this code receives *proper* review
70465+ */
70466+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
70467+ !capable(CAP_SETGID))
70468+ return -EPERM;
70469+ }
70470+#endif
70471+
70472 /*
70473 * Determine whether and which event to report to ptracer. When
70474 * called from kernel_thread or CLONE_UNTRACED is explicitly
70475@@ -1599,6 +1676,8 @@ long do_fork(unsigned long clone_flags,
70476 if (clone_flags & CLONE_PARENT_SETTID)
70477 put_user(nr, parent_tidptr);
70478
70479+ gr_handle_brute_check();
70480+
70481 if (clone_flags & CLONE_VFORK) {
70482 p->vfork_done = &vfork;
70483 init_completion(&vfork);
70484@@ -1752,7 +1831,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
70485 return 0;
70486
70487 /* don't need lock here; in the worst case we'll do useless copy */
70488- if (fs->users == 1)
70489+ if (atomic_read(&fs->users) == 1)
70490 return 0;
70491
70492 *new_fsp = copy_fs_struct(fs);
70493@@ -1866,7 +1945,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
70494 fs = current->fs;
70495 spin_lock(&fs->lock);
70496 current->fs = new_fs;
70497- if (--fs->users)
70498+ gr_set_chroot_entries(current, &current->fs->root);
70499+ if (atomic_dec_return(&fs->users))
70500 new_fs = NULL;
70501 else
70502 new_fs = fs;
70503diff --git a/kernel/futex.c b/kernel/futex.c
70504index 19eb089..b8c65ea 100644
70505--- a/kernel/futex.c
70506+++ b/kernel/futex.c
70507@@ -54,6 +54,7 @@
70508 #include <linux/mount.h>
70509 #include <linux/pagemap.h>
70510 #include <linux/syscalls.h>
70511+#include <linux/ptrace.h>
70512 #include <linux/signal.h>
70513 #include <linux/export.h>
70514 #include <linux/magic.h>
70515@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
70516 struct page *page, *page_head;
70517 int err, ro = 0;
70518
70519+#ifdef CONFIG_PAX_SEGMEXEC
70520+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
70521+ return -EFAULT;
70522+#endif
70523+
70524 /*
70525 * The futex address must be "naturally" aligned.
70526 */
70527@@ -2733,6 +2739,7 @@ static int __init futex_init(void)
70528 {
70529 u32 curval;
70530 int i;
70531+ mm_segment_t oldfs;
70532
70533 /*
70534 * This will fail and we want it. Some arch implementations do
70535@@ -2744,8 +2751,11 @@ static int __init futex_init(void)
70536 * implementation, the non-functional ones will return
70537 * -ENOSYS.
70538 */
70539+ oldfs = get_fs();
70540+ set_fs(USER_DS);
70541 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
70542 futex_cmpxchg_enabled = 1;
70543+ set_fs(oldfs);
70544
70545 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
70546 plist_head_init(&futex_queues[i].chain);
70547diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
70548index 9b22d03..6295b62 100644
70549--- a/kernel/gcov/base.c
70550+++ b/kernel/gcov/base.c
70551@@ -102,11 +102,6 @@ void gcov_enable_events(void)
70552 }
70553
70554 #ifdef CONFIG_MODULES
70555-static inline int within(void *addr, void *start, unsigned long size)
70556-{
70557- return ((addr >= start) && (addr < start + size));
70558-}
70559-
70560 /* Update list and generate events when modules are unloaded. */
70561 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
70562 void *data)
70563@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
70564 prev = NULL;
70565 /* Remove entries located in module from linked list. */
70566 for (info = gcov_info_head; info; info = info->next) {
70567- if (within(info, mod->module_core, mod->core_size)) {
70568+ if (within_module_core_rw((unsigned long)info, mod)) {
70569 if (prev)
70570 prev->next = info->next;
70571 else
70572diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
70573index 6db7a5e..0d600bd 100644
70574--- a/kernel/hrtimer.c
70575+++ b/kernel/hrtimer.c
70576@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
70577 local_irq_restore(flags);
70578 }
70579
70580-static void run_hrtimer_softirq(struct softirq_action *h)
70581+static void run_hrtimer_softirq(void)
70582 {
70583 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
70584
70585@@ -1751,7 +1751,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
70586 return NOTIFY_OK;
70587 }
70588
70589-static struct notifier_block __cpuinitdata hrtimers_nb = {
70590+static struct notifier_block hrtimers_nb = {
70591 .notifier_call = hrtimer_cpu_notify,
70592 };
70593
70594diff --git a/kernel/jump_label.c b/kernel/jump_label.c
70595index 60f48fa..7f3a770 100644
70596--- a/kernel/jump_label.c
70597+++ b/kernel/jump_label.c
70598@@ -13,6 +13,7 @@
70599 #include <linux/sort.h>
70600 #include <linux/err.h>
70601 #include <linux/static_key.h>
70602+#include <linux/mm.h>
70603
70604 #ifdef HAVE_JUMP_LABEL
70605
70606@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
70607
70608 size = (((unsigned long)stop - (unsigned long)start)
70609 / sizeof(struct jump_entry));
70610+ pax_open_kernel();
70611 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
70612+ pax_close_kernel();
70613 }
70614
70615 static void jump_label_update(struct static_key *key, int enable);
70616@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
70617 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
70618 struct jump_entry *iter;
70619
70620+ pax_open_kernel();
70621 for (iter = iter_start; iter < iter_stop; iter++) {
70622 if (within_module_init(iter->code, mod))
70623 iter->code = 0;
70624 }
70625+ pax_close_kernel();
70626 }
70627
70628 static int
70629diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
70630index 2169fee..45c017a 100644
70631--- a/kernel/kallsyms.c
70632+++ b/kernel/kallsyms.c
70633@@ -11,6 +11,9 @@
70634 * Changed the compression method from stem compression to "table lookup"
70635 * compression (see scripts/kallsyms.c for a more complete description)
70636 */
70637+#ifdef CONFIG_GRKERNSEC_HIDESYM
70638+#define __INCLUDED_BY_HIDESYM 1
70639+#endif
70640 #include <linux/kallsyms.h>
70641 #include <linux/module.h>
70642 #include <linux/init.h>
70643@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
70644
70645 static inline int is_kernel_inittext(unsigned long addr)
70646 {
70647+ if (system_state != SYSTEM_BOOTING)
70648+ return 0;
70649+
70650 if (addr >= (unsigned long)_sinittext
70651 && addr <= (unsigned long)_einittext)
70652 return 1;
70653 return 0;
70654 }
70655
70656+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70657+#ifdef CONFIG_MODULES
70658+static inline int is_module_text(unsigned long addr)
70659+{
70660+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
70661+ return 1;
70662+
70663+ addr = ktla_ktva(addr);
70664+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
70665+}
70666+#else
70667+static inline int is_module_text(unsigned long addr)
70668+{
70669+ return 0;
70670+}
70671+#endif
70672+#endif
70673+
70674 static inline int is_kernel_text(unsigned long addr)
70675 {
70676 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
70677@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
70678
70679 static inline int is_kernel(unsigned long addr)
70680 {
70681+
70682+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70683+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
70684+ return 1;
70685+
70686+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
70687+#else
70688 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
70689+#endif
70690+
70691 return 1;
70692 return in_gate_area_no_mm(addr);
70693 }
70694
70695 static int is_ksym_addr(unsigned long addr)
70696 {
70697+
70698+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70699+ if (is_module_text(addr))
70700+ return 0;
70701+#endif
70702+
70703 if (all_var)
70704 return is_kernel(addr);
70705
70706@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
70707
70708 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
70709 {
70710- iter->name[0] = '\0';
70711 iter->nameoff = get_symbol_offset(new_pos);
70712 iter->pos = new_pos;
70713 }
70714@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
70715 {
70716 struct kallsym_iter *iter = m->private;
70717
70718+#ifdef CONFIG_GRKERNSEC_HIDESYM
70719+ if (current_uid())
70720+ return 0;
70721+#endif
70722+
70723 /* Some debugging symbols have no name. Ignore them. */
70724 if (!iter->name[0])
70725 return 0;
70726@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
70727 */
70728 type = iter->exported ? toupper(iter->type) :
70729 tolower(iter->type);
70730+
70731 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
70732 type, iter->name, iter->module_name);
70733 } else
70734@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
70735 struct kallsym_iter *iter;
70736 int ret;
70737
70738- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
70739+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
70740 if (!iter)
70741 return -ENOMEM;
70742 reset_iter(iter, 0);
70743diff --git a/kernel/kcmp.c b/kernel/kcmp.c
70744index e30ac0f..3528cac 100644
70745--- a/kernel/kcmp.c
70746+++ b/kernel/kcmp.c
70747@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
70748 struct task_struct *task1, *task2;
70749 int ret;
70750
70751+#ifdef CONFIG_GRKERNSEC
70752+ return -ENOSYS;
70753+#endif
70754+
70755 rcu_read_lock();
70756
70757 /*
70758diff --git a/kernel/kexec.c b/kernel/kexec.c
70759index 5e4bd78..00c5b91 100644
70760--- a/kernel/kexec.c
70761+++ b/kernel/kexec.c
70762@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
70763 unsigned long flags)
70764 {
70765 struct compat_kexec_segment in;
70766- struct kexec_segment out, __user *ksegments;
70767+ struct kexec_segment out;
70768+ struct kexec_segment __user *ksegments;
70769 unsigned long i, result;
70770
70771 /* Don't allow clients that don't understand the native
70772diff --git a/kernel/kmod.c b/kernel/kmod.c
70773index 0023a87..3fe3781 100644
70774--- a/kernel/kmod.c
70775+++ b/kernel/kmod.c
70776@@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
70777 kfree(info->argv);
70778 }
70779
70780-static int call_modprobe(char *module_name, int wait)
70781+static int call_modprobe(char *module_name, char *module_param, int wait)
70782 {
70783 static char *envp[] = {
70784 "HOME=/",
70785@@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
70786 NULL
70787 };
70788
70789- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
70790+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
70791 if (!argv)
70792 goto out;
70793
70794@@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
70795 argv[1] = "-q";
70796 argv[2] = "--";
70797 argv[3] = module_name; /* check free_modprobe_argv() */
70798- argv[4] = NULL;
70799+ argv[4] = module_param;
70800+ argv[5] = NULL;
70801
70802 return call_usermodehelper_fns(modprobe_path, argv, envp,
70803 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
70804@@ -120,9 +121,8 @@ out:
70805 * If module auto-loading support is disabled then this function
70806 * becomes a no-operation.
70807 */
70808-int __request_module(bool wait, const char *fmt, ...)
70809+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
70810 {
70811- va_list args;
70812 char module_name[MODULE_NAME_LEN];
70813 unsigned int max_modprobes;
70814 int ret;
70815@@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
70816 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
70817 static int kmod_loop_msg;
70818
70819- va_start(args, fmt);
70820- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
70821- va_end(args);
70822+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
70823 if (ret >= MODULE_NAME_LEN)
70824 return -ENAMETOOLONG;
70825
70826@@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
70827 if (ret)
70828 return ret;
70829
70830+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70831+ if (!current_uid()) {
70832+ /* hack to workaround consolekit/udisks stupidity */
70833+ read_lock(&tasklist_lock);
70834+ if (!strcmp(current->comm, "mount") &&
70835+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
70836+ read_unlock(&tasklist_lock);
70837+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
70838+ return -EPERM;
70839+ }
70840+ read_unlock(&tasklist_lock);
70841+ }
70842+#endif
70843+
70844 /* If modprobe needs a service that is in a module, we get a recursive
70845 * loop. Limit the number of running kmod threads to max_threads/2 or
70846 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
70847@@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
70848
70849 trace_module_request(module_name, wait, _RET_IP_);
70850
70851- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
70852+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
70853
70854 atomic_dec(&kmod_concurrent);
70855 return ret;
70856 }
70857+
70858+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
70859+{
70860+ va_list args;
70861+ int ret;
70862+
70863+ va_start(args, fmt);
70864+ ret = ____request_module(wait, module_param, fmt, args);
70865+ va_end(args);
70866+
70867+ return ret;
70868+}
70869+
70870+int __request_module(bool wait, const char *fmt, ...)
70871+{
70872+ va_list args;
70873+ int ret;
70874+
70875+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70876+ if (current_uid()) {
70877+ char module_param[MODULE_NAME_LEN];
70878+
70879+ memset(module_param, 0, sizeof(module_param));
70880+
70881+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
70882+
70883+ va_start(args, fmt);
70884+ ret = ____request_module(wait, module_param, fmt, args);
70885+ va_end(args);
70886+
70887+ return ret;
70888+ }
70889+#endif
70890+
70891+ va_start(args, fmt);
70892+ ret = ____request_module(wait, NULL, fmt, args);
70893+ va_end(args);
70894+
70895+ return ret;
70896+}
70897+
70898 EXPORT_SYMBOL(__request_module);
70899 #endif /* CONFIG_MODULES */
70900
70901@@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
70902 *
70903 * Thus the __user pointer cast is valid here.
70904 */
70905- sys_wait4(pid, (int __user *)&ret, 0, NULL);
70906+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
70907
70908 /*
70909 * If ret is 0, either ____call_usermodehelper failed and the
70910diff --git a/kernel/kprobes.c b/kernel/kprobes.c
70911index 098f396..fe85ff1 100644
70912--- a/kernel/kprobes.c
70913+++ b/kernel/kprobes.c
70914@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
70915 * kernel image and loaded module images reside. This is required
70916 * so x86_64 can correctly handle the %rip-relative fixups.
70917 */
70918- kip->insns = module_alloc(PAGE_SIZE);
70919+ kip->insns = module_alloc_exec(PAGE_SIZE);
70920 if (!kip->insns) {
70921 kfree(kip);
70922 return NULL;
70923@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
70924 */
70925 if (!list_is_singular(&kip->list)) {
70926 list_del(&kip->list);
70927- module_free(NULL, kip->insns);
70928+ module_free_exec(NULL, kip->insns);
70929 kfree(kip);
70930 }
70931 return 1;
70932@@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
70933 {
70934 int i, err = 0;
70935 unsigned long offset = 0, size = 0;
70936- char *modname, namebuf[128];
70937+ char *modname, namebuf[KSYM_NAME_LEN];
70938 const char *symbol_name;
70939 void *addr;
70940 struct kprobe_blackpoint *kb;
70941@@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
70942 kprobe_type = "k";
70943
70944 if (sym)
70945- seq_printf(pi, "%p %s %s+0x%x %s ",
70946+ seq_printf(pi, "%pK %s %s+0x%x %s ",
70947 p->addr, kprobe_type, sym, offset,
70948 (modname ? modname : " "));
70949 else
70950- seq_printf(pi, "%p %s %p ",
70951+ seq_printf(pi, "%pK %s %pK ",
70952 p->addr, kprobe_type, p->addr);
70953
70954 if (!pp)
70955@@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
70956 const char *sym = NULL;
70957 unsigned int i = *(loff_t *) v;
70958 unsigned long offset = 0;
70959- char *modname, namebuf[128];
70960+ char *modname, namebuf[KSYM_NAME_LEN];
70961
70962 head = &kprobe_table[i];
70963 preempt_disable();
70964diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
70965index 6ada93c..55baf4d 100644
70966--- a/kernel/ksysfs.c
70967+++ b/kernel/ksysfs.c
70968@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
70969 {
70970 if (count+1 > UEVENT_HELPER_PATH_LEN)
70971 return -ENOENT;
70972+ if (!capable(CAP_SYS_ADMIN))
70973+ return -EPERM;
70974 memcpy(uevent_helper, buf, count);
70975 uevent_helper[count] = '\0';
70976 if (count && uevent_helper[count-1] == '\n')
70977diff --git a/kernel/lockdep.c b/kernel/lockdep.c
70978index 7981e5b..7f2105c 100644
70979--- a/kernel/lockdep.c
70980+++ b/kernel/lockdep.c
70981@@ -590,6 +590,10 @@ static int static_obj(void *obj)
70982 end = (unsigned long) &_end,
70983 addr = (unsigned long) obj;
70984
70985+#ifdef CONFIG_PAX_KERNEXEC
70986+ start = ktla_ktva(start);
70987+#endif
70988+
70989 /*
70990 * static variable?
70991 */
70992@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
70993 if (!static_obj(lock->key)) {
70994 debug_locks_off();
70995 printk("INFO: trying to register non-static key.\n");
70996+ printk("lock:%pS key:%pS.\n", lock, lock->key);
70997 printk("the code is fine but needs lockdep annotation.\n");
70998 printk("turning off the locking correctness validator.\n");
70999 dump_stack();
71000@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
71001 if (!class)
71002 return 0;
71003 }
71004- atomic_inc((atomic_t *)&class->ops);
71005+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
71006 if (very_verbose(class)) {
71007 printk("\nacquire class [%p] %s", class->key, class->name);
71008 if (class->name_version > 1)
71009diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
71010index b2c71c5..7b88d63 100644
71011--- a/kernel/lockdep_proc.c
71012+++ b/kernel/lockdep_proc.c
71013@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
71014 return 0;
71015 }
71016
71017- seq_printf(m, "%p", class->key);
71018+ seq_printf(m, "%pK", class->key);
71019 #ifdef CONFIG_DEBUG_LOCKDEP
71020 seq_printf(m, " OPS:%8ld", class->ops);
71021 #endif
71022@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
71023
71024 list_for_each_entry(entry, &class->locks_after, entry) {
71025 if (entry->distance == 1) {
71026- seq_printf(m, " -> [%p] ", entry->class->key);
71027+ seq_printf(m, " -> [%pK] ", entry->class->key);
71028 print_name(m, entry->class);
71029 seq_puts(m, "\n");
71030 }
71031@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
71032 if (!class->key)
71033 continue;
71034
71035- seq_printf(m, "[%p] ", class->key);
71036+ seq_printf(m, "[%pK] ", class->key);
71037 print_name(m, class);
71038 seq_puts(m, "\n");
71039 }
71040@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
71041 if (!i)
71042 seq_line(m, '-', 40-namelen, namelen);
71043
71044- snprintf(ip, sizeof(ip), "[<%p>]",
71045+ snprintf(ip, sizeof(ip), "[<%pK>]",
71046 (void *)class->contention_point[i]);
71047 seq_printf(m, "%40s %14lu %29s %pS\n",
71048 name, stats->contention_point[i],
71049@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
71050 if (!i)
71051 seq_line(m, '-', 40-namelen, namelen);
71052
71053- snprintf(ip, sizeof(ip), "[<%p>]",
71054+ snprintf(ip, sizeof(ip), "[<%pK>]",
71055 (void *)class->contending_point[i]);
71056 seq_printf(m, "%40s %14lu %29s %pS\n",
71057 name, stats->contending_point[i],
71058diff --git a/kernel/module.c b/kernel/module.c
71059index eab0827..75ede66 100644
71060--- a/kernel/module.c
71061+++ b/kernel/module.c
71062@@ -61,6 +61,7 @@
71063 #include <linux/pfn.h>
71064 #include <linux/bsearch.h>
71065 #include <linux/fips.h>
71066+#include <linux/grsecurity.h>
71067 #include <uapi/linux/module.h>
71068 #include "module-internal.h"
71069
71070@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
71071
71072 /* Bounds of module allocation, for speeding __module_address.
71073 * Protected by module_mutex. */
71074-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
71075+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
71076+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
71077
71078 int register_module_notifier(struct notifier_block * nb)
71079 {
71080@@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
71081 return true;
71082
71083 list_for_each_entry_rcu(mod, &modules, list) {
71084- struct symsearch arr[] = {
71085+ struct symsearch modarr[] = {
71086 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
71087 NOT_GPL_ONLY, false },
71088 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
71089@@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
71090 if (mod->state == MODULE_STATE_UNFORMED)
71091 continue;
71092
71093- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
71094+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
71095 return true;
71096 }
71097 return false;
71098@@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
71099 static int percpu_modalloc(struct module *mod,
71100 unsigned long size, unsigned long align)
71101 {
71102- if (align > PAGE_SIZE) {
71103+ if (align-1 >= PAGE_SIZE) {
71104 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
71105 mod->name, align, PAGE_SIZE);
71106 align = PAGE_SIZE;
71107@@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
71108 static ssize_t show_coresize(struct module_attribute *mattr,
71109 struct module_kobject *mk, char *buffer)
71110 {
71111- return sprintf(buffer, "%u\n", mk->mod->core_size);
71112+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
71113 }
71114
71115 static struct module_attribute modinfo_coresize =
71116@@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
71117 static ssize_t show_initsize(struct module_attribute *mattr,
71118 struct module_kobject *mk, char *buffer)
71119 {
71120- return sprintf(buffer, "%u\n", mk->mod->init_size);
71121+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
71122 }
71123
71124 static struct module_attribute modinfo_initsize =
71125@@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
71126 */
71127 #ifdef CONFIG_SYSFS
71128
71129-#ifdef CONFIG_KALLSYMS
71130+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
71131 static inline bool sect_empty(const Elf_Shdr *sect)
71132 {
71133 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
71134@@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
71135
71136 static void unset_module_core_ro_nx(struct module *mod)
71137 {
71138- set_page_attributes(mod->module_core + mod->core_text_size,
71139- mod->module_core + mod->core_size,
71140+ set_page_attributes(mod->module_core_rw,
71141+ mod->module_core_rw + mod->core_size_rw,
71142 set_memory_x);
71143- set_page_attributes(mod->module_core,
71144- mod->module_core + mod->core_ro_size,
71145+ set_page_attributes(mod->module_core_rx,
71146+ mod->module_core_rx + mod->core_size_rx,
71147 set_memory_rw);
71148 }
71149
71150 static void unset_module_init_ro_nx(struct module *mod)
71151 {
71152- set_page_attributes(mod->module_init + mod->init_text_size,
71153- mod->module_init + mod->init_size,
71154+ set_page_attributes(mod->module_init_rw,
71155+ mod->module_init_rw + mod->init_size_rw,
71156 set_memory_x);
71157- set_page_attributes(mod->module_init,
71158- mod->module_init + mod->init_ro_size,
71159+ set_page_attributes(mod->module_init_rx,
71160+ mod->module_init_rx + mod->init_size_rx,
71161 set_memory_rw);
71162 }
71163
71164@@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
71165 list_for_each_entry_rcu(mod, &modules, list) {
71166 if (mod->state == MODULE_STATE_UNFORMED)
71167 continue;
71168- if ((mod->module_core) && (mod->core_text_size)) {
71169- set_page_attributes(mod->module_core,
71170- mod->module_core + mod->core_text_size,
71171+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
71172+ set_page_attributes(mod->module_core_rx,
71173+ mod->module_core_rx + mod->core_size_rx,
71174 set_memory_rw);
71175 }
71176- if ((mod->module_init) && (mod->init_text_size)) {
71177- set_page_attributes(mod->module_init,
71178- mod->module_init + mod->init_text_size,
71179+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
71180+ set_page_attributes(mod->module_init_rx,
71181+ mod->module_init_rx + mod->init_size_rx,
71182 set_memory_rw);
71183 }
71184 }
71185@@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
71186 list_for_each_entry_rcu(mod, &modules, list) {
71187 if (mod->state == MODULE_STATE_UNFORMED)
71188 continue;
71189- if ((mod->module_core) && (mod->core_text_size)) {
71190- set_page_attributes(mod->module_core,
71191- mod->module_core + mod->core_text_size,
71192+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
71193+ set_page_attributes(mod->module_core_rx,
71194+ mod->module_core_rx + mod->core_size_rx,
71195 set_memory_ro);
71196 }
71197- if ((mod->module_init) && (mod->init_text_size)) {
71198- set_page_attributes(mod->module_init,
71199- mod->module_init + mod->init_text_size,
71200+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
71201+ set_page_attributes(mod->module_init_rx,
71202+ mod->module_init_rx + mod->init_size_rx,
71203 set_memory_ro);
71204 }
71205 }
71206@@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
71207
71208 /* This may be NULL, but that's OK */
71209 unset_module_init_ro_nx(mod);
71210- module_free(mod, mod->module_init);
71211+ module_free(mod, mod->module_init_rw);
71212+ module_free_exec(mod, mod->module_init_rx);
71213 kfree(mod->args);
71214 percpu_modfree(mod);
71215
71216 /* Free lock-classes: */
71217- lockdep_free_key_range(mod->module_core, mod->core_size);
71218+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
71219+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
71220
71221 /* Finally, free the core (containing the module structure) */
71222 unset_module_core_ro_nx(mod);
71223- module_free(mod, mod->module_core);
71224+ module_free_exec(mod, mod->module_core_rx);
71225+ module_free(mod, mod->module_core_rw);
71226
71227 #ifdef CONFIG_MPU
71228 update_protections(current->mm);
71229@@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71230 int ret = 0;
71231 const struct kernel_symbol *ksym;
71232
71233+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71234+ int is_fs_load = 0;
71235+ int register_filesystem_found = 0;
71236+ char *p;
71237+
71238+ p = strstr(mod->args, "grsec_modharden_fs");
71239+ if (p) {
71240+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
71241+ /* copy \0 as well */
71242+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
71243+ is_fs_load = 1;
71244+ }
71245+#endif
71246+
71247 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
71248 const char *name = info->strtab + sym[i].st_name;
71249
71250+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71251+ /* it's a real shame this will never get ripped and copied
71252+ upstream! ;(
71253+ */
71254+ if (is_fs_load && !strcmp(name, "register_filesystem"))
71255+ register_filesystem_found = 1;
71256+#endif
71257+
71258 switch (sym[i].st_shndx) {
71259 case SHN_COMMON:
71260 /* We compiled with -fno-common. These are not
71261@@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71262 ksym = resolve_symbol_wait(mod, info, name);
71263 /* Ok if resolved. */
71264 if (ksym && !IS_ERR(ksym)) {
71265+ pax_open_kernel();
71266 sym[i].st_value = ksym->value;
71267+ pax_close_kernel();
71268 break;
71269 }
71270
71271@@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71272 secbase = (unsigned long)mod_percpu(mod);
71273 else
71274 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
71275+ pax_open_kernel();
71276 sym[i].st_value += secbase;
71277+ pax_close_kernel();
71278 break;
71279 }
71280 }
71281
71282+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71283+ if (is_fs_load && !register_filesystem_found) {
71284+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
71285+ ret = -EPERM;
71286+ }
71287+#endif
71288+
71289 return ret;
71290 }
71291
71292@@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
71293 || s->sh_entsize != ~0UL
71294 || strstarts(sname, ".init"))
71295 continue;
71296- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
71297+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71298+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
71299+ else
71300+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
71301 pr_debug("\t%s\n", sname);
71302 }
71303- switch (m) {
71304- case 0: /* executable */
71305- mod->core_size = debug_align(mod->core_size);
71306- mod->core_text_size = mod->core_size;
71307- break;
71308- case 1: /* RO: text and ro-data */
71309- mod->core_size = debug_align(mod->core_size);
71310- mod->core_ro_size = mod->core_size;
71311- break;
71312- case 3: /* whole core */
71313- mod->core_size = debug_align(mod->core_size);
71314- break;
71315- }
71316 }
71317
71318 pr_debug("Init section allocation order:\n");
71319@@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
71320 || s->sh_entsize != ~0UL
71321 || !strstarts(sname, ".init"))
71322 continue;
71323- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
71324- | INIT_OFFSET_MASK);
71325+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71326+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
71327+ else
71328+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
71329+ s->sh_entsize |= INIT_OFFSET_MASK;
71330 pr_debug("\t%s\n", sname);
71331 }
71332- switch (m) {
71333- case 0: /* executable */
71334- mod->init_size = debug_align(mod->init_size);
71335- mod->init_text_size = mod->init_size;
71336- break;
71337- case 1: /* RO: text and ro-data */
71338- mod->init_size = debug_align(mod->init_size);
71339- mod->init_ro_size = mod->init_size;
71340- break;
71341- case 3: /* whole init */
71342- mod->init_size = debug_align(mod->init_size);
71343- break;
71344- }
71345 }
71346 }
71347
71348@@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
71349
71350 /* Put symbol section at end of init part of module. */
71351 symsect->sh_flags |= SHF_ALLOC;
71352- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
71353+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
71354 info->index.sym) | INIT_OFFSET_MASK;
71355 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
71356
71357@@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
71358 }
71359
71360 /* Append room for core symbols at end of core part. */
71361- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
71362- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
71363- mod->core_size += strtab_size;
71364+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
71365+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
71366+ mod->core_size_rx += strtab_size;
71367
71368 /* Put string table section at end of init part of module. */
71369 strsect->sh_flags |= SHF_ALLOC;
71370- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
71371+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
71372 info->index.str) | INIT_OFFSET_MASK;
71373 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
71374 }
71375@@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
71376 /* Make sure we get permanent strtab: don't use info->strtab. */
71377 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
71378
71379+ pax_open_kernel();
71380+
71381 /* Set types up while we still have access to sections. */
71382 for (i = 0; i < mod->num_symtab; i++)
71383 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
71384
71385- mod->core_symtab = dst = mod->module_core + info->symoffs;
71386- mod->core_strtab = s = mod->module_core + info->stroffs;
71387+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
71388+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
71389 src = mod->symtab;
71390 for (ndst = i = 0; i < mod->num_symtab; i++) {
71391 if (i == 0 ||
71392@@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
71393 }
71394 }
71395 mod->core_num_syms = ndst;
71396+
71397+ pax_close_kernel();
71398 }
71399 #else
71400 static inline void layout_symtab(struct module *mod, struct load_info *info)
71401@@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
71402 return vmalloc_exec(size);
71403 }
71404
71405-static void *module_alloc_update_bounds(unsigned long size)
71406+static void *module_alloc_update_bounds_rw(unsigned long size)
71407 {
71408 void *ret = module_alloc(size);
71409
71410 if (ret) {
71411 mutex_lock(&module_mutex);
71412 /* Update module bounds. */
71413- if ((unsigned long)ret < module_addr_min)
71414- module_addr_min = (unsigned long)ret;
71415- if ((unsigned long)ret + size > module_addr_max)
71416- module_addr_max = (unsigned long)ret + size;
71417+ if ((unsigned long)ret < module_addr_min_rw)
71418+ module_addr_min_rw = (unsigned long)ret;
71419+ if ((unsigned long)ret + size > module_addr_max_rw)
71420+ module_addr_max_rw = (unsigned long)ret + size;
71421+ mutex_unlock(&module_mutex);
71422+ }
71423+ return ret;
71424+}
71425+
71426+static void *module_alloc_update_bounds_rx(unsigned long size)
71427+{
71428+ void *ret = module_alloc_exec(size);
71429+
71430+ if (ret) {
71431+ mutex_lock(&module_mutex);
71432+ /* Update module bounds. */
71433+ if ((unsigned long)ret < module_addr_min_rx)
71434+ module_addr_min_rx = (unsigned long)ret;
71435+ if ((unsigned long)ret + size > module_addr_max_rx)
71436+ module_addr_max_rx = (unsigned long)ret + size;
71437 mutex_unlock(&module_mutex);
71438 }
71439 return ret;
71440@@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
71441 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
71442 {
71443 const char *modmagic = get_modinfo(info, "vermagic");
71444+ const char *license = get_modinfo(info, "license");
71445 int err;
71446
71447+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
71448+ if (!license || !license_is_gpl_compatible(license))
71449+ return -ENOEXEC;
71450+#endif
71451+
71452 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
71453 modmagic = NULL;
71454
71455@@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
71456 }
71457
71458 /* Set up license info based on the info section */
71459- set_license(mod, get_modinfo(info, "license"));
71460+ set_license(mod, license);
71461
71462 return 0;
71463 }
71464@@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
71465 void *ptr;
71466
71467 /* Do the allocs. */
71468- ptr = module_alloc_update_bounds(mod->core_size);
71469+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
71470 /*
71471 * The pointer to this block is stored in the module structure
71472 * which is inside the block. Just mark it as not being a
71473@@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
71474 if (!ptr)
71475 return -ENOMEM;
71476
71477- memset(ptr, 0, mod->core_size);
71478- mod->module_core = ptr;
71479+ memset(ptr, 0, mod->core_size_rw);
71480+ mod->module_core_rw = ptr;
71481
71482- if (mod->init_size) {
71483- ptr = module_alloc_update_bounds(mod->init_size);
71484+ if (mod->init_size_rw) {
71485+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
71486 /*
71487 * The pointer to this block is stored in the module structure
71488 * which is inside the block. This block doesn't need to be
71489@@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
71490 */
71491 kmemleak_ignore(ptr);
71492 if (!ptr) {
71493- module_free(mod, mod->module_core);
71494+ module_free(mod, mod->module_core_rw);
71495 return -ENOMEM;
71496 }
71497- memset(ptr, 0, mod->init_size);
71498- mod->module_init = ptr;
71499+ memset(ptr, 0, mod->init_size_rw);
71500+ mod->module_init_rw = ptr;
71501 } else
71502- mod->module_init = NULL;
71503+ mod->module_init_rw = NULL;
71504+
71505+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
71506+ kmemleak_not_leak(ptr);
71507+ if (!ptr) {
71508+ if (mod->module_init_rw)
71509+ module_free(mod, mod->module_init_rw);
71510+ module_free(mod, mod->module_core_rw);
71511+ return -ENOMEM;
71512+ }
71513+
71514+ pax_open_kernel();
71515+ memset(ptr, 0, mod->core_size_rx);
71516+ pax_close_kernel();
71517+ mod->module_core_rx = ptr;
71518+
71519+ if (mod->init_size_rx) {
71520+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
71521+ kmemleak_ignore(ptr);
71522+ if (!ptr && mod->init_size_rx) {
71523+ module_free_exec(mod, mod->module_core_rx);
71524+ if (mod->module_init_rw)
71525+ module_free(mod, mod->module_init_rw);
71526+ module_free(mod, mod->module_core_rw);
71527+ return -ENOMEM;
71528+ }
71529+
71530+ pax_open_kernel();
71531+ memset(ptr, 0, mod->init_size_rx);
71532+ pax_close_kernel();
71533+ mod->module_init_rx = ptr;
71534+ } else
71535+ mod->module_init_rx = NULL;
71536
71537 /* Transfer each section which specifies SHF_ALLOC */
71538 pr_debug("final section addresses:\n");
71539@@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
71540 if (!(shdr->sh_flags & SHF_ALLOC))
71541 continue;
71542
71543- if (shdr->sh_entsize & INIT_OFFSET_MASK)
71544- dest = mod->module_init
71545- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71546- else
71547- dest = mod->module_core + shdr->sh_entsize;
71548+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
71549+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
71550+ dest = mod->module_init_rw
71551+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71552+ else
71553+ dest = mod->module_init_rx
71554+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71555+ } else {
71556+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
71557+ dest = mod->module_core_rw + shdr->sh_entsize;
71558+ else
71559+ dest = mod->module_core_rx + shdr->sh_entsize;
71560+ }
71561+
71562+ if (shdr->sh_type != SHT_NOBITS) {
71563+
71564+#ifdef CONFIG_PAX_KERNEXEC
71565+#ifdef CONFIG_X86_64
71566+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
71567+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
71568+#endif
71569+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
71570+ pax_open_kernel();
71571+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
71572+ pax_close_kernel();
71573+ } else
71574+#endif
71575
71576- if (shdr->sh_type != SHT_NOBITS)
71577 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
71578+ }
71579 /* Update sh_addr to point to copy in image. */
71580- shdr->sh_addr = (unsigned long)dest;
71581+
71582+#ifdef CONFIG_PAX_KERNEXEC
71583+ if (shdr->sh_flags & SHF_EXECINSTR)
71584+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
71585+ else
71586+#endif
71587+
71588+ shdr->sh_addr = (unsigned long)dest;
71589 pr_debug("\t0x%lx %s\n",
71590 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
71591 }
71592@@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
71593 * Do it before processing of module parameters, so the module
71594 * can provide parameter accessor functions of its own.
71595 */
71596- if (mod->module_init)
71597- flush_icache_range((unsigned long)mod->module_init,
71598- (unsigned long)mod->module_init
71599- + mod->init_size);
71600- flush_icache_range((unsigned long)mod->module_core,
71601- (unsigned long)mod->module_core + mod->core_size);
71602+ if (mod->module_init_rx)
71603+ flush_icache_range((unsigned long)mod->module_init_rx,
71604+ (unsigned long)mod->module_init_rx
71605+ + mod->init_size_rx);
71606+ flush_icache_range((unsigned long)mod->module_core_rx,
71607+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
71608
71609 set_fs(old_fs);
71610 }
71611@@ -2983,8 +3088,10 @@ out:
71612 static void module_deallocate(struct module *mod, struct load_info *info)
71613 {
71614 percpu_modfree(mod);
71615- module_free(mod, mod->module_init);
71616- module_free(mod, mod->module_core);
71617+ module_free_exec(mod, mod->module_init_rx);
71618+ module_free_exec(mod, mod->module_core_rx);
71619+ module_free(mod, mod->module_init_rw);
71620+ module_free(mod, mod->module_core_rw);
71621 }
71622
71623 int __weak module_finalize(const Elf_Ehdr *hdr,
71624@@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
71625 static int post_relocation(struct module *mod, const struct load_info *info)
71626 {
71627 /* Sort exception table now relocations are done. */
71628+ pax_open_kernel();
71629 sort_extable(mod->extable, mod->extable + mod->num_exentries);
71630+ pax_close_kernel();
71631
71632 /* Copy relocated percpu area over. */
71633 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
71634@@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
71635 MODULE_STATE_COMING, mod);
71636
71637 /* Set RO and NX regions for core */
71638- set_section_ro_nx(mod->module_core,
71639- mod->core_text_size,
71640- mod->core_ro_size,
71641- mod->core_size);
71642+ set_section_ro_nx(mod->module_core_rx,
71643+ mod->core_size_rx,
71644+ mod->core_size_rx,
71645+ mod->core_size_rx);
71646
71647 /* Set RO and NX regions for init */
71648- set_section_ro_nx(mod->module_init,
71649- mod->init_text_size,
71650- mod->init_ro_size,
71651- mod->init_size);
71652+ set_section_ro_nx(mod->module_init_rx,
71653+ mod->init_size_rx,
71654+ mod->init_size_rx,
71655+ mod->init_size_rx);
71656
71657 do_mod_ctors(mod);
71658 /* Start the module */
71659@@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
71660 mod->strtab = mod->core_strtab;
71661 #endif
71662 unset_module_init_ro_nx(mod);
71663- module_free(mod, mod->module_init);
71664- mod->module_init = NULL;
71665- mod->init_size = 0;
71666- mod->init_ro_size = 0;
71667- mod->init_text_size = 0;
71668+ module_free(mod, mod->module_init_rw);
71669+ module_free_exec(mod, mod->module_init_rx);
71670+ mod->module_init_rw = NULL;
71671+ mod->module_init_rx = NULL;
71672+ mod->init_size_rw = 0;
71673+ mod->init_size_rx = 0;
71674 mutex_unlock(&module_mutex);
71675 wake_up_all(&module_wq);
71676
71677@@ -3209,9 +3319,38 @@ again:
71678 if (err)
71679 goto free_unload;
71680
71681+ /* Now copy in args */
71682+ mod->args = strndup_user(uargs, ~0UL >> 1);
71683+ if (IS_ERR(mod->args)) {
71684+ err = PTR_ERR(mod->args);
71685+ goto free_unload;
71686+ }
71687+
71688 /* Set up MODINFO_ATTR fields */
71689 setup_modinfo(mod, info);
71690
71691+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71692+ {
71693+ char *p, *p2;
71694+
71695+ if (strstr(mod->args, "grsec_modharden_netdev")) {
71696+ 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);
71697+ err = -EPERM;
71698+ goto free_modinfo;
71699+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
71700+ p += sizeof("grsec_modharden_normal") - 1;
71701+ p2 = strstr(p, "_");
71702+ if (p2) {
71703+ *p2 = '\0';
71704+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
71705+ *p2 = '_';
71706+ }
71707+ err = -EPERM;
71708+ goto free_modinfo;
71709+ }
71710+ }
71711+#endif
71712+
71713 /* Fix up syms, so that st_value is a pointer to location. */
71714 err = simplify_symbols(mod, info);
71715 if (err < 0)
71716@@ -3227,13 +3366,6 @@ again:
71717
71718 flush_module_icache(mod);
71719
71720- /* Now copy in args */
71721- mod->args = strndup_user(uargs, ~0UL >> 1);
71722- if (IS_ERR(mod->args)) {
71723- err = PTR_ERR(mod->args);
71724- goto free_arch_cleanup;
71725- }
71726-
71727 dynamic_debug_setup(info->debug, info->num_debug);
71728
71729 mutex_lock(&module_mutex);
71730@@ -3278,11 +3410,10 @@ again:
71731 mutex_unlock(&module_mutex);
71732 dynamic_debug_remove(info->debug);
71733 synchronize_sched();
71734- kfree(mod->args);
71735- free_arch_cleanup:
71736 module_arch_cleanup(mod);
71737 free_modinfo:
71738 free_modinfo(mod);
71739+ kfree(mod->args);
71740 free_unload:
71741 module_unload_free(mod);
71742 unlink_mod:
71743@@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
71744 unsigned long nextval;
71745
71746 /* At worse, next value is at end of module */
71747- if (within_module_init(addr, mod))
71748- nextval = (unsigned long)mod->module_init+mod->init_text_size;
71749+ if (within_module_init_rx(addr, mod))
71750+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
71751+ else if (within_module_init_rw(addr, mod))
71752+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
71753+ else if (within_module_core_rx(addr, mod))
71754+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
71755+ else if (within_module_core_rw(addr, mod))
71756+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
71757 else
71758- nextval = (unsigned long)mod->module_core+mod->core_text_size;
71759+ return NULL;
71760
71761 /* Scan for closest preceding symbol, and next symbol. (ELF
71762 starts real symbols at 1). */
71763@@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
71764 return 0;
71765
71766 seq_printf(m, "%s %u",
71767- mod->name, mod->init_size + mod->core_size);
71768+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
71769 print_unload_info(m, mod);
71770
71771 /* Informative for users. */
71772@@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
71773 mod->state == MODULE_STATE_COMING ? "Loading":
71774 "Live");
71775 /* Used by oprofile and other similar tools. */
71776- seq_printf(m, " 0x%pK", mod->module_core);
71777+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
71778
71779 /* Taints info */
71780 if (mod->taints)
71781@@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
71782
71783 static int __init proc_modules_init(void)
71784 {
71785+#ifndef CONFIG_GRKERNSEC_HIDESYM
71786+#ifdef CONFIG_GRKERNSEC_PROC_USER
71787+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
71788+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71789+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
71790+#else
71791 proc_create("modules", 0, NULL, &proc_modules_operations);
71792+#endif
71793+#else
71794+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
71795+#endif
71796 return 0;
71797 }
71798 module_init(proc_modules_init);
71799@@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
71800 {
71801 struct module *mod;
71802
71803- if (addr < module_addr_min || addr > module_addr_max)
71804+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
71805+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
71806 return NULL;
71807
71808 list_for_each_entry_rcu(mod, &modules, list) {
71809 if (mod->state == MODULE_STATE_UNFORMED)
71810 continue;
71811- if (within_module_core(addr, mod)
71812- || within_module_init(addr, mod))
71813+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
71814 return mod;
71815 }
71816 return NULL;
71817@@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
71818 */
71819 struct module *__module_text_address(unsigned long addr)
71820 {
71821- struct module *mod = __module_address(addr);
71822+ struct module *mod;
71823+
71824+#ifdef CONFIG_X86_32
71825+ addr = ktla_ktva(addr);
71826+#endif
71827+
71828+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
71829+ return NULL;
71830+
71831+ mod = __module_address(addr);
71832+
71833 if (mod) {
71834 /* Make sure it's within the text section. */
71835- if (!within(addr, mod->module_init, mod->init_text_size)
71836- && !within(addr, mod->module_core, mod->core_text_size))
71837+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
71838 mod = NULL;
71839 }
71840 return mod;
71841diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
71842index 7e3443f..b2a1e6b 100644
71843--- a/kernel/mutex-debug.c
71844+++ b/kernel/mutex-debug.c
71845@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
71846 }
71847
71848 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71849- struct thread_info *ti)
71850+ struct task_struct *task)
71851 {
71852 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
71853
71854 /* Mark the current thread as blocked on the lock: */
71855- ti->task->blocked_on = waiter;
71856+ task->blocked_on = waiter;
71857 }
71858
71859 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71860- struct thread_info *ti)
71861+ struct task_struct *task)
71862 {
71863 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
71864- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
71865- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
71866- ti->task->blocked_on = NULL;
71867+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
71868+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
71869+ task->blocked_on = NULL;
71870
71871 list_del_init(&waiter->list);
71872 waiter->task = NULL;
71873diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
71874index 0799fd3..d06ae3b 100644
71875--- a/kernel/mutex-debug.h
71876+++ b/kernel/mutex-debug.h
71877@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
71878 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
71879 extern void debug_mutex_add_waiter(struct mutex *lock,
71880 struct mutex_waiter *waiter,
71881- struct thread_info *ti);
71882+ struct task_struct *task);
71883 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71884- struct thread_info *ti);
71885+ struct task_struct *task);
71886 extern void debug_mutex_unlock(struct mutex *lock);
71887 extern void debug_mutex_init(struct mutex *lock, const char *name,
71888 struct lock_class_key *key);
71889diff --git a/kernel/mutex.c b/kernel/mutex.c
71890index a307cc9..27fd2e9 100644
71891--- a/kernel/mutex.c
71892+++ b/kernel/mutex.c
71893@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71894 spin_lock_mutex(&lock->wait_lock, flags);
71895
71896 debug_mutex_lock_common(lock, &waiter);
71897- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
71898+ debug_mutex_add_waiter(lock, &waiter, task);
71899
71900 /* add waiting tasks to the end of the waitqueue (FIFO): */
71901 list_add_tail(&waiter.list, &lock->wait_list);
71902@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71903 * TASK_UNINTERRUPTIBLE case.)
71904 */
71905 if (unlikely(signal_pending_state(state, task))) {
71906- mutex_remove_waiter(lock, &waiter,
71907- task_thread_info(task));
71908+ mutex_remove_waiter(lock, &waiter, task);
71909 mutex_release(&lock->dep_map, 1, ip);
71910 spin_unlock_mutex(&lock->wait_lock, flags);
71911
71912@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71913 done:
71914 lock_acquired(&lock->dep_map, ip);
71915 /* got the lock - rejoice! */
71916- mutex_remove_waiter(lock, &waiter, current_thread_info());
71917+ mutex_remove_waiter(lock, &waiter, task);
71918 mutex_set_owner(lock);
71919
71920 /* set it to 0 if there are no waiters left: */
71921diff --git a/kernel/notifier.c b/kernel/notifier.c
71922index 2d5cc4c..d9ea600 100644
71923--- a/kernel/notifier.c
71924+++ b/kernel/notifier.c
71925@@ -5,6 +5,7 @@
71926 #include <linux/rcupdate.h>
71927 #include <linux/vmalloc.h>
71928 #include <linux/reboot.h>
71929+#include <linux/mm.h>
71930
71931 /*
71932 * Notifier list for kernel code which wants to be called
71933@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
71934 while ((*nl) != NULL) {
71935 if (n->priority > (*nl)->priority)
71936 break;
71937- nl = &((*nl)->next);
71938+ nl = (struct notifier_block **)&((*nl)->next);
71939 }
71940- n->next = *nl;
71941+ pax_open_kernel();
71942+ *(const void **)&n->next = *nl;
71943 rcu_assign_pointer(*nl, n);
71944+ pax_close_kernel();
71945 return 0;
71946 }
71947
71948@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
71949 return 0;
71950 if (n->priority > (*nl)->priority)
71951 break;
71952- nl = &((*nl)->next);
71953+ nl = (struct notifier_block **)&((*nl)->next);
71954 }
71955- n->next = *nl;
71956+ pax_open_kernel();
71957+ *(const void **)&n->next = *nl;
71958 rcu_assign_pointer(*nl, n);
71959+ pax_close_kernel();
71960 return 0;
71961 }
71962
71963@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
71964 {
71965 while ((*nl) != NULL) {
71966 if ((*nl) == n) {
71967+ pax_open_kernel();
71968 rcu_assign_pointer(*nl, n->next);
71969+ pax_close_kernel();
71970 return 0;
71971 }
71972- nl = &((*nl)->next);
71973+ nl = (struct notifier_block **)&((*nl)->next);
71974 }
71975 return -ENOENT;
71976 }
71977diff --git a/kernel/panic.c b/kernel/panic.c
71978index e1b2822..5edc1d9 100644
71979--- a/kernel/panic.c
71980+++ b/kernel/panic.c
71981@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
71982 const char *board;
71983
71984 printk(KERN_WARNING "------------[ cut here ]------------\n");
71985- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
71986+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
71987 board = dmi_get_system_info(DMI_PRODUCT_NAME);
71988 if (board)
71989 printk(KERN_WARNING "Hardware name: %s\n", board);
71990@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
71991 */
71992 void __stack_chk_fail(void)
71993 {
71994- panic("stack-protector: Kernel stack is corrupted in: %p\n",
71995+ dump_stack();
71996+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
71997 __builtin_return_address(0));
71998 }
71999 EXPORT_SYMBOL(__stack_chk_fail);
72000diff --git a/kernel/pid.c b/kernel/pid.c
72001index f2c6a68..4922d97 100644
72002--- a/kernel/pid.c
72003+++ b/kernel/pid.c
72004@@ -33,6 +33,7 @@
72005 #include <linux/rculist.h>
72006 #include <linux/bootmem.h>
72007 #include <linux/hash.h>
72008+#include <linux/security.h>
72009 #include <linux/pid_namespace.h>
72010 #include <linux/init_task.h>
72011 #include <linux/syscalls.h>
72012@@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
72013
72014 int pid_max = PID_MAX_DEFAULT;
72015
72016-#define RESERVED_PIDS 300
72017+#define RESERVED_PIDS 500
72018
72019 int pid_max_min = RESERVED_PIDS + 1;
72020 int pid_max_max = PID_MAX_LIMIT;
72021@@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
72022 */
72023 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
72024 {
72025+ struct task_struct *task;
72026+
72027 rcu_lockdep_assert(rcu_read_lock_held(),
72028 "find_task_by_pid_ns() needs rcu_read_lock()"
72029 " protection");
72030- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
72031+
72032+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
72033+
72034+ if (gr_pid_is_chrooted(task))
72035+ return NULL;
72036+
72037+ return task;
72038 }
72039
72040 struct task_struct *find_task_by_vpid(pid_t vnr)
72041@@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
72042 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
72043 }
72044
72045+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
72046+{
72047+ rcu_lockdep_assert(rcu_read_lock_held(),
72048+ "find_task_by_pid_ns() needs rcu_read_lock()"
72049+ " protection");
72050+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
72051+}
72052+
72053 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
72054 {
72055 struct pid *pid;
72056diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
72057index a278cad..bff5bd3 100644
72058--- a/kernel/posix-cpu-timers.c
72059+++ b/kernel/posix-cpu-timers.c
72060@@ -1557,14 +1557,14 @@ struct k_clock clock_posix_cpu = {
72061
72062 static __init int init_posix_cpu_timers(void)
72063 {
72064- struct k_clock process = {
72065+ static struct k_clock process = {
72066 .clock_getres = process_cpu_clock_getres,
72067 .clock_get = process_cpu_clock_get,
72068 .timer_create = process_cpu_timer_create,
72069 .nsleep = process_cpu_nsleep,
72070 .nsleep_restart = process_cpu_nsleep_restart,
72071 };
72072- struct k_clock thread = {
72073+ static struct k_clock thread = {
72074 .clock_getres = thread_cpu_clock_getres,
72075 .clock_get = thread_cpu_clock_get,
72076 .timer_create = thread_cpu_timer_create,
72077diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
72078index 69185ae..cc2847a 100644
72079--- a/kernel/posix-timers.c
72080+++ b/kernel/posix-timers.c
72081@@ -43,6 +43,7 @@
72082 #include <linux/idr.h>
72083 #include <linux/posix-clock.h>
72084 #include <linux/posix-timers.h>
72085+#include <linux/grsecurity.h>
72086 #include <linux/syscalls.h>
72087 #include <linux/wait.h>
72088 #include <linux/workqueue.h>
72089@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
72090 * which we beg off on and pass to do_sys_settimeofday().
72091 */
72092
72093-static struct k_clock posix_clocks[MAX_CLOCKS];
72094+static struct k_clock *posix_clocks[MAX_CLOCKS];
72095
72096 /*
72097 * These ones are defined below.
72098@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
72099 */
72100 static __init int init_posix_timers(void)
72101 {
72102- struct k_clock clock_realtime = {
72103+ static struct k_clock clock_realtime = {
72104 .clock_getres = hrtimer_get_res,
72105 .clock_get = posix_clock_realtime_get,
72106 .clock_set = posix_clock_realtime_set,
72107@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
72108 .timer_get = common_timer_get,
72109 .timer_del = common_timer_del,
72110 };
72111- struct k_clock clock_monotonic = {
72112+ static struct k_clock clock_monotonic = {
72113 .clock_getres = hrtimer_get_res,
72114 .clock_get = posix_ktime_get_ts,
72115 .nsleep = common_nsleep,
72116@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
72117 .timer_get = common_timer_get,
72118 .timer_del = common_timer_del,
72119 };
72120- struct k_clock clock_monotonic_raw = {
72121+ static struct k_clock clock_monotonic_raw = {
72122 .clock_getres = hrtimer_get_res,
72123 .clock_get = posix_get_monotonic_raw,
72124 };
72125- struct k_clock clock_realtime_coarse = {
72126+ static struct k_clock clock_realtime_coarse = {
72127 .clock_getres = posix_get_coarse_res,
72128 .clock_get = posix_get_realtime_coarse,
72129 };
72130- struct k_clock clock_monotonic_coarse = {
72131+ static struct k_clock clock_monotonic_coarse = {
72132 .clock_getres = posix_get_coarse_res,
72133 .clock_get = posix_get_monotonic_coarse,
72134 };
72135- struct k_clock clock_boottime = {
72136+ static struct k_clock clock_boottime = {
72137 .clock_getres = hrtimer_get_res,
72138 .clock_get = posix_get_boottime,
72139 .nsleep = common_nsleep,
72140@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
72141 return;
72142 }
72143
72144- posix_clocks[clock_id] = *new_clock;
72145+ posix_clocks[clock_id] = new_clock;
72146 }
72147 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
72148
72149@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
72150 return (id & CLOCKFD_MASK) == CLOCKFD ?
72151 &clock_posix_dynamic : &clock_posix_cpu;
72152
72153- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
72154+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
72155 return NULL;
72156- return &posix_clocks[id];
72157+ return posix_clocks[id];
72158 }
72159
72160 static int common_timer_create(struct k_itimer *new_timer)
72161@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
72162 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
72163 return -EFAULT;
72164
72165+ /* only the CLOCK_REALTIME clock can be set, all other clocks
72166+ have their clock_set fptr set to a nosettime dummy function
72167+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
72168+ call common_clock_set, which calls do_sys_settimeofday, which
72169+ we hook
72170+ */
72171+
72172 return kc->clock_set(which_clock, &new_tp);
72173 }
72174
72175diff --git a/kernel/power/process.c b/kernel/power/process.c
72176index d5a258b..4271191 100644
72177--- a/kernel/power/process.c
72178+++ b/kernel/power/process.c
72179@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
72180 u64 elapsed_csecs64;
72181 unsigned int elapsed_csecs;
72182 bool wakeup = false;
72183+ bool timedout = false;
72184
72185 do_gettimeofday(&start);
72186
72187@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
72188
72189 while (true) {
72190 todo = 0;
72191+ if (time_after(jiffies, end_time))
72192+ timedout = true;
72193 read_lock(&tasklist_lock);
72194 do_each_thread(g, p) {
72195 if (p == current || !freeze_task(p))
72196 continue;
72197
72198- if (!freezer_should_skip(p))
72199+ if (!freezer_should_skip(p)) {
72200 todo++;
72201+ if (timedout) {
72202+ printk(KERN_ERR "Task refusing to freeze:\n");
72203+ sched_show_task(p);
72204+ }
72205+ }
72206 } while_each_thread(g, p);
72207 read_unlock(&tasklist_lock);
72208
72209@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
72210 todo += wq_busy;
72211 }
72212
72213- if (!todo || time_after(jiffies, end_time))
72214+ if (!todo || timedout)
72215 break;
72216
72217 if (pm_wakeup_pending()) {
72218diff --git a/kernel/printk.c b/kernel/printk.c
72219index 267ce78..952f8a8 100644
72220--- a/kernel/printk.c
72221+++ b/kernel/printk.c
72222@@ -834,6 +834,11 @@ static int check_syslog_permissions(int type, bool from_file)
72223 if (from_file && type != SYSLOG_ACTION_OPEN)
72224 return 0;
72225
72226+#ifdef CONFIG_GRKERNSEC_DMESG
72227+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
72228+ return -EPERM;
72229+#endif
72230+
72231 if (syslog_action_restricted(type)) {
72232 if (capable(CAP_SYSLOG))
72233 return 0;
72234diff --git a/kernel/profile.c b/kernel/profile.c
72235index 1f39181..86093471 100644
72236--- a/kernel/profile.c
72237+++ b/kernel/profile.c
72238@@ -40,7 +40,7 @@ struct profile_hit {
72239 /* Oprofile timer tick hook */
72240 static int (*timer_hook)(struct pt_regs *) __read_mostly;
72241
72242-static atomic_t *prof_buffer;
72243+static atomic_unchecked_t *prof_buffer;
72244 static unsigned long prof_len, prof_shift;
72245
72246 int prof_on __read_mostly;
72247@@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
72248 hits[i].pc = 0;
72249 continue;
72250 }
72251- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
72252+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
72253 hits[i].hits = hits[i].pc = 0;
72254 }
72255 }
72256@@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
72257 * Add the current hit(s) and flush the write-queue out
72258 * to the global buffer:
72259 */
72260- atomic_add(nr_hits, &prof_buffer[pc]);
72261+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
72262 for (i = 0; i < NR_PROFILE_HIT; ++i) {
72263- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
72264+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
72265 hits[i].pc = hits[i].hits = 0;
72266 }
72267 out:
72268@@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
72269 {
72270 unsigned long pc;
72271 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
72272- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
72273+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
72274 }
72275 #endif /* !CONFIG_SMP */
72276
72277@@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
72278 return -EFAULT;
72279 buf++; p++; count--; read++;
72280 }
72281- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
72282+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
72283 if (copy_to_user(buf, (void *)pnt, count))
72284 return -EFAULT;
72285 read += count;
72286@@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
72287 }
72288 #endif
72289 profile_discard_flip_buffers();
72290- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
72291+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
72292 return count;
72293 }
72294
72295diff --git a/kernel/ptrace.c b/kernel/ptrace.c
72296index 6cbeaae..363c48a 100644
72297--- a/kernel/ptrace.c
72298+++ b/kernel/ptrace.c
72299@@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
72300 if (seize)
72301 flags |= PT_SEIZED;
72302 rcu_read_lock();
72303- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
72304+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
72305 flags |= PT_PTRACE_CAP;
72306 rcu_read_unlock();
72307 task->ptrace = flags;
72308@@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
72309 break;
72310 return -EIO;
72311 }
72312- if (copy_to_user(dst, buf, retval))
72313+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
72314 return -EFAULT;
72315 copied += retval;
72316 src += retval;
72317@@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
72318 bool seized = child->ptrace & PT_SEIZED;
72319 int ret = -EIO;
72320 siginfo_t siginfo, *si;
72321- void __user *datavp = (void __user *) data;
72322+ void __user *datavp = (__force void __user *) data;
72323 unsigned long __user *datalp = datavp;
72324 unsigned long flags;
72325
72326@@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
72327 goto out;
72328 }
72329
72330+ if (gr_handle_ptrace(child, request)) {
72331+ ret = -EPERM;
72332+ goto out_put_task_struct;
72333+ }
72334+
72335 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72336 ret = ptrace_attach(child, request, addr, data);
72337 /*
72338 * Some architectures need to do book-keeping after
72339 * a ptrace attach.
72340 */
72341- if (!ret)
72342+ if (!ret) {
72343 arch_ptrace_attach(child);
72344+ gr_audit_ptrace(child);
72345+ }
72346 goto out_put_task_struct;
72347 }
72348
72349@@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
72350 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
72351 if (copied != sizeof(tmp))
72352 return -EIO;
72353- return put_user(tmp, (unsigned long __user *)data);
72354+ return put_user(tmp, (__force unsigned long __user *)data);
72355 }
72356
72357 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
72358@@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
72359 goto out;
72360 }
72361
72362+ if (gr_handle_ptrace(child, request)) {
72363+ ret = -EPERM;
72364+ goto out_put_task_struct;
72365+ }
72366+
72367 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72368 ret = ptrace_attach(child, request, addr, data);
72369 /*
72370 * Some architectures need to do book-keeping after
72371 * a ptrace attach.
72372 */
72373- if (!ret)
72374+ if (!ret) {
72375 arch_ptrace_attach(child);
72376+ gr_audit_ptrace(child);
72377+ }
72378 goto out_put_task_struct;
72379 }
72380
72381diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
72382index e7dce58..ad0d7b7 100644
72383--- a/kernel/rcutiny.c
72384+++ b/kernel/rcutiny.c
72385@@ -46,7 +46,7 @@
72386 struct rcu_ctrlblk;
72387 static void invoke_rcu_callbacks(void);
72388 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
72389-static void rcu_process_callbacks(struct softirq_action *unused);
72390+static void rcu_process_callbacks(void);
72391 static void __call_rcu(struct rcu_head *head,
72392 void (*func)(struct rcu_head *rcu),
72393 struct rcu_ctrlblk *rcp);
72394@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
72395 rcu_is_callbacks_kthread()));
72396 }
72397
72398-static void rcu_process_callbacks(struct softirq_action *unused)
72399+static void rcu_process_callbacks(void)
72400 {
72401 __rcu_process_callbacks(&rcu_sched_ctrlblk);
72402 __rcu_process_callbacks(&rcu_bh_ctrlblk);
72403diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
72404index f85016a..91cb03b 100644
72405--- a/kernel/rcutiny_plugin.h
72406+++ b/kernel/rcutiny_plugin.h
72407@@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
72408 have_rcu_kthread_work = morework;
72409 local_irq_restore(flags);
72410 if (work)
72411- rcu_process_callbacks(NULL);
72412+ rcu_process_callbacks();
72413 schedule_timeout_interruptible(1); /* Leave CPU for others. */
72414 }
72415
72416diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
72417index 31dea01..ad91ffb 100644
72418--- a/kernel/rcutorture.c
72419+++ b/kernel/rcutorture.c
72420@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
72421 { 0 };
72422 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
72423 { 0 };
72424-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
72425-static atomic_t n_rcu_torture_alloc;
72426-static atomic_t n_rcu_torture_alloc_fail;
72427-static atomic_t n_rcu_torture_free;
72428-static atomic_t n_rcu_torture_mberror;
72429-static atomic_t n_rcu_torture_error;
72430+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
72431+static atomic_unchecked_t n_rcu_torture_alloc;
72432+static atomic_unchecked_t n_rcu_torture_alloc_fail;
72433+static atomic_unchecked_t n_rcu_torture_free;
72434+static atomic_unchecked_t n_rcu_torture_mberror;
72435+static atomic_unchecked_t n_rcu_torture_error;
72436 static long n_rcu_torture_barrier_error;
72437 static long n_rcu_torture_boost_ktrerror;
72438 static long n_rcu_torture_boost_rterror;
72439@@ -272,11 +272,11 @@ rcu_torture_alloc(void)
72440
72441 spin_lock_bh(&rcu_torture_lock);
72442 if (list_empty(&rcu_torture_freelist)) {
72443- atomic_inc(&n_rcu_torture_alloc_fail);
72444+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
72445 spin_unlock_bh(&rcu_torture_lock);
72446 return NULL;
72447 }
72448- atomic_inc(&n_rcu_torture_alloc);
72449+ atomic_inc_unchecked(&n_rcu_torture_alloc);
72450 p = rcu_torture_freelist.next;
72451 list_del_init(p);
72452 spin_unlock_bh(&rcu_torture_lock);
72453@@ -289,7 +289,7 @@ rcu_torture_alloc(void)
72454 static void
72455 rcu_torture_free(struct rcu_torture *p)
72456 {
72457- atomic_inc(&n_rcu_torture_free);
72458+ atomic_inc_unchecked(&n_rcu_torture_free);
72459 spin_lock_bh(&rcu_torture_lock);
72460 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
72461 spin_unlock_bh(&rcu_torture_lock);
72462@@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
72463 i = rp->rtort_pipe_count;
72464 if (i > RCU_TORTURE_PIPE_LEN)
72465 i = RCU_TORTURE_PIPE_LEN;
72466- atomic_inc(&rcu_torture_wcount[i]);
72467+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
72468 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
72469 rp->rtort_mbtest = 0;
72470 rcu_torture_free(rp);
72471@@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
72472 i = rp->rtort_pipe_count;
72473 if (i > RCU_TORTURE_PIPE_LEN)
72474 i = RCU_TORTURE_PIPE_LEN;
72475- atomic_inc(&rcu_torture_wcount[i]);
72476+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
72477 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
72478 rp->rtort_mbtest = 0;
72479 list_del(&rp->rtort_free);
72480@@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
72481 i = old_rp->rtort_pipe_count;
72482 if (i > RCU_TORTURE_PIPE_LEN)
72483 i = RCU_TORTURE_PIPE_LEN;
72484- atomic_inc(&rcu_torture_wcount[i]);
72485+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
72486 old_rp->rtort_pipe_count++;
72487 cur_ops->deferred_free(old_rp);
72488 }
72489@@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
72490 }
72491 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
72492 if (p->rtort_mbtest == 0)
72493- atomic_inc(&n_rcu_torture_mberror);
72494+ atomic_inc_unchecked(&n_rcu_torture_mberror);
72495 spin_lock(&rand_lock);
72496 cur_ops->read_delay(&rand);
72497 n_rcu_torture_timers++;
72498@@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
72499 }
72500 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
72501 if (p->rtort_mbtest == 0)
72502- atomic_inc(&n_rcu_torture_mberror);
72503+ atomic_inc_unchecked(&n_rcu_torture_mberror);
72504 cur_ops->read_delay(&rand);
72505 preempt_disable();
72506 pipe_count = p->rtort_pipe_count;
72507@@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
72508 rcu_torture_current,
72509 rcu_torture_current_version,
72510 list_empty(&rcu_torture_freelist),
72511- atomic_read(&n_rcu_torture_alloc),
72512- atomic_read(&n_rcu_torture_alloc_fail),
72513- atomic_read(&n_rcu_torture_free));
72514+ atomic_read_unchecked(&n_rcu_torture_alloc),
72515+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
72516+ atomic_read_unchecked(&n_rcu_torture_free));
72517 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
72518- atomic_read(&n_rcu_torture_mberror),
72519+ atomic_read_unchecked(&n_rcu_torture_mberror),
72520 n_rcu_torture_boost_ktrerror,
72521 n_rcu_torture_boost_rterror);
72522 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
72523@@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
72524 n_barrier_attempts,
72525 n_rcu_torture_barrier_error);
72526 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
72527- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
72528+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
72529 n_rcu_torture_barrier_error != 0 ||
72530 n_rcu_torture_boost_ktrerror != 0 ||
72531 n_rcu_torture_boost_rterror != 0 ||
72532 n_rcu_torture_boost_failure != 0 ||
72533 i > 1) {
72534 cnt += sprintf(&page[cnt], "!!! ");
72535- atomic_inc(&n_rcu_torture_error);
72536+ atomic_inc_unchecked(&n_rcu_torture_error);
72537 WARN_ON_ONCE(1);
72538 }
72539 cnt += sprintf(&page[cnt], "Reader Pipe: ");
72540@@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
72541 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
72542 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
72543 cnt += sprintf(&page[cnt], " %d",
72544- atomic_read(&rcu_torture_wcount[i]));
72545+ atomic_read_unchecked(&rcu_torture_wcount[i]));
72546 }
72547 cnt += sprintf(&page[cnt], "\n");
72548 if (cur_ops->stats)
72549@@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
72550
72551 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
72552
72553- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
72554+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
72555 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
72556 else if (n_online_successes != n_online_attempts ||
72557 n_offline_successes != n_offline_attempts)
72558@@ -1989,18 +1989,18 @@ rcu_torture_init(void)
72559
72560 rcu_torture_current = NULL;
72561 rcu_torture_current_version = 0;
72562- atomic_set(&n_rcu_torture_alloc, 0);
72563- atomic_set(&n_rcu_torture_alloc_fail, 0);
72564- atomic_set(&n_rcu_torture_free, 0);
72565- atomic_set(&n_rcu_torture_mberror, 0);
72566- atomic_set(&n_rcu_torture_error, 0);
72567+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
72568+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
72569+ atomic_set_unchecked(&n_rcu_torture_free, 0);
72570+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
72571+ atomic_set_unchecked(&n_rcu_torture_error, 0);
72572 n_rcu_torture_barrier_error = 0;
72573 n_rcu_torture_boost_ktrerror = 0;
72574 n_rcu_torture_boost_rterror = 0;
72575 n_rcu_torture_boost_failure = 0;
72576 n_rcu_torture_boosts = 0;
72577 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
72578- atomic_set(&rcu_torture_wcount[i], 0);
72579+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
72580 for_each_possible_cpu(cpu) {
72581 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
72582 per_cpu(rcu_torture_count, cpu)[i] = 0;
72583diff --git a/kernel/rcutree.c b/kernel/rcutree.c
72584index e441b77..dd54f17 100644
72585--- a/kernel/rcutree.c
72586+++ b/kernel/rcutree.c
72587@@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
72588 rcu_prepare_for_idle(smp_processor_id());
72589 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
72590 smp_mb__before_atomic_inc(); /* See above. */
72591- atomic_inc(&rdtp->dynticks);
72592+ atomic_inc_unchecked(&rdtp->dynticks);
72593 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
72594- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
72595+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
72596
72597 /*
72598 * It is illegal to enter an extended quiescent state while
72599@@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
72600 int user)
72601 {
72602 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
72603- atomic_inc(&rdtp->dynticks);
72604+ atomic_inc_unchecked(&rdtp->dynticks);
72605 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
72606 smp_mb__after_atomic_inc(); /* See above. */
72607- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
72608+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
72609 rcu_cleanup_after_idle(smp_processor_id());
72610 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
72611 if (!user && !is_idle_task(current)) {
72612@@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
72613 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
72614
72615 if (rdtp->dynticks_nmi_nesting == 0 &&
72616- (atomic_read(&rdtp->dynticks) & 0x1))
72617+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
72618 return;
72619 rdtp->dynticks_nmi_nesting++;
72620 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
72621- atomic_inc(&rdtp->dynticks);
72622+ atomic_inc_unchecked(&rdtp->dynticks);
72623 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
72624 smp_mb__after_atomic_inc(); /* See above. */
72625- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
72626+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
72627 }
72628
72629 /**
72630@@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
72631 return;
72632 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
72633 smp_mb__before_atomic_inc(); /* See above. */
72634- atomic_inc(&rdtp->dynticks);
72635+ atomic_inc_unchecked(&rdtp->dynticks);
72636 smp_mb__after_atomic_inc(); /* Force delay to next write. */
72637- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
72638+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
72639 }
72640
72641 /**
72642@@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
72643 int ret;
72644
72645 preempt_disable();
72646- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
72647+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
72648 preempt_enable();
72649 return ret;
72650 }
72651@@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
72652 */
72653 static int dyntick_save_progress_counter(struct rcu_data *rdp)
72654 {
72655- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
72656+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
72657 return (rdp->dynticks_snap & 0x1) == 0;
72658 }
72659
72660@@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
72661 unsigned int curr;
72662 unsigned int snap;
72663
72664- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
72665+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
72666 snap = (unsigned int)rdp->dynticks_snap;
72667
72668 /*
72669@@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
72670 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
72671 */
72672 if (till_stall_check < 3) {
72673- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
72674+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
72675 till_stall_check = 3;
72676 } else if (till_stall_check > 300) {
72677- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
72678+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
72679 till_stall_check = 300;
72680 }
72681 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
72682@@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
72683 rsp->qlen += rdp->qlen;
72684 rdp->n_cbs_orphaned += rdp->qlen;
72685 rdp->qlen_lazy = 0;
72686- ACCESS_ONCE(rdp->qlen) = 0;
72687+ ACCESS_ONCE_RW(rdp->qlen) = 0;
72688 }
72689
72690 /*
72691@@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
72692 }
72693 smp_mb(); /* List handling before counting for rcu_barrier(). */
72694 rdp->qlen_lazy -= count_lazy;
72695- ACCESS_ONCE(rdp->qlen) -= count;
72696+ ACCESS_ONCE_RW(rdp->qlen) -= count;
72697 rdp->n_cbs_invoked += count;
72698
72699 /* Reinstate batch limit if we have worked down the excess. */
72700@@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
72701 /*
72702 * Do RCU core processing for the current CPU.
72703 */
72704-static void rcu_process_callbacks(struct softirq_action *unused)
72705+static void rcu_process_callbacks(void)
72706 {
72707 struct rcu_state *rsp;
72708
72709@@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
72710 local_irq_restore(flags);
72711 return;
72712 }
72713- ACCESS_ONCE(rdp->qlen)++;
72714+ ACCESS_ONCE_RW(rdp->qlen)++;
72715 if (lazy)
72716 rdp->qlen_lazy++;
72717 else
72718@@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
72719 * counter wrap on a 32-bit system. Quite a few more CPUs would of
72720 * course be required on a 64-bit system.
72721 */
72722- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
72723+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
72724 (ulong)atomic_long_read(&rsp->expedited_done) +
72725 ULONG_MAX / 8)) {
72726 synchronize_sched();
72727- atomic_long_inc(&rsp->expedited_wrap);
72728+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
72729 return;
72730 }
72731
72732@@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
72733 * Take a ticket. Note that atomic_inc_return() implies a
72734 * full memory barrier.
72735 */
72736- snap = atomic_long_inc_return(&rsp->expedited_start);
72737+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
72738 firstsnap = snap;
72739 get_online_cpus();
72740 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
72741@@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
72742 synchronize_sched_expedited_cpu_stop,
72743 NULL) == -EAGAIN) {
72744 put_online_cpus();
72745- atomic_long_inc(&rsp->expedited_tryfail);
72746+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
72747
72748 /* Check to see if someone else did our work for us. */
72749 s = atomic_long_read(&rsp->expedited_done);
72750 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
72751 /* ensure test happens before caller kfree */
72752 smp_mb__before_atomic_inc(); /* ^^^ */
72753- atomic_long_inc(&rsp->expedited_workdone1);
72754+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
72755 return;
72756 }
72757
72758@@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
72759 udelay(trycount * num_online_cpus());
72760 } else {
72761 wait_rcu_gp(call_rcu_sched);
72762- atomic_long_inc(&rsp->expedited_normal);
72763+ atomic_long_inc_unchecked(&rsp->expedited_normal);
72764 return;
72765 }
72766
72767@@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
72768 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
72769 /* ensure test happens before caller kfree */
72770 smp_mb__before_atomic_inc(); /* ^^^ */
72771- atomic_long_inc(&rsp->expedited_workdone2);
72772+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
72773 return;
72774 }
72775
72776@@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
72777 * period works for us.
72778 */
72779 get_online_cpus();
72780- snap = atomic_long_read(&rsp->expedited_start);
72781+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
72782 smp_mb(); /* ensure read is before try_stop_cpus(). */
72783 }
72784- atomic_long_inc(&rsp->expedited_stoppedcpus);
72785+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
72786
72787 /*
72788 * Everyone up to our most recent fetch is covered by our grace
72789@@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
72790 * than we did already did their update.
72791 */
72792 do {
72793- atomic_long_inc(&rsp->expedited_done_tries);
72794+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
72795 s = atomic_long_read(&rsp->expedited_done);
72796 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
72797 /* ensure test happens before caller kfree */
72798 smp_mb__before_atomic_inc(); /* ^^^ */
72799- atomic_long_inc(&rsp->expedited_done_lost);
72800+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
72801 break;
72802 }
72803 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
72804- atomic_long_inc(&rsp->expedited_done_exit);
72805+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
72806
72807 put_online_cpus();
72808 }
72809@@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
72810 * ACCESS_ONCE() to prevent the compiler from speculating
72811 * the increment to precede the early-exit check.
72812 */
72813- ACCESS_ONCE(rsp->n_barrier_done)++;
72814+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
72815 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
72816 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
72817 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
72818@@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
72819
72820 /* Increment ->n_barrier_done to prevent duplicate work. */
72821 smp_mb(); /* Keep increment after above mechanism. */
72822- ACCESS_ONCE(rsp->n_barrier_done)++;
72823+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
72824 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
72825 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
72826 smp_mb(); /* Keep increment before caller's subsequent code. */
72827@@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
72828 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
72829 init_callback_list(rdp);
72830 rdp->qlen_lazy = 0;
72831- ACCESS_ONCE(rdp->qlen) = 0;
72832+ ACCESS_ONCE_RW(rdp->qlen) = 0;
72833 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
72834 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
72835- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
72836+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
72837 #ifdef CONFIG_RCU_USER_QS
72838 WARN_ON_ONCE(rdp->dynticks->in_user);
72839 #endif
72840@@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
72841 rdp->blimit = blimit;
72842 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
72843 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
72844- atomic_set(&rdp->dynticks->dynticks,
72845- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
72846+ atomic_set_unchecked(&rdp->dynticks->dynticks,
72847+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
72848 rcu_prepare_for_idle_init(cpu);
72849 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
72850
72851diff --git a/kernel/rcutree.h b/kernel/rcutree.h
72852index 4b69291..704c92e 100644
72853--- a/kernel/rcutree.h
72854+++ b/kernel/rcutree.h
72855@@ -86,7 +86,7 @@ struct rcu_dynticks {
72856 long long dynticks_nesting; /* Track irq/process nesting level. */
72857 /* Process level is worth LLONG_MAX/2. */
72858 int dynticks_nmi_nesting; /* Track NMI nesting level. */
72859- atomic_t dynticks; /* Even value for idle, else odd. */
72860+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
72861 #ifdef CONFIG_RCU_FAST_NO_HZ
72862 int dyntick_drain; /* Prepare-for-idle state variable. */
72863 unsigned long dyntick_holdoff;
72864@@ -423,17 +423,17 @@ struct rcu_state {
72865 /* _rcu_barrier(). */
72866 /* End of fields guarded by barrier_mutex. */
72867
72868- atomic_long_t expedited_start; /* Starting ticket. */
72869- atomic_long_t expedited_done; /* Done ticket. */
72870- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
72871- atomic_long_t expedited_tryfail; /* # acquisition failures. */
72872- atomic_long_t expedited_workdone1; /* # done by others #1. */
72873- atomic_long_t expedited_workdone2; /* # done by others #2. */
72874- atomic_long_t expedited_normal; /* # fallbacks to normal. */
72875- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
72876- atomic_long_t expedited_done_tries; /* # tries to update _done. */
72877- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
72878- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
72879+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
72880+ atomic_long_t expedited_done; /* Done ticket. */
72881+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
72882+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
72883+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
72884+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
72885+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
72886+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
72887+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
72888+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
72889+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
72890
72891 unsigned long jiffies_force_qs; /* Time at which to invoke */
72892 /* force_quiescent_state(). */
72893diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
72894index c1cc7e1..5043e0e 100644
72895--- a/kernel/rcutree_plugin.h
72896+++ b/kernel/rcutree_plugin.h
72897@@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
72898
72899 /* Clean up and exit. */
72900 smp_mb(); /* ensure expedited GP seen before counter increment. */
72901- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
72902+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
72903 unlock_mb_ret:
72904 mutex_unlock(&sync_rcu_preempt_exp_mutex);
72905 mb_ret:
72906@@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
72907 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
72908 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
72909 cpu, ticks_value, ticks_title,
72910- atomic_read(&rdtp->dynticks) & 0xfff,
72911+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
72912 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
72913 fast_no_hz);
72914 }
72915@@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
72916
72917 /* Enqueue the callback on the nocb list and update counts. */
72918 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
72919- ACCESS_ONCE(*old_rhpp) = rhp;
72920+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
72921 atomic_long_add(rhcount, &rdp->nocb_q_count);
72922 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
72923
72924@@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
72925 * Extract queued callbacks, update counts, and wait
72926 * for a grace period to elapse.
72927 */
72928- ACCESS_ONCE(rdp->nocb_head) = NULL;
72929+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
72930 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
72931 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
72932 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
72933- ACCESS_ONCE(rdp->nocb_p_count) += c;
72934- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
72935+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
72936+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
72937 wait_rcu_gp(rdp->rsp->call_remote);
72938
72939 /* Each pass through the following loop invokes a callback. */
72940@@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
72941 list = next;
72942 }
72943 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
72944- ACCESS_ONCE(rdp->nocb_p_count) -= c;
72945- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
72946+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
72947+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
72948 rdp->n_nocbs_invoked += c;
72949 }
72950 return 0;
72951@@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
72952 rdp = per_cpu_ptr(rsp->rda, cpu);
72953 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
72954 BUG_ON(IS_ERR(t));
72955- ACCESS_ONCE(rdp->nocb_kthread) = t;
72956+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
72957 }
72958 }
72959
72960diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
72961index 0d095dc..1985b19 100644
72962--- a/kernel/rcutree_trace.c
72963+++ b/kernel/rcutree_trace.c
72964@@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
72965 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
72966 rdp->passed_quiesce, rdp->qs_pending);
72967 seq_printf(m, " dt=%d/%llx/%d df=%lu",
72968- atomic_read(&rdp->dynticks->dynticks),
72969+ atomic_read_unchecked(&rdp->dynticks->dynticks),
72970 rdp->dynticks->dynticks_nesting,
72971 rdp->dynticks->dynticks_nmi_nesting,
72972 rdp->dynticks_fqs);
72973@@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
72974 struct rcu_state *rsp = (struct rcu_state *)m->private;
72975
72976 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",
72977- atomic_long_read(&rsp->expedited_start),
72978+ atomic_long_read_unchecked(&rsp->expedited_start),
72979 atomic_long_read(&rsp->expedited_done),
72980- atomic_long_read(&rsp->expedited_wrap),
72981- atomic_long_read(&rsp->expedited_tryfail),
72982- atomic_long_read(&rsp->expedited_workdone1),
72983- atomic_long_read(&rsp->expedited_workdone2),
72984- atomic_long_read(&rsp->expedited_normal),
72985- atomic_long_read(&rsp->expedited_stoppedcpus),
72986- atomic_long_read(&rsp->expedited_done_tries),
72987- atomic_long_read(&rsp->expedited_done_lost),
72988- atomic_long_read(&rsp->expedited_done_exit));
72989+ atomic_long_read_unchecked(&rsp->expedited_wrap),
72990+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
72991+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
72992+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
72993+ atomic_long_read_unchecked(&rsp->expedited_normal),
72994+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
72995+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
72996+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
72997+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
72998 return 0;
72999 }
73000
73001diff --git a/kernel/resource.c b/kernel/resource.c
73002index 73f35d4..4684fc4 100644
73003--- a/kernel/resource.c
73004+++ b/kernel/resource.c
73005@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
73006
73007 static int __init ioresources_init(void)
73008 {
73009+#ifdef CONFIG_GRKERNSEC_PROC_ADD
73010+#ifdef CONFIG_GRKERNSEC_PROC_USER
73011+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
73012+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
73013+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
73014+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
73015+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
73016+#endif
73017+#else
73018 proc_create("ioports", 0, NULL, &proc_ioports_operations);
73019 proc_create("iomem", 0, NULL, &proc_iomem_operations);
73020+#endif
73021 return 0;
73022 }
73023 __initcall(ioresources_init);
73024diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
73025index 98ec494..4241d6d 100644
73026--- a/kernel/rtmutex-tester.c
73027+++ b/kernel/rtmutex-tester.c
73028@@ -20,7 +20,7 @@
73029 #define MAX_RT_TEST_MUTEXES 8
73030
73031 static spinlock_t rttest_lock;
73032-static atomic_t rttest_event;
73033+static atomic_unchecked_t rttest_event;
73034
73035 struct test_thread_data {
73036 int opcode;
73037@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73038
73039 case RTTEST_LOCKCONT:
73040 td->mutexes[td->opdata] = 1;
73041- td->event = atomic_add_return(1, &rttest_event);
73042+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73043 return 0;
73044
73045 case RTTEST_RESET:
73046@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73047 return 0;
73048
73049 case RTTEST_RESETEVENT:
73050- atomic_set(&rttest_event, 0);
73051+ atomic_set_unchecked(&rttest_event, 0);
73052 return 0;
73053
73054 default:
73055@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73056 return ret;
73057
73058 td->mutexes[id] = 1;
73059- td->event = atomic_add_return(1, &rttest_event);
73060+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73061 rt_mutex_lock(&mutexes[id]);
73062- td->event = atomic_add_return(1, &rttest_event);
73063+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73064 td->mutexes[id] = 4;
73065 return 0;
73066
73067@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73068 return ret;
73069
73070 td->mutexes[id] = 1;
73071- td->event = atomic_add_return(1, &rttest_event);
73072+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73073 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
73074- td->event = atomic_add_return(1, &rttest_event);
73075+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73076 td->mutexes[id] = ret ? 0 : 4;
73077 return ret ? -EINTR : 0;
73078
73079@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73080 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
73081 return ret;
73082
73083- td->event = atomic_add_return(1, &rttest_event);
73084+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73085 rt_mutex_unlock(&mutexes[id]);
73086- td->event = atomic_add_return(1, &rttest_event);
73087+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73088 td->mutexes[id] = 0;
73089 return 0;
73090
73091@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73092 break;
73093
73094 td->mutexes[dat] = 2;
73095- td->event = atomic_add_return(1, &rttest_event);
73096+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73097 break;
73098
73099 default:
73100@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73101 return;
73102
73103 td->mutexes[dat] = 3;
73104- td->event = atomic_add_return(1, &rttest_event);
73105+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73106 break;
73107
73108 case RTTEST_LOCKNOWAIT:
73109@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73110 return;
73111
73112 td->mutexes[dat] = 1;
73113- td->event = atomic_add_return(1, &rttest_event);
73114+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73115 return;
73116
73117 default:
73118diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
73119index 0984a21..939f183 100644
73120--- a/kernel/sched/auto_group.c
73121+++ b/kernel/sched/auto_group.c
73122@@ -11,7 +11,7 @@
73123
73124 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
73125 static struct autogroup autogroup_default;
73126-static atomic_t autogroup_seq_nr;
73127+static atomic_unchecked_t autogroup_seq_nr;
73128
73129 void __init autogroup_init(struct task_struct *init_task)
73130 {
73131@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
73132
73133 kref_init(&ag->kref);
73134 init_rwsem(&ag->lock);
73135- ag->id = atomic_inc_return(&autogroup_seq_nr);
73136+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
73137 ag->tg = tg;
73138 #ifdef CONFIG_RT_GROUP_SCHED
73139 /*
73140diff --git a/kernel/sched/core.c b/kernel/sched/core.c
73141index 26058d0..06f15dd 100644
73142--- a/kernel/sched/core.c
73143+++ b/kernel/sched/core.c
73144@@ -3631,6 +3631,8 @@ int can_nice(const struct task_struct *p, const int nice)
73145 /* convert nice value [19,-20] to rlimit style value [1,40] */
73146 int nice_rlim = 20 - nice;
73147
73148+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
73149+
73150 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
73151 capable(CAP_SYS_NICE));
73152 }
73153@@ -3664,7 +3666,8 @@ SYSCALL_DEFINE1(nice, int, increment)
73154 if (nice > 19)
73155 nice = 19;
73156
73157- if (increment < 0 && !can_nice(current, nice))
73158+ if (increment < 0 && (!can_nice(current, nice) ||
73159+ gr_handle_chroot_nice()))
73160 return -EPERM;
73161
73162 retval = security_task_setnice(current, nice);
73163@@ -3818,6 +3821,7 @@ recheck:
73164 unsigned long rlim_rtprio =
73165 task_rlimit(p, RLIMIT_RTPRIO);
73166
73167+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
73168 /* can't set/change the rt policy */
73169 if (policy != p->policy && !rlim_rtprio)
73170 return -EPERM;
73171@@ -5162,7 +5166,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
73172 * happens before everything else. This has to be lower priority than
73173 * the notifier in the perf_event subsystem, though.
73174 */
73175-static struct notifier_block __cpuinitdata migration_notifier = {
73176+static struct notifier_block migration_notifier = {
73177 .notifier_call = migration_call,
73178 .priority = CPU_PRI_MIGRATION,
73179 };
73180diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
73181index 81fa536..6ccf96a 100644
73182--- a/kernel/sched/fair.c
73183+++ b/kernel/sched/fair.c
73184@@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
73185
73186 static void reset_ptenuma_scan(struct task_struct *p)
73187 {
73188- ACCESS_ONCE(p->mm->numa_scan_seq)++;
73189+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
73190 p->mm->numa_scan_offset = 0;
73191 }
73192
73193@@ -3254,25 +3254,18 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
73194 */
73195 static int select_idle_sibling(struct task_struct *p, int target)
73196 {
73197- int cpu = smp_processor_id();
73198- int prev_cpu = task_cpu(p);
73199 struct sched_domain *sd;
73200 struct sched_group *sg;
73201- int i;
73202+ int i = task_cpu(p);
73203
73204- /*
73205- * If the task is going to be woken-up on this cpu and if it is
73206- * already idle, then it is the right target.
73207- */
73208- if (target == cpu && idle_cpu(cpu))
73209- return cpu;
73210+ if (idle_cpu(target))
73211+ return target;
73212
73213 /*
73214- * If the task is going to be woken-up on the cpu where it previously
73215- * ran and if it is currently idle, then it the right target.
73216+ * If the prevous cpu is cache affine and idle, don't be stupid.
73217 */
73218- if (target == prev_cpu && idle_cpu(prev_cpu))
73219- return prev_cpu;
73220+ if (i != target && cpus_share_cache(i, target) && idle_cpu(i))
73221+ return i;
73222
73223 /*
73224 * Otherwise, iterate the domains and find an elegible idle cpu.
73225@@ -3286,7 +3279,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
73226 goto next;
73227
73228 for_each_cpu(i, sched_group_cpus(sg)) {
73229- if (!idle_cpu(i))
73230+ if (i == target || !idle_cpu(i))
73231 goto next;
73232 }
73233
73234@@ -5663,7 +5656,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
73235 * run_rebalance_domains is triggered when needed from the scheduler tick.
73236 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
73237 */
73238-static void run_rebalance_domains(struct softirq_action *h)
73239+static void run_rebalance_domains(void)
73240 {
73241 int this_cpu = smp_processor_id();
73242 struct rq *this_rq = cpu_rq(this_cpu);
73243diff --git a/kernel/signal.c b/kernel/signal.c
73244index 3d09cf6..a67d2c6 100644
73245--- a/kernel/signal.c
73246+++ b/kernel/signal.c
73247@@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
73248
73249 int print_fatal_signals __read_mostly;
73250
73251-static void __user *sig_handler(struct task_struct *t, int sig)
73252+static __sighandler_t sig_handler(struct task_struct *t, int sig)
73253 {
73254 return t->sighand->action[sig - 1].sa.sa_handler;
73255 }
73256
73257-static int sig_handler_ignored(void __user *handler, int sig)
73258+static int sig_handler_ignored(__sighandler_t handler, int sig)
73259 {
73260 /* Is it explicitly or implicitly ignored? */
73261 return handler == SIG_IGN ||
73262@@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
73263
73264 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
73265 {
73266- void __user *handler;
73267+ __sighandler_t handler;
73268
73269 handler = sig_handler(t, sig);
73270
73271@@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
73272 atomic_inc(&user->sigpending);
73273 rcu_read_unlock();
73274
73275+ if (!override_rlimit)
73276+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
73277+
73278 if (override_rlimit ||
73279 atomic_read(&user->sigpending) <=
73280 task_rlimit(t, RLIMIT_SIGPENDING)) {
73281@@ -492,7 +495,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
73282
73283 int unhandled_signal(struct task_struct *tsk, int sig)
73284 {
73285- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
73286+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
73287 if (is_global_init(tsk))
73288 return 1;
73289 if (handler != SIG_IGN && handler != SIG_DFL)
73290@@ -812,6 +815,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
73291 }
73292 }
73293
73294+ /* allow glibc communication via tgkill to other threads in our
73295+ thread group */
73296+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
73297+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
73298+ && gr_handle_signal(t, sig))
73299+ return -EPERM;
73300+
73301 return security_task_kill(t, info, sig, 0);
73302 }
73303
73304@@ -1194,7 +1204,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
73305 return send_signal(sig, info, p, 1);
73306 }
73307
73308-static int
73309+int
73310 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73311 {
73312 return send_signal(sig, info, t, 0);
73313@@ -1231,6 +1241,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73314 unsigned long int flags;
73315 int ret, blocked, ignored;
73316 struct k_sigaction *action;
73317+ int is_unhandled = 0;
73318
73319 spin_lock_irqsave(&t->sighand->siglock, flags);
73320 action = &t->sighand->action[sig-1];
73321@@ -1245,9 +1256,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73322 }
73323 if (action->sa.sa_handler == SIG_DFL)
73324 t->signal->flags &= ~SIGNAL_UNKILLABLE;
73325+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
73326+ is_unhandled = 1;
73327 ret = specific_send_sig_info(sig, info, t);
73328 spin_unlock_irqrestore(&t->sighand->siglock, flags);
73329
73330+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
73331+ normal operation */
73332+ if (is_unhandled) {
73333+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
73334+ gr_handle_crash(t, sig);
73335+ }
73336+
73337 return ret;
73338 }
73339
73340@@ -1314,8 +1334,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
73341 ret = check_kill_permission(sig, info, p);
73342 rcu_read_unlock();
73343
73344- if (!ret && sig)
73345+ if (!ret && sig) {
73346 ret = do_send_sig_info(sig, info, p, true);
73347+ if (!ret)
73348+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
73349+ }
73350
73351 return ret;
73352 }
73353@@ -2852,7 +2875,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
73354 int error = -ESRCH;
73355
73356 rcu_read_lock();
73357- p = find_task_by_vpid(pid);
73358+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73359+ /* allow glibc communication via tgkill to other threads in our
73360+ thread group */
73361+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
73362+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
73363+ p = find_task_by_vpid_unrestricted(pid);
73364+ else
73365+#endif
73366+ p = find_task_by_vpid(pid);
73367 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
73368 error = check_kill_permission(sig, info, p);
73369 /*
73370@@ -3135,8 +3166,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
73371 }
73372 seg = get_fs();
73373 set_fs(KERNEL_DS);
73374- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
73375- (stack_t __force __user *) &uoss,
73376+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
73377+ (stack_t __force_user *) &uoss,
73378 compat_user_stack_pointer());
73379 set_fs(seg);
73380 if (ret >= 0 && uoss_ptr) {
73381diff --git a/kernel/smp.c b/kernel/smp.c
73382index 69f38bd..77bbf12 100644
73383--- a/kernel/smp.c
73384+++ b/kernel/smp.c
73385@@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
73386 return NOTIFY_OK;
73387 }
73388
73389-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
73390+static struct notifier_block hotplug_cfd_notifier = {
73391 .notifier_call = hotplug_cfd,
73392 };
73393
73394diff --git a/kernel/softirq.c b/kernel/softirq.c
73395index ed567ba..dc61b61 100644
73396--- a/kernel/softirq.c
73397+++ b/kernel/softirq.c
73398@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
73399 EXPORT_SYMBOL(irq_stat);
73400 #endif
73401
73402-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
73403+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
73404
73405 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
73406
73407-char *softirq_to_name[NR_SOFTIRQS] = {
73408+const char * const softirq_to_name[NR_SOFTIRQS] = {
73409 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
73410 "TASKLET", "SCHED", "HRTIMER", "RCU"
73411 };
73412@@ -244,7 +244,7 @@ restart:
73413 kstat_incr_softirqs_this_cpu(vec_nr);
73414
73415 trace_softirq_entry(vec_nr);
73416- h->action(h);
73417+ h->action();
73418 trace_softirq_exit(vec_nr);
73419 if (unlikely(prev_count != preempt_count())) {
73420 printk(KERN_ERR "huh, entered softirq %u %s %p"
73421@@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
73422 or_softirq_pending(1UL << nr);
73423 }
73424
73425-void open_softirq(int nr, void (*action)(struct softirq_action *))
73426+void __init open_softirq(int nr, void (*action)(void))
73427 {
73428 softirq_vec[nr].action = action;
73429 }
73430@@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
73431
73432 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
73433
73434-static void tasklet_action(struct softirq_action *a)
73435+static void tasklet_action(void)
73436 {
73437 struct tasklet_struct *list;
73438
73439@@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
73440 }
73441 }
73442
73443-static void tasklet_hi_action(struct softirq_action *a)
73444+static void tasklet_hi_action(void)
73445 {
73446 struct tasklet_struct *list;
73447
73448@@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
73449 return NOTIFY_OK;
73450 }
73451
73452-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
73453+static struct notifier_block remote_softirq_cpu_notifier = {
73454 .notifier_call = remote_softirq_cpu_notify,
73455 };
73456
73457@@ -835,7 +835,7 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
73458 return NOTIFY_OK;
73459 }
73460
73461-static struct notifier_block __cpuinitdata cpu_nfb = {
73462+static struct notifier_block cpu_nfb = {
73463 .notifier_call = cpu_callback
73464 };
73465
73466diff --git a/kernel/srcu.c b/kernel/srcu.c
73467index 2b85982..d52ab26 100644
73468--- a/kernel/srcu.c
73469+++ b/kernel/srcu.c
73470@@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
73471 preempt_disable();
73472 idx = rcu_dereference_index_check(sp->completed,
73473 rcu_read_lock_sched_held()) & 0x1;
73474- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
73475+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
73476 smp_mb(); /* B */ /* Avoid leaking the critical section. */
73477- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
73478+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
73479 preempt_enable();
73480 return idx;
73481 }
73482@@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
73483 {
73484 preempt_disable();
73485 smp_mb(); /* C */ /* Avoid leaking the critical section. */
73486- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
73487+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
73488 preempt_enable();
73489 }
73490 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
73491diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
73492index 2f194e9..2c05ea9 100644
73493--- a/kernel/stop_machine.c
73494+++ b/kernel/stop_machine.c
73495@@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
73496 * cpu notifiers. It currently shares the same priority as sched
73497 * migration_notifier.
73498 */
73499-static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
73500+static struct notifier_block cpu_stop_cpu_notifier = {
73501 .notifier_call = cpu_stop_cpu_callback,
73502 .priority = 10,
73503 };
73504diff --git a/kernel/sys.c b/kernel/sys.c
73505index 265b376..b0cd50d 100644
73506--- a/kernel/sys.c
73507+++ b/kernel/sys.c
73508@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
73509 error = -EACCES;
73510 goto out;
73511 }
73512+
73513+ if (gr_handle_chroot_setpriority(p, niceval)) {
73514+ error = -EACCES;
73515+ goto out;
73516+ }
73517+
73518 no_nice = security_task_setnice(p, niceval);
73519 if (no_nice) {
73520 error = no_nice;
73521@@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
73522 goto error;
73523 }
73524
73525+ if (gr_check_group_change(new->gid, new->egid, -1))
73526+ goto error;
73527+
73528 if (rgid != (gid_t) -1 ||
73529 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
73530 new->sgid = new->egid;
73531@@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
73532 old = current_cred();
73533
73534 retval = -EPERM;
73535+
73536+ if (gr_check_group_change(kgid, kgid, kgid))
73537+ goto error;
73538+
73539 if (nsown_capable(CAP_SETGID))
73540 new->gid = new->egid = new->sgid = new->fsgid = kgid;
73541 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
73542@@ -647,7 +660,7 @@ error:
73543 /*
73544 * change the user struct in a credentials set to match the new UID
73545 */
73546-static int set_user(struct cred *new)
73547+int set_user(struct cred *new)
73548 {
73549 struct user_struct *new_user;
73550
73551@@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
73552 goto error;
73553 }
73554
73555+ if (gr_check_user_change(new->uid, new->euid, -1))
73556+ goto error;
73557+
73558 if (!uid_eq(new->uid, old->uid)) {
73559 retval = set_user(new);
73560 if (retval < 0)
73561@@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
73562 old = current_cred();
73563
73564 retval = -EPERM;
73565+
73566+ if (gr_check_crash_uid(kuid))
73567+ goto error;
73568+ if (gr_check_user_change(kuid, kuid, kuid))
73569+ goto error;
73570+
73571 if (nsown_capable(CAP_SETUID)) {
73572 new->suid = new->uid = kuid;
73573 if (!uid_eq(kuid, old->uid)) {
73574@@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
73575 goto error;
73576 }
73577
73578+ if (gr_check_user_change(kruid, keuid, -1))
73579+ goto error;
73580+
73581 if (ruid != (uid_t) -1) {
73582 new->uid = kruid;
73583 if (!uid_eq(kruid, old->uid)) {
73584@@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
73585 goto error;
73586 }
73587
73588+ if (gr_check_group_change(krgid, kegid, -1))
73589+ goto error;
73590+
73591 if (rgid != (gid_t) -1)
73592 new->gid = krgid;
73593 if (egid != (gid_t) -1)
73594@@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
73595 if (!uid_valid(kuid))
73596 return old_fsuid;
73597
73598+ if (gr_check_user_change(-1, -1, kuid))
73599+ goto error;
73600+
73601 new = prepare_creds();
73602 if (!new)
73603 return old_fsuid;
73604@@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
73605 }
73606 }
73607
73608+error:
73609 abort_creds(new);
73610 return old_fsuid;
73611
73612@@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
73613 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
73614 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
73615 nsown_capable(CAP_SETGID)) {
73616+ if (gr_check_group_change(-1, -1, kgid))
73617+ goto error;
73618+
73619 if (!gid_eq(kgid, old->fsgid)) {
73620 new->fsgid = kgid;
73621 goto change_okay;
73622 }
73623 }
73624
73625+error:
73626 abort_creds(new);
73627 return old_fsgid;
73628
73629@@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
73630 return -EFAULT;
73631
73632 down_read(&uts_sem);
73633- error = __copy_to_user(&name->sysname, &utsname()->sysname,
73634+ error = __copy_to_user(name->sysname, &utsname()->sysname,
73635 __OLD_UTS_LEN);
73636 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
73637- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
73638+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
73639 __OLD_UTS_LEN);
73640 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
73641- error |= __copy_to_user(&name->release, &utsname()->release,
73642+ error |= __copy_to_user(name->release, &utsname()->release,
73643 __OLD_UTS_LEN);
73644 error |= __put_user(0, name->release + __OLD_UTS_LEN);
73645- error |= __copy_to_user(&name->version, &utsname()->version,
73646+ error |= __copy_to_user(name->version, &utsname()->version,
73647 __OLD_UTS_LEN);
73648 error |= __put_user(0, name->version + __OLD_UTS_LEN);
73649- error |= __copy_to_user(&name->machine, &utsname()->machine,
73650+ error |= __copy_to_user(name->machine, &utsname()->machine,
73651 __OLD_UTS_LEN);
73652 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
73653 up_read(&uts_sem);
73654@@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
73655 error = get_dumpable(me->mm);
73656 break;
73657 case PR_SET_DUMPABLE:
73658- if (arg2 < 0 || arg2 > 1) {
73659+ if (arg2 > 1) {
73660 error = -EINVAL;
73661 break;
73662 }
73663diff --git a/kernel/sysctl.c b/kernel/sysctl.c
73664index c88878d..99d321b 100644
73665--- a/kernel/sysctl.c
73666+++ b/kernel/sysctl.c
73667@@ -92,7 +92,6 @@
73668
73669
73670 #if defined(CONFIG_SYSCTL)
73671-
73672 /* External variables not in a header file. */
73673 extern int sysctl_overcommit_memory;
73674 extern int sysctl_overcommit_ratio;
73675@@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
73676 void __user *buffer, size_t *lenp, loff_t *ppos);
73677 #endif
73678
73679-#ifdef CONFIG_PRINTK
73680 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73681 void __user *buffer, size_t *lenp, loff_t *ppos);
73682-#endif
73683
73684 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
73685 void __user *buffer, size_t *lenp, loff_t *ppos);
73686@@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
73687
73688 #endif
73689
73690+extern struct ctl_table grsecurity_table[];
73691+
73692 static struct ctl_table kern_table[];
73693 static struct ctl_table vm_table[];
73694 static struct ctl_table fs_table[];
73695@@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
73696 int sysctl_legacy_va_layout;
73697 #endif
73698
73699+#ifdef CONFIG_PAX_SOFTMODE
73700+static ctl_table pax_table[] = {
73701+ {
73702+ .procname = "softmode",
73703+ .data = &pax_softmode,
73704+ .maxlen = sizeof(unsigned int),
73705+ .mode = 0600,
73706+ .proc_handler = &proc_dointvec,
73707+ },
73708+
73709+ { }
73710+};
73711+#endif
73712+
73713 /* The default sysctl tables: */
73714
73715 static struct ctl_table sysctl_base_table[] = {
73716@@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
73717 #endif
73718
73719 static struct ctl_table kern_table[] = {
73720+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
73721+ {
73722+ .procname = "grsecurity",
73723+ .mode = 0500,
73724+ .child = grsecurity_table,
73725+ },
73726+#endif
73727+
73728+#ifdef CONFIG_PAX_SOFTMODE
73729+ {
73730+ .procname = "pax",
73731+ .mode = 0500,
73732+ .child = pax_table,
73733+ },
73734+#endif
73735+
73736 {
73737 .procname = "sched_child_runs_first",
73738 .data = &sysctl_sched_child_runs_first,
73739@@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
73740 .data = &modprobe_path,
73741 .maxlen = KMOD_PATH_LEN,
73742 .mode = 0644,
73743- .proc_handler = proc_dostring,
73744+ .proc_handler = proc_dostring_modpriv,
73745 },
73746 {
73747 .procname = "modules_disabled",
73748@@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
73749 .extra1 = &zero,
73750 .extra2 = &one,
73751 },
73752+#endif
73753 {
73754 .procname = "kptr_restrict",
73755 .data = &kptr_restrict,
73756 .maxlen = sizeof(int),
73757 .mode = 0644,
73758 .proc_handler = proc_dointvec_minmax_sysadmin,
73759+#ifdef CONFIG_GRKERNSEC_HIDESYM
73760+ .extra1 = &two,
73761+#else
73762 .extra1 = &zero,
73763+#endif
73764 .extra2 = &two,
73765 },
73766-#endif
73767 {
73768 .procname = "ngroups_max",
73769 .data = &ngroups_max,
73770@@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
73771 .proc_handler = proc_dointvec_minmax,
73772 .extra1 = &zero,
73773 },
73774+ {
73775+ .procname = "heap_stack_gap",
73776+ .data = &sysctl_heap_stack_gap,
73777+ .maxlen = sizeof(sysctl_heap_stack_gap),
73778+ .mode = 0644,
73779+ .proc_handler = proc_doulongvec_minmax,
73780+ },
73781 #else
73782 {
73783 .procname = "nr_trim_pages",
73784@@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
73785 buffer, lenp, ppos);
73786 }
73787
73788+int proc_dostring_modpriv(struct ctl_table *table, int write,
73789+ void __user *buffer, size_t *lenp, loff_t *ppos)
73790+{
73791+ if (write && !capable(CAP_SYS_MODULE))
73792+ return -EPERM;
73793+
73794+ return _proc_do_string(table->data, table->maxlen, write,
73795+ buffer, lenp, ppos);
73796+}
73797+
73798 static size_t proc_skip_spaces(char **buf)
73799 {
73800 size_t ret;
73801@@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
73802 len = strlen(tmp);
73803 if (len > *size)
73804 len = *size;
73805+ if (len > sizeof(tmp))
73806+ len = sizeof(tmp);
73807 if (copy_to_user(*buf, tmp, len))
73808 return -EFAULT;
73809 *size -= len;
73810@@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
73811 return err;
73812 }
73813
73814-#ifdef CONFIG_PRINTK
73815 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73816 void __user *buffer, size_t *lenp, loff_t *ppos)
73817 {
73818@@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73819
73820 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
73821 }
73822-#endif
73823
73824 struct do_proc_dointvec_minmax_conv_param {
73825 int *min;
73826@@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
73827 *i = val;
73828 } else {
73829 val = convdiv * (*i) / convmul;
73830- if (!first)
73831+ if (!first) {
73832 err = proc_put_char(&buffer, &left, '\t');
73833+ if (err)
73834+ break;
73835+ }
73836 err = proc_put_long(&buffer, &left, val, false);
73837 if (err)
73838 break;
73839@@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
73840 return -ENOSYS;
73841 }
73842
73843+int proc_dostring_modpriv(struct ctl_table *table, int write,
73844+ void __user *buffer, size_t *lenp, loff_t *ppos)
73845+{
73846+ return -ENOSYS;
73847+}
73848+
73849 int proc_dointvec(struct ctl_table *table, int write,
73850 void __user *buffer, size_t *lenp, loff_t *ppos)
73851 {
73852@@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
73853 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
73854 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
73855 EXPORT_SYMBOL(proc_dostring);
73856+EXPORT_SYMBOL(proc_dostring_modpriv);
73857 EXPORT_SYMBOL(proc_doulongvec_minmax);
73858 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
73859diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
73860index 5a63844..25dfc5c 100644
73861--- a/kernel/sysctl_binary.c
73862+++ b/kernel/sysctl_binary.c
73863@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
73864 int i;
73865
73866 set_fs(KERNEL_DS);
73867- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
73868+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
73869 set_fs(old_fs);
73870 if (result < 0)
73871 goto out_kfree;
73872@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
73873 }
73874
73875 set_fs(KERNEL_DS);
73876- result = vfs_write(file, buffer, str - buffer, &pos);
73877+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
73878 set_fs(old_fs);
73879 if (result < 0)
73880 goto out_kfree;
73881@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
73882 int i;
73883
73884 set_fs(KERNEL_DS);
73885- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
73886+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
73887 set_fs(old_fs);
73888 if (result < 0)
73889 goto out_kfree;
73890@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
73891 }
73892
73893 set_fs(KERNEL_DS);
73894- result = vfs_write(file, buffer, str - buffer, &pos);
73895+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
73896 set_fs(old_fs);
73897 if (result < 0)
73898 goto out_kfree;
73899@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
73900 int i;
73901
73902 set_fs(KERNEL_DS);
73903- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
73904+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
73905 set_fs(old_fs);
73906 if (result < 0)
73907 goto out;
73908@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
73909 __le16 dnaddr;
73910
73911 set_fs(KERNEL_DS);
73912- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
73913+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
73914 set_fs(old_fs);
73915 if (result < 0)
73916 goto out;
73917@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
73918 le16_to_cpu(dnaddr) & 0x3ff);
73919
73920 set_fs(KERNEL_DS);
73921- result = vfs_write(file, buf, len, &pos);
73922+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
73923 set_fs(old_fs);
73924 if (result < 0)
73925 goto out;
73926diff --git a/kernel/taskstats.c b/kernel/taskstats.c
73927index 145bb4d..b2aa969 100644
73928--- a/kernel/taskstats.c
73929+++ b/kernel/taskstats.c
73930@@ -28,9 +28,12 @@
73931 #include <linux/fs.h>
73932 #include <linux/file.h>
73933 #include <linux/pid_namespace.h>
73934+#include <linux/grsecurity.h>
73935 #include <net/genetlink.h>
73936 #include <linux/atomic.h>
73937
73938+extern int gr_is_taskstats_denied(int pid);
73939+
73940 /*
73941 * Maximum length of a cpumask that can be specified in
73942 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
73943@@ -570,6 +573,9 @@ err:
73944
73945 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
73946 {
73947+ if (gr_is_taskstats_denied(current->pid))
73948+ return -EACCES;
73949+
73950 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
73951 return cmd_attr_register_cpumask(info);
73952 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
73953diff --git a/kernel/time.c b/kernel/time.c
73954index d226c6a..c7c0960 100644
73955--- a/kernel/time.c
73956+++ b/kernel/time.c
73957@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
73958 return error;
73959
73960 if (tz) {
73961+ /* we log in do_settimeofday called below, so don't log twice
73962+ */
73963+ if (!tv)
73964+ gr_log_timechange();
73965+
73966 sys_tz = *tz;
73967 update_vsyscall_tz();
73968 if (firsttime) {
73969diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
73970index f11d83b..d016d91 100644
73971--- a/kernel/time/alarmtimer.c
73972+++ b/kernel/time/alarmtimer.c
73973@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
73974 struct platform_device *pdev;
73975 int error = 0;
73976 int i;
73977- struct k_clock alarm_clock = {
73978+ static struct k_clock alarm_clock = {
73979 .clock_getres = alarm_clock_getres,
73980 .clock_get = alarm_clock_get,
73981 .timer_create = alarm_timer_create,
73982diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
73983index f113755..ec24223 100644
73984--- a/kernel/time/tick-broadcast.c
73985+++ b/kernel/time/tick-broadcast.c
73986@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
73987 * then clear the broadcast bit.
73988 */
73989 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
73990- int cpu = smp_processor_id();
73991+ cpu = smp_processor_id();
73992
73993 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
73994 tick_broadcast_clear_oneshot(cpu);
73995diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
73996index cbc6acb..3a77191 100644
73997--- a/kernel/time/timekeeping.c
73998+++ b/kernel/time/timekeeping.c
73999@@ -15,6 +15,7 @@
74000 #include <linux/init.h>
74001 #include <linux/mm.h>
74002 #include <linux/sched.h>
74003+#include <linux/grsecurity.h>
74004 #include <linux/syscore_ops.h>
74005 #include <linux/clocksource.h>
74006 #include <linux/jiffies.h>
74007@@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
74008 if (!timespec_valid_strict(tv))
74009 return -EINVAL;
74010
74011+ gr_log_timechange();
74012+
74013 write_seqlock_irqsave(&tk->lock, flags);
74014
74015 timekeeping_forward_now(tk);
74016diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
74017index af5a7e9..715611a 100644
74018--- a/kernel/time/timer_list.c
74019+++ b/kernel/time/timer_list.c
74020@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
74021
74022 static void print_name_offset(struct seq_file *m, void *sym)
74023 {
74024+#ifdef CONFIG_GRKERNSEC_HIDESYM
74025+ SEQ_printf(m, "<%p>", NULL);
74026+#else
74027 char symname[KSYM_NAME_LEN];
74028
74029 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
74030 SEQ_printf(m, "<%pK>", sym);
74031 else
74032 SEQ_printf(m, "%s", symname);
74033+#endif
74034 }
74035
74036 static void
74037@@ -112,7 +116,11 @@ next_one:
74038 static void
74039 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
74040 {
74041+#ifdef CONFIG_GRKERNSEC_HIDESYM
74042+ SEQ_printf(m, " .base: %p\n", NULL);
74043+#else
74044 SEQ_printf(m, " .base: %pK\n", base);
74045+#endif
74046 SEQ_printf(m, " .index: %d\n",
74047 base->index);
74048 SEQ_printf(m, " .resolution: %Lu nsecs\n",
74049@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
74050 {
74051 struct proc_dir_entry *pe;
74052
74053+#ifdef CONFIG_GRKERNSEC_PROC_ADD
74054+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
74055+#else
74056 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
74057+#endif
74058 if (!pe)
74059 return -ENOMEM;
74060 return 0;
74061diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
74062index 0b537f2..40d6c20 100644
74063--- a/kernel/time/timer_stats.c
74064+++ b/kernel/time/timer_stats.c
74065@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
74066 static unsigned long nr_entries;
74067 static struct entry entries[MAX_ENTRIES];
74068
74069-static atomic_t overflow_count;
74070+static atomic_unchecked_t overflow_count;
74071
74072 /*
74073 * The entries are in a hash-table, for fast lookup:
74074@@ -140,7 +140,7 @@ static void reset_entries(void)
74075 nr_entries = 0;
74076 memset(entries, 0, sizeof(entries));
74077 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
74078- atomic_set(&overflow_count, 0);
74079+ atomic_set_unchecked(&overflow_count, 0);
74080 }
74081
74082 static struct entry *alloc_entry(void)
74083@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
74084 if (likely(entry))
74085 entry->count++;
74086 else
74087- atomic_inc(&overflow_count);
74088+ atomic_inc_unchecked(&overflow_count);
74089
74090 out_unlock:
74091 raw_spin_unlock_irqrestore(lock, flags);
74092@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
74093
74094 static void print_name_offset(struct seq_file *m, unsigned long addr)
74095 {
74096+#ifdef CONFIG_GRKERNSEC_HIDESYM
74097+ seq_printf(m, "<%p>", NULL);
74098+#else
74099 char symname[KSYM_NAME_LEN];
74100
74101 if (lookup_symbol_name(addr, symname) < 0)
74102- seq_printf(m, "<%p>", (void *)addr);
74103+ seq_printf(m, "<%pK>", (void *)addr);
74104 else
74105 seq_printf(m, "%s", symname);
74106+#endif
74107 }
74108
74109 static int tstats_show(struct seq_file *m, void *v)
74110@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
74111
74112 seq_puts(m, "Timer Stats Version: v0.2\n");
74113 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
74114- if (atomic_read(&overflow_count))
74115+ if (atomic_read_unchecked(&overflow_count))
74116 seq_printf(m, "Overflow: %d entries\n",
74117- atomic_read(&overflow_count));
74118+ atomic_read_unchecked(&overflow_count));
74119
74120 for (i = 0; i < nr_entries; i++) {
74121 entry = entries + i;
74122@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
74123 {
74124 struct proc_dir_entry *pe;
74125
74126+#ifdef CONFIG_GRKERNSEC_PROC_ADD
74127+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
74128+#else
74129 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
74130+#endif
74131 if (!pe)
74132 return -ENOMEM;
74133 return 0;
74134diff --git a/kernel/timer.c b/kernel/timer.c
74135index 367d008..1ee9ed9 100644
74136--- a/kernel/timer.c
74137+++ b/kernel/timer.c
74138@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
74139 /*
74140 * This function runs timers and the timer-tq in bottom half context.
74141 */
74142-static void run_timer_softirq(struct softirq_action *h)
74143+static void run_timer_softirq(void)
74144 {
74145 struct tvec_base *base = __this_cpu_read(tvec_bases);
74146
74147@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
74148 return NOTIFY_OK;
74149 }
74150
74151-static struct notifier_block __cpuinitdata timers_nb = {
74152+static struct notifier_block timers_nb = {
74153 .notifier_call = timer_cpu_notify,
74154 };
74155
74156diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
74157index c0bd030..62a1927 100644
74158--- a/kernel/trace/blktrace.c
74159+++ b/kernel/trace/blktrace.c
74160@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
74161 struct blk_trace *bt = filp->private_data;
74162 char buf[16];
74163
74164- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
74165+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
74166
74167 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
74168 }
74169@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
74170 return 1;
74171
74172 bt = buf->chan->private_data;
74173- atomic_inc(&bt->dropped);
74174+ atomic_inc_unchecked(&bt->dropped);
74175 return 0;
74176 }
74177
74178@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
74179
74180 bt->dir = dir;
74181 bt->dev = dev;
74182- atomic_set(&bt->dropped, 0);
74183+ atomic_set_unchecked(&bt->dropped, 0);
74184
74185 ret = -EIO;
74186 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
74187diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
74188index 41473b4..325fcfc 100644
74189--- a/kernel/trace/ftrace.c
74190+++ b/kernel/trace/ftrace.c
74191@@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
74192 if (unlikely(ftrace_disabled))
74193 return 0;
74194
74195+ ret = ftrace_arch_code_modify_prepare();
74196+ FTRACE_WARN_ON(ret);
74197+ if (ret)
74198+ return 0;
74199+
74200 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
74201+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
74202 if (ret) {
74203 ftrace_bug(ret, ip);
74204- return 0;
74205 }
74206- return 1;
74207+ return ret ? 0 : 1;
74208 }
74209
74210 /*
74211@@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
74212
74213 int
74214 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
74215- void *data)
74216+ void *data)
74217 {
74218 struct ftrace_func_probe *entry;
74219 struct ftrace_page *pg;
74220@@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
74221 if (!count)
74222 return 0;
74223
74224+ pax_open_kernel();
74225 sort(start, count, sizeof(*start),
74226 ftrace_cmp_ips, ftrace_swap_ips);
74227+ pax_close_kernel();
74228
74229 start_pg = ftrace_allocate_pages(count);
74230 if (!start_pg)
74231@@ -4541,8 +4548,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
74232 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
74233
74234 static int ftrace_graph_active;
74235-static struct notifier_block ftrace_suspend_notifier;
74236-
74237 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
74238 {
74239 return 0;
74240@@ -4686,6 +4691,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
74241 return NOTIFY_DONE;
74242 }
74243
74244+static struct notifier_block ftrace_suspend_notifier = {
74245+ .notifier_call = ftrace_suspend_notifier_call
74246+};
74247+
74248 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
74249 trace_func_graph_ent_t entryfunc)
74250 {
74251@@ -4699,7 +4708,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
74252 goto out;
74253 }
74254
74255- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
74256 register_pm_notifier(&ftrace_suspend_notifier);
74257
74258 ftrace_graph_active++;
74259diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
74260index ce8514f..8233573 100644
74261--- a/kernel/trace/ring_buffer.c
74262+++ b/kernel/trace/ring_buffer.c
74263@@ -346,9 +346,9 @@ struct buffer_data_page {
74264 */
74265 struct buffer_page {
74266 struct list_head list; /* list of buffer pages */
74267- local_t write; /* index for next write */
74268+ local_unchecked_t write; /* index for next write */
74269 unsigned read; /* index for next read */
74270- local_t entries; /* entries on this page */
74271+ local_unchecked_t entries; /* entries on this page */
74272 unsigned long real_end; /* real end of data */
74273 struct buffer_data_page *page; /* Actual data page */
74274 };
74275@@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
74276 unsigned long last_overrun;
74277 local_t entries_bytes;
74278 local_t entries;
74279- local_t overrun;
74280- local_t commit_overrun;
74281+ local_unchecked_t overrun;
74282+ local_unchecked_t commit_overrun;
74283 local_t dropped_events;
74284 local_t committing;
74285 local_t commits;
74286@@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
74287 *
74288 * We add a counter to the write field to denote this.
74289 */
74290- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
74291- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
74292+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
74293+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
74294
74295 /*
74296 * Just make sure we have seen our old_write and synchronize
74297@@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
74298 * cmpxchg to only update if an interrupt did not already
74299 * do it for us. If the cmpxchg fails, we don't care.
74300 */
74301- (void)local_cmpxchg(&next_page->write, old_write, val);
74302- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
74303+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
74304+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
74305
74306 /*
74307 * No need to worry about races with clearing out the commit.
74308@@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
74309
74310 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
74311 {
74312- return local_read(&bpage->entries) & RB_WRITE_MASK;
74313+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
74314 }
74315
74316 static inline unsigned long rb_page_write(struct buffer_page *bpage)
74317 {
74318- return local_read(&bpage->write) & RB_WRITE_MASK;
74319+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
74320 }
74321
74322 static int
74323@@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
74324 * bytes consumed in ring buffer from here.
74325 * Increment overrun to account for the lost events.
74326 */
74327- local_add(page_entries, &cpu_buffer->overrun);
74328+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
74329 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
74330 }
74331
74332@@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
74333 * it is our responsibility to update
74334 * the counters.
74335 */
74336- local_add(entries, &cpu_buffer->overrun);
74337+ local_add_unchecked(entries, &cpu_buffer->overrun);
74338 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
74339
74340 /*
74341@@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74342 if (tail == BUF_PAGE_SIZE)
74343 tail_page->real_end = 0;
74344
74345- local_sub(length, &tail_page->write);
74346+ local_sub_unchecked(length, &tail_page->write);
74347 return;
74348 }
74349
74350@@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74351 rb_event_set_padding(event);
74352
74353 /* Set the write back to the previous setting */
74354- local_sub(length, &tail_page->write);
74355+ local_sub_unchecked(length, &tail_page->write);
74356 return;
74357 }
74358
74359@@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74360
74361 /* Set write to end of buffer */
74362 length = (tail + length) - BUF_PAGE_SIZE;
74363- local_sub(length, &tail_page->write);
74364+ local_sub_unchecked(length, &tail_page->write);
74365 }
74366
74367 /*
74368@@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
74369 * about it.
74370 */
74371 if (unlikely(next_page == commit_page)) {
74372- local_inc(&cpu_buffer->commit_overrun);
74373+ local_inc_unchecked(&cpu_buffer->commit_overrun);
74374 goto out_reset;
74375 }
74376
74377@@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
74378 cpu_buffer->tail_page) &&
74379 (cpu_buffer->commit_page ==
74380 cpu_buffer->reader_page))) {
74381- local_inc(&cpu_buffer->commit_overrun);
74382+ local_inc_unchecked(&cpu_buffer->commit_overrun);
74383 goto out_reset;
74384 }
74385 }
74386@@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
74387 length += RB_LEN_TIME_EXTEND;
74388
74389 tail_page = cpu_buffer->tail_page;
74390- write = local_add_return(length, &tail_page->write);
74391+ write = local_add_return_unchecked(length, &tail_page->write);
74392
74393 /* set write to only the index of the write */
74394 write &= RB_WRITE_MASK;
74395@@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
74396 kmemcheck_annotate_bitfield(event, bitfield);
74397 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
74398
74399- local_inc(&tail_page->entries);
74400+ local_inc_unchecked(&tail_page->entries);
74401
74402 /*
74403 * If this is the first commit on the page, then update
74404@@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
74405
74406 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
74407 unsigned long write_mask =
74408- local_read(&bpage->write) & ~RB_WRITE_MASK;
74409+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
74410 unsigned long event_length = rb_event_length(event);
74411 /*
74412 * This is on the tail page. It is possible that
74413@@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
74414 */
74415 old_index += write_mask;
74416 new_index += write_mask;
74417- index = local_cmpxchg(&bpage->write, old_index, new_index);
74418+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
74419 if (index == old_index) {
74420 /* update counters */
74421 local_sub(event_length, &cpu_buffer->entries_bytes);
74422@@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
74423
74424 /* Do the likely case first */
74425 if (likely(bpage->page == (void *)addr)) {
74426- local_dec(&bpage->entries);
74427+ local_dec_unchecked(&bpage->entries);
74428 return;
74429 }
74430
74431@@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
74432 start = bpage;
74433 do {
74434 if (bpage->page == (void *)addr) {
74435- local_dec(&bpage->entries);
74436+ local_dec_unchecked(&bpage->entries);
74437 return;
74438 }
74439 rb_inc_page(cpu_buffer, &bpage);
74440@@ -2926,7 +2926,7 @@ static inline unsigned long
74441 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
74442 {
74443 return local_read(&cpu_buffer->entries) -
74444- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
74445+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
74446 }
74447
74448 /**
74449@@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
74450 return 0;
74451
74452 cpu_buffer = buffer->buffers[cpu];
74453- ret = local_read(&cpu_buffer->overrun);
74454+ ret = local_read_unchecked(&cpu_buffer->overrun);
74455
74456 return ret;
74457 }
74458@@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
74459 return 0;
74460
74461 cpu_buffer = buffer->buffers[cpu];
74462- ret = local_read(&cpu_buffer->commit_overrun);
74463+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
74464
74465 return ret;
74466 }
74467@@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
74468 /* if you care about this being correct, lock the buffer */
74469 for_each_buffer_cpu(buffer, cpu) {
74470 cpu_buffer = buffer->buffers[cpu];
74471- overruns += local_read(&cpu_buffer->overrun);
74472+ overruns += local_read_unchecked(&cpu_buffer->overrun);
74473 }
74474
74475 return overruns;
74476@@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
74477 /*
74478 * Reset the reader page to size zero.
74479 */
74480- local_set(&cpu_buffer->reader_page->write, 0);
74481- local_set(&cpu_buffer->reader_page->entries, 0);
74482+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
74483+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
74484 local_set(&cpu_buffer->reader_page->page->commit, 0);
74485 cpu_buffer->reader_page->real_end = 0;
74486
74487@@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
74488 * want to compare with the last_overrun.
74489 */
74490 smp_mb();
74491- overwrite = local_read(&(cpu_buffer->overrun));
74492+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
74493
74494 /*
74495 * Here's the tricky part.
74496@@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
74497
74498 cpu_buffer->head_page
74499 = list_entry(cpu_buffer->pages, struct buffer_page, list);
74500- local_set(&cpu_buffer->head_page->write, 0);
74501- local_set(&cpu_buffer->head_page->entries, 0);
74502+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
74503+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
74504 local_set(&cpu_buffer->head_page->page->commit, 0);
74505
74506 cpu_buffer->head_page->read = 0;
74507@@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
74508
74509 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
74510 INIT_LIST_HEAD(&cpu_buffer->new_pages);
74511- local_set(&cpu_buffer->reader_page->write, 0);
74512- local_set(&cpu_buffer->reader_page->entries, 0);
74513+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
74514+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
74515 local_set(&cpu_buffer->reader_page->page->commit, 0);
74516 cpu_buffer->reader_page->read = 0;
74517
74518 local_set(&cpu_buffer->entries_bytes, 0);
74519- local_set(&cpu_buffer->overrun, 0);
74520- local_set(&cpu_buffer->commit_overrun, 0);
74521+ local_set_unchecked(&cpu_buffer->overrun, 0);
74522+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
74523 local_set(&cpu_buffer->dropped_events, 0);
74524 local_set(&cpu_buffer->entries, 0);
74525 local_set(&cpu_buffer->committing, 0);
74526@@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
74527 rb_init_page(bpage);
74528 bpage = reader->page;
74529 reader->page = *data_page;
74530- local_set(&reader->write, 0);
74531- local_set(&reader->entries, 0);
74532+ local_set_unchecked(&reader->write, 0);
74533+ local_set_unchecked(&reader->entries, 0);
74534 reader->read = 0;
74535 *data_page = bpage;
74536
74537diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
74538index 3c13e46..883d039 100644
74539--- a/kernel/trace/trace.c
74540+++ b/kernel/trace/trace.c
74541@@ -4465,10 +4465,9 @@ static const struct file_operations tracing_dyn_info_fops = {
74542 };
74543 #endif
74544
74545-static struct dentry *d_tracer;
74546-
74547 struct dentry *tracing_init_dentry(void)
74548 {
74549+ static struct dentry *d_tracer;
74550 static int once;
74551
74552 if (d_tracer)
74553@@ -4488,10 +4487,9 @@ struct dentry *tracing_init_dentry(void)
74554 return d_tracer;
74555 }
74556
74557-static struct dentry *d_percpu;
74558-
74559 struct dentry *tracing_dentry_percpu(void)
74560 {
74561+ static struct dentry *d_percpu;
74562 static int once;
74563 struct dentry *d_tracer;
74564
74565diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
74566index 880073d..42db7c3 100644
74567--- a/kernel/trace/trace_events.c
74568+++ b/kernel/trace/trace_events.c
74569@@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
74570 struct ftrace_module_file_ops {
74571 struct list_head list;
74572 struct module *mod;
74573- struct file_operations id;
74574- struct file_operations enable;
74575- struct file_operations format;
74576- struct file_operations filter;
74577 };
74578
74579 static struct ftrace_module_file_ops *
74580@@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
74581
74582 file_ops->mod = mod;
74583
74584- file_ops->id = ftrace_event_id_fops;
74585- file_ops->id.owner = mod;
74586-
74587- file_ops->enable = ftrace_enable_fops;
74588- file_ops->enable.owner = mod;
74589-
74590- file_ops->filter = ftrace_event_filter_fops;
74591- file_ops->filter.owner = mod;
74592-
74593- file_ops->format = ftrace_event_format_fops;
74594- file_ops->format.owner = mod;
74595+ pax_open_kernel();
74596+ mod->trace_id.owner = mod;
74597+ mod->trace_enable.owner = mod;
74598+ mod->trace_filter.owner = mod;
74599+ mod->trace_format.owner = mod;
74600+ pax_close_kernel();
74601
74602 list_add(&file_ops->list, &ftrace_module_file_list);
74603
74604@@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
74605
74606 for_each_event(call, start, end) {
74607 __trace_add_event_call(*call, mod,
74608- &file_ops->id, &file_ops->enable,
74609- &file_ops->filter, &file_ops->format);
74610+ &mod->trace_id, &mod->trace_enable,
74611+ &mod->trace_filter, &mod->trace_format);
74612 }
74613 }
74614
74615diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
74616index fd3c8aa..5f324a6 100644
74617--- a/kernel/trace/trace_mmiotrace.c
74618+++ b/kernel/trace/trace_mmiotrace.c
74619@@ -24,7 +24,7 @@ struct header_iter {
74620 static struct trace_array *mmio_trace_array;
74621 static bool overrun_detected;
74622 static unsigned long prev_overruns;
74623-static atomic_t dropped_count;
74624+static atomic_unchecked_t dropped_count;
74625
74626 static void mmio_reset_data(struct trace_array *tr)
74627 {
74628@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
74629
74630 static unsigned long count_overruns(struct trace_iterator *iter)
74631 {
74632- unsigned long cnt = atomic_xchg(&dropped_count, 0);
74633+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
74634 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
74635
74636 if (over > prev_overruns)
74637@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
74638 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
74639 sizeof(*entry), 0, pc);
74640 if (!event) {
74641- atomic_inc(&dropped_count);
74642+ atomic_inc_unchecked(&dropped_count);
74643 return;
74644 }
74645 entry = ring_buffer_event_data(event);
74646@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
74647 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
74648 sizeof(*entry), 0, pc);
74649 if (!event) {
74650- atomic_inc(&dropped_count);
74651+ atomic_inc_unchecked(&dropped_count);
74652 return;
74653 }
74654 entry = ring_buffer_event_data(event);
74655diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
74656index 194d796..76edb8f 100644
74657--- a/kernel/trace/trace_output.c
74658+++ b/kernel/trace/trace_output.c
74659@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
74660
74661 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
74662 if (!IS_ERR(p)) {
74663- p = mangle_path(s->buffer + s->len, p, "\n");
74664+ p = mangle_path(s->buffer + s->len, p, "\n\\");
74665 if (p) {
74666 s->len = p - s->buffer;
74667 return 1;
74668@@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
74669 goto out;
74670 }
74671
74672+ pax_open_kernel();
74673 if (event->funcs->trace == NULL)
74674- event->funcs->trace = trace_nop_print;
74675+ *(void **)&event->funcs->trace = trace_nop_print;
74676 if (event->funcs->raw == NULL)
74677- event->funcs->raw = trace_nop_print;
74678+ *(void **)&event->funcs->raw = trace_nop_print;
74679 if (event->funcs->hex == NULL)
74680- event->funcs->hex = trace_nop_print;
74681+ *(void **)&event->funcs->hex = trace_nop_print;
74682 if (event->funcs->binary == NULL)
74683- event->funcs->binary = trace_nop_print;
74684+ *(void **)&event->funcs->binary = trace_nop_print;
74685+ pax_close_kernel();
74686
74687 key = event->type & (EVENT_HASHSIZE - 1);
74688
74689diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
74690index 42ca822..cdcacc6 100644
74691--- a/kernel/trace/trace_stack.c
74692+++ b/kernel/trace/trace_stack.c
74693@@ -52,7 +52,7 @@ static inline void check_stack(void)
74694 return;
74695
74696 /* we do not handle interrupt stacks yet */
74697- if (!object_is_on_stack(&this_size))
74698+ if (!object_starts_on_stack(&this_size))
74699 return;
74700
74701 local_irq_save(flags);
74702diff --git a/kernel/user.c b/kernel/user.c
74703index 33acb5e..57ebfd4 100644
74704--- a/kernel/user.c
74705+++ b/kernel/user.c
74706@@ -47,9 +47,7 @@ struct user_namespace init_user_ns = {
74707 .count = 4294967295U,
74708 },
74709 },
74710- .kref = {
74711- .refcount = ATOMIC_INIT(3),
74712- },
74713+ .count = ATOMIC_INIT(3),
74714 .owner = GLOBAL_ROOT_UID,
74715 .group = GLOBAL_ROOT_GID,
74716 .proc_inum = PROC_USER_INIT_INO,
74717diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
74718index 2b042c4..24f8ec3 100644
74719--- a/kernel/user_namespace.c
74720+++ b/kernel/user_namespace.c
74721@@ -78,7 +78,7 @@ int create_user_ns(struct cred *new)
74722 return ret;
74723 }
74724
74725- kref_init(&ns->kref);
74726+ atomic_set(&ns->count, 1);
74727 /* Leave the new->user_ns reference with the new user namespace. */
74728 ns->parent = parent_ns;
74729 ns->owner = owner;
74730@@ -104,15 +104,16 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
74731 return create_user_ns(cred);
74732 }
74733
74734-void free_user_ns(struct kref *kref)
74735+void free_user_ns(struct user_namespace *ns)
74736 {
74737- struct user_namespace *parent, *ns =
74738- container_of(kref, struct user_namespace, kref);
74739+ struct user_namespace *parent;
74740
74741- parent = ns->parent;
74742- proc_free_inum(ns->proc_inum);
74743- kmem_cache_free(user_ns_cachep, ns);
74744- put_user_ns(parent);
74745+ do {
74746+ parent = ns->parent;
74747+ proc_free_inum(ns->proc_inum);
74748+ kmem_cache_free(user_ns_cachep, ns);
74749+ ns = parent;
74750+ } while (atomic_dec_and_test(&parent->count));
74751 }
74752 EXPORT_SYMBOL(free_user_ns);
74753
74754diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
74755index 67604e5..3ebb003 100644
74756--- a/lib/Kconfig.debug
74757+++ b/lib/Kconfig.debug
74758@@ -1278,6 +1278,7 @@ config LATENCYTOP
74759 depends on DEBUG_KERNEL
74760 depends on STACKTRACE_SUPPORT
74761 depends on PROC_FS
74762+ depends on !GRKERNSEC_HIDESYM
74763 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
74764 select KALLSYMS
74765 select KALLSYMS_ALL
74766@@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
74767
74768 config PROVIDE_OHCI1394_DMA_INIT
74769 bool "Remote debugging over FireWire early on boot"
74770- depends on PCI && X86
74771+ depends on PCI && X86 && !GRKERNSEC
74772 help
74773 If you want to debug problems which hang or crash the kernel early
74774 on boot and the crashing machine has a FireWire port, you can use
74775@@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
74776
74777 config FIREWIRE_OHCI_REMOTE_DMA
74778 bool "Remote debugging over FireWire with firewire-ohci"
74779- depends on FIREWIRE_OHCI
74780+ depends on FIREWIRE_OHCI && !GRKERNSEC
74781 help
74782 This option lets you use the FireWire bus for remote debugging
74783 with help of the firewire-ohci driver. It enables unfiltered
74784diff --git a/lib/Makefile b/lib/Makefile
74785index 02ed6c0..bd243da 100644
74786--- a/lib/Makefile
74787+++ b/lib/Makefile
74788@@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
74789
74790 obj-$(CONFIG_BTREE) += btree.o
74791 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
74792-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
74793+obj-y += list_debug.o
74794 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
74795
74796 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
74797diff --git a/lib/bitmap.c b/lib/bitmap.c
74798index 06f7e4f..f3cf2b0 100644
74799--- a/lib/bitmap.c
74800+++ b/lib/bitmap.c
74801@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
74802 {
74803 int c, old_c, totaldigits, ndigits, nchunks, nbits;
74804 u32 chunk;
74805- const char __user __force *ubuf = (const char __user __force *)buf;
74806+ const char __user *ubuf = (const char __force_user *)buf;
74807
74808 bitmap_zero(maskp, nmaskbits);
74809
74810@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
74811 {
74812 if (!access_ok(VERIFY_READ, ubuf, ulen))
74813 return -EFAULT;
74814- return __bitmap_parse((const char __force *)ubuf,
74815+ return __bitmap_parse((const char __force_kernel *)ubuf,
74816 ulen, 1, maskp, nmaskbits);
74817
74818 }
74819@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
74820 {
74821 unsigned a, b;
74822 int c, old_c, totaldigits;
74823- const char __user __force *ubuf = (const char __user __force *)buf;
74824+ const char __user *ubuf = (const char __force_user *)buf;
74825 int exp_digit, in_range;
74826
74827 totaldigits = c = 0;
74828@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
74829 {
74830 if (!access_ok(VERIFY_READ, ubuf, ulen))
74831 return -EFAULT;
74832- return __bitmap_parselist((const char __force *)ubuf,
74833+ return __bitmap_parselist((const char __force_kernel *)ubuf,
74834 ulen, 1, maskp, nmaskbits);
74835 }
74836 EXPORT_SYMBOL(bitmap_parselist_user);
74837diff --git a/lib/bug.c b/lib/bug.c
74838index d0cdf14..4d07bd2 100644
74839--- a/lib/bug.c
74840+++ b/lib/bug.c
74841@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
74842 return BUG_TRAP_TYPE_NONE;
74843
74844 bug = find_bug(bugaddr);
74845+ if (!bug)
74846+ return BUG_TRAP_TYPE_NONE;
74847
74848 file = NULL;
74849 line = 0;
74850diff --git a/lib/debugobjects.c b/lib/debugobjects.c
74851index d11808c..dc2d6f8 100644
74852--- a/lib/debugobjects.c
74853+++ b/lib/debugobjects.c
74854@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
74855 if (limit > 4)
74856 return;
74857
74858- is_on_stack = object_is_on_stack(addr);
74859+ is_on_stack = object_starts_on_stack(addr);
74860 if (is_on_stack == onstack)
74861 return;
74862
74863diff --git a/lib/devres.c b/lib/devres.c
74864index 80b9c76..9e32279 100644
74865--- a/lib/devres.c
74866+++ b/lib/devres.c
74867@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
74868 void devm_iounmap(struct device *dev, void __iomem *addr)
74869 {
74870 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
74871- (void *)addr));
74872+ (void __force *)addr));
74873 iounmap(addr);
74874 }
74875 EXPORT_SYMBOL(devm_iounmap);
74876@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
74877 {
74878 ioport_unmap(addr);
74879 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
74880- devm_ioport_map_match, (void *)addr));
74881+ devm_ioport_map_match, (void __force *)addr));
74882 }
74883 EXPORT_SYMBOL(devm_ioport_unmap);
74884
74885diff --git a/lib/dma-debug.c b/lib/dma-debug.c
74886index 5e396ac..58d5de1 100644
74887--- a/lib/dma-debug.c
74888+++ b/lib/dma-debug.c
74889@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
74890
74891 void dma_debug_add_bus(struct bus_type *bus)
74892 {
74893- struct notifier_block *nb;
74894+ notifier_block_no_const *nb;
74895
74896 if (global_disable)
74897 return;
74898@@ -942,7 +942,7 @@ out:
74899
74900 static void check_for_stack(struct device *dev, void *addr)
74901 {
74902- if (object_is_on_stack(addr))
74903+ if (object_starts_on_stack(addr))
74904 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
74905 "stack [addr=%p]\n", addr);
74906 }
74907diff --git a/lib/inflate.c b/lib/inflate.c
74908index 013a761..c28f3fc 100644
74909--- a/lib/inflate.c
74910+++ b/lib/inflate.c
74911@@ -269,7 +269,7 @@ static void free(void *where)
74912 malloc_ptr = free_mem_ptr;
74913 }
74914 #else
74915-#define malloc(a) kmalloc(a, GFP_KERNEL)
74916+#define malloc(a) kmalloc((a), GFP_KERNEL)
74917 #define free(a) kfree(a)
74918 #endif
74919
74920diff --git a/lib/ioremap.c b/lib/ioremap.c
74921index 0c9216c..863bd89 100644
74922--- a/lib/ioremap.c
74923+++ b/lib/ioremap.c
74924@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
74925 unsigned long next;
74926
74927 phys_addr -= addr;
74928- pmd = pmd_alloc(&init_mm, pud, addr);
74929+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
74930 if (!pmd)
74931 return -ENOMEM;
74932 do {
74933@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
74934 unsigned long next;
74935
74936 phys_addr -= addr;
74937- pud = pud_alloc(&init_mm, pgd, addr);
74938+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
74939 if (!pud)
74940 return -ENOMEM;
74941 do {
74942diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
74943index bd2bea9..6b3c95e 100644
74944--- a/lib/is_single_threaded.c
74945+++ b/lib/is_single_threaded.c
74946@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
74947 struct task_struct *p, *t;
74948 bool ret;
74949
74950+ if (!mm)
74951+ return true;
74952+
74953 if (atomic_read(&task->signal->live) != 1)
74954 return false;
74955
74956diff --git a/lib/list_debug.c b/lib/list_debug.c
74957index c24c2f7..3fc5da0 100644
74958--- a/lib/list_debug.c
74959+++ b/lib/list_debug.c
74960@@ -11,7 +11,9 @@
74961 #include <linux/bug.h>
74962 #include <linux/kernel.h>
74963 #include <linux/rculist.h>
74964+#include <linux/mm.h>
74965
74966+#ifdef CONFIG_DEBUG_LIST
74967 /*
74968 * Insert a new entry between two known consecutive entries.
74969 *
74970@@ -19,21 +21,32 @@
74971 * the prev/next entries already!
74972 */
74973
74974-void __list_add(struct list_head *new,
74975- struct list_head *prev,
74976- struct list_head *next)
74977+static bool __list_add_debug(struct list_head *new,
74978+ struct list_head *prev,
74979+ struct list_head *next)
74980 {
74981- WARN(next->prev != prev,
74982+ if (WARN(next->prev != prev,
74983 "list_add corruption. next->prev should be "
74984 "prev (%p), but was %p. (next=%p).\n",
74985- prev, next->prev, next);
74986- WARN(prev->next != next,
74987+ prev, next->prev, next) ||
74988+ WARN(prev->next != next,
74989 "list_add corruption. prev->next should be "
74990 "next (%p), but was %p. (prev=%p).\n",
74991- next, prev->next, prev);
74992- WARN(new == prev || new == next,
74993+ next, prev->next, prev) ||
74994+ WARN(new == prev || new == next,
74995 "list_add double add: new=%p, prev=%p, next=%p.\n",
74996- new, prev, next);
74997+ new, prev, next))
74998+ return false;
74999+ return true;
75000+}
75001+
75002+void __list_add(struct list_head *new,
75003+ struct list_head *prev,
75004+ struct list_head *next)
75005+{
75006+ if (!__list_add_debug(new, prev, next))
75007+ return;
75008+
75009 next->prev = new;
75010 new->next = next;
75011 new->prev = prev;
75012@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
75013 }
75014 EXPORT_SYMBOL(__list_add);
75015
75016-void __list_del_entry(struct list_head *entry)
75017+static bool __list_del_entry_debug(struct list_head *entry)
75018 {
75019 struct list_head *prev, *next;
75020
75021@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
75022 WARN(next->prev != entry,
75023 "list_del corruption. next->prev should be %p, "
75024 "but was %p\n", entry, next->prev))
75025+ return false;
75026+ return true;
75027+}
75028+
75029+void __list_del_entry(struct list_head *entry)
75030+{
75031+ if (!__list_del_entry_debug(entry))
75032 return;
75033
75034- __list_del(prev, next);
75035+ __list_del(entry->prev, entry->next);
75036 }
75037 EXPORT_SYMBOL(__list_del_entry);
75038
75039@@ -86,15 +106,54 @@ EXPORT_SYMBOL(list_del);
75040 void __list_add_rcu(struct list_head *new,
75041 struct list_head *prev, struct list_head *next)
75042 {
75043- WARN(next->prev != prev,
75044+ if (WARN(next->prev != prev,
75045 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
75046- prev, next->prev, next);
75047- WARN(prev->next != next,
75048+ prev, next->prev, next) ||
75049+ WARN(prev->next != next,
75050 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
75051- next, prev->next, prev);
75052+ next, prev->next, prev))
75053+ return;
75054+
75055 new->next = next;
75056 new->prev = prev;
75057 rcu_assign_pointer(list_next_rcu(prev), new);
75058 next->prev = new;
75059 }
75060 EXPORT_SYMBOL(__list_add_rcu);
75061+#endif
75062+
75063+void pax_list_add_tail(struct list_head *new, struct list_head *head)
75064+{
75065+ struct list_head *prev, *next;
75066+
75067+ prev = head->prev;
75068+ next = head;
75069+
75070+#ifdef CONFIG_DEBUG_LIST
75071+ if (!__list_add_debug(new, prev, next))
75072+ return;
75073+#endif
75074+
75075+ pax_open_kernel();
75076+ next->prev = new;
75077+ new->next = next;
75078+ new->prev = prev;
75079+ prev->next = new;
75080+ pax_close_kernel();
75081+}
75082+EXPORT_SYMBOL(pax_list_add_tail);
75083+
75084+void pax_list_del(struct list_head *entry)
75085+{
75086+#ifdef CONFIG_DEBUG_LIST
75087+ if (!__list_del_entry_debug(entry))
75088+ return;
75089+#endif
75090+
75091+ pax_open_kernel();
75092+ __list_del(entry->prev, entry->next);
75093+ entry->next = LIST_POISON1;
75094+ entry->prev = LIST_POISON2;
75095+ pax_close_kernel();
75096+}
75097+EXPORT_SYMBOL(pax_list_del);
75098diff --git a/lib/radix-tree.c b/lib/radix-tree.c
75099index e796429..6e38f9f 100644
75100--- a/lib/radix-tree.c
75101+++ b/lib/radix-tree.c
75102@@ -92,7 +92,7 @@ struct radix_tree_preload {
75103 int nr;
75104 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
75105 };
75106-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
75107+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
75108
75109 static inline void *ptr_to_indirect(void *ptr)
75110 {
75111diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
75112index bb2b201..46abaf9 100644
75113--- a/lib/strncpy_from_user.c
75114+++ b/lib/strncpy_from_user.c
75115@@ -21,7 +21,7 @@
75116 */
75117 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
75118 {
75119- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
75120+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
75121 long res = 0;
75122
75123 /*
75124diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
75125index a28df52..3d55877 100644
75126--- a/lib/strnlen_user.c
75127+++ b/lib/strnlen_user.c
75128@@ -26,7 +26,7 @@
75129 */
75130 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
75131 {
75132- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
75133+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
75134 long align, res = 0;
75135 unsigned long c;
75136
75137diff --git a/lib/vsprintf.c b/lib/vsprintf.c
75138index fab33a9..3b5fe68 100644
75139--- a/lib/vsprintf.c
75140+++ b/lib/vsprintf.c
75141@@ -16,6 +16,9 @@
75142 * - scnprintf and vscnprintf
75143 */
75144
75145+#ifdef CONFIG_GRKERNSEC_HIDESYM
75146+#define __INCLUDED_BY_HIDESYM 1
75147+#endif
75148 #include <stdarg.h>
75149 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
75150 #include <linux/types.h>
75151@@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
75152 char sym[KSYM_SYMBOL_LEN];
75153 if (ext == 'B')
75154 sprint_backtrace(sym, value);
75155- else if (ext != 'f' && ext != 's')
75156+ else if (ext != 'f' && ext != 's' && ext != 'a')
75157 sprint_symbol(sym, value);
75158 else
75159 sprint_symbol_no_offset(sym, value);
75160@@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
75161 return number(buf, end, *(const netdev_features_t *)addr, spec);
75162 }
75163
75164+#ifdef CONFIG_GRKERNSEC_HIDESYM
75165+int kptr_restrict __read_mostly = 2;
75166+#else
75167 int kptr_restrict __read_mostly;
75168+#endif
75169
75170 /*
75171 * Show a '%p' thing. A kernel extension is that the '%p' is followed
75172@@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
75173 * - 'S' For symbolic direct pointers with offset
75174 * - 's' For symbolic direct pointers without offset
75175 * - 'B' For backtraced symbolic direct pointers with offset
75176+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
75177+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
75178 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
75179 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
75180 * - 'M' For a 6-byte MAC address, it prints the address in the
75181@@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75182
75183 if (!ptr && *fmt != 'K') {
75184 /*
75185- * Print (null) with the same width as a pointer so it makes
75186+ * Print (nil) with the same width as a pointer so it makes
75187 * tabular output look nice.
75188 */
75189 if (spec.field_width == -1)
75190 spec.field_width = default_width;
75191- return string(buf, end, "(null)", spec);
75192+ return string(buf, end, "(nil)", spec);
75193 }
75194
75195 switch (*fmt) {
75196@@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75197 /* Fallthrough */
75198 case 'S':
75199 case 's':
75200+#ifdef CONFIG_GRKERNSEC_HIDESYM
75201+ break;
75202+#else
75203+ return symbol_string(buf, end, ptr, spec, *fmt);
75204+#endif
75205+ case 'A':
75206+ case 'a':
75207 case 'B':
75208 return symbol_string(buf, end, ptr, spec, *fmt);
75209 case 'R':
75210@@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75211 va_end(va);
75212 return buf;
75213 }
75214+ case 'P':
75215+ break;
75216 case 'K':
75217 /*
75218 * %pK cannot be used in IRQ context because its test
75219@@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75220 }
75221 break;
75222 }
75223+
75224+#ifdef CONFIG_GRKERNSEC_HIDESYM
75225+ /* 'P' = approved pointers to copy to userland,
75226+ as in the /proc/kallsyms case, as we make it display nothing
75227+ for non-root users, and the real contents for root users
75228+ Also ignore 'K' pointers, since we force their NULLing for non-root users
75229+ above
75230+ */
75231+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
75232+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
75233+ dump_stack();
75234+ ptr = NULL;
75235+ }
75236+#endif
75237+
75238 spec.flags |= SMALL;
75239 if (spec.field_width == -1) {
75240 spec.field_width = default_width;
75241@@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75242 typeof(type) value; \
75243 if (sizeof(type) == 8) { \
75244 args = PTR_ALIGN(args, sizeof(u32)); \
75245- *(u32 *)&value = *(u32 *)args; \
75246- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
75247+ *(u32 *)&value = *(const u32 *)args; \
75248+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
75249 } else { \
75250 args = PTR_ALIGN(args, sizeof(type)); \
75251- value = *(typeof(type) *)args; \
75252+ value = *(const typeof(type) *)args; \
75253 } \
75254 args += sizeof(type); \
75255 value; \
75256@@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75257 case FORMAT_TYPE_STR: {
75258 const char *str_arg = args;
75259 args += strlen(str_arg) + 1;
75260- str = string(str, end, (char *)str_arg, spec);
75261+ str = string(str, end, str_arg, spec);
75262 break;
75263 }
75264
75265diff --git a/localversion-grsec b/localversion-grsec
75266new file mode 100644
75267index 0000000..7cd6065
75268--- /dev/null
75269+++ b/localversion-grsec
75270@@ -0,0 +1 @@
75271+-grsec
75272diff --git a/mm/Kconfig b/mm/Kconfig
75273index 278e3ab..87c384d 100644
75274--- a/mm/Kconfig
75275+++ b/mm/Kconfig
75276@@ -286,10 +286,10 @@ config KSM
75277 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
75278
75279 config DEFAULT_MMAP_MIN_ADDR
75280- int "Low address space to protect from user allocation"
75281+ int "Low address space to protect from user allocation"
75282 depends on MMU
75283- default 4096
75284- help
75285+ default 65536
75286+ help
75287 This is the portion of low virtual memory which should be protected
75288 from userspace allocation. Keeping a user from writing to low pages
75289 can help reduce the impact of kernel NULL pointer bugs.
75290@@ -320,7 +320,7 @@ config MEMORY_FAILURE
75291
75292 config HWPOISON_INJECT
75293 tristate "HWPoison pages injector"
75294- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
75295+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
75296 select PROC_PAGE_MONITOR
75297
75298 config NOMMU_INITIAL_TRIM_EXCESS
75299diff --git a/mm/filemap.c b/mm/filemap.c
75300index 83efee7..3f99381 100644
75301--- a/mm/filemap.c
75302+++ b/mm/filemap.c
75303@@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
75304 struct address_space *mapping = file->f_mapping;
75305
75306 if (!mapping->a_ops->readpage)
75307- return -ENOEXEC;
75308+ return -ENODEV;
75309 file_accessed(file);
75310 vma->vm_ops = &generic_file_vm_ops;
75311 return 0;
75312@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
75313 *pos = i_size_read(inode);
75314
75315 if (limit != RLIM_INFINITY) {
75316+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
75317 if (*pos >= limit) {
75318 send_sig(SIGXFSZ, current, 0);
75319 return -EFBIG;
75320diff --git a/mm/fremap.c b/mm/fremap.c
75321index a0aaf0e..20325c3 100644
75322--- a/mm/fremap.c
75323+++ b/mm/fremap.c
75324@@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
75325 retry:
75326 vma = find_vma(mm, start);
75327
75328+#ifdef CONFIG_PAX_SEGMEXEC
75329+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
75330+ goto out;
75331+#endif
75332+
75333 /*
75334 * Make sure the vma is shared, that it supports prefaulting,
75335 * and that the remapped range is valid and fully within
75336diff --git a/mm/highmem.c b/mm/highmem.c
75337index b32b70c..e512eb0 100644
75338--- a/mm/highmem.c
75339+++ b/mm/highmem.c
75340@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
75341 * So no dangers, even with speculative execution.
75342 */
75343 page = pte_page(pkmap_page_table[i]);
75344+ pax_open_kernel();
75345 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
75346-
75347+ pax_close_kernel();
75348 set_page_address(page, NULL);
75349 need_flush = 1;
75350 }
75351@@ -198,9 +199,11 @@ start:
75352 }
75353 }
75354 vaddr = PKMAP_ADDR(last_pkmap_nr);
75355+
75356+ pax_open_kernel();
75357 set_pte_at(&init_mm, vaddr,
75358 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
75359-
75360+ pax_close_kernel();
75361 pkmap_count[last_pkmap_nr] = 1;
75362 set_page_address(page, (void *)vaddr);
75363
75364diff --git a/mm/hugetlb.c b/mm/hugetlb.c
75365index 546db81..01d5c53 100644
75366--- a/mm/hugetlb.c
75367+++ b/mm/hugetlb.c
75368@@ -2511,6 +2511,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
75369 return 1;
75370 }
75371
75372+#ifdef CONFIG_PAX_SEGMEXEC
75373+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
75374+{
75375+ struct mm_struct *mm = vma->vm_mm;
75376+ struct vm_area_struct *vma_m;
75377+ unsigned long address_m;
75378+ pte_t *ptep_m;
75379+
75380+ vma_m = pax_find_mirror_vma(vma);
75381+ if (!vma_m)
75382+ return;
75383+
75384+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75385+ address_m = address + SEGMEXEC_TASK_SIZE;
75386+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
75387+ get_page(page_m);
75388+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
75389+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
75390+}
75391+#endif
75392+
75393 /*
75394 * Hugetlb_cow() should be called with page lock of the original hugepage held.
75395 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
75396@@ -2629,6 +2650,11 @@ retry_avoidcopy:
75397 make_huge_pte(vma, new_page, 1));
75398 page_remove_rmap(old_page);
75399 hugepage_add_new_anon_rmap(new_page, vma, address);
75400+
75401+#ifdef CONFIG_PAX_SEGMEXEC
75402+ pax_mirror_huge_pte(vma, address, new_page);
75403+#endif
75404+
75405 /* Make the old page be freed below */
75406 new_page = old_page;
75407 }
75408@@ -2788,6 +2814,10 @@ retry:
75409 && (vma->vm_flags & VM_SHARED)));
75410 set_huge_pte_at(mm, address, ptep, new_pte);
75411
75412+#ifdef CONFIG_PAX_SEGMEXEC
75413+ pax_mirror_huge_pte(vma, address, page);
75414+#endif
75415+
75416 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
75417 /* Optimization, do the COW without a second fault */
75418 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
75419@@ -2817,6 +2847,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75420 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
75421 struct hstate *h = hstate_vma(vma);
75422
75423+#ifdef CONFIG_PAX_SEGMEXEC
75424+ struct vm_area_struct *vma_m;
75425+#endif
75426+
75427 address &= huge_page_mask(h);
75428
75429 ptep = huge_pte_offset(mm, address);
75430@@ -2830,6 +2864,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75431 VM_FAULT_SET_HINDEX(hstate_index(h));
75432 }
75433
75434+#ifdef CONFIG_PAX_SEGMEXEC
75435+ vma_m = pax_find_mirror_vma(vma);
75436+ if (vma_m) {
75437+ unsigned long address_m;
75438+
75439+ if (vma->vm_start > vma_m->vm_start) {
75440+ address_m = address;
75441+ address -= SEGMEXEC_TASK_SIZE;
75442+ vma = vma_m;
75443+ h = hstate_vma(vma);
75444+ } else
75445+ address_m = address + SEGMEXEC_TASK_SIZE;
75446+
75447+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
75448+ return VM_FAULT_OOM;
75449+ address_m &= HPAGE_MASK;
75450+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
75451+ }
75452+#endif
75453+
75454 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
75455 if (!ptep)
75456 return VM_FAULT_OOM;
75457diff --git a/mm/internal.h b/mm/internal.h
75458index 9ba2110..eaf0674 100644
75459--- a/mm/internal.h
75460+++ b/mm/internal.h
75461@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
75462 * in mm/page_alloc.c
75463 */
75464 extern void __free_pages_bootmem(struct page *page, unsigned int order);
75465+extern void free_compound_page(struct page *page);
75466 extern void prep_compound_page(struct page *page, unsigned long order);
75467 #ifdef CONFIG_MEMORY_FAILURE
75468 extern bool is_free_buddy_page(struct page *page);
75469diff --git a/mm/kmemleak.c b/mm/kmemleak.c
75470index 752a705..6c3102e 100644
75471--- a/mm/kmemleak.c
75472+++ b/mm/kmemleak.c
75473@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
75474
75475 for (i = 0; i < object->trace_len; i++) {
75476 void *ptr = (void *)object->trace[i];
75477- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
75478+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
75479 }
75480 }
75481
75482@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
75483 return -ENOMEM;
75484 }
75485
75486- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
75487+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
75488 &kmemleak_fops);
75489 if (!dentry)
75490 pr_warning("Failed to create the debugfs kmemleak file\n");
75491diff --git a/mm/maccess.c b/mm/maccess.c
75492index d53adf9..03a24bf 100644
75493--- a/mm/maccess.c
75494+++ b/mm/maccess.c
75495@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
75496 set_fs(KERNEL_DS);
75497 pagefault_disable();
75498 ret = __copy_from_user_inatomic(dst,
75499- (__force const void __user *)src, size);
75500+ (const void __force_user *)src, size);
75501 pagefault_enable();
75502 set_fs(old_fs);
75503
75504@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
75505
75506 set_fs(KERNEL_DS);
75507 pagefault_disable();
75508- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
75509+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
75510 pagefault_enable();
75511 set_fs(old_fs);
75512
75513diff --git a/mm/madvise.c b/mm/madvise.c
75514index 03dfa5c..b032917 100644
75515--- a/mm/madvise.c
75516+++ b/mm/madvise.c
75517@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
75518 pgoff_t pgoff;
75519 unsigned long new_flags = vma->vm_flags;
75520
75521+#ifdef CONFIG_PAX_SEGMEXEC
75522+ struct vm_area_struct *vma_m;
75523+#endif
75524+
75525 switch (behavior) {
75526 case MADV_NORMAL:
75527 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
75528@@ -123,6 +127,13 @@ success:
75529 /*
75530 * vm_flags is protected by the mmap_sem held in write mode.
75531 */
75532+
75533+#ifdef CONFIG_PAX_SEGMEXEC
75534+ vma_m = pax_find_mirror_vma(vma);
75535+ if (vma_m)
75536+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
75537+#endif
75538+
75539 vma->vm_flags = new_flags;
75540
75541 out:
75542@@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75543 struct vm_area_struct ** prev,
75544 unsigned long start, unsigned long end)
75545 {
75546+
75547+#ifdef CONFIG_PAX_SEGMEXEC
75548+ struct vm_area_struct *vma_m;
75549+#endif
75550+
75551 *prev = vma;
75552 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
75553 return -EINVAL;
75554@@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75555 zap_page_range(vma, start, end - start, &details);
75556 } else
75557 zap_page_range(vma, start, end - start, NULL);
75558+
75559+#ifdef CONFIG_PAX_SEGMEXEC
75560+ vma_m = pax_find_mirror_vma(vma);
75561+ if (vma_m) {
75562+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
75563+ struct zap_details details = {
75564+ .nonlinear_vma = vma_m,
75565+ .last_index = ULONG_MAX,
75566+ };
75567+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
75568+ } else
75569+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
75570+ }
75571+#endif
75572+
75573 return 0;
75574 }
75575
75576@@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
75577 if (end < start)
75578 goto out;
75579
75580+#ifdef CONFIG_PAX_SEGMEXEC
75581+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
75582+ if (end > SEGMEXEC_TASK_SIZE)
75583+ goto out;
75584+ } else
75585+#endif
75586+
75587+ if (end > TASK_SIZE)
75588+ goto out;
75589+
75590 error = 0;
75591 if (end == start)
75592 goto out;
75593diff --git a/mm/memory-failure.c b/mm/memory-failure.c
75594index c6e4dd3..fdb2ca6 100644
75595--- a/mm/memory-failure.c
75596+++ b/mm/memory-failure.c
75597@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
75598
75599 int sysctl_memory_failure_recovery __read_mostly = 1;
75600
75601-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75602+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75603
75604 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
75605
75606@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
75607 pfn, t->comm, t->pid);
75608 si.si_signo = SIGBUS;
75609 si.si_errno = 0;
75610- si.si_addr = (void *)addr;
75611+ si.si_addr = (void __user *)addr;
75612 #ifdef __ARCH_SI_TRAPNO
75613 si.si_trapno = trapno;
75614 #endif
75615@@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75616 }
75617
75618 nr_pages = 1 << compound_trans_order(hpage);
75619- atomic_long_add(nr_pages, &mce_bad_pages);
75620+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
75621
75622 /*
75623 * We need/can do nothing about count=0 pages.
75624@@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75625 if (!PageHWPoison(hpage)
75626 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
75627 || (p != hpage && TestSetPageHWPoison(hpage))) {
75628- atomic_long_sub(nr_pages, &mce_bad_pages);
75629+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75630 return 0;
75631 }
75632 set_page_hwpoison_huge_page(hpage);
75633@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75634 }
75635 if (hwpoison_filter(p)) {
75636 if (TestClearPageHWPoison(p))
75637- atomic_long_sub(nr_pages, &mce_bad_pages);
75638+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75639 unlock_page(hpage);
75640 put_page(hpage);
75641 return 0;
75642@@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
75643 return 0;
75644 }
75645 if (TestClearPageHWPoison(p))
75646- atomic_long_sub(nr_pages, &mce_bad_pages);
75647+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75648 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
75649 return 0;
75650 }
75651@@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
75652 */
75653 if (TestClearPageHWPoison(page)) {
75654 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
75655- atomic_long_sub(nr_pages, &mce_bad_pages);
75656+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75657 freeit = 1;
75658 if (PageHuge(page))
75659 clear_page_hwpoison_huge_page(page);
75660@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
75661 }
75662 done:
75663 if (!PageHWPoison(hpage))
75664- atomic_long_add(1 << compound_trans_order(hpage),
75665+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
75666 &mce_bad_pages);
75667 set_page_hwpoison_huge_page(hpage);
75668 dequeue_hwpoisoned_huge_page(hpage);
75669@@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
75670 return ret;
75671
75672 done:
75673- atomic_long_add(1, &mce_bad_pages);
75674+ atomic_long_add_unchecked(1, &mce_bad_pages);
75675 SetPageHWPoison(page);
75676 /* keep elevated page count for bad page */
75677 return ret;
75678diff --git a/mm/memory.c b/mm/memory.c
75679index bb1369f..efb96b5 100644
75680--- a/mm/memory.c
75681+++ b/mm/memory.c
75682@@ -433,6 +433,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
75683 free_pte_range(tlb, pmd, addr);
75684 } while (pmd++, addr = next, addr != end);
75685
75686+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
75687 start &= PUD_MASK;
75688 if (start < floor)
75689 return;
75690@@ -447,6 +448,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
75691 pmd = pmd_offset(pud, start);
75692 pud_clear(pud);
75693 pmd_free_tlb(tlb, pmd, start);
75694+#endif
75695+
75696 }
75697
75698 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75699@@ -466,6 +469,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75700 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
75701 } while (pud++, addr = next, addr != end);
75702
75703+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
75704 start &= PGDIR_MASK;
75705 if (start < floor)
75706 return;
75707@@ -480,6 +484,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75708 pud = pud_offset(pgd, start);
75709 pgd_clear(pgd);
75710 pud_free_tlb(tlb, pud, start);
75711+#endif
75712+
75713 }
75714
75715 /*
75716@@ -1618,12 +1624,6 @@ no_page_table:
75717 return page;
75718 }
75719
75720-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
75721-{
75722- return stack_guard_page_start(vma, addr) ||
75723- stack_guard_page_end(vma, addr+PAGE_SIZE);
75724-}
75725-
75726 /**
75727 * __get_user_pages() - pin user pages in memory
75728 * @tsk: task_struct of target task
75729@@ -1709,10 +1709,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75730
75731 i = 0;
75732
75733- do {
75734+ while (nr_pages) {
75735 struct vm_area_struct *vma;
75736
75737- vma = find_extend_vma(mm, start);
75738+ vma = find_vma(mm, start);
75739 if (!vma && in_gate_area(mm, start)) {
75740 unsigned long pg = start & PAGE_MASK;
75741 pgd_t *pgd;
75742@@ -1760,7 +1760,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75743 goto next_page;
75744 }
75745
75746- if (!vma ||
75747+ if (!vma || start < vma->vm_start ||
75748 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
75749 !(vm_flags & vma->vm_flags))
75750 return i ? : -EFAULT;
75751@@ -1787,11 +1787,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75752 int ret;
75753 unsigned int fault_flags = 0;
75754
75755- /* For mlock, just skip the stack guard page. */
75756- if (foll_flags & FOLL_MLOCK) {
75757- if (stack_guard_page(vma, start))
75758- goto next_page;
75759- }
75760 if (foll_flags & FOLL_WRITE)
75761 fault_flags |= FAULT_FLAG_WRITE;
75762 if (nonblocking)
75763@@ -1865,7 +1860,7 @@ next_page:
75764 start += PAGE_SIZE;
75765 nr_pages--;
75766 } while (nr_pages && start < vma->vm_end);
75767- } while (nr_pages);
75768+ }
75769 return i;
75770 }
75771 EXPORT_SYMBOL(__get_user_pages);
75772@@ -2072,6 +2067,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
75773 page_add_file_rmap(page);
75774 set_pte_at(mm, addr, pte, mk_pte(page, prot));
75775
75776+#ifdef CONFIG_PAX_SEGMEXEC
75777+ pax_mirror_file_pte(vma, addr, page, ptl);
75778+#endif
75779+
75780 retval = 0;
75781 pte_unmap_unlock(pte, ptl);
75782 return retval;
75783@@ -2116,9 +2115,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
75784 if (!page_count(page))
75785 return -EINVAL;
75786 if (!(vma->vm_flags & VM_MIXEDMAP)) {
75787+
75788+#ifdef CONFIG_PAX_SEGMEXEC
75789+ struct vm_area_struct *vma_m;
75790+#endif
75791+
75792 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
75793 BUG_ON(vma->vm_flags & VM_PFNMAP);
75794 vma->vm_flags |= VM_MIXEDMAP;
75795+
75796+#ifdef CONFIG_PAX_SEGMEXEC
75797+ vma_m = pax_find_mirror_vma(vma);
75798+ if (vma_m)
75799+ vma_m->vm_flags |= VM_MIXEDMAP;
75800+#endif
75801+
75802 }
75803 return insert_page(vma, addr, page, vma->vm_page_prot);
75804 }
75805@@ -2201,6 +2212,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
75806 unsigned long pfn)
75807 {
75808 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
75809+ BUG_ON(vma->vm_mirror);
75810
75811 if (addr < vma->vm_start || addr >= vma->vm_end)
75812 return -EFAULT;
75813@@ -2401,7 +2413,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
75814
75815 BUG_ON(pud_huge(*pud));
75816
75817- pmd = pmd_alloc(mm, pud, addr);
75818+ pmd = (mm == &init_mm) ?
75819+ pmd_alloc_kernel(mm, pud, addr) :
75820+ pmd_alloc(mm, pud, addr);
75821 if (!pmd)
75822 return -ENOMEM;
75823 do {
75824@@ -2421,7 +2435,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
75825 unsigned long next;
75826 int err;
75827
75828- pud = pud_alloc(mm, pgd, addr);
75829+ pud = (mm == &init_mm) ?
75830+ pud_alloc_kernel(mm, pgd, addr) :
75831+ pud_alloc(mm, pgd, addr);
75832 if (!pud)
75833 return -ENOMEM;
75834 do {
75835@@ -2509,6 +2525,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
75836 copy_user_highpage(dst, src, va, vma);
75837 }
75838
75839+#ifdef CONFIG_PAX_SEGMEXEC
75840+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
75841+{
75842+ struct mm_struct *mm = vma->vm_mm;
75843+ spinlock_t *ptl;
75844+ pte_t *pte, entry;
75845+
75846+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
75847+ entry = *pte;
75848+ if (!pte_present(entry)) {
75849+ if (!pte_none(entry)) {
75850+ BUG_ON(pte_file(entry));
75851+ free_swap_and_cache(pte_to_swp_entry(entry));
75852+ pte_clear_not_present_full(mm, address, pte, 0);
75853+ }
75854+ } else {
75855+ struct page *page;
75856+
75857+ flush_cache_page(vma, address, pte_pfn(entry));
75858+ entry = ptep_clear_flush(vma, address, pte);
75859+ BUG_ON(pte_dirty(entry));
75860+ page = vm_normal_page(vma, address, entry);
75861+ if (page) {
75862+ update_hiwater_rss(mm);
75863+ if (PageAnon(page))
75864+ dec_mm_counter_fast(mm, MM_ANONPAGES);
75865+ else
75866+ dec_mm_counter_fast(mm, MM_FILEPAGES);
75867+ page_remove_rmap(page);
75868+ page_cache_release(page);
75869+ }
75870+ }
75871+ pte_unmap_unlock(pte, ptl);
75872+}
75873+
75874+/* PaX: if vma is mirrored, synchronize the mirror's PTE
75875+ *
75876+ * the ptl of the lower mapped page is held on entry and is not released on exit
75877+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
75878+ */
75879+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
75880+{
75881+ struct mm_struct *mm = vma->vm_mm;
75882+ unsigned long address_m;
75883+ spinlock_t *ptl_m;
75884+ struct vm_area_struct *vma_m;
75885+ pmd_t *pmd_m;
75886+ pte_t *pte_m, entry_m;
75887+
75888+ BUG_ON(!page_m || !PageAnon(page_m));
75889+
75890+ vma_m = pax_find_mirror_vma(vma);
75891+ if (!vma_m)
75892+ return;
75893+
75894+ BUG_ON(!PageLocked(page_m));
75895+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75896+ address_m = address + SEGMEXEC_TASK_SIZE;
75897+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75898+ pte_m = pte_offset_map(pmd_m, address_m);
75899+ ptl_m = pte_lockptr(mm, pmd_m);
75900+ if (ptl != ptl_m) {
75901+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75902+ if (!pte_none(*pte_m))
75903+ goto out;
75904+ }
75905+
75906+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
75907+ page_cache_get(page_m);
75908+ page_add_anon_rmap(page_m, vma_m, address_m);
75909+ inc_mm_counter_fast(mm, MM_ANONPAGES);
75910+ set_pte_at(mm, address_m, pte_m, entry_m);
75911+ update_mmu_cache(vma_m, address_m, entry_m);
75912+out:
75913+ if (ptl != ptl_m)
75914+ spin_unlock(ptl_m);
75915+ pte_unmap(pte_m);
75916+ unlock_page(page_m);
75917+}
75918+
75919+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
75920+{
75921+ struct mm_struct *mm = vma->vm_mm;
75922+ unsigned long address_m;
75923+ spinlock_t *ptl_m;
75924+ struct vm_area_struct *vma_m;
75925+ pmd_t *pmd_m;
75926+ pte_t *pte_m, entry_m;
75927+
75928+ BUG_ON(!page_m || PageAnon(page_m));
75929+
75930+ vma_m = pax_find_mirror_vma(vma);
75931+ if (!vma_m)
75932+ return;
75933+
75934+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75935+ address_m = address + SEGMEXEC_TASK_SIZE;
75936+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75937+ pte_m = pte_offset_map(pmd_m, address_m);
75938+ ptl_m = pte_lockptr(mm, pmd_m);
75939+ if (ptl != ptl_m) {
75940+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75941+ if (!pte_none(*pte_m))
75942+ goto out;
75943+ }
75944+
75945+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
75946+ page_cache_get(page_m);
75947+ page_add_file_rmap(page_m);
75948+ inc_mm_counter_fast(mm, MM_FILEPAGES);
75949+ set_pte_at(mm, address_m, pte_m, entry_m);
75950+ update_mmu_cache(vma_m, address_m, entry_m);
75951+out:
75952+ if (ptl != ptl_m)
75953+ spin_unlock(ptl_m);
75954+ pte_unmap(pte_m);
75955+}
75956+
75957+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
75958+{
75959+ struct mm_struct *mm = vma->vm_mm;
75960+ unsigned long address_m;
75961+ spinlock_t *ptl_m;
75962+ struct vm_area_struct *vma_m;
75963+ pmd_t *pmd_m;
75964+ pte_t *pte_m, entry_m;
75965+
75966+ vma_m = pax_find_mirror_vma(vma);
75967+ if (!vma_m)
75968+ return;
75969+
75970+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75971+ address_m = address + SEGMEXEC_TASK_SIZE;
75972+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75973+ pte_m = pte_offset_map(pmd_m, address_m);
75974+ ptl_m = pte_lockptr(mm, pmd_m);
75975+ if (ptl != ptl_m) {
75976+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75977+ if (!pte_none(*pte_m))
75978+ goto out;
75979+ }
75980+
75981+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
75982+ set_pte_at(mm, address_m, pte_m, entry_m);
75983+out:
75984+ if (ptl != ptl_m)
75985+ spin_unlock(ptl_m);
75986+ pte_unmap(pte_m);
75987+}
75988+
75989+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
75990+{
75991+ struct page *page_m;
75992+ pte_t entry;
75993+
75994+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
75995+ goto out;
75996+
75997+ entry = *pte;
75998+ page_m = vm_normal_page(vma, address, entry);
75999+ if (!page_m)
76000+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
76001+ else if (PageAnon(page_m)) {
76002+ if (pax_find_mirror_vma(vma)) {
76003+ pte_unmap_unlock(pte, ptl);
76004+ lock_page(page_m);
76005+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
76006+ if (pte_same(entry, *pte))
76007+ pax_mirror_anon_pte(vma, address, page_m, ptl);
76008+ else
76009+ unlock_page(page_m);
76010+ }
76011+ } else
76012+ pax_mirror_file_pte(vma, address, page_m, ptl);
76013+
76014+out:
76015+ pte_unmap_unlock(pte, ptl);
76016+}
76017+#endif
76018+
76019 /*
76020 * This routine handles present pages, when users try to write
76021 * to a shared page. It is done by copying the page to a new address
76022@@ -2725,6 +2921,12 @@ gotten:
76023 */
76024 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
76025 if (likely(pte_same(*page_table, orig_pte))) {
76026+
76027+#ifdef CONFIG_PAX_SEGMEXEC
76028+ if (pax_find_mirror_vma(vma))
76029+ BUG_ON(!trylock_page(new_page));
76030+#endif
76031+
76032 if (old_page) {
76033 if (!PageAnon(old_page)) {
76034 dec_mm_counter_fast(mm, MM_FILEPAGES);
76035@@ -2776,6 +2978,10 @@ gotten:
76036 page_remove_rmap(old_page);
76037 }
76038
76039+#ifdef CONFIG_PAX_SEGMEXEC
76040+ pax_mirror_anon_pte(vma, address, new_page, ptl);
76041+#endif
76042+
76043 /* Free the old page.. */
76044 new_page = old_page;
76045 ret |= VM_FAULT_WRITE;
76046@@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
76047 swap_free(entry);
76048 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
76049 try_to_free_swap(page);
76050+
76051+#ifdef CONFIG_PAX_SEGMEXEC
76052+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
76053+#endif
76054+
76055 unlock_page(page);
76056 if (swapcache) {
76057 /*
76058@@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
76059
76060 /* No need to invalidate - it was non-present before */
76061 update_mmu_cache(vma, address, page_table);
76062+
76063+#ifdef CONFIG_PAX_SEGMEXEC
76064+ pax_mirror_anon_pte(vma, address, page, ptl);
76065+#endif
76066+
76067 unlock:
76068 pte_unmap_unlock(page_table, ptl);
76069 out:
76070@@ -3093,40 +3309,6 @@ out_release:
76071 }
76072
76073 /*
76074- * This is like a special single-page "expand_{down|up}wards()",
76075- * except we must first make sure that 'address{-|+}PAGE_SIZE'
76076- * doesn't hit another vma.
76077- */
76078-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
76079-{
76080- address &= PAGE_MASK;
76081- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
76082- struct vm_area_struct *prev = vma->vm_prev;
76083-
76084- /*
76085- * Is there a mapping abutting this one below?
76086- *
76087- * That's only ok if it's the same stack mapping
76088- * that has gotten split..
76089- */
76090- if (prev && prev->vm_end == address)
76091- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
76092-
76093- expand_downwards(vma, address - PAGE_SIZE);
76094- }
76095- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
76096- struct vm_area_struct *next = vma->vm_next;
76097-
76098- /* As VM_GROWSDOWN but s/below/above/ */
76099- if (next && next->vm_start == address + PAGE_SIZE)
76100- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
76101-
76102- expand_upwards(vma, address + PAGE_SIZE);
76103- }
76104- return 0;
76105-}
76106-
76107-/*
76108 * We enter with non-exclusive mmap_sem (to exclude vma changes,
76109 * but allow concurrent faults), and pte mapped but not yet locked.
76110 * We return with mmap_sem still held, but pte unmapped and unlocked.
76111@@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
76112 unsigned long address, pte_t *page_table, pmd_t *pmd,
76113 unsigned int flags)
76114 {
76115- struct page *page;
76116+ struct page *page = NULL;
76117 spinlock_t *ptl;
76118 pte_t entry;
76119
76120- pte_unmap(page_table);
76121-
76122- /* Check if we need to add a guard page to the stack */
76123- if (check_stack_guard_page(vma, address) < 0)
76124- return VM_FAULT_SIGBUS;
76125-
76126- /* Use the zero-page for reads */
76127 if (!(flags & FAULT_FLAG_WRITE)) {
76128 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
76129 vma->vm_page_prot));
76130- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
76131+ ptl = pte_lockptr(mm, pmd);
76132+ spin_lock(ptl);
76133 if (!pte_none(*page_table))
76134 goto unlock;
76135 goto setpte;
76136 }
76137
76138 /* Allocate our own private page. */
76139+ pte_unmap(page_table);
76140+
76141 if (unlikely(anon_vma_prepare(vma)))
76142 goto oom;
76143 page = alloc_zeroed_user_highpage_movable(vma, address);
76144@@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
76145 if (!pte_none(*page_table))
76146 goto release;
76147
76148+#ifdef CONFIG_PAX_SEGMEXEC
76149+ if (pax_find_mirror_vma(vma))
76150+ BUG_ON(!trylock_page(page));
76151+#endif
76152+
76153 inc_mm_counter_fast(mm, MM_ANONPAGES);
76154 page_add_new_anon_rmap(page, vma, address);
76155 setpte:
76156@@ -3181,6 +3364,12 @@ setpte:
76157
76158 /* No need to invalidate - it was non-present before */
76159 update_mmu_cache(vma, address, page_table);
76160+
76161+#ifdef CONFIG_PAX_SEGMEXEC
76162+ if (page)
76163+ pax_mirror_anon_pte(vma, address, page, ptl);
76164+#endif
76165+
76166 unlock:
76167 pte_unmap_unlock(page_table, ptl);
76168 return 0;
76169@@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76170 */
76171 /* Only go through if we didn't race with anybody else... */
76172 if (likely(pte_same(*page_table, orig_pte))) {
76173+
76174+#ifdef CONFIG_PAX_SEGMEXEC
76175+ if (anon && pax_find_mirror_vma(vma))
76176+ BUG_ON(!trylock_page(page));
76177+#endif
76178+
76179 flush_icache_page(vma, page);
76180 entry = mk_pte(page, vma->vm_page_prot);
76181 if (flags & FAULT_FLAG_WRITE)
76182@@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76183
76184 /* no need to invalidate: a not-present page won't be cached */
76185 update_mmu_cache(vma, address, page_table);
76186+
76187+#ifdef CONFIG_PAX_SEGMEXEC
76188+ if (anon)
76189+ pax_mirror_anon_pte(vma, address, page, ptl);
76190+ else
76191+ pax_mirror_file_pte(vma, address, page, ptl);
76192+#endif
76193+
76194 } else {
76195 if (cow_page)
76196 mem_cgroup_uncharge_page(cow_page);
76197@@ -3664,6 +3867,12 @@ int handle_pte_fault(struct mm_struct *mm,
76198 if (flags & FAULT_FLAG_WRITE)
76199 flush_tlb_fix_spurious_fault(vma, address);
76200 }
76201+
76202+#ifdef CONFIG_PAX_SEGMEXEC
76203+ pax_mirror_pte(vma, address, pte, pmd, ptl);
76204+ return 0;
76205+#endif
76206+
76207 unlock:
76208 pte_unmap_unlock(pte, ptl);
76209 return 0;
76210@@ -3680,6 +3889,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76211 pmd_t *pmd;
76212 pte_t *pte;
76213
76214+#ifdef CONFIG_PAX_SEGMEXEC
76215+ struct vm_area_struct *vma_m;
76216+#endif
76217+
76218 __set_current_state(TASK_RUNNING);
76219
76220 count_vm_event(PGFAULT);
76221@@ -3691,6 +3904,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76222 if (unlikely(is_vm_hugetlb_page(vma)))
76223 return hugetlb_fault(mm, vma, address, flags);
76224
76225+#ifdef CONFIG_PAX_SEGMEXEC
76226+ vma_m = pax_find_mirror_vma(vma);
76227+ if (vma_m) {
76228+ unsigned long address_m;
76229+ pgd_t *pgd_m;
76230+ pud_t *pud_m;
76231+ pmd_t *pmd_m;
76232+
76233+ if (vma->vm_start > vma_m->vm_start) {
76234+ address_m = address;
76235+ address -= SEGMEXEC_TASK_SIZE;
76236+ vma = vma_m;
76237+ } else
76238+ address_m = address + SEGMEXEC_TASK_SIZE;
76239+
76240+ pgd_m = pgd_offset(mm, address_m);
76241+ pud_m = pud_alloc(mm, pgd_m, address_m);
76242+ if (!pud_m)
76243+ return VM_FAULT_OOM;
76244+ pmd_m = pmd_alloc(mm, pud_m, address_m);
76245+ if (!pmd_m)
76246+ return VM_FAULT_OOM;
76247+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
76248+ return VM_FAULT_OOM;
76249+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
76250+ }
76251+#endif
76252+
76253 retry:
76254 pgd = pgd_offset(mm, address);
76255 pud = pud_alloc(mm, pgd, address);
76256@@ -3789,6 +4030,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
76257 spin_unlock(&mm->page_table_lock);
76258 return 0;
76259 }
76260+
76261+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
76262+{
76263+ pud_t *new = pud_alloc_one(mm, address);
76264+ if (!new)
76265+ return -ENOMEM;
76266+
76267+ smp_wmb(); /* See comment in __pte_alloc */
76268+
76269+ spin_lock(&mm->page_table_lock);
76270+ if (pgd_present(*pgd)) /* Another has populated it */
76271+ pud_free(mm, new);
76272+ else
76273+ pgd_populate_kernel(mm, pgd, new);
76274+ spin_unlock(&mm->page_table_lock);
76275+ return 0;
76276+}
76277 #endif /* __PAGETABLE_PUD_FOLDED */
76278
76279 #ifndef __PAGETABLE_PMD_FOLDED
76280@@ -3819,6 +4077,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
76281 spin_unlock(&mm->page_table_lock);
76282 return 0;
76283 }
76284+
76285+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
76286+{
76287+ pmd_t *new = pmd_alloc_one(mm, address);
76288+ if (!new)
76289+ return -ENOMEM;
76290+
76291+ smp_wmb(); /* See comment in __pte_alloc */
76292+
76293+ spin_lock(&mm->page_table_lock);
76294+#ifndef __ARCH_HAS_4LEVEL_HACK
76295+ if (pud_present(*pud)) /* Another has populated it */
76296+ pmd_free(mm, new);
76297+ else
76298+ pud_populate_kernel(mm, pud, new);
76299+#else
76300+ if (pgd_present(*pud)) /* Another has populated it */
76301+ pmd_free(mm, new);
76302+ else
76303+ pgd_populate_kernel(mm, pud, new);
76304+#endif /* __ARCH_HAS_4LEVEL_HACK */
76305+ spin_unlock(&mm->page_table_lock);
76306+ return 0;
76307+}
76308 #endif /* __PAGETABLE_PMD_FOLDED */
76309
76310 int make_pages_present(unsigned long addr, unsigned long end)
76311@@ -3856,7 +4138,7 @@ static int __init gate_vma_init(void)
76312 gate_vma.vm_start = FIXADDR_USER_START;
76313 gate_vma.vm_end = FIXADDR_USER_END;
76314 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
76315- gate_vma.vm_page_prot = __P101;
76316+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
76317
76318 return 0;
76319 }
76320diff --git a/mm/mempolicy.c b/mm/mempolicy.c
76321index e2df1c1..1e31d57 100644
76322--- a/mm/mempolicy.c
76323+++ b/mm/mempolicy.c
76324@@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
76325 unsigned long vmstart;
76326 unsigned long vmend;
76327
76328+#ifdef CONFIG_PAX_SEGMEXEC
76329+ struct vm_area_struct *vma_m;
76330+#endif
76331+
76332 vma = find_vma(mm, start);
76333 if (!vma || vma->vm_start > start)
76334 return -EFAULT;
76335@@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
76336 if (err)
76337 goto out;
76338 }
76339+
76340 err = vma_replace_policy(vma, new_pol);
76341 if (err)
76342 goto out;
76343+
76344+#ifdef CONFIG_PAX_SEGMEXEC
76345+ vma_m = pax_find_mirror_vma(vma);
76346+ if (vma_m) {
76347+ err = vma_replace_policy(vma_m, new_pol);
76348+ if (err)
76349+ goto out;
76350+ }
76351+#endif
76352+
76353 }
76354
76355 out:
76356@@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
76357
76358 if (end < start)
76359 return -EINVAL;
76360+
76361+#ifdef CONFIG_PAX_SEGMEXEC
76362+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
76363+ if (end > SEGMEXEC_TASK_SIZE)
76364+ return -EINVAL;
76365+ } else
76366+#endif
76367+
76368+ if (end > TASK_SIZE)
76369+ return -EINVAL;
76370+
76371 if (end == start)
76372 return 0;
76373
76374@@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76375 */
76376 tcred = __task_cred(task);
76377 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
76378- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
76379- !capable(CAP_SYS_NICE)) {
76380+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
76381 rcu_read_unlock();
76382 err = -EPERM;
76383 goto out_put;
76384@@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76385 goto out;
76386 }
76387
76388+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76389+ if (mm != current->mm &&
76390+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
76391+ mmput(mm);
76392+ err = -EPERM;
76393+ goto out;
76394+ }
76395+#endif
76396+
76397 err = do_migrate_pages(mm, old, new,
76398 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
76399
76400diff --git a/mm/migrate.c b/mm/migrate.c
76401index 2fd8b4a..d70358f 100644
76402--- a/mm/migrate.c
76403+++ b/mm/migrate.c
76404@@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
76405 */
76406 tcred = __task_cred(task);
76407 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
76408- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
76409- !capable(CAP_SYS_NICE)) {
76410+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
76411 rcu_read_unlock();
76412 err = -EPERM;
76413 goto out;
76414diff --git a/mm/mlock.c b/mm/mlock.c
76415index c9bd528..da8d069 100644
76416--- a/mm/mlock.c
76417+++ b/mm/mlock.c
76418@@ -13,6 +13,7 @@
76419 #include <linux/pagemap.h>
76420 #include <linux/mempolicy.h>
76421 #include <linux/syscalls.h>
76422+#include <linux/security.h>
76423 #include <linux/sched.h>
76424 #include <linux/export.h>
76425 #include <linux/rmap.h>
76426@@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
76427 {
76428 unsigned long nstart, end, tmp;
76429 struct vm_area_struct * vma, * prev;
76430- int error;
76431+ int error = 0;
76432
76433 VM_BUG_ON(start & ~PAGE_MASK);
76434 VM_BUG_ON(len != PAGE_ALIGN(len));
76435@@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
76436 return -EINVAL;
76437 if (end == start)
76438 return 0;
76439+ if (end > TASK_SIZE)
76440+ return -EINVAL;
76441+
76442 vma = find_vma(current->mm, start);
76443 if (!vma || vma->vm_start > start)
76444 return -ENOMEM;
76445@@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
76446 for (nstart = start ; ; ) {
76447 vm_flags_t newflags;
76448
76449+#ifdef CONFIG_PAX_SEGMEXEC
76450+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76451+ break;
76452+#endif
76453+
76454 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
76455
76456 newflags = vma->vm_flags | VM_LOCKED;
76457@@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
76458 lock_limit >>= PAGE_SHIFT;
76459
76460 /* check against resource limits */
76461+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
76462 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
76463 error = do_mlock(start, len, 1);
76464 up_write(&current->mm->mmap_sem);
76465@@ -528,6 +538,12 @@ static int do_mlockall(int flags)
76466 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
76467 vm_flags_t newflags;
76468
76469+#ifdef CONFIG_PAX_SEGMEXEC
76470+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76471+ break;
76472+#endif
76473+
76474+ BUG_ON(vma->vm_end > TASK_SIZE);
76475 newflags = vma->vm_flags | VM_LOCKED;
76476 if (!(flags & MCL_CURRENT))
76477 newflags &= ~VM_LOCKED;
76478@@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
76479 lock_limit >>= PAGE_SHIFT;
76480
76481 ret = -ENOMEM;
76482+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
76483 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
76484 capable(CAP_IPC_LOCK))
76485 ret = do_mlockall(flags);
76486diff --git a/mm/mmap.c b/mm/mmap.c
76487index d1e4124..32a6988 100644
76488--- a/mm/mmap.c
76489+++ b/mm/mmap.c
76490@@ -32,6 +32,7 @@
76491 #include <linux/khugepaged.h>
76492 #include <linux/uprobes.h>
76493 #include <linux/rbtree_augmented.h>
76494+#include <linux/random.h>
76495
76496 #include <asm/uaccess.h>
76497 #include <asm/cacheflush.h>
76498@@ -48,6 +49,16 @@
76499 #define arch_rebalance_pgtables(addr, len) (addr)
76500 #endif
76501
76502+static inline void verify_mm_writelocked(struct mm_struct *mm)
76503+{
76504+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
76505+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76506+ up_read(&mm->mmap_sem);
76507+ BUG();
76508+ }
76509+#endif
76510+}
76511+
76512 static void unmap_region(struct mm_struct *mm,
76513 struct vm_area_struct *vma, struct vm_area_struct *prev,
76514 unsigned long start, unsigned long end);
76515@@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
76516 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
76517 *
76518 */
76519-pgprot_t protection_map[16] = {
76520+pgprot_t protection_map[16] __read_only = {
76521 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
76522 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
76523 };
76524
76525-pgprot_t vm_get_page_prot(unsigned long vm_flags)
76526+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
76527 {
76528- return __pgprot(pgprot_val(protection_map[vm_flags &
76529+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
76530 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
76531 pgprot_val(arch_vm_get_page_prot(vm_flags)));
76532+
76533+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76534+ if (!(__supported_pte_mask & _PAGE_NX) &&
76535+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
76536+ (vm_flags & (VM_READ | VM_WRITE)))
76537+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
76538+#endif
76539+
76540+ return prot;
76541 }
76542 EXPORT_SYMBOL(vm_get_page_prot);
76543
76544 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
76545 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
76546 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
76547+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
76548 /*
76549 * Make sure vm_committed_as in one cacheline and not cacheline shared with
76550 * other variables. It can be updated by several CPUs frequently.
76551@@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
76552 struct vm_area_struct *next = vma->vm_next;
76553
76554 might_sleep();
76555+ BUG_ON(vma->vm_mirror);
76556 if (vma->vm_ops && vma->vm_ops->close)
76557 vma->vm_ops->close(vma);
76558 if (vma->vm_file)
76559@@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
76560 * not page aligned -Ram Gupta
76561 */
76562 rlim = rlimit(RLIMIT_DATA);
76563+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
76564 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
76565 (mm->end_data - mm->start_data) > rlim)
76566 goto out;
76567@@ -888,6 +911,12 @@ static int
76568 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
76569 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76570 {
76571+
76572+#ifdef CONFIG_PAX_SEGMEXEC
76573+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
76574+ return 0;
76575+#endif
76576+
76577 if (is_mergeable_vma(vma, file, vm_flags) &&
76578 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
76579 if (vma->vm_pgoff == vm_pgoff)
76580@@ -907,6 +936,12 @@ static int
76581 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76582 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76583 {
76584+
76585+#ifdef CONFIG_PAX_SEGMEXEC
76586+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
76587+ return 0;
76588+#endif
76589+
76590 if (is_mergeable_vma(vma, file, vm_flags) &&
76591 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
76592 pgoff_t vm_pglen;
76593@@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76594 struct vm_area_struct *vma_merge(struct mm_struct *mm,
76595 struct vm_area_struct *prev, unsigned long addr,
76596 unsigned long end, unsigned long vm_flags,
76597- struct anon_vma *anon_vma, struct file *file,
76598+ struct anon_vma *anon_vma, struct file *file,
76599 pgoff_t pgoff, struct mempolicy *policy)
76600 {
76601 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
76602 struct vm_area_struct *area, *next;
76603 int err;
76604
76605+#ifdef CONFIG_PAX_SEGMEXEC
76606+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
76607+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
76608+
76609+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
76610+#endif
76611+
76612 /*
76613 * We later require that vma->vm_flags == vm_flags,
76614 * so this tests vma->vm_flags & VM_SPECIAL, too.
76615@@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76616 if (next && next->vm_end == end) /* cases 6, 7, 8 */
76617 next = next->vm_next;
76618
76619+#ifdef CONFIG_PAX_SEGMEXEC
76620+ if (prev)
76621+ prev_m = pax_find_mirror_vma(prev);
76622+ if (area)
76623+ area_m = pax_find_mirror_vma(area);
76624+ if (next)
76625+ next_m = pax_find_mirror_vma(next);
76626+#endif
76627+
76628 /*
76629 * Can it merge with the predecessor?
76630 */
76631@@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76632 /* cases 1, 6 */
76633 err = vma_adjust(prev, prev->vm_start,
76634 next->vm_end, prev->vm_pgoff, NULL);
76635- } else /* cases 2, 5, 7 */
76636+
76637+#ifdef CONFIG_PAX_SEGMEXEC
76638+ if (!err && prev_m)
76639+ err = vma_adjust(prev_m, prev_m->vm_start,
76640+ next_m->vm_end, prev_m->vm_pgoff, NULL);
76641+#endif
76642+
76643+ } else { /* cases 2, 5, 7 */
76644 err = vma_adjust(prev, prev->vm_start,
76645 end, prev->vm_pgoff, NULL);
76646+
76647+#ifdef CONFIG_PAX_SEGMEXEC
76648+ if (!err && prev_m)
76649+ err = vma_adjust(prev_m, prev_m->vm_start,
76650+ end_m, prev_m->vm_pgoff, NULL);
76651+#endif
76652+
76653+ }
76654 if (err)
76655 return NULL;
76656 khugepaged_enter_vma_merge(prev);
76657@@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76658 mpol_equal(policy, vma_policy(next)) &&
76659 can_vma_merge_before(next, vm_flags,
76660 anon_vma, file, pgoff+pglen)) {
76661- if (prev && addr < prev->vm_end) /* case 4 */
76662+ if (prev && addr < prev->vm_end) { /* case 4 */
76663 err = vma_adjust(prev, prev->vm_start,
76664 addr, prev->vm_pgoff, NULL);
76665- else /* cases 3, 8 */
76666+
76667+#ifdef CONFIG_PAX_SEGMEXEC
76668+ if (!err && prev_m)
76669+ err = vma_adjust(prev_m, prev_m->vm_start,
76670+ addr_m, prev_m->vm_pgoff, NULL);
76671+#endif
76672+
76673+ } else { /* cases 3, 8 */
76674 err = vma_adjust(area, addr, next->vm_end,
76675 next->vm_pgoff - pglen, NULL);
76676+
76677+#ifdef CONFIG_PAX_SEGMEXEC
76678+ if (!err && area_m)
76679+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
76680+ next_m->vm_pgoff - pglen, NULL);
76681+#endif
76682+
76683+ }
76684 if (err)
76685 return NULL;
76686 khugepaged_enter_vma_merge(area);
76687@@ -1120,16 +1201,13 @@ none:
76688 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
76689 struct file *file, long pages)
76690 {
76691- const unsigned long stack_flags
76692- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
76693-
76694 mm->total_vm += pages;
76695
76696 if (file) {
76697 mm->shared_vm += pages;
76698 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
76699 mm->exec_vm += pages;
76700- } else if (flags & stack_flags)
76701+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
76702 mm->stack_vm += pages;
76703 }
76704 #endif /* CONFIG_PROC_FS */
76705@@ -1165,7 +1243,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76706 * (the exception is when the underlying filesystem is noexec
76707 * mounted, in which case we dont add PROT_EXEC.)
76708 */
76709- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
76710+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
76711 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
76712 prot |= PROT_EXEC;
76713
76714@@ -1191,7 +1269,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76715 /* Obtain the address to map to. we verify (or select) it and ensure
76716 * that it represents a valid section of the address space.
76717 */
76718- addr = get_unmapped_area(file, addr, len, pgoff, flags);
76719+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
76720 if (addr & ~PAGE_MASK)
76721 return addr;
76722
76723@@ -1202,6 +1280,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76724 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
76725 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
76726
76727+#ifdef CONFIG_PAX_MPROTECT
76728+ if (mm->pax_flags & MF_PAX_MPROTECT) {
76729+#ifndef CONFIG_PAX_MPROTECT_COMPAT
76730+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
76731+ gr_log_rwxmmap(file);
76732+
76733+#ifdef CONFIG_PAX_EMUPLT
76734+ vm_flags &= ~VM_EXEC;
76735+#else
76736+ return -EPERM;
76737+#endif
76738+
76739+ }
76740+
76741+ if (!(vm_flags & VM_EXEC))
76742+ vm_flags &= ~VM_MAYEXEC;
76743+#else
76744+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
76745+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
76746+#endif
76747+ else
76748+ vm_flags &= ~VM_MAYWRITE;
76749+ }
76750+#endif
76751+
76752+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76753+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
76754+ vm_flags &= ~VM_PAGEEXEC;
76755+#endif
76756+
76757 if (flags & MAP_LOCKED)
76758 if (!can_do_mlock())
76759 return -EPERM;
76760@@ -1213,6 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76761 locked += mm->locked_vm;
76762 lock_limit = rlimit(RLIMIT_MEMLOCK);
76763 lock_limit >>= PAGE_SHIFT;
76764+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
76765 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
76766 return -EAGAIN;
76767 }
76768@@ -1279,6 +1388,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76769 }
76770 }
76771
76772+ if (!gr_acl_handle_mmap(file, prot))
76773+ return -EACCES;
76774+
76775 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
76776 }
76777
76778@@ -1356,7 +1468,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
76779 vm_flags_t vm_flags = vma->vm_flags;
76780
76781 /* If it was private or non-writable, the write bit is already clear */
76782- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
76783+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
76784 return 0;
76785
76786 /* The backer wishes to know when pages are first written to? */
76787@@ -1405,13 +1517,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
76788 unsigned long charged = 0;
76789 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
76790
76791+#ifdef CONFIG_PAX_SEGMEXEC
76792+ struct vm_area_struct *vma_m = NULL;
76793+#endif
76794+
76795+ /*
76796+ * mm->mmap_sem is required to protect against another thread
76797+ * changing the mappings in case we sleep.
76798+ */
76799+ verify_mm_writelocked(mm);
76800+
76801 /* Clear old maps */
76802 error = -ENOMEM;
76803-munmap_back:
76804 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
76805 if (do_munmap(mm, addr, len))
76806 return -ENOMEM;
76807- goto munmap_back;
76808+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
76809 }
76810
76811 /* Check against address space limit. */
76812@@ -1460,6 +1581,16 @@ munmap_back:
76813 goto unacct_error;
76814 }
76815
76816+#ifdef CONFIG_PAX_SEGMEXEC
76817+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
76818+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76819+ if (!vma_m) {
76820+ error = -ENOMEM;
76821+ goto free_vma;
76822+ }
76823+ }
76824+#endif
76825+
76826 vma->vm_mm = mm;
76827 vma->vm_start = addr;
76828 vma->vm_end = addr + len;
76829@@ -1484,6 +1615,13 @@ munmap_back:
76830 if (error)
76831 goto unmap_and_free_vma;
76832
76833+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76834+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
76835+ vma->vm_flags |= VM_PAGEEXEC;
76836+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
76837+ }
76838+#endif
76839+
76840 /* Can addr have changed??
76841 *
76842 * Answer: Yes, several device drivers can do it in their
76843@@ -1522,6 +1660,11 @@ munmap_back:
76844 vma_link(mm, vma, prev, rb_link, rb_parent);
76845 file = vma->vm_file;
76846
76847+#ifdef CONFIG_PAX_SEGMEXEC
76848+ if (vma_m)
76849+ BUG_ON(pax_mirror_vma(vma_m, vma));
76850+#endif
76851+
76852 /* Once vma denies write, undo our temporary denial count */
76853 if (correct_wcount)
76854 atomic_inc(&inode->i_writecount);
76855@@ -1529,6 +1672,7 @@ out:
76856 perf_event_mmap(vma);
76857
76858 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
76859+ track_exec_limit(mm, addr, addr + len, vm_flags);
76860 if (vm_flags & VM_LOCKED) {
76861 if (!mlock_vma_pages_range(vma, addr, addr + len))
76862 mm->locked_vm += (len >> PAGE_SHIFT);
76863@@ -1550,6 +1694,12 @@ unmap_and_free_vma:
76864 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
76865 charged = 0;
76866 free_vma:
76867+
76868+#ifdef CONFIG_PAX_SEGMEXEC
76869+ if (vma_m)
76870+ kmem_cache_free(vm_area_cachep, vma_m);
76871+#endif
76872+
76873 kmem_cache_free(vm_area_cachep, vma);
76874 unacct_error:
76875 if (charged)
76876@@ -1557,6 +1707,62 @@ unacct_error:
76877 return error;
76878 }
76879
76880+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
76881+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
76882+{
76883+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
76884+ return (random32() & 0xFF) << PAGE_SHIFT;
76885+
76886+ return 0;
76887+}
76888+#endif
76889+
76890+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
76891+{
76892+ if (!vma) {
76893+#ifdef CONFIG_STACK_GROWSUP
76894+ if (addr > sysctl_heap_stack_gap)
76895+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
76896+ else
76897+ vma = find_vma(current->mm, 0);
76898+ if (vma && (vma->vm_flags & VM_GROWSUP))
76899+ return false;
76900+#endif
76901+ return true;
76902+ }
76903+
76904+ if (addr + len > vma->vm_start)
76905+ return false;
76906+
76907+ if (vma->vm_flags & VM_GROWSDOWN)
76908+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
76909+#ifdef CONFIG_STACK_GROWSUP
76910+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
76911+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
76912+#endif
76913+ else if (offset)
76914+ return offset <= vma->vm_start - addr - len;
76915+
76916+ return true;
76917+}
76918+
76919+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
76920+{
76921+ if (vma->vm_start < len)
76922+ return -ENOMEM;
76923+
76924+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
76925+ if (offset <= vma->vm_start - len)
76926+ return vma->vm_start - len - offset;
76927+ else
76928+ return -ENOMEM;
76929+ }
76930+
76931+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
76932+ return vma->vm_start - len - sysctl_heap_stack_gap;
76933+ return -ENOMEM;
76934+}
76935+
76936 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
76937 {
76938 /*
76939@@ -1776,6 +1982,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
76940 struct mm_struct *mm = current->mm;
76941 struct vm_area_struct *vma;
76942 struct vm_unmapped_area_info info;
76943+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
76944
76945 if (len > TASK_SIZE)
76946 return -ENOMEM;
76947@@ -1783,17 +1990,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
76948 if (flags & MAP_FIXED)
76949 return addr;
76950
76951+#ifdef CONFIG_PAX_RANDMMAP
76952+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
76953+#endif
76954+
76955 if (addr) {
76956 addr = PAGE_ALIGN(addr);
76957 vma = find_vma(mm, addr);
76958- if (TASK_SIZE - len >= addr &&
76959- (!vma || addr + len <= vma->vm_start))
76960+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
76961 return addr;
76962 }
76963
76964 info.flags = 0;
76965 info.length = len;
76966 info.low_limit = TASK_UNMAPPED_BASE;
76967+
76968+#ifdef CONFIG_PAX_RANDMMAP
76969+ if (mm->pax_flags & MF_PAX_RANDMMAP)
76970+ info.low_limit += mm->delta_mmap;
76971+#endif
76972+
76973 info.high_limit = TASK_SIZE;
76974 info.align_mask = 0;
76975 return vm_unmapped_area(&info);
76976@@ -1802,10 +2018,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
76977
76978 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
76979 {
76980+
76981+#ifdef CONFIG_PAX_SEGMEXEC
76982+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
76983+ return;
76984+#endif
76985+
76986 /*
76987 * Is this a new hole at the lowest possible address?
76988 */
76989- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
76990+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
76991 mm->free_area_cache = addr;
76992 }
76993
76994@@ -1823,6 +2045,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76995 struct mm_struct *mm = current->mm;
76996 unsigned long addr = addr0;
76997 struct vm_unmapped_area_info info;
76998+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
76999
77000 /* requested length too big for entire address space */
77001 if (len > TASK_SIZE)
77002@@ -1831,12 +2054,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77003 if (flags & MAP_FIXED)
77004 return addr;
77005
77006+#ifdef CONFIG_PAX_RANDMMAP
77007+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
77008+#endif
77009+
77010 /* requesting a specific address */
77011 if (addr) {
77012 addr = PAGE_ALIGN(addr);
77013 vma = find_vma(mm, addr);
77014- if (TASK_SIZE - len >= addr &&
77015- (!vma || addr + len <= vma->vm_start))
77016+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
77017 return addr;
77018 }
77019
77020@@ -1857,6 +2083,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77021 VM_BUG_ON(addr != -ENOMEM);
77022 info.flags = 0;
77023 info.low_limit = TASK_UNMAPPED_BASE;
77024+
77025+#ifdef CONFIG_PAX_RANDMMAP
77026+ if (mm->pax_flags & MF_PAX_RANDMMAP)
77027+ info.low_limit += mm->delta_mmap;
77028+#endif
77029+
77030 info.high_limit = TASK_SIZE;
77031 addr = vm_unmapped_area(&info);
77032 }
77033@@ -1867,6 +2099,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77034
77035 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
77036 {
77037+
77038+#ifdef CONFIG_PAX_SEGMEXEC
77039+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
77040+ return;
77041+#endif
77042+
77043 /*
77044 * Is this a new hole at the highest possible address?
77045 */
77046@@ -1874,8 +2112,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
77047 mm->free_area_cache = addr;
77048
77049 /* dont allow allocations above current base */
77050- if (mm->free_area_cache > mm->mmap_base)
77051+ if (mm->free_area_cache > mm->mmap_base) {
77052 mm->free_area_cache = mm->mmap_base;
77053+ mm->cached_hole_size = ~0UL;
77054+ }
77055 }
77056
77057 unsigned long
77058@@ -1974,6 +2214,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
77059 return vma;
77060 }
77061
77062+#ifdef CONFIG_PAX_SEGMEXEC
77063+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
77064+{
77065+ struct vm_area_struct *vma_m;
77066+
77067+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
77068+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
77069+ BUG_ON(vma->vm_mirror);
77070+ return NULL;
77071+ }
77072+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
77073+ vma_m = vma->vm_mirror;
77074+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
77075+ BUG_ON(vma->vm_file != vma_m->vm_file);
77076+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
77077+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
77078+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
77079+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
77080+ return vma_m;
77081+}
77082+#endif
77083+
77084 /*
77085 * Verify that the stack growth is acceptable and
77086 * update accounting. This is shared with both the
77087@@ -1990,6 +2252,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77088 return -ENOMEM;
77089
77090 /* Stack limit test */
77091+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
77092 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
77093 return -ENOMEM;
77094
77095@@ -2000,6 +2263,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77096 locked = mm->locked_vm + grow;
77097 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
77098 limit >>= PAGE_SHIFT;
77099+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
77100 if (locked > limit && !capable(CAP_IPC_LOCK))
77101 return -ENOMEM;
77102 }
77103@@ -2029,37 +2293,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77104 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
77105 * vma is the last one with address > vma->vm_end. Have to extend vma.
77106 */
77107+#ifndef CONFIG_IA64
77108+static
77109+#endif
77110 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
77111 {
77112 int error;
77113+ bool locknext;
77114
77115 if (!(vma->vm_flags & VM_GROWSUP))
77116 return -EFAULT;
77117
77118+ /* Also guard against wrapping around to address 0. */
77119+ if (address < PAGE_ALIGN(address+1))
77120+ address = PAGE_ALIGN(address+1);
77121+ else
77122+ return -ENOMEM;
77123+
77124 /*
77125 * We must make sure the anon_vma is allocated
77126 * so that the anon_vma locking is not a noop.
77127 */
77128 if (unlikely(anon_vma_prepare(vma)))
77129 return -ENOMEM;
77130+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
77131+ if (locknext && anon_vma_prepare(vma->vm_next))
77132+ return -ENOMEM;
77133 vma_lock_anon_vma(vma);
77134+ if (locknext)
77135+ vma_lock_anon_vma(vma->vm_next);
77136
77137 /*
77138 * vma->vm_start/vm_end cannot change under us because the caller
77139 * is required to hold the mmap_sem in read mode. We need the
77140- * anon_vma lock to serialize against concurrent expand_stacks.
77141- * Also guard against wrapping around to address 0.
77142+ * anon_vma locks to serialize against concurrent expand_stacks
77143+ * and expand_upwards.
77144 */
77145- if (address < PAGE_ALIGN(address+4))
77146- address = PAGE_ALIGN(address+4);
77147- else {
77148- vma_unlock_anon_vma(vma);
77149- return -ENOMEM;
77150- }
77151 error = 0;
77152
77153 /* Somebody else might have raced and expanded it already */
77154- if (address > vma->vm_end) {
77155+ 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)
77156+ error = -ENOMEM;
77157+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
77158 unsigned long size, grow;
77159
77160 size = address - vma->vm_start;
77161@@ -2094,6 +2369,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
77162 }
77163 }
77164 }
77165+ if (locknext)
77166+ vma_unlock_anon_vma(vma->vm_next);
77167 vma_unlock_anon_vma(vma);
77168 khugepaged_enter_vma_merge(vma);
77169 validate_mm(vma->vm_mm);
77170@@ -2108,6 +2385,8 @@ int expand_downwards(struct vm_area_struct *vma,
77171 unsigned long address)
77172 {
77173 int error;
77174+ bool lockprev = false;
77175+ struct vm_area_struct *prev;
77176
77177 /*
77178 * We must make sure the anon_vma is allocated
77179@@ -2121,6 +2400,15 @@ int expand_downwards(struct vm_area_struct *vma,
77180 if (error)
77181 return error;
77182
77183+ prev = vma->vm_prev;
77184+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
77185+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
77186+#endif
77187+ if (lockprev && anon_vma_prepare(prev))
77188+ return -ENOMEM;
77189+ if (lockprev)
77190+ vma_lock_anon_vma(prev);
77191+
77192 vma_lock_anon_vma(vma);
77193
77194 /*
77195@@ -2130,9 +2418,17 @@ int expand_downwards(struct vm_area_struct *vma,
77196 */
77197
77198 /* Somebody else might have raced and expanded it already */
77199- if (address < vma->vm_start) {
77200+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
77201+ error = -ENOMEM;
77202+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
77203 unsigned long size, grow;
77204
77205+#ifdef CONFIG_PAX_SEGMEXEC
77206+ struct vm_area_struct *vma_m;
77207+
77208+ vma_m = pax_find_mirror_vma(vma);
77209+#endif
77210+
77211 size = vma->vm_end - address;
77212 grow = (vma->vm_start - address) >> PAGE_SHIFT;
77213
77214@@ -2157,6 +2453,18 @@ int expand_downwards(struct vm_area_struct *vma,
77215 vma->vm_pgoff -= grow;
77216 anon_vma_interval_tree_post_update_vma(vma);
77217 vma_gap_update(vma);
77218+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
77219+
77220+#ifdef CONFIG_PAX_SEGMEXEC
77221+ if (vma_m) {
77222+ anon_vma_interval_tree_pre_update_vma(vma_m);
77223+ vma_m->vm_start -= grow << PAGE_SHIFT;
77224+ vma_m->vm_pgoff -= grow;
77225+ anon_vma_interval_tree_post_update_vma(vma_m);
77226+ vma_gap_update(vma_m);
77227+ }
77228+#endif
77229+
77230 spin_unlock(&vma->vm_mm->page_table_lock);
77231
77232 perf_event_mmap(vma);
77233@@ -2236,6 +2544,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
77234 do {
77235 long nrpages = vma_pages(vma);
77236
77237+#ifdef CONFIG_PAX_SEGMEXEC
77238+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
77239+ vma = remove_vma(vma);
77240+ continue;
77241+ }
77242+#endif
77243+
77244 if (vma->vm_flags & VM_ACCOUNT)
77245 nr_accounted += nrpages;
77246 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
77247@@ -2281,6 +2596,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
77248 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
77249 vma->vm_prev = NULL;
77250 do {
77251+
77252+#ifdef CONFIG_PAX_SEGMEXEC
77253+ if (vma->vm_mirror) {
77254+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
77255+ vma->vm_mirror->vm_mirror = NULL;
77256+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
77257+ vma->vm_mirror = NULL;
77258+ }
77259+#endif
77260+
77261 vma_rb_erase(vma, &mm->mm_rb);
77262 mm->map_count--;
77263 tail_vma = vma;
77264@@ -2312,14 +2637,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77265 struct vm_area_struct *new;
77266 int err = -ENOMEM;
77267
77268+#ifdef CONFIG_PAX_SEGMEXEC
77269+ struct vm_area_struct *vma_m, *new_m = NULL;
77270+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
77271+#endif
77272+
77273 if (is_vm_hugetlb_page(vma) && (addr &
77274 ~(huge_page_mask(hstate_vma(vma)))))
77275 return -EINVAL;
77276
77277+#ifdef CONFIG_PAX_SEGMEXEC
77278+ vma_m = pax_find_mirror_vma(vma);
77279+#endif
77280+
77281 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
77282 if (!new)
77283 goto out_err;
77284
77285+#ifdef CONFIG_PAX_SEGMEXEC
77286+ if (vma_m) {
77287+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
77288+ if (!new_m) {
77289+ kmem_cache_free(vm_area_cachep, new);
77290+ goto out_err;
77291+ }
77292+ }
77293+#endif
77294+
77295 /* most fields are the same, copy all, and then fixup */
77296 *new = *vma;
77297
77298@@ -2332,6 +2676,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77299 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
77300 }
77301
77302+#ifdef CONFIG_PAX_SEGMEXEC
77303+ if (vma_m) {
77304+ *new_m = *vma_m;
77305+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
77306+ new_m->vm_mirror = new;
77307+ new->vm_mirror = new_m;
77308+
77309+ if (new_below)
77310+ new_m->vm_end = addr_m;
77311+ else {
77312+ new_m->vm_start = addr_m;
77313+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
77314+ }
77315+ }
77316+#endif
77317+
77318 pol = mpol_dup(vma_policy(vma));
77319 if (IS_ERR(pol)) {
77320 err = PTR_ERR(pol);
77321@@ -2354,6 +2714,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77322 else
77323 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
77324
77325+#ifdef CONFIG_PAX_SEGMEXEC
77326+ if (!err && vma_m) {
77327+ if (anon_vma_clone(new_m, vma_m))
77328+ goto out_free_mpol;
77329+
77330+ mpol_get(pol);
77331+ vma_set_policy(new_m, pol);
77332+
77333+ if (new_m->vm_file)
77334+ get_file(new_m->vm_file);
77335+
77336+ if (new_m->vm_ops && new_m->vm_ops->open)
77337+ new_m->vm_ops->open(new_m);
77338+
77339+ if (new_below)
77340+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
77341+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
77342+ else
77343+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
77344+
77345+ if (err) {
77346+ if (new_m->vm_ops && new_m->vm_ops->close)
77347+ new_m->vm_ops->close(new_m);
77348+ if (new_m->vm_file)
77349+ fput(new_m->vm_file);
77350+ mpol_put(pol);
77351+ }
77352+ }
77353+#endif
77354+
77355 /* Success. */
77356 if (!err)
77357 return 0;
77358@@ -2363,10 +2753,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77359 new->vm_ops->close(new);
77360 if (new->vm_file)
77361 fput(new->vm_file);
77362- unlink_anon_vmas(new);
77363 out_free_mpol:
77364 mpol_put(pol);
77365 out_free_vma:
77366+
77367+#ifdef CONFIG_PAX_SEGMEXEC
77368+ if (new_m) {
77369+ unlink_anon_vmas(new_m);
77370+ kmem_cache_free(vm_area_cachep, new_m);
77371+ }
77372+#endif
77373+
77374+ unlink_anon_vmas(new);
77375 kmem_cache_free(vm_area_cachep, new);
77376 out_err:
77377 return err;
77378@@ -2379,6 +2777,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77379 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77380 unsigned long addr, int new_below)
77381 {
77382+
77383+#ifdef CONFIG_PAX_SEGMEXEC
77384+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
77385+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
77386+ if (mm->map_count >= sysctl_max_map_count-1)
77387+ return -ENOMEM;
77388+ } else
77389+#endif
77390+
77391 if (mm->map_count >= sysctl_max_map_count)
77392 return -ENOMEM;
77393
77394@@ -2390,11 +2797,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77395 * work. This now handles partial unmappings.
77396 * Jeremy Fitzhardinge <jeremy@goop.org>
77397 */
77398+#ifdef CONFIG_PAX_SEGMEXEC
77399 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77400 {
77401+ int ret = __do_munmap(mm, start, len);
77402+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
77403+ return ret;
77404+
77405+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
77406+}
77407+
77408+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77409+#else
77410+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77411+#endif
77412+{
77413 unsigned long end;
77414 struct vm_area_struct *vma, *prev, *last;
77415
77416+ /*
77417+ * mm->mmap_sem is required to protect against another thread
77418+ * changing the mappings in case we sleep.
77419+ */
77420+ verify_mm_writelocked(mm);
77421+
77422 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
77423 return -EINVAL;
77424
77425@@ -2469,6 +2895,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77426 /* Fix up all other VM information */
77427 remove_vma_list(mm, vma);
77428
77429+ track_exec_limit(mm, start, end, 0UL);
77430+
77431 return 0;
77432 }
77433
77434@@ -2477,6 +2905,13 @@ int vm_munmap(unsigned long start, size_t len)
77435 int ret;
77436 struct mm_struct *mm = current->mm;
77437
77438+
77439+#ifdef CONFIG_PAX_SEGMEXEC
77440+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
77441+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
77442+ return -EINVAL;
77443+#endif
77444+
77445 down_write(&mm->mmap_sem);
77446 ret = do_munmap(mm, start, len);
77447 up_write(&mm->mmap_sem);
77448@@ -2490,16 +2925,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
77449 return vm_munmap(addr, len);
77450 }
77451
77452-static inline void verify_mm_writelocked(struct mm_struct *mm)
77453-{
77454-#ifdef CONFIG_DEBUG_VM
77455- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
77456- WARN_ON(1);
77457- up_read(&mm->mmap_sem);
77458- }
77459-#endif
77460-}
77461-
77462 /*
77463 * this is really a simplified "do_mmap". it only handles
77464 * anonymous maps. eventually we may be able to do some
77465@@ -2513,6 +2938,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77466 struct rb_node ** rb_link, * rb_parent;
77467 pgoff_t pgoff = addr >> PAGE_SHIFT;
77468 int error;
77469+ unsigned long charged;
77470
77471 len = PAGE_ALIGN(len);
77472 if (!len)
77473@@ -2520,16 +2946,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77474
77475 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
77476
77477+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
77478+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
77479+ flags &= ~VM_EXEC;
77480+
77481+#ifdef CONFIG_PAX_MPROTECT
77482+ if (mm->pax_flags & MF_PAX_MPROTECT)
77483+ flags &= ~VM_MAYEXEC;
77484+#endif
77485+
77486+ }
77487+#endif
77488+
77489 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
77490 if (error & ~PAGE_MASK)
77491 return error;
77492
77493+ charged = len >> PAGE_SHIFT;
77494+
77495 /*
77496 * mlock MCL_FUTURE?
77497 */
77498 if (mm->def_flags & VM_LOCKED) {
77499 unsigned long locked, lock_limit;
77500- locked = len >> PAGE_SHIFT;
77501+ locked = charged;
77502 locked += mm->locked_vm;
77503 lock_limit = rlimit(RLIMIT_MEMLOCK);
77504 lock_limit >>= PAGE_SHIFT;
77505@@ -2546,21 +2986,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77506 /*
77507 * Clear old maps. this also does some error checking for us
77508 */
77509- munmap_back:
77510 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
77511 if (do_munmap(mm, addr, len))
77512 return -ENOMEM;
77513- goto munmap_back;
77514+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
77515 }
77516
77517 /* Check against address space limits *after* clearing old maps... */
77518- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
77519+ if (!may_expand_vm(mm, charged))
77520 return -ENOMEM;
77521
77522 if (mm->map_count > sysctl_max_map_count)
77523 return -ENOMEM;
77524
77525- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
77526+ if (security_vm_enough_memory_mm(mm, charged))
77527 return -ENOMEM;
77528
77529 /* Can we just expand an old private anonymous mapping? */
77530@@ -2574,7 +3013,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77531 */
77532 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77533 if (!vma) {
77534- vm_unacct_memory(len >> PAGE_SHIFT);
77535+ vm_unacct_memory(charged);
77536 return -ENOMEM;
77537 }
77538
77539@@ -2588,11 +3027,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77540 vma_link(mm, vma, prev, rb_link, rb_parent);
77541 out:
77542 perf_event_mmap(vma);
77543- mm->total_vm += len >> PAGE_SHIFT;
77544+ mm->total_vm += charged;
77545 if (flags & VM_LOCKED) {
77546 if (!mlock_vma_pages_range(vma, addr, addr + len))
77547- mm->locked_vm += (len >> PAGE_SHIFT);
77548+ mm->locked_vm += charged;
77549 }
77550+ track_exec_limit(mm, addr, addr + len, flags);
77551 return addr;
77552 }
77553
77554@@ -2650,6 +3090,7 @@ void exit_mmap(struct mm_struct *mm)
77555 while (vma) {
77556 if (vma->vm_flags & VM_ACCOUNT)
77557 nr_accounted += vma_pages(vma);
77558+ vma->vm_mirror = NULL;
77559 vma = remove_vma(vma);
77560 }
77561 vm_unacct_memory(nr_accounted);
77562@@ -2666,6 +3107,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
77563 struct vm_area_struct *prev;
77564 struct rb_node **rb_link, *rb_parent;
77565
77566+#ifdef CONFIG_PAX_SEGMEXEC
77567+ struct vm_area_struct *vma_m = NULL;
77568+#endif
77569+
77570+ if (security_mmap_addr(vma->vm_start))
77571+ return -EPERM;
77572+
77573 /*
77574 * The vm_pgoff of a purely anonymous vma should be irrelevant
77575 * until its first write fault, when page's anon_vma and index
77576@@ -2689,7 +3137,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
77577 security_vm_enough_memory_mm(mm, vma_pages(vma)))
77578 return -ENOMEM;
77579
77580+#ifdef CONFIG_PAX_SEGMEXEC
77581+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
77582+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77583+ if (!vma_m)
77584+ return -ENOMEM;
77585+ }
77586+#endif
77587+
77588 vma_link(mm, vma, prev, rb_link, rb_parent);
77589+
77590+#ifdef CONFIG_PAX_SEGMEXEC
77591+ if (vma_m)
77592+ BUG_ON(pax_mirror_vma(vma_m, vma));
77593+#endif
77594+
77595 return 0;
77596 }
77597
77598@@ -2709,6 +3171,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77599 struct mempolicy *pol;
77600 bool faulted_in_anon_vma = true;
77601
77602+ BUG_ON(vma->vm_mirror);
77603+
77604 /*
77605 * If anonymous vma has not yet been faulted, update new pgoff
77606 * to match new location, to increase its chance of merging.
77607@@ -2775,6 +3239,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77608 return NULL;
77609 }
77610
77611+#ifdef CONFIG_PAX_SEGMEXEC
77612+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
77613+{
77614+ struct vm_area_struct *prev_m;
77615+ struct rb_node **rb_link_m, *rb_parent_m;
77616+ struct mempolicy *pol_m;
77617+
77618+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
77619+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
77620+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
77621+ *vma_m = *vma;
77622+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
77623+ if (anon_vma_clone(vma_m, vma))
77624+ return -ENOMEM;
77625+ pol_m = vma_policy(vma_m);
77626+ mpol_get(pol_m);
77627+ vma_set_policy(vma_m, pol_m);
77628+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
77629+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
77630+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
77631+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
77632+ if (vma_m->vm_file)
77633+ get_file(vma_m->vm_file);
77634+ if (vma_m->vm_ops && vma_m->vm_ops->open)
77635+ vma_m->vm_ops->open(vma_m);
77636+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
77637+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
77638+ vma_m->vm_mirror = vma;
77639+ vma->vm_mirror = vma_m;
77640+ return 0;
77641+}
77642+#endif
77643+
77644 /*
77645 * Return true if the calling process may expand its vm space by the passed
77646 * number of pages
77647@@ -2786,6 +3283,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
77648
77649 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
77650
77651+#ifdef CONFIG_PAX_RANDMMAP
77652+ if (mm->pax_flags & MF_PAX_RANDMMAP)
77653+ cur -= mm->brk_gap;
77654+#endif
77655+
77656+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
77657 if (cur + npages > lim)
77658 return 0;
77659 return 1;
77660@@ -2856,6 +3359,22 @@ int install_special_mapping(struct mm_struct *mm,
77661 vma->vm_start = addr;
77662 vma->vm_end = addr + len;
77663
77664+#ifdef CONFIG_PAX_MPROTECT
77665+ if (mm->pax_flags & MF_PAX_MPROTECT) {
77666+#ifndef CONFIG_PAX_MPROTECT_COMPAT
77667+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
77668+ return -EPERM;
77669+ if (!(vm_flags & VM_EXEC))
77670+ vm_flags &= ~VM_MAYEXEC;
77671+#else
77672+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
77673+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
77674+#endif
77675+ else
77676+ vm_flags &= ~VM_MAYWRITE;
77677+ }
77678+#endif
77679+
77680 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
77681 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
77682
77683diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c
77684index 8a5ac8c..f5c3d96 100644
77685--- a/mm/mmu_notifier.c
77686+++ b/mm/mmu_notifier.c
77687@@ -37,49 +37,51 @@ static struct srcu_struct srcu;
77688 void __mmu_notifier_release(struct mm_struct *mm)
77689 {
77690 struct mmu_notifier *mn;
77691- struct hlist_node *n;
77692 int id;
77693
77694 /*
77695- * SRCU here will block mmu_notifier_unregister until
77696- * ->release returns.
77697+ * srcu_read_lock() here will block synchronize_srcu() in
77698+ * mmu_notifier_unregister() until all registered
77699+ * ->release() callouts this function makes have
77700+ * returned.
77701 */
77702 id = srcu_read_lock(&srcu);
77703- hlist_for_each_entry_rcu(mn, n, &mm->mmu_notifier_mm->list, hlist)
77704- /*
77705- * if ->release runs before mmu_notifier_unregister it
77706- * must be handled as it's the only way for the driver
77707- * to flush all existing sptes and stop the driver
77708- * from establishing any more sptes before all the
77709- * pages in the mm are freed.
77710- */
77711- if (mn->ops->release)
77712- mn->ops->release(mn, mm);
77713- srcu_read_unlock(&srcu, id);
77714-
77715 spin_lock(&mm->mmu_notifier_mm->lock);
77716 while (unlikely(!hlist_empty(&mm->mmu_notifier_mm->list))) {
77717 mn = hlist_entry(mm->mmu_notifier_mm->list.first,
77718 struct mmu_notifier,
77719 hlist);
77720+
77721 /*
77722- * We arrived before mmu_notifier_unregister so
77723- * mmu_notifier_unregister will do nothing other than
77724- * to wait ->release to finish and
77725- * mmu_notifier_unregister to return.
77726+ * Unlink. This will prevent mmu_notifier_unregister()
77727+ * from also making the ->release() callout.
77728 */
77729 hlist_del_init_rcu(&mn->hlist);
77730+ spin_unlock(&mm->mmu_notifier_mm->lock);
77731+
77732+ /*
77733+ * Clear sptes. (see 'release' description in mmu_notifier.h)
77734+ */
77735+ if (mn->ops->release)
77736+ mn->ops->release(mn, mm);
77737+
77738+ spin_lock(&mm->mmu_notifier_mm->lock);
77739 }
77740 spin_unlock(&mm->mmu_notifier_mm->lock);
77741
77742 /*
77743- * synchronize_srcu here prevents mmu_notifier_release to
77744- * return to exit_mmap (which would proceed freeing all pages
77745- * in the mm) until the ->release method returns, if it was
77746- * invoked by mmu_notifier_unregister.
77747- *
77748- * The mmu_notifier_mm can't go away from under us because one
77749- * mm_count is hold by exit_mmap.
77750+ * All callouts to ->release() which we have done are complete.
77751+ * Allow synchronize_srcu() in mmu_notifier_unregister() to complete
77752+ */
77753+ srcu_read_unlock(&srcu, id);
77754+
77755+ /*
77756+ * mmu_notifier_unregister() may have unlinked a notifier and may
77757+ * still be calling out to it. Additionally, other notifiers
77758+ * may have been active via vmtruncate() et. al. Block here
77759+ * to ensure that all notifier callouts for this mm have been
77760+ * completed and the sptes are really cleaned up before returning
77761+ * to exit_mmap().
77762 */
77763 synchronize_srcu(&srcu);
77764 }
77765@@ -294,31 +296,31 @@ void mmu_notifier_unregister(struct mmu_notifier *mn, struct mm_struct *mm)
77766 {
77767 BUG_ON(atomic_read(&mm->mm_count) <= 0);
77768
77769+ spin_lock(&mm->mmu_notifier_mm->lock);
77770 if (!hlist_unhashed(&mn->hlist)) {
77771- /*
77772- * SRCU here will force exit_mmap to wait ->release to finish
77773- * before freeing the pages.
77774- */
77775 int id;
77776
77777+ /*
77778+ * Ensure we synchronize up with __mmu_notifier_release().
77779+ */
77780 id = srcu_read_lock(&srcu);
77781- /*
77782- * exit_mmap will block in mmu_notifier_release to
77783- * guarantee ->release is called before freeing the
77784- * pages.
77785- */
77786- if (mn->ops->release)
77787- mn->ops->release(mn, mm);
77788- srcu_read_unlock(&srcu, id);
77789
77790- spin_lock(&mm->mmu_notifier_mm->lock);
77791 hlist_del_rcu(&mn->hlist);
77792 spin_unlock(&mm->mmu_notifier_mm->lock);
77793- }
77794+
77795+ if (mn->ops->release)
77796+ mn->ops->release(mn, mm);
77797+
77798+ /*
77799+ * Allow __mmu_notifier_release() to complete.
77800+ */
77801+ srcu_read_unlock(&srcu, id);
77802+ } else
77803+ spin_unlock(&mm->mmu_notifier_mm->lock);
77804
77805 /*
77806- * Wait any running method to finish, of course including
77807- * ->release if it was run by mmu_notifier_relase instead of us.
77808+ * Wait for any running method to finish, including ->release() if it
77809+ * was run by __mmu_notifier_release() instead of us.
77810 */
77811 synchronize_srcu(&srcu);
77812
77813diff --git a/mm/mprotect.c b/mm/mprotect.c
77814index 94722a4..9837984 100644
77815--- a/mm/mprotect.c
77816+++ b/mm/mprotect.c
77817@@ -23,10 +23,17 @@
77818 #include <linux/mmu_notifier.h>
77819 #include <linux/migrate.h>
77820 #include <linux/perf_event.h>
77821+
77822+#ifdef CONFIG_PAX_MPROTECT
77823+#include <linux/elf.h>
77824+#include <linux/binfmts.h>
77825+#endif
77826+
77827 #include <asm/uaccess.h>
77828 #include <asm/pgtable.h>
77829 #include <asm/cacheflush.h>
77830 #include <asm/tlbflush.h>
77831+#include <asm/mmu_context.h>
77832
77833 #ifndef pgprot_modify
77834 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
77835@@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
77836 return pages;
77837 }
77838
77839+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
77840+/* called while holding the mmap semaphor for writing except stack expansion */
77841+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
77842+{
77843+ unsigned long oldlimit, newlimit = 0UL;
77844+
77845+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
77846+ return;
77847+
77848+ spin_lock(&mm->page_table_lock);
77849+ oldlimit = mm->context.user_cs_limit;
77850+ if ((prot & VM_EXEC) && oldlimit < end)
77851+ /* USER_CS limit moved up */
77852+ newlimit = end;
77853+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
77854+ /* USER_CS limit moved down */
77855+ newlimit = start;
77856+
77857+ if (newlimit) {
77858+ mm->context.user_cs_limit = newlimit;
77859+
77860+#ifdef CONFIG_SMP
77861+ wmb();
77862+ cpus_clear(mm->context.cpu_user_cs_mask);
77863+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
77864+#endif
77865+
77866+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
77867+ }
77868+ spin_unlock(&mm->page_table_lock);
77869+ if (newlimit == end) {
77870+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
77871+
77872+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
77873+ if (is_vm_hugetlb_page(vma))
77874+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
77875+ else
77876+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
77877+ }
77878+}
77879+#endif
77880+
77881 int
77882 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77883 unsigned long start, unsigned long end, unsigned long newflags)
77884@@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77885 int error;
77886 int dirty_accountable = 0;
77887
77888+#ifdef CONFIG_PAX_SEGMEXEC
77889+ struct vm_area_struct *vma_m = NULL;
77890+ unsigned long start_m, end_m;
77891+
77892+ start_m = start + SEGMEXEC_TASK_SIZE;
77893+ end_m = end + SEGMEXEC_TASK_SIZE;
77894+#endif
77895+
77896 if (newflags == oldflags) {
77897 *pprev = vma;
77898 return 0;
77899 }
77900
77901+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
77902+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
77903+
77904+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
77905+ return -ENOMEM;
77906+
77907+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
77908+ return -ENOMEM;
77909+ }
77910+
77911 /*
77912 * If we make a private mapping writable we increase our commit;
77913 * but (without finer accounting) cannot reduce our commit if we
77914@@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77915 }
77916 }
77917
77918+#ifdef CONFIG_PAX_SEGMEXEC
77919+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
77920+ if (start != vma->vm_start) {
77921+ error = split_vma(mm, vma, start, 1);
77922+ if (error)
77923+ goto fail;
77924+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
77925+ *pprev = (*pprev)->vm_next;
77926+ }
77927+
77928+ if (end != vma->vm_end) {
77929+ error = split_vma(mm, vma, end, 0);
77930+ if (error)
77931+ goto fail;
77932+ }
77933+
77934+ if (pax_find_mirror_vma(vma)) {
77935+ error = __do_munmap(mm, start_m, end_m - start_m);
77936+ if (error)
77937+ goto fail;
77938+ } else {
77939+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77940+ if (!vma_m) {
77941+ error = -ENOMEM;
77942+ goto fail;
77943+ }
77944+ vma->vm_flags = newflags;
77945+ error = pax_mirror_vma(vma_m, vma);
77946+ if (error) {
77947+ vma->vm_flags = oldflags;
77948+ goto fail;
77949+ }
77950+ }
77951+ }
77952+#endif
77953+
77954 /*
77955 * First try to merge with previous and/or next vma.
77956 */
77957@@ -296,9 +399,21 @@ success:
77958 * vm_flags and vm_page_prot are protected by the mmap_sem
77959 * held in write mode.
77960 */
77961+
77962+#ifdef CONFIG_PAX_SEGMEXEC
77963+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
77964+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
77965+#endif
77966+
77967 vma->vm_flags = newflags;
77968+
77969+#ifdef CONFIG_PAX_MPROTECT
77970+ if (mm->binfmt && mm->binfmt->handle_mprotect)
77971+ mm->binfmt->handle_mprotect(vma, newflags);
77972+#endif
77973+
77974 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
77975- vm_get_page_prot(newflags));
77976+ vm_get_page_prot(vma->vm_flags));
77977
77978 if (vma_wants_writenotify(vma)) {
77979 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
77980@@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77981 end = start + len;
77982 if (end <= start)
77983 return -ENOMEM;
77984+
77985+#ifdef CONFIG_PAX_SEGMEXEC
77986+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
77987+ if (end > SEGMEXEC_TASK_SIZE)
77988+ return -EINVAL;
77989+ } else
77990+#endif
77991+
77992+ if (end > TASK_SIZE)
77993+ return -EINVAL;
77994+
77995 if (!arch_validate_prot(prot))
77996 return -EINVAL;
77997
77998@@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77999 /*
78000 * Does the application expect PROT_READ to imply PROT_EXEC:
78001 */
78002- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
78003+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
78004 prot |= PROT_EXEC;
78005
78006 vm_flags = calc_vm_prot_bits(prot);
78007@@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78008 if (start > vma->vm_start)
78009 prev = vma;
78010
78011+#ifdef CONFIG_PAX_MPROTECT
78012+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
78013+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
78014+#endif
78015+
78016 for (nstart = start ; ; ) {
78017 unsigned long newflags;
78018
78019@@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78020
78021 /* newflags >> 4 shift VM_MAY% in place of VM_% */
78022 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
78023+ if (prot & (PROT_WRITE | PROT_EXEC))
78024+ gr_log_rwxmprotect(vma->vm_file);
78025+
78026+ error = -EACCES;
78027+ goto out;
78028+ }
78029+
78030+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
78031 error = -EACCES;
78032 goto out;
78033 }
78034@@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78035 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
78036 if (error)
78037 goto out;
78038+
78039+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
78040+
78041 nstart = tmp;
78042
78043 if (nstart < prev->vm_end)
78044diff --git a/mm/mremap.c b/mm/mremap.c
78045index e1031e1..1f2a0a1 100644
78046--- a/mm/mremap.c
78047+++ b/mm/mremap.c
78048@@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
78049 continue;
78050 pte = ptep_get_and_clear(mm, old_addr, old_pte);
78051 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
78052+
78053+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
78054+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
78055+ pte = pte_exprotect(pte);
78056+#endif
78057+
78058 set_pte_at(mm, new_addr, new_pte, pte);
78059 }
78060
78061@@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
78062 if (is_vm_hugetlb_page(vma))
78063 goto Einval;
78064
78065+#ifdef CONFIG_PAX_SEGMEXEC
78066+ if (pax_find_mirror_vma(vma))
78067+ goto Einval;
78068+#endif
78069+
78070 /* We can't remap across vm area boundaries */
78071 if (old_len > vma->vm_end - addr)
78072 goto Efault;
78073@@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
78074 unsigned long ret = -EINVAL;
78075 unsigned long charged = 0;
78076 unsigned long map_flags;
78077+ unsigned long pax_task_size = TASK_SIZE;
78078
78079 if (new_addr & ~PAGE_MASK)
78080 goto out;
78081
78082- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
78083+#ifdef CONFIG_PAX_SEGMEXEC
78084+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
78085+ pax_task_size = SEGMEXEC_TASK_SIZE;
78086+#endif
78087+
78088+ pax_task_size -= PAGE_SIZE;
78089+
78090+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
78091 goto out;
78092
78093 /* Check if the location we're moving into overlaps the
78094 * old location at all, and fail if it does.
78095 */
78096- if ((new_addr <= addr) && (new_addr+new_len) > addr)
78097- goto out;
78098-
78099- if ((addr <= new_addr) && (addr+old_len) > new_addr)
78100+ if (addr + old_len > new_addr && new_addr + new_len > addr)
78101 goto out;
78102
78103 ret = do_munmap(mm, new_addr, new_len);
78104@@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
78105 struct vm_area_struct *vma;
78106 unsigned long ret = -EINVAL;
78107 unsigned long charged = 0;
78108+ unsigned long pax_task_size = TASK_SIZE;
78109
78110 down_write(&current->mm->mmap_sem);
78111
78112@@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
78113 if (!new_len)
78114 goto out;
78115
78116+#ifdef CONFIG_PAX_SEGMEXEC
78117+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
78118+ pax_task_size = SEGMEXEC_TASK_SIZE;
78119+#endif
78120+
78121+ pax_task_size -= PAGE_SIZE;
78122+
78123+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
78124+ old_len > pax_task_size || addr > pax_task_size-old_len)
78125+ goto out;
78126+
78127 if (flags & MREMAP_FIXED) {
78128 if (flags & MREMAP_MAYMOVE)
78129 ret = mremap_to(addr, old_len, new_addr, new_len);
78130@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
78131 addr + new_len);
78132 }
78133 ret = addr;
78134+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
78135 goto out;
78136 }
78137 }
78138@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
78139 goto out;
78140 }
78141
78142+ map_flags = vma->vm_flags;
78143 ret = move_vma(vma, addr, old_len, new_len, new_addr);
78144+ if (!(ret & ~PAGE_MASK)) {
78145+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
78146+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
78147+ }
78148 }
78149 out:
78150 if (ret & ~PAGE_MASK)
78151diff --git a/mm/nommu.c b/mm/nommu.c
78152index 79c3cac..4d357e0 100644
78153--- a/mm/nommu.c
78154+++ b/mm/nommu.c
78155@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
78156 int sysctl_overcommit_ratio = 50; /* default is 50% */
78157 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
78158 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
78159-int heap_stack_gap = 0;
78160
78161 atomic_long_t mmap_pages_allocated;
78162
78163@@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
78164 EXPORT_SYMBOL(find_vma);
78165
78166 /*
78167- * find a VMA
78168- * - we don't extend stack VMAs under NOMMU conditions
78169- */
78170-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
78171-{
78172- return find_vma(mm, addr);
78173-}
78174-
78175-/*
78176 * expand a stack to a given address
78177 * - not supported under NOMMU conditions
78178 */
78179@@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
78180
78181 /* most fields are the same, copy all, and then fixup */
78182 *new = *vma;
78183+ INIT_LIST_HEAD(&new->anon_vma_chain);
78184 *region = *vma->vm_region;
78185 new->vm_region = region;
78186
78187diff --git a/mm/page-writeback.c b/mm/page-writeback.c
78188index 0713bfb..e3774e0 100644
78189--- a/mm/page-writeback.c
78190+++ b/mm/page-writeback.c
78191@@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
78192 }
78193 }
78194
78195-static struct notifier_block __cpuinitdata ratelimit_nb = {
78196+static struct notifier_block ratelimit_nb = {
78197 .notifier_call = ratelimit_handler,
78198 .next = NULL,
78199 };
78200diff --git a/mm/page_alloc.c b/mm/page_alloc.c
78201index 6a83cd3..bc2dcb6 100644
78202--- a/mm/page_alloc.c
78203+++ b/mm/page_alloc.c
78204@@ -338,7 +338,7 @@ out:
78205 * This usage means that zero-order pages may not be compound.
78206 */
78207
78208-static void free_compound_page(struct page *page)
78209+void free_compound_page(struct page *page)
78210 {
78211 __free_pages_ok(page, compound_order(page));
78212 }
78213@@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
78214 int i;
78215 int bad = 0;
78216
78217+#ifdef CONFIG_PAX_MEMORY_SANITIZE
78218+ unsigned long index = 1UL << order;
78219+#endif
78220+
78221 trace_mm_page_free(page, order);
78222 kmemcheck_free_shadow(page, order);
78223
78224@@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
78225 debug_check_no_obj_freed(page_address(page),
78226 PAGE_SIZE << order);
78227 }
78228+
78229+#ifdef CONFIG_PAX_MEMORY_SANITIZE
78230+ for (; index; --index)
78231+ sanitize_highpage(page + index - 1);
78232+#endif
78233+
78234 arch_free_page(page, order);
78235 kernel_map_pages(page, 1 << order, 0);
78236
78237@@ -861,8 +871,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
78238 arch_alloc_page(page, order);
78239 kernel_map_pages(page, 1 << order, 1);
78240
78241+#ifndef CONFIG_PAX_MEMORY_SANITIZE
78242 if (gfp_flags & __GFP_ZERO)
78243 prep_zero_page(page, order, gfp_flags);
78244+#endif
78245
78246 if (order && (gfp_flags & __GFP_COMP))
78247 prep_compound_page(page, order);
78248@@ -3752,7 +3764,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
78249 unsigned long pfn;
78250
78251 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
78252+#ifdef CONFIG_X86_32
78253+ /* boot failures in VMware 8 on 32bit vanilla since
78254+ this change */
78255+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
78256+#else
78257 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
78258+#endif
78259 return 1;
78260 }
78261 return 0;
78262diff --git a/mm/percpu.c b/mm/percpu.c
78263index 8c8e08f..73a5cda 100644
78264--- a/mm/percpu.c
78265+++ b/mm/percpu.c
78266@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
78267 static unsigned int pcpu_high_unit_cpu __read_mostly;
78268
78269 /* the address of the first chunk which starts with the kernel static area */
78270-void *pcpu_base_addr __read_mostly;
78271+void *pcpu_base_addr __read_only;
78272 EXPORT_SYMBOL_GPL(pcpu_base_addr);
78273
78274 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
78275diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
78276index 926b466..b23df53 100644
78277--- a/mm/process_vm_access.c
78278+++ b/mm/process_vm_access.c
78279@@ -13,6 +13,7 @@
78280 #include <linux/uio.h>
78281 #include <linux/sched.h>
78282 #include <linux/highmem.h>
78283+#include <linux/security.h>
78284 #include <linux/ptrace.h>
78285 #include <linux/slab.h>
78286 #include <linux/syscalls.h>
78287@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
78288 size_t iov_l_curr_offset = 0;
78289 ssize_t iov_len;
78290
78291+ return -ENOSYS; // PaX: until properly audited
78292+
78293 /*
78294 * Work out how many pages of struct pages we're going to need
78295 * when eventually calling get_user_pages
78296 */
78297 for (i = 0; i < riovcnt; i++) {
78298 iov_len = rvec[i].iov_len;
78299- if (iov_len > 0) {
78300- nr_pages_iov = ((unsigned long)rvec[i].iov_base
78301- + iov_len)
78302- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
78303- / PAGE_SIZE + 1;
78304- nr_pages = max(nr_pages, nr_pages_iov);
78305- }
78306+ if (iov_len <= 0)
78307+ continue;
78308+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
78309+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
78310+ nr_pages = max(nr_pages, nr_pages_iov);
78311 }
78312
78313 if (nr_pages == 0)
78314@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
78315 goto free_proc_pages;
78316 }
78317
78318+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
78319+ rc = -EPERM;
78320+ goto put_task_struct;
78321+ }
78322+
78323 mm = mm_access(task, PTRACE_MODE_ATTACH);
78324 if (!mm || IS_ERR(mm)) {
78325 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
78326diff --git a/mm/rmap.c b/mm/rmap.c
78327index 2c78f8c..9e9c624 100644
78328--- a/mm/rmap.c
78329+++ b/mm/rmap.c
78330@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78331 struct anon_vma *anon_vma = vma->anon_vma;
78332 struct anon_vma_chain *avc;
78333
78334+#ifdef CONFIG_PAX_SEGMEXEC
78335+ struct anon_vma_chain *avc_m = NULL;
78336+#endif
78337+
78338 might_sleep();
78339 if (unlikely(!anon_vma)) {
78340 struct mm_struct *mm = vma->vm_mm;
78341@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78342 if (!avc)
78343 goto out_enomem;
78344
78345+#ifdef CONFIG_PAX_SEGMEXEC
78346+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
78347+ if (!avc_m)
78348+ goto out_enomem_free_avc;
78349+#endif
78350+
78351 anon_vma = find_mergeable_anon_vma(vma);
78352 allocated = NULL;
78353 if (!anon_vma) {
78354@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78355 /* page_table_lock to protect against threads */
78356 spin_lock(&mm->page_table_lock);
78357 if (likely(!vma->anon_vma)) {
78358+
78359+#ifdef CONFIG_PAX_SEGMEXEC
78360+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
78361+
78362+ if (vma_m) {
78363+ BUG_ON(vma_m->anon_vma);
78364+ vma_m->anon_vma = anon_vma;
78365+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
78366+ avc_m = NULL;
78367+ }
78368+#endif
78369+
78370 vma->anon_vma = anon_vma;
78371 anon_vma_chain_link(vma, avc, anon_vma);
78372 allocated = NULL;
78373@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78374
78375 if (unlikely(allocated))
78376 put_anon_vma(allocated);
78377+
78378+#ifdef CONFIG_PAX_SEGMEXEC
78379+ if (unlikely(avc_m))
78380+ anon_vma_chain_free(avc_m);
78381+#endif
78382+
78383 if (unlikely(avc))
78384 anon_vma_chain_free(avc);
78385 }
78386 return 0;
78387
78388 out_enomem_free_avc:
78389+
78390+#ifdef CONFIG_PAX_SEGMEXEC
78391+ if (avc_m)
78392+ anon_vma_chain_free(avc_m);
78393+#endif
78394+
78395 anon_vma_chain_free(avc);
78396 out_enomem:
78397 return -ENOMEM;
78398@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
78399 * Attach the anon_vmas from src to dst.
78400 * Returns 0 on success, -ENOMEM on failure.
78401 */
78402-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
78403+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
78404 {
78405 struct anon_vma_chain *avc, *pavc;
78406 struct anon_vma *root = NULL;
78407@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
78408 * the corresponding VMA in the parent process is attached to.
78409 * Returns 0 on success, non-zero on failure.
78410 */
78411-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
78412+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
78413 {
78414 struct anon_vma_chain *avc;
78415 struct anon_vma *anon_vma;
78416diff --git a/mm/shmem.c b/mm/shmem.c
78417index 5dd56f6..994b702 100644
78418--- a/mm/shmem.c
78419+++ b/mm/shmem.c
78420@@ -31,7 +31,7 @@
78421 #include <linux/export.h>
78422 #include <linux/swap.h>
78423
78424-static struct vfsmount *shm_mnt;
78425+struct vfsmount *shm_mnt;
78426
78427 #ifdef CONFIG_SHMEM
78428 /*
78429@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
78430 #define BOGO_DIRENT_SIZE 20
78431
78432 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
78433-#define SHORT_SYMLINK_LEN 128
78434+#define SHORT_SYMLINK_LEN 64
78435
78436 /*
78437 * shmem_fallocate and shmem_writepage communicate via inode->i_private
78438@@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
78439 static int shmem_xattr_validate(const char *name)
78440 {
78441 struct { const char *prefix; size_t len; } arr[] = {
78442+
78443+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
78444+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
78445+#endif
78446+
78447 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
78448 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
78449 };
78450@@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
78451 if (err)
78452 return err;
78453
78454+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
78455+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
78456+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
78457+ return -EOPNOTSUPP;
78458+ if (size > 8)
78459+ return -EINVAL;
78460+ }
78461+#endif
78462+
78463 return simple_xattr_set(&info->xattrs, name, value, size, flags);
78464 }
78465
78466@@ -2487,6 +2501,7 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
78467 unsigned long inodes;
78468 int error = -EINVAL;
78469
78470+ config.mpol = NULL;
78471 if (shmem_parse_options(data, &config, true))
78472 return error;
78473
78474@@ -2511,8 +2526,13 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
78475 sbinfo->max_inodes = config.max_inodes;
78476 sbinfo->free_inodes = config.max_inodes - inodes;
78477
78478- mpol_put(sbinfo->mpol);
78479- sbinfo->mpol = config.mpol; /* transfers initial ref */
78480+ /*
78481+ * Preserve previous mempolicy unless mpol remount option was specified.
78482+ */
78483+ if (config.mpol) {
78484+ mpol_put(sbinfo->mpol);
78485+ sbinfo->mpol = config.mpol; /* transfers initial ref */
78486+ }
78487 out:
78488 spin_unlock(&sbinfo->stat_lock);
78489 return error;
78490@@ -2556,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
78491 int err = -ENOMEM;
78492
78493 /* Round up to L1_CACHE_BYTES to resist false sharing */
78494- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
78495- L1_CACHE_BYTES), GFP_KERNEL);
78496+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
78497 if (!sbinfo)
78498 return -ENOMEM;
78499
78500diff --git a/mm/slab.c b/mm/slab.c
78501index e7667a3..b62c169 100644
78502--- a/mm/slab.c
78503+++ b/mm/slab.c
78504@@ -306,7 +306,7 @@ struct kmem_list3 {
78505 * Need this for bootstrapping a per node allocator.
78506 */
78507 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
78508-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
78509+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
78510 #define CACHE_CACHE 0
78511 #define SIZE_AC MAX_NUMNODES
78512 #define SIZE_L3 (2 * MAX_NUMNODES)
78513@@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
78514 if ((x)->max_freeable < i) \
78515 (x)->max_freeable = i; \
78516 } while (0)
78517-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
78518-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
78519-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
78520-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
78521+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
78522+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
78523+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
78524+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
78525 #else
78526 #define STATS_INC_ACTIVE(x) do { } while (0)
78527 #define STATS_DEC_ACTIVE(x) do { } while (0)
78528@@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
78529 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
78530 */
78531 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
78532- const struct slab *slab, void *obj)
78533+ const struct slab *slab, const void *obj)
78534 {
78535 u32 offset = (obj - slab->s_mem);
78536 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
78537@@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
78538 struct cache_names {
78539 char *name;
78540 char *name_dma;
78541+ char *name_usercopy;
78542 };
78543
78544 static struct cache_names __initdata cache_names[] = {
78545-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
78546+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
78547 #include <linux/kmalloc_sizes.h>
78548- {NULL,}
78549+ {NULL}
78550 #undef CACHE
78551 };
78552
78553@@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
78554 if (unlikely(gfpflags & GFP_DMA))
78555 return csizep->cs_dmacachep;
78556 #endif
78557+
78558+#ifdef CONFIG_PAX_USERCOPY_SLABS
78559+ if (unlikely(gfpflags & GFP_USERCOPY))
78560+ return csizep->cs_usercopycachep;
78561+#endif
78562+
78563 return csizep->cs_cachep;
78564 }
78565
78566@@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
78567 return notifier_from_errno(err);
78568 }
78569
78570-static struct notifier_block __cpuinitdata cpucache_notifier = {
78571+static struct notifier_block cpucache_notifier = {
78572 &cpuup_callback, NULL, 0
78573 };
78574
78575@@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
78576 */
78577
78578 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
78579- sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
78580+ sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78581
78582 if (INDEX_AC != INDEX_L3)
78583 sizes[INDEX_L3].cs_cachep =
78584 create_kmalloc_cache(names[INDEX_L3].name,
78585- sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
78586+ sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78587
78588 slab_early_init = 0;
78589
78590@@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
78591 */
78592 if (!sizes->cs_cachep)
78593 sizes->cs_cachep = create_kmalloc_cache(names->name,
78594- sizes->cs_size, ARCH_KMALLOC_FLAGS);
78595+ sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78596
78597 #ifdef CONFIG_ZONE_DMA
78598 sizes->cs_dmacachep = create_kmalloc_cache(
78599 names->name_dma, sizes->cs_size,
78600 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
78601 #endif
78602+
78603+#ifdef CONFIG_PAX_USERCOPY_SLABS
78604+ sizes->cs_usercopycachep = create_kmalloc_cache(
78605+ names->name_usercopy, sizes->cs_size,
78606+ ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78607+#endif
78608+
78609 sizes++;
78610 names++;
78611 }
78612@@ -4365,10 +4379,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
78613 }
78614 /* cpu stats */
78615 {
78616- unsigned long allochit = atomic_read(&cachep->allochit);
78617- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
78618- unsigned long freehit = atomic_read(&cachep->freehit);
78619- unsigned long freemiss = atomic_read(&cachep->freemiss);
78620+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
78621+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
78622+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
78623+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
78624
78625 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
78626 allochit, allocmiss, freehit, freemiss);
78627@@ -4600,13 +4614,71 @@ static const struct file_operations proc_slabstats_operations = {
78628 static int __init slab_proc_init(void)
78629 {
78630 #ifdef CONFIG_DEBUG_SLAB_LEAK
78631- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
78632+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
78633 #endif
78634 return 0;
78635 }
78636 module_init(slab_proc_init);
78637 #endif
78638
78639+bool is_usercopy_object(const void *ptr)
78640+{
78641+ struct page *page;
78642+ struct kmem_cache *cachep;
78643+
78644+ if (ZERO_OR_NULL_PTR(ptr))
78645+ return false;
78646+
78647+ if (!slab_is_available())
78648+ return false;
78649+
78650+ if (!virt_addr_valid(ptr))
78651+ return false;
78652+
78653+ page = virt_to_head_page(ptr);
78654+
78655+ if (!PageSlab(page))
78656+ return false;
78657+
78658+ cachep = page->slab_cache;
78659+ return cachep->flags & SLAB_USERCOPY;
78660+}
78661+
78662+#ifdef CONFIG_PAX_USERCOPY
78663+const char *check_heap_object(const void *ptr, unsigned long n)
78664+{
78665+ struct page *page;
78666+ struct kmem_cache *cachep;
78667+ struct slab *slabp;
78668+ unsigned int objnr;
78669+ unsigned long offset;
78670+
78671+ if (ZERO_OR_NULL_PTR(ptr))
78672+ return "<null>";
78673+
78674+ if (!virt_addr_valid(ptr))
78675+ return NULL;
78676+
78677+ page = virt_to_head_page(ptr);
78678+
78679+ if (!PageSlab(page))
78680+ return NULL;
78681+
78682+ cachep = page->slab_cache;
78683+ if (!(cachep->flags & SLAB_USERCOPY))
78684+ return cachep->name;
78685+
78686+ slabp = page->slab_page;
78687+ objnr = obj_to_index(cachep, slabp, ptr);
78688+ BUG_ON(objnr >= cachep->num);
78689+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
78690+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
78691+ return NULL;
78692+
78693+ return cachep->name;
78694+}
78695+#endif
78696+
78697 /**
78698 * ksize - get the actual amount of memory allocated for a given object
78699 * @objp: Pointer to the object
78700diff --git a/mm/slab.h b/mm/slab.h
78701index 34a98d6..73633d1 100644
78702--- a/mm/slab.h
78703+++ b/mm/slab.h
78704@@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
78705
78706 /* Legal flag mask for kmem_cache_create(), for various configurations */
78707 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
78708- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
78709+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
78710
78711 #if defined(CONFIG_DEBUG_SLAB)
78712 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
78713@@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
78714 return s;
78715
78716 page = virt_to_head_page(x);
78717+
78718+ BUG_ON(!PageSlab(page));
78719+
78720 cachep = page->slab_cache;
78721 if (slab_equal_or_root(cachep, s))
78722 return cachep;
78723diff --git a/mm/slab_common.c b/mm/slab_common.c
78724index 3f3cd97..e050794 100644
78725--- a/mm/slab_common.c
78726+++ b/mm/slab_common.c
78727@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
78728
78729 err = __kmem_cache_create(s, flags);
78730 if (!err) {
78731- s->refcount = 1;
78732+ atomic_set(&s->refcount, 1);
78733 list_add(&s->list, &slab_caches);
78734 memcg_cache_list_add(memcg, s);
78735 } else {
78736@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
78737
78738 get_online_cpus();
78739 mutex_lock(&slab_mutex);
78740- s->refcount--;
78741- if (!s->refcount) {
78742+ if (atomic_dec_and_test(&s->refcount)) {
78743 list_del(&s->list);
78744
78745 if (!__kmem_cache_shutdown(s)) {
78746@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
78747 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
78748 name, size, err);
78749
78750- s->refcount = -1; /* Exempt from merging for now */
78751+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
78752 }
78753
78754 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
78755@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
78756
78757 create_boot_cache(s, name, size, flags);
78758 list_add(&s->list, &slab_caches);
78759- s->refcount = 1;
78760+ atomic_set(&s->refcount, 1);
78761 return s;
78762 }
78763
78764diff --git a/mm/slob.c b/mm/slob.c
78765index a99fdf7..f5b6577 100644
78766--- a/mm/slob.c
78767+++ b/mm/slob.c
78768@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
78769 /*
78770 * Return the size of a slob block.
78771 */
78772-static slobidx_t slob_units(slob_t *s)
78773+static slobidx_t slob_units(const slob_t *s)
78774 {
78775 if (s->units > 0)
78776 return s->units;
78777@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
78778 /*
78779 * Return the next free slob block pointer after this one.
78780 */
78781-static slob_t *slob_next(slob_t *s)
78782+static slob_t *slob_next(const slob_t *s)
78783 {
78784 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
78785 slobidx_t next;
78786@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
78787 /*
78788 * Returns true if s is the last free block in its page.
78789 */
78790-static int slob_last(slob_t *s)
78791+static int slob_last(const slob_t *s)
78792 {
78793 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
78794 }
78795
78796-static void *slob_new_pages(gfp_t gfp, int order, int node)
78797+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
78798 {
78799- void *page;
78800+ struct page *page;
78801
78802 #ifdef CONFIG_NUMA
78803 if (node != NUMA_NO_NODE)
78804@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
78805 if (!page)
78806 return NULL;
78807
78808- return page_address(page);
78809+ __SetPageSlab(page);
78810+ return page;
78811 }
78812
78813-static void slob_free_pages(void *b, int order)
78814+static void slob_free_pages(struct page *sp, int order)
78815 {
78816 if (current->reclaim_state)
78817 current->reclaim_state->reclaimed_slab += 1 << order;
78818- free_pages((unsigned long)b, order);
78819+ __ClearPageSlab(sp);
78820+ reset_page_mapcount(sp);
78821+ sp->private = 0;
78822+ __free_pages(sp, order);
78823 }
78824
78825 /*
78826@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
78827
78828 /* Not enough space: must allocate a new page */
78829 if (!b) {
78830- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
78831- if (!b)
78832+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
78833+ if (!sp)
78834 return NULL;
78835- sp = virt_to_page(b);
78836- __SetPageSlab(sp);
78837+ b = page_address(sp);
78838
78839 spin_lock_irqsave(&slob_lock, flags);
78840 sp->units = SLOB_UNITS(PAGE_SIZE);
78841 sp->freelist = b;
78842+ sp->private = 0;
78843 INIT_LIST_HEAD(&sp->list);
78844 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
78845 set_slob_page_free(sp, slob_list);
78846@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
78847 if (slob_page_free(sp))
78848 clear_slob_page_free(sp);
78849 spin_unlock_irqrestore(&slob_lock, flags);
78850- __ClearPageSlab(sp);
78851- reset_page_mapcount(sp);
78852- slob_free_pages(b, 0);
78853+ slob_free_pages(sp, 0);
78854 return;
78855 }
78856
78857@@ -424,11 +426,10 @@ out:
78858 */
78859
78860 static __always_inline void *
78861-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78862+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
78863 {
78864- unsigned int *m;
78865- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78866- void *ret;
78867+ slob_t *m;
78868+ void *ret = NULL;
78869
78870 gfp &= gfp_allowed_mask;
78871
78872@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78873
78874 if (!m)
78875 return NULL;
78876- *m = size;
78877+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
78878+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
78879+ m[0].units = size;
78880+ m[1].units = align;
78881 ret = (void *)m + align;
78882
78883 trace_kmalloc_node(caller, ret,
78884 size, size + align, gfp, node);
78885 } else {
78886 unsigned int order = get_order(size);
78887+ struct page *page;
78888
78889 if (likely(order))
78890 gfp |= __GFP_COMP;
78891- ret = slob_new_pages(gfp, order, node);
78892+ page = slob_new_pages(gfp, order, node);
78893+ if (page) {
78894+ ret = page_address(page);
78895+ page->private = size;
78896+ }
78897
78898 trace_kmalloc_node(caller, ret,
78899 size, PAGE_SIZE << order, gfp, node);
78900 }
78901
78902- kmemleak_alloc(ret, size, 1, gfp);
78903+ return ret;
78904+}
78905+
78906+static __always_inline void *
78907+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78908+{
78909+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78910+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
78911+
78912+ if (!ZERO_OR_NULL_PTR(ret))
78913+ kmemleak_alloc(ret, size, 1, gfp);
78914 return ret;
78915 }
78916
78917@@ -494,33 +513,110 @@ void kfree(const void *block)
78918 kmemleak_free(block);
78919
78920 sp = virt_to_page(block);
78921- if (PageSlab(sp)) {
78922+ VM_BUG_ON(!PageSlab(sp));
78923+ if (!sp->private) {
78924 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78925- unsigned int *m = (unsigned int *)(block - align);
78926- slob_free(m, *m + align);
78927- } else
78928+ slob_t *m = (slob_t *)(block - align);
78929+ slob_free(m, m[0].units + align);
78930+ } else {
78931+ __ClearPageSlab(sp);
78932+ reset_page_mapcount(sp);
78933+ sp->private = 0;
78934 __free_pages(sp, compound_order(sp));
78935+ }
78936 }
78937 EXPORT_SYMBOL(kfree);
78938
78939+bool is_usercopy_object(const void *ptr)
78940+{
78941+ if (!slab_is_available())
78942+ return false;
78943+
78944+ // PAX: TODO
78945+
78946+ return false;
78947+}
78948+
78949+#ifdef CONFIG_PAX_USERCOPY
78950+const char *check_heap_object(const void *ptr, unsigned long n)
78951+{
78952+ struct page *page;
78953+ const slob_t *free;
78954+ const void *base;
78955+ unsigned long flags;
78956+
78957+ if (ZERO_OR_NULL_PTR(ptr))
78958+ return "<null>";
78959+
78960+ if (!virt_addr_valid(ptr))
78961+ return NULL;
78962+
78963+ page = virt_to_head_page(ptr);
78964+ if (!PageSlab(page))
78965+ return NULL;
78966+
78967+ if (page->private) {
78968+ base = page;
78969+ if (base <= ptr && n <= page->private - (ptr - base))
78970+ return NULL;
78971+ return "<slob>";
78972+ }
78973+
78974+ /* some tricky double walking to find the chunk */
78975+ spin_lock_irqsave(&slob_lock, flags);
78976+ base = (void *)((unsigned long)ptr & PAGE_MASK);
78977+ free = page->freelist;
78978+
78979+ while (!slob_last(free) && (void *)free <= ptr) {
78980+ base = free + slob_units(free);
78981+ free = slob_next(free);
78982+ }
78983+
78984+ while (base < (void *)free) {
78985+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
78986+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
78987+ int offset;
78988+
78989+ if (ptr < base + align)
78990+ break;
78991+
78992+ offset = ptr - base - align;
78993+ if (offset >= m) {
78994+ base += size;
78995+ continue;
78996+ }
78997+
78998+ if (n > m - offset)
78999+ break;
79000+
79001+ spin_unlock_irqrestore(&slob_lock, flags);
79002+ return NULL;
79003+ }
79004+
79005+ spin_unlock_irqrestore(&slob_lock, flags);
79006+ return "<slob>";
79007+}
79008+#endif
79009+
79010 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
79011 size_t ksize(const void *block)
79012 {
79013 struct page *sp;
79014 int align;
79015- unsigned int *m;
79016+ slob_t *m;
79017
79018 BUG_ON(!block);
79019 if (unlikely(block == ZERO_SIZE_PTR))
79020 return 0;
79021
79022 sp = virt_to_page(block);
79023- if (unlikely(!PageSlab(sp)))
79024- return PAGE_SIZE << compound_order(sp);
79025+ VM_BUG_ON(!PageSlab(sp));
79026+ if (sp->private)
79027+ return sp->private;
79028
79029 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
79030- m = (unsigned int *)(block - align);
79031- return SLOB_UNITS(*m) * SLOB_UNIT;
79032+ m = (slob_t *)(block - align);
79033+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
79034 }
79035 EXPORT_SYMBOL(ksize);
79036
79037@@ -536,23 +632,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
79038
79039 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
79040 {
79041- void *b;
79042+ void *b = NULL;
79043
79044 flags &= gfp_allowed_mask;
79045
79046 lockdep_trace_alloc(flags);
79047
79048+#ifdef CONFIG_PAX_USERCOPY_SLABS
79049+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
79050+#else
79051 if (c->size < PAGE_SIZE) {
79052 b = slob_alloc(c->size, flags, c->align, node);
79053 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
79054 SLOB_UNITS(c->size) * SLOB_UNIT,
79055 flags, node);
79056 } else {
79057- b = slob_new_pages(flags, get_order(c->size), node);
79058+ struct page *sp;
79059+
79060+ sp = slob_new_pages(flags, get_order(c->size), node);
79061+ if (sp) {
79062+ b = page_address(sp);
79063+ sp->private = c->size;
79064+ }
79065 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
79066 PAGE_SIZE << get_order(c->size),
79067 flags, node);
79068 }
79069+#endif
79070
79071 if (c->ctor)
79072 c->ctor(b);
79073@@ -564,10 +670,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
79074
79075 static void __kmem_cache_free(void *b, int size)
79076 {
79077- if (size < PAGE_SIZE)
79078+ struct page *sp;
79079+
79080+ sp = virt_to_page(b);
79081+ BUG_ON(!PageSlab(sp));
79082+ if (!sp->private)
79083 slob_free(b, size);
79084 else
79085- slob_free_pages(b, get_order(size));
79086+ slob_free_pages(sp, get_order(size));
79087 }
79088
79089 static void kmem_rcu_free(struct rcu_head *head)
79090@@ -580,17 +690,31 @@ static void kmem_rcu_free(struct rcu_head *head)
79091
79092 void kmem_cache_free(struct kmem_cache *c, void *b)
79093 {
79094+ int size = c->size;
79095+
79096+#ifdef CONFIG_PAX_USERCOPY_SLABS
79097+ if (size + c->align < PAGE_SIZE) {
79098+ size += c->align;
79099+ b -= c->align;
79100+ }
79101+#endif
79102+
79103 kmemleak_free_recursive(b, c->flags);
79104 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
79105 struct slob_rcu *slob_rcu;
79106- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
79107- slob_rcu->size = c->size;
79108+ slob_rcu = b + (size - sizeof(struct slob_rcu));
79109+ slob_rcu->size = size;
79110 call_rcu(&slob_rcu->head, kmem_rcu_free);
79111 } else {
79112- __kmem_cache_free(b, c->size);
79113+ __kmem_cache_free(b, size);
79114 }
79115
79116+#ifdef CONFIG_PAX_USERCOPY_SLABS
79117+ trace_kfree(_RET_IP_, b);
79118+#else
79119 trace_kmem_cache_free(_RET_IP_, b);
79120+#endif
79121+
79122 }
79123 EXPORT_SYMBOL(kmem_cache_free);
79124
79125diff --git a/mm/slub.c b/mm/slub.c
79126index ba2ca53..00b1f4e 100644
79127--- a/mm/slub.c
79128+++ b/mm/slub.c
79129@@ -197,7 +197,7 @@ struct track {
79130
79131 enum track_item { TRACK_ALLOC, TRACK_FREE };
79132
79133-#ifdef CONFIG_SYSFS
79134+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79135 static int sysfs_slab_add(struct kmem_cache *);
79136 static int sysfs_slab_alias(struct kmem_cache *, const char *);
79137 static void sysfs_slab_remove(struct kmem_cache *);
79138@@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
79139 if (!t->addr)
79140 return;
79141
79142- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
79143+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
79144 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
79145 #ifdef CONFIG_STACKTRACE
79146 {
79147@@ -2653,7 +2653,7 @@ static int slub_min_objects;
79148 * Merge control. If this is set then no merging of slab caches will occur.
79149 * (Could be removed. This was introduced to pacify the merge skeptics.)
79150 */
79151-static int slub_nomerge;
79152+static int slub_nomerge = 1;
79153
79154 /*
79155 * Calculate the order of allocation given an slab object size.
79156@@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
79157 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
79158 #endif
79159
79160+#ifdef CONFIG_PAX_USERCOPY_SLABS
79161+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
79162+#endif
79163+
79164 static int __init setup_slub_min_order(char *str)
79165 {
79166 get_option(&str, &slub_min_order);
79167@@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
79168 return kmalloc_dma_caches[index];
79169
79170 #endif
79171+
79172+#ifdef CONFIG_PAX_USERCOPY_SLABS
79173+ if (flags & SLAB_USERCOPY)
79174+ return kmalloc_usercopy_caches[index];
79175+
79176+#endif
79177+
79178 return kmalloc_caches[index];
79179 }
79180
79181@@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
79182 EXPORT_SYMBOL(__kmalloc_node);
79183 #endif
79184
79185+bool is_usercopy_object(const void *ptr)
79186+{
79187+ struct page *page;
79188+ struct kmem_cache *s;
79189+
79190+ if (ZERO_OR_NULL_PTR(ptr))
79191+ return false;
79192+
79193+ if (!slab_is_available())
79194+ return false;
79195+
79196+ if (!virt_addr_valid(ptr))
79197+ return false;
79198+
79199+ page = virt_to_head_page(ptr);
79200+
79201+ if (!PageSlab(page))
79202+ return false;
79203+
79204+ s = page->slab_cache;
79205+ return s->flags & SLAB_USERCOPY;
79206+}
79207+
79208+#ifdef CONFIG_PAX_USERCOPY
79209+const char *check_heap_object(const void *ptr, unsigned long n)
79210+{
79211+ struct page *page;
79212+ struct kmem_cache *s;
79213+ unsigned long offset;
79214+
79215+ if (ZERO_OR_NULL_PTR(ptr))
79216+ return "<null>";
79217+
79218+ if (!virt_addr_valid(ptr))
79219+ return NULL;
79220+
79221+ page = virt_to_head_page(ptr);
79222+
79223+ if (!PageSlab(page))
79224+ return NULL;
79225+
79226+ s = page->slab_cache;
79227+ if (!(s->flags & SLAB_USERCOPY))
79228+ return s->name;
79229+
79230+ offset = (ptr - page_address(page)) % s->size;
79231+ if (offset <= s->object_size && n <= s->object_size - offset)
79232+ return NULL;
79233+
79234+ return s->name;
79235+}
79236+#endif
79237+
79238 size_t ksize(const void *object)
79239 {
79240 struct page *page;
79241@@ -3712,17 +3776,17 @@ void __init kmem_cache_init(void)
79242
79243 /* Caches that are not of the two-to-the-power-of size */
79244 if (KMALLOC_MIN_SIZE <= 32) {
79245- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
79246+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
79247 caches++;
79248 }
79249
79250 if (KMALLOC_MIN_SIZE <= 64) {
79251- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
79252+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
79253 caches++;
79254 }
79255
79256 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
79257- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
79258+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
79259 caches++;
79260 }
79261
79262@@ -3764,6 +3828,22 @@ void __init kmem_cache_init(void)
79263 }
79264 }
79265 #endif
79266+
79267+#ifdef CONFIG_PAX_USERCOPY_SLABS
79268+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
79269+ struct kmem_cache *s = kmalloc_caches[i];
79270+
79271+ if (s && s->size) {
79272+ char *name = kasprintf(GFP_NOWAIT,
79273+ "usercopy-kmalloc-%d", s->object_size);
79274+
79275+ BUG_ON(!name);
79276+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
79277+ s->object_size, SLAB_USERCOPY);
79278+ }
79279+ }
79280+#endif
79281+
79282 printk(KERN_INFO
79283 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
79284 " CPUs=%d, Nodes=%d\n",
79285@@ -3790,7 +3870,7 @@ static int slab_unmergeable(struct kmem_cache *s)
79286 /*
79287 * We may have set a slab to be unmergeable during bootstrap.
79288 */
79289- if (s->refcount < 0)
79290+ if (atomic_read(&s->refcount) < 0)
79291 return 1;
79292
79293 return 0;
79294@@ -3848,7 +3928,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
79295
79296 s = find_mergeable(memcg, size, align, flags, name, ctor);
79297 if (s) {
79298- s->refcount++;
79299+ atomic_inc(&s->refcount);
79300 /*
79301 * Adjust the object sizes so that we clear
79302 * the complete object on kzalloc.
79303@@ -3857,7 +3937,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
79304 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
79305
79306 if (sysfs_slab_alias(s, name)) {
79307- s->refcount--;
79308+ atomic_dec(&s->refcount);
79309 s = NULL;
79310 }
79311 }
79312@@ -3919,7 +3999,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
79313 return NOTIFY_OK;
79314 }
79315
79316-static struct notifier_block __cpuinitdata slab_notifier = {
79317+static struct notifier_block slab_notifier = {
79318 .notifier_call = slab_cpuup_callback
79319 };
79320
79321@@ -3977,7 +4057,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
79322 }
79323 #endif
79324
79325-#ifdef CONFIG_SYSFS
79326+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79327 static int count_inuse(struct page *page)
79328 {
79329 return page->inuse;
79330@@ -4364,12 +4444,12 @@ static void resiliency_test(void)
79331 validate_slab_cache(kmalloc_caches[9]);
79332 }
79333 #else
79334-#ifdef CONFIG_SYSFS
79335+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79336 static void resiliency_test(void) {};
79337 #endif
79338 #endif
79339
79340-#ifdef CONFIG_SYSFS
79341+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79342 enum slab_stat_type {
79343 SL_ALL, /* All slabs */
79344 SL_PARTIAL, /* Only partially allocated slabs */
79345@@ -4613,7 +4693,7 @@ SLAB_ATTR_RO(ctor);
79346
79347 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
79348 {
79349- return sprintf(buf, "%d\n", s->refcount - 1);
79350+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
79351 }
79352 SLAB_ATTR_RO(aliases);
79353
79354@@ -5266,6 +5346,7 @@ static char *create_unique_id(struct kmem_cache *s)
79355 return name;
79356 }
79357
79358+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79359 static int sysfs_slab_add(struct kmem_cache *s)
79360 {
79361 int err;
79362@@ -5323,6 +5404,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
79363 kobject_del(&s->kobj);
79364 kobject_put(&s->kobj);
79365 }
79366+#endif
79367
79368 /*
79369 * Need to buffer aliases during bootup until sysfs becomes
79370@@ -5336,6 +5418,7 @@ struct saved_alias {
79371
79372 static struct saved_alias *alias_list;
79373
79374+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79375 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
79376 {
79377 struct saved_alias *al;
79378@@ -5358,6 +5441,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
79379 alias_list = al;
79380 return 0;
79381 }
79382+#endif
79383
79384 static int __init slab_sysfs_init(void)
79385 {
79386diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
79387index 1b7e22a..3fcd4f3 100644
79388--- a/mm/sparse-vmemmap.c
79389+++ b/mm/sparse-vmemmap.c
79390@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
79391 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
79392 if (!p)
79393 return NULL;
79394- pud_populate(&init_mm, pud, p);
79395+ pud_populate_kernel(&init_mm, pud, p);
79396 }
79397 return pud;
79398 }
79399@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
79400 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
79401 if (!p)
79402 return NULL;
79403- pgd_populate(&init_mm, pgd, p);
79404+ pgd_populate_kernel(&init_mm, pgd, p);
79405 }
79406 return pgd;
79407 }
79408diff --git a/mm/sparse.c b/mm/sparse.c
79409index 6b5fb76..db0c190 100644
79410--- a/mm/sparse.c
79411+++ b/mm/sparse.c
79412@@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
79413
79414 for (i = 0; i < PAGES_PER_SECTION; i++) {
79415 if (PageHWPoison(&memmap[i])) {
79416- atomic_long_sub(1, &mce_bad_pages);
79417+ atomic_long_sub_unchecked(1, &mce_bad_pages);
79418 ClearPageHWPoison(&memmap[i]);
79419 }
79420 }
79421diff --git a/mm/swap.c b/mm/swap.c
79422index 6310dc2..3662b3f 100644
79423--- a/mm/swap.c
79424+++ b/mm/swap.c
79425@@ -30,6 +30,7 @@
79426 #include <linux/backing-dev.h>
79427 #include <linux/memcontrol.h>
79428 #include <linux/gfp.h>
79429+#include <linux/hugetlb.h>
79430
79431 #include "internal.h"
79432
79433@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
79434
79435 __page_cache_release(page);
79436 dtor = get_compound_page_dtor(page);
79437+ if (!PageHuge(page))
79438+ BUG_ON(dtor != free_compound_page);
79439 (*dtor)(page);
79440 }
79441
79442diff --git a/mm/swapfile.c b/mm/swapfile.c
79443index e97a0e5..b50e796 100644
79444--- a/mm/swapfile.c
79445+++ b/mm/swapfile.c
79446@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
79447
79448 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
79449 /* Activity counter to indicate that a swapon or swapoff has occurred */
79450-static atomic_t proc_poll_event = ATOMIC_INIT(0);
79451+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
79452
79453 static inline unsigned char swap_count(unsigned char ent)
79454 {
79455@@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
79456 }
79457 filp_close(swap_file, NULL);
79458 err = 0;
79459- atomic_inc(&proc_poll_event);
79460+ atomic_inc_unchecked(&proc_poll_event);
79461 wake_up_interruptible(&proc_poll_wait);
79462
79463 out_dput:
79464@@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
79465
79466 poll_wait(file, &proc_poll_wait, wait);
79467
79468- if (seq->poll_event != atomic_read(&proc_poll_event)) {
79469- seq->poll_event = atomic_read(&proc_poll_event);
79470+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
79471+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
79472 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
79473 }
79474
79475@@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
79476 return ret;
79477
79478 seq = file->private_data;
79479- seq->poll_event = atomic_read(&proc_poll_event);
79480+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
79481 return 0;
79482 }
79483
79484@@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
79485 (frontswap_map) ? "FS" : "");
79486
79487 mutex_unlock(&swapon_mutex);
79488- atomic_inc(&proc_poll_event);
79489+ atomic_inc_unchecked(&proc_poll_event);
79490 wake_up_interruptible(&proc_poll_wait);
79491
79492 if (S_ISREG(inode->i_mode))
79493diff --git a/mm/util.c b/mm/util.c
79494index c55e26b..3f913a9 100644
79495--- a/mm/util.c
79496+++ b/mm/util.c
79497@@ -292,6 +292,12 @@ done:
79498 void arch_pick_mmap_layout(struct mm_struct *mm)
79499 {
79500 mm->mmap_base = TASK_UNMAPPED_BASE;
79501+
79502+#ifdef CONFIG_PAX_RANDMMAP
79503+ if (mm->pax_flags & MF_PAX_RANDMMAP)
79504+ mm->mmap_base += mm->delta_mmap;
79505+#endif
79506+
79507 mm->get_unmapped_area = arch_get_unmapped_area;
79508 mm->unmap_area = arch_unmap_area;
79509 }
79510diff --git a/mm/vmalloc.c b/mm/vmalloc.c
79511index 5123a16..f234a48 100644
79512--- a/mm/vmalloc.c
79513+++ b/mm/vmalloc.c
79514@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
79515
79516 pte = pte_offset_kernel(pmd, addr);
79517 do {
79518- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79519- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79520+
79521+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79522+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
79523+ BUG_ON(!pte_exec(*pte));
79524+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
79525+ continue;
79526+ }
79527+#endif
79528+
79529+ {
79530+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79531+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79532+ }
79533 } while (pte++, addr += PAGE_SIZE, addr != end);
79534 }
79535
79536@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
79537 pte = pte_alloc_kernel(pmd, addr);
79538 if (!pte)
79539 return -ENOMEM;
79540+
79541+ pax_open_kernel();
79542 do {
79543 struct page *page = pages[*nr];
79544
79545- if (WARN_ON(!pte_none(*pte)))
79546+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79547+ if (pgprot_val(prot) & _PAGE_NX)
79548+#endif
79549+
79550+ if (!pte_none(*pte)) {
79551+ pax_close_kernel();
79552+ WARN_ON(1);
79553 return -EBUSY;
79554- if (WARN_ON(!page))
79555+ }
79556+ if (!page) {
79557+ pax_close_kernel();
79558+ WARN_ON(1);
79559 return -ENOMEM;
79560+ }
79561 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
79562 (*nr)++;
79563 } while (pte++, addr += PAGE_SIZE, addr != end);
79564+ pax_close_kernel();
79565 return 0;
79566 }
79567
79568@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
79569 pmd_t *pmd;
79570 unsigned long next;
79571
79572- pmd = pmd_alloc(&init_mm, pud, addr);
79573+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
79574 if (!pmd)
79575 return -ENOMEM;
79576 do {
79577@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
79578 pud_t *pud;
79579 unsigned long next;
79580
79581- pud = pud_alloc(&init_mm, pgd, addr);
79582+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
79583 if (!pud)
79584 return -ENOMEM;
79585 do {
79586@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
79587 * and fall back on vmalloc() if that fails. Others
79588 * just put it in the vmalloc space.
79589 */
79590-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
79591+#ifdef CONFIG_MODULES
79592+#ifdef MODULES_VADDR
79593 unsigned long addr = (unsigned long)x;
79594 if (addr >= MODULES_VADDR && addr < MODULES_END)
79595 return 1;
79596 #endif
79597+
79598+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79599+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
79600+ return 1;
79601+#endif
79602+
79603+#endif
79604+
79605 return is_vmalloc_addr(x);
79606 }
79607
79608@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
79609
79610 if (!pgd_none(*pgd)) {
79611 pud_t *pud = pud_offset(pgd, addr);
79612+#ifdef CONFIG_X86
79613+ if (!pud_large(*pud))
79614+#endif
79615 if (!pud_none(*pud)) {
79616 pmd_t *pmd = pmd_offset(pud, addr);
79617+#ifdef CONFIG_X86
79618+ if (!pmd_large(*pmd))
79619+#endif
79620 if (!pmd_none(*pmd)) {
79621 pte_t *ptep, pte;
79622
79623@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
79624 * Allocate a region of KVA of the specified size and alignment, within the
79625 * vstart and vend.
79626 */
79627-static struct vmap_area *alloc_vmap_area(unsigned long size,
79628+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
79629 unsigned long align,
79630 unsigned long vstart, unsigned long vend,
79631 int node, gfp_t gfp_mask)
79632@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
79633 struct vm_struct *area;
79634
79635 BUG_ON(in_interrupt());
79636+
79637+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79638+ if (flags & VM_KERNEXEC) {
79639+ if (start != VMALLOC_START || end != VMALLOC_END)
79640+ return NULL;
79641+ start = (unsigned long)MODULES_EXEC_VADDR;
79642+ end = (unsigned long)MODULES_EXEC_END;
79643+ }
79644+#endif
79645+
79646 if (flags & VM_IOREMAP) {
79647 int bit = fls(size);
79648
79649@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
79650 if (count > totalram_pages)
79651 return NULL;
79652
79653+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79654+ if (!(pgprot_val(prot) & _PAGE_NX))
79655+ flags |= VM_KERNEXEC;
79656+#endif
79657+
79658 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
79659 __builtin_return_address(0));
79660 if (!area)
79661@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
79662 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
79663 goto fail;
79664
79665+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79666+ if (!(pgprot_val(prot) & _PAGE_NX))
79667+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
79668+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
79669+ else
79670+#endif
79671+
79672 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
79673 start, end, node, gfp_mask, caller);
79674 if (!area)
79675@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
79676 * For tight control over page level allocator and protection flags
79677 * use __vmalloc() instead.
79678 */
79679-
79680 void *vmalloc_exec(unsigned long size)
79681 {
79682- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
79683+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
79684 -1, __builtin_return_address(0));
79685 }
79686
79687@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
79688 unsigned long uaddr = vma->vm_start;
79689 unsigned long usize = vma->vm_end - vma->vm_start;
79690
79691+ BUG_ON(vma->vm_mirror);
79692+
79693 if ((PAGE_SIZE-1) & (unsigned long)addr)
79694 return -EINVAL;
79695
79696@@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
79697 v->addr, v->addr + v->size, v->size);
79698
79699 if (v->caller)
79700+#ifdef CONFIG_GRKERNSEC_HIDESYM
79701+ seq_printf(m, " %pK", v->caller);
79702+#else
79703 seq_printf(m, " %pS", v->caller);
79704+#endif
79705
79706 if (v->nr_pages)
79707 seq_printf(m, " pages=%d", v->nr_pages);
79708diff --git a/mm/vmstat.c b/mm/vmstat.c
79709index 9800306..76b4b27 100644
79710--- a/mm/vmstat.c
79711+++ b/mm/vmstat.c
79712@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
79713 *
79714 * vm_stat contains the global counters
79715 */
79716-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
79717+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
79718 EXPORT_SYMBOL(vm_stat);
79719
79720 #ifdef CONFIG_SMP
79721@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
79722 v = p->vm_stat_diff[i];
79723 p->vm_stat_diff[i] = 0;
79724 local_irq_restore(flags);
79725- atomic_long_add(v, &zone->vm_stat[i]);
79726+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
79727 global_diff[i] += v;
79728 #ifdef CONFIG_NUMA
79729 /* 3 seconds idle till flush */
79730@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
79731
79732 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
79733 if (global_diff[i])
79734- atomic_long_add(global_diff[i], &vm_stat[i]);
79735+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
79736 }
79737
79738 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
79739@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
79740 if (pset->vm_stat_diff[i]) {
79741 int v = pset->vm_stat_diff[i];
79742 pset->vm_stat_diff[i] = 0;
79743- atomic_long_add(v, &zone->vm_stat[i]);
79744- atomic_long_add(v, &vm_stat[i]);
79745+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
79746+ atomic_long_add_unchecked(v, &vm_stat[i]);
79747 }
79748 }
79749 #endif
79750@@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
79751 return NOTIFY_OK;
79752 }
79753
79754-static struct notifier_block __cpuinitdata vmstat_notifier =
79755+static struct notifier_block vmstat_notifier =
79756 { &vmstat_cpuup_callback, NULL, 0 };
79757 #endif
79758
79759@@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
79760 start_cpu_timer(cpu);
79761 #endif
79762 #ifdef CONFIG_PROC_FS
79763- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
79764- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
79765- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
79766- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
79767+ {
79768+ mode_t gr_mode = S_IRUGO;
79769+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79770+ gr_mode = S_IRUSR;
79771+#endif
79772+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
79773+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
79774+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79775+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
79776+#else
79777+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
79778+#endif
79779+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
79780+ }
79781 #endif
79782 return 0;
79783 }
79784diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
79785index a292e80..785ee68 100644
79786--- a/net/8021q/vlan.c
79787+++ b/net/8021q/vlan.c
79788@@ -485,7 +485,7 @@ out:
79789 return NOTIFY_DONE;
79790 }
79791
79792-static struct notifier_block vlan_notifier_block __read_mostly = {
79793+static struct notifier_block vlan_notifier_block = {
79794 .notifier_call = vlan_device_event,
79795 };
79796
79797@@ -560,8 +560,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
79798 err = -EPERM;
79799 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
79800 break;
79801- if ((args.u.name_type >= 0) &&
79802- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
79803+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
79804 struct vlan_net *vn;
79805
79806 vn = net_generic(net, vlan_net_id);
79807diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
79808index 02efb25..41541a9 100644
79809--- a/net/9p/trans_fd.c
79810+++ b/net/9p/trans_fd.c
79811@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
79812 oldfs = get_fs();
79813 set_fs(get_ds());
79814 /* The cast to a user pointer is valid due to the set_fs() */
79815- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
79816+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
79817 set_fs(oldfs);
79818
79819 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
79820diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
79821index 876fbe8..8bbea9f 100644
79822--- a/net/atm/atm_misc.c
79823+++ b/net/atm/atm_misc.c
79824@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
79825 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
79826 return 1;
79827 atm_return(vcc, truesize);
79828- atomic_inc(&vcc->stats->rx_drop);
79829+ atomic_inc_unchecked(&vcc->stats->rx_drop);
79830 return 0;
79831 }
79832 EXPORT_SYMBOL(atm_charge);
79833@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
79834 }
79835 }
79836 atm_return(vcc, guess);
79837- atomic_inc(&vcc->stats->rx_drop);
79838+ atomic_inc_unchecked(&vcc->stats->rx_drop);
79839 return NULL;
79840 }
79841 EXPORT_SYMBOL(atm_alloc_charge);
79842@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
79843
79844 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
79845 {
79846-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79847+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79848 __SONET_ITEMS
79849 #undef __HANDLE_ITEM
79850 }
79851@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
79852
79853 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
79854 {
79855-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
79856+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
79857 __SONET_ITEMS
79858 #undef __HANDLE_ITEM
79859 }
79860diff --git a/net/atm/lec.h b/net/atm/lec.h
79861index a86aff9..3a0d6f6 100644
79862--- a/net/atm/lec.h
79863+++ b/net/atm/lec.h
79864@@ -48,7 +48,7 @@ struct lane2_ops {
79865 const u8 *tlvs, u32 sizeoftlvs);
79866 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
79867 const u8 *tlvs, u32 sizeoftlvs);
79868-};
79869+} __no_const;
79870
79871 /*
79872 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
79873diff --git a/net/atm/proc.c b/net/atm/proc.c
79874index 0d020de..011c7bb 100644
79875--- a/net/atm/proc.c
79876+++ b/net/atm/proc.c
79877@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
79878 const struct k_atm_aal_stats *stats)
79879 {
79880 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
79881- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
79882- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
79883- atomic_read(&stats->rx_drop));
79884+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
79885+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
79886+ atomic_read_unchecked(&stats->rx_drop));
79887 }
79888
79889 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
79890diff --git a/net/atm/resources.c b/net/atm/resources.c
79891index 0447d5d..3cf4728 100644
79892--- a/net/atm/resources.c
79893+++ b/net/atm/resources.c
79894@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
79895 static void copy_aal_stats(struct k_atm_aal_stats *from,
79896 struct atm_aal_stats *to)
79897 {
79898-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79899+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79900 __AAL_STAT_ITEMS
79901 #undef __HANDLE_ITEM
79902 }
79903@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
79904 static void subtract_aal_stats(struct k_atm_aal_stats *from,
79905 struct atm_aal_stats *to)
79906 {
79907-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
79908+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
79909 __AAL_STAT_ITEMS
79910 #undef __HANDLE_ITEM
79911 }
79912diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
79913index 7d02ebd..4d4cc01 100644
79914--- a/net/batman-adv/bat_iv_ogm.c
79915+++ b/net/batman-adv/bat_iv_ogm.c
79916@@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
79917
79918 /* randomize initial seqno to avoid collision */
79919 get_random_bytes(&random_seqno, sizeof(random_seqno));
79920- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
79921+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
79922
79923 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
79924 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
79925@@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
79926 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
79927
79928 /* change sequence number to network order */
79929- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
79930+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
79931 batadv_ogm_packet->seqno = htonl(seqno);
79932- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
79933+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
79934
79935 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
79936 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
79937@@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
79938 return;
79939
79940 /* could be changed by schedule_own_packet() */
79941- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
79942+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
79943
79944 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
79945 has_directlink_flag = 1;
79946diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
79947index f1d37cd..4190879 100644
79948--- a/net/batman-adv/hard-interface.c
79949+++ b/net/batman-adv/hard-interface.c
79950@@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
79951 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
79952 dev_add_pack(&hard_iface->batman_adv_ptype);
79953
79954- atomic_set(&hard_iface->frag_seqno, 1);
79955+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
79956 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
79957 hard_iface->net_dev->name);
79958
79959@@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
79960 /* This can't be called via a bat_priv callback because
79961 * we have no bat_priv yet.
79962 */
79963- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
79964+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
79965 hard_iface->bat_iv.ogm_buff = NULL;
79966
79967 return hard_iface;
79968diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
79969index 6b548fd..fc32c8d 100644
79970--- a/net/batman-adv/soft-interface.c
79971+++ b/net/batman-adv/soft-interface.c
79972@@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
79973 primary_if->net_dev->dev_addr, ETH_ALEN);
79974
79975 /* set broadcast sequence number */
79976- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
79977+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
79978 bcast_packet->seqno = htonl(seqno);
79979
79980 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
79981@@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
79982 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
79983
79984 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
79985- atomic_set(&bat_priv->bcast_seqno, 1);
79986+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
79987 atomic_set(&bat_priv->tt.vn, 0);
79988 atomic_set(&bat_priv->tt.local_changes, 0);
79989 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
79990diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
79991index ae9ac9a..11e0fe7 100644
79992--- a/net/batman-adv/types.h
79993+++ b/net/batman-adv/types.h
79994@@ -48,7 +48,7 @@
79995 struct batadv_hard_iface_bat_iv {
79996 unsigned char *ogm_buff;
79997 int ogm_buff_len;
79998- atomic_t ogm_seqno;
79999+ atomic_unchecked_t ogm_seqno;
80000 };
80001
80002 struct batadv_hard_iface {
80003@@ -56,7 +56,7 @@ struct batadv_hard_iface {
80004 int16_t if_num;
80005 char if_status;
80006 struct net_device *net_dev;
80007- atomic_t frag_seqno;
80008+ atomic_unchecked_t frag_seqno;
80009 struct kobject *hardif_obj;
80010 atomic_t refcount;
80011 struct packet_type batman_adv_ptype;
80012@@ -284,7 +284,7 @@ struct batadv_priv {
80013 atomic_t orig_interval; /* uint */
80014 atomic_t hop_penalty; /* uint */
80015 atomic_t log_level; /* uint */
80016- atomic_t bcast_seqno;
80017+ atomic_unchecked_t bcast_seqno;
80018 atomic_t bcast_queue_left;
80019 atomic_t batman_queue_left;
80020 char num_ifaces;
80021diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
80022index 10aff49..ea8e021 100644
80023--- a/net/batman-adv/unicast.c
80024+++ b/net/batman-adv/unicast.c
80025@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
80026 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
80027 frag2->flags = large_tail;
80028
80029- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
80030+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
80031 frag1->seqno = htons(seqno - 1);
80032 frag2->seqno = htons(seqno);
80033
80034diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
80035index 07f0739..3c42e34 100644
80036--- a/net/bluetooth/hci_sock.c
80037+++ b/net/bluetooth/hci_sock.c
80038@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
80039 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
80040 }
80041
80042- len = min_t(unsigned int, len, sizeof(uf));
80043+ len = min((size_t)len, sizeof(uf));
80044 if (copy_from_user(&uf, optval, len)) {
80045 err = -EFAULT;
80046 break;
80047diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
80048index 22e6583..426e2f3 100644
80049--- a/net/bluetooth/l2cap_core.c
80050+++ b/net/bluetooth/l2cap_core.c
80051@@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
80052 break;
80053
80054 case L2CAP_CONF_RFC:
80055- if (olen == sizeof(rfc))
80056- memcpy(&rfc, (void *)val, olen);
80057+ if (olen != sizeof(rfc))
80058+ break;
80059+
80060+ memcpy(&rfc, (void *)val, olen);
80061
80062 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
80063 rfc.mode != chan->mode)
80064diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
80065index 1bcfb84..dad9f98 100644
80066--- a/net/bluetooth/l2cap_sock.c
80067+++ b/net/bluetooth/l2cap_sock.c
80068@@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
80069 struct sock *sk = sock->sk;
80070 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
80071 struct l2cap_options opts;
80072- int len, err = 0;
80073+ int err = 0;
80074+ size_t len = optlen;
80075 u32 opt;
80076
80077 BT_DBG("sk %p", sk);
80078@@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
80079 opts.max_tx = chan->max_tx;
80080 opts.txwin_size = chan->tx_win;
80081
80082- len = min_t(unsigned int, sizeof(opts), optlen);
80083+ len = min(sizeof(opts), len);
80084 if (copy_from_user((char *) &opts, optval, len)) {
80085 err = -EFAULT;
80086 break;
80087@@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
80088 struct bt_security sec;
80089 struct bt_power pwr;
80090 struct l2cap_conn *conn;
80091- int len, err = 0;
80092+ int err = 0;
80093+ size_t len = optlen;
80094 u32 opt;
80095
80096 BT_DBG("sk %p", sk);
80097@@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
80098
80099 sec.level = BT_SECURITY_LOW;
80100
80101- len = min_t(unsigned int, sizeof(sec), optlen);
80102+ len = min(sizeof(sec), len);
80103 if (copy_from_user((char *) &sec, optval, len)) {
80104 err = -EFAULT;
80105 break;
80106@@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
80107
80108 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
80109
80110- len = min_t(unsigned int, sizeof(pwr), optlen);
80111+ len = min(sizeof(pwr), len);
80112 if (copy_from_user((char *) &pwr, optval, len)) {
80113 err = -EFAULT;
80114 break;
80115diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
80116index ce3f665..2c7d08f 100644
80117--- a/net/bluetooth/rfcomm/sock.c
80118+++ b/net/bluetooth/rfcomm/sock.c
80119@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
80120 struct sock *sk = sock->sk;
80121 struct bt_security sec;
80122 int err = 0;
80123- size_t len;
80124+ size_t len = optlen;
80125 u32 opt;
80126
80127 BT_DBG("sk %p", sk);
80128@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
80129
80130 sec.level = BT_SECURITY_LOW;
80131
80132- len = min_t(unsigned int, sizeof(sec), optlen);
80133+ len = min(sizeof(sec), len);
80134 if (copy_from_user((char *) &sec, optval, len)) {
80135 err = -EFAULT;
80136 break;
80137diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
80138index bd6fd0f..6492cba 100644
80139--- a/net/bluetooth/rfcomm/tty.c
80140+++ b/net/bluetooth/rfcomm/tty.c
80141@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
80142 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
80143
80144 spin_lock_irqsave(&dev->port.lock, flags);
80145- if (dev->port.count > 0) {
80146+ if (atomic_read(&dev->port.count) > 0) {
80147 spin_unlock_irqrestore(&dev->port.lock, flags);
80148 return;
80149 }
80150@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
80151 return -ENODEV;
80152
80153 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
80154- dev->channel, dev->port.count);
80155+ dev->channel, atomic_read(&dev->port.count));
80156
80157 spin_lock_irqsave(&dev->port.lock, flags);
80158- if (++dev->port.count > 1) {
80159+ if (atomic_inc_return(&dev->port.count) > 1) {
80160 spin_unlock_irqrestore(&dev->port.lock, flags);
80161 return 0;
80162 }
80163@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
80164 return;
80165
80166 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
80167- dev->port.count);
80168+ atomic_read(&dev->port.count));
80169
80170 spin_lock_irqsave(&dev->port.lock, flags);
80171- if (!--dev->port.count) {
80172+ if (!atomic_dec_return(&dev->port.count)) {
80173 spin_unlock_irqrestore(&dev->port.lock, flags);
80174 if (dev->tty_dev->parent)
80175 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
80176diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
80177index 5fe2ff3..121d696 100644
80178--- a/net/bridge/netfilter/ebtables.c
80179+++ b/net/bridge/netfilter/ebtables.c
80180@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80181 tmp.valid_hooks = t->table->valid_hooks;
80182 }
80183 mutex_unlock(&ebt_mutex);
80184- if (copy_to_user(user, &tmp, *len) != 0){
80185+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
80186 BUGPRINT("c2u Didn't work\n");
80187 ret = -EFAULT;
80188 break;
80189@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
80190 goto out;
80191 tmp.valid_hooks = t->valid_hooks;
80192
80193- if (copy_to_user(user, &tmp, *len) != 0) {
80194+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
80195 ret = -EFAULT;
80196 break;
80197 }
80198@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
80199 tmp.entries_size = t->table->entries_size;
80200 tmp.valid_hooks = t->table->valid_hooks;
80201
80202- if (copy_to_user(user, &tmp, *len) != 0) {
80203+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
80204 ret = -EFAULT;
80205 break;
80206 }
80207diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
80208index a376ec1..1fbd6be 100644
80209--- a/net/caif/cfctrl.c
80210+++ b/net/caif/cfctrl.c
80211@@ -10,6 +10,7 @@
80212 #include <linux/spinlock.h>
80213 #include <linux/slab.h>
80214 #include <linux/pkt_sched.h>
80215+#include <linux/sched.h>
80216 #include <net/caif/caif_layer.h>
80217 #include <net/caif/cfpkt.h>
80218 #include <net/caif/cfctrl.h>
80219@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
80220 memset(&dev_info, 0, sizeof(dev_info));
80221 dev_info.id = 0xff;
80222 cfsrvl_init(&this->serv, 0, &dev_info, false);
80223- atomic_set(&this->req_seq_no, 1);
80224- atomic_set(&this->rsp_seq_no, 1);
80225+ atomic_set_unchecked(&this->req_seq_no, 1);
80226+ atomic_set_unchecked(&this->rsp_seq_no, 1);
80227 this->serv.layer.receive = cfctrl_recv;
80228 sprintf(this->serv.layer.name, "ctrl");
80229 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
80230@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
80231 struct cfctrl_request_info *req)
80232 {
80233 spin_lock_bh(&ctrl->info_list_lock);
80234- atomic_inc(&ctrl->req_seq_no);
80235- req->sequence_no = atomic_read(&ctrl->req_seq_no);
80236+ atomic_inc_unchecked(&ctrl->req_seq_no);
80237+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
80238 list_add_tail(&req->list, &ctrl->list);
80239 spin_unlock_bh(&ctrl->info_list_lock);
80240 }
80241@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
80242 if (p != first)
80243 pr_warn("Requests are not received in order\n");
80244
80245- atomic_set(&ctrl->rsp_seq_no,
80246+ atomic_set_unchecked(&ctrl->rsp_seq_no,
80247 p->sequence_no);
80248 list_del(&p->list);
80249 goto out;
80250diff --git a/net/can/af_can.c b/net/can/af_can.c
80251index ddac1ee..3ee0a78 100644
80252--- a/net/can/af_can.c
80253+++ b/net/can/af_can.c
80254@@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
80255 };
80256
80257 /* notifier block for netdevice event */
80258-static struct notifier_block can_netdev_notifier __read_mostly = {
80259+static struct notifier_block can_netdev_notifier = {
80260 .notifier_call = can_notifier,
80261 };
80262
80263diff --git a/net/can/gw.c b/net/can/gw.c
80264index 574dda78e..3d2b3da 100644
80265--- a/net/can/gw.c
80266+++ b/net/can/gw.c
80267@@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
80268 MODULE_ALIAS("can-gw");
80269
80270 static HLIST_HEAD(cgw_list);
80271-static struct notifier_block notifier;
80272
80273 static struct kmem_cache *cgw_cache __read_mostly;
80274
80275@@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
80276 return err;
80277 }
80278
80279+static struct notifier_block notifier = {
80280+ .notifier_call = cgw_notifier
80281+};
80282+
80283 static __init int cgw_module_init(void)
80284 {
80285 printk(banner);
80286@@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
80287 return -ENOMEM;
80288
80289 /* set notifier */
80290- notifier.notifier_call = cgw_notifier;
80291 register_netdevice_notifier(&notifier);
80292
80293 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
80294diff --git a/net/compat.c b/net/compat.c
80295index 79ae884..17c5c09 100644
80296--- a/net/compat.c
80297+++ b/net/compat.c
80298@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
80299 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
80300 __get_user(kmsg->msg_flags, &umsg->msg_flags))
80301 return -EFAULT;
80302- kmsg->msg_name = compat_ptr(tmp1);
80303- kmsg->msg_iov = compat_ptr(tmp2);
80304- kmsg->msg_control = compat_ptr(tmp3);
80305+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
80306+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
80307+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
80308 return 0;
80309 }
80310
80311@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
80312
80313 if (kern_msg->msg_namelen) {
80314 if (mode == VERIFY_READ) {
80315- int err = move_addr_to_kernel(kern_msg->msg_name,
80316+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
80317 kern_msg->msg_namelen,
80318 kern_address);
80319 if (err < 0)
80320@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
80321 kern_msg->msg_name = NULL;
80322
80323 tot_len = iov_from_user_compat_to_kern(kern_iov,
80324- (struct compat_iovec __user *)kern_msg->msg_iov,
80325+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
80326 kern_msg->msg_iovlen);
80327 if (tot_len >= 0)
80328 kern_msg->msg_iov = kern_iov;
80329@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
80330
80331 #define CMSG_COMPAT_FIRSTHDR(msg) \
80332 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
80333- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
80334+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
80335 (struct compat_cmsghdr __user *)NULL)
80336
80337 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
80338 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
80339 (ucmlen) <= (unsigned long) \
80340 ((mhdr)->msg_controllen - \
80341- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
80342+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
80343
80344 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
80345 struct compat_cmsghdr __user *cmsg, int cmsg_len)
80346 {
80347 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
80348- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
80349+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
80350 msg->msg_controllen)
80351 return NULL;
80352 return (struct compat_cmsghdr __user *)ptr;
80353@@ -219,7 +219,7 @@ Efault:
80354
80355 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
80356 {
80357- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
80358+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
80359 struct compat_cmsghdr cmhdr;
80360 struct compat_timeval ctv;
80361 struct compat_timespec cts[3];
80362@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
80363
80364 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
80365 {
80366- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
80367+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
80368 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
80369 int fdnum = scm->fp->count;
80370 struct file **fp = scm->fp->fp;
80371@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
80372 return -EFAULT;
80373 old_fs = get_fs();
80374 set_fs(KERNEL_DS);
80375- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
80376+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
80377 set_fs(old_fs);
80378
80379 return err;
80380@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
80381 len = sizeof(ktime);
80382 old_fs = get_fs();
80383 set_fs(KERNEL_DS);
80384- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
80385+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
80386 set_fs(old_fs);
80387
80388 if (!err) {
80389@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80390 case MCAST_JOIN_GROUP:
80391 case MCAST_LEAVE_GROUP:
80392 {
80393- struct compat_group_req __user *gr32 = (void *)optval;
80394+ struct compat_group_req __user *gr32 = (void __user *)optval;
80395 struct group_req __user *kgr =
80396 compat_alloc_user_space(sizeof(struct group_req));
80397 u32 interface;
80398@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80399 case MCAST_BLOCK_SOURCE:
80400 case MCAST_UNBLOCK_SOURCE:
80401 {
80402- struct compat_group_source_req __user *gsr32 = (void *)optval;
80403+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
80404 struct group_source_req __user *kgsr = compat_alloc_user_space(
80405 sizeof(struct group_source_req));
80406 u32 interface;
80407@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80408 }
80409 case MCAST_MSFILTER:
80410 {
80411- struct compat_group_filter __user *gf32 = (void *)optval;
80412+ struct compat_group_filter __user *gf32 = (void __user *)optval;
80413 struct group_filter __user *kgf;
80414 u32 interface, fmode, numsrc;
80415
80416@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
80417 char __user *optval, int __user *optlen,
80418 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
80419 {
80420- struct compat_group_filter __user *gf32 = (void *)optval;
80421+ struct compat_group_filter __user *gf32 = (void __user *)optval;
80422 struct group_filter __user *kgf;
80423 int __user *koptlen;
80424 u32 interface, fmode, numsrc;
80425@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
80426
80427 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
80428 return -EINVAL;
80429- if (copy_from_user(a, args, nas[call]))
80430+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
80431 return -EFAULT;
80432 a0 = a[0];
80433 a1 = a[1];
80434diff --git a/net/core/datagram.c b/net/core/datagram.c
80435index 368f9c3..f82d4a3 100644
80436--- a/net/core/datagram.c
80437+++ b/net/core/datagram.c
80438@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
80439 }
80440
80441 kfree_skb(skb);
80442- atomic_inc(&sk->sk_drops);
80443+ atomic_inc_unchecked(&sk->sk_drops);
80444 sk_mem_reclaim_partial(sk);
80445
80446 return err;
80447diff --git a/net/core/dev.c b/net/core/dev.c
80448index f64e439..8f959e6 100644
80449--- a/net/core/dev.c
80450+++ b/net/core/dev.c
80451@@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
80452 if (no_module && capable(CAP_NET_ADMIN))
80453 no_module = request_module("netdev-%s", name);
80454 if (no_module && capable(CAP_SYS_MODULE)) {
80455+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80456+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
80457+#else
80458 if (!request_module("%s", name))
80459 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
80460 name);
80461+#endif
80462 }
80463 }
80464 EXPORT_SYMBOL(dev_load);
80465@@ -1715,7 +1719,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
80466 {
80467 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
80468 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
80469- atomic_long_inc(&dev->rx_dropped);
80470+ atomic_long_inc_unchecked(&dev->rx_dropped);
80471 kfree_skb(skb);
80472 return NET_RX_DROP;
80473 }
80474@@ -1725,7 +1729,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
80475 nf_reset(skb);
80476
80477 if (unlikely(!is_skb_forwardable(dev, skb))) {
80478- atomic_long_inc(&dev->rx_dropped);
80479+ atomic_long_inc_unchecked(&dev->rx_dropped);
80480 kfree_skb(skb);
80481 return NET_RX_DROP;
80482 }
80483@@ -2180,7 +2184,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
80484
80485 struct dev_gso_cb {
80486 void (*destructor)(struct sk_buff *skb);
80487-};
80488+} __no_const;
80489
80490 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
80491
80492@@ -3053,7 +3057,7 @@ enqueue:
80493
80494 local_irq_restore(flags);
80495
80496- atomic_long_inc(&skb->dev->rx_dropped);
80497+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
80498 kfree_skb(skb);
80499 return NET_RX_DROP;
80500 }
80501@@ -3125,7 +3129,7 @@ int netif_rx_ni(struct sk_buff *skb)
80502 }
80503 EXPORT_SYMBOL(netif_rx_ni);
80504
80505-static void net_tx_action(struct softirq_action *h)
80506+static void net_tx_action(void)
80507 {
80508 struct softnet_data *sd = &__get_cpu_var(softnet_data);
80509
80510@@ -3456,7 +3460,7 @@ ncls:
80511 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
80512 } else {
80513 drop:
80514- atomic_long_inc(&skb->dev->rx_dropped);
80515+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
80516 kfree_skb(skb);
80517 /* Jamal, now you will not able to escape explaining
80518 * me how you were going to use this. :-)
80519@@ -4039,7 +4043,7 @@ void netif_napi_del(struct napi_struct *napi)
80520 }
80521 EXPORT_SYMBOL(netif_napi_del);
80522
80523-static void net_rx_action(struct softirq_action *h)
80524+static void net_rx_action(void)
80525 {
80526 struct softnet_data *sd = &__get_cpu_var(softnet_data);
80527 unsigned long time_limit = jiffies + 2;
80528@@ -4523,8 +4527,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
80529 else
80530 seq_printf(seq, "%04x", ntohs(pt->type));
80531
80532+#ifdef CONFIG_GRKERNSEC_HIDESYM
80533+ seq_printf(seq, " %-8s %p\n",
80534+ pt->dev ? pt->dev->name : "", NULL);
80535+#else
80536 seq_printf(seq, " %-8s %pF\n",
80537 pt->dev ? pt->dev->name : "", pt->func);
80538+#endif
80539 }
80540
80541 return 0;
80542@@ -6096,7 +6105,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
80543 } else {
80544 netdev_stats_to_stats64(storage, &dev->stats);
80545 }
80546- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
80547+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
80548 return storage;
80549 }
80550 EXPORT_SYMBOL(dev_get_stats);
80551diff --git a/net/core/flow.c b/net/core/flow.c
80552index b0901ee..7d3c2ca 100644
80553--- a/net/core/flow.c
80554+++ b/net/core/flow.c
80555@@ -61,7 +61,7 @@ struct flow_cache {
80556 struct timer_list rnd_timer;
80557 };
80558
80559-atomic_t flow_cache_genid = ATOMIC_INIT(0);
80560+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
80561 EXPORT_SYMBOL(flow_cache_genid);
80562 static struct flow_cache flow_cache_global;
80563 static struct kmem_cache *flow_cachep __read_mostly;
80564@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
80565
80566 static int flow_entry_valid(struct flow_cache_entry *fle)
80567 {
80568- if (atomic_read(&flow_cache_genid) != fle->genid)
80569+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
80570 return 0;
80571 if (fle->object && !fle->object->ops->check(fle->object))
80572 return 0;
80573@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
80574 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
80575 fcp->hash_count++;
80576 }
80577- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
80578+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
80579 flo = fle->object;
80580 if (!flo)
80581 goto ret_object;
80582@@ -280,7 +280,7 @@ nocache:
80583 }
80584 flo = resolver(net, key, family, dir, flo, ctx);
80585 if (fle) {
80586- fle->genid = atomic_read(&flow_cache_genid);
80587+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
80588 if (!IS_ERR(flo))
80589 fle->object = flo;
80590 else
80591diff --git a/net/core/iovec.c b/net/core/iovec.c
80592index 7e7aeb0..2a998cb 100644
80593--- a/net/core/iovec.c
80594+++ b/net/core/iovec.c
80595@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
80596 if (m->msg_namelen) {
80597 if (mode == VERIFY_READ) {
80598 void __user *namep;
80599- namep = (void __user __force *) m->msg_name;
80600+ namep = (void __force_user *) m->msg_name;
80601 err = move_addr_to_kernel(namep, m->msg_namelen,
80602 address);
80603 if (err < 0)
80604@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
80605 }
80606
80607 size = m->msg_iovlen * sizeof(struct iovec);
80608- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
80609+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
80610 return -EFAULT;
80611
80612 m->msg_iov = iov;
80613diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
80614index 1868625..5f4de62 100644
80615--- a/net/core/rtnetlink.c
80616+++ b/net/core/rtnetlink.c
80617@@ -58,7 +58,7 @@ struct rtnl_link {
80618 rtnl_doit_func doit;
80619 rtnl_dumpit_func dumpit;
80620 rtnl_calcit_func calcit;
80621-};
80622+} __no_const;
80623
80624 static DEFINE_MUTEX(rtnl_mutex);
80625
80626diff --git a/net/core/scm.c b/net/core/scm.c
80627index 905dcc6..14ee2d6 100644
80628--- a/net/core/scm.c
80629+++ b/net/core/scm.c
80630@@ -224,7 +224,7 @@ EXPORT_SYMBOL(__scm_send);
80631 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
80632 {
80633 struct cmsghdr __user *cm
80634- = (__force struct cmsghdr __user *)msg->msg_control;
80635+ = (struct cmsghdr __force_user *)msg->msg_control;
80636 struct cmsghdr cmhdr;
80637 int cmlen = CMSG_LEN(len);
80638 int err;
80639@@ -247,7 +247,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
80640 err = -EFAULT;
80641 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
80642 goto out;
80643- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
80644+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
80645 goto out;
80646 cmlen = CMSG_SPACE(len);
80647 if (msg->msg_controllen < cmlen)
80648@@ -263,7 +263,7 @@ EXPORT_SYMBOL(put_cmsg);
80649 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
80650 {
80651 struct cmsghdr __user *cm
80652- = (__force struct cmsghdr __user*)msg->msg_control;
80653+ = (struct cmsghdr __force_user *)msg->msg_control;
80654
80655 int fdmax = 0;
80656 int fdnum = scm->fp->count;
80657@@ -283,7 +283,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
80658 if (fdnum < fdmax)
80659 fdmax = fdnum;
80660
80661- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
80662+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
80663 i++, cmfptr++)
80664 {
80665 struct socket *sock;
80666diff --git a/net/core/sock.c b/net/core/sock.c
80667index bc131d4..029e378 100644
80668--- a/net/core/sock.c
80669+++ b/net/core/sock.c
80670@@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80671 struct sk_buff_head *list = &sk->sk_receive_queue;
80672
80673 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
80674- atomic_inc(&sk->sk_drops);
80675+ atomic_inc_unchecked(&sk->sk_drops);
80676 trace_sock_rcvqueue_full(sk, skb);
80677 return -ENOMEM;
80678 }
80679@@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80680 return err;
80681
80682 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
80683- atomic_inc(&sk->sk_drops);
80684+ atomic_inc_unchecked(&sk->sk_drops);
80685 return -ENOBUFS;
80686 }
80687
80688@@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80689 skb_dst_force(skb);
80690
80691 spin_lock_irqsave(&list->lock, flags);
80692- skb->dropcount = atomic_read(&sk->sk_drops);
80693+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
80694 __skb_queue_tail(list, skb);
80695 spin_unlock_irqrestore(&list->lock, flags);
80696
80697@@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
80698 skb->dev = NULL;
80699
80700 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
80701- atomic_inc(&sk->sk_drops);
80702+ atomic_inc_unchecked(&sk->sk_drops);
80703 goto discard_and_relse;
80704 }
80705 if (nested)
80706@@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
80707 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
80708 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
80709 bh_unlock_sock(sk);
80710- atomic_inc(&sk->sk_drops);
80711+ atomic_inc_unchecked(&sk->sk_drops);
80712 goto discard_and_relse;
80713 }
80714
80715@@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80716 struct timeval tm;
80717 } v;
80718
80719- int lv = sizeof(int);
80720- int len;
80721+ unsigned int lv = sizeof(int);
80722+ unsigned int len;
80723
80724 if (get_user(len, optlen))
80725 return -EFAULT;
80726- if (len < 0)
80727+ if (len > INT_MAX)
80728 return -EINVAL;
80729
80730 memset(&v, 0, sizeof(v));
80731@@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80732
80733 case SO_PEERNAME:
80734 {
80735- char address[128];
80736+ char address[_K_SS_MAXSIZE];
80737
80738 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
80739 return -ENOTCONN;
80740- if (lv < len)
80741+ if (lv < len || sizeof address < len)
80742 return -EINVAL;
80743 if (copy_to_user(optval, address, len))
80744 return -EFAULT;
80745@@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80746
80747 if (len > lv)
80748 len = lv;
80749- if (copy_to_user(optval, &v, len))
80750+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
80751 return -EFAULT;
80752 lenout:
80753 if (put_user(len, optlen))
80754@@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
80755 */
80756 smp_wmb();
80757 atomic_set(&sk->sk_refcnt, 1);
80758- atomic_set(&sk->sk_drops, 0);
80759+ atomic_set_unchecked(&sk->sk_drops, 0);
80760 }
80761 EXPORT_SYMBOL(sock_init_data);
80762
80763diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
80764index 602cd63..0a699b1 100644
80765--- a/net/core/sock_diag.c
80766+++ b/net/core/sock_diag.c
80767@@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
80768
80769 int sock_diag_check_cookie(void *sk, __u32 *cookie)
80770 {
80771+#ifndef CONFIG_GRKERNSEC_HIDESYM
80772 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
80773 cookie[1] != INET_DIAG_NOCOOKIE) &&
80774 ((u32)(unsigned long)sk != cookie[0] ||
80775 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
80776 return -ESTALE;
80777 else
80778+#endif
80779 return 0;
80780 }
80781 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
80782
80783 void sock_diag_save_cookie(void *sk, __u32 *cookie)
80784 {
80785+#ifdef CONFIG_GRKERNSEC_HIDESYM
80786+ cookie[0] = 0;
80787+ cookie[1] = 0;
80788+#else
80789 cookie[0] = (u32)(unsigned long)sk;
80790 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
80791+#endif
80792 }
80793 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
80794
80795@@ -97,21 +104,6 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
80796 }
80797 EXPORT_SYMBOL_GPL(sock_diag_unregister);
80798
80799-static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
80800-{
80801- if (sock_diag_handlers[family] == NULL)
80802- request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
80803- NETLINK_SOCK_DIAG, family);
80804-
80805- mutex_lock(&sock_diag_table_mutex);
80806- return sock_diag_handlers[family];
80807-}
80808-
80809-static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
80810-{
80811- mutex_unlock(&sock_diag_table_mutex);
80812-}
80813-
80814 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
80815 {
80816 int err;
80817@@ -121,12 +113,20 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
80818 if (nlmsg_len(nlh) < sizeof(*req))
80819 return -EINVAL;
80820
80821- hndl = sock_diag_lock_handler(req->sdiag_family);
80822+ if (req->sdiag_family >= AF_MAX)
80823+ return -EINVAL;
80824+
80825+ if (sock_diag_handlers[req->sdiag_family] == NULL)
80826+ request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
80827+ NETLINK_SOCK_DIAG, req->sdiag_family);
80828+
80829+ mutex_lock(&sock_diag_table_mutex);
80830+ hndl = sock_diag_handlers[req->sdiag_family];
80831 if (hndl == NULL)
80832 err = -ENOENT;
80833 else
80834 err = hndl->dump(skb, nlh);
80835- sock_diag_unlock_handler(hndl);
80836+ mutex_unlock(&sock_diag_table_mutex);
80837
80838 return err;
80839 }
80840diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
80841index a55eecc..dd8428c 100644
80842--- a/net/decnet/sysctl_net_decnet.c
80843+++ b/net/decnet/sysctl_net_decnet.c
80844@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
80845
80846 if (len > *lenp) len = *lenp;
80847
80848- if (copy_to_user(buffer, addr, len))
80849+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
80850 return -EFAULT;
80851
80852 *lenp = len;
80853@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
80854
80855 if (len > *lenp) len = *lenp;
80856
80857- if (copy_to_user(buffer, devname, len))
80858+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
80859 return -EFAULT;
80860
80861 *lenp = len;
80862diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
80863index a69b4e4..dbccba5 100644
80864--- a/net/ipv4/ah4.c
80865+++ b/net/ipv4/ah4.c
80866@@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
80867 return;
80868
80869 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
80870- atomic_inc(&flow_cache_genid);
80871+ atomic_inc_unchecked(&flow_cache_genid);
80872 rt_genid_bump(net);
80873
80874 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
80875diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
80876index 3b4f0cd..8cb864c 100644
80877--- a/net/ipv4/esp4.c
80878+++ b/net/ipv4/esp4.c
80879@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
80880 return;
80881
80882 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
80883- atomic_inc(&flow_cache_genid);
80884+ atomic_inc_unchecked(&flow_cache_genid);
80885 rt_genid_bump(net);
80886
80887 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
80888diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
80889index 5cd75e2..f57ef39 100644
80890--- a/net/ipv4/fib_frontend.c
80891+++ b/net/ipv4/fib_frontend.c
80892@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
80893 #ifdef CONFIG_IP_ROUTE_MULTIPATH
80894 fib_sync_up(dev);
80895 #endif
80896- atomic_inc(&net->ipv4.dev_addr_genid);
80897+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80898 rt_cache_flush(dev_net(dev));
80899 break;
80900 case NETDEV_DOWN:
80901 fib_del_ifaddr(ifa, NULL);
80902- atomic_inc(&net->ipv4.dev_addr_genid);
80903+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80904 if (ifa->ifa_dev->ifa_list == NULL) {
80905 /* Last address was deleted from this interface.
80906 * Disable IP.
80907@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
80908 #ifdef CONFIG_IP_ROUTE_MULTIPATH
80909 fib_sync_up(dev);
80910 #endif
80911- atomic_inc(&net->ipv4.dev_addr_genid);
80912+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80913 rt_cache_flush(net);
80914 break;
80915 case NETDEV_DOWN:
80916diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
80917index 4797a80..2bd54e9 100644
80918--- a/net/ipv4/fib_semantics.c
80919+++ b/net/ipv4/fib_semantics.c
80920@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
80921 nh->nh_saddr = inet_select_addr(nh->nh_dev,
80922 nh->nh_gw,
80923 nh->nh_parent->fib_scope);
80924- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
80925+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
80926
80927 return nh->nh_saddr;
80928 }
80929diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
80930index fa3ae81..0dbe6b8 100644
80931--- a/net/ipv4/inet_hashtables.c
80932+++ b/net/ipv4/inet_hashtables.c
80933@@ -18,12 +18,15 @@
80934 #include <linux/sched.h>
80935 #include <linux/slab.h>
80936 #include <linux/wait.h>
80937+#include <linux/security.h>
80938
80939 #include <net/inet_connection_sock.h>
80940 #include <net/inet_hashtables.h>
80941 #include <net/secure_seq.h>
80942 #include <net/ip.h>
80943
80944+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
80945+
80946 /*
80947 * Allocate and initialize a new local port bind bucket.
80948 * The bindhash mutex for snum's hash chain must be held here.
80949@@ -540,6 +543,8 @@ ok:
80950 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
80951 spin_unlock(&head->lock);
80952
80953+ gr_update_task_in_ip_table(current, inet_sk(sk));
80954+
80955 if (tw) {
80956 inet_twsk_deschedule(tw, death_row);
80957 while (twrefcnt) {
80958diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
80959index 000e3d2..5472da3 100644
80960--- a/net/ipv4/inetpeer.c
80961+++ b/net/ipv4/inetpeer.c
80962@@ -503,8 +503,8 @@ relookup:
80963 if (p) {
80964 p->daddr = *daddr;
80965 atomic_set(&p->refcnt, 1);
80966- atomic_set(&p->rid, 0);
80967- atomic_set(&p->ip_id_count,
80968+ atomic_set_unchecked(&p->rid, 0);
80969+ atomic_set_unchecked(&p->ip_id_count,
80970 (daddr->family == AF_INET) ?
80971 secure_ip_id(daddr->addr.a4) :
80972 secure_ipv6_id(daddr->addr.a6));
80973diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
80974index eb9d63a..50babc1 100644
80975--- a/net/ipv4/ip_fragment.c
80976+++ b/net/ipv4/ip_fragment.c
80977@@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
80978 return 0;
80979
80980 start = qp->rid;
80981- end = atomic_inc_return(&peer->rid);
80982+ end = atomic_inc_return_unchecked(&peer->rid);
80983 qp->rid = end;
80984
80985 rc = qp->q.fragments && (end - start) > max;
80986diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
80987index d9c4f11..02b82db 100644
80988--- a/net/ipv4/ip_sockglue.c
80989+++ b/net/ipv4/ip_sockglue.c
80990@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
80991 len = min_t(unsigned int, len, opt->optlen);
80992 if (put_user(len, optlen))
80993 return -EFAULT;
80994- if (copy_to_user(optval, opt->__data, len))
80995+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
80996+ copy_to_user(optval, opt->__data, len))
80997 return -EFAULT;
80998 return 0;
80999 }
81000@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
81001 if (sk->sk_type != SOCK_STREAM)
81002 return -ENOPROTOOPT;
81003
81004- msg.msg_control = optval;
81005+ msg.msg_control = (void __force_kernel *)optval;
81006 msg.msg_controllen = len;
81007 msg.msg_flags = flags;
81008
81009diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
81010index 9a46dae..5f793a0 100644
81011--- a/net/ipv4/ipcomp.c
81012+++ b/net/ipv4/ipcomp.c
81013@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
81014 return;
81015
81016 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
81017- atomic_inc(&flow_cache_genid);
81018+ atomic_inc_unchecked(&flow_cache_genid);
81019 rt_genid_bump(net);
81020
81021 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
81022diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
81023index a2e50ae..e152b7c 100644
81024--- a/net/ipv4/ipconfig.c
81025+++ b/net/ipv4/ipconfig.c
81026@@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
81027
81028 mm_segment_t oldfs = get_fs();
81029 set_fs(get_ds());
81030- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
81031+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
81032 set_fs(oldfs);
81033 return res;
81034 }
81035@@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
81036
81037 mm_segment_t oldfs = get_fs();
81038 set_fs(get_ds());
81039- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
81040+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
81041 set_fs(oldfs);
81042 return res;
81043 }
81044@@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
81045
81046 mm_segment_t oldfs = get_fs();
81047 set_fs(get_ds());
81048- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
81049+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
81050 set_fs(oldfs);
81051 return res;
81052 }
81053diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
81054index 3ea4127..849297b 100644
81055--- a/net/ipv4/netfilter/arp_tables.c
81056+++ b/net/ipv4/netfilter/arp_tables.c
81057@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
81058 #endif
81059
81060 static int get_info(struct net *net, void __user *user,
81061- const int *len, int compat)
81062+ int len, int compat)
81063 {
81064 char name[XT_TABLE_MAXNAMELEN];
81065 struct xt_table *t;
81066 int ret;
81067
81068- if (*len != sizeof(struct arpt_getinfo)) {
81069- duprintf("length %u != %Zu\n", *len,
81070+ if (len != sizeof(struct arpt_getinfo)) {
81071+ duprintf("length %u != %Zu\n", len,
81072 sizeof(struct arpt_getinfo));
81073 return -EINVAL;
81074 }
81075@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
81076 info.size = private->size;
81077 strcpy(info.name, name);
81078
81079- if (copy_to_user(user, &info, *len) != 0)
81080+ if (copy_to_user(user, &info, len) != 0)
81081 ret = -EFAULT;
81082 else
81083 ret = 0;
81084@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
81085
81086 switch (cmd) {
81087 case ARPT_SO_GET_INFO:
81088- ret = get_info(sock_net(sk), user, len, 1);
81089+ ret = get_info(sock_net(sk), user, *len, 1);
81090 break;
81091 case ARPT_SO_GET_ENTRIES:
81092 ret = compat_get_entries(sock_net(sk), user, len);
81093@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
81094
81095 switch (cmd) {
81096 case ARPT_SO_GET_INFO:
81097- ret = get_info(sock_net(sk), user, len, 0);
81098+ ret = get_info(sock_net(sk), user, *len, 0);
81099 break;
81100
81101 case ARPT_SO_GET_ENTRIES:
81102diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
81103index 17c5e06..1b91206 100644
81104--- a/net/ipv4/netfilter/ip_tables.c
81105+++ b/net/ipv4/netfilter/ip_tables.c
81106@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
81107 #endif
81108
81109 static int get_info(struct net *net, void __user *user,
81110- const int *len, int compat)
81111+ int len, int compat)
81112 {
81113 char name[XT_TABLE_MAXNAMELEN];
81114 struct xt_table *t;
81115 int ret;
81116
81117- if (*len != sizeof(struct ipt_getinfo)) {
81118- duprintf("length %u != %zu\n", *len,
81119+ if (len != sizeof(struct ipt_getinfo)) {
81120+ duprintf("length %u != %zu\n", len,
81121 sizeof(struct ipt_getinfo));
81122 return -EINVAL;
81123 }
81124@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
81125 info.size = private->size;
81126 strcpy(info.name, name);
81127
81128- if (copy_to_user(user, &info, *len) != 0)
81129+ if (copy_to_user(user, &info, len) != 0)
81130 ret = -EFAULT;
81131 else
81132 ret = 0;
81133@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81134
81135 switch (cmd) {
81136 case IPT_SO_GET_INFO:
81137- ret = get_info(sock_net(sk), user, len, 1);
81138+ ret = get_info(sock_net(sk), user, *len, 1);
81139 break;
81140 case IPT_SO_GET_ENTRIES:
81141 ret = compat_get_entries(sock_net(sk), user, len);
81142@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81143
81144 switch (cmd) {
81145 case IPT_SO_GET_INFO:
81146- ret = get_info(sock_net(sk), user, len, 0);
81147+ ret = get_info(sock_net(sk), user, *len, 0);
81148 break;
81149
81150 case IPT_SO_GET_ENTRIES:
81151diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
81152index 6f9c072..38ea6c6 100644
81153--- a/net/ipv4/ping.c
81154+++ b/net/ipv4/ping.c
81155@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
81156 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
81157 0, sock_i_ino(sp),
81158 atomic_read(&sp->sk_refcnt), sp,
81159- atomic_read(&sp->sk_drops), len);
81160+ atomic_read_unchecked(&sp->sk_drops), len);
81161 }
81162
81163 static int ping_seq_show(struct seq_file *seq, void *v)
81164diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
81165index 6f08991..55867ad 100644
81166--- a/net/ipv4/raw.c
81167+++ b/net/ipv4/raw.c
81168@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
81169 int raw_rcv(struct sock *sk, struct sk_buff *skb)
81170 {
81171 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
81172- atomic_inc(&sk->sk_drops);
81173+ atomic_inc_unchecked(&sk->sk_drops);
81174 kfree_skb(skb);
81175 return NET_RX_DROP;
81176 }
81177@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
81178
81179 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
81180 {
81181+ struct icmp_filter filter;
81182+
81183 if (optlen > sizeof(struct icmp_filter))
81184 optlen = sizeof(struct icmp_filter);
81185- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
81186+ if (copy_from_user(&filter, optval, optlen))
81187 return -EFAULT;
81188+ raw_sk(sk)->filter = filter;
81189 return 0;
81190 }
81191
81192 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
81193 {
81194 int len, ret = -EFAULT;
81195+ struct icmp_filter filter;
81196
81197 if (get_user(len, optlen))
81198 goto out;
81199@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
81200 if (len > sizeof(struct icmp_filter))
81201 len = sizeof(struct icmp_filter);
81202 ret = -EFAULT;
81203- if (put_user(len, optlen) ||
81204- copy_to_user(optval, &raw_sk(sk)->filter, len))
81205+ filter = raw_sk(sk)->filter;
81206+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
81207 goto out;
81208 ret = 0;
81209 out: return ret;
81210@@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
81211 0, 0L, 0,
81212 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
81213 0, sock_i_ino(sp),
81214- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
81215+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
81216 }
81217
81218 static int raw_seq_show(struct seq_file *seq, void *v)
81219diff --git a/net/ipv4/route.c b/net/ipv4/route.c
81220index a0fcc47..5949bba1 100644
81221--- a/net/ipv4/route.c
81222+++ b/net/ipv4/route.c
81223@@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
81224
81225 static __net_init int rt_genid_init(struct net *net)
81226 {
81227- atomic_set(&net->rt_genid, 0);
81228+ atomic_set_unchecked(&net->rt_genid, 0);
81229 get_random_bytes(&net->ipv4.dev_addr_genid,
81230 sizeof(net->ipv4.dev_addr_genid));
81231 return 0;
81232diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
81233index ad70a96..50cb55b 100644
81234--- a/net/ipv4/tcp_input.c
81235+++ b/net/ipv4/tcp_input.c
81236@@ -4733,7 +4733,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
81237 * simplifies code)
81238 */
81239 static void
81240-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
81241+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
81242 struct sk_buff *head, struct sk_buff *tail,
81243 u32 start, u32 end)
81244 {
81245@@ -5850,6 +5850,7 @@ discard:
81246 tcp_paws_reject(&tp->rx_opt, 0))
81247 goto discard_and_undo;
81248
81249+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
81250 if (th->syn) {
81251 /* We see SYN without ACK. It is attempt of
81252 * simultaneous connect with crossed SYNs.
81253@@ -5900,6 +5901,7 @@ discard:
81254 goto discard;
81255 #endif
81256 }
81257+#endif
81258 /* "fifth, if neither of the SYN or RST bits is set then
81259 * drop the segment and return."
81260 */
81261@@ -5944,7 +5946,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
81262 goto discard;
81263
81264 if (th->syn) {
81265- if (th->fin)
81266+ if (th->fin || th->urg || th->psh)
81267 goto discard;
81268 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
81269 return 1;
81270diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
81271index eadb693..e8f7251 100644
81272--- a/net/ipv4/tcp_ipv4.c
81273+++ b/net/ipv4/tcp_ipv4.c
81274@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
81275 EXPORT_SYMBOL(sysctl_tcp_low_latency);
81276
81277
81278+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81279+extern int grsec_enable_blackhole;
81280+#endif
81281+
81282 #ifdef CONFIG_TCP_MD5SIG
81283 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
81284 __be32 daddr, __be32 saddr, const struct tcphdr *th);
81285@@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
81286 return 0;
81287
81288 reset:
81289+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81290+ if (!grsec_enable_blackhole)
81291+#endif
81292 tcp_v4_send_reset(rsk, skb);
81293 discard:
81294 kfree_skb(skb);
81295@@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
81296 TCP_SKB_CB(skb)->sacked = 0;
81297
81298 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
81299- if (!sk)
81300+ if (!sk) {
81301+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81302+ ret = 1;
81303+#endif
81304 goto no_tcp_socket;
81305-
81306+ }
81307 process:
81308- if (sk->sk_state == TCP_TIME_WAIT)
81309+ if (sk->sk_state == TCP_TIME_WAIT) {
81310+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81311+ ret = 2;
81312+#endif
81313 goto do_time_wait;
81314+ }
81315
81316 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
81317 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
81318@@ -2050,6 +2064,10 @@ no_tcp_socket:
81319 bad_packet:
81320 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
81321 } else {
81322+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81323+ if (!grsec_enable_blackhole || (ret == 1 &&
81324+ (skb->dev->flags & IFF_LOOPBACK)))
81325+#endif
81326 tcp_v4_send_reset(NULL, skb);
81327 }
81328
81329diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
81330index f35f2df..ccb5ca6 100644
81331--- a/net/ipv4/tcp_minisocks.c
81332+++ b/net/ipv4/tcp_minisocks.c
81333@@ -27,6 +27,10 @@
81334 #include <net/inet_common.h>
81335 #include <net/xfrm.h>
81336
81337+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81338+extern int grsec_enable_blackhole;
81339+#endif
81340+
81341 int sysctl_tcp_syncookies __read_mostly = 1;
81342 EXPORT_SYMBOL(sysctl_tcp_syncookies);
81343
81344@@ -742,7 +746,10 @@ embryonic_reset:
81345 * avoid becoming vulnerable to outside attack aiming at
81346 * resetting legit local connections.
81347 */
81348- req->rsk_ops->send_reset(sk, skb);
81349+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81350+ if (!grsec_enable_blackhole)
81351+#endif
81352+ req->rsk_ops->send_reset(sk, skb);
81353 } else if (fastopen) { /* received a valid RST pkt */
81354 reqsk_fastopen_remove(sk, req, true);
81355 tcp_reset(sk);
81356diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
81357index 4526fe6..1a34e43 100644
81358--- a/net/ipv4/tcp_probe.c
81359+++ b/net/ipv4/tcp_probe.c
81360@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
81361 if (cnt + width >= len)
81362 break;
81363
81364- if (copy_to_user(buf + cnt, tbuf, width))
81365+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
81366 return -EFAULT;
81367 cnt += width;
81368 }
81369diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
81370index b78aac3..e18230b 100644
81371--- a/net/ipv4/tcp_timer.c
81372+++ b/net/ipv4/tcp_timer.c
81373@@ -22,6 +22,10 @@
81374 #include <linux/gfp.h>
81375 #include <net/tcp.h>
81376
81377+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81378+extern int grsec_lastack_retries;
81379+#endif
81380+
81381 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
81382 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
81383 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
81384@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
81385 }
81386 }
81387
81388+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81389+ if ((sk->sk_state == TCP_LAST_ACK) &&
81390+ (grsec_lastack_retries > 0) &&
81391+ (grsec_lastack_retries < retry_until))
81392+ retry_until = grsec_lastack_retries;
81393+#endif
81394+
81395 if (retransmits_timed_out(sk, retry_until,
81396 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
81397 /* Has it gone just too far? */
81398diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
81399index 1f4d405..3524677 100644
81400--- a/net/ipv4/udp.c
81401+++ b/net/ipv4/udp.c
81402@@ -87,6 +87,7 @@
81403 #include <linux/types.h>
81404 #include <linux/fcntl.h>
81405 #include <linux/module.h>
81406+#include <linux/security.h>
81407 #include <linux/socket.h>
81408 #include <linux/sockios.h>
81409 #include <linux/igmp.h>
81410@@ -111,6 +112,10 @@
81411 #include <trace/events/skb.h>
81412 #include "udp_impl.h"
81413
81414+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81415+extern int grsec_enable_blackhole;
81416+#endif
81417+
81418 struct udp_table udp_table __read_mostly;
81419 EXPORT_SYMBOL(udp_table);
81420
81421@@ -569,6 +574,9 @@ found:
81422 return s;
81423 }
81424
81425+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
81426+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
81427+
81428 /*
81429 * This routine is called by the ICMP module when it gets some
81430 * sort of error condition. If err < 0 then the socket should
81431@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
81432 dport = usin->sin_port;
81433 if (dport == 0)
81434 return -EINVAL;
81435+
81436+ err = gr_search_udp_sendmsg(sk, usin);
81437+ if (err)
81438+ return err;
81439 } else {
81440 if (sk->sk_state != TCP_ESTABLISHED)
81441 return -EDESTADDRREQ;
81442+
81443+ err = gr_search_udp_sendmsg(sk, NULL);
81444+ if (err)
81445+ return err;
81446+
81447 daddr = inet->inet_daddr;
81448 dport = inet->inet_dport;
81449 /* Open fast path for connected socket.
81450@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
81451 udp_lib_checksum_complete(skb)) {
81452 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81453 IS_UDPLITE(sk));
81454- atomic_inc(&sk->sk_drops);
81455+ atomic_inc_unchecked(&sk->sk_drops);
81456 __skb_unlink(skb, rcvq);
81457 __skb_queue_tail(&list_kill, skb);
81458 }
81459@@ -1194,6 +1211,10 @@ try_again:
81460 if (!skb)
81461 goto out;
81462
81463+ err = gr_search_udp_recvmsg(sk, skb);
81464+ if (err)
81465+ goto out_free;
81466+
81467 ulen = skb->len - sizeof(struct udphdr);
81468 copied = len;
81469 if (copied > ulen)
81470@@ -1227,7 +1248,7 @@ try_again:
81471 if (unlikely(err)) {
81472 trace_kfree_skb(skb, udp_recvmsg);
81473 if (!peeked) {
81474- atomic_inc(&sk->sk_drops);
81475+ atomic_inc_unchecked(&sk->sk_drops);
81476 UDP_INC_STATS_USER(sock_net(sk),
81477 UDP_MIB_INERRORS, is_udplite);
81478 }
81479@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
81480
81481 drop:
81482 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
81483- atomic_inc(&sk->sk_drops);
81484+ atomic_inc_unchecked(&sk->sk_drops);
81485 kfree_skb(skb);
81486 return -1;
81487 }
81488@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
81489 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
81490
81491 if (!skb1) {
81492- atomic_inc(&sk->sk_drops);
81493+ atomic_inc_unchecked(&sk->sk_drops);
81494 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
81495 IS_UDPLITE(sk));
81496 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81497@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
81498 goto csum_error;
81499
81500 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
81501+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81502+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
81503+#endif
81504 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
81505
81506 /*
81507@@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
81508 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
81509 0, sock_i_ino(sp),
81510 atomic_read(&sp->sk_refcnt), sp,
81511- atomic_read(&sp->sk_drops), len);
81512+ atomic_read_unchecked(&sp->sk_drops), len);
81513 }
81514
81515 int udp4_seq_show(struct seq_file *seq, void *v)
81516diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
81517index 1b5d8cb..2e8c2d9 100644
81518--- a/net/ipv6/addrconf.c
81519+++ b/net/ipv6/addrconf.c
81520@@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
81521 p.iph.ihl = 5;
81522 p.iph.protocol = IPPROTO_IPV6;
81523 p.iph.ttl = 64;
81524- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
81525+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
81526
81527 if (ops->ndo_do_ioctl) {
81528 mm_segment_t oldfs = get_fs();
81529diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
81530index 131dd09..7647ada 100644
81531--- a/net/ipv6/ip6_gre.c
81532+++ b/net/ipv6/ip6_gre.c
81533@@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
81534 }
81535
81536
81537-static struct inet6_protocol ip6gre_protocol __read_mostly = {
81538+static struct inet6_protocol ip6gre_protocol = {
81539 .handler = ip6gre_rcv,
81540 .err_handler = ip6gre_err,
81541 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
81542diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
81543index d1e2e8e..51c19ae 100644
81544--- a/net/ipv6/ipv6_sockglue.c
81545+++ b/net/ipv6/ipv6_sockglue.c
81546@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
81547 if (sk->sk_type != SOCK_STREAM)
81548 return -ENOPROTOOPT;
81549
81550- msg.msg_control = optval;
81551+ msg.msg_control = (void __force_kernel *)optval;
81552 msg.msg_controllen = len;
81553 msg.msg_flags = flags;
81554
81555diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
81556index 125a90d..2a11f36 100644
81557--- a/net/ipv6/netfilter/ip6_tables.c
81558+++ b/net/ipv6/netfilter/ip6_tables.c
81559@@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
81560 #endif
81561
81562 static int get_info(struct net *net, void __user *user,
81563- const int *len, int compat)
81564+ int len, int compat)
81565 {
81566 char name[XT_TABLE_MAXNAMELEN];
81567 struct xt_table *t;
81568 int ret;
81569
81570- if (*len != sizeof(struct ip6t_getinfo)) {
81571- duprintf("length %u != %zu\n", *len,
81572+ if (len != sizeof(struct ip6t_getinfo)) {
81573+ duprintf("length %u != %zu\n", len,
81574 sizeof(struct ip6t_getinfo));
81575 return -EINVAL;
81576 }
81577@@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
81578 info.size = private->size;
81579 strcpy(info.name, name);
81580
81581- if (copy_to_user(user, &info, *len) != 0)
81582+ if (copy_to_user(user, &info, len) != 0)
81583 ret = -EFAULT;
81584 else
81585 ret = 0;
81586@@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81587
81588 switch (cmd) {
81589 case IP6T_SO_GET_INFO:
81590- ret = get_info(sock_net(sk), user, len, 1);
81591+ ret = get_info(sock_net(sk), user, *len, 1);
81592 break;
81593 case IP6T_SO_GET_ENTRIES:
81594 ret = compat_get_entries(sock_net(sk), user, len);
81595@@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81596
81597 switch (cmd) {
81598 case IP6T_SO_GET_INFO:
81599- ret = get_info(sock_net(sk), user, len, 0);
81600+ ret = get_info(sock_net(sk), user, *len, 0);
81601 break;
81602
81603 case IP6T_SO_GET_ENTRIES:
81604diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
81605index 70fa814..d70c28c 100644
81606--- a/net/ipv6/raw.c
81607+++ b/net/ipv6/raw.c
81608@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
81609 {
81610 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
81611 skb_checksum_complete(skb)) {
81612- atomic_inc(&sk->sk_drops);
81613+ atomic_inc_unchecked(&sk->sk_drops);
81614 kfree_skb(skb);
81615 return NET_RX_DROP;
81616 }
81617@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
81618 struct raw6_sock *rp = raw6_sk(sk);
81619
81620 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
81621- atomic_inc(&sk->sk_drops);
81622+ atomic_inc_unchecked(&sk->sk_drops);
81623 kfree_skb(skb);
81624 return NET_RX_DROP;
81625 }
81626@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
81627
81628 if (inet->hdrincl) {
81629 if (skb_checksum_complete(skb)) {
81630- atomic_inc(&sk->sk_drops);
81631+ atomic_inc_unchecked(&sk->sk_drops);
81632 kfree_skb(skb);
81633 return NET_RX_DROP;
81634 }
81635@@ -604,7 +604,7 @@ out:
81636 return err;
81637 }
81638
81639-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
81640+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
81641 struct flowi6 *fl6, struct dst_entry **dstp,
81642 unsigned int flags)
81643 {
81644@@ -916,12 +916,15 @@ do_confirm:
81645 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
81646 char __user *optval, int optlen)
81647 {
81648+ struct icmp6_filter filter;
81649+
81650 switch (optname) {
81651 case ICMPV6_FILTER:
81652 if (optlen > sizeof(struct icmp6_filter))
81653 optlen = sizeof(struct icmp6_filter);
81654- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
81655+ if (copy_from_user(&filter, optval, optlen))
81656 return -EFAULT;
81657+ raw6_sk(sk)->filter = filter;
81658 return 0;
81659 default:
81660 return -ENOPROTOOPT;
81661@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
81662 char __user *optval, int __user *optlen)
81663 {
81664 int len;
81665+ struct icmp6_filter filter;
81666
81667 switch (optname) {
81668 case ICMPV6_FILTER:
81669@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
81670 len = sizeof(struct icmp6_filter);
81671 if (put_user(len, optlen))
81672 return -EFAULT;
81673- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
81674+ filter = raw6_sk(sk)->filter;
81675+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
81676 return -EFAULT;
81677 return 0;
81678 default:
81679@@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
81680 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
81681 0,
81682 sock_i_ino(sp),
81683- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
81684+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
81685 }
81686
81687 static int raw6_seq_show(struct seq_file *seq, void *v)
81688diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
81689index 4f435371..5de9da7 100644
81690--- a/net/ipv6/tcp_ipv6.c
81691+++ b/net/ipv6/tcp_ipv6.c
81692@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
81693 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
81694 }
81695
81696+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81697+extern int grsec_enable_blackhole;
81698+#endif
81699+
81700 static void tcp_v6_hash(struct sock *sk)
81701 {
81702 if (sk->sk_state != TCP_CLOSE) {
81703@@ -1433,6 +1437,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
81704 return 0;
81705
81706 reset:
81707+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81708+ if (!grsec_enable_blackhole)
81709+#endif
81710 tcp_v6_send_reset(sk, skb);
81711 discard:
81712 if (opt_skb)
81713@@ -1514,12 +1521,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
81714 TCP_SKB_CB(skb)->sacked = 0;
81715
81716 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
81717- if (!sk)
81718+ if (!sk) {
81719+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81720+ ret = 1;
81721+#endif
81722 goto no_tcp_socket;
81723+ }
81724
81725 process:
81726- if (sk->sk_state == TCP_TIME_WAIT)
81727+ if (sk->sk_state == TCP_TIME_WAIT) {
81728+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81729+ ret = 2;
81730+#endif
81731 goto do_time_wait;
81732+ }
81733
81734 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
81735 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
81736@@ -1568,6 +1583,10 @@ no_tcp_socket:
81737 bad_packet:
81738 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
81739 } else {
81740+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81741+ if (!grsec_enable_blackhole || (ret == 1 &&
81742+ (skb->dev->flags & IFF_LOOPBACK)))
81743+#endif
81744 tcp_v6_send_reset(NULL, skb);
81745 }
81746
81747diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
81748index fb08329..2d6919e 100644
81749--- a/net/ipv6/udp.c
81750+++ b/net/ipv6/udp.c
81751@@ -51,6 +51,10 @@
81752 #include <trace/events/skb.h>
81753 #include "udp_impl.h"
81754
81755+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81756+extern int grsec_enable_blackhole;
81757+#endif
81758+
81759 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
81760 {
81761 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
81762@@ -395,7 +399,7 @@ try_again:
81763 if (unlikely(err)) {
81764 trace_kfree_skb(skb, udpv6_recvmsg);
81765 if (!peeked) {
81766- atomic_inc(&sk->sk_drops);
81767+ atomic_inc_unchecked(&sk->sk_drops);
81768 if (is_udp4)
81769 UDP_INC_STATS_USER(sock_net(sk),
81770 UDP_MIB_INERRORS,
81771@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
81772 return rc;
81773 drop:
81774 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
81775- atomic_inc(&sk->sk_drops);
81776+ atomic_inc_unchecked(&sk->sk_drops);
81777 kfree_skb(skb);
81778 return -1;
81779 }
81780@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
81781 if (likely(skb1 == NULL))
81782 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
81783 if (!skb1) {
81784- atomic_inc(&sk->sk_drops);
81785+ atomic_inc_unchecked(&sk->sk_drops);
81786 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
81787 IS_UDPLITE(sk));
81788 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81789@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
81790 goto discard;
81791
81792 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
81793+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81794+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
81795+#endif
81796 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
81797
81798 kfree_skb(skb);
81799@@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
81800 0,
81801 sock_i_ino(sp),
81802 atomic_read(&sp->sk_refcnt), sp,
81803- atomic_read(&sp->sk_drops));
81804+ atomic_read_unchecked(&sp->sk_drops));
81805 }
81806
81807 int udp6_seq_show(struct seq_file *seq, void *v)
81808diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
81809index a68c88c..d55b0c5 100644
81810--- a/net/irda/ircomm/ircomm_tty.c
81811+++ b/net/irda/ircomm/ircomm_tty.c
81812@@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81813 add_wait_queue(&port->open_wait, &wait);
81814
81815 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
81816- __FILE__, __LINE__, tty->driver->name, port->count);
81817+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81818
81819 spin_lock_irqsave(&port->lock, flags);
81820 if (!tty_hung_up_p(filp)) {
81821 extra_count = 1;
81822- port->count--;
81823+ atomic_dec(&port->count);
81824 }
81825 spin_unlock_irqrestore(&port->lock, flags);
81826 port->blocked_open++;
81827@@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81828 }
81829
81830 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
81831- __FILE__, __LINE__, tty->driver->name, port->count);
81832+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81833
81834 schedule();
81835 }
81836@@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81837 if (extra_count) {
81838 /* ++ is not atomic, so this should be protected - Jean II */
81839 spin_lock_irqsave(&port->lock, flags);
81840- port->count++;
81841+ atomic_inc(&port->count);
81842 spin_unlock_irqrestore(&port->lock, flags);
81843 }
81844 port->blocked_open--;
81845
81846 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
81847- __FILE__, __LINE__, tty->driver->name, port->count);
81848+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81849
81850 if (!retval)
81851 port->flags |= ASYNC_NORMAL_ACTIVE;
81852@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
81853
81854 /* ++ is not atomic, so this should be protected - Jean II */
81855 spin_lock_irqsave(&self->port.lock, flags);
81856- self->port.count++;
81857+ atomic_inc(&self->port.count);
81858 spin_unlock_irqrestore(&self->port.lock, flags);
81859 tty_port_tty_set(&self->port, tty);
81860
81861 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
81862- self->line, self->port.count);
81863+ self->line, atomic_read(&self->port.count));
81864
81865 /* Not really used by us, but lets do it anyway */
81866 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
81867@@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
81868 tty_kref_put(port->tty);
81869 }
81870 port->tty = NULL;
81871- port->count = 0;
81872+ atomic_set(&port->count, 0);
81873 spin_unlock_irqrestore(&port->lock, flags);
81874
81875 wake_up_interruptible(&port->open_wait);
81876@@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
81877 seq_putc(m, '\n');
81878
81879 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
81880- seq_printf(m, "Open count: %d\n", self->port.count);
81881+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
81882 seq_printf(m, "Max data size: %d\n", self->max_data_size);
81883 seq_printf(m, "Max header size: %d\n", self->max_header_size);
81884
81885diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
81886index cd6f7a9..e63fe89 100644
81887--- a/net/iucv/af_iucv.c
81888+++ b/net/iucv/af_iucv.c
81889@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
81890
81891 write_lock_bh(&iucv_sk_list.lock);
81892
81893- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
81894+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81895 while (__iucv_get_sock_by_name(name)) {
81896 sprintf(name, "%08x",
81897- atomic_inc_return(&iucv_sk_list.autobind_name));
81898+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81899 }
81900
81901 write_unlock_bh(&iucv_sk_list.lock);
81902diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
81903index df08250..02021fe 100644
81904--- a/net/iucv/iucv.c
81905+++ b/net/iucv/iucv.c
81906@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
81907 return NOTIFY_OK;
81908 }
81909
81910-static struct notifier_block __refdata iucv_cpu_notifier = {
81911+static struct notifier_block iucv_cpu_notifier = {
81912 .notifier_call = iucv_cpu_notify,
81913 };
81914
81915diff --git a/net/key/af_key.c b/net/key/af_key.c
81916index 5b426a6..970032b 100644
81917--- a/net/key/af_key.c
81918+++ b/net/key/af_key.c
81919@@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
81920 static u32 get_acqseq(void)
81921 {
81922 u32 res;
81923- static atomic_t acqseq;
81924+ static atomic_unchecked_t acqseq;
81925
81926 do {
81927- res = atomic_inc_return(&acqseq);
81928+ res = atomic_inc_return_unchecked(&acqseq);
81929 } while (!res);
81930 return res;
81931 }
81932diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
81933index 0479c64..d031db6 100644
81934--- a/net/mac80211/cfg.c
81935+++ b/net/mac80211/cfg.c
81936@@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
81937 ret = ieee80211_vif_use_channel(sdata, chandef,
81938 IEEE80211_CHANCTX_EXCLUSIVE);
81939 }
81940- } else if (local->open_count == local->monitors) {
81941+ } else if (local_read(&local->open_count) == local->monitors) {
81942 local->_oper_channel = chandef->chan;
81943 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
81944 ieee80211_hw_config(local, 0);
81945@@ -2716,7 +2716,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
81946 else
81947 local->probe_req_reg--;
81948
81949- if (!local->open_count)
81950+ if (!local_read(&local->open_count))
81951 break;
81952
81953 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
81954diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
81955index 2ed065c..948177f 100644
81956--- a/net/mac80211/ieee80211_i.h
81957+++ b/net/mac80211/ieee80211_i.h
81958@@ -28,6 +28,7 @@
81959 #include <net/ieee80211_radiotap.h>
81960 #include <net/cfg80211.h>
81961 #include <net/mac80211.h>
81962+#include <asm/local.h>
81963 #include "key.h"
81964 #include "sta_info.h"
81965 #include "debug.h"
81966@@ -909,7 +910,7 @@ struct ieee80211_local {
81967 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
81968 spinlock_t queue_stop_reason_lock;
81969
81970- int open_count;
81971+ local_t open_count;
81972 int monitors, cooked_mntrs;
81973 /* number of interfaces with corresponding FIF_ flags */
81974 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
81975diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
81976index 8be854e..ad72a69 100644
81977--- a/net/mac80211/iface.c
81978+++ b/net/mac80211/iface.c
81979@@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81980 break;
81981 }
81982
81983- if (local->open_count == 0) {
81984+ if (local_read(&local->open_count) == 0) {
81985 res = drv_start(local);
81986 if (res)
81987 goto err_del_bss;
81988@@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81989 break;
81990 }
81991
81992- if (local->monitors == 0 && local->open_count == 0) {
81993+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
81994 res = ieee80211_add_virtual_monitor(local);
81995 if (res)
81996 goto err_stop;
81997@@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81998 mutex_unlock(&local->mtx);
81999
82000 if (coming_up)
82001- local->open_count++;
82002+ local_inc(&local->open_count);
82003
82004 if (hw_reconf_flags)
82005 ieee80211_hw_config(local, hw_reconf_flags);
82006@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
82007 err_del_interface:
82008 drv_remove_interface(local, sdata);
82009 err_stop:
82010- if (!local->open_count)
82011+ if (!local_read(&local->open_count))
82012 drv_stop(local);
82013 err_del_bss:
82014 sdata->bss = NULL;
82015@@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
82016 }
82017
82018 if (going_down)
82019- local->open_count--;
82020+ local_dec(&local->open_count);
82021
82022 switch (sdata->vif.type) {
82023 case NL80211_IFTYPE_AP_VLAN:
82024@@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
82025
82026 ieee80211_recalc_ps(local, -1);
82027
82028- if (local->open_count == 0) {
82029+ if (local_read(&local->open_count) == 0) {
82030 if (local->ops->napi_poll)
82031 napi_disable(&local->napi);
82032 ieee80211_clear_tx_pending(local);
82033@@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
82034 }
82035 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
82036
82037- if (local->monitors == local->open_count && local->monitors > 0)
82038+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
82039 ieee80211_add_virtual_monitor(local);
82040 }
82041
82042diff --git a/net/mac80211/main.c b/net/mac80211/main.c
82043index 1b087ff..bf600e9 100644
82044--- a/net/mac80211/main.c
82045+++ b/net/mac80211/main.c
82046@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
82047 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
82048 IEEE80211_CONF_CHANGE_POWER);
82049
82050- if (changed && local->open_count) {
82051+ if (changed && local_read(&local->open_count)) {
82052 ret = drv_config(local, changed);
82053 /*
82054 * Goal:
82055diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
82056index 79a48f3..5e185c9 100644
82057--- a/net/mac80211/pm.c
82058+++ b/net/mac80211/pm.c
82059@@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
82060 struct sta_info *sta;
82061 struct ieee80211_chanctx *ctx;
82062
82063- if (!local->open_count)
82064+ if (!local_read(&local->open_count))
82065 goto suspend;
82066
82067 ieee80211_scan_cancel(local);
82068@@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
82069 cancel_work_sync(&local->dynamic_ps_enable_work);
82070 del_timer_sync(&local->dynamic_ps_timer);
82071
82072- local->wowlan = wowlan && local->open_count;
82073+ local->wowlan = wowlan && local_read(&local->open_count);
82074 if (local->wowlan) {
82075 int err = drv_suspend(local, wowlan);
82076 if (err < 0) {
82077@@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
82078 mutex_unlock(&local->chanctx_mtx);
82079
82080 /* stop hardware - this must stop RX */
82081- if (local->open_count)
82082+ if (local_read(&local->open_count))
82083 ieee80211_stop_device(local);
82084
82085 suspend:
82086diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
82087index dd88381..eef4dd6 100644
82088--- a/net/mac80211/rate.c
82089+++ b/net/mac80211/rate.c
82090@@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
82091
82092 ASSERT_RTNL();
82093
82094- if (local->open_count)
82095+ if (local_read(&local->open_count))
82096 return -EBUSY;
82097
82098 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
82099diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
82100index c97a065..ff61928 100644
82101--- a/net/mac80211/rc80211_pid_debugfs.c
82102+++ b/net/mac80211/rc80211_pid_debugfs.c
82103@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
82104
82105 spin_unlock_irqrestore(&events->lock, status);
82106
82107- if (copy_to_user(buf, pb, p))
82108+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
82109 return -EFAULT;
82110
82111 return p;
82112diff --git a/net/mac80211/util.c b/net/mac80211/util.c
82113index f11e8c5..08d0013 100644
82114--- a/net/mac80211/util.c
82115+++ b/net/mac80211/util.c
82116@@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
82117 }
82118 #endif
82119 /* everything else happens only if HW was up & running */
82120- if (!local->open_count)
82121+ if (!local_read(&local->open_count))
82122 goto wake_up;
82123
82124 /*
82125diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
82126index 49e96df..63a51c3 100644
82127--- a/net/netfilter/Kconfig
82128+++ b/net/netfilter/Kconfig
82129@@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
82130
82131 To compile it as a module, choose M here. If unsure, say N.
82132
82133+config NETFILTER_XT_MATCH_GRADM
82134+ tristate '"gradm" match support'
82135+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
82136+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
82137+ ---help---
82138+ The gradm match allows to match on grsecurity RBAC being enabled.
82139+ It is useful when iptables rules are applied early on bootup to
82140+ prevent connections to the machine (except from a trusted host)
82141+ while the RBAC system is disabled.
82142+
82143 config NETFILTER_XT_MATCH_HASHLIMIT
82144 tristate '"hashlimit" match support'
82145 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
82146diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
82147index 3259697..54d5393 100644
82148--- a/net/netfilter/Makefile
82149+++ b/net/netfilter/Makefile
82150@@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
82151 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
82152 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
82153 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
82154+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
82155 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
82156 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
82157 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
82158diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
82159index 30e764a..c3b6a9d 100644
82160--- a/net/netfilter/ipvs/ip_vs_conn.c
82161+++ b/net/netfilter/ipvs/ip_vs_conn.c
82162@@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
82163 /* Increase the refcnt counter of the dest */
82164 atomic_inc(&dest->refcnt);
82165
82166- conn_flags = atomic_read(&dest->conn_flags);
82167+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
82168 if (cp->protocol != IPPROTO_UDP)
82169 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
82170 flags = cp->flags;
82171@@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
82172 atomic_set(&cp->refcnt, 1);
82173
82174 atomic_set(&cp->n_control, 0);
82175- atomic_set(&cp->in_pkts, 0);
82176+ atomic_set_unchecked(&cp->in_pkts, 0);
82177
82178 atomic_inc(&ipvs->conn_count);
82179 if (flags & IP_VS_CONN_F_NO_CPORT)
82180@@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
82181
82182 /* Don't drop the entry if its number of incoming packets is not
82183 located in [0, 8] */
82184- i = atomic_read(&cp->in_pkts);
82185+ i = atomic_read_unchecked(&cp->in_pkts);
82186 if (i > 8 || i < 0) return 0;
82187
82188 if (!todrop_rate[i]) return 0;
82189diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
82190index 47edf5a..235b07d 100644
82191--- a/net/netfilter/ipvs/ip_vs_core.c
82192+++ b/net/netfilter/ipvs/ip_vs_core.c
82193@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
82194 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
82195 /* do not touch skb anymore */
82196
82197- atomic_inc(&cp->in_pkts);
82198+ atomic_inc_unchecked(&cp->in_pkts);
82199 ip_vs_conn_put(cp);
82200 return ret;
82201 }
82202@@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
82203 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
82204 pkts = sysctl_sync_threshold(ipvs);
82205 else
82206- pkts = atomic_add_return(1, &cp->in_pkts);
82207+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
82208
82209 if (ipvs->sync_state & IP_VS_STATE_MASTER)
82210 ip_vs_sync_conn(net, cp, pkts);
82211diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
82212index ec664cb..cd576ab 100644
82213--- a/net/netfilter/ipvs/ip_vs_ctl.c
82214+++ b/net/netfilter/ipvs/ip_vs_ctl.c
82215@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
82216 ip_vs_rs_hash(ipvs, dest);
82217 write_unlock_bh(&ipvs->rs_lock);
82218 }
82219- atomic_set(&dest->conn_flags, conn_flags);
82220+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
82221
82222 /* bind the service */
82223 if (!dest->svc) {
82224@@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
82225 " %-7s %-6d %-10d %-10d\n",
82226 &dest->addr.in6,
82227 ntohs(dest->port),
82228- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
82229+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
82230 atomic_read(&dest->weight),
82231 atomic_read(&dest->activeconns),
82232 atomic_read(&dest->inactconns));
82233@@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
82234 "%-7s %-6d %-10d %-10d\n",
82235 ntohl(dest->addr.ip),
82236 ntohs(dest->port),
82237- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
82238+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
82239 atomic_read(&dest->weight),
82240 atomic_read(&dest->activeconns),
82241 atomic_read(&dest->inactconns));
82242@@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
82243
82244 entry.addr = dest->addr.ip;
82245 entry.port = dest->port;
82246- entry.conn_flags = atomic_read(&dest->conn_flags);
82247+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
82248 entry.weight = atomic_read(&dest->weight);
82249 entry.u_threshold = dest->u_threshold;
82250 entry.l_threshold = dest->l_threshold;
82251@@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
82252 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
82253 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
82254 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
82255- (atomic_read(&dest->conn_flags) &
82256+ (atomic_read_unchecked(&dest->conn_flags) &
82257 IP_VS_CONN_F_FWD_MASK)) ||
82258 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
82259 atomic_read(&dest->weight)) ||
82260diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
82261index 44fd10c..2a163b3 100644
82262--- a/net/netfilter/ipvs/ip_vs_sync.c
82263+++ b/net/netfilter/ipvs/ip_vs_sync.c
82264@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
82265 cp = cp->control;
82266 if (cp) {
82267 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
82268- pkts = atomic_add_return(1, &cp->in_pkts);
82269+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
82270 else
82271 pkts = sysctl_sync_threshold(ipvs);
82272 ip_vs_sync_conn(net, cp->control, pkts);
82273@@ -758,7 +758,7 @@ control:
82274 if (!cp)
82275 return;
82276 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
82277- pkts = atomic_add_return(1, &cp->in_pkts);
82278+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
82279 else
82280 pkts = sysctl_sync_threshold(ipvs);
82281 goto sloop;
82282@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
82283
82284 if (opt)
82285 memcpy(&cp->in_seq, opt, sizeof(*opt));
82286- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
82287+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
82288 cp->state = state;
82289 cp->old_state = cp->state;
82290 /*
82291diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
82292index ee6b7a9..f9a89f6 100644
82293--- a/net/netfilter/ipvs/ip_vs_xmit.c
82294+++ b/net/netfilter/ipvs/ip_vs_xmit.c
82295@@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
82296 else
82297 rc = NF_ACCEPT;
82298 /* do not touch skb anymore */
82299- atomic_inc(&cp->in_pkts);
82300+ atomic_inc_unchecked(&cp->in_pkts);
82301 goto out;
82302 }
82303
82304@@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
82305 else
82306 rc = NF_ACCEPT;
82307 /* do not touch skb anymore */
82308- atomic_inc(&cp->in_pkts);
82309+ atomic_inc_unchecked(&cp->in_pkts);
82310 goto out;
82311 }
82312
82313diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
82314index e4a0c4f..c263f28 100644
82315--- a/net/netfilter/nf_conntrack_core.c
82316+++ b/net/netfilter/nf_conntrack_core.c
82317@@ -1529,6 +1529,10 @@ err_extend:
82318 #define DYING_NULLS_VAL ((1<<30)+1)
82319 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
82320
82321+#ifdef CONFIG_GRKERNSEC_HIDESYM
82322+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
82323+#endif
82324+
82325 static int nf_conntrack_init_net(struct net *net)
82326 {
82327 int ret;
82328@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
82329 goto err_stat;
82330 }
82331
82332+#ifdef CONFIG_GRKERNSEC_HIDESYM
82333+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
82334+#else
82335 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
82336+#endif
82337 if (!net->ct.slabname) {
82338 ret = -ENOMEM;
82339 goto err_slabname;
82340diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
82341index 92fd8ec..3f6ea4b 100644
82342--- a/net/netfilter/nfnetlink_log.c
82343+++ b/net/netfilter/nfnetlink_log.c
82344@@ -72,7 +72,7 @@ struct nfulnl_instance {
82345 };
82346
82347 static DEFINE_SPINLOCK(instances_lock);
82348-static atomic_t global_seq;
82349+static atomic_unchecked_t global_seq;
82350
82351 #define INSTANCE_BUCKETS 16
82352 static struct hlist_head instance_table[INSTANCE_BUCKETS];
82353@@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
82354 /* global sequence number */
82355 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
82356 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
82357- htonl(atomic_inc_return(&global_seq))))
82358+ htonl(atomic_inc_return_unchecked(&global_seq))))
82359 goto nla_put_failure;
82360
82361 if (data_len) {
82362diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
82363new file mode 100644
82364index 0000000..c566332
82365--- /dev/null
82366+++ b/net/netfilter/xt_gradm.c
82367@@ -0,0 +1,51 @@
82368+/*
82369+ * gradm match for netfilter
82370