]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.8.1-201302281903.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.1-201302281903.patch
CommitLineData
e4bbbf63
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 746c856..c014cfa 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 7df49fa..38b62bf 100644
5498--- a/arch/parisc/include/asm/pgtable.h
5499+++ b/arch/parisc/include/asm/pgtable.h
5500@@ -218,6 +218,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
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 5062ff3..e0b75f3 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 0694d09..b58b3aa 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@@ -1542,6 +1543,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@@ -1599,6 +1601,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@@ -1662,6 +1665,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@@ -1737,9 +1741,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 b70709b..1d8d02a 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 8a7c48b..72effc2 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 7339a4b..445aaba 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 80aa1fc..1ede041 100644
33872--- a/drivers/gpu/drm/i915/intel_display.c
33873+++ b/drivers/gpu/drm/i915/intel_display.c
33874@@ -2255,7 +2255,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@@ -7122,8 +7122,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@@ -7490,7 +7489,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@@ -7507,7 +7506,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 508570e..f706dc7 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 bfd6771..e0d93c4 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@@ -2936,7 +2936,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/uio/uio.c b/drivers/uio/uio.c
41525index 5110f36..8dc0a74 100644
41526--- a/drivers/uio/uio.c
41527+++ b/drivers/uio/uio.c
41528@@ -25,6 +25,7 @@
41529 #include <linux/kobject.h>
41530 #include <linux/cdev.h>
41531 #include <linux/uio_driver.h>
41532+#include <asm/local.h>
41533
41534 #define UIO_MAX_DEVICES (1U << MINORBITS)
41535
41536@@ -32,10 +33,10 @@ struct uio_device {
41537 struct module *owner;
41538 struct device *dev;
41539 int minor;
41540- atomic_t event;
41541+ atomic_unchecked_t event;
41542 struct fasync_struct *async_queue;
41543 wait_queue_head_t wait;
41544- int vma_count;
41545+ local_t vma_count;
41546 struct uio_info *info;
41547 struct kobject *map_dir;
41548 struct kobject *portio_dir;
41549@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
41550 struct device_attribute *attr, char *buf)
41551 {
41552 struct uio_device *idev = dev_get_drvdata(dev);
41553- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
41554+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
41555 }
41556
41557 static struct device_attribute uio_class_attributes[] = {
41558@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
41559 {
41560 struct uio_device *idev = info->uio_dev;
41561
41562- atomic_inc(&idev->event);
41563+ atomic_inc_unchecked(&idev->event);
41564 wake_up_interruptible(&idev->wait);
41565 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
41566 }
41567@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
41568 }
41569
41570 listener->dev = idev;
41571- listener->event_count = atomic_read(&idev->event);
41572+ listener->event_count = atomic_read_unchecked(&idev->event);
41573 filep->private_data = listener;
41574
41575 if (idev->info->open) {
41576@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
41577 return -EIO;
41578
41579 poll_wait(filep, &idev->wait, wait);
41580- if (listener->event_count != atomic_read(&idev->event))
41581+ if (listener->event_count != atomic_read_unchecked(&idev->event))
41582 return POLLIN | POLLRDNORM;
41583 return 0;
41584 }
41585@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
41586 do {
41587 set_current_state(TASK_INTERRUPTIBLE);
41588
41589- event_count = atomic_read(&idev->event);
41590+ event_count = atomic_read_unchecked(&idev->event);
41591 if (event_count != listener->event_count) {
41592 if (copy_to_user(buf, &event_count, count))
41593 retval = -EFAULT;
41594@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
41595 static void uio_vma_open(struct vm_area_struct *vma)
41596 {
41597 struct uio_device *idev = vma->vm_private_data;
41598- idev->vma_count++;
41599+ local_inc(&idev->vma_count);
41600 }
41601
41602 static void uio_vma_close(struct vm_area_struct *vma)
41603 {
41604 struct uio_device *idev = vma->vm_private_data;
41605- idev->vma_count--;
41606+ local_dec(&idev->vma_count);
41607 }
41608
41609 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41610@@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
41611 idev->owner = owner;
41612 idev->info = info;
41613 init_waitqueue_head(&idev->wait);
41614- atomic_set(&idev->event, 0);
41615+ atomic_set_unchecked(&idev->event, 0);
41616
41617 ret = uio_get_minor(idev);
41618 if (ret)
41619diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
41620index b7eb86a..36d28af 100644
41621--- a/drivers/usb/atm/cxacru.c
41622+++ b/drivers/usb/atm/cxacru.c
41623@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
41624 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
41625 if (ret < 2)
41626 return -EINVAL;
41627- if (index < 0 || index > 0x7f)
41628+ if (index > 0x7f)
41629 return -EINVAL;
41630 pos += tmp;
41631
41632diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
41633index 35f10bf..6a38a0b 100644
41634--- a/drivers/usb/atm/usbatm.c
41635+++ b/drivers/usb/atm/usbatm.c
41636@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41637 if (printk_ratelimit())
41638 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
41639 __func__, vpi, vci);
41640- atomic_inc(&vcc->stats->rx_err);
41641+ atomic_inc_unchecked(&vcc->stats->rx_err);
41642 return;
41643 }
41644
41645@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41646 if (length > ATM_MAX_AAL5_PDU) {
41647 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
41648 __func__, length, vcc);
41649- atomic_inc(&vcc->stats->rx_err);
41650+ atomic_inc_unchecked(&vcc->stats->rx_err);
41651 goto out;
41652 }
41653
41654@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41655 if (sarb->len < pdu_length) {
41656 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
41657 __func__, pdu_length, sarb->len, vcc);
41658- atomic_inc(&vcc->stats->rx_err);
41659+ atomic_inc_unchecked(&vcc->stats->rx_err);
41660 goto out;
41661 }
41662
41663 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
41664 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
41665 __func__, vcc);
41666- atomic_inc(&vcc->stats->rx_err);
41667+ atomic_inc_unchecked(&vcc->stats->rx_err);
41668 goto out;
41669 }
41670
41671@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41672 if (printk_ratelimit())
41673 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
41674 __func__, length);
41675- atomic_inc(&vcc->stats->rx_drop);
41676+ atomic_inc_unchecked(&vcc->stats->rx_drop);
41677 goto out;
41678 }
41679
41680@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41681
41682 vcc->push(vcc, skb);
41683
41684- atomic_inc(&vcc->stats->rx);
41685+ atomic_inc_unchecked(&vcc->stats->rx);
41686 out:
41687 skb_trim(sarb, 0);
41688 }
41689@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
41690 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
41691
41692 usbatm_pop(vcc, skb);
41693- atomic_inc(&vcc->stats->tx);
41694+ atomic_inc_unchecked(&vcc->stats->tx);
41695
41696 skb = skb_dequeue(&instance->sndqueue);
41697 }
41698@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
41699 if (!left--)
41700 return sprintf(page,
41701 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
41702- atomic_read(&atm_dev->stats.aal5.tx),
41703- atomic_read(&atm_dev->stats.aal5.tx_err),
41704- atomic_read(&atm_dev->stats.aal5.rx),
41705- atomic_read(&atm_dev->stats.aal5.rx_err),
41706- atomic_read(&atm_dev->stats.aal5.rx_drop));
41707+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
41708+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
41709+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
41710+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
41711+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
41712
41713 if (!left--) {
41714 if (instance->disconnected)
41715diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
41716index cbacea9..246cccd 100644
41717--- a/drivers/usb/core/devices.c
41718+++ b/drivers/usb/core/devices.c
41719@@ -126,7 +126,7 @@ static const char format_endpt[] =
41720 * time it gets called.
41721 */
41722 static struct device_connect_event {
41723- atomic_t count;
41724+ atomic_unchecked_t count;
41725 wait_queue_head_t wait;
41726 } device_event = {
41727 .count = ATOMIC_INIT(1),
41728@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
41729
41730 void usbfs_conn_disc_event(void)
41731 {
41732- atomic_add(2, &device_event.count);
41733+ atomic_add_unchecked(2, &device_event.count);
41734 wake_up(&device_event.wait);
41735 }
41736
41737@@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
41738
41739 poll_wait(file, &device_event.wait, wait);
41740
41741- event_count = atomic_read(&device_event.count);
41742+ event_count = atomic_read_unchecked(&device_event.count);
41743 if (file->f_version != event_count) {
41744 file->f_version = event_count;
41745 return POLLIN | POLLRDNORM;
41746diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
41747index 8e64adf..9a33a3c 100644
41748--- a/drivers/usb/core/hcd.c
41749+++ b/drivers/usb/core/hcd.c
41750@@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41751 */
41752 usb_get_urb(urb);
41753 atomic_inc(&urb->use_count);
41754- atomic_inc(&urb->dev->urbnum);
41755+ atomic_inc_unchecked(&urb->dev->urbnum);
41756 usbmon_urb_submit(&hcd->self, urb);
41757
41758 /* NOTE requirements on root-hub callers (usbfs and the hub
41759@@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41760 urb->hcpriv = NULL;
41761 INIT_LIST_HEAD(&urb->urb_list);
41762 atomic_dec(&urb->use_count);
41763- atomic_dec(&urb->dev->urbnum);
41764+ atomic_dec_unchecked(&urb->dev->urbnum);
41765 if (atomic_read(&urb->reject))
41766 wake_up(&usb_kill_urb_queue);
41767 usb_put_urb(urb);
41768diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
41769index 818e4a0..0fc9589 100644
41770--- a/drivers/usb/core/sysfs.c
41771+++ b/drivers/usb/core/sysfs.c
41772@@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
41773 struct usb_device *udev;
41774
41775 udev = to_usb_device(dev);
41776- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
41777+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
41778 }
41779 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
41780
41781diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
41782index f81b925..78d22ec 100644
41783--- a/drivers/usb/core/usb.c
41784+++ b/drivers/usb/core/usb.c
41785@@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
41786 set_dev_node(&dev->dev, dev_to_node(bus->controller));
41787 dev->state = USB_STATE_ATTACHED;
41788 dev->lpm_disable_count = 1;
41789- atomic_set(&dev->urbnum, 0);
41790+ atomic_set_unchecked(&dev->urbnum, 0);
41791
41792 INIT_LIST_HEAD(&dev->ep0.urb_list);
41793 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
41794diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
41795index 5e29dde..eca992f 100644
41796--- a/drivers/usb/early/ehci-dbgp.c
41797+++ b/drivers/usb/early/ehci-dbgp.c
41798@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
41799
41800 #ifdef CONFIG_KGDB
41801 static struct kgdb_io kgdbdbgp_io_ops;
41802-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
41803+static struct kgdb_io kgdbdbgp_io_ops_console;
41804+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
41805 #else
41806 #define dbgp_kgdb_mode (0)
41807 #endif
41808@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
41809 .write_char = kgdbdbgp_write_char,
41810 };
41811
41812+static struct kgdb_io kgdbdbgp_io_ops_console = {
41813+ .name = "kgdbdbgp",
41814+ .read_char = kgdbdbgp_read_char,
41815+ .write_char = kgdbdbgp_write_char,
41816+ .is_console = 1
41817+};
41818+
41819 static int kgdbdbgp_wait_time;
41820
41821 static int __init kgdbdbgp_parse_config(char *str)
41822@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
41823 ptr++;
41824 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
41825 }
41826- kgdb_register_io_module(&kgdbdbgp_io_ops);
41827- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
41828+ if (early_dbgp_console.index != -1)
41829+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
41830+ else
41831+ kgdb_register_io_module(&kgdbdbgp_io_ops);
41832
41833 return 0;
41834 }
41835diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
41836index 598dcc1..032dd4f 100644
41837--- a/drivers/usb/gadget/u_serial.c
41838+++ b/drivers/usb/gadget/u_serial.c
41839@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41840 spin_lock_irq(&port->port_lock);
41841
41842 /* already open? Great. */
41843- if (port->port.count) {
41844+ if (atomic_read(&port->port.count)) {
41845 status = 0;
41846- port->port.count++;
41847+ atomic_inc(&port->port.count);
41848
41849 /* currently opening/closing? wait ... */
41850 } else if (port->openclose) {
41851@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41852 tty->driver_data = port;
41853 port->port.tty = tty;
41854
41855- port->port.count = 1;
41856+ atomic_set(&port->port.count, 1);
41857 port->openclose = false;
41858
41859 /* if connected, start the I/O stream */
41860@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41861
41862 spin_lock_irq(&port->port_lock);
41863
41864- if (port->port.count != 1) {
41865- if (port->port.count == 0)
41866+ if (atomic_read(&port->port.count) != 1) {
41867+ if (atomic_read(&port->port.count) == 0)
41868 WARN_ON(1);
41869 else
41870- --port->port.count;
41871+ atomic_dec(&port->port.count);
41872 goto exit;
41873 }
41874
41875@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41876 * and sleep if necessary
41877 */
41878 port->openclose = true;
41879- port->port.count = 0;
41880+ atomic_set(&port->port.count, 0);
41881
41882 gser = port->port_usb;
41883 if (gser && gser->disconnect)
41884@@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
41885 int cond;
41886
41887 spin_lock_irq(&port->port_lock);
41888- cond = (port->port.count == 0) && !port->openclose;
41889+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
41890 spin_unlock_irq(&port->port_lock);
41891 return cond;
41892 }
41893@@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
41894 /* if it's already open, start I/O ... and notify the serial
41895 * protocol about open/close status (connect/disconnect).
41896 */
41897- if (port->port.count) {
41898+ if (atomic_read(&port->port.count)) {
41899 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
41900 gs_start_io(port);
41901 if (gser->connect)
41902@@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
41903
41904 port->port_usb = NULL;
41905 gser->ioport = NULL;
41906- if (port->port.count > 0 || port->openclose) {
41907+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
41908 wake_up_interruptible(&port->drain_wait);
41909 if (port->port.tty)
41910 tty_hangup(port->port.tty);
41911@@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
41912
41913 /* finally, free any unused/unusable I/O buffers */
41914 spin_lock_irqsave(&port->port_lock, flags);
41915- if (port->port.count == 0 && !port->openclose)
41916+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
41917 gs_buf_free(&port->port_write_buf);
41918 gs_free_requests(gser->out, &port->read_pool, NULL);
41919 gs_free_requests(gser->out, &port->read_queue, NULL);
41920diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
41921index 5f3bcd3..bfca43f 100644
41922--- a/drivers/usb/serial/console.c
41923+++ b/drivers/usb/serial/console.c
41924@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
41925
41926 info->port = port;
41927
41928- ++port->port.count;
41929+ atomic_inc(&port->port.count);
41930 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
41931 if (serial->type->set_termios) {
41932 /*
41933@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
41934 }
41935 /* Now that any required fake tty operations are completed restore
41936 * the tty port count */
41937- --port->port.count;
41938+ atomic_dec(&port->port.count);
41939 /* The console is special in terms of closing the device so
41940 * indicate this port is now acting as a system console. */
41941 port->port.console = 1;
41942@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
41943 free_tty:
41944 kfree(tty);
41945 reset_open_count:
41946- port->port.count = 0;
41947+ atomic_set(&port->port.count, 0);
41948 usb_autopm_put_interface(serial->interface);
41949 error_get_interface:
41950 usb_serial_put(serial);
41951diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
41952index d6bea3e..60b250e 100644
41953--- a/drivers/usb/wusbcore/wa-hc.h
41954+++ b/drivers/usb/wusbcore/wa-hc.h
41955@@ -192,7 +192,7 @@ struct wahc {
41956 struct list_head xfer_delayed_list;
41957 spinlock_t xfer_list_lock;
41958 struct work_struct xfer_work;
41959- atomic_t xfer_id_count;
41960+ atomic_unchecked_t xfer_id_count;
41961 };
41962
41963
41964@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
41965 INIT_LIST_HEAD(&wa->xfer_delayed_list);
41966 spin_lock_init(&wa->xfer_list_lock);
41967 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
41968- atomic_set(&wa->xfer_id_count, 1);
41969+ atomic_set_unchecked(&wa->xfer_id_count, 1);
41970 }
41971
41972 /**
41973diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
41974index 57c01ab..8a05959 100644
41975--- a/drivers/usb/wusbcore/wa-xfer.c
41976+++ b/drivers/usb/wusbcore/wa-xfer.c
41977@@ -296,7 +296,7 @@ out:
41978 */
41979 static void wa_xfer_id_init(struct wa_xfer *xfer)
41980 {
41981- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
41982+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
41983 }
41984
41985 /*
41986diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
41987index 8c55011..eed4ae1a 100644
41988--- a/drivers/video/aty/aty128fb.c
41989+++ b/drivers/video/aty/aty128fb.c
41990@@ -149,7 +149,7 @@ enum {
41991 };
41992
41993 /* Must match above enum */
41994-static char * const r128_family[] = {
41995+static const char * const r128_family[] = {
41996 "AGP",
41997 "PCI",
41998 "PRO AGP",
41999diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
42000index 5c3960d..15cf8fc 100644
42001--- a/drivers/video/fbcmap.c
42002+++ b/drivers/video/fbcmap.c
42003@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
42004 rc = -ENODEV;
42005 goto out;
42006 }
42007- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
42008- !info->fbops->fb_setcmap)) {
42009+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
42010 rc = -EINVAL;
42011 goto out1;
42012 }
42013diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
42014index dc61c12..e29796e 100644
42015--- a/drivers/video/fbmem.c
42016+++ b/drivers/video/fbmem.c
42017@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42018 image->dx += image->width + 8;
42019 }
42020 } else if (rotate == FB_ROTATE_UD) {
42021- for (x = 0; x < num && image->dx >= 0; x++) {
42022+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
42023 info->fbops->fb_imageblit(info, image);
42024 image->dx -= image->width + 8;
42025 }
42026@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42027 image->dy += image->height + 8;
42028 }
42029 } else if (rotate == FB_ROTATE_CCW) {
42030- for (x = 0; x < num && image->dy >= 0; x++) {
42031+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
42032 info->fbops->fb_imageblit(info, image);
42033 image->dy -= image->height + 8;
42034 }
42035@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
42036 return -EFAULT;
42037 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
42038 return -EINVAL;
42039- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
42040+ if (con2fb.framebuffer >= FB_MAX)
42041 return -EINVAL;
42042 if (!registered_fb[con2fb.framebuffer])
42043 request_module("fb%d", con2fb.framebuffer);
42044diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
42045index 7672d2e..b56437f 100644
42046--- a/drivers/video/i810/i810_accel.c
42047+++ b/drivers/video/i810/i810_accel.c
42048@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
42049 }
42050 }
42051 printk("ringbuffer lockup!!!\n");
42052+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
42053 i810_report_error(mmio);
42054 par->dev_flags |= LOCKUP;
42055 info->pixmap.scan_align = 1;
42056diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
42057index 3c14e43..eafa544 100644
42058--- a/drivers/video/logo/logo_linux_clut224.ppm
42059+++ b/drivers/video/logo/logo_linux_clut224.ppm
42060@@ -1,1604 +1,1123 @@
42061 P3
42062-# Standard 224-color Linux logo
42063 80 80
42064 255
42065- 0 0 0 0 0 0 0 0 0 0 0 0
42066- 0 0 0 0 0 0 0 0 0 0 0 0
42067- 0 0 0 0 0 0 0 0 0 0 0 0
42068- 0 0 0 0 0 0 0 0 0 0 0 0
42069- 0 0 0 0 0 0 0 0 0 0 0 0
42070- 0 0 0 0 0 0 0 0 0 0 0 0
42071- 0 0 0 0 0 0 0 0 0 0 0 0
42072- 0 0 0 0 0 0 0 0 0 0 0 0
42073- 0 0 0 0 0 0 0 0 0 0 0 0
42074- 6 6 6 6 6 6 10 10 10 10 10 10
42075- 10 10 10 6 6 6 6 6 6 6 6 6
42076- 0 0 0 0 0 0 0 0 0 0 0 0
42077- 0 0 0 0 0 0 0 0 0 0 0 0
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- 0 0 0 0 0 0 0 0 0 0 0 0
42088- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 10 10 10 14 14 14
42094- 22 22 22 26 26 26 30 30 30 34 34 34
42095- 30 30 30 30 30 30 26 26 26 18 18 18
42096- 14 14 14 10 10 10 6 6 6 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 0 0 1 0 0 1 0 0 0
42107- 0 0 0 0 0 0 0 0 0 0 0 0
42108- 0 0 0 0 0 0 0 0 0 0 0 0
42109- 0 0 0 0 0 0 0 0 0 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- 6 6 6 14 14 14 26 26 26 42 42 42
42114- 54 54 54 66 66 66 78 78 78 78 78 78
42115- 78 78 78 74 74 74 66 66 66 54 54 54
42116- 42 42 42 26 26 26 18 18 18 10 10 10
42117- 6 6 6 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 0 0 0 0 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- 0 0 1 0 0 0 0 0 0 0 0 0
42127- 0 0 0 0 0 0 0 0 0 0 0 0
42128- 0 0 0 0 0 0 0 0 0 0 0 0
42129- 0 0 0 0 0 0 0 0 0 0 0 0
42130- 0 0 0 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 10 10 10
42133- 22 22 22 42 42 42 66 66 66 86 86 86
42134- 66 66 66 38 38 38 38 38 38 22 22 22
42135- 26 26 26 34 34 34 54 54 54 66 66 66
42136- 86 86 86 70 70 70 46 46 46 26 26 26
42137- 14 14 14 6 6 6 0 0 0 0 0 0
42138- 0 0 0 0 0 0 0 0 0 0 0 0
42139- 0 0 0 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 0 0 0
42146- 0 0 1 0 0 1 0 0 1 0 0 0
42147- 0 0 0 0 0 0 0 0 0 0 0 0
42148- 0 0 0 0 0 0 0 0 0 0 0 0
42149- 0 0 0 0 0 0 0 0 0 0 0 0
42150- 0 0 0 0 0 0 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 10 10 10 26 26 26
42153- 50 50 50 82 82 82 58 58 58 6 6 6
42154- 2 2 6 2 2 6 2 2 6 2 2 6
42155- 2 2 6 2 2 6 2 2 6 2 2 6
42156- 6 6 6 54 54 54 86 86 86 66 66 66
42157- 38 38 38 18 18 18 6 6 6 0 0 0
42158- 0 0 0 0 0 0 0 0 0 0 0 0
42159- 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0
42166- 0 0 0 0 0 0 0 0 0 0 0 0
42167- 0 0 0 0 0 0 0 0 0 0 0 0
42168- 0 0 0 0 0 0 0 0 0 0 0 0
42169- 0 0 0 0 0 0 0 0 0 0 0 0
42170- 0 0 0 0 0 0 0 0 0 0 0 0
42171- 0 0 0 0 0 0 0 0 0 0 0 0
42172- 0 0 0 6 6 6 22 22 22 50 50 50
42173- 78 78 78 34 34 34 2 2 6 2 2 6
42174- 2 2 6 2 2 6 2 2 6 2 2 6
42175- 2 2 6 2 2 6 2 2 6 2 2 6
42176- 2 2 6 2 2 6 6 6 6 70 70 70
42177- 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
42186- 0 0 1 0 0 1 0 0 1 0 0 0
42187- 0 0 0 0 0 0 0 0 0 0 0 0
42188- 0 0 0 0 0 0 0 0 0 0 0 0
42189- 0 0 0 0 0 0 0 0 0 0 0 0
42190- 0 0 0 0 0 0 0 0 0 0 0 0
42191- 0 0 0 0 0 0 0 0 0 0 0 0
42192- 6 6 6 18 18 18 42 42 42 82 82 82
42193- 26 26 26 2 2 6 2 2 6 2 2 6
42194- 2 2 6 2 2 6 2 2 6 2 2 6
42195- 2 2 6 2 2 6 2 2 6 14 14 14
42196- 46 46 46 34 34 34 6 6 6 2 2 6
42197- 42 42 42 78 78 78 42 42 42 18 18 18
42198- 6 6 6 0 0 0 0 0 0 0 0 0
42199- 0 0 0 0 0 0 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
42206- 0 0 1 0 0 0 0 0 1 0 0 0
42207- 0 0 0 0 0 0 0 0 0 0 0 0
42208- 0 0 0 0 0 0 0 0 0 0 0 0
42209- 0 0 0 0 0 0 0 0 0 0 0 0
42210- 0 0 0 0 0 0 0 0 0 0 0 0
42211- 0 0 0 0 0 0 0 0 0 0 0 0
42212- 10 10 10 30 30 30 66 66 66 58 58 58
42213- 2 2 6 2 2 6 2 2 6 2 2 6
42214- 2 2 6 2 2 6 2 2 6 2 2 6
42215- 2 2 6 2 2 6 2 2 6 26 26 26
42216- 86 86 86 101 101 101 46 46 46 10 10 10
42217- 2 2 6 58 58 58 70 70 70 34 34 34
42218- 10 10 10 0 0 0 0 0 0 0 0 0
42219- 0 0 0 0 0 0 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
42226- 0 0 1 0 0 1 0 0 1 0 0 0
42227- 0 0 0 0 0 0 0 0 0 0 0 0
42228- 0 0 0 0 0 0 0 0 0 0 0 0
42229- 0 0 0 0 0 0 0 0 0 0 0 0
42230- 0 0 0 0 0 0 0 0 0 0 0 0
42231- 0 0 0 0 0 0 0 0 0 0 0 0
42232- 14 14 14 42 42 42 86 86 86 10 10 10
42233- 2 2 6 2 2 6 2 2 6 2 2 6
42234- 2 2 6 2 2 6 2 2 6 2 2 6
42235- 2 2 6 2 2 6 2 2 6 30 30 30
42236- 94 94 94 94 94 94 58 58 58 26 26 26
42237- 2 2 6 6 6 6 78 78 78 54 54 54
42238- 22 22 22 6 6 6 0 0 0 0 0 0
42239- 0 0 0 0 0 0 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
42246- 0 0 0 0 0 0 0 0 0 0 0 0
42247- 0 0 0 0 0 0 0 0 0 0 0 0
42248- 0 0 0 0 0 0 0 0 0 0 0 0
42249- 0 0 0 0 0 0 0 0 0 0 0 0
42250- 0 0 0 0 0 0 0 0 0 0 0 0
42251- 0 0 0 0 0 0 0 0 0 6 6 6
42252- 22 22 22 62 62 62 62 62 62 2 2 6
42253- 2 2 6 2 2 6 2 2 6 2 2 6
42254- 2 2 6 2 2 6 2 2 6 2 2 6
42255- 2 2 6 2 2 6 2 2 6 26 26 26
42256- 54 54 54 38 38 38 18 18 18 10 10 10
42257- 2 2 6 2 2 6 34 34 34 82 82 82
42258- 38 38 38 14 14 14 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 0 0 0
42265- 0 0 0 0 0 0 0 0 0 0 0 0
42266- 0 0 0 0 0 1 0 0 1 0 0 0
42267- 0 0 0 0 0 0 0 0 0 0 0 0
42268- 0 0 0 0 0 0 0 0 0 0 0 0
42269- 0 0 0 0 0 0 0 0 0 0 0 0
42270- 0 0 0 0 0 0 0 0 0 0 0 0
42271- 0 0 0 0 0 0 0 0 0 6 6 6
42272- 30 30 30 78 78 78 30 30 30 2 2 6
42273- 2 2 6 2 2 6 2 2 6 2 2 6
42274- 2 2 6 2 2 6 2 2 6 2 2 6
42275- 2 2 6 2 2 6 2 2 6 10 10 10
42276- 10 10 10 2 2 6 2 2 6 2 2 6
42277- 2 2 6 2 2 6 2 2 6 78 78 78
42278- 50 50 50 18 18 18 6 6 6 0 0 0
42279- 0 0 0 0 0 0 0 0 0 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 0 0 0
42285- 0 0 0 0 0 0 0 0 0 0 0 0
42286- 0 0 1 0 0 0 0 0 0 0 0 0
42287- 0 0 0 0 0 0 0 0 0 0 0 0
42288- 0 0 0 0 0 0 0 0 0 0 0 0
42289- 0 0 0 0 0 0 0 0 0 0 0 0
42290- 0 0 0 0 0 0 0 0 0 0 0 0
42291- 0 0 0 0 0 0 0 0 0 10 10 10
42292- 38 38 38 86 86 86 14 14 14 2 2 6
42293- 2 2 6 2 2 6 2 2 6 2 2 6
42294- 2 2 6 2 2 6 2 2 6 2 2 6
42295- 2 2 6 2 2 6 2 2 6 2 2 6
42296- 2 2 6 2 2 6 2 2 6 2 2 6
42297- 2 2 6 2 2 6 2 2 6 54 54 54
42298- 66 66 66 26 26 26 6 6 6 0 0 0
42299- 0 0 0 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 0 0 0
42305- 0 0 0 0 0 0 0 0 0 0 0 0
42306- 0 0 0 0 0 1 0 0 1 0 0 0
42307- 0 0 0 0 0 0 0 0 0 0 0 0
42308- 0 0 0 0 0 0 0 0 0 0 0 0
42309- 0 0 0 0 0 0 0 0 0 0 0 0
42310- 0 0 0 0 0 0 0 0 0 0 0 0
42311- 0 0 0 0 0 0 0 0 0 14 14 14
42312- 42 42 42 82 82 82 2 2 6 2 2 6
42313- 2 2 6 6 6 6 10 10 10 2 2 6
42314- 2 2 6 2 2 6 2 2 6 2 2 6
42315- 2 2 6 2 2 6 2 2 6 6 6 6
42316- 14 14 14 10 10 10 2 2 6 2 2 6
42317- 2 2 6 2 2 6 2 2 6 18 18 18
42318- 82 82 82 34 34 34 10 10 10 0 0 0
42319- 0 0 0 0 0 0 0 0 0 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 0 0 0
42325- 0 0 0 0 0 0 0 0 0 0 0 0
42326- 0 0 1 0 0 0 0 0 0 0 0 0
42327- 0 0 0 0 0 0 0 0 0 0 0 0
42328- 0 0 0 0 0 0 0 0 0 0 0 0
42329- 0 0 0 0 0 0 0 0 0 0 0 0
42330- 0 0 0 0 0 0 0 0 0 0 0 0
42331- 0 0 0 0 0 0 0 0 0 14 14 14
42332- 46 46 46 86 86 86 2 2 6 2 2 6
42333- 6 6 6 6 6 6 22 22 22 34 34 34
42334- 6 6 6 2 2 6 2 2 6 2 2 6
42335- 2 2 6 2 2 6 18 18 18 34 34 34
42336- 10 10 10 50 50 50 22 22 22 2 2 6
42337- 2 2 6 2 2 6 2 2 6 10 10 10
42338- 86 86 86 42 42 42 14 14 14 0 0 0
42339- 0 0 0 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 0 0 0
42345- 0 0 0 0 0 0 0 0 0 0 0 0
42346- 0 0 1 0 0 1 0 0 1 0 0 0
42347- 0 0 0 0 0 0 0 0 0 0 0 0
42348- 0 0 0 0 0 0 0 0 0 0 0 0
42349- 0 0 0 0 0 0 0 0 0 0 0 0
42350- 0 0 0 0 0 0 0 0 0 0 0 0
42351- 0 0 0 0 0 0 0 0 0 14 14 14
42352- 46 46 46 86 86 86 2 2 6 2 2 6
42353- 38 38 38 116 116 116 94 94 94 22 22 22
42354- 22 22 22 2 2 6 2 2 6 2 2 6
42355- 14 14 14 86 86 86 138 138 138 162 162 162
42356-154 154 154 38 38 38 26 26 26 6 6 6
42357- 2 2 6 2 2 6 2 2 6 2 2 6
42358- 86 86 86 46 46 46 14 14 14 0 0 0
42359- 0 0 0 0 0 0 0 0 0 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 0 0 0
42365- 0 0 0 0 0 0 0 0 0 0 0 0
42366- 0 0 0 0 0 0 0 0 0 0 0 0
42367- 0 0 0 0 0 0 0 0 0 0 0 0
42368- 0 0 0 0 0 0 0 0 0 0 0 0
42369- 0 0 0 0 0 0 0 0 0 0 0 0
42370- 0 0 0 0 0 0 0 0 0 0 0 0
42371- 0 0 0 0 0 0 0 0 0 14 14 14
42372- 46 46 46 86 86 86 2 2 6 14 14 14
42373-134 134 134 198 198 198 195 195 195 116 116 116
42374- 10 10 10 2 2 6 2 2 6 6 6 6
42375-101 98 89 187 187 187 210 210 210 218 218 218
42376-214 214 214 134 134 134 14 14 14 6 6 6
42377- 2 2 6 2 2 6 2 2 6 2 2 6
42378- 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0
42385- 0 0 0 0 0 0 0 0 1 0 0 0
42386- 0 0 1 0 0 1 0 0 1 0 0 0
42387- 0 0 0 0 0 0 0 0 0 0 0 0
42388- 0 0 0 0 0 0 0 0 0 0 0 0
42389- 0 0 0 0 0 0 0 0 0 0 0 0
42390- 0 0 0 0 0 0 0 0 0 0 0 0
42391- 0 0 0 0 0 0 0 0 0 14 14 14
42392- 46 46 46 86 86 86 2 2 6 54 54 54
42393-218 218 218 195 195 195 226 226 226 246 246 246
42394- 58 58 58 2 2 6 2 2 6 30 30 30
42395-210 210 210 253 253 253 174 174 174 123 123 123
42396-221 221 221 234 234 234 74 74 74 2 2 6
42397- 2 2 6 2 2 6 2 2 6 2 2 6
42398- 70 70 70 58 58 58 22 22 22 6 6 6
42399- 0 0 0 0 0 0 0 0 0 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 0 0 0
42405- 0 0 0 0 0 0 0 0 0 0 0 0
42406- 0 0 0 0 0 0 0 0 0 0 0 0
42407- 0 0 0 0 0 0 0 0 0 0 0 0
42408- 0 0 0 0 0 0 0 0 0 0 0 0
42409- 0 0 0 0 0 0 0 0 0 0 0 0
42410- 0 0 0 0 0 0 0 0 0 0 0 0
42411- 0 0 0 0 0 0 0 0 0 14 14 14
42412- 46 46 46 82 82 82 2 2 6 106 106 106
42413-170 170 170 26 26 26 86 86 86 226 226 226
42414-123 123 123 10 10 10 14 14 14 46 46 46
42415-231 231 231 190 190 190 6 6 6 70 70 70
42416- 90 90 90 238 238 238 158 158 158 2 2 6
42417- 2 2 6 2 2 6 2 2 6 2 2 6
42418- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
42425- 0 0 0 0 0 0 0 0 1 0 0 0
42426- 0 0 1 0 0 1 0 0 1 0 0 0
42427- 0 0 0 0 0 0 0 0 0 0 0 0
42428- 0 0 0 0 0 0 0 0 0 0 0 0
42429- 0 0 0 0 0 0 0 0 0 0 0 0
42430- 0 0 0 0 0 0 0 0 0 0 0 0
42431- 0 0 0 0 0 0 0 0 0 14 14 14
42432- 42 42 42 86 86 86 6 6 6 116 116 116
42433-106 106 106 6 6 6 70 70 70 149 149 149
42434-128 128 128 18 18 18 38 38 38 54 54 54
42435-221 221 221 106 106 106 2 2 6 14 14 14
42436- 46 46 46 190 190 190 198 198 198 2 2 6
42437- 2 2 6 2 2 6 2 2 6 2 2 6
42438- 74 74 74 62 62 62 22 22 22 6 6 6
42439- 0 0 0 0 0 0 0 0 0 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 0 0 0
42445- 0 0 0 0 0 0 0 0 1 0 0 0
42446- 0 0 1 0 0 0 0 0 1 0 0 0
42447- 0 0 0 0 0 0 0 0 0 0 0 0
42448- 0 0 0 0 0 0 0 0 0 0 0 0
42449- 0 0 0 0 0 0 0 0 0 0 0 0
42450- 0 0 0 0 0 0 0 0 0 0 0 0
42451- 0 0 0 0 0 0 0 0 0 14 14 14
42452- 42 42 42 94 94 94 14 14 14 101 101 101
42453-128 128 128 2 2 6 18 18 18 116 116 116
42454-118 98 46 121 92 8 121 92 8 98 78 10
42455-162 162 162 106 106 106 2 2 6 2 2 6
42456- 2 2 6 195 195 195 195 195 195 6 6 6
42457- 2 2 6 2 2 6 2 2 6 2 2 6
42458- 74 74 74 62 62 62 22 22 22 6 6 6
42459- 0 0 0 0 0 0 0 0 0 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 0 0 0
42465- 0 0 0 0 0 0 0 0 1 0 0 1
42466- 0 0 1 0 0 0 0 0 1 0 0 0
42467- 0 0 0 0 0 0 0 0 0 0 0 0
42468- 0 0 0 0 0 0 0 0 0 0 0 0
42469- 0 0 0 0 0 0 0 0 0 0 0 0
42470- 0 0 0 0 0 0 0 0 0 0 0 0
42471- 0 0 0 0 0 0 0 0 0 10 10 10
42472- 38 38 38 90 90 90 14 14 14 58 58 58
42473-210 210 210 26 26 26 54 38 6 154 114 10
42474-226 170 11 236 186 11 225 175 15 184 144 12
42475-215 174 15 175 146 61 37 26 9 2 2 6
42476- 70 70 70 246 246 246 138 138 138 2 2 6
42477- 2 2 6 2 2 6 2 2 6 2 2 6
42478- 70 70 70 66 66 66 26 26 26 6 6 6
42479- 0 0 0 0 0 0 0 0 0 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 0 0 0
42485- 0 0 0 0 0 0 0 0 0 0 0 0
42486- 0 0 0 0 0 0 0 0 0 0 0 0
42487- 0 0 0 0 0 0 0 0 0 0 0 0
42488- 0 0 0 0 0 0 0 0 0 0 0 0
42489- 0 0 0 0 0 0 0 0 0 0 0 0
42490- 0 0 0 0 0 0 0 0 0 0 0 0
42491- 0 0 0 0 0 0 0 0 0 10 10 10
42492- 38 38 38 86 86 86 14 14 14 10 10 10
42493-195 195 195 188 164 115 192 133 9 225 175 15
42494-239 182 13 234 190 10 232 195 16 232 200 30
42495-245 207 45 241 208 19 232 195 16 184 144 12
42496-218 194 134 211 206 186 42 42 42 2 2 6
42497- 2 2 6 2 2 6 2 2 6 2 2 6
42498- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
42505- 0 0 0 0 0 0 0 0 0 0 0 0
42506- 0 0 0 0 0 0 0 0 0 0 0 0
42507- 0 0 0 0 0 0 0 0 0 0 0 0
42508- 0 0 0 0 0 0 0 0 0 0 0 0
42509- 0 0 0 0 0 0 0 0 0 0 0 0
42510- 0 0 0 0 0 0 0 0 0 0 0 0
42511- 0 0 0 0 0 0 0 0 0 10 10 10
42512- 34 34 34 86 86 86 14 14 14 2 2 6
42513-121 87 25 192 133 9 219 162 10 239 182 13
42514-236 186 11 232 195 16 241 208 19 244 214 54
42515-246 218 60 246 218 38 246 215 20 241 208 19
42516-241 208 19 226 184 13 121 87 25 2 2 6
42517- 2 2 6 2 2 6 2 2 6 2 2 6
42518- 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
42525- 0 0 0 0 0 0 0 0 0 0 0 0
42526- 0 0 0 0 0 0 0 0 0 0 0 0
42527- 0 0 0 0 0 0 0 0 0 0 0 0
42528- 0 0 0 0 0 0 0 0 0 0 0 0
42529- 0 0 0 0 0 0 0 0 0 0 0 0
42530- 0 0 0 0 0 0 0 0 0 0 0 0
42531- 0 0 0 0 0 0 0 0 0 10 10 10
42532- 34 34 34 82 82 82 30 30 30 61 42 6
42533-180 123 7 206 145 10 230 174 11 239 182 13
42534-234 190 10 238 202 15 241 208 19 246 218 74
42535-246 218 38 246 215 20 246 215 20 246 215 20
42536-226 184 13 215 174 15 184 144 12 6 6 6
42537- 2 2 6 2 2 6 2 2 6 2 2 6
42538- 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
42545- 0 0 0 0 0 0 0 0 0 0 0 0
42546- 0 0 0 0 0 0 0 0 0 0 0 0
42547- 0 0 0 0 0 0 0 0 0 0 0 0
42548- 0 0 0 0 0 0 0 0 0 0 0 0
42549- 0 0 0 0 0 0 0 0 0 0 0 0
42550- 0 0 0 0 0 0 0 0 0 0 0 0
42551- 0 0 0 0 0 0 0 0 0 10 10 10
42552- 30 30 30 78 78 78 50 50 50 104 69 6
42553-192 133 9 216 158 10 236 178 12 236 186 11
42554-232 195 16 241 208 19 244 214 54 245 215 43
42555-246 215 20 246 215 20 241 208 19 198 155 10
42556-200 144 11 216 158 10 156 118 10 2 2 6
42557- 2 2 6 2 2 6 2 2 6 2 2 6
42558- 6 6 6 90 90 90 54 54 54 18 18 18
42559- 6 6 6 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 0 0 0
42565- 0 0 0 0 0 0 0 0 0 0 0 0
42566- 0 0 0 0 0 0 0 0 0 0 0 0
42567- 0 0 0 0 0 0 0 0 0 0 0 0
42568- 0 0 0 0 0 0 0 0 0 0 0 0
42569- 0 0 0 0 0 0 0 0 0 0 0 0
42570- 0 0 0 0 0 0 0 0 0 0 0 0
42571- 0 0 0 0 0 0 0 0 0 10 10 10
42572- 30 30 30 78 78 78 46 46 46 22 22 22
42573-137 92 6 210 162 10 239 182 13 238 190 10
42574-238 202 15 241 208 19 246 215 20 246 215 20
42575-241 208 19 203 166 17 185 133 11 210 150 10
42576-216 158 10 210 150 10 102 78 10 2 2 6
42577- 6 6 6 54 54 54 14 14 14 2 2 6
42578- 2 2 6 62 62 62 74 74 74 30 30 30
42579- 10 10 10 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 0 0 0
42585- 0 0 0 0 0 0 0 0 0 0 0 0
42586- 0 0 0 0 0 0 0 0 0 0 0 0
42587- 0 0 0 0 0 0 0 0 0 0 0 0
42588- 0 0 0 0 0 0 0 0 0 0 0 0
42589- 0 0 0 0 0 0 0 0 0 0 0 0
42590- 0 0 0 0 0 0 0 0 0 0 0 0
42591- 0 0 0 0 0 0 0 0 0 10 10 10
42592- 34 34 34 78 78 78 50 50 50 6 6 6
42593- 94 70 30 139 102 15 190 146 13 226 184 13
42594-232 200 30 232 195 16 215 174 15 190 146 13
42595-168 122 10 192 133 9 210 150 10 213 154 11
42596-202 150 34 182 157 106 101 98 89 2 2 6
42597- 2 2 6 78 78 78 116 116 116 58 58 58
42598- 2 2 6 22 22 22 90 90 90 46 46 46
42599- 18 18 18 6 6 6 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 0 0 0
42605- 0 0 0 0 0 0 0 0 0 0 0 0
42606- 0 0 0 0 0 0 0 0 0 0 0 0
42607- 0 0 0 0 0 0 0 0 0 0 0 0
42608- 0 0 0 0 0 0 0 0 0 0 0 0
42609- 0 0 0 0 0 0 0 0 0 0 0 0
42610- 0 0 0 0 0 0 0 0 0 0 0 0
42611- 0 0 0 0 0 0 0 0 0 10 10 10
42612- 38 38 38 86 86 86 50 50 50 6 6 6
42613-128 128 128 174 154 114 156 107 11 168 122 10
42614-198 155 10 184 144 12 197 138 11 200 144 11
42615-206 145 10 206 145 10 197 138 11 188 164 115
42616-195 195 195 198 198 198 174 174 174 14 14 14
42617- 2 2 6 22 22 22 116 116 116 116 116 116
42618- 22 22 22 2 2 6 74 74 74 70 70 70
42619- 30 30 30 10 10 10 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 0 0 0
42625- 0 0 0 0 0 0 0 0 0 0 0 0
42626- 0 0 0 0 0 0 0 0 0 0 0 0
42627- 0 0 0 0 0 0 0 0 0 0 0 0
42628- 0 0 0 0 0 0 0 0 0 0 0 0
42629- 0 0 0 0 0 0 0 0 0 0 0 0
42630- 0 0 0 0 0 0 0 0 0 0 0 0
42631- 0 0 0 0 0 0 6 6 6 18 18 18
42632- 50 50 50 101 101 101 26 26 26 10 10 10
42633-138 138 138 190 190 190 174 154 114 156 107 11
42634-197 138 11 200 144 11 197 138 11 192 133 9
42635-180 123 7 190 142 34 190 178 144 187 187 187
42636-202 202 202 221 221 221 214 214 214 66 66 66
42637- 2 2 6 2 2 6 50 50 50 62 62 62
42638- 6 6 6 2 2 6 10 10 10 90 90 90
42639- 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0
42645- 0 0 0 0 0 0 0 0 0 0 0 0
42646- 0 0 0 0 0 0 0 0 0 0 0 0
42647- 0 0 0 0 0 0 0 0 0 0 0 0
42648- 0 0 0 0 0 0 0 0 0 0 0 0
42649- 0 0 0 0 0 0 0 0 0 0 0 0
42650- 0 0 0 0 0 0 0 0 0 0 0 0
42651- 0 0 0 0 0 0 10 10 10 34 34 34
42652- 74 74 74 74 74 74 2 2 6 6 6 6
42653-144 144 144 198 198 198 190 190 190 178 166 146
42654-154 121 60 156 107 11 156 107 11 168 124 44
42655-174 154 114 187 187 187 190 190 190 210 210 210
42656-246 246 246 253 253 253 253 253 253 182 182 182
42657- 6 6 6 2 2 6 2 2 6 2 2 6
42658- 2 2 6 2 2 6 2 2 6 62 62 62
42659- 74 74 74 34 34 34 14 14 14 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 0 0 0 0 0 0
42665- 0 0 0 0 0 0 0 0 0 0 0 0
42666- 0 0 0 0 0 0 0 0 0 0 0 0
42667- 0 0 0 0 0 0 0 0 0 0 0 0
42668- 0 0 0 0 0 0 0 0 0 0 0 0
42669- 0 0 0 0 0 0 0 0 0 0 0 0
42670- 0 0 0 0 0 0 0 0 0 0 0 0
42671- 0 0 0 10 10 10 22 22 22 54 54 54
42672- 94 94 94 18 18 18 2 2 6 46 46 46
42673-234 234 234 221 221 221 190 190 190 190 190 190
42674-190 190 190 187 187 187 187 187 187 190 190 190
42675-190 190 190 195 195 195 214 214 214 242 242 242
42676-253 253 253 253 253 253 253 253 253 253 253 253
42677- 82 82 82 2 2 6 2 2 6 2 2 6
42678- 2 2 6 2 2 6 2 2 6 14 14 14
42679- 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
42685- 0 0 0 0 0 0 0 0 0 0 0 0
42686- 0 0 0 0 0 0 0 0 0 0 0 0
42687- 0 0 0 0 0 0 0 0 0 0 0 0
42688- 0 0 0 0 0 0 0 0 0 0 0 0
42689- 0 0 0 0 0 0 0 0 0 0 0 0
42690- 0 0 0 0 0 0 0 0 0 0 0 0
42691- 6 6 6 18 18 18 46 46 46 90 90 90
42692- 46 46 46 18 18 18 6 6 6 182 182 182
42693-253 253 253 246 246 246 206 206 206 190 190 190
42694-190 190 190 190 190 190 190 190 190 190 190 190
42695-206 206 206 231 231 231 250 250 250 253 253 253
42696-253 253 253 253 253 253 253 253 253 253 253 253
42697-202 202 202 14 14 14 2 2 6 2 2 6
42698- 2 2 6 2 2 6 2 2 6 2 2 6
42699- 42 42 42 86 86 86 42 42 42 18 18 18
42700- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
42705- 0 0 0 0 0 0 0 0 0 0 0 0
42706- 0 0 0 0 0 0 0 0 0 0 0 0
42707- 0 0 0 0 0 0 0 0 0 0 0 0
42708- 0 0 0 0 0 0 0 0 0 0 0 0
42709- 0 0 0 0 0 0 0 0 0 0 0 0
42710- 0 0 0 0 0 0 0 0 0 6 6 6
42711- 14 14 14 38 38 38 74 74 74 66 66 66
42712- 2 2 6 6 6 6 90 90 90 250 250 250
42713-253 253 253 253 253 253 238 238 238 198 198 198
42714-190 190 190 190 190 190 195 195 195 221 221 221
42715-246 246 246 253 253 253 253 253 253 253 253 253
42716-253 253 253 253 253 253 253 253 253 253 253 253
42717-253 253 253 82 82 82 2 2 6 2 2 6
42718- 2 2 6 2 2 6 2 2 6 2 2 6
42719- 2 2 6 78 78 78 70 70 70 34 34 34
42720- 14 14 14 6 6 6 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 0 0 0
42724- 0 0 0 0 0 0 0 0 0 0 0 0
42725- 0 0 0 0 0 0 0 0 0 0 0 0
42726- 0 0 0 0 0 0 0 0 0 0 0 0
42727- 0 0 0 0 0 0 0 0 0 0 0 0
42728- 0 0 0 0 0 0 0 0 0 0 0 0
42729- 0 0 0 0 0 0 0 0 0 0 0 0
42730- 0 0 0 0 0 0 0 0 0 14 14 14
42731- 34 34 34 66 66 66 78 78 78 6 6 6
42732- 2 2 6 18 18 18 218 218 218 253 253 253
42733-253 253 253 253 253 253 253 253 253 246 246 246
42734-226 226 226 231 231 231 246 246 246 253 253 253
42735-253 253 253 253 253 253 253 253 253 253 253 253
42736-253 253 253 253 253 253 253 253 253 253 253 253
42737-253 253 253 178 178 178 2 2 6 2 2 6
42738- 2 2 6 2 2 6 2 2 6 2 2 6
42739- 2 2 6 18 18 18 90 90 90 62 62 62
42740- 30 30 30 10 10 10 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 0 0 0
42744- 0 0 0 0 0 0 0 0 0 0 0 0
42745- 0 0 0 0 0 0 0 0 0 0 0 0
42746- 0 0 0 0 0 0 0 0 0 0 0 0
42747- 0 0 0 0 0 0 0 0 0 0 0 0
42748- 0 0 0 0 0 0 0 0 0 0 0 0
42749- 0 0 0 0 0 0 0 0 0 0 0 0
42750- 0 0 0 0 0 0 10 10 10 26 26 26
42751- 58 58 58 90 90 90 18 18 18 2 2 6
42752- 2 2 6 110 110 110 253 253 253 253 253 253
42753-253 253 253 253 253 253 253 253 253 253 253 253
42754-250 250 250 253 253 253 253 253 253 253 253 253
42755-253 253 253 253 253 253 253 253 253 253 253 253
42756-253 253 253 253 253 253 253 253 253 253 253 253
42757-253 253 253 231 231 231 18 18 18 2 2 6
42758- 2 2 6 2 2 6 2 2 6 2 2 6
42759- 2 2 6 2 2 6 18 18 18 94 94 94
42760- 54 54 54 26 26 26 10 10 10 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 0 0 0 0 0 0
42764- 0 0 0 0 0 0 0 0 0 0 0 0
42765- 0 0 0 0 0 0 0 0 0 0 0 0
42766- 0 0 0 0 0 0 0 0 0 0 0 0
42767- 0 0 0 0 0 0 0 0 0 0 0 0
42768- 0 0 0 0 0 0 0 0 0 0 0 0
42769- 0 0 0 0 0 0 0 0 0 0 0 0
42770- 0 0 0 6 6 6 22 22 22 50 50 50
42771- 90 90 90 26 26 26 2 2 6 2 2 6
42772- 14 14 14 195 195 195 250 250 250 253 253 253
42773-253 253 253 253 253 253 253 253 253 253 253 253
42774-253 253 253 253 253 253 253 253 253 253 253 253
42775-253 253 253 253 253 253 253 253 253 253 253 253
42776-253 253 253 253 253 253 253 253 253 253 253 253
42777-250 250 250 242 242 242 54 54 54 2 2 6
42778- 2 2 6 2 2 6 2 2 6 2 2 6
42779- 2 2 6 2 2 6 2 2 6 38 38 38
42780- 86 86 86 50 50 50 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
42784- 0 0 0 0 0 0 0 0 0 0 0 0
42785- 0 0 0 0 0 0 0 0 0 0 0 0
42786- 0 0 0 0 0 0 0 0 0 0 0 0
42787- 0 0 0 0 0 0 0 0 0 0 0 0
42788- 0 0 0 0 0 0 0 0 0 0 0 0
42789- 0 0 0 0 0 0 0 0 0 0 0 0
42790- 6 6 6 14 14 14 38 38 38 82 82 82
42791- 34 34 34 2 2 6 2 2 6 2 2 6
42792- 42 42 42 195 195 195 246 246 246 253 253 253
42793-253 253 253 253 253 253 253 253 253 250 250 250
42794-242 242 242 242 242 242 250 250 250 253 253 253
42795-253 253 253 253 253 253 253 253 253 253 253 253
42796-253 253 253 250 250 250 246 246 246 238 238 238
42797-226 226 226 231 231 231 101 101 101 6 6 6
42798- 2 2 6 2 2 6 2 2 6 2 2 6
42799- 2 2 6 2 2 6 2 2 6 2 2 6
42800- 38 38 38 82 82 82 42 42 42 14 14 14
42801- 6 6 6 0 0 0 0 0 0 0 0 0
42802- 0 0 0 0 0 0 0 0 0 0 0 0
42803- 0 0 0 0 0 0 0 0 0 0 0 0
42804- 0 0 0 0 0 0 0 0 0 0 0 0
42805- 0 0 0 0 0 0 0 0 0 0 0 0
42806- 0 0 0 0 0 0 0 0 0 0 0 0
42807- 0 0 0 0 0 0 0 0 0 0 0 0
42808- 0 0 0 0 0 0 0 0 0 0 0 0
42809- 0 0 0 0 0 0 0 0 0 0 0 0
42810- 10 10 10 26 26 26 62 62 62 66 66 66
42811- 2 2 6 2 2 6 2 2 6 6 6 6
42812- 70 70 70 170 170 170 206 206 206 234 234 234
42813-246 246 246 250 250 250 250 250 250 238 238 238
42814-226 226 226 231 231 231 238 238 238 250 250 250
42815-250 250 250 250 250 250 246 246 246 231 231 231
42816-214 214 214 206 206 206 202 202 202 202 202 202
42817-198 198 198 202 202 202 182 182 182 18 18 18
42818- 2 2 6 2 2 6 2 2 6 2 2 6
42819- 2 2 6 2 2 6 2 2 6 2 2 6
42820- 2 2 6 62 62 62 66 66 66 30 30 30
42821- 10 10 10 0 0 0 0 0 0 0 0 0
42822- 0 0 0 0 0 0 0 0 0 0 0 0
42823- 0 0 0 0 0 0 0 0 0 0 0 0
42824- 0 0 0 0 0 0 0 0 0 0 0 0
42825- 0 0 0 0 0 0 0 0 0 0 0 0
42826- 0 0 0 0 0 0 0 0 0 0 0 0
42827- 0 0 0 0 0 0 0 0 0 0 0 0
42828- 0 0 0 0 0 0 0 0 0 0 0 0
42829- 0 0 0 0 0 0 0 0 0 0 0 0
42830- 14 14 14 42 42 42 82 82 82 18 18 18
42831- 2 2 6 2 2 6 2 2 6 10 10 10
42832- 94 94 94 182 182 182 218 218 218 242 242 242
42833-250 250 250 253 253 253 253 253 253 250 250 250
42834-234 234 234 253 253 253 253 253 253 253 253 253
42835-253 253 253 253 253 253 253 253 253 246 246 246
42836-238 238 238 226 226 226 210 210 210 202 202 202
42837-195 195 195 195 195 195 210 210 210 158 158 158
42838- 6 6 6 14 14 14 50 50 50 14 14 14
42839- 2 2 6 2 2 6 2 2 6 2 2 6
42840- 2 2 6 6 6 6 86 86 86 46 46 46
42841- 18 18 18 6 6 6 0 0 0 0 0 0
42842- 0 0 0 0 0 0 0 0 0 0 0 0
42843- 0 0 0 0 0 0 0 0 0 0 0 0
42844- 0 0 0 0 0 0 0 0 0 0 0 0
42845- 0 0 0 0 0 0 0 0 0 0 0 0
42846- 0 0 0 0 0 0 0 0 0 0 0 0
42847- 0 0 0 0 0 0 0 0 0 0 0 0
42848- 0 0 0 0 0 0 0 0 0 0 0 0
42849- 0 0 0 0 0 0 0 0 0 6 6 6
42850- 22 22 22 54 54 54 70 70 70 2 2 6
42851- 2 2 6 10 10 10 2 2 6 22 22 22
42852-166 166 166 231 231 231 250 250 250 253 253 253
42853-253 253 253 253 253 253 253 253 253 250 250 250
42854-242 242 242 253 253 253 253 253 253 253 253 253
42855-253 253 253 253 253 253 253 253 253 253 253 253
42856-253 253 253 253 253 253 253 253 253 246 246 246
42857-231 231 231 206 206 206 198 198 198 226 226 226
42858- 94 94 94 2 2 6 6 6 6 38 38 38
42859- 30 30 30 2 2 6 2 2 6 2 2 6
42860- 2 2 6 2 2 6 62 62 62 66 66 66
42861- 26 26 26 10 10 10 0 0 0 0 0 0
42862- 0 0 0 0 0 0 0 0 0 0 0 0
42863- 0 0 0 0 0 0 0 0 0 0 0 0
42864- 0 0 0 0 0 0 0 0 0 0 0 0
42865- 0 0 0 0 0 0 0 0 0 0 0 0
42866- 0 0 0 0 0 0 0 0 0 0 0 0
42867- 0 0 0 0 0 0 0 0 0 0 0 0
42868- 0 0 0 0 0 0 0 0 0 0 0 0
42869- 0 0 0 0 0 0 0 0 0 10 10 10
42870- 30 30 30 74 74 74 50 50 50 2 2 6
42871- 26 26 26 26 26 26 2 2 6 106 106 106
42872-238 238 238 253 253 253 253 253 253 253 253 253
42873-253 253 253 253 253 253 253 253 253 253 253 253
42874-253 253 253 253 253 253 253 253 253 253 253 253
42875-253 253 253 253 253 253 253 253 253 253 253 253
42876-253 253 253 253 253 253 253 253 253 253 253 253
42877-253 253 253 246 246 246 218 218 218 202 202 202
42878-210 210 210 14 14 14 2 2 6 2 2 6
42879- 30 30 30 22 22 22 2 2 6 2 2 6
42880- 2 2 6 2 2 6 18 18 18 86 86 86
42881- 42 42 42 14 14 14 0 0 0 0 0 0
42882- 0 0 0 0 0 0 0 0 0 0 0 0
42883- 0 0 0 0 0 0 0 0 0 0 0 0
42884- 0 0 0 0 0 0 0 0 0 0 0 0
42885- 0 0 0 0 0 0 0 0 0 0 0 0
42886- 0 0 0 0 0 0 0 0 0 0 0 0
42887- 0 0 0 0 0 0 0 0 0 0 0 0
42888- 0 0 0 0 0 0 0 0 0 0 0 0
42889- 0 0 0 0 0 0 0 0 0 14 14 14
42890- 42 42 42 90 90 90 22 22 22 2 2 6
42891- 42 42 42 2 2 6 18 18 18 218 218 218
42892-253 253 253 253 253 253 253 253 253 253 253 253
42893-253 253 253 253 253 253 253 253 253 253 253 253
42894-253 253 253 253 253 253 253 253 253 253 253 253
42895-253 253 253 253 253 253 253 253 253 253 253 253
42896-253 253 253 253 253 253 253 253 253 253 253 253
42897-253 253 253 253 253 253 250 250 250 221 221 221
42898-218 218 218 101 101 101 2 2 6 14 14 14
42899- 18 18 18 38 38 38 10 10 10 2 2 6
42900- 2 2 6 2 2 6 2 2 6 78 78 78
42901- 58 58 58 22 22 22 6 6 6 0 0 0
42902- 0 0 0 0 0 0 0 0 0 0 0 0
42903- 0 0 0 0 0 0 0 0 0 0 0 0
42904- 0 0 0 0 0 0 0 0 0 0 0 0
42905- 0 0 0 0 0 0 0 0 0 0 0 0
42906- 0 0 0 0 0 0 0 0 0 0 0 0
42907- 0 0 0 0 0 0 0 0 0 0 0 0
42908- 0 0 0 0 0 0 0 0 0 0 0 0
42909- 0 0 0 0 0 0 6 6 6 18 18 18
42910- 54 54 54 82 82 82 2 2 6 26 26 26
42911- 22 22 22 2 2 6 123 123 123 253 253 253
42912-253 253 253 253 253 253 253 253 253 253 253 253
42913-253 253 253 253 253 253 253 253 253 253 253 253
42914-253 253 253 253 253 253 253 253 253 253 253 253
42915-253 253 253 253 253 253 253 253 253 253 253 253
42916-253 253 253 253 253 253 253 253 253 253 253 253
42917-253 253 253 253 253 253 253 253 253 250 250 250
42918-238 238 238 198 198 198 6 6 6 38 38 38
42919- 58 58 58 26 26 26 38 38 38 2 2 6
42920- 2 2 6 2 2 6 2 2 6 46 46 46
42921- 78 78 78 30 30 30 10 10 10 0 0 0
42922- 0 0 0 0 0 0 0 0 0 0 0 0
42923- 0 0 0 0 0 0 0 0 0 0 0 0
42924- 0 0 0 0 0 0 0 0 0 0 0 0
42925- 0 0 0 0 0 0 0 0 0 0 0 0
42926- 0 0 0 0 0 0 0 0 0 0 0 0
42927- 0 0 0 0 0 0 0 0 0 0 0 0
42928- 0 0 0 0 0 0 0 0 0 0 0 0
42929- 0 0 0 0 0 0 10 10 10 30 30 30
42930- 74 74 74 58 58 58 2 2 6 42 42 42
42931- 2 2 6 22 22 22 231 231 231 253 253 253
42932-253 253 253 253 253 253 253 253 253 253 253 253
42933-253 253 253 253 253 253 253 253 253 250 250 250
42934-253 253 253 253 253 253 253 253 253 253 253 253
42935-253 253 253 253 253 253 253 253 253 253 253 253
42936-253 253 253 253 253 253 253 253 253 253 253 253
42937-253 253 253 253 253 253 253 253 253 253 253 253
42938-253 253 253 246 246 246 46 46 46 38 38 38
42939- 42 42 42 14 14 14 38 38 38 14 14 14
42940- 2 2 6 2 2 6 2 2 6 6 6 6
42941- 86 86 86 46 46 46 14 14 14 0 0 0
42942- 0 0 0 0 0 0 0 0 0 0 0 0
42943- 0 0 0 0 0 0 0 0 0 0 0 0
42944- 0 0 0 0 0 0 0 0 0 0 0 0
42945- 0 0 0 0 0 0 0 0 0 0 0 0
42946- 0 0 0 0 0 0 0 0 0 0 0 0
42947- 0 0 0 0 0 0 0 0 0 0 0 0
42948- 0 0 0 0 0 0 0 0 0 0 0 0
42949- 0 0 0 6 6 6 14 14 14 42 42 42
42950- 90 90 90 18 18 18 18 18 18 26 26 26
42951- 2 2 6 116 116 116 253 253 253 253 253 253
42952-253 253 253 253 253 253 253 253 253 253 253 253
42953-253 253 253 253 253 253 250 250 250 238 238 238
42954-253 253 253 253 253 253 253 253 253 253 253 253
42955-253 253 253 253 253 253 253 253 253 253 253 253
42956-253 253 253 253 253 253 253 253 253 253 253 253
42957-253 253 253 253 253 253 253 253 253 253 253 253
42958-253 253 253 253 253 253 94 94 94 6 6 6
42959- 2 2 6 2 2 6 10 10 10 34 34 34
42960- 2 2 6 2 2 6 2 2 6 2 2 6
42961- 74 74 74 58 58 58 22 22 22 6 6 6
42962- 0 0 0 0 0 0 0 0 0 0 0 0
42963- 0 0 0 0 0 0 0 0 0 0 0 0
42964- 0 0 0 0 0 0 0 0 0 0 0 0
42965- 0 0 0 0 0 0 0 0 0 0 0 0
42966- 0 0 0 0 0 0 0 0 0 0 0 0
42967- 0 0 0 0 0 0 0 0 0 0 0 0
42968- 0 0 0 0 0 0 0 0 0 0 0 0
42969- 0 0 0 10 10 10 26 26 26 66 66 66
42970- 82 82 82 2 2 6 38 38 38 6 6 6
42971- 14 14 14 210 210 210 253 253 253 253 253 253
42972-253 253 253 253 253 253 253 253 253 253 253 253
42973-253 253 253 253 253 253 246 246 246 242 242 242
42974-253 253 253 253 253 253 253 253 253 253 253 253
42975-253 253 253 253 253 253 253 253 253 253 253 253
42976-253 253 253 253 253 253 253 253 253 253 253 253
42977-253 253 253 253 253 253 253 253 253 253 253 253
42978-253 253 253 253 253 253 144 144 144 2 2 6
42979- 2 2 6 2 2 6 2 2 6 46 46 46
42980- 2 2 6 2 2 6 2 2 6 2 2 6
42981- 42 42 42 74 74 74 30 30 30 10 10 10
42982- 0 0 0 0 0 0 0 0 0 0 0 0
42983- 0 0 0 0 0 0 0 0 0 0 0 0
42984- 0 0 0 0 0 0 0 0 0 0 0 0
42985- 0 0 0 0 0 0 0 0 0 0 0 0
42986- 0 0 0 0 0 0 0 0 0 0 0 0
42987- 0 0 0 0 0 0 0 0 0 0 0 0
42988- 0 0 0 0 0 0 0 0 0 0 0 0
42989- 6 6 6 14 14 14 42 42 42 90 90 90
42990- 26 26 26 6 6 6 42 42 42 2 2 6
42991- 74 74 74 250 250 250 253 253 253 253 253 253
42992-253 253 253 253 253 253 253 253 253 253 253 253
42993-253 253 253 253 253 253 242 242 242 242 242 242
42994-253 253 253 253 253 253 253 253 253 253 253 253
42995-253 253 253 253 253 253 253 253 253 253 253 253
42996-253 253 253 253 253 253 253 253 253 253 253 253
42997-253 253 253 253 253 253 253 253 253 253 253 253
42998-253 253 253 253 253 253 182 182 182 2 2 6
42999- 2 2 6 2 2 6 2 2 6 46 46 46
43000- 2 2 6 2 2 6 2 2 6 2 2 6
43001- 10 10 10 86 86 86 38 38 38 10 10 10
43002- 0 0 0 0 0 0 0 0 0 0 0 0
43003- 0 0 0 0 0 0 0 0 0 0 0 0
43004- 0 0 0 0 0 0 0 0 0 0 0 0
43005- 0 0 0 0 0 0 0 0 0 0 0 0
43006- 0 0 0 0 0 0 0 0 0 0 0 0
43007- 0 0 0 0 0 0 0 0 0 0 0 0
43008- 0 0 0 0 0 0 0 0 0 0 0 0
43009- 10 10 10 26 26 26 66 66 66 82 82 82
43010- 2 2 6 22 22 22 18 18 18 2 2 6
43011-149 149 149 253 253 253 253 253 253 253 253 253
43012-253 253 253 253 253 253 253 253 253 253 253 253
43013-253 253 253 253 253 253 234 234 234 242 242 242
43014-253 253 253 253 253 253 253 253 253 253 253 253
43015-253 253 253 253 253 253 253 253 253 253 253 253
43016-253 253 253 253 253 253 253 253 253 253 253 253
43017-253 253 253 253 253 253 253 253 253 253 253 253
43018-253 253 253 253 253 253 206 206 206 2 2 6
43019- 2 2 6 2 2 6 2 2 6 38 38 38
43020- 2 2 6 2 2 6 2 2 6 2 2 6
43021- 6 6 6 86 86 86 46 46 46 14 14 14
43022- 0 0 0 0 0 0 0 0 0 0 0 0
43023- 0 0 0 0 0 0 0 0 0 0 0 0
43024- 0 0 0 0 0 0 0 0 0 0 0 0
43025- 0 0 0 0 0 0 0 0 0 0 0 0
43026- 0 0 0 0 0 0 0 0 0 0 0 0
43027- 0 0 0 0 0 0 0 0 0 0 0 0
43028- 0 0 0 0 0 0 0 0 0 6 6 6
43029- 18 18 18 46 46 46 86 86 86 18 18 18
43030- 2 2 6 34 34 34 10 10 10 6 6 6
43031-210 210 210 253 253 253 253 253 253 253 253 253
43032-253 253 253 253 253 253 253 253 253 253 253 253
43033-253 253 253 253 253 253 234 234 234 242 242 242
43034-253 253 253 253 253 253 253 253 253 253 253 253
43035-253 253 253 253 253 253 253 253 253 253 253 253
43036-253 253 253 253 253 253 253 253 253 253 253 253
43037-253 253 253 253 253 253 253 253 253 253 253 253
43038-253 253 253 253 253 253 221 221 221 6 6 6
43039- 2 2 6 2 2 6 6 6 6 30 30 30
43040- 2 2 6 2 2 6 2 2 6 2 2 6
43041- 2 2 6 82 82 82 54 54 54 18 18 18
43042- 6 6 6 0 0 0 0 0 0 0 0 0
43043- 0 0 0 0 0 0 0 0 0 0 0 0
43044- 0 0 0 0 0 0 0 0 0 0 0 0
43045- 0 0 0 0 0 0 0 0 0 0 0 0
43046- 0 0 0 0 0 0 0 0 0 0 0 0
43047- 0 0 0 0 0 0 0 0 0 0 0 0
43048- 0 0 0 0 0 0 0 0 0 10 10 10
43049- 26 26 26 66 66 66 62 62 62 2 2 6
43050- 2 2 6 38 38 38 10 10 10 26 26 26
43051-238 238 238 253 253 253 253 253 253 253 253 253
43052-253 253 253 253 253 253 253 253 253 253 253 253
43053-253 253 253 253 253 253 231 231 231 238 238 238
43054-253 253 253 253 253 253 253 253 253 253 253 253
43055-253 253 253 253 253 253 253 253 253 253 253 253
43056-253 253 253 253 253 253 253 253 253 253 253 253
43057-253 253 253 253 253 253 253 253 253 253 253 253
43058-253 253 253 253 253 253 231 231 231 6 6 6
43059- 2 2 6 2 2 6 10 10 10 30 30 30
43060- 2 2 6 2 2 6 2 2 6 2 2 6
43061- 2 2 6 66 66 66 58 58 58 22 22 22
43062- 6 6 6 0 0 0 0 0 0 0 0 0
43063- 0 0 0 0 0 0 0 0 0 0 0 0
43064- 0 0 0 0 0 0 0 0 0 0 0 0
43065- 0 0 0 0 0 0 0 0 0 0 0 0
43066- 0 0 0 0 0 0 0 0 0 0 0 0
43067- 0 0 0 0 0 0 0 0 0 0 0 0
43068- 0 0 0 0 0 0 0 0 0 10 10 10
43069- 38 38 38 78 78 78 6 6 6 2 2 6
43070- 2 2 6 46 46 46 14 14 14 42 42 42
43071-246 246 246 253 253 253 253 253 253 253 253 253
43072-253 253 253 253 253 253 253 253 253 253 253 253
43073-253 253 253 253 253 253 231 231 231 242 242 242
43074-253 253 253 253 253 253 253 253 253 253 253 253
43075-253 253 253 253 253 253 253 253 253 253 253 253
43076-253 253 253 253 253 253 253 253 253 253 253 253
43077-253 253 253 253 253 253 253 253 253 253 253 253
43078-253 253 253 253 253 253 234 234 234 10 10 10
43079- 2 2 6 2 2 6 22 22 22 14 14 14
43080- 2 2 6 2 2 6 2 2 6 2 2 6
43081- 2 2 6 66 66 66 62 62 62 22 22 22
43082- 6 6 6 0 0 0 0 0 0 0 0 0
43083- 0 0 0 0 0 0 0 0 0 0 0 0
43084- 0 0 0 0 0 0 0 0 0 0 0 0
43085- 0 0 0 0 0 0 0 0 0 0 0 0
43086- 0 0 0 0 0 0 0 0 0 0 0 0
43087- 0 0 0 0 0 0 0 0 0 0 0 0
43088- 0 0 0 0 0 0 6 6 6 18 18 18
43089- 50 50 50 74 74 74 2 2 6 2 2 6
43090- 14 14 14 70 70 70 34 34 34 62 62 62
43091-250 250 250 253 253 253 253 253 253 253 253 253
43092-253 253 253 253 253 253 253 253 253 253 253 253
43093-253 253 253 253 253 253 231 231 231 246 246 246
43094-253 253 253 253 253 253 253 253 253 253 253 253
43095-253 253 253 253 253 253 253 253 253 253 253 253
43096-253 253 253 253 253 253 253 253 253 253 253 253
43097-253 253 253 253 253 253 253 253 253 253 253 253
43098-253 253 253 253 253 253 234 234 234 14 14 14
43099- 2 2 6 2 2 6 30 30 30 2 2 6
43100- 2 2 6 2 2 6 2 2 6 2 2 6
43101- 2 2 6 66 66 66 62 62 62 22 22 22
43102- 6 6 6 0 0 0 0 0 0 0 0 0
43103- 0 0 0 0 0 0 0 0 0 0 0 0
43104- 0 0 0 0 0 0 0 0 0 0 0 0
43105- 0 0 0 0 0 0 0 0 0 0 0 0
43106- 0 0 0 0 0 0 0 0 0 0 0 0
43107- 0 0 0 0 0 0 0 0 0 0 0 0
43108- 0 0 0 0 0 0 6 6 6 18 18 18
43109- 54 54 54 62 62 62 2 2 6 2 2 6
43110- 2 2 6 30 30 30 46 46 46 70 70 70
43111-250 250 250 253 253 253 253 253 253 253 253 253
43112-253 253 253 253 253 253 253 253 253 253 253 253
43113-253 253 253 253 253 253 231 231 231 246 246 246
43114-253 253 253 253 253 253 253 253 253 253 253 253
43115-253 253 253 253 253 253 253 253 253 253 253 253
43116-253 253 253 253 253 253 253 253 253 253 253 253
43117-253 253 253 253 253 253 253 253 253 253 253 253
43118-253 253 253 253 253 253 226 226 226 10 10 10
43119- 2 2 6 6 6 6 30 30 30 2 2 6
43120- 2 2 6 2 2 6 2 2 6 2 2 6
43121- 2 2 6 66 66 66 58 58 58 22 22 22
43122- 6 6 6 0 0 0 0 0 0 0 0 0
43123- 0 0 0 0 0 0 0 0 0 0 0 0
43124- 0 0 0 0 0 0 0 0 0 0 0 0
43125- 0 0 0 0 0 0 0 0 0 0 0 0
43126- 0 0 0 0 0 0 0 0 0 0 0 0
43127- 0 0 0 0 0 0 0 0 0 0 0 0
43128- 0 0 0 0 0 0 6 6 6 22 22 22
43129- 58 58 58 62 62 62 2 2 6 2 2 6
43130- 2 2 6 2 2 6 30 30 30 78 78 78
43131-250 250 250 253 253 253 253 253 253 253 253 253
43132-253 253 253 253 253 253 253 253 253 253 253 253
43133-253 253 253 253 253 253 231 231 231 246 246 246
43134-253 253 253 253 253 253 253 253 253 253 253 253
43135-253 253 253 253 253 253 253 253 253 253 253 253
43136-253 253 253 253 253 253 253 253 253 253 253 253
43137-253 253 253 253 253 253 253 253 253 253 253 253
43138-253 253 253 253 253 253 206 206 206 2 2 6
43139- 22 22 22 34 34 34 18 14 6 22 22 22
43140- 26 26 26 18 18 18 6 6 6 2 2 6
43141- 2 2 6 82 82 82 54 54 54 18 18 18
43142- 6 6 6 0 0 0 0 0 0 0 0 0
43143- 0 0 0 0 0 0 0 0 0 0 0 0
43144- 0 0 0 0 0 0 0 0 0 0 0 0
43145- 0 0 0 0 0 0 0 0 0 0 0 0
43146- 0 0 0 0 0 0 0 0 0 0 0 0
43147- 0 0 0 0 0 0 0 0 0 0 0 0
43148- 0 0 0 0 0 0 6 6 6 26 26 26
43149- 62 62 62 106 106 106 74 54 14 185 133 11
43150-210 162 10 121 92 8 6 6 6 62 62 62
43151-238 238 238 253 253 253 253 253 253 253 253 253
43152-253 253 253 253 253 253 253 253 253 253 253 253
43153-253 253 253 253 253 253 231 231 231 246 246 246
43154-253 253 253 253 253 253 253 253 253 253 253 253
43155-253 253 253 253 253 253 253 253 253 253 253 253
43156-253 253 253 253 253 253 253 253 253 253 253 253
43157-253 253 253 253 253 253 253 253 253 253 253 253
43158-253 253 253 253 253 253 158 158 158 18 18 18
43159- 14 14 14 2 2 6 2 2 6 2 2 6
43160- 6 6 6 18 18 18 66 66 66 38 38 38
43161- 6 6 6 94 94 94 50 50 50 18 18 18
43162- 6 6 6 0 0 0 0 0 0 0 0 0
43163- 0 0 0 0 0 0 0 0 0 0 0 0
43164- 0 0 0 0 0 0 0 0 0 0 0 0
43165- 0 0 0 0 0 0 0 0 0 0 0 0
43166- 0 0 0 0 0 0 0 0 0 0 0 0
43167- 0 0 0 0 0 0 0 0 0 6 6 6
43168- 10 10 10 10 10 10 18 18 18 38 38 38
43169- 78 78 78 142 134 106 216 158 10 242 186 14
43170-246 190 14 246 190 14 156 118 10 10 10 10
43171- 90 90 90 238 238 238 253 253 253 253 253 253
43172-253 253 253 253 253 253 253 253 253 253 253 253
43173-253 253 253 253 253 253 231 231 231 250 250 250
43174-253 253 253 253 253 253 253 253 253 253 253 253
43175-253 253 253 253 253 253 253 253 253 253 253 253
43176-253 253 253 253 253 253 253 253 253 253 253 253
43177-253 253 253 253 253 253 253 253 253 246 230 190
43178-238 204 91 238 204 91 181 142 44 37 26 9
43179- 2 2 6 2 2 6 2 2 6 2 2 6
43180- 2 2 6 2 2 6 38 38 38 46 46 46
43181- 26 26 26 106 106 106 54 54 54 18 18 18
43182- 6 6 6 0 0 0 0 0 0 0 0 0
43183- 0 0 0 0 0 0 0 0 0 0 0 0
43184- 0 0 0 0 0 0 0 0 0 0 0 0
43185- 0 0 0 0 0 0 0 0 0 0 0 0
43186- 0 0 0 0 0 0 0 0 0 0 0 0
43187- 0 0 0 6 6 6 14 14 14 22 22 22
43188- 30 30 30 38 38 38 50 50 50 70 70 70
43189-106 106 106 190 142 34 226 170 11 242 186 14
43190-246 190 14 246 190 14 246 190 14 154 114 10
43191- 6 6 6 74 74 74 226 226 226 253 253 253
43192-253 253 253 253 253 253 253 253 253 253 253 253
43193-253 253 253 253 253 253 231 231 231 250 250 250
43194-253 253 253 253 253 253 253 253 253 253 253 253
43195-253 253 253 253 253 253 253 253 253 253 253 253
43196-253 253 253 253 253 253 253 253 253 253 253 253
43197-253 253 253 253 253 253 253 253 253 228 184 62
43198-241 196 14 241 208 19 232 195 16 38 30 10
43199- 2 2 6 2 2 6 2 2 6 2 2 6
43200- 2 2 6 6 6 6 30 30 30 26 26 26
43201-203 166 17 154 142 90 66 66 66 26 26 26
43202- 6 6 6 0 0 0 0 0 0 0 0 0
43203- 0 0 0 0 0 0 0 0 0 0 0 0
43204- 0 0 0 0 0 0 0 0 0 0 0 0
43205- 0 0 0 0 0 0 0 0 0 0 0 0
43206- 0 0 0 0 0 0 0 0 0 0 0 0
43207- 6 6 6 18 18 18 38 38 38 58 58 58
43208- 78 78 78 86 86 86 101 101 101 123 123 123
43209-175 146 61 210 150 10 234 174 13 246 186 14
43210-246 190 14 246 190 14 246 190 14 238 190 10
43211-102 78 10 2 2 6 46 46 46 198 198 198
43212-253 253 253 253 253 253 253 253 253 253 253 253
43213-253 253 253 253 253 253 234 234 234 242 242 242
43214-253 253 253 253 253 253 253 253 253 253 253 253
43215-253 253 253 253 253 253 253 253 253 253 253 253
43216-253 253 253 253 253 253 253 253 253 253 253 253
43217-253 253 253 253 253 253 253 253 253 224 178 62
43218-242 186 14 241 196 14 210 166 10 22 18 6
43219- 2 2 6 2 2 6 2 2 6 2 2 6
43220- 2 2 6 2 2 6 6 6 6 121 92 8
43221-238 202 15 232 195 16 82 82 82 34 34 34
43222- 10 10 10 0 0 0 0 0 0 0 0 0
43223- 0 0 0 0 0 0 0 0 0 0 0 0
43224- 0 0 0 0 0 0 0 0 0 0 0 0
43225- 0 0 0 0 0 0 0 0 0 0 0 0
43226- 0 0 0 0 0 0 0 0 0 0 0 0
43227- 14 14 14 38 38 38 70 70 70 154 122 46
43228-190 142 34 200 144 11 197 138 11 197 138 11
43229-213 154 11 226 170 11 242 186 14 246 190 14
43230-246 190 14 246 190 14 246 190 14 246 190 14
43231-225 175 15 46 32 6 2 2 6 22 22 22
43232-158 158 158 250 250 250 253 253 253 253 253 253
43233-253 253 253 253 253 253 253 253 253 253 253 253
43234-253 253 253 253 253 253 253 253 253 253 253 253
43235-253 253 253 253 253 253 253 253 253 253 253 253
43236-253 253 253 253 253 253 253 253 253 253 253 253
43237-253 253 253 250 250 250 242 242 242 224 178 62
43238-239 182 13 236 186 11 213 154 11 46 32 6
43239- 2 2 6 2 2 6 2 2 6 2 2 6
43240- 2 2 6 2 2 6 61 42 6 225 175 15
43241-238 190 10 236 186 11 112 100 78 42 42 42
43242- 14 14 14 0 0 0 0 0 0 0 0 0
43243- 0 0 0 0 0 0 0 0 0 0 0 0
43244- 0 0 0 0 0 0 0 0 0 0 0 0
43245- 0 0 0 0 0 0 0 0 0 0 0 0
43246- 0 0 0 0 0 0 0 0 0 6 6 6
43247- 22 22 22 54 54 54 154 122 46 213 154 11
43248-226 170 11 230 174 11 226 170 11 226 170 11
43249-236 178 12 242 186 14 246 190 14 246 190 14
43250-246 190 14 246 190 14 246 190 14 246 190 14
43251-241 196 14 184 144 12 10 10 10 2 2 6
43252- 6 6 6 116 116 116 242 242 242 253 253 253
43253-253 253 253 253 253 253 253 253 253 253 253 253
43254-253 253 253 253 253 253 253 253 253 253 253 253
43255-253 253 253 253 253 253 253 253 253 253 253 253
43256-253 253 253 253 253 253 253 253 253 253 253 253
43257-253 253 253 231 231 231 198 198 198 214 170 54
43258-236 178 12 236 178 12 210 150 10 137 92 6
43259- 18 14 6 2 2 6 2 2 6 2 2 6
43260- 6 6 6 70 47 6 200 144 11 236 178 12
43261-239 182 13 239 182 13 124 112 88 58 58 58
43262- 22 22 22 6 6 6 0 0 0 0 0 0
43263- 0 0 0 0 0 0 0 0 0 0 0 0
43264- 0 0 0 0 0 0 0 0 0 0 0 0
43265- 0 0 0 0 0 0 0 0 0 0 0 0
43266- 0 0 0 0 0 0 0 0 0 10 10 10
43267- 30 30 30 70 70 70 180 133 36 226 170 11
43268-239 182 13 242 186 14 242 186 14 246 186 14
43269-246 190 14 246 190 14 246 190 14 246 190 14
43270-246 190 14 246 190 14 246 190 14 246 190 14
43271-246 190 14 232 195 16 98 70 6 2 2 6
43272- 2 2 6 2 2 6 66 66 66 221 221 221
43273-253 253 253 253 253 253 253 253 253 253 253 253
43274-253 253 253 253 253 253 253 253 253 253 253 253
43275-253 253 253 253 253 253 253 253 253 253 253 253
43276-253 253 253 253 253 253 253 253 253 253 253 253
43277-253 253 253 206 206 206 198 198 198 214 166 58
43278-230 174 11 230 174 11 216 158 10 192 133 9
43279-163 110 8 116 81 8 102 78 10 116 81 8
43280-167 114 7 197 138 11 226 170 11 239 182 13
43281-242 186 14 242 186 14 162 146 94 78 78 78
43282- 34 34 34 14 14 14 6 6 6 0 0 0
43283- 0 0 0 0 0 0 0 0 0 0 0 0
43284- 0 0 0 0 0 0 0 0 0 0 0 0
43285- 0 0 0 0 0 0 0 0 0 0 0 0
43286- 0 0 0 0 0 0 0 0 0 6 6 6
43287- 30 30 30 78 78 78 190 142 34 226 170 11
43288-239 182 13 246 190 14 246 190 14 246 190 14
43289-246 190 14 246 190 14 246 190 14 246 190 14
43290-246 190 14 246 190 14 246 190 14 246 190 14
43291-246 190 14 241 196 14 203 166 17 22 18 6
43292- 2 2 6 2 2 6 2 2 6 38 38 38
43293-218 218 218 253 253 253 253 253 253 253 253 253
43294-253 253 253 253 253 253 253 253 253 253 253 253
43295-253 253 253 253 253 253 253 253 253 253 253 253
43296-253 253 253 253 253 253 253 253 253 253 253 253
43297-250 250 250 206 206 206 198 198 198 202 162 69
43298-226 170 11 236 178 12 224 166 10 210 150 10
43299-200 144 11 197 138 11 192 133 9 197 138 11
43300-210 150 10 226 170 11 242 186 14 246 190 14
43301-246 190 14 246 186 14 225 175 15 124 112 88
43302- 62 62 62 30 30 30 14 14 14 6 6 6
43303- 0 0 0 0 0 0 0 0 0 0 0 0
43304- 0 0 0 0 0 0 0 0 0 0 0 0
43305- 0 0 0 0 0 0 0 0 0 0 0 0
43306- 0 0 0 0 0 0 0 0 0 10 10 10
43307- 30 30 30 78 78 78 174 135 50 224 166 10
43308-239 182 13 246 190 14 246 190 14 246 190 14
43309-246 190 14 246 190 14 246 190 14 246 190 14
43310-246 190 14 246 190 14 246 190 14 246 190 14
43311-246 190 14 246 190 14 241 196 14 139 102 15
43312- 2 2 6 2 2 6 2 2 6 2 2 6
43313- 78 78 78 250 250 250 253 253 253 253 253 253
43314-253 253 253 253 253 253 253 253 253 253 253 253
43315-253 253 253 253 253 253 253 253 253 253 253 253
43316-253 253 253 253 253 253 253 253 253 253 253 253
43317-250 250 250 214 214 214 198 198 198 190 150 46
43318-219 162 10 236 178 12 234 174 13 224 166 10
43319-216 158 10 213 154 11 213 154 11 216 158 10
43320-226 170 11 239 182 13 246 190 14 246 190 14
43321-246 190 14 246 190 14 242 186 14 206 162 42
43322-101 101 101 58 58 58 30 30 30 14 14 14
43323- 6 6 6 0 0 0 0 0 0 0 0 0
43324- 0 0 0 0 0 0 0 0 0 0 0 0
43325- 0 0 0 0 0 0 0 0 0 0 0 0
43326- 0 0 0 0 0 0 0 0 0 10 10 10
43327- 30 30 30 74 74 74 174 135 50 216 158 10
43328-236 178 12 246 190 14 246 190 14 246 190 14
43329-246 190 14 246 190 14 246 190 14 246 190 14
43330-246 190 14 246 190 14 246 190 14 246 190 14
43331-246 190 14 246 190 14 241 196 14 226 184 13
43332- 61 42 6 2 2 6 2 2 6 2 2 6
43333- 22 22 22 238 238 238 253 253 253 253 253 253
43334-253 253 253 253 253 253 253 253 253 253 253 253
43335-253 253 253 253 253 253 253 253 253 253 253 253
43336-253 253 253 253 253 253 253 253 253 253 253 253
43337-253 253 253 226 226 226 187 187 187 180 133 36
43338-216 158 10 236 178 12 239 182 13 236 178 12
43339-230 174 11 226 170 11 226 170 11 230 174 11
43340-236 178 12 242 186 14 246 190 14 246 190 14
43341-246 190 14 246 190 14 246 186 14 239 182 13
43342-206 162 42 106 106 106 66 66 66 34 34 34
43343- 14 14 14 6 6 6 0 0 0 0 0 0
43344- 0 0 0 0 0 0 0 0 0 0 0 0
43345- 0 0 0 0 0 0 0 0 0 0 0 0
43346- 0 0 0 0 0 0 0 0 0 6 6 6
43347- 26 26 26 70 70 70 163 133 67 213 154 11
43348-236 178 12 246 190 14 246 190 14 246 190 14
43349-246 190 14 246 190 14 246 190 14 246 190 14
43350-246 190 14 246 190 14 246 190 14 246 190 14
43351-246 190 14 246 190 14 246 190 14 241 196 14
43352-190 146 13 18 14 6 2 2 6 2 2 6
43353- 46 46 46 246 246 246 253 253 253 253 253 253
43354-253 253 253 253 253 253 253 253 253 253 253 253
43355-253 253 253 253 253 253 253 253 253 253 253 253
43356-253 253 253 253 253 253 253 253 253 253 253 253
43357-253 253 253 221 221 221 86 86 86 156 107 11
43358-216 158 10 236 178 12 242 186 14 246 186 14
43359-242 186 14 239 182 13 239 182 13 242 186 14
43360-242 186 14 246 186 14 246 190 14 246 190 14
43361-246 190 14 246 190 14 246 190 14 246 190 14
43362-242 186 14 225 175 15 142 122 72 66 66 66
43363- 30 30 30 10 10 10 0 0 0 0 0 0
43364- 0 0 0 0 0 0 0 0 0 0 0 0
43365- 0 0 0 0 0 0 0 0 0 0 0 0
43366- 0 0 0 0 0 0 0 0 0 6 6 6
43367- 26 26 26 70 70 70 163 133 67 210 150 10
43368-236 178 12 246 190 14 246 190 14 246 190 14
43369-246 190 14 246 190 14 246 190 14 246 190 14
43370-246 190 14 246 190 14 246 190 14 246 190 14
43371-246 190 14 246 190 14 246 190 14 246 190 14
43372-232 195 16 121 92 8 34 34 34 106 106 106
43373-221 221 221 253 253 253 253 253 253 253 253 253
43374-253 253 253 253 253 253 253 253 253 253 253 253
43375-253 253 253 253 253 253 253 253 253 253 253 253
43376-253 253 253 253 253 253 253 253 253 253 253 253
43377-242 242 242 82 82 82 18 14 6 163 110 8
43378-216 158 10 236 178 12 242 186 14 246 190 14
43379-246 190 14 246 190 14 246 190 14 246 190 14
43380-246 190 14 246 190 14 246 190 14 246 190 14
43381-246 190 14 246 190 14 246 190 14 246 190 14
43382-246 190 14 246 190 14 242 186 14 163 133 67
43383- 46 46 46 18 18 18 6 6 6 0 0 0
43384- 0 0 0 0 0 0 0 0 0 0 0 0
43385- 0 0 0 0 0 0 0 0 0 0 0 0
43386- 0 0 0 0 0 0 0 0 0 10 10 10
43387- 30 30 30 78 78 78 163 133 67 210 150 10
43388-236 178 12 246 186 14 246 190 14 246 190 14
43389-246 190 14 246 190 14 246 190 14 246 190 14
43390-246 190 14 246 190 14 246 190 14 246 190 14
43391-246 190 14 246 190 14 246 190 14 246 190 14
43392-241 196 14 215 174 15 190 178 144 253 253 253
43393-253 253 253 253 253 253 253 253 253 253 253 253
43394-253 253 253 253 253 253 253 253 253 253 253 253
43395-253 253 253 253 253 253 253 253 253 253 253 253
43396-253 253 253 253 253 253 253 253 253 218 218 218
43397- 58 58 58 2 2 6 22 18 6 167 114 7
43398-216 158 10 236 178 12 246 186 14 246 190 14
43399-246 190 14 246 190 14 246 190 14 246 190 14
43400-246 190 14 246 190 14 246 190 14 246 190 14
43401-246 190 14 246 190 14 246 190 14 246 190 14
43402-246 190 14 246 186 14 242 186 14 190 150 46
43403- 54 54 54 22 22 22 6 6 6 0 0 0
43404- 0 0 0 0 0 0 0 0 0 0 0 0
43405- 0 0 0 0 0 0 0 0 0 0 0 0
43406- 0 0 0 0 0 0 0 0 0 14 14 14
43407- 38 38 38 86 86 86 180 133 36 213 154 11
43408-236 178 12 246 186 14 246 190 14 246 190 14
43409-246 190 14 246 190 14 246 190 14 246 190 14
43410-246 190 14 246 190 14 246 190 14 246 190 14
43411-246 190 14 246 190 14 246 190 14 246 190 14
43412-246 190 14 232 195 16 190 146 13 214 214 214
43413-253 253 253 253 253 253 253 253 253 253 253 253
43414-253 253 253 253 253 253 253 253 253 253 253 253
43415-253 253 253 253 253 253 253 253 253 253 253 253
43416-253 253 253 250 250 250 170 170 170 26 26 26
43417- 2 2 6 2 2 6 37 26 9 163 110 8
43418-219 162 10 239 182 13 246 186 14 246 190 14
43419-246 190 14 246 190 14 246 190 14 246 190 14
43420-246 190 14 246 190 14 246 190 14 246 190 14
43421-246 190 14 246 190 14 246 190 14 246 190 14
43422-246 186 14 236 178 12 224 166 10 142 122 72
43423- 46 46 46 18 18 18 6 6 6 0 0 0
43424- 0 0 0 0 0 0 0 0 0 0 0 0
43425- 0 0 0 0 0 0 0 0 0 0 0 0
43426- 0 0 0 0 0 0 6 6 6 18 18 18
43427- 50 50 50 109 106 95 192 133 9 224 166 10
43428-242 186 14 246 190 14 246 190 14 246 190 14
43429-246 190 14 246 190 14 246 190 14 246 190 14
43430-246 190 14 246 190 14 246 190 14 246 190 14
43431-246 190 14 246 190 14 246 190 14 246 190 14
43432-242 186 14 226 184 13 210 162 10 142 110 46
43433-226 226 226 253 253 253 253 253 253 253 253 253
43434-253 253 253 253 253 253 253 253 253 253 253 253
43435-253 253 253 253 253 253 253 253 253 253 253 253
43436-198 198 198 66 66 66 2 2 6 2 2 6
43437- 2 2 6 2 2 6 50 34 6 156 107 11
43438-219 162 10 239 182 13 246 186 14 246 190 14
43439-246 190 14 246 190 14 246 190 14 246 190 14
43440-246 190 14 246 190 14 246 190 14 246 190 14
43441-246 190 14 246 190 14 246 190 14 242 186 14
43442-234 174 13 213 154 11 154 122 46 66 66 66
43443- 30 30 30 10 10 10 0 0 0 0 0 0
43444- 0 0 0 0 0 0 0 0 0 0 0 0
43445- 0 0 0 0 0 0 0 0 0 0 0 0
43446- 0 0 0 0 0 0 6 6 6 22 22 22
43447- 58 58 58 154 121 60 206 145 10 234 174 13
43448-242 186 14 246 186 14 246 190 14 246 190 14
43449-246 190 14 246 190 14 246 190 14 246 190 14
43450-246 190 14 246 190 14 246 190 14 246 190 14
43451-246 190 14 246 190 14 246 190 14 246 190 14
43452-246 186 14 236 178 12 210 162 10 163 110 8
43453- 61 42 6 138 138 138 218 218 218 250 250 250
43454-253 253 253 253 253 253 253 253 253 250 250 250
43455-242 242 242 210 210 210 144 144 144 66 66 66
43456- 6 6 6 2 2 6 2 2 6 2 2 6
43457- 2 2 6 2 2 6 61 42 6 163 110 8
43458-216 158 10 236 178 12 246 190 14 246 190 14
43459-246 190 14 246 190 14 246 190 14 246 190 14
43460-246 190 14 246 190 14 246 190 14 246 190 14
43461-246 190 14 239 182 13 230 174 11 216 158 10
43462-190 142 34 124 112 88 70 70 70 38 38 38
43463- 18 18 18 6 6 6 0 0 0 0 0 0
43464- 0 0 0 0 0 0 0 0 0 0 0 0
43465- 0 0 0 0 0 0 0 0 0 0 0 0
43466- 0 0 0 0 0 0 6 6 6 22 22 22
43467- 62 62 62 168 124 44 206 145 10 224 166 10
43468-236 178 12 239 182 13 242 186 14 242 186 14
43469-246 186 14 246 190 14 246 190 14 246 190 14
43470-246 190 14 246 190 14 246 190 14 246 190 14
43471-246 190 14 246 190 14 246 190 14 246 190 14
43472-246 190 14 236 178 12 216 158 10 175 118 6
43473- 80 54 7 2 2 6 6 6 6 30 30 30
43474- 54 54 54 62 62 62 50 50 50 38 38 38
43475- 14 14 14 2 2 6 2 2 6 2 2 6
43476- 2 2 6 2 2 6 2 2 6 2 2 6
43477- 2 2 6 6 6 6 80 54 7 167 114 7
43478-213 154 11 236 178 12 246 190 14 246 190 14
43479-246 190 14 246 190 14 246 190 14 246 190 14
43480-246 190 14 242 186 14 239 182 13 239 182 13
43481-230 174 11 210 150 10 174 135 50 124 112 88
43482- 82 82 82 54 54 54 34 34 34 18 18 18
43483- 6 6 6 0 0 0 0 0 0 0 0 0
43484- 0 0 0 0 0 0 0 0 0 0 0 0
43485- 0 0 0 0 0 0 0 0 0 0 0 0
43486- 0 0 0 0 0 0 6 6 6 18 18 18
43487- 50 50 50 158 118 36 192 133 9 200 144 11
43488-216 158 10 219 162 10 224 166 10 226 170 11
43489-230 174 11 236 178 12 239 182 13 239 182 13
43490-242 186 14 246 186 14 246 190 14 246 190 14
43491-246 190 14 246 190 14 246 190 14 246 190 14
43492-246 186 14 230 174 11 210 150 10 163 110 8
43493-104 69 6 10 10 10 2 2 6 2 2 6
43494- 2 2 6 2 2 6 2 2 6 2 2 6
43495- 2 2 6 2 2 6 2 2 6 2 2 6
43496- 2 2 6 2 2 6 2 2 6 2 2 6
43497- 2 2 6 6 6 6 91 60 6 167 114 7
43498-206 145 10 230 174 11 242 186 14 246 190 14
43499-246 190 14 246 190 14 246 186 14 242 186 14
43500-239 182 13 230 174 11 224 166 10 213 154 11
43501-180 133 36 124 112 88 86 86 86 58 58 58
43502- 38 38 38 22 22 22 10 10 10 6 6 6
43503- 0 0 0 0 0 0 0 0 0 0 0 0
43504- 0 0 0 0 0 0 0 0 0 0 0 0
43505- 0 0 0 0 0 0 0 0 0 0 0 0
43506- 0 0 0 0 0 0 0 0 0 14 14 14
43507- 34 34 34 70 70 70 138 110 50 158 118 36
43508-167 114 7 180 123 7 192 133 9 197 138 11
43509-200 144 11 206 145 10 213 154 11 219 162 10
43510-224 166 10 230 174 11 239 182 13 242 186 14
43511-246 186 14 246 186 14 246 186 14 246 186 14
43512-239 182 13 216 158 10 185 133 11 152 99 6
43513-104 69 6 18 14 6 2 2 6 2 2 6
43514- 2 2 6 2 2 6 2 2 6 2 2 6
43515- 2 2 6 2 2 6 2 2 6 2 2 6
43516- 2 2 6 2 2 6 2 2 6 2 2 6
43517- 2 2 6 6 6 6 80 54 7 152 99 6
43518-192 133 9 219 162 10 236 178 12 239 182 13
43519-246 186 14 242 186 14 239 182 13 236 178 12
43520-224 166 10 206 145 10 192 133 9 154 121 60
43521- 94 94 94 62 62 62 42 42 42 22 22 22
43522- 14 14 14 6 6 6 0 0 0 0 0 0
43523- 0 0 0 0 0 0 0 0 0 0 0 0
43524- 0 0 0 0 0 0 0 0 0 0 0 0
43525- 0 0 0 0 0 0 0 0 0 0 0 0
43526- 0 0 0 0 0 0 0 0 0 6 6 6
43527- 18 18 18 34 34 34 58 58 58 78 78 78
43528-101 98 89 124 112 88 142 110 46 156 107 11
43529-163 110 8 167 114 7 175 118 6 180 123 7
43530-185 133 11 197 138 11 210 150 10 219 162 10
43531-226 170 11 236 178 12 236 178 12 234 174 13
43532-219 162 10 197 138 11 163 110 8 130 83 6
43533- 91 60 6 10 10 10 2 2 6 2 2 6
43534- 18 18 18 38 38 38 38 38 38 38 38 38
43535- 38 38 38 38 38 38 38 38 38 38 38 38
43536- 38 38 38 38 38 38 26 26 26 2 2 6
43537- 2 2 6 6 6 6 70 47 6 137 92 6
43538-175 118 6 200 144 11 219 162 10 230 174 11
43539-234 174 13 230 174 11 219 162 10 210 150 10
43540-192 133 9 163 110 8 124 112 88 82 82 82
43541- 50 50 50 30 30 30 14 14 14 6 6 6
43542- 0 0 0 0 0 0 0 0 0 0 0 0
43543- 0 0 0 0 0 0 0 0 0 0 0 0
43544- 0 0 0 0 0 0 0 0 0 0 0 0
43545- 0 0 0 0 0 0 0 0 0 0 0 0
43546- 0 0 0 0 0 0 0 0 0 0 0 0
43547- 6 6 6 14 14 14 22 22 22 34 34 34
43548- 42 42 42 58 58 58 74 74 74 86 86 86
43549-101 98 89 122 102 70 130 98 46 121 87 25
43550-137 92 6 152 99 6 163 110 8 180 123 7
43551-185 133 11 197 138 11 206 145 10 200 144 11
43552-180 123 7 156 107 11 130 83 6 104 69 6
43553- 50 34 6 54 54 54 110 110 110 101 98 89
43554- 86 86 86 82 82 82 78 78 78 78 78 78
43555- 78 78 78 78 78 78 78 78 78 78 78 78
43556- 78 78 78 82 82 82 86 86 86 94 94 94
43557-106 106 106 101 101 101 86 66 34 124 80 6
43558-156 107 11 180 123 7 192 133 9 200 144 11
43559-206 145 10 200 144 11 192 133 9 175 118 6
43560-139 102 15 109 106 95 70 70 70 42 42 42
43561- 22 22 22 10 10 10 0 0 0 0 0 0
43562- 0 0 0 0 0 0 0 0 0 0 0 0
43563- 0 0 0 0 0 0 0 0 0 0 0 0
43564- 0 0 0 0 0 0 0 0 0 0 0 0
43565- 0 0 0 0 0 0 0 0 0 0 0 0
43566- 0 0 0 0 0 0 0 0 0 0 0 0
43567- 0 0 0 0 0 0 6 6 6 10 10 10
43568- 14 14 14 22 22 22 30 30 30 38 38 38
43569- 50 50 50 62 62 62 74 74 74 90 90 90
43570-101 98 89 112 100 78 121 87 25 124 80 6
43571-137 92 6 152 99 6 152 99 6 152 99 6
43572-138 86 6 124 80 6 98 70 6 86 66 30
43573-101 98 89 82 82 82 58 58 58 46 46 46
43574- 38 38 38 34 34 34 34 34 34 34 34 34
43575- 34 34 34 34 34 34 34 34 34 34 34 34
43576- 34 34 34 34 34 34 38 38 38 42 42 42
43577- 54 54 54 82 82 82 94 86 76 91 60 6
43578-134 86 6 156 107 11 167 114 7 175 118 6
43579-175 118 6 167 114 7 152 99 6 121 87 25
43580-101 98 89 62 62 62 34 34 34 18 18 18
43581- 6 6 6 0 0 0 0 0 0 0 0 0
43582- 0 0 0 0 0 0 0 0 0 0 0 0
43583- 0 0 0 0 0 0 0 0 0 0 0 0
43584- 0 0 0 0 0 0 0 0 0 0 0 0
43585- 0 0 0 0 0 0 0 0 0 0 0 0
43586- 0 0 0 0 0 0 0 0 0 0 0 0
43587- 0 0 0 0 0 0 0 0 0 0 0 0
43588- 0 0 0 6 6 6 6 6 6 10 10 10
43589- 18 18 18 22 22 22 30 30 30 42 42 42
43590- 50 50 50 66 66 66 86 86 86 101 98 89
43591-106 86 58 98 70 6 104 69 6 104 69 6
43592-104 69 6 91 60 6 82 62 34 90 90 90
43593- 62 62 62 38 38 38 22 22 22 14 14 14
43594- 10 10 10 10 10 10 10 10 10 10 10 10
43595- 10 10 10 10 10 10 6 6 6 10 10 10
43596- 10 10 10 10 10 10 10 10 10 14 14 14
43597- 22 22 22 42 42 42 70 70 70 89 81 66
43598- 80 54 7 104 69 6 124 80 6 137 92 6
43599-134 86 6 116 81 8 100 82 52 86 86 86
43600- 58 58 58 30 30 30 14 14 14 6 6 6
43601- 0 0 0 0 0 0 0 0 0 0 0 0
43602- 0 0 0 0 0 0 0 0 0 0 0 0
43603- 0 0 0 0 0 0 0 0 0 0 0 0
43604- 0 0 0 0 0 0 0 0 0 0 0 0
43605- 0 0 0 0 0 0 0 0 0 0 0 0
43606- 0 0 0 0 0 0 0 0 0 0 0 0
43607- 0 0 0 0 0 0 0 0 0 0 0 0
43608- 0 0 0 0 0 0 0 0 0 0 0 0
43609- 0 0 0 6 6 6 10 10 10 14 14 14
43610- 18 18 18 26 26 26 38 38 38 54 54 54
43611- 70 70 70 86 86 86 94 86 76 89 81 66
43612- 89 81 66 86 86 86 74 74 74 50 50 50
43613- 30 30 30 14 14 14 6 6 6 0 0 0
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- 6 6 6 18 18 18 34 34 34 58 58 58
43618- 82 82 82 89 81 66 89 81 66 89 81 66
43619- 94 86 66 94 86 76 74 74 74 50 50 50
43620- 26 26 26 14 14 14 6 6 6 0 0 0
43621- 0 0 0 0 0 0 0 0 0 0 0 0
43622- 0 0 0 0 0 0 0 0 0 0 0 0
43623- 0 0 0 0 0 0 0 0 0 0 0 0
43624- 0 0 0 0 0 0 0 0 0 0 0 0
43625- 0 0 0 0 0 0 0 0 0 0 0 0
43626- 0 0 0 0 0 0 0 0 0 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 6 6 6 14 14 14 18 18 18
43631- 30 30 30 38 38 38 46 46 46 54 54 54
43632- 50 50 50 42 42 42 30 30 30 18 18 18
43633- 10 10 10 0 0 0 0 0 0 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 6 6 6 14 14 14 26 26 26
43638- 38 38 38 50 50 50 58 58 58 58 58 58
43639- 54 54 54 42 42 42 30 30 30 18 18 18
43640- 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
43644- 0 0 0 0 0 0 0 0 0 0 0 0
43645- 0 0 0 0 0 0 0 0 0 0 0 0
43646- 0 0 0 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 0 0 0 0 0 0 6 6 6
43651- 6 6 6 10 10 10 14 14 14 18 18 18
43652- 18 18 18 14 14 14 10 10 10 6 6 6
43653- 0 0 0 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 6 6 6
43658- 14 14 14 18 18 18 22 22 22 22 22 22
43659- 18 18 18 14 14 14 10 10 10 6 6 6
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 0 0 0
43664- 0 0 0 0 0 0 0 0 0 0 0 0
43665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43678+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 4 4 4 4 4 4 4 4 4 4 4 4
43692+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 4 4 4 4 4 4 4 4 4 4 4 4
43706+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 4 4 4 4 4 4 4 4 4 4 4 4
43720+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 4 4 4 4 4 4 4 4 4 4 4 4
43734+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 4 4 4 4 4 4 4 4 4 4 4 4
43748+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 3 3 3 0 0 0 0 0 0
43754+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 1 1 1 0 0 0
43759+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43760+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
43761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43762+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 4 4 4 4 4 4 4 4 4
43767+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
43768+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
43769+5 5 5 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 4 4 4 4 4 4
43772+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
43773+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
43774+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
43775+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43776+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 4 4 4 4 4 4 4 4 4 4 4 4
43781+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
43782+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
43783+0 0 0 3 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
43786+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
43787+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
43788+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
43789+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
43790+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+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
43795+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
43796+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
43797+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 5 5 5 5 5 5
43800+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
43801+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
43802+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
43803+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
43804+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 4 4 4 4 4 4 4 4 4 4 4 4
43808+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
43809+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
43810+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
43811+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
43812+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43813+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
43814+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
43815+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
43816+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
43817+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
43818+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 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43822+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
43823+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
43824+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
43825+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
43826+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
43827+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
43828+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
43829+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
43830+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
43831+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
43832+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 4 4 4
43835+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
43836+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
43837+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
43838+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
43839+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
43840+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
43841+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
43842+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
43843+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
43844+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
43845+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
43846+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 4 4 4 4 4 4
43849+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
43850+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
43851+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
43852+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
43853+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
43854+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
43855+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
43856+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
43857+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
43858+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
43859+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
43860+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 4 4 4 4 4 4 4 4 4
43863+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
43864+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
43865+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
43866+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
43867+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
43868+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
43869+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
43870+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
43871+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
43872+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
43873+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43874+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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43877+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
43878+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
43879+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
43880+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
43881+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
43882+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
43883+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
43884+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
43885+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
43886+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
43887+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
43888+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+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
43891+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
43892+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
43893+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
43894+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
43895+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
43896+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
43897+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
43898+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
43899+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
43900+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
43901+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
43902+4 4 4 4 4 4
43903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43904+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
43905+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
43906+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
43907+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43908+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
43909+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
43910+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
43911+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
43912+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
43913+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
43914+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
43915+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
43916+0 0 0 4 4 4
43917+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
43918+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
43919+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
43920+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
43921+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
43922+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
43923+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
43924+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
43925+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
43926+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
43927+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
43928+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
43929+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
43930+2 0 0 0 0 0
43931+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
43932+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
43933+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
43934+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
43935+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
43936+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
43937+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
43938+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
43939+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
43940+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
43941+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
43942+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
43943+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
43944+37 38 37 0 0 0
43945+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
43946+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
43947+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
43948+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
43949+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
43950+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
43951+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
43952+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
43953+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
43954+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
43955+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
43956+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
43957+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
43958+85 115 134 4 0 0
43959+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
43960+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
43961+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
43962+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
43963+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
43964+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
43965+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
43966+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
43967+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
43968+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
43969+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
43970+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
43971+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
43972+60 73 81 4 0 0
43973+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
43974+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
43975+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
43976+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
43977+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
43978+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
43979+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
43980+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
43981+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
43982+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
43983+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
43984+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
43985+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
43986+16 19 21 4 0 0
43987+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
43988+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
43989+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
43990+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
43991+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
43992+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
43993+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
43994+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
43995+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
43996+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
43997+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
43998+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
43999+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
44000+4 0 0 4 3 3
44001+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
44002+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
44003+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
44004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
44005+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
44006+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
44007+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
44008+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
44009+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
44010+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
44011+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
44012+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
44013+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
44014+3 2 2 4 4 4
44015+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
44016+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
44017+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
44018+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
44019+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
44020+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
44021+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
44022+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
44023+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
44024+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
44025+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
44026+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
44027+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
44028+4 4 4 4 4 4
44029+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
44030+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
44031+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
44032+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
44033+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
44034+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
44035+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
44036+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
44037+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
44038+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
44039+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
44040+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
44041+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
44042+4 4 4 4 4 4
44043+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
44044+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
44045+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
44046+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
44047+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
44048+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
44049+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
44050+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
44051+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
44052+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
44053+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
44054+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
44055+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
44056+5 5 5 5 5 5
44057+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
44058+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
44059+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
44060+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
44061+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
44062+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44063+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
44064+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
44065+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
44066+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
44067+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
44068+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
44069+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
44070+5 5 5 4 4 4
44071+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
44072+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
44073+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
44074+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
44075+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
44076+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
44077+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
44078+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
44079+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
44080+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
44081+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
44082+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
44083+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44084+4 4 4 4 4 4
44085+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
44086+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
44087+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
44088+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
44089+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
44090+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44091+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44092+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
44093+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
44094+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
44095+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
44096+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
44097+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44098+4 4 4 4 4 4
44099+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
44100+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
44101+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
44102+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
44103+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
44104+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
44105+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
44106+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
44107+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
44108+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
44109+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 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 4 4 4 4 4 4 4 4 4 4 4 4
44112+4 4 4 4 4 4
44113+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
44114+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
44115+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
44116+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
44117+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
44118+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44119+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44120+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
44121+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
44122+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
44123+6 6 6 4 0 0 4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
44126+4 4 4 4 4 4
44127+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
44128+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
44129+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
44130+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
44131+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
44132+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
44133+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
44134+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
44135+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
44136+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
44137+4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44140+4 4 4 4 4 4
44141+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
44142+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
44143+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
44144+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
44145+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
44146+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
44147+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
44148+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
44149+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
44150+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
44151+6 6 6 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
44154+4 4 4 4 4 4
44155+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
44156+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
44157+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
44158+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
44159+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
44160+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
44161+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
44162+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
44163+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
44164+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
44165+4 0 0 3 2 2 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44168+4 4 4 4 4 4
44169+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
44170+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
44171+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
44172+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
44173+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
44174+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
44175+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
44176+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
44177+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
44178+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
44179+4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44182+4 4 4 4 4 4
44183+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
44184+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
44185+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
44186+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
44187+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44188+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
44189+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
44190+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
44191+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
44192+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
44193+4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44196+4 4 4 4 4 4
44197+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
44198+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
44199+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
44200+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
44201+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44202+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
44203+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
44204+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
44205+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
44206+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
44207+4 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44210+4 4 4 4 4 4
44211+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
44212+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
44213+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
44214+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
44215+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44216+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
44217+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
44218+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
44219+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
44220+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44221+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44224+4 4 4 4 4 4
44225+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
44226+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
44227+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
44228+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
44229+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
44230+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
44231+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
44232+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
44233+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44234+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44235+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44238+4 4 4 4 4 4
44239+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
44240+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
44241+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
44242+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
44243+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44244+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
44245+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
44246+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
44247+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
44248+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44249+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44252+4 4 4 4 4 4
44253+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
44254+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
44255+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
44256+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
44257+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
44258+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
44259+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
44260+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
44261+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44262+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44263+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44266+4 4 4 4 4 4
44267+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
44268+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
44269+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
44270+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
44271+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
44272+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
44273+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
44274+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
44275+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
44276+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44277+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44280+4 4 4 4 4 4
44281+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
44282+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
44283+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
44284+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
44285+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
44286+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
44287+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
44288+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
44289+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44290+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44291+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44294+4 4 4 4 4 4
44295+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
44296+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
44297+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
44298+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
44299+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
44300+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
44301+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
44302+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
44303+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
44304+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44305+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44308+4 4 4 4 4 4
44309+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
44310+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
44311+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
44312+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
44313+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
44314+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
44315+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
44316+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
44317+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44318+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44319+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44322+4 4 4 4 4 4
44323+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44324+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
44325+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
44326+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
44327+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
44328+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
44329+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
44330+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
44331+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
44332+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44333+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44336+4 4 4 4 4 4
44337+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
44338+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
44339+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
44340+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
44341+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
44342+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
44343+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44344+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
44345+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44346+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44347+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44350+4 4 4 4 4 4
44351+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44352+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
44353+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
44354+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
44355+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
44356+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
44357+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44358+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
44359+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
44360+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44361+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44364+4 4 4 4 4 4
44365+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
44366+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
44367+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
44368+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
44369+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
44370+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
44371+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
44372+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
44373+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
44374+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44375+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44378+4 4 4 4 4 4
44379+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44380+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
44381+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
44382+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
44383+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
44384+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
44385+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
44386+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
44387+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
44388+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44389+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44392+4 4 4 4 4 4
44393+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
44394+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
44395+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
44396+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
44397+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
44398+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
44399+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
44400+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
44401+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
44402+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44403+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44406+4 4 4 4 4 4
44407+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44408+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
44409+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
44410+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
44411+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
44412+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
44413+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
44414+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
44415+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
44416+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44417+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44420+4 4 4 4 4 4
44421+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
44422+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
44423+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
44424+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
44425+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
44426+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
44427+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
44428+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
44429+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
44430+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
44431+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44434+4 4 4 4 4 4
44435+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
44436+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
44437+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
44438+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
44439+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
44440+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
44441+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
44442+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
44443+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
44444+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
44445+0 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
44448+4 4 4 4 4 4
44449+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
44450+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
44451+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
44452+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
44453+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
44454+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
44455+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44456+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
44457+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
44458+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
44459+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44462+4 4 4 4 4 4
44463+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
44464+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
44465+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
44466+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
44467+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
44468+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
44469+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
44470+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
44471+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
44472+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
44473+5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44476+4 4 4 4 4 4
44477+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
44478+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
44479+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
44480+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
44481+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
44482+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
44483+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
44484+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
44485+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
44486+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
44490+4 4 4 4 4 4
44491+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44492+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
44493+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
44494+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
44495+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
44496+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
44497+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
44498+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
44499+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
44500+13 16 17 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
44504+4 4 4 4 4 4
44505+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
44506+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
44507+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
44508+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
44509+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
44510+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
44511+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
44512+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
44513+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
44514+4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44518+4 4 4 4 4 4
44519+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
44520+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
44521+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
44522+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
44523+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
44524+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
44525+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
44526+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
44527+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
44528+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44532+4 4 4 4 4 4
44533+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
44534+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44535+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
44536+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
44537+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
44538+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
44539+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
44540+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
44541+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 4 4 4 4 4 4 4 4 4 4 4 4
44546+4 4 4 4 4 4
44547+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
44548+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
44549+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
44550+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
44551+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
44552+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
44553+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
44554+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
44555+4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
44560+4 4 4 4 4 4
44561+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
44562+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
44563+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
44564+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
44565+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
44566+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
44567+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
44568+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
44569+4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
44574+4 4 4 4 4 4
44575+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
44576+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
44577+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
44578+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
44579+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
44580+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
44581+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
44582+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4 4 4 4
44588+4 4 4 4 4 4
44589+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
44590+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
44591+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
44592+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
44593+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
44594+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
44595+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
44596+6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
44602+4 4 4 4 4 4
44603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44604+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
44605+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44606+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
44607+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
44608+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
44609+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
44610+4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
44616+4 4 4 4 4 4
44617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44618+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
44619+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
44620+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
44621+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
44622+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
44623+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
44624+6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44630+4 4 4 4 4 4
44631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44632+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
44633+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
44634+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
44635+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
44636+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
44637+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
44638+5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44644+4 4 4 4 4 4
44645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44647+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
44648+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
44649+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
44650+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
44651+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
44652+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44658+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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44662+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44663+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
44664+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
44665+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
44672+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 4 4 4
44675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44676+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
44677+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
44678+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
44679+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
44686+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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44690+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
44691+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44692+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
44693+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44700+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 4 4 4 4 4 4 4 4 4 4 4 4
44704+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
44705+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
44706+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
44707+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44714+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 4 4 4 4 4 4 4 4 4
44718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44719+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
44720+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44721+6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44728+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 4 4 4
44732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44733+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
44734+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
44735+4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44742+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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44747+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
44748+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
44749+5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44756+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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44761+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
44762+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
44770+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 4 4 4 4 4 4 4 4 4
44775+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
44776+5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44784+4 4 4 4 4 4
44785diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
44786index 86d449e..af6a7f7 100644
44787--- a/drivers/video/udlfb.c
44788+++ b/drivers/video/udlfb.c
44789@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
44790 dlfb_urb_completion(urb);
44791
44792 error:
44793- atomic_add(bytes_sent, &dev->bytes_sent);
44794- atomic_add(bytes_identical, &dev->bytes_identical);
44795- atomic_add(width*height*2, &dev->bytes_rendered);
44796+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44797+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44798+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
44799 end_cycles = get_cycles();
44800- atomic_add(((unsigned int) ((end_cycles - start_cycles)
44801+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44802 >> 10)), /* Kcycles */
44803 &dev->cpu_kcycles_used);
44804
44805@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
44806 dlfb_urb_completion(urb);
44807
44808 error:
44809- atomic_add(bytes_sent, &dev->bytes_sent);
44810- atomic_add(bytes_identical, &dev->bytes_identical);
44811- atomic_add(bytes_rendered, &dev->bytes_rendered);
44812+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44813+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44814+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
44815 end_cycles = get_cycles();
44816- atomic_add(((unsigned int) ((end_cycles - start_cycles)
44817+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44818 >> 10)), /* Kcycles */
44819 &dev->cpu_kcycles_used);
44820 }
44821@@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
44822 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44823 struct dlfb_data *dev = fb_info->par;
44824 return snprintf(buf, PAGE_SIZE, "%u\n",
44825- atomic_read(&dev->bytes_rendered));
44826+ atomic_read_unchecked(&dev->bytes_rendered));
44827 }
44828
44829 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44830@@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44831 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44832 struct dlfb_data *dev = fb_info->par;
44833 return snprintf(buf, PAGE_SIZE, "%u\n",
44834- atomic_read(&dev->bytes_identical));
44835+ atomic_read_unchecked(&dev->bytes_identical));
44836 }
44837
44838 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44839@@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44840 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44841 struct dlfb_data *dev = fb_info->par;
44842 return snprintf(buf, PAGE_SIZE, "%u\n",
44843- atomic_read(&dev->bytes_sent));
44844+ atomic_read_unchecked(&dev->bytes_sent));
44845 }
44846
44847 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44848@@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44849 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44850 struct dlfb_data *dev = fb_info->par;
44851 return snprintf(buf, PAGE_SIZE, "%u\n",
44852- atomic_read(&dev->cpu_kcycles_used));
44853+ atomic_read_unchecked(&dev->cpu_kcycles_used));
44854 }
44855
44856 static ssize_t edid_show(
44857@@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
44858 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44859 struct dlfb_data *dev = fb_info->par;
44860
44861- atomic_set(&dev->bytes_rendered, 0);
44862- atomic_set(&dev->bytes_identical, 0);
44863- atomic_set(&dev->bytes_sent, 0);
44864- atomic_set(&dev->cpu_kcycles_used, 0);
44865+ atomic_set_unchecked(&dev->bytes_rendered, 0);
44866+ atomic_set_unchecked(&dev->bytes_identical, 0);
44867+ atomic_set_unchecked(&dev->bytes_sent, 0);
44868+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
44869
44870 return count;
44871 }
44872diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
44873index b75db01..5631c6d 100644
44874--- a/drivers/video/uvesafb.c
44875+++ b/drivers/video/uvesafb.c
44876@@ -19,6 +19,7 @@
44877 #include <linux/io.h>
44878 #include <linux/mutex.h>
44879 #include <linux/slab.h>
44880+#include <linux/moduleloader.h>
44881 #include <video/edid.h>
44882 #include <video/uvesafb.h>
44883 #ifdef CONFIG_X86
44884@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
44885 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
44886 par->pmi_setpal = par->ypan = 0;
44887 } else {
44888+
44889+#ifdef CONFIG_PAX_KERNEXEC
44890+#ifdef CONFIG_MODULES
44891+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
44892+#endif
44893+ if (!par->pmi_code) {
44894+ par->pmi_setpal = par->ypan = 0;
44895+ return 0;
44896+ }
44897+#endif
44898+
44899 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
44900 + task->t.regs.edi);
44901+
44902+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44903+ pax_open_kernel();
44904+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
44905+ pax_close_kernel();
44906+
44907+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
44908+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
44909+#else
44910 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
44911 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
44912+#endif
44913+
44914 printk(KERN_INFO "uvesafb: protected mode interface info at "
44915 "%04x:%04x\n",
44916 (u16)task->t.regs.es, (u16)task->t.regs.edi);
44917@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
44918 par->ypan = ypan;
44919
44920 if (par->pmi_setpal || par->ypan) {
44921+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
44922 if (__supported_pte_mask & _PAGE_NX) {
44923 par->pmi_setpal = par->ypan = 0;
44924 printk(KERN_WARNING "uvesafb: NX protection is actively."
44925 "We have better not to use the PMI.\n");
44926- } else {
44927+ } else
44928+#endif
44929 uvesafb_vbe_getpmi(task, par);
44930- }
44931 }
44932 #else
44933 /* The protected mode interface is not available on non-x86. */
44934@@ -1836,6 +1860,11 @@ out:
44935 if (par->vbe_modes)
44936 kfree(par->vbe_modes);
44937
44938+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44939+ if (par->pmi_code)
44940+ module_free_exec(NULL, par->pmi_code);
44941+#endif
44942+
44943 framebuffer_release(info);
44944 return err;
44945 }
44946@@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
44947 kfree(par->vbe_state_orig);
44948 if (par->vbe_state_saved)
44949 kfree(par->vbe_state_saved);
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 }
44957
44958 framebuffer_release(info);
44959diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
44960index 501b340..86bd4cf 100644
44961--- a/drivers/video/vesafb.c
44962+++ b/drivers/video/vesafb.c
44963@@ -9,6 +9,7 @@
44964 */
44965
44966 #include <linux/module.h>
44967+#include <linux/moduleloader.h>
44968 #include <linux/kernel.h>
44969 #include <linux/errno.h>
44970 #include <linux/string.h>
44971@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
44972 static int vram_total __initdata; /* Set total amount of memory */
44973 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
44974 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
44975-static void (*pmi_start)(void) __read_mostly;
44976-static void (*pmi_pal) (void) __read_mostly;
44977+static void (*pmi_start)(void) __read_only;
44978+static void (*pmi_pal) (void) __read_only;
44979 static int depth __read_mostly;
44980 static int vga_compat __read_mostly;
44981 /* --------------------------------------------------------------------- */
44982@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
44983 unsigned int size_vmode;
44984 unsigned int size_remap;
44985 unsigned int size_total;
44986+ void *pmi_code = NULL;
44987
44988 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
44989 return -ENODEV;
44990@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
44991 size_remap = size_total;
44992 vesafb_fix.smem_len = size_remap;
44993
44994-#ifndef __i386__
44995- screen_info.vesapm_seg = 0;
44996-#endif
44997-
44998 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
44999 printk(KERN_WARNING
45000 "vesafb: cannot reserve video memory at 0x%lx\n",
45001@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
45002 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
45003 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
45004
45005+#ifdef __i386__
45006+
45007+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45008+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
45009+ if (!pmi_code)
45010+#elif !defined(CONFIG_PAX_KERNEXEC)
45011+ if (0)
45012+#endif
45013+
45014+#endif
45015+ screen_info.vesapm_seg = 0;
45016+
45017 if (screen_info.vesapm_seg) {
45018- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
45019- screen_info.vesapm_seg,screen_info.vesapm_off);
45020+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
45021+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
45022 }
45023
45024 if (screen_info.vesapm_seg < 0xc000)
45025@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
45026
45027 if (ypan || pmi_setpal) {
45028 unsigned short *pmi_base;
45029+
45030 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
45031- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
45032- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
45033+
45034+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45035+ pax_open_kernel();
45036+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
45037+#else
45038+ pmi_code = pmi_base;
45039+#endif
45040+
45041+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
45042+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
45043+
45044+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45045+ pmi_start = ktva_ktla(pmi_start);
45046+ pmi_pal = ktva_ktla(pmi_pal);
45047+ pax_close_kernel();
45048+#endif
45049+
45050 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
45051 if (pmi_base[3]) {
45052 printk(KERN_INFO "vesafb: pmi: ports = ");
45053@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
45054 info->node, info->fix.id);
45055 return 0;
45056 err:
45057+
45058+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45059+ module_free_exec(NULL, pmi_code);
45060+#endif
45061+
45062 if (info->screen_base)
45063 iounmap(info->screen_base);
45064 framebuffer_release(info);
45065diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
45066index 88714ae..16c2e11 100644
45067--- a/drivers/video/via/via_clock.h
45068+++ b/drivers/video/via/via_clock.h
45069@@ -56,7 +56,7 @@ struct via_clock {
45070
45071 void (*set_engine_pll_state)(u8 state);
45072 void (*set_engine_pll)(struct via_pll_config config);
45073-};
45074+} __no_const;
45075
45076
45077 static inline u32 get_pll_internal_frequency(u32 ref_freq,
45078diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
45079index fef20db..d28b1ab 100644
45080--- a/drivers/xen/xenfs/xenstored.c
45081+++ b/drivers/xen/xenfs/xenstored.c
45082@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
45083 static int xsd_kva_open(struct inode *inode, struct file *file)
45084 {
45085 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
45086+#ifdef CONFIG_GRKERNSEC_HIDESYM
45087+ NULL);
45088+#else
45089 xen_store_interface);
45090+#endif
45091+
45092 if (!file->private_data)
45093 return -ENOMEM;
45094 return 0;
45095diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
45096index 890bed5..17ae73e 100644
45097--- a/fs/9p/vfs_inode.c
45098+++ b/fs/9p/vfs_inode.c
45099@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
45100 void
45101 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
45102 {
45103- char *s = nd_get_link(nd);
45104+ const char *s = nd_get_link(nd);
45105
45106 p9_debug(P9_DEBUG_VFS, " %s %s\n",
45107 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
45108diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
45109index 0efd152..b5802ad 100644
45110--- a/fs/Kconfig.binfmt
45111+++ b/fs/Kconfig.binfmt
45112@@ -89,7 +89,7 @@ config HAVE_AOUT
45113
45114 config BINFMT_AOUT
45115 tristate "Kernel support for a.out and ECOFF binaries"
45116- depends on HAVE_AOUT
45117+ depends on HAVE_AOUT && BROKEN
45118 ---help---
45119 A.out (Assembler.OUTput) is a set of formats for libraries and
45120 executables used in the earliest versions of UNIX. Linux used
45121diff --git a/fs/aio.c b/fs/aio.c
45122index 71f613c..9d01f1f 100644
45123--- a/fs/aio.c
45124+++ b/fs/aio.c
45125@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
45126 size += sizeof(struct io_event) * nr_events;
45127 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
45128
45129- if (nr_pages < 0)
45130+ if (nr_pages <= 0)
45131 return -EINVAL;
45132
45133 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
45134@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
45135 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
45136 {
45137 ssize_t ret;
45138+ struct iovec iovstack;
45139
45140 #ifdef CONFIG_COMPAT
45141 if (compat)
45142 ret = compat_rw_copy_check_uvector(type,
45143 (struct compat_iovec __user *)kiocb->ki_buf,
45144- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
45145+ kiocb->ki_nbytes, 1, &iovstack,
45146 &kiocb->ki_iovec);
45147 else
45148 #endif
45149 ret = rw_copy_check_uvector(type,
45150 (struct iovec __user *)kiocb->ki_buf,
45151- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
45152+ kiocb->ki_nbytes, 1, &iovstack,
45153 &kiocb->ki_iovec);
45154 if (ret < 0)
45155 goto out;
45156@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
45157 if (ret < 0)
45158 goto out;
45159
45160+ if (kiocb->ki_iovec == &iovstack) {
45161+ kiocb->ki_inline_vec = iovstack;
45162+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
45163+ }
45164 kiocb->ki_nr_segs = kiocb->ki_nbytes;
45165 kiocb->ki_cur_seg = 0;
45166 /* ki_nbytes/left now reflect bytes instead of segs */
45167diff --git a/fs/attr.c b/fs/attr.c
45168index 1449adb..a2038c2 100644
45169--- a/fs/attr.c
45170+++ b/fs/attr.c
45171@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
45172 unsigned long limit;
45173
45174 limit = rlimit(RLIMIT_FSIZE);
45175+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
45176 if (limit != RLIM_INFINITY && offset > limit)
45177 goto out_sig;
45178 if (offset > inode->i_sb->s_maxbytes)
45179diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
45180index 03bc1d3..6205356 100644
45181--- a/fs/autofs4/waitq.c
45182+++ b/fs/autofs4/waitq.c
45183@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
45184 {
45185 unsigned long sigpipe, flags;
45186 mm_segment_t fs;
45187- const char *data = (const char *)addr;
45188+ const char __user *data = (const char __force_user *)addr;
45189 ssize_t wr = 0;
45190
45191 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
45192@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
45193 return 1;
45194 }
45195
45196+#ifdef CONFIG_GRKERNSEC_HIDESYM
45197+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
45198+#endif
45199+
45200 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
45201 enum autofs_notify notify)
45202 {
45203@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
45204
45205 /* If this is a direct mount request create a dummy name */
45206 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
45207+#ifdef CONFIG_GRKERNSEC_HIDESYM
45208+ /* this name does get written to userland via autofs4_write() */
45209+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
45210+#else
45211 qstr.len = sprintf(name, "%p", dentry);
45212+#endif
45213 else {
45214 qstr.len = autofs4_getpath(sbi, dentry, &name);
45215 if (!qstr.len) {
45216diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
45217index 2b3bda8..6a2d4be 100644
45218--- a/fs/befs/linuxvfs.c
45219+++ b/fs/befs/linuxvfs.c
45220@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
45221 {
45222 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
45223 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
45224- char *link = nd_get_link(nd);
45225+ const char *link = nd_get_link(nd);
45226 if (!IS_ERR(link))
45227 kfree(link);
45228 }
45229diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
45230index 6043567..16a9239 100644
45231--- a/fs/binfmt_aout.c
45232+++ b/fs/binfmt_aout.c
45233@@ -16,6 +16,7 @@
45234 #include <linux/string.h>
45235 #include <linux/fs.h>
45236 #include <linux/file.h>
45237+#include <linux/security.h>
45238 #include <linux/stat.h>
45239 #include <linux/fcntl.h>
45240 #include <linux/ptrace.h>
45241@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
45242 #endif
45243 # define START_STACK(u) ((void __user *)u.start_stack)
45244
45245+ memset(&dump, 0, sizeof(dump));
45246+
45247 fs = get_fs();
45248 set_fs(KERNEL_DS);
45249 has_dumped = 1;
45250@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
45251
45252 /* If the size of the dump file exceeds the rlimit, then see what would happen
45253 if we wrote the stack, but not the data area. */
45254+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
45255 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
45256 dump.u_dsize = 0;
45257
45258 /* Make sure we have enough room to write the stack and data areas. */
45259+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
45260 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
45261 dump.u_ssize = 0;
45262
45263@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
45264 rlim = rlimit(RLIMIT_DATA);
45265 if (rlim >= RLIM_INFINITY)
45266 rlim = ~0;
45267+
45268+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
45269 if (ex.a_data + ex.a_bss > rlim)
45270 return -ENOMEM;
45271
45272@@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
45273
45274 install_exec_creds(bprm);
45275
45276+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45277+ current->mm->pax_flags = 0UL;
45278+#endif
45279+
45280+#ifdef CONFIG_PAX_PAGEEXEC
45281+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
45282+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
45283+
45284+#ifdef CONFIG_PAX_EMUTRAMP
45285+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
45286+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
45287+#endif
45288+
45289+#ifdef CONFIG_PAX_MPROTECT
45290+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
45291+ current->mm->pax_flags |= MF_PAX_MPROTECT;
45292+#endif
45293+
45294+ }
45295+#endif
45296+
45297 if (N_MAGIC(ex) == OMAGIC) {
45298 unsigned long text_addr, map_size;
45299 loff_t pos;
45300@@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
45301 }
45302
45303 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
45304- PROT_READ | PROT_WRITE | PROT_EXEC,
45305+ PROT_READ | PROT_WRITE,
45306 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
45307 fd_offset + ex.a_text);
45308 if (error != N_DATADDR(ex)) {
45309diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
45310index 0c42cdb..f4be023 100644
45311--- a/fs/binfmt_elf.c
45312+++ b/fs/binfmt_elf.c
45313@@ -33,6 +33,7 @@
45314 #include <linux/elf.h>
45315 #include <linux/utsname.h>
45316 #include <linux/coredump.h>
45317+#include <linux/xattr.h>
45318 #include <asm/uaccess.h>
45319 #include <asm/param.h>
45320 #include <asm/page.h>
45321@@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
45322 #define elf_core_dump NULL
45323 #endif
45324
45325+#ifdef CONFIG_PAX_MPROTECT
45326+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
45327+#endif
45328+
45329 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
45330 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
45331 #else
45332@@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
45333 .load_binary = load_elf_binary,
45334 .load_shlib = load_elf_library,
45335 .core_dump = elf_core_dump,
45336+
45337+#ifdef CONFIG_PAX_MPROTECT
45338+ .handle_mprotect= elf_handle_mprotect,
45339+#endif
45340+
45341 .min_coredump = ELF_EXEC_PAGESIZE,
45342 };
45343
45344@@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
45345
45346 static int set_brk(unsigned long start, unsigned long end)
45347 {
45348+ unsigned long e = end;
45349+
45350 start = ELF_PAGEALIGN(start);
45351 end = ELF_PAGEALIGN(end);
45352 if (end > start) {
45353@@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
45354 if (BAD_ADDR(addr))
45355 return addr;
45356 }
45357- current->mm->start_brk = current->mm->brk = end;
45358+ current->mm->start_brk = current->mm->brk = e;
45359 return 0;
45360 }
45361
45362@@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
45363 elf_addr_t __user *u_rand_bytes;
45364 const char *k_platform = ELF_PLATFORM;
45365 const char *k_base_platform = ELF_BASE_PLATFORM;
45366- unsigned char k_rand_bytes[16];
45367+ u32 k_rand_bytes[4];
45368 int items;
45369 elf_addr_t *elf_info;
45370 int ei_index = 0;
45371 const struct cred *cred = current_cred();
45372 struct vm_area_struct *vma;
45373+ unsigned long saved_auxv[AT_VECTOR_SIZE];
45374
45375 /*
45376 * In some cases (e.g. Hyper-Threading), we want to avoid L1
45377@@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
45378 * Generate 16 random bytes for userspace PRNG seeding.
45379 */
45380 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
45381- u_rand_bytes = (elf_addr_t __user *)
45382- STACK_ALLOC(p, sizeof(k_rand_bytes));
45383+ srandom32(k_rand_bytes[0] ^ random32());
45384+ srandom32(k_rand_bytes[1] ^ random32());
45385+ srandom32(k_rand_bytes[2] ^ random32());
45386+ srandom32(k_rand_bytes[3] ^ random32());
45387+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
45388+ u_rand_bytes = (elf_addr_t __user *) p;
45389 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
45390 return -EFAULT;
45391
45392@@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
45393 return -EFAULT;
45394 current->mm->env_end = p;
45395
45396+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
45397+
45398 /* Put the elf_info on the stack in the right place. */
45399 sp = (elf_addr_t __user *)envp + 1;
45400- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
45401+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
45402 return -EFAULT;
45403 return 0;
45404 }
45405@@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
45406 an ELF header */
45407
45408 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45409- struct file *interpreter, unsigned long *interp_map_addr,
45410- unsigned long no_base)
45411+ struct file *interpreter, unsigned long no_base)
45412 {
45413 struct elf_phdr *elf_phdata;
45414 struct elf_phdr *eppnt;
45415- unsigned long load_addr = 0;
45416+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
45417 int load_addr_set = 0;
45418 unsigned long last_bss = 0, elf_bss = 0;
45419- unsigned long error = ~0UL;
45420+ unsigned long error = -EINVAL;
45421 unsigned long total_size;
45422 int retval, i, size;
45423
45424@@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45425 goto out_close;
45426 }
45427
45428+#ifdef CONFIG_PAX_SEGMEXEC
45429+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
45430+ pax_task_size = SEGMEXEC_TASK_SIZE;
45431+#endif
45432+
45433 eppnt = elf_phdata;
45434 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
45435 if (eppnt->p_type == PT_LOAD) {
45436@@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45437 map_addr = elf_map(interpreter, load_addr + vaddr,
45438 eppnt, elf_prot, elf_type, total_size);
45439 total_size = 0;
45440- if (!*interp_map_addr)
45441- *interp_map_addr = map_addr;
45442 error = map_addr;
45443 if (BAD_ADDR(map_addr))
45444 goto out_close;
45445@@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45446 k = load_addr + eppnt->p_vaddr;
45447 if (BAD_ADDR(k) ||
45448 eppnt->p_filesz > eppnt->p_memsz ||
45449- eppnt->p_memsz > TASK_SIZE ||
45450- TASK_SIZE - eppnt->p_memsz < k) {
45451+ eppnt->p_memsz > pax_task_size ||
45452+ pax_task_size - eppnt->p_memsz < k) {
45453 error = -ENOMEM;
45454 goto out_close;
45455 }
45456@@ -530,6 +551,315 @@ out:
45457 return error;
45458 }
45459
45460+#ifdef CONFIG_PAX_PT_PAX_FLAGS
45461+#ifdef CONFIG_PAX_SOFTMODE
45462+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
45463+{
45464+ unsigned long pax_flags = 0UL;
45465+
45466+#ifdef CONFIG_PAX_PAGEEXEC
45467+ if (elf_phdata->p_flags & PF_PAGEEXEC)
45468+ pax_flags |= MF_PAX_PAGEEXEC;
45469+#endif
45470+
45471+#ifdef CONFIG_PAX_SEGMEXEC
45472+ if (elf_phdata->p_flags & PF_SEGMEXEC)
45473+ pax_flags |= MF_PAX_SEGMEXEC;
45474+#endif
45475+
45476+#ifdef CONFIG_PAX_EMUTRAMP
45477+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
45478+ pax_flags |= MF_PAX_EMUTRAMP;
45479+#endif
45480+
45481+#ifdef CONFIG_PAX_MPROTECT
45482+ if (elf_phdata->p_flags & PF_MPROTECT)
45483+ pax_flags |= MF_PAX_MPROTECT;
45484+#endif
45485+
45486+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45487+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
45488+ pax_flags |= MF_PAX_RANDMMAP;
45489+#endif
45490+
45491+ return pax_flags;
45492+}
45493+#endif
45494+
45495+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
45496+{
45497+ unsigned long pax_flags = 0UL;
45498+
45499+#ifdef CONFIG_PAX_PAGEEXEC
45500+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
45501+ pax_flags |= MF_PAX_PAGEEXEC;
45502+#endif
45503+
45504+#ifdef CONFIG_PAX_SEGMEXEC
45505+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
45506+ pax_flags |= MF_PAX_SEGMEXEC;
45507+#endif
45508+
45509+#ifdef CONFIG_PAX_EMUTRAMP
45510+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
45511+ pax_flags |= MF_PAX_EMUTRAMP;
45512+#endif
45513+
45514+#ifdef CONFIG_PAX_MPROTECT
45515+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
45516+ pax_flags |= MF_PAX_MPROTECT;
45517+#endif
45518+
45519+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45520+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
45521+ pax_flags |= MF_PAX_RANDMMAP;
45522+#endif
45523+
45524+ return pax_flags;
45525+}
45526+#endif
45527+
45528+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
45529+#ifdef CONFIG_PAX_SOFTMODE
45530+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
45531+{
45532+ unsigned long pax_flags = 0UL;
45533+
45534+#ifdef CONFIG_PAX_PAGEEXEC
45535+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
45536+ pax_flags |= MF_PAX_PAGEEXEC;
45537+#endif
45538+
45539+#ifdef CONFIG_PAX_SEGMEXEC
45540+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
45541+ pax_flags |= MF_PAX_SEGMEXEC;
45542+#endif
45543+
45544+#ifdef CONFIG_PAX_EMUTRAMP
45545+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
45546+ pax_flags |= MF_PAX_EMUTRAMP;
45547+#endif
45548+
45549+#ifdef CONFIG_PAX_MPROTECT
45550+ if (pax_flags_softmode & MF_PAX_MPROTECT)
45551+ pax_flags |= MF_PAX_MPROTECT;
45552+#endif
45553+
45554+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45555+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
45556+ pax_flags |= MF_PAX_RANDMMAP;
45557+#endif
45558+
45559+ return pax_flags;
45560+}
45561+#endif
45562+
45563+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
45564+{
45565+ unsigned long pax_flags = 0UL;
45566+
45567+#ifdef CONFIG_PAX_PAGEEXEC
45568+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
45569+ pax_flags |= MF_PAX_PAGEEXEC;
45570+#endif
45571+
45572+#ifdef CONFIG_PAX_SEGMEXEC
45573+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
45574+ pax_flags |= MF_PAX_SEGMEXEC;
45575+#endif
45576+
45577+#ifdef CONFIG_PAX_EMUTRAMP
45578+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
45579+ pax_flags |= MF_PAX_EMUTRAMP;
45580+#endif
45581+
45582+#ifdef CONFIG_PAX_MPROTECT
45583+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
45584+ pax_flags |= MF_PAX_MPROTECT;
45585+#endif
45586+
45587+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45588+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
45589+ pax_flags |= MF_PAX_RANDMMAP;
45590+#endif
45591+
45592+ return pax_flags;
45593+}
45594+#endif
45595+
45596+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45597+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
45598+{
45599+ unsigned long pax_flags = 0UL;
45600+
45601+#ifdef CONFIG_PAX_EI_PAX
45602+
45603+#ifdef CONFIG_PAX_PAGEEXEC
45604+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
45605+ pax_flags |= MF_PAX_PAGEEXEC;
45606+#endif
45607+
45608+#ifdef CONFIG_PAX_SEGMEXEC
45609+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
45610+ pax_flags |= MF_PAX_SEGMEXEC;
45611+#endif
45612+
45613+#ifdef CONFIG_PAX_EMUTRAMP
45614+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
45615+ pax_flags |= MF_PAX_EMUTRAMP;
45616+#endif
45617+
45618+#ifdef CONFIG_PAX_MPROTECT
45619+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
45620+ pax_flags |= MF_PAX_MPROTECT;
45621+#endif
45622+
45623+#ifdef CONFIG_PAX_ASLR
45624+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
45625+ pax_flags |= MF_PAX_RANDMMAP;
45626+#endif
45627+
45628+#else
45629+
45630+#ifdef CONFIG_PAX_PAGEEXEC
45631+ pax_flags |= MF_PAX_PAGEEXEC;
45632+#endif
45633+
45634+#ifdef CONFIG_PAX_SEGMEXEC
45635+ pax_flags |= MF_PAX_SEGMEXEC;
45636+#endif
45637+
45638+#ifdef CONFIG_PAX_MPROTECT
45639+ pax_flags |= MF_PAX_MPROTECT;
45640+#endif
45641+
45642+#ifdef CONFIG_PAX_RANDMMAP
45643+ if (randomize_va_space)
45644+ pax_flags |= MF_PAX_RANDMMAP;
45645+#endif
45646+
45647+#endif
45648+
45649+ return pax_flags;
45650+}
45651+
45652+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
45653+{
45654+
45655+#ifdef CONFIG_PAX_PT_PAX_FLAGS
45656+ unsigned long i;
45657+
45658+ for (i = 0UL; i < elf_ex->e_phnum; i++)
45659+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
45660+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
45661+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
45662+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
45663+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
45664+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
45665+ return ~0UL;
45666+
45667+#ifdef CONFIG_PAX_SOFTMODE
45668+ if (pax_softmode)
45669+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
45670+ else
45671+#endif
45672+
45673+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
45674+ break;
45675+ }
45676+#endif
45677+
45678+ return ~0UL;
45679+}
45680+
45681+static unsigned long pax_parse_xattr_pax(struct file * const file)
45682+{
45683+
45684+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
45685+ ssize_t xattr_size, i;
45686+ unsigned char xattr_value[5];
45687+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
45688+
45689+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
45690+ if (xattr_size <= 0 || xattr_size > 5)
45691+ return ~0UL;
45692+
45693+ for (i = 0; i < xattr_size; i++)
45694+ switch (xattr_value[i]) {
45695+ default:
45696+ return ~0UL;
45697+
45698+#define parse_flag(option1, option2, flag) \
45699+ case option1: \
45700+ if (pax_flags_hardmode & MF_PAX_##flag) \
45701+ return ~0UL; \
45702+ pax_flags_hardmode |= MF_PAX_##flag; \
45703+ break; \
45704+ case option2: \
45705+ if (pax_flags_softmode & MF_PAX_##flag) \
45706+ return ~0UL; \
45707+ pax_flags_softmode |= MF_PAX_##flag; \
45708+ break;
45709+
45710+ parse_flag('p', 'P', PAGEEXEC);
45711+ parse_flag('e', 'E', EMUTRAMP);
45712+ parse_flag('m', 'M', MPROTECT);
45713+ parse_flag('r', 'R', RANDMMAP);
45714+ parse_flag('s', 'S', SEGMEXEC);
45715+
45716+#undef parse_flag
45717+ }
45718+
45719+ if (pax_flags_hardmode & pax_flags_softmode)
45720+ return ~0UL;
45721+
45722+#ifdef CONFIG_PAX_SOFTMODE
45723+ if (pax_softmode)
45724+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
45725+ else
45726+#endif
45727+
45728+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
45729+#else
45730+ return ~0UL;
45731+#endif
45732+
45733+}
45734+
45735+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
45736+{
45737+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
45738+
45739+ pax_flags = pax_parse_ei_pax(elf_ex);
45740+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
45741+ xattr_pax_flags = pax_parse_xattr_pax(file);
45742+
45743+ if (pt_pax_flags == ~0UL)
45744+ pt_pax_flags = xattr_pax_flags;
45745+ else if (xattr_pax_flags == ~0UL)
45746+ xattr_pax_flags = pt_pax_flags;
45747+ if (pt_pax_flags != xattr_pax_flags)
45748+ return -EINVAL;
45749+ if (pt_pax_flags != ~0UL)
45750+ pax_flags = pt_pax_flags;
45751+
45752+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
45753+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45754+ if ((__supported_pte_mask & _PAGE_NX))
45755+ pax_flags &= ~MF_PAX_SEGMEXEC;
45756+ else
45757+ pax_flags &= ~MF_PAX_PAGEEXEC;
45758+ }
45759+#endif
45760+
45761+ if (0 > pax_check_flags(&pax_flags))
45762+ return -EINVAL;
45763+
45764+ current->mm->pax_flags = pax_flags;
45765+ return 0;
45766+}
45767+#endif
45768+
45769 /*
45770 * These are the functions used to load ELF style executables and shared
45771 * libraries. There is no binary dependent code anywhere else.
45772@@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
45773 {
45774 unsigned int random_variable = 0;
45775
45776+#ifdef CONFIG_PAX_RANDUSTACK
45777+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
45778+ return stack_top - current->mm->delta_stack;
45779+#endif
45780+
45781 if ((current->flags & PF_RANDOMIZE) &&
45782 !(current->personality & ADDR_NO_RANDOMIZE)) {
45783 random_variable = get_random_int() & STACK_RND_MASK;
45784@@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
45785 unsigned long load_addr = 0, load_bias = 0;
45786 int load_addr_set = 0;
45787 char * elf_interpreter = NULL;
45788- unsigned long error;
45789+ unsigned long error = 0;
45790 struct elf_phdr *elf_ppnt, *elf_phdata;
45791 unsigned long elf_bss, elf_brk;
45792 int retval, i;
45793@@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
45794 unsigned long start_code, end_code, start_data, end_data;
45795 unsigned long reloc_func_desc __maybe_unused = 0;
45796 int executable_stack = EXSTACK_DEFAULT;
45797- unsigned long def_flags = 0;
45798 struct pt_regs *regs = current_pt_regs();
45799 struct {
45800 struct elfhdr elf_ex;
45801 struct elfhdr interp_elf_ex;
45802 } *loc;
45803+ unsigned long pax_task_size = TASK_SIZE;
45804
45805 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
45806 if (!loc) {
45807@@ -715,11 +1050,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
45808 goto out_free_dentry;
45809
45810 /* OK, This is the point of no return */
45811- current->mm->def_flags = def_flags;
45812+
45813+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45814+ current->mm->pax_flags = 0UL;
45815+#endif
45816+
45817+#ifdef CONFIG_PAX_DLRESOLVE
45818+ current->mm->call_dl_resolve = 0UL;
45819+#endif
45820+
45821+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
45822+ current->mm->call_syscall = 0UL;
45823+#endif
45824+
45825+#ifdef CONFIG_PAX_ASLR
45826+ current->mm->delta_mmap = 0UL;
45827+ current->mm->delta_stack = 0UL;
45828+#endif
45829+
45830+ current->mm->def_flags = 0;
45831+
45832+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45833+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
45834+ send_sig(SIGKILL, current, 0);
45835+ goto out_free_dentry;
45836+ }
45837+#endif
45838+
45839+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
45840+ pax_set_initial_flags(bprm);
45841+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
45842+ if (pax_set_initial_flags_func)
45843+ (pax_set_initial_flags_func)(bprm);
45844+#endif
45845+
45846+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
45847+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
45848+ current->mm->context.user_cs_limit = PAGE_SIZE;
45849+ current->mm->def_flags |= VM_PAGEEXEC;
45850+ }
45851+#endif
45852+
45853+#ifdef CONFIG_PAX_SEGMEXEC
45854+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
45855+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
45856+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
45857+ pax_task_size = SEGMEXEC_TASK_SIZE;
45858+ current->mm->def_flags |= VM_NOHUGEPAGE;
45859+ }
45860+#endif
45861+
45862+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
45863+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45864+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
45865+ put_cpu();
45866+ }
45867+#endif
45868
45869 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
45870 may depend on the personality. */
45871 SET_PERSONALITY(loc->elf_ex);
45872+
45873+#ifdef CONFIG_PAX_ASLR
45874+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45875+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
45876+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
45877+ }
45878+#endif
45879+
45880+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45881+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45882+ executable_stack = EXSTACK_DISABLE_X;
45883+ current->personality &= ~READ_IMPLIES_EXEC;
45884+ } else
45885+#endif
45886+
45887 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
45888 current->personality |= READ_IMPLIES_EXEC;
45889
45890@@ -810,6 +1215,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
45891 #else
45892 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
45893 #endif
45894+
45895+#ifdef CONFIG_PAX_RANDMMAP
45896+ /* PaX: randomize base address at the default exe base if requested */
45897+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
45898+#ifdef CONFIG_SPARC64
45899+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
45900+#else
45901+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
45902+#endif
45903+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
45904+ elf_flags |= MAP_FIXED;
45905+ }
45906+#endif
45907+
45908 }
45909
45910 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
45911@@ -842,9 +1261,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
45912 * allowed task size. Note that p_filesz must always be
45913 * <= p_memsz so it is only necessary to check p_memsz.
45914 */
45915- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45916- elf_ppnt->p_memsz > TASK_SIZE ||
45917- TASK_SIZE - elf_ppnt->p_memsz < k) {
45918+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45919+ elf_ppnt->p_memsz > pax_task_size ||
45920+ pax_task_size - elf_ppnt->p_memsz < k) {
45921 /* set_brk can never work. Avoid overflows. */
45922 send_sig(SIGKILL, current, 0);
45923 retval = -EINVAL;
45924@@ -883,17 +1302,44 @@ static int load_elf_binary(struct linux_binprm *bprm)
45925 goto out_free_dentry;
45926 }
45927 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
45928- send_sig(SIGSEGV, current, 0);
45929- retval = -EFAULT; /* Nobody gets to see this, but.. */
45930- goto out_free_dentry;
45931+ /*
45932+ * This bss-zeroing can fail if the ELF
45933+ * file specifies odd protections. So
45934+ * we don't check the return value
45935+ */
45936 }
45937
45938+#ifdef CONFIG_PAX_RANDMMAP
45939+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45940+ unsigned long start, size;
45941+
45942+ start = ELF_PAGEALIGN(elf_brk);
45943+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
45944+ down_read(&current->mm->mmap_sem);
45945+ retval = -ENOMEM;
45946+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
45947+ unsigned long prot = PROT_NONE;
45948+
45949+ up_read(&current->mm->mmap_sem);
45950+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
45951+// if (current->personality & ADDR_NO_RANDOMIZE)
45952+// prot = PROT_READ;
45953+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
45954+ retval = IS_ERR_VALUE(start) ? start : 0;
45955+ } else
45956+ up_read(&current->mm->mmap_sem);
45957+ if (retval == 0)
45958+ retval = set_brk(start + size, start + size + PAGE_SIZE);
45959+ if (retval < 0) {
45960+ send_sig(SIGKILL, current, 0);
45961+ goto out_free_dentry;
45962+ }
45963+ }
45964+#endif
45965+
45966 if (elf_interpreter) {
45967- unsigned long interp_map_addr = 0;
45968-
45969 elf_entry = load_elf_interp(&loc->interp_elf_ex,
45970 interpreter,
45971- &interp_map_addr,
45972 load_bias);
45973 if (!IS_ERR((void *)elf_entry)) {
45974 /*
45975@@ -1115,7 +1561,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
45976 * Decide what to dump of a segment, part, all or none.
45977 */
45978 static unsigned long vma_dump_size(struct vm_area_struct *vma,
45979- unsigned long mm_flags)
45980+ unsigned long mm_flags, long signr)
45981 {
45982 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
45983
45984@@ -1152,7 +1598,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
45985 if (vma->vm_file == NULL)
45986 return 0;
45987
45988- if (FILTER(MAPPED_PRIVATE))
45989+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
45990 goto whole;
45991
45992 /*
45993@@ -1374,9 +1820,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
45994 {
45995 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
45996 int i = 0;
45997- do
45998+ do {
45999 i += 2;
46000- while (auxv[i - 2] != AT_NULL);
46001+ } while (auxv[i - 2] != AT_NULL);
46002 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
46003 }
46004
46005@@ -2006,14 +2452,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
46006 }
46007
46008 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
46009- unsigned long mm_flags)
46010+ struct coredump_params *cprm)
46011 {
46012 struct vm_area_struct *vma;
46013 size_t size = 0;
46014
46015 for (vma = first_vma(current, gate_vma); vma != NULL;
46016 vma = next_vma(vma, gate_vma))
46017- size += vma_dump_size(vma, mm_flags);
46018+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
46019 return size;
46020 }
46021
46022@@ -2107,7 +2553,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46023
46024 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
46025
46026- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
46027+ offset += elf_core_vma_data_size(gate_vma, cprm);
46028 offset += elf_core_extra_data_size();
46029 e_shoff = offset;
46030
46031@@ -2121,10 +2567,12 @@ static int elf_core_dump(struct coredump_params *cprm)
46032 offset = dataoff;
46033
46034 size += sizeof(*elf);
46035+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
46036 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
46037 goto end_coredump;
46038
46039 size += sizeof(*phdr4note);
46040+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
46041 if (size > cprm->limit
46042 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
46043 goto end_coredump;
46044@@ -2138,7 +2586,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46045 phdr.p_offset = offset;
46046 phdr.p_vaddr = vma->vm_start;
46047 phdr.p_paddr = 0;
46048- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
46049+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
46050 phdr.p_memsz = vma->vm_end - vma->vm_start;
46051 offset += phdr.p_filesz;
46052 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
46053@@ -2149,6 +2597,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46054 phdr.p_align = ELF_EXEC_PAGESIZE;
46055
46056 size += sizeof(phdr);
46057+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
46058 if (size > cprm->limit
46059 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
46060 goto end_coredump;
46061@@ -2173,7 +2622,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46062 unsigned long addr;
46063 unsigned long end;
46064
46065- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
46066+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
46067
46068 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
46069 struct page *page;
46070@@ -2182,6 +2631,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46071 page = get_dump_page(addr);
46072 if (page) {
46073 void *kaddr = kmap(page);
46074+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
46075 stop = ((size += PAGE_SIZE) > cprm->limit) ||
46076 !dump_write(cprm->file, kaddr,
46077 PAGE_SIZE);
46078@@ -2199,6 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46079
46080 if (e_phnum == PN_XNUM) {
46081 size += sizeof(*shdr4extnum);
46082+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
46083 if (size > cprm->limit
46084 || !dump_write(cprm->file, shdr4extnum,
46085 sizeof(*shdr4extnum)))
46086@@ -2219,6 +2670,97 @@ out:
46087
46088 #endif /* CONFIG_ELF_CORE */
46089
46090+#ifdef CONFIG_PAX_MPROTECT
46091+/* PaX: non-PIC ELF libraries need relocations on their executable segments
46092+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
46093+ * we'll remove VM_MAYWRITE for good on RELRO segments.
46094+ *
46095+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
46096+ * basis because we want to allow the common case and not the special ones.
46097+ */
46098+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
46099+{
46100+ struct elfhdr elf_h;
46101+ struct elf_phdr elf_p;
46102+ unsigned long i;
46103+ unsigned long oldflags;
46104+ bool is_textrel_rw, is_textrel_rx, is_relro;
46105+
46106+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
46107+ return;
46108+
46109+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
46110+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
46111+
46112+#ifdef CONFIG_PAX_ELFRELOCS
46113+ /* possible TEXTREL */
46114+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
46115+ 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);
46116+#else
46117+ is_textrel_rw = false;
46118+ is_textrel_rx = false;
46119+#endif
46120+
46121+ /* possible RELRO */
46122+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
46123+
46124+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
46125+ return;
46126+
46127+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
46128+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
46129+
46130+#ifdef CONFIG_PAX_ETEXECRELOCS
46131+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
46132+#else
46133+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
46134+#endif
46135+
46136+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
46137+ !elf_check_arch(&elf_h) ||
46138+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
46139+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
46140+ return;
46141+
46142+ for (i = 0UL; i < elf_h.e_phnum; i++) {
46143+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
46144+ return;
46145+ switch (elf_p.p_type) {
46146+ case PT_DYNAMIC:
46147+ if (!is_textrel_rw && !is_textrel_rx)
46148+ continue;
46149+ i = 0UL;
46150+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
46151+ elf_dyn dyn;
46152+
46153+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
46154+ return;
46155+ if (dyn.d_tag == DT_NULL)
46156+ return;
46157+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
46158+ gr_log_textrel(vma);
46159+ if (is_textrel_rw)
46160+ vma->vm_flags |= VM_MAYWRITE;
46161+ else
46162+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
46163+ vma->vm_flags &= ~VM_MAYWRITE;
46164+ return;
46165+ }
46166+ i++;
46167+ }
46168+ return;
46169+
46170+ case PT_GNU_RELRO:
46171+ if (!is_relro)
46172+ continue;
46173+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
46174+ vma->vm_flags &= ~VM_MAYWRITE;
46175+ return;
46176+ }
46177+ }
46178+}
46179+#endif
46180+
46181 static int __init init_elf_binfmt(void)
46182 {
46183 register_binfmt(&elf_format);
46184diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
46185index b563719..3868998 100644
46186--- a/fs/binfmt_flat.c
46187+++ b/fs/binfmt_flat.c
46188@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
46189 realdatastart = (unsigned long) -ENOMEM;
46190 printk("Unable to allocate RAM for process data, errno %d\n",
46191 (int)-realdatastart);
46192+ down_write(&current->mm->mmap_sem);
46193 vm_munmap(textpos, text_len);
46194+ up_write(&current->mm->mmap_sem);
46195 ret = realdatastart;
46196 goto err;
46197 }
46198@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
46199 }
46200 if (IS_ERR_VALUE(result)) {
46201 printk("Unable to read data+bss, errno %d\n", (int)-result);
46202+ down_write(&current->mm->mmap_sem);
46203 vm_munmap(textpos, text_len);
46204 vm_munmap(realdatastart, len);
46205+ up_write(&current->mm->mmap_sem);
46206 ret = result;
46207 goto err;
46208 }
46209@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
46210 }
46211 if (IS_ERR_VALUE(result)) {
46212 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
46213+ down_write(&current->mm->mmap_sem);
46214 vm_munmap(textpos, text_len + data_len + extra +
46215 MAX_SHARED_LIBS * sizeof(unsigned long));
46216+ up_write(&current->mm->mmap_sem);
46217 ret = result;
46218 goto err;
46219 }
46220diff --git a/fs/bio.c b/fs/bio.c
46221index b96fc6c..431d628 100644
46222--- a/fs/bio.c
46223+++ b/fs/bio.c
46224@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
46225 /*
46226 * Overflow, abort
46227 */
46228- if (end < start)
46229+ if (end < start || end - start > INT_MAX - nr_pages)
46230 return ERR_PTR(-EINVAL);
46231
46232 nr_pages += end - start;
46233@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
46234 /*
46235 * Overflow, abort
46236 */
46237- if (end < start)
46238+ if (end < start || end - start > INT_MAX - nr_pages)
46239 return ERR_PTR(-EINVAL);
46240
46241 nr_pages += end - start;
46242@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
46243 const int read = bio_data_dir(bio) == READ;
46244 struct bio_map_data *bmd = bio->bi_private;
46245 int i;
46246- char *p = bmd->sgvecs[0].iov_base;
46247+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
46248
46249 __bio_for_each_segment(bvec, bio, i, 0) {
46250 char *addr = page_address(bvec->bv_page);
46251diff --git a/fs/block_dev.c b/fs/block_dev.c
46252index 78333a3..23dcb4d 100644
46253--- a/fs/block_dev.c
46254+++ b/fs/block_dev.c
46255@@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
46256 else if (bdev->bd_contains == bdev)
46257 return true; /* is a whole device which isn't held */
46258
46259- else if (whole->bd_holder == bd_may_claim)
46260+ else if (whole->bd_holder == (void *)bd_may_claim)
46261 return true; /* is a partition of a device that is being partitioned */
46262 else if (whole->bd_holder != NULL)
46263 return false; /* is a partition of a held device */
46264diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
46265index eea5da7..88fead70 100644
46266--- a/fs/btrfs/ctree.c
46267+++ b/fs/btrfs/ctree.c
46268@@ -1033,9 +1033,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
46269 free_extent_buffer(buf);
46270 add_root_to_dirty_list(root);
46271 } else {
46272- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
46273- parent_start = parent->start;
46274- else
46275+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
46276+ if (parent)
46277+ parent_start = parent->start;
46278+ else
46279+ parent_start = 0;
46280+ } else
46281 parent_start = 0;
46282
46283 WARN_ON(trans->transid != btrfs_header_generation(parent));
46284diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
46285index cc93b23..f3c42bf 100644
46286--- a/fs/btrfs/inode.c
46287+++ b/fs/btrfs/inode.c
46288@@ -7296,7 +7296,7 @@ fail:
46289 return -ENOMEM;
46290 }
46291
46292-static int btrfs_getattr(struct vfsmount *mnt,
46293+int btrfs_getattr(struct vfsmount *mnt,
46294 struct dentry *dentry, struct kstat *stat)
46295 {
46296 struct inode *inode = dentry->d_inode;
46297@@ -7310,6 +7310,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
46298 return 0;
46299 }
46300
46301+EXPORT_SYMBOL(btrfs_getattr);
46302+
46303+dev_t get_btrfs_dev_from_inode(struct inode *inode)
46304+{
46305+ return BTRFS_I(inode)->root->anon_dev;
46306+}
46307+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
46308+
46309 /*
46310 * If a file is moved, it will inherit the cow and compression flags of the new
46311 * directory.
46312diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
46313index 338f259..b657640 100644
46314--- a/fs/btrfs/ioctl.c
46315+++ b/fs/btrfs/ioctl.c
46316@@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
46317 for (i = 0; i < num_types; i++) {
46318 struct btrfs_space_info *tmp;
46319
46320+ /* Don't copy in more than we allocated */
46321 if (!slot_count)
46322 break;
46323
46324+ slot_count--;
46325+
46326 info = NULL;
46327 rcu_read_lock();
46328 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
46329@@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
46330 memcpy(dest, &space, sizeof(space));
46331 dest++;
46332 space_args.total_spaces++;
46333- slot_count--;
46334 }
46335- if (!slot_count)
46336- break;
46337 }
46338 up_read(&info->groups_sem);
46339 }
46340diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
46341index 300e09a..9fe4539 100644
46342--- a/fs/btrfs/relocation.c
46343+++ b/fs/btrfs/relocation.c
46344@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
46345 }
46346 spin_unlock(&rc->reloc_root_tree.lock);
46347
46348- BUG_ON((struct btrfs_root *)node->data != root);
46349+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
46350
46351 if (!del) {
46352 spin_lock(&rc->reloc_root_tree.lock);
46353diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
46354index d8982e9..29a85fa 100644
46355--- a/fs/btrfs/super.c
46356+++ b/fs/btrfs/super.c
46357@@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
46358 function, line, errstr);
46359 return;
46360 }
46361- ACCESS_ONCE(trans->transaction->aborted) = errno;
46362+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
46363 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
46364 }
46365 /*
46366diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
46367index 622f469..e8d2d55 100644
46368--- a/fs/cachefiles/bind.c
46369+++ b/fs/cachefiles/bind.c
46370@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
46371 args);
46372
46373 /* start by checking things over */
46374- ASSERT(cache->fstop_percent >= 0 &&
46375- cache->fstop_percent < cache->fcull_percent &&
46376+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
46377 cache->fcull_percent < cache->frun_percent &&
46378 cache->frun_percent < 100);
46379
46380- ASSERT(cache->bstop_percent >= 0 &&
46381- cache->bstop_percent < cache->bcull_percent &&
46382+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
46383 cache->bcull_percent < cache->brun_percent &&
46384 cache->brun_percent < 100);
46385
46386diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
46387index 0a1467b..6a53245 100644
46388--- a/fs/cachefiles/daemon.c
46389+++ b/fs/cachefiles/daemon.c
46390@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
46391 if (n > buflen)
46392 return -EMSGSIZE;
46393
46394- if (copy_to_user(_buffer, buffer, n) != 0)
46395+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
46396 return -EFAULT;
46397
46398 return n;
46399@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
46400 if (test_bit(CACHEFILES_DEAD, &cache->flags))
46401 return -EIO;
46402
46403- if (datalen < 0 || datalen > PAGE_SIZE - 1)
46404+ if (datalen > PAGE_SIZE - 1)
46405 return -EOPNOTSUPP;
46406
46407 /* drag the command string into the kernel so we can parse it */
46408@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
46409 if (args[0] != '%' || args[1] != '\0')
46410 return -EINVAL;
46411
46412- if (fstop < 0 || fstop >= cache->fcull_percent)
46413+ if (fstop >= cache->fcull_percent)
46414 return cachefiles_daemon_range_error(cache, args);
46415
46416 cache->fstop_percent = fstop;
46417@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
46418 if (args[0] != '%' || args[1] != '\0')
46419 return -EINVAL;
46420
46421- if (bstop < 0 || bstop >= cache->bcull_percent)
46422+ if (bstop >= cache->bcull_percent)
46423 return cachefiles_daemon_range_error(cache, args);
46424
46425 cache->bstop_percent = bstop;
46426diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
46427index 4938251..7e01445 100644
46428--- a/fs/cachefiles/internal.h
46429+++ b/fs/cachefiles/internal.h
46430@@ -59,7 +59,7 @@ struct cachefiles_cache {
46431 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
46432 struct rb_root active_nodes; /* active nodes (can't be culled) */
46433 rwlock_t active_lock; /* lock for active_nodes */
46434- atomic_t gravecounter; /* graveyard uniquifier */
46435+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
46436 unsigned frun_percent; /* when to stop culling (% files) */
46437 unsigned fcull_percent; /* when to start culling (% files) */
46438 unsigned fstop_percent; /* when to stop allocating (% files) */
46439@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
46440 * proc.c
46441 */
46442 #ifdef CONFIG_CACHEFILES_HISTOGRAM
46443-extern atomic_t cachefiles_lookup_histogram[HZ];
46444-extern atomic_t cachefiles_mkdir_histogram[HZ];
46445-extern atomic_t cachefiles_create_histogram[HZ];
46446+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
46447+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
46448+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
46449
46450 extern int __init cachefiles_proc_init(void);
46451 extern void cachefiles_proc_cleanup(void);
46452 static inline
46453-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
46454+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
46455 {
46456 unsigned long jif = jiffies - start_jif;
46457 if (jif >= HZ)
46458 jif = HZ - 1;
46459- atomic_inc(&histogram[jif]);
46460+ atomic_inc_unchecked(&histogram[jif]);
46461 }
46462
46463 #else
46464diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
46465index 8c01c5fc..15f982e 100644
46466--- a/fs/cachefiles/namei.c
46467+++ b/fs/cachefiles/namei.c
46468@@ -317,7 +317,7 @@ try_again:
46469 /* first step is to make up a grave dentry in the graveyard */
46470 sprintf(nbuffer, "%08x%08x",
46471 (uint32_t) get_seconds(),
46472- (uint32_t) atomic_inc_return(&cache->gravecounter));
46473+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
46474
46475 /* do the multiway lock magic */
46476 trap = lock_rename(cache->graveyard, dir);
46477diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
46478index eccd339..4c1d995 100644
46479--- a/fs/cachefiles/proc.c
46480+++ b/fs/cachefiles/proc.c
46481@@ -14,9 +14,9 @@
46482 #include <linux/seq_file.h>
46483 #include "internal.h"
46484
46485-atomic_t cachefiles_lookup_histogram[HZ];
46486-atomic_t cachefiles_mkdir_histogram[HZ];
46487-atomic_t cachefiles_create_histogram[HZ];
46488+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
46489+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
46490+atomic_unchecked_t cachefiles_create_histogram[HZ];
46491
46492 /*
46493 * display the latency histogram
46494@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
46495 return 0;
46496 default:
46497 index = (unsigned long) v - 3;
46498- x = atomic_read(&cachefiles_lookup_histogram[index]);
46499- y = atomic_read(&cachefiles_mkdir_histogram[index]);
46500- z = atomic_read(&cachefiles_create_histogram[index]);
46501+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
46502+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
46503+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
46504 if (x == 0 && y == 0 && z == 0)
46505 return 0;
46506
46507diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
46508index 4809922..aab2c39 100644
46509--- a/fs/cachefiles/rdwr.c
46510+++ b/fs/cachefiles/rdwr.c
46511@@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
46512 old_fs = get_fs();
46513 set_fs(KERNEL_DS);
46514 ret = file->f_op->write(
46515- file, (const void __user *) data, len, &pos);
46516+ file, (const void __force_user *) data, len, &pos);
46517 set_fs(old_fs);
46518 kunmap(page);
46519 if (ret != len)
46520diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
46521index 8c1aabe..bbf856a 100644
46522--- a/fs/ceph/dir.c
46523+++ b/fs/ceph/dir.c
46524@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
46525 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
46526 struct ceph_mds_client *mdsc = fsc->mdsc;
46527 unsigned frag = fpos_frag(filp->f_pos);
46528- int off = fpos_off(filp->f_pos);
46529+ unsigned int off = fpos_off(filp->f_pos);
46530 int err;
46531 u32 ftype;
46532 struct ceph_mds_reply_info_parsed *rinfo;
46533diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
46534index d9ea6ed..1e6c8ac 100644
46535--- a/fs/cifs/cifs_debug.c
46536+++ b/fs/cifs/cifs_debug.c
46537@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
46538
46539 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
46540 #ifdef CONFIG_CIFS_STATS2
46541- atomic_set(&totBufAllocCount, 0);
46542- atomic_set(&totSmBufAllocCount, 0);
46543+ atomic_set_unchecked(&totBufAllocCount, 0);
46544+ atomic_set_unchecked(&totSmBufAllocCount, 0);
46545 #endif /* CONFIG_CIFS_STATS2 */
46546 spin_lock(&cifs_tcp_ses_lock);
46547 list_for_each(tmp1, &cifs_tcp_ses_list) {
46548@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
46549 tcon = list_entry(tmp3,
46550 struct cifs_tcon,
46551 tcon_list);
46552- atomic_set(&tcon->num_smbs_sent, 0);
46553+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
46554 if (server->ops->clear_stats)
46555 server->ops->clear_stats(tcon);
46556 }
46557@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
46558 smBufAllocCount.counter, cifs_min_small);
46559 #ifdef CONFIG_CIFS_STATS2
46560 seq_printf(m, "Total Large %d Small %d Allocations\n",
46561- atomic_read(&totBufAllocCount),
46562- atomic_read(&totSmBufAllocCount));
46563+ atomic_read_unchecked(&totBufAllocCount),
46564+ atomic_read_unchecked(&totSmBufAllocCount));
46565 #endif /* CONFIG_CIFS_STATS2 */
46566
46567 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
46568@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
46569 if (tcon->need_reconnect)
46570 seq_puts(m, "\tDISCONNECTED ");
46571 seq_printf(m, "\nSMBs: %d",
46572- atomic_read(&tcon->num_smbs_sent));
46573+ atomic_read_unchecked(&tcon->num_smbs_sent));
46574 if (server->ops->print_stats)
46575 server->ops->print_stats(m, tcon);
46576 }
46577diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
46578index de7f916..6cb22a9 100644
46579--- a/fs/cifs/cifsfs.c
46580+++ b/fs/cifs/cifsfs.c
46581@@ -997,7 +997,7 @@ cifs_init_request_bufs(void)
46582 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
46583 cifs_req_cachep = kmem_cache_create("cifs_request",
46584 CIFSMaxBufSize + max_hdr_size, 0,
46585- SLAB_HWCACHE_ALIGN, NULL);
46586+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
46587 if (cifs_req_cachep == NULL)
46588 return -ENOMEM;
46589
46590@@ -1024,7 +1024,7 @@ cifs_init_request_bufs(void)
46591 efficient to alloc 1 per page off the slab compared to 17K (5page)
46592 alloc of large cifs buffers even when page debugging is on */
46593 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
46594- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
46595+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
46596 NULL);
46597 if (cifs_sm_req_cachep == NULL) {
46598 mempool_destroy(cifs_req_poolp);
46599@@ -1109,8 +1109,8 @@ init_cifs(void)
46600 atomic_set(&bufAllocCount, 0);
46601 atomic_set(&smBufAllocCount, 0);
46602 #ifdef CONFIG_CIFS_STATS2
46603- atomic_set(&totBufAllocCount, 0);
46604- atomic_set(&totSmBufAllocCount, 0);
46605+ atomic_set_unchecked(&totBufAllocCount, 0);
46606+ atomic_set_unchecked(&totSmBufAllocCount, 0);
46607 #endif /* CONFIG_CIFS_STATS2 */
46608
46609 atomic_set(&midCount, 0);
46610diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
46611index e6899ce..d6b2920 100644
46612--- a/fs/cifs/cifsglob.h
46613+++ b/fs/cifs/cifsglob.h
46614@@ -751,35 +751,35 @@ struct cifs_tcon {
46615 __u16 Flags; /* optional support bits */
46616 enum statusEnum tidStatus;
46617 #ifdef CONFIG_CIFS_STATS
46618- atomic_t num_smbs_sent;
46619+ atomic_unchecked_t num_smbs_sent;
46620 union {
46621 struct {
46622- atomic_t num_writes;
46623- atomic_t num_reads;
46624- atomic_t num_flushes;
46625- atomic_t num_oplock_brks;
46626- atomic_t num_opens;
46627- atomic_t num_closes;
46628- atomic_t num_deletes;
46629- atomic_t num_mkdirs;
46630- atomic_t num_posixopens;
46631- atomic_t num_posixmkdirs;
46632- atomic_t num_rmdirs;
46633- atomic_t num_renames;
46634- atomic_t num_t2renames;
46635- atomic_t num_ffirst;
46636- atomic_t num_fnext;
46637- atomic_t num_fclose;
46638- atomic_t num_hardlinks;
46639- atomic_t num_symlinks;
46640- atomic_t num_locks;
46641- atomic_t num_acl_get;
46642- atomic_t num_acl_set;
46643+ atomic_unchecked_t num_writes;
46644+ atomic_unchecked_t num_reads;
46645+ atomic_unchecked_t num_flushes;
46646+ atomic_unchecked_t num_oplock_brks;
46647+ atomic_unchecked_t num_opens;
46648+ atomic_unchecked_t num_closes;
46649+ atomic_unchecked_t num_deletes;
46650+ atomic_unchecked_t num_mkdirs;
46651+ atomic_unchecked_t num_posixopens;
46652+ atomic_unchecked_t num_posixmkdirs;
46653+ atomic_unchecked_t num_rmdirs;
46654+ atomic_unchecked_t num_renames;
46655+ atomic_unchecked_t num_t2renames;
46656+ atomic_unchecked_t num_ffirst;
46657+ atomic_unchecked_t num_fnext;
46658+ atomic_unchecked_t num_fclose;
46659+ atomic_unchecked_t num_hardlinks;
46660+ atomic_unchecked_t num_symlinks;
46661+ atomic_unchecked_t num_locks;
46662+ atomic_unchecked_t num_acl_get;
46663+ atomic_unchecked_t num_acl_set;
46664 } cifs_stats;
46665 #ifdef CONFIG_CIFS_SMB2
46666 struct {
46667- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
46668- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
46669+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
46670+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
46671 } smb2_stats;
46672 #endif /* CONFIG_CIFS_SMB2 */
46673 } stats;
46674@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
46675 }
46676
46677 #ifdef CONFIG_CIFS_STATS
46678-#define cifs_stats_inc atomic_inc
46679+#define cifs_stats_inc atomic_inc_unchecked
46680
46681 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
46682 unsigned int bytes)
46683@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
46684 /* Various Debug counters */
46685 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
46686 #ifdef CONFIG_CIFS_STATS2
46687-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
46688-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
46689+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
46690+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
46691 #endif
46692 GLOBAL_EXTERN atomic_t smBufAllocCount;
46693 GLOBAL_EXTERN atomic_t midCount;
46694diff --git a/fs/cifs/link.c b/fs/cifs/link.c
46695index 51dc2fb..1e12a33 100644
46696--- a/fs/cifs/link.c
46697+++ b/fs/cifs/link.c
46698@@ -616,7 +616,7 @@ symlink_exit:
46699
46700 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
46701 {
46702- char *p = nd_get_link(nd);
46703+ const char *p = nd_get_link(nd);
46704 if (!IS_ERR(p))
46705 kfree(p);
46706 }
46707diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
46708index 3a00c0d..42d901c 100644
46709--- a/fs/cifs/misc.c
46710+++ b/fs/cifs/misc.c
46711@@ -169,7 +169,7 @@ cifs_buf_get(void)
46712 memset(ret_buf, 0, buf_size + 3);
46713 atomic_inc(&bufAllocCount);
46714 #ifdef CONFIG_CIFS_STATS2
46715- atomic_inc(&totBufAllocCount);
46716+ atomic_inc_unchecked(&totBufAllocCount);
46717 #endif /* CONFIG_CIFS_STATS2 */
46718 }
46719
46720@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
46721 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
46722 atomic_inc(&smBufAllocCount);
46723 #ifdef CONFIG_CIFS_STATS2
46724- atomic_inc(&totSmBufAllocCount);
46725+ atomic_inc_unchecked(&totSmBufAllocCount);
46726 #endif /* CONFIG_CIFS_STATS2 */
46727
46728 }
46729diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
46730index 47bc5a8..10decbe 100644
46731--- a/fs/cifs/smb1ops.c
46732+++ b/fs/cifs/smb1ops.c
46733@@ -586,27 +586,27 @@ static void
46734 cifs_clear_stats(struct cifs_tcon *tcon)
46735 {
46736 #ifdef CONFIG_CIFS_STATS
46737- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
46738- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
46739- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
46740- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46741- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
46742- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
46743- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46744- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
46745- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
46746- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
46747- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
46748- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
46749- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
46750- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
46751- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
46752- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
46753- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
46754- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
46755- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
46756- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
46757- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
46758+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
46759+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
46760+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
46761+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46762+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
46763+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
46764+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46765+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
46766+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
46767+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
46768+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
46769+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
46770+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
46771+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
46772+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
46773+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
46774+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
46775+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
46776+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
46777+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
46778+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
46779 #endif
46780 }
46781
46782@@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46783 {
46784 #ifdef CONFIG_CIFS_STATS
46785 seq_printf(m, " Oplocks breaks: %d",
46786- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
46787+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
46788 seq_printf(m, "\nReads: %d Bytes: %llu",
46789- atomic_read(&tcon->stats.cifs_stats.num_reads),
46790+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
46791 (long long)(tcon->bytes_read));
46792 seq_printf(m, "\nWrites: %d Bytes: %llu",
46793- atomic_read(&tcon->stats.cifs_stats.num_writes),
46794+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
46795 (long long)(tcon->bytes_written));
46796 seq_printf(m, "\nFlushes: %d",
46797- atomic_read(&tcon->stats.cifs_stats.num_flushes));
46798+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
46799 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
46800- atomic_read(&tcon->stats.cifs_stats.num_locks),
46801- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
46802- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
46803+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
46804+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
46805+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
46806 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
46807- atomic_read(&tcon->stats.cifs_stats.num_opens),
46808- atomic_read(&tcon->stats.cifs_stats.num_closes),
46809- atomic_read(&tcon->stats.cifs_stats.num_deletes));
46810+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
46811+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
46812+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
46813 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
46814- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
46815- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
46816+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
46817+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
46818 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
46819- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
46820- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
46821+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
46822+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
46823 seq_printf(m, "\nRenames: %d T2 Renames %d",
46824- atomic_read(&tcon->stats.cifs_stats.num_renames),
46825- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
46826+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
46827+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
46828 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
46829- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
46830- atomic_read(&tcon->stats.cifs_stats.num_fnext),
46831- atomic_read(&tcon->stats.cifs_stats.num_fclose));
46832+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
46833+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
46834+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
46835 #endif
46836 }
46837
46838diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
46839index c9c7aa7..065056a 100644
46840--- a/fs/cifs/smb2ops.c
46841+++ b/fs/cifs/smb2ops.c
46842@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
46843 #ifdef CONFIG_CIFS_STATS
46844 int i;
46845 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
46846- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46847- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46848+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46849+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46850 }
46851 #endif
46852 }
46853@@ -284,66 +284,66 @@ static void
46854 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46855 {
46856 #ifdef CONFIG_CIFS_STATS
46857- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46858- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46859+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46860+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46861 seq_printf(m, "\nNegotiates: %d sent %d failed",
46862- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
46863- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
46864+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
46865+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
46866 seq_printf(m, "\nSessionSetups: %d sent %d failed",
46867- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
46868- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
46869+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
46870+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
46871 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
46872 seq_printf(m, "\nLogoffs: %d sent %d failed",
46873- atomic_read(&sent[SMB2_LOGOFF_HE]),
46874- atomic_read(&failed[SMB2_LOGOFF_HE]));
46875+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
46876+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
46877 seq_printf(m, "\nTreeConnects: %d sent %d failed",
46878- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
46879- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
46880+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
46881+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
46882 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
46883- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
46884- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
46885+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
46886+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
46887 seq_printf(m, "\nCreates: %d sent %d failed",
46888- atomic_read(&sent[SMB2_CREATE_HE]),
46889- atomic_read(&failed[SMB2_CREATE_HE]));
46890+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
46891+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
46892 seq_printf(m, "\nCloses: %d sent %d failed",
46893- atomic_read(&sent[SMB2_CLOSE_HE]),
46894- atomic_read(&failed[SMB2_CLOSE_HE]));
46895+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
46896+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
46897 seq_printf(m, "\nFlushes: %d sent %d failed",
46898- atomic_read(&sent[SMB2_FLUSH_HE]),
46899- atomic_read(&failed[SMB2_FLUSH_HE]));
46900+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
46901+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
46902 seq_printf(m, "\nReads: %d sent %d failed",
46903- atomic_read(&sent[SMB2_READ_HE]),
46904- atomic_read(&failed[SMB2_READ_HE]));
46905+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
46906+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
46907 seq_printf(m, "\nWrites: %d sent %d failed",
46908- atomic_read(&sent[SMB2_WRITE_HE]),
46909- atomic_read(&failed[SMB2_WRITE_HE]));
46910+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
46911+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
46912 seq_printf(m, "\nLocks: %d sent %d failed",
46913- atomic_read(&sent[SMB2_LOCK_HE]),
46914- atomic_read(&failed[SMB2_LOCK_HE]));
46915+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
46916+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
46917 seq_printf(m, "\nIOCTLs: %d sent %d failed",
46918- atomic_read(&sent[SMB2_IOCTL_HE]),
46919- atomic_read(&failed[SMB2_IOCTL_HE]));
46920+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
46921+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
46922 seq_printf(m, "\nCancels: %d sent %d failed",
46923- atomic_read(&sent[SMB2_CANCEL_HE]),
46924- atomic_read(&failed[SMB2_CANCEL_HE]));
46925+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
46926+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
46927 seq_printf(m, "\nEchos: %d sent %d failed",
46928- atomic_read(&sent[SMB2_ECHO_HE]),
46929- atomic_read(&failed[SMB2_ECHO_HE]));
46930+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
46931+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
46932 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
46933- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
46934- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
46935+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
46936+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
46937 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
46938- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
46939- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
46940+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
46941+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
46942 seq_printf(m, "\nQueryInfos: %d sent %d failed",
46943- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
46944- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
46945+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
46946+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
46947 seq_printf(m, "\nSetInfos: %d sent %d failed",
46948- atomic_read(&sent[SMB2_SET_INFO_HE]),
46949- atomic_read(&failed[SMB2_SET_INFO_HE]));
46950+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
46951+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
46952 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
46953- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
46954- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
46955+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
46956+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
46957 #endif
46958 }
46959
46960diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
46961index 41d9d07..dbb4772 100644
46962--- a/fs/cifs/smb2pdu.c
46963+++ b/fs/cifs/smb2pdu.c
46964@@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
46965 default:
46966 cERROR(1, "info level %u isn't supported",
46967 srch_inf->info_level);
46968- rc = -EINVAL;
46969- goto qdir_exit;
46970+ return -EINVAL;
46971 }
46972
46973 req->FileIndex = cpu_to_le32(index);
46974diff --git a/fs/coda/cache.c b/fs/coda/cache.c
46975index 958ae0e..505c9d0 100644
46976--- a/fs/coda/cache.c
46977+++ b/fs/coda/cache.c
46978@@ -24,7 +24,7 @@
46979 #include "coda_linux.h"
46980 #include "coda_cache.h"
46981
46982-static atomic_t permission_epoch = ATOMIC_INIT(0);
46983+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
46984
46985 /* replace or extend an acl cache hit */
46986 void coda_cache_enter(struct inode *inode, int mask)
46987@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
46988 struct coda_inode_info *cii = ITOC(inode);
46989
46990 spin_lock(&cii->c_lock);
46991- cii->c_cached_epoch = atomic_read(&permission_epoch);
46992+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
46993 if (cii->c_uid != current_fsuid()) {
46994 cii->c_uid = current_fsuid();
46995 cii->c_cached_perm = mask;
46996@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
46997 {
46998 struct coda_inode_info *cii = ITOC(inode);
46999 spin_lock(&cii->c_lock);
47000- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
47001+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
47002 spin_unlock(&cii->c_lock);
47003 }
47004
47005 /* remove all acl caches */
47006 void coda_cache_clear_all(struct super_block *sb)
47007 {
47008- atomic_inc(&permission_epoch);
47009+ atomic_inc_unchecked(&permission_epoch);
47010 }
47011
47012
47013@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
47014 spin_lock(&cii->c_lock);
47015 hit = (mask & cii->c_cached_perm) == mask &&
47016 cii->c_uid == current_fsuid() &&
47017- cii->c_cached_epoch == atomic_read(&permission_epoch);
47018+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
47019 spin_unlock(&cii->c_lock);
47020
47021 return hit;
47022diff --git a/fs/compat.c b/fs/compat.c
47023index 015e1e1..5ce8e54 100644
47024--- a/fs/compat.c
47025+++ b/fs/compat.c
47026@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
47027
47028 set_fs(KERNEL_DS);
47029 /* The __user pointer cast is valid because of the set_fs() */
47030- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
47031+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
47032 set_fs(oldfs);
47033 /* truncating is ok because it's a user address */
47034 if (!ret)
47035@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
47036 goto out;
47037
47038 ret = -EINVAL;
47039- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
47040+ if (nr_segs > UIO_MAXIOV)
47041 goto out;
47042 if (nr_segs > fast_segs) {
47043 ret = -ENOMEM;
47044@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
47045
47046 struct compat_readdir_callback {
47047 struct compat_old_linux_dirent __user *dirent;
47048+ struct file * file;
47049 int result;
47050 };
47051
47052@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
47053 buf->result = -EOVERFLOW;
47054 return -EOVERFLOW;
47055 }
47056+
47057+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47058+ return 0;
47059+
47060 buf->result++;
47061 dirent = buf->dirent;
47062 if (!access_ok(VERIFY_WRITE, dirent,
47063@@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
47064
47065 buf.result = 0;
47066 buf.dirent = dirent;
47067+ buf.file = f.file;
47068
47069 error = vfs_readdir(f.file, compat_fillonedir, &buf);
47070 if (buf.result)
47071@@ -897,6 +903,7 @@ struct compat_linux_dirent {
47072 struct compat_getdents_callback {
47073 struct compat_linux_dirent __user *current_dir;
47074 struct compat_linux_dirent __user *previous;
47075+ struct file * file;
47076 int count;
47077 int error;
47078 };
47079@@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
47080 buf->error = -EOVERFLOW;
47081 return -EOVERFLOW;
47082 }
47083+
47084+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47085+ return 0;
47086+
47087 dirent = buf->previous;
47088 if (dirent) {
47089 if (__put_user(offset, &dirent->d_off))
47090@@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
47091 buf.previous = NULL;
47092 buf.count = count;
47093 buf.error = 0;
47094+ buf.file = f.file;
47095
47096 error = vfs_readdir(f.file, compat_filldir, &buf);
47097 if (error >= 0)
47098@@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
47099 struct compat_getdents_callback64 {
47100 struct linux_dirent64 __user *current_dir;
47101 struct linux_dirent64 __user *previous;
47102+ struct file * file;
47103 int count;
47104 int error;
47105 };
47106@@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
47107 buf->error = -EINVAL; /* only used if we fail.. */
47108 if (reclen > buf->count)
47109 return -EINVAL;
47110+
47111+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47112+ return 0;
47113+
47114 dirent = buf->previous;
47115
47116 if (dirent) {
47117@@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
47118 buf.previous = NULL;
47119 buf.count = count;
47120 buf.error = 0;
47121+ buf.file = f.file;
47122
47123 error = vfs_readdir(f.file, compat_filldir64, &buf);
47124 if (error >= 0)
47125 error = buf.error;
47126 lastdirent = buf.previous;
47127 if (lastdirent) {
47128- typeof(lastdirent->d_off) d_off = f.file->f_pos;
47129+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
47130 if (__put_user_unaligned(d_off, &lastdirent->d_off))
47131 error = -EFAULT;
47132 else
47133diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
47134index a81147e..20bf2b5 100644
47135--- a/fs/compat_binfmt_elf.c
47136+++ b/fs/compat_binfmt_elf.c
47137@@ -30,11 +30,13 @@
47138 #undef elf_phdr
47139 #undef elf_shdr
47140 #undef elf_note
47141+#undef elf_dyn
47142 #undef elf_addr_t
47143 #define elfhdr elf32_hdr
47144 #define elf_phdr elf32_phdr
47145 #define elf_shdr elf32_shdr
47146 #define elf_note elf32_note
47147+#define elf_dyn Elf32_Dyn
47148 #define elf_addr_t Elf32_Addr
47149
47150 /*
47151diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
47152index e2f57a0..3c78771 100644
47153--- a/fs/compat_ioctl.c
47154+++ b/fs/compat_ioctl.c
47155@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
47156 return -EFAULT;
47157 if (__get_user(udata, &ss32->iomem_base))
47158 return -EFAULT;
47159- ss.iomem_base = compat_ptr(udata);
47160+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
47161 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
47162 __get_user(ss.port_high, &ss32->port_high))
47163 return -EFAULT;
47164@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
47165 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
47166 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
47167 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
47168- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
47169+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
47170 return -EFAULT;
47171
47172 return ioctl_preallocate(file, p);
47173@@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
47174 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
47175 {
47176 unsigned int a, b;
47177- a = *(unsigned int *)p;
47178- b = *(unsigned int *)q;
47179+ a = *(const unsigned int *)p;
47180+ b = *(const unsigned int *)q;
47181 if (a > b)
47182 return 1;
47183 if (a < b)
47184diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
47185index 712b10f..c33c4ca 100644
47186--- a/fs/configfs/dir.c
47187+++ b/fs/configfs/dir.c
47188@@ -1037,10 +1037,11 @@ static int configfs_dump(struct configfs_dirent *sd, int level)
47189 static int configfs_depend_prep(struct dentry *origin,
47190 struct config_item *target)
47191 {
47192- struct configfs_dirent *child_sd, *sd = origin->d_fsdata;
47193+ struct configfs_dirent *child_sd, *sd;
47194 int ret = 0;
47195
47196- BUG_ON(!origin || !sd);
47197+ BUG_ON(!origin || !origin->d_fsdata);
47198+ sd = origin->d_fsdata;
47199
47200 if (sd->s_element == target) /* Boo-yah */
47201 goto out;
47202@@ -1564,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
47203 }
47204 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
47205 struct configfs_dirent *next;
47206- const char * name;
47207+ const unsigned char * name;
47208+ char d_name[sizeof(next->s_dentry->d_iname)];
47209 int len;
47210 struct inode *inode = NULL;
47211
47212@@ -1574,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
47213 continue;
47214
47215 name = configfs_get_name(next);
47216- len = strlen(name);
47217+ if (next->s_dentry && name == next->s_dentry->d_iname) {
47218+ len = next->s_dentry->d_name.len;
47219+ memcpy(d_name, name, len);
47220+ name = d_name;
47221+ } else
47222+ len = strlen(name);
47223
47224 /*
47225 * We'll have a dentry and an inode for
47226diff --git a/fs/coredump.c b/fs/coredump.c
47227index 1774932..5812106 100644
47228--- a/fs/coredump.c
47229+++ b/fs/coredump.c
47230@@ -52,7 +52,7 @@ struct core_name {
47231 char *corename;
47232 int used, size;
47233 };
47234-static atomic_t call_count = ATOMIC_INIT(1);
47235+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
47236
47237 /* The maximal length of core_pattern is also specified in sysctl.c */
47238
47239@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
47240 {
47241 char *old_corename = cn->corename;
47242
47243- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
47244+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
47245 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
47246
47247 if (!cn->corename) {
47248@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
47249 int pid_in_pattern = 0;
47250 int err = 0;
47251
47252- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
47253+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
47254 cn->corename = kmalloc(cn->size, GFP_KERNEL);
47255 cn->used = 0;
47256
47257@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
47258 pipe = file->f_path.dentry->d_inode->i_pipe;
47259
47260 pipe_lock(pipe);
47261- pipe->readers++;
47262- pipe->writers--;
47263+ atomic_inc(&pipe->readers);
47264+ atomic_dec(&pipe->writers);
47265
47266- while ((pipe->readers > 1) && (!signal_pending(current))) {
47267+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
47268 wake_up_interruptible_sync(&pipe->wait);
47269 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47270 pipe_wait(pipe);
47271 }
47272
47273- pipe->readers--;
47274- pipe->writers++;
47275+ atomic_dec(&pipe->readers);
47276+ atomic_inc(&pipe->writers);
47277 pipe_unlock(pipe);
47278
47279 }
47280@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
47281 int ispipe;
47282 struct files_struct *displaced;
47283 bool need_nonrelative = false;
47284- static atomic_t core_dump_count = ATOMIC_INIT(0);
47285+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
47286+ long signr = siginfo->si_signo;
47287 struct coredump_params cprm = {
47288 .siginfo = siginfo,
47289 .regs = signal_pt_regs(),
47290@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
47291 .mm_flags = mm->flags,
47292 };
47293
47294- audit_core_dumps(siginfo->si_signo);
47295+ audit_core_dumps(signr);
47296+
47297+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
47298+ gr_handle_brute_attach(cprm.mm_flags);
47299
47300 binfmt = mm->binfmt;
47301 if (!binfmt || !binfmt->core_dump)
47302@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
47303 need_nonrelative = true;
47304 }
47305
47306- retval = coredump_wait(siginfo->si_signo, &core_state);
47307+ retval = coredump_wait(signr, &core_state);
47308 if (retval < 0)
47309 goto fail_creds;
47310
47311@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
47312 }
47313 cprm.limit = RLIM_INFINITY;
47314
47315- dump_count = atomic_inc_return(&core_dump_count);
47316+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
47317 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
47318 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
47319 task_tgid_vnr(current), current->comm);
47320@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
47321 } else {
47322 struct inode *inode;
47323
47324+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
47325+
47326 if (cprm.limit < binfmt->min_coredump)
47327 goto fail_unlock;
47328
47329@@ -640,7 +646,7 @@ close_fail:
47330 filp_close(cprm.file, NULL);
47331 fail_dropcount:
47332 if (ispipe)
47333- atomic_dec(&core_dump_count);
47334+ atomic_dec_unchecked(&core_dump_count);
47335 fail_unlock:
47336 kfree(cn.corename);
47337 fail_corename:
47338@@ -659,7 +665,7 @@ fail:
47339 */
47340 int dump_write(struct file *file, const void *addr, int nr)
47341 {
47342- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
47343+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
47344 }
47345 EXPORT_SYMBOL(dump_write);
47346
47347diff --git a/fs/dcache.c b/fs/dcache.c
47348index 19153a0..428c2f5 100644
47349--- a/fs/dcache.c
47350+++ b/fs/dcache.c
47351@@ -3133,7 +3133,7 @@ void __init vfs_caches_init(unsigned long mempages)
47352 mempages -= reserve;
47353
47354 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
47355- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
47356+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
47357
47358 dcache_init();
47359 inode_init();
47360diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
47361index a5f12b7..4ee8a6f 100644
47362--- a/fs/debugfs/inode.c
47363+++ b/fs/debugfs/inode.c
47364@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
47365 */
47366 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
47367 {
47368+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
47369+ return __create_file(name, S_IFDIR | S_IRWXU,
47370+#else
47371 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
47372+#endif
47373 parent, NULL, NULL);
47374 }
47375 EXPORT_SYMBOL_GPL(debugfs_create_dir);
47376diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
47377index cc7709e..7e7211f 100644
47378--- a/fs/ecryptfs/inode.c
47379+++ b/fs/ecryptfs/inode.c
47380@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
47381 old_fs = get_fs();
47382 set_fs(get_ds());
47383 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
47384- (char __user *)lower_buf,
47385+ (char __force_user *)lower_buf,
47386 PATH_MAX);
47387 set_fs(old_fs);
47388 if (rc < 0)
47389@@ -706,7 +706,7 @@ out:
47390 static void
47391 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
47392 {
47393- char *buf = nd_get_link(nd);
47394+ const char *buf = nd_get_link(nd);
47395 if (!IS_ERR(buf)) {
47396 /* Free the char* */
47397 kfree(buf);
47398diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
47399index 412e6ed..4292d22 100644
47400--- a/fs/ecryptfs/miscdev.c
47401+++ b/fs/ecryptfs/miscdev.c
47402@@ -315,7 +315,7 @@ check_list:
47403 goto out_unlock_msg_ctx;
47404 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
47405 if (msg_ctx->msg) {
47406- if (copy_to_user(&buf[i], packet_length, packet_length_size))
47407+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
47408 goto out_unlock_msg_ctx;
47409 i += packet_length_size;
47410 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
47411diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
47412index b2a34a1..162fa69 100644
47413--- a/fs/ecryptfs/read_write.c
47414+++ b/fs/ecryptfs/read_write.c
47415@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
47416 return -EIO;
47417 fs_save = get_fs();
47418 set_fs(get_ds());
47419- rc = vfs_write(lower_file, data, size, &offset);
47420+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
47421 set_fs(fs_save);
47422 mark_inode_dirty_sync(ecryptfs_inode);
47423 return rc;
47424@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
47425 return -EIO;
47426 fs_save = get_fs();
47427 set_fs(get_ds());
47428- rc = vfs_read(lower_file, data, size, &offset);
47429+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
47430 set_fs(fs_save);
47431 return rc;
47432 }
47433diff --git a/fs/exec.c b/fs/exec.c
47434index 20df02c..1dff97d 100644
47435--- a/fs/exec.c
47436+++ b/fs/exec.c
47437@@ -55,6 +55,17 @@
47438 #include <linux/pipe_fs_i.h>
47439 #include <linux/oom.h>
47440 #include <linux/compat.h>
47441+#include <linux/random.h>
47442+#include <linux/seq_file.h>
47443+#include <linux/coredump.h>
47444+#include <linux/mman.h>
47445+
47446+#ifdef CONFIG_PAX_REFCOUNT
47447+#include <linux/kallsyms.h>
47448+#include <linux/kdebug.h>
47449+#endif
47450+
47451+#include <trace/events/fs.h>
47452
47453 #include <asm/uaccess.h>
47454 #include <asm/mmu_context.h>
47455@@ -66,6 +77,18 @@
47456
47457 #include <trace/events/sched.h>
47458
47459+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
47460+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
47461+{
47462+ 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");
47463+}
47464+#endif
47465+
47466+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
47467+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
47468+EXPORT_SYMBOL(pax_set_initial_flags_func);
47469+#endif
47470+
47471 int suid_dumpable = 0;
47472
47473 static LIST_HEAD(formats);
47474@@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
47475 int write)
47476 {
47477 struct page *page;
47478- int ret;
47479
47480-#ifdef CONFIG_STACK_GROWSUP
47481- if (write) {
47482- ret = expand_downwards(bprm->vma, pos);
47483- if (ret < 0)
47484- return NULL;
47485- }
47486-#endif
47487- ret = get_user_pages(current, bprm->mm, pos,
47488- 1, write, 1, &page, NULL);
47489- if (ret <= 0)
47490+ if (0 > expand_downwards(bprm->vma, pos))
47491+ return NULL;
47492+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
47493 return NULL;
47494
47495 if (write) {
47496@@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
47497 if (size <= ARG_MAX)
47498 return page;
47499
47500+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47501+ // only allow 512KB for argv+env on suid/sgid binaries
47502+ // to prevent easy ASLR exhaustion
47503+ if (((bprm->cred->euid != current_euid()) ||
47504+ (bprm->cred->egid != current_egid())) &&
47505+ (size > (512 * 1024))) {
47506+ put_page(page);
47507+ return NULL;
47508+ }
47509+#endif
47510+
47511 /*
47512 * Limit to 1/4-th the stack size for the argv+env strings.
47513 * This ensures that:
47514@@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
47515 vma->vm_end = STACK_TOP_MAX;
47516 vma->vm_start = vma->vm_end - PAGE_SIZE;
47517 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
47518+
47519+#ifdef CONFIG_PAX_SEGMEXEC
47520+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
47521+#endif
47522+
47523 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
47524 INIT_LIST_HEAD(&vma->anon_vma_chain);
47525
47526@@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
47527 mm->stack_vm = mm->total_vm = 1;
47528 up_write(&mm->mmap_sem);
47529 bprm->p = vma->vm_end - sizeof(void *);
47530+
47531+#ifdef CONFIG_PAX_RANDUSTACK
47532+ if (randomize_va_space)
47533+ bprm->p ^= random32() & ~PAGE_MASK;
47534+#endif
47535+
47536 return 0;
47537 err:
47538 up_write(&mm->mmap_sem);
47539@@ -384,19 +421,7 @@ err:
47540 return err;
47541 }
47542
47543-struct user_arg_ptr {
47544-#ifdef CONFIG_COMPAT
47545- bool is_compat;
47546-#endif
47547- union {
47548- const char __user *const __user *native;
47549-#ifdef CONFIG_COMPAT
47550- const compat_uptr_t __user *compat;
47551-#endif
47552- } ptr;
47553-};
47554-
47555-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
47556+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
47557 {
47558 const char __user *native;
47559
47560@@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
47561 compat_uptr_t compat;
47562
47563 if (get_user(compat, argv.ptr.compat + nr))
47564- return ERR_PTR(-EFAULT);
47565+ return (const char __force_user *)ERR_PTR(-EFAULT);
47566
47567 return compat_ptr(compat);
47568 }
47569 #endif
47570
47571 if (get_user(native, argv.ptr.native + nr))
47572- return ERR_PTR(-EFAULT);
47573+ return (const char __force_user *)ERR_PTR(-EFAULT);
47574
47575 return native;
47576 }
47577@@ -431,7 +456,7 @@ static int count(struct user_arg_ptr argv, int max)
47578 if (!p)
47579 break;
47580
47581- if (IS_ERR(p))
47582+ if (IS_ERR((const char __force_kernel *)p))
47583 return -EFAULT;
47584
47585 if (i >= max)
47586@@ -466,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
47587
47588 ret = -EFAULT;
47589 str = get_user_arg_ptr(argv, argc);
47590- if (IS_ERR(str))
47591+ if (IS_ERR((const char __force_kernel *)str))
47592 goto out;
47593
47594 len = strnlen_user(str, MAX_ARG_STRLEN);
47595@@ -548,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
47596 int r;
47597 mm_segment_t oldfs = get_fs();
47598 struct user_arg_ptr argv = {
47599- .ptr.native = (const char __user *const __user *)__argv,
47600+ .ptr.native = (const char __force_user *const __force_user *)__argv,
47601 };
47602
47603 set_fs(KERNEL_DS);
47604@@ -583,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
47605 unsigned long new_end = old_end - shift;
47606 struct mmu_gather tlb;
47607
47608- BUG_ON(new_start > new_end);
47609+ if (new_start >= new_end || new_start < mmap_min_addr)
47610+ return -ENOMEM;
47611
47612 /*
47613 * ensure there are no vmas between where we want to go
47614@@ -592,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
47615 if (vma != find_vma(mm, new_start))
47616 return -EFAULT;
47617
47618+#ifdef CONFIG_PAX_SEGMEXEC
47619+ BUG_ON(pax_find_mirror_vma(vma));
47620+#endif
47621+
47622 /*
47623 * cover the whole range: [new_start, old_end)
47624 */
47625@@ -672,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
47626 stack_top = arch_align_stack(stack_top);
47627 stack_top = PAGE_ALIGN(stack_top);
47628
47629- if (unlikely(stack_top < mmap_min_addr) ||
47630- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
47631- return -ENOMEM;
47632-
47633 stack_shift = vma->vm_end - stack_top;
47634
47635 bprm->p -= stack_shift;
47636@@ -687,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
47637 bprm->exec -= stack_shift;
47638
47639 down_write(&mm->mmap_sem);
47640+
47641+ /* Move stack pages down in memory. */
47642+ if (stack_shift) {
47643+ ret = shift_arg_pages(vma, stack_shift);
47644+ if (ret)
47645+ goto out_unlock;
47646+ }
47647+
47648 vm_flags = VM_STACK_FLAGS;
47649
47650+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47651+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47652+ vm_flags &= ~VM_EXEC;
47653+
47654+#ifdef CONFIG_PAX_MPROTECT
47655+ if (mm->pax_flags & MF_PAX_MPROTECT)
47656+ vm_flags &= ~VM_MAYEXEC;
47657+#endif
47658+
47659+ }
47660+#endif
47661+
47662 /*
47663 * Adjust stack execute permissions; explicitly enable for
47664 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
47665@@ -707,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
47666 goto out_unlock;
47667 BUG_ON(prev != vma);
47668
47669- /* Move stack pages down in memory. */
47670- if (stack_shift) {
47671- ret = shift_arg_pages(vma, stack_shift);
47672- if (ret)
47673- goto out_unlock;
47674- }
47675-
47676 /* mprotect_fixup is overkill to remove the temporary stack flags */
47677 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
47678
47679@@ -737,6 +776,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
47680 #endif
47681 current->mm->start_stack = bprm->p;
47682 ret = expand_stack(vma, stack_base);
47683+
47684+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
47685+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
47686+ unsigned long size, flags, vm_flags;
47687+
47688+ size = STACK_TOP - vma->vm_end;
47689+ flags = MAP_FIXED | MAP_PRIVATE;
47690+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
47691+
47692+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
47693+
47694+#ifdef CONFIG_X86
47695+ if (!ret) {
47696+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
47697+ ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
47698+ }
47699+#endif
47700+
47701+ }
47702+#endif
47703+
47704 if (ret)
47705 ret = -EFAULT;
47706
47707@@ -772,6 +832,8 @@ struct file *open_exec(const char *name)
47708
47709 fsnotify_open(file);
47710
47711+ trace_open_exec(name);
47712+
47713 err = deny_write_access(file);
47714 if (err)
47715 goto exit;
47716@@ -795,7 +857,7 @@ int kernel_read(struct file *file, loff_t offset,
47717 old_fs = get_fs();
47718 set_fs(get_ds());
47719 /* The cast to a user pointer is valid due to the set_fs() */
47720- result = vfs_read(file, (void __user *)addr, count, &pos);
47721+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
47722 set_fs(old_fs);
47723 return result;
47724 }
47725@@ -1247,7 +1309,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
47726 }
47727 rcu_read_unlock();
47728
47729- if (p->fs->users > n_fs) {
47730+ if (atomic_read(&p->fs->users) > n_fs) {
47731 bprm->unsafe |= LSM_UNSAFE_SHARE;
47732 } else {
47733 res = -EAGAIN;
47734@@ -1447,6 +1509,28 @@ int search_binary_handler(struct linux_binprm *bprm)
47735
47736 EXPORT_SYMBOL(search_binary_handler);
47737
47738+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47739+static DEFINE_PER_CPU(u64, exec_counter);
47740+static int __init init_exec_counters(void)
47741+{
47742+ unsigned int cpu;
47743+
47744+ for_each_possible_cpu(cpu) {
47745+ per_cpu(exec_counter, cpu) = (u64)cpu;
47746+ }
47747+
47748+ return 0;
47749+}
47750+early_initcall(init_exec_counters);
47751+static inline void increment_exec_counter(void)
47752+{
47753+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
47754+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
47755+}
47756+#else
47757+static inline void increment_exec_counter(void) {}
47758+#endif
47759+
47760 /*
47761 * sys_execve() executes a new program.
47762 */
47763@@ -1454,6 +1538,11 @@ static int do_execve_common(const char *filename,
47764 struct user_arg_ptr argv,
47765 struct user_arg_ptr envp)
47766 {
47767+#ifdef CONFIG_GRKERNSEC
47768+ struct file *old_exec_file;
47769+ struct acl_subject_label *old_acl;
47770+ struct rlimit old_rlim[RLIM_NLIMITS];
47771+#endif
47772 struct linux_binprm *bprm;
47773 struct file *file;
47774 struct files_struct *displaced;
47775@@ -1461,6 +1550,8 @@ static int do_execve_common(const char *filename,
47776 int retval;
47777 const struct cred *cred = current_cred();
47778
47779+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
47780+
47781 /*
47782 * We move the actual failure in case of RLIMIT_NPROC excess from
47783 * set*uid() to execve() because too many poorly written programs
47784@@ -1501,12 +1592,27 @@ static int do_execve_common(const char *filename,
47785 if (IS_ERR(file))
47786 goto out_unmark;
47787
47788+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
47789+ retval = -EPERM;
47790+ goto out_file;
47791+ }
47792+
47793 sched_exec();
47794
47795 bprm->file = file;
47796 bprm->filename = filename;
47797 bprm->interp = filename;
47798
47799+ if (gr_process_user_ban()) {
47800+ retval = -EPERM;
47801+ goto out_file;
47802+ }
47803+
47804+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
47805+ retval = -EACCES;
47806+ goto out_file;
47807+ }
47808+
47809 retval = bprm_mm_init(bprm);
47810 if (retval)
47811 goto out_file;
47812@@ -1523,24 +1629,65 @@ static int do_execve_common(const char *filename,
47813 if (retval < 0)
47814 goto out;
47815
47816+#ifdef CONFIG_GRKERNSEC
47817+ old_acl = current->acl;
47818+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
47819+ old_exec_file = current->exec_file;
47820+ get_file(file);
47821+ current->exec_file = file;
47822+#endif
47823+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47824+ /* limit suid stack to 8MB
47825+ * we saved the old limits above and will restore them if this exec fails
47826+ */
47827+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
47828+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
47829+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
47830+#endif
47831+
47832+ if (!gr_tpe_allow(file)) {
47833+ retval = -EACCES;
47834+ goto out_fail;
47835+ }
47836+
47837+ if (gr_check_crash_exec(file)) {
47838+ retval = -EACCES;
47839+ goto out_fail;
47840+ }
47841+
47842+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
47843+ bprm->unsafe);
47844+ if (retval < 0)
47845+ goto out_fail;
47846+
47847 retval = copy_strings_kernel(1, &bprm->filename, bprm);
47848 if (retval < 0)
47849- goto out;
47850+ goto out_fail;
47851
47852 bprm->exec = bprm->p;
47853 retval = copy_strings(bprm->envc, envp, bprm);
47854 if (retval < 0)
47855- goto out;
47856+ goto out_fail;
47857
47858 retval = copy_strings(bprm->argc, argv, bprm);
47859 if (retval < 0)
47860- goto out;
47861+ goto out_fail;
47862+
47863+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
47864+
47865+ gr_handle_exec_args(bprm, argv);
47866
47867 retval = search_binary_handler(bprm);
47868 if (retval < 0)
47869- goto out;
47870+ goto out_fail;
47871+#ifdef CONFIG_GRKERNSEC
47872+ if (old_exec_file)
47873+ fput(old_exec_file);
47874+#endif
47875
47876 /* execve succeeded */
47877+
47878+ increment_exec_counter();
47879 current->fs->in_exec = 0;
47880 current->in_execve = 0;
47881 acct_update_integrals(current);
47882@@ -1549,6 +1696,14 @@ static int do_execve_common(const char *filename,
47883 put_files_struct(displaced);
47884 return retval;
47885
47886+out_fail:
47887+#ifdef CONFIG_GRKERNSEC
47888+ current->acl = old_acl;
47889+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
47890+ fput(current->exec_file);
47891+ current->exec_file = old_exec_file;
47892+#endif
47893+
47894 out:
47895 if (bprm->mm) {
47896 acct_arg_size(bprm, 0);
47897@@ -1697,3 +1852,253 @@ asmlinkage long compat_sys_execve(const char __user * filename,
47898 return error;
47899 }
47900 #endif
47901+
47902+int pax_check_flags(unsigned long *flags)
47903+{
47904+ int retval = 0;
47905+
47906+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
47907+ if (*flags & MF_PAX_SEGMEXEC)
47908+ {
47909+ *flags &= ~MF_PAX_SEGMEXEC;
47910+ retval = -EINVAL;
47911+ }
47912+#endif
47913+
47914+ if ((*flags & MF_PAX_PAGEEXEC)
47915+
47916+#ifdef CONFIG_PAX_PAGEEXEC
47917+ && (*flags & MF_PAX_SEGMEXEC)
47918+#endif
47919+
47920+ )
47921+ {
47922+ *flags &= ~MF_PAX_PAGEEXEC;
47923+ retval = -EINVAL;
47924+ }
47925+
47926+ if ((*flags & MF_PAX_MPROTECT)
47927+
47928+#ifdef CONFIG_PAX_MPROTECT
47929+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47930+#endif
47931+
47932+ )
47933+ {
47934+ *flags &= ~MF_PAX_MPROTECT;
47935+ retval = -EINVAL;
47936+ }
47937+
47938+ if ((*flags & MF_PAX_EMUTRAMP)
47939+
47940+#ifdef CONFIG_PAX_EMUTRAMP
47941+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47942+#endif
47943+
47944+ )
47945+ {
47946+ *flags &= ~MF_PAX_EMUTRAMP;
47947+ retval = -EINVAL;
47948+ }
47949+
47950+ return retval;
47951+}
47952+
47953+EXPORT_SYMBOL(pax_check_flags);
47954+
47955+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47956+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
47957+{
47958+ struct task_struct *tsk = current;
47959+ struct mm_struct *mm = current->mm;
47960+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
47961+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
47962+ char *path_exec = NULL;
47963+ char *path_fault = NULL;
47964+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
47965+ siginfo_t info = { };
47966+
47967+ if (buffer_exec && buffer_fault) {
47968+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
47969+
47970+ down_read(&mm->mmap_sem);
47971+ vma = mm->mmap;
47972+ while (vma && (!vma_exec || !vma_fault)) {
47973+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
47974+ vma_exec = vma;
47975+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
47976+ vma_fault = vma;
47977+ vma = vma->vm_next;
47978+ }
47979+ if (vma_exec) {
47980+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
47981+ if (IS_ERR(path_exec))
47982+ path_exec = "<path too long>";
47983+ else {
47984+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
47985+ if (path_exec) {
47986+ *path_exec = 0;
47987+ path_exec = buffer_exec;
47988+ } else
47989+ path_exec = "<path too long>";
47990+ }
47991+ }
47992+ if (vma_fault) {
47993+ start = vma_fault->vm_start;
47994+ end = vma_fault->vm_end;
47995+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
47996+ if (vma_fault->vm_file) {
47997+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
47998+ if (IS_ERR(path_fault))
47999+ path_fault = "<path too long>";
48000+ else {
48001+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
48002+ if (path_fault) {
48003+ *path_fault = 0;
48004+ path_fault = buffer_fault;
48005+ } else
48006+ path_fault = "<path too long>";
48007+ }
48008+ } else
48009+ path_fault = "<anonymous mapping>";
48010+ }
48011+ up_read(&mm->mmap_sem);
48012+ }
48013+ if (tsk->signal->curr_ip)
48014+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
48015+ else
48016+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
48017+ 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),
48018+ from_kuid(&init_user_ns, task_uid(tsk)), from_kuid(&init_user_ns, task_euid(tsk)), pc, sp);
48019+ free_page((unsigned long)buffer_exec);
48020+ free_page((unsigned long)buffer_fault);
48021+ pax_report_insns(regs, pc, sp);
48022+ info.si_signo = SIGKILL;
48023+ info.si_errno = 0;
48024+ info.si_code = SI_KERNEL;
48025+ info.si_pid = 0;
48026+ info.si_uid = 0;
48027+ do_coredump(&info);
48028+}
48029+#endif
48030+
48031+#ifdef CONFIG_PAX_REFCOUNT
48032+void pax_report_refcount_overflow(struct pt_regs *regs)
48033+{
48034+ if (current->signal->curr_ip)
48035+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
48036+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
48037+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
48038+ else
48039+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
48040+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
48041+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
48042+ show_regs(regs);
48043+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
48044+}
48045+#endif
48046+
48047+#ifdef CONFIG_PAX_USERCOPY
48048+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
48049+static noinline int check_stack_object(const void *obj, unsigned long len)
48050+{
48051+ const void * const stack = task_stack_page(current);
48052+ const void * const stackend = stack + THREAD_SIZE;
48053+
48054+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48055+ const void *frame = NULL;
48056+ const void *oldframe;
48057+#endif
48058+
48059+ if (obj + len < obj)
48060+ return -1;
48061+
48062+ if (obj + len <= stack || stackend <= obj)
48063+ return 0;
48064+
48065+ if (obj < stack || stackend < obj + len)
48066+ return -1;
48067+
48068+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48069+ oldframe = __builtin_frame_address(1);
48070+ if (oldframe)
48071+ frame = __builtin_frame_address(2);
48072+ /*
48073+ low ----------------------------------------------> high
48074+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
48075+ ^----------------^
48076+ allow copies only within here
48077+ */
48078+ while (stack <= frame && frame < stackend) {
48079+ /* if obj + len extends past the last frame, this
48080+ check won't pass and the next frame will be 0,
48081+ causing us to bail out and correctly report
48082+ the copy as invalid
48083+ */
48084+ if (obj + len <= frame)
48085+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
48086+ oldframe = frame;
48087+ frame = *(const void * const *)frame;
48088+ }
48089+ return -1;
48090+#else
48091+ return 1;
48092+#endif
48093+}
48094+
48095+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
48096+{
48097+ if (current->signal->curr_ip)
48098+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48099+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48100+ else
48101+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48102+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48103+ dump_stack();
48104+ gr_handle_kernel_exploit();
48105+ do_group_exit(SIGKILL);
48106+}
48107+#endif
48108+
48109+void __check_object_size(const void *ptr, unsigned long n, bool to)
48110+{
48111+
48112+#ifdef CONFIG_PAX_USERCOPY
48113+ const char *type;
48114+
48115+ if (!n)
48116+ return;
48117+
48118+ type = check_heap_object(ptr, n);
48119+ if (!type) {
48120+ if (check_stack_object(ptr, n) != -1)
48121+ return;
48122+ type = "<process stack>";
48123+ }
48124+
48125+ pax_report_usercopy(ptr, n, to, type);
48126+#endif
48127+
48128+}
48129+EXPORT_SYMBOL(__check_object_size);
48130+
48131+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
48132+void pax_track_stack(void)
48133+{
48134+ unsigned long sp = (unsigned long)&sp;
48135+ if (sp < current_thread_info()->lowest_stack &&
48136+ sp > (unsigned long)task_stack_page(current))
48137+ current_thread_info()->lowest_stack = sp;
48138+}
48139+EXPORT_SYMBOL(pax_track_stack);
48140+#endif
48141+
48142+#ifdef CONFIG_PAX_SIZE_OVERFLOW
48143+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
48144+{
48145+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
48146+ dump_stack();
48147+ do_group_exit(SIGKILL);
48148+}
48149+EXPORT_SYMBOL(report_size_overflow);
48150+#endif
48151diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
48152index 2616d0e..2ffdec9 100644
48153--- a/fs/ext2/balloc.c
48154+++ b/fs/ext2/balloc.c
48155@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
48156
48157 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48158 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48159- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48160+ if (free_blocks < root_blocks + 1 &&
48161 !uid_eq(sbi->s_resuid, current_fsuid()) &&
48162 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
48163- !in_group_p (sbi->s_resgid))) {
48164+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
48165 return 0;
48166 }
48167 return 1;
48168diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
48169index 22548f5..41521d8 100644
48170--- a/fs/ext3/balloc.c
48171+++ b/fs/ext3/balloc.c
48172@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
48173
48174 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48175 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48176- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48177+ if (free_blocks < root_blocks + 1 &&
48178 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
48179 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
48180- !in_group_p (sbi->s_resgid))) {
48181+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
48182 return 0;
48183 }
48184 return 1;
48185diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
48186index cf18217..8f6b9c3 100644
48187--- a/fs/ext4/balloc.c
48188+++ b/fs/ext4/balloc.c
48189@@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
48190 /* Hm, nope. Are (enough) root reserved clusters available? */
48191 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
48192 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
48193- capable(CAP_SYS_RESOURCE) ||
48194- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
48195+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
48196+ capable_nolog(CAP_SYS_RESOURCE)) {
48197
48198 if (free_clusters >= (nclusters + dirty_clusters))
48199 return 1;
48200diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
48201index 8462eb3..4a71af6 100644
48202--- a/fs/ext4/ext4.h
48203+++ b/fs/ext4/ext4.h
48204@@ -1265,19 +1265,19 @@ struct ext4_sb_info {
48205 unsigned long s_mb_last_start;
48206
48207 /* stats for buddy allocator */
48208- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
48209- atomic_t s_bal_success; /* we found long enough chunks */
48210- atomic_t s_bal_allocated; /* in blocks */
48211- atomic_t s_bal_ex_scanned; /* total extents scanned */
48212- atomic_t s_bal_goals; /* goal hits */
48213- atomic_t s_bal_breaks; /* too long searches */
48214- atomic_t s_bal_2orders; /* 2^order hits */
48215+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
48216+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
48217+ atomic_unchecked_t s_bal_allocated; /* in blocks */
48218+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
48219+ atomic_unchecked_t s_bal_goals; /* goal hits */
48220+ atomic_unchecked_t s_bal_breaks; /* too long searches */
48221+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
48222 spinlock_t s_bal_lock;
48223 unsigned long s_mb_buddies_generated;
48224 unsigned long long s_mb_generation_time;
48225- atomic_t s_mb_lost_chunks;
48226- atomic_t s_mb_preallocated;
48227- atomic_t s_mb_discarded;
48228+ atomic_unchecked_t s_mb_lost_chunks;
48229+ atomic_unchecked_t s_mb_preallocated;
48230+ atomic_unchecked_t s_mb_discarded;
48231 atomic_t s_lock_busy;
48232
48233 /* locality groups */
48234diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
48235index 1bf6fe7..1a5bdef 100644
48236--- a/fs/ext4/mballoc.c
48237+++ b/fs/ext4/mballoc.c
48238@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
48239 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
48240
48241 if (EXT4_SB(sb)->s_mb_stats)
48242- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
48243+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
48244
48245 break;
48246 }
48247@@ -2044,7 +2044,7 @@ repeat:
48248 ac->ac_status = AC_STATUS_CONTINUE;
48249 ac->ac_flags |= EXT4_MB_HINT_FIRST;
48250 cr = 3;
48251- atomic_inc(&sbi->s_mb_lost_chunks);
48252+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
48253 goto repeat;
48254 }
48255 }
48256@@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
48257 if (sbi->s_mb_stats) {
48258 ext4_msg(sb, KERN_INFO,
48259 "mballoc: %u blocks %u reqs (%u success)",
48260- atomic_read(&sbi->s_bal_allocated),
48261- atomic_read(&sbi->s_bal_reqs),
48262- atomic_read(&sbi->s_bal_success));
48263+ atomic_read_unchecked(&sbi->s_bal_allocated),
48264+ atomic_read_unchecked(&sbi->s_bal_reqs),
48265+ atomic_read_unchecked(&sbi->s_bal_success));
48266 ext4_msg(sb, KERN_INFO,
48267 "mballoc: %u extents scanned, %u goal hits, "
48268 "%u 2^N hits, %u breaks, %u lost",
48269- atomic_read(&sbi->s_bal_ex_scanned),
48270- atomic_read(&sbi->s_bal_goals),
48271- atomic_read(&sbi->s_bal_2orders),
48272- atomic_read(&sbi->s_bal_breaks),
48273- atomic_read(&sbi->s_mb_lost_chunks));
48274+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
48275+ atomic_read_unchecked(&sbi->s_bal_goals),
48276+ atomic_read_unchecked(&sbi->s_bal_2orders),
48277+ atomic_read_unchecked(&sbi->s_bal_breaks),
48278+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
48279 ext4_msg(sb, KERN_INFO,
48280 "mballoc: %lu generated and it took %Lu",
48281 sbi->s_mb_buddies_generated,
48282 sbi->s_mb_generation_time);
48283 ext4_msg(sb, KERN_INFO,
48284 "mballoc: %u preallocated, %u discarded",
48285- atomic_read(&sbi->s_mb_preallocated),
48286- atomic_read(&sbi->s_mb_discarded));
48287+ atomic_read_unchecked(&sbi->s_mb_preallocated),
48288+ atomic_read_unchecked(&sbi->s_mb_discarded));
48289 }
48290
48291 free_percpu(sbi->s_locality_groups);
48292@@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
48293 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
48294
48295 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
48296- atomic_inc(&sbi->s_bal_reqs);
48297- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48298+ atomic_inc_unchecked(&sbi->s_bal_reqs);
48299+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48300 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
48301- atomic_inc(&sbi->s_bal_success);
48302- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
48303+ atomic_inc_unchecked(&sbi->s_bal_success);
48304+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
48305 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
48306 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
48307- atomic_inc(&sbi->s_bal_goals);
48308+ atomic_inc_unchecked(&sbi->s_bal_goals);
48309 if (ac->ac_found > sbi->s_mb_max_to_scan)
48310- atomic_inc(&sbi->s_bal_breaks);
48311+ atomic_inc_unchecked(&sbi->s_bal_breaks);
48312 }
48313
48314 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
48315@@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
48316 trace_ext4_mb_new_inode_pa(ac, pa);
48317
48318 ext4_mb_use_inode_pa(ac, pa);
48319- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
48320+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
48321
48322 ei = EXT4_I(ac->ac_inode);
48323 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
48324@@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
48325 trace_ext4_mb_new_group_pa(ac, pa);
48326
48327 ext4_mb_use_group_pa(ac, pa);
48328- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48329+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48330
48331 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
48332 lg = ac->ac_lg;
48333@@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
48334 * from the bitmap and continue.
48335 */
48336 }
48337- atomic_add(free, &sbi->s_mb_discarded);
48338+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
48339
48340 return err;
48341 }
48342@@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
48343 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
48344 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
48345 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
48346- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
48347+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
48348 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
48349
48350 return 0;
48351diff --git a/fs/fcntl.c b/fs/fcntl.c
48352index 71a600a..20d87b1 100644
48353--- a/fs/fcntl.c
48354+++ b/fs/fcntl.c
48355@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
48356 if (err)
48357 return err;
48358
48359+ if (gr_handle_chroot_fowner(pid, type))
48360+ return -ENOENT;
48361+ if (gr_check_protected_task_fowner(pid, type))
48362+ return -EACCES;
48363+
48364 f_modown(filp, pid, type, force);
48365 return 0;
48366 }
48367diff --git a/fs/fhandle.c b/fs/fhandle.c
48368index 999ff5c..41f4109 100644
48369--- a/fs/fhandle.c
48370+++ b/fs/fhandle.c
48371@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
48372 } else
48373 retval = 0;
48374 /* copy the mount id */
48375- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
48376- sizeof(*mnt_id)) ||
48377+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
48378 copy_to_user(ufh, handle,
48379 sizeof(struct file_handle) + handle_bytes))
48380 retval = -EFAULT;
48381diff --git a/fs/fifo.c b/fs/fifo.c
48382index cf6f434..3d7942c 100644
48383--- a/fs/fifo.c
48384+++ b/fs/fifo.c
48385@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
48386 */
48387 filp->f_op = &read_pipefifo_fops;
48388 pipe->r_counter++;
48389- if (pipe->readers++ == 0)
48390+ if (atomic_inc_return(&pipe->readers) == 1)
48391 wake_up_partner(inode);
48392
48393- if (!pipe->writers) {
48394+ if (!atomic_read(&pipe->writers)) {
48395 if ((filp->f_flags & O_NONBLOCK)) {
48396 /* suppress POLLHUP until we have
48397 * seen a writer */
48398@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
48399 * errno=ENXIO when there is no process reading the FIFO.
48400 */
48401 ret = -ENXIO;
48402- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
48403+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
48404 goto err;
48405
48406 filp->f_op = &write_pipefifo_fops;
48407 pipe->w_counter++;
48408- if (!pipe->writers++)
48409+ if (atomic_inc_return(&pipe->writers) == 1)
48410 wake_up_partner(inode);
48411
48412- if (!pipe->readers) {
48413+ if (!atomic_read(&pipe->readers)) {
48414 if (wait_for_partner(inode, &pipe->r_counter))
48415 goto err_wr;
48416 }
48417@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
48418 */
48419 filp->f_op = &rdwr_pipefifo_fops;
48420
48421- pipe->readers++;
48422- pipe->writers++;
48423+ atomic_inc(&pipe->readers);
48424+ atomic_inc(&pipe->writers);
48425 pipe->r_counter++;
48426 pipe->w_counter++;
48427- if (pipe->readers == 1 || pipe->writers == 1)
48428+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
48429 wake_up_partner(inode);
48430 break;
48431
48432@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
48433 return 0;
48434
48435 err_rd:
48436- if (!--pipe->readers)
48437+ if (atomic_dec_and_test(&pipe->readers))
48438 wake_up_interruptible(&pipe->wait);
48439 ret = -ERESTARTSYS;
48440 goto err;
48441
48442 err_wr:
48443- if (!--pipe->writers)
48444+ if (atomic_dec_and_test(&pipe->writers))
48445 wake_up_interruptible(&pipe->wait);
48446 ret = -ERESTARTSYS;
48447 goto err;
48448
48449 err:
48450- if (!pipe->readers && !pipe->writers)
48451+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
48452 free_pipe_info(inode);
48453
48454 err_nocleanup:
48455diff --git a/fs/file.c b/fs/file.c
48456index 2b3570b..c57924b 100644
48457--- a/fs/file.c
48458+++ b/fs/file.c
48459@@ -16,6 +16,7 @@
48460 #include <linux/slab.h>
48461 #include <linux/vmalloc.h>
48462 #include <linux/file.h>
48463+#include <linux/security.h>
48464 #include <linux/fdtable.h>
48465 #include <linux/bitops.h>
48466 #include <linux/interrupt.h>
48467@@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
48468 if (!file)
48469 return __close_fd(files, fd);
48470
48471+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
48472 if (fd >= rlimit(RLIMIT_NOFILE))
48473 return -EBADF;
48474
48475@@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
48476 if (unlikely(oldfd == newfd))
48477 return -EINVAL;
48478
48479+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
48480 if (newfd >= rlimit(RLIMIT_NOFILE))
48481 return -EBADF;
48482
48483@@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
48484 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
48485 {
48486 int err;
48487+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
48488 if (from >= rlimit(RLIMIT_NOFILE))
48489 return -EINVAL;
48490 err = alloc_fd(from, flags);
48491diff --git a/fs/filesystems.c b/fs/filesystems.c
48492index da165f6..3671bdb 100644
48493--- a/fs/filesystems.c
48494+++ b/fs/filesystems.c
48495@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
48496 int len = dot ? dot - name : strlen(name);
48497
48498 fs = __get_fs_type(name, len);
48499+
48500+#ifdef CONFIG_GRKERNSEC_MODHARDEN
48501+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
48502+#else
48503 if (!fs && (request_module("%.*s", len, name) == 0))
48504+#endif
48505 fs = __get_fs_type(name, len);
48506
48507 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
48508diff --git a/fs/fs_struct.c b/fs/fs_struct.c
48509index fe6ca58..65318cf 100644
48510--- a/fs/fs_struct.c
48511+++ b/fs/fs_struct.c
48512@@ -4,6 +4,7 @@
48513 #include <linux/path.h>
48514 #include <linux/slab.h>
48515 #include <linux/fs_struct.h>
48516+#include <linux/grsecurity.h>
48517 #include "internal.h"
48518
48519 /*
48520@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
48521 write_seqcount_begin(&fs->seq);
48522 old_root = fs->root;
48523 fs->root = *path;
48524+ gr_set_chroot_entries(current, path);
48525 write_seqcount_end(&fs->seq);
48526 spin_unlock(&fs->lock);
48527 if (old_root.dentry)
48528@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
48529 return 1;
48530 }
48531
48532+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
48533+{
48534+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
48535+ return 0;
48536+ *p = *new;
48537+
48538+ /* This function is only called from pivot_root(). Leave our
48539+ gr_chroot_dentry and is_chrooted flags as-is, so that a
48540+ pivoted root isn't treated as a chroot
48541+ */
48542+ //gr_set_chroot_entries(task, new);
48543+
48544+ return 1;
48545+}
48546+
48547 void chroot_fs_refs(struct path *old_root, struct path *new_root)
48548 {
48549 struct task_struct *g, *p;
48550@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
48551 int hits = 0;
48552 spin_lock(&fs->lock);
48553 write_seqcount_begin(&fs->seq);
48554- hits += replace_path(&fs->root, old_root, new_root);
48555+ hits += replace_root_path(p, &fs->root, old_root, new_root);
48556 hits += replace_path(&fs->pwd, old_root, new_root);
48557 write_seqcount_end(&fs->seq);
48558 while (hits--) {
48559@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
48560 task_lock(tsk);
48561 spin_lock(&fs->lock);
48562 tsk->fs = NULL;
48563- kill = !--fs->users;
48564+ gr_clear_chroot_entries(tsk);
48565+ kill = !atomic_dec_return(&fs->users);
48566 spin_unlock(&fs->lock);
48567 task_unlock(tsk);
48568 if (kill)
48569@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
48570 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
48571 /* We don't need to lock fs - think why ;-) */
48572 if (fs) {
48573- fs->users = 1;
48574+ atomic_set(&fs->users, 1);
48575 fs->in_exec = 0;
48576 spin_lock_init(&fs->lock);
48577 seqcount_init(&fs->seq);
48578@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
48579 spin_lock(&old->lock);
48580 fs->root = old->root;
48581 path_get(&fs->root);
48582+ /* instead of calling gr_set_chroot_entries here,
48583+ we call it from every caller of this function
48584+ */
48585 fs->pwd = old->pwd;
48586 path_get(&fs->pwd);
48587 spin_unlock(&old->lock);
48588@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
48589
48590 task_lock(current);
48591 spin_lock(&fs->lock);
48592- kill = !--fs->users;
48593+ kill = !atomic_dec_return(&fs->users);
48594 current->fs = new_fs;
48595+ gr_set_chroot_entries(current, &new_fs->root);
48596 spin_unlock(&fs->lock);
48597 task_unlock(current);
48598
48599@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
48600
48601 int current_umask(void)
48602 {
48603- return current->fs->umask;
48604+ return current->fs->umask | gr_acl_umask();
48605 }
48606 EXPORT_SYMBOL(current_umask);
48607
48608 /* to be mentioned only in INIT_TASK */
48609 struct fs_struct init_fs = {
48610- .users = 1,
48611+ .users = ATOMIC_INIT(1),
48612 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
48613 .seq = SEQCNT_ZERO,
48614 .umask = 0022,
48615diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
48616index 8dcb114..b1072e2 100644
48617--- a/fs/fscache/cookie.c
48618+++ b/fs/fscache/cookie.c
48619@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
48620 parent ? (char *) parent->def->name : "<no-parent>",
48621 def->name, netfs_data);
48622
48623- fscache_stat(&fscache_n_acquires);
48624+ fscache_stat_unchecked(&fscache_n_acquires);
48625
48626 /* if there's no parent cookie, then we don't create one here either */
48627 if (!parent) {
48628- fscache_stat(&fscache_n_acquires_null);
48629+ fscache_stat_unchecked(&fscache_n_acquires_null);
48630 _leave(" [no parent]");
48631 return NULL;
48632 }
48633@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
48634 /* allocate and initialise a cookie */
48635 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
48636 if (!cookie) {
48637- fscache_stat(&fscache_n_acquires_oom);
48638+ fscache_stat_unchecked(&fscache_n_acquires_oom);
48639 _leave(" [ENOMEM]");
48640 return NULL;
48641 }
48642@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
48643
48644 switch (cookie->def->type) {
48645 case FSCACHE_COOKIE_TYPE_INDEX:
48646- fscache_stat(&fscache_n_cookie_index);
48647+ fscache_stat_unchecked(&fscache_n_cookie_index);
48648 break;
48649 case FSCACHE_COOKIE_TYPE_DATAFILE:
48650- fscache_stat(&fscache_n_cookie_data);
48651+ fscache_stat_unchecked(&fscache_n_cookie_data);
48652 break;
48653 default:
48654- fscache_stat(&fscache_n_cookie_special);
48655+ fscache_stat_unchecked(&fscache_n_cookie_special);
48656 break;
48657 }
48658
48659@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
48660 if (fscache_acquire_non_index_cookie(cookie) < 0) {
48661 atomic_dec(&parent->n_children);
48662 __fscache_cookie_put(cookie);
48663- fscache_stat(&fscache_n_acquires_nobufs);
48664+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
48665 _leave(" = NULL");
48666 return NULL;
48667 }
48668 }
48669
48670- fscache_stat(&fscache_n_acquires_ok);
48671+ fscache_stat_unchecked(&fscache_n_acquires_ok);
48672 _leave(" = %p", cookie);
48673 return cookie;
48674 }
48675@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
48676 cache = fscache_select_cache_for_object(cookie->parent);
48677 if (!cache) {
48678 up_read(&fscache_addremove_sem);
48679- fscache_stat(&fscache_n_acquires_no_cache);
48680+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
48681 _leave(" = -ENOMEDIUM [no cache]");
48682 return -ENOMEDIUM;
48683 }
48684@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
48685 object = cache->ops->alloc_object(cache, cookie);
48686 fscache_stat_d(&fscache_n_cop_alloc_object);
48687 if (IS_ERR(object)) {
48688- fscache_stat(&fscache_n_object_no_alloc);
48689+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
48690 ret = PTR_ERR(object);
48691 goto error;
48692 }
48693
48694- fscache_stat(&fscache_n_object_alloc);
48695+ fscache_stat_unchecked(&fscache_n_object_alloc);
48696
48697 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
48698
48699@@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
48700
48701 _enter("{%s}", cookie->def->name);
48702
48703- fscache_stat(&fscache_n_invalidates);
48704+ fscache_stat_unchecked(&fscache_n_invalidates);
48705
48706 /* Only permit invalidation of data files. Invalidating an index will
48707 * require the caller to release all its attachments to the tree rooted
48708@@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
48709 struct fscache_object *object;
48710 struct hlist_node *_p;
48711
48712- fscache_stat(&fscache_n_updates);
48713+ fscache_stat_unchecked(&fscache_n_updates);
48714
48715 if (!cookie) {
48716- fscache_stat(&fscache_n_updates_null);
48717+ fscache_stat_unchecked(&fscache_n_updates_null);
48718 _leave(" [no cookie]");
48719 return;
48720 }
48721@@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48722 struct fscache_object *object;
48723 unsigned long event;
48724
48725- fscache_stat(&fscache_n_relinquishes);
48726+ fscache_stat_unchecked(&fscache_n_relinquishes);
48727 if (retire)
48728- fscache_stat(&fscache_n_relinquishes_retire);
48729+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
48730
48731 if (!cookie) {
48732- fscache_stat(&fscache_n_relinquishes_null);
48733+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
48734 _leave(" [no cookie]");
48735 return;
48736 }
48737@@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48738
48739 /* wait for the cookie to finish being instantiated (or to fail) */
48740 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
48741- fscache_stat(&fscache_n_relinquishes_waitcrt);
48742+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
48743 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
48744 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
48745 }
48746diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
48747index ee38fef..0a326d4 100644
48748--- a/fs/fscache/internal.h
48749+++ b/fs/fscache/internal.h
48750@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
48751 * stats.c
48752 */
48753 #ifdef CONFIG_FSCACHE_STATS
48754-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
48755-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
48756+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
48757+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
48758
48759-extern atomic_t fscache_n_op_pend;
48760-extern atomic_t fscache_n_op_run;
48761-extern atomic_t fscache_n_op_enqueue;
48762-extern atomic_t fscache_n_op_deferred_release;
48763-extern atomic_t fscache_n_op_release;
48764-extern atomic_t fscache_n_op_gc;
48765-extern atomic_t fscache_n_op_cancelled;
48766-extern atomic_t fscache_n_op_rejected;
48767+extern atomic_unchecked_t fscache_n_op_pend;
48768+extern atomic_unchecked_t fscache_n_op_run;
48769+extern atomic_unchecked_t fscache_n_op_enqueue;
48770+extern atomic_unchecked_t fscache_n_op_deferred_release;
48771+extern atomic_unchecked_t fscache_n_op_release;
48772+extern atomic_unchecked_t fscache_n_op_gc;
48773+extern atomic_unchecked_t fscache_n_op_cancelled;
48774+extern atomic_unchecked_t fscache_n_op_rejected;
48775
48776-extern atomic_t fscache_n_attr_changed;
48777-extern atomic_t fscache_n_attr_changed_ok;
48778-extern atomic_t fscache_n_attr_changed_nobufs;
48779-extern atomic_t fscache_n_attr_changed_nomem;
48780-extern atomic_t fscache_n_attr_changed_calls;
48781+extern atomic_unchecked_t fscache_n_attr_changed;
48782+extern atomic_unchecked_t fscache_n_attr_changed_ok;
48783+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
48784+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
48785+extern atomic_unchecked_t fscache_n_attr_changed_calls;
48786
48787-extern atomic_t fscache_n_allocs;
48788-extern atomic_t fscache_n_allocs_ok;
48789-extern atomic_t fscache_n_allocs_wait;
48790-extern atomic_t fscache_n_allocs_nobufs;
48791-extern atomic_t fscache_n_allocs_intr;
48792-extern atomic_t fscache_n_allocs_object_dead;
48793-extern atomic_t fscache_n_alloc_ops;
48794-extern atomic_t fscache_n_alloc_op_waits;
48795+extern atomic_unchecked_t fscache_n_allocs;
48796+extern atomic_unchecked_t fscache_n_allocs_ok;
48797+extern atomic_unchecked_t fscache_n_allocs_wait;
48798+extern atomic_unchecked_t fscache_n_allocs_nobufs;
48799+extern atomic_unchecked_t fscache_n_allocs_intr;
48800+extern atomic_unchecked_t fscache_n_allocs_object_dead;
48801+extern atomic_unchecked_t fscache_n_alloc_ops;
48802+extern atomic_unchecked_t fscache_n_alloc_op_waits;
48803
48804-extern atomic_t fscache_n_retrievals;
48805-extern atomic_t fscache_n_retrievals_ok;
48806-extern atomic_t fscache_n_retrievals_wait;
48807-extern atomic_t fscache_n_retrievals_nodata;
48808-extern atomic_t fscache_n_retrievals_nobufs;
48809-extern atomic_t fscache_n_retrievals_intr;
48810-extern atomic_t fscache_n_retrievals_nomem;
48811-extern atomic_t fscache_n_retrievals_object_dead;
48812-extern atomic_t fscache_n_retrieval_ops;
48813-extern atomic_t fscache_n_retrieval_op_waits;
48814+extern atomic_unchecked_t fscache_n_retrievals;
48815+extern atomic_unchecked_t fscache_n_retrievals_ok;
48816+extern atomic_unchecked_t fscache_n_retrievals_wait;
48817+extern atomic_unchecked_t fscache_n_retrievals_nodata;
48818+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
48819+extern atomic_unchecked_t fscache_n_retrievals_intr;
48820+extern atomic_unchecked_t fscache_n_retrievals_nomem;
48821+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
48822+extern atomic_unchecked_t fscache_n_retrieval_ops;
48823+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
48824
48825-extern atomic_t fscache_n_stores;
48826-extern atomic_t fscache_n_stores_ok;
48827-extern atomic_t fscache_n_stores_again;
48828-extern atomic_t fscache_n_stores_nobufs;
48829-extern atomic_t fscache_n_stores_oom;
48830-extern atomic_t fscache_n_store_ops;
48831-extern atomic_t fscache_n_store_calls;
48832-extern atomic_t fscache_n_store_pages;
48833-extern atomic_t fscache_n_store_radix_deletes;
48834-extern atomic_t fscache_n_store_pages_over_limit;
48835+extern atomic_unchecked_t fscache_n_stores;
48836+extern atomic_unchecked_t fscache_n_stores_ok;
48837+extern atomic_unchecked_t fscache_n_stores_again;
48838+extern atomic_unchecked_t fscache_n_stores_nobufs;
48839+extern atomic_unchecked_t fscache_n_stores_oom;
48840+extern atomic_unchecked_t fscache_n_store_ops;
48841+extern atomic_unchecked_t fscache_n_store_calls;
48842+extern atomic_unchecked_t fscache_n_store_pages;
48843+extern atomic_unchecked_t fscache_n_store_radix_deletes;
48844+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
48845
48846-extern atomic_t fscache_n_store_vmscan_not_storing;
48847-extern atomic_t fscache_n_store_vmscan_gone;
48848-extern atomic_t fscache_n_store_vmscan_busy;
48849-extern atomic_t fscache_n_store_vmscan_cancelled;
48850-extern atomic_t fscache_n_store_vmscan_wait;
48851+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48852+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
48853+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
48854+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48855+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
48856
48857-extern atomic_t fscache_n_marks;
48858-extern atomic_t fscache_n_uncaches;
48859+extern atomic_unchecked_t fscache_n_marks;
48860+extern atomic_unchecked_t fscache_n_uncaches;
48861
48862-extern atomic_t fscache_n_acquires;
48863-extern atomic_t fscache_n_acquires_null;
48864-extern atomic_t fscache_n_acquires_no_cache;
48865-extern atomic_t fscache_n_acquires_ok;
48866-extern atomic_t fscache_n_acquires_nobufs;
48867-extern atomic_t fscache_n_acquires_oom;
48868+extern atomic_unchecked_t fscache_n_acquires;
48869+extern atomic_unchecked_t fscache_n_acquires_null;
48870+extern atomic_unchecked_t fscache_n_acquires_no_cache;
48871+extern atomic_unchecked_t fscache_n_acquires_ok;
48872+extern atomic_unchecked_t fscache_n_acquires_nobufs;
48873+extern atomic_unchecked_t fscache_n_acquires_oom;
48874
48875-extern atomic_t fscache_n_invalidates;
48876-extern atomic_t fscache_n_invalidates_run;
48877+extern atomic_unchecked_t fscache_n_invalidates;
48878+extern atomic_unchecked_t fscache_n_invalidates_run;
48879
48880-extern atomic_t fscache_n_updates;
48881-extern atomic_t fscache_n_updates_null;
48882-extern atomic_t fscache_n_updates_run;
48883+extern atomic_unchecked_t fscache_n_updates;
48884+extern atomic_unchecked_t fscache_n_updates_null;
48885+extern atomic_unchecked_t fscache_n_updates_run;
48886
48887-extern atomic_t fscache_n_relinquishes;
48888-extern atomic_t fscache_n_relinquishes_null;
48889-extern atomic_t fscache_n_relinquishes_waitcrt;
48890-extern atomic_t fscache_n_relinquishes_retire;
48891+extern atomic_unchecked_t fscache_n_relinquishes;
48892+extern atomic_unchecked_t fscache_n_relinquishes_null;
48893+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
48894+extern atomic_unchecked_t fscache_n_relinquishes_retire;
48895
48896-extern atomic_t fscache_n_cookie_index;
48897-extern atomic_t fscache_n_cookie_data;
48898-extern atomic_t fscache_n_cookie_special;
48899+extern atomic_unchecked_t fscache_n_cookie_index;
48900+extern atomic_unchecked_t fscache_n_cookie_data;
48901+extern atomic_unchecked_t fscache_n_cookie_special;
48902
48903-extern atomic_t fscache_n_object_alloc;
48904-extern atomic_t fscache_n_object_no_alloc;
48905-extern atomic_t fscache_n_object_lookups;
48906-extern atomic_t fscache_n_object_lookups_negative;
48907-extern atomic_t fscache_n_object_lookups_positive;
48908-extern atomic_t fscache_n_object_lookups_timed_out;
48909-extern atomic_t fscache_n_object_created;
48910-extern atomic_t fscache_n_object_avail;
48911-extern atomic_t fscache_n_object_dead;
48912+extern atomic_unchecked_t fscache_n_object_alloc;
48913+extern atomic_unchecked_t fscache_n_object_no_alloc;
48914+extern atomic_unchecked_t fscache_n_object_lookups;
48915+extern atomic_unchecked_t fscache_n_object_lookups_negative;
48916+extern atomic_unchecked_t fscache_n_object_lookups_positive;
48917+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
48918+extern atomic_unchecked_t fscache_n_object_created;
48919+extern atomic_unchecked_t fscache_n_object_avail;
48920+extern atomic_unchecked_t fscache_n_object_dead;
48921
48922-extern atomic_t fscache_n_checkaux_none;
48923-extern atomic_t fscache_n_checkaux_okay;
48924-extern atomic_t fscache_n_checkaux_update;
48925-extern atomic_t fscache_n_checkaux_obsolete;
48926+extern atomic_unchecked_t fscache_n_checkaux_none;
48927+extern atomic_unchecked_t fscache_n_checkaux_okay;
48928+extern atomic_unchecked_t fscache_n_checkaux_update;
48929+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
48930
48931 extern atomic_t fscache_n_cop_alloc_object;
48932 extern atomic_t fscache_n_cop_lookup_object;
48933@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
48934 atomic_inc(stat);
48935 }
48936
48937+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
48938+{
48939+ atomic_inc_unchecked(stat);
48940+}
48941+
48942 static inline void fscache_stat_d(atomic_t *stat)
48943 {
48944 atomic_dec(stat);
48945@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
48946
48947 #define __fscache_stat(stat) (NULL)
48948 #define fscache_stat(stat) do {} while (0)
48949+#define fscache_stat_unchecked(stat) do {} while (0)
48950 #define fscache_stat_d(stat) do {} while (0)
48951 #endif
48952
48953diff --git a/fs/fscache/object.c b/fs/fscache/object.c
48954index 50d41c1..10ee117 100644
48955--- a/fs/fscache/object.c
48956+++ b/fs/fscache/object.c
48957@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48958 /* Invalidate an object on disk */
48959 case FSCACHE_OBJECT_INVALIDATING:
48960 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
48961- fscache_stat(&fscache_n_invalidates_run);
48962+ fscache_stat_unchecked(&fscache_n_invalidates_run);
48963 fscache_stat(&fscache_n_cop_invalidate_object);
48964 fscache_invalidate_object(object);
48965 fscache_stat_d(&fscache_n_cop_invalidate_object);
48966@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48967 /* update the object metadata on disk */
48968 case FSCACHE_OBJECT_UPDATING:
48969 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
48970- fscache_stat(&fscache_n_updates_run);
48971+ fscache_stat_unchecked(&fscache_n_updates_run);
48972 fscache_stat(&fscache_n_cop_update_object);
48973 object->cache->ops->update_object(object);
48974 fscache_stat_d(&fscache_n_cop_update_object);
48975@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48976 spin_lock(&object->lock);
48977 object->state = FSCACHE_OBJECT_DEAD;
48978 spin_unlock(&object->lock);
48979- fscache_stat(&fscache_n_object_dead);
48980+ fscache_stat_unchecked(&fscache_n_object_dead);
48981 goto terminal_transit;
48982
48983 /* handle the parent cache of this object being withdrawn from
48984@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48985 spin_lock(&object->lock);
48986 object->state = FSCACHE_OBJECT_DEAD;
48987 spin_unlock(&object->lock);
48988- fscache_stat(&fscache_n_object_dead);
48989+ fscache_stat_unchecked(&fscache_n_object_dead);
48990 goto terminal_transit;
48991
48992 /* complain about the object being woken up once it is
48993@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
48994 parent->cookie->def->name, cookie->def->name,
48995 object->cache->tag->name);
48996
48997- fscache_stat(&fscache_n_object_lookups);
48998+ fscache_stat_unchecked(&fscache_n_object_lookups);
48999 fscache_stat(&fscache_n_cop_lookup_object);
49000 ret = object->cache->ops->lookup_object(object);
49001 fscache_stat_d(&fscache_n_cop_lookup_object);
49002@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
49003 if (ret == -ETIMEDOUT) {
49004 /* probably stuck behind another object, so move this one to
49005 * the back of the queue */
49006- fscache_stat(&fscache_n_object_lookups_timed_out);
49007+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
49008 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49009 }
49010
49011@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
49012
49013 spin_lock(&object->lock);
49014 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49015- fscache_stat(&fscache_n_object_lookups_negative);
49016+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
49017
49018 /* transit here to allow write requests to begin stacking up
49019 * and read requests to begin returning ENODATA */
49020@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
49021 * result, in which case there may be data available */
49022 spin_lock(&object->lock);
49023 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49024- fscache_stat(&fscache_n_object_lookups_positive);
49025+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
49026
49027 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
49028
49029@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
49030 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49031 } else {
49032 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
49033- fscache_stat(&fscache_n_object_created);
49034+ fscache_stat_unchecked(&fscache_n_object_created);
49035
49036 object->state = FSCACHE_OBJECT_AVAILABLE;
49037 spin_unlock(&object->lock);
49038@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
49039 fscache_enqueue_dependents(object);
49040
49041 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
49042- fscache_stat(&fscache_n_object_avail);
49043+ fscache_stat_unchecked(&fscache_n_object_avail);
49044
49045 _leave("");
49046 }
49047@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49048 enum fscache_checkaux result;
49049
49050 if (!object->cookie->def->check_aux) {
49051- fscache_stat(&fscache_n_checkaux_none);
49052+ fscache_stat_unchecked(&fscache_n_checkaux_none);
49053 return FSCACHE_CHECKAUX_OKAY;
49054 }
49055
49056@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49057 switch (result) {
49058 /* entry okay as is */
49059 case FSCACHE_CHECKAUX_OKAY:
49060- fscache_stat(&fscache_n_checkaux_okay);
49061+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
49062 break;
49063
49064 /* entry requires update */
49065 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
49066- fscache_stat(&fscache_n_checkaux_update);
49067+ fscache_stat_unchecked(&fscache_n_checkaux_update);
49068 break;
49069
49070 /* entry requires deletion */
49071 case FSCACHE_CHECKAUX_OBSOLETE:
49072- fscache_stat(&fscache_n_checkaux_obsolete);
49073+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
49074 break;
49075
49076 default:
49077diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
49078index 762a9ec..2023284 100644
49079--- a/fs/fscache/operation.c
49080+++ b/fs/fscache/operation.c
49081@@ -17,7 +17,7 @@
49082 #include <linux/slab.h>
49083 #include "internal.h"
49084
49085-atomic_t fscache_op_debug_id;
49086+atomic_unchecked_t fscache_op_debug_id;
49087 EXPORT_SYMBOL(fscache_op_debug_id);
49088
49089 /**
49090@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
49091 ASSERTCMP(atomic_read(&op->usage), >, 0);
49092 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
49093
49094- fscache_stat(&fscache_n_op_enqueue);
49095+ fscache_stat_unchecked(&fscache_n_op_enqueue);
49096 switch (op->flags & FSCACHE_OP_TYPE) {
49097 case FSCACHE_OP_ASYNC:
49098 _debug("queue async");
49099@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
49100 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
49101 if (op->processor)
49102 fscache_enqueue_operation(op);
49103- fscache_stat(&fscache_n_op_run);
49104+ fscache_stat_unchecked(&fscache_n_op_run);
49105 }
49106
49107 /*
49108@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49109 if (object->n_in_progress > 0) {
49110 atomic_inc(&op->usage);
49111 list_add_tail(&op->pend_link, &object->pending_ops);
49112- fscache_stat(&fscache_n_op_pend);
49113+ fscache_stat_unchecked(&fscache_n_op_pend);
49114 } else if (!list_empty(&object->pending_ops)) {
49115 atomic_inc(&op->usage);
49116 list_add_tail(&op->pend_link, &object->pending_ops);
49117- fscache_stat(&fscache_n_op_pend);
49118+ fscache_stat_unchecked(&fscache_n_op_pend);
49119 fscache_start_operations(object);
49120 } else {
49121 ASSERTCMP(object->n_in_progress, ==, 0);
49122@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49123 object->n_exclusive++; /* reads and writes must wait */
49124 atomic_inc(&op->usage);
49125 list_add_tail(&op->pend_link, &object->pending_ops);
49126- fscache_stat(&fscache_n_op_pend);
49127+ fscache_stat_unchecked(&fscache_n_op_pend);
49128 ret = 0;
49129 } else {
49130 /* If we're in any other state, there must have been an I/O
49131@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
49132 if (object->n_exclusive > 0) {
49133 atomic_inc(&op->usage);
49134 list_add_tail(&op->pend_link, &object->pending_ops);
49135- fscache_stat(&fscache_n_op_pend);
49136+ fscache_stat_unchecked(&fscache_n_op_pend);
49137 } else if (!list_empty(&object->pending_ops)) {
49138 atomic_inc(&op->usage);
49139 list_add_tail(&op->pend_link, &object->pending_ops);
49140- fscache_stat(&fscache_n_op_pend);
49141+ fscache_stat_unchecked(&fscache_n_op_pend);
49142 fscache_start_operations(object);
49143 } else {
49144 ASSERTCMP(object->n_exclusive, ==, 0);
49145@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
49146 object->n_ops++;
49147 atomic_inc(&op->usage);
49148 list_add_tail(&op->pend_link, &object->pending_ops);
49149- fscache_stat(&fscache_n_op_pend);
49150+ fscache_stat_unchecked(&fscache_n_op_pend);
49151 ret = 0;
49152 } else if (object->state == FSCACHE_OBJECT_DYING ||
49153 object->state == FSCACHE_OBJECT_LC_DYING ||
49154 object->state == FSCACHE_OBJECT_WITHDRAWING) {
49155- fscache_stat(&fscache_n_op_rejected);
49156+ fscache_stat_unchecked(&fscache_n_op_rejected);
49157 op->state = FSCACHE_OP_ST_CANCELLED;
49158 ret = -ENOBUFS;
49159 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
49160@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
49161 ret = -EBUSY;
49162 if (op->state == FSCACHE_OP_ST_PENDING) {
49163 ASSERT(!list_empty(&op->pend_link));
49164- fscache_stat(&fscache_n_op_cancelled);
49165+ fscache_stat_unchecked(&fscache_n_op_cancelled);
49166 list_del_init(&op->pend_link);
49167 if (do_cancel)
49168 do_cancel(op);
49169@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
49170 while (!list_empty(&object->pending_ops)) {
49171 op = list_entry(object->pending_ops.next,
49172 struct fscache_operation, pend_link);
49173- fscache_stat(&fscache_n_op_cancelled);
49174+ fscache_stat_unchecked(&fscache_n_op_cancelled);
49175 list_del_init(&op->pend_link);
49176
49177 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
49178@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
49179 op->state, ==, FSCACHE_OP_ST_CANCELLED);
49180 op->state = FSCACHE_OP_ST_DEAD;
49181
49182- fscache_stat(&fscache_n_op_release);
49183+ fscache_stat_unchecked(&fscache_n_op_release);
49184
49185 if (op->release) {
49186 op->release(op);
49187@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
49188 * lock, and defer it otherwise */
49189 if (!spin_trylock(&object->lock)) {
49190 _debug("defer put");
49191- fscache_stat(&fscache_n_op_deferred_release);
49192+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
49193
49194 cache = object->cache;
49195 spin_lock(&cache->op_gc_list_lock);
49196@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
49197
49198 _debug("GC DEFERRED REL OBJ%x OP%x",
49199 object->debug_id, op->debug_id);
49200- fscache_stat(&fscache_n_op_gc);
49201+ fscache_stat_unchecked(&fscache_n_op_gc);
49202
49203 ASSERTCMP(atomic_read(&op->usage), ==, 0);
49204 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
49205diff --git a/fs/fscache/page.c b/fs/fscache/page.c
49206index ff000e5..c44ec6d 100644
49207--- a/fs/fscache/page.c
49208+++ b/fs/fscache/page.c
49209@@ -61,7 +61,7 @@ try_again:
49210 val = radix_tree_lookup(&cookie->stores, page->index);
49211 if (!val) {
49212 rcu_read_unlock();
49213- fscache_stat(&fscache_n_store_vmscan_not_storing);
49214+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
49215 __fscache_uncache_page(cookie, page);
49216 return true;
49217 }
49218@@ -91,11 +91,11 @@ try_again:
49219 spin_unlock(&cookie->stores_lock);
49220
49221 if (xpage) {
49222- fscache_stat(&fscache_n_store_vmscan_cancelled);
49223- fscache_stat(&fscache_n_store_radix_deletes);
49224+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
49225+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49226 ASSERTCMP(xpage, ==, page);
49227 } else {
49228- fscache_stat(&fscache_n_store_vmscan_gone);
49229+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
49230 }
49231
49232 wake_up_bit(&cookie->flags, 0);
49233@@ -110,11 +110,11 @@ page_busy:
49234 * sleeping on memory allocation, so we may need to impose a timeout
49235 * too. */
49236 if (!(gfp & __GFP_WAIT)) {
49237- fscache_stat(&fscache_n_store_vmscan_busy);
49238+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
49239 return false;
49240 }
49241
49242- fscache_stat(&fscache_n_store_vmscan_wait);
49243+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
49244 __fscache_wait_on_page_write(cookie, page);
49245 gfp &= ~__GFP_WAIT;
49246 goto try_again;
49247@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
49248 FSCACHE_COOKIE_STORING_TAG);
49249 if (!radix_tree_tag_get(&cookie->stores, page->index,
49250 FSCACHE_COOKIE_PENDING_TAG)) {
49251- fscache_stat(&fscache_n_store_radix_deletes);
49252+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49253 xpage = radix_tree_delete(&cookie->stores, page->index);
49254 }
49255 spin_unlock(&cookie->stores_lock);
49256@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
49257
49258 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
49259
49260- fscache_stat(&fscache_n_attr_changed_calls);
49261+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
49262
49263 if (fscache_object_is_active(object)) {
49264 fscache_stat(&fscache_n_cop_attr_changed);
49265@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49266
49267 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49268
49269- fscache_stat(&fscache_n_attr_changed);
49270+ fscache_stat_unchecked(&fscache_n_attr_changed);
49271
49272 op = kzalloc(sizeof(*op), GFP_KERNEL);
49273 if (!op) {
49274- fscache_stat(&fscache_n_attr_changed_nomem);
49275+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
49276 _leave(" = -ENOMEM");
49277 return -ENOMEM;
49278 }
49279@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49280 if (fscache_submit_exclusive_op(object, op) < 0)
49281 goto nobufs;
49282 spin_unlock(&cookie->lock);
49283- fscache_stat(&fscache_n_attr_changed_ok);
49284+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
49285 fscache_put_operation(op);
49286 _leave(" = 0");
49287 return 0;
49288@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49289 nobufs:
49290 spin_unlock(&cookie->lock);
49291 kfree(op);
49292- fscache_stat(&fscache_n_attr_changed_nobufs);
49293+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
49294 _leave(" = %d", -ENOBUFS);
49295 return -ENOBUFS;
49296 }
49297@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
49298 /* allocate a retrieval operation and attempt to submit it */
49299 op = kzalloc(sizeof(*op), GFP_NOIO);
49300 if (!op) {
49301- fscache_stat(&fscache_n_retrievals_nomem);
49302+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49303 return NULL;
49304 }
49305
49306@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
49307 return 0;
49308 }
49309
49310- fscache_stat(&fscache_n_retrievals_wait);
49311+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
49312
49313 jif = jiffies;
49314 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
49315 fscache_wait_bit_interruptible,
49316 TASK_INTERRUPTIBLE) != 0) {
49317- fscache_stat(&fscache_n_retrievals_intr);
49318+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
49319 _leave(" = -ERESTARTSYS");
49320 return -ERESTARTSYS;
49321 }
49322@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
49323 */
49324 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49325 struct fscache_retrieval *op,
49326- atomic_t *stat_op_waits,
49327- atomic_t *stat_object_dead)
49328+ atomic_unchecked_t *stat_op_waits,
49329+ atomic_unchecked_t *stat_object_dead)
49330 {
49331 int ret;
49332
49333@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49334 goto check_if_dead;
49335
49336 _debug(">>> WT");
49337- fscache_stat(stat_op_waits);
49338+ fscache_stat_unchecked(stat_op_waits);
49339 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
49340 fscache_wait_bit_interruptible,
49341 TASK_INTERRUPTIBLE) != 0) {
49342@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49343
49344 check_if_dead:
49345 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
49346- fscache_stat(stat_object_dead);
49347+ fscache_stat_unchecked(stat_object_dead);
49348 _leave(" = -ENOBUFS [cancelled]");
49349 return -ENOBUFS;
49350 }
49351 if (unlikely(fscache_object_is_dead(object))) {
49352 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
49353 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
49354- fscache_stat(stat_object_dead);
49355+ fscache_stat_unchecked(stat_object_dead);
49356 return -ENOBUFS;
49357 }
49358 return 0;
49359@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49360
49361 _enter("%p,%p,,,", cookie, page);
49362
49363- fscache_stat(&fscache_n_retrievals);
49364+ fscache_stat_unchecked(&fscache_n_retrievals);
49365
49366 if (hlist_empty(&cookie->backing_objects))
49367 goto nobufs;
49368@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49369 goto nobufs_unlock_dec;
49370 spin_unlock(&cookie->lock);
49371
49372- fscache_stat(&fscache_n_retrieval_ops);
49373+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
49374
49375 /* pin the netfs read context in case we need to do the actual netfs
49376 * read because we've encountered a cache read failure */
49377@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49378
49379 error:
49380 if (ret == -ENOMEM)
49381- fscache_stat(&fscache_n_retrievals_nomem);
49382+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49383 else if (ret == -ERESTARTSYS)
49384- fscache_stat(&fscache_n_retrievals_intr);
49385+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
49386 else if (ret == -ENODATA)
49387- fscache_stat(&fscache_n_retrievals_nodata);
49388+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
49389 else if (ret < 0)
49390- fscache_stat(&fscache_n_retrievals_nobufs);
49391+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49392 else
49393- fscache_stat(&fscache_n_retrievals_ok);
49394+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
49395
49396 fscache_put_retrieval(op);
49397 _leave(" = %d", ret);
49398@@ -467,7 +467,7 @@ nobufs_unlock:
49399 spin_unlock(&cookie->lock);
49400 kfree(op);
49401 nobufs:
49402- fscache_stat(&fscache_n_retrievals_nobufs);
49403+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49404 _leave(" = -ENOBUFS");
49405 return -ENOBUFS;
49406 }
49407@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49408
49409 _enter("%p,,%d,,,", cookie, *nr_pages);
49410
49411- fscache_stat(&fscache_n_retrievals);
49412+ fscache_stat_unchecked(&fscache_n_retrievals);
49413
49414 if (hlist_empty(&cookie->backing_objects))
49415 goto nobufs;
49416@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49417 goto nobufs_unlock_dec;
49418 spin_unlock(&cookie->lock);
49419
49420- fscache_stat(&fscache_n_retrieval_ops);
49421+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
49422
49423 /* pin the netfs read context in case we need to do the actual netfs
49424 * read because we've encountered a cache read failure */
49425@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49426
49427 error:
49428 if (ret == -ENOMEM)
49429- fscache_stat(&fscache_n_retrievals_nomem);
49430+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49431 else if (ret == -ERESTARTSYS)
49432- fscache_stat(&fscache_n_retrievals_intr);
49433+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
49434 else if (ret == -ENODATA)
49435- fscache_stat(&fscache_n_retrievals_nodata);
49436+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
49437 else if (ret < 0)
49438- fscache_stat(&fscache_n_retrievals_nobufs);
49439+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49440 else
49441- fscache_stat(&fscache_n_retrievals_ok);
49442+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
49443
49444 fscache_put_retrieval(op);
49445 _leave(" = %d", ret);
49446@@ -591,7 +591,7 @@ nobufs_unlock:
49447 spin_unlock(&cookie->lock);
49448 kfree(op);
49449 nobufs:
49450- fscache_stat(&fscache_n_retrievals_nobufs);
49451+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49452 _leave(" = -ENOBUFS");
49453 return -ENOBUFS;
49454 }
49455@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49456
49457 _enter("%p,%p,,,", cookie, page);
49458
49459- fscache_stat(&fscache_n_allocs);
49460+ fscache_stat_unchecked(&fscache_n_allocs);
49461
49462 if (hlist_empty(&cookie->backing_objects))
49463 goto nobufs;
49464@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49465 goto nobufs_unlock;
49466 spin_unlock(&cookie->lock);
49467
49468- fscache_stat(&fscache_n_alloc_ops);
49469+ fscache_stat_unchecked(&fscache_n_alloc_ops);
49470
49471 ret = fscache_wait_for_retrieval_activation(
49472 object, op,
49473@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49474
49475 error:
49476 if (ret == -ERESTARTSYS)
49477- fscache_stat(&fscache_n_allocs_intr);
49478+ fscache_stat_unchecked(&fscache_n_allocs_intr);
49479 else if (ret < 0)
49480- fscache_stat(&fscache_n_allocs_nobufs);
49481+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
49482 else
49483- fscache_stat(&fscache_n_allocs_ok);
49484+ fscache_stat_unchecked(&fscache_n_allocs_ok);
49485
49486 fscache_put_retrieval(op);
49487 _leave(" = %d", ret);
49488@@ -677,7 +677,7 @@ nobufs_unlock:
49489 spin_unlock(&cookie->lock);
49490 kfree(op);
49491 nobufs:
49492- fscache_stat(&fscache_n_allocs_nobufs);
49493+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
49494 _leave(" = -ENOBUFS");
49495 return -ENOBUFS;
49496 }
49497@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49498
49499 spin_lock(&cookie->stores_lock);
49500
49501- fscache_stat(&fscache_n_store_calls);
49502+ fscache_stat_unchecked(&fscache_n_store_calls);
49503
49504 /* find a page to store */
49505 page = NULL;
49506@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49507 page = results[0];
49508 _debug("gang %d [%lx]", n, page->index);
49509 if (page->index > op->store_limit) {
49510- fscache_stat(&fscache_n_store_pages_over_limit);
49511+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
49512 goto superseded;
49513 }
49514
49515@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49516 spin_unlock(&cookie->stores_lock);
49517 spin_unlock(&object->lock);
49518
49519- fscache_stat(&fscache_n_store_pages);
49520+ fscache_stat_unchecked(&fscache_n_store_pages);
49521 fscache_stat(&fscache_n_cop_write_page);
49522 ret = object->cache->ops->write_page(op, page);
49523 fscache_stat_d(&fscache_n_cop_write_page);
49524@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49525 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49526 ASSERT(PageFsCache(page));
49527
49528- fscache_stat(&fscache_n_stores);
49529+ fscache_stat_unchecked(&fscache_n_stores);
49530
49531 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
49532 _leave(" = -ENOBUFS [invalidating]");
49533@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49534 spin_unlock(&cookie->stores_lock);
49535 spin_unlock(&object->lock);
49536
49537- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
49538+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
49539 op->store_limit = object->store_limit;
49540
49541 if (fscache_submit_op(object, &op->op) < 0)
49542@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49543
49544 spin_unlock(&cookie->lock);
49545 radix_tree_preload_end();
49546- fscache_stat(&fscache_n_store_ops);
49547- fscache_stat(&fscache_n_stores_ok);
49548+ fscache_stat_unchecked(&fscache_n_store_ops);
49549+ fscache_stat_unchecked(&fscache_n_stores_ok);
49550
49551 /* the work queue now carries its own ref on the object */
49552 fscache_put_operation(&op->op);
49553@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49554 return 0;
49555
49556 already_queued:
49557- fscache_stat(&fscache_n_stores_again);
49558+ fscache_stat_unchecked(&fscache_n_stores_again);
49559 already_pending:
49560 spin_unlock(&cookie->stores_lock);
49561 spin_unlock(&object->lock);
49562 spin_unlock(&cookie->lock);
49563 radix_tree_preload_end();
49564 kfree(op);
49565- fscache_stat(&fscache_n_stores_ok);
49566+ fscache_stat_unchecked(&fscache_n_stores_ok);
49567 _leave(" = 0");
49568 return 0;
49569
49570@@ -959,14 +959,14 @@ nobufs:
49571 spin_unlock(&cookie->lock);
49572 radix_tree_preload_end();
49573 kfree(op);
49574- fscache_stat(&fscache_n_stores_nobufs);
49575+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
49576 _leave(" = -ENOBUFS");
49577 return -ENOBUFS;
49578
49579 nomem_free:
49580 kfree(op);
49581 nomem:
49582- fscache_stat(&fscache_n_stores_oom);
49583+ fscache_stat_unchecked(&fscache_n_stores_oom);
49584 _leave(" = -ENOMEM");
49585 return -ENOMEM;
49586 }
49587@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
49588 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49589 ASSERTCMP(page, !=, NULL);
49590
49591- fscache_stat(&fscache_n_uncaches);
49592+ fscache_stat_unchecked(&fscache_n_uncaches);
49593
49594 /* cache withdrawal may beat us to it */
49595 if (!PageFsCache(page))
49596@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
49597 struct fscache_cookie *cookie = op->op.object->cookie;
49598
49599 #ifdef CONFIG_FSCACHE_STATS
49600- atomic_inc(&fscache_n_marks);
49601+ atomic_inc_unchecked(&fscache_n_marks);
49602 #endif
49603
49604 _debug("- mark %p{%lx}", page, page->index);
49605diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
49606index 8179e8b..5072cc7 100644
49607--- a/fs/fscache/stats.c
49608+++ b/fs/fscache/stats.c
49609@@ -18,99 +18,99 @@
49610 /*
49611 * operation counters
49612 */
49613-atomic_t fscache_n_op_pend;
49614-atomic_t fscache_n_op_run;
49615-atomic_t fscache_n_op_enqueue;
49616-atomic_t fscache_n_op_requeue;
49617-atomic_t fscache_n_op_deferred_release;
49618-atomic_t fscache_n_op_release;
49619-atomic_t fscache_n_op_gc;
49620-atomic_t fscache_n_op_cancelled;
49621-atomic_t fscache_n_op_rejected;
49622+atomic_unchecked_t fscache_n_op_pend;
49623+atomic_unchecked_t fscache_n_op_run;
49624+atomic_unchecked_t fscache_n_op_enqueue;
49625+atomic_unchecked_t fscache_n_op_requeue;
49626+atomic_unchecked_t fscache_n_op_deferred_release;
49627+atomic_unchecked_t fscache_n_op_release;
49628+atomic_unchecked_t fscache_n_op_gc;
49629+atomic_unchecked_t fscache_n_op_cancelled;
49630+atomic_unchecked_t fscache_n_op_rejected;
49631
49632-atomic_t fscache_n_attr_changed;
49633-atomic_t fscache_n_attr_changed_ok;
49634-atomic_t fscache_n_attr_changed_nobufs;
49635-atomic_t fscache_n_attr_changed_nomem;
49636-atomic_t fscache_n_attr_changed_calls;
49637+atomic_unchecked_t fscache_n_attr_changed;
49638+atomic_unchecked_t fscache_n_attr_changed_ok;
49639+atomic_unchecked_t fscache_n_attr_changed_nobufs;
49640+atomic_unchecked_t fscache_n_attr_changed_nomem;
49641+atomic_unchecked_t fscache_n_attr_changed_calls;
49642
49643-atomic_t fscache_n_allocs;
49644-atomic_t fscache_n_allocs_ok;
49645-atomic_t fscache_n_allocs_wait;
49646-atomic_t fscache_n_allocs_nobufs;
49647-atomic_t fscache_n_allocs_intr;
49648-atomic_t fscache_n_allocs_object_dead;
49649-atomic_t fscache_n_alloc_ops;
49650-atomic_t fscache_n_alloc_op_waits;
49651+atomic_unchecked_t fscache_n_allocs;
49652+atomic_unchecked_t fscache_n_allocs_ok;
49653+atomic_unchecked_t fscache_n_allocs_wait;
49654+atomic_unchecked_t fscache_n_allocs_nobufs;
49655+atomic_unchecked_t fscache_n_allocs_intr;
49656+atomic_unchecked_t fscache_n_allocs_object_dead;
49657+atomic_unchecked_t fscache_n_alloc_ops;
49658+atomic_unchecked_t fscache_n_alloc_op_waits;
49659
49660-atomic_t fscache_n_retrievals;
49661-atomic_t fscache_n_retrievals_ok;
49662-atomic_t fscache_n_retrievals_wait;
49663-atomic_t fscache_n_retrievals_nodata;
49664-atomic_t fscache_n_retrievals_nobufs;
49665-atomic_t fscache_n_retrievals_intr;
49666-atomic_t fscache_n_retrievals_nomem;
49667-atomic_t fscache_n_retrievals_object_dead;
49668-atomic_t fscache_n_retrieval_ops;
49669-atomic_t fscache_n_retrieval_op_waits;
49670+atomic_unchecked_t fscache_n_retrievals;
49671+atomic_unchecked_t fscache_n_retrievals_ok;
49672+atomic_unchecked_t fscache_n_retrievals_wait;
49673+atomic_unchecked_t fscache_n_retrievals_nodata;
49674+atomic_unchecked_t fscache_n_retrievals_nobufs;
49675+atomic_unchecked_t fscache_n_retrievals_intr;
49676+atomic_unchecked_t fscache_n_retrievals_nomem;
49677+atomic_unchecked_t fscache_n_retrievals_object_dead;
49678+atomic_unchecked_t fscache_n_retrieval_ops;
49679+atomic_unchecked_t fscache_n_retrieval_op_waits;
49680
49681-atomic_t fscache_n_stores;
49682-atomic_t fscache_n_stores_ok;
49683-atomic_t fscache_n_stores_again;
49684-atomic_t fscache_n_stores_nobufs;
49685-atomic_t fscache_n_stores_oom;
49686-atomic_t fscache_n_store_ops;
49687-atomic_t fscache_n_store_calls;
49688-atomic_t fscache_n_store_pages;
49689-atomic_t fscache_n_store_radix_deletes;
49690-atomic_t fscache_n_store_pages_over_limit;
49691+atomic_unchecked_t fscache_n_stores;
49692+atomic_unchecked_t fscache_n_stores_ok;
49693+atomic_unchecked_t fscache_n_stores_again;
49694+atomic_unchecked_t fscache_n_stores_nobufs;
49695+atomic_unchecked_t fscache_n_stores_oom;
49696+atomic_unchecked_t fscache_n_store_ops;
49697+atomic_unchecked_t fscache_n_store_calls;
49698+atomic_unchecked_t fscache_n_store_pages;
49699+atomic_unchecked_t fscache_n_store_radix_deletes;
49700+atomic_unchecked_t fscache_n_store_pages_over_limit;
49701
49702-atomic_t fscache_n_store_vmscan_not_storing;
49703-atomic_t fscache_n_store_vmscan_gone;
49704-atomic_t fscache_n_store_vmscan_busy;
49705-atomic_t fscache_n_store_vmscan_cancelled;
49706-atomic_t fscache_n_store_vmscan_wait;
49707+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
49708+atomic_unchecked_t fscache_n_store_vmscan_gone;
49709+atomic_unchecked_t fscache_n_store_vmscan_busy;
49710+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
49711+atomic_unchecked_t fscache_n_store_vmscan_wait;
49712
49713-atomic_t fscache_n_marks;
49714-atomic_t fscache_n_uncaches;
49715+atomic_unchecked_t fscache_n_marks;
49716+atomic_unchecked_t fscache_n_uncaches;
49717
49718-atomic_t fscache_n_acquires;
49719-atomic_t fscache_n_acquires_null;
49720-atomic_t fscache_n_acquires_no_cache;
49721-atomic_t fscache_n_acquires_ok;
49722-atomic_t fscache_n_acquires_nobufs;
49723-atomic_t fscache_n_acquires_oom;
49724+atomic_unchecked_t fscache_n_acquires;
49725+atomic_unchecked_t fscache_n_acquires_null;
49726+atomic_unchecked_t fscache_n_acquires_no_cache;
49727+atomic_unchecked_t fscache_n_acquires_ok;
49728+atomic_unchecked_t fscache_n_acquires_nobufs;
49729+atomic_unchecked_t fscache_n_acquires_oom;
49730
49731-atomic_t fscache_n_invalidates;
49732-atomic_t fscache_n_invalidates_run;
49733+atomic_unchecked_t fscache_n_invalidates;
49734+atomic_unchecked_t fscache_n_invalidates_run;
49735
49736-atomic_t fscache_n_updates;
49737-atomic_t fscache_n_updates_null;
49738-atomic_t fscache_n_updates_run;
49739+atomic_unchecked_t fscache_n_updates;
49740+atomic_unchecked_t fscache_n_updates_null;
49741+atomic_unchecked_t fscache_n_updates_run;
49742
49743-atomic_t fscache_n_relinquishes;
49744-atomic_t fscache_n_relinquishes_null;
49745-atomic_t fscache_n_relinquishes_waitcrt;
49746-atomic_t fscache_n_relinquishes_retire;
49747+atomic_unchecked_t fscache_n_relinquishes;
49748+atomic_unchecked_t fscache_n_relinquishes_null;
49749+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
49750+atomic_unchecked_t fscache_n_relinquishes_retire;
49751
49752-atomic_t fscache_n_cookie_index;
49753-atomic_t fscache_n_cookie_data;
49754-atomic_t fscache_n_cookie_special;
49755+atomic_unchecked_t fscache_n_cookie_index;
49756+atomic_unchecked_t fscache_n_cookie_data;
49757+atomic_unchecked_t fscache_n_cookie_special;
49758
49759-atomic_t fscache_n_object_alloc;
49760-atomic_t fscache_n_object_no_alloc;
49761-atomic_t fscache_n_object_lookups;
49762-atomic_t fscache_n_object_lookups_negative;
49763-atomic_t fscache_n_object_lookups_positive;
49764-atomic_t fscache_n_object_lookups_timed_out;
49765-atomic_t fscache_n_object_created;
49766-atomic_t fscache_n_object_avail;
49767-atomic_t fscache_n_object_dead;
49768+atomic_unchecked_t fscache_n_object_alloc;
49769+atomic_unchecked_t fscache_n_object_no_alloc;
49770+atomic_unchecked_t fscache_n_object_lookups;
49771+atomic_unchecked_t fscache_n_object_lookups_negative;
49772+atomic_unchecked_t fscache_n_object_lookups_positive;
49773+atomic_unchecked_t fscache_n_object_lookups_timed_out;
49774+atomic_unchecked_t fscache_n_object_created;
49775+atomic_unchecked_t fscache_n_object_avail;
49776+atomic_unchecked_t fscache_n_object_dead;
49777
49778-atomic_t fscache_n_checkaux_none;
49779-atomic_t fscache_n_checkaux_okay;
49780-atomic_t fscache_n_checkaux_update;
49781-atomic_t fscache_n_checkaux_obsolete;
49782+atomic_unchecked_t fscache_n_checkaux_none;
49783+atomic_unchecked_t fscache_n_checkaux_okay;
49784+atomic_unchecked_t fscache_n_checkaux_update;
49785+atomic_unchecked_t fscache_n_checkaux_obsolete;
49786
49787 atomic_t fscache_n_cop_alloc_object;
49788 atomic_t fscache_n_cop_lookup_object;
49789@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
49790 seq_puts(m, "FS-Cache statistics\n");
49791
49792 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
49793- atomic_read(&fscache_n_cookie_index),
49794- atomic_read(&fscache_n_cookie_data),
49795- atomic_read(&fscache_n_cookie_special));
49796+ atomic_read_unchecked(&fscache_n_cookie_index),
49797+ atomic_read_unchecked(&fscache_n_cookie_data),
49798+ atomic_read_unchecked(&fscache_n_cookie_special));
49799
49800 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
49801- atomic_read(&fscache_n_object_alloc),
49802- atomic_read(&fscache_n_object_no_alloc),
49803- atomic_read(&fscache_n_object_avail),
49804- atomic_read(&fscache_n_object_dead));
49805+ atomic_read_unchecked(&fscache_n_object_alloc),
49806+ atomic_read_unchecked(&fscache_n_object_no_alloc),
49807+ atomic_read_unchecked(&fscache_n_object_avail),
49808+ atomic_read_unchecked(&fscache_n_object_dead));
49809 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
49810- atomic_read(&fscache_n_checkaux_none),
49811- atomic_read(&fscache_n_checkaux_okay),
49812- atomic_read(&fscache_n_checkaux_update),
49813- atomic_read(&fscache_n_checkaux_obsolete));
49814+ atomic_read_unchecked(&fscache_n_checkaux_none),
49815+ atomic_read_unchecked(&fscache_n_checkaux_okay),
49816+ atomic_read_unchecked(&fscache_n_checkaux_update),
49817+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
49818
49819 seq_printf(m, "Pages : mrk=%u unc=%u\n",
49820- atomic_read(&fscache_n_marks),
49821- atomic_read(&fscache_n_uncaches));
49822+ atomic_read_unchecked(&fscache_n_marks),
49823+ atomic_read_unchecked(&fscache_n_uncaches));
49824
49825 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
49826 " oom=%u\n",
49827- atomic_read(&fscache_n_acquires),
49828- atomic_read(&fscache_n_acquires_null),
49829- atomic_read(&fscache_n_acquires_no_cache),
49830- atomic_read(&fscache_n_acquires_ok),
49831- atomic_read(&fscache_n_acquires_nobufs),
49832- atomic_read(&fscache_n_acquires_oom));
49833+ atomic_read_unchecked(&fscache_n_acquires),
49834+ atomic_read_unchecked(&fscache_n_acquires_null),
49835+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
49836+ atomic_read_unchecked(&fscache_n_acquires_ok),
49837+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
49838+ atomic_read_unchecked(&fscache_n_acquires_oom));
49839
49840 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
49841- atomic_read(&fscache_n_object_lookups),
49842- atomic_read(&fscache_n_object_lookups_negative),
49843- atomic_read(&fscache_n_object_lookups_positive),
49844- atomic_read(&fscache_n_object_created),
49845- atomic_read(&fscache_n_object_lookups_timed_out));
49846+ atomic_read_unchecked(&fscache_n_object_lookups),
49847+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
49848+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
49849+ atomic_read_unchecked(&fscache_n_object_created),
49850+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
49851
49852 seq_printf(m, "Invals : n=%u run=%u\n",
49853- atomic_read(&fscache_n_invalidates),
49854- atomic_read(&fscache_n_invalidates_run));
49855+ atomic_read_unchecked(&fscache_n_invalidates),
49856+ atomic_read_unchecked(&fscache_n_invalidates_run));
49857
49858 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
49859- atomic_read(&fscache_n_updates),
49860- atomic_read(&fscache_n_updates_null),
49861- atomic_read(&fscache_n_updates_run));
49862+ atomic_read_unchecked(&fscache_n_updates),
49863+ atomic_read_unchecked(&fscache_n_updates_null),
49864+ atomic_read_unchecked(&fscache_n_updates_run));
49865
49866 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
49867- atomic_read(&fscache_n_relinquishes),
49868- atomic_read(&fscache_n_relinquishes_null),
49869- atomic_read(&fscache_n_relinquishes_waitcrt),
49870- atomic_read(&fscache_n_relinquishes_retire));
49871+ atomic_read_unchecked(&fscache_n_relinquishes),
49872+ atomic_read_unchecked(&fscache_n_relinquishes_null),
49873+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
49874+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
49875
49876 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
49877- atomic_read(&fscache_n_attr_changed),
49878- atomic_read(&fscache_n_attr_changed_ok),
49879- atomic_read(&fscache_n_attr_changed_nobufs),
49880- atomic_read(&fscache_n_attr_changed_nomem),
49881- atomic_read(&fscache_n_attr_changed_calls));
49882+ atomic_read_unchecked(&fscache_n_attr_changed),
49883+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
49884+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
49885+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
49886+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
49887
49888 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
49889- atomic_read(&fscache_n_allocs),
49890- atomic_read(&fscache_n_allocs_ok),
49891- atomic_read(&fscache_n_allocs_wait),
49892- atomic_read(&fscache_n_allocs_nobufs),
49893- atomic_read(&fscache_n_allocs_intr));
49894+ atomic_read_unchecked(&fscache_n_allocs),
49895+ atomic_read_unchecked(&fscache_n_allocs_ok),
49896+ atomic_read_unchecked(&fscache_n_allocs_wait),
49897+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
49898+ atomic_read_unchecked(&fscache_n_allocs_intr));
49899 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
49900- atomic_read(&fscache_n_alloc_ops),
49901- atomic_read(&fscache_n_alloc_op_waits),
49902- atomic_read(&fscache_n_allocs_object_dead));
49903+ atomic_read_unchecked(&fscache_n_alloc_ops),
49904+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
49905+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
49906
49907 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
49908 " int=%u oom=%u\n",
49909- atomic_read(&fscache_n_retrievals),
49910- atomic_read(&fscache_n_retrievals_ok),
49911- atomic_read(&fscache_n_retrievals_wait),
49912- atomic_read(&fscache_n_retrievals_nodata),
49913- atomic_read(&fscache_n_retrievals_nobufs),
49914- atomic_read(&fscache_n_retrievals_intr),
49915- atomic_read(&fscache_n_retrievals_nomem));
49916+ atomic_read_unchecked(&fscache_n_retrievals),
49917+ atomic_read_unchecked(&fscache_n_retrievals_ok),
49918+ atomic_read_unchecked(&fscache_n_retrievals_wait),
49919+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
49920+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
49921+ atomic_read_unchecked(&fscache_n_retrievals_intr),
49922+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
49923 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
49924- atomic_read(&fscache_n_retrieval_ops),
49925- atomic_read(&fscache_n_retrieval_op_waits),
49926- atomic_read(&fscache_n_retrievals_object_dead));
49927+ atomic_read_unchecked(&fscache_n_retrieval_ops),
49928+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
49929+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
49930
49931 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
49932- atomic_read(&fscache_n_stores),
49933- atomic_read(&fscache_n_stores_ok),
49934- atomic_read(&fscache_n_stores_again),
49935- atomic_read(&fscache_n_stores_nobufs),
49936- atomic_read(&fscache_n_stores_oom));
49937+ atomic_read_unchecked(&fscache_n_stores),
49938+ atomic_read_unchecked(&fscache_n_stores_ok),
49939+ atomic_read_unchecked(&fscache_n_stores_again),
49940+ atomic_read_unchecked(&fscache_n_stores_nobufs),
49941+ atomic_read_unchecked(&fscache_n_stores_oom));
49942 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
49943- atomic_read(&fscache_n_store_ops),
49944- atomic_read(&fscache_n_store_calls),
49945- atomic_read(&fscache_n_store_pages),
49946- atomic_read(&fscache_n_store_radix_deletes),
49947- atomic_read(&fscache_n_store_pages_over_limit));
49948+ atomic_read_unchecked(&fscache_n_store_ops),
49949+ atomic_read_unchecked(&fscache_n_store_calls),
49950+ atomic_read_unchecked(&fscache_n_store_pages),
49951+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
49952+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
49953
49954 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
49955- atomic_read(&fscache_n_store_vmscan_not_storing),
49956- atomic_read(&fscache_n_store_vmscan_gone),
49957- atomic_read(&fscache_n_store_vmscan_busy),
49958- atomic_read(&fscache_n_store_vmscan_cancelled),
49959- atomic_read(&fscache_n_store_vmscan_wait));
49960+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
49961+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
49962+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
49963+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
49964+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
49965
49966 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
49967- atomic_read(&fscache_n_op_pend),
49968- atomic_read(&fscache_n_op_run),
49969- atomic_read(&fscache_n_op_enqueue),
49970- atomic_read(&fscache_n_op_cancelled),
49971- atomic_read(&fscache_n_op_rejected));
49972+ atomic_read_unchecked(&fscache_n_op_pend),
49973+ atomic_read_unchecked(&fscache_n_op_run),
49974+ atomic_read_unchecked(&fscache_n_op_enqueue),
49975+ atomic_read_unchecked(&fscache_n_op_cancelled),
49976+ atomic_read_unchecked(&fscache_n_op_rejected));
49977 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
49978- atomic_read(&fscache_n_op_deferred_release),
49979- atomic_read(&fscache_n_op_release),
49980- atomic_read(&fscache_n_op_gc));
49981+ atomic_read_unchecked(&fscache_n_op_deferred_release),
49982+ atomic_read_unchecked(&fscache_n_op_release),
49983+ atomic_read_unchecked(&fscache_n_op_gc));
49984
49985 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
49986 atomic_read(&fscache_n_cop_alloc_object),
49987diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
49988index e397b67..b0d8709 100644
49989--- a/fs/fuse/cuse.c
49990+++ b/fs/fuse/cuse.c
49991@@ -593,10 +593,12 @@ static int __init cuse_init(void)
49992 INIT_LIST_HEAD(&cuse_conntbl[i]);
49993
49994 /* inherit and extend fuse_dev_operations */
49995- cuse_channel_fops = fuse_dev_operations;
49996- cuse_channel_fops.owner = THIS_MODULE;
49997- cuse_channel_fops.open = cuse_channel_open;
49998- cuse_channel_fops.release = cuse_channel_release;
49999+ pax_open_kernel();
50000+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
50001+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
50002+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
50003+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
50004+ pax_close_kernel();
50005
50006 cuse_class = class_create(THIS_MODULE, "cuse");
50007 if (IS_ERR(cuse_class))
50008diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
50009index e83351a..41e3c9c 100644
50010--- a/fs/fuse/dev.c
50011+++ b/fs/fuse/dev.c
50012@@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
50013 ret = 0;
50014 pipe_lock(pipe);
50015
50016- if (!pipe->readers) {
50017+ if (!atomic_read(&pipe->readers)) {
50018 send_sig(SIGPIPE, current, 0);
50019 if (!ret)
50020 ret = -EPIPE;
50021diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
50022index b7c09f9..3eff736 100644
50023--- a/fs/fuse/dir.c
50024+++ b/fs/fuse/dir.c
50025@@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
50026 return link;
50027 }
50028
50029-static void free_link(char *link)
50030+static void free_link(const char *link)
50031 {
50032 if (!IS_ERR(link))
50033 free_page((unsigned long) link);
50034diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
50035index 2b6f569..fcb4d1f 100644
50036--- a/fs/gfs2/inode.c
50037+++ b/fs/gfs2/inode.c
50038@@ -1499,7 +1499,7 @@ out:
50039
50040 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
50041 {
50042- char *s = nd_get_link(nd);
50043+ const char *s = nd_get_link(nd);
50044 if (!IS_ERR(s))
50045 kfree(s);
50046 }
50047diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
50048index 78bde32..767e906 100644
50049--- a/fs/hugetlbfs/inode.c
50050+++ b/fs/hugetlbfs/inode.c
50051@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
50052 struct mm_struct *mm = current->mm;
50053 struct vm_area_struct *vma;
50054 struct hstate *h = hstate_file(file);
50055+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
50056 struct vm_unmapped_area_info info;
50057
50058 if (len & ~huge_page_mask(h))
50059@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
50060 return addr;
50061 }
50062
50063+#ifdef CONFIG_PAX_RANDMMAP
50064+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
50065+#endif
50066+
50067 if (addr) {
50068 addr = ALIGN(addr, huge_page_size(h));
50069 vma = find_vma(mm, addr);
50070- if (TASK_SIZE - len >= addr &&
50071- (!vma || addr + len <= vma->vm_start))
50072+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
50073 return addr;
50074 }
50075
50076 info.flags = 0;
50077 info.length = len;
50078 info.low_limit = TASK_UNMAPPED_BASE;
50079+
50080+#ifdef CONFIG_PAX_RANDMMAP
50081+ if (mm->pax_flags & MF_PAX_RANDMMAP)
50082+ info.low_limit += mm->delta_mmap;
50083+#endif
50084+
50085 info.high_limit = TASK_SIZE;
50086 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
50087 info.align_offset = 0;
50088@@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
50089 .kill_sb = kill_litter_super,
50090 };
50091
50092-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
50093+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
50094
50095 static int can_do_hugetlb_shm(void)
50096 {
50097diff --git a/fs/inode.c b/fs/inode.c
50098index 14084b7..29af1d9 100644
50099--- a/fs/inode.c
50100+++ b/fs/inode.c
50101@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
50102
50103 #ifdef CONFIG_SMP
50104 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
50105- static atomic_t shared_last_ino;
50106- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
50107+ static atomic_unchecked_t shared_last_ino;
50108+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
50109
50110 res = next - LAST_INO_BATCH;
50111 }
50112diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
50113index 4a6cf28..d3a29d3 100644
50114--- a/fs/jffs2/erase.c
50115+++ b/fs/jffs2/erase.c
50116@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
50117 struct jffs2_unknown_node marker = {
50118 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
50119 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50120- .totlen = cpu_to_je32(c->cleanmarker_size)
50121+ .totlen = cpu_to_je32(c->cleanmarker_size),
50122+ .hdr_crc = cpu_to_je32(0)
50123 };
50124
50125 jffs2_prealloc_raw_node_refs(c, jeb, 1);
50126diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
50127index a6597d6..41b30ec 100644
50128--- a/fs/jffs2/wbuf.c
50129+++ b/fs/jffs2/wbuf.c
50130@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
50131 {
50132 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
50133 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50134- .totlen = constant_cpu_to_je32(8)
50135+ .totlen = constant_cpu_to_je32(8),
50136+ .hdr_crc = constant_cpu_to_je32(0)
50137 };
50138
50139 /*
50140diff --git a/fs/jfs/super.c b/fs/jfs/super.c
50141index 1a543be..d803c40 100644
50142--- a/fs/jfs/super.c
50143+++ b/fs/jfs/super.c
50144@@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
50145
50146 jfs_inode_cachep =
50147 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
50148- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
50149+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
50150 init_once);
50151 if (jfs_inode_cachep == NULL)
50152 return -ENOMEM;
50153diff --git a/fs/libfs.c b/fs/libfs.c
50154index 916da8c..1588998 100644
50155--- a/fs/libfs.c
50156+++ b/fs/libfs.c
50157@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
50158
50159 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
50160 struct dentry *next;
50161+ char d_name[sizeof(next->d_iname)];
50162+ const unsigned char *name;
50163+
50164 next = list_entry(p, struct dentry, d_u.d_child);
50165 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
50166 if (!simple_positive(next)) {
50167@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
50168
50169 spin_unlock(&next->d_lock);
50170 spin_unlock(&dentry->d_lock);
50171- if (filldir(dirent, next->d_name.name,
50172+ name = next->d_name.name;
50173+ if (name == next->d_iname) {
50174+ memcpy(d_name, name, next->d_name.len);
50175+ name = d_name;
50176+ }
50177+ if (filldir(dirent, name,
50178 next->d_name.len, filp->f_pos,
50179 next->d_inode->i_ino,
50180 dt_type(next->d_inode)) < 0)
50181diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
50182index 52e5120..808936e 100644
50183--- a/fs/lockd/clntproc.c
50184+++ b/fs/lockd/clntproc.c
50185@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
50186 /*
50187 * Cookie counter for NLM requests
50188 */
50189-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
50190+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
50191
50192 void nlmclnt_next_cookie(struct nlm_cookie *c)
50193 {
50194- u32 cookie = atomic_inc_return(&nlm_cookie);
50195+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
50196
50197 memcpy(c->data, &cookie, 4);
50198 c->len=4;
50199diff --git a/fs/locks.c b/fs/locks.c
50200index a94e331..060bce3 100644
50201--- a/fs/locks.c
50202+++ b/fs/locks.c
50203@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
50204 return;
50205
50206 if (filp->f_op && filp->f_op->flock) {
50207- struct file_lock fl = {
50208+ struct file_lock flock = {
50209 .fl_pid = current->tgid,
50210 .fl_file = filp,
50211 .fl_flags = FL_FLOCK,
50212 .fl_type = F_UNLCK,
50213 .fl_end = OFFSET_MAX,
50214 };
50215- filp->f_op->flock(filp, F_SETLKW, &fl);
50216- if (fl.fl_ops && fl.fl_ops->fl_release_private)
50217- fl.fl_ops->fl_release_private(&fl);
50218+ filp->f_op->flock(filp, F_SETLKW, &flock);
50219+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
50220+ flock.fl_ops->fl_release_private(&flock);
50221 }
50222
50223 lock_flocks();
50224diff --git a/fs/namei.c b/fs/namei.c
50225index 43a97ee..117e7e4 100644
50226--- a/fs/namei.c
50227+++ b/fs/namei.c
50228@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
50229 if (ret != -EACCES)
50230 return ret;
50231
50232+#ifdef CONFIG_GRKERNSEC
50233+ /* we'll block if we have to log due to a denied capability use */
50234+ if (mask & MAY_NOT_BLOCK)
50235+ return -ECHILD;
50236+#endif
50237+
50238 if (S_ISDIR(inode->i_mode)) {
50239 /* DACs are overridable for directories */
50240- if (inode_capable(inode, CAP_DAC_OVERRIDE))
50241- return 0;
50242 if (!(mask & MAY_WRITE))
50243- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
50244+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
50245+ inode_capable(inode, CAP_DAC_READ_SEARCH))
50246 return 0;
50247+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
50248+ return 0;
50249 return -EACCES;
50250 }
50251 /*
50252+ * Searching includes executable on directories, else just read.
50253+ */
50254+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
50255+ if (mask == MAY_READ)
50256+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
50257+ inode_capable(inode, CAP_DAC_READ_SEARCH))
50258+ return 0;
50259+
50260+ /*
50261 * Read/write DACs are always overridable.
50262 * Executable DACs are overridable when there is
50263 * at least one exec bit set.
50264@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
50265 if (inode_capable(inode, CAP_DAC_OVERRIDE))
50266 return 0;
50267
50268- /*
50269- * Searching includes executable on directories, else just read.
50270- */
50271- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
50272- if (mask == MAY_READ)
50273- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
50274- return 0;
50275-
50276 return -EACCES;
50277 }
50278
50279@@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
50280 {
50281 struct dentry *dentry = link->dentry;
50282 int error;
50283- char *s;
50284+ const char *s;
50285
50286 BUG_ON(nd->flags & LOOKUP_RCU);
50287
50288@@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
50289 if (error)
50290 goto out_put_nd_path;
50291
50292+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
50293+ dentry->d_inode, dentry, nd->path.mnt)) {
50294+ error = -EACCES;
50295+ goto out_put_nd_path;
50296+ }
50297+
50298 nd->last_type = LAST_BIND;
50299 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
50300 error = PTR_ERR(*p);
50301@@ -1596,6 +1610,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
50302 break;
50303 res = walk_component(nd, path, &nd->last,
50304 nd->last_type, LOOKUP_FOLLOW);
50305+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
50306+ res = -EACCES;
50307 put_link(nd, &link, cookie);
50308 } while (res > 0);
50309
50310@@ -1694,7 +1710,7 @@ EXPORT_SYMBOL(full_name_hash);
50311 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
50312 {
50313 unsigned long a, b, adata, bdata, mask, hash, len;
50314- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
50315+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
50316
50317 hash = a = 0;
50318 len = -sizeof(unsigned long);
50319@@ -1979,6 +1995,8 @@ static int path_lookupat(int dfd, const char *name,
50320 if (err)
50321 break;
50322 err = lookup_last(nd, &path);
50323+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
50324+ err = -EACCES;
50325 put_link(nd, &link, cookie);
50326 }
50327 }
50328@@ -1986,6 +2004,21 @@ static int path_lookupat(int dfd, const char *name,
50329 if (!err)
50330 err = complete_walk(nd);
50331
50332+ if (!(nd->flags & LOOKUP_PARENT)) {
50333+#ifdef CONFIG_GRKERNSEC
50334+ if (flags & LOOKUP_RCU) {
50335+ if (!err)
50336+ path_put(&nd->path);
50337+ err = -ECHILD;
50338+ } else
50339+#endif
50340+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50341+ if (!err)
50342+ path_put(&nd->path);
50343+ err = -ENOENT;
50344+ }
50345+ }
50346+
50347 if (!err && nd->flags & LOOKUP_DIRECTORY) {
50348 if (!nd->inode->i_op->lookup) {
50349 path_put(&nd->path);
50350@@ -2013,8 +2046,17 @@ static int filename_lookup(int dfd, struct filename *name,
50351 retval = path_lookupat(dfd, name->name,
50352 flags | LOOKUP_REVAL, nd);
50353
50354- if (likely(!retval))
50355+ if (likely(!retval)) {
50356+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
50357+#ifdef CONFIG_GRKERNSEC
50358+ if (flags & LOOKUP_RCU)
50359+ return -ECHILD;
50360+#endif
50361+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
50362+ return -ENOENT;
50363+ }
50364 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
50365+ }
50366 return retval;
50367 }
50368
50369@@ -2392,6 +2434,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
50370 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
50371 return -EPERM;
50372
50373+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
50374+ return -EPERM;
50375+ if (gr_handle_rawio(inode))
50376+ return -EPERM;
50377+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
50378+ return -EACCES;
50379+
50380 return 0;
50381 }
50382
50383@@ -2613,7 +2662,7 @@ looked_up:
50384 * cleared otherwise prior to returning.
50385 */
50386 static int lookup_open(struct nameidata *nd, struct path *path,
50387- struct file *file,
50388+ struct path *link, struct file *file,
50389 const struct open_flags *op,
50390 bool got_write, int *opened)
50391 {
50392@@ -2648,6 +2697,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
50393 /* Negative dentry, just create the file */
50394 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
50395 umode_t mode = op->mode;
50396+
50397+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
50398+ error = -EACCES;
50399+ goto out_dput;
50400+ }
50401+
50402+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
50403+ error = -EACCES;
50404+ goto out_dput;
50405+ }
50406+
50407 if (!IS_POSIXACL(dir->d_inode))
50408 mode &= ~current_umask();
50409 /*
50410@@ -2669,6 +2729,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
50411 nd->flags & LOOKUP_EXCL);
50412 if (error)
50413 goto out_dput;
50414+ else
50415+ gr_handle_create(dentry, nd->path.mnt);
50416 }
50417 out_no_open:
50418 path->dentry = dentry;
50419@@ -2683,7 +2745,7 @@ out_dput:
50420 /*
50421 * Handle the last step of open()
50422 */
50423-static int do_last(struct nameidata *nd, struct path *path,
50424+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
50425 struct file *file, const struct open_flags *op,
50426 int *opened, struct filename *name)
50427 {
50428@@ -2712,16 +2774,44 @@ static int do_last(struct nameidata *nd, struct path *path,
50429 error = complete_walk(nd);
50430 if (error)
50431 return error;
50432+#ifdef CONFIG_GRKERNSEC
50433+ if (nd->flags & LOOKUP_RCU) {
50434+ error = -ECHILD;
50435+ goto out;
50436+ }
50437+#endif
50438+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50439+ error = -ENOENT;
50440+ goto out;
50441+ }
50442 audit_inode(name, nd->path.dentry, 0);
50443 if (open_flag & O_CREAT) {
50444 error = -EISDIR;
50445 goto out;
50446 }
50447+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
50448+ error = -EACCES;
50449+ goto out;
50450+ }
50451 goto finish_open;
50452 case LAST_BIND:
50453 error = complete_walk(nd);
50454 if (error)
50455 return error;
50456+#ifdef CONFIG_GRKERNSEC
50457+ if (nd->flags & LOOKUP_RCU) {
50458+ error = -ECHILD;
50459+ goto out;
50460+ }
50461+#endif
50462+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
50463+ error = -ENOENT;
50464+ goto out;
50465+ }
50466+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
50467+ error = -EACCES;
50468+ goto out;
50469+ }
50470 audit_inode(name, dir, 0);
50471 goto finish_open;
50472 }
50473@@ -2770,7 +2860,7 @@ retry_lookup:
50474 */
50475 }
50476 mutex_lock(&dir->d_inode->i_mutex);
50477- error = lookup_open(nd, path, file, op, got_write, opened);
50478+ error = lookup_open(nd, path, link, file, op, got_write, opened);
50479 mutex_unlock(&dir->d_inode->i_mutex);
50480
50481 if (error <= 0) {
50482@@ -2794,11 +2884,28 @@ retry_lookup:
50483 goto finish_open_created;
50484 }
50485
50486+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
50487+ error = -ENOENT;
50488+ goto exit_dput;
50489+ }
50490+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
50491+ error = -EACCES;
50492+ goto exit_dput;
50493+ }
50494+
50495 /*
50496 * create/update audit record if it already exists.
50497 */
50498- if (path->dentry->d_inode)
50499+ if (path->dentry->d_inode) {
50500+ /* only check if O_CREAT is specified, all other checks need to go
50501+ into may_open */
50502+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
50503+ error = -EACCES;
50504+ goto exit_dput;
50505+ }
50506+
50507 audit_inode(name, path->dentry, 0);
50508+ }
50509
50510 /*
50511 * If atomic_open() acquired write access it is dropped now due to
50512@@ -2839,6 +2946,11 @@ finish_lookup:
50513 }
50514 }
50515 BUG_ON(inode != path->dentry->d_inode);
50516+ /* if we're resolving a symlink to another symlink */
50517+ if (link && gr_handle_symlink_owner(link, inode)) {
50518+ error = -EACCES;
50519+ goto out;
50520+ }
50521 return 1;
50522 }
50523
50524@@ -2848,7 +2960,6 @@ finish_lookup:
50525 save_parent.dentry = nd->path.dentry;
50526 save_parent.mnt = mntget(path->mnt);
50527 nd->path.dentry = path->dentry;
50528-
50529 }
50530 nd->inode = inode;
50531 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
50532@@ -2857,6 +2968,22 @@ finish_lookup:
50533 path_put(&save_parent);
50534 return error;
50535 }
50536+
50537+#ifdef CONFIG_GRKERNSEC
50538+ if (nd->flags & LOOKUP_RCU) {
50539+ error = -ECHILD;
50540+ goto out;
50541+ }
50542+#endif
50543+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50544+ error = -ENOENT;
50545+ goto out;
50546+ }
50547+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
50548+ error = -EACCES;
50549+ goto out;
50550+ }
50551+
50552 error = -EISDIR;
50553 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
50554 goto out;
50555@@ -2955,7 +3082,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
50556 if (unlikely(error))
50557 goto out;
50558
50559- error = do_last(nd, &path, file, op, &opened, pathname);
50560+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
50561 while (unlikely(error > 0)) { /* trailing symlink */
50562 struct path link = path;
50563 void *cookie;
50564@@ -2973,7 +3100,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
50565 error = follow_link(&link, nd, &cookie);
50566 if (unlikely(error))
50567 break;
50568- error = do_last(nd, &path, file, op, &opened, pathname);
50569+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
50570 put_link(nd, &link, cookie);
50571 }
50572 out:
50573@@ -3073,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
50574 goto unlock;
50575
50576 error = -EEXIST;
50577- if (dentry->d_inode)
50578+ if (dentry->d_inode) {
50579+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
50580+ error = -ENOENT;
50581+ }
50582 goto fail;
50583+ }
50584 /*
50585 * Special case - lookup gave negative, but... we had foo/bar/
50586 * From the vfs_mknod() POV we just have a negative dentry -
50587@@ -3126,6 +3257,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
50588 }
50589 EXPORT_SYMBOL(user_path_create);
50590
50591+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
50592+{
50593+ struct filename *tmp = getname(pathname);
50594+ struct dentry *res;
50595+ if (IS_ERR(tmp))
50596+ return ERR_CAST(tmp);
50597+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
50598+ if (IS_ERR(res))
50599+ putname(tmp);
50600+ else
50601+ *to = tmp;
50602+ return res;
50603+}
50604+
50605 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
50606 {
50607 int error = may_create(dir, dentry);
50608@@ -3188,6 +3333,17 @@ retry:
50609
50610 if (!IS_POSIXACL(path.dentry->d_inode))
50611 mode &= ~current_umask();
50612+
50613+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
50614+ error = -EPERM;
50615+ goto out;
50616+ }
50617+
50618+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
50619+ error = -EACCES;
50620+ goto out;
50621+ }
50622+
50623 error = security_path_mknod(&path, dentry, mode, dev);
50624 if (error)
50625 goto out;
50626@@ -3204,6 +3360,8 @@ retry:
50627 break;
50628 }
50629 out:
50630+ if (!error)
50631+ gr_handle_create(dentry, path.mnt);
50632 done_path_create(&path, dentry);
50633 if (retry_estale(error, lookup_flags)) {
50634 lookup_flags |= LOOKUP_REVAL;
50635@@ -3256,9 +3414,16 @@ retry:
50636
50637 if (!IS_POSIXACL(path.dentry->d_inode))
50638 mode &= ~current_umask();
50639+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
50640+ error = -EACCES;
50641+ goto out;
50642+ }
50643 error = security_path_mkdir(&path, dentry, mode);
50644 if (!error)
50645 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
50646+ if (!error)
50647+ gr_handle_create(dentry, path.mnt);
50648+out:
50649 done_path_create(&path, dentry);
50650 if (retry_estale(error, lookup_flags)) {
50651 lookup_flags |= LOOKUP_REVAL;
50652@@ -3339,6 +3504,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
50653 struct filename *name;
50654 struct dentry *dentry;
50655 struct nameidata nd;
50656+ ino_t saved_ino = 0;
50657+ dev_t saved_dev = 0;
50658 unsigned int lookup_flags = 0;
50659 retry:
50660 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
50661@@ -3371,10 +3538,21 @@ retry:
50662 error = -ENOENT;
50663 goto exit3;
50664 }
50665+
50666+ saved_ino = dentry->d_inode->i_ino;
50667+ saved_dev = gr_get_dev_from_dentry(dentry);
50668+
50669+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
50670+ error = -EACCES;
50671+ goto exit3;
50672+ }
50673+
50674 error = security_path_rmdir(&nd.path, dentry);
50675 if (error)
50676 goto exit3;
50677 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
50678+ if (!error && (saved_dev || saved_ino))
50679+ gr_handle_delete(saved_ino, saved_dev);
50680 exit3:
50681 dput(dentry);
50682 exit2:
50683@@ -3440,6 +3618,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
50684 struct dentry *dentry;
50685 struct nameidata nd;
50686 struct inode *inode = NULL;
50687+ ino_t saved_ino = 0;
50688+ dev_t saved_dev = 0;
50689 unsigned int lookup_flags = 0;
50690 retry:
50691 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
50692@@ -3466,10 +3646,22 @@ retry:
50693 if (!inode)
50694 goto slashes;
50695 ihold(inode);
50696+
50697+ if (inode->i_nlink <= 1) {
50698+ saved_ino = inode->i_ino;
50699+ saved_dev = gr_get_dev_from_dentry(dentry);
50700+ }
50701+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
50702+ error = -EACCES;
50703+ goto exit2;
50704+ }
50705+
50706 error = security_path_unlink(&nd.path, dentry);
50707 if (error)
50708 goto exit2;
50709 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
50710+ if (!error && (saved_ino || saved_dev))
50711+ gr_handle_delete(saved_ino, saved_dev);
50712 exit2:
50713 dput(dentry);
50714 }
50715@@ -3547,9 +3739,17 @@ retry:
50716 if (IS_ERR(dentry))
50717 goto out_putname;
50718
50719+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
50720+ error = -EACCES;
50721+ goto out;
50722+ }
50723+
50724 error = security_path_symlink(&path, dentry, from->name);
50725 if (!error)
50726 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
50727+ if (!error)
50728+ gr_handle_create(dentry, path.mnt);
50729+out:
50730 done_path_create(&path, dentry);
50731 if (retry_estale(error, lookup_flags)) {
50732 lookup_flags |= LOOKUP_REVAL;
50733@@ -3623,6 +3823,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
50734 {
50735 struct dentry *new_dentry;
50736 struct path old_path, new_path;
50737+ struct filename *to = NULL;
50738 int how = 0;
50739 int error;
50740
50741@@ -3646,7 +3847,7 @@ retry:
50742 if (error)
50743 return error;
50744
50745- new_dentry = user_path_create(newdfd, newname, &new_path,
50746+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
50747 (how & LOOKUP_REVAL));
50748 error = PTR_ERR(new_dentry);
50749 if (IS_ERR(new_dentry))
50750@@ -3658,11 +3859,28 @@ retry:
50751 error = may_linkat(&old_path);
50752 if (unlikely(error))
50753 goto out_dput;
50754+
50755+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
50756+ old_path.dentry->d_inode,
50757+ old_path.dentry->d_inode->i_mode, to)) {
50758+ error = -EACCES;
50759+ goto out_dput;
50760+ }
50761+
50762+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
50763+ old_path.dentry, old_path.mnt, to)) {
50764+ error = -EACCES;
50765+ goto out_dput;
50766+ }
50767+
50768 error = security_path_link(old_path.dentry, &new_path, new_dentry);
50769 if (error)
50770 goto out_dput;
50771 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
50772+ if (!error)
50773+ gr_handle_create(new_dentry, new_path.mnt);
50774 out_dput:
50775+ putname(to);
50776 done_path_create(&new_path, new_dentry);
50777 if (retry_estale(error, how)) {
50778 how |= LOOKUP_REVAL;
50779@@ -3908,12 +4126,21 @@ retry:
50780 if (new_dentry == trap)
50781 goto exit5;
50782
50783+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
50784+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
50785+ to);
50786+ if (error)
50787+ goto exit5;
50788+
50789 error = security_path_rename(&oldnd.path, old_dentry,
50790 &newnd.path, new_dentry);
50791 if (error)
50792 goto exit5;
50793 error = vfs_rename(old_dir->d_inode, old_dentry,
50794 new_dir->d_inode, new_dentry);
50795+ if (!error)
50796+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
50797+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
50798 exit5:
50799 dput(new_dentry);
50800 exit4:
50801@@ -3945,6 +4172,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
50802
50803 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
50804 {
50805+ char tmpbuf[64];
50806+ const char *newlink;
50807 int len;
50808
50809 len = PTR_ERR(link);
50810@@ -3954,7 +4183,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
50811 len = strlen(link);
50812 if (len > (unsigned) buflen)
50813 len = buflen;
50814- if (copy_to_user(buffer, link, len))
50815+
50816+ if (len < sizeof(tmpbuf)) {
50817+ memcpy(tmpbuf, link, len);
50818+ newlink = tmpbuf;
50819+ } else
50820+ newlink = link;
50821+
50822+ if (copy_to_user(buffer, newlink, len))
50823 len = -EFAULT;
50824 out:
50825 return len;
50826diff --git a/fs/namespace.c b/fs/namespace.c
50827index a51054f..f9b53e5 100644
50828--- a/fs/namespace.c
50829+++ b/fs/namespace.c
50830@@ -1215,6 +1215,9 @@ static int do_umount(struct mount *mnt, int flags)
50831 if (!(sb->s_flags & MS_RDONLY))
50832 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
50833 up_write(&sb->s_umount);
50834+
50835+ gr_log_remount(mnt->mnt_devname, retval);
50836+
50837 return retval;
50838 }
50839
50840@@ -1234,6 +1237,9 @@ static int do_umount(struct mount *mnt, int flags)
50841 br_write_unlock(&vfsmount_lock);
50842 up_write(&namespace_sem);
50843 release_mounts(&umount_list);
50844+
50845+ gr_log_unmount(mnt->mnt_devname, retval);
50846+
50847 return retval;
50848 }
50849
50850@@ -2287,6 +2293,16 @@ long do_mount(const char *dev_name, const char *dir_name,
50851 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
50852 MS_STRICTATIME);
50853
50854+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
50855+ retval = -EPERM;
50856+ goto dput_out;
50857+ }
50858+
50859+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
50860+ retval = -EPERM;
50861+ goto dput_out;
50862+ }
50863+
50864 if (flags & MS_REMOUNT)
50865 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
50866 data_page);
50867@@ -2301,6 +2317,9 @@ long do_mount(const char *dev_name, const char *dir_name,
50868 dev_name, data_page);
50869 dput_out:
50870 path_put(&path);
50871+
50872+ gr_log_mount(dev_name, dir_name, retval);
50873+
50874 return retval;
50875 }
50876
50877@@ -2587,6 +2606,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
50878 if (error)
50879 goto out2;
50880
50881+ if (gr_handle_chroot_pivot()) {
50882+ error = -EPERM;
50883+ goto out2;
50884+ }
50885+
50886 get_fs_root(current->fs, &root);
50887 error = lock_mount(&old);
50888 if (error)
50889@@ -2790,7 +2814,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
50890 !nsown_capable(CAP_SYS_ADMIN))
50891 return -EPERM;
50892
50893- if (fs->users != 1)
50894+ if (atomic_read(&fs->users) != 1)
50895 return -EINVAL;
50896
50897 get_mnt_ns(mnt_ns);
50898diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
50899index ebeb94c..ff35337 100644
50900--- a/fs/nfs/inode.c
50901+++ b/fs/nfs/inode.c
50902@@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
50903 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
50904 }
50905
50906-static atomic_long_t nfs_attr_generation_counter;
50907+static atomic_long_unchecked_t nfs_attr_generation_counter;
50908
50909 static unsigned long nfs_read_attr_generation_counter(void)
50910 {
50911- return atomic_long_read(&nfs_attr_generation_counter);
50912+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
50913 }
50914
50915 unsigned long nfs_inc_attr_generation_counter(void)
50916 {
50917- return atomic_long_inc_return(&nfs_attr_generation_counter);
50918+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
50919 }
50920
50921 void nfs_fattr_init(struct nfs_fattr *fattr)
50922diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
50923index d586117..143d568 100644
50924--- a/fs/nfsd/vfs.c
50925+++ b/fs/nfsd/vfs.c
50926@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
50927 } else {
50928 oldfs = get_fs();
50929 set_fs(KERNEL_DS);
50930- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
50931+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
50932 set_fs(oldfs);
50933 }
50934
50935@@ -1025,7 +1025,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
50936
50937 /* Write the data. */
50938 oldfs = get_fs(); set_fs(KERNEL_DS);
50939- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
50940+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
50941 set_fs(oldfs);
50942 if (host_err < 0)
50943 goto out_nfserr;
50944@@ -1571,7 +1571,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
50945 */
50946
50947 oldfs = get_fs(); set_fs(KERNEL_DS);
50948- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
50949+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
50950 set_fs(oldfs);
50951
50952 if (host_err < 0)
50953diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
50954index 9ff4a5e..deb1f0f 100644
50955--- a/fs/notify/fanotify/fanotify_user.c
50956+++ b/fs/notify/fanotify/fanotify_user.c
50957@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
50958
50959 fd = fanotify_event_metadata.fd;
50960 ret = -EFAULT;
50961- if (copy_to_user(buf, &fanotify_event_metadata,
50962- fanotify_event_metadata.event_len))
50963+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
50964+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
50965 goto out_close_fd;
50966
50967 ret = prepare_for_access_response(group, event, fd);
50968diff --git a/fs/notify/notification.c b/fs/notify/notification.c
50969index 7b51b05..5ea5ef6 100644
50970--- a/fs/notify/notification.c
50971+++ b/fs/notify/notification.c
50972@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
50973 * get set to 0 so it will never get 'freed'
50974 */
50975 static struct fsnotify_event *q_overflow_event;
50976-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50977+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50978
50979 /**
50980 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
50981@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50982 */
50983 u32 fsnotify_get_cookie(void)
50984 {
50985- return atomic_inc_return(&fsnotify_sync_cookie);
50986+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
50987 }
50988 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
50989
50990diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
50991index 99e3610..02c1068 100644
50992--- a/fs/ntfs/dir.c
50993+++ b/fs/ntfs/dir.c
50994@@ -1329,7 +1329,7 @@ find_next_index_buffer:
50995 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
50996 ~(s64)(ndir->itype.index.block_size - 1)));
50997 /* Bounds checks. */
50998- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
50999+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
51000 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
51001 "inode 0x%lx or driver bug.", vdir->i_ino);
51002 goto err_out;
51003diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
51004index 5b2d4f0..c6de396 100644
51005--- a/fs/ntfs/file.c
51006+++ b/fs/ntfs/file.c
51007@@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
51008 #endif /* NTFS_RW */
51009 };
51010
51011-const struct file_operations ntfs_empty_file_ops = {};
51012+const struct file_operations ntfs_empty_file_ops __read_only;
51013
51014-const struct inode_operations ntfs_empty_inode_ops = {};
51015+const struct inode_operations ntfs_empty_inode_ops __read_only;
51016diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
51017index a9f78c7..ed8a381 100644
51018--- a/fs/ocfs2/localalloc.c
51019+++ b/fs/ocfs2/localalloc.c
51020@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
51021 goto bail;
51022 }
51023
51024- atomic_inc(&osb->alloc_stats.moves);
51025+ atomic_inc_unchecked(&osb->alloc_stats.moves);
51026
51027 bail:
51028 if (handle)
51029diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
51030index d355e6e..578d905 100644
51031--- a/fs/ocfs2/ocfs2.h
51032+++ b/fs/ocfs2/ocfs2.h
51033@@ -235,11 +235,11 @@ enum ocfs2_vol_state
51034
51035 struct ocfs2_alloc_stats
51036 {
51037- atomic_t moves;
51038- atomic_t local_data;
51039- atomic_t bitmap_data;
51040- atomic_t bg_allocs;
51041- atomic_t bg_extends;
51042+ atomic_unchecked_t moves;
51043+ atomic_unchecked_t local_data;
51044+ atomic_unchecked_t bitmap_data;
51045+ atomic_unchecked_t bg_allocs;
51046+ atomic_unchecked_t bg_extends;
51047 };
51048
51049 enum ocfs2_local_alloc_state
51050diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
51051index f169da4..9112253 100644
51052--- a/fs/ocfs2/suballoc.c
51053+++ b/fs/ocfs2/suballoc.c
51054@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
51055 mlog_errno(status);
51056 goto bail;
51057 }
51058- atomic_inc(&osb->alloc_stats.bg_extends);
51059+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
51060
51061 /* You should never ask for this much metadata */
51062 BUG_ON(bits_wanted >
51063@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
51064 mlog_errno(status);
51065 goto bail;
51066 }
51067- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51068+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51069
51070 *suballoc_loc = res.sr_bg_blkno;
51071 *suballoc_bit_start = res.sr_bit_offset;
51072@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
51073 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
51074 res->sr_bits);
51075
51076- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51077+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51078
51079 BUG_ON(res->sr_bits != 1);
51080
51081@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
51082 mlog_errno(status);
51083 goto bail;
51084 }
51085- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51086+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51087
51088 BUG_ON(res.sr_bits != 1);
51089
51090@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
51091 cluster_start,
51092 num_clusters);
51093 if (!status)
51094- atomic_inc(&osb->alloc_stats.local_data);
51095+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
51096 } else {
51097 if (min_clusters > (osb->bitmap_cpg - 1)) {
51098 /* The only paths asking for contiguousness
51099@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
51100 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
51101 res.sr_bg_blkno,
51102 res.sr_bit_offset);
51103- atomic_inc(&osb->alloc_stats.bitmap_data);
51104+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
51105 *num_clusters = res.sr_bits;
51106 }
51107 }
51108diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
51109index 0e91ec2..f4b3fc6 100644
51110--- a/fs/ocfs2/super.c
51111+++ b/fs/ocfs2/super.c
51112@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
51113 "%10s => GlobalAllocs: %d LocalAllocs: %d "
51114 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
51115 "Stats",
51116- atomic_read(&osb->alloc_stats.bitmap_data),
51117- atomic_read(&osb->alloc_stats.local_data),
51118- atomic_read(&osb->alloc_stats.bg_allocs),
51119- atomic_read(&osb->alloc_stats.moves),
51120- atomic_read(&osb->alloc_stats.bg_extends));
51121+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
51122+ atomic_read_unchecked(&osb->alloc_stats.local_data),
51123+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
51124+ atomic_read_unchecked(&osb->alloc_stats.moves),
51125+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
51126
51127 out += snprintf(buf + out, len - out,
51128 "%10s => State: %u Descriptor: %llu Size: %u bits "
51129@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
51130 spin_lock_init(&osb->osb_xattr_lock);
51131 ocfs2_init_steal_slots(osb);
51132
51133- atomic_set(&osb->alloc_stats.moves, 0);
51134- atomic_set(&osb->alloc_stats.local_data, 0);
51135- atomic_set(&osb->alloc_stats.bitmap_data, 0);
51136- atomic_set(&osb->alloc_stats.bg_allocs, 0);
51137- atomic_set(&osb->alloc_stats.bg_extends, 0);
51138+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
51139+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
51140+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
51141+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
51142+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
51143
51144 /* Copy the blockcheck stats from the superblock probe */
51145 osb->osb_ecc_stats = *stats;
51146diff --git a/fs/open.c b/fs/open.c
51147index 9b33c0c..2ffcca2 100644
51148--- a/fs/open.c
51149+++ b/fs/open.c
51150@@ -31,6 +31,8 @@
51151 #include <linux/ima.h>
51152 #include <linux/dnotify.h>
51153
51154+#define CREATE_TRACE_POINTS
51155+#include <trace/events/fs.h>
51156 #include "internal.h"
51157
51158 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
51159@@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
51160 error = locks_verify_truncate(inode, NULL, length);
51161 if (!error)
51162 error = security_path_truncate(path);
51163+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
51164+ error = -EACCES;
51165 if (!error)
51166 error = do_truncate(path->dentry, length, 0, NULL);
51167
51168@@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
51169 error = locks_verify_truncate(inode, f.file, length);
51170 if (!error)
51171 error = security_path_truncate(&f.file->f_path);
51172+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
51173+ error = -EACCES;
51174 if (!error)
51175 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
51176 sb_end_write(inode->i_sb);
51177@@ -373,6 +379,9 @@ retry:
51178 if (__mnt_is_readonly(path.mnt))
51179 res = -EROFS;
51180
51181+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
51182+ res = -EACCES;
51183+
51184 out_path_release:
51185 path_put(&path);
51186 if (retry_estale(res, lookup_flags)) {
51187@@ -404,6 +413,8 @@ retry:
51188 if (error)
51189 goto dput_and_out;
51190
51191+ gr_log_chdir(path.dentry, path.mnt);
51192+
51193 set_fs_pwd(current->fs, &path);
51194
51195 dput_and_out:
51196@@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
51197 goto out_putf;
51198
51199 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
51200+
51201+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
51202+ error = -EPERM;
51203+
51204+ if (!error)
51205+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
51206+
51207 if (!error)
51208 set_fs_pwd(current->fs, &f.file->f_path);
51209 out_putf:
51210@@ -462,7 +480,13 @@ retry:
51211 if (error)
51212 goto dput_and_out;
51213
51214+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
51215+ goto dput_and_out;
51216+
51217 set_fs_root(current->fs, &path);
51218+
51219+ gr_handle_chroot_chdir(&path);
51220+
51221 error = 0;
51222 dput_and_out:
51223 path_put(&path);
51224@@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
51225 if (error)
51226 return error;
51227 mutex_lock(&inode->i_mutex);
51228+
51229+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
51230+ error = -EACCES;
51231+ goto out_unlock;
51232+ }
51233+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
51234+ error = -EACCES;
51235+ goto out_unlock;
51236+ }
51237+
51238 error = security_path_chmod(path, mode);
51239 if (error)
51240 goto out_unlock;
51241@@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
51242 uid = make_kuid(current_user_ns(), user);
51243 gid = make_kgid(current_user_ns(), group);
51244
51245+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
51246+ return -EACCES;
51247+
51248 newattrs.ia_valid = ATTR_CTIME;
51249 if (user != (uid_t) -1) {
51250 if (!uid_valid(uid))
51251@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
51252 } else {
51253 fsnotify_open(f);
51254 fd_install(fd, f);
51255+ trace_do_sys_open(tmp->name, flags, mode);
51256 }
51257 }
51258 putname(tmp);
51259diff --git a/fs/pipe.c b/fs/pipe.c
51260index bd3479d..fb92c4d 100644
51261--- a/fs/pipe.c
51262+++ b/fs/pipe.c
51263@@ -438,9 +438,9 @@ redo:
51264 }
51265 if (bufs) /* More to do? */
51266 continue;
51267- if (!pipe->writers)
51268+ if (!atomic_read(&pipe->writers))
51269 break;
51270- if (!pipe->waiting_writers) {
51271+ if (!atomic_read(&pipe->waiting_writers)) {
51272 /* syscall merging: Usually we must not sleep
51273 * if O_NONBLOCK is set, or if we got some data.
51274 * But if a writer sleeps in kernel space, then
51275@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
51276 mutex_lock(&inode->i_mutex);
51277 pipe = inode->i_pipe;
51278
51279- if (!pipe->readers) {
51280+ if (!atomic_read(&pipe->readers)) {
51281 send_sig(SIGPIPE, current, 0);
51282 ret = -EPIPE;
51283 goto out;
51284@@ -553,7 +553,7 @@ redo1:
51285 for (;;) {
51286 int bufs;
51287
51288- if (!pipe->readers) {
51289+ if (!atomic_read(&pipe->readers)) {
51290 send_sig(SIGPIPE, current, 0);
51291 if (!ret)
51292 ret = -EPIPE;
51293@@ -644,9 +644,9 @@ redo2:
51294 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
51295 do_wakeup = 0;
51296 }
51297- pipe->waiting_writers++;
51298+ atomic_inc(&pipe->waiting_writers);
51299 pipe_wait(pipe);
51300- pipe->waiting_writers--;
51301+ atomic_dec(&pipe->waiting_writers);
51302 }
51303 out:
51304 mutex_unlock(&inode->i_mutex);
51305@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
51306 mask = 0;
51307 if (filp->f_mode & FMODE_READ) {
51308 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
51309- if (!pipe->writers && filp->f_version != pipe->w_counter)
51310+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
51311 mask |= POLLHUP;
51312 }
51313
51314@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
51315 * Most Unices do not set POLLERR for FIFOs but on Linux they
51316 * behave exactly like pipes for poll().
51317 */
51318- if (!pipe->readers)
51319+ if (!atomic_read(&pipe->readers))
51320 mask |= POLLERR;
51321 }
51322
51323@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
51324
51325 mutex_lock(&inode->i_mutex);
51326 pipe = inode->i_pipe;
51327- pipe->readers -= decr;
51328- pipe->writers -= decw;
51329+ atomic_sub(decr, &pipe->readers);
51330+ atomic_sub(decw, &pipe->writers);
51331
51332- if (!pipe->readers && !pipe->writers) {
51333+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
51334 free_pipe_info(inode);
51335 } else {
51336 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
51337@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
51338
51339 if (inode->i_pipe) {
51340 ret = 0;
51341- inode->i_pipe->readers++;
51342+ atomic_inc(&inode->i_pipe->readers);
51343 }
51344
51345 mutex_unlock(&inode->i_mutex);
51346@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
51347
51348 if (inode->i_pipe) {
51349 ret = 0;
51350- inode->i_pipe->writers++;
51351+ atomic_inc(&inode->i_pipe->writers);
51352 }
51353
51354 mutex_unlock(&inode->i_mutex);
51355@@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
51356 if (inode->i_pipe) {
51357 ret = 0;
51358 if (filp->f_mode & FMODE_READ)
51359- inode->i_pipe->readers++;
51360+ atomic_inc(&inode->i_pipe->readers);
51361 if (filp->f_mode & FMODE_WRITE)
51362- inode->i_pipe->writers++;
51363+ atomic_inc(&inode->i_pipe->writers);
51364 }
51365
51366 mutex_unlock(&inode->i_mutex);
51367@@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
51368 inode->i_pipe = NULL;
51369 }
51370
51371-static struct vfsmount *pipe_mnt __read_mostly;
51372+struct vfsmount *pipe_mnt __read_mostly;
51373
51374 /*
51375 * pipefs_dname() is called from d_path().
51376@@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
51377 goto fail_iput;
51378 inode->i_pipe = pipe;
51379
51380- pipe->readers = pipe->writers = 1;
51381+ atomic_set(&pipe->readers, 1);
51382+ atomic_set(&pipe->writers, 1);
51383 inode->i_fop = &rdwr_pipefifo_fops;
51384
51385 /*
51386diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
51387index 15af622..0e9f4467 100644
51388--- a/fs/proc/Kconfig
51389+++ b/fs/proc/Kconfig
51390@@ -30,12 +30,12 @@ config PROC_FS
51391
51392 config PROC_KCORE
51393 bool "/proc/kcore support" if !ARM
51394- depends on PROC_FS && MMU
51395+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
51396
51397 config PROC_VMCORE
51398 bool "/proc/vmcore support"
51399- depends on PROC_FS && CRASH_DUMP
51400- default y
51401+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
51402+ default n
51403 help
51404 Exports the dump image of crashed kernel in ELF format.
51405
51406@@ -59,8 +59,8 @@ config PROC_SYSCTL
51407 limited in memory.
51408
51409 config PROC_PAGE_MONITOR
51410- default y
51411- depends on PROC_FS && MMU
51412+ default n
51413+ depends on PROC_FS && MMU && !GRKERNSEC
51414 bool "Enable /proc page monitoring" if EXPERT
51415 help
51416 Various /proc files exist to monitor process memory utilization:
51417diff --git a/fs/proc/array.c b/fs/proc/array.c
51418index 6a91e6f..e54dbc14 100644
51419--- a/fs/proc/array.c
51420+++ b/fs/proc/array.c
51421@@ -60,6 +60,7 @@
51422 #include <linux/tty.h>
51423 #include <linux/string.h>
51424 #include <linux/mman.h>
51425+#include <linux/grsecurity.h>
51426 #include <linux/proc_fs.h>
51427 #include <linux/ioport.h>
51428 #include <linux/uaccess.h>
51429@@ -362,6 +363,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
51430 seq_putc(m, '\n');
51431 }
51432
51433+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
51434+static inline void task_pax(struct seq_file *m, struct task_struct *p)
51435+{
51436+ if (p->mm)
51437+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
51438+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
51439+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
51440+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
51441+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
51442+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
51443+ else
51444+ seq_printf(m, "PaX:\t-----\n");
51445+}
51446+#endif
51447+
51448 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51449 struct pid *pid, struct task_struct *task)
51450 {
51451@@ -380,9 +396,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51452 task_cpus_allowed(m, task);
51453 cpuset_task_status_allowed(m, task);
51454 task_context_switch_counts(m, task);
51455+
51456+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
51457+ task_pax(m, task);
51458+#endif
51459+
51460+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
51461+ task_grsec_rbac(m, task);
51462+#endif
51463+
51464 return 0;
51465 }
51466
51467+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51468+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51469+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
51470+ _mm->pax_flags & MF_PAX_SEGMEXEC))
51471+#endif
51472+
51473 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51474 struct pid *pid, struct task_struct *task, int whole)
51475 {
51476@@ -404,6 +435,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51477 char tcomm[sizeof(task->comm)];
51478 unsigned long flags;
51479
51480+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51481+ if (current->exec_id != m->exec_id) {
51482+ gr_log_badprocpid("stat");
51483+ return 0;
51484+ }
51485+#endif
51486+
51487 state = *get_task_state(task);
51488 vsize = eip = esp = 0;
51489 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
51490@@ -475,6 +513,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51491 gtime = task->gtime;
51492 }
51493
51494+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51495+ if (PAX_RAND_FLAGS(mm)) {
51496+ eip = 0;
51497+ esp = 0;
51498+ wchan = 0;
51499+ }
51500+#endif
51501+#ifdef CONFIG_GRKERNSEC_HIDESYM
51502+ wchan = 0;
51503+ eip =0;
51504+ esp =0;
51505+#endif
51506+
51507 /* scale priority and nice values from timeslices to -20..20 */
51508 /* to make it look like a "normal" Unix priority/nice value */
51509 priority = task_prio(task);
51510@@ -511,9 +562,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51511 seq_put_decimal_ull(m, ' ', vsize);
51512 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
51513 seq_put_decimal_ull(m, ' ', rsslim);
51514+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51515+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
51516+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
51517+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
51518+#else
51519 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
51520 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
51521 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
51522+#endif
51523 seq_put_decimal_ull(m, ' ', esp);
51524 seq_put_decimal_ull(m, ' ', eip);
51525 /* The signal information here is obsolete.
51526@@ -535,7 +592,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51527 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
51528 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
51529
51530- if (mm && permitted) {
51531+ if (mm && permitted
51532+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51533+ && !PAX_RAND_FLAGS(mm)
51534+#endif
51535+ ) {
51536 seq_put_decimal_ull(m, ' ', mm->start_data);
51537 seq_put_decimal_ull(m, ' ', mm->end_data);
51538 seq_put_decimal_ull(m, ' ', mm->start_brk);
51539@@ -573,8 +634,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51540 struct pid *pid, struct task_struct *task)
51541 {
51542 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
51543- struct mm_struct *mm = get_task_mm(task);
51544+ struct mm_struct *mm;
51545
51546+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51547+ if (current->exec_id != m->exec_id) {
51548+ gr_log_badprocpid("statm");
51549+ return 0;
51550+ }
51551+#endif
51552+ mm = get_task_mm(task);
51553 if (mm) {
51554 size = task_statm(mm, &shared, &text, &data, &resident);
51555 mmput(mm);
51556@@ -597,6 +665,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51557 return 0;
51558 }
51559
51560+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51561+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
51562+{
51563+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
51564+}
51565+#endif
51566+
51567 #ifdef CONFIG_CHECKPOINT_RESTORE
51568 static struct pid *
51569 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
51570diff --git a/fs/proc/base.c b/fs/proc/base.c
51571index 9b43ff77..3d6a99f 100644
51572--- a/fs/proc/base.c
51573+++ b/fs/proc/base.c
51574@@ -111,6 +111,14 @@ struct pid_entry {
51575 union proc_op op;
51576 };
51577
51578+struct getdents_callback {
51579+ struct linux_dirent __user * current_dir;
51580+ struct linux_dirent __user * previous;
51581+ struct file * file;
51582+ int count;
51583+ int error;
51584+};
51585+
51586 #define NOD(NAME, MODE, IOP, FOP, OP) { \
51587 .name = (NAME), \
51588 .len = sizeof(NAME) - 1, \
51589@@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
51590 if (!mm->arg_end)
51591 goto out_mm; /* Shh! No looking before we're done */
51592
51593+ if (gr_acl_handle_procpidmem(task))
51594+ goto out_mm;
51595+
51596 len = mm->arg_end - mm->arg_start;
51597
51598 if (len > PAGE_SIZE)
51599@@ -235,12 +246,28 @@ out:
51600 return res;
51601 }
51602
51603+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51604+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51605+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
51606+ _mm->pax_flags & MF_PAX_SEGMEXEC))
51607+#endif
51608+
51609 static int proc_pid_auxv(struct task_struct *task, char *buffer)
51610 {
51611 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
51612 int res = PTR_ERR(mm);
51613 if (mm && !IS_ERR(mm)) {
51614 unsigned int nwords = 0;
51615+
51616+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51617+ /* allow if we're currently ptracing this task */
51618+ if (PAX_RAND_FLAGS(mm) &&
51619+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
51620+ mmput(mm);
51621+ return 0;
51622+ }
51623+#endif
51624+
51625 do {
51626 nwords += 2;
51627 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
51628@@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
51629 }
51630
51631
51632-#ifdef CONFIG_KALLSYMS
51633+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51634 /*
51635 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
51636 * Returns the resolved symbol. If that fails, simply return the address.
51637@@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
51638 mutex_unlock(&task->signal->cred_guard_mutex);
51639 }
51640
51641-#ifdef CONFIG_STACKTRACE
51642+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51643
51644 #define MAX_STACK_TRACE_DEPTH 64
51645
51646@@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
51647 return count;
51648 }
51649
51650-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51651+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51652 static int proc_pid_syscall(struct task_struct *task, char *buffer)
51653 {
51654 long nr;
51655@@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
51656 /************************************************************************/
51657
51658 /* permission checks */
51659-static int proc_fd_access_allowed(struct inode *inode)
51660+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
51661 {
51662 struct task_struct *task;
51663 int allowed = 0;
51664@@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
51665 */
51666 task = get_proc_task(inode);
51667 if (task) {
51668- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
51669+ if (log)
51670+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
51671+ else
51672+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
51673 put_task_struct(task);
51674 }
51675 return allowed;
51676@@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
51677 struct task_struct *task,
51678 int hide_pid_min)
51679 {
51680+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51681+ return false;
51682+
51683+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51684+ rcu_read_lock();
51685+ {
51686+ const struct cred *tmpcred = current_cred();
51687+ const struct cred *cred = __task_cred(task);
51688+
51689+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
51690+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51691+ || in_group_p(grsec_proc_gid)
51692+#endif
51693+ ) {
51694+ rcu_read_unlock();
51695+ return true;
51696+ }
51697+ }
51698+ rcu_read_unlock();
51699+
51700+ if (!pid->hide_pid)
51701+ return false;
51702+#endif
51703+
51704 if (pid->hide_pid < hide_pid_min)
51705 return true;
51706 if (in_group_p(pid->pid_gid))
51707 return true;
51708+
51709 return ptrace_may_access(task, PTRACE_MODE_READ);
51710 }
51711
51712@@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
51713 put_task_struct(task);
51714
51715 if (!has_perms) {
51716+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51717+ {
51718+#else
51719 if (pid->hide_pid == 2) {
51720+#endif
51721 /*
51722 * Let's make getdents(), stat(), and open()
51723 * consistent with each other. If a process
51724@@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
51725 if (!task)
51726 return -ESRCH;
51727
51728+ if (gr_acl_handle_procpidmem(task)) {
51729+ put_task_struct(task);
51730+ return -EPERM;
51731+ }
51732+
51733 mm = mm_access(task, mode);
51734 put_task_struct(task);
51735
51736@@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
51737
51738 file->private_data = mm;
51739
51740+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51741+ file->f_version = current->exec_id;
51742+#endif
51743+
51744 return 0;
51745 }
51746
51747@@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
51748 ssize_t copied;
51749 char *page;
51750
51751+#ifdef CONFIG_GRKERNSEC
51752+ if (write)
51753+ return -EPERM;
51754+#endif
51755+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51756+ if (file->f_version != current->exec_id) {
51757+ gr_log_badprocpid("mem");
51758+ return 0;
51759+ }
51760+#endif
51761+
51762 if (!mm)
51763 return 0;
51764
51765@@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
51766 if (!mm)
51767 return 0;
51768
51769+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51770+ if (file->f_version != current->exec_id) {
51771+ gr_log_badprocpid("environ");
51772+ return 0;
51773+ }
51774+#endif
51775+
51776 page = (char *)__get_free_page(GFP_TEMPORARY);
51777 if (!page)
51778 return -ENOMEM;
51779@@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
51780 int error = -EACCES;
51781
51782 /* Are we allowed to snoop on the tasks file descriptors? */
51783- if (!proc_fd_access_allowed(inode))
51784+ if (!proc_fd_access_allowed(inode, 0))
51785 goto out;
51786
51787 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51788@@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
51789 struct path path;
51790
51791 /* Are we allowed to snoop on the tasks file descriptors? */
51792- if (!proc_fd_access_allowed(inode))
51793- goto out;
51794+ /* logging this is needed for learning on chromium to work properly,
51795+ but we don't want to flood the logs from 'ps' which does a readlink
51796+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
51797+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
51798+ */
51799+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
51800+ if (!proc_fd_access_allowed(inode,0))
51801+ goto out;
51802+ } else {
51803+ if (!proc_fd_access_allowed(inode,1))
51804+ goto out;
51805+ }
51806
51807 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51808 if (error)
51809@@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
51810 rcu_read_lock();
51811 cred = __task_cred(task);
51812 inode->i_uid = cred->euid;
51813+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51814+ inode->i_gid = grsec_proc_gid;
51815+#else
51816 inode->i_gid = cred->egid;
51817+#endif
51818 rcu_read_unlock();
51819 }
51820 security_task_to_inode(task, inode);
51821@@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
51822 return -ENOENT;
51823 }
51824 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51825+#ifdef CONFIG_GRKERNSEC_PROC_USER
51826+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51827+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51828+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51829+#endif
51830 task_dumpable(task)) {
51831 cred = __task_cred(task);
51832 stat->uid = cred->euid;
51833+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51834+ stat->gid = grsec_proc_gid;
51835+#else
51836 stat->gid = cred->egid;
51837+#endif
51838 }
51839 }
51840 rcu_read_unlock();
51841@@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
51842
51843 if (task) {
51844 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51845+#ifdef CONFIG_GRKERNSEC_PROC_USER
51846+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51847+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51848+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51849+#endif
51850 task_dumpable(task)) {
51851 rcu_read_lock();
51852 cred = __task_cred(task);
51853 inode->i_uid = cred->euid;
51854+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51855+ inode->i_gid = grsec_proc_gid;
51856+#else
51857 inode->i_gid = cred->egid;
51858+#endif
51859 rcu_read_unlock();
51860 } else {
51861 inode->i_uid = GLOBAL_ROOT_UID;
51862@@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
51863 if (!task)
51864 goto out_no_task;
51865
51866+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51867+ goto out;
51868+
51869 /*
51870 * Yes, it does not scale. And it should not. Don't add
51871 * new entries into /proc/<tgid>/ without very good reasons.
51872@@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
51873 if (!task)
51874 goto out_no_task;
51875
51876+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51877+ goto out;
51878+
51879 ret = 0;
51880 i = filp->f_pos;
51881 switch (i) {
51882@@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
51883 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
51884 #endif
51885 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51886-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51887+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51888 INF("syscall", S_IRUGO, proc_pid_syscall),
51889 #endif
51890 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51891@@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
51892 #ifdef CONFIG_SECURITY
51893 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51894 #endif
51895-#ifdef CONFIG_KALLSYMS
51896+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51897 INF("wchan", S_IRUGO, proc_pid_wchan),
51898 #endif
51899-#ifdef CONFIG_STACKTRACE
51900+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51901 ONE("stack", S_IRUGO, proc_pid_stack),
51902 #endif
51903 #ifdef CONFIG_SCHEDSTATS
51904@@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
51905 #ifdef CONFIG_HARDWALL
51906 INF("hardwall", S_IRUGO, proc_pid_hardwall),
51907 #endif
51908+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51909+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
51910+#endif
51911 #ifdef CONFIG_USER_NS
51912 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
51913 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
51914@@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
51915 if (!inode)
51916 goto out;
51917
51918+#ifdef CONFIG_GRKERNSEC_PROC_USER
51919+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
51920+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51921+ inode->i_gid = grsec_proc_gid;
51922+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
51923+#else
51924 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
51925+#endif
51926 inode->i_op = &proc_tgid_base_inode_operations;
51927 inode->i_fop = &proc_tgid_base_operations;
51928 inode->i_flags|=S_IMMUTABLE;
51929@@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
51930 if (!task)
51931 goto out;
51932
51933+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51934+ goto out_put_task;
51935+
51936 result = proc_pid_instantiate(dir, dentry, task, NULL);
51937+out_put_task:
51938 put_task_struct(task);
51939 out:
51940 return result;
51941@@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
51942 static int fake_filldir(void *buf, const char *name, int namelen,
51943 loff_t offset, u64 ino, unsigned d_type)
51944 {
51945+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
51946+ __buf->error = -EINVAL;
51947 return 0;
51948 }
51949
51950@@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
51951 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
51952 #endif
51953 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51954-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51955+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51956 INF("syscall", S_IRUGO, proc_pid_syscall),
51957 #endif
51958 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51959@@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
51960 #ifdef CONFIG_SECURITY
51961 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51962 #endif
51963-#ifdef CONFIG_KALLSYMS
51964+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51965 INF("wchan", S_IRUGO, proc_pid_wchan),
51966 #endif
51967-#ifdef CONFIG_STACKTRACE
51968+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51969 ONE("stack", S_IRUGO, proc_pid_stack),
51970 #endif
51971 #ifdef CONFIG_SCHEDSTATS
51972diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
51973index 82676e3..5f8518a 100644
51974--- a/fs/proc/cmdline.c
51975+++ b/fs/proc/cmdline.c
51976@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
51977
51978 static int __init proc_cmdline_init(void)
51979 {
51980+#ifdef CONFIG_GRKERNSEC_PROC_ADD
51981+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
51982+#else
51983 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
51984+#endif
51985 return 0;
51986 }
51987 module_init(proc_cmdline_init);
51988diff --git a/fs/proc/devices.c b/fs/proc/devices.c
51989index b143471..bb105e5 100644
51990--- a/fs/proc/devices.c
51991+++ b/fs/proc/devices.c
51992@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
51993
51994 static int __init proc_devices_init(void)
51995 {
51996+#ifdef CONFIG_GRKERNSEC_PROC_ADD
51997+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
51998+#else
51999 proc_create("devices", 0, NULL, &proc_devinfo_operations);
52000+#endif
52001 return 0;
52002 }
52003 module_init(proc_devices_init);
52004diff --git a/fs/proc/fd.c b/fs/proc/fd.c
52005index d7a4a28..0201742 100644
52006--- a/fs/proc/fd.c
52007+++ b/fs/proc/fd.c
52008@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
52009 if (!task)
52010 return -ENOENT;
52011
52012- files = get_files_struct(task);
52013+ if (!gr_acl_handle_procpidmem(task))
52014+ files = get_files_struct(task);
52015 put_task_struct(task);
52016
52017 if (files) {
52018@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
52019 */
52020 int proc_fd_permission(struct inode *inode, int mask)
52021 {
52022+ struct task_struct *task;
52023 int rv = generic_permission(inode, mask);
52024- if (rv == 0)
52025- return 0;
52026+
52027 if (task_pid(current) == proc_pid(inode))
52028 rv = 0;
52029+
52030+ task = get_proc_task(inode);
52031+ if (task == NULL)
52032+ return rv;
52033+
52034+ if (gr_acl_handle_procpidmem(task))
52035+ rv = -EACCES;
52036+
52037+ put_task_struct(task);
52038+
52039 return rv;
52040 }
52041
52042diff --git a/fs/proc/inode.c b/fs/proc/inode.c
52043index 439ae688..c21ac36 100644
52044--- a/fs/proc/inode.c
52045+++ b/fs/proc/inode.c
52046@@ -21,11 +21,17 @@
52047 #include <linux/seq_file.h>
52048 #include <linux/slab.h>
52049 #include <linux/mount.h>
52050+#include <linux/grsecurity.h>
52051
52052 #include <asm/uaccess.h>
52053
52054 #include "internal.h"
52055
52056+#ifdef CONFIG_PROC_SYSCTL
52057+extern const struct inode_operations proc_sys_inode_operations;
52058+extern const struct inode_operations proc_sys_dir_operations;
52059+#endif
52060+
52061 static void proc_evict_inode(struct inode *inode)
52062 {
52063 struct proc_dir_entry *de;
52064@@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
52065 ns = PROC_I(inode)->ns;
52066 if (ns_ops && ns)
52067 ns_ops->put(ns);
52068+
52069+#ifdef CONFIG_PROC_SYSCTL
52070+ if (inode->i_op == &proc_sys_inode_operations ||
52071+ inode->i_op == &proc_sys_dir_operations)
52072+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
52073+#endif
52074+
52075 }
52076
52077 static struct kmem_cache * proc_inode_cachep;
52078@@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
52079 if (de->mode) {
52080 inode->i_mode = de->mode;
52081 inode->i_uid = de->uid;
52082+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52083+ inode->i_gid = grsec_proc_gid;
52084+#else
52085 inode->i_gid = de->gid;
52086+#endif
52087 }
52088 if (de->size)
52089 inode->i_size = de->size;
52090diff --git a/fs/proc/internal.h b/fs/proc/internal.h
52091index 252544c..04395b9 100644
52092--- a/fs/proc/internal.h
52093+++ b/fs/proc/internal.h
52094@@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52095 struct pid *pid, struct task_struct *task);
52096 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
52097 struct pid *pid, struct task_struct *task);
52098+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52099+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
52100+#endif
52101 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
52102
52103 extern const struct file_operations proc_tid_children_operations;
52104diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
52105index e96d4f1..8b116ed 100644
52106--- a/fs/proc/kcore.c
52107+++ b/fs/proc/kcore.c
52108@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52109 * the addresses in the elf_phdr on our list.
52110 */
52111 start = kc_offset_to_vaddr(*fpos - elf_buflen);
52112- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
52113+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
52114+ if (tsz > buflen)
52115 tsz = buflen;
52116-
52117+
52118 while (buflen) {
52119 struct kcore_list *m;
52120
52121@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52122 kfree(elf_buf);
52123 } else {
52124 if (kern_addr_valid(start)) {
52125- unsigned long n;
52126+ char *elf_buf;
52127+ mm_segment_t oldfs;
52128
52129- n = copy_to_user(buffer, (char *)start, tsz);
52130- /*
52131- * We cannot distinguish between fault on source
52132- * and fault on destination. When this happens
52133- * we clear too and hope it will trigger the
52134- * EFAULT again.
52135- */
52136- if (n) {
52137- if (clear_user(buffer + tsz - n,
52138- n))
52139+ elf_buf = kmalloc(tsz, GFP_KERNEL);
52140+ if (!elf_buf)
52141+ return -ENOMEM;
52142+ oldfs = get_fs();
52143+ set_fs(KERNEL_DS);
52144+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
52145+ set_fs(oldfs);
52146+ if (copy_to_user(buffer, elf_buf, tsz)) {
52147+ kfree(elf_buf);
52148 return -EFAULT;
52149+ }
52150 }
52151+ set_fs(oldfs);
52152+ kfree(elf_buf);
52153 } else {
52154 if (clear_user(buffer, tsz))
52155 return -EFAULT;
52156@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52157
52158 static int open_kcore(struct inode *inode, struct file *filp)
52159 {
52160+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
52161+ return -EPERM;
52162+#endif
52163 if (!capable(CAP_SYS_RAWIO))
52164 return -EPERM;
52165 if (kcore_need_update)
52166diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
52167index 80e4645..53e5fcf 100644
52168--- a/fs/proc/meminfo.c
52169+++ b/fs/proc/meminfo.c
52170@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
52171 vmi.used >> 10,
52172 vmi.largest_chunk >> 10
52173 #ifdef CONFIG_MEMORY_FAILURE
52174- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
52175+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
52176 #endif
52177 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
52178 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
52179diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
52180index b1822dd..df622cb 100644
52181--- a/fs/proc/nommu.c
52182+++ b/fs/proc/nommu.c
52183@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
52184 if (len < 1)
52185 len = 1;
52186 seq_printf(m, "%*c", len, ' ');
52187- seq_path(m, &file->f_path, "");
52188+ seq_path(m, &file->f_path, "\n\\");
52189 }
52190
52191 seq_putc(m, '\n');
52192diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
52193index fe72cd0..cb9b67d 100644
52194--- a/fs/proc/proc_net.c
52195+++ b/fs/proc/proc_net.c
52196@@ -23,6 +23,7 @@
52197 #include <linux/nsproxy.h>
52198 #include <net/net_namespace.h>
52199 #include <linux/seq_file.h>
52200+#include <linux/grsecurity.h>
52201
52202 #include "internal.h"
52203
52204@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
52205 struct task_struct *task;
52206 struct nsproxy *ns;
52207 struct net *net = NULL;
52208+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52209+ const struct cred *cred = current_cred();
52210+#endif
52211+
52212+#ifdef CONFIG_GRKERNSEC_PROC_USER
52213+ if (cred->fsuid)
52214+ return net;
52215+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52216+ if (cred->fsuid && !in_group_p(grsec_proc_gid))
52217+ return net;
52218+#endif
52219
52220 rcu_read_lock();
52221 task = pid_task(proc_pid(dir), PIDTYPE_PID);
52222diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
52223index 1827d88..9a60b01 100644
52224--- a/fs/proc/proc_sysctl.c
52225+++ b/fs/proc/proc_sysctl.c
52226@@ -12,11 +12,15 @@
52227 #include <linux/module.h>
52228 #include "internal.h"
52229
52230+extern int gr_handle_chroot_sysctl(const int op);
52231+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
52232+ const int op);
52233+
52234 static const struct dentry_operations proc_sys_dentry_operations;
52235 static const struct file_operations proc_sys_file_operations;
52236-static const struct inode_operations proc_sys_inode_operations;
52237+const struct inode_operations proc_sys_inode_operations;
52238 static const struct file_operations proc_sys_dir_file_operations;
52239-static const struct inode_operations proc_sys_dir_operations;
52240+const struct inode_operations proc_sys_dir_operations;
52241
52242 void proc_sys_poll_notify(struct ctl_table_poll *poll)
52243 {
52244@@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
52245
52246 err = NULL;
52247 d_set_d_op(dentry, &proc_sys_dentry_operations);
52248+
52249+ gr_handle_proc_create(dentry, inode);
52250+
52251 d_add(dentry, inode);
52252
52253 out:
52254@@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52255 struct inode *inode = filp->f_path.dentry->d_inode;
52256 struct ctl_table_header *head = grab_header(inode);
52257 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
52258+ int op = write ? MAY_WRITE : MAY_READ;
52259 ssize_t error;
52260 size_t res;
52261
52262@@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52263 * and won't be until we finish.
52264 */
52265 error = -EPERM;
52266- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
52267+ if (sysctl_perm(head, table, op))
52268 goto out;
52269
52270 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
52271@@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52272 if (!table->proc_handler)
52273 goto out;
52274
52275+#ifdef CONFIG_GRKERNSEC
52276+ error = -EPERM;
52277+ if (gr_handle_chroot_sysctl(op))
52278+ goto out;
52279+ dget(filp->f_path.dentry);
52280+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
52281+ dput(filp->f_path.dentry);
52282+ goto out;
52283+ }
52284+ dput(filp->f_path.dentry);
52285+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
52286+ goto out;
52287+ if (write && !capable(CAP_SYS_ADMIN))
52288+ goto out;
52289+#endif
52290+
52291 /* careful: calling conventions are nasty here */
52292 res = count;
52293 error = table->proc_handler(table, write, buf, &res, ppos);
52294@@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
52295 return -ENOMEM;
52296 } else {
52297 d_set_d_op(child, &proc_sys_dentry_operations);
52298+
52299+ gr_handle_proc_create(child, inode);
52300+
52301 d_add(child, inode);
52302 }
52303 } else {
52304@@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
52305 if ((*pos)++ < file->f_pos)
52306 return 0;
52307
52308+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
52309+ return 0;
52310+
52311 if (unlikely(S_ISLNK(table->mode)))
52312 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
52313 else
52314@@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
52315 if (IS_ERR(head))
52316 return PTR_ERR(head);
52317
52318+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
52319+ return -ENOENT;
52320+
52321 generic_fillattr(inode, stat);
52322 if (table)
52323 stat->mode = (stat->mode & S_IFMT) | table->mode;
52324@@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
52325 .llseek = generic_file_llseek,
52326 };
52327
52328-static const struct inode_operations proc_sys_inode_operations = {
52329+const struct inode_operations proc_sys_inode_operations = {
52330 .permission = proc_sys_permission,
52331 .setattr = proc_sys_setattr,
52332 .getattr = proc_sys_getattr,
52333 };
52334
52335-static const struct inode_operations proc_sys_dir_operations = {
52336+const struct inode_operations proc_sys_dir_operations = {
52337 .lookup = proc_sys_lookup,
52338 .permission = proc_sys_permission,
52339 .setattr = proc_sys_setattr,
52340diff --git a/fs/proc/root.c b/fs/proc/root.c
52341index c6e9fac..a740964 100644
52342--- a/fs/proc/root.c
52343+++ b/fs/proc/root.c
52344@@ -176,7 +176,15 @@ void __init proc_root_init(void)
52345 #ifdef CONFIG_PROC_DEVICETREE
52346 proc_device_tree_init();
52347 #endif
52348+#ifdef CONFIG_GRKERNSEC_PROC_ADD
52349+#ifdef CONFIG_GRKERNSEC_PROC_USER
52350+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
52351+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52352+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
52353+#endif
52354+#else
52355 proc_mkdir("bus", NULL);
52356+#endif
52357 proc_sys_init();
52358 }
52359
52360diff --git a/fs/proc/self.c b/fs/proc/self.c
52361index aa5cc3b..c91a5d0 100644
52362--- a/fs/proc/self.c
52363+++ b/fs/proc/self.c
52364@@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
52365 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
52366 void *cookie)
52367 {
52368- char *s = nd_get_link(nd);
52369+ const char *s = nd_get_link(nd);
52370 if (!IS_ERR(s))
52371 kfree(s);
52372 }
52373diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
52374index ca5ce7f..02c1cf0 100644
52375--- a/fs/proc/task_mmu.c
52376+++ b/fs/proc/task_mmu.c
52377@@ -11,12 +11,19 @@
52378 #include <linux/rmap.h>
52379 #include <linux/swap.h>
52380 #include <linux/swapops.h>
52381+#include <linux/grsecurity.h>
52382
52383 #include <asm/elf.h>
52384 #include <asm/uaccess.h>
52385 #include <asm/tlbflush.h>
52386 #include "internal.h"
52387
52388+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52389+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
52390+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
52391+ _mm->pax_flags & MF_PAX_SEGMEXEC))
52392+#endif
52393+
52394 void task_mem(struct seq_file *m, struct mm_struct *mm)
52395 {
52396 unsigned long data, text, lib, swap;
52397@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52398 "VmExe:\t%8lu kB\n"
52399 "VmLib:\t%8lu kB\n"
52400 "VmPTE:\t%8lu kB\n"
52401- "VmSwap:\t%8lu kB\n",
52402- hiwater_vm << (PAGE_SHIFT-10),
52403+ "VmSwap:\t%8lu kB\n"
52404+
52405+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52406+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
52407+#endif
52408+
52409+ ,hiwater_vm << (PAGE_SHIFT-10),
52410 total_vm << (PAGE_SHIFT-10),
52411 mm->locked_vm << (PAGE_SHIFT-10),
52412 mm->pinned_vm << (PAGE_SHIFT-10),
52413@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52414 data << (PAGE_SHIFT-10),
52415 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
52416 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
52417- swap << (PAGE_SHIFT-10));
52418+ swap << (PAGE_SHIFT-10)
52419+
52420+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52421+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52422+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
52423+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
52424+#else
52425+ , mm->context.user_cs_base
52426+ , mm->context.user_cs_limit
52427+#endif
52428+#endif
52429+
52430+ );
52431 }
52432
52433 unsigned long task_vsize(struct mm_struct *mm)
52434@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52435 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
52436 }
52437
52438- /* We don't show the stack guard page in /proc/maps */
52439+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52440+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
52441+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
52442+#else
52443 start = vma->vm_start;
52444- if (stack_guard_page_start(vma, start))
52445- start += PAGE_SIZE;
52446 end = vma->vm_end;
52447- if (stack_guard_page_end(vma, end))
52448- end -= PAGE_SIZE;
52449+#endif
52450
52451 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
52452 start,
52453@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52454 flags & VM_WRITE ? 'w' : '-',
52455 flags & VM_EXEC ? 'x' : '-',
52456 flags & VM_MAYSHARE ? 's' : 'p',
52457+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52458+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
52459+#else
52460 pgoff,
52461+#endif
52462 MAJOR(dev), MINOR(dev), ino, &len);
52463
52464 /*
52465@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52466 */
52467 if (file) {
52468 pad_len_spaces(m, len);
52469- seq_path(m, &file->f_path, "\n");
52470+ seq_path(m, &file->f_path, "\n\\");
52471 goto done;
52472 }
52473
52474@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52475 * Thread stack in /proc/PID/task/TID/maps or
52476 * the main process stack.
52477 */
52478- if (!is_pid || (vma->vm_start <= mm->start_stack &&
52479- vma->vm_end >= mm->start_stack)) {
52480+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
52481+ (vma->vm_start <= mm->start_stack &&
52482+ vma->vm_end >= mm->start_stack)) {
52483 name = "[stack]";
52484 } else {
52485 /* Thread stack in /proc/PID/maps */
52486@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
52487 struct proc_maps_private *priv = m->private;
52488 struct task_struct *task = priv->task;
52489
52490+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52491+ if (current->exec_id != m->exec_id) {
52492+ gr_log_badprocpid("maps");
52493+ return 0;
52494+ }
52495+#endif
52496+
52497 show_map_vma(m, vma, is_pid);
52498
52499 if (m->count < m->size) /* vma is copied successfully */
52500@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
52501 .private = &mss,
52502 };
52503
52504+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52505+ if (current->exec_id != m->exec_id) {
52506+ gr_log_badprocpid("smaps");
52507+ return 0;
52508+ }
52509+#endif
52510 memset(&mss, 0, sizeof mss);
52511- mss.vma = vma;
52512- /* mmap_sem is held in m_start */
52513- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
52514- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
52515-
52516+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52517+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
52518+#endif
52519+ mss.vma = vma;
52520+ /* mmap_sem is held in m_start */
52521+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
52522+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
52523+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52524+ }
52525+#endif
52526 show_map_vma(m, vma, is_pid);
52527
52528 seq_printf(m,
52529@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
52530 "KernelPageSize: %8lu kB\n"
52531 "MMUPageSize: %8lu kB\n"
52532 "Locked: %8lu kB\n",
52533+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52534+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
52535+#else
52536 (vma->vm_end - vma->vm_start) >> 10,
52537+#endif
52538 mss.resident >> 10,
52539 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
52540 mss.shared_clean >> 10,
52541@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
52542 int n;
52543 char buffer[50];
52544
52545+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52546+ if (current->exec_id != m->exec_id) {
52547+ gr_log_badprocpid("numa_maps");
52548+ return 0;
52549+ }
52550+#endif
52551+
52552 if (!mm)
52553 return 0;
52554
52555@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
52556 mpol_to_str(buffer, sizeof(buffer), pol);
52557 mpol_cond_put(pol);
52558
52559+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52560+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
52561+#else
52562 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
52563+#endif
52564
52565 if (file) {
52566 seq_printf(m, " file=");
52567- seq_path(m, &file->f_path, "\n\t= ");
52568+ seq_path(m, &file->f_path, "\n\t\\= ");
52569 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
52570 seq_printf(m, " heap");
52571 } else {
52572diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
52573index 1ccfa53..0848f95 100644
52574--- a/fs/proc/task_nommu.c
52575+++ b/fs/proc/task_nommu.c
52576@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52577 else
52578 bytes += kobjsize(mm);
52579
52580- if (current->fs && current->fs->users > 1)
52581+ if (current->fs && atomic_read(&current->fs->users) > 1)
52582 sbytes += kobjsize(current->fs);
52583 else
52584 bytes += kobjsize(current->fs);
52585@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
52586
52587 if (file) {
52588 pad_len_spaces(m, len);
52589- seq_path(m, &file->f_path, "");
52590+ seq_path(m, &file->f_path, "\n\\");
52591 } else if (mm) {
52592 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
52593
52594diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
52595index 16e8abb..2dcf914 100644
52596--- a/fs/quota/netlink.c
52597+++ b/fs/quota/netlink.c
52598@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
52599 void quota_send_warning(struct kqid qid, dev_t dev,
52600 const char warntype)
52601 {
52602- static atomic_t seq;
52603+ static atomic_unchecked_t seq;
52604 struct sk_buff *skb;
52605 void *msg_head;
52606 int ret;
52607@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
52608 "VFS: Not enough memory to send quota warning.\n");
52609 return;
52610 }
52611- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
52612+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
52613 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
52614 if (!msg_head) {
52615 printk(KERN_ERR
52616diff --git a/fs/readdir.c b/fs/readdir.c
52617index 5e69ef5..e5d9099 100644
52618--- a/fs/readdir.c
52619+++ b/fs/readdir.c
52620@@ -17,6 +17,7 @@
52621 #include <linux/security.h>
52622 #include <linux/syscalls.h>
52623 #include <linux/unistd.h>
52624+#include <linux/namei.h>
52625
52626 #include <asm/uaccess.h>
52627
52628@@ -67,6 +68,7 @@ struct old_linux_dirent {
52629
52630 struct readdir_callback {
52631 struct old_linux_dirent __user * dirent;
52632+ struct file * file;
52633 int result;
52634 };
52635
52636@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
52637 buf->result = -EOVERFLOW;
52638 return -EOVERFLOW;
52639 }
52640+
52641+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52642+ return 0;
52643+
52644 buf->result++;
52645 dirent = buf->dirent;
52646 if (!access_ok(VERIFY_WRITE, dirent,
52647@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
52648
52649 buf.result = 0;
52650 buf.dirent = dirent;
52651+ buf.file = f.file;
52652
52653 error = vfs_readdir(f.file, fillonedir, &buf);
52654 if (buf.result)
52655@@ -139,6 +146,7 @@ struct linux_dirent {
52656 struct getdents_callback {
52657 struct linux_dirent __user * current_dir;
52658 struct linux_dirent __user * previous;
52659+ struct file * file;
52660 int count;
52661 int error;
52662 };
52663@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
52664 buf->error = -EOVERFLOW;
52665 return -EOVERFLOW;
52666 }
52667+
52668+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52669+ return 0;
52670+
52671 dirent = buf->previous;
52672 if (dirent) {
52673 if (__put_user(offset, &dirent->d_off))
52674@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
52675 buf.previous = NULL;
52676 buf.count = count;
52677 buf.error = 0;
52678+ buf.file = f.file;
52679
52680 error = vfs_readdir(f.file, filldir, &buf);
52681 if (error >= 0)
52682@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
52683 struct getdents_callback64 {
52684 struct linux_dirent64 __user * current_dir;
52685 struct linux_dirent64 __user * previous;
52686+ struct file *file;
52687 int count;
52688 int error;
52689 };
52690@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
52691 buf->error = -EINVAL; /* only used if we fail.. */
52692 if (reclen > buf->count)
52693 return -EINVAL;
52694+
52695+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52696+ return 0;
52697+
52698 dirent = buf->previous;
52699 if (dirent) {
52700 if (__put_user(offset, &dirent->d_off))
52701@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
52702
52703 buf.current_dir = dirent;
52704 buf.previous = NULL;
52705+ buf.file = f.file;
52706 buf.count = count;
52707 buf.error = 0;
52708
52709@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
52710 error = buf.error;
52711 lastdirent = buf.previous;
52712 if (lastdirent) {
52713- typeof(lastdirent->d_off) d_off = f.file->f_pos;
52714+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
52715 if (__put_user(d_off, &lastdirent->d_off))
52716 error = -EFAULT;
52717 else
52718diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
52719index 2b7882b..1c5ef48 100644
52720--- a/fs/reiserfs/do_balan.c
52721+++ b/fs/reiserfs/do_balan.c
52722@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
52723 return;
52724 }
52725
52726- atomic_inc(&(fs_generation(tb->tb_sb)));
52727+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
52728 do_balance_starts(tb);
52729
52730 /* balance leaf returns 0 except if combining L R and S into
52731diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
52732index e60e870..f40ac16 100644
52733--- a/fs/reiserfs/procfs.c
52734+++ b/fs/reiserfs/procfs.c
52735@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
52736 "SMALL_TAILS " : "NO_TAILS ",
52737 replay_only(sb) ? "REPLAY_ONLY " : "",
52738 convert_reiserfs(sb) ? "CONV " : "",
52739- atomic_read(&r->s_generation_counter),
52740+ atomic_read_unchecked(&r->s_generation_counter),
52741 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
52742 SF(s_do_balance), SF(s_unneeded_left_neighbor),
52743 SF(s_good_search_by_key_reada), SF(s_bmaps),
52744diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
52745index 157e474..65a6114 100644
52746--- a/fs/reiserfs/reiserfs.h
52747+++ b/fs/reiserfs/reiserfs.h
52748@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
52749 /* Comment? -Hans */
52750 wait_queue_head_t s_wait;
52751 /* To be obsoleted soon by per buffer seals.. -Hans */
52752- atomic_t s_generation_counter; // increased by one every time the
52753+ atomic_unchecked_t s_generation_counter; // increased by one every time the
52754 // tree gets re-balanced
52755 unsigned long s_properties; /* File system properties. Currently holds
52756 on-disk FS format */
52757@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
52758 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
52759
52760 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
52761-#define get_generation(s) atomic_read (&fs_generation(s))
52762+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
52763 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
52764 #define __fs_changed(gen,s) (gen != get_generation (s))
52765 #define fs_changed(gen,s) \
52766diff --git a/fs/select.c b/fs/select.c
52767index 2ef72d9..f213b17 100644
52768--- a/fs/select.c
52769+++ b/fs/select.c
52770@@ -20,6 +20,7 @@
52771 #include <linux/export.h>
52772 #include <linux/slab.h>
52773 #include <linux/poll.h>
52774+#include <linux/security.h>
52775 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
52776 #include <linux/file.h>
52777 #include <linux/fdtable.h>
52778@@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
52779 struct poll_list *walk = head;
52780 unsigned long todo = nfds;
52781
52782+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
52783 if (nfds > rlimit(RLIMIT_NOFILE))
52784 return -EINVAL;
52785
52786diff --git a/fs/seq_file.c b/fs/seq_file.c
52787index f2bc3df..239d4f6 100644
52788--- a/fs/seq_file.c
52789+++ b/fs/seq_file.c
52790@@ -10,6 +10,7 @@
52791 #include <linux/seq_file.h>
52792 #include <linux/slab.h>
52793 #include <linux/cred.h>
52794+#include <linux/sched.h>
52795
52796 #include <asm/uaccess.h>
52797 #include <asm/page.h>
52798@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
52799 #ifdef CONFIG_USER_NS
52800 p->user_ns = file->f_cred->user_ns;
52801 #endif
52802+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52803+ p->exec_id = current->exec_id;
52804+#endif
52805
52806 /*
52807 * Wrappers around seq_open(e.g. swaps_open) need to be
52808@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52809 return 0;
52810 }
52811 if (!m->buf) {
52812- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52813+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52814 if (!m->buf)
52815 return -ENOMEM;
52816 }
52817@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52818 Eoverflow:
52819 m->op->stop(m, p);
52820 kfree(m->buf);
52821- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52822+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52823 return !m->buf ? -ENOMEM : -EAGAIN;
52824 }
52825
52826@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52827
52828 /* grab buffer if we didn't have one */
52829 if (!m->buf) {
52830- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52831+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52832 if (!m->buf)
52833 goto Enomem;
52834 }
52835@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52836 goto Fill;
52837 m->op->stop(m, p);
52838 kfree(m->buf);
52839- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52840+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52841 if (!m->buf)
52842 goto Enomem;
52843 m->count = 0;
52844@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
52845 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
52846 void *data)
52847 {
52848- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
52849+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
52850 int res = -ENOMEM;
52851
52852 if (op) {
52853diff --git a/fs/splice.c b/fs/splice.c
52854index 6909d89..5b2e8f9 100644
52855--- a/fs/splice.c
52856+++ b/fs/splice.c
52857@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52858 pipe_lock(pipe);
52859
52860 for (;;) {
52861- if (!pipe->readers) {
52862+ if (!atomic_read(&pipe->readers)) {
52863 send_sig(SIGPIPE, current, 0);
52864 if (!ret)
52865 ret = -EPIPE;
52866@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52867 do_wakeup = 0;
52868 }
52869
52870- pipe->waiting_writers++;
52871+ atomic_inc(&pipe->waiting_writers);
52872 pipe_wait(pipe);
52873- pipe->waiting_writers--;
52874+ atomic_dec(&pipe->waiting_writers);
52875 }
52876
52877 pipe_unlock(pipe);
52878@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
52879 old_fs = get_fs();
52880 set_fs(get_ds());
52881 /* The cast to a user pointer is valid due to the set_fs() */
52882- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
52883+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
52884 set_fs(old_fs);
52885
52886 return res;
52887@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
52888 old_fs = get_fs();
52889 set_fs(get_ds());
52890 /* The cast to a user pointer is valid due to the set_fs() */
52891- res = vfs_write(file, (const char __user *)buf, count, &pos);
52892+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
52893 set_fs(old_fs);
52894
52895 return res;
52896@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
52897 goto err;
52898
52899 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
52900- vec[i].iov_base = (void __user *) page_address(page);
52901+ vec[i].iov_base = (void __force_user *) page_address(page);
52902 vec[i].iov_len = this_len;
52903 spd.pages[i] = page;
52904 spd.nr_pages++;
52905@@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
52906 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
52907 {
52908 while (!pipe->nrbufs) {
52909- if (!pipe->writers)
52910+ if (!atomic_read(&pipe->writers))
52911 return 0;
52912
52913- if (!pipe->waiting_writers && sd->num_spliced)
52914+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
52915 return 0;
52916
52917 if (sd->flags & SPLICE_F_NONBLOCK)
52918@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
52919 * out of the pipe right after the splice_to_pipe(). So set
52920 * PIPE_READERS appropriately.
52921 */
52922- pipe->readers = 1;
52923+ atomic_set(&pipe->readers, 1);
52924
52925 current->splice_pipe = pipe;
52926 }
52927@@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52928 ret = -ERESTARTSYS;
52929 break;
52930 }
52931- if (!pipe->writers)
52932+ if (!atomic_read(&pipe->writers))
52933 break;
52934- if (!pipe->waiting_writers) {
52935+ if (!atomic_read(&pipe->waiting_writers)) {
52936 if (flags & SPLICE_F_NONBLOCK) {
52937 ret = -EAGAIN;
52938 break;
52939@@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52940 pipe_lock(pipe);
52941
52942 while (pipe->nrbufs >= pipe->buffers) {
52943- if (!pipe->readers) {
52944+ if (!atomic_read(&pipe->readers)) {
52945 send_sig(SIGPIPE, current, 0);
52946 ret = -EPIPE;
52947 break;
52948@@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52949 ret = -ERESTARTSYS;
52950 break;
52951 }
52952- pipe->waiting_writers++;
52953+ atomic_inc(&pipe->waiting_writers);
52954 pipe_wait(pipe);
52955- pipe->waiting_writers--;
52956+ atomic_dec(&pipe->waiting_writers);
52957 }
52958
52959 pipe_unlock(pipe);
52960@@ -1823,14 +1823,14 @@ retry:
52961 pipe_double_lock(ipipe, opipe);
52962
52963 do {
52964- if (!opipe->readers) {
52965+ if (!atomic_read(&opipe->readers)) {
52966 send_sig(SIGPIPE, current, 0);
52967 if (!ret)
52968 ret = -EPIPE;
52969 break;
52970 }
52971
52972- if (!ipipe->nrbufs && !ipipe->writers)
52973+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
52974 break;
52975
52976 /*
52977@@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
52978 pipe_double_lock(ipipe, opipe);
52979
52980 do {
52981- if (!opipe->readers) {
52982+ if (!atomic_read(&opipe->readers)) {
52983 send_sig(SIGPIPE, current, 0);
52984 if (!ret)
52985 ret = -EPIPE;
52986@@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
52987 * return EAGAIN if we have the potential of some data in the
52988 * future, otherwise just return 0
52989 */
52990- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
52991+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
52992 ret = -EAGAIN;
52993
52994 pipe_unlock(ipipe);
52995diff --git a/fs/stat.c b/fs/stat.c
52996index 14f4545..9b7f55b 100644
52997--- a/fs/stat.c
52998+++ b/fs/stat.c
52999@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
53000 stat->gid = inode->i_gid;
53001 stat->rdev = inode->i_rdev;
53002 stat->size = i_size_read(inode);
53003- stat->atime = inode->i_atime;
53004- stat->mtime = inode->i_mtime;
53005+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
53006+ stat->atime = inode->i_ctime;
53007+ stat->mtime = inode->i_ctime;
53008+ } else {
53009+ stat->atime = inode->i_atime;
53010+ stat->mtime = inode->i_mtime;
53011+ }
53012 stat->ctime = inode->i_ctime;
53013 stat->blksize = (1 << inode->i_blkbits);
53014 stat->blocks = inode->i_blocks;
53015@@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
53016 if (retval)
53017 return retval;
53018
53019- if (inode->i_op->getattr)
53020- return inode->i_op->getattr(mnt, dentry, stat);
53021+ if (inode->i_op->getattr) {
53022+ retval = inode->i_op->getattr(mnt, dentry, stat);
53023+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
53024+ stat->atime = stat->ctime;
53025+ stat->mtime = stat->ctime;
53026+ }
53027+ return retval;
53028+ }
53029
53030 generic_fillattr(inode, stat);
53031 return 0;
53032diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
53033index 2fbdff6..5530a61 100644
53034--- a/fs/sysfs/dir.c
53035+++ b/fs/sysfs/dir.c
53036@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
53037 struct sysfs_dirent *sd;
53038 int rc;
53039
53040+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
53041+ const char *parent_name = parent_sd->s_name;
53042+
53043+ mode = S_IFDIR | S_IRWXU;
53044+
53045+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
53046+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
53047+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
53048+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
53049+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
53050+#endif
53051+
53052 /* allocate */
53053 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
53054 if (!sd)
53055diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
53056index 602f56d..6853db8 100644
53057--- a/fs/sysfs/file.c
53058+++ b/fs/sysfs/file.c
53059@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
53060
53061 struct sysfs_open_dirent {
53062 atomic_t refcnt;
53063- atomic_t event;
53064+ atomic_unchecked_t event;
53065 wait_queue_head_t poll;
53066 struct list_head buffers; /* goes through sysfs_buffer.list */
53067 };
53068@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
53069 if (!sysfs_get_active(attr_sd))
53070 return -ENODEV;
53071
53072- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
53073+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
53074 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
53075
53076 sysfs_put_active(attr_sd);
53077@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
53078 return -ENOMEM;
53079
53080 atomic_set(&new_od->refcnt, 0);
53081- atomic_set(&new_od->event, 1);
53082+ atomic_set_unchecked(&new_od->event, 1);
53083 init_waitqueue_head(&new_od->poll);
53084 INIT_LIST_HEAD(&new_od->buffers);
53085 goto retry;
53086@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
53087
53088 sysfs_put_active(attr_sd);
53089
53090- if (buffer->event != atomic_read(&od->event))
53091+ if (buffer->event != atomic_read_unchecked(&od->event))
53092 goto trigger;
53093
53094 return DEFAULT_POLLMASK;
53095@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
53096
53097 od = sd->s_attr.open;
53098 if (od) {
53099- atomic_inc(&od->event);
53100+ atomic_inc_unchecked(&od->event);
53101 wake_up_interruptible(&od->poll);
53102 }
53103
53104diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
53105index 3c9eb56..9dea5be 100644
53106--- a/fs/sysfs/symlink.c
53107+++ b/fs/sysfs/symlink.c
53108@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
53109
53110 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
53111 {
53112- char *page = nd_get_link(nd);
53113+ const char *page = nd_get_link(nd);
53114 if (!IS_ERR(page))
53115 free_page((unsigned long)page);
53116 }
53117diff --git a/fs/udf/misc.c b/fs/udf/misc.c
53118index c175b4d..8f36a16 100644
53119--- a/fs/udf/misc.c
53120+++ b/fs/udf/misc.c
53121@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
53122
53123 u8 udf_tag_checksum(const struct tag *t)
53124 {
53125- u8 *data = (u8 *)t;
53126+ const u8 *data = (const u8 *)t;
53127 u8 checksum = 0;
53128 int i;
53129 for (i = 0; i < sizeof(struct tag); ++i)
53130diff --git a/fs/utimes.c b/fs/utimes.c
53131index f4fb7ec..3fe03c0 100644
53132--- a/fs/utimes.c
53133+++ b/fs/utimes.c
53134@@ -1,6 +1,7 @@
53135 #include <linux/compiler.h>
53136 #include <linux/file.h>
53137 #include <linux/fs.h>
53138+#include <linux/security.h>
53139 #include <linux/linkage.h>
53140 #include <linux/mount.h>
53141 #include <linux/namei.h>
53142@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
53143 goto mnt_drop_write_and_out;
53144 }
53145 }
53146+
53147+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
53148+ error = -EACCES;
53149+ goto mnt_drop_write_and_out;
53150+ }
53151+
53152 mutex_lock(&inode->i_mutex);
53153 error = notify_change(path->dentry, &newattrs);
53154 mutex_unlock(&inode->i_mutex);
53155diff --git a/fs/xattr.c b/fs/xattr.c
53156index 3377dff..4feded6 100644
53157--- a/fs/xattr.c
53158+++ b/fs/xattr.c
53159@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
53160 * Extended attribute SET operations
53161 */
53162 static long
53163-setxattr(struct dentry *d, const char __user *name, const void __user *value,
53164+setxattr(struct path *path, const char __user *name, const void __user *value,
53165 size_t size, int flags)
53166 {
53167 int error;
53168@@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
53169 posix_acl_fix_xattr_from_user(kvalue, size);
53170 }
53171
53172- error = vfs_setxattr(d, kname, kvalue, size, flags);
53173+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
53174+ error = -EACCES;
53175+ goto out;
53176+ }
53177+
53178+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
53179 out:
53180 if (vvalue)
53181 vfree(vvalue);
53182@@ -377,7 +382,7 @@ retry:
53183 return error;
53184 error = mnt_want_write(path.mnt);
53185 if (!error) {
53186- error = setxattr(path.dentry, name, value, size, flags);
53187+ error = setxattr(&path, name, value, size, flags);
53188 mnt_drop_write(path.mnt);
53189 }
53190 path_put(&path);
53191@@ -401,7 +406,7 @@ retry:
53192 return error;
53193 error = mnt_want_write(path.mnt);
53194 if (!error) {
53195- error = setxattr(path.dentry, name, value, size, flags);
53196+ error = setxattr(&path, name, value, size, flags);
53197 mnt_drop_write(path.mnt);
53198 }
53199 path_put(&path);
53200@@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
53201 const void __user *,value, size_t, size, int, flags)
53202 {
53203 struct fd f = fdget(fd);
53204- struct dentry *dentry;
53205 int error = -EBADF;
53206
53207 if (!f.file)
53208 return error;
53209- dentry = f.file->f_path.dentry;
53210- audit_inode(NULL, dentry, 0);
53211+ audit_inode(NULL, f.file->f_path.dentry, 0);
53212 error = mnt_want_write_file(f.file);
53213 if (!error) {
53214- error = setxattr(dentry, name, value, size, flags);
53215+ error = setxattr(&f.file->f_path, name, value, size, flags);
53216 mnt_drop_write_file(f.file);
53217 }
53218 fdput(f);
53219diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
53220index 9fbea87..6b19972 100644
53221--- a/fs/xattr_acl.c
53222+++ b/fs/xattr_acl.c
53223@@ -76,8 +76,8 @@ struct posix_acl *
53224 posix_acl_from_xattr(struct user_namespace *user_ns,
53225 const void *value, size_t size)
53226 {
53227- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
53228- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
53229+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
53230+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
53231 int count;
53232 struct posix_acl *acl;
53233 struct posix_acl_entry *acl_e;
53234diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
53235index cdb2d33..704ce7f 100644
53236--- a/fs/xfs/xfs_bmap.c
53237+++ b/fs/xfs/xfs_bmap.c
53238@@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
53239 int nmap,
53240 int ret_nmap);
53241 #else
53242-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
53243+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
53244 #endif /* DEBUG */
53245
53246 STATIC int
53247diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
53248index 1b9fc3e..e1bdde0 100644
53249--- a/fs/xfs/xfs_dir2_sf.c
53250+++ b/fs/xfs/xfs_dir2_sf.c
53251@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
53252 }
53253
53254 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
53255- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
53256+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
53257+ char name[sfep->namelen];
53258+ memcpy(name, sfep->name, sfep->namelen);
53259+ if (filldir(dirent, name, sfep->namelen,
53260+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
53261+ *offset = off & 0x7fffffff;
53262+ return 0;
53263+ }
53264+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
53265 off & 0x7fffffff, ino, DT_UNKNOWN)) {
53266 *offset = off & 0x7fffffff;
53267 return 0;
53268diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
53269index c1c3ef8..0952438 100644
53270--- a/fs/xfs/xfs_ioctl.c
53271+++ b/fs/xfs/xfs_ioctl.c
53272@@ -127,7 +127,7 @@ xfs_find_handle(
53273 }
53274
53275 error = -EFAULT;
53276- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
53277+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
53278 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
53279 goto out_put;
53280
53281diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
53282index d82efaa..0904a8e 100644
53283--- a/fs/xfs/xfs_iops.c
53284+++ b/fs/xfs/xfs_iops.c
53285@@ -395,7 +395,7 @@ xfs_vn_put_link(
53286 struct nameidata *nd,
53287 void *p)
53288 {
53289- char *s = nd_get_link(nd);
53290+ const char *s = nd_get_link(nd);
53291
53292 if (!IS_ERR(s))
53293 kfree(s);
53294diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
53295new file mode 100644
53296index 0000000..92247e4
53297--- /dev/null
53298+++ b/grsecurity/Kconfig
53299@@ -0,0 +1,1021 @@
53300+#
53301+# grecurity configuration
53302+#
53303+menu "Memory Protections"
53304+depends on GRKERNSEC
53305+
53306+config GRKERNSEC_KMEM
53307+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
53308+ default y if GRKERNSEC_CONFIG_AUTO
53309+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
53310+ help
53311+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
53312+ be written to or read from to modify or leak the contents of the running
53313+ kernel. /dev/port will also not be allowed to be opened and support
53314+ for /dev/cpu/*/msr will be removed. If you have module
53315+ support disabled, enabling this will close up five ways that are
53316+ currently used to insert malicious code into the running kernel.
53317+
53318+ Even with all these features enabled, we still highly recommend that
53319+ you use the RBAC system, as it is still possible for an attacker to
53320+ modify the running kernel through privileged I/O granted by ioperm/iopl.
53321+
53322+ If you are not using XFree86, you may be able to stop this additional
53323+ case by enabling the 'Disable privileged I/O' option. Though nothing
53324+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
53325+ but only to video memory, which is the only writing we allow in this
53326+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
53327+ not be allowed to mprotect it with PROT_WRITE later.
53328+ Enabling this feature will prevent the "cpupower" and "powertop" tools
53329+ from working.
53330+
53331+ It is highly recommended that you say Y here if you meet all the
53332+ conditions above.
53333+
53334+config GRKERNSEC_VM86
53335+ bool "Restrict VM86 mode"
53336+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53337+ depends on X86_32
53338+
53339+ help
53340+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
53341+ make use of a special execution mode on 32bit x86 processors called
53342+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
53343+ video cards and will still work with this option enabled. The purpose
53344+ of the option is to prevent exploitation of emulation errors in
53345+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
53346+ Nearly all users should be able to enable this option.
53347+
53348+config GRKERNSEC_IO
53349+ bool "Disable privileged I/O"
53350+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53351+ depends on X86
53352+ select RTC_CLASS
53353+ select RTC_INTF_DEV
53354+ select RTC_DRV_CMOS
53355+
53356+ help
53357+ If you say Y here, all ioperm and iopl calls will return an error.
53358+ Ioperm and iopl can be used to modify the running kernel.
53359+ Unfortunately, some programs need this access to operate properly,
53360+ the most notable of which are XFree86 and hwclock. hwclock can be
53361+ remedied by having RTC support in the kernel, so real-time
53362+ clock support is enabled if this option is enabled, to ensure
53363+ that hwclock operates correctly. XFree86 still will not
53364+ operate correctly with this option enabled, so DO NOT CHOOSE Y
53365+ IF YOU USE XFree86. If you use XFree86 and you still want to
53366+ protect your kernel against modification, use the RBAC system.
53367+
53368+config GRKERNSEC_JIT_HARDEN
53369+ bool "Harden BPF JIT against spray attacks"
53370+ default y if GRKERNSEC_CONFIG_AUTO
53371+ depends on BPF_JIT
53372+ help
53373+ If you say Y here, the native code generated by the kernel's Berkeley
53374+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
53375+ attacks that attempt to fit attacker-beneficial instructions in
53376+ 32bit immediate fields of JIT-generated native instructions. The
53377+ attacker will generally aim to cause an unintended instruction sequence
53378+ of JIT-generated native code to execute by jumping into the middle of
53379+ a generated instruction. This feature effectively randomizes the 32bit
53380+ immediate constants present in the generated code to thwart such attacks.
53381+
53382+ If you're using KERNEXEC, it's recommended that you enable this option
53383+ to supplement the hardening of the kernel.
53384+
53385+config GRKERNSEC_RAND_THREADSTACK
53386+ bool "Insert random gaps between thread stacks"
53387+ default y if GRKERNSEC_CONFIG_AUTO
53388+ depends on PAX_RANDMMAP && !PPC
53389+ help
53390+ If you say Y here, a random-sized gap will be enforced between allocated
53391+ thread stacks. Glibc's NPTL and other threading libraries that
53392+ pass MAP_STACK to the kernel for thread stack allocation are supported.
53393+ The implementation currently provides 8 bits of entropy for the gap.
53394+
53395+ Many distributions do not compile threaded remote services with the
53396+ -fstack-check argument to GCC, causing the variable-sized stack-based
53397+ allocator, alloca(), to not probe the stack on allocation. This
53398+ permits an unbounded alloca() to skip over any guard page and potentially
53399+ modify another thread's stack reliably. An enforced random gap
53400+ reduces the reliability of such an attack and increases the chance
53401+ that such a read/write to another thread's stack instead lands in
53402+ an unmapped area, causing a crash and triggering grsecurity's
53403+ anti-bruteforcing logic.
53404+
53405+config GRKERNSEC_PROC_MEMMAP
53406+ bool "Harden ASLR against information leaks and entropy reduction"
53407+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
53408+ depends on PAX_NOEXEC || PAX_ASLR
53409+ help
53410+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
53411+ give no information about the addresses of its mappings if
53412+ PaX features that rely on random addresses are enabled on the task.
53413+ In addition to sanitizing this information and disabling other
53414+ dangerous sources of information, this option causes reads of sensitive
53415+ /proc/<pid> entries where the file descriptor was opened in a different
53416+ task than the one performing the read. Such attempts are logged.
53417+ This option also limits argv/env strings for suid/sgid binaries
53418+ to 512KB to prevent a complete exhaustion of the stack entropy provided
53419+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
53420+ binaries to prevent alternative mmap layouts from being abused.
53421+
53422+ If you use PaX it is essential that you say Y here as it closes up
53423+ several holes that make full ASLR useless locally.
53424+
53425+config GRKERNSEC_BRUTE
53426+ bool "Deter exploit bruteforcing"
53427+ default y if GRKERNSEC_CONFIG_AUTO
53428+ help
53429+ If you say Y here, attempts to bruteforce exploits against forking
53430+ daemons such as apache or sshd, as well as against suid/sgid binaries
53431+ will be deterred. When a child of a forking daemon is killed by PaX
53432+ or crashes due to an illegal instruction or other suspicious signal,
53433+ the parent process will be delayed 30 seconds upon every subsequent
53434+ fork until the administrator is able to assess the situation and
53435+ restart the daemon.
53436+ In the suid/sgid case, the attempt is logged, the user has all their
53437+ processes terminated, and they are prevented from executing any further
53438+ processes for 15 minutes.
53439+ It is recommended that you also enable signal logging in the auditing
53440+ section so that logs are generated when a process triggers a suspicious
53441+ signal.
53442+ If the sysctl option is enabled, a sysctl option with name
53443+ "deter_bruteforce" is created.
53444+
53445+
53446+config GRKERNSEC_MODHARDEN
53447+ bool "Harden module auto-loading"
53448+ default y if GRKERNSEC_CONFIG_AUTO
53449+ depends on MODULES
53450+ help
53451+ If you say Y here, module auto-loading in response to use of some
53452+ feature implemented by an unloaded module will be restricted to
53453+ root users. Enabling this option helps defend against attacks
53454+ by unprivileged users who abuse the auto-loading behavior to
53455+ cause a vulnerable module to load that is then exploited.
53456+
53457+ If this option prevents a legitimate use of auto-loading for a
53458+ non-root user, the administrator can execute modprobe manually
53459+ with the exact name of the module mentioned in the alert log.
53460+ Alternatively, the administrator can add the module to the list
53461+ of modules loaded at boot by modifying init scripts.
53462+
53463+ Modification of init scripts will most likely be needed on
53464+ Ubuntu servers with encrypted home directory support enabled,
53465+ as the first non-root user logging in will cause the ecb(aes),
53466+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
53467+
53468+config GRKERNSEC_HIDESYM
53469+ bool "Hide kernel symbols"
53470+ default y if GRKERNSEC_CONFIG_AUTO
53471+ select PAX_USERCOPY_SLABS
53472+ help
53473+ If you say Y here, getting information on loaded modules, and
53474+ displaying all kernel symbols through a syscall will be restricted
53475+ to users with CAP_SYS_MODULE. For software compatibility reasons,
53476+ /proc/kallsyms will be restricted to the root user. The RBAC
53477+ system can hide that entry even from root.
53478+
53479+ This option also prevents leaking of kernel addresses through
53480+ several /proc entries.
53481+
53482+ Note that this option is only effective provided the following
53483+ conditions are met:
53484+ 1) The kernel using grsecurity is not precompiled by some distribution
53485+ 2) You have also enabled GRKERNSEC_DMESG
53486+ 3) You are using the RBAC system and hiding other files such as your
53487+ kernel image and System.map. Alternatively, enabling this option
53488+ causes the permissions on /boot, /lib/modules, and the kernel
53489+ source directory to change at compile time to prevent
53490+ reading by non-root users.
53491+ If the above conditions are met, this option will aid in providing a
53492+ useful protection against local kernel exploitation of overflows
53493+ and arbitrary read/write vulnerabilities.
53494+
53495+config GRKERNSEC_KERN_LOCKOUT
53496+ bool "Active kernel exploit response"
53497+ default y if GRKERNSEC_CONFIG_AUTO
53498+ depends on X86 || ARM || PPC || SPARC
53499+ help
53500+ If you say Y here, when a PaX alert is triggered due to suspicious
53501+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
53502+ or an OOPS occurs due to bad memory accesses, instead of just
53503+ terminating the offending process (and potentially allowing
53504+ a subsequent exploit from the same user), we will take one of two
53505+ actions:
53506+ If the user was root, we will panic the system
53507+ If the user was non-root, we will log the attempt, terminate
53508+ all processes owned by the user, then prevent them from creating
53509+ any new processes until the system is restarted
53510+ This deters repeated kernel exploitation/bruteforcing attempts
53511+ and is useful for later forensics.
53512+
53513+endmenu
53514+menu "Role Based Access Control Options"
53515+depends on GRKERNSEC
53516+
53517+config GRKERNSEC_RBAC_DEBUG
53518+ bool
53519+
53520+config GRKERNSEC_NO_RBAC
53521+ bool "Disable RBAC system"
53522+ help
53523+ If you say Y here, the /dev/grsec device will be removed from the kernel,
53524+ preventing the RBAC system from being enabled. You should only say Y
53525+ here if you have no intention of using the RBAC system, so as to prevent
53526+ an attacker with root access from misusing the RBAC system to hide files
53527+ and processes when loadable module support and /dev/[k]mem have been
53528+ locked down.
53529+
53530+config GRKERNSEC_ACL_HIDEKERN
53531+ bool "Hide kernel processes"
53532+ help
53533+ If you say Y here, all kernel threads will be hidden to all
53534+ processes but those whose subject has the "view hidden processes"
53535+ flag.
53536+
53537+config GRKERNSEC_ACL_MAXTRIES
53538+ int "Maximum tries before password lockout"
53539+ default 3
53540+ help
53541+ This option enforces the maximum number of times a user can attempt
53542+ to authorize themselves with the grsecurity RBAC system before being
53543+ denied the ability to attempt authorization again for a specified time.
53544+ The lower the number, the harder it will be to brute-force a password.
53545+
53546+config GRKERNSEC_ACL_TIMEOUT
53547+ int "Time to wait after max password tries, in seconds"
53548+ default 30
53549+ help
53550+ This option specifies the time the user must wait after attempting to
53551+ authorize to the RBAC system with the maximum number of invalid
53552+ passwords. The higher the number, the harder it will be to brute-force
53553+ a password.
53554+
53555+endmenu
53556+menu "Filesystem Protections"
53557+depends on GRKERNSEC
53558+
53559+config GRKERNSEC_PROC
53560+ bool "Proc restrictions"
53561+ default y if GRKERNSEC_CONFIG_AUTO
53562+ help
53563+ If you say Y here, the permissions of the /proc filesystem
53564+ will be altered to enhance system security and privacy. You MUST
53565+ choose either a user only restriction or a user and group restriction.
53566+ Depending upon the option you choose, you can either restrict users to
53567+ see only the processes they themselves run, or choose a group that can
53568+ view all processes and files normally restricted to root if you choose
53569+ the "restrict to user only" option. NOTE: If you're running identd or
53570+ ntpd as a non-root user, you will have to run it as the group you
53571+ specify here.
53572+
53573+config GRKERNSEC_PROC_USER
53574+ bool "Restrict /proc to user only"
53575+ depends on GRKERNSEC_PROC
53576+ help
53577+ If you say Y here, non-root users will only be able to view their own
53578+ processes, and restricts them from viewing network-related information,
53579+ and viewing kernel symbol and module information.
53580+
53581+config GRKERNSEC_PROC_USERGROUP
53582+ bool "Allow special group"
53583+ default y if GRKERNSEC_CONFIG_AUTO
53584+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
53585+ help
53586+ If you say Y here, you will be able to select a group that will be
53587+ able to view all processes and network-related information. If you've
53588+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
53589+ remain hidden. This option is useful if you want to run identd as
53590+ a non-root user. The group you select may also be chosen at boot time
53591+ via "grsec_proc_gid=" on the kernel commandline.
53592+
53593+config GRKERNSEC_PROC_GID
53594+ int "GID for special group"
53595+ depends on GRKERNSEC_PROC_USERGROUP
53596+ default 1001
53597+
53598+config GRKERNSEC_PROC_ADD
53599+ bool "Additional restrictions"
53600+ default y if GRKERNSEC_CONFIG_AUTO
53601+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
53602+ help
53603+ If you say Y here, additional restrictions will be placed on
53604+ /proc that keep normal users from viewing device information and
53605+ slabinfo information that could be useful for exploits.
53606+
53607+config GRKERNSEC_LINK
53608+ bool "Linking restrictions"
53609+ default y if GRKERNSEC_CONFIG_AUTO
53610+ help
53611+ If you say Y here, /tmp race exploits will be prevented, since users
53612+ will no longer be able to follow symlinks owned by other users in
53613+ world-writable +t directories (e.g. /tmp), unless the owner of the
53614+ symlink is the owner of the directory. users will also not be
53615+ able to hardlink to files they do not own. If the sysctl option is
53616+ enabled, a sysctl option with name "linking_restrictions" is created.
53617+
53618+config GRKERNSEC_SYMLINKOWN
53619+ bool "Kernel-enforced SymlinksIfOwnerMatch"
53620+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
53621+ help
53622+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
53623+ that prevents it from being used as a security feature. As Apache
53624+ verifies the symlink by performing a stat() against the target of
53625+ the symlink before it is followed, an attacker can setup a symlink
53626+ to point to a same-owned file, then replace the symlink with one
53627+ that targets another user's file just after Apache "validates" the
53628+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
53629+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
53630+ will be in place for the group you specify. If the sysctl option
53631+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
53632+ created.
53633+
53634+config GRKERNSEC_SYMLINKOWN_GID
53635+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
53636+ depends on GRKERNSEC_SYMLINKOWN
53637+ default 1006
53638+ help
53639+ Setting this GID determines what group kernel-enforced
53640+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
53641+ is enabled, a sysctl option with name "symlinkown_gid" is created.
53642+
53643+config GRKERNSEC_FIFO
53644+ bool "FIFO restrictions"
53645+ default y if GRKERNSEC_CONFIG_AUTO
53646+ help
53647+ If you say Y here, users will not be able to write to FIFOs they don't
53648+ own in world-writable +t directories (e.g. /tmp), unless the owner of
53649+ the FIFO is the same owner of the directory it's held in. If the sysctl
53650+ option is enabled, a sysctl option with name "fifo_restrictions" is
53651+ created.
53652+
53653+config GRKERNSEC_SYSFS_RESTRICT
53654+ bool "Sysfs/debugfs restriction"
53655+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53656+ depends on SYSFS
53657+ help
53658+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
53659+ any filesystem normally mounted under it (e.g. debugfs) will be
53660+ mostly accessible only by root. These filesystems generally provide access
53661+ to hardware and debug information that isn't appropriate for unprivileged
53662+ users of the system. Sysfs and debugfs have also become a large source
53663+ of new vulnerabilities, ranging from infoleaks to local compromise.
53664+ There has been very little oversight with an eye toward security involved
53665+ in adding new exporters of information to these filesystems, so their
53666+ use is discouraged.
53667+ For reasons of compatibility, a few directories have been whitelisted
53668+ for access by non-root users:
53669+ /sys/fs/selinux
53670+ /sys/fs/fuse
53671+ /sys/devices/system/cpu
53672+
53673+config GRKERNSEC_ROFS
53674+ bool "Runtime read-only mount protection"
53675+ help
53676+ If you say Y here, a sysctl option with name "romount_protect" will
53677+ be created. By setting this option to 1 at runtime, filesystems
53678+ will be protected in the following ways:
53679+ * No new writable mounts will be allowed
53680+ * Existing read-only mounts won't be able to be remounted read/write
53681+ * Write operations will be denied on all block devices
53682+ This option acts independently of grsec_lock: once it is set to 1,
53683+ it cannot be turned off. Therefore, please be mindful of the resulting
53684+ behavior if this option is enabled in an init script on a read-only
53685+ filesystem. This feature is mainly intended for secure embedded systems.
53686+
53687+config GRKERNSEC_DEVICE_SIDECHANNEL
53688+ bool "Eliminate stat/notify-based device sidechannels"
53689+ default y if GRKERNSEC_CONFIG_AUTO
53690+ help
53691+ If you say Y here, timing analyses on block or character
53692+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
53693+ will be thwarted for unprivileged users. If a process without
53694+ CAP_MKNOD stats such a device, the last access and last modify times
53695+ will match the device's create time. No access or modify events
53696+ will be triggered through inotify/dnotify/fanotify for such devices.
53697+ This feature will prevent attacks that may at a minimum
53698+ allow an attacker to determine the administrator's password length.
53699+
53700+config GRKERNSEC_CHROOT
53701+ bool "Chroot jail restrictions"
53702+ default y if GRKERNSEC_CONFIG_AUTO
53703+ help
53704+ If you say Y here, you will be able to choose several options that will
53705+ make breaking out of a chrooted jail much more difficult. If you
53706+ encounter no software incompatibilities with the following options, it
53707+ is recommended that you enable each one.
53708+
53709+config GRKERNSEC_CHROOT_MOUNT
53710+ bool "Deny mounts"
53711+ default y if GRKERNSEC_CONFIG_AUTO
53712+ depends on GRKERNSEC_CHROOT
53713+ help
53714+ If you say Y here, processes inside a chroot will not be able to
53715+ mount or remount filesystems. If the sysctl option is enabled, a
53716+ sysctl option with name "chroot_deny_mount" is created.
53717+
53718+config GRKERNSEC_CHROOT_DOUBLE
53719+ bool "Deny double-chroots"
53720+ default y if GRKERNSEC_CONFIG_AUTO
53721+ depends on GRKERNSEC_CHROOT
53722+ help
53723+ If you say Y here, processes inside a chroot will not be able to chroot
53724+ again outside the chroot. This is a widely used method of breaking
53725+ out of a chroot jail and should not be allowed. If the sysctl
53726+ option is enabled, a sysctl option with name
53727+ "chroot_deny_chroot" is created.
53728+
53729+config GRKERNSEC_CHROOT_PIVOT
53730+ bool "Deny pivot_root in chroot"
53731+ default y if GRKERNSEC_CONFIG_AUTO
53732+ depends on GRKERNSEC_CHROOT
53733+ help
53734+ If you say Y here, processes inside a chroot will not be able to use
53735+ a function called pivot_root() that was introduced in Linux 2.3.41. It
53736+ works similar to chroot in that it changes the root filesystem. This
53737+ function could be misused in a chrooted process to attempt to break out
53738+ of the chroot, and therefore should not be allowed. If the sysctl
53739+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
53740+ created.
53741+
53742+config GRKERNSEC_CHROOT_CHDIR
53743+ bool "Enforce chdir(\"/\") on all chroots"
53744+ default y if GRKERNSEC_CONFIG_AUTO
53745+ depends on GRKERNSEC_CHROOT
53746+ help
53747+ If you say Y here, the current working directory of all newly-chrooted
53748+ applications will be set to the the root directory of the chroot.
53749+ The man page on chroot(2) states:
53750+ Note that this call does not change the current working
53751+ directory, so that `.' can be outside the tree rooted at
53752+ `/'. In particular, the super-user can escape from a
53753+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
53754+
53755+ It is recommended that you say Y here, since it's not known to break
53756+ any software. If the sysctl option is enabled, a sysctl option with
53757+ name "chroot_enforce_chdir" is created.
53758+
53759+config GRKERNSEC_CHROOT_CHMOD
53760+ bool "Deny (f)chmod +s"
53761+ default y if GRKERNSEC_CONFIG_AUTO
53762+ depends on GRKERNSEC_CHROOT
53763+ help
53764+ If you say Y here, processes inside a chroot will not be able to chmod
53765+ or fchmod files to make them have suid or sgid bits. This protects
53766+ against another published method of breaking a chroot. If the sysctl
53767+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
53768+ created.
53769+
53770+config GRKERNSEC_CHROOT_FCHDIR
53771+ bool "Deny fchdir out of chroot"
53772+ default y if GRKERNSEC_CONFIG_AUTO
53773+ depends on GRKERNSEC_CHROOT
53774+ help
53775+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
53776+ to a file descriptor of the chrooting process that points to a directory
53777+ outside the filesystem will be stopped. If the sysctl option
53778+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
53779+
53780+config GRKERNSEC_CHROOT_MKNOD
53781+ bool "Deny mknod"
53782+ default y if GRKERNSEC_CONFIG_AUTO
53783+ depends on GRKERNSEC_CHROOT
53784+ help
53785+ If you say Y here, processes inside a chroot will not be allowed to
53786+ mknod. The problem with using mknod inside a chroot is that it
53787+ would allow an attacker to create a device entry that is the same
53788+ as one on the physical root of your system, which could range from
53789+ anything from the console device to a device for your harddrive (which
53790+ they could then use to wipe the drive or steal data). It is recommended
53791+ that you say Y here, unless you run into software incompatibilities.
53792+ If the sysctl option is enabled, a sysctl option with name
53793+ "chroot_deny_mknod" is created.
53794+
53795+config GRKERNSEC_CHROOT_SHMAT
53796+ bool "Deny shmat() out of chroot"
53797+ default y if GRKERNSEC_CONFIG_AUTO
53798+ depends on GRKERNSEC_CHROOT
53799+ help
53800+ If you say Y here, processes inside a chroot will not be able to attach
53801+ to shared memory segments that were created outside of the chroot jail.
53802+ It is recommended that you say Y here. If the sysctl option is enabled,
53803+ a sysctl option with name "chroot_deny_shmat" is created.
53804+
53805+config GRKERNSEC_CHROOT_UNIX
53806+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
53807+ default y if GRKERNSEC_CONFIG_AUTO
53808+ depends on GRKERNSEC_CHROOT
53809+ help
53810+ If you say Y here, processes inside a chroot will not be able to
53811+ connect to abstract (meaning not belonging to a filesystem) Unix
53812+ domain sockets that were bound outside of a chroot. It is recommended
53813+ that you say Y here. If the sysctl option is enabled, a sysctl option
53814+ with name "chroot_deny_unix" is created.
53815+
53816+config GRKERNSEC_CHROOT_FINDTASK
53817+ bool "Protect outside processes"
53818+ default y if GRKERNSEC_CONFIG_AUTO
53819+ depends on GRKERNSEC_CHROOT
53820+ help
53821+ If you say Y here, processes inside a chroot will not be able to
53822+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
53823+ getsid, or view any process outside of the chroot. If the sysctl
53824+ option is enabled, a sysctl option with name "chroot_findtask" is
53825+ created.
53826+
53827+config GRKERNSEC_CHROOT_NICE
53828+ bool "Restrict priority changes"
53829+ default y if GRKERNSEC_CONFIG_AUTO
53830+ depends on GRKERNSEC_CHROOT
53831+ help
53832+ If you say Y here, processes inside a chroot will not be able to raise
53833+ the priority of processes in the chroot, or alter the priority of
53834+ processes outside the chroot. This provides more security than simply
53835+ removing CAP_SYS_NICE from the process' capability set. If the
53836+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
53837+ is created.
53838+
53839+config GRKERNSEC_CHROOT_SYSCTL
53840+ bool "Deny sysctl writes"
53841+ default y if GRKERNSEC_CONFIG_AUTO
53842+ depends on GRKERNSEC_CHROOT
53843+ help
53844+ If you say Y here, an attacker in a chroot will not be able to
53845+ write to sysctl entries, either by sysctl(2) or through a /proc
53846+ interface. It is strongly recommended that you say Y here. If the
53847+ sysctl option is enabled, a sysctl option with name
53848+ "chroot_deny_sysctl" is created.
53849+
53850+config GRKERNSEC_CHROOT_CAPS
53851+ bool "Capability restrictions"
53852+ default y if GRKERNSEC_CONFIG_AUTO
53853+ depends on GRKERNSEC_CHROOT
53854+ help
53855+ If you say Y here, the capabilities on all processes within a
53856+ chroot jail will be lowered to stop module insertion, raw i/o,
53857+ system and net admin tasks, rebooting the system, modifying immutable
53858+ files, modifying IPC owned by another, and changing the system time.
53859+ This is left an option because it can break some apps. Disable this
53860+ if your chrooted apps are having problems performing those kinds of
53861+ tasks. If the sysctl option is enabled, a sysctl option with
53862+ name "chroot_caps" is created.
53863+
53864+endmenu
53865+menu "Kernel Auditing"
53866+depends on GRKERNSEC
53867+
53868+config GRKERNSEC_AUDIT_GROUP
53869+ bool "Single group for auditing"
53870+ help
53871+ If you say Y here, the exec and chdir logging features will only operate
53872+ on a group you specify. This option is recommended if you only want to
53873+ watch certain users instead of having a large amount of logs from the
53874+ entire system. If the sysctl option is enabled, a sysctl option with
53875+ name "audit_group" is created.
53876+
53877+config GRKERNSEC_AUDIT_GID
53878+ int "GID for auditing"
53879+ depends on GRKERNSEC_AUDIT_GROUP
53880+ default 1007
53881+
53882+config GRKERNSEC_EXECLOG
53883+ bool "Exec logging"
53884+ help
53885+ If you say Y here, all execve() calls will be logged (since the
53886+ other exec*() calls are frontends to execve(), all execution
53887+ will be logged). Useful for shell-servers that like to keep track
53888+ of their users. If the sysctl option is enabled, a sysctl option with
53889+ name "exec_logging" is created.
53890+ WARNING: This option when enabled will produce a LOT of logs, especially
53891+ on an active system.
53892+
53893+config GRKERNSEC_RESLOG
53894+ bool "Resource logging"
53895+ default y if GRKERNSEC_CONFIG_AUTO
53896+ help
53897+ If you say Y here, all attempts to overstep resource limits will
53898+ be logged with the resource name, the requested size, and the current
53899+ limit. It is highly recommended that you say Y here. If the sysctl
53900+ option is enabled, a sysctl option with name "resource_logging" is
53901+ created. If the RBAC system is enabled, the sysctl value is ignored.
53902+
53903+config GRKERNSEC_CHROOT_EXECLOG
53904+ bool "Log execs within chroot"
53905+ help
53906+ If you say Y here, all executions inside a chroot jail will be logged
53907+ to syslog. This can cause a large amount of logs if certain
53908+ applications (eg. djb's daemontools) are installed on the system, and
53909+ is therefore left as an option. If the sysctl option is enabled, a
53910+ sysctl option with name "chroot_execlog" is created.
53911+
53912+config GRKERNSEC_AUDIT_PTRACE
53913+ bool "Ptrace logging"
53914+ help
53915+ If you say Y here, all attempts to attach to a process via ptrace
53916+ will be logged. If the sysctl option is enabled, a sysctl option
53917+ with name "audit_ptrace" is created.
53918+
53919+config GRKERNSEC_AUDIT_CHDIR
53920+ bool "Chdir logging"
53921+ help
53922+ If you say Y here, all chdir() calls will be logged. If the sysctl
53923+ option is enabled, a sysctl option with name "audit_chdir" is created.
53924+
53925+config GRKERNSEC_AUDIT_MOUNT
53926+ bool "(Un)Mount logging"
53927+ help
53928+ If you say Y here, all mounts and unmounts will be logged. If the
53929+ sysctl option is enabled, a sysctl option with name "audit_mount" is
53930+ created.
53931+
53932+config GRKERNSEC_SIGNAL
53933+ bool "Signal logging"
53934+ default y if GRKERNSEC_CONFIG_AUTO
53935+ help
53936+ If you say Y here, certain important signals will be logged, such as
53937+ SIGSEGV, which will as a result inform you of when a error in a program
53938+ occurred, which in some cases could mean a possible exploit attempt.
53939+ If the sysctl option is enabled, a sysctl option with name
53940+ "signal_logging" is created.
53941+
53942+config GRKERNSEC_FORKFAIL
53943+ bool "Fork failure logging"
53944+ help
53945+ If you say Y here, all failed fork() attempts will be logged.
53946+ This could suggest a fork bomb, or someone attempting to overstep
53947+ their process limit. If the sysctl option is enabled, a sysctl option
53948+ with name "forkfail_logging" is created.
53949+
53950+config GRKERNSEC_TIME
53951+ bool "Time change logging"
53952+ default y if GRKERNSEC_CONFIG_AUTO
53953+ help
53954+ If you say Y here, any changes of the system clock will be logged.
53955+ If the sysctl option is enabled, a sysctl option with name
53956+ "timechange_logging" is created.
53957+
53958+config GRKERNSEC_PROC_IPADDR
53959+ bool "/proc/<pid>/ipaddr support"
53960+ default y if GRKERNSEC_CONFIG_AUTO
53961+ help
53962+ If you say Y here, a new entry will be added to each /proc/<pid>
53963+ directory that contains the IP address of the person using the task.
53964+ The IP is carried across local TCP and AF_UNIX stream sockets.
53965+ This information can be useful for IDS/IPSes to perform remote response
53966+ to a local attack. The entry is readable by only the owner of the
53967+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
53968+ the RBAC system), and thus does not create privacy concerns.
53969+
53970+config GRKERNSEC_RWXMAP_LOG
53971+ bool 'Denied RWX mmap/mprotect logging'
53972+ default y if GRKERNSEC_CONFIG_AUTO
53973+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
53974+ help
53975+ If you say Y here, calls to mmap() and mprotect() with explicit
53976+ usage of PROT_WRITE and PROT_EXEC together will be logged when
53977+ denied by the PAX_MPROTECT feature. If the sysctl option is
53978+ enabled, a sysctl option with name "rwxmap_logging" is created.
53979+
53980+config GRKERNSEC_AUDIT_TEXTREL
53981+ bool 'ELF text relocations logging (READ HELP)'
53982+ depends on PAX_MPROTECT
53983+ help
53984+ If you say Y here, text relocations will be logged with the filename
53985+ of the offending library or binary. The purpose of the feature is
53986+ to help Linux distribution developers get rid of libraries and
53987+ binaries that need text relocations which hinder the future progress
53988+ of PaX. Only Linux distribution developers should say Y here, and
53989+ never on a production machine, as this option creates an information
53990+ leak that could aid an attacker in defeating the randomization of
53991+ a single memory region. If the sysctl option is enabled, a sysctl
53992+ option with name "audit_textrel" is created.
53993+
53994+endmenu
53995+
53996+menu "Executable Protections"
53997+depends on GRKERNSEC
53998+
53999+config GRKERNSEC_DMESG
54000+ bool "Dmesg(8) restriction"
54001+ default y if GRKERNSEC_CONFIG_AUTO
54002+ help
54003+ If you say Y here, non-root users will not be able to use dmesg(8)
54004+ to view the contents of the kernel's circular log buffer.
54005+ The kernel's log buffer often contains kernel addresses and other
54006+ identifying information useful to an attacker in fingerprinting a
54007+ system for a targeted exploit.
54008+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
54009+ created.
54010+
54011+config GRKERNSEC_HARDEN_PTRACE
54012+ bool "Deter ptrace-based process snooping"
54013+ default y if GRKERNSEC_CONFIG_AUTO
54014+ help
54015+ If you say Y here, TTY sniffers and other malicious monitoring
54016+ programs implemented through ptrace will be defeated. If you
54017+ have been using the RBAC system, this option has already been
54018+ enabled for several years for all users, with the ability to make
54019+ fine-grained exceptions.
54020+
54021+ This option only affects the ability of non-root users to ptrace
54022+ processes that are not a descendent of the ptracing process.
54023+ This means that strace ./binary and gdb ./binary will still work,
54024+ but attaching to arbitrary processes will not. If the sysctl
54025+ option is enabled, a sysctl option with name "harden_ptrace" is
54026+ created.
54027+
54028+config GRKERNSEC_PTRACE_READEXEC
54029+ bool "Require read access to ptrace sensitive binaries"
54030+ default y if GRKERNSEC_CONFIG_AUTO
54031+ help
54032+ If you say Y here, unprivileged users will not be able to ptrace unreadable
54033+ binaries. This option is useful in environments that
54034+ remove the read bits (e.g. file mode 4711) from suid binaries to
54035+ prevent infoleaking of their contents. This option adds
54036+ consistency to the use of that file mode, as the binary could normally
54037+ be read out when run without privileges while ptracing.
54038+
54039+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
54040+ is created.
54041+
54042+config GRKERNSEC_SETXID
54043+ bool "Enforce consistent multithreaded privileges"
54044+ default y if GRKERNSEC_CONFIG_AUTO
54045+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
54046+ help
54047+ If you say Y here, a change from a root uid to a non-root uid
54048+ in a multithreaded application will cause the resulting uids,
54049+ gids, supplementary groups, and capabilities in that thread
54050+ to be propagated to the other threads of the process. In most
54051+ cases this is unnecessary, as glibc will emulate this behavior
54052+ on behalf of the application. Other libcs do not act in the
54053+ same way, allowing the other threads of the process to continue
54054+ running with root privileges. If the sysctl option is enabled,
54055+ a sysctl option with name "consistent_setxid" is created.
54056+
54057+config GRKERNSEC_TPE
54058+ bool "Trusted Path Execution (TPE)"
54059+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
54060+ help
54061+ If you say Y here, you will be able to choose a gid to add to the
54062+ supplementary groups of users you want to mark as "untrusted."
54063+ These users will not be able to execute any files that are not in
54064+ root-owned directories writable only by root. If the sysctl option
54065+ is enabled, a sysctl option with name "tpe" is created.
54066+
54067+config GRKERNSEC_TPE_ALL
54068+ bool "Partially restrict all non-root users"
54069+ depends on GRKERNSEC_TPE
54070+ help
54071+ If you say Y here, all non-root users will be covered under
54072+ a weaker TPE restriction. This is separate from, and in addition to,
54073+ the main TPE options that you have selected elsewhere. Thus, if a
54074+ "trusted" GID is chosen, this restriction applies to even that GID.
54075+ Under this restriction, all non-root users will only be allowed to
54076+ execute files in directories they own that are not group or
54077+ world-writable, or in directories owned by root and writable only by
54078+ root. If the sysctl option is enabled, a sysctl option with name
54079+ "tpe_restrict_all" is created.
54080+
54081+config GRKERNSEC_TPE_INVERT
54082+ bool "Invert GID option"
54083+ depends on GRKERNSEC_TPE
54084+ help
54085+ If you say Y here, the group you specify in the TPE configuration will
54086+ decide what group TPE restrictions will be *disabled* for. This
54087+ option is useful if you want TPE restrictions to be applied to most
54088+ users on the system. If the sysctl option is enabled, a sysctl option
54089+ with name "tpe_invert" is created. Unlike other sysctl options, this
54090+ entry will default to on for backward-compatibility.
54091+
54092+config GRKERNSEC_TPE_GID
54093+ int
54094+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
54095+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
54096+
54097+config GRKERNSEC_TPE_UNTRUSTED_GID
54098+ int "GID for TPE-untrusted users"
54099+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
54100+ default 1005
54101+ help
54102+ Setting this GID determines what group TPE restrictions will be
54103+ *enabled* for. If the sysctl option is enabled, a sysctl option
54104+ with name "tpe_gid" is created.
54105+
54106+config GRKERNSEC_TPE_TRUSTED_GID
54107+ int "GID for TPE-trusted users"
54108+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
54109+ default 1005
54110+ help
54111+ Setting this GID determines what group TPE restrictions will be
54112+ *disabled* for. If the sysctl option is enabled, a sysctl option
54113+ with name "tpe_gid" is created.
54114+
54115+endmenu
54116+menu "Network Protections"
54117+depends on GRKERNSEC
54118+
54119+config GRKERNSEC_RANDNET
54120+ bool "Larger entropy pools"
54121+ default y if GRKERNSEC_CONFIG_AUTO
54122+ help
54123+ If you say Y here, the entropy pools used for many features of Linux
54124+ and grsecurity will be doubled in size. Since several grsecurity
54125+ features use additional randomness, it is recommended that you say Y
54126+ here. Saying Y here has a similar effect as modifying
54127+ /proc/sys/kernel/random/poolsize.
54128+
54129+config GRKERNSEC_BLACKHOLE
54130+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
54131+ default y if GRKERNSEC_CONFIG_AUTO
54132+ depends on NET
54133+ help
54134+ If you say Y here, neither TCP resets nor ICMP
54135+ destination-unreachable packets will be sent in response to packets
54136+ sent to ports for which no associated listening process exists.
54137+ This feature supports both IPV4 and IPV6 and exempts the
54138+ loopback interface from blackholing. Enabling this feature
54139+ makes a host more resilient to DoS attacks and reduces network
54140+ visibility against scanners.
54141+
54142+ The blackhole feature as-implemented is equivalent to the FreeBSD
54143+ blackhole feature, as it prevents RST responses to all packets, not
54144+ just SYNs. Under most application behavior this causes no
54145+ problems, but applications (like haproxy) may not close certain
54146+ connections in a way that cleanly terminates them on the remote
54147+ end, leaving the remote host in LAST_ACK state. Because of this
54148+ side-effect and to prevent intentional LAST_ACK DoSes, this
54149+ feature also adds automatic mitigation against such attacks.
54150+ The mitigation drastically reduces the amount of time a socket
54151+ can spend in LAST_ACK state. If you're using haproxy and not
54152+ all servers it connects to have this option enabled, consider
54153+ disabling this feature on the haproxy host.
54154+
54155+ If the sysctl option is enabled, two sysctl options with names
54156+ "ip_blackhole" and "lastack_retries" will be created.
54157+ While "ip_blackhole" takes the standard zero/non-zero on/off
54158+ toggle, "lastack_retries" uses the same kinds of values as
54159+ "tcp_retries1" and "tcp_retries2". The default value of 4
54160+ prevents a socket from lasting more than 45 seconds in LAST_ACK
54161+ state.
54162+
54163+config GRKERNSEC_NO_SIMULT_CONNECT
54164+ bool "Disable TCP Simultaneous Connect"
54165+ default y if GRKERNSEC_CONFIG_AUTO
54166+ depends on NET
54167+ help
54168+ If you say Y here, a feature by Willy Tarreau will be enabled that
54169+ removes a weakness in Linux's strict implementation of TCP that
54170+ allows two clients to connect to each other without either entering
54171+ a listening state. The weakness allows an attacker to easily prevent
54172+ a client from connecting to a known server provided the source port
54173+ for the connection is guessed correctly.
54174+
54175+ As the weakness could be used to prevent an antivirus or IPS from
54176+ fetching updates, or prevent an SSL gateway from fetching a CRL,
54177+ it should be eliminated by enabling this option. Though Linux is
54178+ one of few operating systems supporting simultaneous connect, it
54179+ has no legitimate use in practice and is rarely supported by firewalls.
54180+
54181+config GRKERNSEC_SOCKET
54182+ bool "Socket restrictions"
54183+ depends on NET
54184+ help
54185+ If you say Y here, you will be able to choose from several options.
54186+ If you assign a GID on your system and add it to the supplementary
54187+ groups of users you want to restrict socket access to, this patch
54188+ will perform up to three things, based on the option(s) you choose.
54189+
54190+config GRKERNSEC_SOCKET_ALL
54191+ bool "Deny any sockets to group"
54192+ depends on GRKERNSEC_SOCKET
54193+ help
54194+ If you say Y here, you will be able to choose a GID of whose users will
54195+ be unable to connect to other hosts from your machine or run server
54196+ applications from your machine. If the sysctl option is enabled, a
54197+ sysctl option with name "socket_all" is created.
54198+
54199+config GRKERNSEC_SOCKET_ALL_GID
54200+ int "GID to deny all sockets for"
54201+ depends on GRKERNSEC_SOCKET_ALL
54202+ default 1004
54203+ help
54204+ Here you can choose the GID to disable socket access for. Remember to
54205+ add the users you want socket access disabled for to the GID
54206+ specified here. If the sysctl option is enabled, a sysctl option
54207+ with name "socket_all_gid" is created.
54208+
54209+config GRKERNSEC_SOCKET_CLIENT
54210+ bool "Deny client sockets to group"
54211+ depends on GRKERNSEC_SOCKET
54212+ help
54213+ If you say Y here, you will be able to choose a GID of whose users will
54214+ be unable to connect to other hosts from your machine, but will be
54215+ able to run servers. If this option is enabled, all users in the group
54216+ you specify will have to use passive mode when initiating ftp transfers
54217+ from the shell on your machine. If the sysctl option is enabled, a
54218+ sysctl option with name "socket_client" is created.
54219+
54220+config GRKERNSEC_SOCKET_CLIENT_GID
54221+ int "GID to deny client sockets for"
54222+ depends on GRKERNSEC_SOCKET_CLIENT
54223+ default 1003
54224+ help
54225+ Here you can choose the GID to disable client socket access for.
54226+ Remember to add the users you want client socket access disabled for to
54227+ the GID specified here. If the sysctl option is enabled, a sysctl
54228+ option with name "socket_client_gid" is created.
54229+
54230+config GRKERNSEC_SOCKET_SERVER
54231+ bool "Deny server sockets to group"
54232+ depends on GRKERNSEC_SOCKET
54233+ help
54234+ If you say Y here, you will be able to choose a GID of whose users will
54235+ be unable to run server applications from your machine. If the sysctl
54236+ option is enabled, a sysctl option with name "socket_server" is created.
54237+
54238+config GRKERNSEC_SOCKET_SERVER_GID
54239+ int "GID to deny server sockets for"
54240+ depends on GRKERNSEC_SOCKET_SERVER
54241+ default 1002
54242+ help
54243+ Here you can choose the GID to disable server socket access for.
54244+ Remember to add the users you want server socket access disabled for to
54245+ the GID specified here. If the sysctl option is enabled, a sysctl
54246+ option with name "socket_server_gid" is created.
54247+
54248+endmenu
54249+menu "Sysctl Support"
54250+depends on GRKERNSEC && SYSCTL
54251+
54252+config GRKERNSEC_SYSCTL
54253+ bool "Sysctl support"
54254+ default y if GRKERNSEC_CONFIG_AUTO
54255+ help
54256+ If you say Y here, you will be able to change the options that
54257+ grsecurity runs with at bootup, without having to recompile your
54258+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
54259+ to enable (1) or disable (0) various features. All the sysctl entries
54260+ are mutable until the "grsec_lock" entry is set to a non-zero value.
54261+ All features enabled in the kernel configuration are disabled at boot
54262+ if you do not say Y to the "Turn on features by default" option.
54263+ All options should be set at startup, and the grsec_lock entry should
54264+ be set to a non-zero value after all the options are set.
54265+ *THIS IS EXTREMELY IMPORTANT*
54266+
54267+config GRKERNSEC_SYSCTL_DISTRO
54268+ bool "Extra sysctl support for distro makers (READ HELP)"
54269+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
54270+ help
54271+ If you say Y here, additional sysctl options will be created
54272+ for features that affect processes running as root. Therefore,
54273+ it is critical when using this option that the grsec_lock entry be
54274+ enabled after boot. Only distros with prebuilt kernel packages
54275+ with this option enabled that can ensure grsec_lock is enabled
54276+ after boot should use this option.
54277+ *Failure to set grsec_lock after boot makes all grsec features
54278+ this option covers useless*
54279+
54280+ Currently this option creates the following sysctl entries:
54281+ "Disable Privileged I/O": "disable_priv_io"
54282+
54283+config GRKERNSEC_SYSCTL_ON
54284+ bool "Turn on features by default"
54285+ default y if GRKERNSEC_CONFIG_AUTO
54286+ depends on GRKERNSEC_SYSCTL
54287+ help
54288+ If you say Y here, instead of having all features enabled in the
54289+ kernel configuration disabled at boot time, the features will be
54290+ enabled at boot time. It is recommended you say Y here unless
54291+ there is some reason you would want all sysctl-tunable features to
54292+ be disabled by default. As mentioned elsewhere, it is important
54293+ to enable the grsec_lock entry once you have finished modifying
54294+ the sysctl entries.
54295+
54296+endmenu
54297+menu "Logging Options"
54298+depends on GRKERNSEC
54299+
54300+config GRKERNSEC_FLOODTIME
54301+ int "Seconds in between log messages (minimum)"
54302+ default 10
54303+ help
54304+ This option allows you to enforce the number of seconds between
54305+ grsecurity log messages. The default should be suitable for most
54306+ people, however, if you choose to change it, choose a value small enough
54307+ to allow informative logs to be produced, but large enough to
54308+ prevent flooding.
54309+
54310+config GRKERNSEC_FLOODBURST
54311+ int "Number of messages in a burst (maximum)"
54312+ default 6
54313+ help
54314+ This option allows you to choose the maximum number of messages allowed
54315+ within the flood time interval you chose in a separate option. The
54316+ default should be suitable for most people, however if you find that
54317+ many of your logs are being interpreted as flooding, you may want to
54318+ raise this value.
54319+
54320+endmenu
54321diff --git a/grsecurity/Makefile b/grsecurity/Makefile
54322new file mode 100644
54323index 0000000..1b9afa9
54324--- /dev/null
54325+++ b/grsecurity/Makefile
54326@@ -0,0 +1,38 @@
54327+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
54328+# during 2001-2009 it has been completely redesigned by Brad Spengler
54329+# into an RBAC system
54330+#
54331+# All code in this directory and various hooks inserted throughout the kernel
54332+# are copyright Brad Spengler - Open Source Security, Inc., and released
54333+# under the GPL v2 or higher
54334+
54335+KBUILD_CFLAGS += -Werror
54336+
54337+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
54338+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
54339+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
54340+
54341+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
54342+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
54343+ gracl_learn.o grsec_log.o
54344+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
54345+
54346+ifdef CONFIG_NET
54347+obj-y += grsec_sock.o
54348+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
54349+endif
54350+
54351+ifndef CONFIG_GRKERNSEC
54352+obj-y += grsec_disabled.o
54353+endif
54354+
54355+ifdef CONFIG_GRKERNSEC_HIDESYM
54356+extra-y := grsec_hidesym.o
54357+$(obj)/grsec_hidesym.o:
54358+ @-chmod -f 500 /boot
54359+ @-chmod -f 500 /lib/modules
54360+ @-chmod -f 500 /lib64/modules
54361+ @-chmod -f 500 /lib32/modules
54362+ @-chmod -f 700 .
54363+ @echo ' grsec: protected kernel image paths'
54364+endif
54365diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
54366new file mode 100644
54367index 0000000..69e1320
54368--- /dev/null
54369+++ b/grsecurity/gracl.c
54370@@ -0,0 +1,4019 @@
54371+#include <linux/kernel.h>
54372+#include <linux/module.h>
54373+#include <linux/sched.h>
54374+#include <linux/mm.h>
54375+#include <linux/file.h>
54376+#include <linux/fs.h>
54377+#include <linux/namei.h>
54378+#include <linux/mount.h>
54379+#include <linux/tty.h>
54380+#include <linux/proc_fs.h>
54381+#include <linux/lglock.h>
54382+#include <linux/slab.h>
54383+#include <linux/vmalloc.h>
54384+#include <linux/types.h>
54385+#include <linux/sysctl.h>
54386+#include <linux/netdevice.h>
54387+#include <linux/ptrace.h>
54388+#include <linux/gracl.h>
54389+#include <linux/gralloc.h>
54390+#include <linux/security.h>
54391+#include <linux/grinternal.h>
54392+#include <linux/pid_namespace.h>
54393+#include <linux/stop_machine.h>
54394+#include <linux/fdtable.h>
54395+#include <linux/percpu.h>
54396+#include <linux/lglock.h>
54397+#include <linux/hugetlb.h>
54398+#include "../fs/mount.h"
54399+
54400+#include <asm/uaccess.h>
54401+#include <asm/errno.h>
54402+#include <asm/mman.h>
54403+
54404+extern struct lglock vfsmount_lock;
54405+
54406+static struct acl_role_db acl_role_set;
54407+static struct name_db name_set;
54408+static struct inodev_db inodev_set;
54409+
54410+/* for keeping track of userspace pointers used for subjects, so we
54411+ can share references in the kernel as well
54412+*/
54413+
54414+static struct path real_root;
54415+
54416+static struct acl_subj_map_db subj_map_set;
54417+
54418+static struct acl_role_label *default_role;
54419+
54420+static struct acl_role_label *role_list;
54421+
54422+static u16 acl_sp_role_value;
54423+
54424+extern char *gr_shared_page[4];
54425+static DEFINE_MUTEX(gr_dev_mutex);
54426+DEFINE_RWLOCK(gr_inode_lock);
54427+
54428+struct gr_arg *gr_usermode;
54429+
54430+static unsigned int gr_status __read_only = GR_STATUS_INIT;
54431+
54432+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
54433+extern void gr_clear_learn_entries(void);
54434+
54435+unsigned char *gr_system_salt;
54436+unsigned char *gr_system_sum;
54437+
54438+static struct sprole_pw **acl_special_roles = NULL;
54439+static __u16 num_sprole_pws = 0;
54440+
54441+static struct acl_role_label *kernel_role = NULL;
54442+
54443+static unsigned int gr_auth_attempts = 0;
54444+static unsigned long gr_auth_expires = 0UL;
54445+
54446+#ifdef CONFIG_NET
54447+extern struct vfsmount *sock_mnt;
54448+#endif
54449+
54450+extern struct vfsmount *pipe_mnt;
54451+extern struct vfsmount *shm_mnt;
54452+
54453+#ifdef CONFIG_HUGETLBFS
54454+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
54455+#endif
54456+
54457+static struct acl_object_label *fakefs_obj_rw;
54458+static struct acl_object_label *fakefs_obj_rwx;
54459+
54460+extern int gr_init_uidset(void);
54461+extern void gr_free_uidset(void);
54462+extern void gr_remove_uid(uid_t uid);
54463+extern int gr_find_uid(uid_t uid);
54464+
54465+__inline__ int
54466+gr_acl_is_enabled(void)
54467+{
54468+ return (gr_status & GR_READY);
54469+}
54470+
54471+#ifdef CONFIG_BTRFS_FS
54472+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
54473+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
54474+#endif
54475+
54476+static inline dev_t __get_dev(const struct dentry *dentry)
54477+{
54478+#ifdef CONFIG_BTRFS_FS
54479+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
54480+ return get_btrfs_dev_from_inode(dentry->d_inode);
54481+ else
54482+#endif
54483+ return dentry->d_inode->i_sb->s_dev;
54484+}
54485+
54486+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
54487+{
54488+ return __get_dev(dentry);
54489+}
54490+
54491+static char gr_task_roletype_to_char(struct task_struct *task)
54492+{
54493+ switch (task->role->roletype &
54494+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
54495+ GR_ROLE_SPECIAL)) {
54496+ case GR_ROLE_DEFAULT:
54497+ return 'D';
54498+ case GR_ROLE_USER:
54499+ return 'U';
54500+ case GR_ROLE_GROUP:
54501+ return 'G';
54502+ case GR_ROLE_SPECIAL:
54503+ return 'S';
54504+ }
54505+
54506+ return 'X';
54507+}
54508+
54509+char gr_roletype_to_char(void)
54510+{
54511+ return gr_task_roletype_to_char(current);
54512+}
54513+
54514+__inline__ int
54515+gr_acl_tpe_check(void)
54516+{
54517+ if (unlikely(!(gr_status & GR_READY)))
54518+ return 0;
54519+ if (current->role->roletype & GR_ROLE_TPE)
54520+ return 1;
54521+ else
54522+ return 0;
54523+}
54524+
54525+int
54526+gr_handle_rawio(const struct inode *inode)
54527+{
54528+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54529+ if (inode && S_ISBLK(inode->i_mode) &&
54530+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
54531+ !capable(CAP_SYS_RAWIO))
54532+ return 1;
54533+#endif
54534+ return 0;
54535+}
54536+
54537+static int
54538+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
54539+{
54540+ if (likely(lena != lenb))
54541+ return 0;
54542+
54543+ return !memcmp(a, b, lena);
54544+}
54545+
54546+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
54547+{
54548+ *buflen -= namelen;
54549+ if (*buflen < 0)
54550+ return -ENAMETOOLONG;
54551+ *buffer -= namelen;
54552+ memcpy(*buffer, str, namelen);
54553+ return 0;
54554+}
54555+
54556+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
54557+{
54558+ return prepend(buffer, buflen, name->name, name->len);
54559+}
54560+
54561+static int prepend_path(const struct path *path, struct path *root,
54562+ char **buffer, int *buflen)
54563+{
54564+ struct dentry *dentry = path->dentry;
54565+ struct vfsmount *vfsmnt = path->mnt;
54566+ struct mount *mnt = real_mount(vfsmnt);
54567+ bool slash = false;
54568+ int error = 0;
54569+
54570+ while (dentry != root->dentry || vfsmnt != root->mnt) {
54571+ struct dentry * parent;
54572+
54573+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
54574+ /* Global root? */
54575+ if (!mnt_has_parent(mnt)) {
54576+ goto out;
54577+ }
54578+ dentry = mnt->mnt_mountpoint;
54579+ mnt = mnt->mnt_parent;
54580+ vfsmnt = &mnt->mnt;
54581+ continue;
54582+ }
54583+ parent = dentry->d_parent;
54584+ prefetch(parent);
54585+ spin_lock(&dentry->d_lock);
54586+ error = prepend_name(buffer, buflen, &dentry->d_name);
54587+ spin_unlock(&dentry->d_lock);
54588+ if (!error)
54589+ error = prepend(buffer, buflen, "/", 1);
54590+ if (error)
54591+ break;
54592+
54593+ slash = true;
54594+ dentry = parent;
54595+ }
54596+
54597+out:
54598+ if (!error && !slash)
54599+ error = prepend(buffer, buflen, "/", 1);
54600+
54601+ return error;
54602+}
54603+
54604+/* this must be called with vfsmount_lock and rename_lock held */
54605+
54606+static char *__our_d_path(const struct path *path, struct path *root,
54607+ char *buf, int buflen)
54608+{
54609+ char *res = buf + buflen;
54610+ int error;
54611+
54612+ prepend(&res, &buflen, "\0", 1);
54613+ error = prepend_path(path, root, &res, &buflen);
54614+ if (error)
54615+ return ERR_PTR(error);
54616+
54617+ return res;
54618+}
54619+
54620+static char *
54621+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
54622+{
54623+ char *retval;
54624+
54625+ retval = __our_d_path(path, root, buf, buflen);
54626+ if (unlikely(IS_ERR(retval)))
54627+ retval = strcpy(buf, "<path too long>");
54628+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
54629+ retval[1] = '\0';
54630+
54631+ return retval;
54632+}
54633+
54634+static char *
54635+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
54636+ char *buf, int buflen)
54637+{
54638+ struct path path;
54639+ char *res;
54640+
54641+ path.dentry = (struct dentry *)dentry;
54642+ path.mnt = (struct vfsmount *)vfsmnt;
54643+
54644+ /* we can use real_root.dentry, real_root.mnt, because this is only called
54645+ by the RBAC system */
54646+ res = gen_full_path(&path, &real_root, buf, buflen);
54647+
54648+ return res;
54649+}
54650+
54651+static char *
54652+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
54653+ char *buf, int buflen)
54654+{
54655+ char *res;
54656+ struct path path;
54657+ struct path root;
54658+ struct task_struct *reaper = init_pid_ns.child_reaper;
54659+
54660+ path.dentry = (struct dentry *)dentry;
54661+ path.mnt = (struct vfsmount *)vfsmnt;
54662+
54663+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
54664+ get_fs_root(reaper->fs, &root);
54665+
54666+ write_seqlock(&rename_lock);
54667+ br_read_lock(&vfsmount_lock);
54668+ res = gen_full_path(&path, &root, buf, buflen);
54669+ br_read_unlock(&vfsmount_lock);
54670+ write_sequnlock(&rename_lock);
54671+
54672+ path_put(&root);
54673+ return res;
54674+}
54675+
54676+static char *
54677+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
54678+{
54679+ char *ret;
54680+ write_seqlock(&rename_lock);
54681+ br_read_lock(&vfsmount_lock);
54682+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
54683+ PAGE_SIZE);
54684+ br_read_unlock(&vfsmount_lock);
54685+ write_sequnlock(&rename_lock);
54686+ return ret;
54687+}
54688+
54689+static char *
54690+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
54691+{
54692+ char *ret;
54693+ char *buf;
54694+ int buflen;
54695+
54696+ write_seqlock(&rename_lock);
54697+ br_read_lock(&vfsmount_lock);
54698+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54699+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
54700+ buflen = (int)(ret - buf);
54701+ if (buflen >= 5)
54702+ prepend(&ret, &buflen, "/proc", 5);
54703+ else
54704+ ret = strcpy(buf, "<path too long>");
54705+ br_read_unlock(&vfsmount_lock);
54706+ write_sequnlock(&rename_lock);
54707+ return ret;
54708+}
54709+
54710+char *
54711+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
54712+{
54713+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
54714+ PAGE_SIZE);
54715+}
54716+
54717+char *
54718+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
54719+{
54720+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54721+ PAGE_SIZE);
54722+}
54723+
54724+char *
54725+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
54726+{
54727+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
54728+ PAGE_SIZE);
54729+}
54730+
54731+char *
54732+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
54733+{
54734+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
54735+ PAGE_SIZE);
54736+}
54737+
54738+char *
54739+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
54740+{
54741+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
54742+ PAGE_SIZE);
54743+}
54744+
54745+__inline__ __u32
54746+to_gr_audit(const __u32 reqmode)
54747+{
54748+ /* masks off auditable permission flags, then shifts them to create
54749+ auditing flags, and adds the special case of append auditing if
54750+ we're requesting write */
54751+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
54752+}
54753+
54754+struct acl_subject_label *
54755+lookup_subject_map(const struct acl_subject_label *userp)
54756+{
54757+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
54758+ struct subject_map *match;
54759+
54760+ match = subj_map_set.s_hash[index];
54761+
54762+ while (match && match->user != userp)
54763+ match = match->next;
54764+
54765+ if (match != NULL)
54766+ return match->kernel;
54767+ else
54768+ return NULL;
54769+}
54770+
54771+static void
54772+insert_subj_map_entry(struct subject_map *subjmap)
54773+{
54774+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
54775+ struct subject_map **curr;
54776+
54777+ subjmap->prev = NULL;
54778+
54779+ curr = &subj_map_set.s_hash[index];
54780+ if (*curr != NULL)
54781+ (*curr)->prev = subjmap;
54782+
54783+ subjmap->next = *curr;
54784+ *curr = subjmap;
54785+
54786+ return;
54787+}
54788+
54789+static struct acl_role_label *
54790+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
54791+ const gid_t gid)
54792+{
54793+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
54794+ struct acl_role_label *match;
54795+ struct role_allowed_ip *ipp;
54796+ unsigned int x;
54797+ u32 curr_ip = task->signal->curr_ip;
54798+
54799+ task->signal->saved_ip = curr_ip;
54800+
54801+ match = acl_role_set.r_hash[index];
54802+
54803+ while (match) {
54804+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
54805+ for (x = 0; x < match->domain_child_num; x++) {
54806+ if (match->domain_children[x] == uid)
54807+ goto found;
54808+ }
54809+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
54810+ break;
54811+ match = match->next;
54812+ }
54813+found:
54814+ if (match == NULL) {
54815+ try_group:
54816+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
54817+ match = acl_role_set.r_hash[index];
54818+
54819+ while (match) {
54820+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
54821+ for (x = 0; x < match->domain_child_num; x++) {
54822+ if (match->domain_children[x] == gid)
54823+ goto found2;
54824+ }
54825+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
54826+ break;
54827+ match = match->next;
54828+ }
54829+found2:
54830+ if (match == NULL)
54831+ match = default_role;
54832+ if (match->allowed_ips == NULL)
54833+ return match;
54834+ else {
54835+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54836+ if (likely
54837+ ((ntohl(curr_ip) & ipp->netmask) ==
54838+ (ntohl(ipp->addr) & ipp->netmask)))
54839+ return match;
54840+ }
54841+ match = default_role;
54842+ }
54843+ } else if (match->allowed_ips == NULL) {
54844+ return match;
54845+ } else {
54846+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54847+ if (likely
54848+ ((ntohl(curr_ip) & ipp->netmask) ==
54849+ (ntohl(ipp->addr) & ipp->netmask)))
54850+ return match;
54851+ }
54852+ goto try_group;
54853+ }
54854+
54855+ return match;
54856+}
54857+
54858+struct acl_subject_label *
54859+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
54860+ const struct acl_role_label *role)
54861+{
54862+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54863+ struct acl_subject_label *match;
54864+
54865+ match = role->subj_hash[index];
54866+
54867+ while (match && (match->inode != ino || match->device != dev ||
54868+ (match->mode & GR_DELETED))) {
54869+ match = match->next;
54870+ }
54871+
54872+ if (match && !(match->mode & GR_DELETED))
54873+ return match;
54874+ else
54875+ return NULL;
54876+}
54877+
54878+struct acl_subject_label *
54879+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
54880+ const struct acl_role_label *role)
54881+{
54882+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54883+ struct acl_subject_label *match;
54884+
54885+ match = role->subj_hash[index];
54886+
54887+ while (match && (match->inode != ino || match->device != dev ||
54888+ !(match->mode & GR_DELETED))) {
54889+ match = match->next;
54890+ }
54891+
54892+ if (match && (match->mode & GR_DELETED))
54893+ return match;
54894+ else
54895+ return NULL;
54896+}
54897+
54898+static struct acl_object_label *
54899+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
54900+ const struct acl_subject_label *subj)
54901+{
54902+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
54903+ struct acl_object_label *match;
54904+
54905+ match = subj->obj_hash[index];
54906+
54907+ while (match && (match->inode != ino || match->device != dev ||
54908+ (match->mode & GR_DELETED))) {
54909+ match = match->next;
54910+ }
54911+
54912+ if (match && !(match->mode & GR_DELETED))
54913+ return match;
54914+ else
54915+ return NULL;
54916+}
54917+
54918+static struct acl_object_label *
54919+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
54920+ const struct acl_subject_label *subj)
54921+{
54922+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
54923+ struct acl_object_label *match;
54924+
54925+ match = subj->obj_hash[index];
54926+
54927+ while (match && (match->inode != ino || match->device != dev ||
54928+ !(match->mode & GR_DELETED))) {
54929+ match = match->next;
54930+ }
54931+
54932+ if (match && (match->mode & GR_DELETED))
54933+ return match;
54934+
54935+ match = subj->obj_hash[index];
54936+
54937+ while (match && (match->inode != ino || match->device != dev ||
54938+ (match->mode & GR_DELETED))) {
54939+ match = match->next;
54940+ }
54941+
54942+ if (match && !(match->mode & GR_DELETED))
54943+ return match;
54944+ else
54945+ return NULL;
54946+}
54947+
54948+static struct name_entry *
54949+lookup_name_entry(const char *name)
54950+{
54951+ unsigned int len = strlen(name);
54952+ unsigned int key = full_name_hash(name, len);
54953+ unsigned int index = key % name_set.n_size;
54954+ struct name_entry *match;
54955+
54956+ match = name_set.n_hash[index];
54957+
54958+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
54959+ match = match->next;
54960+
54961+ return match;
54962+}
54963+
54964+static struct name_entry *
54965+lookup_name_entry_create(const char *name)
54966+{
54967+ unsigned int len = strlen(name);
54968+ unsigned int key = full_name_hash(name, len);
54969+ unsigned int index = key % name_set.n_size;
54970+ struct name_entry *match;
54971+
54972+ match = name_set.n_hash[index];
54973+
54974+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
54975+ !match->deleted))
54976+ match = match->next;
54977+
54978+ if (match && match->deleted)
54979+ return match;
54980+
54981+ match = name_set.n_hash[index];
54982+
54983+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
54984+ match->deleted))
54985+ match = match->next;
54986+
54987+ if (match && !match->deleted)
54988+ return match;
54989+ else
54990+ return NULL;
54991+}
54992+
54993+static struct inodev_entry *
54994+lookup_inodev_entry(const ino_t ino, const dev_t dev)
54995+{
54996+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
54997+ struct inodev_entry *match;
54998+
54999+ match = inodev_set.i_hash[index];
55000+
55001+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
55002+ match = match->next;
55003+
55004+ return match;
55005+}
55006+
55007+static void
55008+insert_inodev_entry(struct inodev_entry *entry)
55009+{
55010+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
55011+ inodev_set.i_size);
55012+ struct inodev_entry **curr;
55013+
55014+ entry->prev = NULL;
55015+
55016+ curr = &inodev_set.i_hash[index];
55017+ if (*curr != NULL)
55018+ (*curr)->prev = entry;
55019+
55020+ entry->next = *curr;
55021+ *curr = entry;
55022+
55023+ return;
55024+}
55025+
55026+static void
55027+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
55028+{
55029+ unsigned int index =
55030+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
55031+ struct acl_role_label **curr;
55032+ struct acl_role_label *tmp, *tmp2;
55033+
55034+ curr = &acl_role_set.r_hash[index];
55035+
55036+ /* simple case, slot is empty, just set it to our role */
55037+ if (*curr == NULL) {
55038+ *curr = role;
55039+ } else {
55040+ /* example:
55041+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
55042+ 2 -> 3
55043+ */
55044+ /* first check to see if we can already be reached via this slot */
55045+ tmp = *curr;
55046+ while (tmp && tmp != role)
55047+ tmp = tmp->next;
55048+ if (tmp == role) {
55049+ /* we don't need to add ourselves to this slot's chain */
55050+ return;
55051+ }
55052+ /* we need to add ourselves to this chain, two cases */
55053+ if (role->next == NULL) {
55054+ /* simple case, append the current chain to our role */
55055+ role->next = *curr;
55056+ *curr = role;
55057+ } else {
55058+ /* 1 -> 2 -> 3 -> 4
55059+ 2 -> 3 -> 4
55060+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
55061+ */
55062+ /* trickier case: walk our role's chain until we find
55063+ the role for the start of the current slot's chain */
55064+ tmp = role;
55065+ tmp2 = *curr;
55066+ while (tmp->next && tmp->next != tmp2)
55067+ tmp = tmp->next;
55068+ if (tmp->next == tmp2) {
55069+ /* from example above, we found 3, so just
55070+ replace this slot's chain with ours */
55071+ *curr = role;
55072+ } else {
55073+ /* we didn't find a subset of our role's chain
55074+ in the current slot's chain, so append their
55075+ chain to ours, and set us as the first role in
55076+ the slot's chain
55077+
55078+ we could fold this case with the case above,
55079+ but making it explicit for clarity
55080+ */
55081+ tmp->next = tmp2;
55082+ *curr = role;
55083+ }
55084+ }
55085+ }
55086+
55087+ return;
55088+}
55089+
55090+static void
55091+insert_acl_role_label(struct acl_role_label *role)
55092+{
55093+ int i;
55094+
55095+ if (role_list == NULL) {
55096+ role_list = role;
55097+ role->prev = NULL;
55098+ } else {
55099+ role->prev = role_list;
55100+ role_list = role;
55101+ }
55102+
55103+ /* used for hash chains */
55104+ role->next = NULL;
55105+
55106+ if (role->roletype & GR_ROLE_DOMAIN) {
55107+ for (i = 0; i < role->domain_child_num; i++)
55108+ __insert_acl_role_label(role, role->domain_children[i]);
55109+ } else
55110+ __insert_acl_role_label(role, role->uidgid);
55111+}
55112+
55113+static int
55114+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
55115+{
55116+ struct name_entry **curr, *nentry;
55117+ struct inodev_entry *ientry;
55118+ unsigned int len = strlen(name);
55119+ unsigned int key = full_name_hash(name, len);
55120+ unsigned int index = key % name_set.n_size;
55121+
55122+ curr = &name_set.n_hash[index];
55123+
55124+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
55125+ curr = &((*curr)->next);
55126+
55127+ if (*curr != NULL)
55128+ return 1;
55129+
55130+ nentry = acl_alloc(sizeof (struct name_entry));
55131+ if (nentry == NULL)
55132+ return 0;
55133+ ientry = acl_alloc(sizeof (struct inodev_entry));
55134+ if (ientry == NULL)
55135+ return 0;
55136+ ientry->nentry = nentry;
55137+
55138+ nentry->key = key;
55139+ nentry->name = name;
55140+ nentry->inode = inode;
55141+ nentry->device = device;
55142+ nentry->len = len;
55143+ nentry->deleted = deleted;
55144+
55145+ nentry->prev = NULL;
55146+ curr = &name_set.n_hash[index];
55147+ if (*curr != NULL)
55148+ (*curr)->prev = nentry;
55149+ nentry->next = *curr;
55150+ *curr = nentry;
55151+
55152+ /* insert us into the table searchable by inode/dev */
55153+ insert_inodev_entry(ientry);
55154+
55155+ return 1;
55156+}
55157+
55158+static void
55159+insert_acl_obj_label(struct acl_object_label *obj,
55160+ struct acl_subject_label *subj)
55161+{
55162+ unsigned int index =
55163+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
55164+ struct acl_object_label **curr;
55165+
55166+
55167+ obj->prev = NULL;
55168+
55169+ curr = &subj->obj_hash[index];
55170+ if (*curr != NULL)
55171+ (*curr)->prev = obj;
55172+
55173+ obj->next = *curr;
55174+ *curr = obj;
55175+
55176+ return;
55177+}
55178+
55179+static void
55180+insert_acl_subj_label(struct acl_subject_label *obj,
55181+ struct acl_role_label *role)
55182+{
55183+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
55184+ struct acl_subject_label **curr;
55185+
55186+ obj->prev = NULL;
55187+
55188+ curr = &role->subj_hash[index];
55189+ if (*curr != NULL)
55190+ (*curr)->prev = obj;
55191+
55192+ obj->next = *curr;
55193+ *curr = obj;
55194+
55195+ return;
55196+}
55197+
55198+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
55199+
55200+static void *
55201+create_table(__u32 * len, int elementsize)
55202+{
55203+ unsigned int table_sizes[] = {
55204+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
55205+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
55206+ 4194301, 8388593, 16777213, 33554393, 67108859
55207+ };
55208+ void *newtable = NULL;
55209+ unsigned int pwr = 0;
55210+
55211+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
55212+ table_sizes[pwr] <= *len)
55213+ pwr++;
55214+
55215+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
55216+ return newtable;
55217+
55218+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
55219+ newtable =
55220+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
55221+ else
55222+ newtable = vmalloc(table_sizes[pwr] * elementsize);
55223+
55224+ *len = table_sizes[pwr];
55225+
55226+ return newtable;
55227+}
55228+
55229+static int
55230+init_variables(const struct gr_arg *arg)
55231+{
55232+ struct task_struct *reaper = init_pid_ns.child_reaper;
55233+ unsigned int stacksize;
55234+
55235+ subj_map_set.s_size = arg->role_db.num_subjects;
55236+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
55237+ name_set.n_size = arg->role_db.num_objects;
55238+ inodev_set.i_size = arg->role_db.num_objects;
55239+
55240+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
55241+ !name_set.n_size || !inodev_set.i_size)
55242+ return 1;
55243+
55244+ if (!gr_init_uidset())
55245+ return 1;
55246+
55247+ /* set up the stack that holds allocation info */
55248+
55249+ stacksize = arg->role_db.num_pointers + 5;
55250+
55251+ if (!acl_alloc_stack_init(stacksize))
55252+ return 1;
55253+
55254+ /* grab reference for the real root dentry and vfsmount */
55255+ get_fs_root(reaper->fs, &real_root);
55256+
55257+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55258+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
55259+#endif
55260+
55261+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
55262+ if (fakefs_obj_rw == NULL)
55263+ return 1;
55264+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
55265+
55266+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
55267+ if (fakefs_obj_rwx == NULL)
55268+ return 1;
55269+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
55270+
55271+ subj_map_set.s_hash =
55272+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
55273+ acl_role_set.r_hash =
55274+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
55275+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
55276+ inodev_set.i_hash =
55277+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
55278+
55279+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
55280+ !name_set.n_hash || !inodev_set.i_hash)
55281+ return 1;
55282+
55283+ memset(subj_map_set.s_hash, 0,
55284+ sizeof(struct subject_map *) * subj_map_set.s_size);
55285+ memset(acl_role_set.r_hash, 0,
55286+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
55287+ memset(name_set.n_hash, 0,
55288+ sizeof (struct name_entry *) * name_set.n_size);
55289+ memset(inodev_set.i_hash, 0,
55290+ sizeof (struct inodev_entry *) * inodev_set.i_size);
55291+
55292+ return 0;
55293+}
55294+
55295+/* free information not needed after startup
55296+ currently contains user->kernel pointer mappings for subjects
55297+*/
55298+
55299+static void
55300+free_init_variables(void)
55301+{
55302+ __u32 i;
55303+
55304+ if (subj_map_set.s_hash) {
55305+ for (i = 0; i < subj_map_set.s_size; i++) {
55306+ if (subj_map_set.s_hash[i]) {
55307+ kfree(subj_map_set.s_hash[i]);
55308+ subj_map_set.s_hash[i] = NULL;
55309+ }
55310+ }
55311+
55312+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
55313+ PAGE_SIZE)
55314+ kfree(subj_map_set.s_hash);
55315+ else
55316+ vfree(subj_map_set.s_hash);
55317+ }
55318+
55319+ return;
55320+}
55321+
55322+static void
55323+free_variables(void)
55324+{
55325+ struct acl_subject_label *s;
55326+ struct acl_role_label *r;
55327+ struct task_struct *task, *task2;
55328+ unsigned int x;
55329+
55330+ gr_clear_learn_entries();
55331+
55332+ read_lock(&tasklist_lock);
55333+ do_each_thread(task2, task) {
55334+ task->acl_sp_role = 0;
55335+ task->acl_role_id = 0;
55336+ task->acl = NULL;
55337+ task->role = NULL;
55338+ } while_each_thread(task2, task);
55339+ read_unlock(&tasklist_lock);
55340+
55341+ /* release the reference to the real root dentry and vfsmount */
55342+ path_put(&real_root);
55343+ memset(&real_root, 0, sizeof(real_root));
55344+
55345+ /* free all object hash tables */
55346+
55347+ FOR_EACH_ROLE_START(r)
55348+ if (r->subj_hash == NULL)
55349+ goto next_role;
55350+ FOR_EACH_SUBJECT_START(r, s, x)
55351+ if (s->obj_hash == NULL)
55352+ break;
55353+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
55354+ kfree(s->obj_hash);
55355+ else
55356+ vfree(s->obj_hash);
55357+ FOR_EACH_SUBJECT_END(s, x)
55358+ FOR_EACH_NESTED_SUBJECT_START(r, s)
55359+ if (s->obj_hash == NULL)
55360+ break;
55361+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
55362+ kfree(s->obj_hash);
55363+ else
55364+ vfree(s->obj_hash);
55365+ FOR_EACH_NESTED_SUBJECT_END(s)
55366+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
55367+ kfree(r->subj_hash);
55368+ else
55369+ vfree(r->subj_hash);
55370+ r->subj_hash = NULL;
55371+next_role:
55372+ FOR_EACH_ROLE_END(r)
55373+
55374+ acl_free_all();
55375+
55376+ if (acl_role_set.r_hash) {
55377+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
55378+ PAGE_SIZE)
55379+ kfree(acl_role_set.r_hash);
55380+ else
55381+ vfree(acl_role_set.r_hash);
55382+ }
55383+ if (name_set.n_hash) {
55384+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
55385+ PAGE_SIZE)
55386+ kfree(name_set.n_hash);
55387+ else
55388+ vfree(name_set.n_hash);
55389+ }
55390+
55391+ if (inodev_set.i_hash) {
55392+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
55393+ PAGE_SIZE)
55394+ kfree(inodev_set.i_hash);
55395+ else
55396+ vfree(inodev_set.i_hash);
55397+ }
55398+
55399+ gr_free_uidset();
55400+
55401+ memset(&name_set, 0, sizeof (struct name_db));
55402+ memset(&inodev_set, 0, sizeof (struct inodev_db));
55403+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
55404+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
55405+
55406+ default_role = NULL;
55407+ kernel_role = NULL;
55408+ role_list = NULL;
55409+
55410+ return;
55411+}
55412+
55413+static __u32
55414+count_user_objs(struct acl_object_label *userp)
55415+{
55416+ struct acl_object_label o_tmp;
55417+ __u32 num = 0;
55418+
55419+ while (userp) {
55420+ if (copy_from_user(&o_tmp, userp,
55421+ sizeof (struct acl_object_label)))
55422+ break;
55423+
55424+ userp = o_tmp.prev;
55425+ num++;
55426+ }
55427+
55428+ return num;
55429+}
55430+
55431+static struct acl_subject_label *
55432+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
55433+
55434+static int
55435+copy_user_glob(struct acl_object_label *obj)
55436+{
55437+ struct acl_object_label *g_tmp, **guser;
55438+ unsigned int len;
55439+ char *tmp;
55440+
55441+ if (obj->globbed == NULL)
55442+ return 0;
55443+
55444+ guser = &obj->globbed;
55445+ while (*guser) {
55446+ g_tmp = (struct acl_object_label *)
55447+ acl_alloc(sizeof (struct acl_object_label));
55448+ if (g_tmp == NULL)
55449+ return -ENOMEM;
55450+
55451+ if (copy_from_user(g_tmp, *guser,
55452+ sizeof (struct acl_object_label)))
55453+ return -EFAULT;
55454+
55455+ len = strnlen_user(g_tmp->filename, PATH_MAX);
55456+
55457+ if (!len || len >= PATH_MAX)
55458+ return -EINVAL;
55459+
55460+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55461+ return -ENOMEM;
55462+
55463+ if (copy_from_user(tmp, g_tmp->filename, len))
55464+ return -EFAULT;
55465+ tmp[len-1] = '\0';
55466+ g_tmp->filename = tmp;
55467+
55468+ *guser = g_tmp;
55469+ guser = &(g_tmp->next);
55470+ }
55471+
55472+ return 0;
55473+}
55474+
55475+static int
55476+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
55477+ struct acl_role_label *role)
55478+{
55479+ struct acl_object_label *o_tmp;
55480+ unsigned int len;
55481+ int ret;
55482+ char *tmp;
55483+
55484+ while (userp) {
55485+ if ((o_tmp = (struct acl_object_label *)
55486+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
55487+ return -ENOMEM;
55488+
55489+ if (copy_from_user(o_tmp, userp,
55490+ sizeof (struct acl_object_label)))
55491+ return -EFAULT;
55492+
55493+ userp = o_tmp->prev;
55494+
55495+ len = strnlen_user(o_tmp->filename, PATH_MAX);
55496+
55497+ if (!len || len >= PATH_MAX)
55498+ return -EINVAL;
55499+
55500+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55501+ return -ENOMEM;
55502+
55503+ if (copy_from_user(tmp, o_tmp->filename, len))
55504+ return -EFAULT;
55505+ tmp[len-1] = '\0';
55506+ o_tmp->filename = tmp;
55507+
55508+ insert_acl_obj_label(o_tmp, subj);
55509+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
55510+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
55511+ return -ENOMEM;
55512+
55513+ ret = copy_user_glob(o_tmp);
55514+ if (ret)
55515+ return ret;
55516+
55517+ if (o_tmp->nested) {
55518+ int already_copied;
55519+
55520+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
55521+ if (IS_ERR(o_tmp->nested))
55522+ return PTR_ERR(o_tmp->nested);
55523+
55524+ /* insert into nested subject list if we haven't copied this one yet
55525+ to prevent duplicate entries */
55526+ if (!already_copied) {
55527+ o_tmp->nested->next = role->hash->first;
55528+ role->hash->first = o_tmp->nested;
55529+ }
55530+ }
55531+ }
55532+
55533+ return 0;
55534+}
55535+
55536+static __u32
55537+count_user_subjs(struct acl_subject_label *userp)
55538+{
55539+ struct acl_subject_label s_tmp;
55540+ __u32 num = 0;
55541+
55542+ while (userp) {
55543+ if (copy_from_user(&s_tmp, userp,
55544+ sizeof (struct acl_subject_label)))
55545+ break;
55546+
55547+ userp = s_tmp.prev;
55548+ }
55549+
55550+ return num;
55551+}
55552+
55553+static int
55554+copy_user_allowedips(struct acl_role_label *rolep)
55555+{
55556+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
55557+
55558+ ruserip = rolep->allowed_ips;
55559+
55560+ while (ruserip) {
55561+ rlast = rtmp;
55562+
55563+ if ((rtmp = (struct role_allowed_ip *)
55564+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
55565+ return -ENOMEM;
55566+
55567+ if (copy_from_user(rtmp, ruserip,
55568+ sizeof (struct role_allowed_ip)))
55569+ return -EFAULT;
55570+
55571+ ruserip = rtmp->prev;
55572+
55573+ if (!rlast) {
55574+ rtmp->prev = NULL;
55575+ rolep->allowed_ips = rtmp;
55576+ } else {
55577+ rlast->next = rtmp;
55578+ rtmp->prev = rlast;
55579+ }
55580+
55581+ if (!ruserip)
55582+ rtmp->next = NULL;
55583+ }
55584+
55585+ return 0;
55586+}
55587+
55588+static int
55589+copy_user_transitions(struct acl_role_label *rolep)
55590+{
55591+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
55592+
55593+ unsigned int len;
55594+ char *tmp;
55595+
55596+ rusertp = rolep->transitions;
55597+
55598+ while (rusertp) {
55599+ rlast = rtmp;
55600+
55601+ if ((rtmp = (struct role_transition *)
55602+ acl_alloc(sizeof (struct role_transition))) == NULL)
55603+ return -ENOMEM;
55604+
55605+ if (copy_from_user(rtmp, rusertp,
55606+ sizeof (struct role_transition)))
55607+ return -EFAULT;
55608+
55609+ rusertp = rtmp->prev;
55610+
55611+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
55612+
55613+ if (!len || len >= GR_SPROLE_LEN)
55614+ return -EINVAL;
55615+
55616+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55617+ return -ENOMEM;
55618+
55619+ if (copy_from_user(tmp, rtmp->rolename, len))
55620+ return -EFAULT;
55621+ tmp[len-1] = '\0';
55622+ rtmp->rolename = tmp;
55623+
55624+ if (!rlast) {
55625+ rtmp->prev = NULL;
55626+ rolep->transitions = rtmp;
55627+ } else {
55628+ rlast->next = rtmp;
55629+ rtmp->prev = rlast;
55630+ }
55631+
55632+ if (!rusertp)
55633+ rtmp->next = NULL;
55634+ }
55635+
55636+ return 0;
55637+}
55638+
55639+static struct acl_subject_label *
55640+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
55641+{
55642+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
55643+ unsigned int len;
55644+ char *tmp;
55645+ __u32 num_objs;
55646+ struct acl_ip_label **i_tmp, *i_utmp2;
55647+ struct gr_hash_struct ghash;
55648+ struct subject_map *subjmap;
55649+ unsigned int i_num;
55650+ int err;
55651+
55652+ if (already_copied != NULL)
55653+ *already_copied = 0;
55654+
55655+ s_tmp = lookup_subject_map(userp);
55656+
55657+ /* we've already copied this subject into the kernel, just return
55658+ the reference to it, and don't copy it over again
55659+ */
55660+ if (s_tmp) {
55661+ if (already_copied != NULL)
55662+ *already_copied = 1;
55663+ return(s_tmp);
55664+ }
55665+
55666+ if ((s_tmp = (struct acl_subject_label *)
55667+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
55668+ return ERR_PTR(-ENOMEM);
55669+
55670+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
55671+ if (subjmap == NULL)
55672+ return ERR_PTR(-ENOMEM);
55673+
55674+ subjmap->user = userp;
55675+ subjmap->kernel = s_tmp;
55676+ insert_subj_map_entry(subjmap);
55677+
55678+ if (copy_from_user(s_tmp, userp,
55679+ sizeof (struct acl_subject_label)))
55680+ return ERR_PTR(-EFAULT);
55681+
55682+ len = strnlen_user(s_tmp->filename, PATH_MAX);
55683+
55684+ if (!len || len >= PATH_MAX)
55685+ return ERR_PTR(-EINVAL);
55686+
55687+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55688+ return ERR_PTR(-ENOMEM);
55689+
55690+ if (copy_from_user(tmp, s_tmp->filename, len))
55691+ return ERR_PTR(-EFAULT);
55692+ tmp[len-1] = '\0';
55693+ s_tmp->filename = tmp;
55694+
55695+ if (!strcmp(s_tmp->filename, "/"))
55696+ role->root_label = s_tmp;
55697+
55698+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
55699+ return ERR_PTR(-EFAULT);
55700+
55701+ /* copy user and group transition tables */
55702+
55703+ if (s_tmp->user_trans_num) {
55704+ uid_t *uidlist;
55705+
55706+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
55707+ if (uidlist == NULL)
55708+ return ERR_PTR(-ENOMEM);
55709+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
55710+ return ERR_PTR(-EFAULT);
55711+
55712+ s_tmp->user_transitions = uidlist;
55713+ }
55714+
55715+ if (s_tmp->group_trans_num) {
55716+ gid_t *gidlist;
55717+
55718+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
55719+ if (gidlist == NULL)
55720+ return ERR_PTR(-ENOMEM);
55721+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
55722+ return ERR_PTR(-EFAULT);
55723+
55724+ s_tmp->group_transitions = gidlist;
55725+ }
55726+
55727+ /* set up object hash table */
55728+ num_objs = count_user_objs(ghash.first);
55729+
55730+ s_tmp->obj_hash_size = num_objs;
55731+ s_tmp->obj_hash =
55732+ (struct acl_object_label **)
55733+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
55734+
55735+ if (!s_tmp->obj_hash)
55736+ return ERR_PTR(-ENOMEM);
55737+
55738+ memset(s_tmp->obj_hash, 0,
55739+ s_tmp->obj_hash_size *
55740+ sizeof (struct acl_object_label *));
55741+
55742+ /* add in objects */
55743+ err = copy_user_objs(ghash.first, s_tmp, role);
55744+
55745+ if (err)
55746+ return ERR_PTR(err);
55747+
55748+ /* set pointer for parent subject */
55749+ if (s_tmp->parent_subject) {
55750+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
55751+
55752+ if (IS_ERR(s_tmp2))
55753+ return s_tmp2;
55754+
55755+ s_tmp->parent_subject = s_tmp2;
55756+ }
55757+
55758+ /* add in ip acls */
55759+
55760+ if (!s_tmp->ip_num) {
55761+ s_tmp->ips = NULL;
55762+ goto insert;
55763+ }
55764+
55765+ i_tmp =
55766+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
55767+ sizeof (struct acl_ip_label *));
55768+
55769+ if (!i_tmp)
55770+ return ERR_PTR(-ENOMEM);
55771+
55772+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
55773+ *(i_tmp + i_num) =
55774+ (struct acl_ip_label *)
55775+ acl_alloc(sizeof (struct acl_ip_label));
55776+ if (!*(i_tmp + i_num))
55777+ return ERR_PTR(-ENOMEM);
55778+
55779+ if (copy_from_user
55780+ (&i_utmp2, s_tmp->ips + i_num,
55781+ sizeof (struct acl_ip_label *)))
55782+ return ERR_PTR(-EFAULT);
55783+
55784+ if (copy_from_user
55785+ (*(i_tmp + i_num), i_utmp2,
55786+ sizeof (struct acl_ip_label)))
55787+ return ERR_PTR(-EFAULT);
55788+
55789+ if ((*(i_tmp + i_num))->iface == NULL)
55790+ continue;
55791+
55792+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
55793+ if (!len || len >= IFNAMSIZ)
55794+ return ERR_PTR(-EINVAL);
55795+ tmp = acl_alloc(len);
55796+ if (tmp == NULL)
55797+ return ERR_PTR(-ENOMEM);
55798+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
55799+ return ERR_PTR(-EFAULT);
55800+ (*(i_tmp + i_num))->iface = tmp;
55801+ }
55802+
55803+ s_tmp->ips = i_tmp;
55804+
55805+insert:
55806+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
55807+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
55808+ return ERR_PTR(-ENOMEM);
55809+
55810+ return s_tmp;
55811+}
55812+
55813+static int
55814+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
55815+{
55816+ struct acl_subject_label s_pre;
55817+ struct acl_subject_label * ret;
55818+ int err;
55819+
55820+ while (userp) {
55821+ if (copy_from_user(&s_pre, userp,
55822+ sizeof (struct acl_subject_label)))
55823+ return -EFAULT;
55824+
55825+ ret = do_copy_user_subj(userp, role, NULL);
55826+
55827+ err = PTR_ERR(ret);
55828+ if (IS_ERR(ret))
55829+ return err;
55830+
55831+ insert_acl_subj_label(ret, role);
55832+
55833+ userp = s_pre.prev;
55834+ }
55835+
55836+ return 0;
55837+}
55838+
55839+static int
55840+copy_user_acl(struct gr_arg *arg)
55841+{
55842+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
55843+ struct acl_subject_label *subj_list;
55844+ struct sprole_pw *sptmp;
55845+ struct gr_hash_struct *ghash;
55846+ uid_t *domainlist;
55847+ unsigned int r_num;
55848+ unsigned int len;
55849+ char *tmp;
55850+ int err = 0;
55851+ __u16 i;
55852+ __u32 num_subjs;
55853+
55854+ /* we need a default and kernel role */
55855+ if (arg->role_db.num_roles < 2)
55856+ return -EINVAL;
55857+
55858+ /* copy special role authentication info from userspace */
55859+
55860+ num_sprole_pws = arg->num_sprole_pws;
55861+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
55862+
55863+ if (!acl_special_roles && num_sprole_pws)
55864+ return -ENOMEM;
55865+
55866+ for (i = 0; i < num_sprole_pws; i++) {
55867+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
55868+ if (!sptmp)
55869+ return -ENOMEM;
55870+ if (copy_from_user(sptmp, arg->sprole_pws + i,
55871+ sizeof (struct sprole_pw)))
55872+ return -EFAULT;
55873+
55874+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
55875+
55876+ if (!len || len >= GR_SPROLE_LEN)
55877+ return -EINVAL;
55878+
55879+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55880+ return -ENOMEM;
55881+
55882+ if (copy_from_user(tmp, sptmp->rolename, len))
55883+ return -EFAULT;
55884+
55885+ tmp[len-1] = '\0';
55886+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55887+ printk(KERN_ALERT "Copying special role %s\n", tmp);
55888+#endif
55889+ sptmp->rolename = tmp;
55890+ acl_special_roles[i] = sptmp;
55891+ }
55892+
55893+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
55894+
55895+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
55896+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
55897+
55898+ if (!r_tmp)
55899+ return -ENOMEM;
55900+
55901+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
55902+ sizeof (struct acl_role_label *)))
55903+ return -EFAULT;
55904+
55905+ if (copy_from_user(r_tmp, r_utmp2,
55906+ sizeof (struct acl_role_label)))
55907+ return -EFAULT;
55908+
55909+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
55910+
55911+ if (!len || len >= PATH_MAX)
55912+ return -EINVAL;
55913+
55914+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55915+ return -ENOMEM;
55916+
55917+ if (copy_from_user(tmp, r_tmp->rolename, len))
55918+ return -EFAULT;
55919+
55920+ tmp[len-1] = '\0';
55921+ r_tmp->rolename = tmp;
55922+
55923+ if (!strcmp(r_tmp->rolename, "default")
55924+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
55925+ default_role = r_tmp;
55926+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
55927+ kernel_role = r_tmp;
55928+ }
55929+
55930+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
55931+ return -ENOMEM;
55932+
55933+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
55934+ return -EFAULT;
55935+
55936+ r_tmp->hash = ghash;
55937+
55938+ num_subjs = count_user_subjs(r_tmp->hash->first);
55939+
55940+ r_tmp->subj_hash_size = num_subjs;
55941+ r_tmp->subj_hash =
55942+ (struct acl_subject_label **)
55943+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
55944+
55945+ if (!r_tmp->subj_hash)
55946+ return -ENOMEM;
55947+
55948+ err = copy_user_allowedips(r_tmp);
55949+ if (err)
55950+ return err;
55951+
55952+ /* copy domain info */
55953+ if (r_tmp->domain_children != NULL) {
55954+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
55955+ if (domainlist == NULL)
55956+ return -ENOMEM;
55957+
55958+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
55959+ return -EFAULT;
55960+
55961+ r_tmp->domain_children = domainlist;
55962+ }
55963+
55964+ err = copy_user_transitions(r_tmp);
55965+ if (err)
55966+ return err;
55967+
55968+ memset(r_tmp->subj_hash, 0,
55969+ r_tmp->subj_hash_size *
55970+ sizeof (struct acl_subject_label *));
55971+
55972+ /* acquire the list of subjects, then NULL out
55973+ the list prior to parsing the subjects for this role,
55974+ as during this parsing the list is replaced with a list
55975+ of *nested* subjects for the role
55976+ */
55977+ subj_list = r_tmp->hash->first;
55978+
55979+ /* set nested subject list to null */
55980+ r_tmp->hash->first = NULL;
55981+
55982+ err = copy_user_subjs(subj_list, r_tmp);
55983+
55984+ if (err)
55985+ return err;
55986+
55987+ insert_acl_role_label(r_tmp);
55988+ }
55989+
55990+ if (default_role == NULL || kernel_role == NULL)
55991+ return -EINVAL;
55992+
55993+ return err;
55994+}
55995+
55996+static int
55997+gracl_init(struct gr_arg *args)
55998+{
55999+ int error = 0;
56000+
56001+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
56002+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
56003+
56004+ if (init_variables(args)) {
56005+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
56006+ error = -ENOMEM;
56007+ free_variables();
56008+ goto out;
56009+ }
56010+
56011+ error = copy_user_acl(args);
56012+ free_init_variables();
56013+ if (error) {
56014+ free_variables();
56015+ goto out;
56016+ }
56017+
56018+ if ((error = gr_set_acls(0))) {
56019+ free_variables();
56020+ goto out;
56021+ }
56022+
56023+ pax_open_kernel();
56024+ gr_status |= GR_READY;
56025+ pax_close_kernel();
56026+
56027+ out:
56028+ return error;
56029+}
56030+
56031+/* derived from glibc fnmatch() 0: match, 1: no match*/
56032+
56033+static int
56034+glob_match(const char *p, const char *n)
56035+{
56036+ char c;
56037+
56038+ while ((c = *p++) != '\0') {
56039+ switch (c) {
56040+ case '?':
56041+ if (*n == '\0')
56042+ return 1;
56043+ else if (*n == '/')
56044+ return 1;
56045+ break;
56046+ case '\\':
56047+ if (*n != c)
56048+ return 1;
56049+ break;
56050+ case '*':
56051+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
56052+ if (*n == '/')
56053+ return 1;
56054+ else if (c == '?') {
56055+ if (*n == '\0')
56056+ return 1;
56057+ else
56058+ ++n;
56059+ }
56060+ }
56061+ if (c == '\0') {
56062+ return 0;
56063+ } else {
56064+ const char *endp;
56065+
56066+ if ((endp = strchr(n, '/')) == NULL)
56067+ endp = n + strlen(n);
56068+
56069+ if (c == '[') {
56070+ for (--p; n < endp; ++n)
56071+ if (!glob_match(p, n))
56072+ return 0;
56073+ } else if (c == '/') {
56074+ while (*n != '\0' && *n != '/')
56075+ ++n;
56076+ if (*n == '/' && !glob_match(p, n + 1))
56077+ return 0;
56078+ } else {
56079+ for (--p; n < endp; ++n)
56080+ if (*n == c && !glob_match(p, n))
56081+ return 0;
56082+ }
56083+
56084+ return 1;
56085+ }
56086+ case '[':
56087+ {
56088+ int not;
56089+ char cold;
56090+
56091+ if (*n == '\0' || *n == '/')
56092+ return 1;
56093+
56094+ not = (*p == '!' || *p == '^');
56095+ if (not)
56096+ ++p;
56097+
56098+ c = *p++;
56099+ for (;;) {
56100+ unsigned char fn = (unsigned char)*n;
56101+
56102+ if (c == '\0')
56103+ return 1;
56104+ else {
56105+ if (c == fn)
56106+ goto matched;
56107+ cold = c;
56108+ c = *p++;
56109+
56110+ if (c == '-' && *p != ']') {
56111+ unsigned char cend = *p++;
56112+
56113+ if (cend == '\0')
56114+ return 1;
56115+
56116+ if (cold <= fn && fn <= cend)
56117+ goto matched;
56118+
56119+ c = *p++;
56120+ }
56121+ }
56122+
56123+ if (c == ']')
56124+ break;
56125+ }
56126+ if (!not)
56127+ return 1;
56128+ break;
56129+ matched:
56130+ while (c != ']') {
56131+ if (c == '\0')
56132+ return 1;
56133+
56134+ c = *p++;
56135+ }
56136+ if (not)
56137+ return 1;
56138+ }
56139+ break;
56140+ default:
56141+ if (c != *n)
56142+ return 1;
56143+ }
56144+
56145+ ++n;
56146+ }
56147+
56148+ if (*n == '\0')
56149+ return 0;
56150+
56151+ if (*n == '/')
56152+ return 0;
56153+
56154+ return 1;
56155+}
56156+
56157+static struct acl_object_label *
56158+chk_glob_label(struct acl_object_label *globbed,
56159+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
56160+{
56161+ struct acl_object_label *tmp;
56162+
56163+ if (*path == NULL)
56164+ *path = gr_to_filename_nolock(dentry, mnt);
56165+
56166+ tmp = globbed;
56167+
56168+ while (tmp) {
56169+ if (!glob_match(tmp->filename, *path))
56170+ return tmp;
56171+ tmp = tmp->next;
56172+ }
56173+
56174+ return NULL;
56175+}
56176+
56177+static struct acl_object_label *
56178+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
56179+ const ino_t curr_ino, const dev_t curr_dev,
56180+ const struct acl_subject_label *subj, char **path, const int checkglob)
56181+{
56182+ struct acl_subject_label *tmpsubj;
56183+ struct acl_object_label *retval;
56184+ struct acl_object_label *retval2;
56185+
56186+ tmpsubj = (struct acl_subject_label *) subj;
56187+ read_lock(&gr_inode_lock);
56188+ do {
56189+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
56190+ if (retval) {
56191+ if (checkglob && retval->globbed) {
56192+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
56193+ if (retval2)
56194+ retval = retval2;
56195+ }
56196+ break;
56197+ }
56198+ } while ((tmpsubj = tmpsubj->parent_subject));
56199+ read_unlock(&gr_inode_lock);
56200+
56201+ return retval;
56202+}
56203+
56204+static __inline__ struct acl_object_label *
56205+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
56206+ struct dentry *curr_dentry,
56207+ const struct acl_subject_label *subj, char **path, const int checkglob)
56208+{
56209+ int newglob = checkglob;
56210+ ino_t inode;
56211+ dev_t device;
56212+
56213+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
56214+ as we don't want a / * rule to match instead of the / object
56215+ don't do this for create lookups that call this function though, since they're looking up
56216+ on the parent and thus need globbing checks on all paths
56217+ */
56218+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
56219+ newglob = GR_NO_GLOB;
56220+
56221+ spin_lock(&curr_dentry->d_lock);
56222+ inode = curr_dentry->d_inode->i_ino;
56223+ device = __get_dev(curr_dentry);
56224+ spin_unlock(&curr_dentry->d_lock);
56225+
56226+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
56227+}
56228+
56229+#ifdef CONFIG_HUGETLBFS
56230+static inline bool
56231+is_hugetlbfs_mnt(const struct vfsmount *mnt)
56232+{
56233+ int i;
56234+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
56235+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
56236+ return true;
56237+ }
56238+
56239+ return false;
56240+}
56241+#endif
56242+
56243+static struct acl_object_label *
56244+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56245+ const struct acl_subject_label *subj, char *path, const int checkglob)
56246+{
56247+ struct dentry *dentry = (struct dentry *) l_dentry;
56248+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
56249+ struct mount *real_mnt = real_mount(mnt);
56250+ struct acl_object_label *retval;
56251+ struct dentry *parent;
56252+
56253+ write_seqlock(&rename_lock);
56254+ br_read_lock(&vfsmount_lock);
56255+
56256+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
56257+#ifdef CONFIG_NET
56258+ mnt == sock_mnt ||
56259+#endif
56260+#ifdef CONFIG_HUGETLBFS
56261+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
56262+#endif
56263+ /* ignore Eric Biederman */
56264+ IS_PRIVATE(l_dentry->d_inode))) {
56265+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
56266+ goto out;
56267+ }
56268+
56269+ for (;;) {
56270+ if (dentry == real_root.dentry && mnt == real_root.mnt)
56271+ break;
56272+
56273+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
56274+ if (!mnt_has_parent(real_mnt))
56275+ break;
56276+
56277+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56278+ if (retval != NULL)
56279+ goto out;
56280+
56281+ dentry = real_mnt->mnt_mountpoint;
56282+ real_mnt = real_mnt->mnt_parent;
56283+ mnt = &real_mnt->mnt;
56284+ continue;
56285+ }
56286+
56287+ parent = dentry->d_parent;
56288+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56289+ if (retval != NULL)
56290+ goto out;
56291+
56292+ dentry = parent;
56293+ }
56294+
56295+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56296+
56297+ /* real_root is pinned so we don't have to hold a reference */
56298+ if (retval == NULL)
56299+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
56300+out:
56301+ br_read_unlock(&vfsmount_lock);
56302+ write_sequnlock(&rename_lock);
56303+
56304+ BUG_ON(retval == NULL);
56305+
56306+ return retval;
56307+}
56308+
56309+static __inline__ struct acl_object_label *
56310+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56311+ const struct acl_subject_label *subj)
56312+{
56313+ char *path = NULL;
56314+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
56315+}
56316+
56317+static __inline__ struct acl_object_label *
56318+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56319+ const struct acl_subject_label *subj)
56320+{
56321+ char *path = NULL;
56322+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
56323+}
56324+
56325+static __inline__ struct acl_object_label *
56326+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56327+ const struct acl_subject_label *subj, char *path)
56328+{
56329+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
56330+}
56331+
56332+static struct acl_subject_label *
56333+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56334+ const struct acl_role_label *role)
56335+{
56336+ struct dentry *dentry = (struct dentry *) l_dentry;
56337+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
56338+ struct mount *real_mnt = real_mount(mnt);
56339+ struct acl_subject_label *retval;
56340+ struct dentry *parent;
56341+
56342+ write_seqlock(&rename_lock);
56343+ br_read_lock(&vfsmount_lock);
56344+
56345+ for (;;) {
56346+ if (dentry == real_root.dentry && mnt == real_root.mnt)
56347+ break;
56348+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
56349+ if (!mnt_has_parent(real_mnt))
56350+ break;
56351+
56352+ spin_lock(&dentry->d_lock);
56353+ read_lock(&gr_inode_lock);
56354+ retval =
56355+ lookup_acl_subj_label(dentry->d_inode->i_ino,
56356+ __get_dev(dentry), role);
56357+ read_unlock(&gr_inode_lock);
56358+ spin_unlock(&dentry->d_lock);
56359+ if (retval != NULL)
56360+ goto out;
56361+
56362+ dentry = real_mnt->mnt_mountpoint;
56363+ real_mnt = real_mnt->mnt_parent;
56364+ mnt = &real_mnt->mnt;
56365+ continue;
56366+ }
56367+
56368+ spin_lock(&dentry->d_lock);
56369+ read_lock(&gr_inode_lock);
56370+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
56371+ __get_dev(dentry), role);
56372+ read_unlock(&gr_inode_lock);
56373+ parent = dentry->d_parent;
56374+ spin_unlock(&dentry->d_lock);
56375+
56376+ if (retval != NULL)
56377+ goto out;
56378+
56379+ dentry = parent;
56380+ }
56381+
56382+ spin_lock(&dentry->d_lock);
56383+ read_lock(&gr_inode_lock);
56384+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
56385+ __get_dev(dentry), role);
56386+ read_unlock(&gr_inode_lock);
56387+ spin_unlock(&dentry->d_lock);
56388+
56389+ if (unlikely(retval == NULL)) {
56390+ /* real_root is pinned, we don't need to hold a reference */
56391+ read_lock(&gr_inode_lock);
56392+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
56393+ __get_dev(real_root.dentry), role);
56394+ read_unlock(&gr_inode_lock);
56395+ }
56396+out:
56397+ br_read_unlock(&vfsmount_lock);
56398+ write_sequnlock(&rename_lock);
56399+
56400+ BUG_ON(retval == NULL);
56401+
56402+ return retval;
56403+}
56404+
56405+static void
56406+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
56407+{
56408+ struct task_struct *task = current;
56409+ const struct cred *cred = current_cred();
56410+
56411+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
56412+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
56413+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
56414+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
56415+
56416+ return;
56417+}
56418+
56419+static void
56420+gr_log_learn_id_change(const char type, const unsigned int real,
56421+ const unsigned int effective, const unsigned int fs)
56422+{
56423+ struct task_struct *task = current;
56424+ const struct cred *cred = current_cred();
56425+
56426+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
56427+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
56428+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
56429+ type, real, effective, fs, &task->signal->saved_ip);
56430+
56431+ return;
56432+}
56433+
56434+__u32
56435+gr_search_file(const struct dentry * dentry, const __u32 mode,
56436+ const struct vfsmount * mnt)
56437+{
56438+ __u32 retval = mode;
56439+ struct acl_subject_label *curracl;
56440+ struct acl_object_label *currobj;
56441+
56442+ if (unlikely(!(gr_status & GR_READY)))
56443+ return (mode & ~GR_AUDITS);
56444+
56445+ curracl = current->acl;
56446+
56447+ currobj = chk_obj_label(dentry, mnt, curracl);
56448+ retval = currobj->mode & mode;
56449+
56450+ /* if we're opening a specified transfer file for writing
56451+ (e.g. /dev/initctl), then transfer our role to init
56452+ */
56453+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
56454+ current->role->roletype & GR_ROLE_PERSIST)) {
56455+ struct task_struct *task = init_pid_ns.child_reaper;
56456+
56457+ if (task->role != current->role) {
56458+ task->acl_sp_role = 0;
56459+ task->acl_role_id = current->acl_role_id;
56460+ task->role = current->role;
56461+ rcu_read_lock();
56462+ read_lock(&grsec_exec_file_lock);
56463+ gr_apply_subject_to_task(task);
56464+ read_unlock(&grsec_exec_file_lock);
56465+ rcu_read_unlock();
56466+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
56467+ }
56468+ }
56469+
56470+ if (unlikely
56471+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
56472+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
56473+ __u32 new_mode = mode;
56474+
56475+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
56476+
56477+ retval = new_mode;
56478+
56479+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
56480+ new_mode |= GR_INHERIT;
56481+
56482+ if (!(mode & GR_NOLEARN))
56483+ gr_log_learn(dentry, mnt, new_mode);
56484+ }
56485+
56486+ return retval;
56487+}
56488+
56489+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
56490+ const struct dentry *parent,
56491+ const struct vfsmount *mnt)
56492+{
56493+ struct name_entry *match;
56494+ struct acl_object_label *matchpo;
56495+ struct acl_subject_label *curracl;
56496+ char *path;
56497+
56498+ if (unlikely(!(gr_status & GR_READY)))
56499+ return NULL;
56500+
56501+ preempt_disable();
56502+ path = gr_to_filename_rbac(new_dentry, mnt);
56503+ match = lookup_name_entry_create(path);
56504+
56505+ curracl = current->acl;
56506+
56507+ if (match) {
56508+ read_lock(&gr_inode_lock);
56509+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
56510+ read_unlock(&gr_inode_lock);
56511+
56512+ if (matchpo) {
56513+ preempt_enable();
56514+ return matchpo;
56515+ }
56516+ }
56517+
56518+ // lookup parent
56519+
56520+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
56521+
56522+ preempt_enable();
56523+ return matchpo;
56524+}
56525+
56526+__u32
56527+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
56528+ const struct vfsmount * mnt, const __u32 mode)
56529+{
56530+ struct acl_object_label *matchpo;
56531+ __u32 retval;
56532+
56533+ if (unlikely(!(gr_status & GR_READY)))
56534+ return (mode & ~GR_AUDITS);
56535+
56536+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
56537+
56538+ retval = matchpo->mode & mode;
56539+
56540+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
56541+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
56542+ __u32 new_mode = mode;
56543+
56544+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
56545+
56546+ gr_log_learn(new_dentry, mnt, new_mode);
56547+ return new_mode;
56548+ }
56549+
56550+ return retval;
56551+}
56552+
56553+__u32
56554+gr_check_link(const struct dentry * new_dentry,
56555+ const struct dentry * parent_dentry,
56556+ const struct vfsmount * parent_mnt,
56557+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
56558+{
56559+ struct acl_object_label *obj;
56560+ __u32 oldmode, newmode;
56561+ __u32 needmode;
56562+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
56563+ GR_DELETE | GR_INHERIT;
56564+
56565+ if (unlikely(!(gr_status & GR_READY)))
56566+ return (GR_CREATE | GR_LINK);
56567+
56568+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
56569+ oldmode = obj->mode;
56570+
56571+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
56572+ newmode = obj->mode;
56573+
56574+ needmode = newmode & checkmodes;
56575+
56576+ // old name for hardlink must have at least the permissions of the new name
56577+ if ((oldmode & needmode) != needmode)
56578+ goto bad;
56579+
56580+ // if old name had restrictions/auditing, make sure the new name does as well
56581+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
56582+
56583+ // don't allow hardlinking of suid/sgid/fcapped files without permission
56584+ if (is_privileged_binary(old_dentry))
56585+ needmode |= GR_SETID;
56586+
56587+ if ((newmode & needmode) != needmode)
56588+ goto bad;
56589+
56590+ // enforce minimum permissions
56591+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
56592+ return newmode;
56593+bad:
56594+ needmode = oldmode;
56595+ if (is_privileged_binary(old_dentry))
56596+ needmode |= GR_SETID;
56597+
56598+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
56599+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
56600+ return (GR_CREATE | GR_LINK);
56601+ } else if (newmode & GR_SUPPRESS)
56602+ return GR_SUPPRESS;
56603+ else
56604+ return 0;
56605+}
56606+
56607+int
56608+gr_check_hidden_task(const struct task_struct *task)
56609+{
56610+ if (unlikely(!(gr_status & GR_READY)))
56611+ return 0;
56612+
56613+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
56614+ return 1;
56615+
56616+ return 0;
56617+}
56618+
56619+int
56620+gr_check_protected_task(const struct task_struct *task)
56621+{
56622+ if (unlikely(!(gr_status & GR_READY) || !task))
56623+ return 0;
56624+
56625+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
56626+ task->acl != current->acl)
56627+ return 1;
56628+
56629+ return 0;
56630+}
56631+
56632+int
56633+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
56634+{
56635+ struct task_struct *p;
56636+ int ret = 0;
56637+
56638+ if (unlikely(!(gr_status & GR_READY) || !pid))
56639+ return ret;
56640+
56641+ read_lock(&tasklist_lock);
56642+ do_each_pid_task(pid, type, p) {
56643+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
56644+ p->acl != current->acl) {
56645+ ret = 1;
56646+ goto out;
56647+ }
56648+ } while_each_pid_task(pid, type, p);
56649+out:
56650+ read_unlock(&tasklist_lock);
56651+
56652+ return ret;
56653+}
56654+
56655+void
56656+gr_copy_label(struct task_struct *tsk)
56657+{
56658+ tsk->signal->used_accept = 0;
56659+ tsk->acl_sp_role = 0;
56660+ tsk->acl_role_id = current->acl_role_id;
56661+ tsk->acl = current->acl;
56662+ tsk->role = current->role;
56663+ tsk->signal->curr_ip = current->signal->curr_ip;
56664+ tsk->signal->saved_ip = current->signal->saved_ip;
56665+ if (current->exec_file)
56666+ get_file(current->exec_file);
56667+ tsk->exec_file = current->exec_file;
56668+ tsk->is_writable = current->is_writable;
56669+ if (unlikely(current->signal->used_accept)) {
56670+ current->signal->curr_ip = 0;
56671+ current->signal->saved_ip = 0;
56672+ }
56673+
56674+ return;
56675+}
56676+
56677+static void
56678+gr_set_proc_res(struct task_struct *task)
56679+{
56680+ struct acl_subject_label *proc;
56681+ unsigned short i;
56682+
56683+ proc = task->acl;
56684+
56685+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
56686+ return;
56687+
56688+ for (i = 0; i < RLIM_NLIMITS; i++) {
56689+ if (!(proc->resmask & (1 << i)))
56690+ continue;
56691+
56692+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
56693+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
56694+ }
56695+
56696+ return;
56697+}
56698+
56699+extern int __gr_process_user_ban(struct user_struct *user);
56700+
56701+int
56702+gr_check_user_change(int real, int effective, int fs)
56703+{
56704+ unsigned int i;
56705+ __u16 num;
56706+ uid_t *uidlist;
56707+ int curuid;
56708+ int realok = 0;
56709+ int effectiveok = 0;
56710+ int fsok = 0;
56711+
56712+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56713+ struct user_struct *user;
56714+
56715+ if (real == -1)
56716+ goto skipit;
56717+
56718+ user = find_user(real);
56719+ if (user == NULL)
56720+ goto skipit;
56721+
56722+ if (__gr_process_user_ban(user)) {
56723+ /* for find_user */
56724+ free_uid(user);
56725+ return 1;
56726+ }
56727+
56728+ /* for find_user */
56729+ free_uid(user);
56730+
56731+skipit:
56732+#endif
56733+
56734+ if (unlikely(!(gr_status & GR_READY)))
56735+ return 0;
56736+
56737+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56738+ gr_log_learn_id_change('u', real, effective, fs);
56739+
56740+ num = current->acl->user_trans_num;
56741+ uidlist = current->acl->user_transitions;
56742+
56743+ if (uidlist == NULL)
56744+ return 0;
56745+
56746+ if (real == -1)
56747+ realok = 1;
56748+ if (effective == -1)
56749+ effectiveok = 1;
56750+ if (fs == -1)
56751+ fsok = 1;
56752+
56753+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
56754+ for (i = 0; i < num; i++) {
56755+ curuid = (int)uidlist[i];
56756+ if (real == curuid)
56757+ realok = 1;
56758+ if (effective == curuid)
56759+ effectiveok = 1;
56760+ if (fs == curuid)
56761+ fsok = 1;
56762+ }
56763+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
56764+ for (i = 0; i < num; i++) {
56765+ curuid = (int)uidlist[i];
56766+ if (real == curuid)
56767+ break;
56768+ if (effective == curuid)
56769+ break;
56770+ if (fs == curuid)
56771+ break;
56772+ }
56773+ /* not in deny list */
56774+ if (i == num) {
56775+ realok = 1;
56776+ effectiveok = 1;
56777+ fsok = 1;
56778+ }
56779+ }
56780+
56781+ if (realok && effectiveok && fsok)
56782+ return 0;
56783+ else {
56784+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56785+ return 1;
56786+ }
56787+}
56788+
56789+int
56790+gr_check_group_change(int real, int effective, int fs)
56791+{
56792+ unsigned int i;
56793+ __u16 num;
56794+ gid_t *gidlist;
56795+ int curgid;
56796+ int realok = 0;
56797+ int effectiveok = 0;
56798+ int fsok = 0;
56799+
56800+ if (unlikely(!(gr_status & GR_READY)))
56801+ return 0;
56802+
56803+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56804+ gr_log_learn_id_change('g', real, effective, fs);
56805+
56806+ num = current->acl->group_trans_num;
56807+ gidlist = current->acl->group_transitions;
56808+
56809+ if (gidlist == NULL)
56810+ return 0;
56811+
56812+ if (real == -1)
56813+ realok = 1;
56814+ if (effective == -1)
56815+ effectiveok = 1;
56816+ if (fs == -1)
56817+ fsok = 1;
56818+
56819+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
56820+ for (i = 0; i < num; i++) {
56821+ curgid = (int)gidlist[i];
56822+ if (real == curgid)
56823+ realok = 1;
56824+ if (effective == curgid)
56825+ effectiveok = 1;
56826+ if (fs == curgid)
56827+ fsok = 1;
56828+ }
56829+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
56830+ for (i = 0; i < num; i++) {
56831+ curgid = (int)gidlist[i];
56832+ if (real == curgid)
56833+ break;
56834+ if (effective == curgid)
56835+ break;
56836+ if (fs == curgid)
56837+ break;
56838+ }
56839+ /* not in deny list */
56840+ if (i == num) {
56841+ realok = 1;
56842+ effectiveok = 1;
56843+ fsok = 1;
56844+ }
56845+ }
56846+
56847+ if (realok && effectiveok && fsok)
56848+ return 0;
56849+ else {
56850+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56851+ return 1;
56852+ }
56853+}
56854+
56855+extern int gr_acl_is_capable(const int cap);
56856+
56857+void
56858+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
56859+{
56860+ struct acl_role_label *role = task->role;
56861+ struct acl_subject_label *subj = NULL;
56862+ struct acl_object_label *obj;
56863+ struct file *filp;
56864+
56865+ if (unlikely(!(gr_status & GR_READY)))
56866+ return;
56867+
56868+ filp = task->exec_file;
56869+
56870+ /* kernel process, we'll give them the kernel role */
56871+ if (unlikely(!filp)) {
56872+ task->role = kernel_role;
56873+ task->acl = kernel_role->root_label;
56874+ return;
56875+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
56876+ role = lookup_acl_role_label(task, uid, gid);
56877+
56878+ /* don't change the role if we're not a privileged process */
56879+ if (role && task->role != role &&
56880+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
56881+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
56882+ return;
56883+
56884+ /* perform subject lookup in possibly new role
56885+ we can use this result below in the case where role == task->role
56886+ */
56887+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
56888+
56889+ /* if we changed uid/gid, but result in the same role
56890+ and are using inheritance, don't lose the inherited subject
56891+ if current subject is other than what normal lookup
56892+ would result in, we arrived via inheritance, don't
56893+ lose subject
56894+ */
56895+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
56896+ (subj == task->acl)))
56897+ task->acl = subj;
56898+
56899+ task->role = role;
56900+
56901+ task->is_writable = 0;
56902+
56903+ /* ignore additional mmap checks for processes that are writable
56904+ by the default ACL */
56905+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56906+ if (unlikely(obj->mode & GR_WRITE))
56907+ task->is_writable = 1;
56908+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
56909+ if (unlikely(obj->mode & GR_WRITE))
56910+ task->is_writable = 1;
56911+
56912+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56913+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56914+#endif
56915+
56916+ gr_set_proc_res(task);
56917+
56918+ return;
56919+}
56920+
56921+int
56922+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
56923+ const int unsafe_flags)
56924+{
56925+ struct task_struct *task = current;
56926+ struct acl_subject_label *newacl;
56927+ struct acl_object_label *obj;
56928+ __u32 retmode;
56929+
56930+ if (unlikely(!(gr_status & GR_READY)))
56931+ return 0;
56932+
56933+ newacl = chk_subj_label(dentry, mnt, task->role);
56934+
56935+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
56936+ did an exec
56937+ */
56938+ rcu_read_lock();
56939+ read_lock(&tasklist_lock);
56940+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
56941+ (task->parent->acl->mode & GR_POVERRIDE))) {
56942+ read_unlock(&tasklist_lock);
56943+ rcu_read_unlock();
56944+ goto skip_check;
56945+ }
56946+ read_unlock(&tasklist_lock);
56947+ rcu_read_unlock();
56948+
56949+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
56950+ !(task->role->roletype & GR_ROLE_GOD) &&
56951+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
56952+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
56953+ if (unsafe_flags & LSM_UNSAFE_SHARE)
56954+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
56955+ else
56956+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
56957+ return -EACCES;
56958+ }
56959+
56960+skip_check:
56961+
56962+ obj = chk_obj_label(dentry, mnt, task->acl);
56963+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
56964+
56965+ if (!(task->acl->mode & GR_INHERITLEARN) &&
56966+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
56967+ if (obj->nested)
56968+ task->acl = obj->nested;
56969+ else
56970+ task->acl = newacl;
56971+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
56972+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
56973+
56974+ task->is_writable = 0;
56975+
56976+ /* ignore additional mmap checks for processes that are writable
56977+ by the default ACL */
56978+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
56979+ if (unlikely(obj->mode & GR_WRITE))
56980+ task->is_writable = 1;
56981+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
56982+ if (unlikely(obj->mode & GR_WRITE))
56983+ task->is_writable = 1;
56984+
56985+ gr_set_proc_res(task);
56986+
56987+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56988+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56989+#endif
56990+ return 0;
56991+}
56992+
56993+/* always called with valid inodev ptr */
56994+static void
56995+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
56996+{
56997+ struct acl_object_label *matchpo;
56998+ struct acl_subject_label *matchps;
56999+ struct acl_subject_label *subj;
57000+ struct acl_role_label *role;
57001+ unsigned int x;
57002+
57003+ FOR_EACH_ROLE_START(role)
57004+ FOR_EACH_SUBJECT_START(role, subj, x)
57005+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
57006+ matchpo->mode |= GR_DELETED;
57007+ FOR_EACH_SUBJECT_END(subj,x)
57008+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
57009+ /* nested subjects aren't in the role's subj_hash table */
57010+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
57011+ matchpo->mode |= GR_DELETED;
57012+ FOR_EACH_NESTED_SUBJECT_END(subj)
57013+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
57014+ matchps->mode |= GR_DELETED;
57015+ FOR_EACH_ROLE_END(role)
57016+
57017+ inodev->nentry->deleted = 1;
57018+
57019+ return;
57020+}
57021+
57022+void
57023+gr_handle_delete(const ino_t ino, const dev_t dev)
57024+{
57025+ struct inodev_entry *inodev;
57026+
57027+ if (unlikely(!(gr_status & GR_READY)))
57028+ return;
57029+
57030+ write_lock(&gr_inode_lock);
57031+ inodev = lookup_inodev_entry(ino, dev);
57032+ if (inodev != NULL)
57033+ do_handle_delete(inodev, ino, dev);
57034+ write_unlock(&gr_inode_lock);
57035+
57036+ return;
57037+}
57038+
57039+static void
57040+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
57041+ const ino_t newinode, const dev_t newdevice,
57042+ struct acl_subject_label *subj)
57043+{
57044+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
57045+ struct acl_object_label *match;
57046+
57047+ match = subj->obj_hash[index];
57048+
57049+ while (match && (match->inode != oldinode ||
57050+ match->device != olddevice ||
57051+ !(match->mode & GR_DELETED)))
57052+ match = match->next;
57053+
57054+ if (match && (match->inode == oldinode)
57055+ && (match->device == olddevice)
57056+ && (match->mode & GR_DELETED)) {
57057+ if (match->prev == NULL) {
57058+ subj->obj_hash[index] = match->next;
57059+ if (match->next != NULL)
57060+ match->next->prev = NULL;
57061+ } else {
57062+ match->prev->next = match->next;
57063+ if (match->next != NULL)
57064+ match->next->prev = match->prev;
57065+ }
57066+ match->prev = NULL;
57067+ match->next = NULL;
57068+ match->inode = newinode;
57069+ match->device = newdevice;
57070+ match->mode &= ~GR_DELETED;
57071+
57072+ insert_acl_obj_label(match, subj);
57073+ }
57074+
57075+ return;
57076+}
57077+
57078+static void
57079+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
57080+ const ino_t newinode, const dev_t newdevice,
57081+ struct acl_role_label *role)
57082+{
57083+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
57084+ struct acl_subject_label *match;
57085+
57086+ match = role->subj_hash[index];
57087+
57088+ while (match && (match->inode != oldinode ||
57089+ match->device != olddevice ||
57090+ !(match->mode & GR_DELETED)))
57091+ match = match->next;
57092+
57093+ if (match && (match->inode == oldinode)
57094+ && (match->device == olddevice)
57095+ && (match->mode & GR_DELETED)) {
57096+ if (match->prev == NULL) {
57097+ role->subj_hash[index] = match->next;
57098+ if (match->next != NULL)
57099+ match->next->prev = NULL;
57100+ } else {
57101+ match->prev->next = match->next;
57102+ if (match->next != NULL)
57103+ match->next->prev = match->prev;
57104+ }
57105+ match->prev = NULL;
57106+ match->next = NULL;
57107+ match->inode = newinode;
57108+ match->device = newdevice;
57109+ match->mode &= ~GR_DELETED;
57110+
57111+ insert_acl_subj_label(match, role);
57112+ }
57113+
57114+ return;
57115+}
57116+
57117+static void
57118+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
57119+ const ino_t newinode, const dev_t newdevice)
57120+{
57121+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
57122+ struct inodev_entry *match;
57123+
57124+ match = inodev_set.i_hash[index];
57125+
57126+ while (match && (match->nentry->inode != oldinode ||
57127+ match->nentry->device != olddevice || !match->nentry->deleted))
57128+ match = match->next;
57129+
57130+ if (match && (match->nentry->inode == oldinode)
57131+ && (match->nentry->device == olddevice) &&
57132+ match->nentry->deleted) {
57133+ if (match->prev == NULL) {
57134+ inodev_set.i_hash[index] = match->next;
57135+ if (match->next != NULL)
57136+ match->next->prev = NULL;
57137+ } else {
57138+ match->prev->next = match->next;
57139+ if (match->next != NULL)
57140+ match->next->prev = match->prev;
57141+ }
57142+ match->prev = NULL;
57143+ match->next = NULL;
57144+ match->nentry->inode = newinode;
57145+ match->nentry->device = newdevice;
57146+ match->nentry->deleted = 0;
57147+
57148+ insert_inodev_entry(match);
57149+ }
57150+
57151+ return;
57152+}
57153+
57154+static void
57155+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
57156+{
57157+ struct acl_subject_label *subj;
57158+ struct acl_role_label *role;
57159+ unsigned int x;
57160+
57161+ FOR_EACH_ROLE_START(role)
57162+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
57163+
57164+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
57165+ if ((subj->inode == ino) && (subj->device == dev)) {
57166+ subj->inode = ino;
57167+ subj->device = dev;
57168+ }
57169+ /* nested subjects aren't in the role's subj_hash table */
57170+ update_acl_obj_label(matchn->inode, matchn->device,
57171+ ino, dev, subj);
57172+ FOR_EACH_NESTED_SUBJECT_END(subj)
57173+ FOR_EACH_SUBJECT_START(role, subj, x)
57174+ update_acl_obj_label(matchn->inode, matchn->device,
57175+ ino, dev, subj);
57176+ FOR_EACH_SUBJECT_END(subj,x)
57177+ FOR_EACH_ROLE_END(role)
57178+
57179+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
57180+
57181+ return;
57182+}
57183+
57184+static void
57185+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
57186+ const struct vfsmount *mnt)
57187+{
57188+ ino_t ino = dentry->d_inode->i_ino;
57189+ dev_t dev = __get_dev(dentry);
57190+
57191+ __do_handle_create(matchn, ino, dev);
57192+
57193+ return;
57194+}
57195+
57196+void
57197+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57198+{
57199+ struct name_entry *matchn;
57200+
57201+ if (unlikely(!(gr_status & GR_READY)))
57202+ return;
57203+
57204+ preempt_disable();
57205+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
57206+
57207+ if (unlikely((unsigned long)matchn)) {
57208+ write_lock(&gr_inode_lock);
57209+ do_handle_create(matchn, dentry, mnt);
57210+ write_unlock(&gr_inode_lock);
57211+ }
57212+ preempt_enable();
57213+
57214+ return;
57215+}
57216+
57217+void
57218+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57219+{
57220+ struct name_entry *matchn;
57221+
57222+ if (unlikely(!(gr_status & GR_READY)))
57223+ return;
57224+
57225+ preempt_disable();
57226+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
57227+
57228+ if (unlikely((unsigned long)matchn)) {
57229+ write_lock(&gr_inode_lock);
57230+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
57231+ write_unlock(&gr_inode_lock);
57232+ }
57233+ preempt_enable();
57234+
57235+ return;
57236+}
57237+
57238+void
57239+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57240+ struct dentry *old_dentry,
57241+ struct dentry *new_dentry,
57242+ struct vfsmount *mnt, const __u8 replace)
57243+{
57244+ struct name_entry *matchn;
57245+ struct inodev_entry *inodev;
57246+ struct inode *inode = new_dentry->d_inode;
57247+ ino_t old_ino = old_dentry->d_inode->i_ino;
57248+ dev_t old_dev = __get_dev(old_dentry);
57249+
57250+ /* vfs_rename swaps the name and parent link for old_dentry and
57251+ new_dentry
57252+ at this point, old_dentry has the new name, parent link, and inode
57253+ for the renamed file
57254+ if a file is being replaced by a rename, new_dentry has the inode
57255+ and name for the replaced file
57256+ */
57257+
57258+ if (unlikely(!(gr_status & GR_READY)))
57259+ return;
57260+
57261+ preempt_disable();
57262+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
57263+
57264+ /* we wouldn't have to check d_inode if it weren't for
57265+ NFS silly-renaming
57266+ */
57267+
57268+ write_lock(&gr_inode_lock);
57269+ if (unlikely(replace && inode)) {
57270+ ino_t new_ino = inode->i_ino;
57271+ dev_t new_dev = __get_dev(new_dentry);
57272+
57273+ inodev = lookup_inodev_entry(new_ino, new_dev);
57274+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
57275+ do_handle_delete(inodev, new_ino, new_dev);
57276+ }
57277+
57278+ inodev = lookup_inodev_entry(old_ino, old_dev);
57279+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
57280+ do_handle_delete(inodev, old_ino, old_dev);
57281+
57282+ if (unlikely((unsigned long)matchn))
57283+ do_handle_create(matchn, old_dentry, mnt);
57284+
57285+ write_unlock(&gr_inode_lock);
57286+ preempt_enable();
57287+
57288+ return;
57289+}
57290+
57291+static int
57292+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
57293+ unsigned char **sum)
57294+{
57295+ struct acl_role_label *r;
57296+ struct role_allowed_ip *ipp;
57297+ struct role_transition *trans;
57298+ unsigned int i;
57299+ int found = 0;
57300+ u32 curr_ip = current->signal->curr_ip;
57301+
57302+ current->signal->saved_ip = curr_ip;
57303+
57304+ /* check transition table */
57305+
57306+ for (trans = current->role->transitions; trans; trans = trans->next) {
57307+ if (!strcmp(rolename, trans->rolename)) {
57308+ found = 1;
57309+ break;
57310+ }
57311+ }
57312+
57313+ if (!found)
57314+ return 0;
57315+
57316+ /* handle special roles that do not require authentication
57317+ and check ip */
57318+
57319+ FOR_EACH_ROLE_START(r)
57320+ if (!strcmp(rolename, r->rolename) &&
57321+ (r->roletype & GR_ROLE_SPECIAL)) {
57322+ found = 0;
57323+ if (r->allowed_ips != NULL) {
57324+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
57325+ if ((ntohl(curr_ip) & ipp->netmask) ==
57326+ (ntohl(ipp->addr) & ipp->netmask))
57327+ found = 1;
57328+ }
57329+ } else
57330+ found = 2;
57331+ if (!found)
57332+ return 0;
57333+
57334+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
57335+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
57336+ *salt = NULL;
57337+ *sum = NULL;
57338+ return 1;
57339+ }
57340+ }
57341+ FOR_EACH_ROLE_END(r)
57342+
57343+ for (i = 0; i < num_sprole_pws; i++) {
57344+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
57345+ *salt = acl_special_roles[i]->salt;
57346+ *sum = acl_special_roles[i]->sum;
57347+ return 1;
57348+ }
57349+ }
57350+
57351+ return 0;
57352+}
57353+
57354+static void
57355+assign_special_role(char *rolename)
57356+{
57357+ struct acl_object_label *obj;
57358+ struct acl_role_label *r;
57359+ struct acl_role_label *assigned = NULL;
57360+ struct task_struct *tsk;
57361+ struct file *filp;
57362+
57363+ FOR_EACH_ROLE_START(r)
57364+ if (!strcmp(rolename, r->rolename) &&
57365+ (r->roletype & GR_ROLE_SPECIAL)) {
57366+ assigned = r;
57367+ break;
57368+ }
57369+ FOR_EACH_ROLE_END(r)
57370+
57371+ if (!assigned)
57372+ return;
57373+
57374+ read_lock(&tasklist_lock);
57375+ read_lock(&grsec_exec_file_lock);
57376+
57377+ tsk = current->real_parent;
57378+ if (tsk == NULL)
57379+ goto out_unlock;
57380+
57381+ filp = tsk->exec_file;
57382+ if (filp == NULL)
57383+ goto out_unlock;
57384+
57385+ tsk->is_writable = 0;
57386+
57387+ tsk->acl_sp_role = 1;
57388+ tsk->acl_role_id = ++acl_sp_role_value;
57389+ tsk->role = assigned;
57390+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
57391+
57392+ /* ignore additional mmap checks for processes that are writable
57393+ by the default ACL */
57394+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57395+ if (unlikely(obj->mode & GR_WRITE))
57396+ tsk->is_writable = 1;
57397+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
57398+ if (unlikely(obj->mode & GR_WRITE))
57399+ tsk->is_writable = 1;
57400+
57401+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57402+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
57403+#endif
57404+
57405+out_unlock:
57406+ read_unlock(&grsec_exec_file_lock);
57407+ read_unlock(&tasklist_lock);
57408+ return;
57409+}
57410+
57411+int gr_check_secure_terminal(struct task_struct *task)
57412+{
57413+ struct task_struct *p, *p2, *p3;
57414+ struct files_struct *files;
57415+ struct fdtable *fdt;
57416+ struct file *our_file = NULL, *file;
57417+ int i;
57418+
57419+ if (task->signal->tty == NULL)
57420+ return 1;
57421+
57422+ files = get_files_struct(task);
57423+ if (files != NULL) {
57424+ rcu_read_lock();
57425+ fdt = files_fdtable(files);
57426+ for (i=0; i < fdt->max_fds; i++) {
57427+ file = fcheck_files(files, i);
57428+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
57429+ get_file(file);
57430+ our_file = file;
57431+ }
57432+ }
57433+ rcu_read_unlock();
57434+ put_files_struct(files);
57435+ }
57436+
57437+ if (our_file == NULL)
57438+ return 1;
57439+
57440+ read_lock(&tasklist_lock);
57441+ do_each_thread(p2, p) {
57442+ files = get_files_struct(p);
57443+ if (files == NULL ||
57444+ (p->signal && p->signal->tty == task->signal->tty)) {
57445+ if (files != NULL)
57446+ put_files_struct(files);
57447+ continue;
57448+ }
57449+ rcu_read_lock();
57450+ fdt = files_fdtable(files);
57451+ for (i=0; i < fdt->max_fds; i++) {
57452+ file = fcheck_files(files, i);
57453+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
57454+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
57455+ p3 = task;
57456+ while (p3->pid > 0) {
57457+ if (p3 == p)
57458+ break;
57459+ p3 = p3->real_parent;
57460+ }
57461+ if (p3 == p)
57462+ break;
57463+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
57464+ gr_handle_alertkill(p);
57465+ rcu_read_unlock();
57466+ put_files_struct(files);
57467+ read_unlock(&tasklist_lock);
57468+ fput(our_file);
57469+ return 0;
57470+ }
57471+ }
57472+ rcu_read_unlock();
57473+ put_files_struct(files);
57474+ } while_each_thread(p2, p);
57475+ read_unlock(&tasklist_lock);
57476+
57477+ fput(our_file);
57478+ return 1;
57479+}
57480+
57481+static int gr_rbac_disable(void *unused)
57482+{
57483+ pax_open_kernel();
57484+ gr_status &= ~GR_READY;
57485+ pax_close_kernel();
57486+
57487+ return 0;
57488+}
57489+
57490+ssize_t
57491+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
57492+{
57493+ struct gr_arg_wrapper uwrap;
57494+ unsigned char *sprole_salt = NULL;
57495+ unsigned char *sprole_sum = NULL;
57496+ int error = sizeof (struct gr_arg_wrapper);
57497+ int error2 = 0;
57498+
57499+ mutex_lock(&gr_dev_mutex);
57500+
57501+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
57502+ error = -EPERM;
57503+ goto out;
57504+ }
57505+
57506+ if (count != sizeof (struct gr_arg_wrapper)) {
57507+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
57508+ error = -EINVAL;
57509+ goto out;
57510+ }
57511+
57512+
57513+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
57514+ gr_auth_expires = 0;
57515+ gr_auth_attempts = 0;
57516+ }
57517+
57518+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
57519+ error = -EFAULT;
57520+ goto out;
57521+ }
57522+
57523+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
57524+ error = -EINVAL;
57525+ goto out;
57526+ }
57527+
57528+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
57529+ error = -EFAULT;
57530+ goto out;
57531+ }
57532+
57533+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
57534+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
57535+ time_after(gr_auth_expires, get_seconds())) {
57536+ error = -EBUSY;
57537+ goto out;
57538+ }
57539+
57540+ /* if non-root trying to do anything other than use a special role,
57541+ do not attempt authentication, do not count towards authentication
57542+ locking
57543+ */
57544+
57545+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
57546+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
57547+ !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
57548+ error = -EPERM;
57549+ goto out;
57550+ }
57551+
57552+ /* ensure pw and special role name are null terminated */
57553+
57554+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
57555+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
57556+
57557+ /* Okay.
57558+ * We have our enough of the argument structure..(we have yet
57559+ * to copy_from_user the tables themselves) . Copy the tables
57560+ * only if we need them, i.e. for loading operations. */
57561+
57562+ switch (gr_usermode->mode) {
57563+ case GR_STATUS:
57564+ if (gr_status & GR_READY) {
57565+ error = 1;
57566+ if (!gr_check_secure_terminal(current))
57567+ error = 3;
57568+ } else
57569+ error = 2;
57570+ goto out;
57571+ case GR_SHUTDOWN:
57572+ if ((gr_status & GR_READY)
57573+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57574+ stop_machine(gr_rbac_disable, NULL, NULL);
57575+ free_variables();
57576+ memset(gr_usermode, 0, sizeof (struct gr_arg));
57577+ memset(gr_system_salt, 0, GR_SALT_LEN);
57578+ memset(gr_system_sum, 0, GR_SHA_LEN);
57579+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
57580+ } else if (gr_status & GR_READY) {
57581+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
57582+ error = -EPERM;
57583+ } else {
57584+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
57585+ error = -EAGAIN;
57586+ }
57587+ break;
57588+ case GR_ENABLE:
57589+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
57590+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
57591+ else {
57592+ if (gr_status & GR_READY)
57593+ error = -EAGAIN;
57594+ else
57595+ error = error2;
57596+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
57597+ }
57598+ break;
57599+ case GR_RELOAD:
57600+ if (!(gr_status & GR_READY)) {
57601+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
57602+ error = -EAGAIN;
57603+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57604+ stop_machine(gr_rbac_disable, NULL, NULL);
57605+ free_variables();
57606+ error2 = gracl_init(gr_usermode);
57607+ if (!error2)
57608+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
57609+ else {
57610+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
57611+ error = error2;
57612+ }
57613+ } else {
57614+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
57615+ error = -EPERM;
57616+ }
57617+ break;
57618+ case GR_SEGVMOD:
57619+ if (unlikely(!(gr_status & GR_READY))) {
57620+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
57621+ error = -EAGAIN;
57622+ break;
57623+ }
57624+
57625+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57626+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
57627+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
57628+ struct acl_subject_label *segvacl;
57629+ segvacl =
57630+ lookup_acl_subj_label(gr_usermode->segv_inode,
57631+ gr_usermode->segv_device,
57632+ current->role);
57633+ if (segvacl) {
57634+ segvacl->crashes = 0;
57635+ segvacl->expires = 0;
57636+ }
57637+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
57638+ gr_remove_uid(gr_usermode->segv_uid);
57639+ }
57640+ } else {
57641+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
57642+ error = -EPERM;
57643+ }
57644+ break;
57645+ case GR_SPROLE:
57646+ case GR_SPROLEPAM:
57647+ if (unlikely(!(gr_status & GR_READY))) {
57648+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
57649+ error = -EAGAIN;
57650+ break;
57651+ }
57652+
57653+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
57654+ current->role->expires = 0;
57655+ current->role->auth_attempts = 0;
57656+ }
57657+
57658+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
57659+ time_after(current->role->expires, get_seconds())) {
57660+ error = -EBUSY;
57661+ goto out;
57662+ }
57663+
57664+ if (lookup_special_role_auth
57665+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
57666+ && ((!sprole_salt && !sprole_sum)
57667+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
57668+ char *p = "";
57669+ assign_special_role(gr_usermode->sp_role);
57670+ read_lock(&tasklist_lock);
57671+ if (current->real_parent)
57672+ p = current->real_parent->role->rolename;
57673+ read_unlock(&tasklist_lock);
57674+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
57675+ p, acl_sp_role_value);
57676+ } else {
57677+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
57678+ error = -EPERM;
57679+ if(!(current->role->auth_attempts++))
57680+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
57681+
57682+ goto out;
57683+ }
57684+ break;
57685+ case GR_UNSPROLE:
57686+ if (unlikely(!(gr_status & GR_READY))) {
57687+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
57688+ error = -EAGAIN;
57689+ break;
57690+ }
57691+
57692+ if (current->role->roletype & GR_ROLE_SPECIAL) {
57693+ char *p = "";
57694+ int i = 0;
57695+
57696+ read_lock(&tasklist_lock);
57697+ if (current->real_parent) {
57698+ p = current->real_parent->role->rolename;
57699+ i = current->real_parent->acl_role_id;
57700+ }
57701+ read_unlock(&tasklist_lock);
57702+
57703+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
57704+ gr_set_acls(1);
57705+ } else {
57706+ error = -EPERM;
57707+ goto out;
57708+ }
57709+ break;
57710+ default:
57711+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
57712+ error = -EINVAL;
57713+ break;
57714+ }
57715+
57716+ if (error != -EPERM)
57717+ goto out;
57718+
57719+ if(!(gr_auth_attempts++))
57720+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
57721+
57722+ out:
57723+ mutex_unlock(&gr_dev_mutex);
57724+ return error;
57725+}
57726+
57727+/* must be called with
57728+ rcu_read_lock();
57729+ read_lock(&tasklist_lock);
57730+ read_lock(&grsec_exec_file_lock);
57731+*/
57732+int gr_apply_subject_to_task(struct task_struct *task)
57733+{
57734+ struct acl_object_label *obj;
57735+ char *tmpname;
57736+ struct acl_subject_label *tmpsubj;
57737+ struct file *filp;
57738+ struct name_entry *nmatch;
57739+
57740+ filp = task->exec_file;
57741+ if (filp == NULL)
57742+ return 0;
57743+
57744+ /* the following is to apply the correct subject
57745+ on binaries running when the RBAC system
57746+ is enabled, when the binaries have been
57747+ replaced or deleted since their execution
57748+ -----
57749+ when the RBAC system starts, the inode/dev
57750+ from exec_file will be one the RBAC system
57751+ is unaware of. It only knows the inode/dev
57752+ of the present file on disk, or the absence
57753+ of it.
57754+ */
57755+ preempt_disable();
57756+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
57757+
57758+ nmatch = lookup_name_entry(tmpname);
57759+ preempt_enable();
57760+ tmpsubj = NULL;
57761+ if (nmatch) {
57762+ if (nmatch->deleted)
57763+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
57764+ else
57765+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
57766+ if (tmpsubj != NULL)
57767+ task->acl = tmpsubj;
57768+ }
57769+ if (tmpsubj == NULL)
57770+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
57771+ task->role);
57772+ if (task->acl) {
57773+ task->is_writable = 0;
57774+ /* ignore additional mmap checks for processes that are writable
57775+ by the default ACL */
57776+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57777+ if (unlikely(obj->mode & GR_WRITE))
57778+ task->is_writable = 1;
57779+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
57780+ if (unlikely(obj->mode & GR_WRITE))
57781+ task->is_writable = 1;
57782+
57783+ gr_set_proc_res(task);
57784+
57785+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57786+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57787+#endif
57788+ } else {
57789+ return 1;
57790+ }
57791+
57792+ return 0;
57793+}
57794+
57795+int
57796+gr_set_acls(const int type)
57797+{
57798+ struct task_struct *task, *task2;
57799+ struct acl_role_label *role = current->role;
57800+ __u16 acl_role_id = current->acl_role_id;
57801+ const struct cred *cred;
57802+ int ret;
57803+
57804+ rcu_read_lock();
57805+ read_lock(&tasklist_lock);
57806+ read_lock(&grsec_exec_file_lock);
57807+ do_each_thread(task2, task) {
57808+ /* check to see if we're called from the exit handler,
57809+ if so, only replace ACLs that have inherited the admin
57810+ ACL */
57811+
57812+ if (type && (task->role != role ||
57813+ task->acl_role_id != acl_role_id))
57814+ continue;
57815+
57816+ task->acl_role_id = 0;
57817+ task->acl_sp_role = 0;
57818+
57819+ if (task->exec_file) {
57820+ cred = __task_cred(task);
57821+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
57822+ ret = gr_apply_subject_to_task(task);
57823+ if (ret) {
57824+ read_unlock(&grsec_exec_file_lock);
57825+ read_unlock(&tasklist_lock);
57826+ rcu_read_unlock();
57827+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
57828+ return ret;
57829+ }
57830+ } else {
57831+ // it's a kernel process
57832+ task->role = kernel_role;
57833+ task->acl = kernel_role->root_label;
57834+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
57835+ task->acl->mode &= ~GR_PROCFIND;
57836+#endif
57837+ }
57838+ } while_each_thread(task2, task);
57839+ read_unlock(&grsec_exec_file_lock);
57840+ read_unlock(&tasklist_lock);
57841+ rcu_read_unlock();
57842+
57843+ return 0;
57844+}
57845+
57846+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
57847+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
57848+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
57849+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
57850+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
57851+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
57852+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
57853+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
57854+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
57855+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
57856+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
57857+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
57858+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
57859+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
57860+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
57861+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
57862+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
57863+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
57864+};
57865+
57866+void
57867+gr_learn_resource(const struct task_struct *task,
57868+ const int res, const unsigned long wanted, const int gt)
57869+{
57870+ struct acl_subject_label *acl;
57871+ const struct cred *cred;
57872+
57873+ if (unlikely((gr_status & GR_READY) &&
57874+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
57875+ goto skip_reslog;
57876+
57877+ gr_log_resource(task, res, wanted, gt);
57878+skip_reslog:
57879+
57880+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
57881+ return;
57882+
57883+ acl = task->acl;
57884+
57885+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
57886+ !(acl->resmask & (1 << (unsigned short) res))))
57887+ return;
57888+
57889+ if (wanted >= acl->res[res].rlim_cur) {
57890+ unsigned long res_add;
57891+
57892+ res_add = wanted + res_learn_bumps[res];
57893+
57894+ acl->res[res].rlim_cur = res_add;
57895+
57896+ if (wanted > acl->res[res].rlim_max)
57897+ acl->res[res].rlim_max = res_add;
57898+
57899+ /* only log the subject filename, since resource logging is supported for
57900+ single-subject learning only */
57901+ rcu_read_lock();
57902+ cred = __task_cred(task);
57903+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57904+ task->role->roletype, cred->uid, cred->gid, acl->filename,
57905+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
57906+ "", (unsigned long) res, &task->signal->saved_ip);
57907+ rcu_read_unlock();
57908+ }
57909+
57910+ return;
57911+}
57912+EXPORT_SYMBOL(gr_learn_resource);
57913+#endif
57914+
57915+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
57916+void
57917+pax_set_initial_flags(struct linux_binprm *bprm)
57918+{
57919+ struct task_struct *task = current;
57920+ struct acl_subject_label *proc;
57921+ unsigned long flags;
57922+
57923+ if (unlikely(!(gr_status & GR_READY)))
57924+ return;
57925+
57926+ flags = pax_get_flags(task);
57927+
57928+ proc = task->acl;
57929+
57930+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
57931+ flags &= ~MF_PAX_PAGEEXEC;
57932+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
57933+ flags &= ~MF_PAX_SEGMEXEC;
57934+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
57935+ flags &= ~MF_PAX_RANDMMAP;
57936+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
57937+ flags &= ~MF_PAX_EMUTRAMP;
57938+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
57939+ flags &= ~MF_PAX_MPROTECT;
57940+
57941+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
57942+ flags |= MF_PAX_PAGEEXEC;
57943+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
57944+ flags |= MF_PAX_SEGMEXEC;
57945+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
57946+ flags |= MF_PAX_RANDMMAP;
57947+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
57948+ flags |= MF_PAX_EMUTRAMP;
57949+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
57950+ flags |= MF_PAX_MPROTECT;
57951+
57952+ pax_set_flags(task, flags);
57953+
57954+ return;
57955+}
57956+#endif
57957+
57958+int
57959+gr_handle_proc_ptrace(struct task_struct *task)
57960+{
57961+ struct file *filp;
57962+ struct task_struct *tmp = task;
57963+ struct task_struct *curtemp = current;
57964+ __u32 retmode;
57965+
57966+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
57967+ if (unlikely(!(gr_status & GR_READY)))
57968+ return 0;
57969+#endif
57970+
57971+ read_lock(&tasklist_lock);
57972+ read_lock(&grsec_exec_file_lock);
57973+ filp = task->exec_file;
57974+
57975+ while (tmp->pid > 0) {
57976+ if (tmp == curtemp)
57977+ break;
57978+ tmp = tmp->real_parent;
57979+ }
57980+
57981+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
57982+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
57983+ read_unlock(&grsec_exec_file_lock);
57984+ read_unlock(&tasklist_lock);
57985+ return 1;
57986+ }
57987+
57988+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57989+ if (!(gr_status & GR_READY)) {
57990+ read_unlock(&grsec_exec_file_lock);
57991+ read_unlock(&tasklist_lock);
57992+ return 0;
57993+ }
57994+#endif
57995+
57996+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
57997+ read_unlock(&grsec_exec_file_lock);
57998+ read_unlock(&tasklist_lock);
57999+
58000+ if (retmode & GR_NOPTRACE)
58001+ return 1;
58002+
58003+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
58004+ && (current->acl != task->acl || (current->acl != current->role->root_label
58005+ && current->pid != task->pid)))
58006+ return 1;
58007+
58008+ return 0;
58009+}
58010+
58011+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
58012+{
58013+ if (unlikely(!(gr_status & GR_READY)))
58014+ return;
58015+
58016+ if (!(current->role->roletype & GR_ROLE_GOD))
58017+ return;
58018+
58019+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
58020+ p->role->rolename, gr_task_roletype_to_char(p),
58021+ p->acl->filename);
58022+}
58023+
58024+int
58025+gr_handle_ptrace(struct task_struct *task, const long request)
58026+{
58027+ struct task_struct *tmp = task;
58028+ struct task_struct *curtemp = current;
58029+ __u32 retmode;
58030+
58031+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
58032+ if (unlikely(!(gr_status & GR_READY)))
58033+ return 0;
58034+#endif
58035+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
58036+ read_lock(&tasklist_lock);
58037+ while (tmp->pid > 0) {
58038+ if (tmp == curtemp)
58039+ break;
58040+ tmp = tmp->real_parent;
58041+ }
58042+
58043+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
58044+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
58045+ read_unlock(&tasklist_lock);
58046+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58047+ return 1;
58048+ }
58049+ read_unlock(&tasklist_lock);
58050+ }
58051+
58052+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58053+ if (!(gr_status & GR_READY))
58054+ return 0;
58055+#endif
58056+
58057+ read_lock(&grsec_exec_file_lock);
58058+ if (unlikely(!task->exec_file)) {
58059+ read_unlock(&grsec_exec_file_lock);
58060+ return 0;
58061+ }
58062+
58063+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
58064+ read_unlock(&grsec_exec_file_lock);
58065+
58066+ if (retmode & GR_NOPTRACE) {
58067+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58068+ return 1;
58069+ }
58070+
58071+ if (retmode & GR_PTRACERD) {
58072+ switch (request) {
58073+ case PTRACE_SEIZE:
58074+ case PTRACE_POKETEXT:
58075+ case PTRACE_POKEDATA:
58076+ case PTRACE_POKEUSR:
58077+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
58078+ case PTRACE_SETREGS:
58079+ case PTRACE_SETFPREGS:
58080+#endif
58081+#ifdef CONFIG_X86
58082+ case PTRACE_SETFPXREGS:
58083+#endif
58084+#ifdef CONFIG_ALTIVEC
58085+ case PTRACE_SETVRREGS:
58086+#endif
58087+ return 1;
58088+ default:
58089+ return 0;
58090+ }
58091+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
58092+ !(current->role->roletype & GR_ROLE_GOD) &&
58093+ (current->acl != task->acl)) {
58094+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58095+ return 1;
58096+ }
58097+
58098+ return 0;
58099+}
58100+
58101+static int is_writable_mmap(const struct file *filp)
58102+{
58103+ struct task_struct *task = current;
58104+ struct acl_object_label *obj, *obj2;
58105+
58106+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
58107+ !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))) {
58108+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
58109+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
58110+ task->role->root_label);
58111+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
58112+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
58113+ return 1;
58114+ }
58115+ }
58116+ return 0;
58117+}
58118+
58119+int
58120+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
58121+{
58122+ __u32 mode;
58123+
58124+ if (unlikely(!file || !(prot & PROT_EXEC)))
58125+ return 1;
58126+
58127+ if (is_writable_mmap(file))
58128+ return 0;
58129+
58130+ mode =
58131+ gr_search_file(file->f_path.dentry,
58132+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
58133+ file->f_path.mnt);
58134+
58135+ if (!gr_tpe_allow(file))
58136+ return 0;
58137+
58138+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
58139+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58140+ return 0;
58141+ } else if (unlikely(!(mode & GR_EXEC))) {
58142+ return 0;
58143+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
58144+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58145+ return 1;
58146+ }
58147+
58148+ return 1;
58149+}
58150+
58151+int
58152+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58153+{
58154+ __u32 mode;
58155+
58156+ if (unlikely(!file || !(prot & PROT_EXEC)))
58157+ return 1;
58158+
58159+ if (is_writable_mmap(file))
58160+ return 0;
58161+
58162+ mode =
58163+ gr_search_file(file->f_path.dentry,
58164+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
58165+ file->f_path.mnt);
58166+
58167+ if (!gr_tpe_allow(file))
58168+ return 0;
58169+
58170+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
58171+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58172+ return 0;
58173+ } else if (unlikely(!(mode & GR_EXEC))) {
58174+ return 0;
58175+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
58176+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58177+ return 1;
58178+ }
58179+
58180+ return 1;
58181+}
58182+
58183+void
58184+gr_acl_handle_psacct(struct task_struct *task, const long code)
58185+{
58186+ unsigned long runtime;
58187+ unsigned long cputime;
58188+ unsigned int wday, cday;
58189+ __u8 whr, chr;
58190+ __u8 wmin, cmin;
58191+ __u8 wsec, csec;
58192+ struct timespec timeval;
58193+
58194+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
58195+ !(task->acl->mode & GR_PROCACCT)))
58196+ return;
58197+
58198+ do_posix_clock_monotonic_gettime(&timeval);
58199+ runtime = timeval.tv_sec - task->start_time.tv_sec;
58200+ wday = runtime / (3600 * 24);
58201+ runtime -= wday * (3600 * 24);
58202+ whr = runtime / 3600;
58203+ runtime -= whr * 3600;
58204+ wmin = runtime / 60;
58205+ runtime -= wmin * 60;
58206+ wsec = runtime;
58207+
58208+ cputime = (task->utime + task->stime) / HZ;
58209+ cday = cputime / (3600 * 24);
58210+ cputime -= cday * (3600 * 24);
58211+ chr = cputime / 3600;
58212+ cputime -= chr * 3600;
58213+ cmin = cputime / 60;
58214+ cputime -= cmin * 60;
58215+ csec = cputime;
58216+
58217+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
58218+
58219+ return;
58220+}
58221+
58222+void gr_set_kernel_label(struct task_struct *task)
58223+{
58224+ if (gr_status & GR_READY) {
58225+ task->role = kernel_role;
58226+ task->acl = kernel_role->root_label;
58227+ }
58228+ return;
58229+}
58230+
58231+#ifdef CONFIG_TASKSTATS
58232+int gr_is_taskstats_denied(int pid)
58233+{
58234+ struct task_struct *task;
58235+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58236+ const struct cred *cred;
58237+#endif
58238+ int ret = 0;
58239+
58240+ /* restrict taskstats viewing to un-chrooted root users
58241+ who have the 'view' subject flag if the RBAC system is enabled
58242+ */
58243+
58244+ rcu_read_lock();
58245+ read_lock(&tasklist_lock);
58246+ task = find_task_by_vpid(pid);
58247+ if (task) {
58248+#ifdef CONFIG_GRKERNSEC_CHROOT
58249+ if (proc_is_chrooted(task))
58250+ ret = -EACCES;
58251+#endif
58252+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58253+ cred = __task_cred(task);
58254+#ifdef CONFIG_GRKERNSEC_PROC_USER
58255+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
58256+ ret = -EACCES;
58257+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58258+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
58259+ ret = -EACCES;
58260+#endif
58261+#endif
58262+ if (gr_status & GR_READY) {
58263+ if (!(task->acl->mode & GR_VIEW))
58264+ ret = -EACCES;
58265+ }
58266+ } else
58267+ ret = -ENOENT;
58268+
58269+ read_unlock(&tasklist_lock);
58270+ rcu_read_unlock();
58271+
58272+ return ret;
58273+}
58274+#endif
58275+
58276+/* AUXV entries are filled via a descendant of search_binary_handler
58277+ after we've already applied the subject for the target
58278+*/
58279+int gr_acl_enable_at_secure(void)
58280+{
58281+ if (unlikely(!(gr_status & GR_READY)))
58282+ return 0;
58283+
58284+ if (current->acl->mode & GR_ATSECURE)
58285+ return 1;
58286+
58287+ return 0;
58288+}
58289+
58290+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
58291+{
58292+ struct task_struct *task = current;
58293+ struct dentry *dentry = file->f_path.dentry;
58294+ struct vfsmount *mnt = file->f_path.mnt;
58295+ struct acl_object_label *obj, *tmp;
58296+ struct acl_subject_label *subj;
58297+ unsigned int bufsize;
58298+ int is_not_root;
58299+ char *path;
58300+ dev_t dev = __get_dev(dentry);
58301+
58302+ if (unlikely(!(gr_status & GR_READY)))
58303+ return 1;
58304+
58305+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
58306+ return 1;
58307+
58308+ /* ignore Eric Biederman */
58309+ if (IS_PRIVATE(dentry->d_inode))
58310+ return 1;
58311+
58312+ subj = task->acl;
58313+ read_lock(&gr_inode_lock);
58314+ do {
58315+ obj = lookup_acl_obj_label(ino, dev, subj);
58316+ if (obj != NULL) {
58317+ read_unlock(&gr_inode_lock);
58318+ return (obj->mode & GR_FIND) ? 1 : 0;
58319+ }
58320+ } while ((subj = subj->parent_subject));
58321+ read_unlock(&gr_inode_lock);
58322+
58323+ /* this is purely an optimization since we're looking for an object
58324+ for the directory we're doing a readdir on
58325+ if it's possible for any globbed object to match the entry we're
58326+ filling into the directory, then the object we find here will be
58327+ an anchor point with attached globbed objects
58328+ */
58329+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
58330+ if (obj->globbed == NULL)
58331+ return (obj->mode & GR_FIND) ? 1 : 0;
58332+
58333+ is_not_root = ((obj->filename[0] == '/') &&
58334+ (obj->filename[1] == '\0')) ? 0 : 1;
58335+ bufsize = PAGE_SIZE - namelen - is_not_root;
58336+
58337+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
58338+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
58339+ return 1;
58340+
58341+ preempt_disable();
58342+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
58343+ bufsize);
58344+
58345+ bufsize = strlen(path);
58346+
58347+ /* if base is "/", don't append an additional slash */
58348+ if (is_not_root)
58349+ *(path + bufsize) = '/';
58350+ memcpy(path + bufsize + is_not_root, name, namelen);
58351+ *(path + bufsize + namelen + is_not_root) = '\0';
58352+
58353+ tmp = obj->globbed;
58354+ while (tmp) {
58355+ if (!glob_match(tmp->filename, path)) {
58356+ preempt_enable();
58357+ return (tmp->mode & GR_FIND) ? 1 : 0;
58358+ }
58359+ tmp = tmp->next;
58360+ }
58361+ preempt_enable();
58362+ return (obj->mode & GR_FIND) ? 1 : 0;
58363+}
58364+
58365+void gr_put_exec_file(struct task_struct *task)
58366+{
58367+ struct file *filp;
58368+
58369+ write_lock(&grsec_exec_file_lock);
58370+ filp = task->exec_file;
58371+ task->exec_file = NULL;
58372+ write_unlock(&grsec_exec_file_lock);
58373+
58374+ if (filp)
58375+ fput(filp);
58376+
58377+ return;
58378+}
58379+
58380+
58381+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
58382+EXPORT_SYMBOL(gr_acl_is_enabled);
58383+#endif
58384+EXPORT_SYMBOL(gr_set_kernel_label);
58385+#ifdef CONFIG_SECURITY
58386+EXPORT_SYMBOL(gr_check_user_change);
58387+EXPORT_SYMBOL(gr_check_group_change);
58388+#endif
58389+
58390diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
58391new file mode 100644
58392index 0000000..34fefda
58393--- /dev/null
58394+++ b/grsecurity/gracl_alloc.c
58395@@ -0,0 +1,105 @@
58396+#include <linux/kernel.h>
58397+#include <linux/mm.h>
58398+#include <linux/slab.h>
58399+#include <linux/vmalloc.h>
58400+#include <linux/gracl.h>
58401+#include <linux/grsecurity.h>
58402+
58403+static unsigned long alloc_stack_next = 1;
58404+static unsigned long alloc_stack_size = 1;
58405+static void **alloc_stack;
58406+
58407+static __inline__ int
58408+alloc_pop(void)
58409+{
58410+ if (alloc_stack_next == 1)
58411+ return 0;
58412+
58413+ kfree(alloc_stack[alloc_stack_next - 2]);
58414+
58415+ alloc_stack_next--;
58416+
58417+ return 1;
58418+}
58419+
58420+static __inline__ int
58421+alloc_push(void *buf)
58422+{
58423+ if (alloc_stack_next >= alloc_stack_size)
58424+ return 1;
58425+
58426+ alloc_stack[alloc_stack_next - 1] = buf;
58427+
58428+ alloc_stack_next++;
58429+
58430+ return 0;
58431+}
58432+
58433+void *
58434+acl_alloc(unsigned long len)
58435+{
58436+ void *ret = NULL;
58437+
58438+ if (!len || len > PAGE_SIZE)
58439+ goto out;
58440+
58441+ ret = kmalloc(len, GFP_KERNEL);
58442+
58443+ if (ret) {
58444+ if (alloc_push(ret)) {
58445+ kfree(ret);
58446+ ret = NULL;
58447+ }
58448+ }
58449+
58450+out:
58451+ return ret;
58452+}
58453+
58454+void *
58455+acl_alloc_num(unsigned long num, unsigned long len)
58456+{
58457+ if (!len || (num > (PAGE_SIZE / len)))
58458+ return NULL;
58459+
58460+ return acl_alloc(num * len);
58461+}
58462+
58463+void
58464+acl_free_all(void)
58465+{
58466+ if (gr_acl_is_enabled() || !alloc_stack)
58467+ return;
58468+
58469+ while (alloc_pop()) ;
58470+
58471+ if (alloc_stack) {
58472+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
58473+ kfree(alloc_stack);
58474+ else
58475+ vfree(alloc_stack);
58476+ }
58477+
58478+ alloc_stack = NULL;
58479+ alloc_stack_size = 1;
58480+ alloc_stack_next = 1;
58481+
58482+ return;
58483+}
58484+
58485+int
58486+acl_alloc_stack_init(unsigned long size)
58487+{
58488+ if ((size * sizeof (void *)) <= PAGE_SIZE)
58489+ alloc_stack =
58490+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
58491+ else
58492+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
58493+
58494+ alloc_stack_size = size;
58495+
58496+ if (!alloc_stack)
58497+ return 0;
58498+ else
58499+ return 1;
58500+}
58501diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
58502new file mode 100644
58503index 0000000..6d21049
58504--- /dev/null
58505+++ b/grsecurity/gracl_cap.c
58506@@ -0,0 +1,110 @@
58507+#include <linux/kernel.h>
58508+#include <linux/module.h>
58509+#include <linux/sched.h>
58510+#include <linux/gracl.h>
58511+#include <linux/grsecurity.h>
58512+#include <linux/grinternal.h>
58513+
58514+extern const char *captab_log[];
58515+extern int captab_log_entries;
58516+
58517+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58518+{
58519+ struct acl_subject_label *curracl;
58520+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
58521+ kernel_cap_t cap_audit = __cap_empty_set;
58522+
58523+ if (!gr_acl_is_enabled())
58524+ return 1;
58525+
58526+ curracl = task->acl;
58527+
58528+ cap_drop = curracl->cap_lower;
58529+ cap_mask = curracl->cap_mask;
58530+ cap_audit = curracl->cap_invert_audit;
58531+
58532+ while ((curracl = curracl->parent_subject)) {
58533+ /* if the cap isn't specified in the current computed mask but is specified in the
58534+ current level subject, and is lowered in the current level subject, then add
58535+ it to the set of dropped capabilities
58536+ otherwise, add the current level subject's mask to the current computed mask
58537+ */
58538+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
58539+ cap_raise(cap_mask, cap);
58540+ if (cap_raised(curracl->cap_lower, cap))
58541+ cap_raise(cap_drop, cap);
58542+ if (cap_raised(curracl->cap_invert_audit, cap))
58543+ cap_raise(cap_audit, cap);
58544+ }
58545+ }
58546+
58547+ if (!cap_raised(cap_drop, cap)) {
58548+ if (cap_raised(cap_audit, cap))
58549+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
58550+ return 1;
58551+ }
58552+
58553+ curracl = task->acl;
58554+
58555+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
58556+ && cap_raised(cred->cap_effective, cap)) {
58557+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
58558+ task->role->roletype, cred->uid,
58559+ cred->gid, task->exec_file ?
58560+ gr_to_filename(task->exec_file->f_path.dentry,
58561+ task->exec_file->f_path.mnt) : curracl->filename,
58562+ curracl->filename, 0UL,
58563+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
58564+ return 1;
58565+ }
58566+
58567+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
58568+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
58569+
58570+ return 0;
58571+}
58572+
58573+int
58574+gr_acl_is_capable(const int cap)
58575+{
58576+ return gr_task_acl_is_capable(current, current_cred(), cap);
58577+}
58578+
58579+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
58580+{
58581+ struct acl_subject_label *curracl;
58582+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
58583+
58584+ if (!gr_acl_is_enabled())
58585+ return 1;
58586+
58587+ curracl = task->acl;
58588+
58589+ cap_drop = curracl->cap_lower;
58590+ cap_mask = curracl->cap_mask;
58591+
58592+ while ((curracl = curracl->parent_subject)) {
58593+ /* if the cap isn't specified in the current computed mask but is specified in the
58594+ current level subject, and is lowered in the current level subject, then add
58595+ it to the set of dropped capabilities
58596+ otherwise, add the current level subject's mask to the current computed mask
58597+ */
58598+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
58599+ cap_raise(cap_mask, cap);
58600+ if (cap_raised(curracl->cap_lower, cap))
58601+ cap_raise(cap_drop, cap);
58602+ }
58603+ }
58604+
58605+ if (!cap_raised(cap_drop, cap))
58606+ return 1;
58607+
58608+ return 0;
58609+}
58610+
58611+int
58612+gr_acl_is_capable_nolog(const int cap)
58613+{
58614+ return gr_task_acl_is_capable_nolog(current, cap);
58615+}
58616+
58617diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
58618new file mode 100644
58619index 0000000..a340c17
58620--- /dev/null
58621+++ b/grsecurity/gracl_fs.c
58622@@ -0,0 +1,431 @@
58623+#include <linux/kernel.h>
58624+#include <linux/sched.h>
58625+#include <linux/types.h>
58626+#include <linux/fs.h>
58627+#include <linux/file.h>
58628+#include <linux/stat.h>
58629+#include <linux/grsecurity.h>
58630+#include <linux/grinternal.h>
58631+#include <linux/gracl.h>
58632+
58633+umode_t
58634+gr_acl_umask(void)
58635+{
58636+ if (unlikely(!gr_acl_is_enabled()))
58637+ return 0;
58638+
58639+ return current->role->umask;
58640+}
58641+
58642+__u32
58643+gr_acl_handle_hidden_file(const struct dentry * dentry,
58644+ const struct vfsmount * mnt)
58645+{
58646+ __u32 mode;
58647+
58648+ if (unlikely(!dentry->d_inode))
58649+ return GR_FIND;
58650+
58651+ mode =
58652+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
58653+
58654+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
58655+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
58656+ return mode;
58657+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
58658+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
58659+ return 0;
58660+ } else if (unlikely(!(mode & GR_FIND)))
58661+ return 0;
58662+
58663+ return GR_FIND;
58664+}
58665+
58666+__u32
58667+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58668+ int acc_mode)
58669+{
58670+ __u32 reqmode = GR_FIND;
58671+ __u32 mode;
58672+
58673+ if (unlikely(!dentry->d_inode))
58674+ return reqmode;
58675+
58676+ if (acc_mode & MAY_APPEND)
58677+ reqmode |= GR_APPEND;
58678+ else if (acc_mode & MAY_WRITE)
58679+ reqmode |= GR_WRITE;
58680+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
58681+ reqmode |= GR_READ;
58682+
58683+ mode =
58684+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
58685+ mnt);
58686+
58687+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58688+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
58689+ reqmode & GR_READ ? " reading" : "",
58690+ reqmode & GR_WRITE ? " writing" : reqmode &
58691+ GR_APPEND ? " appending" : "");
58692+ return reqmode;
58693+ } else
58694+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58695+ {
58696+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
58697+ reqmode & GR_READ ? " reading" : "",
58698+ reqmode & GR_WRITE ? " writing" : reqmode &
58699+ GR_APPEND ? " appending" : "");
58700+ return 0;
58701+ } else if (unlikely((mode & reqmode) != reqmode))
58702+ return 0;
58703+
58704+ return reqmode;
58705+}
58706+
58707+__u32
58708+gr_acl_handle_creat(const struct dentry * dentry,
58709+ const struct dentry * p_dentry,
58710+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58711+ const int imode)
58712+{
58713+ __u32 reqmode = GR_WRITE | GR_CREATE;
58714+ __u32 mode;
58715+
58716+ if (acc_mode & MAY_APPEND)
58717+ reqmode |= GR_APPEND;
58718+ // if a directory was required or the directory already exists, then
58719+ // don't count this open as a read
58720+ if ((acc_mode & MAY_READ) &&
58721+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
58722+ reqmode |= GR_READ;
58723+ if ((open_flags & O_CREAT) &&
58724+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
58725+ reqmode |= GR_SETID;
58726+
58727+ mode =
58728+ gr_check_create(dentry, p_dentry, p_mnt,
58729+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
58730+
58731+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58732+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
58733+ reqmode & GR_READ ? " reading" : "",
58734+ reqmode & GR_WRITE ? " writing" : reqmode &
58735+ GR_APPEND ? " appending" : "");
58736+ return reqmode;
58737+ } else
58738+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58739+ {
58740+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
58741+ reqmode & GR_READ ? " reading" : "",
58742+ reqmode & GR_WRITE ? " writing" : reqmode &
58743+ GR_APPEND ? " appending" : "");
58744+ return 0;
58745+ } else if (unlikely((mode & reqmode) != reqmode))
58746+ return 0;
58747+
58748+ return reqmode;
58749+}
58750+
58751+__u32
58752+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
58753+ const int fmode)
58754+{
58755+ __u32 mode, reqmode = GR_FIND;
58756+
58757+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
58758+ reqmode |= GR_EXEC;
58759+ if (fmode & S_IWOTH)
58760+ reqmode |= GR_WRITE;
58761+ if (fmode & S_IROTH)
58762+ reqmode |= GR_READ;
58763+
58764+ mode =
58765+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
58766+ mnt);
58767+
58768+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58769+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58770+ reqmode & GR_READ ? " reading" : "",
58771+ reqmode & GR_WRITE ? " writing" : "",
58772+ reqmode & GR_EXEC ? " executing" : "");
58773+ return reqmode;
58774+ } else
58775+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58776+ {
58777+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58778+ reqmode & GR_READ ? " reading" : "",
58779+ reqmode & GR_WRITE ? " writing" : "",
58780+ reqmode & GR_EXEC ? " executing" : "");
58781+ return 0;
58782+ } else if (unlikely((mode & reqmode) != reqmode))
58783+ return 0;
58784+
58785+ return reqmode;
58786+}
58787+
58788+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
58789+{
58790+ __u32 mode;
58791+
58792+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
58793+
58794+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58795+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
58796+ return mode;
58797+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58798+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
58799+ return 0;
58800+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
58801+ return 0;
58802+
58803+ return (reqmode);
58804+}
58805+
58806+__u32
58807+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58808+{
58809+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
58810+}
58811+
58812+__u32
58813+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
58814+{
58815+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
58816+}
58817+
58818+__u32
58819+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
58820+{
58821+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
58822+}
58823+
58824+__u32
58825+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
58826+{
58827+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
58828+}
58829+
58830+__u32
58831+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
58832+ umode_t *modeptr)
58833+{
58834+ umode_t mode;
58835+
58836+ *modeptr &= ~gr_acl_umask();
58837+ mode = *modeptr;
58838+
58839+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
58840+ return 1;
58841+
58842+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
58843+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
58844+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
58845+ GR_CHMOD_ACL_MSG);
58846+ } else {
58847+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
58848+ }
58849+}
58850+
58851+__u32
58852+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
58853+{
58854+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
58855+}
58856+
58857+__u32
58858+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
58859+{
58860+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
58861+}
58862+
58863+__u32
58864+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
58865+{
58866+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
58867+}
58868+
58869+__u32
58870+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
58871+{
58872+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
58873+ GR_UNIXCONNECT_ACL_MSG);
58874+}
58875+
58876+/* hardlinks require at minimum create and link permission,
58877+ any additional privilege required is based on the
58878+ privilege of the file being linked to
58879+*/
58880+__u32
58881+gr_acl_handle_link(const struct dentry * new_dentry,
58882+ const struct dentry * parent_dentry,
58883+ const struct vfsmount * parent_mnt,
58884+ const struct dentry * old_dentry,
58885+ const struct vfsmount * old_mnt, const struct filename *to)
58886+{
58887+ __u32 mode;
58888+ __u32 needmode = GR_CREATE | GR_LINK;
58889+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
58890+
58891+ mode =
58892+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
58893+ old_mnt);
58894+
58895+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
58896+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58897+ return mode;
58898+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58899+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58900+ return 0;
58901+ } else if (unlikely((mode & needmode) != needmode))
58902+ return 0;
58903+
58904+ return 1;
58905+}
58906+
58907+__u32
58908+gr_acl_handle_symlink(const struct dentry * new_dentry,
58909+ const struct dentry * parent_dentry,
58910+ const struct vfsmount * parent_mnt, const struct filename *from)
58911+{
58912+ __u32 needmode = GR_WRITE | GR_CREATE;
58913+ __u32 mode;
58914+
58915+ mode =
58916+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
58917+ GR_CREATE | GR_AUDIT_CREATE |
58918+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
58919+
58920+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
58921+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
58922+ return mode;
58923+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58924+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
58925+ return 0;
58926+ } else if (unlikely((mode & needmode) != needmode))
58927+ return 0;
58928+
58929+ return (GR_WRITE | GR_CREATE);
58930+}
58931+
58932+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)
58933+{
58934+ __u32 mode;
58935+
58936+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
58937+
58938+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58939+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
58940+ return mode;
58941+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58942+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
58943+ return 0;
58944+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
58945+ return 0;
58946+
58947+ return (reqmode);
58948+}
58949+
58950+__u32
58951+gr_acl_handle_mknod(const struct dentry * new_dentry,
58952+ const struct dentry * parent_dentry,
58953+ const struct vfsmount * parent_mnt,
58954+ const int mode)
58955+{
58956+ __u32 reqmode = GR_WRITE | GR_CREATE;
58957+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
58958+ reqmode |= GR_SETID;
58959+
58960+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
58961+ reqmode, GR_MKNOD_ACL_MSG);
58962+}
58963+
58964+__u32
58965+gr_acl_handle_mkdir(const struct dentry *new_dentry,
58966+ const struct dentry *parent_dentry,
58967+ const struct vfsmount *parent_mnt)
58968+{
58969+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
58970+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
58971+}
58972+
58973+#define RENAME_CHECK_SUCCESS(old, new) \
58974+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
58975+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
58976+
58977+int
58978+gr_acl_handle_rename(struct dentry *new_dentry,
58979+ struct dentry *parent_dentry,
58980+ const struct vfsmount *parent_mnt,
58981+ struct dentry *old_dentry,
58982+ struct inode *old_parent_inode,
58983+ struct vfsmount *old_mnt, const struct filename *newname)
58984+{
58985+ __u32 comp1, comp2;
58986+ int error = 0;
58987+
58988+ if (unlikely(!gr_acl_is_enabled()))
58989+ return 0;
58990+
58991+ if (!new_dentry->d_inode) {
58992+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
58993+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
58994+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
58995+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
58996+ GR_DELETE | GR_AUDIT_DELETE |
58997+ GR_AUDIT_READ | GR_AUDIT_WRITE |
58998+ GR_SUPPRESS, old_mnt);
58999+ } else {
59000+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
59001+ GR_CREATE | GR_DELETE |
59002+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
59003+ GR_AUDIT_READ | GR_AUDIT_WRITE |
59004+ GR_SUPPRESS, parent_mnt);
59005+ comp2 =
59006+ gr_search_file(old_dentry,
59007+ GR_READ | GR_WRITE | GR_AUDIT_READ |
59008+ GR_DELETE | GR_AUDIT_DELETE |
59009+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
59010+ }
59011+
59012+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
59013+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
59014+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
59015+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
59016+ && !(comp2 & GR_SUPPRESS)) {
59017+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
59018+ error = -EACCES;
59019+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
59020+ error = -EACCES;
59021+
59022+ return error;
59023+}
59024+
59025+void
59026+gr_acl_handle_exit(void)
59027+{
59028+ u16 id;
59029+ char *rolename;
59030+
59031+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
59032+ !(current->role->roletype & GR_ROLE_PERSIST))) {
59033+ id = current->acl_role_id;
59034+ rolename = current->role->rolename;
59035+ gr_set_acls(1);
59036+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
59037+ }
59038+
59039+ gr_put_exec_file(current);
59040+ return;
59041+}
59042+
59043+int
59044+gr_acl_handle_procpidmem(const struct task_struct *task)
59045+{
59046+ if (unlikely(!gr_acl_is_enabled()))
59047+ return 0;
59048+
59049+ if (task != current && task->acl->mode & GR_PROTPROCFD)
59050+ return -EACCES;
59051+
59052+ return 0;
59053+}
59054diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
59055new file mode 100644
59056index 0000000..58800a7
59057--- /dev/null
59058+++ b/grsecurity/gracl_ip.c
59059@@ -0,0 +1,384 @@
59060+#include <linux/kernel.h>
59061+#include <asm/uaccess.h>
59062+#include <asm/errno.h>
59063+#include <net/sock.h>
59064+#include <linux/file.h>
59065+#include <linux/fs.h>
59066+#include <linux/net.h>
59067+#include <linux/in.h>
59068+#include <linux/skbuff.h>
59069+#include <linux/ip.h>
59070+#include <linux/udp.h>
59071+#include <linux/types.h>
59072+#include <linux/sched.h>
59073+#include <linux/netdevice.h>
59074+#include <linux/inetdevice.h>
59075+#include <linux/gracl.h>
59076+#include <linux/grsecurity.h>
59077+#include <linux/grinternal.h>
59078+
59079+#define GR_BIND 0x01
59080+#define GR_CONNECT 0x02
59081+#define GR_INVERT 0x04
59082+#define GR_BINDOVERRIDE 0x08
59083+#define GR_CONNECTOVERRIDE 0x10
59084+#define GR_SOCK_FAMILY 0x20
59085+
59086+static const char * gr_protocols[IPPROTO_MAX] = {
59087+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
59088+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
59089+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
59090+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
59091+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
59092+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
59093+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
59094+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
59095+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
59096+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
59097+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
59098+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
59099+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
59100+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
59101+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
59102+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
59103+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
59104+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
59105+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
59106+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
59107+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
59108+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
59109+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
59110+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
59111+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
59112+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
59113+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
59114+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
59115+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
59116+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
59117+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
59118+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
59119+ };
59120+
59121+static const char * gr_socktypes[SOCK_MAX] = {
59122+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
59123+ "unknown:7", "unknown:8", "unknown:9", "packet"
59124+ };
59125+
59126+static const char * gr_sockfamilies[AF_MAX+1] = {
59127+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
59128+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
59129+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
59130+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
59131+ };
59132+
59133+const char *
59134+gr_proto_to_name(unsigned char proto)
59135+{
59136+ return gr_protocols[proto];
59137+}
59138+
59139+const char *
59140+gr_socktype_to_name(unsigned char type)
59141+{
59142+ return gr_socktypes[type];
59143+}
59144+
59145+const char *
59146+gr_sockfamily_to_name(unsigned char family)
59147+{
59148+ return gr_sockfamilies[family];
59149+}
59150+
59151+int
59152+gr_search_socket(const int domain, const int type, const int protocol)
59153+{
59154+ struct acl_subject_label *curr;
59155+ const struct cred *cred = current_cred();
59156+
59157+ if (unlikely(!gr_acl_is_enabled()))
59158+ goto exit;
59159+
59160+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
59161+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
59162+ goto exit; // let the kernel handle it
59163+
59164+ curr = current->acl;
59165+
59166+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
59167+ /* the family is allowed, if this is PF_INET allow it only if
59168+ the extra sock type/protocol checks pass */
59169+ if (domain == PF_INET)
59170+ goto inet_check;
59171+ goto exit;
59172+ } else {
59173+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59174+ __u32 fakeip = 0;
59175+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59176+ current->role->roletype, cred->uid,
59177+ cred->gid, current->exec_file ?
59178+ gr_to_filename(current->exec_file->f_path.dentry,
59179+ current->exec_file->f_path.mnt) :
59180+ curr->filename, curr->filename,
59181+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
59182+ &current->signal->saved_ip);
59183+ goto exit;
59184+ }
59185+ goto exit_fail;
59186+ }
59187+
59188+inet_check:
59189+ /* the rest of this checking is for IPv4 only */
59190+ if (!curr->ips)
59191+ goto exit;
59192+
59193+ if ((curr->ip_type & (1 << type)) &&
59194+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
59195+ goto exit;
59196+
59197+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59198+ /* we don't place acls on raw sockets , and sometimes
59199+ dgram/ip sockets are opened for ioctl and not
59200+ bind/connect, so we'll fake a bind learn log */
59201+ if (type == SOCK_RAW || type == SOCK_PACKET) {
59202+ __u32 fakeip = 0;
59203+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59204+ current->role->roletype, cred->uid,
59205+ cred->gid, current->exec_file ?
59206+ gr_to_filename(current->exec_file->f_path.dentry,
59207+ current->exec_file->f_path.mnt) :
59208+ curr->filename, curr->filename,
59209+ &fakeip, 0, type,
59210+ protocol, GR_CONNECT, &current->signal->saved_ip);
59211+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
59212+ __u32 fakeip = 0;
59213+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59214+ current->role->roletype, cred->uid,
59215+ cred->gid, current->exec_file ?
59216+ gr_to_filename(current->exec_file->f_path.dentry,
59217+ current->exec_file->f_path.mnt) :
59218+ curr->filename, curr->filename,
59219+ &fakeip, 0, type,
59220+ protocol, GR_BIND, &current->signal->saved_ip);
59221+ }
59222+ /* we'll log when they use connect or bind */
59223+ goto exit;
59224+ }
59225+
59226+exit_fail:
59227+ if (domain == PF_INET)
59228+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
59229+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
59230+ else
59231+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
59232+ gr_socktype_to_name(type), protocol);
59233+
59234+ return 0;
59235+exit:
59236+ return 1;
59237+}
59238+
59239+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)
59240+{
59241+ if ((ip->mode & mode) &&
59242+ (ip_port >= ip->low) &&
59243+ (ip_port <= ip->high) &&
59244+ ((ntohl(ip_addr) & our_netmask) ==
59245+ (ntohl(our_addr) & our_netmask))
59246+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
59247+ && (ip->type & (1 << type))) {
59248+ if (ip->mode & GR_INVERT)
59249+ return 2; // specifically denied
59250+ else
59251+ return 1; // allowed
59252+ }
59253+
59254+ return 0; // not specifically allowed, may continue parsing
59255+}
59256+
59257+static int
59258+gr_search_connectbind(const int full_mode, struct sock *sk,
59259+ struct sockaddr_in *addr, const int type)
59260+{
59261+ char iface[IFNAMSIZ] = {0};
59262+ struct acl_subject_label *curr;
59263+ struct acl_ip_label *ip;
59264+ struct inet_sock *isk;
59265+ struct net_device *dev;
59266+ struct in_device *idev;
59267+ unsigned long i;
59268+ int ret;
59269+ int mode = full_mode & (GR_BIND | GR_CONNECT);
59270+ __u32 ip_addr = 0;
59271+ __u32 our_addr;
59272+ __u32 our_netmask;
59273+ char *p;
59274+ __u16 ip_port = 0;
59275+ const struct cred *cred = current_cred();
59276+
59277+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
59278+ return 0;
59279+
59280+ curr = current->acl;
59281+ isk = inet_sk(sk);
59282+
59283+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
59284+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
59285+ addr->sin_addr.s_addr = curr->inaddr_any_override;
59286+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
59287+ struct sockaddr_in saddr;
59288+ int err;
59289+
59290+ saddr.sin_family = AF_INET;
59291+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
59292+ saddr.sin_port = isk->inet_sport;
59293+
59294+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
59295+ if (err)
59296+ return err;
59297+
59298+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
59299+ if (err)
59300+ return err;
59301+ }
59302+
59303+ if (!curr->ips)
59304+ return 0;
59305+
59306+ ip_addr = addr->sin_addr.s_addr;
59307+ ip_port = ntohs(addr->sin_port);
59308+
59309+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59310+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59311+ current->role->roletype, cred->uid,
59312+ cred->gid, current->exec_file ?
59313+ gr_to_filename(current->exec_file->f_path.dentry,
59314+ current->exec_file->f_path.mnt) :
59315+ curr->filename, curr->filename,
59316+ &ip_addr, ip_port, type,
59317+ sk->sk_protocol, mode, &current->signal->saved_ip);
59318+ return 0;
59319+ }
59320+
59321+ for (i = 0; i < curr->ip_num; i++) {
59322+ ip = *(curr->ips + i);
59323+ if (ip->iface != NULL) {
59324+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
59325+ p = strchr(iface, ':');
59326+ if (p != NULL)
59327+ *p = '\0';
59328+ dev = dev_get_by_name(sock_net(sk), iface);
59329+ if (dev == NULL)
59330+ continue;
59331+ idev = in_dev_get(dev);
59332+ if (idev == NULL) {
59333+ dev_put(dev);
59334+ continue;
59335+ }
59336+ rcu_read_lock();
59337+ for_ifa(idev) {
59338+ if (!strcmp(ip->iface, ifa->ifa_label)) {
59339+ our_addr = ifa->ifa_address;
59340+ our_netmask = 0xffffffff;
59341+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
59342+ if (ret == 1) {
59343+ rcu_read_unlock();
59344+ in_dev_put(idev);
59345+ dev_put(dev);
59346+ return 0;
59347+ } else if (ret == 2) {
59348+ rcu_read_unlock();
59349+ in_dev_put(idev);
59350+ dev_put(dev);
59351+ goto denied;
59352+ }
59353+ }
59354+ } endfor_ifa(idev);
59355+ rcu_read_unlock();
59356+ in_dev_put(idev);
59357+ dev_put(dev);
59358+ } else {
59359+ our_addr = ip->addr;
59360+ our_netmask = ip->netmask;
59361+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
59362+ if (ret == 1)
59363+ return 0;
59364+ else if (ret == 2)
59365+ goto denied;
59366+ }
59367+ }
59368+
59369+denied:
59370+ if (mode == GR_BIND)
59371+ 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));
59372+ else if (mode == GR_CONNECT)
59373+ 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));
59374+
59375+ return -EACCES;
59376+}
59377+
59378+int
59379+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
59380+{
59381+ /* always allow disconnection of dgram sockets with connect */
59382+ if (addr->sin_family == AF_UNSPEC)
59383+ return 0;
59384+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
59385+}
59386+
59387+int
59388+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
59389+{
59390+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
59391+}
59392+
59393+int gr_search_listen(struct socket *sock)
59394+{
59395+ struct sock *sk = sock->sk;
59396+ struct sockaddr_in addr;
59397+
59398+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
59399+ addr.sin_port = inet_sk(sk)->inet_sport;
59400+
59401+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
59402+}
59403+
59404+int gr_search_accept(struct socket *sock)
59405+{
59406+ struct sock *sk = sock->sk;
59407+ struct sockaddr_in addr;
59408+
59409+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
59410+ addr.sin_port = inet_sk(sk)->inet_sport;
59411+
59412+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
59413+}
59414+
59415+int
59416+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
59417+{
59418+ if (addr)
59419+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
59420+ else {
59421+ struct sockaddr_in sin;
59422+ const struct inet_sock *inet = inet_sk(sk);
59423+
59424+ sin.sin_addr.s_addr = inet->inet_daddr;
59425+ sin.sin_port = inet->inet_dport;
59426+
59427+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
59428+ }
59429+}
59430+
59431+int
59432+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
59433+{
59434+ struct sockaddr_in sin;
59435+
59436+ if (unlikely(skb->len < sizeof (struct udphdr)))
59437+ return 0; // skip this packet
59438+
59439+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
59440+ sin.sin_port = udp_hdr(skb)->source;
59441+
59442+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
59443+}
59444diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
59445new file mode 100644
59446index 0000000..25f54ef
59447--- /dev/null
59448+++ b/grsecurity/gracl_learn.c
59449@@ -0,0 +1,207 @@
59450+#include <linux/kernel.h>
59451+#include <linux/mm.h>
59452+#include <linux/sched.h>
59453+#include <linux/poll.h>
59454+#include <linux/string.h>
59455+#include <linux/file.h>
59456+#include <linux/types.h>
59457+#include <linux/vmalloc.h>
59458+#include <linux/grinternal.h>
59459+
59460+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
59461+ size_t count, loff_t *ppos);
59462+extern int gr_acl_is_enabled(void);
59463+
59464+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
59465+static int gr_learn_attached;
59466+
59467+/* use a 512k buffer */
59468+#define LEARN_BUFFER_SIZE (512 * 1024)
59469+
59470+static DEFINE_SPINLOCK(gr_learn_lock);
59471+static DEFINE_MUTEX(gr_learn_user_mutex);
59472+
59473+/* we need to maintain two buffers, so that the kernel context of grlearn
59474+ uses a semaphore around the userspace copying, and the other kernel contexts
59475+ use a spinlock when copying into the buffer, since they cannot sleep
59476+*/
59477+static char *learn_buffer;
59478+static char *learn_buffer_user;
59479+static int learn_buffer_len;
59480+static int learn_buffer_user_len;
59481+
59482+static ssize_t
59483+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
59484+{
59485+ DECLARE_WAITQUEUE(wait, current);
59486+ ssize_t retval = 0;
59487+
59488+ add_wait_queue(&learn_wait, &wait);
59489+ set_current_state(TASK_INTERRUPTIBLE);
59490+ do {
59491+ mutex_lock(&gr_learn_user_mutex);
59492+ spin_lock(&gr_learn_lock);
59493+ if (learn_buffer_len)
59494+ break;
59495+ spin_unlock(&gr_learn_lock);
59496+ mutex_unlock(&gr_learn_user_mutex);
59497+ if (file->f_flags & O_NONBLOCK) {
59498+ retval = -EAGAIN;
59499+ goto out;
59500+ }
59501+ if (signal_pending(current)) {
59502+ retval = -ERESTARTSYS;
59503+ goto out;
59504+ }
59505+
59506+ schedule();
59507+ } while (1);
59508+
59509+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
59510+ learn_buffer_user_len = learn_buffer_len;
59511+ retval = learn_buffer_len;
59512+ learn_buffer_len = 0;
59513+
59514+ spin_unlock(&gr_learn_lock);
59515+
59516+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
59517+ retval = -EFAULT;
59518+
59519+ mutex_unlock(&gr_learn_user_mutex);
59520+out:
59521+ set_current_state(TASK_RUNNING);
59522+ remove_wait_queue(&learn_wait, &wait);
59523+ return retval;
59524+}
59525+
59526+static unsigned int
59527+poll_learn(struct file * file, poll_table * wait)
59528+{
59529+ poll_wait(file, &learn_wait, wait);
59530+
59531+ if (learn_buffer_len)
59532+ return (POLLIN | POLLRDNORM);
59533+
59534+ return 0;
59535+}
59536+
59537+void
59538+gr_clear_learn_entries(void)
59539+{
59540+ char *tmp;
59541+
59542+ mutex_lock(&gr_learn_user_mutex);
59543+ spin_lock(&gr_learn_lock);
59544+ tmp = learn_buffer;
59545+ learn_buffer = NULL;
59546+ spin_unlock(&gr_learn_lock);
59547+ if (tmp)
59548+ vfree(tmp);
59549+ if (learn_buffer_user != NULL) {
59550+ vfree(learn_buffer_user);
59551+ learn_buffer_user = NULL;
59552+ }
59553+ learn_buffer_len = 0;
59554+ mutex_unlock(&gr_learn_user_mutex);
59555+
59556+ return;
59557+}
59558+
59559+void
59560+gr_add_learn_entry(const char *fmt, ...)
59561+{
59562+ va_list args;
59563+ unsigned int len;
59564+
59565+ if (!gr_learn_attached)
59566+ return;
59567+
59568+ spin_lock(&gr_learn_lock);
59569+
59570+ /* leave a gap at the end so we know when it's "full" but don't have to
59571+ compute the exact length of the string we're trying to append
59572+ */
59573+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
59574+ spin_unlock(&gr_learn_lock);
59575+ wake_up_interruptible(&learn_wait);
59576+ return;
59577+ }
59578+ if (learn_buffer == NULL) {
59579+ spin_unlock(&gr_learn_lock);
59580+ return;
59581+ }
59582+
59583+ va_start(args, fmt);
59584+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
59585+ va_end(args);
59586+
59587+ learn_buffer_len += len + 1;
59588+
59589+ spin_unlock(&gr_learn_lock);
59590+ wake_up_interruptible(&learn_wait);
59591+
59592+ return;
59593+}
59594+
59595+static int
59596+open_learn(struct inode *inode, struct file *file)
59597+{
59598+ if (file->f_mode & FMODE_READ && gr_learn_attached)
59599+ return -EBUSY;
59600+ if (file->f_mode & FMODE_READ) {
59601+ int retval = 0;
59602+ mutex_lock(&gr_learn_user_mutex);
59603+ if (learn_buffer == NULL)
59604+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
59605+ if (learn_buffer_user == NULL)
59606+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
59607+ if (learn_buffer == NULL) {
59608+ retval = -ENOMEM;
59609+ goto out_error;
59610+ }
59611+ if (learn_buffer_user == NULL) {
59612+ retval = -ENOMEM;
59613+ goto out_error;
59614+ }
59615+ learn_buffer_len = 0;
59616+ learn_buffer_user_len = 0;
59617+ gr_learn_attached = 1;
59618+out_error:
59619+ mutex_unlock(&gr_learn_user_mutex);
59620+ return retval;
59621+ }
59622+ return 0;
59623+}
59624+
59625+static int
59626+close_learn(struct inode *inode, struct file *file)
59627+{
59628+ if (file->f_mode & FMODE_READ) {
59629+ char *tmp = NULL;
59630+ mutex_lock(&gr_learn_user_mutex);
59631+ spin_lock(&gr_learn_lock);
59632+ tmp = learn_buffer;
59633+ learn_buffer = NULL;
59634+ spin_unlock(&gr_learn_lock);
59635+ if (tmp)
59636+ vfree(tmp);
59637+ if (learn_buffer_user != NULL) {
59638+ vfree(learn_buffer_user);
59639+ learn_buffer_user = NULL;
59640+ }
59641+ learn_buffer_len = 0;
59642+ learn_buffer_user_len = 0;
59643+ gr_learn_attached = 0;
59644+ mutex_unlock(&gr_learn_user_mutex);
59645+ }
59646+
59647+ return 0;
59648+}
59649+
59650+const struct file_operations grsec_fops = {
59651+ .read = read_learn,
59652+ .write = write_grsec_handler,
59653+ .open = open_learn,
59654+ .release = close_learn,
59655+ .poll = poll_learn,
59656+};
59657diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
59658new file mode 100644
59659index 0000000..39645c9
59660--- /dev/null
59661+++ b/grsecurity/gracl_res.c
59662@@ -0,0 +1,68 @@
59663+#include <linux/kernel.h>
59664+#include <linux/sched.h>
59665+#include <linux/gracl.h>
59666+#include <linux/grinternal.h>
59667+
59668+static const char *restab_log[] = {
59669+ [RLIMIT_CPU] = "RLIMIT_CPU",
59670+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
59671+ [RLIMIT_DATA] = "RLIMIT_DATA",
59672+ [RLIMIT_STACK] = "RLIMIT_STACK",
59673+ [RLIMIT_CORE] = "RLIMIT_CORE",
59674+ [RLIMIT_RSS] = "RLIMIT_RSS",
59675+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
59676+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
59677+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
59678+ [RLIMIT_AS] = "RLIMIT_AS",
59679+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
59680+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
59681+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
59682+ [RLIMIT_NICE] = "RLIMIT_NICE",
59683+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
59684+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
59685+ [GR_CRASH_RES] = "RLIMIT_CRASH"
59686+};
59687+
59688+void
59689+gr_log_resource(const struct task_struct *task,
59690+ const int res, const unsigned long wanted, const int gt)
59691+{
59692+ const struct cred *cred;
59693+ unsigned long rlim;
59694+
59695+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
59696+ return;
59697+
59698+ // not yet supported resource
59699+ if (unlikely(!restab_log[res]))
59700+ return;
59701+
59702+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
59703+ rlim = task_rlimit_max(task, res);
59704+ else
59705+ rlim = task_rlimit(task, res);
59706+
59707+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
59708+ return;
59709+
59710+ rcu_read_lock();
59711+ cred = __task_cred(task);
59712+
59713+ if (res == RLIMIT_NPROC &&
59714+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
59715+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
59716+ goto out_rcu_unlock;
59717+ else if (res == RLIMIT_MEMLOCK &&
59718+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
59719+ goto out_rcu_unlock;
59720+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
59721+ goto out_rcu_unlock;
59722+ rcu_read_unlock();
59723+
59724+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
59725+
59726+ return;
59727+out_rcu_unlock:
59728+ rcu_read_unlock();
59729+ return;
59730+}
59731diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
59732new file mode 100644
59733index 0000000..25197e9
59734--- /dev/null
59735+++ b/grsecurity/gracl_segv.c
59736@@ -0,0 +1,299 @@
59737+#include <linux/kernel.h>
59738+#include <linux/mm.h>
59739+#include <asm/uaccess.h>
59740+#include <asm/errno.h>
59741+#include <asm/mman.h>
59742+#include <net/sock.h>
59743+#include <linux/file.h>
59744+#include <linux/fs.h>
59745+#include <linux/net.h>
59746+#include <linux/in.h>
59747+#include <linux/slab.h>
59748+#include <linux/types.h>
59749+#include <linux/sched.h>
59750+#include <linux/timer.h>
59751+#include <linux/gracl.h>
59752+#include <linux/grsecurity.h>
59753+#include <linux/grinternal.h>
59754+
59755+static struct crash_uid *uid_set;
59756+static unsigned short uid_used;
59757+static DEFINE_SPINLOCK(gr_uid_lock);
59758+extern rwlock_t gr_inode_lock;
59759+extern struct acl_subject_label *
59760+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
59761+ struct acl_role_label *role);
59762+
59763+#ifdef CONFIG_BTRFS_FS
59764+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
59765+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
59766+#endif
59767+
59768+static inline dev_t __get_dev(const struct dentry *dentry)
59769+{
59770+#ifdef CONFIG_BTRFS_FS
59771+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
59772+ return get_btrfs_dev_from_inode(dentry->d_inode);
59773+ else
59774+#endif
59775+ return dentry->d_inode->i_sb->s_dev;
59776+}
59777+
59778+int
59779+gr_init_uidset(void)
59780+{
59781+ uid_set =
59782+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
59783+ uid_used = 0;
59784+
59785+ return uid_set ? 1 : 0;
59786+}
59787+
59788+void
59789+gr_free_uidset(void)
59790+{
59791+ if (uid_set)
59792+ kfree(uid_set);
59793+
59794+ return;
59795+}
59796+
59797+int
59798+gr_find_uid(const uid_t uid)
59799+{
59800+ struct crash_uid *tmp = uid_set;
59801+ uid_t buid;
59802+ int low = 0, high = uid_used - 1, mid;
59803+
59804+ while (high >= low) {
59805+ mid = (low + high) >> 1;
59806+ buid = tmp[mid].uid;
59807+ if (buid == uid)
59808+ return mid;
59809+ if (buid > uid)
59810+ high = mid - 1;
59811+ if (buid < uid)
59812+ low = mid + 1;
59813+ }
59814+
59815+ return -1;
59816+}
59817+
59818+static __inline__ void
59819+gr_insertsort(void)
59820+{
59821+ unsigned short i, j;
59822+ struct crash_uid index;
59823+
59824+ for (i = 1; i < uid_used; i++) {
59825+ index = uid_set[i];
59826+ j = i;
59827+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
59828+ uid_set[j] = uid_set[j - 1];
59829+ j--;
59830+ }
59831+ uid_set[j] = index;
59832+ }
59833+
59834+ return;
59835+}
59836+
59837+static __inline__ void
59838+gr_insert_uid(const uid_t uid, const unsigned long expires)
59839+{
59840+ int loc;
59841+
59842+ if (uid_used == GR_UIDTABLE_MAX)
59843+ return;
59844+
59845+ loc = gr_find_uid(uid);
59846+
59847+ if (loc >= 0) {
59848+ uid_set[loc].expires = expires;
59849+ return;
59850+ }
59851+
59852+ uid_set[uid_used].uid = uid;
59853+ uid_set[uid_used].expires = expires;
59854+ uid_used++;
59855+
59856+ gr_insertsort();
59857+
59858+ return;
59859+}
59860+
59861+void
59862+gr_remove_uid(const unsigned short loc)
59863+{
59864+ unsigned short i;
59865+
59866+ for (i = loc + 1; i < uid_used; i++)
59867+ uid_set[i - 1] = uid_set[i];
59868+
59869+ uid_used--;
59870+
59871+ return;
59872+}
59873+
59874+int
59875+gr_check_crash_uid(const uid_t uid)
59876+{
59877+ int loc;
59878+ int ret = 0;
59879+
59880+ if (unlikely(!gr_acl_is_enabled()))
59881+ return 0;
59882+
59883+ spin_lock(&gr_uid_lock);
59884+ loc = gr_find_uid(uid);
59885+
59886+ if (loc < 0)
59887+ goto out_unlock;
59888+
59889+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
59890+ gr_remove_uid(loc);
59891+ else
59892+ ret = 1;
59893+
59894+out_unlock:
59895+ spin_unlock(&gr_uid_lock);
59896+ return ret;
59897+}
59898+
59899+static __inline__ int
59900+proc_is_setxid(const struct cred *cred)
59901+{
59902+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
59903+ !uid_eq(cred->uid, cred->fsuid))
59904+ return 1;
59905+ if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
59906+ !uid_eq(cred->gid, cred->fsgid))
59907+ return 1;
59908+
59909+ return 0;
59910+}
59911+
59912+extern int gr_fake_force_sig(int sig, struct task_struct *t);
59913+
59914+void
59915+gr_handle_crash(struct task_struct *task, const int sig)
59916+{
59917+ struct acl_subject_label *curr;
59918+ struct task_struct *tsk, *tsk2;
59919+ const struct cred *cred;
59920+ const struct cred *cred2;
59921+
59922+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
59923+ return;
59924+
59925+ if (unlikely(!gr_acl_is_enabled()))
59926+ return;
59927+
59928+ curr = task->acl;
59929+
59930+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
59931+ return;
59932+
59933+ if (time_before_eq(curr->expires, get_seconds())) {
59934+ curr->expires = 0;
59935+ curr->crashes = 0;
59936+ }
59937+
59938+ curr->crashes++;
59939+
59940+ if (!curr->expires)
59941+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
59942+
59943+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
59944+ time_after(curr->expires, get_seconds())) {
59945+ rcu_read_lock();
59946+ cred = __task_cred(task);
59947+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
59948+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
59949+ spin_lock(&gr_uid_lock);
59950+ gr_insert_uid(cred->uid, curr->expires);
59951+ spin_unlock(&gr_uid_lock);
59952+ curr->expires = 0;
59953+ curr->crashes = 0;
59954+ read_lock(&tasklist_lock);
59955+ do_each_thread(tsk2, tsk) {
59956+ cred2 = __task_cred(tsk);
59957+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
59958+ gr_fake_force_sig(SIGKILL, tsk);
59959+ } while_each_thread(tsk2, tsk);
59960+ read_unlock(&tasklist_lock);
59961+ } else {
59962+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
59963+ read_lock(&tasklist_lock);
59964+ read_lock(&grsec_exec_file_lock);
59965+ do_each_thread(tsk2, tsk) {
59966+ if (likely(tsk != task)) {
59967+ // if this thread has the same subject as the one that triggered
59968+ // RES_CRASH and it's the same binary, kill it
59969+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
59970+ gr_fake_force_sig(SIGKILL, tsk);
59971+ }
59972+ } while_each_thread(tsk2, tsk);
59973+ read_unlock(&grsec_exec_file_lock);
59974+ read_unlock(&tasklist_lock);
59975+ }
59976+ rcu_read_unlock();
59977+ }
59978+
59979+ return;
59980+}
59981+
59982+int
59983+gr_check_crash_exec(const struct file *filp)
59984+{
59985+ struct acl_subject_label *curr;
59986+
59987+ if (unlikely(!gr_acl_is_enabled()))
59988+ return 0;
59989+
59990+ read_lock(&gr_inode_lock);
59991+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
59992+ __get_dev(filp->f_path.dentry),
59993+ current->role);
59994+ read_unlock(&gr_inode_lock);
59995+
59996+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
59997+ (!curr->crashes && !curr->expires))
59998+ return 0;
59999+
60000+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
60001+ time_after(curr->expires, get_seconds()))
60002+ return 1;
60003+ else if (time_before_eq(curr->expires, get_seconds())) {
60004+ curr->crashes = 0;
60005+ curr->expires = 0;
60006+ }
60007+
60008+ return 0;
60009+}
60010+
60011+void
60012+gr_handle_alertkill(struct task_struct *task)
60013+{
60014+ struct acl_subject_label *curracl;
60015+ __u32 curr_ip;
60016+ struct task_struct *p, *p2;
60017+
60018+ if (unlikely(!gr_acl_is_enabled()))
60019+ return;
60020+
60021+ curracl = task->acl;
60022+ curr_ip = task->signal->curr_ip;
60023+
60024+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
60025+ read_lock(&tasklist_lock);
60026+ do_each_thread(p2, p) {
60027+ if (p->signal->curr_ip == curr_ip)
60028+ gr_fake_force_sig(SIGKILL, p);
60029+ } while_each_thread(p2, p);
60030+ read_unlock(&tasklist_lock);
60031+ } else if (curracl->mode & GR_KILLPROC)
60032+ gr_fake_force_sig(SIGKILL, task);
60033+
60034+ return;
60035+}
60036diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
60037new file mode 100644
60038index 0000000..9d83a69
60039--- /dev/null
60040+++ b/grsecurity/gracl_shm.c
60041@@ -0,0 +1,40 @@
60042+#include <linux/kernel.h>
60043+#include <linux/mm.h>
60044+#include <linux/sched.h>
60045+#include <linux/file.h>
60046+#include <linux/ipc.h>
60047+#include <linux/gracl.h>
60048+#include <linux/grsecurity.h>
60049+#include <linux/grinternal.h>
60050+
60051+int
60052+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60053+ const time_t shm_createtime, const uid_t cuid, const int shmid)
60054+{
60055+ struct task_struct *task;
60056+
60057+ if (!gr_acl_is_enabled())
60058+ return 1;
60059+
60060+ rcu_read_lock();
60061+ read_lock(&tasklist_lock);
60062+
60063+ task = find_task_by_vpid(shm_cprid);
60064+
60065+ if (unlikely(!task))
60066+ task = find_task_by_vpid(shm_lapid);
60067+
60068+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
60069+ (task->pid == shm_lapid)) &&
60070+ (task->acl->mode & GR_PROTSHM) &&
60071+ (task->acl != current->acl))) {
60072+ read_unlock(&tasklist_lock);
60073+ rcu_read_unlock();
60074+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
60075+ return 0;
60076+ }
60077+ read_unlock(&tasklist_lock);
60078+ rcu_read_unlock();
60079+
60080+ return 1;
60081+}
60082diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
60083new file mode 100644
60084index 0000000..bc0be01
60085--- /dev/null
60086+++ b/grsecurity/grsec_chdir.c
60087@@ -0,0 +1,19 @@
60088+#include <linux/kernel.h>
60089+#include <linux/sched.h>
60090+#include <linux/fs.h>
60091+#include <linux/file.h>
60092+#include <linux/grsecurity.h>
60093+#include <linux/grinternal.h>
60094+
60095+void
60096+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
60097+{
60098+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60099+ if ((grsec_enable_chdir && grsec_enable_group &&
60100+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
60101+ !grsec_enable_group)) {
60102+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
60103+ }
60104+#endif
60105+ return;
60106+}
60107diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
60108new file mode 100644
60109index 0000000..70fe0ae
60110--- /dev/null
60111+++ b/grsecurity/grsec_chroot.c
60112@@ -0,0 +1,357 @@
60113+#include <linux/kernel.h>
60114+#include <linux/module.h>
60115+#include <linux/sched.h>
60116+#include <linux/file.h>
60117+#include <linux/fs.h>
60118+#include <linux/mount.h>
60119+#include <linux/types.h>
60120+#include "../fs/mount.h"
60121+#include <linux/grsecurity.h>
60122+#include <linux/grinternal.h>
60123+
60124+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
60125+{
60126+#ifdef CONFIG_GRKERNSEC
60127+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
60128+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
60129+ task->gr_is_chrooted = 1;
60130+ else
60131+ task->gr_is_chrooted = 0;
60132+
60133+ task->gr_chroot_dentry = path->dentry;
60134+#endif
60135+ return;
60136+}
60137+
60138+void gr_clear_chroot_entries(struct task_struct *task)
60139+{
60140+#ifdef CONFIG_GRKERNSEC
60141+ task->gr_is_chrooted = 0;
60142+ task->gr_chroot_dentry = NULL;
60143+#endif
60144+ return;
60145+}
60146+
60147+int
60148+gr_handle_chroot_unix(const pid_t pid)
60149+{
60150+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60151+ struct task_struct *p;
60152+
60153+ if (unlikely(!grsec_enable_chroot_unix))
60154+ return 1;
60155+
60156+ if (likely(!proc_is_chrooted(current)))
60157+ return 1;
60158+
60159+ rcu_read_lock();
60160+ read_lock(&tasklist_lock);
60161+ p = find_task_by_vpid_unrestricted(pid);
60162+ if (unlikely(p && !have_same_root(current, p))) {
60163+ read_unlock(&tasklist_lock);
60164+ rcu_read_unlock();
60165+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
60166+ return 0;
60167+ }
60168+ read_unlock(&tasklist_lock);
60169+ rcu_read_unlock();
60170+#endif
60171+ return 1;
60172+}
60173+
60174+int
60175+gr_handle_chroot_nice(void)
60176+{
60177+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60178+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
60179+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
60180+ return -EPERM;
60181+ }
60182+#endif
60183+ return 0;
60184+}
60185+
60186+int
60187+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
60188+{
60189+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60190+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
60191+ && proc_is_chrooted(current)) {
60192+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
60193+ return -EACCES;
60194+ }
60195+#endif
60196+ return 0;
60197+}
60198+
60199+int
60200+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
60201+{
60202+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60203+ struct task_struct *p;
60204+ int ret = 0;
60205+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
60206+ return ret;
60207+
60208+ read_lock(&tasklist_lock);
60209+ do_each_pid_task(pid, type, p) {
60210+ if (!have_same_root(current, p)) {
60211+ ret = 1;
60212+ goto out;
60213+ }
60214+ } while_each_pid_task(pid, type, p);
60215+out:
60216+ read_unlock(&tasklist_lock);
60217+ return ret;
60218+#endif
60219+ return 0;
60220+}
60221+
60222+int
60223+gr_pid_is_chrooted(struct task_struct *p)
60224+{
60225+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60226+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
60227+ return 0;
60228+
60229+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
60230+ !have_same_root(current, p)) {
60231+ return 1;
60232+ }
60233+#endif
60234+ return 0;
60235+}
60236+
60237+EXPORT_SYMBOL(gr_pid_is_chrooted);
60238+
60239+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
60240+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
60241+{
60242+ struct path path, currentroot;
60243+ int ret = 0;
60244+
60245+ path.dentry = (struct dentry *)u_dentry;
60246+ path.mnt = (struct vfsmount *)u_mnt;
60247+ get_fs_root(current->fs, &currentroot);
60248+ if (path_is_under(&path, &currentroot))
60249+ ret = 1;
60250+ path_put(&currentroot);
60251+
60252+ return ret;
60253+}
60254+#endif
60255+
60256+int
60257+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
60258+{
60259+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60260+ if (!grsec_enable_chroot_fchdir)
60261+ return 1;
60262+
60263+ if (!proc_is_chrooted(current))
60264+ return 1;
60265+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
60266+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
60267+ return 0;
60268+ }
60269+#endif
60270+ return 1;
60271+}
60272+
60273+int
60274+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60275+ const time_t shm_createtime)
60276+{
60277+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60278+ struct task_struct *p;
60279+ time_t starttime;
60280+
60281+ if (unlikely(!grsec_enable_chroot_shmat))
60282+ return 1;
60283+
60284+ if (likely(!proc_is_chrooted(current)))
60285+ return 1;
60286+
60287+ rcu_read_lock();
60288+ read_lock(&tasklist_lock);
60289+
60290+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
60291+ starttime = p->start_time.tv_sec;
60292+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
60293+ if (have_same_root(current, p)) {
60294+ goto allow;
60295+ } else {
60296+ read_unlock(&tasklist_lock);
60297+ rcu_read_unlock();
60298+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
60299+ return 0;
60300+ }
60301+ }
60302+ /* creator exited, pid reuse, fall through to next check */
60303+ }
60304+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
60305+ if (unlikely(!have_same_root(current, p))) {
60306+ read_unlock(&tasklist_lock);
60307+ rcu_read_unlock();
60308+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
60309+ return 0;
60310+ }
60311+ }
60312+
60313+allow:
60314+ read_unlock(&tasklist_lock);
60315+ rcu_read_unlock();
60316+#endif
60317+ return 1;
60318+}
60319+
60320+void
60321+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
60322+{
60323+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60324+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
60325+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
60326+#endif
60327+ return;
60328+}
60329+
60330+int
60331+gr_handle_chroot_mknod(const struct dentry *dentry,
60332+ const struct vfsmount *mnt, const int mode)
60333+{
60334+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60335+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
60336+ proc_is_chrooted(current)) {
60337+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
60338+ return -EPERM;
60339+ }
60340+#endif
60341+ return 0;
60342+}
60343+
60344+int
60345+gr_handle_chroot_mount(const struct dentry *dentry,
60346+ const struct vfsmount *mnt, const char *dev_name)
60347+{
60348+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60349+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
60350+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
60351+ return -EPERM;
60352+ }
60353+#endif
60354+ return 0;
60355+}
60356+
60357+int
60358+gr_handle_chroot_pivot(void)
60359+{
60360+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60361+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
60362+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
60363+ return -EPERM;
60364+ }
60365+#endif
60366+ return 0;
60367+}
60368+
60369+int
60370+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
60371+{
60372+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60373+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
60374+ !gr_is_outside_chroot(dentry, mnt)) {
60375+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
60376+ return -EPERM;
60377+ }
60378+#endif
60379+ return 0;
60380+}
60381+
60382+extern const char *captab_log[];
60383+extern int captab_log_entries;
60384+
60385+int
60386+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60387+{
60388+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60389+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
60390+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
60391+ if (cap_raised(chroot_caps, cap)) {
60392+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
60393+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
60394+ }
60395+ return 0;
60396+ }
60397+ }
60398+#endif
60399+ return 1;
60400+}
60401+
60402+int
60403+gr_chroot_is_capable(const int cap)
60404+{
60405+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60406+ return gr_task_chroot_is_capable(current, current_cred(), cap);
60407+#endif
60408+ return 1;
60409+}
60410+
60411+int
60412+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
60413+{
60414+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60415+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
60416+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
60417+ if (cap_raised(chroot_caps, cap)) {
60418+ return 0;
60419+ }
60420+ }
60421+#endif
60422+ return 1;
60423+}
60424+
60425+int
60426+gr_chroot_is_capable_nolog(const int cap)
60427+{
60428+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60429+ return gr_task_chroot_is_capable_nolog(current, cap);
60430+#endif
60431+ return 1;
60432+}
60433+
60434+int
60435+gr_handle_chroot_sysctl(const int op)
60436+{
60437+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60438+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
60439+ proc_is_chrooted(current))
60440+ return -EACCES;
60441+#endif
60442+ return 0;
60443+}
60444+
60445+void
60446+gr_handle_chroot_chdir(struct path *path)
60447+{
60448+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60449+ if (grsec_enable_chroot_chdir)
60450+ set_fs_pwd(current->fs, path);
60451+#endif
60452+ return;
60453+}
60454+
60455+int
60456+gr_handle_chroot_chmod(const struct dentry *dentry,
60457+ const struct vfsmount *mnt, const int mode)
60458+{
60459+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60460+ /* allow chmod +s on directories, but not files */
60461+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
60462+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
60463+ proc_is_chrooted(current)) {
60464+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
60465+ return -EPERM;
60466+ }
60467+#endif
60468+ return 0;
60469+}
60470diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
60471new file mode 100644
60472index 0000000..e6796b3
60473--- /dev/null
60474+++ b/grsecurity/grsec_disabled.c
60475@@ -0,0 +1,434 @@
60476+#include <linux/kernel.h>
60477+#include <linux/module.h>
60478+#include <linux/sched.h>
60479+#include <linux/file.h>
60480+#include <linux/fs.h>
60481+#include <linux/kdev_t.h>
60482+#include <linux/net.h>
60483+#include <linux/in.h>
60484+#include <linux/ip.h>
60485+#include <linux/skbuff.h>
60486+#include <linux/sysctl.h>
60487+
60488+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60489+void
60490+pax_set_initial_flags(struct linux_binprm *bprm)
60491+{
60492+ return;
60493+}
60494+#endif
60495+
60496+#ifdef CONFIG_SYSCTL
60497+__u32
60498+gr_handle_sysctl(const struct ctl_table * table, const int op)
60499+{
60500+ return 0;
60501+}
60502+#endif
60503+
60504+#ifdef CONFIG_TASKSTATS
60505+int gr_is_taskstats_denied(int pid)
60506+{
60507+ return 0;
60508+}
60509+#endif
60510+
60511+int
60512+gr_acl_is_enabled(void)
60513+{
60514+ return 0;
60515+}
60516+
60517+void
60518+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
60519+{
60520+ return;
60521+}
60522+
60523+int
60524+gr_handle_rawio(const struct inode *inode)
60525+{
60526+ return 0;
60527+}
60528+
60529+void
60530+gr_acl_handle_psacct(struct task_struct *task, const long code)
60531+{
60532+ return;
60533+}
60534+
60535+int
60536+gr_handle_ptrace(struct task_struct *task, const long request)
60537+{
60538+ return 0;
60539+}
60540+
60541+int
60542+gr_handle_proc_ptrace(struct task_struct *task)
60543+{
60544+ return 0;
60545+}
60546+
60547+int
60548+gr_set_acls(const int type)
60549+{
60550+ return 0;
60551+}
60552+
60553+int
60554+gr_check_hidden_task(const struct task_struct *tsk)
60555+{
60556+ return 0;
60557+}
60558+
60559+int
60560+gr_check_protected_task(const struct task_struct *task)
60561+{
60562+ return 0;
60563+}
60564+
60565+int
60566+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
60567+{
60568+ return 0;
60569+}
60570+
60571+void
60572+gr_copy_label(struct task_struct *tsk)
60573+{
60574+ return;
60575+}
60576+
60577+void
60578+gr_set_pax_flags(struct task_struct *task)
60579+{
60580+ return;
60581+}
60582+
60583+int
60584+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
60585+ const int unsafe_share)
60586+{
60587+ return 0;
60588+}
60589+
60590+void
60591+gr_handle_delete(const ino_t ino, const dev_t dev)
60592+{
60593+ return;
60594+}
60595+
60596+void
60597+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
60598+{
60599+ return;
60600+}
60601+
60602+void
60603+gr_handle_crash(struct task_struct *task, const int sig)
60604+{
60605+ return;
60606+}
60607+
60608+int
60609+gr_check_crash_exec(const struct file *filp)
60610+{
60611+ return 0;
60612+}
60613+
60614+int
60615+gr_check_crash_uid(const uid_t uid)
60616+{
60617+ return 0;
60618+}
60619+
60620+void
60621+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
60622+ struct dentry *old_dentry,
60623+ struct dentry *new_dentry,
60624+ struct vfsmount *mnt, const __u8 replace)
60625+{
60626+ return;
60627+}
60628+
60629+int
60630+gr_search_socket(const int family, const int type, const int protocol)
60631+{
60632+ return 1;
60633+}
60634+
60635+int
60636+gr_search_connectbind(const int mode, const struct socket *sock,
60637+ const struct sockaddr_in *addr)
60638+{
60639+ return 0;
60640+}
60641+
60642+void
60643+gr_handle_alertkill(struct task_struct *task)
60644+{
60645+ return;
60646+}
60647+
60648+__u32
60649+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
60650+{
60651+ return 1;
60652+}
60653+
60654+__u32
60655+gr_acl_handle_hidden_file(const struct dentry * dentry,
60656+ const struct vfsmount * mnt)
60657+{
60658+ return 1;
60659+}
60660+
60661+__u32
60662+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
60663+ int acc_mode)
60664+{
60665+ return 1;
60666+}
60667+
60668+__u32
60669+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
60670+{
60671+ return 1;
60672+}
60673+
60674+__u32
60675+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
60676+{
60677+ return 1;
60678+}
60679+
60680+int
60681+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
60682+ unsigned int *vm_flags)
60683+{
60684+ return 1;
60685+}
60686+
60687+__u32
60688+gr_acl_handle_truncate(const struct dentry * dentry,
60689+ const struct vfsmount * mnt)
60690+{
60691+ return 1;
60692+}
60693+
60694+__u32
60695+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
60696+{
60697+ return 1;
60698+}
60699+
60700+__u32
60701+gr_acl_handle_access(const struct dentry * dentry,
60702+ const struct vfsmount * mnt, const int fmode)
60703+{
60704+ return 1;
60705+}
60706+
60707+__u32
60708+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
60709+ umode_t *mode)
60710+{
60711+ return 1;
60712+}
60713+
60714+__u32
60715+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
60716+{
60717+ return 1;
60718+}
60719+
60720+__u32
60721+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
60722+{
60723+ return 1;
60724+}
60725+
60726+void
60727+grsecurity_init(void)
60728+{
60729+ return;
60730+}
60731+
60732+umode_t gr_acl_umask(void)
60733+{
60734+ return 0;
60735+}
60736+
60737+__u32
60738+gr_acl_handle_mknod(const struct dentry * new_dentry,
60739+ const struct dentry * parent_dentry,
60740+ const struct vfsmount * parent_mnt,
60741+ const int mode)
60742+{
60743+ return 1;
60744+}
60745+
60746+__u32
60747+gr_acl_handle_mkdir(const struct dentry * new_dentry,
60748+ const struct dentry * parent_dentry,
60749+ const struct vfsmount * parent_mnt)
60750+{
60751+ return 1;
60752+}
60753+
60754+__u32
60755+gr_acl_handle_symlink(const struct dentry * new_dentry,
60756+ const struct dentry * parent_dentry,
60757+ const struct vfsmount * parent_mnt, const struct filename *from)
60758+{
60759+ return 1;
60760+}
60761+
60762+__u32
60763+gr_acl_handle_link(const struct dentry * new_dentry,
60764+ const struct dentry * parent_dentry,
60765+ const struct vfsmount * parent_mnt,
60766+ const struct dentry * old_dentry,
60767+ const struct vfsmount * old_mnt, const struct filename *to)
60768+{
60769+ return 1;
60770+}
60771+
60772+int
60773+gr_acl_handle_rename(const struct dentry *new_dentry,
60774+ const struct dentry *parent_dentry,
60775+ const struct vfsmount *parent_mnt,
60776+ const struct dentry *old_dentry,
60777+ const struct inode *old_parent_inode,
60778+ const struct vfsmount *old_mnt, const struct filename *newname)
60779+{
60780+ return 0;
60781+}
60782+
60783+int
60784+gr_acl_handle_filldir(const struct file *file, const char *name,
60785+ const int namelen, const ino_t ino)
60786+{
60787+ return 1;
60788+}
60789+
60790+int
60791+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60792+ const time_t shm_createtime, const uid_t cuid, const int shmid)
60793+{
60794+ return 1;
60795+}
60796+
60797+int
60798+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
60799+{
60800+ return 0;
60801+}
60802+
60803+int
60804+gr_search_accept(const struct socket *sock)
60805+{
60806+ return 0;
60807+}
60808+
60809+int
60810+gr_search_listen(const struct socket *sock)
60811+{
60812+ return 0;
60813+}
60814+
60815+int
60816+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
60817+{
60818+ return 0;
60819+}
60820+
60821+__u32
60822+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
60823+{
60824+ return 1;
60825+}
60826+
60827+__u32
60828+gr_acl_handle_creat(const struct dentry * dentry,
60829+ const struct dentry * p_dentry,
60830+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
60831+ const int imode)
60832+{
60833+ return 1;
60834+}
60835+
60836+void
60837+gr_acl_handle_exit(void)
60838+{
60839+ return;
60840+}
60841+
60842+int
60843+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
60844+{
60845+ return 1;
60846+}
60847+
60848+void
60849+gr_set_role_label(const uid_t uid, const gid_t gid)
60850+{
60851+ return;
60852+}
60853+
60854+int
60855+gr_acl_handle_procpidmem(const struct task_struct *task)
60856+{
60857+ return 0;
60858+}
60859+
60860+int
60861+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
60862+{
60863+ return 0;
60864+}
60865+
60866+int
60867+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
60868+{
60869+ return 0;
60870+}
60871+
60872+void
60873+gr_set_kernel_label(struct task_struct *task)
60874+{
60875+ return;
60876+}
60877+
60878+int
60879+gr_check_user_change(int real, int effective, int fs)
60880+{
60881+ return 0;
60882+}
60883+
60884+int
60885+gr_check_group_change(int real, int effective, int fs)
60886+{
60887+ return 0;
60888+}
60889+
60890+int gr_acl_enable_at_secure(void)
60891+{
60892+ return 0;
60893+}
60894+
60895+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
60896+{
60897+ return dentry->d_inode->i_sb->s_dev;
60898+}
60899+
60900+void gr_put_exec_file(struct task_struct *task)
60901+{
60902+ return;
60903+}
60904+
60905+EXPORT_SYMBOL(gr_set_kernel_label);
60906+#ifdef CONFIG_SECURITY
60907+EXPORT_SYMBOL(gr_check_user_change);
60908+EXPORT_SYMBOL(gr_check_group_change);
60909+#endif
60910diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
60911new file mode 100644
60912index 0000000..abfa971
60913--- /dev/null
60914+++ b/grsecurity/grsec_exec.c
60915@@ -0,0 +1,174 @@
60916+#include <linux/kernel.h>
60917+#include <linux/sched.h>
60918+#include <linux/file.h>
60919+#include <linux/binfmts.h>
60920+#include <linux/fs.h>
60921+#include <linux/types.h>
60922+#include <linux/grdefs.h>
60923+#include <linux/grsecurity.h>
60924+#include <linux/grinternal.h>
60925+#include <linux/capability.h>
60926+#include <linux/module.h>
60927+
60928+#include <asm/uaccess.h>
60929+
60930+#ifdef CONFIG_GRKERNSEC_EXECLOG
60931+static char gr_exec_arg_buf[132];
60932+static DEFINE_MUTEX(gr_exec_arg_mutex);
60933+#endif
60934+
60935+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
60936+
60937+void
60938+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
60939+{
60940+#ifdef CONFIG_GRKERNSEC_EXECLOG
60941+ char *grarg = gr_exec_arg_buf;
60942+ unsigned int i, x, execlen = 0;
60943+ char c;
60944+
60945+ if (!((grsec_enable_execlog && grsec_enable_group &&
60946+ in_group_p(grsec_audit_gid))
60947+ || (grsec_enable_execlog && !grsec_enable_group)))
60948+ return;
60949+
60950+ mutex_lock(&gr_exec_arg_mutex);
60951+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
60952+
60953+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
60954+ const char __user *p;
60955+ unsigned int len;
60956+
60957+ p = get_user_arg_ptr(argv, i);
60958+ if (IS_ERR(p))
60959+ goto log;
60960+
60961+ len = strnlen_user(p, 128 - execlen);
60962+ if (len > 128 - execlen)
60963+ len = 128 - execlen;
60964+ else if (len > 0)
60965+ len--;
60966+ if (copy_from_user(grarg + execlen, p, len))
60967+ goto log;
60968+
60969+ /* rewrite unprintable characters */
60970+ for (x = 0; x < len; x++) {
60971+ c = *(grarg + execlen + x);
60972+ if (c < 32 || c > 126)
60973+ *(grarg + execlen + x) = ' ';
60974+ }
60975+
60976+ execlen += len;
60977+ *(grarg + execlen) = ' ';
60978+ *(grarg + execlen + 1) = '\0';
60979+ execlen++;
60980+ }
60981+
60982+ log:
60983+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
60984+ bprm->file->f_path.mnt, grarg);
60985+ mutex_unlock(&gr_exec_arg_mutex);
60986+#endif
60987+ return;
60988+}
60989+
60990+#ifdef CONFIG_GRKERNSEC
60991+extern int gr_acl_is_capable(const int cap);
60992+extern int gr_acl_is_capable_nolog(const int cap);
60993+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60994+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
60995+extern int gr_chroot_is_capable(const int cap);
60996+extern int gr_chroot_is_capable_nolog(const int cap);
60997+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60998+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
60999+#endif
61000+
61001+const char *captab_log[] = {
61002+ "CAP_CHOWN",
61003+ "CAP_DAC_OVERRIDE",
61004+ "CAP_DAC_READ_SEARCH",
61005+ "CAP_FOWNER",
61006+ "CAP_FSETID",
61007+ "CAP_KILL",
61008+ "CAP_SETGID",
61009+ "CAP_SETUID",
61010+ "CAP_SETPCAP",
61011+ "CAP_LINUX_IMMUTABLE",
61012+ "CAP_NET_BIND_SERVICE",
61013+ "CAP_NET_BROADCAST",
61014+ "CAP_NET_ADMIN",
61015+ "CAP_NET_RAW",
61016+ "CAP_IPC_LOCK",
61017+ "CAP_IPC_OWNER",
61018+ "CAP_SYS_MODULE",
61019+ "CAP_SYS_RAWIO",
61020+ "CAP_SYS_CHROOT",
61021+ "CAP_SYS_PTRACE",
61022+ "CAP_SYS_PACCT",
61023+ "CAP_SYS_ADMIN",
61024+ "CAP_SYS_BOOT",
61025+ "CAP_SYS_NICE",
61026+ "CAP_SYS_RESOURCE",
61027+ "CAP_SYS_TIME",
61028+ "CAP_SYS_TTY_CONFIG",
61029+ "CAP_MKNOD",
61030+ "CAP_LEASE",
61031+ "CAP_AUDIT_WRITE",
61032+ "CAP_AUDIT_CONTROL",
61033+ "CAP_SETFCAP",
61034+ "CAP_MAC_OVERRIDE",
61035+ "CAP_MAC_ADMIN",
61036+ "CAP_SYSLOG",
61037+ "CAP_WAKE_ALARM"
61038+};
61039+
61040+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
61041+
61042+int gr_is_capable(const int cap)
61043+{
61044+#ifdef CONFIG_GRKERNSEC
61045+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
61046+ return 1;
61047+ return 0;
61048+#else
61049+ return 1;
61050+#endif
61051+}
61052+
61053+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
61054+{
61055+#ifdef CONFIG_GRKERNSEC
61056+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
61057+ return 1;
61058+ return 0;
61059+#else
61060+ return 1;
61061+#endif
61062+}
61063+
61064+int gr_is_capable_nolog(const int cap)
61065+{
61066+#ifdef CONFIG_GRKERNSEC
61067+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
61068+ return 1;
61069+ return 0;
61070+#else
61071+ return 1;
61072+#endif
61073+}
61074+
61075+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
61076+{
61077+#ifdef CONFIG_GRKERNSEC
61078+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
61079+ return 1;
61080+ return 0;
61081+#else
61082+ return 1;
61083+#endif
61084+}
61085+
61086+EXPORT_SYMBOL(gr_is_capable);
61087+EXPORT_SYMBOL(gr_is_capable_nolog);
61088+EXPORT_SYMBOL(gr_task_is_capable);
61089+EXPORT_SYMBOL(gr_task_is_capable_nolog);
61090diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
61091new file mode 100644
61092index 0000000..d3ee748
61093--- /dev/null
61094+++ b/grsecurity/grsec_fifo.c
61095@@ -0,0 +1,24 @@
61096+#include <linux/kernel.h>
61097+#include <linux/sched.h>
61098+#include <linux/fs.h>
61099+#include <linux/file.h>
61100+#include <linux/grinternal.h>
61101+
61102+int
61103+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
61104+ const struct dentry *dir, const int flag, const int acc_mode)
61105+{
61106+#ifdef CONFIG_GRKERNSEC_FIFO
61107+ const struct cred *cred = current_cred();
61108+
61109+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
61110+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
61111+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
61112+ (cred->fsuid != dentry->d_inode->i_uid)) {
61113+ if (!inode_permission(dentry->d_inode, acc_mode))
61114+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
61115+ return -EACCES;
61116+ }
61117+#endif
61118+ return 0;
61119+}
61120diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
61121new file mode 100644
61122index 0000000..8ca18bf
61123--- /dev/null
61124+++ b/grsecurity/grsec_fork.c
61125@@ -0,0 +1,23 @@
61126+#include <linux/kernel.h>
61127+#include <linux/sched.h>
61128+#include <linux/grsecurity.h>
61129+#include <linux/grinternal.h>
61130+#include <linux/errno.h>
61131+
61132+void
61133+gr_log_forkfail(const int retval)
61134+{
61135+#ifdef CONFIG_GRKERNSEC_FORKFAIL
61136+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
61137+ switch (retval) {
61138+ case -EAGAIN:
61139+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
61140+ break;
61141+ case -ENOMEM:
61142+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
61143+ break;
61144+ }
61145+ }
61146+#endif
61147+ return;
61148+}
61149diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
61150new file mode 100644
61151index 0000000..05a6015
61152--- /dev/null
61153+++ b/grsecurity/grsec_init.c
61154@@ -0,0 +1,283 @@
61155+#include <linux/kernel.h>
61156+#include <linux/sched.h>
61157+#include <linux/mm.h>
61158+#include <linux/gracl.h>
61159+#include <linux/slab.h>
61160+#include <linux/vmalloc.h>
61161+#include <linux/percpu.h>
61162+#include <linux/module.h>
61163+
61164+int grsec_enable_ptrace_readexec;
61165+int grsec_enable_setxid;
61166+int grsec_enable_symlinkown;
61167+int grsec_symlinkown_gid;
61168+int grsec_enable_brute;
61169+int grsec_enable_link;
61170+int grsec_enable_dmesg;
61171+int grsec_enable_harden_ptrace;
61172+int grsec_enable_fifo;
61173+int grsec_enable_execlog;
61174+int grsec_enable_signal;
61175+int grsec_enable_forkfail;
61176+int grsec_enable_audit_ptrace;
61177+int grsec_enable_time;
61178+int grsec_enable_audit_textrel;
61179+int grsec_enable_group;
61180+int grsec_audit_gid;
61181+int grsec_enable_chdir;
61182+int grsec_enable_mount;
61183+int grsec_enable_rofs;
61184+int grsec_enable_chroot_findtask;
61185+int grsec_enable_chroot_mount;
61186+int grsec_enable_chroot_shmat;
61187+int grsec_enable_chroot_fchdir;
61188+int grsec_enable_chroot_double;
61189+int grsec_enable_chroot_pivot;
61190+int grsec_enable_chroot_chdir;
61191+int grsec_enable_chroot_chmod;
61192+int grsec_enable_chroot_mknod;
61193+int grsec_enable_chroot_nice;
61194+int grsec_enable_chroot_execlog;
61195+int grsec_enable_chroot_caps;
61196+int grsec_enable_chroot_sysctl;
61197+int grsec_enable_chroot_unix;
61198+int grsec_enable_tpe;
61199+int grsec_tpe_gid;
61200+int grsec_enable_blackhole;
61201+#ifdef CONFIG_IPV6_MODULE
61202+EXPORT_SYMBOL(grsec_enable_blackhole);
61203+#endif
61204+int grsec_lastack_retries;
61205+int grsec_enable_tpe_all;
61206+int grsec_enable_tpe_invert;
61207+int grsec_enable_socket_all;
61208+int grsec_socket_all_gid;
61209+int grsec_enable_socket_client;
61210+int grsec_socket_client_gid;
61211+int grsec_enable_socket_server;
61212+int grsec_socket_server_gid;
61213+int grsec_resource_logging;
61214+int grsec_disable_privio;
61215+int grsec_enable_log_rwxmaps;
61216+int grsec_lock;
61217+
61218+DEFINE_SPINLOCK(grsec_alert_lock);
61219+unsigned long grsec_alert_wtime = 0;
61220+unsigned long grsec_alert_fyet = 0;
61221+
61222+DEFINE_SPINLOCK(grsec_audit_lock);
61223+
61224+DEFINE_RWLOCK(grsec_exec_file_lock);
61225+
61226+char *gr_shared_page[4];
61227+
61228+char *gr_alert_log_fmt;
61229+char *gr_audit_log_fmt;
61230+char *gr_alert_log_buf;
61231+char *gr_audit_log_buf;
61232+
61233+extern struct gr_arg *gr_usermode;
61234+extern unsigned char *gr_system_salt;
61235+extern unsigned char *gr_system_sum;
61236+
61237+void __init
61238+grsecurity_init(void)
61239+{
61240+ int j;
61241+ /* create the per-cpu shared pages */
61242+
61243+#ifdef CONFIG_X86
61244+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
61245+#endif
61246+
61247+ for (j = 0; j < 4; j++) {
61248+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
61249+ if (gr_shared_page[j] == NULL) {
61250+ panic("Unable to allocate grsecurity shared page");
61251+ return;
61252+ }
61253+ }
61254+
61255+ /* allocate log buffers */
61256+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
61257+ if (!gr_alert_log_fmt) {
61258+ panic("Unable to allocate grsecurity alert log format buffer");
61259+ return;
61260+ }
61261+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
61262+ if (!gr_audit_log_fmt) {
61263+ panic("Unable to allocate grsecurity audit log format buffer");
61264+ return;
61265+ }
61266+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
61267+ if (!gr_alert_log_buf) {
61268+ panic("Unable to allocate grsecurity alert log buffer");
61269+ return;
61270+ }
61271+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
61272+ if (!gr_audit_log_buf) {
61273+ panic("Unable to allocate grsecurity audit log buffer");
61274+ return;
61275+ }
61276+
61277+ /* allocate memory for authentication structure */
61278+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
61279+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
61280+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
61281+
61282+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
61283+ panic("Unable to allocate grsecurity authentication structure");
61284+ return;
61285+ }
61286+
61287+
61288+#ifdef CONFIG_GRKERNSEC_IO
61289+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
61290+ grsec_disable_privio = 1;
61291+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
61292+ grsec_disable_privio = 1;
61293+#else
61294+ grsec_disable_privio = 0;
61295+#endif
61296+#endif
61297+
61298+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
61299+ /* for backward compatibility, tpe_invert always defaults to on if
61300+ enabled in the kernel
61301+ */
61302+ grsec_enable_tpe_invert = 1;
61303+#endif
61304+
61305+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
61306+#ifndef CONFIG_GRKERNSEC_SYSCTL
61307+ grsec_lock = 1;
61308+#endif
61309+
61310+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61311+ grsec_enable_audit_textrel = 1;
61312+#endif
61313+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61314+ grsec_enable_log_rwxmaps = 1;
61315+#endif
61316+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
61317+ grsec_enable_group = 1;
61318+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
61319+#endif
61320+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61321+ grsec_enable_ptrace_readexec = 1;
61322+#endif
61323+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
61324+ grsec_enable_chdir = 1;
61325+#endif
61326+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61327+ grsec_enable_harden_ptrace = 1;
61328+#endif
61329+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61330+ grsec_enable_mount = 1;
61331+#endif
61332+#ifdef CONFIG_GRKERNSEC_LINK
61333+ grsec_enable_link = 1;
61334+#endif
61335+#ifdef CONFIG_GRKERNSEC_BRUTE
61336+ grsec_enable_brute = 1;
61337+#endif
61338+#ifdef CONFIG_GRKERNSEC_DMESG
61339+ grsec_enable_dmesg = 1;
61340+#endif
61341+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
61342+ grsec_enable_blackhole = 1;
61343+ grsec_lastack_retries = 4;
61344+#endif
61345+#ifdef CONFIG_GRKERNSEC_FIFO
61346+ grsec_enable_fifo = 1;
61347+#endif
61348+#ifdef CONFIG_GRKERNSEC_EXECLOG
61349+ grsec_enable_execlog = 1;
61350+#endif
61351+#ifdef CONFIG_GRKERNSEC_SETXID
61352+ grsec_enable_setxid = 1;
61353+#endif
61354+#ifdef CONFIG_GRKERNSEC_SIGNAL
61355+ grsec_enable_signal = 1;
61356+#endif
61357+#ifdef CONFIG_GRKERNSEC_FORKFAIL
61358+ grsec_enable_forkfail = 1;
61359+#endif
61360+#ifdef CONFIG_GRKERNSEC_TIME
61361+ grsec_enable_time = 1;
61362+#endif
61363+#ifdef CONFIG_GRKERNSEC_RESLOG
61364+ grsec_resource_logging = 1;
61365+#endif
61366+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61367+ grsec_enable_chroot_findtask = 1;
61368+#endif
61369+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61370+ grsec_enable_chroot_unix = 1;
61371+#endif
61372+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61373+ grsec_enable_chroot_mount = 1;
61374+#endif
61375+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61376+ grsec_enable_chroot_fchdir = 1;
61377+#endif
61378+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61379+ grsec_enable_chroot_shmat = 1;
61380+#endif
61381+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61382+ grsec_enable_audit_ptrace = 1;
61383+#endif
61384+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61385+ grsec_enable_chroot_double = 1;
61386+#endif
61387+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61388+ grsec_enable_chroot_pivot = 1;
61389+#endif
61390+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61391+ grsec_enable_chroot_chdir = 1;
61392+#endif
61393+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61394+ grsec_enable_chroot_chmod = 1;
61395+#endif
61396+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61397+ grsec_enable_chroot_mknod = 1;
61398+#endif
61399+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61400+ grsec_enable_chroot_nice = 1;
61401+#endif
61402+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61403+ grsec_enable_chroot_execlog = 1;
61404+#endif
61405+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61406+ grsec_enable_chroot_caps = 1;
61407+#endif
61408+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
61409+ grsec_enable_chroot_sysctl = 1;
61410+#endif
61411+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61412+ grsec_enable_symlinkown = 1;
61413+ grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
61414+#endif
61415+#ifdef CONFIG_GRKERNSEC_TPE
61416+ grsec_enable_tpe = 1;
61417+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
61418+#ifdef CONFIG_GRKERNSEC_TPE_ALL
61419+ grsec_enable_tpe_all = 1;
61420+#endif
61421+#endif
61422+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61423+ grsec_enable_socket_all = 1;
61424+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
61425+#endif
61426+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61427+ grsec_enable_socket_client = 1;
61428+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
61429+#endif
61430+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61431+ grsec_enable_socket_server = 1;
61432+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
61433+#endif
61434+#endif
61435+
61436+ return;
61437+}
61438diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
61439new file mode 100644
61440index 0000000..6095407
61441--- /dev/null
61442+++ b/grsecurity/grsec_link.c
61443@@ -0,0 +1,58 @@
61444+#include <linux/kernel.h>
61445+#include <linux/sched.h>
61446+#include <linux/fs.h>
61447+#include <linux/file.h>
61448+#include <linux/grinternal.h>
61449+
61450+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
61451+{
61452+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61453+ const struct inode *link_inode = link->dentry->d_inode;
61454+
61455+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
61456+ /* ignore root-owned links, e.g. /proc/self */
61457+ !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
61458+ !uid_eq(link_inode->i_uid, target->i_uid)) {
61459+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
61460+ return 1;
61461+ }
61462+#endif
61463+ return 0;
61464+}
61465+
61466+int
61467+gr_handle_follow_link(const struct inode *parent,
61468+ const struct inode *inode,
61469+ const struct dentry *dentry, const struct vfsmount *mnt)
61470+{
61471+#ifdef CONFIG_GRKERNSEC_LINK
61472+ const struct cred *cred = current_cred();
61473+
61474+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
61475+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
61476+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
61477+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
61478+ return -EACCES;
61479+ }
61480+#endif
61481+ return 0;
61482+}
61483+
61484+int
61485+gr_handle_hardlink(const struct dentry *dentry,
61486+ const struct vfsmount *mnt,
61487+ struct inode *inode, const int mode, const struct filename *to)
61488+{
61489+#ifdef CONFIG_GRKERNSEC_LINK
61490+ const struct cred *cred = current_cred();
61491+
61492+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
61493+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
61494+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
61495+ !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
61496+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
61497+ return -EPERM;
61498+ }
61499+#endif
61500+ return 0;
61501+}
61502diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
61503new file mode 100644
61504index 0000000..7bd6c2b
61505--- /dev/null
61506+++ b/grsecurity/grsec_log.c
61507@@ -0,0 +1,329 @@
61508+#include <linux/kernel.h>
61509+#include <linux/sched.h>
61510+#include <linux/file.h>
61511+#include <linux/tty.h>
61512+#include <linux/fs.h>
61513+#include <linux/grinternal.h>
61514+
61515+#ifdef CONFIG_TREE_PREEMPT_RCU
61516+#define DISABLE_PREEMPT() preempt_disable()
61517+#define ENABLE_PREEMPT() preempt_enable()
61518+#else
61519+#define DISABLE_PREEMPT()
61520+#define ENABLE_PREEMPT()
61521+#endif
61522+
61523+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
61524+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
61525+
61526+#define BEGIN_LOCKS(x) \
61527+ DISABLE_PREEMPT(); \
61528+ rcu_read_lock(); \
61529+ read_lock(&tasklist_lock); \
61530+ read_lock(&grsec_exec_file_lock); \
61531+ if (x != GR_DO_AUDIT) \
61532+ spin_lock(&grsec_alert_lock); \
61533+ else \
61534+ spin_lock(&grsec_audit_lock)
61535+
61536+#define END_LOCKS(x) \
61537+ if (x != GR_DO_AUDIT) \
61538+ spin_unlock(&grsec_alert_lock); \
61539+ else \
61540+ spin_unlock(&grsec_audit_lock); \
61541+ read_unlock(&grsec_exec_file_lock); \
61542+ read_unlock(&tasklist_lock); \
61543+ rcu_read_unlock(); \
61544+ ENABLE_PREEMPT(); \
61545+ if (x == GR_DONT_AUDIT) \
61546+ gr_handle_alertkill(current)
61547+
61548+enum {
61549+ FLOODING,
61550+ NO_FLOODING
61551+};
61552+
61553+extern char *gr_alert_log_fmt;
61554+extern char *gr_audit_log_fmt;
61555+extern char *gr_alert_log_buf;
61556+extern char *gr_audit_log_buf;
61557+
61558+static int gr_log_start(int audit)
61559+{
61560+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
61561+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
61562+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61563+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
61564+ unsigned long curr_secs = get_seconds();
61565+
61566+ if (audit == GR_DO_AUDIT)
61567+ goto set_fmt;
61568+
61569+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
61570+ grsec_alert_wtime = curr_secs;
61571+ grsec_alert_fyet = 0;
61572+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
61573+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
61574+ grsec_alert_fyet++;
61575+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
61576+ grsec_alert_wtime = curr_secs;
61577+ grsec_alert_fyet++;
61578+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
61579+ return FLOODING;
61580+ }
61581+ else return FLOODING;
61582+
61583+set_fmt:
61584+#endif
61585+ memset(buf, 0, PAGE_SIZE);
61586+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
61587+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
61588+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
61589+ } else if (current->signal->curr_ip) {
61590+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
61591+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
61592+ } else if (gr_acl_is_enabled()) {
61593+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
61594+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
61595+ } else {
61596+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
61597+ strcpy(buf, fmt);
61598+ }
61599+
61600+ return NO_FLOODING;
61601+}
61602+
61603+static void gr_log_middle(int audit, const char *msg, va_list ap)
61604+ __attribute__ ((format (printf, 2, 0)));
61605+
61606+static void gr_log_middle(int audit, const char *msg, va_list ap)
61607+{
61608+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61609+ unsigned int len = strlen(buf);
61610+
61611+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
61612+
61613+ return;
61614+}
61615+
61616+static void gr_log_middle_varargs(int audit, const char *msg, ...)
61617+ __attribute__ ((format (printf, 2, 3)));
61618+
61619+static void gr_log_middle_varargs(int audit, const char *msg, ...)
61620+{
61621+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61622+ unsigned int len = strlen(buf);
61623+ va_list ap;
61624+
61625+ va_start(ap, msg);
61626+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
61627+ va_end(ap);
61628+
61629+ return;
61630+}
61631+
61632+static void gr_log_end(int audit, int append_default)
61633+{
61634+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61635+ if (append_default) {
61636+ struct task_struct *task = current;
61637+ struct task_struct *parent = task->real_parent;
61638+ const struct cred *cred = __task_cred(task);
61639+ const struct cred *pcred = __task_cred(parent);
61640+ unsigned int len = strlen(buf);
61641+
61642+ 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));
61643+ }
61644+
61645+ printk("%s\n", buf);
61646+
61647+ return;
61648+}
61649+
61650+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
61651+{
61652+ int logtype;
61653+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
61654+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
61655+ void *voidptr = NULL;
61656+ int num1 = 0, num2 = 0;
61657+ unsigned long ulong1 = 0, ulong2 = 0;
61658+ struct dentry *dentry = NULL;
61659+ struct vfsmount *mnt = NULL;
61660+ struct file *file = NULL;
61661+ struct task_struct *task = NULL;
61662+ const struct cred *cred, *pcred;
61663+ va_list ap;
61664+
61665+ BEGIN_LOCKS(audit);
61666+ logtype = gr_log_start(audit);
61667+ if (logtype == FLOODING) {
61668+ END_LOCKS(audit);
61669+ return;
61670+ }
61671+ va_start(ap, argtypes);
61672+ switch (argtypes) {
61673+ case GR_TTYSNIFF:
61674+ task = va_arg(ap, struct task_struct *);
61675+ 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));
61676+ break;
61677+ case GR_SYSCTL_HIDDEN:
61678+ str1 = va_arg(ap, char *);
61679+ gr_log_middle_varargs(audit, msg, result, str1);
61680+ break;
61681+ case GR_RBAC:
61682+ dentry = va_arg(ap, struct dentry *);
61683+ mnt = va_arg(ap, struct vfsmount *);
61684+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
61685+ break;
61686+ case GR_RBAC_STR:
61687+ dentry = va_arg(ap, struct dentry *);
61688+ mnt = va_arg(ap, struct vfsmount *);
61689+ str1 = va_arg(ap, char *);
61690+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
61691+ break;
61692+ case GR_STR_RBAC:
61693+ str1 = va_arg(ap, char *);
61694+ dentry = va_arg(ap, struct dentry *);
61695+ mnt = va_arg(ap, struct vfsmount *);
61696+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
61697+ break;
61698+ case GR_RBAC_MODE2:
61699+ dentry = va_arg(ap, struct dentry *);
61700+ mnt = va_arg(ap, struct vfsmount *);
61701+ str1 = va_arg(ap, char *);
61702+ str2 = va_arg(ap, char *);
61703+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
61704+ break;
61705+ case GR_RBAC_MODE3:
61706+ dentry = va_arg(ap, struct dentry *);
61707+ mnt = va_arg(ap, struct vfsmount *);
61708+ str1 = va_arg(ap, char *);
61709+ str2 = va_arg(ap, char *);
61710+ str3 = va_arg(ap, char *);
61711+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
61712+ break;
61713+ case GR_FILENAME:
61714+ dentry = va_arg(ap, struct dentry *);
61715+ mnt = va_arg(ap, struct vfsmount *);
61716+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
61717+ break;
61718+ case GR_STR_FILENAME:
61719+ str1 = va_arg(ap, char *);
61720+ dentry = va_arg(ap, struct dentry *);
61721+ mnt = va_arg(ap, struct vfsmount *);
61722+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
61723+ break;
61724+ case GR_FILENAME_STR:
61725+ dentry = va_arg(ap, struct dentry *);
61726+ mnt = va_arg(ap, struct vfsmount *);
61727+ str1 = va_arg(ap, char *);
61728+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
61729+ break;
61730+ case GR_FILENAME_TWO_INT:
61731+ dentry = va_arg(ap, struct dentry *);
61732+ mnt = va_arg(ap, struct vfsmount *);
61733+ num1 = va_arg(ap, int);
61734+ num2 = va_arg(ap, int);
61735+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
61736+ break;
61737+ case GR_FILENAME_TWO_INT_STR:
61738+ dentry = va_arg(ap, struct dentry *);
61739+ mnt = va_arg(ap, struct vfsmount *);
61740+ num1 = va_arg(ap, int);
61741+ num2 = va_arg(ap, int);
61742+ str1 = va_arg(ap, char *);
61743+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
61744+ break;
61745+ case GR_TEXTREL:
61746+ file = va_arg(ap, struct file *);
61747+ ulong1 = va_arg(ap, unsigned long);
61748+ ulong2 = va_arg(ap, unsigned long);
61749+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
61750+ break;
61751+ case GR_PTRACE:
61752+ task = va_arg(ap, struct task_struct *);
61753+ 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));
61754+ break;
61755+ case GR_RESOURCE:
61756+ task = va_arg(ap, struct task_struct *);
61757+ cred = __task_cred(task);
61758+ pcred = __task_cred(task->real_parent);
61759+ ulong1 = va_arg(ap, unsigned long);
61760+ str1 = va_arg(ap, char *);
61761+ ulong2 = va_arg(ap, unsigned long);
61762+ 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));
61763+ break;
61764+ case GR_CAP:
61765+ task = va_arg(ap, struct task_struct *);
61766+ cred = __task_cred(task);
61767+ pcred = __task_cred(task->real_parent);
61768+ str1 = va_arg(ap, char *);
61769+ 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));
61770+ break;
61771+ case GR_SIG:
61772+ str1 = va_arg(ap, char *);
61773+ voidptr = va_arg(ap, void *);
61774+ gr_log_middle_varargs(audit, msg, str1, voidptr);
61775+ break;
61776+ case GR_SIG2:
61777+ task = va_arg(ap, struct task_struct *);
61778+ cred = __task_cred(task);
61779+ pcred = __task_cred(task->real_parent);
61780+ num1 = va_arg(ap, int);
61781+ 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));
61782+ break;
61783+ case GR_CRASH1:
61784+ task = va_arg(ap, struct task_struct *);
61785+ cred = __task_cred(task);
61786+ pcred = __task_cred(task->real_parent);
61787+ ulong1 = va_arg(ap, unsigned long);
61788+ 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);
61789+ break;
61790+ case GR_CRASH2:
61791+ task = va_arg(ap, struct task_struct *);
61792+ cred = __task_cred(task);
61793+ pcred = __task_cred(task->real_parent);
61794+ ulong1 = va_arg(ap, unsigned long);
61795+ 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);
61796+ break;
61797+ case GR_RWXMAP:
61798+ file = va_arg(ap, struct file *);
61799+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
61800+ break;
61801+ case GR_PSACCT:
61802+ {
61803+ unsigned int wday, cday;
61804+ __u8 whr, chr;
61805+ __u8 wmin, cmin;
61806+ __u8 wsec, csec;
61807+ char cur_tty[64] = { 0 };
61808+ char parent_tty[64] = { 0 };
61809+
61810+ task = va_arg(ap, struct task_struct *);
61811+ wday = va_arg(ap, unsigned int);
61812+ cday = va_arg(ap, unsigned int);
61813+ whr = va_arg(ap, int);
61814+ chr = va_arg(ap, int);
61815+ wmin = va_arg(ap, int);
61816+ cmin = va_arg(ap, int);
61817+ wsec = va_arg(ap, int);
61818+ csec = va_arg(ap, int);
61819+ ulong1 = va_arg(ap, unsigned long);
61820+ cred = __task_cred(task);
61821+ pcred = __task_cred(task->real_parent);
61822+
61823+ 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));
61824+ }
61825+ break;
61826+ default:
61827+ gr_log_middle(audit, msg, ap);
61828+ }
61829+ va_end(ap);
61830+ // these don't need DEFAULTSECARGS printed on the end
61831+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
61832+ gr_log_end(audit, 0);
61833+ else
61834+ gr_log_end(audit, 1);
61835+ END_LOCKS(audit);
61836+}
61837diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
61838new file mode 100644
61839index 0000000..f536303
61840--- /dev/null
61841+++ b/grsecurity/grsec_mem.c
61842@@ -0,0 +1,40 @@
61843+#include <linux/kernel.h>
61844+#include <linux/sched.h>
61845+#include <linux/mm.h>
61846+#include <linux/mman.h>
61847+#include <linux/grinternal.h>
61848+
61849+void
61850+gr_handle_ioperm(void)
61851+{
61852+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
61853+ return;
61854+}
61855+
61856+void
61857+gr_handle_iopl(void)
61858+{
61859+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
61860+ return;
61861+}
61862+
61863+void
61864+gr_handle_mem_readwrite(u64 from, u64 to)
61865+{
61866+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
61867+ return;
61868+}
61869+
61870+void
61871+gr_handle_vm86(void)
61872+{
61873+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
61874+ return;
61875+}
61876+
61877+void
61878+gr_log_badprocpid(const char *entry)
61879+{
61880+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
61881+ return;
61882+}
61883diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
61884new file mode 100644
61885index 0000000..2131422
61886--- /dev/null
61887+++ b/grsecurity/grsec_mount.c
61888@@ -0,0 +1,62 @@
61889+#include <linux/kernel.h>
61890+#include <linux/sched.h>
61891+#include <linux/mount.h>
61892+#include <linux/grsecurity.h>
61893+#include <linux/grinternal.h>
61894+
61895+void
61896+gr_log_remount(const char *devname, const int retval)
61897+{
61898+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61899+ if (grsec_enable_mount && (retval >= 0))
61900+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
61901+#endif
61902+ return;
61903+}
61904+
61905+void
61906+gr_log_unmount(const char *devname, const int retval)
61907+{
61908+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61909+ if (grsec_enable_mount && (retval >= 0))
61910+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
61911+#endif
61912+ return;
61913+}
61914+
61915+void
61916+gr_log_mount(const char *from, const char *to, const int retval)
61917+{
61918+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61919+ if (grsec_enable_mount && (retval >= 0))
61920+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
61921+#endif
61922+ return;
61923+}
61924+
61925+int
61926+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
61927+{
61928+#ifdef CONFIG_GRKERNSEC_ROFS
61929+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
61930+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
61931+ return -EPERM;
61932+ } else
61933+ return 0;
61934+#endif
61935+ return 0;
61936+}
61937+
61938+int
61939+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
61940+{
61941+#ifdef CONFIG_GRKERNSEC_ROFS
61942+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
61943+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
61944+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
61945+ return -EPERM;
61946+ } else
61947+ return 0;
61948+#endif
61949+ return 0;
61950+}
61951diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
61952new file mode 100644
61953index 0000000..a3b12a0
61954--- /dev/null
61955+++ b/grsecurity/grsec_pax.c
61956@@ -0,0 +1,36 @@
61957+#include <linux/kernel.h>
61958+#include <linux/sched.h>
61959+#include <linux/mm.h>
61960+#include <linux/file.h>
61961+#include <linux/grinternal.h>
61962+#include <linux/grsecurity.h>
61963+
61964+void
61965+gr_log_textrel(struct vm_area_struct * vma)
61966+{
61967+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61968+ if (grsec_enable_audit_textrel)
61969+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
61970+#endif
61971+ return;
61972+}
61973+
61974+void
61975+gr_log_rwxmmap(struct file *file)
61976+{
61977+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61978+ if (grsec_enable_log_rwxmaps)
61979+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
61980+#endif
61981+ return;
61982+}
61983+
61984+void
61985+gr_log_rwxmprotect(struct file *file)
61986+{
61987+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61988+ if (grsec_enable_log_rwxmaps)
61989+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
61990+#endif
61991+ return;
61992+}
61993diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
61994new file mode 100644
61995index 0000000..f7f29aa
61996--- /dev/null
61997+++ b/grsecurity/grsec_ptrace.c
61998@@ -0,0 +1,30 @@
61999+#include <linux/kernel.h>
62000+#include <linux/sched.h>
62001+#include <linux/grinternal.h>
62002+#include <linux/security.h>
62003+
62004+void
62005+gr_audit_ptrace(struct task_struct *task)
62006+{
62007+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
62008+ if (grsec_enable_audit_ptrace)
62009+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
62010+#endif
62011+ return;
62012+}
62013+
62014+int
62015+gr_ptrace_readexec(struct file *file, int unsafe_flags)
62016+{
62017+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
62018+ const struct dentry *dentry = file->f_path.dentry;
62019+ const struct vfsmount *mnt = file->f_path.mnt;
62020+
62021+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
62022+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
62023+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
62024+ return -EACCES;
62025+ }
62026+#endif
62027+ return 0;
62028+}
62029diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
62030new file mode 100644
62031index 0000000..5c00416
62032--- /dev/null
62033+++ b/grsecurity/grsec_sig.c
62034@@ -0,0 +1,222 @@
62035+#include <linux/kernel.h>
62036+#include <linux/sched.h>
62037+#include <linux/delay.h>
62038+#include <linux/grsecurity.h>
62039+#include <linux/grinternal.h>
62040+#include <linux/hardirq.h>
62041+
62042+char *signames[] = {
62043+ [SIGSEGV] = "Segmentation fault",
62044+ [SIGILL] = "Illegal instruction",
62045+ [SIGABRT] = "Abort",
62046+ [SIGBUS] = "Invalid alignment/Bus error"
62047+};
62048+
62049+void
62050+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
62051+{
62052+#ifdef CONFIG_GRKERNSEC_SIGNAL
62053+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
62054+ (sig == SIGABRT) || (sig == SIGBUS))) {
62055+ if (t->pid == current->pid) {
62056+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
62057+ } else {
62058+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
62059+ }
62060+ }
62061+#endif
62062+ return;
62063+}
62064+
62065+int
62066+gr_handle_signal(const struct task_struct *p, const int sig)
62067+{
62068+#ifdef CONFIG_GRKERNSEC
62069+ /* ignore the 0 signal for protected task checks */
62070+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
62071+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
62072+ return -EPERM;
62073+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
62074+ return -EPERM;
62075+ }
62076+#endif
62077+ return 0;
62078+}
62079+
62080+#ifdef CONFIG_GRKERNSEC
62081+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
62082+
62083+int gr_fake_force_sig(int sig, struct task_struct *t)
62084+{
62085+ unsigned long int flags;
62086+ int ret, blocked, ignored;
62087+ struct k_sigaction *action;
62088+
62089+ spin_lock_irqsave(&t->sighand->siglock, flags);
62090+ action = &t->sighand->action[sig-1];
62091+ ignored = action->sa.sa_handler == SIG_IGN;
62092+ blocked = sigismember(&t->blocked, sig);
62093+ if (blocked || ignored) {
62094+ action->sa.sa_handler = SIG_DFL;
62095+ if (blocked) {
62096+ sigdelset(&t->blocked, sig);
62097+ recalc_sigpending_and_wake(t);
62098+ }
62099+ }
62100+ if (action->sa.sa_handler == SIG_DFL)
62101+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
62102+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
62103+
62104+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
62105+
62106+ return ret;
62107+}
62108+#endif
62109+
62110+#ifdef CONFIG_GRKERNSEC_BRUTE
62111+#define GR_USER_BAN_TIME (15 * 60)
62112+#define GR_DAEMON_BRUTE_TIME (30 * 60)
62113+
62114+static int __get_dumpable(unsigned long mm_flags)
62115+{
62116+ int ret;
62117+
62118+ ret = mm_flags & MMF_DUMPABLE_MASK;
62119+ return (ret >= 2) ? 2 : ret;
62120+}
62121+#endif
62122+
62123+void gr_handle_brute_attach(unsigned long mm_flags)
62124+{
62125+#ifdef CONFIG_GRKERNSEC_BRUTE
62126+ struct task_struct *p = current;
62127+ kuid_t uid = GLOBAL_ROOT_UID;
62128+ int daemon = 0;
62129+
62130+ if (!grsec_enable_brute)
62131+ return;
62132+
62133+ rcu_read_lock();
62134+ read_lock(&tasklist_lock);
62135+ read_lock(&grsec_exec_file_lock);
62136+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
62137+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
62138+ p->real_parent->brute = 1;
62139+ daemon = 1;
62140+ } else {
62141+ const struct cred *cred = __task_cred(p), *cred2;
62142+ struct task_struct *tsk, *tsk2;
62143+
62144+ if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
62145+ struct user_struct *user;
62146+
62147+ uid = cred->uid;
62148+
62149+ /* this is put upon execution past expiration */
62150+ user = find_user(uid);
62151+ if (user == NULL)
62152+ goto unlock;
62153+ user->banned = 1;
62154+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
62155+ if (user->ban_expires == ~0UL)
62156+ user->ban_expires--;
62157+
62158+ do_each_thread(tsk2, tsk) {
62159+ cred2 = __task_cred(tsk);
62160+ if (tsk != p && uid_eq(cred2->uid, uid))
62161+ gr_fake_force_sig(SIGKILL, tsk);
62162+ } while_each_thread(tsk2, tsk);
62163+ }
62164+ }
62165+unlock:
62166+ read_unlock(&grsec_exec_file_lock);
62167+ read_unlock(&tasklist_lock);
62168+ rcu_read_unlock();
62169+
62170+ if (!uid_eq(uid, GLOBAL_ROOT_UID))
62171+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
62172+ from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
62173+ else if (daemon)
62174+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
62175+
62176+#endif
62177+ return;
62178+}
62179+
62180+void gr_handle_brute_check(void)
62181+{
62182+#ifdef CONFIG_GRKERNSEC_BRUTE
62183+ struct task_struct *p = current;
62184+
62185+ if (unlikely(p->brute)) {
62186+ if (!grsec_enable_brute)
62187+ p->brute = 0;
62188+ else if (time_before(get_seconds(), p->brute_expires))
62189+ msleep(30 * 1000);
62190+ }
62191+#endif
62192+ return;
62193+}
62194+
62195+void gr_handle_kernel_exploit(void)
62196+{
62197+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
62198+ const struct cred *cred;
62199+ struct task_struct *tsk, *tsk2;
62200+ struct user_struct *user;
62201+ kuid_t uid;
62202+
62203+ if (in_irq() || in_serving_softirq() || in_nmi())
62204+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
62205+
62206+ uid = current_uid();
62207+
62208+ if (uid_eq(uid, GLOBAL_ROOT_UID))
62209+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
62210+ else {
62211+ /* kill all the processes of this user, hold a reference
62212+ to their creds struct, and prevent them from creating
62213+ another process until system reset
62214+ */
62215+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
62216+ from_kuid_munged(&init_user_ns, uid));
62217+ /* we intentionally leak this ref */
62218+ user = get_uid(current->cred->user);
62219+ if (user) {
62220+ user->banned = 1;
62221+ user->ban_expires = ~0UL;
62222+ }
62223+
62224+ read_lock(&tasklist_lock);
62225+ do_each_thread(tsk2, tsk) {
62226+ cred = __task_cred(tsk);
62227+ if (uid_eq(cred->uid, uid))
62228+ gr_fake_force_sig(SIGKILL, tsk);
62229+ } while_each_thread(tsk2, tsk);
62230+ read_unlock(&tasklist_lock);
62231+ }
62232+#endif
62233+}
62234+
62235+int __gr_process_user_ban(struct user_struct *user)
62236+{
62237+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62238+ if (unlikely(user->banned)) {
62239+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
62240+ user->banned = 0;
62241+ user->ban_expires = 0;
62242+ free_uid(user);
62243+ } else
62244+ return -EPERM;
62245+ }
62246+#endif
62247+ return 0;
62248+}
62249+
62250+int gr_process_user_ban(void)
62251+{
62252+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62253+ return __gr_process_user_ban(current->cred->user);
62254+#endif
62255+ return 0;
62256+}
62257diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
62258new file mode 100644
62259index 0000000..4030d57
62260--- /dev/null
62261+++ b/grsecurity/grsec_sock.c
62262@@ -0,0 +1,244 @@
62263+#include <linux/kernel.h>
62264+#include <linux/module.h>
62265+#include <linux/sched.h>
62266+#include <linux/file.h>
62267+#include <linux/net.h>
62268+#include <linux/in.h>
62269+#include <linux/ip.h>
62270+#include <net/sock.h>
62271+#include <net/inet_sock.h>
62272+#include <linux/grsecurity.h>
62273+#include <linux/grinternal.h>
62274+#include <linux/gracl.h>
62275+
62276+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
62277+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
62278+
62279+EXPORT_SYMBOL(gr_search_udp_recvmsg);
62280+EXPORT_SYMBOL(gr_search_udp_sendmsg);
62281+
62282+#ifdef CONFIG_UNIX_MODULE
62283+EXPORT_SYMBOL(gr_acl_handle_unix);
62284+EXPORT_SYMBOL(gr_acl_handle_mknod);
62285+EXPORT_SYMBOL(gr_handle_chroot_unix);
62286+EXPORT_SYMBOL(gr_handle_create);
62287+#endif
62288+
62289+#ifdef CONFIG_GRKERNSEC
62290+#define gr_conn_table_size 32749
62291+struct conn_table_entry {
62292+ struct conn_table_entry *next;
62293+ struct signal_struct *sig;
62294+};
62295+
62296+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
62297+DEFINE_SPINLOCK(gr_conn_table_lock);
62298+
62299+extern const char * gr_socktype_to_name(unsigned char type);
62300+extern const char * gr_proto_to_name(unsigned char proto);
62301+extern const char * gr_sockfamily_to_name(unsigned char family);
62302+
62303+static __inline__ int
62304+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
62305+{
62306+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
62307+}
62308+
62309+static __inline__ int
62310+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
62311+ __u16 sport, __u16 dport)
62312+{
62313+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
62314+ sig->gr_sport == sport && sig->gr_dport == dport))
62315+ return 1;
62316+ else
62317+ return 0;
62318+}
62319+
62320+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
62321+{
62322+ struct conn_table_entry **match;
62323+ unsigned int index;
62324+
62325+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
62326+ sig->gr_sport, sig->gr_dport,
62327+ gr_conn_table_size);
62328+
62329+ newent->sig = sig;
62330+
62331+ match = &gr_conn_table[index];
62332+ newent->next = *match;
62333+ *match = newent;
62334+
62335+ return;
62336+}
62337+
62338+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
62339+{
62340+ struct conn_table_entry *match, *last = NULL;
62341+ unsigned int index;
62342+
62343+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
62344+ sig->gr_sport, sig->gr_dport,
62345+ gr_conn_table_size);
62346+
62347+ match = gr_conn_table[index];
62348+ while (match && !conn_match(match->sig,
62349+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
62350+ sig->gr_dport)) {
62351+ last = match;
62352+ match = match->next;
62353+ }
62354+
62355+ if (match) {
62356+ if (last)
62357+ last->next = match->next;
62358+ else
62359+ gr_conn_table[index] = NULL;
62360+ kfree(match);
62361+ }
62362+
62363+ return;
62364+}
62365+
62366+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
62367+ __u16 sport, __u16 dport)
62368+{
62369+ struct conn_table_entry *match;
62370+ unsigned int index;
62371+
62372+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
62373+
62374+ match = gr_conn_table[index];
62375+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
62376+ match = match->next;
62377+
62378+ if (match)
62379+ return match->sig;
62380+ else
62381+ return NULL;
62382+}
62383+
62384+#endif
62385+
62386+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
62387+{
62388+#ifdef CONFIG_GRKERNSEC
62389+ struct signal_struct *sig = task->signal;
62390+ struct conn_table_entry *newent;
62391+
62392+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
62393+ if (newent == NULL)
62394+ return;
62395+ /* no bh lock needed since we are called with bh disabled */
62396+ spin_lock(&gr_conn_table_lock);
62397+ gr_del_task_from_ip_table_nolock(sig);
62398+ sig->gr_saddr = inet->inet_rcv_saddr;
62399+ sig->gr_daddr = inet->inet_daddr;
62400+ sig->gr_sport = inet->inet_sport;
62401+ sig->gr_dport = inet->inet_dport;
62402+ gr_add_to_task_ip_table_nolock(sig, newent);
62403+ spin_unlock(&gr_conn_table_lock);
62404+#endif
62405+ return;
62406+}
62407+
62408+void gr_del_task_from_ip_table(struct task_struct *task)
62409+{
62410+#ifdef CONFIG_GRKERNSEC
62411+ spin_lock_bh(&gr_conn_table_lock);
62412+ gr_del_task_from_ip_table_nolock(task->signal);
62413+ spin_unlock_bh(&gr_conn_table_lock);
62414+#endif
62415+ return;
62416+}
62417+
62418+void
62419+gr_attach_curr_ip(const struct sock *sk)
62420+{
62421+#ifdef CONFIG_GRKERNSEC
62422+ struct signal_struct *p, *set;
62423+ const struct inet_sock *inet = inet_sk(sk);
62424+
62425+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
62426+ return;
62427+
62428+ set = current->signal;
62429+
62430+ spin_lock_bh(&gr_conn_table_lock);
62431+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
62432+ inet->inet_dport, inet->inet_sport);
62433+ if (unlikely(p != NULL)) {
62434+ set->curr_ip = p->curr_ip;
62435+ set->used_accept = 1;
62436+ gr_del_task_from_ip_table_nolock(p);
62437+ spin_unlock_bh(&gr_conn_table_lock);
62438+ return;
62439+ }
62440+ spin_unlock_bh(&gr_conn_table_lock);
62441+
62442+ set->curr_ip = inet->inet_daddr;
62443+ set->used_accept = 1;
62444+#endif
62445+ return;
62446+}
62447+
62448+int
62449+gr_handle_sock_all(const int family, const int type, const int protocol)
62450+{
62451+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62452+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
62453+ (family != AF_UNIX)) {
62454+ if (family == AF_INET)
62455+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
62456+ else
62457+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
62458+ return -EACCES;
62459+ }
62460+#endif
62461+ return 0;
62462+}
62463+
62464+int
62465+gr_handle_sock_server(const struct sockaddr *sck)
62466+{
62467+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62468+ if (grsec_enable_socket_server &&
62469+ in_group_p(grsec_socket_server_gid) &&
62470+ sck && (sck->sa_family != AF_UNIX) &&
62471+ (sck->sa_family != AF_LOCAL)) {
62472+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
62473+ return -EACCES;
62474+ }
62475+#endif
62476+ return 0;
62477+}
62478+
62479+int
62480+gr_handle_sock_server_other(const struct sock *sck)
62481+{
62482+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62483+ if (grsec_enable_socket_server &&
62484+ in_group_p(grsec_socket_server_gid) &&
62485+ sck && (sck->sk_family != AF_UNIX) &&
62486+ (sck->sk_family != AF_LOCAL)) {
62487+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
62488+ return -EACCES;
62489+ }
62490+#endif
62491+ return 0;
62492+}
62493+
62494+int
62495+gr_handle_sock_client(const struct sockaddr *sck)
62496+{
62497+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62498+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
62499+ sck && (sck->sa_family != AF_UNIX) &&
62500+ (sck->sa_family != AF_LOCAL)) {
62501+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
62502+ return -EACCES;
62503+ }
62504+#endif
62505+ return 0;
62506+}
62507diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
62508new file mode 100644
62509index 0000000..f55ef0f
62510--- /dev/null
62511+++ b/grsecurity/grsec_sysctl.c
62512@@ -0,0 +1,469 @@
62513+#include <linux/kernel.h>
62514+#include <linux/sched.h>
62515+#include <linux/sysctl.h>
62516+#include <linux/grsecurity.h>
62517+#include <linux/grinternal.h>
62518+
62519+int
62520+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
62521+{
62522+#ifdef CONFIG_GRKERNSEC_SYSCTL
62523+ if (dirname == NULL || name == NULL)
62524+ return 0;
62525+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
62526+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
62527+ return -EACCES;
62528+ }
62529+#endif
62530+ return 0;
62531+}
62532+
62533+#ifdef CONFIG_GRKERNSEC_ROFS
62534+static int __maybe_unused one = 1;
62535+#endif
62536+
62537+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
62538+struct ctl_table grsecurity_table[] = {
62539+#ifdef CONFIG_GRKERNSEC_SYSCTL
62540+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
62541+#ifdef CONFIG_GRKERNSEC_IO
62542+ {
62543+ .procname = "disable_priv_io",
62544+ .data = &grsec_disable_privio,
62545+ .maxlen = sizeof(int),
62546+ .mode = 0600,
62547+ .proc_handler = &proc_dointvec,
62548+ },
62549+#endif
62550+#endif
62551+#ifdef CONFIG_GRKERNSEC_LINK
62552+ {
62553+ .procname = "linking_restrictions",
62554+ .data = &grsec_enable_link,
62555+ .maxlen = sizeof(int),
62556+ .mode = 0600,
62557+ .proc_handler = &proc_dointvec,
62558+ },
62559+#endif
62560+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
62561+ {
62562+ .procname = "enforce_symlinksifowner",
62563+ .data = &grsec_enable_symlinkown,
62564+ .maxlen = sizeof(int),
62565+ .mode = 0600,
62566+ .proc_handler = &proc_dointvec,
62567+ },
62568+ {
62569+ .procname = "symlinkown_gid",
62570+ .data = &grsec_symlinkown_gid,
62571+ .maxlen = sizeof(int),
62572+ .mode = 0600,
62573+ .proc_handler = &proc_dointvec,
62574+ },
62575+#endif
62576+#ifdef CONFIG_GRKERNSEC_BRUTE
62577+ {
62578+ .procname = "deter_bruteforce",
62579+ .data = &grsec_enable_brute,
62580+ .maxlen = sizeof(int),
62581+ .mode = 0600,
62582+ .proc_handler = &proc_dointvec,
62583+ },
62584+#endif
62585+#ifdef CONFIG_GRKERNSEC_FIFO
62586+ {
62587+ .procname = "fifo_restrictions",
62588+ .data = &grsec_enable_fifo,
62589+ .maxlen = sizeof(int),
62590+ .mode = 0600,
62591+ .proc_handler = &proc_dointvec,
62592+ },
62593+#endif
62594+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
62595+ {
62596+ .procname = "ptrace_readexec",
62597+ .data = &grsec_enable_ptrace_readexec,
62598+ .maxlen = sizeof(int),
62599+ .mode = 0600,
62600+ .proc_handler = &proc_dointvec,
62601+ },
62602+#endif
62603+#ifdef CONFIG_GRKERNSEC_SETXID
62604+ {
62605+ .procname = "consistent_setxid",
62606+ .data = &grsec_enable_setxid,
62607+ .maxlen = sizeof(int),
62608+ .mode = 0600,
62609+ .proc_handler = &proc_dointvec,
62610+ },
62611+#endif
62612+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
62613+ {
62614+ .procname = "ip_blackhole",
62615+ .data = &grsec_enable_blackhole,
62616+ .maxlen = sizeof(int),
62617+ .mode = 0600,
62618+ .proc_handler = &proc_dointvec,
62619+ },
62620+ {
62621+ .procname = "lastack_retries",
62622+ .data = &grsec_lastack_retries,
62623+ .maxlen = sizeof(int),
62624+ .mode = 0600,
62625+ .proc_handler = &proc_dointvec,
62626+ },
62627+#endif
62628+#ifdef CONFIG_GRKERNSEC_EXECLOG
62629+ {
62630+ .procname = "exec_logging",
62631+ .data = &grsec_enable_execlog,
62632+ .maxlen = sizeof(int),
62633+ .mode = 0600,
62634+ .proc_handler = &proc_dointvec,
62635+ },
62636+#endif
62637+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62638+ {
62639+ .procname = "rwxmap_logging",
62640+ .data = &grsec_enable_log_rwxmaps,
62641+ .maxlen = sizeof(int),
62642+ .mode = 0600,
62643+ .proc_handler = &proc_dointvec,
62644+ },
62645+#endif
62646+#ifdef CONFIG_GRKERNSEC_SIGNAL
62647+ {
62648+ .procname = "signal_logging",
62649+ .data = &grsec_enable_signal,
62650+ .maxlen = sizeof(int),
62651+ .mode = 0600,
62652+ .proc_handler = &proc_dointvec,
62653+ },
62654+#endif
62655+#ifdef CONFIG_GRKERNSEC_FORKFAIL
62656+ {
62657+ .procname = "forkfail_logging",
62658+ .data = &grsec_enable_forkfail,
62659+ .maxlen = sizeof(int),
62660+ .mode = 0600,
62661+ .proc_handler = &proc_dointvec,
62662+ },
62663+#endif
62664+#ifdef CONFIG_GRKERNSEC_TIME
62665+ {
62666+ .procname = "timechange_logging",
62667+ .data = &grsec_enable_time,
62668+ .maxlen = sizeof(int),
62669+ .mode = 0600,
62670+ .proc_handler = &proc_dointvec,
62671+ },
62672+#endif
62673+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
62674+ {
62675+ .procname = "chroot_deny_shmat",
62676+ .data = &grsec_enable_chroot_shmat,
62677+ .maxlen = sizeof(int),
62678+ .mode = 0600,
62679+ .proc_handler = &proc_dointvec,
62680+ },
62681+#endif
62682+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
62683+ {
62684+ .procname = "chroot_deny_unix",
62685+ .data = &grsec_enable_chroot_unix,
62686+ .maxlen = sizeof(int),
62687+ .mode = 0600,
62688+ .proc_handler = &proc_dointvec,
62689+ },
62690+#endif
62691+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
62692+ {
62693+ .procname = "chroot_deny_mount",
62694+ .data = &grsec_enable_chroot_mount,
62695+ .maxlen = sizeof(int),
62696+ .mode = 0600,
62697+ .proc_handler = &proc_dointvec,
62698+ },
62699+#endif
62700+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
62701+ {
62702+ .procname = "chroot_deny_fchdir",
62703+ .data = &grsec_enable_chroot_fchdir,
62704+ .maxlen = sizeof(int),
62705+ .mode = 0600,
62706+ .proc_handler = &proc_dointvec,
62707+ },
62708+#endif
62709+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
62710+ {
62711+ .procname = "chroot_deny_chroot",
62712+ .data = &grsec_enable_chroot_double,
62713+ .maxlen = sizeof(int),
62714+ .mode = 0600,
62715+ .proc_handler = &proc_dointvec,
62716+ },
62717+#endif
62718+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
62719+ {
62720+ .procname = "chroot_deny_pivot",
62721+ .data = &grsec_enable_chroot_pivot,
62722+ .maxlen = sizeof(int),
62723+ .mode = 0600,
62724+ .proc_handler = &proc_dointvec,
62725+ },
62726+#endif
62727+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
62728+ {
62729+ .procname = "chroot_enforce_chdir",
62730+ .data = &grsec_enable_chroot_chdir,
62731+ .maxlen = sizeof(int),
62732+ .mode = 0600,
62733+ .proc_handler = &proc_dointvec,
62734+ },
62735+#endif
62736+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62737+ {
62738+ .procname = "chroot_deny_chmod",
62739+ .data = &grsec_enable_chroot_chmod,
62740+ .maxlen = sizeof(int),
62741+ .mode = 0600,
62742+ .proc_handler = &proc_dointvec,
62743+ },
62744+#endif
62745+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
62746+ {
62747+ .procname = "chroot_deny_mknod",
62748+ .data = &grsec_enable_chroot_mknod,
62749+ .maxlen = sizeof(int),
62750+ .mode = 0600,
62751+ .proc_handler = &proc_dointvec,
62752+ },
62753+#endif
62754+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62755+ {
62756+ .procname = "chroot_restrict_nice",
62757+ .data = &grsec_enable_chroot_nice,
62758+ .maxlen = sizeof(int),
62759+ .mode = 0600,
62760+ .proc_handler = &proc_dointvec,
62761+ },
62762+#endif
62763+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62764+ {
62765+ .procname = "chroot_execlog",
62766+ .data = &grsec_enable_chroot_execlog,
62767+ .maxlen = sizeof(int),
62768+ .mode = 0600,
62769+ .proc_handler = &proc_dointvec,
62770+ },
62771+#endif
62772+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62773+ {
62774+ .procname = "chroot_caps",
62775+ .data = &grsec_enable_chroot_caps,
62776+ .maxlen = sizeof(int),
62777+ .mode = 0600,
62778+ .proc_handler = &proc_dointvec,
62779+ },
62780+#endif
62781+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62782+ {
62783+ .procname = "chroot_deny_sysctl",
62784+ .data = &grsec_enable_chroot_sysctl,
62785+ .maxlen = sizeof(int),
62786+ .mode = 0600,
62787+ .proc_handler = &proc_dointvec,
62788+ },
62789+#endif
62790+#ifdef CONFIG_GRKERNSEC_TPE
62791+ {
62792+ .procname = "tpe",
62793+ .data = &grsec_enable_tpe,
62794+ .maxlen = sizeof(int),
62795+ .mode = 0600,
62796+ .proc_handler = &proc_dointvec,
62797+ },
62798+ {
62799+ .procname = "tpe_gid",
62800+ .data = &grsec_tpe_gid,
62801+ .maxlen = sizeof(int),
62802+ .mode = 0600,
62803+ .proc_handler = &proc_dointvec,
62804+ },
62805+#endif
62806+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62807+ {
62808+ .procname = "tpe_invert",
62809+ .data = &grsec_enable_tpe_invert,
62810+ .maxlen = sizeof(int),
62811+ .mode = 0600,
62812+ .proc_handler = &proc_dointvec,
62813+ },
62814+#endif
62815+#ifdef CONFIG_GRKERNSEC_TPE_ALL
62816+ {
62817+ .procname = "tpe_restrict_all",
62818+ .data = &grsec_enable_tpe_all,
62819+ .maxlen = sizeof(int),
62820+ .mode = 0600,
62821+ .proc_handler = &proc_dointvec,
62822+ },
62823+#endif
62824+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62825+ {
62826+ .procname = "socket_all",
62827+ .data = &grsec_enable_socket_all,
62828+ .maxlen = sizeof(int),
62829+ .mode = 0600,
62830+ .proc_handler = &proc_dointvec,
62831+ },
62832+ {
62833+ .procname = "socket_all_gid",
62834+ .data = &grsec_socket_all_gid,
62835+ .maxlen = sizeof(int),
62836+ .mode = 0600,
62837+ .proc_handler = &proc_dointvec,
62838+ },
62839+#endif
62840+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62841+ {
62842+ .procname = "socket_client",
62843+ .data = &grsec_enable_socket_client,
62844+ .maxlen = sizeof(int),
62845+ .mode = 0600,
62846+ .proc_handler = &proc_dointvec,
62847+ },
62848+ {
62849+ .procname = "socket_client_gid",
62850+ .data = &grsec_socket_client_gid,
62851+ .maxlen = sizeof(int),
62852+ .mode = 0600,
62853+ .proc_handler = &proc_dointvec,
62854+ },
62855+#endif
62856+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62857+ {
62858+ .procname = "socket_server",
62859+ .data = &grsec_enable_socket_server,
62860+ .maxlen = sizeof(int),
62861+ .mode = 0600,
62862+ .proc_handler = &proc_dointvec,
62863+ },
62864+ {
62865+ .procname = "socket_server_gid",
62866+ .data = &grsec_socket_server_gid,
62867+ .maxlen = sizeof(int),
62868+ .mode = 0600,
62869+ .proc_handler = &proc_dointvec,
62870+ },
62871+#endif
62872+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
62873+ {
62874+ .procname = "audit_group",
62875+ .data = &grsec_enable_group,
62876+ .maxlen = sizeof(int),
62877+ .mode = 0600,
62878+ .proc_handler = &proc_dointvec,
62879+ },
62880+ {
62881+ .procname = "audit_gid",
62882+ .data = &grsec_audit_gid,
62883+ .maxlen = sizeof(int),
62884+ .mode = 0600,
62885+ .proc_handler = &proc_dointvec,
62886+ },
62887+#endif
62888+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62889+ {
62890+ .procname = "audit_chdir",
62891+ .data = &grsec_enable_chdir,
62892+ .maxlen = sizeof(int),
62893+ .mode = 0600,
62894+ .proc_handler = &proc_dointvec,
62895+ },
62896+#endif
62897+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62898+ {
62899+ .procname = "audit_mount",
62900+ .data = &grsec_enable_mount,
62901+ .maxlen = sizeof(int),
62902+ .mode = 0600,
62903+ .proc_handler = &proc_dointvec,
62904+ },
62905+#endif
62906+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
62907+ {
62908+ .procname = "audit_textrel",
62909+ .data = &grsec_enable_audit_textrel,
62910+ .maxlen = sizeof(int),
62911+ .mode = 0600,
62912+ .proc_handler = &proc_dointvec,
62913+ },
62914+#endif
62915+#ifdef CONFIG_GRKERNSEC_DMESG
62916+ {
62917+ .procname = "dmesg",
62918+ .data = &grsec_enable_dmesg,
62919+ .maxlen = sizeof(int),
62920+ .mode = 0600,
62921+ .proc_handler = &proc_dointvec,
62922+ },
62923+#endif
62924+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62925+ {
62926+ .procname = "chroot_findtask",
62927+ .data = &grsec_enable_chroot_findtask,
62928+ .maxlen = sizeof(int),
62929+ .mode = 0600,
62930+ .proc_handler = &proc_dointvec,
62931+ },
62932+#endif
62933+#ifdef CONFIG_GRKERNSEC_RESLOG
62934+ {
62935+ .procname = "resource_logging",
62936+ .data = &grsec_resource_logging,
62937+ .maxlen = sizeof(int),
62938+ .mode = 0600,
62939+ .proc_handler = &proc_dointvec,
62940+ },
62941+#endif
62942+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
62943+ {
62944+ .procname = "audit_ptrace",
62945+ .data = &grsec_enable_audit_ptrace,
62946+ .maxlen = sizeof(int),
62947+ .mode = 0600,
62948+ .proc_handler = &proc_dointvec,
62949+ },
62950+#endif
62951+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62952+ {
62953+ .procname = "harden_ptrace",
62954+ .data = &grsec_enable_harden_ptrace,
62955+ .maxlen = sizeof(int),
62956+ .mode = 0600,
62957+ .proc_handler = &proc_dointvec,
62958+ },
62959+#endif
62960+ {
62961+ .procname = "grsec_lock",
62962+ .data = &grsec_lock,
62963+ .maxlen = sizeof(int),
62964+ .mode = 0600,
62965+ .proc_handler = &proc_dointvec,
62966+ },
62967+#endif
62968+#ifdef CONFIG_GRKERNSEC_ROFS
62969+ {
62970+ .procname = "romount_protect",
62971+ .data = &grsec_enable_rofs,
62972+ .maxlen = sizeof(int),
62973+ .mode = 0600,
62974+ .proc_handler = &proc_dointvec_minmax,
62975+ .extra1 = &one,
62976+ .extra2 = &one,
62977+ },
62978+#endif
62979+ { }
62980+};
62981+#endif
62982diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
62983new file mode 100644
62984index 0000000..0dc13c3
62985--- /dev/null
62986+++ b/grsecurity/grsec_time.c
62987@@ -0,0 +1,16 @@
62988+#include <linux/kernel.h>
62989+#include <linux/sched.h>
62990+#include <linux/grinternal.h>
62991+#include <linux/module.h>
62992+
62993+void
62994+gr_log_timechange(void)
62995+{
62996+#ifdef CONFIG_GRKERNSEC_TIME
62997+ if (grsec_enable_time)
62998+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
62999+#endif
63000+ return;
63001+}
63002+
63003+EXPORT_SYMBOL(gr_log_timechange);
63004diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
63005new file mode 100644
63006index 0000000..07e0dc0
63007--- /dev/null
63008+++ b/grsecurity/grsec_tpe.c
63009@@ -0,0 +1,73 @@
63010+#include <linux/kernel.h>
63011+#include <linux/sched.h>
63012+#include <linux/file.h>
63013+#include <linux/fs.h>
63014+#include <linux/grinternal.h>
63015+
63016+extern int gr_acl_tpe_check(void);
63017+
63018+int
63019+gr_tpe_allow(const struct file *file)
63020+{
63021+#ifdef CONFIG_GRKERNSEC
63022+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
63023+ const struct cred *cred = current_cred();
63024+ char *msg = NULL;
63025+ char *msg2 = NULL;
63026+
63027+ // never restrict root
63028+ if (!cred->uid)
63029+ return 1;
63030+
63031+ if (grsec_enable_tpe) {
63032+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
63033+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
63034+ msg = "not being in trusted group";
63035+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
63036+ msg = "being in untrusted group";
63037+#else
63038+ if (in_group_p(grsec_tpe_gid))
63039+ msg = "being in untrusted group";
63040+#endif
63041+ }
63042+ if (!msg && gr_acl_tpe_check())
63043+ msg = "being in untrusted role";
63044+
63045+ // not in any affected group/role
63046+ if (!msg)
63047+ goto next_check;
63048+
63049+ if (inode->i_uid)
63050+ msg2 = "file in non-root-owned directory";
63051+ else if (inode->i_mode & S_IWOTH)
63052+ msg2 = "file in world-writable directory";
63053+ else if (inode->i_mode & S_IWGRP)
63054+ msg2 = "file in group-writable directory";
63055+
63056+ if (msg && msg2) {
63057+ char fullmsg[70] = {0};
63058+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
63059+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
63060+ return 0;
63061+ }
63062+ msg = NULL;
63063+next_check:
63064+#ifdef CONFIG_GRKERNSEC_TPE_ALL
63065+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
63066+ return 1;
63067+
63068+ if (inode->i_uid && (inode->i_uid != cred->uid))
63069+ msg = "directory not owned by user";
63070+ else if (inode->i_mode & S_IWOTH)
63071+ msg = "file in world-writable directory";
63072+ else if (inode->i_mode & S_IWGRP)
63073+ msg = "file in group-writable directory";
63074+
63075+ if (msg) {
63076+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
63077+ return 0;
63078+ }
63079+#endif
63080+#endif
63081+ return 1;
63082+}
63083diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
63084new file mode 100644
63085index 0000000..9f7b1ac
63086--- /dev/null
63087+++ b/grsecurity/grsum.c
63088@@ -0,0 +1,61 @@
63089+#include <linux/err.h>
63090+#include <linux/kernel.h>
63091+#include <linux/sched.h>
63092+#include <linux/mm.h>
63093+#include <linux/scatterlist.h>
63094+#include <linux/crypto.h>
63095+#include <linux/gracl.h>
63096+
63097+
63098+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
63099+#error "crypto and sha256 must be built into the kernel"
63100+#endif
63101+
63102+int
63103+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
63104+{
63105+ char *p;
63106+ struct crypto_hash *tfm;
63107+ struct hash_desc desc;
63108+ struct scatterlist sg;
63109+ unsigned char temp_sum[GR_SHA_LEN];
63110+ volatile int retval = 0;
63111+ volatile int dummy = 0;
63112+ unsigned int i;
63113+
63114+ sg_init_table(&sg, 1);
63115+
63116+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
63117+ if (IS_ERR(tfm)) {
63118+ /* should never happen, since sha256 should be built in */
63119+ return 1;
63120+ }
63121+
63122+ desc.tfm = tfm;
63123+ desc.flags = 0;
63124+
63125+ crypto_hash_init(&desc);
63126+
63127+ p = salt;
63128+ sg_set_buf(&sg, p, GR_SALT_LEN);
63129+ crypto_hash_update(&desc, &sg, sg.length);
63130+
63131+ p = entry->pw;
63132+ sg_set_buf(&sg, p, strlen(p));
63133+
63134+ crypto_hash_update(&desc, &sg, sg.length);
63135+
63136+ crypto_hash_final(&desc, temp_sum);
63137+
63138+ memset(entry->pw, 0, GR_PW_LEN);
63139+
63140+ for (i = 0; i < GR_SHA_LEN; i++)
63141+ if (sum[i] != temp_sum[i])
63142+ retval = 1;
63143+ else
63144+ dummy = 1; // waste a cycle
63145+
63146+ crypto_free_hash(tfm);
63147+
63148+ return retval;
63149+}
63150diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
63151index 77ff547..181834f 100644
63152--- a/include/asm-generic/4level-fixup.h
63153+++ b/include/asm-generic/4level-fixup.h
63154@@ -13,8 +13,10 @@
63155 #define pmd_alloc(mm, pud, address) \
63156 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
63157 NULL: pmd_offset(pud, address))
63158+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
63159
63160 #define pud_alloc(mm, pgd, address) (pgd)
63161+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
63162 #define pud_offset(pgd, start) (pgd)
63163 #define pud_none(pud) 0
63164 #define pud_bad(pud) 0
63165diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
63166index b7babf0..04ad282 100644
63167--- a/include/asm-generic/atomic-long.h
63168+++ b/include/asm-generic/atomic-long.h
63169@@ -22,6 +22,12 @@
63170
63171 typedef atomic64_t atomic_long_t;
63172
63173+#ifdef CONFIG_PAX_REFCOUNT
63174+typedef atomic64_unchecked_t atomic_long_unchecked_t;
63175+#else
63176+typedef atomic64_t atomic_long_unchecked_t;
63177+#endif
63178+
63179 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
63180
63181 static inline long atomic_long_read(atomic_long_t *l)
63182@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
63183 return (long)atomic64_read(v);
63184 }
63185
63186+#ifdef CONFIG_PAX_REFCOUNT
63187+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
63188+{
63189+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63190+
63191+ return (long)atomic64_read_unchecked(v);
63192+}
63193+#endif
63194+
63195 static inline void atomic_long_set(atomic_long_t *l, long i)
63196 {
63197 atomic64_t *v = (atomic64_t *)l;
63198@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
63199 atomic64_set(v, i);
63200 }
63201
63202+#ifdef CONFIG_PAX_REFCOUNT
63203+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
63204+{
63205+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63206+
63207+ atomic64_set_unchecked(v, i);
63208+}
63209+#endif
63210+
63211 static inline void atomic_long_inc(atomic_long_t *l)
63212 {
63213 atomic64_t *v = (atomic64_t *)l;
63214@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
63215 atomic64_inc(v);
63216 }
63217
63218+#ifdef CONFIG_PAX_REFCOUNT
63219+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
63220+{
63221+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63222+
63223+ atomic64_inc_unchecked(v);
63224+}
63225+#endif
63226+
63227 static inline void atomic_long_dec(atomic_long_t *l)
63228 {
63229 atomic64_t *v = (atomic64_t *)l;
63230@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
63231 atomic64_dec(v);
63232 }
63233
63234+#ifdef CONFIG_PAX_REFCOUNT
63235+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
63236+{
63237+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63238+
63239+ atomic64_dec_unchecked(v);
63240+}
63241+#endif
63242+
63243 static inline void atomic_long_add(long i, atomic_long_t *l)
63244 {
63245 atomic64_t *v = (atomic64_t *)l;
63246@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
63247 atomic64_add(i, v);
63248 }
63249
63250+#ifdef CONFIG_PAX_REFCOUNT
63251+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
63252+{
63253+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63254+
63255+ atomic64_add_unchecked(i, v);
63256+}
63257+#endif
63258+
63259 static inline void atomic_long_sub(long i, atomic_long_t *l)
63260 {
63261 atomic64_t *v = (atomic64_t *)l;
63262@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
63263 atomic64_sub(i, v);
63264 }
63265
63266+#ifdef CONFIG_PAX_REFCOUNT
63267+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
63268+{
63269+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63270+
63271+ atomic64_sub_unchecked(i, v);
63272+}
63273+#endif
63274+
63275 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
63276 {
63277 atomic64_t *v = (atomic64_t *)l;
63278@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
63279 return (long)atomic64_add_return(i, v);
63280 }
63281
63282+#ifdef CONFIG_PAX_REFCOUNT
63283+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
63284+{
63285+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63286+
63287+ return (long)atomic64_add_return_unchecked(i, v);
63288+}
63289+#endif
63290+
63291 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
63292 {
63293 atomic64_t *v = (atomic64_t *)l;
63294@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
63295 return (long)atomic64_inc_return(v);
63296 }
63297
63298+#ifdef CONFIG_PAX_REFCOUNT
63299+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
63300+{
63301+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63302+
63303+ return (long)atomic64_inc_return_unchecked(v);
63304+}
63305+#endif
63306+
63307 static inline long atomic_long_dec_return(atomic_long_t *l)
63308 {
63309 atomic64_t *v = (atomic64_t *)l;
63310@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
63311
63312 typedef atomic_t atomic_long_t;
63313
63314+#ifdef CONFIG_PAX_REFCOUNT
63315+typedef atomic_unchecked_t atomic_long_unchecked_t;
63316+#else
63317+typedef atomic_t atomic_long_unchecked_t;
63318+#endif
63319+
63320 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
63321 static inline long atomic_long_read(atomic_long_t *l)
63322 {
63323@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
63324 return (long)atomic_read(v);
63325 }
63326
63327+#ifdef CONFIG_PAX_REFCOUNT
63328+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
63329+{
63330+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63331+
63332+ return (long)atomic_read_unchecked(v);
63333+}
63334+#endif
63335+
63336 static inline void atomic_long_set(atomic_long_t *l, long i)
63337 {
63338 atomic_t *v = (atomic_t *)l;
63339@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
63340 atomic_set(v, i);
63341 }
63342
63343+#ifdef CONFIG_PAX_REFCOUNT
63344+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
63345+{
63346+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63347+
63348+ atomic_set_unchecked(v, i);
63349+}
63350+#endif
63351+
63352 static inline void atomic_long_inc(atomic_long_t *l)
63353 {
63354 atomic_t *v = (atomic_t *)l;
63355@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
63356 atomic_inc(v);
63357 }
63358
63359+#ifdef CONFIG_PAX_REFCOUNT
63360+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
63361+{
63362+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63363+
63364+ atomic_inc_unchecked(v);
63365+}
63366+#endif
63367+
63368 static inline void atomic_long_dec(atomic_long_t *l)
63369 {
63370 atomic_t *v = (atomic_t *)l;
63371@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
63372 atomic_dec(v);
63373 }
63374
63375+#ifdef CONFIG_PAX_REFCOUNT
63376+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
63377+{
63378+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63379+
63380+ atomic_dec_unchecked(v);
63381+}
63382+#endif
63383+
63384 static inline void atomic_long_add(long i, atomic_long_t *l)
63385 {
63386 atomic_t *v = (atomic_t *)l;
63387@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
63388 atomic_add(i, v);
63389 }
63390
63391+#ifdef CONFIG_PAX_REFCOUNT
63392+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
63393+{
63394+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63395+
63396+ atomic_add_unchecked(i, v);
63397+}
63398+#endif
63399+
63400 static inline void atomic_long_sub(long i, atomic_long_t *l)
63401 {
63402 atomic_t *v = (atomic_t *)l;
63403@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
63404 atomic_sub(i, v);
63405 }
63406
63407+#ifdef CONFIG_PAX_REFCOUNT
63408+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
63409+{
63410+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63411+
63412+ atomic_sub_unchecked(i, v);
63413+}
63414+#endif
63415+
63416 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
63417 {
63418 atomic_t *v = (atomic_t *)l;
63419@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
63420 return (long)atomic_add_return(i, v);
63421 }
63422
63423+#ifdef CONFIG_PAX_REFCOUNT
63424+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
63425+{
63426+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63427+
63428+ return (long)atomic_add_return_unchecked(i, v);
63429+}
63430+
63431+#endif
63432+
63433 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
63434 {
63435 atomic_t *v = (atomic_t *)l;
63436@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
63437 return (long)atomic_inc_return(v);
63438 }
63439
63440+#ifdef CONFIG_PAX_REFCOUNT
63441+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
63442+{
63443+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63444+
63445+ return (long)atomic_inc_return_unchecked(v);
63446+}
63447+#endif
63448+
63449 static inline long atomic_long_dec_return(atomic_long_t *l)
63450 {
63451 atomic_t *v = (atomic_t *)l;
63452@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
63453
63454 #endif /* BITS_PER_LONG == 64 */
63455
63456+#ifdef CONFIG_PAX_REFCOUNT
63457+static inline void pax_refcount_needs_these_functions(void)
63458+{
63459+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
63460+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
63461+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
63462+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
63463+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
63464+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
63465+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
63466+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
63467+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
63468+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
63469+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
63470+#ifdef CONFIG_X86
63471+ atomic_clear_mask_unchecked(0, NULL);
63472+ atomic_set_mask_unchecked(0, NULL);
63473+#endif
63474+
63475+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
63476+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
63477+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
63478+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
63479+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
63480+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
63481+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
63482+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
63483+}
63484+#else
63485+#define atomic_read_unchecked(v) atomic_read(v)
63486+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
63487+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
63488+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
63489+#define atomic_inc_unchecked(v) atomic_inc(v)
63490+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
63491+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
63492+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
63493+#define atomic_dec_unchecked(v) atomic_dec(v)
63494+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
63495+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
63496+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
63497+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
63498+
63499+#define atomic_long_read_unchecked(v) atomic_long_read(v)
63500+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
63501+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
63502+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
63503+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
63504+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
63505+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
63506+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
63507+#endif
63508+
63509 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
63510diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
63511index 1ced641..c896ee8 100644
63512--- a/include/asm-generic/atomic.h
63513+++ b/include/asm-generic/atomic.h
63514@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
63515 * Atomically clears the bits set in @mask from @v
63516 */
63517 #ifndef atomic_clear_mask
63518-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
63519+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
63520 {
63521 unsigned long flags;
63522
63523diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
63524index b18ce4f..2ee2843 100644
63525--- a/include/asm-generic/atomic64.h
63526+++ b/include/asm-generic/atomic64.h
63527@@ -16,6 +16,8 @@ typedef struct {
63528 long long counter;
63529 } atomic64_t;
63530
63531+typedef atomic64_t atomic64_unchecked_t;
63532+
63533 #define ATOMIC64_INIT(i) { (i) }
63534
63535 extern long long atomic64_read(const atomic64_t *v);
63536@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
63537 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
63538 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
63539
63540+#define atomic64_read_unchecked(v) atomic64_read(v)
63541+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
63542+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
63543+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
63544+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
63545+#define atomic64_inc_unchecked(v) atomic64_inc(v)
63546+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
63547+#define atomic64_dec_unchecked(v) atomic64_dec(v)
63548+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
63549+
63550 #endif /* _ASM_GENERIC_ATOMIC64_H */
63551diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
63552index 1bfcfe5..e04c5c9 100644
63553--- a/include/asm-generic/cache.h
63554+++ b/include/asm-generic/cache.h
63555@@ -6,7 +6,7 @@
63556 * cache lines need to provide their own cache.h.
63557 */
63558
63559-#define L1_CACHE_SHIFT 5
63560-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
63561+#define L1_CACHE_SHIFT 5UL
63562+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
63563
63564 #endif /* __ASM_GENERIC_CACHE_H */
63565diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
63566index 0d68a1e..b74a761 100644
63567--- a/include/asm-generic/emergency-restart.h
63568+++ b/include/asm-generic/emergency-restart.h
63569@@ -1,7 +1,7 @@
63570 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
63571 #define _ASM_GENERIC_EMERGENCY_RESTART_H
63572
63573-static inline void machine_emergency_restart(void)
63574+static inline __noreturn void machine_emergency_restart(void)
63575 {
63576 machine_restart(NULL);
63577 }
63578diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
63579index 90f99c7..00ce236 100644
63580--- a/include/asm-generic/kmap_types.h
63581+++ b/include/asm-generic/kmap_types.h
63582@@ -2,9 +2,9 @@
63583 #define _ASM_GENERIC_KMAP_TYPES_H
63584
63585 #ifdef __WITH_KM_FENCE
63586-# define KM_TYPE_NR 41
63587+# define KM_TYPE_NR 42
63588 #else
63589-# define KM_TYPE_NR 20
63590+# define KM_TYPE_NR 21
63591 #endif
63592
63593 #endif
63594diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
63595index 9ceb03b..62b0b8f 100644
63596--- a/include/asm-generic/local.h
63597+++ b/include/asm-generic/local.h
63598@@ -23,24 +23,37 @@ typedef struct
63599 atomic_long_t a;
63600 } local_t;
63601
63602+typedef struct {
63603+ atomic_long_unchecked_t a;
63604+} local_unchecked_t;
63605+
63606 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
63607
63608 #define local_read(l) atomic_long_read(&(l)->a)
63609+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
63610 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
63611+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
63612 #define local_inc(l) atomic_long_inc(&(l)->a)
63613+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
63614 #define local_dec(l) atomic_long_dec(&(l)->a)
63615+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
63616 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
63617+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
63618 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
63619+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
63620
63621 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
63622 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
63623 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
63624 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
63625 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
63626+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
63627 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
63628 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
63629+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
63630
63631 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
63632+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
63633 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
63634 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
63635 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
63636diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
63637index 725612b..9cc513a 100644
63638--- a/include/asm-generic/pgtable-nopmd.h
63639+++ b/include/asm-generic/pgtable-nopmd.h
63640@@ -1,14 +1,19 @@
63641 #ifndef _PGTABLE_NOPMD_H
63642 #define _PGTABLE_NOPMD_H
63643
63644-#ifndef __ASSEMBLY__
63645-
63646 #include <asm-generic/pgtable-nopud.h>
63647
63648-struct mm_struct;
63649-
63650 #define __PAGETABLE_PMD_FOLDED
63651
63652+#define PMD_SHIFT PUD_SHIFT
63653+#define PTRS_PER_PMD 1
63654+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
63655+#define PMD_MASK (~(PMD_SIZE-1))
63656+
63657+#ifndef __ASSEMBLY__
63658+
63659+struct mm_struct;
63660+
63661 /*
63662 * Having the pmd type consist of a pud gets the size right, and allows
63663 * us to conceptually access the pud entry that this pmd is folded into
63664@@ -16,11 +21,6 @@ struct mm_struct;
63665 */
63666 typedef struct { pud_t pud; } pmd_t;
63667
63668-#define PMD_SHIFT PUD_SHIFT
63669-#define PTRS_PER_PMD 1
63670-#define PMD_SIZE (1UL << PMD_SHIFT)
63671-#define PMD_MASK (~(PMD_SIZE-1))
63672-
63673 /*
63674 * The "pud_xxx()" functions here are trivial for a folded two-level
63675 * setup: the pmd is never bad, and a pmd always exists (as it's folded
63676diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
63677index 810431d..0ec4804f 100644
63678--- a/include/asm-generic/pgtable-nopud.h
63679+++ b/include/asm-generic/pgtable-nopud.h
63680@@ -1,10 +1,15 @@
63681 #ifndef _PGTABLE_NOPUD_H
63682 #define _PGTABLE_NOPUD_H
63683
63684-#ifndef __ASSEMBLY__
63685-
63686 #define __PAGETABLE_PUD_FOLDED
63687
63688+#define PUD_SHIFT PGDIR_SHIFT
63689+#define PTRS_PER_PUD 1
63690+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
63691+#define PUD_MASK (~(PUD_SIZE-1))
63692+
63693+#ifndef __ASSEMBLY__
63694+
63695 /*
63696 * Having the pud type consist of a pgd gets the size right, and allows
63697 * us to conceptually access the pgd entry that this pud is folded into
63698@@ -12,11 +17,6 @@
63699 */
63700 typedef struct { pgd_t pgd; } pud_t;
63701
63702-#define PUD_SHIFT PGDIR_SHIFT
63703-#define PTRS_PER_PUD 1
63704-#define PUD_SIZE (1UL << PUD_SHIFT)
63705-#define PUD_MASK (~(PUD_SIZE-1))
63706-
63707 /*
63708 * The "pgd_xxx()" functions here are trivial for a folded two-level
63709 * setup: the pud is never bad, and a pud always exists (as it's folded
63710@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
63711 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
63712
63713 #define pgd_populate(mm, pgd, pud) do { } while (0)
63714+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
63715 /*
63716 * (puds are folded into pgds so this doesn't get actually called,
63717 * but the define is needed for a generic inline function.)
63718diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
63719index 5cf680a..4b74d62 100644
63720--- a/include/asm-generic/pgtable.h
63721+++ b/include/asm-generic/pgtable.h
63722@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
63723 }
63724 #endif /* CONFIG_NUMA_BALANCING */
63725
63726+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
63727+static inline unsigned long pax_open_kernel(void) { return 0; }
63728+#endif
63729+
63730+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
63731+static inline unsigned long pax_close_kernel(void) { return 0; }
63732+#endif
63733+
63734 #endif /* CONFIG_MMU */
63735
63736 #endif /* !__ASSEMBLY__ */
63737diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
63738index d1ea7ce..b1ebf2a 100644
63739--- a/include/asm-generic/vmlinux.lds.h
63740+++ b/include/asm-generic/vmlinux.lds.h
63741@@ -218,6 +218,7 @@
63742 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
63743 VMLINUX_SYMBOL(__start_rodata) = .; \
63744 *(.rodata) *(.rodata.*) \
63745+ *(.data..read_only) \
63746 *(__vermagic) /* Kernel version magic */ \
63747 . = ALIGN(8); \
63748 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
63749@@ -725,17 +726,18 @@
63750 * section in the linker script will go there too. @phdr should have
63751 * a leading colon.
63752 *
63753- * Note that this macros defines __per_cpu_load as an absolute symbol.
63754+ * Note that this macros defines per_cpu_load as an absolute symbol.
63755 * If there is no need to put the percpu section at a predetermined
63756 * address, use PERCPU_SECTION.
63757 */
63758 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
63759- VMLINUX_SYMBOL(__per_cpu_load) = .; \
63760- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
63761+ per_cpu_load = .; \
63762+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
63763 - LOAD_OFFSET) { \
63764+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
63765 PERCPU_INPUT(cacheline) \
63766 } phdr \
63767- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
63768+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
63769
63770 /**
63771 * PERCPU_SECTION - define output section for percpu area, simple version
63772diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
63773index 418d270..bfd2794 100644
63774--- a/include/crypto/algapi.h
63775+++ b/include/crypto/algapi.h
63776@@ -34,7 +34,7 @@ struct crypto_type {
63777 unsigned int maskclear;
63778 unsigned int maskset;
63779 unsigned int tfmsize;
63780-};
63781+} __do_const;
63782
63783 struct crypto_instance {
63784 struct crypto_alg alg;
63785diff --git a/include/drm/drmP.h b/include/drm/drmP.h
63786index fad21c9..3fff955 100644
63787--- a/include/drm/drmP.h
63788+++ b/include/drm/drmP.h
63789@@ -72,6 +72,7 @@
63790 #include <linux/workqueue.h>
63791 #include <linux/poll.h>
63792 #include <asm/pgalloc.h>
63793+#include <asm/local.h>
63794 #include <drm/drm.h>
63795 #include <drm/drm_sarea.h>
63796
63797@@ -1068,7 +1069,7 @@ struct drm_device {
63798
63799 /** \name Usage Counters */
63800 /*@{ */
63801- int open_count; /**< Outstanding files open */
63802+ local_t open_count; /**< Outstanding files open */
63803 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
63804 atomic_t vma_count; /**< Outstanding vma areas open */
63805 int buf_use; /**< Buffers in use -- cannot alloc */
63806@@ -1079,7 +1080,7 @@ struct drm_device {
63807 /*@{ */
63808 unsigned long counters;
63809 enum drm_stat_type types[15];
63810- atomic_t counts[15];
63811+ atomic_unchecked_t counts[15];
63812 /*@} */
63813
63814 struct list_head filelist;
63815diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
63816index f43d556..94d9343 100644
63817--- a/include/drm/drm_crtc_helper.h
63818+++ b/include/drm/drm_crtc_helper.h
63819@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
63820 struct drm_connector *connector);
63821 /* disable encoder when not in use - more explicit than dpms off */
63822 void (*disable)(struct drm_encoder *encoder);
63823-};
63824+} __no_const;
63825
63826 /**
63827 * drm_connector_helper_funcs - helper operations for connectors
63828diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
63829index 72dcbe8..8db58d7 100644
63830--- a/include/drm/ttm/ttm_memory.h
63831+++ b/include/drm/ttm/ttm_memory.h
63832@@ -48,7 +48,7 @@
63833
63834 struct ttm_mem_shrink {
63835 int (*do_shrink) (struct ttm_mem_shrink *);
63836-};
63837+} __no_const;
63838
63839 /**
63840 * struct ttm_mem_global - Global memory accounting structure.
63841diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
63842index c1da539..4db35ec 100644
63843--- a/include/linux/atmdev.h
63844+++ b/include/linux/atmdev.h
63845@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
63846 #endif
63847
63848 struct k_atm_aal_stats {
63849-#define __HANDLE_ITEM(i) atomic_t i
63850+#define __HANDLE_ITEM(i) atomic_unchecked_t i
63851 __AAL_STAT_ITEMS
63852 #undef __HANDLE_ITEM
63853 };
63854diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
63855index 0530b98..b127a9e 100644
63856--- a/include/linux/binfmts.h
63857+++ b/include/linux/binfmts.h
63858@@ -73,6 +73,7 @@ struct linux_binfmt {
63859 int (*load_binary)(struct linux_binprm *);
63860 int (*load_shlib)(struct file *);
63861 int (*core_dump)(struct coredump_params *cprm);
63862+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
63863 unsigned long min_coredump; /* minimal dump size */
63864 };
63865
63866diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
63867index f94bc83..62b9cfe 100644
63868--- a/include/linux/blkdev.h
63869+++ b/include/linux/blkdev.h
63870@@ -1498,7 +1498,7 @@ struct block_device_operations {
63871 /* this callback is with swap_lock and sometimes page table lock held */
63872 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
63873 struct module *owner;
63874-};
63875+} __do_const;
63876
63877 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
63878 unsigned long);
63879diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
63880index 7c2e030..b72475d 100644
63881--- a/include/linux/blktrace_api.h
63882+++ b/include/linux/blktrace_api.h
63883@@ -23,7 +23,7 @@ struct blk_trace {
63884 struct dentry *dir;
63885 struct dentry *dropped_file;
63886 struct dentry *msg_file;
63887- atomic_t dropped;
63888+ atomic_unchecked_t dropped;
63889 };
63890
63891 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
63892diff --git a/include/linux/cache.h b/include/linux/cache.h
63893index 4c57065..4307975 100644
63894--- a/include/linux/cache.h
63895+++ b/include/linux/cache.h
63896@@ -16,6 +16,10 @@
63897 #define __read_mostly
63898 #endif
63899
63900+#ifndef __read_only
63901+#define __read_only __read_mostly
63902+#endif
63903+
63904 #ifndef ____cacheline_aligned
63905 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
63906 #endif
63907diff --git a/include/linux/capability.h b/include/linux/capability.h
63908index 98503b7..cc36d18 100644
63909--- a/include/linux/capability.h
63910+++ b/include/linux/capability.h
63911@@ -211,8 +211,13 @@ extern bool capable(int cap);
63912 extern bool ns_capable(struct user_namespace *ns, int cap);
63913 extern bool nsown_capable(int cap);
63914 extern bool inode_capable(const struct inode *inode, int cap);
63915+extern bool capable_nolog(int cap);
63916+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
63917+extern bool inode_capable_nolog(const struct inode *inode, int cap);
63918
63919 /* audit system wants to get cap info from files as well */
63920 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
63921
63922+extern int is_privileged_binary(const struct dentry *dentry);
63923+
63924 #endif /* !_LINUX_CAPABILITY_H */
63925diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
63926index 8609d57..86e4d79 100644
63927--- a/include/linux/cdrom.h
63928+++ b/include/linux/cdrom.h
63929@@ -87,7 +87,6 @@ struct cdrom_device_ops {
63930
63931 /* driver specifications */
63932 const int capability; /* capability flags */
63933- int n_minors; /* number of active minor devices */
63934 /* handle uniform packets for scsi type devices (scsi,atapi) */
63935 int (*generic_packet) (struct cdrom_device_info *,
63936 struct packet_command *);
63937diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
63938index 42e55de..1cd0e66 100644
63939--- a/include/linux/cleancache.h
63940+++ b/include/linux/cleancache.h
63941@@ -31,7 +31,7 @@ struct cleancache_ops {
63942 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
63943 void (*invalidate_inode)(int, struct cleancache_filekey);
63944 void (*invalidate_fs)(int);
63945-};
63946+} __no_const;
63947
63948 extern struct cleancache_ops
63949 cleancache_register_ops(struct cleancache_ops *ops);
63950diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
63951index 662fd1b..e801992 100644
63952--- a/include/linux/compiler-gcc4.h
63953+++ b/include/linux/compiler-gcc4.h
63954@@ -34,6 +34,21 @@
63955 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
63956
63957 #if __GNUC_MINOR__ >= 5
63958+
63959+#ifdef CONSTIFY_PLUGIN
63960+#define __no_const __attribute__((no_const))
63961+#define __do_const __attribute__((do_const))
63962+#endif
63963+
63964+#ifdef SIZE_OVERFLOW_PLUGIN
63965+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
63966+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
63967+#endif
63968+
63969+#ifdef LATENT_ENTROPY_PLUGIN
63970+#define __latent_entropy __attribute__((latent_entropy))
63971+#endif
63972+
63973 /*
63974 * Mark a position in code as unreachable. This can be used to
63975 * suppress control flow warnings after asm blocks that transfer
63976@@ -49,6 +64,11 @@
63977 #define __noclone __attribute__((__noclone__))
63978
63979 #endif
63980+
63981+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
63982+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
63983+#define __bos0(ptr) __bos((ptr), 0)
63984+#define __bos1(ptr) __bos((ptr), 1)
63985 #endif
63986
63987 #if __GNUC_MINOR__ >= 6
63988diff --git a/include/linux/compiler.h b/include/linux/compiler.h
63989index dd852b7..72924c0 100644
63990--- a/include/linux/compiler.h
63991+++ b/include/linux/compiler.h
63992@@ -5,11 +5,14 @@
63993
63994 #ifdef __CHECKER__
63995 # define __user __attribute__((noderef, address_space(1)))
63996+# define __force_user __force __user
63997 # define __kernel __attribute__((address_space(0)))
63998+# define __force_kernel __force __kernel
63999 # define __safe __attribute__((safe))
64000 # define __force __attribute__((force))
64001 # define __nocast __attribute__((nocast))
64002 # define __iomem __attribute__((noderef, address_space(2)))
64003+# define __force_iomem __force __iomem
64004 # define __must_hold(x) __attribute__((context(x,1,1)))
64005 # define __acquires(x) __attribute__((context(x,0,1)))
64006 # define __releases(x) __attribute__((context(x,1,0)))
64007@@ -17,20 +20,48 @@
64008 # define __release(x) __context__(x,-1)
64009 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
64010 # define __percpu __attribute__((noderef, address_space(3)))
64011+# define __force_percpu __force __percpu
64012 #ifdef CONFIG_SPARSE_RCU_POINTER
64013 # define __rcu __attribute__((noderef, address_space(4)))
64014+# define __force_rcu __force __rcu
64015 #else
64016 # define __rcu
64017+# define __force_rcu
64018 #endif
64019 extern void __chk_user_ptr(const volatile void __user *);
64020 extern void __chk_io_ptr(const volatile void __iomem *);
64021+#elif defined(CHECKER_PLUGIN)
64022+//# define __user
64023+//# define __force_user
64024+//# define __kernel
64025+//# define __force_kernel
64026+# define __safe
64027+# define __force
64028+# define __nocast
64029+# define __iomem
64030+# define __force_iomem
64031+# define __chk_user_ptr(x) (void)0
64032+# define __chk_io_ptr(x) (void)0
64033+# define __builtin_warning(x, y...) (1)
64034+# define __acquires(x)
64035+# define __releases(x)
64036+# define __acquire(x) (void)0
64037+# define __release(x) (void)0
64038+# define __cond_lock(x,c) (c)
64039+# define __percpu
64040+# define __force_percpu
64041+# define __rcu
64042+# define __force_rcu
64043 #else
64044 # define __user
64045+# define __force_user
64046 # define __kernel
64047+# define __force_kernel
64048 # define __safe
64049 # define __force
64050 # define __nocast
64051 # define __iomem
64052+# define __force_iomem
64053 # define __chk_user_ptr(x) (void)0
64054 # define __chk_io_ptr(x) (void)0
64055 # define __builtin_warning(x, y...) (1)
64056@@ -41,7 +72,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
64057 # define __release(x) (void)0
64058 # define __cond_lock(x,c) (c)
64059 # define __percpu
64060+# define __force_percpu
64061 # define __rcu
64062+# define __force_rcu
64063 #endif
64064
64065 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
64066@@ -275,6 +308,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64067 # define __attribute_const__ /* unimplemented */
64068 #endif
64069
64070+#ifndef __no_const
64071+# define __no_const
64072+#endif
64073+
64074+#ifndef __do_const
64075+# define __do_const
64076+#endif
64077+
64078+#ifndef __size_overflow
64079+# define __size_overflow(...)
64080+#endif
64081+
64082+#ifndef __intentional_overflow
64083+# define __intentional_overflow(...)
64084+#endif
64085+
64086+#ifndef __latent_entropy
64087+# define __latent_entropy
64088+#endif
64089+
64090 /*
64091 * Tell gcc if a function is cold. The compiler will assume any path
64092 * directly leading to the call is unlikely.
64093@@ -284,6 +337,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64094 #define __cold
64095 #endif
64096
64097+#ifndef __alloc_size
64098+#define __alloc_size(...)
64099+#endif
64100+
64101+#ifndef __bos
64102+#define __bos(ptr, arg)
64103+#endif
64104+
64105+#ifndef __bos0
64106+#define __bos0(ptr)
64107+#endif
64108+
64109+#ifndef __bos1
64110+#define __bos1(ptr)
64111+#endif
64112+
64113 /* Simple shorthand for a section definition */
64114 #ifndef __section
64115 # define __section(S) __attribute__ ((__section__(#S)))
64116@@ -323,6 +392,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64117 * use is to mediate communication between process-level code and irq/NMI
64118 * handlers, all running on the same CPU.
64119 */
64120-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
64121+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
64122+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
64123
64124 #endif /* __LINUX_COMPILER_H */
64125diff --git a/include/linux/cpu.h b/include/linux/cpu.h
64126index ce7a074..01ab8ac 100644
64127--- a/include/linux/cpu.h
64128+++ b/include/linux/cpu.h
64129@@ -115,7 +115,7 @@ enum {
64130 /* Need to know about CPUs going up/down? */
64131 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
64132 #define cpu_notifier(fn, pri) { \
64133- static struct notifier_block fn##_nb __cpuinitdata = \
64134+ static struct notifier_block fn##_nb = \
64135 { .notifier_call = fn, .priority = pri }; \
64136 register_cpu_notifier(&fn##_nb); \
64137 }
64138diff --git a/include/linux/cred.h b/include/linux/cred.h
64139index 04421e8..6bce4ef 100644
64140--- a/include/linux/cred.h
64141+++ b/include/linux/cred.h
64142@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
64143 static inline void validate_process_creds(void)
64144 {
64145 }
64146+static inline void validate_task_creds(struct task_struct *task)
64147+{
64148+}
64149 #endif
64150
64151 /**
64152diff --git a/include/linux/crypto.h b/include/linux/crypto.h
64153index b92eadf..b4ecdc1 100644
64154--- a/include/linux/crypto.h
64155+++ b/include/linux/crypto.h
64156@@ -373,7 +373,7 @@ struct cipher_tfm {
64157 const u8 *key, unsigned int keylen);
64158 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
64159 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
64160-};
64161+} __no_const;
64162
64163 struct hash_tfm {
64164 int (*init)(struct hash_desc *desc);
64165@@ -394,13 +394,13 @@ struct compress_tfm {
64166 int (*cot_decompress)(struct crypto_tfm *tfm,
64167 const u8 *src, unsigned int slen,
64168 u8 *dst, unsigned int *dlen);
64169-};
64170+} __no_const;
64171
64172 struct rng_tfm {
64173 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
64174 unsigned int dlen);
64175 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
64176-};
64177+} __no_const;
64178
64179 #define crt_ablkcipher crt_u.ablkcipher
64180 #define crt_aead crt_u.aead
64181diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
64182index 7925bf0..d5143d2 100644
64183--- a/include/linux/decompress/mm.h
64184+++ b/include/linux/decompress/mm.h
64185@@ -77,7 +77,7 @@ static void free(void *where)
64186 * warnings when not needed (indeed large_malloc / large_free are not
64187 * needed by inflate */
64188
64189-#define malloc(a) kmalloc(a, GFP_KERNEL)
64190+#define malloc(a) kmalloc((a), GFP_KERNEL)
64191 #define free(a) kfree(a)
64192
64193 #define large_malloc(a) vmalloc(a)
64194diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
64195index 94af418..b1ca7a2 100644
64196--- a/include/linux/dma-mapping.h
64197+++ b/include/linux/dma-mapping.h
64198@@ -54,7 +54,7 @@ struct dma_map_ops {
64199 u64 (*get_required_mask)(struct device *dev);
64200 #endif
64201 int is_phys;
64202-};
64203+} __do_const;
64204
64205 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
64206
64207diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
64208index d3201e4..8281e63 100644
64209--- a/include/linux/dmaengine.h
64210+++ b/include/linux/dmaengine.h
64211@@ -1018,9 +1018,9 @@ struct dma_pinned_list {
64212 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
64213 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
64214
64215-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
64216+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
64217 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
64218-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
64219+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
64220 struct dma_pinned_list *pinned_list, struct page *page,
64221 unsigned int offset, size_t len);
64222
64223diff --git a/include/linux/efi.h b/include/linux/efi.h
64224index 7a9498a..155713d 100644
64225--- a/include/linux/efi.h
64226+++ b/include/linux/efi.h
64227@@ -733,6 +733,7 @@ struct efivar_operations {
64228 efi_set_variable_t *set_variable;
64229 efi_query_variable_info_t *query_variable_info;
64230 };
64231+typedef struct efivar_operations __no_const efivar_operations_no_const;
64232
64233 struct efivars {
64234 /*
64235diff --git a/include/linux/elf.h b/include/linux/elf.h
64236index 8c9048e..16a4665 100644
64237--- a/include/linux/elf.h
64238+++ b/include/linux/elf.h
64239@@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
64240 #define elf_note elf32_note
64241 #define elf_addr_t Elf32_Off
64242 #define Elf_Half Elf32_Half
64243+#define elf_dyn Elf32_Dyn
64244
64245 #else
64246
64247@@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
64248 #define elf_note elf64_note
64249 #define elf_addr_t Elf64_Off
64250 #define Elf_Half Elf64_Half
64251+#define elf_dyn Elf64_Dyn
64252
64253 #endif
64254
64255diff --git a/include/linux/filter.h b/include/linux/filter.h
64256index c45eabc..baa0be5 100644
64257--- a/include/linux/filter.h
64258+++ b/include/linux/filter.h
64259@@ -20,6 +20,7 @@ struct compat_sock_fprog {
64260
64261 struct sk_buff;
64262 struct sock;
64263+struct bpf_jit_work;
64264
64265 struct sk_filter
64266 {
64267@@ -27,6 +28,9 @@ struct sk_filter
64268 unsigned int len; /* Number of filter blocks */
64269 unsigned int (*bpf_func)(const struct sk_buff *skb,
64270 const struct sock_filter *filter);
64271+#ifdef CONFIG_BPF_JIT
64272+ struct bpf_jit_work *work;
64273+#endif
64274 struct rcu_head rcu;
64275 struct sock_filter insns[0];
64276 };
64277diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
64278index 3044254..9767f41 100644
64279--- a/include/linux/frontswap.h
64280+++ b/include/linux/frontswap.h
64281@@ -11,7 +11,7 @@ struct frontswap_ops {
64282 int (*load)(unsigned, pgoff_t, struct page *);
64283 void (*invalidate_page)(unsigned, pgoff_t);
64284 void (*invalidate_area)(unsigned);
64285-};
64286+} __no_const;
64287
64288 extern bool frontswap_enabled;
64289 extern struct frontswap_ops
64290diff --git a/include/linux/fs.h b/include/linux/fs.h
64291index 7617ee0..b575199 100644
64292--- a/include/linux/fs.h
64293+++ b/include/linux/fs.h
64294@@ -1541,7 +1541,8 @@ struct file_operations {
64295 long (*fallocate)(struct file *file, int mode, loff_t offset,
64296 loff_t len);
64297 int (*show_fdinfo)(struct seq_file *m, struct file *f);
64298-};
64299+} __do_const;
64300+typedef struct file_operations __no_const file_operations_no_const;
64301
64302 struct inode_operations {
64303 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
64304@@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
64305 inode->i_flags |= S_NOSEC;
64306 }
64307
64308+static inline bool is_sidechannel_device(const struct inode *inode)
64309+{
64310+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
64311+ umode_t mode = inode->i_mode;
64312+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
64313+#else
64314+ return false;
64315+#endif
64316+}
64317+
64318 #endif /* _LINUX_FS_H */
64319diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
64320index d0ae3a8..0244b34 100644
64321--- a/include/linux/fs_struct.h
64322+++ b/include/linux/fs_struct.h
64323@@ -6,7 +6,7 @@
64324 #include <linux/seqlock.h>
64325
64326 struct fs_struct {
64327- int users;
64328+ atomic_t users;
64329 spinlock_t lock;
64330 seqcount_t seq;
64331 int umask;
64332diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
64333index 5dfa0aa..6acf322 100644
64334--- a/include/linux/fscache-cache.h
64335+++ b/include/linux/fscache-cache.h
64336@@ -112,7 +112,7 @@ struct fscache_operation {
64337 fscache_operation_release_t release;
64338 };
64339
64340-extern atomic_t fscache_op_debug_id;
64341+extern atomic_unchecked_t fscache_op_debug_id;
64342 extern void fscache_op_work_func(struct work_struct *work);
64343
64344 extern void fscache_enqueue_operation(struct fscache_operation *);
64345@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
64346 INIT_WORK(&op->work, fscache_op_work_func);
64347 atomic_set(&op->usage, 1);
64348 op->state = FSCACHE_OP_ST_INITIALISED;
64349- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
64350+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
64351 op->processor = processor;
64352 op->release = release;
64353 INIT_LIST_HEAD(&op->pend_link);
64354diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
64355index 0fbfb46..508eb0d 100644
64356--- a/include/linux/fsnotify.h
64357+++ b/include/linux/fsnotify.h
64358@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
64359 struct inode *inode = path->dentry->d_inode;
64360 __u32 mask = FS_ACCESS;
64361
64362+ if (is_sidechannel_device(inode))
64363+ return;
64364+
64365 if (S_ISDIR(inode->i_mode))
64366 mask |= FS_ISDIR;
64367
64368@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
64369 struct inode *inode = path->dentry->d_inode;
64370 __u32 mask = FS_MODIFY;
64371
64372+ if (is_sidechannel_device(inode))
64373+ return;
64374+
64375 if (S_ISDIR(inode->i_mode))
64376 mask |= FS_ISDIR;
64377
64378@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
64379 */
64380 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
64381 {
64382- return kstrdup(name, GFP_KERNEL);
64383+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
64384 }
64385
64386 /*
64387diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
64388index a3d4895..ddd2a50 100644
64389--- a/include/linux/ftrace_event.h
64390+++ b/include/linux/ftrace_event.h
64391@@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
64392 extern int trace_add_event_call(struct ftrace_event_call *call);
64393 extern void trace_remove_event_call(struct ftrace_event_call *call);
64394
64395-#define is_signed_type(type) (((type)(-1)) < 0)
64396+#define is_signed_type(type) (((type)(-1)) < (type)1)
64397
64398 int trace_set_clr_event(const char *system, const char *event, int set);
64399
64400diff --git a/include/linux/genhd.h b/include/linux/genhd.h
64401index 79b8bba..86b539e 100644
64402--- a/include/linux/genhd.h
64403+++ b/include/linux/genhd.h
64404@@ -194,7 +194,7 @@ struct gendisk {
64405 struct kobject *slave_dir;
64406
64407 struct timer_rand_state *random;
64408- atomic_t sync_io; /* RAID */
64409+ atomic_unchecked_t sync_io; /* RAID */
64410 struct disk_events *ev;
64411 #ifdef CONFIG_BLK_DEV_INTEGRITY
64412 struct blk_integrity *integrity;
64413diff --git a/include/linux/gfp.h b/include/linux/gfp.h
64414index 0f615eb..5c3832f 100644
64415--- a/include/linux/gfp.h
64416+++ b/include/linux/gfp.h
64417@@ -35,6 +35,13 @@ struct vm_area_struct;
64418 #define ___GFP_NO_KSWAPD 0x400000u
64419 #define ___GFP_OTHER_NODE 0x800000u
64420 #define ___GFP_WRITE 0x1000000u
64421+
64422+#ifdef CONFIG_PAX_USERCOPY_SLABS
64423+#define ___GFP_USERCOPY 0x2000000u
64424+#else
64425+#define ___GFP_USERCOPY 0
64426+#endif
64427+
64428 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
64429
64430 /*
64431@@ -92,6 +99,7 @@ struct vm_area_struct;
64432 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
64433 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
64434 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
64435+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
64436
64437 /*
64438 * This may seem redundant, but it's a way of annotating false positives vs.
64439@@ -99,7 +107,7 @@ struct vm_area_struct;
64440 */
64441 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
64442
64443-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
64444+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
64445 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
64446
64447 /* This equals 0, but use constants in case they ever change */
64448@@ -153,6 +161,8 @@ struct vm_area_struct;
64449 /* 4GB DMA on some platforms */
64450 #define GFP_DMA32 __GFP_DMA32
64451
64452+#define GFP_USERCOPY __GFP_USERCOPY
64453+
64454 /* Convert GFP flags to their corresponding migrate type */
64455 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
64456 {
64457diff --git a/include/linux/gracl.h b/include/linux/gracl.h
64458new file mode 100644
64459index 0000000..ebe6d72
64460--- /dev/null
64461+++ b/include/linux/gracl.h
64462@@ -0,0 +1,319 @@
64463+#ifndef GR_ACL_H
64464+#define GR_ACL_H
64465+
64466+#include <linux/grdefs.h>
64467+#include <linux/resource.h>
64468+#include <linux/capability.h>
64469+#include <linux/dcache.h>
64470+#include <asm/resource.h>
64471+
64472+/* Major status information */
64473+
64474+#define GR_VERSION "grsecurity 2.9.1"
64475+#define GRSECURITY_VERSION 0x2901
64476+
64477+enum {
64478+ GR_SHUTDOWN = 0,
64479+ GR_ENABLE = 1,
64480+ GR_SPROLE = 2,
64481+ GR_RELOAD = 3,
64482+ GR_SEGVMOD = 4,
64483+ GR_STATUS = 5,
64484+ GR_UNSPROLE = 6,
64485+ GR_PASSSET = 7,
64486+ GR_SPROLEPAM = 8,
64487+};
64488+
64489+/* Password setup definitions
64490+ * kernel/grhash.c */
64491+enum {
64492+ GR_PW_LEN = 128,
64493+ GR_SALT_LEN = 16,
64494+ GR_SHA_LEN = 32,
64495+};
64496+
64497+enum {
64498+ GR_SPROLE_LEN = 64,
64499+};
64500+
64501+enum {
64502+ GR_NO_GLOB = 0,
64503+ GR_REG_GLOB,
64504+ GR_CREATE_GLOB
64505+};
64506+
64507+#define GR_NLIMITS 32
64508+
64509+/* Begin Data Structures */
64510+
64511+struct sprole_pw {
64512+ unsigned char *rolename;
64513+ unsigned char salt[GR_SALT_LEN];
64514+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
64515+};
64516+
64517+struct name_entry {
64518+ __u32 key;
64519+ ino_t inode;
64520+ dev_t device;
64521+ char *name;
64522+ __u16 len;
64523+ __u8 deleted;
64524+ struct name_entry *prev;
64525+ struct name_entry *next;
64526+};
64527+
64528+struct inodev_entry {
64529+ struct name_entry *nentry;
64530+ struct inodev_entry *prev;
64531+ struct inodev_entry *next;
64532+};
64533+
64534+struct acl_role_db {
64535+ struct acl_role_label **r_hash;
64536+ __u32 r_size;
64537+};
64538+
64539+struct inodev_db {
64540+ struct inodev_entry **i_hash;
64541+ __u32 i_size;
64542+};
64543+
64544+struct name_db {
64545+ struct name_entry **n_hash;
64546+ __u32 n_size;
64547+};
64548+
64549+struct crash_uid {
64550+ uid_t uid;
64551+ unsigned long expires;
64552+};
64553+
64554+struct gr_hash_struct {
64555+ void **table;
64556+ void **nametable;
64557+ void *first;
64558+ __u32 table_size;
64559+ __u32 used_size;
64560+ int type;
64561+};
64562+
64563+/* Userspace Grsecurity ACL data structures */
64564+
64565+struct acl_subject_label {
64566+ char *filename;
64567+ ino_t inode;
64568+ dev_t device;
64569+ __u32 mode;
64570+ kernel_cap_t cap_mask;
64571+ kernel_cap_t cap_lower;
64572+ kernel_cap_t cap_invert_audit;
64573+
64574+ struct rlimit res[GR_NLIMITS];
64575+ __u32 resmask;
64576+
64577+ __u8 user_trans_type;
64578+ __u8 group_trans_type;
64579+ uid_t *user_transitions;
64580+ gid_t *group_transitions;
64581+ __u16 user_trans_num;
64582+ __u16 group_trans_num;
64583+
64584+ __u32 sock_families[2];
64585+ __u32 ip_proto[8];
64586+ __u32 ip_type;
64587+ struct acl_ip_label **ips;
64588+ __u32 ip_num;
64589+ __u32 inaddr_any_override;
64590+
64591+ __u32 crashes;
64592+ unsigned long expires;
64593+
64594+ struct acl_subject_label *parent_subject;
64595+ struct gr_hash_struct *hash;
64596+ struct acl_subject_label *prev;
64597+ struct acl_subject_label *next;
64598+
64599+ struct acl_object_label **obj_hash;
64600+ __u32 obj_hash_size;
64601+ __u16 pax_flags;
64602+};
64603+
64604+struct role_allowed_ip {
64605+ __u32 addr;
64606+ __u32 netmask;
64607+
64608+ struct role_allowed_ip *prev;
64609+ struct role_allowed_ip *next;
64610+};
64611+
64612+struct role_transition {
64613+ char *rolename;
64614+
64615+ struct role_transition *prev;
64616+ struct role_transition *next;
64617+};
64618+
64619+struct acl_role_label {
64620+ char *rolename;
64621+ uid_t uidgid;
64622+ __u16 roletype;
64623+
64624+ __u16 auth_attempts;
64625+ unsigned long expires;
64626+
64627+ struct acl_subject_label *root_label;
64628+ struct gr_hash_struct *hash;
64629+
64630+ struct acl_role_label *prev;
64631+ struct acl_role_label *next;
64632+
64633+ struct role_transition *transitions;
64634+ struct role_allowed_ip *allowed_ips;
64635+ uid_t *domain_children;
64636+ __u16 domain_child_num;
64637+
64638+ umode_t umask;
64639+
64640+ struct acl_subject_label **subj_hash;
64641+ __u32 subj_hash_size;
64642+};
64643+
64644+struct user_acl_role_db {
64645+ struct acl_role_label **r_table;
64646+ __u32 num_pointers; /* Number of allocations to track */
64647+ __u32 num_roles; /* Number of roles */
64648+ __u32 num_domain_children; /* Number of domain children */
64649+ __u32 num_subjects; /* Number of subjects */
64650+ __u32 num_objects; /* Number of objects */
64651+};
64652+
64653+struct acl_object_label {
64654+ char *filename;
64655+ ino_t inode;
64656+ dev_t device;
64657+ __u32 mode;
64658+
64659+ struct acl_subject_label *nested;
64660+ struct acl_object_label *globbed;
64661+
64662+ /* next two structures not used */
64663+
64664+ struct acl_object_label *prev;
64665+ struct acl_object_label *next;
64666+};
64667+
64668+struct acl_ip_label {
64669+ char *iface;
64670+ __u32 addr;
64671+ __u32 netmask;
64672+ __u16 low, high;
64673+ __u8 mode;
64674+ __u32 type;
64675+ __u32 proto[8];
64676+
64677+ /* next two structures not used */
64678+
64679+ struct acl_ip_label *prev;
64680+ struct acl_ip_label *next;
64681+};
64682+
64683+struct gr_arg {
64684+ struct user_acl_role_db role_db;
64685+ unsigned char pw[GR_PW_LEN];
64686+ unsigned char salt[GR_SALT_LEN];
64687+ unsigned char sum[GR_SHA_LEN];
64688+ unsigned char sp_role[GR_SPROLE_LEN];
64689+ struct sprole_pw *sprole_pws;
64690+ dev_t segv_device;
64691+ ino_t segv_inode;
64692+ uid_t segv_uid;
64693+ __u16 num_sprole_pws;
64694+ __u16 mode;
64695+};
64696+
64697+struct gr_arg_wrapper {
64698+ struct gr_arg *arg;
64699+ __u32 version;
64700+ __u32 size;
64701+};
64702+
64703+struct subject_map {
64704+ struct acl_subject_label *user;
64705+ struct acl_subject_label *kernel;
64706+ struct subject_map *prev;
64707+ struct subject_map *next;
64708+};
64709+
64710+struct acl_subj_map_db {
64711+ struct subject_map **s_hash;
64712+ __u32 s_size;
64713+};
64714+
64715+/* End Data Structures Section */
64716+
64717+/* Hash functions generated by empirical testing by Brad Spengler
64718+ Makes good use of the low bits of the inode. Generally 0-1 times
64719+ in loop for successful match. 0-3 for unsuccessful match.
64720+ Shift/add algorithm with modulus of table size and an XOR*/
64721+
64722+static __inline__ unsigned int
64723+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
64724+{
64725+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
64726+}
64727+
64728+ static __inline__ unsigned int
64729+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
64730+{
64731+ return ((const unsigned long)userp % sz);
64732+}
64733+
64734+static __inline__ unsigned int
64735+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
64736+{
64737+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
64738+}
64739+
64740+static __inline__ unsigned int
64741+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
64742+{
64743+ return full_name_hash((const unsigned char *)name, len) % sz;
64744+}
64745+
64746+#define FOR_EACH_ROLE_START(role) \
64747+ role = role_list; \
64748+ while (role) {
64749+
64750+#define FOR_EACH_ROLE_END(role) \
64751+ role = role->prev; \
64752+ }
64753+
64754+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
64755+ subj = NULL; \
64756+ iter = 0; \
64757+ while (iter < role->subj_hash_size) { \
64758+ if (subj == NULL) \
64759+ subj = role->subj_hash[iter]; \
64760+ if (subj == NULL) { \
64761+ iter++; \
64762+ continue; \
64763+ }
64764+
64765+#define FOR_EACH_SUBJECT_END(subj,iter) \
64766+ subj = subj->next; \
64767+ if (subj == NULL) \
64768+ iter++; \
64769+ }
64770+
64771+
64772+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
64773+ subj = role->hash->first; \
64774+ while (subj != NULL) {
64775+
64776+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
64777+ subj = subj->next; \
64778+ }
64779+
64780+#endif
64781+
64782diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
64783new file mode 100644
64784index 0000000..323ecf2
64785--- /dev/null
64786+++ b/include/linux/gralloc.h
64787@@ -0,0 +1,9 @@
64788+#ifndef __GRALLOC_H
64789+#define __GRALLOC_H
64790+
64791+void acl_free_all(void);
64792+int acl_alloc_stack_init(unsigned long size);
64793+void *acl_alloc(unsigned long len);
64794+void *acl_alloc_num(unsigned long num, unsigned long len);
64795+
64796+#endif
64797diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
64798new file mode 100644
64799index 0000000..be66033
64800--- /dev/null
64801+++ b/include/linux/grdefs.h
64802@@ -0,0 +1,140 @@
64803+#ifndef GRDEFS_H
64804+#define GRDEFS_H
64805+
64806+/* Begin grsecurity status declarations */
64807+
64808+enum {
64809+ GR_READY = 0x01,
64810+ GR_STATUS_INIT = 0x00 // disabled state
64811+};
64812+
64813+/* Begin ACL declarations */
64814+
64815+/* Role flags */
64816+
64817+enum {
64818+ GR_ROLE_USER = 0x0001,
64819+ GR_ROLE_GROUP = 0x0002,
64820+ GR_ROLE_DEFAULT = 0x0004,
64821+ GR_ROLE_SPECIAL = 0x0008,
64822+ GR_ROLE_AUTH = 0x0010,
64823+ GR_ROLE_NOPW = 0x0020,
64824+ GR_ROLE_GOD = 0x0040,
64825+ GR_ROLE_LEARN = 0x0080,
64826+ GR_ROLE_TPE = 0x0100,
64827+ GR_ROLE_DOMAIN = 0x0200,
64828+ GR_ROLE_PAM = 0x0400,
64829+ GR_ROLE_PERSIST = 0x0800
64830+};
64831+
64832+/* ACL Subject and Object mode flags */
64833+enum {
64834+ GR_DELETED = 0x80000000
64835+};
64836+
64837+/* ACL Object-only mode flags */
64838+enum {
64839+ GR_READ = 0x00000001,
64840+ GR_APPEND = 0x00000002,
64841+ GR_WRITE = 0x00000004,
64842+ GR_EXEC = 0x00000008,
64843+ GR_FIND = 0x00000010,
64844+ GR_INHERIT = 0x00000020,
64845+ GR_SETID = 0x00000040,
64846+ GR_CREATE = 0x00000080,
64847+ GR_DELETE = 0x00000100,
64848+ GR_LINK = 0x00000200,
64849+ GR_AUDIT_READ = 0x00000400,
64850+ GR_AUDIT_APPEND = 0x00000800,
64851+ GR_AUDIT_WRITE = 0x00001000,
64852+ GR_AUDIT_EXEC = 0x00002000,
64853+ GR_AUDIT_FIND = 0x00004000,
64854+ GR_AUDIT_INHERIT= 0x00008000,
64855+ GR_AUDIT_SETID = 0x00010000,
64856+ GR_AUDIT_CREATE = 0x00020000,
64857+ GR_AUDIT_DELETE = 0x00040000,
64858+ GR_AUDIT_LINK = 0x00080000,
64859+ GR_PTRACERD = 0x00100000,
64860+ GR_NOPTRACE = 0x00200000,
64861+ GR_SUPPRESS = 0x00400000,
64862+ GR_NOLEARN = 0x00800000,
64863+ GR_INIT_TRANSFER= 0x01000000
64864+};
64865+
64866+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
64867+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
64868+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
64869+
64870+/* ACL subject-only mode flags */
64871+enum {
64872+ GR_KILL = 0x00000001,
64873+ GR_VIEW = 0x00000002,
64874+ GR_PROTECTED = 0x00000004,
64875+ GR_LEARN = 0x00000008,
64876+ GR_OVERRIDE = 0x00000010,
64877+ /* just a placeholder, this mode is only used in userspace */
64878+ GR_DUMMY = 0x00000020,
64879+ GR_PROTSHM = 0x00000040,
64880+ GR_KILLPROC = 0x00000080,
64881+ GR_KILLIPPROC = 0x00000100,
64882+ /* just a placeholder, this mode is only used in userspace */
64883+ GR_NOTROJAN = 0x00000200,
64884+ GR_PROTPROCFD = 0x00000400,
64885+ GR_PROCACCT = 0x00000800,
64886+ GR_RELAXPTRACE = 0x00001000,
64887+ //GR_NESTED = 0x00002000,
64888+ GR_INHERITLEARN = 0x00004000,
64889+ GR_PROCFIND = 0x00008000,
64890+ GR_POVERRIDE = 0x00010000,
64891+ GR_KERNELAUTH = 0x00020000,
64892+ GR_ATSECURE = 0x00040000,
64893+ GR_SHMEXEC = 0x00080000
64894+};
64895+
64896+enum {
64897+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
64898+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
64899+ GR_PAX_ENABLE_MPROTECT = 0x0004,
64900+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
64901+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
64902+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
64903+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
64904+ GR_PAX_DISABLE_MPROTECT = 0x0400,
64905+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
64906+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
64907+};
64908+
64909+enum {
64910+ GR_ID_USER = 0x01,
64911+ GR_ID_GROUP = 0x02,
64912+};
64913+
64914+enum {
64915+ GR_ID_ALLOW = 0x01,
64916+ GR_ID_DENY = 0x02,
64917+};
64918+
64919+#define GR_CRASH_RES 31
64920+#define GR_UIDTABLE_MAX 500
64921+
64922+/* begin resource learning section */
64923+enum {
64924+ GR_RLIM_CPU_BUMP = 60,
64925+ GR_RLIM_FSIZE_BUMP = 50000,
64926+ GR_RLIM_DATA_BUMP = 10000,
64927+ GR_RLIM_STACK_BUMP = 1000,
64928+ GR_RLIM_CORE_BUMP = 10000,
64929+ GR_RLIM_RSS_BUMP = 500000,
64930+ GR_RLIM_NPROC_BUMP = 1,
64931+ GR_RLIM_NOFILE_BUMP = 5,
64932+ GR_RLIM_MEMLOCK_BUMP = 50000,
64933+ GR_RLIM_AS_BUMP = 500000,
64934+ GR_RLIM_LOCKS_BUMP = 2,
64935+ GR_RLIM_SIGPENDING_BUMP = 5,
64936+ GR_RLIM_MSGQUEUE_BUMP = 10000,
64937+ GR_RLIM_NICE_BUMP = 1,
64938+ GR_RLIM_RTPRIO_BUMP = 1,
64939+ GR_RLIM_RTTIME_BUMP = 1000000
64940+};
64941+
64942+#endif
64943diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
64944new file mode 100644
64945index 0000000..baa6e96
64946--- /dev/null
64947+++ b/include/linux/grinternal.h
64948@@ -0,0 +1,215 @@
64949+#ifndef __GRINTERNAL_H
64950+#define __GRINTERNAL_H
64951+
64952+#ifdef CONFIG_GRKERNSEC
64953+
64954+#include <linux/fs.h>
64955+#include <linux/mnt_namespace.h>
64956+#include <linux/nsproxy.h>
64957+#include <linux/gracl.h>
64958+#include <linux/grdefs.h>
64959+#include <linux/grmsg.h>
64960+
64961+void gr_add_learn_entry(const char *fmt, ...)
64962+ __attribute__ ((format (printf, 1, 2)));
64963+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
64964+ const struct vfsmount *mnt);
64965+__u32 gr_check_create(const struct dentry *new_dentry,
64966+ const struct dentry *parent,
64967+ const struct vfsmount *mnt, const __u32 mode);
64968+int gr_check_protected_task(const struct task_struct *task);
64969+__u32 to_gr_audit(const __u32 reqmode);
64970+int gr_set_acls(const int type);
64971+int gr_apply_subject_to_task(struct task_struct *task);
64972+int gr_acl_is_enabled(void);
64973+char gr_roletype_to_char(void);
64974+
64975+void gr_handle_alertkill(struct task_struct *task);
64976+char *gr_to_filename(const struct dentry *dentry,
64977+ const struct vfsmount *mnt);
64978+char *gr_to_filename1(const struct dentry *dentry,
64979+ const struct vfsmount *mnt);
64980+char *gr_to_filename2(const struct dentry *dentry,
64981+ const struct vfsmount *mnt);
64982+char *gr_to_filename3(const struct dentry *dentry,
64983+ const struct vfsmount *mnt);
64984+
64985+extern int grsec_enable_ptrace_readexec;
64986+extern int grsec_enable_harden_ptrace;
64987+extern int grsec_enable_link;
64988+extern int grsec_enable_fifo;
64989+extern int grsec_enable_execve;
64990+extern int grsec_enable_shm;
64991+extern int grsec_enable_execlog;
64992+extern int grsec_enable_signal;
64993+extern int grsec_enable_audit_ptrace;
64994+extern int grsec_enable_forkfail;
64995+extern int grsec_enable_time;
64996+extern int grsec_enable_rofs;
64997+extern int grsec_enable_chroot_shmat;
64998+extern int grsec_enable_chroot_mount;
64999+extern int grsec_enable_chroot_double;
65000+extern int grsec_enable_chroot_pivot;
65001+extern int grsec_enable_chroot_chdir;
65002+extern int grsec_enable_chroot_chmod;
65003+extern int grsec_enable_chroot_mknod;
65004+extern int grsec_enable_chroot_fchdir;
65005+extern int grsec_enable_chroot_nice;
65006+extern int grsec_enable_chroot_execlog;
65007+extern int grsec_enable_chroot_caps;
65008+extern int grsec_enable_chroot_sysctl;
65009+extern int grsec_enable_chroot_unix;
65010+extern int grsec_enable_symlinkown;
65011+extern int grsec_symlinkown_gid;
65012+extern int grsec_enable_tpe;
65013+extern int grsec_tpe_gid;
65014+extern int grsec_enable_tpe_all;
65015+extern int grsec_enable_tpe_invert;
65016+extern int grsec_enable_socket_all;
65017+extern int grsec_socket_all_gid;
65018+extern int grsec_enable_socket_client;
65019+extern int grsec_socket_client_gid;
65020+extern int grsec_enable_socket_server;
65021+extern int grsec_socket_server_gid;
65022+extern int grsec_audit_gid;
65023+extern int grsec_enable_group;
65024+extern int grsec_enable_audit_textrel;
65025+extern int grsec_enable_log_rwxmaps;
65026+extern int grsec_enable_mount;
65027+extern int grsec_enable_chdir;
65028+extern int grsec_resource_logging;
65029+extern int grsec_enable_blackhole;
65030+extern int grsec_lastack_retries;
65031+extern int grsec_enable_brute;
65032+extern int grsec_lock;
65033+
65034+extern spinlock_t grsec_alert_lock;
65035+extern unsigned long grsec_alert_wtime;
65036+extern unsigned long grsec_alert_fyet;
65037+
65038+extern spinlock_t grsec_audit_lock;
65039+
65040+extern rwlock_t grsec_exec_file_lock;
65041+
65042+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
65043+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
65044+ (tsk)->exec_file->f_vfsmnt) : "/")
65045+
65046+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
65047+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
65048+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
65049+
65050+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
65051+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
65052+ (tsk)->exec_file->f_vfsmnt) : "/")
65053+
65054+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
65055+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
65056+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
65057+
65058+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
65059+
65060+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
65061+
65062+#define GR_CHROOT_CAPS {{ \
65063+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
65064+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
65065+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
65066+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
65067+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
65068+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
65069+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
65070+
65071+#define security_learn(normal_msg,args...) \
65072+({ \
65073+ read_lock(&grsec_exec_file_lock); \
65074+ gr_add_learn_entry(normal_msg "\n", ## args); \
65075+ read_unlock(&grsec_exec_file_lock); \
65076+})
65077+
65078+enum {
65079+ GR_DO_AUDIT,
65080+ GR_DONT_AUDIT,
65081+ /* used for non-audit messages that we shouldn't kill the task on */
65082+ GR_DONT_AUDIT_GOOD
65083+};
65084+
65085+enum {
65086+ GR_TTYSNIFF,
65087+ GR_RBAC,
65088+ GR_RBAC_STR,
65089+ GR_STR_RBAC,
65090+ GR_RBAC_MODE2,
65091+ GR_RBAC_MODE3,
65092+ GR_FILENAME,
65093+ GR_SYSCTL_HIDDEN,
65094+ GR_NOARGS,
65095+ GR_ONE_INT,
65096+ GR_ONE_INT_TWO_STR,
65097+ GR_ONE_STR,
65098+ GR_STR_INT,
65099+ GR_TWO_STR_INT,
65100+ GR_TWO_INT,
65101+ GR_TWO_U64,
65102+ GR_THREE_INT,
65103+ GR_FIVE_INT_TWO_STR,
65104+ GR_TWO_STR,
65105+ GR_THREE_STR,
65106+ GR_FOUR_STR,
65107+ GR_STR_FILENAME,
65108+ GR_FILENAME_STR,
65109+ GR_FILENAME_TWO_INT,
65110+ GR_FILENAME_TWO_INT_STR,
65111+ GR_TEXTREL,
65112+ GR_PTRACE,
65113+ GR_RESOURCE,
65114+ GR_CAP,
65115+ GR_SIG,
65116+ GR_SIG2,
65117+ GR_CRASH1,
65118+ GR_CRASH2,
65119+ GR_PSACCT,
65120+ GR_RWXMAP
65121+};
65122+
65123+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
65124+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
65125+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
65126+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
65127+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
65128+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
65129+#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)
65130+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
65131+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
65132+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
65133+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
65134+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
65135+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
65136+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
65137+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
65138+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
65139+#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)
65140+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
65141+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
65142+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
65143+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
65144+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
65145+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
65146+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
65147+#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)
65148+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
65149+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
65150+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
65151+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
65152+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
65153+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
65154+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
65155+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
65156+#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)
65157+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
65158+
65159+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
65160+
65161+#endif
65162+
65163+#endif
65164diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
65165new file mode 100644
65166index 0000000..2bd4c8d
65167--- /dev/null
65168+++ b/include/linux/grmsg.h
65169@@ -0,0 +1,111 @@
65170+#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"
65171+#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"
65172+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
65173+#define GR_STOPMOD_MSG "denied modification of module state by "
65174+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
65175+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
65176+#define GR_IOPERM_MSG "denied use of ioperm() by "
65177+#define GR_IOPL_MSG "denied use of iopl() by "
65178+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
65179+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
65180+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
65181+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
65182+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
65183+#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"
65184+#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"
65185+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
65186+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
65187+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
65188+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
65189+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
65190+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
65191+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
65192+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
65193+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
65194+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
65195+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
65196+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
65197+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
65198+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
65199+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
65200+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
65201+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
65202+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
65203+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
65204+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
65205+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
65206+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
65207+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
65208+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
65209+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
65210+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
65211+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
65212+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
65213+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
65214+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
65215+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
65216+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
65217+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
65218+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
65219+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
65220+#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"
65221+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
65222+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
65223+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
65224+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
65225+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
65226+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
65227+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
65228+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
65229+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
65230+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
65231+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
65232+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
65233+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
65234+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
65235+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
65236+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
65237+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
65238+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
65239+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
65240+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
65241+#define GR_FAILFORK_MSG "failed fork with errno %s by "
65242+#define GR_NICE_CHROOT_MSG "denied priority change by "
65243+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
65244+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
65245+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
65246+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
65247+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
65248+#define GR_TIME_MSG "time set by "
65249+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
65250+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
65251+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
65252+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
65253+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
65254+#define GR_BIND_MSG "denied bind() by "
65255+#define GR_CONNECT_MSG "denied connect() by "
65256+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
65257+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
65258+#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"
65259+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
65260+#define GR_CAP_ACL_MSG "use of %s denied for "
65261+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
65262+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
65263+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
65264+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
65265+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
65266+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
65267+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
65268+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
65269+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
65270+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
65271+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
65272+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
65273+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
65274+#define GR_VM86_MSG "denied use of vm86 by "
65275+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
65276+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
65277+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
65278+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
65279+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
65280+#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 "
65281diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
65282new file mode 100644
65283index 0000000..c5e5913
65284--- /dev/null
65285+++ b/include/linux/grsecurity.h
65286@@ -0,0 +1,257 @@
65287+#ifndef GR_SECURITY_H
65288+#define GR_SECURITY_H
65289+#include <linux/fs.h>
65290+#include <linux/fs_struct.h>
65291+#include <linux/binfmts.h>
65292+#include <linux/gracl.h>
65293+
65294+/* notify of brain-dead configs */
65295+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65296+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
65297+#endif
65298+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
65299+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
65300+#endif
65301+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
65302+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
65303+#endif
65304+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
65305+#error "CONFIG_PAX enabled, but no PaX options are enabled."
65306+#endif
65307+
65308+#include <linux/compat.h>
65309+
65310+struct user_arg_ptr {
65311+#ifdef CONFIG_COMPAT
65312+ bool is_compat;
65313+#endif
65314+ union {
65315+ const char __user *const __user *native;
65316+#ifdef CONFIG_COMPAT
65317+ const compat_uptr_t __user *compat;
65318+#endif
65319+ } ptr;
65320+};
65321+
65322+void gr_handle_brute_attach(unsigned long mm_flags);
65323+void gr_handle_brute_check(void);
65324+void gr_handle_kernel_exploit(void);
65325+int gr_process_user_ban(void);
65326+
65327+char gr_roletype_to_char(void);
65328+
65329+int gr_acl_enable_at_secure(void);
65330+
65331+int gr_check_user_change(int real, int effective, int fs);
65332+int gr_check_group_change(int real, int effective, int fs);
65333+
65334+void gr_del_task_from_ip_table(struct task_struct *p);
65335+
65336+int gr_pid_is_chrooted(struct task_struct *p);
65337+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
65338+int gr_handle_chroot_nice(void);
65339+int gr_handle_chroot_sysctl(const int op);
65340+int gr_handle_chroot_setpriority(struct task_struct *p,
65341+ const int niceval);
65342+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
65343+int gr_handle_chroot_chroot(const struct dentry *dentry,
65344+ const struct vfsmount *mnt);
65345+void gr_handle_chroot_chdir(struct path *path);
65346+int gr_handle_chroot_chmod(const struct dentry *dentry,
65347+ const struct vfsmount *mnt, const int mode);
65348+int gr_handle_chroot_mknod(const struct dentry *dentry,
65349+ const struct vfsmount *mnt, const int mode);
65350+int gr_handle_chroot_mount(const struct dentry *dentry,
65351+ const struct vfsmount *mnt,
65352+ const char *dev_name);
65353+int gr_handle_chroot_pivot(void);
65354+int gr_handle_chroot_unix(const pid_t pid);
65355+
65356+int gr_handle_rawio(const struct inode *inode);
65357+
65358+void gr_handle_ioperm(void);
65359+void gr_handle_iopl(void);
65360+
65361+umode_t gr_acl_umask(void);
65362+
65363+int gr_tpe_allow(const struct file *file);
65364+
65365+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
65366+void gr_clear_chroot_entries(struct task_struct *task);
65367+
65368+void gr_log_forkfail(const int retval);
65369+void gr_log_timechange(void);
65370+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
65371+void gr_log_chdir(const struct dentry *dentry,
65372+ const struct vfsmount *mnt);
65373+void gr_log_chroot_exec(const struct dentry *dentry,
65374+ const struct vfsmount *mnt);
65375+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
65376+void gr_log_remount(const char *devname, const int retval);
65377+void gr_log_unmount(const char *devname, const int retval);
65378+void gr_log_mount(const char *from, const char *to, const int retval);
65379+void gr_log_textrel(struct vm_area_struct *vma);
65380+void gr_log_rwxmmap(struct file *file);
65381+void gr_log_rwxmprotect(struct file *file);
65382+
65383+int gr_handle_follow_link(const struct inode *parent,
65384+ const struct inode *inode,
65385+ const struct dentry *dentry,
65386+ const struct vfsmount *mnt);
65387+int gr_handle_fifo(const struct dentry *dentry,
65388+ const struct vfsmount *mnt,
65389+ const struct dentry *dir, const int flag,
65390+ const int acc_mode);
65391+int gr_handle_hardlink(const struct dentry *dentry,
65392+ const struct vfsmount *mnt,
65393+ struct inode *inode,
65394+ const int mode, const struct filename *to);
65395+
65396+int gr_is_capable(const int cap);
65397+int gr_is_capable_nolog(const int cap);
65398+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
65399+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
65400+
65401+void gr_copy_label(struct task_struct *tsk);
65402+void gr_handle_crash(struct task_struct *task, const int sig);
65403+int gr_handle_signal(const struct task_struct *p, const int sig);
65404+int gr_check_crash_uid(const uid_t uid);
65405+int gr_check_protected_task(const struct task_struct *task);
65406+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
65407+int gr_acl_handle_mmap(const struct file *file,
65408+ const unsigned long prot);
65409+int gr_acl_handle_mprotect(const struct file *file,
65410+ const unsigned long prot);
65411+int gr_check_hidden_task(const struct task_struct *tsk);
65412+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
65413+ const struct vfsmount *mnt);
65414+__u32 gr_acl_handle_utime(const struct dentry *dentry,
65415+ const struct vfsmount *mnt);
65416+__u32 gr_acl_handle_access(const struct dentry *dentry,
65417+ const struct vfsmount *mnt, const int fmode);
65418+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
65419+ const struct vfsmount *mnt, umode_t *mode);
65420+__u32 gr_acl_handle_chown(const struct dentry *dentry,
65421+ const struct vfsmount *mnt);
65422+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
65423+ const struct vfsmount *mnt);
65424+int gr_handle_ptrace(struct task_struct *task, const long request);
65425+int gr_handle_proc_ptrace(struct task_struct *task);
65426+__u32 gr_acl_handle_execve(const struct dentry *dentry,
65427+ const struct vfsmount *mnt);
65428+int gr_check_crash_exec(const struct file *filp);
65429+int gr_acl_is_enabled(void);
65430+void gr_set_kernel_label(struct task_struct *task);
65431+void gr_set_role_label(struct task_struct *task, const uid_t uid,
65432+ const gid_t gid);
65433+int gr_set_proc_label(const struct dentry *dentry,
65434+ const struct vfsmount *mnt,
65435+ const int unsafe_flags);
65436+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
65437+ const struct vfsmount *mnt);
65438+__u32 gr_acl_handle_open(const struct dentry *dentry,
65439+ const struct vfsmount *mnt, int acc_mode);
65440+__u32 gr_acl_handle_creat(const struct dentry *dentry,
65441+ const struct dentry *p_dentry,
65442+ const struct vfsmount *p_mnt,
65443+ int open_flags, int acc_mode, const int imode);
65444+void gr_handle_create(const struct dentry *dentry,
65445+ const struct vfsmount *mnt);
65446+void gr_handle_proc_create(const struct dentry *dentry,
65447+ const struct inode *inode);
65448+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
65449+ const struct dentry *parent_dentry,
65450+ const struct vfsmount *parent_mnt,
65451+ const int mode);
65452+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
65453+ const struct dentry *parent_dentry,
65454+ const struct vfsmount *parent_mnt);
65455+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
65456+ const struct vfsmount *mnt);
65457+void gr_handle_delete(const ino_t ino, const dev_t dev);
65458+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
65459+ const struct vfsmount *mnt);
65460+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
65461+ const struct dentry *parent_dentry,
65462+ const struct vfsmount *parent_mnt,
65463+ const struct filename *from);
65464+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
65465+ const struct dentry *parent_dentry,
65466+ const struct vfsmount *parent_mnt,
65467+ const struct dentry *old_dentry,
65468+ const struct vfsmount *old_mnt, const struct filename *to);
65469+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
65470+int gr_acl_handle_rename(struct dentry *new_dentry,
65471+ struct dentry *parent_dentry,
65472+ const struct vfsmount *parent_mnt,
65473+ struct dentry *old_dentry,
65474+ struct inode *old_parent_inode,
65475+ struct vfsmount *old_mnt, const struct filename *newname);
65476+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65477+ struct dentry *old_dentry,
65478+ struct dentry *new_dentry,
65479+ struct vfsmount *mnt, const __u8 replace);
65480+__u32 gr_check_link(const struct dentry *new_dentry,
65481+ const struct dentry *parent_dentry,
65482+ const struct vfsmount *parent_mnt,
65483+ const struct dentry *old_dentry,
65484+ const struct vfsmount *old_mnt);
65485+int gr_acl_handle_filldir(const struct file *file, const char *name,
65486+ const unsigned int namelen, const ino_t ino);
65487+
65488+__u32 gr_acl_handle_unix(const struct dentry *dentry,
65489+ const struct vfsmount *mnt);
65490+void gr_acl_handle_exit(void);
65491+void gr_acl_handle_psacct(struct task_struct *task, const long code);
65492+int gr_acl_handle_procpidmem(const struct task_struct *task);
65493+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
65494+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
65495+void gr_audit_ptrace(struct task_struct *task);
65496+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
65497+void gr_put_exec_file(struct task_struct *task);
65498+
65499+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
65500+
65501+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
65502+extern void gr_learn_resource(const struct task_struct *task, const int res,
65503+ const unsigned long wanted, const int gt);
65504+#else
65505+static inline void gr_learn_resource(const struct task_struct *task, const int res,
65506+ const unsigned long wanted, const int gt)
65507+{
65508+}
65509+#endif
65510+
65511+#ifdef CONFIG_GRKERNSEC_RESLOG
65512+extern void gr_log_resource(const struct task_struct *task, const int res,
65513+ const unsigned long wanted, const int gt);
65514+#else
65515+static inline void gr_log_resource(const struct task_struct *task, const int res,
65516+ const unsigned long wanted, const int gt)
65517+{
65518+}
65519+#endif
65520+
65521+#ifdef CONFIG_GRKERNSEC
65522+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
65523+void gr_handle_vm86(void);
65524+void gr_handle_mem_readwrite(u64 from, u64 to);
65525+
65526+void gr_log_badprocpid(const char *entry);
65527+
65528+extern int grsec_enable_dmesg;
65529+extern int grsec_disable_privio;
65530+
65531+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65532+extern int grsec_proc_gid;
65533+#endif
65534+
65535+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65536+extern int grsec_enable_chroot_findtask;
65537+#endif
65538+#ifdef CONFIG_GRKERNSEC_SETXID
65539+extern int grsec_enable_setxid;
65540+#endif
65541+#endif
65542+
65543+#endif
65544diff --git a/include/linux/grsock.h b/include/linux/grsock.h
65545new file mode 100644
65546index 0000000..e7ffaaf
65547--- /dev/null
65548+++ b/include/linux/grsock.h
65549@@ -0,0 +1,19 @@
65550+#ifndef __GRSOCK_H
65551+#define __GRSOCK_H
65552+
65553+extern void gr_attach_curr_ip(const struct sock *sk);
65554+extern int gr_handle_sock_all(const int family, const int type,
65555+ const int protocol);
65556+extern int gr_handle_sock_server(const struct sockaddr *sck);
65557+extern int gr_handle_sock_server_other(const struct sock *sck);
65558+extern int gr_handle_sock_client(const struct sockaddr *sck);
65559+extern int gr_search_connect(struct socket * sock,
65560+ struct sockaddr_in * addr);
65561+extern int gr_search_bind(struct socket * sock,
65562+ struct sockaddr_in * addr);
65563+extern int gr_search_listen(struct socket * sock);
65564+extern int gr_search_accept(struct socket * sock);
65565+extern int gr_search_socket(const int domain, const int type,
65566+ const int protocol);
65567+
65568+#endif
65569diff --git a/include/linux/highmem.h b/include/linux/highmem.h
65570index ef788b5..ac41b7b 100644
65571--- a/include/linux/highmem.h
65572+++ b/include/linux/highmem.h
65573@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
65574 kunmap_atomic(kaddr);
65575 }
65576
65577+static inline void sanitize_highpage(struct page *page)
65578+{
65579+ void *kaddr;
65580+ unsigned long flags;
65581+
65582+ local_irq_save(flags);
65583+ kaddr = kmap_atomic(page);
65584+ clear_page(kaddr);
65585+ kunmap_atomic(kaddr);
65586+ local_irq_restore(flags);
65587+}
65588+
65589 static inline void zero_user_segments(struct page *page,
65590 unsigned start1, unsigned end1,
65591 unsigned start2, unsigned end2)
65592diff --git a/include/linux/i2c.h b/include/linux/i2c.h
65593index d0c4db7..61b3577 100644
65594--- a/include/linux/i2c.h
65595+++ b/include/linux/i2c.h
65596@@ -369,6 +369,7 @@ struct i2c_algorithm {
65597 /* To determine what the adapter supports */
65598 u32 (*functionality) (struct i2c_adapter *);
65599 };
65600+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
65601
65602 /*
65603 * i2c_adapter is the structure used to identify a physical i2c bus along
65604diff --git a/include/linux/i2o.h b/include/linux/i2o.h
65605index d23c3c2..eb63c81 100644
65606--- a/include/linux/i2o.h
65607+++ b/include/linux/i2o.h
65608@@ -565,7 +565,7 @@ struct i2o_controller {
65609 struct i2o_device *exec; /* Executive */
65610 #if BITS_PER_LONG == 64
65611 spinlock_t context_list_lock; /* lock for context_list */
65612- atomic_t context_list_counter; /* needed for unique contexts */
65613+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
65614 struct list_head context_list; /* list of context id's
65615 and pointers */
65616 #endif
65617diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
65618index aff7ad8..3942bbd 100644
65619--- a/include/linux/if_pppox.h
65620+++ b/include/linux/if_pppox.h
65621@@ -76,7 +76,7 @@ struct pppox_proto {
65622 int (*ioctl)(struct socket *sock, unsigned int cmd,
65623 unsigned long arg);
65624 struct module *owner;
65625-};
65626+} __do_const;
65627
65628 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
65629 extern void unregister_pppox_proto(int proto_num);
65630diff --git a/include/linux/init.h b/include/linux/init.h
65631index 10ed4f4..8e8490d 100644
65632--- a/include/linux/init.h
65633+++ b/include/linux/init.h
65634@@ -39,9 +39,36 @@
65635 * Also note, that this data cannot be "const".
65636 */
65637
65638+#ifdef MODULE
65639+#define add_init_latent_entropy
65640+#define add_devinit_latent_entropy
65641+#define add_cpuinit_latent_entropy
65642+#define add_meminit_latent_entropy
65643+#else
65644+#define add_init_latent_entropy __latent_entropy
65645+
65646+#ifdef CONFIG_HOTPLUG
65647+#define add_devinit_latent_entropy
65648+#else
65649+#define add_devinit_latent_entropy __latent_entropy
65650+#endif
65651+
65652+#ifdef CONFIG_HOTPLUG_CPU
65653+#define add_cpuinit_latent_entropy
65654+#else
65655+#define add_cpuinit_latent_entropy __latent_entropy
65656+#endif
65657+
65658+#ifdef CONFIG_MEMORY_HOTPLUG
65659+#define add_meminit_latent_entropy
65660+#else
65661+#define add_meminit_latent_entropy __latent_entropy
65662+#endif
65663+#endif
65664+
65665 /* These are for everybody (although not all archs will actually
65666 discard it in modules) */
65667-#define __init __section(.init.text) __cold notrace
65668+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
65669 #define __initdata __section(.init.data)
65670 #define __initconst __constsection(.init.rodata)
65671 #define __exitdata __section(.exit.data)
65672@@ -94,7 +121,7 @@
65673 #define __exit __section(.exit.text) __exitused __cold notrace
65674
65675 /* Used for HOTPLUG_CPU */
65676-#define __cpuinit __section(.cpuinit.text) __cold notrace
65677+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
65678 #define __cpuinitdata __section(.cpuinit.data)
65679 #define __cpuinitconst __constsection(.cpuinit.rodata)
65680 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
65681@@ -102,7 +129,7 @@
65682 #define __cpuexitconst __constsection(.cpuexit.rodata)
65683
65684 /* Used for MEMORY_HOTPLUG */
65685-#define __meminit __section(.meminit.text) __cold notrace
65686+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
65687 #define __meminitdata __section(.meminit.data)
65688 #define __meminitconst __constsection(.meminit.rodata)
65689 #define __memexit __section(.memexit.text) __exitused __cold notrace
65690diff --git a/include/linux/init_task.h b/include/linux/init_task.h
65691index 6d087c5..401cab8 100644
65692--- a/include/linux/init_task.h
65693+++ b/include/linux/init_task.h
65694@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
65695
65696 #define INIT_TASK_COMM "swapper"
65697
65698+#ifdef CONFIG_X86
65699+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
65700+#else
65701+#define INIT_TASK_THREAD_INFO
65702+#endif
65703+
65704 /*
65705 * INIT_TASK is used to set up the first task table, touch at
65706 * your own risk!. Base=0, limit=0x1fffff (=2MB)
65707@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
65708 RCU_POINTER_INITIALIZER(cred, &init_cred), \
65709 .comm = INIT_TASK_COMM, \
65710 .thread = INIT_THREAD, \
65711+ INIT_TASK_THREAD_INFO \
65712 .fs = &init_fs, \
65713 .files = &init_files, \
65714 .signal = &init_signals, \
65715diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
65716index 5fa5afe..ac55b25 100644
65717--- a/include/linux/interrupt.h
65718+++ b/include/linux/interrupt.h
65719@@ -430,7 +430,7 @@ enum
65720 /* map softirq index to softirq name. update 'softirq_to_name' in
65721 * kernel/softirq.c when adding a new softirq.
65722 */
65723-extern char *softirq_to_name[NR_SOFTIRQS];
65724+extern const char * const softirq_to_name[NR_SOFTIRQS];
65725
65726 /* softirq mask and active fields moved to irq_cpustat_t in
65727 * asm/hardirq.h to get better cache usage. KAO
65728@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
65729
65730 struct softirq_action
65731 {
65732- void (*action)(struct softirq_action *);
65733-};
65734+ void (*action)(void);
65735+} __no_const;
65736
65737 asmlinkage void do_softirq(void);
65738 asmlinkage void __do_softirq(void);
65739-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
65740+extern void open_softirq(int nr, void (*action)(void));
65741 extern void softirq_init(void);
65742 extern void __raise_softirq_irqoff(unsigned int nr);
65743
65744diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
65745index 6883e19..06992b1 100644
65746--- a/include/linux/kallsyms.h
65747+++ b/include/linux/kallsyms.h
65748@@ -15,7 +15,8 @@
65749
65750 struct module;
65751
65752-#ifdef CONFIG_KALLSYMS
65753+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
65754+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65755 /* Lookup the address for a symbol. Returns 0 if not found. */
65756 unsigned long kallsyms_lookup_name(const char *name);
65757
65758@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
65759 /* Stupid that this does nothing, but I didn't create this mess. */
65760 #define __print_symbol(fmt, addr)
65761 #endif /*CONFIG_KALLSYMS*/
65762+#else /* when included by kallsyms.c, vsnprintf.c, or
65763+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
65764+extern void __print_symbol(const char *fmt, unsigned long address);
65765+extern int sprint_backtrace(char *buffer, unsigned long address);
65766+extern int sprint_symbol(char *buffer, unsigned long address);
65767+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
65768+const char *kallsyms_lookup(unsigned long addr,
65769+ unsigned long *symbolsize,
65770+ unsigned long *offset,
65771+ char **modname, char *namebuf);
65772+#endif
65773
65774 /* This macro allows us to keep printk typechecking */
65775 static __printf(1, 2)
65776diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
65777index 4dff0c6..1ca9b72 100644
65778--- a/include/linux/kgdb.h
65779+++ b/include/linux/kgdb.h
65780@@ -53,7 +53,7 @@ extern int kgdb_connected;
65781 extern int kgdb_io_module_registered;
65782
65783 extern atomic_t kgdb_setting_breakpoint;
65784-extern atomic_t kgdb_cpu_doing_single_step;
65785+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
65786
65787 extern struct task_struct *kgdb_usethread;
65788 extern struct task_struct *kgdb_contthread;
65789@@ -255,7 +255,7 @@ struct kgdb_arch {
65790 void (*correct_hw_break)(void);
65791
65792 void (*enable_nmi)(bool on);
65793-};
65794+} __do_const;
65795
65796 /**
65797 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
65798@@ -280,7 +280,7 @@ struct kgdb_io {
65799 void (*pre_exception) (void);
65800 void (*post_exception) (void);
65801 int is_console;
65802-};
65803+} __do_const;
65804
65805 extern struct kgdb_arch arch_kgdb_ops;
65806
65807diff --git a/include/linux/kmod.h b/include/linux/kmod.h
65808index 5398d58..5883a34 100644
65809--- a/include/linux/kmod.h
65810+++ b/include/linux/kmod.h
65811@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
65812 * usually useless though. */
65813 extern __printf(2, 3)
65814 int __request_module(bool wait, const char *name, ...);
65815+extern __printf(3, 4)
65816+int ___request_module(bool wait, char *param_name, const char *name, ...);
65817 #define request_module(mod...) __request_module(true, mod)
65818 #define request_module_nowait(mod...) __request_module(false, mod)
65819 #define try_then_request_module(x, mod...) \
65820diff --git a/include/linux/kobject.h b/include/linux/kobject.h
65821index 939b112..90b7f44 100644
65822--- a/include/linux/kobject.h
65823+++ b/include/linux/kobject.h
65824@@ -111,7 +111,7 @@ struct kobj_type {
65825 struct attribute **default_attrs;
65826 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
65827 const void *(*namespace)(struct kobject *kobj);
65828-};
65829+} __do_const;
65830
65831 struct kobj_uevent_env {
65832 char *envp[UEVENT_NUM_ENVP];
65833diff --git a/include/linux/kref.h b/include/linux/kref.h
65834index 4972e6e..de4d19b 100644
65835--- a/include/linux/kref.h
65836+++ b/include/linux/kref.h
65837@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
65838 static inline int kref_sub(struct kref *kref, unsigned int count,
65839 void (*release)(struct kref *kref))
65840 {
65841- WARN_ON(release == NULL);
65842+ BUG_ON(release == NULL);
65843
65844 if (atomic_sub_and_test((int) count, &kref->refcount)) {
65845 release(kref);
65846diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
65847index 2c497ab..afe32f5 100644
65848--- a/include/linux/kvm_host.h
65849+++ b/include/linux/kvm_host.h
65850@@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
65851 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
65852 void vcpu_put(struct kvm_vcpu *vcpu);
65853
65854-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65855+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65856 struct module *module);
65857 void kvm_exit(void);
65858
65859@@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
65860 struct kvm_guest_debug *dbg);
65861 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
65862
65863-int kvm_arch_init(void *opaque);
65864+int kvm_arch_init(const void *opaque);
65865 void kvm_arch_exit(void);
65866
65867 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
65868diff --git a/include/linux/libata.h b/include/linux/libata.h
65869index 649e5f8..ead5194 100644
65870--- a/include/linux/libata.h
65871+++ b/include/linux/libata.h
65872@@ -915,7 +915,7 @@ struct ata_port_operations {
65873 * fields must be pointers.
65874 */
65875 const struct ata_port_operations *inherits;
65876-};
65877+} __do_const;
65878
65879 struct ata_port_info {
65880 unsigned long flags;
65881diff --git a/include/linux/list.h b/include/linux/list.h
65882index cc6d2aa..71febca 100644
65883--- a/include/linux/list.h
65884+++ b/include/linux/list.h
65885@@ -112,6 +112,9 @@ extern void __list_del_entry(struct list_head *entry);
65886 extern void list_del(struct list_head *entry);
65887 #endif
65888
65889+extern void pax_list_add_tail(struct list_head *new, struct list_head *head);
65890+extern void pax_list_del(struct list_head *entry);
65891+
65892 /**
65893 * list_replace - replace old entry by new one
65894 * @old : the element to be replaced
65895diff --git a/include/linux/mm.h b/include/linux/mm.h
65896index 66e2f7c..ea88001 100644
65897--- a/include/linux/mm.h
65898+++ b/include/linux/mm.h
65899@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
65900 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
65901 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
65902 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
65903+
65904+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
65905+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
65906+#endif
65907+
65908 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
65909
65910 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
65911@@ -231,6 +236,7 @@ struct vm_operations_struct {
65912 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
65913 unsigned long size, pgoff_t pgoff);
65914 };
65915+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
65916
65917 struct mmu_gather;
65918 struct inode;
65919@@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
65920 int set_page_dirty_lock(struct page *page);
65921 int clear_page_dirty_for_io(struct page *page);
65922
65923-/* Is the vma a continuation of the stack vma above it? */
65924-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
65925-{
65926- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
65927-}
65928-
65929-static inline int stack_guard_page_start(struct vm_area_struct *vma,
65930- unsigned long addr)
65931-{
65932- return (vma->vm_flags & VM_GROWSDOWN) &&
65933- (vma->vm_start == addr) &&
65934- !vma_growsdown(vma->vm_prev, addr);
65935-}
65936-
65937-/* Is the vma a continuation of the stack vma below it? */
65938-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
65939-{
65940- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
65941-}
65942-
65943-static inline int stack_guard_page_end(struct vm_area_struct *vma,
65944- unsigned long addr)
65945-{
65946- return (vma->vm_flags & VM_GROWSUP) &&
65947- (vma->vm_end == addr) &&
65948- !vma_growsup(vma->vm_next, addr);
65949-}
65950-
65951 extern pid_t
65952 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
65953
65954@@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
65955 }
65956 #endif
65957
65958+#ifdef CONFIG_MMU
65959+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
65960+#else
65961+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
65962+{
65963+ return __pgprot(0);
65964+}
65965+#endif
65966+
65967 int vma_wants_writenotify(struct vm_area_struct *vma);
65968
65969 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
65970@@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
65971 {
65972 return 0;
65973 }
65974+
65975+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
65976+ unsigned long address)
65977+{
65978+ return 0;
65979+}
65980 #else
65981 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
65982+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
65983 #endif
65984
65985 #ifdef __PAGETABLE_PMD_FOLDED
65986@@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
65987 {
65988 return 0;
65989 }
65990+
65991+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
65992+ unsigned long address)
65993+{
65994+ return 0;
65995+}
65996 #else
65997 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
65998+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
65999 #endif
66000
66001 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
66002@@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
66003 NULL: pud_offset(pgd, address);
66004 }
66005
66006+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
66007+{
66008+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
66009+ NULL: pud_offset(pgd, address);
66010+}
66011+
66012 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
66013 {
66014 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
66015 NULL: pmd_offset(pud, address);
66016 }
66017+
66018+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
66019+{
66020+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
66021+ NULL: pmd_offset(pud, address);
66022+}
66023 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
66024
66025 #if USE_SPLIT_PTLOCKS
66026@@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
66027 unsigned long, unsigned long,
66028 unsigned long, unsigned long);
66029 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
66030+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
66031
66032 /* These take the mm semaphore themselves */
66033 extern unsigned long vm_brk(unsigned long, unsigned long);
66034@@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
66035 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
66036 struct vm_area_struct **pprev);
66037
66038+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
66039+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
66040+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
66041+
66042 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
66043 NULL if none. Assume start_addr < end_addr. */
66044 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
66045@@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
66046 return vma;
66047 }
66048
66049-#ifdef CONFIG_MMU
66050-pgprot_t vm_get_page_prot(unsigned long vm_flags);
66051-#else
66052-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
66053-{
66054- return __pgprot(0);
66055-}
66056-#endif
66057-
66058 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
66059 unsigned long change_prot_numa(struct vm_area_struct *vma,
66060 unsigned long start, unsigned long end);
66061@@ -1721,7 +1730,7 @@ extern int unpoison_memory(unsigned long pfn);
66062 extern int sysctl_memory_failure_early_kill;
66063 extern int sysctl_memory_failure_recovery;
66064 extern void shake_page(struct page *p, int access);
66065-extern atomic_long_t mce_bad_pages;
66066+extern atomic_long_unchecked_t mce_bad_pages;
66067 extern int soft_offline_page(struct page *page, int flags);
66068
66069 extern void dump_page(struct page *page);
66070@@ -1752,5 +1761,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
66071 static inline bool page_is_guard(struct page *page) { return false; }
66072 #endif /* CONFIG_DEBUG_PAGEALLOC */
66073
66074+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
66075+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
66076+#else
66077+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
66078+#endif
66079+
66080 #endif /* __KERNEL__ */
66081 #endif /* _LINUX_MM_H */
66082diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
66083index f8f5162..6276a36 100644
66084--- a/include/linux/mm_types.h
66085+++ b/include/linux/mm_types.h
66086@@ -288,6 +288,8 @@ struct vm_area_struct {
66087 #ifdef CONFIG_NUMA
66088 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
66089 #endif
66090+
66091+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
66092 };
66093
66094 struct core_thread {
66095@@ -362,7 +364,7 @@ struct mm_struct {
66096 unsigned long def_flags;
66097 unsigned long nr_ptes; /* Page table pages */
66098 unsigned long start_code, end_code, start_data, end_data;
66099- unsigned long start_brk, brk, start_stack;
66100+ unsigned long brk_gap, start_brk, brk, start_stack;
66101 unsigned long arg_start, arg_end, env_start, env_end;
66102
66103 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
66104@@ -436,6 +438,24 @@ struct mm_struct {
66105 int first_nid;
66106 #endif
66107 struct uprobes_state uprobes_state;
66108+
66109+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66110+ unsigned long pax_flags;
66111+#endif
66112+
66113+#ifdef CONFIG_PAX_DLRESOLVE
66114+ unsigned long call_dl_resolve;
66115+#endif
66116+
66117+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
66118+ unsigned long call_syscall;
66119+#endif
66120+
66121+#ifdef CONFIG_PAX_ASLR
66122+ unsigned long delta_mmap; /* randomized offset */
66123+ unsigned long delta_stack; /* randomized offset */
66124+#endif
66125+
66126 };
66127
66128 /* first nid will either be a valid NID or one of these values */
66129diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
66130index c5d5278..f0b68c8 100644
66131--- a/include/linux/mmiotrace.h
66132+++ b/include/linux/mmiotrace.h
66133@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
66134 /* Called from ioremap.c */
66135 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
66136 void __iomem *addr);
66137-extern void mmiotrace_iounmap(volatile void __iomem *addr);
66138+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
66139
66140 /* For anyone to insert markers. Remember trailing newline. */
66141 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
66142@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
66143 {
66144 }
66145
66146-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
66147+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
66148 {
66149 }
66150
66151diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
66152index 73b64a3..6562925 100644
66153--- a/include/linux/mmzone.h
66154+++ b/include/linux/mmzone.h
66155@@ -412,7 +412,7 @@ struct zone {
66156 unsigned long flags; /* zone flags, see below */
66157
66158 /* Zone statistics */
66159- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66160+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66161
66162 /*
66163 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
66164diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
66165index fed3def..7cc3f93 100644
66166--- a/include/linux/mod_devicetable.h
66167+++ b/include/linux/mod_devicetable.h
66168@@ -12,7 +12,7 @@
66169 typedef unsigned long kernel_ulong_t;
66170 #endif
66171
66172-#define PCI_ANY_ID (~0)
66173+#define PCI_ANY_ID ((__u16)~0)
66174
66175 struct pci_device_id {
66176 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
66177@@ -139,7 +139,7 @@ struct usb_device_id {
66178 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
66179 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
66180
66181-#define HID_ANY_ID (~0)
66182+#define HID_ANY_ID (~0U)
66183 #define HID_BUS_ANY 0xffff
66184 #define HID_GROUP_ANY 0x0000
66185
66186diff --git a/include/linux/module.h b/include/linux/module.h
66187index 1375ee3..d631af0 100644
66188--- a/include/linux/module.h
66189+++ b/include/linux/module.h
66190@@ -17,9 +17,11 @@
66191 #include <linux/moduleparam.h>
66192 #include <linux/tracepoint.h>
66193 #include <linux/export.h>
66194+#include <linux/fs.h>
66195
66196 #include <linux/percpu.h>
66197 #include <asm/module.h>
66198+#include <asm/pgtable.h>
66199
66200 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
66201 #define MODULE_SIG_STRING "~Module signature appended~\n"
66202@@ -281,19 +283,16 @@ struct module
66203 int (*init)(void);
66204
66205 /* If this is non-NULL, vfree after init() returns */
66206- void *module_init;
66207+ void *module_init_rx, *module_init_rw;
66208
66209 /* Here is the actual code + data, vfree'd on unload. */
66210- void *module_core;
66211+ void *module_core_rx, *module_core_rw;
66212
66213 /* Here are the sizes of the init and core sections */
66214- unsigned int init_size, core_size;
66215+ unsigned int init_size_rw, core_size_rw;
66216
66217 /* The size of the executable code in each section. */
66218- unsigned int init_text_size, core_text_size;
66219-
66220- /* Size of RO sections of the module (text+rodata) */
66221- unsigned int init_ro_size, core_ro_size;
66222+ unsigned int init_size_rx, core_size_rx;
66223
66224 /* Arch-specific module values */
66225 struct mod_arch_specific arch;
66226@@ -349,6 +348,10 @@ struct module
66227 #ifdef CONFIG_EVENT_TRACING
66228 struct ftrace_event_call **trace_events;
66229 unsigned int num_trace_events;
66230+ struct file_operations trace_id;
66231+ struct file_operations trace_enable;
66232+ struct file_operations trace_format;
66233+ struct file_operations trace_filter;
66234 #endif
66235 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
66236 unsigned int num_ftrace_callsites;
66237@@ -396,16 +399,46 @@ bool is_module_address(unsigned long addr);
66238 bool is_module_percpu_address(unsigned long addr);
66239 bool is_module_text_address(unsigned long addr);
66240
66241+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
66242+{
66243+
66244+#ifdef CONFIG_PAX_KERNEXEC
66245+ if (ktla_ktva(addr) >= (unsigned long)start &&
66246+ ktla_ktva(addr) < (unsigned long)start + size)
66247+ return 1;
66248+#endif
66249+
66250+ return ((void *)addr >= start && (void *)addr < start + size);
66251+}
66252+
66253+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
66254+{
66255+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
66256+}
66257+
66258+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
66259+{
66260+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
66261+}
66262+
66263+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
66264+{
66265+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
66266+}
66267+
66268+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
66269+{
66270+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
66271+}
66272+
66273 static inline int within_module_core(unsigned long addr, struct module *mod)
66274 {
66275- return (unsigned long)mod->module_core <= addr &&
66276- addr < (unsigned long)mod->module_core + mod->core_size;
66277+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
66278 }
66279
66280 static inline int within_module_init(unsigned long addr, struct module *mod)
66281 {
66282- return (unsigned long)mod->module_init <= addr &&
66283- addr < (unsigned long)mod->module_init + mod->init_size;
66284+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
66285 }
66286
66287 /* Search for module by name: must hold module_mutex. */
66288diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
66289index 560ca53..5ee8d73 100644
66290--- a/include/linux/moduleloader.h
66291+++ b/include/linux/moduleloader.h
66292@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
66293
66294 /* Allocator used for allocating struct module, core sections and init
66295 sections. Returns NULL on failure. */
66296-void *module_alloc(unsigned long size);
66297+void *module_alloc(unsigned long size) __size_overflow(1);
66298+
66299+#ifdef CONFIG_PAX_KERNEXEC
66300+void *module_alloc_exec(unsigned long size) __size_overflow(1);
66301+#else
66302+#define module_alloc_exec(x) module_alloc(x)
66303+#endif
66304
66305 /* Free memory returned from module_alloc. */
66306 void module_free(struct module *mod, void *module_region);
66307
66308+#ifdef CONFIG_PAX_KERNEXEC
66309+void module_free_exec(struct module *mod, void *module_region);
66310+#else
66311+#define module_free_exec(x, y) module_free((x), (y))
66312+#endif
66313+
66314 /*
66315 * Apply the given relocation to the (simplified) ELF. Return -error
66316 * or 0.
66317@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
66318 unsigned int relsec,
66319 struct module *me)
66320 {
66321+#ifdef CONFIG_MODULES
66322 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
66323+#endif
66324 return -ENOEXEC;
66325 }
66326 #endif
66327@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
66328 unsigned int relsec,
66329 struct module *me)
66330 {
66331+#ifdef CONFIG_MODULES
66332 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
66333+#endif
66334 return -ENOEXEC;
66335 }
66336 #endif
66337diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
66338index 137b419..fe663ec 100644
66339--- a/include/linux/moduleparam.h
66340+++ b/include/linux/moduleparam.h
66341@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
66342 * @len is usually just sizeof(string).
66343 */
66344 #define module_param_string(name, string, len, perm) \
66345- static const struct kparam_string __param_string_##name \
66346+ static const struct kparam_string __param_string_##name __used \
66347 = { len, string }; \
66348 __module_param_call(MODULE_PARAM_PREFIX, name, \
66349 &param_ops_string, \
66350@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
66351 */
66352 #define module_param_array_named(name, array, type, nump, perm) \
66353 param_check_##type(name, &(array)[0]); \
66354- static const struct kparam_array __param_arr_##name \
66355+ static const struct kparam_array __param_arr_##name __used \
66356 = { .max = ARRAY_SIZE(array), .num = nump, \
66357 .ops = &param_ops_##type, \
66358 .elemsize = sizeof(array[0]), .elem = array }; \
66359diff --git a/include/linux/namei.h b/include/linux/namei.h
66360index 5a5ff57..5ae5070 100644
66361--- a/include/linux/namei.h
66362+++ b/include/linux/namei.h
66363@@ -19,7 +19,7 @@ struct nameidata {
66364 unsigned seq;
66365 int last_type;
66366 unsigned depth;
66367- char *saved_names[MAX_NESTED_LINKS + 1];
66368+ const char *saved_names[MAX_NESTED_LINKS + 1];
66369 };
66370
66371 /*
66372@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
66373
66374 extern void nd_jump_link(struct nameidata *nd, struct path *path);
66375
66376-static inline void nd_set_link(struct nameidata *nd, char *path)
66377+static inline void nd_set_link(struct nameidata *nd, const char *path)
66378 {
66379 nd->saved_names[nd->depth] = path;
66380 }
66381
66382-static inline char *nd_get_link(struct nameidata *nd)
66383+static inline const char *nd_get_link(const struct nameidata *nd)
66384 {
66385 return nd->saved_names[nd->depth];
66386 }
66387diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
66388index 9ef07d0..130a5d9 100644
66389--- a/include/linux/netdevice.h
66390+++ b/include/linux/netdevice.h
66391@@ -1012,6 +1012,7 @@ struct net_device_ops {
66392 u32 pid, u32 seq,
66393 struct net_device *dev);
66394 };
66395+typedef struct net_device_ops __no_const net_device_ops_no_const;
66396
66397 /*
66398 * The DEVICE structure.
66399@@ -1078,7 +1079,7 @@ struct net_device {
66400 int iflink;
66401
66402 struct net_device_stats stats;
66403- atomic_long_t rx_dropped; /* dropped packets by core network
66404+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
66405 * Do not use this in drivers.
66406 */
66407
66408diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
66409index 7958e84..ed74d7a 100644
66410--- a/include/linux/netfilter/ipset/ip_set.h
66411+++ b/include/linux/netfilter/ipset/ip_set.h
66412@@ -98,7 +98,7 @@ struct ip_set_type_variant {
66413 /* Return true if "b" set is the same as "a"
66414 * according to the create set parameters */
66415 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
66416-};
66417+} __do_const;
66418
66419 /* The core set type structure */
66420 struct ip_set_type {
66421diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
66422index 4966dde..7d8ce06 100644
66423--- a/include/linux/netfilter/nfnetlink.h
66424+++ b/include/linux/netfilter/nfnetlink.h
66425@@ -16,7 +16,7 @@ struct nfnl_callback {
66426 const struct nlattr * const cda[]);
66427 const struct nla_policy *policy; /* netlink attribute policy */
66428 const u_int16_t attr_count; /* number of nlattr's */
66429-};
66430+} __do_const;
66431
66432 struct nfnetlink_subsystem {
66433 const char *name;
66434diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
66435new file mode 100644
66436index 0000000..33f4af8
66437--- /dev/null
66438+++ b/include/linux/netfilter/xt_gradm.h
66439@@ -0,0 +1,9 @@
66440+#ifndef _LINUX_NETFILTER_XT_GRADM_H
66441+#define _LINUX_NETFILTER_XT_GRADM_H 1
66442+
66443+struct xt_gradm_mtinfo {
66444+ __u16 flags;
66445+ __u16 invflags;
66446+};
66447+
66448+#endif
66449diff --git a/include/linux/notifier.h b/include/linux/notifier.h
66450index d65746e..62e72c2 100644
66451--- a/include/linux/notifier.h
66452+++ b/include/linux/notifier.h
66453@@ -51,7 +51,8 @@ struct notifier_block {
66454 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
66455 struct notifier_block __rcu *next;
66456 int priority;
66457-};
66458+} __do_const;
66459+typedef struct notifier_block __no_const notifier_block_no_const;
66460
66461 struct atomic_notifier_head {
66462 spinlock_t lock;
66463diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
66464index a4c5624..79d6d88 100644
66465--- a/include/linux/oprofile.h
66466+++ b/include/linux/oprofile.h
66467@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
66468 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
66469 char const * name, ulong * val);
66470
66471-/** Create a file for read-only access to an atomic_t. */
66472+/** Create a file for read-only access to an atomic_unchecked_t. */
66473 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
66474- char const * name, atomic_t * val);
66475+ char const * name, atomic_unchecked_t * val);
66476
66477 /** create a directory */
66478 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
66479diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
66480index 6bfb2faa..e5bc5e5 100644
66481--- a/include/linux/perf_event.h
66482+++ b/include/linux/perf_event.h
66483@@ -328,8 +328,8 @@ struct perf_event {
66484
66485 enum perf_event_active_state state;
66486 unsigned int attach_state;
66487- local64_t count;
66488- atomic64_t child_count;
66489+ local64_t count; /* PaX: fix it one day */
66490+ atomic64_unchecked_t child_count;
66491
66492 /*
66493 * These are the total time in nanoseconds that the event
66494@@ -380,8 +380,8 @@ struct perf_event {
66495 * These accumulate total time (in nanoseconds) that children
66496 * events have been enabled and running, respectively.
66497 */
66498- atomic64_t child_total_time_enabled;
66499- atomic64_t child_total_time_running;
66500+ atomic64_unchecked_t child_total_time_enabled;
66501+ atomic64_unchecked_t child_total_time_running;
66502
66503 /*
66504 * Protect attach/detach and child_list:
66505@@ -801,7 +801,7 @@ static inline void perf_event_task_tick(void) { }
66506 */
66507 #define perf_cpu_notifier(fn) \
66508 do { \
66509- static struct notifier_block fn##_nb __cpuinitdata = \
66510+ static struct notifier_block fn##_nb = \
66511 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
66512 unsigned long cpu = smp_processor_id(); \
66513 unsigned long flags; \
66514diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
66515index ad1a427..6419649 100644
66516--- a/include/linux/pipe_fs_i.h
66517+++ b/include/linux/pipe_fs_i.h
66518@@ -45,9 +45,9 @@ struct pipe_buffer {
66519 struct pipe_inode_info {
66520 wait_queue_head_t wait;
66521 unsigned int nrbufs, curbuf, buffers;
66522- unsigned int readers;
66523- unsigned int writers;
66524- unsigned int waiting_writers;
66525+ atomic_t readers;
66526+ atomic_t writers;
66527+ atomic_t waiting_writers;
66528 unsigned int r_counter;
66529 unsigned int w_counter;
66530 struct page *tmp_page;
66531diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
66532index 5f28cae..3d23723 100644
66533--- a/include/linux/platform_data/usb-ehci-s5p.h
66534+++ b/include/linux/platform_data/usb-ehci-s5p.h
66535@@ -14,7 +14,7 @@
66536 struct s5p_ehci_platdata {
66537 int (*phy_init)(struct platform_device *pdev, int type);
66538 int (*phy_exit)(struct platform_device *pdev, int type);
66539-};
66540+} __no_const;
66541
66542 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
66543
66544diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
66545index f271860..6b3bec5 100644
66546--- a/include/linux/pm_runtime.h
66547+++ b/include/linux/pm_runtime.h
66548@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
66549
66550 static inline void pm_runtime_mark_last_busy(struct device *dev)
66551 {
66552- ACCESS_ONCE(dev->power.last_busy) = jiffies;
66553+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
66554 }
66555
66556 #else /* !CONFIG_PM_RUNTIME */
66557diff --git a/include/linux/poison.h b/include/linux/poison.h
66558index 2110a81..13a11bb 100644
66559--- a/include/linux/poison.h
66560+++ b/include/linux/poison.h
66561@@ -19,8 +19,8 @@
66562 * under normal circumstances, used to verify that nobody uses
66563 * non-initialized list entries.
66564 */
66565-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
66566-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
66567+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
66568+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
66569
66570 /********** include/linux/timer.h **********/
66571 /*
66572diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
66573index c0f44c2..1572583 100644
66574--- a/include/linux/power/smartreflex.h
66575+++ b/include/linux/power/smartreflex.h
66576@@ -238,7 +238,7 @@ struct omap_sr_class_data {
66577 int (*notify)(struct omap_sr *sr, u32 status);
66578 u8 notify_flags;
66579 u8 class_type;
66580-};
66581+} __do_const;
66582
66583 /**
66584 * struct omap_sr_nvalue_table - Smartreflex n-target value info
66585diff --git a/include/linux/printk.h b/include/linux/printk.h
66586index 9afc01e..92c32e8 100644
66587--- a/include/linux/printk.h
66588+++ b/include/linux/printk.h
66589@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
66590 extern int printk_needs_cpu(int cpu);
66591 extern void printk_tick(void);
66592
66593+extern int kptr_restrict;
66594+
66595 #ifdef CONFIG_PRINTK
66596 asmlinkage __printf(5, 0)
66597 int vprintk_emit(int facility, int level,
66598@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
66599
66600 extern int printk_delay_msec;
66601 extern int dmesg_restrict;
66602-extern int kptr_restrict;
66603
66604 void log_buf_kexec_setup(void);
66605 void __init setup_log_buf(int early);
66606diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
66607index 32676b3..8f7a182 100644
66608--- a/include/linux/proc_fs.h
66609+++ b/include/linux/proc_fs.h
66610@@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
66611 return proc_create_data(name, mode, parent, proc_fops, NULL);
66612 }
66613
66614+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
66615+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
66616+{
66617+#ifdef CONFIG_GRKERNSEC_PROC_USER
66618+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
66619+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66620+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
66621+#else
66622+ return proc_create_data(name, mode, parent, proc_fops, NULL);
66623+#endif
66624+}
66625+
66626 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
66627 umode_t mode, struct proc_dir_entry *base,
66628 read_proc_t *read_proc, void * data)
66629diff --git a/include/linux/random.h b/include/linux/random.h
66630index d984608..d6f0042 100644
66631--- a/include/linux/random.h
66632+++ b/include/linux/random.h
66633@@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
66634 u32 prandom_u32_state(struct rnd_state *);
66635 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
66636
66637+static inline unsigned long pax_get_random_long(void)
66638+{
66639+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
66640+}
66641+
66642 /*
66643 * Handle minimum values for seeds
66644 */
66645diff --git a/include/linux/reboot.h b/include/linux/reboot.h
66646index 23b3630..e1bc12b 100644
66647--- a/include/linux/reboot.h
66648+++ b/include/linux/reboot.h
66649@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
66650 * Architecture-specific implementations of sys_reboot commands.
66651 */
66652
66653-extern void machine_restart(char *cmd);
66654-extern void machine_halt(void);
66655-extern void machine_power_off(void);
66656+extern void machine_restart(char *cmd) __noreturn;
66657+extern void machine_halt(void) __noreturn;
66658+extern void machine_power_off(void) __noreturn;
66659
66660 extern void machine_shutdown(void);
66661 struct pt_regs;
66662@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
66663 */
66664
66665 extern void kernel_restart_prepare(char *cmd);
66666-extern void kernel_restart(char *cmd);
66667-extern void kernel_halt(void);
66668-extern void kernel_power_off(void);
66669+extern void kernel_restart(char *cmd) __noreturn;
66670+extern void kernel_halt(void) __noreturn;
66671+extern void kernel_power_off(void) __noreturn;
66672
66673 extern int C_A_D; /* for sysctl */
66674 void ctrl_alt_del(void);
66675@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
66676 * Emergency restart, callable from an interrupt handler.
66677 */
66678
66679-extern void emergency_restart(void);
66680+extern void emergency_restart(void) __noreturn;
66681 #include <asm/emergency-restart.h>
66682
66683 #endif /* _LINUX_REBOOT_H */
66684diff --git a/include/linux/regset.h b/include/linux/regset.h
66685index 8e0c9fe..ac4d221 100644
66686--- a/include/linux/regset.h
66687+++ b/include/linux/regset.h
66688@@ -161,7 +161,8 @@ struct user_regset {
66689 unsigned int align;
66690 unsigned int bias;
66691 unsigned int core_note_type;
66692-};
66693+} __do_const;
66694+typedef struct user_regset __no_const user_regset_no_const;
66695
66696 /**
66697 * struct user_regset_view - available regsets
66698diff --git a/include/linux/relay.h b/include/linux/relay.h
66699index 91cacc3..b55ff74 100644
66700--- a/include/linux/relay.h
66701+++ b/include/linux/relay.h
66702@@ -160,7 +160,7 @@ struct rchan_callbacks
66703 * The callback should return 0 if successful, negative if not.
66704 */
66705 int (*remove_buf_file)(struct dentry *dentry);
66706-};
66707+} __no_const;
66708
66709 /*
66710 * CONFIG_RELAY kernel API, kernel/relay.c
66711diff --git a/include/linux/rio.h b/include/linux/rio.h
66712index a3e7842..d973ca6 100644
66713--- a/include/linux/rio.h
66714+++ b/include/linux/rio.h
66715@@ -339,7 +339,7 @@ struct rio_ops {
66716 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
66717 u64 rstart, u32 size, u32 flags);
66718 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
66719-};
66720+} __no_const;
66721
66722 #define RIO_RESOURCE_MEM 0x00000100
66723 #define RIO_RESOURCE_DOORBELL 0x00000200
66724diff --git a/include/linux/rmap.h b/include/linux/rmap.h
66725index c20635c..2f5def4 100644
66726--- a/include/linux/rmap.h
66727+++ b/include/linux/rmap.h
66728@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
66729 void anon_vma_init(void); /* create anon_vma_cachep */
66730 int anon_vma_prepare(struct vm_area_struct *);
66731 void unlink_anon_vmas(struct vm_area_struct *);
66732-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
66733-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
66734+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
66735+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
66736
66737 static inline void anon_vma_merge(struct vm_area_struct *vma,
66738 struct vm_area_struct *next)
66739diff --git a/include/linux/sched.h b/include/linux/sched.h
66740index d211247..d64a165 100644
66741--- a/include/linux/sched.h
66742+++ b/include/linux/sched.h
66743@@ -61,6 +61,7 @@ struct bio_list;
66744 struct fs_struct;
66745 struct perf_event_context;
66746 struct blk_plug;
66747+struct linux_binprm;
66748
66749 /*
66750 * List of flags we want to share for kernel threads,
66751@@ -354,10 +355,23 @@ struct user_namespace;
66752 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
66753
66754 extern int sysctl_max_map_count;
66755+extern unsigned long sysctl_heap_stack_gap;
66756
66757 #include <linux/aio.h>
66758
66759 #ifdef CONFIG_MMU
66760+
66761+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
66762+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
66763+#else
66764+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
66765+{
66766+ return 0;
66767+}
66768+#endif
66769+
66770+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
66771+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
66772 extern void arch_pick_mmap_layout(struct mm_struct *mm);
66773 extern unsigned long
66774 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
66775@@ -639,6 +653,17 @@ struct signal_struct {
66776 #ifdef CONFIG_TASKSTATS
66777 struct taskstats *stats;
66778 #endif
66779+
66780+#ifdef CONFIG_GRKERNSEC
66781+ u32 curr_ip;
66782+ u32 saved_ip;
66783+ u32 gr_saddr;
66784+ u32 gr_daddr;
66785+ u16 gr_sport;
66786+ u16 gr_dport;
66787+ u8 used_accept:1;
66788+#endif
66789+
66790 #ifdef CONFIG_AUDIT
66791 unsigned audit_tty;
66792 struct tty_audit_buf *tty_audit_buf;
66793@@ -717,6 +742,11 @@ struct user_struct {
66794 struct key *session_keyring; /* UID's default session keyring */
66795 #endif
66796
66797+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66798+ unsigned int banned;
66799+ unsigned long ban_expires;
66800+#endif
66801+
66802 /* Hash table maintenance information */
66803 struct hlist_node uidhash_node;
66804 kuid_t uid;
66805@@ -1360,8 +1390,8 @@ struct task_struct {
66806 struct list_head thread_group;
66807
66808 struct completion *vfork_done; /* for vfork() */
66809- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
66810- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66811+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
66812+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66813
66814 cputime_t utime, stime, utimescaled, stimescaled;
66815 cputime_t gtime;
66816@@ -1377,11 +1407,6 @@ struct task_struct {
66817 struct task_cputime cputime_expires;
66818 struct list_head cpu_timers[3];
66819
66820-/* process credentials */
66821- const struct cred __rcu *real_cred; /* objective and real subjective task
66822- * credentials (COW) */
66823- const struct cred __rcu *cred; /* effective (overridable) subjective task
66824- * credentials (COW) */
66825 char comm[TASK_COMM_LEN]; /* executable name excluding path
66826 - access with [gs]et_task_comm (which lock
66827 it with task_lock())
66828@@ -1398,6 +1423,10 @@ struct task_struct {
66829 #endif
66830 /* CPU-specific state of this task */
66831 struct thread_struct thread;
66832+/* thread_info moved to task_struct */
66833+#ifdef CONFIG_X86
66834+ struct thread_info tinfo;
66835+#endif
66836 /* filesystem information */
66837 struct fs_struct *fs;
66838 /* open file information */
66839@@ -1471,6 +1500,10 @@ struct task_struct {
66840 gfp_t lockdep_reclaim_gfp;
66841 #endif
66842
66843+/* process credentials */
66844+ const struct cred __rcu *real_cred; /* objective and real subjective task
66845+ * credentials (COW) */
66846+
66847 /* journalling filesystem info */
66848 void *journal_info;
66849
66850@@ -1509,6 +1542,10 @@ struct task_struct {
66851 /* cg_list protected by css_set_lock and tsk->alloc_lock */
66852 struct list_head cg_list;
66853 #endif
66854+
66855+ const struct cred __rcu *cred; /* effective (overridable) subjective task
66856+ * credentials (COW) */
66857+
66858 #ifdef CONFIG_FUTEX
66859 struct robust_list_head __user *robust_list;
66860 #ifdef CONFIG_COMPAT
66861@@ -1605,8 +1642,74 @@ struct task_struct {
66862 #ifdef CONFIG_UPROBES
66863 struct uprobe_task *utask;
66864 #endif
66865+
66866+#ifdef CONFIG_GRKERNSEC
66867+ /* grsecurity */
66868+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66869+ u64 exec_id;
66870+#endif
66871+#ifdef CONFIG_GRKERNSEC_SETXID
66872+ const struct cred *delayed_cred;
66873+#endif
66874+ struct dentry *gr_chroot_dentry;
66875+ struct acl_subject_label *acl;
66876+ struct acl_role_label *role;
66877+ struct file *exec_file;
66878+ unsigned long brute_expires;
66879+ u16 acl_role_id;
66880+ /* is this the task that authenticated to the special role */
66881+ u8 acl_sp_role;
66882+ u8 is_writable;
66883+ u8 brute;
66884+ u8 gr_is_chrooted;
66885+#endif
66886+
66887 };
66888
66889+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
66890+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
66891+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
66892+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
66893+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
66894+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
66895+
66896+#ifdef CONFIG_PAX_SOFTMODE
66897+extern int pax_softmode;
66898+#endif
66899+
66900+extern int pax_check_flags(unsigned long *);
66901+
66902+/* if tsk != current then task_lock must be held on it */
66903+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66904+static inline unsigned long pax_get_flags(struct task_struct *tsk)
66905+{
66906+ if (likely(tsk->mm))
66907+ return tsk->mm->pax_flags;
66908+ else
66909+ return 0UL;
66910+}
66911+
66912+/* if tsk != current then task_lock must be held on it */
66913+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
66914+{
66915+ if (likely(tsk->mm)) {
66916+ tsk->mm->pax_flags = flags;
66917+ return 0;
66918+ }
66919+ return -EINVAL;
66920+}
66921+#endif
66922+
66923+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
66924+extern void pax_set_initial_flags(struct linux_binprm *bprm);
66925+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
66926+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
66927+#endif
66928+
66929+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
66930+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
66931+extern void pax_report_refcount_overflow(struct pt_regs *regs);
66932+
66933 /* Future-safe accessor for struct task_struct's cpus_allowed. */
66934 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
66935
66936@@ -2155,7 +2258,9 @@ void yield(void);
66937 extern struct exec_domain default_exec_domain;
66938
66939 union thread_union {
66940+#ifndef CONFIG_X86
66941 struct thread_info thread_info;
66942+#endif
66943 unsigned long stack[THREAD_SIZE/sizeof(long)];
66944 };
66945
66946@@ -2188,6 +2293,7 @@ extern struct pid_namespace init_pid_ns;
66947 */
66948
66949 extern struct task_struct *find_task_by_vpid(pid_t nr);
66950+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
66951 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
66952 struct pid_namespace *ns);
66953
66954@@ -2344,7 +2450,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
66955 extern void exit_itimers(struct signal_struct *);
66956 extern void flush_itimer_signals(void);
66957
66958-extern void do_group_exit(int);
66959+extern __noreturn void do_group_exit(int);
66960
66961 extern int allow_signal(int);
66962 extern int disallow_signal(int);
66963@@ -2545,9 +2651,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
66964
66965 #endif
66966
66967-static inline int object_is_on_stack(void *obj)
66968+static inline int object_starts_on_stack(void *obj)
66969 {
66970- void *stack = task_stack_page(current);
66971+ const void *stack = task_stack_page(current);
66972
66973 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
66974 }
66975diff --git a/include/linux/security.h b/include/linux/security.h
66976index eee7478..290f7ba 100644
66977--- a/include/linux/security.h
66978+++ b/include/linux/security.h
66979@@ -26,6 +26,7 @@
66980 #include <linux/capability.h>
66981 #include <linux/slab.h>
66982 #include <linux/err.h>
66983+#include <linux/grsecurity.h>
66984
66985 struct linux_binprm;
66986 struct cred;
66987diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
66988index 68a04a3..866e6a1 100644
66989--- a/include/linux/seq_file.h
66990+++ b/include/linux/seq_file.h
66991@@ -26,6 +26,9 @@ struct seq_file {
66992 struct mutex lock;
66993 const struct seq_operations *op;
66994 int poll_event;
66995+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66996+ u64 exec_id;
66997+#endif
66998 #ifdef CONFIG_USER_NS
66999 struct user_namespace *user_ns;
67000 #endif
67001@@ -38,6 +41,7 @@ struct seq_operations {
67002 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
67003 int (*show) (struct seq_file *m, void *v);
67004 };
67005+typedef struct seq_operations __no_const seq_operations_no_const;
67006
67007 #define SEQ_SKIP 1
67008
67009diff --git a/include/linux/shm.h b/include/linux/shm.h
67010index 429c199..4d42e38 100644
67011--- a/include/linux/shm.h
67012+++ b/include/linux/shm.h
67013@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
67014
67015 /* The task created the shm object. NULL if the task is dead. */
67016 struct task_struct *shm_creator;
67017+#ifdef CONFIG_GRKERNSEC
67018+ time_t shm_createtime;
67019+ pid_t shm_lapid;
67020+#endif
67021 };
67022
67023 /* shm_mode upper byte flags */
67024diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
67025index 320e976..fd52553 100644
67026--- a/include/linux/skbuff.h
67027+++ b/include/linux/skbuff.h
67028@@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
67029 extern struct sk_buff *__alloc_skb(unsigned int size,
67030 gfp_t priority, int flags, int node);
67031 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
67032-static inline struct sk_buff *alloc_skb(unsigned int size,
67033+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
67034 gfp_t priority)
67035 {
67036 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
67037@@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
67038 */
67039 static inline int skb_queue_empty(const struct sk_buff_head *list)
67040 {
67041- return list->next == (struct sk_buff *)list;
67042+ return list->next == (const struct sk_buff *)list;
67043 }
67044
67045 /**
67046@@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
67047 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
67048 const struct sk_buff *skb)
67049 {
67050- return skb->next == (struct sk_buff *)list;
67051+ return skb->next == (const struct sk_buff *)list;
67052 }
67053
67054 /**
67055@@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
67056 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
67057 const struct sk_buff *skb)
67058 {
67059- return skb->prev == (struct sk_buff *)list;
67060+ return skb->prev == (const struct sk_buff *)list;
67061 }
67062
67063 /**
67064@@ -1722,7 +1722,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
67065 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
67066 */
67067 #ifndef NET_SKB_PAD
67068-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
67069+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
67070 #endif
67071
67072 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
67073@@ -2300,7 +2300,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
67074 int noblock, int *err);
67075 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
67076 struct poll_table_struct *wait);
67077-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
67078+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
67079 int offset, struct iovec *to,
67080 int size);
67081 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
67082diff --git a/include/linux/slab.h b/include/linux/slab.h
67083index 5d168d7..720bff3 100644
67084--- a/include/linux/slab.h
67085+++ b/include/linux/slab.h
67086@@ -12,13 +12,20 @@
67087 #include <linux/gfp.h>
67088 #include <linux/types.h>
67089 #include <linux/workqueue.h>
67090-
67091+#include <linux/err.h>
67092
67093 /*
67094 * Flags to pass to kmem_cache_create().
67095 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
67096 */
67097 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
67098+
67099+#ifdef CONFIG_PAX_USERCOPY_SLABS
67100+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
67101+#else
67102+#define SLAB_USERCOPY 0x00000000UL
67103+#endif
67104+
67105 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
67106 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
67107 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
67108@@ -89,10 +96,13 @@
67109 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
67110 * Both make kfree a no-op.
67111 */
67112-#define ZERO_SIZE_PTR ((void *)16)
67113+#define ZERO_SIZE_PTR \
67114+({ \
67115+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
67116+ (void *)(-MAX_ERRNO-1L); \
67117+})
67118
67119-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
67120- (unsigned long)ZERO_SIZE_PTR)
67121+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
67122
67123 /*
67124 * Common fields provided in kmem_cache by all slab allocators
67125@@ -112,7 +122,7 @@ struct kmem_cache {
67126 unsigned int align; /* Alignment as calculated */
67127 unsigned long flags; /* Active flags on the slab */
67128 const char *name; /* Slab name for sysfs */
67129- int refcount; /* Use counter */
67130+ atomic_t refcount; /* Use counter */
67131 void (*ctor)(void *); /* Called on object slot creation */
67132 struct list_head list; /* List of all slab caches on the system */
67133 };
67134@@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
67135 void kfree(const void *);
67136 void kzfree(const void *);
67137 size_t ksize(const void *);
67138+const char *check_heap_object(const void *ptr, unsigned long n);
67139+bool is_usercopy_object(const void *ptr);
67140
67141 /*
67142 * Allocator specific definitions. These are mainly used to establish optimized
67143@@ -311,6 +323,7 @@ size_t ksize(const void *);
67144 * for general use, and so are not documented here. For a full list of
67145 * potential flags, always refer to linux/gfp.h.
67146 */
67147+
67148 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
67149 {
67150 if (size != 0 && n > SIZE_MAX / size)
67151@@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
67152 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
67153 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
67154 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
67155-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
67156+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
67157 #define kmalloc_track_caller(size, flags) \
67158 __kmalloc_track_caller(size, flags, _RET_IP_)
67159 #else
67160@@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
67161 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
67162 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
67163 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
67164-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
67165+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
67166 #define kmalloc_node_track_caller(size, flags, node) \
67167 __kmalloc_node_track_caller(size, flags, node, \
67168 _RET_IP_)
67169diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
67170index 8bb6e0e..8eb0dbe 100644
67171--- a/include/linux/slab_def.h
67172+++ b/include/linux/slab_def.h
67173@@ -52,7 +52,7 @@ struct kmem_cache {
67174 /* 4) cache creation/removal */
67175 const char *name;
67176 struct list_head list;
67177- int refcount;
67178+ atomic_t refcount;
67179 int object_size;
67180 int align;
67181
67182@@ -68,10 +68,10 @@ struct kmem_cache {
67183 unsigned long node_allocs;
67184 unsigned long node_frees;
67185 unsigned long node_overflow;
67186- atomic_t allochit;
67187- atomic_t allocmiss;
67188- atomic_t freehit;
67189- atomic_t freemiss;
67190+ atomic_unchecked_t allochit;
67191+ atomic_unchecked_t allocmiss;
67192+ atomic_unchecked_t freehit;
67193+ atomic_unchecked_t freemiss;
67194
67195 /*
67196 * If debugging is enabled, then the allocator can add additional
67197@@ -111,11 +111,16 @@ struct cache_sizes {
67198 #ifdef CONFIG_ZONE_DMA
67199 struct kmem_cache *cs_dmacachep;
67200 #endif
67201+
67202+#ifdef CONFIG_PAX_USERCOPY_SLABS
67203+ struct kmem_cache *cs_usercopycachep;
67204+#endif
67205+
67206 };
67207 extern struct cache_sizes malloc_sizes[];
67208
67209 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
67210-void *__kmalloc(size_t size, gfp_t flags);
67211+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
67212
67213 #ifdef CONFIG_TRACING
67214 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
67215@@ -152,6 +157,13 @@ found:
67216 cachep = malloc_sizes[i].cs_dmacachep;
67217 else
67218 #endif
67219+
67220+#ifdef CONFIG_PAX_USERCOPY_SLABS
67221+ if (flags & GFP_USERCOPY)
67222+ cachep = malloc_sizes[i].cs_usercopycachep;
67223+ else
67224+#endif
67225+
67226 cachep = malloc_sizes[i].cs_cachep;
67227
67228 ret = kmem_cache_alloc_trace(cachep, flags, size);
67229@@ -162,7 +174,7 @@ found:
67230 }
67231
67232 #ifdef CONFIG_NUMA
67233-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
67234+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67235 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
67236
67237 #ifdef CONFIG_TRACING
67238@@ -205,6 +217,13 @@ found:
67239 cachep = malloc_sizes[i].cs_dmacachep;
67240 else
67241 #endif
67242+
67243+#ifdef CONFIG_PAX_USERCOPY_SLABS
67244+ if (flags & GFP_USERCOPY)
67245+ cachep = malloc_sizes[i].cs_usercopycachep;
67246+ else
67247+#endif
67248+
67249 cachep = malloc_sizes[i].cs_cachep;
67250
67251 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
67252diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
67253index f28e14a..7831211 100644
67254--- a/include/linux/slob_def.h
67255+++ b/include/linux/slob_def.h
67256@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
67257 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
67258 }
67259
67260-void *__kmalloc_node(size_t size, gfp_t flags, int node);
67261+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67262
67263 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
67264 {
67265@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
67266 return __kmalloc_node(size, flags, NUMA_NO_NODE);
67267 }
67268
67269-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
67270+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
67271 {
67272 return kmalloc(size, flags);
67273 }
67274diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
67275index 9db4825..ed42fb5 100644
67276--- a/include/linux/slub_def.h
67277+++ b/include/linux/slub_def.h
67278@@ -91,7 +91,7 @@ struct kmem_cache {
67279 struct kmem_cache_order_objects max;
67280 struct kmem_cache_order_objects min;
67281 gfp_t allocflags; /* gfp flags to use on each alloc */
67282- int refcount; /* Refcount for slab cache destroy */
67283+ atomic_t refcount; /* Refcount for slab cache destroy */
67284 void (*ctor)(void *);
67285 int inuse; /* Offset to metadata */
67286 int align; /* Alignment */
67287@@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
67288 * Sorry that the following has to be that ugly but some versions of GCC
67289 * have trouble with constant propagation and loops.
67290 */
67291-static __always_inline int kmalloc_index(size_t size)
67292+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
67293 {
67294 if (!size)
67295 return 0;
67296@@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
67297 }
67298
67299 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
67300-void *__kmalloc(size_t size, gfp_t flags);
67301+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
67302
67303 static __always_inline void *
67304 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
67305@@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
67306 }
67307 #endif
67308
67309-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
67310+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
67311 {
67312 unsigned int order = get_order(size);
67313 return kmalloc_order_trace(size, flags, order);
67314@@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
67315 }
67316
67317 #ifdef CONFIG_NUMA
67318-void *__kmalloc_node(size_t size, gfp_t flags, int node);
67319+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67320 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
67321
67322 #ifdef CONFIG_TRACING
67323diff --git a/include/linux/sonet.h b/include/linux/sonet.h
67324index 680f9a3..f13aeb0 100644
67325--- a/include/linux/sonet.h
67326+++ b/include/linux/sonet.h
67327@@ -7,7 +7,7 @@
67328 #include <uapi/linux/sonet.h>
67329
67330 struct k_sonet_stats {
67331-#define __HANDLE_ITEM(i) atomic_t i
67332+#define __HANDLE_ITEM(i) atomic_unchecked_t i
67333 __SONET_ITEMS
67334 #undef __HANDLE_ITEM
67335 };
67336diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
67337index 34206b8..f019e06 100644
67338--- a/include/linux/sunrpc/clnt.h
67339+++ b/include/linux/sunrpc/clnt.h
67340@@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
67341 {
67342 switch (sap->sa_family) {
67343 case AF_INET:
67344- return ntohs(((struct sockaddr_in *)sap)->sin_port);
67345+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
67346 case AF_INET6:
67347- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
67348+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
67349 }
67350 return 0;
67351 }
67352@@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
67353 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
67354 const struct sockaddr *src)
67355 {
67356- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
67357+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
67358 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
67359
67360 dsin->sin_family = ssin->sin_family;
67361@@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
67362 if (sa->sa_family != AF_INET6)
67363 return 0;
67364
67365- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
67366+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
67367 }
67368
67369 #endif /* __KERNEL__ */
67370diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
67371index 0b8e3e6..33e0a01 100644
67372--- a/include/linux/sunrpc/svc_rdma.h
67373+++ b/include/linux/sunrpc/svc_rdma.h
67374@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
67375 extern unsigned int svcrdma_max_requests;
67376 extern unsigned int svcrdma_max_req_size;
67377
67378-extern atomic_t rdma_stat_recv;
67379-extern atomic_t rdma_stat_read;
67380-extern atomic_t rdma_stat_write;
67381-extern atomic_t rdma_stat_sq_starve;
67382-extern atomic_t rdma_stat_rq_starve;
67383-extern atomic_t rdma_stat_rq_poll;
67384-extern atomic_t rdma_stat_rq_prod;
67385-extern atomic_t rdma_stat_sq_poll;
67386-extern atomic_t rdma_stat_sq_prod;
67387+extern atomic_unchecked_t rdma_stat_recv;
67388+extern atomic_unchecked_t rdma_stat_read;
67389+extern atomic_unchecked_t rdma_stat_write;
67390+extern atomic_unchecked_t rdma_stat_sq_starve;
67391+extern atomic_unchecked_t rdma_stat_rq_starve;
67392+extern atomic_unchecked_t rdma_stat_rq_poll;
67393+extern atomic_unchecked_t rdma_stat_rq_prod;
67394+extern atomic_unchecked_t rdma_stat_sq_poll;
67395+extern atomic_unchecked_t rdma_stat_sq_prod;
67396
67397 #define RPCRDMA_VERSION 1
67398
67399diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
67400index 14a8ff2..21fe4c7 100644
67401--- a/include/linux/sysctl.h
67402+++ b/include/linux/sysctl.h
67403@@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
67404
67405 extern int proc_dostring(struct ctl_table *, int,
67406 void __user *, size_t *, loff_t *);
67407+extern int proc_dostring_modpriv(struct ctl_table *, int,
67408+ void __user *, size_t *, loff_t *);
67409 extern int proc_dointvec(struct ctl_table *, int,
67410 void __user *, size_t *, loff_t *);
67411 extern int proc_dointvec_minmax(struct ctl_table *, int,
67412diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
67413index 7faf933..c1ad32c 100644
67414--- a/include/linux/sysrq.h
67415+++ b/include/linux/sysrq.h
67416@@ -15,6 +15,7 @@
67417 #define _LINUX_SYSRQ_H
67418
67419 #include <linux/errno.h>
67420+#include <linux/compiler.h>
67421 #include <linux/types.h>
67422
67423 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
67424@@ -36,7 +37,7 @@ struct sysrq_key_op {
67425 char *help_msg;
67426 char *action_msg;
67427 int enable_mask;
67428-};
67429+} __do_const;
67430
67431 #ifdef CONFIG_MAGIC_SYSRQ
67432
67433diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
67434index e7e0473..39b7b52 100644
67435--- a/include/linux/thread_info.h
67436+++ b/include/linux/thread_info.h
67437@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
67438 #error "no set_restore_sigmask() provided and default one won't work"
67439 #endif
67440
67441+extern void __check_object_size(const void *ptr, unsigned long n, bool to);
67442+static inline void check_object_size(const void *ptr, unsigned long n, bool to)
67443+{
67444+#ifndef CONFIG_PAX_USERCOPY_DEBUG
67445+ if (!__builtin_constant_p(n))
67446+#endif
67447+ __check_object_size(ptr, n, to);
67448+}
67449+
67450 #endif /* __KERNEL__ */
67451
67452 #endif /* _LINUX_THREAD_INFO_H */
67453diff --git a/include/linux/tty.h b/include/linux/tty.h
67454index 8db1b56..c16a040 100644
67455--- a/include/linux/tty.h
67456+++ b/include/linux/tty.h
67457@@ -194,7 +194,7 @@ struct tty_port {
67458 const struct tty_port_operations *ops; /* Port operations */
67459 spinlock_t lock; /* Lock protecting tty field */
67460 int blocked_open; /* Waiting to open */
67461- int count; /* Usage count */
67462+ atomic_t count; /* Usage count */
67463 wait_queue_head_t open_wait; /* Open waiters */
67464 wait_queue_head_t close_wait; /* Close waiters */
67465 wait_queue_head_t delta_msr_wait; /* Modem status change */
67466@@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
67467 struct tty_struct *tty, struct file *filp);
67468 static inline int tty_port_users(struct tty_port *port)
67469 {
67470- return port->count + port->blocked_open;
67471+ return atomic_read(&port->count) + port->blocked_open;
67472 }
67473
67474 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
67475diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
67476index dd976cf..e272742 100644
67477--- a/include/linux/tty_driver.h
67478+++ b/include/linux/tty_driver.h
67479@@ -284,7 +284,7 @@ struct tty_operations {
67480 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
67481 #endif
67482 const struct file_operations *proc_fops;
67483-};
67484+} __do_const;
67485
67486 struct tty_driver {
67487 int magic; /* magic number for this structure */
67488diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
67489index fb79dd8d..07d4773 100644
67490--- a/include/linux/tty_ldisc.h
67491+++ b/include/linux/tty_ldisc.h
67492@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
67493
67494 struct module *owner;
67495
67496- int refcount;
67497+ atomic_t refcount;
67498 };
67499
67500 struct tty_ldisc {
67501diff --git a/include/linux/types.h b/include/linux/types.h
67502index 4d118ba..c3ee9bf 100644
67503--- a/include/linux/types.h
67504+++ b/include/linux/types.h
67505@@ -176,10 +176,26 @@ typedef struct {
67506 int counter;
67507 } atomic_t;
67508
67509+#ifdef CONFIG_PAX_REFCOUNT
67510+typedef struct {
67511+ int counter;
67512+} atomic_unchecked_t;
67513+#else
67514+typedef atomic_t atomic_unchecked_t;
67515+#endif
67516+
67517 #ifdef CONFIG_64BIT
67518 typedef struct {
67519 long counter;
67520 } atomic64_t;
67521+
67522+#ifdef CONFIG_PAX_REFCOUNT
67523+typedef struct {
67524+ long counter;
67525+} atomic64_unchecked_t;
67526+#else
67527+typedef atomic64_t atomic64_unchecked_t;
67528+#endif
67529 #endif
67530
67531 struct list_head {
67532diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
67533index 5ca0951..ab496a5 100644
67534--- a/include/linux/uaccess.h
67535+++ b/include/linux/uaccess.h
67536@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
67537 long ret; \
67538 mm_segment_t old_fs = get_fs(); \
67539 \
67540- set_fs(KERNEL_DS); \
67541 pagefault_disable(); \
67542- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
67543- pagefault_enable(); \
67544+ set_fs(KERNEL_DS); \
67545+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
67546 set_fs(old_fs); \
67547+ pagefault_enable(); \
67548 ret; \
67549 })
67550
67551diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
67552index 99c1b4d..bb94261 100644
67553--- a/include/linux/unaligned/access_ok.h
67554+++ b/include/linux/unaligned/access_ok.h
67555@@ -6,32 +6,32 @@
67556
67557 static inline u16 get_unaligned_le16(const void *p)
67558 {
67559- return le16_to_cpup((__le16 *)p);
67560+ return le16_to_cpup((const __le16 *)p);
67561 }
67562
67563 static inline u32 get_unaligned_le32(const void *p)
67564 {
67565- return le32_to_cpup((__le32 *)p);
67566+ return le32_to_cpup((const __le32 *)p);
67567 }
67568
67569 static inline u64 get_unaligned_le64(const void *p)
67570 {
67571- return le64_to_cpup((__le64 *)p);
67572+ return le64_to_cpup((const __le64 *)p);
67573 }
67574
67575 static inline u16 get_unaligned_be16(const void *p)
67576 {
67577- return be16_to_cpup((__be16 *)p);
67578+ return be16_to_cpup((const __be16 *)p);
67579 }
67580
67581 static inline u32 get_unaligned_be32(const void *p)
67582 {
67583- return be32_to_cpup((__be32 *)p);
67584+ return be32_to_cpup((const __be32 *)p);
67585 }
67586
67587 static inline u64 get_unaligned_be64(const void *p)
67588 {
67589- return be64_to_cpup((__be64 *)p);
67590+ return be64_to_cpup((const __be64 *)p);
67591 }
67592
67593 static inline void put_unaligned_le16(u16 val, void *p)
67594diff --git a/include/linux/usb.h b/include/linux/usb.h
67595index 4d22d0f..ac43c2f 100644
67596--- a/include/linux/usb.h
67597+++ b/include/linux/usb.h
67598@@ -554,7 +554,7 @@ struct usb_device {
67599 int maxchild;
67600
67601 u32 quirks;
67602- atomic_t urbnum;
67603+ atomic_unchecked_t urbnum;
67604
67605 unsigned long active_duration;
67606
67607diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
67608index c5d36c6..108f4f9 100644
67609--- a/include/linux/usb/renesas_usbhs.h
67610+++ b/include/linux/usb/renesas_usbhs.h
67611@@ -39,7 +39,7 @@ enum {
67612 */
67613 struct renesas_usbhs_driver_callback {
67614 int (*notify_hotplug)(struct platform_device *pdev);
67615-};
67616+} __no_const;
67617
67618 /*
67619 * callback functions for platform
67620diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
67621index b9bd2e6..4ce0093 100644
67622--- a/include/linux/user_namespace.h
67623+++ b/include/linux/user_namespace.h
67624@@ -21,7 +21,7 @@ struct user_namespace {
67625 struct uid_gid_map uid_map;
67626 struct uid_gid_map gid_map;
67627 struct uid_gid_map projid_map;
67628- struct kref kref;
67629+ atomic_t count;
67630 struct user_namespace *parent;
67631 kuid_t owner;
67632 kgid_t group;
67633@@ -35,18 +35,18 @@ extern struct user_namespace init_user_ns;
67634 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
67635 {
67636 if (ns)
67637- kref_get(&ns->kref);
67638+ atomic_inc(&ns->count);
67639 return ns;
67640 }
67641
67642 extern int create_user_ns(struct cred *new);
67643 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
67644-extern void free_user_ns(struct kref *kref);
67645+extern void free_user_ns(struct user_namespace *ns);
67646
67647 static inline void put_user_ns(struct user_namespace *ns)
67648 {
67649- if (ns)
67650- kref_put(&ns->kref, free_user_ns);
67651+ if (ns && atomic_dec_and_test(&ns->count))
67652+ free_user_ns(ns);
67653 }
67654
67655 struct seq_operations;
67656diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
67657index 6f8fbcf..8259001 100644
67658--- a/include/linux/vermagic.h
67659+++ b/include/linux/vermagic.h
67660@@ -25,9 +25,35 @@
67661 #define MODULE_ARCH_VERMAGIC ""
67662 #endif
67663
67664+#ifdef CONFIG_PAX_REFCOUNT
67665+#define MODULE_PAX_REFCOUNT "REFCOUNT "
67666+#else
67667+#define MODULE_PAX_REFCOUNT ""
67668+#endif
67669+
67670+#ifdef CONSTIFY_PLUGIN
67671+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
67672+#else
67673+#define MODULE_CONSTIFY_PLUGIN ""
67674+#endif
67675+
67676+#ifdef STACKLEAK_PLUGIN
67677+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
67678+#else
67679+#define MODULE_STACKLEAK_PLUGIN ""
67680+#endif
67681+
67682+#ifdef CONFIG_GRKERNSEC
67683+#define MODULE_GRSEC "GRSEC "
67684+#else
67685+#define MODULE_GRSEC ""
67686+#endif
67687+
67688 #define VERMAGIC_STRING \
67689 UTS_RELEASE " " \
67690 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
67691 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
67692- MODULE_ARCH_VERMAGIC
67693+ MODULE_ARCH_VERMAGIC \
67694+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
67695+ MODULE_GRSEC
67696
67697diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
67698index 6071e91..ca6a489 100644
67699--- a/include/linux/vmalloc.h
67700+++ b/include/linux/vmalloc.h
67701@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
67702 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
67703 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
67704 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
67705+
67706+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
67707+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
67708+#endif
67709+
67710 /* bits [20..32] reserved for arch specific ioremap internals */
67711
67712 /*
67713@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
67714 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
67715 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
67716 unsigned long start, unsigned long end, gfp_t gfp_mask,
67717- pgprot_t prot, int node, const void *caller);
67718+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
67719 extern void vfree(const void *addr);
67720
67721 extern void *vmap(struct page **pages, unsigned int count,
67722@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
67723 extern void free_vm_area(struct vm_struct *area);
67724
67725 /* for /dev/kmem */
67726-extern long vread(char *buf, char *addr, unsigned long count);
67727-extern long vwrite(char *buf, char *addr, unsigned long count);
67728+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
67729+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
67730
67731 /*
67732 * Internals. Dont't use..
67733diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
67734index a13291f..af51fa3 100644
67735--- a/include/linux/vmstat.h
67736+++ b/include/linux/vmstat.h
67737@@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
67738 /*
67739 * Zone based page accounting with per cpu differentials.
67740 */
67741-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67742+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67743
67744 static inline void zone_page_state_add(long x, struct zone *zone,
67745 enum zone_stat_item item)
67746 {
67747- atomic_long_add(x, &zone->vm_stat[item]);
67748- atomic_long_add(x, &vm_stat[item]);
67749+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
67750+ atomic_long_add_unchecked(x, &vm_stat[item]);
67751 }
67752
67753 static inline unsigned long global_page_state(enum zone_stat_item item)
67754 {
67755- long x = atomic_long_read(&vm_stat[item]);
67756+ long x = atomic_long_read_unchecked(&vm_stat[item]);
67757 #ifdef CONFIG_SMP
67758 if (x < 0)
67759 x = 0;
67760@@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
67761 static inline unsigned long zone_page_state(struct zone *zone,
67762 enum zone_stat_item item)
67763 {
67764- long x = atomic_long_read(&zone->vm_stat[item]);
67765+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
67766 #ifdef CONFIG_SMP
67767 if (x < 0)
67768 x = 0;
67769@@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
67770 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
67771 enum zone_stat_item item)
67772 {
67773- long x = atomic_long_read(&zone->vm_stat[item]);
67774+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
67775
67776 #ifdef CONFIG_SMP
67777 int cpu;
67778@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
67779
67780 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
67781 {
67782- atomic_long_inc(&zone->vm_stat[item]);
67783- atomic_long_inc(&vm_stat[item]);
67784+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
67785+ atomic_long_inc_unchecked(&vm_stat[item]);
67786 }
67787
67788 static inline void __inc_zone_page_state(struct page *page,
67789@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
67790
67791 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
67792 {
67793- atomic_long_dec(&zone->vm_stat[item]);
67794- atomic_long_dec(&vm_stat[item]);
67795+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
67796+ atomic_long_dec_unchecked(&vm_stat[item]);
67797 }
67798
67799 static inline void __dec_zone_page_state(struct page *page,
67800diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
67801index 95d1c91..6798cca 100644
67802--- a/include/media/v4l2-dev.h
67803+++ b/include/media/v4l2-dev.h
67804@@ -76,7 +76,7 @@ struct v4l2_file_operations {
67805 int (*mmap) (struct file *, struct vm_area_struct *);
67806 int (*open) (struct file *);
67807 int (*release) (struct file *);
67808-};
67809+} __do_const;
67810
67811 /*
67812 * Newer version of video_device, handled by videodev2.c
67813diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
67814index 4118ad1..cb7e25f 100644
67815--- a/include/media/v4l2-ioctl.h
67816+++ b/include/media/v4l2-ioctl.h
67817@@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
67818 bool valid_prio, int cmd, void *arg);
67819 };
67820
67821-
67822 /* v4l debugging and diagnostics */
67823
67824 /* Debug bitmask flags to be used on V4L2 */
67825diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
67826index 9e5425b..8136ffc 100644
67827--- a/include/net/caif/cfctrl.h
67828+++ b/include/net/caif/cfctrl.h
67829@@ -52,7 +52,7 @@ struct cfctrl_rsp {
67830 void (*radioset_rsp)(void);
67831 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
67832 struct cflayer *client_layer);
67833-};
67834+} __no_const;
67835
67836 /* Link Setup Parameters for CAIF-Links. */
67837 struct cfctrl_link_param {
67838@@ -101,8 +101,8 @@ struct cfctrl_request_info {
67839 struct cfctrl {
67840 struct cfsrvl serv;
67841 struct cfctrl_rsp res;
67842- atomic_t req_seq_no;
67843- atomic_t rsp_seq_no;
67844+ atomic_unchecked_t req_seq_no;
67845+ atomic_unchecked_t rsp_seq_no;
67846 struct list_head list;
67847 /* Protects from simultaneous access to first_req list */
67848 spinlock_t info_list_lock;
67849diff --git a/include/net/flow.h b/include/net/flow.h
67850index 628e11b..4c475df 100644
67851--- a/include/net/flow.h
67852+++ b/include/net/flow.h
67853@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
67854
67855 extern void flow_cache_flush(void);
67856 extern void flow_cache_flush_deferred(void);
67857-extern atomic_t flow_cache_genid;
67858+extern atomic_unchecked_t flow_cache_genid;
67859
67860 #endif
67861diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
67862index e5062c9..48a9a4b 100644
67863--- a/include/net/gro_cells.h
67864+++ b/include/net/gro_cells.h
67865@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
67866 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
67867
67868 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
67869- atomic_long_inc(&dev->rx_dropped);
67870+ atomic_long_inc_unchecked(&dev->rx_dropped);
67871 kfree_skb(skb);
67872 return;
67873 }
67874@@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
67875 int i;
67876
67877 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
67878- gcells->cells = kcalloc(sizeof(struct gro_cell),
67879- gcells->gro_cells_mask + 1,
67880+ gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
67881+ sizeof(struct gro_cell),
67882 GFP_KERNEL);
67883 if (!gcells->cells)
67884 return -ENOMEM;
67885diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
67886index 1832927..ce39aea 100644
67887--- a/include/net/inet_connection_sock.h
67888+++ b/include/net/inet_connection_sock.h
67889@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
67890 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
67891 int (*bind_conflict)(const struct sock *sk,
67892 const struct inet_bind_bucket *tb, bool relax);
67893-};
67894+} __do_const;
67895
67896 /** inet_connection_sock - INET connection oriented sock
67897 *
67898diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
67899index 53f464d..ba76aaa 100644
67900--- a/include/net/inetpeer.h
67901+++ b/include/net/inetpeer.h
67902@@ -47,8 +47,8 @@ struct inet_peer {
67903 */
67904 union {
67905 struct {
67906- atomic_t rid; /* Frag reception counter */
67907- atomic_t ip_id_count; /* IP ID for the next packet */
67908+ atomic_unchecked_t rid; /* Frag reception counter */
67909+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
67910 };
67911 struct rcu_head rcu;
67912 struct inet_peer *gc_next;
67913@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
67914 more++;
67915 inet_peer_refcheck(p);
67916 do {
67917- old = atomic_read(&p->ip_id_count);
67918+ old = atomic_read_unchecked(&p->ip_id_count);
67919 new = old + more;
67920 if (!new)
67921 new = 1;
67922- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
67923+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
67924 return new;
67925 }
67926
67927diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
67928index 9497be1..5a4fafe 100644
67929--- a/include/net/ip_fib.h
67930+++ b/include/net/ip_fib.h
67931@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
67932
67933 #define FIB_RES_SADDR(net, res) \
67934 ((FIB_RES_NH(res).nh_saddr_genid == \
67935- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
67936+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
67937 FIB_RES_NH(res).nh_saddr : \
67938 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
67939 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
67940diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
67941index 68c69d5..2ee192b 100644
67942--- a/include/net/ip_vs.h
67943+++ b/include/net/ip_vs.h
67944@@ -599,7 +599,7 @@ struct ip_vs_conn {
67945 struct ip_vs_conn *control; /* Master control connection */
67946 atomic_t n_control; /* Number of controlled ones */
67947 struct ip_vs_dest *dest; /* real server */
67948- atomic_t in_pkts; /* incoming packet counter */
67949+ atomic_unchecked_t in_pkts; /* incoming packet counter */
67950
67951 /* packet transmitter for different forwarding methods. If it
67952 mangles the packet, it must return NF_DROP or better NF_STOLEN,
67953@@ -737,7 +737,7 @@ struct ip_vs_dest {
67954 __be16 port; /* port number of the server */
67955 union nf_inet_addr addr; /* IP address of the server */
67956 volatile unsigned int flags; /* dest status flags */
67957- atomic_t conn_flags; /* flags to copy to conn */
67958+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
67959 atomic_t weight; /* server weight */
67960
67961 atomic_t refcnt; /* reference counter */
67962diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
67963index 80ffde3..968b0f4 100644
67964--- a/include/net/irda/ircomm_tty.h
67965+++ b/include/net/irda/ircomm_tty.h
67966@@ -35,6 +35,7 @@
67967 #include <linux/termios.h>
67968 #include <linux/timer.h>
67969 #include <linux/tty.h> /* struct tty_struct */
67970+#include <asm/local.h>
67971
67972 #include <net/irda/irias_object.h>
67973 #include <net/irda/ircomm_core.h>
67974diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
67975index cc7c197..9f2da2a 100644
67976--- a/include/net/iucv/af_iucv.h
67977+++ b/include/net/iucv/af_iucv.h
67978@@ -141,7 +141,7 @@ struct iucv_sock {
67979 struct iucv_sock_list {
67980 struct hlist_head head;
67981 rwlock_t lock;
67982- atomic_t autobind_name;
67983+ atomic_unchecked_t autobind_name;
67984 };
67985
67986 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
67987diff --git a/include/net/neighbour.h b/include/net/neighbour.h
67988index 0dab173..1b76af0 100644
67989--- a/include/net/neighbour.h
67990+++ b/include/net/neighbour.h
67991@@ -123,7 +123,7 @@ struct neigh_ops {
67992 void (*error_report)(struct neighbour *, struct sk_buff *);
67993 int (*output)(struct neighbour *, struct sk_buff *);
67994 int (*connected_output)(struct neighbour *, struct sk_buff *);
67995-};
67996+} __do_const;
67997
67998 struct pneigh_entry {
67999 struct pneigh_entry *next;
68000diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
68001index de644bc..666aed3 100644
68002--- a/include/net/net_namespace.h
68003+++ b/include/net/net_namespace.h
68004@@ -115,7 +115,7 @@ struct net {
68005 #endif
68006 struct netns_ipvs *ipvs;
68007 struct sock *diag_nlsk;
68008- atomic_t rt_genid;
68009+ atomic_unchecked_t rt_genid;
68010 };
68011
68012 /*
68013@@ -330,12 +330,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
68014
68015 static inline int rt_genid(struct net *net)
68016 {
68017- return atomic_read(&net->rt_genid);
68018+ return atomic_read_unchecked(&net->rt_genid);
68019 }
68020
68021 static inline void rt_genid_bump(struct net *net)
68022 {
68023- atomic_inc(&net->rt_genid);
68024+ atomic_inc_unchecked(&net->rt_genid);
68025 }
68026
68027 #endif /* __NET_NET_NAMESPACE_H */
68028diff --git a/include/net/netdma.h b/include/net/netdma.h
68029index 8ba8ce2..99b7fff 100644
68030--- a/include/net/netdma.h
68031+++ b/include/net/netdma.h
68032@@ -24,7 +24,7 @@
68033 #include <linux/dmaengine.h>
68034 #include <linux/skbuff.h>
68035
68036-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
68037+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
68038 struct sk_buff *skb, int offset, struct iovec *to,
68039 size_t len, struct dma_pinned_list *pinned_list);
68040
68041diff --git a/include/net/netlink.h b/include/net/netlink.h
68042index 9690b0f..87aded7 100644
68043--- a/include/net/netlink.h
68044+++ b/include/net/netlink.h
68045@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
68046 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
68047 {
68048 if (mark)
68049- skb_trim(skb, (unsigned char *) mark - skb->data);
68050+ skb_trim(skb, (const unsigned char *) mark - skb->data);
68051 }
68052
68053 /**
68054diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
68055index 2ae2b83..dbdc85e 100644
68056--- a/include/net/netns/ipv4.h
68057+++ b/include/net/netns/ipv4.h
68058@@ -64,7 +64,7 @@ struct netns_ipv4 {
68059 kgid_t sysctl_ping_group_range[2];
68060 long sysctl_tcp_mem[3];
68061
68062- atomic_t dev_addr_genid;
68063+ atomic_unchecked_t dev_addr_genid;
68064
68065 #ifdef CONFIG_IP_MROUTE
68066 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
68067diff --git a/include/net/protocol.h b/include/net/protocol.h
68068index 047c047..b9dad15 100644
68069--- a/include/net/protocol.h
68070+++ b/include/net/protocol.h
68071@@ -44,7 +44,7 @@ struct net_protocol {
68072 void (*err_handler)(struct sk_buff *skb, u32 info);
68073 unsigned int no_policy:1,
68074 netns_ok:1;
68075-};
68076+} __do_const;
68077
68078 #if IS_ENABLED(CONFIG_IPV6)
68079 struct inet6_protocol {
68080@@ -57,7 +57,7 @@ struct inet6_protocol {
68081 u8 type, u8 code, int offset,
68082 __be32 info);
68083 unsigned int flags; /* INET6_PROTO_xxx */
68084-};
68085+} __do_const;
68086
68087 #define INET6_PROTO_NOPOLICY 0x1
68088 #define INET6_PROTO_FINAL 0x2
68089diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
68090index 7fdf298..197e9f7 100644
68091--- a/include/net/sctp/sctp.h
68092+++ b/include/net/sctp/sctp.h
68093@@ -330,9 +330,9 @@ do { \
68094
68095 #else /* SCTP_DEBUG */
68096
68097-#define SCTP_DEBUG_PRINTK(whatever...)
68098-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
68099-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
68100+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
68101+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
68102+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
68103 #define SCTP_ENABLE_DEBUG
68104 #define SCTP_DISABLE_DEBUG
68105 #define SCTP_ASSERT(expr, str, func)
68106diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
68107index fdeb85a..0c554d5 100644
68108--- a/include/net/sctp/structs.h
68109+++ b/include/net/sctp/structs.h
68110@@ -497,7 +497,7 @@ struct sctp_af {
68111 int sockaddr_len;
68112 sa_family_t sa_family;
68113 struct list_head list;
68114-};
68115+} __do_const;
68116
68117 struct sctp_af *sctp_get_af_specific(sa_family_t);
68118 int sctp_register_af(struct sctp_af *);
68119@@ -517,7 +517,7 @@ struct sctp_pf {
68120 struct sctp_association *asoc);
68121 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
68122 struct sctp_af *af;
68123-};
68124+} __do_const;
68125
68126
68127 /* Structure to track chunk fragments that have been acked, but peer
68128diff --git a/include/net/sock.h b/include/net/sock.h
68129index 25afaa0..8bb0070 100644
68130--- a/include/net/sock.h
68131+++ b/include/net/sock.h
68132@@ -322,7 +322,7 @@ struct sock {
68133 #ifdef CONFIG_RPS
68134 __u32 sk_rxhash;
68135 #endif
68136- atomic_t sk_drops;
68137+ atomic_unchecked_t sk_drops;
68138 int sk_rcvbuf;
68139
68140 struct sk_filter __rcu *sk_filter;
68141@@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
68142 }
68143
68144 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
68145- char __user *from, char *to,
68146+ char __user *from, unsigned char *to,
68147 int copy, int offset)
68148 {
68149 if (skb->ip_summed == CHECKSUM_NONE) {
68150@@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
68151 }
68152 }
68153
68154-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
68155+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
68156
68157 /**
68158 * sk_page_frag - return an appropriate page_frag
68159diff --git a/include/net/tcp.h b/include/net/tcp.h
68160index aed42c7..43890c6 100644
68161--- a/include/net/tcp.h
68162+++ b/include/net/tcp.h
68163@@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
68164 extern void tcp_xmit_retransmit_queue(struct sock *);
68165 extern void tcp_simple_retransmit(struct sock *);
68166 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
68167-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
68168+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
68169
68170 extern void tcp_send_probe0(struct sock *);
68171 extern void tcp_send_partial(struct sock *);
68172@@ -701,8 +701,8 @@ struct tcp_skb_cb {
68173 struct inet6_skb_parm h6;
68174 #endif
68175 } header; /* For incoming frames */
68176- __u32 seq; /* Starting sequence number */
68177- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
68178+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
68179+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
68180 __u32 when; /* used to compute rtt's */
68181 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
68182
68183@@ -716,7 +716,7 @@ struct tcp_skb_cb {
68184
68185 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
68186 /* 1 byte hole */
68187- __u32 ack_seq; /* Sequence number ACK'd */
68188+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
68189 };
68190
68191 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
68192diff --git a/include/net/xfrm.h b/include/net/xfrm.h
68193index 63445ed..74ef61d 100644
68194--- a/include/net/xfrm.h
68195+++ b/include/net/xfrm.h
68196@@ -423,7 +423,7 @@ struct xfrm_mode {
68197 struct module *owner;
68198 unsigned int encap;
68199 int flags;
68200-};
68201+} __do_const;
68202
68203 /* Flags for xfrm_mode. */
68204 enum {
68205@@ -514,7 +514,7 @@ struct xfrm_policy {
68206 struct timer_list timer;
68207
68208 struct flow_cache_object flo;
68209- atomic_t genid;
68210+ atomic_unchecked_t genid;
68211 u32 priority;
68212 u32 index;
68213 struct xfrm_mark mark;
68214diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
68215index 1a046b1..ee0bef0 100644
68216--- a/include/rdma/iw_cm.h
68217+++ b/include/rdma/iw_cm.h
68218@@ -122,7 +122,7 @@ struct iw_cm_verbs {
68219 int backlog);
68220
68221 int (*destroy_listen)(struct iw_cm_id *cm_id);
68222-};
68223+} __no_const;
68224
68225 /**
68226 * iw_create_cm_id - Create an IW CM identifier.
68227diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
68228index 399162b..b337f1a 100644
68229--- a/include/scsi/libfc.h
68230+++ b/include/scsi/libfc.h
68231@@ -762,6 +762,7 @@ struct libfc_function_template {
68232 */
68233 void (*disc_stop_final) (struct fc_lport *);
68234 };
68235+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
68236
68237 /**
68238 * struct fc_disc - Discovery context
68239@@ -866,7 +867,7 @@ struct fc_lport {
68240 struct fc_vport *vport;
68241
68242 /* Operational Information */
68243- struct libfc_function_template tt;
68244+ libfc_function_template_no_const tt;
68245 u8 link_up;
68246 u8 qfull;
68247 enum fc_lport_state state;
68248diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
68249index e65c62e..aa2e5a2 100644
68250--- a/include/scsi/scsi_device.h
68251+++ b/include/scsi/scsi_device.h
68252@@ -170,9 +170,9 @@ struct scsi_device {
68253 unsigned int max_device_blocked; /* what device_blocked counts down from */
68254 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
68255
68256- atomic_t iorequest_cnt;
68257- atomic_t iodone_cnt;
68258- atomic_t ioerr_cnt;
68259+ atomic_unchecked_t iorequest_cnt;
68260+ atomic_unchecked_t iodone_cnt;
68261+ atomic_unchecked_t ioerr_cnt;
68262
68263 struct device sdev_gendev,
68264 sdev_dev;
68265diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
68266index b797e8f..8e2c3aa 100644
68267--- a/include/scsi/scsi_transport_fc.h
68268+++ b/include/scsi/scsi_transport_fc.h
68269@@ -751,7 +751,8 @@ struct fc_function_template {
68270 unsigned long show_host_system_hostname:1;
68271
68272 unsigned long disable_target_scan:1;
68273-};
68274+} __do_const;
68275+typedef struct fc_function_template __no_const fc_function_template_no_const;
68276
68277
68278 /**
68279diff --git a/include/sound/soc.h b/include/sound/soc.h
68280index bc56738..a4be132 100644
68281--- a/include/sound/soc.h
68282+++ b/include/sound/soc.h
68283@@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
68284 /* probe ordering - for components with runtime dependencies */
68285 int probe_order;
68286 int remove_order;
68287-};
68288+} __do_const;
68289
68290 /* SoC platform interface */
68291 struct snd_soc_platform_driver {
68292@@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
68293 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
68294 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
68295 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
68296-};
68297+} __do_const;
68298
68299 struct snd_soc_platform {
68300 const char *name;
68301diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
68302index 663e34a..91b306a 100644
68303--- a/include/target/target_core_base.h
68304+++ b/include/target/target_core_base.h
68305@@ -654,7 +654,7 @@ struct se_device {
68306 spinlock_t stats_lock;
68307 /* Active commands on this virtual SE device */
68308 atomic_t simple_cmds;
68309- atomic_t dev_ordered_id;
68310+ atomic_unchecked_t dev_ordered_id;
68311 atomic_t dev_ordered_sync;
68312 atomic_t dev_qf_count;
68313 int export_count;
68314diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
68315new file mode 100644
68316index 0000000..fb634b7
68317--- /dev/null
68318+++ b/include/trace/events/fs.h
68319@@ -0,0 +1,53 @@
68320+#undef TRACE_SYSTEM
68321+#define TRACE_SYSTEM fs
68322+
68323+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
68324+#define _TRACE_FS_H
68325+
68326+#include <linux/fs.h>
68327+#include <linux/tracepoint.h>
68328+
68329+TRACE_EVENT(do_sys_open,
68330+
68331+ TP_PROTO(const char *filename, int flags, int mode),
68332+
68333+ TP_ARGS(filename, flags, mode),
68334+
68335+ TP_STRUCT__entry(
68336+ __string( filename, filename )
68337+ __field( int, flags )
68338+ __field( int, mode )
68339+ ),
68340+
68341+ TP_fast_assign(
68342+ __assign_str(filename, filename);
68343+ __entry->flags = flags;
68344+ __entry->mode = mode;
68345+ ),
68346+
68347+ TP_printk("\"%s\" %x %o",
68348+ __get_str(filename), __entry->flags, __entry->mode)
68349+);
68350+
68351+TRACE_EVENT(open_exec,
68352+
68353+ TP_PROTO(const char *filename),
68354+
68355+ TP_ARGS(filename),
68356+
68357+ TP_STRUCT__entry(
68358+ __string( filename, filename )
68359+ ),
68360+
68361+ TP_fast_assign(
68362+ __assign_str(filename, filename);
68363+ ),
68364+
68365+ TP_printk("\"%s\"",
68366+ __get_str(filename))
68367+);
68368+
68369+#endif /* _TRACE_FS_H */
68370+
68371+/* This part must be outside protection */
68372+#include <trace/define_trace.h>
68373diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
68374index 1c09820..7f5ec79 100644
68375--- a/include/trace/events/irq.h
68376+++ b/include/trace/events/irq.h
68377@@ -36,7 +36,7 @@ struct softirq_action;
68378 */
68379 TRACE_EVENT(irq_handler_entry,
68380
68381- TP_PROTO(int irq, struct irqaction *action),
68382+ TP_PROTO(int irq, const struct irqaction *action),
68383
68384 TP_ARGS(irq, action),
68385
68386@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
68387 */
68388 TRACE_EVENT(irq_handler_exit,
68389
68390- TP_PROTO(int irq, struct irqaction *action, int ret),
68391+ TP_PROTO(int irq, const struct irqaction *action, int ret),
68392
68393 TP_ARGS(irq, action, ret),
68394
68395diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
68396index 7caf44c..23c6f27 100644
68397--- a/include/uapi/linux/a.out.h
68398+++ b/include/uapi/linux/a.out.h
68399@@ -39,6 +39,14 @@ enum machine_type {
68400 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
68401 };
68402
68403+/* Constants for the N_FLAGS field */
68404+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
68405+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
68406+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
68407+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
68408+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
68409+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
68410+
68411 #if !defined (N_MAGIC)
68412 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
68413 #endif
68414diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
68415index d876736..b36014e 100644
68416--- a/include/uapi/linux/byteorder/little_endian.h
68417+++ b/include/uapi/linux/byteorder/little_endian.h
68418@@ -42,51 +42,51 @@
68419
68420 static inline __le64 __cpu_to_le64p(const __u64 *p)
68421 {
68422- return (__force __le64)*p;
68423+ return (__force const __le64)*p;
68424 }
68425 static inline __u64 __le64_to_cpup(const __le64 *p)
68426 {
68427- return (__force __u64)*p;
68428+ return (__force const __u64)*p;
68429 }
68430 static inline __le32 __cpu_to_le32p(const __u32 *p)
68431 {
68432- return (__force __le32)*p;
68433+ return (__force const __le32)*p;
68434 }
68435 static inline __u32 __le32_to_cpup(const __le32 *p)
68436 {
68437- return (__force __u32)*p;
68438+ return (__force const __u32)*p;
68439 }
68440 static inline __le16 __cpu_to_le16p(const __u16 *p)
68441 {
68442- return (__force __le16)*p;
68443+ return (__force const __le16)*p;
68444 }
68445 static inline __u16 __le16_to_cpup(const __le16 *p)
68446 {
68447- return (__force __u16)*p;
68448+ return (__force const __u16)*p;
68449 }
68450 static inline __be64 __cpu_to_be64p(const __u64 *p)
68451 {
68452- return (__force __be64)__swab64p(p);
68453+ return (__force const __be64)__swab64p(p);
68454 }
68455 static inline __u64 __be64_to_cpup(const __be64 *p)
68456 {
68457- return __swab64p((__u64 *)p);
68458+ return __swab64p((const __u64 *)p);
68459 }
68460 static inline __be32 __cpu_to_be32p(const __u32 *p)
68461 {
68462- return (__force __be32)__swab32p(p);
68463+ return (__force const __be32)__swab32p(p);
68464 }
68465 static inline __u32 __be32_to_cpup(const __be32 *p)
68466 {
68467- return __swab32p((__u32 *)p);
68468+ return __swab32p((const __u32 *)p);
68469 }
68470 static inline __be16 __cpu_to_be16p(const __u16 *p)
68471 {
68472- return (__force __be16)__swab16p(p);
68473+ return (__force const __be16)__swab16p(p);
68474 }
68475 static inline __u16 __be16_to_cpup(const __be16 *p)
68476 {
68477- return __swab16p((__u16 *)p);
68478+ return __swab16p((const __u16 *)p);
68479 }
68480 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
68481 #define __le64_to_cpus(x) do { (void)(x); } while (0)
68482diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
68483index 126a817..d522bd1 100644
68484--- a/include/uapi/linux/elf.h
68485+++ b/include/uapi/linux/elf.h
68486@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
68487 #define PT_GNU_EH_FRAME 0x6474e550
68488
68489 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
68490+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
68491+
68492+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
68493+
68494+/* Constants for the e_flags field */
68495+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
68496+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
68497+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
68498+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
68499+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
68500+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
68501
68502 /*
68503 * Extended Numbering
68504@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
68505 #define DT_DEBUG 21
68506 #define DT_TEXTREL 22
68507 #define DT_JMPREL 23
68508+#define DT_FLAGS 30
68509+ #define DF_TEXTREL 0x00000004
68510 #define DT_ENCODING 32
68511 #define OLD_DT_LOOS 0x60000000
68512 #define DT_LOOS 0x6000000d
68513@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
68514 #define PF_W 0x2
68515 #define PF_X 0x1
68516
68517+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
68518+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
68519+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
68520+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
68521+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
68522+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
68523+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
68524+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
68525+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
68526+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
68527+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
68528+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
68529+
68530 typedef struct elf32_phdr{
68531 Elf32_Word p_type;
68532 Elf32_Off p_offset;
68533@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
68534 #define EI_OSABI 7
68535 #define EI_PAD 8
68536
68537+#define EI_PAX 14
68538+
68539 #define ELFMAG0 0x7f /* EI_MAG */
68540 #define ELFMAG1 'E'
68541 #define ELFMAG2 'L'
68542diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
68543index aa169c4..6a2771d 100644
68544--- a/include/uapi/linux/personality.h
68545+++ b/include/uapi/linux/personality.h
68546@@ -30,6 +30,7 @@ enum {
68547 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
68548 ADDR_NO_RANDOMIZE | \
68549 ADDR_COMPAT_LAYOUT | \
68550+ ADDR_LIMIT_3GB | \
68551 MMAP_PAGE_ZERO)
68552
68553 /*
68554diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
68555index 7530e74..e714828 100644
68556--- a/include/uapi/linux/screen_info.h
68557+++ b/include/uapi/linux/screen_info.h
68558@@ -43,7 +43,8 @@ struct screen_info {
68559 __u16 pages; /* 0x32 */
68560 __u16 vesa_attributes; /* 0x34 */
68561 __u32 capabilities; /* 0x36 */
68562- __u8 _reserved[6]; /* 0x3a */
68563+ __u16 vesapm_size; /* 0x3a */
68564+ __u8 _reserved[4]; /* 0x3c */
68565 } __attribute__((packed));
68566
68567 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
68568diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
68569index 6d67213..8dab561 100644
68570--- a/include/uapi/linux/sysctl.h
68571+++ b/include/uapi/linux/sysctl.h
68572@@ -155,7 +155,11 @@ enum
68573 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
68574 };
68575
68576-
68577+#ifdef CONFIG_PAX_SOFTMODE
68578+enum {
68579+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
68580+};
68581+#endif
68582
68583 /* CTL_VM names: */
68584 enum
68585diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
68586index 26607bd..588b65f 100644
68587--- a/include/uapi/linux/xattr.h
68588+++ b/include/uapi/linux/xattr.h
68589@@ -60,5 +60,9 @@
68590 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
68591 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
68592
68593+/* User namespace */
68594+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
68595+#define XATTR_PAX_FLAGS_SUFFIX "flags"
68596+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
68597
68598 #endif /* _UAPI_LINUX_XATTR_H */
68599diff --git a/include/video/udlfb.h b/include/video/udlfb.h
68600index f9466fa..f4e2b81 100644
68601--- a/include/video/udlfb.h
68602+++ b/include/video/udlfb.h
68603@@ -53,10 +53,10 @@ struct dlfb_data {
68604 u32 pseudo_palette[256];
68605 int blank_mode; /*one of FB_BLANK_ */
68606 /* blit-only rendering path metrics, exposed through sysfs */
68607- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
68608- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
68609- atomic_t bytes_sent; /* to usb, after compression including overhead */
68610- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
68611+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
68612+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
68613+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
68614+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
68615 };
68616
68617 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
68618diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
68619index 0993a22..32ba2fe 100644
68620--- a/include/video/uvesafb.h
68621+++ b/include/video/uvesafb.h
68622@@ -177,6 +177,7 @@ struct uvesafb_par {
68623 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
68624 u8 pmi_setpal; /* PMI for palette changes */
68625 u16 *pmi_base; /* protected mode interface location */
68626+ u8 *pmi_code; /* protected mode code location */
68627 void *pmi_start;
68628 void *pmi_pal;
68629 u8 *vbe_state_orig; /*
68630diff --git a/init/Kconfig b/init/Kconfig
68631index be8b7f5..b13cb62 100644
68632--- a/init/Kconfig
68633+++ b/init/Kconfig
68634@@ -990,6 +990,7 @@ endif # CGROUPS
68635
68636 config CHECKPOINT_RESTORE
68637 bool "Checkpoint/restore support" if EXPERT
68638+ depends on !GRKERNSEC
68639 default n
68640 help
68641 Enables additional kernel features in a sake of checkpoint/restore.
68642@@ -1079,6 +1080,8 @@ config UIDGID_CONVERTED
68643 depends on OCFS2_FS = n
68644 depends on XFS_FS = n
68645
68646+ depends on GRKERNSEC = n
68647+
68648 config UIDGID_STRICT_TYPE_CHECKS
68649 bool "Require conversions between uid/gids and their internal representation"
68650 depends on UIDGID_CONVERTED
68651@@ -1468,7 +1471,7 @@ config SLUB_DEBUG
68652
68653 config COMPAT_BRK
68654 bool "Disable heap randomization"
68655- default y
68656+ default n
68657 help
68658 Randomizing heap placement makes heap exploits harder, but it
68659 also breaks ancient binaries (including anything libc5 based).
68660@@ -1711,7 +1714,7 @@ config INIT_ALL_POSSIBLE
68661 config STOP_MACHINE
68662 bool
68663 default y
68664- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
68665+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
68666 help
68667 Need stop_machine() primitive.
68668
68669diff --git a/init/Makefile b/init/Makefile
68670index 7bc47ee..6da2dc7 100644
68671--- a/init/Makefile
68672+++ b/init/Makefile
68673@@ -2,6 +2,9 @@
68674 # Makefile for the linux kernel.
68675 #
68676
68677+ccflags-y := $(GCC_PLUGINS_CFLAGS)
68678+asflags-y := $(GCC_PLUGINS_AFLAGS)
68679+
68680 obj-y := main.o version.o mounts.o
68681 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
68682 obj-y += noinitramfs.o
68683diff --git a/init/do_mounts.c b/init/do_mounts.c
68684index 1d1b634..a1c810f 100644
68685--- a/init/do_mounts.c
68686+++ b/init/do_mounts.c
68687@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
68688 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
68689 {
68690 struct super_block *s;
68691- int err = sys_mount(name, "/root", fs, flags, data);
68692+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
68693 if (err)
68694 return err;
68695
68696- sys_chdir("/root");
68697+ sys_chdir((const char __force_user *)"/root");
68698 s = current->fs->pwd.dentry->d_sb;
68699 ROOT_DEV = s->s_dev;
68700 printk(KERN_INFO
68701@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
68702 va_start(args, fmt);
68703 vsprintf(buf, fmt, args);
68704 va_end(args);
68705- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
68706+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
68707 if (fd >= 0) {
68708 sys_ioctl(fd, FDEJECT, 0);
68709 sys_close(fd);
68710 }
68711 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
68712- fd = sys_open("/dev/console", O_RDWR, 0);
68713+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
68714 if (fd >= 0) {
68715 sys_ioctl(fd, TCGETS, (long)&termios);
68716 termios.c_lflag &= ~ICANON;
68717 sys_ioctl(fd, TCSETSF, (long)&termios);
68718- sys_read(fd, &c, 1);
68719+ sys_read(fd, (char __user *)&c, 1);
68720 termios.c_lflag |= ICANON;
68721 sys_ioctl(fd, TCSETSF, (long)&termios);
68722 sys_close(fd);
68723@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
68724 mount_root();
68725 out:
68726 devtmpfs_mount("dev");
68727- sys_mount(".", "/", NULL, MS_MOVE, NULL);
68728- sys_chroot(".");
68729+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
68730+ sys_chroot((const char __force_user *)".");
68731 }
68732diff --git a/init/do_mounts.h b/init/do_mounts.h
68733index f5b978a..69dbfe8 100644
68734--- a/init/do_mounts.h
68735+++ b/init/do_mounts.h
68736@@ -15,15 +15,15 @@ extern int root_mountflags;
68737
68738 static inline int create_dev(char *name, dev_t dev)
68739 {
68740- sys_unlink(name);
68741- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
68742+ sys_unlink((char __force_user *)name);
68743+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
68744 }
68745
68746 #if BITS_PER_LONG == 32
68747 static inline u32 bstat(char *name)
68748 {
68749 struct stat64 stat;
68750- if (sys_stat64(name, &stat) != 0)
68751+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
68752 return 0;
68753 if (!S_ISBLK(stat.st_mode))
68754 return 0;
68755@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
68756 static inline u32 bstat(char *name)
68757 {
68758 struct stat stat;
68759- if (sys_newstat(name, &stat) != 0)
68760+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
68761 return 0;
68762 if (!S_ISBLK(stat.st_mode))
68763 return 0;
68764diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
68765index f9acf71..1e19144 100644
68766--- a/init/do_mounts_initrd.c
68767+++ b/init/do_mounts_initrd.c
68768@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
68769 create_dev("/dev/root.old", Root_RAM0);
68770 /* mount initrd on rootfs' /root */
68771 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
68772- sys_mkdir("/old", 0700);
68773- sys_chdir("/old");
68774+ sys_mkdir((const char __force_user *)"/old", 0700);
68775+ sys_chdir((const char __force_user *)"/old");
68776
68777 /*
68778 * In case that a resume from disk is carried out by linuxrc or one of
68779@@ -73,31 +73,31 @@ static void __init handle_initrd(void)
68780 current->flags &= ~PF_FREEZER_SKIP;
68781
68782 /* move initrd to rootfs' /old */
68783- sys_mount("..", ".", NULL, MS_MOVE, NULL);
68784+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
68785 /* switch root and cwd back to / of rootfs */
68786- sys_chroot("..");
68787+ sys_chroot((const char __force_user *)"..");
68788
68789 if (new_decode_dev(real_root_dev) == Root_RAM0) {
68790- sys_chdir("/old");
68791+ sys_chdir((const char __force_user *)"/old");
68792 return;
68793 }
68794
68795- sys_chdir("/");
68796+ sys_chdir((const char __force_user *)"/");
68797 ROOT_DEV = new_decode_dev(real_root_dev);
68798 mount_root();
68799
68800 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
68801- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
68802+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
68803 if (!error)
68804 printk("okay\n");
68805 else {
68806- int fd = sys_open("/dev/root.old", O_RDWR, 0);
68807+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
68808 if (error == -ENOENT)
68809 printk("/initrd does not exist. Ignored.\n");
68810 else
68811 printk("failed\n");
68812 printk(KERN_NOTICE "Unmounting old root\n");
68813- sys_umount("/old", MNT_DETACH);
68814+ sys_umount((char __force_user *)"/old", MNT_DETACH);
68815 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
68816 if (fd < 0) {
68817 error = fd;
68818@@ -120,11 +120,11 @@ int __init initrd_load(void)
68819 * mounted in the normal path.
68820 */
68821 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
68822- sys_unlink("/initrd.image");
68823+ sys_unlink((const char __force_user *)"/initrd.image");
68824 handle_initrd();
68825 return 1;
68826 }
68827 }
68828- sys_unlink("/initrd.image");
68829+ sys_unlink((const char __force_user *)"/initrd.image");
68830 return 0;
68831 }
68832diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
68833index 8cb6db5..d729f50 100644
68834--- a/init/do_mounts_md.c
68835+++ b/init/do_mounts_md.c
68836@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
68837 partitioned ? "_d" : "", minor,
68838 md_setup_args[ent].device_names);
68839
68840- fd = sys_open(name, 0, 0);
68841+ fd = sys_open((char __force_user *)name, 0, 0);
68842 if (fd < 0) {
68843 printk(KERN_ERR "md: open failed - cannot start "
68844 "array %s\n", name);
68845@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
68846 * array without it
68847 */
68848 sys_close(fd);
68849- fd = sys_open(name, 0, 0);
68850+ fd = sys_open((char __force_user *)name, 0, 0);
68851 sys_ioctl(fd, BLKRRPART, 0);
68852 }
68853 sys_close(fd);
68854@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
68855
68856 wait_for_device_probe();
68857
68858- fd = sys_open("/dev/md0", 0, 0);
68859+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
68860 if (fd >= 0) {
68861 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
68862 sys_close(fd);
68863diff --git a/init/init_task.c b/init/init_task.c
68864index 8b2f399..f0797c9 100644
68865--- a/init/init_task.c
68866+++ b/init/init_task.c
68867@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
68868 * Initial thread structure. Alignment of this is handled by a special
68869 * linker map entry.
68870 */
68871+#ifdef CONFIG_X86
68872+union thread_union init_thread_union __init_task_data;
68873+#else
68874 union thread_union init_thread_union __init_task_data =
68875 { INIT_THREAD_INFO(init_task) };
68876+#endif
68877diff --git a/init/initramfs.c b/init/initramfs.c
68878index 84c6bf1..8899338 100644
68879--- a/init/initramfs.c
68880+++ b/init/initramfs.c
68881@@ -84,7 +84,7 @@ static void __init free_hash(void)
68882 }
68883 }
68884
68885-static long __init do_utime(char *filename, time_t mtime)
68886+static long __init do_utime(char __force_user *filename, time_t mtime)
68887 {
68888 struct timespec t[2];
68889
68890@@ -119,7 +119,7 @@ static void __init dir_utime(void)
68891 struct dir_entry *de, *tmp;
68892 list_for_each_entry_safe(de, tmp, &dir_list, list) {
68893 list_del(&de->list);
68894- do_utime(de->name, de->mtime);
68895+ do_utime((char __force_user *)de->name, de->mtime);
68896 kfree(de->name);
68897 kfree(de);
68898 }
68899@@ -281,7 +281,7 @@ static int __init maybe_link(void)
68900 if (nlink >= 2) {
68901 char *old = find_link(major, minor, ino, mode, collected);
68902 if (old)
68903- return (sys_link(old, collected) < 0) ? -1 : 1;
68904+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
68905 }
68906 return 0;
68907 }
68908@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
68909 {
68910 struct stat st;
68911
68912- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
68913+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
68914 if (S_ISDIR(st.st_mode))
68915- sys_rmdir(path);
68916+ sys_rmdir((char __force_user *)path);
68917 else
68918- sys_unlink(path);
68919+ sys_unlink((char __force_user *)path);
68920 }
68921 }
68922
68923@@ -315,7 +315,7 @@ static int __init do_name(void)
68924 int openflags = O_WRONLY|O_CREAT;
68925 if (ml != 1)
68926 openflags |= O_TRUNC;
68927- wfd = sys_open(collected, openflags, mode);
68928+ wfd = sys_open((char __force_user *)collected, openflags, mode);
68929
68930 if (wfd >= 0) {
68931 sys_fchown(wfd, uid, gid);
68932@@ -327,17 +327,17 @@ static int __init do_name(void)
68933 }
68934 }
68935 } else if (S_ISDIR(mode)) {
68936- sys_mkdir(collected, mode);
68937- sys_chown(collected, uid, gid);
68938- sys_chmod(collected, mode);
68939+ sys_mkdir((char __force_user *)collected, mode);
68940+ sys_chown((char __force_user *)collected, uid, gid);
68941+ sys_chmod((char __force_user *)collected, mode);
68942 dir_add(collected, mtime);
68943 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
68944 S_ISFIFO(mode) || S_ISSOCK(mode)) {
68945 if (maybe_link() == 0) {
68946- sys_mknod(collected, mode, rdev);
68947- sys_chown(collected, uid, gid);
68948- sys_chmod(collected, mode);
68949- do_utime(collected, mtime);
68950+ sys_mknod((char __force_user *)collected, mode, rdev);
68951+ sys_chown((char __force_user *)collected, uid, gid);
68952+ sys_chmod((char __force_user *)collected, mode);
68953+ do_utime((char __force_user *)collected, mtime);
68954 }
68955 }
68956 return 0;
68957@@ -346,15 +346,15 @@ static int __init do_name(void)
68958 static int __init do_copy(void)
68959 {
68960 if (count >= body_len) {
68961- sys_write(wfd, victim, body_len);
68962+ sys_write(wfd, (char __force_user *)victim, body_len);
68963 sys_close(wfd);
68964- do_utime(vcollected, mtime);
68965+ do_utime((char __force_user *)vcollected, mtime);
68966 kfree(vcollected);
68967 eat(body_len);
68968 state = SkipIt;
68969 return 0;
68970 } else {
68971- sys_write(wfd, victim, count);
68972+ sys_write(wfd, (char __force_user *)victim, count);
68973 body_len -= count;
68974 eat(count);
68975 return 1;
68976@@ -365,9 +365,9 @@ static int __init do_symlink(void)
68977 {
68978 collected[N_ALIGN(name_len) + body_len] = '\0';
68979 clean_path(collected, 0);
68980- sys_symlink(collected + N_ALIGN(name_len), collected);
68981- sys_lchown(collected, uid, gid);
68982- do_utime(collected, mtime);
68983+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
68984+ sys_lchown((char __force_user *)collected, uid, gid);
68985+ do_utime((char __force_user *)collected, mtime);
68986 state = SkipIt;
68987 next_state = Reset;
68988 return 0;
68989diff --git a/init/main.c b/init/main.c
68990index cee4b5c..47f445e 100644
68991--- a/init/main.c
68992+++ b/init/main.c
68993@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
68994 extern void tc_init(void);
68995 #endif
68996
68997+extern void grsecurity_init(void);
68998+
68999 /*
69000 * Debug helper: via this flag we know that we are in 'early bootup code'
69001 * where only the boot processor is running with IRQ disabled. This means
69002@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
69003
69004 __setup("reset_devices", set_reset_devices);
69005
69006+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
69007+int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
69008+static int __init setup_grsec_proc_gid(char *str)
69009+{
69010+ grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
69011+ return 1;
69012+}
69013+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
69014+#endif
69015+
69016+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
69017+extern char pax_enter_kernel_user[];
69018+extern char pax_exit_kernel_user[];
69019+extern pgdval_t clone_pgd_mask;
69020+#endif
69021+
69022+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
69023+static int __init setup_pax_nouderef(char *str)
69024+{
69025+#ifdef CONFIG_X86_32
69026+ unsigned int cpu;
69027+ struct desc_struct *gdt;
69028+
69029+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
69030+ gdt = get_cpu_gdt_table(cpu);
69031+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
69032+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
69033+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
69034+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
69035+ }
69036+ loadsegment(ds, __KERNEL_DS);
69037+ loadsegment(es, __KERNEL_DS);
69038+ loadsegment(ss, __KERNEL_DS);
69039+#else
69040+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
69041+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
69042+ clone_pgd_mask = ~(pgdval_t)0UL;
69043+#endif
69044+
69045+ return 0;
69046+}
69047+early_param("pax_nouderef", setup_pax_nouderef);
69048+#endif
69049+
69050+#ifdef CONFIG_PAX_SOFTMODE
69051+int pax_softmode;
69052+
69053+static int __init setup_pax_softmode(char *str)
69054+{
69055+ get_option(&str, &pax_softmode);
69056+ return 1;
69057+}
69058+__setup("pax_softmode=", setup_pax_softmode);
69059+#endif
69060+
69061 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
69062 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
69063 static const char *panic_later, *panic_param;
69064@@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
69065 {
69066 int count = preempt_count();
69067 int ret;
69068+ const char *msg1 = "", *msg2 = "";
69069
69070 if (initcall_debug)
69071 ret = do_one_initcall_debug(fn);
69072@@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
69073 sprintf(msgbuf, "error code %d ", ret);
69074
69075 if (preempt_count() != count) {
69076- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
69077+ msg1 = " preemption imbalance";
69078 preempt_count() = count;
69079 }
69080 if (irqs_disabled()) {
69081- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
69082+ msg2 = " disabled interrupts";
69083 local_irq_enable();
69084 }
69085- if (msgbuf[0]) {
69086- printk("initcall %pF returned with %s\n", fn, msgbuf);
69087+ if (msgbuf[0] || *msg1 || *msg2) {
69088+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
69089 }
69090
69091 return ret;
69092@@ -743,6 +801,10 @@ static char *initcall_level_names[] __initdata = {
69093 "late",
69094 };
69095
69096+#ifdef CONFIG_PAX_LATENT_ENTROPY
69097+u64 latent_entropy;
69098+#endif
69099+
69100 static void __init do_initcall_level(int level)
69101 {
69102 extern const struct kernel_param __start___param[], __stop___param[];
69103@@ -755,8 +817,14 @@ static void __init do_initcall_level(int level)
69104 level, level,
69105 &repair_env_string);
69106
69107- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
69108+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
69109 do_one_initcall(*fn);
69110+
69111+#ifdef CONFIG_PAX_LATENT_ENTROPY
69112+ add_device_randomness(&latent_entropy, sizeof(latent_entropy));
69113+#endif
69114+
69115+ }
69116 }
69117
69118 static void __init do_initcalls(void)
69119@@ -790,8 +858,14 @@ static void __init do_pre_smp_initcalls(void)
69120 {
69121 initcall_t *fn;
69122
69123- for (fn = __initcall_start; fn < __initcall0_start; fn++)
69124+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
69125 do_one_initcall(*fn);
69126+
69127+#ifdef CONFIG_PAX_LATENT_ENTROPY
69128+ add_device_randomness(&latent_entropy, sizeof(latent_entropy));
69129+#endif
69130+
69131+ }
69132 }
69133
69134 static int run_init_process(const char *init_filename)
69135@@ -877,7 +951,7 @@ static noinline void __init kernel_init_freeable(void)
69136 do_basic_setup();
69137
69138 /* Open the /dev/console on the rootfs, this should never fail */
69139- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
69140+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
69141 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
69142
69143 (void) sys_dup(0);
69144@@ -890,11 +964,13 @@ static noinline void __init kernel_init_freeable(void)
69145 if (!ramdisk_execute_command)
69146 ramdisk_execute_command = "/init";
69147
69148- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
69149+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
69150 ramdisk_execute_command = NULL;
69151 prepare_namespace();
69152 }
69153
69154+ grsecurity_init();
69155+
69156 /*
69157 * Ok, we have completed the initial bootup, and
69158 * we're essentially up and running. Get rid of the
69159diff --git a/ipc/mqueue.c b/ipc/mqueue.c
69160index 71a3ca1..cc330ee 100644
69161--- a/ipc/mqueue.c
69162+++ b/ipc/mqueue.c
69163@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
69164 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
69165 info->attr.mq_msgsize);
69166
69167+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
69168 spin_lock(&mq_lock);
69169 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
69170 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
69171diff --git a/ipc/msg.c b/ipc/msg.c
69172index 950572f..266c15f 100644
69173--- a/ipc/msg.c
69174+++ b/ipc/msg.c
69175@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
69176 return security_msg_queue_associate(msq, msgflg);
69177 }
69178
69179+static struct ipc_ops msg_ops = {
69180+ .getnew = newque,
69181+ .associate = msg_security,
69182+ .more_checks = NULL
69183+};
69184+
69185 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
69186 {
69187 struct ipc_namespace *ns;
69188- struct ipc_ops msg_ops;
69189 struct ipc_params msg_params;
69190
69191 ns = current->nsproxy->ipc_ns;
69192
69193- msg_ops.getnew = newque;
69194- msg_ops.associate = msg_security;
69195- msg_ops.more_checks = NULL;
69196-
69197 msg_params.key = key;
69198 msg_params.flg = msgflg;
69199
69200diff --git a/ipc/sem.c b/ipc/sem.c
69201index 58d31f1..cce7a55 100644
69202--- a/ipc/sem.c
69203+++ b/ipc/sem.c
69204@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
69205 return 0;
69206 }
69207
69208+static struct ipc_ops sem_ops = {
69209+ .getnew = newary,
69210+ .associate = sem_security,
69211+ .more_checks = sem_more_checks
69212+};
69213+
69214 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
69215 {
69216 struct ipc_namespace *ns;
69217- struct ipc_ops sem_ops;
69218 struct ipc_params sem_params;
69219
69220 ns = current->nsproxy->ipc_ns;
69221@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
69222 if (nsems < 0 || nsems > ns->sc_semmsl)
69223 return -EINVAL;
69224
69225- sem_ops.getnew = newary;
69226- sem_ops.associate = sem_security;
69227- sem_ops.more_checks = sem_more_checks;
69228-
69229 sem_params.key = key;
69230 sem_params.flg = semflg;
69231 sem_params.u.nsems = nsems;
69232diff --git a/ipc/shm.c b/ipc/shm.c
69233index 4fa6d8f..38dfd0c 100644
69234--- a/ipc/shm.c
69235+++ b/ipc/shm.c
69236@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
69237 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
69238 #endif
69239
69240+#ifdef CONFIG_GRKERNSEC
69241+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69242+ const time_t shm_createtime, const uid_t cuid,
69243+ const int shmid);
69244+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69245+ const time_t shm_createtime);
69246+#endif
69247+
69248 void shm_init_ns(struct ipc_namespace *ns)
69249 {
69250 ns->shm_ctlmax = SHMMAX;
69251@@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
69252 shp->shm_lprid = 0;
69253 shp->shm_atim = shp->shm_dtim = 0;
69254 shp->shm_ctim = get_seconds();
69255+#ifdef CONFIG_GRKERNSEC
69256+ {
69257+ struct timespec timeval;
69258+ do_posix_clock_monotonic_gettime(&timeval);
69259+
69260+ shp->shm_createtime = timeval.tv_sec;
69261+ }
69262+#endif
69263 shp->shm_segsz = size;
69264 shp->shm_nattch = 0;
69265 shp->shm_file = file;
69266@@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
69267 return 0;
69268 }
69269
69270+static struct ipc_ops shm_ops = {
69271+ .getnew = newseg,
69272+ .associate = shm_security,
69273+ .more_checks = shm_more_checks
69274+};
69275+
69276 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
69277 {
69278 struct ipc_namespace *ns;
69279- struct ipc_ops shm_ops;
69280 struct ipc_params shm_params;
69281
69282 ns = current->nsproxy->ipc_ns;
69283
69284- shm_ops.getnew = newseg;
69285- shm_ops.associate = shm_security;
69286- shm_ops.more_checks = shm_more_checks;
69287-
69288 shm_params.key = key;
69289 shm_params.flg = shmflg;
69290 shm_params.u.size = size;
69291@@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
69292 f_mode = FMODE_READ | FMODE_WRITE;
69293 }
69294 if (shmflg & SHM_EXEC) {
69295+
69296+#ifdef CONFIG_PAX_MPROTECT
69297+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
69298+ goto out;
69299+#endif
69300+
69301 prot |= PROT_EXEC;
69302 acc_mode |= S_IXUGO;
69303 }
69304@@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
69305 if (err)
69306 goto out_unlock;
69307
69308+#ifdef CONFIG_GRKERNSEC
69309+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
69310+ shp->shm_perm.cuid, shmid) ||
69311+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
69312+ err = -EACCES;
69313+ goto out_unlock;
69314+ }
69315+#endif
69316+
69317 path = shp->shm_file->f_path;
69318 path_get(&path);
69319 shp->shm_nattch++;
69320+#ifdef CONFIG_GRKERNSEC
69321+ shp->shm_lapid = current->pid;
69322+#endif
69323 size = i_size_read(path.dentry->d_inode);
69324 shm_unlock(shp);
69325
69326diff --git a/kernel/acct.c b/kernel/acct.c
69327index 051e071..15e0920 100644
69328--- a/kernel/acct.c
69329+++ b/kernel/acct.c
69330@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
69331 */
69332 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
69333 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
69334- file->f_op->write(file, (char *)&ac,
69335+ file->f_op->write(file, (char __force_user *)&ac,
69336 sizeof(acct_t), &file->f_pos);
69337 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
69338 set_fs(fs);
69339diff --git a/kernel/audit.c b/kernel/audit.c
69340index d596e53..dbef3c3 100644
69341--- a/kernel/audit.c
69342+++ b/kernel/audit.c
69343@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
69344 3) suppressed due to audit_rate_limit
69345 4) suppressed due to audit_backlog_limit
69346 */
69347-static atomic_t audit_lost = ATOMIC_INIT(0);
69348+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
69349
69350 /* The netlink socket. */
69351 static struct sock *audit_sock;
69352@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
69353 unsigned long now;
69354 int print;
69355
69356- atomic_inc(&audit_lost);
69357+ atomic_inc_unchecked(&audit_lost);
69358
69359 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
69360
69361@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
69362 printk(KERN_WARNING
69363 "audit: audit_lost=%d audit_rate_limit=%d "
69364 "audit_backlog_limit=%d\n",
69365- atomic_read(&audit_lost),
69366+ atomic_read_unchecked(&audit_lost),
69367 audit_rate_limit,
69368 audit_backlog_limit);
69369 audit_panic(message);
69370@@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
69371 status_set.pid = audit_pid;
69372 status_set.rate_limit = audit_rate_limit;
69373 status_set.backlog_limit = audit_backlog_limit;
69374- status_set.lost = atomic_read(&audit_lost);
69375+ status_set.lost = atomic_read_unchecked(&audit_lost);
69376 status_set.backlog = skb_queue_len(&audit_skb_queue);
69377 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
69378 &status_set, sizeof(status_set));
69379diff --git a/kernel/auditsc.c b/kernel/auditsc.c
69380index a371f85..da826c1 100644
69381--- a/kernel/auditsc.c
69382+++ b/kernel/auditsc.c
69383@@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
69384 }
69385
69386 /* global counter which is incremented every time something logs in */
69387-static atomic_t session_id = ATOMIC_INIT(0);
69388+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
69389
69390 /**
69391 * audit_set_loginuid - set current task's audit_context loginuid
69392@@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
69393 return -EPERM;
69394 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
69395
69396- sessionid = atomic_inc_return(&session_id);
69397+ sessionid = atomic_inc_return_unchecked(&session_id);
69398 if (context && context->in_syscall) {
69399 struct audit_buffer *ab;
69400
69401diff --git a/kernel/capability.c b/kernel/capability.c
69402index 493d972..f87dfbd 100644
69403--- a/kernel/capability.c
69404+++ b/kernel/capability.c
69405@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
69406 * before modification is attempted and the application
69407 * fails.
69408 */
69409+ if (tocopy > ARRAY_SIZE(kdata))
69410+ return -EFAULT;
69411+
69412 if (copy_to_user(dataptr, kdata, tocopy
69413 * sizeof(struct __user_cap_data_struct))) {
69414 return -EFAULT;
69415@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
69416 int ret;
69417
69418 rcu_read_lock();
69419- ret = security_capable(__task_cred(t), ns, cap);
69420+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
69421+ gr_task_is_capable(t, __task_cred(t), cap);
69422 rcu_read_unlock();
69423
69424- return (ret == 0);
69425+ return ret;
69426 }
69427
69428 /**
69429@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
69430 int ret;
69431
69432 rcu_read_lock();
69433- ret = security_capable_noaudit(__task_cred(t), ns, cap);
69434+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
69435 rcu_read_unlock();
69436
69437- return (ret == 0);
69438+ return ret;
69439 }
69440
69441 /**
69442@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
69443 BUG();
69444 }
69445
69446- if (security_capable(current_cred(), ns, cap) == 0) {
69447+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
69448 current->flags |= PF_SUPERPRIV;
69449 return true;
69450 }
69451@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
69452 }
69453 EXPORT_SYMBOL(ns_capable);
69454
69455+bool ns_capable_nolog(struct user_namespace *ns, int cap)
69456+{
69457+ if (unlikely(!cap_valid(cap))) {
69458+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
69459+ BUG();
69460+ }
69461+
69462+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
69463+ current->flags |= PF_SUPERPRIV;
69464+ return true;
69465+ }
69466+ return false;
69467+}
69468+EXPORT_SYMBOL(ns_capable_nolog);
69469+
69470 /**
69471 * capable - Determine if the current task has a superior capability in effect
69472 * @cap: The capability to be tested for
69473@@ -408,6 +427,12 @@ bool capable(int cap)
69474 }
69475 EXPORT_SYMBOL(capable);
69476
69477+bool capable_nolog(int cap)
69478+{
69479+ return ns_capable_nolog(&init_user_ns, cap);
69480+}
69481+EXPORT_SYMBOL(capable_nolog);
69482+
69483 /**
69484 * nsown_capable - Check superior capability to one's own user_ns
69485 * @cap: The capability in question
69486@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
69487
69488 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
69489 }
69490+
69491+bool inode_capable_nolog(const struct inode *inode, int cap)
69492+{
69493+ struct user_namespace *ns = current_user_ns();
69494+
69495+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
69496+}
69497diff --git a/kernel/cgroup.c b/kernel/cgroup.c
69498index 4855892..30d23b4 100644
69499--- a/kernel/cgroup.c
69500+++ b/kernel/cgroup.c
69501@@ -5535,7 +5535,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
69502 struct css_set *cg = link->cg;
69503 struct task_struct *task;
69504 int count = 0;
69505- seq_printf(seq, "css_set %p\n", cg);
69506+ seq_printf(seq, "css_set %pK\n", cg);
69507 list_for_each_entry(task, &cg->tasks, cg_list) {
69508 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
69509 seq_puts(seq, " ...\n");
69510diff --git a/kernel/compat.c b/kernel/compat.c
69511index 36700e9..73d770c 100644
69512--- a/kernel/compat.c
69513+++ b/kernel/compat.c
69514@@ -13,6 +13,7 @@
69515
69516 #include <linux/linkage.h>
69517 #include <linux/compat.h>
69518+#include <linux/module.h>
69519 #include <linux/errno.h>
69520 #include <linux/time.h>
69521 #include <linux/signal.h>
69522@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
69523 mm_segment_t oldfs;
69524 long ret;
69525
69526- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
69527+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
69528 oldfs = get_fs();
69529 set_fs(KERNEL_DS);
69530 ret = hrtimer_nanosleep_restart(restart);
69531@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
69532 oldfs = get_fs();
69533 set_fs(KERNEL_DS);
69534 ret = hrtimer_nanosleep(&tu,
69535- rmtp ? (struct timespec __user *)&rmt : NULL,
69536+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
69537 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
69538 set_fs(oldfs);
69539
69540@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
69541 mm_segment_t old_fs = get_fs();
69542
69543 set_fs(KERNEL_DS);
69544- ret = sys_sigpending((old_sigset_t __user *) &s);
69545+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
69546 set_fs(old_fs);
69547 if (ret == 0)
69548 ret = put_user(s, set);
69549@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
69550 mm_segment_t old_fs = get_fs();
69551
69552 set_fs(KERNEL_DS);
69553- ret = sys_old_getrlimit(resource, &r);
69554+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
69555 set_fs(old_fs);
69556
69557 if (!ret) {
69558@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
69559 mm_segment_t old_fs = get_fs();
69560
69561 set_fs(KERNEL_DS);
69562- ret = sys_getrusage(who, (struct rusage __user *) &r);
69563+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
69564 set_fs(old_fs);
69565
69566 if (ret)
69567@@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
69568 set_fs (KERNEL_DS);
69569 ret = sys_wait4(pid,
69570 (stat_addr ?
69571- (unsigned int __user *) &status : NULL),
69572- options, (struct rusage __user *) &r);
69573+ (unsigned int __force_user *) &status : NULL),
69574+ options, (struct rusage __force_user *) &r);
69575 set_fs (old_fs);
69576
69577 if (ret > 0) {
69578@@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
69579 memset(&info, 0, sizeof(info));
69580
69581 set_fs(KERNEL_DS);
69582- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
69583- uru ? (struct rusage __user *)&ru : NULL);
69584+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
69585+ uru ? (struct rusage __force_user *)&ru : NULL);
69586 set_fs(old_fs);
69587
69588 if ((ret < 0) || (info.si_signo == 0))
69589@@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
69590 oldfs = get_fs();
69591 set_fs(KERNEL_DS);
69592 err = sys_timer_settime(timer_id, flags,
69593- (struct itimerspec __user *) &newts,
69594- (struct itimerspec __user *) &oldts);
69595+ (struct itimerspec __force_user *) &newts,
69596+ (struct itimerspec __force_user *) &oldts);
69597 set_fs(oldfs);
69598 if (!err && old && put_compat_itimerspec(old, &oldts))
69599 return -EFAULT;
69600@@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
69601 oldfs = get_fs();
69602 set_fs(KERNEL_DS);
69603 err = sys_timer_gettime(timer_id,
69604- (struct itimerspec __user *) &ts);
69605+ (struct itimerspec __force_user *) &ts);
69606 set_fs(oldfs);
69607 if (!err && put_compat_itimerspec(setting, &ts))
69608 return -EFAULT;
69609@@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
69610 oldfs = get_fs();
69611 set_fs(KERNEL_DS);
69612 err = sys_clock_settime(which_clock,
69613- (struct timespec __user *) &ts);
69614+ (struct timespec __force_user *) &ts);
69615 set_fs(oldfs);
69616 return err;
69617 }
69618@@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
69619 oldfs = get_fs();
69620 set_fs(KERNEL_DS);
69621 err = sys_clock_gettime(which_clock,
69622- (struct timespec __user *) &ts);
69623+ (struct timespec __force_user *) &ts);
69624 set_fs(oldfs);
69625 if (!err && put_compat_timespec(&ts, tp))
69626 return -EFAULT;
69627@@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
69628
69629 oldfs = get_fs();
69630 set_fs(KERNEL_DS);
69631- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
69632+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
69633 set_fs(oldfs);
69634
69635 err = compat_put_timex(utp, &txc);
69636@@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
69637 oldfs = get_fs();
69638 set_fs(KERNEL_DS);
69639 err = sys_clock_getres(which_clock,
69640- (struct timespec __user *) &ts);
69641+ (struct timespec __force_user *) &ts);
69642 set_fs(oldfs);
69643 if (!err && tp && put_compat_timespec(&ts, tp))
69644 return -EFAULT;
69645@@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
69646 long err;
69647 mm_segment_t oldfs;
69648 struct timespec tu;
69649- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
69650+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
69651
69652- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
69653+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
69654 oldfs = get_fs();
69655 set_fs(KERNEL_DS);
69656 err = clock_nanosleep_restart(restart);
69657@@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
69658 oldfs = get_fs();
69659 set_fs(KERNEL_DS);
69660 err = sys_clock_nanosleep(which_clock, flags,
69661- (struct timespec __user *) &in,
69662- (struct timespec __user *) &out);
69663+ (struct timespec __force_user *) &in,
69664+ (struct timespec __force_user *) &out);
69665 set_fs(oldfs);
69666
69667 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
69668diff --git a/kernel/configs.c b/kernel/configs.c
69669index 42e8fa0..9e7406b 100644
69670--- a/kernel/configs.c
69671+++ b/kernel/configs.c
69672@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
69673 struct proc_dir_entry *entry;
69674
69675 /* create the current config file */
69676+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
69677+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
69678+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
69679+ &ikconfig_file_ops);
69680+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69681+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
69682+ &ikconfig_file_ops);
69683+#endif
69684+#else
69685 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
69686 &ikconfig_file_ops);
69687+#endif
69688+
69689 if (!entry)
69690 return -ENOMEM;
69691
69692diff --git a/kernel/cred.c b/kernel/cred.c
69693index e0573a4..eefe488 100644
69694--- a/kernel/cred.c
69695+++ b/kernel/cred.c
69696@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
69697 validate_creds(cred);
69698 alter_cred_subscribers(cred, -1);
69699 put_cred(cred);
69700+
69701+#ifdef CONFIG_GRKERNSEC_SETXID
69702+ cred = (struct cred *) tsk->delayed_cred;
69703+ if (cred != NULL) {
69704+ tsk->delayed_cred = NULL;
69705+ validate_creds(cred);
69706+ alter_cred_subscribers(cred, -1);
69707+ put_cred(cred);
69708+ }
69709+#endif
69710 }
69711
69712 /**
69713@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
69714 * Always returns 0 thus allowing this function to be tail-called at the end
69715 * of, say, sys_setgid().
69716 */
69717-int commit_creds(struct cred *new)
69718+static int __commit_creds(struct cred *new)
69719 {
69720 struct task_struct *task = current;
69721 const struct cred *old = task->real_cred;
69722@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
69723
69724 get_cred(new); /* we will require a ref for the subj creds too */
69725
69726+ gr_set_role_label(task, new->uid, new->gid);
69727+
69728 /* dumpability changes */
69729 if (!uid_eq(old->euid, new->euid) ||
69730 !gid_eq(old->egid, new->egid) ||
69731@@ -479,6 +491,101 @@ int commit_creds(struct cred *new)
69732 put_cred(old);
69733 return 0;
69734 }
69735+#ifdef CONFIG_GRKERNSEC_SETXID
69736+extern int set_user(struct cred *new);
69737+
69738+void gr_delayed_cred_worker(void)
69739+{
69740+ const struct cred *new = current->delayed_cred;
69741+ struct cred *ncred;
69742+
69743+ current->delayed_cred = NULL;
69744+
69745+ if (current_uid() && new != NULL) {
69746+ // from doing get_cred on it when queueing this
69747+ put_cred(new);
69748+ return;
69749+ } else if (new == NULL)
69750+ return;
69751+
69752+ ncred = prepare_creds();
69753+ if (!ncred)
69754+ goto die;
69755+ // uids
69756+ ncred->uid = new->uid;
69757+ ncred->euid = new->euid;
69758+ ncred->suid = new->suid;
69759+ ncred->fsuid = new->fsuid;
69760+ // gids
69761+ ncred->gid = new->gid;
69762+ ncred->egid = new->egid;
69763+ ncred->sgid = new->sgid;
69764+ ncred->fsgid = new->fsgid;
69765+ // groups
69766+ if (set_groups(ncred, new->group_info) < 0) {
69767+ abort_creds(ncred);
69768+ goto die;
69769+ }
69770+ // caps
69771+ ncred->securebits = new->securebits;
69772+ ncred->cap_inheritable = new->cap_inheritable;
69773+ ncred->cap_permitted = new->cap_permitted;
69774+ ncred->cap_effective = new->cap_effective;
69775+ ncred->cap_bset = new->cap_bset;
69776+
69777+ if (set_user(ncred)) {
69778+ abort_creds(ncred);
69779+ goto die;
69780+ }
69781+
69782+ // from doing get_cred on it when queueing this
69783+ put_cred(new);
69784+
69785+ __commit_creds(ncred);
69786+ return;
69787+die:
69788+ // from doing get_cred on it when queueing this
69789+ put_cred(new);
69790+ do_group_exit(SIGKILL);
69791+}
69792+#endif
69793+
69794+int commit_creds(struct cred *new)
69795+{
69796+#ifdef CONFIG_GRKERNSEC_SETXID
69797+ int ret;
69798+ int schedule_it = 0;
69799+ struct task_struct *t;
69800+
69801+ /* we won't get called with tasklist_lock held for writing
69802+ and interrupts disabled as the cred struct in that case is
69803+ init_cred
69804+ */
69805+ if (grsec_enable_setxid && !current_is_single_threaded() &&
69806+ !current_uid() && new->uid) {
69807+ schedule_it = 1;
69808+ }
69809+ ret = __commit_creds(new);
69810+ if (schedule_it) {
69811+ rcu_read_lock();
69812+ read_lock(&tasklist_lock);
69813+ for (t = next_thread(current); t != current;
69814+ t = next_thread(t)) {
69815+ if (t->delayed_cred == NULL) {
69816+ t->delayed_cred = get_cred(new);
69817+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
69818+ set_tsk_need_resched(t);
69819+ }
69820+ }
69821+ read_unlock(&tasklist_lock);
69822+ rcu_read_unlock();
69823+ }
69824+ return ret;
69825+#else
69826+ return __commit_creds(new);
69827+#endif
69828+}
69829+
69830 EXPORT_SYMBOL(commit_creds);
69831
69832 /**
69833diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
69834index 9a61738..c5c8f3a 100644
69835--- a/kernel/debug/debug_core.c
69836+++ b/kernel/debug/debug_core.c
69837@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
69838 */
69839 static atomic_t masters_in_kgdb;
69840 static atomic_t slaves_in_kgdb;
69841-static atomic_t kgdb_break_tasklet_var;
69842+static atomic_unchecked_t kgdb_break_tasklet_var;
69843 atomic_t kgdb_setting_breakpoint;
69844
69845 struct task_struct *kgdb_usethread;
69846@@ -132,7 +132,7 @@ int kgdb_single_step;
69847 static pid_t kgdb_sstep_pid;
69848
69849 /* to keep track of the CPU which is doing the single stepping*/
69850-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69851+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69852
69853 /*
69854 * If you are debugging a problem where roundup (the collection of
69855@@ -540,7 +540,7 @@ return_normal:
69856 * kernel will only try for the value of sstep_tries before
69857 * giving up and continuing on.
69858 */
69859- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
69860+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
69861 (kgdb_info[cpu].task &&
69862 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
69863 atomic_set(&kgdb_active, -1);
69864@@ -634,8 +634,8 @@ cpu_master_loop:
69865 }
69866
69867 kgdb_restore:
69868- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
69869- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
69870+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
69871+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
69872 if (kgdb_info[sstep_cpu].task)
69873 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
69874 else
69875@@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
69876 static void kgdb_tasklet_bpt(unsigned long ing)
69877 {
69878 kgdb_breakpoint();
69879- atomic_set(&kgdb_break_tasklet_var, 0);
69880+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
69881 }
69882
69883 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
69884
69885 void kgdb_schedule_breakpoint(void)
69886 {
69887- if (atomic_read(&kgdb_break_tasklet_var) ||
69888+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
69889 atomic_read(&kgdb_active) != -1 ||
69890 atomic_read(&kgdb_setting_breakpoint))
69891 return;
69892- atomic_inc(&kgdb_break_tasklet_var);
69893+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
69894 tasklet_schedule(&kgdb_tasklet_breakpoint);
69895 }
69896 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
69897diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
69898index 8875254..7cf4928 100644
69899--- a/kernel/debug/kdb/kdb_main.c
69900+++ b/kernel/debug/kdb/kdb_main.c
69901@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
69902 continue;
69903
69904 kdb_printf("%-20s%8u 0x%p ", mod->name,
69905- mod->core_size, (void *)mod);
69906+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
69907 #ifdef CONFIG_MODULE_UNLOAD
69908 kdb_printf("%4ld ", module_refcount(mod));
69909 #endif
69910@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
69911 kdb_printf(" (Loading)");
69912 else
69913 kdb_printf(" (Live)");
69914- kdb_printf(" 0x%p", mod->module_core);
69915+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
69916
69917 #ifdef CONFIG_MODULE_UNLOAD
69918 {
69919diff --git a/kernel/events/core.c b/kernel/events/core.c
69920index 7b6646a..3cb1135 100644
69921--- a/kernel/events/core.c
69922+++ b/kernel/events/core.c
69923@@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
69924 return 0;
69925 }
69926
69927-static atomic64_t perf_event_id;
69928+static atomic64_unchecked_t perf_event_id;
69929
69930 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
69931 enum event_type_t event_type);
69932@@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
69933
69934 static inline u64 perf_event_count(struct perf_event *event)
69935 {
69936- return local64_read(&event->count) + atomic64_read(&event->child_count);
69937+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
69938 }
69939
69940 static u64 perf_event_read(struct perf_event *event)
69941@@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
69942 mutex_lock(&event->child_mutex);
69943 total += perf_event_read(event);
69944 *enabled += event->total_time_enabled +
69945- atomic64_read(&event->child_total_time_enabled);
69946+ atomic64_read_unchecked(&event->child_total_time_enabled);
69947 *running += event->total_time_running +
69948- atomic64_read(&event->child_total_time_running);
69949+ atomic64_read_unchecked(&event->child_total_time_running);
69950
69951 list_for_each_entry(child, &event->child_list, child_list) {
69952 total += perf_event_read(child);
69953@@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
69954 userpg->offset -= local64_read(&event->hw.prev_count);
69955
69956 userpg->time_enabled = enabled +
69957- atomic64_read(&event->child_total_time_enabled);
69958+ atomic64_read_unchecked(&event->child_total_time_enabled);
69959
69960 userpg->time_running = running +
69961- atomic64_read(&event->child_total_time_running);
69962+ atomic64_read_unchecked(&event->child_total_time_running);
69963
69964 arch_perf_update_userpage(userpg, now);
69965
69966@@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
69967 values[n++] = perf_event_count(event);
69968 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
69969 values[n++] = enabled +
69970- atomic64_read(&event->child_total_time_enabled);
69971+ atomic64_read_unchecked(&event->child_total_time_enabled);
69972 }
69973 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
69974 values[n++] = running +
69975- atomic64_read(&event->child_total_time_running);
69976+ atomic64_read_unchecked(&event->child_total_time_running);
69977 }
69978 if (read_format & PERF_FORMAT_ID)
69979 values[n++] = primary_event_id(event);
69980@@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
69981 * need to add enough zero bytes after the string to handle
69982 * the 64bit alignment we do later.
69983 */
69984- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
69985+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
69986 if (!buf) {
69987 name = strncpy(tmp, "//enomem", sizeof(tmp));
69988 goto got_name;
69989 }
69990- name = d_path(&file->f_path, buf, PATH_MAX);
69991+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
69992 if (IS_ERR(name)) {
69993 name = strncpy(tmp, "//toolong", sizeof(tmp));
69994 goto got_name;
69995@@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
69996 event->parent = parent_event;
69997
69998 event->ns = get_pid_ns(task_active_pid_ns(current));
69999- event->id = atomic64_inc_return(&perf_event_id);
70000+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
70001
70002 event->state = PERF_EVENT_STATE_INACTIVE;
70003
70004@@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
70005 /*
70006 * Add back the child's count to the parent's count:
70007 */
70008- atomic64_add(child_val, &parent_event->child_count);
70009- atomic64_add(child_event->total_time_enabled,
70010+ atomic64_add_unchecked(child_val, &parent_event->child_count);
70011+ atomic64_add_unchecked(child_event->total_time_enabled,
70012 &parent_event->child_total_time_enabled);
70013- atomic64_add(child_event->total_time_running,
70014+ atomic64_add_unchecked(child_event->total_time_running,
70015 &parent_event->child_total_time_running);
70016
70017 /*
70018diff --git a/kernel/exit.c b/kernel/exit.c
70019index b4df219..f13c02d 100644
70020--- a/kernel/exit.c
70021+++ b/kernel/exit.c
70022@@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
70023 struct task_struct *leader;
70024 int zap_leader;
70025 repeat:
70026+#ifdef CONFIG_NET
70027+ gr_del_task_from_ip_table(p);
70028+#endif
70029+
70030 /* don't need to get the RCU readlock here - the process is dead and
70031 * can't be modifying its own credentials. But shut RCU-lockdep up */
70032 rcu_read_lock();
70033@@ -338,7 +342,7 @@ int allow_signal(int sig)
70034 * know it'll be handled, so that they don't get converted to
70035 * SIGKILL or just silently dropped.
70036 */
70037- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
70038+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
70039 recalc_sigpending();
70040 spin_unlock_irq(&current->sighand->siglock);
70041 return 0;
70042@@ -708,6 +712,8 @@ void do_exit(long code)
70043 struct task_struct *tsk = current;
70044 int group_dead;
70045
70046+ set_fs(USER_DS);
70047+
70048 profile_task_exit(tsk);
70049
70050 WARN_ON(blk_needs_flush_plug(tsk));
70051@@ -724,7 +730,6 @@ void do_exit(long code)
70052 * mm_release()->clear_child_tid() from writing to a user-controlled
70053 * kernel address.
70054 */
70055- set_fs(USER_DS);
70056
70057 ptrace_event(PTRACE_EVENT_EXIT, code);
70058
70059@@ -783,6 +788,9 @@ void do_exit(long code)
70060 tsk->exit_code = code;
70061 taskstats_exit(tsk, group_dead);
70062
70063+ gr_acl_handle_psacct(tsk, code);
70064+ gr_acl_handle_exit();
70065+
70066 exit_mm(tsk);
70067
70068 if (group_dead)
70069@@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
70070 * Take down every thread in the group. This is called by fatal signals
70071 * as well as by sys_exit_group (below).
70072 */
70073-void
70074+__noreturn void
70075 do_group_exit(int exit_code)
70076 {
70077 struct signal_struct *sig = current->signal;
70078diff --git a/kernel/fork.c b/kernel/fork.c
70079index c535f33..1d768f9 100644
70080--- a/kernel/fork.c
70081+++ b/kernel/fork.c
70082@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
70083 *stackend = STACK_END_MAGIC; /* for overflow detection */
70084
70085 #ifdef CONFIG_CC_STACKPROTECTOR
70086- tsk->stack_canary = get_random_int();
70087+ tsk->stack_canary = pax_get_random_long();
70088 #endif
70089
70090 /*
70091@@ -344,13 +344,81 @@ free_tsk:
70092 }
70093
70094 #ifdef CONFIG_MMU
70095+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
70096+{
70097+ struct vm_area_struct *tmp;
70098+ unsigned long charge;
70099+ struct mempolicy *pol;
70100+ struct file *file;
70101+
70102+ charge = 0;
70103+ if (mpnt->vm_flags & VM_ACCOUNT) {
70104+ unsigned long len = vma_pages(mpnt);
70105+
70106+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
70107+ goto fail_nomem;
70108+ charge = len;
70109+ }
70110+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
70111+ if (!tmp)
70112+ goto fail_nomem;
70113+ *tmp = *mpnt;
70114+ tmp->vm_mm = mm;
70115+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
70116+ pol = mpol_dup(vma_policy(mpnt));
70117+ if (IS_ERR(pol))
70118+ goto fail_nomem_policy;
70119+ vma_set_policy(tmp, pol);
70120+ if (anon_vma_fork(tmp, mpnt))
70121+ goto fail_nomem_anon_vma_fork;
70122+ tmp->vm_flags &= ~VM_LOCKED;
70123+ tmp->vm_next = tmp->vm_prev = NULL;
70124+ tmp->vm_mirror = NULL;
70125+ file = tmp->vm_file;
70126+ if (file) {
70127+ struct inode *inode = file->f_path.dentry->d_inode;
70128+ struct address_space *mapping = file->f_mapping;
70129+
70130+ get_file(file);
70131+ if (tmp->vm_flags & VM_DENYWRITE)
70132+ atomic_dec(&inode->i_writecount);
70133+ mutex_lock(&mapping->i_mmap_mutex);
70134+ if (tmp->vm_flags & VM_SHARED)
70135+ mapping->i_mmap_writable++;
70136+ flush_dcache_mmap_lock(mapping);
70137+ /* insert tmp into the share list, just after mpnt */
70138+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
70139+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
70140+ else
70141+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
70142+ flush_dcache_mmap_unlock(mapping);
70143+ mutex_unlock(&mapping->i_mmap_mutex);
70144+ }
70145+
70146+ /*
70147+ * Clear hugetlb-related page reserves for children. This only
70148+ * affects MAP_PRIVATE mappings. Faults generated by the child
70149+ * are not guaranteed to succeed, even if read-only
70150+ */
70151+ if (is_vm_hugetlb_page(tmp))
70152+ reset_vma_resv_huge_pages(tmp);
70153+
70154+ return tmp;
70155+
70156+fail_nomem_anon_vma_fork:
70157+ mpol_put(pol);
70158+fail_nomem_policy:
70159+ kmem_cache_free(vm_area_cachep, tmp);
70160+fail_nomem:
70161+ vm_unacct_memory(charge);
70162+ return NULL;
70163+}
70164+
70165 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70166 {
70167 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
70168 struct rb_node **rb_link, *rb_parent;
70169 int retval;
70170- unsigned long charge;
70171- struct mempolicy *pol;
70172
70173 uprobe_start_dup_mmap();
70174 down_write(&oldmm->mmap_sem);
70175@@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70176 mm->locked_vm = 0;
70177 mm->mmap = NULL;
70178 mm->mmap_cache = NULL;
70179- mm->free_area_cache = oldmm->mmap_base;
70180- mm->cached_hole_size = ~0UL;
70181+ mm->free_area_cache = oldmm->free_area_cache;
70182+ mm->cached_hole_size = oldmm->cached_hole_size;
70183 mm->map_count = 0;
70184 cpumask_clear(mm_cpumask(mm));
70185 mm->mm_rb = RB_ROOT;
70186@@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70187
70188 prev = NULL;
70189 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
70190- struct file *file;
70191-
70192 if (mpnt->vm_flags & VM_DONTCOPY) {
70193 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
70194 -vma_pages(mpnt));
70195 continue;
70196 }
70197- charge = 0;
70198- if (mpnt->vm_flags & VM_ACCOUNT) {
70199- unsigned long len = vma_pages(mpnt);
70200-
70201- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
70202- goto fail_nomem;
70203- charge = len;
70204- }
70205- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
70206- if (!tmp)
70207- goto fail_nomem;
70208- *tmp = *mpnt;
70209- INIT_LIST_HEAD(&tmp->anon_vma_chain);
70210- pol = mpol_dup(vma_policy(mpnt));
70211- retval = PTR_ERR(pol);
70212- if (IS_ERR(pol))
70213- goto fail_nomem_policy;
70214- vma_set_policy(tmp, pol);
70215- tmp->vm_mm = mm;
70216- if (anon_vma_fork(tmp, mpnt))
70217- goto fail_nomem_anon_vma_fork;
70218- tmp->vm_flags &= ~VM_LOCKED;
70219- tmp->vm_next = tmp->vm_prev = NULL;
70220- file = tmp->vm_file;
70221- if (file) {
70222- struct inode *inode = file->f_path.dentry->d_inode;
70223- struct address_space *mapping = file->f_mapping;
70224-
70225- get_file(file);
70226- if (tmp->vm_flags & VM_DENYWRITE)
70227- atomic_dec(&inode->i_writecount);
70228- mutex_lock(&mapping->i_mmap_mutex);
70229- if (tmp->vm_flags & VM_SHARED)
70230- mapping->i_mmap_writable++;
70231- flush_dcache_mmap_lock(mapping);
70232- /* insert tmp into the share list, just after mpnt */
70233- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
70234- vma_nonlinear_insert(tmp,
70235- &mapping->i_mmap_nonlinear);
70236- else
70237- vma_interval_tree_insert_after(tmp, mpnt,
70238- &mapping->i_mmap);
70239- flush_dcache_mmap_unlock(mapping);
70240- mutex_unlock(&mapping->i_mmap_mutex);
70241+ tmp = dup_vma(mm, oldmm, mpnt);
70242+ if (!tmp) {
70243+ retval = -ENOMEM;
70244+ goto out;
70245 }
70246
70247 /*
70248@@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70249 if (retval)
70250 goto out;
70251 }
70252+
70253+#ifdef CONFIG_PAX_SEGMEXEC
70254+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
70255+ struct vm_area_struct *mpnt_m;
70256+
70257+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
70258+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
70259+
70260+ if (!mpnt->vm_mirror)
70261+ continue;
70262+
70263+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
70264+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
70265+ mpnt->vm_mirror = mpnt_m;
70266+ } else {
70267+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
70268+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
70269+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
70270+ mpnt->vm_mirror->vm_mirror = mpnt;
70271+ }
70272+ }
70273+ BUG_ON(mpnt_m);
70274+ }
70275+#endif
70276+
70277 /* a new mm has just been created */
70278 arch_dup_mmap(oldmm, mm);
70279 retval = 0;
70280@@ -472,14 +523,6 @@ out:
70281 up_write(&oldmm->mmap_sem);
70282 uprobe_end_dup_mmap();
70283 return retval;
70284-fail_nomem_anon_vma_fork:
70285- mpol_put(pol);
70286-fail_nomem_policy:
70287- kmem_cache_free(vm_area_cachep, tmp);
70288-fail_nomem:
70289- retval = -ENOMEM;
70290- vm_unacct_memory(charge);
70291- goto out;
70292 }
70293
70294 static inline int mm_alloc_pgd(struct mm_struct *mm)
70295@@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
70296 return ERR_PTR(err);
70297
70298 mm = get_task_mm(task);
70299- if (mm && mm != current->mm &&
70300- !ptrace_may_access(task, mode)) {
70301+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
70302+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
70303 mmput(mm);
70304 mm = ERR_PTR(-EACCES);
70305 }
70306@@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
70307 spin_unlock(&fs->lock);
70308 return -EAGAIN;
70309 }
70310- fs->users++;
70311+ atomic_inc(&fs->users);
70312 spin_unlock(&fs->lock);
70313 return 0;
70314 }
70315 tsk->fs = copy_fs_struct(fs);
70316 if (!tsk->fs)
70317 return -ENOMEM;
70318+ /* Carry through gr_chroot_dentry and is_chrooted instead
70319+ of recomputing it here. Already copied when the task struct
70320+ is duplicated. This allows pivot_root to not be treated as
70321+ a chroot
70322+ */
70323+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
70324+
70325 return 0;
70326 }
70327
70328@@ -1193,6 +1243,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
70329 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
70330 #endif
70331 retval = -EAGAIN;
70332+
70333+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
70334+
70335 if (atomic_read(&p->real_cred->user->processes) >=
70336 task_rlimit(p, RLIMIT_NPROC)) {
70337 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
70338@@ -1432,6 +1485,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
70339 goto bad_fork_free_pid;
70340 }
70341
70342+ /* synchronizes with gr_set_acls()
70343+ we need to call this past the point of no return for fork()
70344+ */
70345+ gr_copy_label(p);
70346+
70347 if (clone_flags & CLONE_THREAD) {
70348 current->signal->nr_threads++;
70349 atomic_inc(&current->signal->live);
70350@@ -1515,6 +1573,8 @@ bad_fork_cleanup_count:
70351 bad_fork_free:
70352 free_task(p);
70353 fork_out:
70354+ gr_log_forkfail(retval);
70355+
70356 return ERR_PTR(retval);
70357 }
70358
70359@@ -1565,6 +1625,23 @@ long do_fork(unsigned long clone_flags,
70360 return -EINVAL;
70361 }
70362
70363+#ifdef CONFIG_GRKERNSEC
70364+ if (clone_flags & CLONE_NEWUSER) {
70365+ /*
70366+ * This doesn't really inspire confidence:
70367+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
70368+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
70369+ * Increases kernel attack surface in areas developers
70370+ * previously cared little about ("low importance due
70371+ * to requiring "root" capability")
70372+ * To be removed when this code receives *proper* review
70373+ */
70374+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
70375+ !capable(CAP_SETGID))
70376+ return -EPERM;
70377+ }
70378+#endif
70379+
70380 /*
70381 * Determine whether and which event to report to ptracer. When
70382 * called from kernel_thread or CLONE_UNTRACED is explicitly
70383@@ -1599,6 +1676,8 @@ long do_fork(unsigned long clone_flags,
70384 if (clone_flags & CLONE_PARENT_SETTID)
70385 put_user(nr, parent_tidptr);
70386
70387+ gr_handle_brute_check();
70388+
70389 if (clone_flags & CLONE_VFORK) {
70390 p->vfork_done = &vfork;
70391 init_completion(&vfork);
70392@@ -1752,7 +1831,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
70393 return 0;
70394
70395 /* don't need lock here; in the worst case we'll do useless copy */
70396- if (fs->users == 1)
70397+ if (atomic_read(&fs->users) == 1)
70398 return 0;
70399
70400 *new_fsp = copy_fs_struct(fs);
70401@@ -1866,7 +1945,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
70402 fs = current->fs;
70403 spin_lock(&fs->lock);
70404 current->fs = new_fs;
70405- if (--fs->users)
70406+ gr_set_chroot_entries(current, &current->fs->root);
70407+ if (atomic_dec_return(&fs->users))
70408 new_fs = NULL;
70409 else
70410 new_fs = fs;
70411diff --git a/kernel/futex.c b/kernel/futex.c
70412index 8879430..31696f1 100644
70413--- a/kernel/futex.c
70414+++ b/kernel/futex.c
70415@@ -54,6 +54,7 @@
70416 #include <linux/mount.h>
70417 #include <linux/pagemap.h>
70418 #include <linux/syscalls.h>
70419+#include <linux/ptrace.h>
70420 #include <linux/signal.h>
70421 #include <linux/export.h>
70422 #include <linux/magic.h>
70423@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
70424 struct page *page, *page_head;
70425 int err, ro = 0;
70426
70427+#ifdef CONFIG_PAX_SEGMEXEC
70428+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
70429+ return -EFAULT;
70430+#endif
70431+
70432 /*
70433 * The futex address must be "naturally" aligned.
70434 */
70435@@ -2731,6 +2737,7 @@ static int __init futex_init(void)
70436 {
70437 u32 curval;
70438 int i;
70439+ mm_segment_t oldfs;
70440
70441 /*
70442 * This will fail and we want it. Some arch implementations do
70443@@ -2742,8 +2749,11 @@ static int __init futex_init(void)
70444 * implementation, the non-functional ones will return
70445 * -ENOSYS.
70446 */
70447+ oldfs = get_fs();
70448+ set_fs(USER_DS);
70449 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
70450 futex_cmpxchg_enabled = 1;
70451+ set_fs(oldfs);
70452
70453 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
70454 plist_head_init(&futex_queues[i].chain);
70455diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
70456index 9b22d03..6295b62 100644
70457--- a/kernel/gcov/base.c
70458+++ b/kernel/gcov/base.c
70459@@ -102,11 +102,6 @@ void gcov_enable_events(void)
70460 }
70461
70462 #ifdef CONFIG_MODULES
70463-static inline int within(void *addr, void *start, unsigned long size)
70464-{
70465- return ((addr >= start) && (addr < start + size));
70466-}
70467-
70468 /* Update list and generate events when modules are unloaded. */
70469 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
70470 void *data)
70471@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
70472 prev = NULL;
70473 /* Remove entries located in module from linked list. */
70474 for (info = gcov_info_head; info; info = info->next) {
70475- if (within(info, mod->module_core, mod->core_size)) {
70476+ if (within_module_core_rw((unsigned long)info, mod)) {
70477 if (prev)
70478 prev->next = info->next;
70479 else
70480diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
70481index cdd5607..c3fc919 100644
70482--- a/kernel/hrtimer.c
70483+++ b/kernel/hrtimer.c
70484@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
70485 local_irq_restore(flags);
70486 }
70487
70488-static void run_hrtimer_softirq(struct softirq_action *h)
70489+static void run_hrtimer_softirq(void)
70490 {
70491 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
70492
70493@@ -1751,7 +1751,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
70494 return NOTIFY_OK;
70495 }
70496
70497-static struct notifier_block __cpuinitdata hrtimers_nb = {
70498+static struct notifier_block hrtimers_nb = {
70499 .notifier_call = hrtimer_cpu_notify,
70500 };
70501
70502diff --git a/kernel/jump_label.c b/kernel/jump_label.c
70503index 60f48fa..7f3a770 100644
70504--- a/kernel/jump_label.c
70505+++ b/kernel/jump_label.c
70506@@ -13,6 +13,7 @@
70507 #include <linux/sort.h>
70508 #include <linux/err.h>
70509 #include <linux/static_key.h>
70510+#include <linux/mm.h>
70511
70512 #ifdef HAVE_JUMP_LABEL
70513
70514@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
70515
70516 size = (((unsigned long)stop - (unsigned long)start)
70517 / sizeof(struct jump_entry));
70518+ pax_open_kernel();
70519 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
70520+ pax_close_kernel();
70521 }
70522
70523 static void jump_label_update(struct static_key *key, int enable);
70524@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
70525 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
70526 struct jump_entry *iter;
70527
70528+ pax_open_kernel();
70529 for (iter = iter_start; iter < iter_stop; iter++) {
70530 if (within_module_init(iter->code, mod))
70531 iter->code = 0;
70532 }
70533+ pax_close_kernel();
70534 }
70535
70536 static int
70537diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
70538index 2169fee..45c017a 100644
70539--- a/kernel/kallsyms.c
70540+++ b/kernel/kallsyms.c
70541@@ -11,6 +11,9 @@
70542 * Changed the compression method from stem compression to "table lookup"
70543 * compression (see scripts/kallsyms.c for a more complete description)
70544 */
70545+#ifdef CONFIG_GRKERNSEC_HIDESYM
70546+#define __INCLUDED_BY_HIDESYM 1
70547+#endif
70548 #include <linux/kallsyms.h>
70549 #include <linux/module.h>
70550 #include <linux/init.h>
70551@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
70552
70553 static inline int is_kernel_inittext(unsigned long addr)
70554 {
70555+ if (system_state != SYSTEM_BOOTING)
70556+ return 0;
70557+
70558 if (addr >= (unsigned long)_sinittext
70559 && addr <= (unsigned long)_einittext)
70560 return 1;
70561 return 0;
70562 }
70563
70564+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70565+#ifdef CONFIG_MODULES
70566+static inline int is_module_text(unsigned long addr)
70567+{
70568+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
70569+ return 1;
70570+
70571+ addr = ktla_ktva(addr);
70572+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
70573+}
70574+#else
70575+static inline int is_module_text(unsigned long addr)
70576+{
70577+ return 0;
70578+}
70579+#endif
70580+#endif
70581+
70582 static inline int is_kernel_text(unsigned long addr)
70583 {
70584 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
70585@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
70586
70587 static inline int is_kernel(unsigned long addr)
70588 {
70589+
70590+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70591+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
70592+ return 1;
70593+
70594+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
70595+#else
70596 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
70597+#endif
70598+
70599 return 1;
70600 return in_gate_area_no_mm(addr);
70601 }
70602
70603 static int is_ksym_addr(unsigned long addr)
70604 {
70605+
70606+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70607+ if (is_module_text(addr))
70608+ return 0;
70609+#endif
70610+
70611 if (all_var)
70612 return is_kernel(addr);
70613
70614@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
70615
70616 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
70617 {
70618- iter->name[0] = '\0';
70619 iter->nameoff = get_symbol_offset(new_pos);
70620 iter->pos = new_pos;
70621 }
70622@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
70623 {
70624 struct kallsym_iter *iter = m->private;
70625
70626+#ifdef CONFIG_GRKERNSEC_HIDESYM
70627+ if (current_uid())
70628+ return 0;
70629+#endif
70630+
70631 /* Some debugging symbols have no name. Ignore them. */
70632 if (!iter->name[0])
70633 return 0;
70634@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
70635 */
70636 type = iter->exported ? toupper(iter->type) :
70637 tolower(iter->type);
70638+
70639 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
70640 type, iter->name, iter->module_name);
70641 } else
70642@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
70643 struct kallsym_iter *iter;
70644 int ret;
70645
70646- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
70647+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
70648 if (!iter)
70649 return -ENOMEM;
70650 reset_iter(iter, 0);
70651diff --git a/kernel/kcmp.c b/kernel/kcmp.c
70652index e30ac0f..3528cac 100644
70653--- a/kernel/kcmp.c
70654+++ b/kernel/kcmp.c
70655@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
70656 struct task_struct *task1, *task2;
70657 int ret;
70658
70659+#ifdef CONFIG_GRKERNSEC
70660+ return -ENOSYS;
70661+#endif
70662+
70663 rcu_read_lock();
70664
70665 /*
70666diff --git a/kernel/kexec.c b/kernel/kexec.c
70667index 5e4bd78..00c5b91 100644
70668--- a/kernel/kexec.c
70669+++ b/kernel/kexec.c
70670@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
70671 unsigned long flags)
70672 {
70673 struct compat_kexec_segment in;
70674- struct kexec_segment out, __user *ksegments;
70675+ struct kexec_segment out;
70676+ struct kexec_segment __user *ksegments;
70677 unsigned long i, result;
70678
70679 /* Don't allow clients that don't understand the native
70680diff --git a/kernel/kmod.c b/kernel/kmod.c
70681index 0023a87..3fe3781 100644
70682--- a/kernel/kmod.c
70683+++ b/kernel/kmod.c
70684@@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
70685 kfree(info->argv);
70686 }
70687
70688-static int call_modprobe(char *module_name, int wait)
70689+static int call_modprobe(char *module_name, char *module_param, int wait)
70690 {
70691 static char *envp[] = {
70692 "HOME=/",
70693@@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
70694 NULL
70695 };
70696
70697- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
70698+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
70699 if (!argv)
70700 goto out;
70701
70702@@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
70703 argv[1] = "-q";
70704 argv[2] = "--";
70705 argv[3] = module_name; /* check free_modprobe_argv() */
70706- argv[4] = NULL;
70707+ argv[4] = module_param;
70708+ argv[5] = NULL;
70709
70710 return call_usermodehelper_fns(modprobe_path, argv, envp,
70711 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
70712@@ -120,9 +121,8 @@ out:
70713 * If module auto-loading support is disabled then this function
70714 * becomes a no-operation.
70715 */
70716-int __request_module(bool wait, const char *fmt, ...)
70717+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
70718 {
70719- va_list args;
70720 char module_name[MODULE_NAME_LEN];
70721 unsigned int max_modprobes;
70722 int ret;
70723@@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
70724 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
70725 static int kmod_loop_msg;
70726
70727- va_start(args, fmt);
70728- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
70729- va_end(args);
70730+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
70731 if (ret >= MODULE_NAME_LEN)
70732 return -ENAMETOOLONG;
70733
70734@@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
70735 if (ret)
70736 return ret;
70737
70738+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70739+ if (!current_uid()) {
70740+ /* hack to workaround consolekit/udisks stupidity */
70741+ read_lock(&tasklist_lock);
70742+ if (!strcmp(current->comm, "mount") &&
70743+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
70744+ read_unlock(&tasklist_lock);
70745+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
70746+ return -EPERM;
70747+ }
70748+ read_unlock(&tasklist_lock);
70749+ }
70750+#endif
70751+
70752 /* If modprobe needs a service that is in a module, we get a recursive
70753 * loop. Limit the number of running kmod threads to max_threads/2 or
70754 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
70755@@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
70756
70757 trace_module_request(module_name, wait, _RET_IP_);
70758
70759- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
70760+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
70761
70762 atomic_dec(&kmod_concurrent);
70763 return ret;
70764 }
70765+
70766+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
70767+{
70768+ va_list args;
70769+ int ret;
70770+
70771+ va_start(args, fmt);
70772+ ret = ____request_module(wait, module_param, fmt, args);
70773+ va_end(args);
70774+
70775+ return ret;
70776+}
70777+
70778+int __request_module(bool wait, const char *fmt, ...)
70779+{
70780+ va_list args;
70781+ int ret;
70782+
70783+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70784+ if (current_uid()) {
70785+ char module_param[MODULE_NAME_LEN];
70786+
70787+ memset(module_param, 0, sizeof(module_param));
70788+
70789+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
70790+
70791+ va_start(args, fmt);
70792+ ret = ____request_module(wait, module_param, fmt, args);
70793+ va_end(args);
70794+
70795+ return ret;
70796+ }
70797+#endif
70798+
70799+ va_start(args, fmt);
70800+ ret = ____request_module(wait, NULL, fmt, args);
70801+ va_end(args);
70802+
70803+ return ret;
70804+}
70805+
70806 EXPORT_SYMBOL(__request_module);
70807 #endif /* CONFIG_MODULES */
70808
70809@@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
70810 *
70811 * Thus the __user pointer cast is valid here.
70812 */
70813- sys_wait4(pid, (int __user *)&ret, 0, NULL);
70814+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
70815
70816 /*
70817 * If ret is 0, either ____call_usermodehelper failed and the
70818diff --git a/kernel/kprobes.c b/kernel/kprobes.c
70819index 098f396..fe85ff1 100644
70820--- a/kernel/kprobes.c
70821+++ b/kernel/kprobes.c
70822@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
70823 * kernel image and loaded module images reside. This is required
70824 * so x86_64 can correctly handle the %rip-relative fixups.
70825 */
70826- kip->insns = module_alloc(PAGE_SIZE);
70827+ kip->insns = module_alloc_exec(PAGE_SIZE);
70828 if (!kip->insns) {
70829 kfree(kip);
70830 return NULL;
70831@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
70832 */
70833 if (!list_is_singular(&kip->list)) {
70834 list_del(&kip->list);
70835- module_free(NULL, kip->insns);
70836+ module_free_exec(NULL, kip->insns);
70837 kfree(kip);
70838 }
70839 return 1;
70840@@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
70841 {
70842 int i, err = 0;
70843 unsigned long offset = 0, size = 0;
70844- char *modname, namebuf[128];
70845+ char *modname, namebuf[KSYM_NAME_LEN];
70846 const char *symbol_name;
70847 void *addr;
70848 struct kprobe_blackpoint *kb;
70849@@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
70850 kprobe_type = "k";
70851
70852 if (sym)
70853- seq_printf(pi, "%p %s %s+0x%x %s ",
70854+ seq_printf(pi, "%pK %s %s+0x%x %s ",
70855 p->addr, kprobe_type, sym, offset,
70856 (modname ? modname : " "));
70857 else
70858- seq_printf(pi, "%p %s %p ",
70859+ seq_printf(pi, "%pK %s %pK ",
70860 p->addr, kprobe_type, p->addr);
70861
70862 if (!pp)
70863@@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
70864 const char *sym = NULL;
70865 unsigned int i = *(loff_t *) v;
70866 unsigned long offset = 0;
70867- char *modname, namebuf[128];
70868+ char *modname, namebuf[KSYM_NAME_LEN];
70869
70870 head = &kprobe_table[i];
70871 preempt_disable();
70872diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
70873index 6ada93c..55baf4d 100644
70874--- a/kernel/ksysfs.c
70875+++ b/kernel/ksysfs.c
70876@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
70877 {
70878 if (count+1 > UEVENT_HELPER_PATH_LEN)
70879 return -ENOENT;
70880+ if (!capable(CAP_SYS_ADMIN))
70881+ return -EPERM;
70882 memcpy(uevent_helper, buf, count);
70883 uevent_helper[count] = '\0';
70884 if (count && uevent_helper[count-1] == '\n')
70885diff --git a/kernel/lockdep.c b/kernel/lockdep.c
70886index 7981e5b..7f2105c 100644
70887--- a/kernel/lockdep.c
70888+++ b/kernel/lockdep.c
70889@@ -590,6 +590,10 @@ static int static_obj(void *obj)
70890 end = (unsigned long) &_end,
70891 addr = (unsigned long) obj;
70892
70893+#ifdef CONFIG_PAX_KERNEXEC
70894+ start = ktla_ktva(start);
70895+#endif
70896+
70897 /*
70898 * static variable?
70899 */
70900@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
70901 if (!static_obj(lock->key)) {
70902 debug_locks_off();
70903 printk("INFO: trying to register non-static key.\n");
70904+ printk("lock:%pS key:%pS.\n", lock, lock->key);
70905 printk("the code is fine but needs lockdep annotation.\n");
70906 printk("turning off the locking correctness validator.\n");
70907 dump_stack();
70908@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
70909 if (!class)
70910 return 0;
70911 }
70912- atomic_inc((atomic_t *)&class->ops);
70913+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
70914 if (very_verbose(class)) {
70915 printk("\nacquire class [%p] %s", class->key, class->name);
70916 if (class->name_version > 1)
70917diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
70918index b2c71c5..7b88d63 100644
70919--- a/kernel/lockdep_proc.c
70920+++ b/kernel/lockdep_proc.c
70921@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
70922 return 0;
70923 }
70924
70925- seq_printf(m, "%p", class->key);
70926+ seq_printf(m, "%pK", class->key);
70927 #ifdef CONFIG_DEBUG_LOCKDEP
70928 seq_printf(m, " OPS:%8ld", class->ops);
70929 #endif
70930@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
70931
70932 list_for_each_entry(entry, &class->locks_after, entry) {
70933 if (entry->distance == 1) {
70934- seq_printf(m, " -> [%p] ", entry->class->key);
70935+ seq_printf(m, " -> [%pK] ", entry->class->key);
70936 print_name(m, entry->class);
70937 seq_puts(m, "\n");
70938 }
70939@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
70940 if (!class->key)
70941 continue;
70942
70943- seq_printf(m, "[%p] ", class->key);
70944+ seq_printf(m, "[%pK] ", class->key);
70945 print_name(m, class);
70946 seq_puts(m, "\n");
70947 }
70948@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70949 if (!i)
70950 seq_line(m, '-', 40-namelen, namelen);
70951
70952- snprintf(ip, sizeof(ip), "[<%p>]",
70953+ snprintf(ip, sizeof(ip), "[<%pK>]",
70954 (void *)class->contention_point[i]);
70955 seq_printf(m, "%40s %14lu %29s %pS\n",
70956 name, stats->contention_point[i],
70957@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70958 if (!i)
70959 seq_line(m, '-', 40-namelen, namelen);
70960
70961- snprintf(ip, sizeof(ip), "[<%p>]",
70962+ snprintf(ip, sizeof(ip), "[<%pK>]",
70963 (void *)class->contending_point[i]);
70964 seq_printf(m, "%40s %14lu %29s %pS\n",
70965 name, stats->contending_point[i],
70966diff --git a/kernel/module.c b/kernel/module.c
70967index eab0827..75ede66 100644
70968--- a/kernel/module.c
70969+++ b/kernel/module.c
70970@@ -61,6 +61,7 @@
70971 #include <linux/pfn.h>
70972 #include <linux/bsearch.h>
70973 #include <linux/fips.h>
70974+#include <linux/grsecurity.h>
70975 #include <uapi/linux/module.h>
70976 #include "module-internal.h"
70977
70978@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
70979
70980 /* Bounds of module allocation, for speeding __module_address.
70981 * Protected by module_mutex. */
70982-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
70983+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
70984+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
70985
70986 int register_module_notifier(struct notifier_block * nb)
70987 {
70988@@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70989 return true;
70990
70991 list_for_each_entry_rcu(mod, &modules, list) {
70992- struct symsearch arr[] = {
70993+ struct symsearch modarr[] = {
70994 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
70995 NOT_GPL_ONLY, false },
70996 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
70997@@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70998 if (mod->state == MODULE_STATE_UNFORMED)
70999 continue;
71000
71001- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
71002+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
71003 return true;
71004 }
71005 return false;
71006@@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
71007 static int percpu_modalloc(struct module *mod,
71008 unsigned long size, unsigned long align)
71009 {
71010- if (align > PAGE_SIZE) {
71011+ if (align-1 >= PAGE_SIZE) {
71012 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
71013 mod->name, align, PAGE_SIZE);
71014 align = PAGE_SIZE;
71015@@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
71016 static ssize_t show_coresize(struct module_attribute *mattr,
71017 struct module_kobject *mk, char *buffer)
71018 {
71019- return sprintf(buffer, "%u\n", mk->mod->core_size);
71020+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
71021 }
71022
71023 static struct module_attribute modinfo_coresize =
71024@@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
71025 static ssize_t show_initsize(struct module_attribute *mattr,
71026 struct module_kobject *mk, char *buffer)
71027 {
71028- return sprintf(buffer, "%u\n", mk->mod->init_size);
71029+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
71030 }
71031
71032 static struct module_attribute modinfo_initsize =
71033@@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
71034 */
71035 #ifdef CONFIG_SYSFS
71036
71037-#ifdef CONFIG_KALLSYMS
71038+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
71039 static inline bool sect_empty(const Elf_Shdr *sect)
71040 {
71041 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
71042@@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
71043
71044 static void unset_module_core_ro_nx(struct module *mod)
71045 {
71046- set_page_attributes(mod->module_core + mod->core_text_size,
71047- mod->module_core + mod->core_size,
71048+ set_page_attributes(mod->module_core_rw,
71049+ mod->module_core_rw + mod->core_size_rw,
71050 set_memory_x);
71051- set_page_attributes(mod->module_core,
71052- mod->module_core + mod->core_ro_size,
71053+ set_page_attributes(mod->module_core_rx,
71054+ mod->module_core_rx + mod->core_size_rx,
71055 set_memory_rw);
71056 }
71057
71058 static void unset_module_init_ro_nx(struct module *mod)
71059 {
71060- set_page_attributes(mod->module_init + mod->init_text_size,
71061- mod->module_init + mod->init_size,
71062+ set_page_attributes(mod->module_init_rw,
71063+ mod->module_init_rw + mod->init_size_rw,
71064 set_memory_x);
71065- set_page_attributes(mod->module_init,
71066- mod->module_init + mod->init_ro_size,
71067+ set_page_attributes(mod->module_init_rx,
71068+ mod->module_init_rx + mod->init_size_rx,
71069 set_memory_rw);
71070 }
71071
71072@@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
71073 list_for_each_entry_rcu(mod, &modules, list) {
71074 if (mod->state == MODULE_STATE_UNFORMED)
71075 continue;
71076- if ((mod->module_core) && (mod->core_text_size)) {
71077- set_page_attributes(mod->module_core,
71078- mod->module_core + mod->core_text_size,
71079+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
71080+ set_page_attributes(mod->module_core_rx,
71081+ mod->module_core_rx + mod->core_size_rx,
71082 set_memory_rw);
71083 }
71084- if ((mod->module_init) && (mod->init_text_size)) {
71085- set_page_attributes(mod->module_init,
71086- mod->module_init + mod->init_text_size,
71087+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
71088+ set_page_attributes(mod->module_init_rx,
71089+ mod->module_init_rx + mod->init_size_rx,
71090 set_memory_rw);
71091 }
71092 }
71093@@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
71094 list_for_each_entry_rcu(mod, &modules, list) {
71095 if (mod->state == MODULE_STATE_UNFORMED)
71096 continue;
71097- if ((mod->module_core) && (mod->core_text_size)) {
71098- set_page_attributes(mod->module_core,
71099- mod->module_core + mod->core_text_size,
71100+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
71101+ set_page_attributes(mod->module_core_rx,
71102+ mod->module_core_rx + mod->core_size_rx,
71103 set_memory_ro);
71104 }
71105- if ((mod->module_init) && (mod->init_text_size)) {
71106- set_page_attributes(mod->module_init,
71107- mod->module_init + mod->init_text_size,
71108+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
71109+ set_page_attributes(mod->module_init_rx,
71110+ mod->module_init_rx + mod->init_size_rx,
71111 set_memory_ro);
71112 }
71113 }
71114@@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
71115
71116 /* This may be NULL, but that's OK */
71117 unset_module_init_ro_nx(mod);
71118- module_free(mod, mod->module_init);
71119+ module_free(mod, mod->module_init_rw);
71120+ module_free_exec(mod, mod->module_init_rx);
71121 kfree(mod->args);
71122 percpu_modfree(mod);
71123
71124 /* Free lock-classes: */
71125- lockdep_free_key_range(mod->module_core, mod->core_size);
71126+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
71127+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
71128
71129 /* Finally, free the core (containing the module structure) */
71130 unset_module_core_ro_nx(mod);
71131- module_free(mod, mod->module_core);
71132+ module_free_exec(mod, mod->module_core_rx);
71133+ module_free(mod, mod->module_core_rw);
71134
71135 #ifdef CONFIG_MPU
71136 update_protections(current->mm);
71137@@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71138 int ret = 0;
71139 const struct kernel_symbol *ksym;
71140
71141+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71142+ int is_fs_load = 0;
71143+ int register_filesystem_found = 0;
71144+ char *p;
71145+
71146+ p = strstr(mod->args, "grsec_modharden_fs");
71147+ if (p) {
71148+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
71149+ /* copy \0 as well */
71150+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
71151+ is_fs_load = 1;
71152+ }
71153+#endif
71154+
71155 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
71156 const char *name = info->strtab + sym[i].st_name;
71157
71158+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71159+ /* it's a real shame this will never get ripped and copied
71160+ upstream! ;(
71161+ */
71162+ if (is_fs_load && !strcmp(name, "register_filesystem"))
71163+ register_filesystem_found = 1;
71164+#endif
71165+
71166 switch (sym[i].st_shndx) {
71167 case SHN_COMMON:
71168 /* We compiled with -fno-common. These are not
71169@@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71170 ksym = resolve_symbol_wait(mod, info, name);
71171 /* Ok if resolved. */
71172 if (ksym && !IS_ERR(ksym)) {
71173+ pax_open_kernel();
71174 sym[i].st_value = ksym->value;
71175+ pax_close_kernel();
71176 break;
71177 }
71178
71179@@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71180 secbase = (unsigned long)mod_percpu(mod);
71181 else
71182 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
71183+ pax_open_kernel();
71184 sym[i].st_value += secbase;
71185+ pax_close_kernel();
71186 break;
71187 }
71188 }
71189
71190+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71191+ if (is_fs_load && !register_filesystem_found) {
71192+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
71193+ ret = -EPERM;
71194+ }
71195+#endif
71196+
71197 return ret;
71198 }
71199
71200@@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
71201 || s->sh_entsize != ~0UL
71202 || strstarts(sname, ".init"))
71203 continue;
71204- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
71205+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71206+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
71207+ else
71208+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
71209 pr_debug("\t%s\n", sname);
71210 }
71211- switch (m) {
71212- case 0: /* executable */
71213- mod->core_size = debug_align(mod->core_size);
71214- mod->core_text_size = mod->core_size;
71215- break;
71216- case 1: /* RO: text and ro-data */
71217- mod->core_size = debug_align(mod->core_size);
71218- mod->core_ro_size = mod->core_size;
71219- break;
71220- case 3: /* whole core */
71221- mod->core_size = debug_align(mod->core_size);
71222- break;
71223- }
71224 }
71225
71226 pr_debug("Init section allocation order:\n");
71227@@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
71228 || s->sh_entsize != ~0UL
71229 || !strstarts(sname, ".init"))
71230 continue;
71231- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
71232- | INIT_OFFSET_MASK);
71233+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71234+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
71235+ else
71236+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
71237+ s->sh_entsize |= INIT_OFFSET_MASK;
71238 pr_debug("\t%s\n", sname);
71239 }
71240- switch (m) {
71241- case 0: /* executable */
71242- mod->init_size = debug_align(mod->init_size);
71243- mod->init_text_size = mod->init_size;
71244- break;
71245- case 1: /* RO: text and ro-data */
71246- mod->init_size = debug_align(mod->init_size);
71247- mod->init_ro_size = mod->init_size;
71248- break;
71249- case 3: /* whole init */
71250- mod->init_size = debug_align(mod->init_size);
71251- break;
71252- }
71253 }
71254 }
71255
71256@@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
71257
71258 /* Put symbol section at end of init part of module. */
71259 symsect->sh_flags |= SHF_ALLOC;
71260- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
71261+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
71262 info->index.sym) | INIT_OFFSET_MASK;
71263 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
71264
71265@@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
71266 }
71267
71268 /* Append room for core symbols at end of core part. */
71269- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
71270- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
71271- mod->core_size += strtab_size;
71272+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
71273+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
71274+ mod->core_size_rx += strtab_size;
71275
71276 /* Put string table section at end of init part of module. */
71277 strsect->sh_flags |= SHF_ALLOC;
71278- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
71279+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
71280 info->index.str) | INIT_OFFSET_MASK;
71281 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
71282 }
71283@@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
71284 /* Make sure we get permanent strtab: don't use info->strtab. */
71285 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
71286
71287+ pax_open_kernel();
71288+
71289 /* Set types up while we still have access to sections. */
71290 for (i = 0; i < mod->num_symtab; i++)
71291 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
71292
71293- mod->core_symtab = dst = mod->module_core + info->symoffs;
71294- mod->core_strtab = s = mod->module_core + info->stroffs;
71295+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
71296+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
71297 src = mod->symtab;
71298 for (ndst = i = 0; i < mod->num_symtab; i++) {
71299 if (i == 0 ||
71300@@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
71301 }
71302 }
71303 mod->core_num_syms = ndst;
71304+
71305+ pax_close_kernel();
71306 }
71307 #else
71308 static inline void layout_symtab(struct module *mod, struct load_info *info)
71309@@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
71310 return vmalloc_exec(size);
71311 }
71312
71313-static void *module_alloc_update_bounds(unsigned long size)
71314+static void *module_alloc_update_bounds_rw(unsigned long size)
71315 {
71316 void *ret = module_alloc(size);
71317
71318 if (ret) {
71319 mutex_lock(&module_mutex);
71320 /* Update module bounds. */
71321- if ((unsigned long)ret < module_addr_min)
71322- module_addr_min = (unsigned long)ret;
71323- if ((unsigned long)ret + size > module_addr_max)
71324- module_addr_max = (unsigned long)ret + size;
71325+ if ((unsigned long)ret < module_addr_min_rw)
71326+ module_addr_min_rw = (unsigned long)ret;
71327+ if ((unsigned long)ret + size > module_addr_max_rw)
71328+ module_addr_max_rw = (unsigned long)ret + size;
71329+ mutex_unlock(&module_mutex);
71330+ }
71331+ return ret;
71332+}
71333+
71334+static void *module_alloc_update_bounds_rx(unsigned long size)
71335+{
71336+ void *ret = module_alloc_exec(size);
71337+
71338+ if (ret) {
71339+ mutex_lock(&module_mutex);
71340+ /* Update module bounds. */
71341+ if ((unsigned long)ret < module_addr_min_rx)
71342+ module_addr_min_rx = (unsigned long)ret;
71343+ if ((unsigned long)ret + size > module_addr_max_rx)
71344+ module_addr_max_rx = (unsigned long)ret + size;
71345 mutex_unlock(&module_mutex);
71346 }
71347 return ret;
71348@@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
71349 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
71350 {
71351 const char *modmagic = get_modinfo(info, "vermagic");
71352+ const char *license = get_modinfo(info, "license");
71353 int err;
71354
71355+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
71356+ if (!license || !license_is_gpl_compatible(license))
71357+ return -ENOEXEC;
71358+#endif
71359+
71360 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
71361 modmagic = NULL;
71362
71363@@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
71364 }
71365
71366 /* Set up license info based on the info section */
71367- set_license(mod, get_modinfo(info, "license"));
71368+ set_license(mod, license);
71369
71370 return 0;
71371 }
71372@@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
71373 void *ptr;
71374
71375 /* Do the allocs. */
71376- ptr = module_alloc_update_bounds(mod->core_size);
71377+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
71378 /*
71379 * The pointer to this block is stored in the module structure
71380 * which is inside the block. Just mark it as not being a
71381@@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
71382 if (!ptr)
71383 return -ENOMEM;
71384
71385- memset(ptr, 0, mod->core_size);
71386- mod->module_core = ptr;
71387+ memset(ptr, 0, mod->core_size_rw);
71388+ mod->module_core_rw = ptr;
71389
71390- if (mod->init_size) {
71391- ptr = module_alloc_update_bounds(mod->init_size);
71392+ if (mod->init_size_rw) {
71393+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
71394 /*
71395 * The pointer to this block is stored in the module structure
71396 * which is inside the block. This block doesn't need to be
71397@@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
71398 */
71399 kmemleak_ignore(ptr);
71400 if (!ptr) {
71401- module_free(mod, mod->module_core);
71402+ module_free(mod, mod->module_core_rw);
71403 return -ENOMEM;
71404 }
71405- memset(ptr, 0, mod->init_size);
71406- mod->module_init = ptr;
71407+ memset(ptr, 0, mod->init_size_rw);
71408+ mod->module_init_rw = ptr;
71409 } else
71410- mod->module_init = NULL;
71411+ mod->module_init_rw = NULL;
71412+
71413+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
71414+ kmemleak_not_leak(ptr);
71415+ if (!ptr) {
71416+ if (mod->module_init_rw)
71417+ module_free(mod, mod->module_init_rw);
71418+ module_free(mod, mod->module_core_rw);
71419+ return -ENOMEM;
71420+ }
71421+
71422+ pax_open_kernel();
71423+ memset(ptr, 0, mod->core_size_rx);
71424+ pax_close_kernel();
71425+ mod->module_core_rx = ptr;
71426+
71427+ if (mod->init_size_rx) {
71428+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
71429+ kmemleak_ignore(ptr);
71430+ if (!ptr && mod->init_size_rx) {
71431+ module_free_exec(mod, mod->module_core_rx);
71432+ if (mod->module_init_rw)
71433+ module_free(mod, mod->module_init_rw);
71434+ module_free(mod, mod->module_core_rw);
71435+ return -ENOMEM;
71436+ }
71437+
71438+ pax_open_kernel();
71439+ memset(ptr, 0, mod->init_size_rx);
71440+ pax_close_kernel();
71441+ mod->module_init_rx = ptr;
71442+ } else
71443+ mod->module_init_rx = NULL;
71444
71445 /* Transfer each section which specifies SHF_ALLOC */
71446 pr_debug("final section addresses:\n");
71447@@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
71448 if (!(shdr->sh_flags & SHF_ALLOC))
71449 continue;
71450
71451- if (shdr->sh_entsize & INIT_OFFSET_MASK)
71452- dest = mod->module_init
71453- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71454- else
71455- dest = mod->module_core + shdr->sh_entsize;
71456+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
71457+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
71458+ dest = mod->module_init_rw
71459+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71460+ else
71461+ dest = mod->module_init_rx
71462+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71463+ } else {
71464+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
71465+ dest = mod->module_core_rw + shdr->sh_entsize;
71466+ else
71467+ dest = mod->module_core_rx + shdr->sh_entsize;
71468+ }
71469+
71470+ if (shdr->sh_type != SHT_NOBITS) {
71471+
71472+#ifdef CONFIG_PAX_KERNEXEC
71473+#ifdef CONFIG_X86_64
71474+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
71475+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
71476+#endif
71477+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
71478+ pax_open_kernel();
71479+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
71480+ pax_close_kernel();
71481+ } else
71482+#endif
71483
71484- if (shdr->sh_type != SHT_NOBITS)
71485 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
71486+ }
71487 /* Update sh_addr to point to copy in image. */
71488- shdr->sh_addr = (unsigned long)dest;
71489+
71490+#ifdef CONFIG_PAX_KERNEXEC
71491+ if (shdr->sh_flags & SHF_EXECINSTR)
71492+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
71493+ else
71494+#endif
71495+
71496+ shdr->sh_addr = (unsigned long)dest;
71497 pr_debug("\t0x%lx %s\n",
71498 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
71499 }
71500@@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
71501 * Do it before processing of module parameters, so the module
71502 * can provide parameter accessor functions of its own.
71503 */
71504- if (mod->module_init)
71505- flush_icache_range((unsigned long)mod->module_init,
71506- (unsigned long)mod->module_init
71507- + mod->init_size);
71508- flush_icache_range((unsigned long)mod->module_core,
71509- (unsigned long)mod->module_core + mod->core_size);
71510+ if (mod->module_init_rx)
71511+ flush_icache_range((unsigned long)mod->module_init_rx,
71512+ (unsigned long)mod->module_init_rx
71513+ + mod->init_size_rx);
71514+ flush_icache_range((unsigned long)mod->module_core_rx,
71515+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
71516
71517 set_fs(old_fs);
71518 }
71519@@ -2983,8 +3088,10 @@ out:
71520 static void module_deallocate(struct module *mod, struct load_info *info)
71521 {
71522 percpu_modfree(mod);
71523- module_free(mod, mod->module_init);
71524- module_free(mod, mod->module_core);
71525+ module_free_exec(mod, mod->module_init_rx);
71526+ module_free_exec(mod, mod->module_core_rx);
71527+ module_free(mod, mod->module_init_rw);
71528+ module_free(mod, mod->module_core_rw);
71529 }
71530
71531 int __weak module_finalize(const Elf_Ehdr *hdr,
71532@@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
71533 static int post_relocation(struct module *mod, const struct load_info *info)
71534 {
71535 /* Sort exception table now relocations are done. */
71536+ pax_open_kernel();
71537 sort_extable(mod->extable, mod->extable + mod->num_exentries);
71538+ pax_close_kernel();
71539
71540 /* Copy relocated percpu area over. */
71541 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
71542@@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
71543 MODULE_STATE_COMING, mod);
71544
71545 /* Set RO and NX regions for core */
71546- set_section_ro_nx(mod->module_core,
71547- mod->core_text_size,
71548- mod->core_ro_size,
71549- mod->core_size);
71550+ set_section_ro_nx(mod->module_core_rx,
71551+ mod->core_size_rx,
71552+ mod->core_size_rx,
71553+ mod->core_size_rx);
71554
71555 /* Set RO and NX regions for init */
71556- set_section_ro_nx(mod->module_init,
71557- mod->init_text_size,
71558- mod->init_ro_size,
71559- mod->init_size);
71560+ set_section_ro_nx(mod->module_init_rx,
71561+ mod->init_size_rx,
71562+ mod->init_size_rx,
71563+ mod->init_size_rx);
71564
71565 do_mod_ctors(mod);
71566 /* Start the module */
71567@@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
71568 mod->strtab = mod->core_strtab;
71569 #endif
71570 unset_module_init_ro_nx(mod);
71571- module_free(mod, mod->module_init);
71572- mod->module_init = NULL;
71573- mod->init_size = 0;
71574- mod->init_ro_size = 0;
71575- mod->init_text_size = 0;
71576+ module_free(mod, mod->module_init_rw);
71577+ module_free_exec(mod, mod->module_init_rx);
71578+ mod->module_init_rw = NULL;
71579+ mod->module_init_rx = NULL;
71580+ mod->init_size_rw = 0;
71581+ mod->init_size_rx = 0;
71582 mutex_unlock(&module_mutex);
71583 wake_up_all(&module_wq);
71584
71585@@ -3209,9 +3319,38 @@ again:
71586 if (err)
71587 goto free_unload;
71588
71589+ /* Now copy in args */
71590+ mod->args = strndup_user(uargs, ~0UL >> 1);
71591+ if (IS_ERR(mod->args)) {
71592+ err = PTR_ERR(mod->args);
71593+ goto free_unload;
71594+ }
71595+
71596 /* Set up MODINFO_ATTR fields */
71597 setup_modinfo(mod, info);
71598
71599+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71600+ {
71601+ char *p, *p2;
71602+
71603+ if (strstr(mod->args, "grsec_modharden_netdev")) {
71604+ 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);
71605+ err = -EPERM;
71606+ goto free_modinfo;
71607+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
71608+ p += sizeof("grsec_modharden_normal") - 1;
71609+ p2 = strstr(p, "_");
71610+ if (p2) {
71611+ *p2 = '\0';
71612+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
71613+ *p2 = '_';
71614+ }
71615+ err = -EPERM;
71616+ goto free_modinfo;
71617+ }
71618+ }
71619+#endif
71620+
71621 /* Fix up syms, so that st_value is a pointer to location. */
71622 err = simplify_symbols(mod, info);
71623 if (err < 0)
71624@@ -3227,13 +3366,6 @@ again:
71625
71626 flush_module_icache(mod);
71627
71628- /* Now copy in args */
71629- mod->args = strndup_user(uargs, ~0UL >> 1);
71630- if (IS_ERR(mod->args)) {
71631- err = PTR_ERR(mod->args);
71632- goto free_arch_cleanup;
71633- }
71634-
71635 dynamic_debug_setup(info->debug, info->num_debug);
71636
71637 mutex_lock(&module_mutex);
71638@@ -3278,11 +3410,10 @@ again:
71639 mutex_unlock(&module_mutex);
71640 dynamic_debug_remove(info->debug);
71641 synchronize_sched();
71642- kfree(mod->args);
71643- free_arch_cleanup:
71644 module_arch_cleanup(mod);
71645 free_modinfo:
71646 free_modinfo(mod);
71647+ kfree(mod->args);
71648 free_unload:
71649 module_unload_free(mod);
71650 unlink_mod:
71651@@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
71652 unsigned long nextval;
71653
71654 /* At worse, next value is at end of module */
71655- if (within_module_init(addr, mod))
71656- nextval = (unsigned long)mod->module_init+mod->init_text_size;
71657+ if (within_module_init_rx(addr, mod))
71658+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
71659+ else if (within_module_init_rw(addr, mod))
71660+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
71661+ else if (within_module_core_rx(addr, mod))
71662+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
71663+ else if (within_module_core_rw(addr, mod))
71664+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
71665 else
71666- nextval = (unsigned long)mod->module_core+mod->core_text_size;
71667+ return NULL;
71668
71669 /* Scan for closest preceding symbol, and next symbol. (ELF
71670 starts real symbols at 1). */
71671@@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
71672 return 0;
71673
71674 seq_printf(m, "%s %u",
71675- mod->name, mod->init_size + mod->core_size);
71676+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
71677 print_unload_info(m, mod);
71678
71679 /* Informative for users. */
71680@@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
71681 mod->state == MODULE_STATE_COMING ? "Loading":
71682 "Live");
71683 /* Used by oprofile and other similar tools. */
71684- seq_printf(m, " 0x%pK", mod->module_core);
71685+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
71686
71687 /* Taints info */
71688 if (mod->taints)
71689@@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
71690
71691 static int __init proc_modules_init(void)
71692 {
71693+#ifndef CONFIG_GRKERNSEC_HIDESYM
71694+#ifdef CONFIG_GRKERNSEC_PROC_USER
71695+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
71696+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71697+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
71698+#else
71699 proc_create("modules", 0, NULL, &proc_modules_operations);
71700+#endif
71701+#else
71702+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
71703+#endif
71704 return 0;
71705 }
71706 module_init(proc_modules_init);
71707@@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
71708 {
71709 struct module *mod;
71710
71711- if (addr < module_addr_min || addr > module_addr_max)
71712+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
71713+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
71714 return NULL;
71715
71716 list_for_each_entry_rcu(mod, &modules, list) {
71717 if (mod->state == MODULE_STATE_UNFORMED)
71718 continue;
71719- if (within_module_core(addr, mod)
71720- || within_module_init(addr, mod))
71721+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
71722 return mod;
71723 }
71724 return NULL;
71725@@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
71726 */
71727 struct module *__module_text_address(unsigned long addr)
71728 {
71729- struct module *mod = __module_address(addr);
71730+ struct module *mod;
71731+
71732+#ifdef CONFIG_X86_32
71733+ addr = ktla_ktva(addr);
71734+#endif
71735+
71736+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
71737+ return NULL;
71738+
71739+ mod = __module_address(addr);
71740+
71741 if (mod) {
71742 /* Make sure it's within the text section. */
71743- if (!within(addr, mod->module_init, mod->init_text_size)
71744- && !within(addr, mod->module_core, mod->core_text_size))
71745+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
71746 mod = NULL;
71747 }
71748 return mod;
71749diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
71750index 7e3443f..b2a1e6b 100644
71751--- a/kernel/mutex-debug.c
71752+++ b/kernel/mutex-debug.c
71753@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
71754 }
71755
71756 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71757- struct thread_info *ti)
71758+ struct task_struct *task)
71759 {
71760 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
71761
71762 /* Mark the current thread as blocked on the lock: */
71763- ti->task->blocked_on = waiter;
71764+ task->blocked_on = waiter;
71765 }
71766
71767 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71768- struct thread_info *ti)
71769+ struct task_struct *task)
71770 {
71771 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
71772- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
71773- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
71774- ti->task->blocked_on = NULL;
71775+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
71776+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
71777+ task->blocked_on = NULL;
71778
71779 list_del_init(&waiter->list);
71780 waiter->task = NULL;
71781diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
71782index 0799fd3..d06ae3b 100644
71783--- a/kernel/mutex-debug.h
71784+++ b/kernel/mutex-debug.h
71785@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
71786 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
71787 extern void debug_mutex_add_waiter(struct mutex *lock,
71788 struct mutex_waiter *waiter,
71789- struct thread_info *ti);
71790+ struct task_struct *task);
71791 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71792- struct thread_info *ti);
71793+ struct task_struct *task);
71794 extern void debug_mutex_unlock(struct mutex *lock);
71795 extern void debug_mutex_init(struct mutex *lock, const char *name,
71796 struct lock_class_key *key);
71797diff --git a/kernel/mutex.c b/kernel/mutex.c
71798index a307cc9..27fd2e9 100644
71799--- a/kernel/mutex.c
71800+++ b/kernel/mutex.c
71801@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71802 spin_lock_mutex(&lock->wait_lock, flags);
71803
71804 debug_mutex_lock_common(lock, &waiter);
71805- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
71806+ debug_mutex_add_waiter(lock, &waiter, task);
71807
71808 /* add waiting tasks to the end of the waitqueue (FIFO): */
71809 list_add_tail(&waiter.list, &lock->wait_list);
71810@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71811 * TASK_UNINTERRUPTIBLE case.)
71812 */
71813 if (unlikely(signal_pending_state(state, task))) {
71814- mutex_remove_waiter(lock, &waiter,
71815- task_thread_info(task));
71816+ mutex_remove_waiter(lock, &waiter, task);
71817 mutex_release(&lock->dep_map, 1, ip);
71818 spin_unlock_mutex(&lock->wait_lock, flags);
71819
71820@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71821 done:
71822 lock_acquired(&lock->dep_map, ip);
71823 /* got the lock - rejoice! */
71824- mutex_remove_waiter(lock, &waiter, current_thread_info());
71825+ mutex_remove_waiter(lock, &waiter, task);
71826 mutex_set_owner(lock);
71827
71828 /* set it to 0 if there are no waiters left: */
71829diff --git a/kernel/notifier.c b/kernel/notifier.c
71830index 2d5cc4c..d9ea600 100644
71831--- a/kernel/notifier.c
71832+++ b/kernel/notifier.c
71833@@ -5,6 +5,7 @@
71834 #include <linux/rcupdate.h>
71835 #include <linux/vmalloc.h>
71836 #include <linux/reboot.h>
71837+#include <linux/mm.h>
71838
71839 /*
71840 * Notifier list for kernel code which wants to be called
71841@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
71842 while ((*nl) != NULL) {
71843 if (n->priority > (*nl)->priority)
71844 break;
71845- nl = &((*nl)->next);
71846+ nl = (struct notifier_block **)&((*nl)->next);
71847 }
71848- n->next = *nl;
71849+ pax_open_kernel();
71850+ *(const void **)&n->next = *nl;
71851 rcu_assign_pointer(*nl, n);
71852+ pax_close_kernel();
71853 return 0;
71854 }
71855
71856@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
71857 return 0;
71858 if (n->priority > (*nl)->priority)
71859 break;
71860- nl = &((*nl)->next);
71861+ nl = (struct notifier_block **)&((*nl)->next);
71862 }
71863- n->next = *nl;
71864+ pax_open_kernel();
71865+ *(const void **)&n->next = *nl;
71866 rcu_assign_pointer(*nl, n);
71867+ pax_close_kernel();
71868 return 0;
71869 }
71870
71871@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
71872 {
71873 while ((*nl) != NULL) {
71874 if ((*nl) == n) {
71875+ pax_open_kernel();
71876 rcu_assign_pointer(*nl, n->next);
71877+ pax_close_kernel();
71878 return 0;
71879 }
71880- nl = &((*nl)->next);
71881+ nl = (struct notifier_block **)&((*nl)->next);
71882 }
71883 return -ENOENT;
71884 }
71885diff --git a/kernel/panic.c b/kernel/panic.c
71886index e1b2822..5edc1d9 100644
71887--- a/kernel/panic.c
71888+++ b/kernel/panic.c
71889@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
71890 const char *board;
71891
71892 printk(KERN_WARNING "------------[ cut here ]------------\n");
71893- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
71894+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
71895 board = dmi_get_system_info(DMI_PRODUCT_NAME);
71896 if (board)
71897 printk(KERN_WARNING "Hardware name: %s\n", board);
71898@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
71899 */
71900 void __stack_chk_fail(void)
71901 {
71902- panic("stack-protector: Kernel stack is corrupted in: %p\n",
71903+ dump_stack();
71904+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
71905 __builtin_return_address(0));
71906 }
71907 EXPORT_SYMBOL(__stack_chk_fail);
71908diff --git a/kernel/pid.c b/kernel/pid.c
71909index f2c6a68..4922d97 100644
71910--- a/kernel/pid.c
71911+++ b/kernel/pid.c
71912@@ -33,6 +33,7 @@
71913 #include <linux/rculist.h>
71914 #include <linux/bootmem.h>
71915 #include <linux/hash.h>
71916+#include <linux/security.h>
71917 #include <linux/pid_namespace.h>
71918 #include <linux/init_task.h>
71919 #include <linux/syscalls.h>
71920@@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
71921
71922 int pid_max = PID_MAX_DEFAULT;
71923
71924-#define RESERVED_PIDS 300
71925+#define RESERVED_PIDS 500
71926
71927 int pid_max_min = RESERVED_PIDS + 1;
71928 int pid_max_max = PID_MAX_LIMIT;
71929@@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
71930 */
71931 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
71932 {
71933+ struct task_struct *task;
71934+
71935 rcu_lockdep_assert(rcu_read_lock_held(),
71936 "find_task_by_pid_ns() needs rcu_read_lock()"
71937 " protection");
71938- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71939+
71940+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71941+
71942+ if (gr_pid_is_chrooted(task))
71943+ return NULL;
71944+
71945+ return task;
71946 }
71947
71948 struct task_struct *find_task_by_vpid(pid_t vnr)
71949@@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
71950 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
71951 }
71952
71953+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
71954+{
71955+ rcu_lockdep_assert(rcu_read_lock_held(),
71956+ "find_task_by_pid_ns() needs rcu_read_lock()"
71957+ " protection");
71958+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
71959+}
71960+
71961 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
71962 {
71963 struct pid *pid;
71964diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
71965index 942ca27..111e609 100644
71966--- a/kernel/posix-cpu-timers.c
71967+++ b/kernel/posix-cpu-timers.c
71968@@ -1576,14 +1576,14 @@ struct k_clock clock_posix_cpu = {
71969
71970 static __init int init_posix_cpu_timers(void)
71971 {
71972- struct k_clock process = {
71973+ static struct k_clock process = {
71974 .clock_getres = process_cpu_clock_getres,
71975 .clock_get = process_cpu_clock_get,
71976 .timer_create = process_cpu_timer_create,
71977 .nsleep = process_cpu_nsleep,
71978 .nsleep_restart = process_cpu_nsleep_restart,
71979 };
71980- struct k_clock thread = {
71981+ static struct k_clock thread = {
71982 .clock_getres = thread_cpu_clock_getres,
71983 .clock_get = thread_cpu_clock_get,
71984 .timer_create = thread_cpu_timer_create,
71985diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
71986index 69185ae..cc2847a 100644
71987--- a/kernel/posix-timers.c
71988+++ b/kernel/posix-timers.c
71989@@ -43,6 +43,7 @@
71990 #include <linux/idr.h>
71991 #include <linux/posix-clock.h>
71992 #include <linux/posix-timers.h>
71993+#include <linux/grsecurity.h>
71994 #include <linux/syscalls.h>
71995 #include <linux/wait.h>
71996 #include <linux/workqueue.h>
71997@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
71998 * which we beg off on and pass to do_sys_settimeofday().
71999 */
72000
72001-static struct k_clock posix_clocks[MAX_CLOCKS];
72002+static struct k_clock *posix_clocks[MAX_CLOCKS];
72003
72004 /*
72005 * These ones are defined below.
72006@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
72007 */
72008 static __init int init_posix_timers(void)
72009 {
72010- struct k_clock clock_realtime = {
72011+ static struct k_clock clock_realtime = {
72012 .clock_getres = hrtimer_get_res,
72013 .clock_get = posix_clock_realtime_get,
72014 .clock_set = posix_clock_realtime_set,
72015@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
72016 .timer_get = common_timer_get,
72017 .timer_del = common_timer_del,
72018 };
72019- struct k_clock clock_monotonic = {
72020+ static struct k_clock clock_monotonic = {
72021 .clock_getres = hrtimer_get_res,
72022 .clock_get = posix_ktime_get_ts,
72023 .nsleep = common_nsleep,
72024@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
72025 .timer_get = common_timer_get,
72026 .timer_del = common_timer_del,
72027 };
72028- struct k_clock clock_monotonic_raw = {
72029+ static struct k_clock clock_monotonic_raw = {
72030 .clock_getres = hrtimer_get_res,
72031 .clock_get = posix_get_monotonic_raw,
72032 };
72033- struct k_clock clock_realtime_coarse = {
72034+ static struct k_clock clock_realtime_coarse = {
72035 .clock_getres = posix_get_coarse_res,
72036 .clock_get = posix_get_realtime_coarse,
72037 };
72038- struct k_clock clock_monotonic_coarse = {
72039+ static struct k_clock clock_monotonic_coarse = {
72040 .clock_getres = posix_get_coarse_res,
72041 .clock_get = posix_get_monotonic_coarse,
72042 };
72043- struct k_clock clock_boottime = {
72044+ static struct k_clock clock_boottime = {
72045 .clock_getres = hrtimer_get_res,
72046 .clock_get = posix_get_boottime,
72047 .nsleep = common_nsleep,
72048@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
72049 return;
72050 }
72051
72052- posix_clocks[clock_id] = *new_clock;
72053+ posix_clocks[clock_id] = new_clock;
72054 }
72055 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
72056
72057@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
72058 return (id & CLOCKFD_MASK) == CLOCKFD ?
72059 &clock_posix_dynamic : &clock_posix_cpu;
72060
72061- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
72062+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
72063 return NULL;
72064- return &posix_clocks[id];
72065+ return posix_clocks[id];
72066 }
72067
72068 static int common_timer_create(struct k_itimer *new_timer)
72069@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
72070 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
72071 return -EFAULT;
72072
72073+ /* only the CLOCK_REALTIME clock can be set, all other clocks
72074+ have their clock_set fptr set to a nosettime dummy function
72075+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
72076+ call common_clock_set, which calls do_sys_settimeofday, which
72077+ we hook
72078+ */
72079+
72080 return kc->clock_set(which_clock, &new_tp);
72081 }
72082
72083diff --git a/kernel/power/process.c b/kernel/power/process.c
72084index d5a258b..4271191 100644
72085--- a/kernel/power/process.c
72086+++ b/kernel/power/process.c
72087@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
72088 u64 elapsed_csecs64;
72089 unsigned int elapsed_csecs;
72090 bool wakeup = false;
72091+ bool timedout = false;
72092
72093 do_gettimeofday(&start);
72094
72095@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
72096
72097 while (true) {
72098 todo = 0;
72099+ if (time_after(jiffies, end_time))
72100+ timedout = true;
72101 read_lock(&tasklist_lock);
72102 do_each_thread(g, p) {
72103 if (p == current || !freeze_task(p))
72104 continue;
72105
72106- if (!freezer_should_skip(p))
72107+ if (!freezer_should_skip(p)) {
72108 todo++;
72109+ if (timedout) {
72110+ printk(KERN_ERR "Task refusing to freeze:\n");
72111+ sched_show_task(p);
72112+ }
72113+ }
72114 } while_each_thread(g, p);
72115 read_unlock(&tasklist_lock);
72116
72117@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
72118 todo += wq_busy;
72119 }
72120
72121- if (!todo || time_after(jiffies, end_time))
72122+ if (!todo || timedout)
72123 break;
72124
72125 if (pm_wakeup_pending()) {
72126diff --git a/kernel/printk.c b/kernel/printk.c
72127index 267ce78..2487112 100644
72128--- a/kernel/printk.c
72129+++ b/kernel/printk.c
72130@@ -609,11 +609,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
72131 return ret;
72132 }
72133
72134+static int check_syslog_permissions(int type, bool from_file);
72135+
72136 static int devkmsg_open(struct inode *inode, struct file *file)
72137 {
72138 struct devkmsg_user *user;
72139 int err;
72140
72141+ err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
72142+ if (err)
72143+ return err;
72144+
72145 /* write-only does not need any file context */
72146 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
72147 return 0;
72148@@ -822,7 +828,7 @@ static int syslog_action_restricted(int type)
72149 if (dmesg_restrict)
72150 return 1;
72151 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
72152- return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
72153+ return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
72154 }
72155
72156 static int check_syslog_permissions(int type, bool from_file)
72157@@ -834,6 +840,11 @@ static int check_syslog_permissions(int type, bool from_file)
72158 if (from_file && type != SYSLOG_ACTION_OPEN)
72159 return 0;
72160
72161+#ifdef CONFIG_GRKERNSEC_DMESG
72162+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
72163+ return -EPERM;
72164+#endif
72165+
72166 if (syslog_action_restricted(type)) {
72167 if (capable(CAP_SYSLOG))
72168 return 0;
72169diff --git a/kernel/profile.c b/kernel/profile.c
72170index 1f39181..86093471 100644
72171--- a/kernel/profile.c
72172+++ b/kernel/profile.c
72173@@ -40,7 +40,7 @@ struct profile_hit {
72174 /* Oprofile timer tick hook */
72175 static int (*timer_hook)(struct pt_regs *) __read_mostly;
72176
72177-static atomic_t *prof_buffer;
72178+static atomic_unchecked_t *prof_buffer;
72179 static unsigned long prof_len, prof_shift;
72180
72181 int prof_on __read_mostly;
72182@@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
72183 hits[i].pc = 0;
72184 continue;
72185 }
72186- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
72187+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
72188 hits[i].hits = hits[i].pc = 0;
72189 }
72190 }
72191@@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
72192 * Add the current hit(s) and flush the write-queue out
72193 * to the global buffer:
72194 */
72195- atomic_add(nr_hits, &prof_buffer[pc]);
72196+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
72197 for (i = 0; i < NR_PROFILE_HIT; ++i) {
72198- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
72199+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
72200 hits[i].pc = hits[i].hits = 0;
72201 }
72202 out:
72203@@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
72204 {
72205 unsigned long pc;
72206 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
72207- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
72208+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
72209 }
72210 #endif /* !CONFIG_SMP */
72211
72212@@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
72213 return -EFAULT;
72214 buf++; p++; count--; read++;
72215 }
72216- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
72217+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
72218 if (copy_to_user(buf, (void *)pnt, count))
72219 return -EFAULT;
72220 read += count;
72221@@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
72222 }
72223 #endif
72224 profile_discard_flip_buffers();
72225- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
72226+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
72227 return count;
72228 }
72229
72230diff --git a/kernel/ptrace.c b/kernel/ptrace.c
72231index 6cbeaae..363c48a 100644
72232--- a/kernel/ptrace.c
72233+++ b/kernel/ptrace.c
72234@@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
72235 if (seize)
72236 flags |= PT_SEIZED;
72237 rcu_read_lock();
72238- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
72239+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
72240 flags |= PT_PTRACE_CAP;
72241 rcu_read_unlock();
72242 task->ptrace = flags;
72243@@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
72244 break;
72245 return -EIO;
72246 }
72247- if (copy_to_user(dst, buf, retval))
72248+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
72249 return -EFAULT;
72250 copied += retval;
72251 src += retval;
72252@@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
72253 bool seized = child->ptrace & PT_SEIZED;
72254 int ret = -EIO;
72255 siginfo_t siginfo, *si;
72256- void __user *datavp = (void __user *) data;
72257+ void __user *datavp = (__force void __user *) data;
72258 unsigned long __user *datalp = datavp;
72259 unsigned long flags;
72260
72261@@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
72262 goto out;
72263 }
72264
72265+ if (gr_handle_ptrace(child, request)) {
72266+ ret = -EPERM;
72267+ goto out_put_task_struct;
72268+ }
72269+
72270 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72271 ret = ptrace_attach(child, request, addr, data);
72272 /*
72273 * Some architectures need to do book-keeping after
72274 * a ptrace attach.
72275 */
72276- if (!ret)
72277+ if (!ret) {
72278 arch_ptrace_attach(child);
72279+ gr_audit_ptrace(child);
72280+ }
72281 goto out_put_task_struct;
72282 }
72283
72284@@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
72285 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
72286 if (copied != sizeof(tmp))
72287 return -EIO;
72288- return put_user(tmp, (unsigned long __user *)data);
72289+ return put_user(tmp, (__force unsigned long __user *)data);
72290 }
72291
72292 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
72293@@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
72294 goto out;
72295 }
72296
72297+ if (gr_handle_ptrace(child, request)) {
72298+ ret = -EPERM;
72299+ goto out_put_task_struct;
72300+ }
72301+
72302 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72303 ret = ptrace_attach(child, request, addr, data);
72304 /*
72305 * Some architectures need to do book-keeping after
72306 * a ptrace attach.
72307 */
72308- if (!ret)
72309+ if (!ret) {
72310 arch_ptrace_attach(child);
72311+ gr_audit_ptrace(child);
72312+ }
72313 goto out_put_task_struct;
72314 }
72315
72316diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
72317index e7dce58..ad0d7b7 100644
72318--- a/kernel/rcutiny.c
72319+++ b/kernel/rcutiny.c
72320@@ -46,7 +46,7 @@
72321 struct rcu_ctrlblk;
72322 static void invoke_rcu_callbacks(void);
72323 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
72324-static void rcu_process_callbacks(struct softirq_action *unused);
72325+static void rcu_process_callbacks(void);
72326 static void __call_rcu(struct rcu_head *head,
72327 void (*func)(struct rcu_head *rcu),
72328 struct rcu_ctrlblk *rcp);
72329@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
72330 rcu_is_callbacks_kthread()));
72331 }
72332
72333-static void rcu_process_callbacks(struct softirq_action *unused)
72334+static void rcu_process_callbacks(void)
72335 {
72336 __rcu_process_callbacks(&rcu_sched_ctrlblk);
72337 __rcu_process_callbacks(&rcu_bh_ctrlblk);
72338diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
72339index f85016a..91cb03b 100644
72340--- a/kernel/rcutiny_plugin.h
72341+++ b/kernel/rcutiny_plugin.h
72342@@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
72343 have_rcu_kthread_work = morework;
72344 local_irq_restore(flags);
72345 if (work)
72346- rcu_process_callbacks(NULL);
72347+ rcu_process_callbacks();
72348 schedule_timeout_interruptible(1); /* Leave CPU for others. */
72349 }
72350
72351diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
72352index 31dea01..ad91ffb 100644
72353--- a/kernel/rcutorture.c
72354+++ b/kernel/rcutorture.c
72355@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
72356 { 0 };
72357 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
72358 { 0 };
72359-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
72360-static atomic_t n_rcu_torture_alloc;
72361-static atomic_t n_rcu_torture_alloc_fail;
72362-static atomic_t n_rcu_torture_free;
72363-static atomic_t n_rcu_torture_mberror;
72364-static atomic_t n_rcu_torture_error;
72365+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
72366+static atomic_unchecked_t n_rcu_torture_alloc;
72367+static atomic_unchecked_t n_rcu_torture_alloc_fail;
72368+static atomic_unchecked_t n_rcu_torture_free;
72369+static atomic_unchecked_t n_rcu_torture_mberror;
72370+static atomic_unchecked_t n_rcu_torture_error;
72371 static long n_rcu_torture_barrier_error;
72372 static long n_rcu_torture_boost_ktrerror;
72373 static long n_rcu_torture_boost_rterror;
72374@@ -272,11 +272,11 @@ rcu_torture_alloc(void)
72375
72376 spin_lock_bh(&rcu_torture_lock);
72377 if (list_empty(&rcu_torture_freelist)) {
72378- atomic_inc(&n_rcu_torture_alloc_fail);
72379+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
72380 spin_unlock_bh(&rcu_torture_lock);
72381 return NULL;
72382 }
72383- atomic_inc(&n_rcu_torture_alloc);
72384+ atomic_inc_unchecked(&n_rcu_torture_alloc);
72385 p = rcu_torture_freelist.next;
72386 list_del_init(p);
72387 spin_unlock_bh(&rcu_torture_lock);
72388@@ -289,7 +289,7 @@ rcu_torture_alloc(void)
72389 static void
72390 rcu_torture_free(struct rcu_torture *p)
72391 {
72392- atomic_inc(&n_rcu_torture_free);
72393+ atomic_inc_unchecked(&n_rcu_torture_free);
72394 spin_lock_bh(&rcu_torture_lock);
72395 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
72396 spin_unlock_bh(&rcu_torture_lock);
72397@@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
72398 i = rp->rtort_pipe_count;
72399 if (i > RCU_TORTURE_PIPE_LEN)
72400 i = RCU_TORTURE_PIPE_LEN;
72401- atomic_inc(&rcu_torture_wcount[i]);
72402+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
72403 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
72404 rp->rtort_mbtest = 0;
72405 rcu_torture_free(rp);
72406@@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
72407 i = rp->rtort_pipe_count;
72408 if (i > RCU_TORTURE_PIPE_LEN)
72409 i = RCU_TORTURE_PIPE_LEN;
72410- atomic_inc(&rcu_torture_wcount[i]);
72411+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
72412 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
72413 rp->rtort_mbtest = 0;
72414 list_del(&rp->rtort_free);
72415@@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
72416 i = old_rp->rtort_pipe_count;
72417 if (i > RCU_TORTURE_PIPE_LEN)
72418 i = RCU_TORTURE_PIPE_LEN;
72419- atomic_inc(&rcu_torture_wcount[i]);
72420+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
72421 old_rp->rtort_pipe_count++;
72422 cur_ops->deferred_free(old_rp);
72423 }
72424@@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
72425 }
72426 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
72427 if (p->rtort_mbtest == 0)
72428- atomic_inc(&n_rcu_torture_mberror);
72429+ atomic_inc_unchecked(&n_rcu_torture_mberror);
72430 spin_lock(&rand_lock);
72431 cur_ops->read_delay(&rand);
72432 n_rcu_torture_timers++;
72433@@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
72434 }
72435 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
72436 if (p->rtort_mbtest == 0)
72437- atomic_inc(&n_rcu_torture_mberror);
72438+ atomic_inc_unchecked(&n_rcu_torture_mberror);
72439 cur_ops->read_delay(&rand);
72440 preempt_disable();
72441 pipe_count = p->rtort_pipe_count;
72442@@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
72443 rcu_torture_current,
72444 rcu_torture_current_version,
72445 list_empty(&rcu_torture_freelist),
72446- atomic_read(&n_rcu_torture_alloc),
72447- atomic_read(&n_rcu_torture_alloc_fail),
72448- atomic_read(&n_rcu_torture_free));
72449+ atomic_read_unchecked(&n_rcu_torture_alloc),
72450+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
72451+ atomic_read_unchecked(&n_rcu_torture_free));
72452 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
72453- atomic_read(&n_rcu_torture_mberror),
72454+ atomic_read_unchecked(&n_rcu_torture_mberror),
72455 n_rcu_torture_boost_ktrerror,
72456 n_rcu_torture_boost_rterror);
72457 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
72458@@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
72459 n_barrier_attempts,
72460 n_rcu_torture_barrier_error);
72461 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
72462- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
72463+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
72464 n_rcu_torture_barrier_error != 0 ||
72465 n_rcu_torture_boost_ktrerror != 0 ||
72466 n_rcu_torture_boost_rterror != 0 ||
72467 n_rcu_torture_boost_failure != 0 ||
72468 i > 1) {
72469 cnt += sprintf(&page[cnt], "!!! ");
72470- atomic_inc(&n_rcu_torture_error);
72471+ atomic_inc_unchecked(&n_rcu_torture_error);
72472 WARN_ON_ONCE(1);
72473 }
72474 cnt += sprintf(&page[cnt], "Reader Pipe: ");
72475@@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
72476 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
72477 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
72478 cnt += sprintf(&page[cnt], " %d",
72479- atomic_read(&rcu_torture_wcount[i]));
72480+ atomic_read_unchecked(&rcu_torture_wcount[i]));
72481 }
72482 cnt += sprintf(&page[cnt], "\n");
72483 if (cur_ops->stats)
72484@@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
72485
72486 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
72487
72488- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
72489+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
72490 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
72491 else if (n_online_successes != n_online_attempts ||
72492 n_offline_successes != n_offline_attempts)
72493@@ -1989,18 +1989,18 @@ rcu_torture_init(void)
72494
72495 rcu_torture_current = NULL;
72496 rcu_torture_current_version = 0;
72497- atomic_set(&n_rcu_torture_alloc, 0);
72498- atomic_set(&n_rcu_torture_alloc_fail, 0);
72499- atomic_set(&n_rcu_torture_free, 0);
72500- atomic_set(&n_rcu_torture_mberror, 0);
72501- atomic_set(&n_rcu_torture_error, 0);
72502+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
72503+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
72504+ atomic_set_unchecked(&n_rcu_torture_free, 0);
72505+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
72506+ atomic_set_unchecked(&n_rcu_torture_error, 0);
72507 n_rcu_torture_barrier_error = 0;
72508 n_rcu_torture_boost_ktrerror = 0;
72509 n_rcu_torture_boost_rterror = 0;
72510 n_rcu_torture_boost_failure = 0;
72511 n_rcu_torture_boosts = 0;
72512 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
72513- atomic_set(&rcu_torture_wcount[i], 0);
72514+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
72515 for_each_possible_cpu(cpu) {
72516 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
72517 per_cpu(rcu_torture_count, cpu)[i] = 0;
72518diff --git a/kernel/rcutree.c b/kernel/rcutree.c
72519index e441b77..dd54f17 100644
72520--- a/kernel/rcutree.c
72521+++ b/kernel/rcutree.c
72522@@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
72523 rcu_prepare_for_idle(smp_processor_id());
72524 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
72525 smp_mb__before_atomic_inc(); /* See above. */
72526- atomic_inc(&rdtp->dynticks);
72527+ atomic_inc_unchecked(&rdtp->dynticks);
72528 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
72529- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
72530+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
72531
72532 /*
72533 * It is illegal to enter an extended quiescent state while
72534@@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
72535 int user)
72536 {
72537 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
72538- atomic_inc(&rdtp->dynticks);
72539+ atomic_inc_unchecked(&rdtp->dynticks);
72540 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
72541 smp_mb__after_atomic_inc(); /* See above. */
72542- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
72543+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
72544 rcu_cleanup_after_idle(smp_processor_id());
72545 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
72546 if (!user && !is_idle_task(current)) {
72547@@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
72548 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
72549
72550 if (rdtp->dynticks_nmi_nesting == 0 &&
72551- (atomic_read(&rdtp->dynticks) & 0x1))
72552+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
72553 return;
72554 rdtp->dynticks_nmi_nesting++;
72555 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
72556- atomic_inc(&rdtp->dynticks);
72557+ atomic_inc_unchecked(&rdtp->dynticks);
72558 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
72559 smp_mb__after_atomic_inc(); /* See above. */
72560- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
72561+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
72562 }
72563
72564 /**
72565@@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
72566 return;
72567 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
72568 smp_mb__before_atomic_inc(); /* See above. */
72569- atomic_inc(&rdtp->dynticks);
72570+ atomic_inc_unchecked(&rdtp->dynticks);
72571 smp_mb__after_atomic_inc(); /* Force delay to next write. */
72572- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
72573+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
72574 }
72575
72576 /**
72577@@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
72578 int ret;
72579
72580 preempt_disable();
72581- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
72582+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
72583 preempt_enable();
72584 return ret;
72585 }
72586@@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
72587 */
72588 static int dyntick_save_progress_counter(struct rcu_data *rdp)
72589 {
72590- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
72591+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
72592 return (rdp->dynticks_snap & 0x1) == 0;
72593 }
72594
72595@@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
72596 unsigned int curr;
72597 unsigned int snap;
72598
72599- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
72600+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
72601 snap = (unsigned int)rdp->dynticks_snap;
72602
72603 /*
72604@@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
72605 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
72606 */
72607 if (till_stall_check < 3) {
72608- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
72609+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
72610 till_stall_check = 3;
72611 } else if (till_stall_check > 300) {
72612- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
72613+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
72614 till_stall_check = 300;
72615 }
72616 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
72617@@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
72618 rsp->qlen += rdp->qlen;
72619 rdp->n_cbs_orphaned += rdp->qlen;
72620 rdp->qlen_lazy = 0;
72621- ACCESS_ONCE(rdp->qlen) = 0;
72622+ ACCESS_ONCE_RW(rdp->qlen) = 0;
72623 }
72624
72625 /*
72626@@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
72627 }
72628 smp_mb(); /* List handling before counting for rcu_barrier(). */
72629 rdp->qlen_lazy -= count_lazy;
72630- ACCESS_ONCE(rdp->qlen) -= count;
72631+ ACCESS_ONCE_RW(rdp->qlen) -= count;
72632 rdp->n_cbs_invoked += count;
72633
72634 /* Reinstate batch limit if we have worked down the excess. */
72635@@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
72636 /*
72637 * Do RCU core processing for the current CPU.
72638 */
72639-static void rcu_process_callbacks(struct softirq_action *unused)
72640+static void rcu_process_callbacks(void)
72641 {
72642 struct rcu_state *rsp;
72643
72644@@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
72645 local_irq_restore(flags);
72646 return;
72647 }
72648- ACCESS_ONCE(rdp->qlen)++;
72649+ ACCESS_ONCE_RW(rdp->qlen)++;
72650 if (lazy)
72651 rdp->qlen_lazy++;
72652 else
72653@@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
72654 * counter wrap on a 32-bit system. Quite a few more CPUs would of
72655 * course be required on a 64-bit system.
72656 */
72657- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
72658+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
72659 (ulong)atomic_long_read(&rsp->expedited_done) +
72660 ULONG_MAX / 8)) {
72661 synchronize_sched();
72662- atomic_long_inc(&rsp->expedited_wrap);
72663+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
72664 return;
72665 }
72666
72667@@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
72668 * Take a ticket. Note that atomic_inc_return() implies a
72669 * full memory barrier.
72670 */
72671- snap = atomic_long_inc_return(&rsp->expedited_start);
72672+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
72673 firstsnap = snap;
72674 get_online_cpus();
72675 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
72676@@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
72677 synchronize_sched_expedited_cpu_stop,
72678 NULL) == -EAGAIN) {
72679 put_online_cpus();
72680- atomic_long_inc(&rsp->expedited_tryfail);
72681+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
72682
72683 /* Check to see if someone else did our work for us. */
72684 s = atomic_long_read(&rsp->expedited_done);
72685 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
72686 /* ensure test happens before caller kfree */
72687 smp_mb__before_atomic_inc(); /* ^^^ */
72688- atomic_long_inc(&rsp->expedited_workdone1);
72689+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
72690 return;
72691 }
72692
72693@@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
72694 udelay(trycount * num_online_cpus());
72695 } else {
72696 wait_rcu_gp(call_rcu_sched);
72697- atomic_long_inc(&rsp->expedited_normal);
72698+ atomic_long_inc_unchecked(&rsp->expedited_normal);
72699 return;
72700 }
72701
72702@@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
72703 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
72704 /* ensure test happens before caller kfree */
72705 smp_mb__before_atomic_inc(); /* ^^^ */
72706- atomic_long_inc(&rsp->expedited_workdone2);
72707+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
72708 return;
72709 }
72710
72711@@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
72712 * period works for us.
72713 */
72714 get_online_cpus();
72715- snap = atomic_long_read(&rsp->expedited_start);
72716+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
72717 smp_mb(); /* ensure read is before try_stop_cpus(). */
72718 }
72719- atomic_long_inc(&rsp->expedited_stoppedcpus);
72720+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
72721
72722 /*
72723 * Everyone up to our most recent fetch is covered by our grace
72724@@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
72725 * than we did already did their update.
72726 */
72727 do {
72728- atomic_long_inc(&rsp->expedited_done_tries);
72729+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
72730 s = atomic_long_read(&rsp->expedited_done);
72731 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
72732 /* ensure test happens before caller kfree */
72733 smp_mb__before_atomic_inc(); /* ^^^ */
72734- atomic_long_inc(&rsp->expedited_done_lost);
72735+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
72736 break;
72737 }
72738 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
72739- atomic_long_inc(&rsp->expedited_done_exit);
72740+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
72741
72742 put_online_cpus();
72743 }
72744@@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
72745 * ACCESS_ONCE() to prevent the compiler from speculating
72746 * the increment to precede the early-exit check.
72747 */
72748- ACCESS_ONCE(rsp->n_barrier_done)++;
72749+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
72750 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
72751 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
72752 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
72753@@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
72754
72755 /* Increment ->n_barrier_done to prevent duplicate work. */
72756 smp_mb(); /* Keep increment after above mechanism. */
72757- ACCESS_ONCE(rsp->n_barrier_done)++;
72758+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
72759 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
72760 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
72761 smp_mb(); /* Keep increment before caller's subsequent code. */
72762@@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
72763 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
72764 init_callback_list(rdp);
72765 rdp->qlen_lazy = 0;
72766- ACCESS_ONCE(rdp->qlen) = 0;
72767+ ACCESS_ONCE_RW(rdp->qlen) = 0;
72768 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
72769 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
72770- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
72771+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
72772 #ifdef CONFIG_RCU_USER_QS
72773 WARN_ON_ONCE(rdp->dynticks->in_user);
72774 #endif
72775@@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
72776 rdp->blimit = blimit;
72777 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
72778 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
72779- atomic_set(&rdp->dynticks->dynticks,
72780- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
72781+ atomic_set_unchecked(&rdp->dynticks->dynticks,
72782+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
72783 rcu_prepare_for_idle_init(cpu);
72784 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
72785
72786diff --git a/kernel/rcutree.h b/kernel/rcutree.h
72787index 4b69291..704c92e 100644
72788--- a/kernel/rcutree.h
72789+++ b/kernel/rcutree.h
72790@@ -86,7 +86,7 @@ struct rcu_dynticks {
72791 long long dynticks_nesting; /* Track irq/process nesting level. */
72792 /* Process level is worth LLONG_MAX/2. */
72793 int dynticks_nmi_nesting; /* Track NMI nesting level. */
72794- atomic_t dynticks; /* Even value for idle, else odd. */
72795+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
72796 #ifdef CONFIG_RCU_FAST_NO_HZ
72797 int dyntick_drain; /* Prepare-for-idle state variable. */
72798 unsigned long dyntick_holdoff;
72799@@ -423,17 +423,17 @@ struct rcu_state {
72800 /* _rcu_barrier(). */
72801 /* End of fields guarded by barrier_mutex. */
72802
72803- atomic_long_t expedited_start; /* Starting ticket. */
72804- atomic_long_t expedited_done; /* Done ticket. */
72805- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
72806- atomic_long_t expedited_tryfail; /* # acquisition failures. */
72807- atomic_long_t expedited_workdone1; /* # done by others #1. */
72808- atomic_long_t expedited_workdone2; /* # done by others #2. */
72809- atomic_long_t expedited_normal; /* # fallbacks to normal. */
72810- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
72811- atomic_long_t expedited_done_tries; /* # tries to update _done. */
72812- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
72813- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
72814+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
72815+ atomic_long_t expedited_done; /* Done ticket. */
72816+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
72817+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
72818+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
72819+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
72820+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
72821+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
72822+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
72823+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
72824+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
72825
72826 unsigned long jiffies_force_qs; /* Time at which to invoke */
72827 /* force_quiescent_state(). */
72828diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
72829index c1cc7e1..5043e0e 100644
72830--- a/kernel/rcutree_plugin.h
72831+++ b/kernel/rcutree_plugin.h
72832@@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
72833
72834 /* Clean up and exit. */
72835 smp_mb(); /* ensure expedited GP seen before counter increment. */
72836- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
72837+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
72838 unlock_mb_ret:
72839 mutex_unlock(&sync_rcu_preempt_exp_mutex);
72840 mb_ret:
72841@@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
72842 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
72843 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
72844 cpu, ticks_value, ticks_title,
72845- atomic_read(&rdtp->dynticks) & 0xfff,
72846+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
72847 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
72848 fast_no_hz);
72849 }
72850@@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
72851
72852 /* Enqueue the callback on the nocb list and update counts. */
72853 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
72854- ACCESS_ONCE(*old_rhpp) = rhp;
72855+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
72856 atomic_long_add(rhcount, &rdp->nocb_q_count);
72857 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
72858
72859@@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
72860 * Extract queued callbacks, update counts, and wait
72861 * for a grace period to elapse.
72862 */
72863- ACCESS_ONCE(rdp->nocb_head) = NULL;
72864+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
72865 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
72866 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
72867 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
72868- ACCESS_ONCE(rdp->nocb_p_count) += c;
72869- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
72870+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
72871+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
72872 wait_rcu_gp(rdp->rsp->call_remote);
72873
72874 /* Each pass through the following loop invokes a callback. */
72875@@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
72876 list = next;
72877 }
72878 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
72879- ACCESS_ONCE(rdp->nocb_p_count) -= c;
72880- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
72881+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
72882+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
72883 rdp->n_nocbs_invoked += c;
72884 }
72885 return 0;
72886@@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
72887 rdp = per_cpu_ptr(rsp->rda, cpu);
72888 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
72889 BUG_ON(IS_ERR(t));
72890- ACCESS_ONCE(rdp->nocb_kthread) = t;
72891+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
72892 }
72893 }
72894
72895diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
72896index 0d095dc..1985b19 100644
72897--- a/kernel/rcutree_trace.c
72898+++ b/kernel/rcutree_trace.c
72899@@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
72900 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
72901 rdp->passed_quiesce, rdp->qs_pending);
72902 seq_printf(m, " dt=%d/%llx/%d df=%lu",
72903- atomic_read(&rdp->dynticks->dynticks),
72904+ atomic_read_unchecked(&rdp->dynticks->dynticks),
72905 rdp->dynticks->dynticks_nesting,
72906 rdp->dynticks->dynticks_nmi_nesting,
72907 rdp->dynticks_fqs);
72908@@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
72909 struct rcu_state *rsp = (struct rcu_state *)m->private;
72910
72911 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",
72912- atomic_long_read(&rsp->expedited_start),
72913+ atomic_long_read_unchecked(&rsp->expedited_start),
72914 atomic_long_read(&rsp->expedited_done),
72915- atomic_long_read(&rsp->expedited_wrap),
72916- atomic_long_read(&rsp->expedited_tryfail),
72917- atomic_long_read(&rsp->expedited_workdone1),
72918- atomic_long_read(&rsp->expedited_workdone2),
72919- atomic_long_read(&rsp->expedited_normal),
72920- atomic_long_read(&rsp->expedited_stoppedcpus),
72921- atomic_long_read(&rsp->expedited_done_tries),
72922- atomic_long_read(&rsp->expedited_done_lost),
72923- atomic_long_read(&rsp->expedited_done_exit));
72924+ atomic_long_read_unchecked(&rsp->expedited_wrap),
72925+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
72926+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
72927+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
72928+ atomic_long_read_unchecked(&rsp->expedited_normal),
72929+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
72930+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
72931+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
72932+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
72933 return 0;
72934 }
72935
72936diff --git a/kernel/resource.c b/kernel/resource.c
72937index 73f35d4..4684fc4 100644
72938--- a/kernel/resource.c
72939+++ b/kernel/resource.c
72940@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
72941
72942 static int __init ioresources_init(void)
72943 {
72944+#ifdef CONFIG_GRKERNSEC_PROC_ADD
72945+#ifdef CONFIG_GRKERNSEC_PROC_USER
72946+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
72947+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
72948+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72949+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
72950+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
72951+#endif
72952+#else
72953 proc_create("ioports", 0, NULL, &proc_ioports_operations);
72954 proc_create("iomem", 0, NULL, &proc_iomem_operations);
72955+#endif
72956 return 0;
72957 }
72958 __initcall(ioresources_init);
72959diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
72960index 98ec494..4241d6d 100644
72961--- a/kernel/rtmutex-tester.c
72962+++ b/kernel/rtmutex-tester.c
72963@@ -20,7 +20,7 @@
72964 #define MAX_RT_TEST_MUTEXES 8
72965
72966 static spinlock_t rttest_lock;
72967-static atomic_t rttest_event;
72968+static atomic_unchecked_t rttest_event;
72969
72970 struct test_thread_data {
72971 int opcode;
72972@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72973
72974 case RTTEST_LOCKCONT:
72975 td->mutexes[td->opdata] = 1;
72976- td->event = atomic_add_return(1, &rttest_event);
72977+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72978 return 0;
72979
72980 case RTTEST_RESET:
72981@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72982 return 0;
72983
72984 case RTTEST_RESETEVENT:
72985- atomic_set(&rttest_event, 0);
72986+ atomic_set_unchecked(&rttest_event, 0);
72987 return 0;
72988
72989 default:
72990@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72991 return ret;
72992
72993 td->mutexes[id] = 1;
72994- td->event = atomic_add_return(1, &rttest_event);
72995+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72996 rt_mutex_lock(&mutexes[id]);
72997- td->event = atomic_add_return(1, &rttest_event);
72998+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72999 td->mutexes[id] = 4;
73000 return 0;
73001
73002@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73003 return ret;
73004
73005 td->mutexes[id] = 1;
73006- td->event = atomic_add_return(1, &rttest_event);
73007+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73008 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
73009- td->event = atomic_add_return(1, &rttest_event);
73010+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73011 td->mutexes[id] = ret ? 0 : 4;
73012 return ret ? -EINTR : 0;
73013
73014@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73015 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
73016 return ret;
73017
73018- td->event = atomic_add_return(1, &rttest_event);
73019+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73020 rt_mutex_unlock(&mutexes[id]);
73021- td->event = atomic_add_return(1, &rttest_event);
73022+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73023 td->mutexes[id] = 0;
73024 return 0;
73025
73026@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73027 break;
73028
73029 td->mutexes[dat] = 2;
73030- td->event = atomic_add_return(1, &rttest_event);
73031+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73032 break;
73033
73034 default:
73035@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73036 return;
73037
73038 td->mutexes[dat] = 3;
73039- td->event = atomic_add_return(1, &rttest_event);
73040+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73041 break;
73042
73043 case RTTEST_LOCKNOWAIT:
73044@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73045 return;
73046
73047 td->mutexes[dat] = 1;
73048- td->event = atomic_add_return(1, &rttest_event);
73049+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73050 return;
73051
73052 default:
73053diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
73054index 0984a21..939f183 100644
73055--- a/kernel/sched/auto_group.c
73056+++ b/kernel/sched/auto_group.c
73057@@ -11,7 +11,7 @@
73058
73059 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
73060 static struct autogroup autogroup_default;
73061-static atomic_t autogroup_seq_nr;
73062+static atomic_unchecked_t autogroup_seq_nr;
73063
73064 void __init autogroup_init(struct task_struct *init_task)
73065 {
73066@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
73067
73068 kref_init(&ag->kref);
73069 init_rwsem(&ag->lock);
73070- ag->id = atomic_inc_return(&autogroup_seq_nr);
73071+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
73072 ag->tg = tg;
73073 #ifdef CONFIG_RT_GROUP_SCHED
73074 /*
73075diff --git a/kernel/sched/core.c b/kernel/sched/core.c
73076index 26058d0..06f15dd 100644
73077--- a/kernel/sched/core.c
73078+++ b/kernel/sched/core.c
73079@@ -3631,6 +3631,8 @@ int can_nice(const struct task_struct *p, const int nice)
73080 /* convert nice value [19,-20] to rlimit style value [1,40] */
73081 int nice_rlim = 20 - nice;
73082
73083+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
73084+
73085 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
73086 capable(CAP_SYS_NICE));
73087 }
73088@@ -3664,7 +3666,8 @@ SYSCALL_DEFINE1(nice, int, increment)
73089 if (nice > 19)
73090 nice = 19;
73091
73092- if (increment < 0 && !can_nice(current, nice))
73093+ if (increment < 0 && (!can_nice(current, nice) ||
73094+ gr_handle_chroot_nice()))
73095 return -EPERM;
73096
73097 retval = security_task_setnice(current, nice);
73098@@ -3818,6 +3821,7 @@ recheck:
73099 unsigned long rlim_rtprio =
73100 task_rlimit(p, RLIMIT_RTPRIO);
73101
73102+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
73103 /* can't set/change the rt policy */
73104 if (policy != p->policy && !rlim_rtprio)
73105 return -EPERM;
73106@@ -5162,7 +5166,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
73107 * happens before everything else. This has to be lower priority than
73108 * the notifier in the perf_event subsystem, though.
73109 */
73110-static struct notifier_block __cpuinitdata migration_notifier = {
73111+static struct notifier_block migration_notifier = {
73112 .notifier_call = migration_call,
73113 .priority = CPU_PRI_MIGRATION,
73114 };
73115diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
73116index 81fa536..6ccf96a 100644
73117--- a/kernel/sched/fair.c
73118+++ b/kernel/sched/fair.c
73119@@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
73120
73121 static void reset_ptenuma_scan(struct task_struct *p)
73122 {
73123- ACCESS_ONCE(p->mm->numa_scan_seq)++;
73124+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
73125 p->mm->numa_scan_offset = 0;
73126 }
73127
73128@@ -3254,25 +3254,18 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
73129 */
73130 static int select_idle_sibling(struct task_struct *p, int target)
73131 {
73132- int cpu = smp_processor_id();
73133- int prev_cpu = task_cpu(p);
73134 struct sched_domain *sd;
73135 struct sched_group *sg;
73136- int i;
73137+ int i = task_cpu(p);
73138
73139- /*
73140- * If the task is going to be woken-up on this cpu and if it is
73141- * already idle, then it is the right target.
73142- */
73143- if (target == cpu && idle_cpu(cpu))
73144- return cpu;
73145+ if (idle_cpu(target))
73146+ return target;
73147
73148 /*
73149- * If the task is going to be woken-up on the cpu where it previously
73150- * ran and if it is currently idle, then it the right target.
73151+ * If the prevous cpu is cache affine and idle, don't be stupid.
73152 */
73153- if (target == prev_cpu && idle_cpu(prev_cpu))
73154- return prev_cpu;
73155+ if (i != target && cpus_share_cache(i, target) && idle_cpu(i))
73156+ return i;
73157
73158 /*
73159 * Otherwise, iterate the domains and find an elegible idle cpu.
73160@@ -3286,7 +3279,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
73161 goto next;
73162
73163 for_each_cpu(i, sched_group_cpus(sg)) {
73164- if (!idle_cpu(i))
73165+ if (i == target || !idle_cpu(i))
73166 goto next;
73167 }
73168
73169@@ -5663,7 +5656,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
73170 * run_rebalance_domains is triggered when needed from the scheduler tick.
73171 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
73172 */
73173-static void run_rebalance_domains(struct softirq_action *h)
73174+static void run_rebalance_domains(void)
73175 {
73176 int this_cpu = smp_processor_id();
73177 struct rq *this_rq = cpu_rq(this_cpu);
73178diff --git a/kernel/signal.c b/kernel/signal.c
73179index 3d09cf6..a67d2c6 100644
73180--- a/kernel/signal.c
73181+++ b/kernel/signal.c
73182@@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
73183
73184 int print_fatal_signals __read_mostly;
73185
73186-static void __user *sig_handler(struct task_struct *t, int sig)
73187+static __sighandler_t sig_handler(struct task_struct *t, int sig)
73188 {
73189 return t->sighand->action[sig - 1].sa.sa_handler;
73190 }
73191
73192-static int sig_handler_ignored(void __user *handler, int sig)
73193+static int sig_handler_ignored(__sighandler_t handler, int sig)
73194 {
73195 /* Is it explicitly or implicitly ignored? */
73196 return handler == SIG_IGN ||
73197@@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
73198
73199 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
73200 {
73201- void __user *handler;
73202+ __sighandler_t handler;
73203
73204 handler = sig_handler(t, sig);
73205
73206@@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
73207 atomic_inc(&user->sigpending);
73208 rcu_read_unlock();
73209
73210+ if (!override_rlimit)
73211+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
73212+
73213 if (override_rlimit ||
73214 atomic_read(&user->sigpending) <=
73215 task_rlimit(t, RLIMIT_SIGPENDING)) {
73216@@ -492,7 +495,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
73217
73218 int unhandled_signal(struct task_struct *tsk, int sig)
73219 {
73220- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
73221+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
73222 if (is_global_init(tsk))
73223 return 1;
73224 if (handler != SIG_IGN && handler != SIG_DFL)
73225@@ -812,6 +815,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
73226 }
73227 }
73228
73229+ /* allow glibc communication via tgkill to other threads in our
73230+ thread group */
73231+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
73232+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
73233+ && gr_handle_signal(t, sig))
73234+ return -EPERM;
73235+
73236 return security_task_kill(t, info, sig, 0);
73237 }
73238
73239@@ -1194,7 +1204,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
73240 return send_signal(sig, info, p, 1);
73241 }
73242
73243-static int
73244+int
73245 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73246 {
73247 return send_signal(sig, info, t, 0);
73248@@ -1231,6 +1241,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73249 unsigned long int flags;
73250 int ret, blocked, ignored;
73251 struct k_sigaction *action;
73252+ int is_unhandled = 0;
73253
73254 spin_lock_irqsave(&t->sighand->siglock, flags);
73255 action = &t->sighand->action[sig-1];
73256@@ -1245,9 +1256,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73257 }
73258 if (action->sa.sa_handler == SIG_DFL)
73259 t->signal->flags &= ~SIGNAL_UNKILLABLE;
73260+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
73261+ is_unhandled = 1;
73262 ret = specific_send_sig_info(sig, info, t);
73263 spin_unlock_irqrestore(&t->sighand->siglock, flags);
73264
73265+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
73266+ normal operation */
73267+ if (is_unhandled) {
73268+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
73269+ gr_handle_crash(t, sig);
73270+ }
73271+
73272 return ret;
73273 }
73274
73275@@ -1314,8 +1334,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
73276 ret = check_kill_permission(sig, info, p);
73277 rcu_read_unlock();
73278
73279- if (!ret && sig)
73280+ if (!ret && sig) {
73281 ret = do_send_sig_info(sig, info, p, true);
73282+ if (!ret)
73283+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
73284+ }
73285
73286 return ret;
73287 }
73288@@ -2852,7 +2875,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
73289 int error = -ESRCH;
73290
73291 rcu_read_lock();
73292- p = find_task_by_vpid(pid);
73293+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73294+ /* allow glibc communication via tgkill to other threads in our
73295+ thread group */
73296+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
73297+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
73298+ p = find_task_by_vpid_unrestricted(pid);
73299+ else
73300+#endif
73301+ p = find_task_by_vpid(pid);
73302 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
73303 error = check_kill_permission(sig, info, p);
73304 /*
73305@@ -3135,8 +3166,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
73306 }
73307 seg = get_fs();
73308 set_fs(KERNEL_DS);
73309- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
73310- (stack_t __force __user *) &uoss,
73311+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
73312+ (stack_t __force_user *) &uoss,
73313 compat_user_stack_pointer());
73314 set_fs(seg);
73315 if (ret >= 0 && uoss_ptr) {
73316diff --git a/kernel/smp.c b/kernel/smp.c
73317index 69f38bd..77bbf12 100644
73318--- a/kernel/smp.c
73319+++ b/kernel/smp.c
73320@@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
73321 return NOTIFY_OK;
73322 }
73323
73324-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
73325+static struct notifier_block hotplug_cfd_notifier = {
73326 .notifier_call = hotplug_cfd,
73327 };
73328
73329diff --git a/kernel/softirq.c b/kernel/softirq.c
73330index ed567ba..dc61b61 100644
73331--- a/kernel/softirq.c
73332+++ b/kernel/softirq.c
73333@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
73334 EXPORT_SYMBOL(irq_stat);
73335 #endif
73336
73337-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
73338+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
73339
73340 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
73341
73342-char *softirq_to_name[NR_SOFTIRQS] = {
73343+const char * const softirq_to_name[NR_SOFTIRQS] = {
73344 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
73345 "TASKLET", "SCHED", "HRTIMER", "RCU"
73346 };
73347@@ -244,7 +244,7 @@ restart:
73348 kstat_incr_softirqs_this_cpu(vec_nr);
73349
73350 trace_softirq_entry(vec_nr);
73351- h->action(h);
73352+ h->action();
73353 trace_softirq_exit(vec_nr);
73354 if (unlikely(prev_count != preempt_count())) {
73355 printk(KERN_ERR "huh, entered softirq %u %s %p"
73356@@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
73357 or_softirq_pending(1UL << nr);
73358 }
73359
73360-void open_softirq(int nr, void (*action)(struct softirq_action *))
73361+void __init open_softirq(int nr, void (*action)(void))
73362 {
73363 softirq_vec[nr].action = action;
73364 }
73365@@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
73366
73367 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
73368
73369-static void tasklet_action(struct softirq_action *a)
73370+static void tasklet_action(void)
73371 {
73372 struct tasklet_struct *list;
73373
73374@@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
73375 }
73376 }
73377
73378-static void tasklet_hi_action(struct softirq_action *a)
73379+static void tasklet_hi_action(void)
73380 {
73381 struct tasklet_struct *list;
73382
73383@@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
73384 return NOTIFY_OK;
73385 }
73386
73387-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
73388+static struct notifier_block remote_softirq_cpu_notifier = {
73389 .notifier_call = remote_softirq_cpu_notify,
73390 };
73391
73392@@ -835,7 +835,7 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
73393 return NOTIFY_OK;
73394 }
73395
73396-static struct notifier_block __cpuinitdata cpu_nfb = {
73397+static struct notifier_block cpu_nfb = {
73398 .notifier_call = cpu_callback
73399 };
73400
73401diff --git a/kernel/srcu.c b/kernel/srcu.c
73402index 2b85982..d52ab26 100644
73403--- a/kernel/srcu.c
73404+++ b/kernel/srcu.c
73405@@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
73406 preempt_disable();
73407 idx = rcu_dereference_index_check(sp->completed,
73408 rcu_read_lock_sched_held()) & 0x1;
73409- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
73410+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
73411 smp_mb(); /* B */ /* Avoid leaking the critical section. */
73412- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
73413+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
73414 preempt_enable();
73415 return idx;
73416 }
73417@@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
73418 {
73419 preempt_disable();
73420 smp_mb(); /* C */ /* Avoid leaking the critical section. */
73421- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
73422+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
73423 preempt_enable();
73424 }
73425 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
73426diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
73427index 2f194e9..2c05ea9 100644
73428--- a/kernel/stop_machine.c
73429+++ b/kernel/stop_machine.c
73430@@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
73431 * cpu notifiers. It currently shares the same priority as sched
73432 * migration_notifier.
73433 */
73434-static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
73435+static struct notifier_block cpu_stop_cpu_notifier = {
73436 .notifier_call = cpu_stop_cpu_callback,
73437 .priority = 10,
73438 };
73439diff --git a/kernel/sys.c b/kernel/sys.c
73440index 265b376..b0cd50d 100644
73441--- a/kernel/sys.c
73442+++ b/kernel/sys.c
73443@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
73444 error = -EACCES;
73445 goto out;
73446 }
73447+
73448+ if (gr_handle_chroot_setpriority(p, niceval)) {
73449+ error = -EACCES;
73450+ goto out;
73451+ }
73452+
73453 no_nice = security_task_setnice(p, niceval);
73454 if (no_nice) {
73455 error = no_nice;
73456@@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
73457 goto error;
73458 }
73459
73460+ if (gr_check_group_change(new->gid, new->egid, -1))
73461+ goto error;
73462+
73463 if (rgid != (gid_t) -1 ||
73464 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
73465 new->sgid = new->egid;
73466@@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
73467 old = current_cred();
73468
73469 retval = -EPERM;
73470+
73471+ if (gr_check_group_change(kgid, kgid, kgid))
73472+ goto error;
73473+
73474 if (nsown_capable(CAP_SETGID))
73475 new->gid = new->egid = new->sgid = new->fsgid = kgid;
73476 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
73477@@ -647,7 +660,7 @@ error:
73478 /*
73479 * change the user struct in a credentials set to match the new UID
73480 */
73481-static int set_user(struct cred *new)
73482+int set_user(struct cred *new)
73483 {
73484 struct user_struct *new_user;
73485
73486@@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
73487 goto error;
73488 }
73489
73490+ if (gr_check_user_change(new->uid, new->euid, -1))
73491+ goto error;
73492+
73493 if (!uid_eq(new->uid, old->uid)) {
73494 retval = set_user(new);
73495 if (retval < 0)
73496@@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
73497 old = current_cred();
73498
73499 retval = -EPERM;
73500+
73501+ if (gr_check_crash_uid(kuid))
73502+ goto error;
73503+ if (gr_check_user_change(kuid, kuid, kuid))
73504+ goto error;
73505+
73506 if (nsown_capable(CAP_SETUID)) {
73507 new->suid = new->uid = kuid;
73508 if (!uid_eq(kuid, old->uid)) {
73509@@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
73510 goto error;
73511 }
73512
73513+ if (gr_check_user_change(kruid, keuid, -1))
73514+ goto error;
73515+
73516 if (ruid != (uid_t) -1) {
73517 new->uid = kruid;
73518 if (!uid_eq(kruid, old->uid)) {
73519@@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
73520 goto error;
73521 }
73522
73523+ if (gr_check_group_change(krgid, kegid, -1))
73524+ goto error;
73525+
73526 if (rgid != (gid_t) -1)
73527 new->gid = krgid;
73528 if (egid != (gid_t) -1)
73529@@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
73530 if (!uid_valid(kuid))
73531 return old_fsuid;
73532
73533+ if (gr_check_user_change(-1, -1, kuid))
73534+ goto error;
73535+
73536 new = prepare_creds();
73537 if (!new)
73538 return old_fsuid;
73539@@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
73540 }
73541 }
73542
73543+error:
73544 abort_creds(new);
73545 return old_fsuid;
73546
73547@@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
73548 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
73549 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
73550 nsown_capable(CAP_SETGID)) {
73551+ if (gr_check_group_change(-1, -1, kgid))
73552+ goto error;
73553+
73554 if (!gid_eq(kgid, old->fsgid)) {
73555 new->fsgid = kgid;
73556 goto change_okay;
73557 }
73558 }
73559
73560+error:
73561 abort_creds(new);
73562 return old_fsgid;
73563
73564@@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
73565 return -EFAULT;
73566
73567 down_read(&uts_sem);
73568- error = __copy_to_user(&name->sysname, &utsname()->sysname,
73569+ error = __copy_to_user(name->sysname, &utsname()->sysname,
73570 __OLD_UTS_LEN);
73571 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
73572- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
73573+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
73574 __OLD_UTS_LEN);
73575 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
73576- error |= __copy_to_user(&name->release, &utsname()->release,
73577+ error |= __copy_to_user(name->release, &utsname()->release,
73578 __OLD_UTS_LEN);
73579 error |= __put_user(0, name->release + __OLD_UTS_LEN);
73580- error |= __copy_to_user(&name->version, &utsname()->version,
73581+ error |= __copy_to_user(name->version, &utsname()->version,
73582 __OLD_UTS_LEN);
73583 error |= __put_user(0, name->version + __OLD_UTS_LEN);
73584- error |= __copy_to_user(&name->machine, &utsname()->machine,
73585+ error |= __copy_to_user(name->machine, &utsname()->machine,
73586 __OLD_UTS_LEN);
73587 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
73588 up_read(&uts_sem);
73589@@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
73590 error = get_dumpable(me->mm);
73591 break;
73592 case PR_SET_DUMPABLE:
73593- if (arg2 < 0 || arg2 > 1) {
73594+ if (arg2 > 1) {
73595 error = -EINVAL;
73596 break;
73597 }
73598diff --git a/kernel/sysctl.c b/kernel/sysctl.c
73599index c88878d..99d321b 100644
73600--- a/kernel/sysctl.c
73601+++ b/kernel/sysctl.c
73602@@ -92,7 +92,6 @@
73603
73604
73605 #if defined(CONFIG_SYSCTL)
73606-
73607 /* External variables not in a header file. */
73608 extern int sysctl_overcommit_memory;
73609 extern int sysctl_overcommit_ratio;
73610@@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
73611 void __user *buffer, size_t *lenp, loff_t *ppos);
73612 #endif
73613
73614-#ifdef CONFIG_PRINTK
73615 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73616 void __user *buffer, size_t *lenp, loff_t *ppos);
73617-#endif
73618
73619 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
73620 void __user *buffer, size_t *lenp, loff_t *ppos);
73621@@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
73622
73623 #endif
73624
73625+extern struct ctl_table grsecurity_table[];
73626+
73627 static struct ctl_table kern_table[];
73628 static struct ctl_table vm_table[];
73629 static struct ctl_table fs_table[];
73630@@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
73631 int sysctl_legacy_va_layout;
73632 #endif
73633
73634+#ifdef CONFIG_PAX_SOFTMODE
73635+static ctl_table pax_table[] = {
73636+ {
73637+ .procname = "softmode",
73638+ .data = &pax_softmode,
73639+ .maxlen = sizeof(unsigned int),
73640+ .mode = 0600,
73641+ .proc_handler = &proc_dointvec,
73642+ },
73643+
73644+ { }
73645+};
73646+#endif
73647+
73648 /* The default sysctl tables: */
73649
73650 static struct ctl_table sysctl_base_table[] = {
73651@@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
73652 #endif
73653
73654 static struct ctl_table kern_table[] = {
73655+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
73656+ {
73657+ .procname = "grsecurity",
73658+ .mode = 0500,
73659+ .child = grsecurity_table,
73660+ },
73661+#endif
73662+
73663+#ifdef CONFIG_PAX_SOFTMODE
73664+ {
73665+ .procname = "pax",
73666+ .mode = 0500,
73667+ .child = pax_table,
73668+ },
73669+#endif
73670+
73671 {
73672 .procname = "sched_child_runs_first",
73673 .data = &sysctl_sched_child_runs_first,
73674@@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
73675 .data = &modprobe_path,
73676 .maxlen = KMOD_PATH_LEN,
73677 .mode = 0644,
73678- .proc_handler = proc_dostring,
73679+ .proc_handler = proc_dostring_modpriv,
73680 },
73681 {
73682 .procname = "modules_disabled",
73683@@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
73684 .extra1 = &zero,
73685 .extra2 = &one,
73686 },
73687+#endif
73688 {
73689 .procname = "kptr_restrict",
73690 .data = &kptr_restrict,
73691 .maxlen = sizeof(int),
73692 .mode = 0644,
73693 .proc_handler = proc_dointvec_minmax_sysadmin,
73694+#ifdef CONFIG_GRKERNSEC_HIDESYM
73695+ .extra1 = &two,
73696+#else
73697 .extra1 = &zero,
73698+#endif
73699 .extra2 = &two,
73700 },
73701-#endif
73702 {
73703 .procname = "ngroups_max",
73704 .data = &ngroups_max,
73705@@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
73706 .proc_handler = proc_dointvec_minmax,
73707 .extra1 = &zero,
73708 },
73709+ {
73710+ .procname = "heap_stack_gap",
73711+ .data = &sysctl_heap_stack_gap,
73712+ .maxlen = sizeof(sysctl_heap_stack_gap),
73713+ .mode = 0644,
73714+ .proc_handler = proc_doulongvec_minmax,
73715+ },
73716 #else
73717 {
73718 .procname = "nr_trim_pages",
73719@@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
73720 buffer, lenp, ppos);
73721 }
73722
73723+int proc_dostring_modpriv(struct ctl_table *table, int write,
73724+ void __user *buffer, size_t *lenp, loff_t *ppos)
73725+{
73726+ if (write && !capable(CAP_SYS_MODULE))
73727+ return -EPERM;
73728+
73729+ return _proc_do_string(table->data, table->maxlen, write,
73730+ buffer, lenp, ppos);
73731+}
73732+
73733 static size_t proc_skip_spaces(char **buf)
73734 {
73735 size_t ret;
73736@@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
73737 len = strlen(tmp);
73738 if (len > *size)
73739 len = *size;
73740+ if (len > sizeof(tmp))
73741+ len = sizeof(tmp);
73742 if (copy_to_user(*buf, tmp, len))
73743 return -EFAULT;
73744 *size -= len;
73745@@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
73746 return err;
73747 }
73748
73749-#ifdef CONFIG_PRINTK
73750 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73751 void __user *buffer, size_t *lenp, loff_t *ppos)
73752 {
73753@@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73754
73755 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
73756 }
73757-#endif
73758
73759 struct do_proc_dointvec_minmax_conv_param {
73760 int *min;
73761@@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
73762 *i = val;
73763 } else {
73764 val = convdiv * (*i) / convmul;
73765- if (!first)
73766+ if (!first) {
73767 err = proc_put_char(&buffer, &left, '\t');
73768+ if (err)
73769+ break;
73770+ }
73771 err = proc_put_long(&buffer, &left, val, false);
73772 if (err)
73773 break;
73774@@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
73775 return -ENOSYS;
73776 }
73777
73778+int proc_dostring_modpriv(struct ctl_table *table, int write,
73779+ void __user *buffer, size_t *lenp, loff_t *ppos)
73780+{
73781+ return -ENOSYS;
73782+}
73783+
73784 int proc_dointvec(struct ctl_table *table, int write,
73785 void __user *buffer, size_t *lenp, loff_t *ppos)
73786 {
73787@@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
73788 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
73789 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
73790 EXPORT_SYMBOL(proc_dostring);
73791+EXPORT_SYMBOL(proc_dostring_modpriv);
73792 EXPORT_SYMBOL(proc_doulongvec_minmax);
73793 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
73794diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
73795index 5a63844..25dfc5c 100644
73796--- a/kernel/sysctl_binary.c
73797+++ b/kernel/sysctl_binary.c
73798@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
73799 int i;
73800
73801 set_fs(KERNEL_DS);
73802- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
73803+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
73804 set_fs(old_fs);
73805 if (result < 0)
73806 goto out_kfree;
73807@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
73808 }
73809
73810 set_fs(KERNEL_DS);
73811- result = vfs_write(file, buffer, str - buffer, &pos);
73812+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
73813 set_fs(old_fs);
73814 if (result < 0)
73815 goto out_kfree;
73816@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
73817 int i;
73818
73819 set_fs(KERNEL_DS);
73820- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
73821+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
73822 set_fs(old_fs);
73823 if (result < 0)
73824 goto out_kfree;
73825@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
73826 }
73827
73828 set_fs(KERNEL_DS);
73829- result = vfs_write(file, buffer, str - buffer, &pos);
73830+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
73831 set_fs(old_fs);
73832 if (result < 0)
73833 goto out_kfree;
73834@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
73835 int i;
73836
73837 set_fs(KERNEL_DS);
73838- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
73839+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
73840 set_fs(old_fs);
73841 if (result < 0)
73842 goto out;
73843@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
73844 __le16 dnaddr;
73845
73846 set_fs(KERNEL_DS);
73847- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
73848+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
73849 set_fs(old_fs);
73850 if (result < 0)
73851 goto out;
73852@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
73853 le16_to_cpu(dnaddr) & 0x3ff);
73854
73855 set_fs(KERNEL_DS);
73856- result = vfs_write(file, buf, len, &pos);
73857+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
73858 set_fs(old_fs);
73859 if (result < 0)
73860 goto out;
73861diff --git a/kernel/taskstats.c b/kernel/taskstats.c
73862index 145bb4d..b2aa969 100644
73863--- a/kernel/taskstats.c
73864+++ b/kernel/taskstats.c
73865@@ -28,9 +28,12 @@
73866 #include <linux/fs.h>
73867 #include <linux/file.h>
73868 #include <linux/pid_namespace.h>
73869+#include <linux/grsecurity.h>
73870 #include <net/genetlink.h>
73871 #include <linux/atomic.h>
73872
73873+extern int gr_is_taskstats_denied(int pid);
73874+
73875 /*
73876 * Maximum length of a cpumask that can be specified in
73877 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
73878@@ -570,6 +573,9 @@ err:
73879
73880 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
73881 {
73882+ if (gr_is_taskstats_denied(current->pid))
73883+ return -EACCES;
73884+
73885 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
73886 return cmd_attr_register_cpumask(info);
73887 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
73888diff --git a/kernel/time.c b/kernel/time.c
73889index d226c6a..c7c0960 100644
73890--- a/kernel/time.c
73891+++ b/kernel/time.c
73892@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
73893 return error;
73894
73895 if (tz) {
73896+ /* we log in do_settimeofday called below, so don't log twice
73897+ */
73898+ if (!tv)
73899+ gr_log_timechange();
73900+
73901 sys_tz = *tz;
73902 update_vsyscall_tz();
73903 if (firsttime) {
73904diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
73905index f11d83b..d016d91 100644
73906--- a/kernel/time/alarmtimer.c
73907+++ b/kernel/time/alarmtimer.c
73908@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
73909 struct platform_device *pdev;
73910 int error = 0;
73911 int i;
73912- struct k_clock alarm_clock = {
73913+ static struct k_clock alarm_clock = {
73914 .clock_getres = alarm_clock_getres,
73915 .clock_get = alarm_clock_get,
73916 .timer_create = alarm_timer_create,
73917diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
73918index f113755..ec24223 100644
73919--- a/kernel/time/tick-broadcast.c
73920+++ b/kernel/time/tick-broadcast.c
73921@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
73922 * then clear the broadcast bit.
73923 */
73924 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
73925- int cpu = smp_processor_id();
73926+ cpu = smp_processor_id();
73927
73928 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
73929 tick_broadcast_clear_oneshot(cpu);
73930diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
73931index cbc6acb..3a77191 100644
73932--- a/kernel/time/timekeeping.c
73933+++ b/kernel/time/timekeeping.c
73934@@ -15,6 +15,7 @@
73935 #include <linux/init.h>
73936 #include <linux/mm.h>
73937 #include <linux/sched.h>
73938+#include <linux/grsecurity.h>
73939 #include <linux/syscore_ops.h>
73940 #include <linux/clocksource.h>
73941 #include <linux/jiffies.h>
73942@@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
73943 if (!timespec_valid_strict(tv))
73944 return -EINVAL;
73945
73946+ gr_log_timechange();
73947+
73948 write_seqlock_irqsave(&tk->lock, flags);
73949
73950 timekeeping_forward_now(tk);
73951diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
73952index af5a7e9..715611a 100644
73953--- a/kernel/time/timer_list.c
73954+++ b/kernel/time/timer_list.c
73955@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
73956
73957 static void print_name_offset(struct seq_file *m, void *sym)
73958 {
73959+#ifdef CONFIG_GRKERNSEC_HIDESYM
73960+ SEQ_printf(m, "<%p>", NULL);
73961+#else
73962 char symname[KSYM_NAME_LEN];
73963
73964 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
73965 SEQ_printf(m, "<%pK>", sym);
73966 else
73967 SEQ_printf(m, "%s", symname);
73968+#endif
73969 }
73970
73971 static void
73972@@ -112,7 +116,11 @@ next_one:
73973 static void
73974 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
73975 {
73976+#ifdef CONFIG_GRKERNSEC_HIDESYM
73977+ SEQ_printf(m, " .base: %p\n", NULL);
73978+#else
73979 SEQ_printf(m, " .base: %pK\n", base);
73980+#endif
73981 SEQ_printf(m, " .index: %d\n",
73982 base->index);
73983 SEQ_printf(m, " .resolution: %Lu nsecs\n",
73984@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
73985 {
73986 struct proc_dir_entry *pe;
73987
73988+#ifdef CONFIG_GRKERNSEC_PROC_ADD
73989+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
73990+#else
73991 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
73992+#endif
73993 if (!pe)
73994 return -ENOMEM;
73995 return 0;
73996diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
73997index 0b537f2..40d6c20 100644
73998--- a/kernel/time/timer_stats.c
73999+++ b/kernel/time/timer_stats.c
74000@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
74001 static unsigned long nr_entries;
74002 static struct entry entries[MAX_ENTRIES];
74003
74004-static atomic_t overflow_count;
74005+static atomic_unchecked_t overflow_count;
74006
74007 /*
74008 * The entries are in a hash-table, for fast lookup:
74009@@ -140,7 +140,7 @@ static void reset_entries(void)
74010 nr_entries = 0;
74011 memset(entries, 0, sizeof(entries));
74012 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
74013- atomic_set(&overflow_count, 0);
74014+ atomic_set_unchecked(&overflow_count, 0);
74015 }
74016
74017 static struct entry *alloc_entry(void)
74018@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
74019 if (likely(entry))
74020 entry->count++;
74021 else
74022- atomic_inc(&overflow_count);
74023+ atomic_inc_unchecked(&overflow_count);
74024
74025 out_unlock:
74026 raw_spin_unlock_irqrestore(lock, flags);
74027@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
74028
74029 static void print_name_offset(struct seq_file *m, unsigned long addr)
74030 {
74031+#ifdef CONFIG_GRKERNSEC_HIDESYM
74032+ seq_printf(m, "<%p>", NULL);
74033+#else
74034 char symname[KSYM_NAME_LEN];
74035
74036 if (lookup_symbol_name(addr, symname) < 0)
74037- seq_printf(m, "<%p>", (void *)addr);
74038+ seq_printf(m, "<%pK>", (void *)addr);
74039 else
74040 seq_printf(m, "%s", symname);
74041+#endif
74042 }
74043
74044 static int tstats_show(struct seq_file *m, void *v)
74045@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
74046
74047 seq_puts(m, "Timer Stats Version: v0.2\n");
74048 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
74049- if (atomic_read(&overflow_count))
74050+ if (atomic_read_unchecked(&overflow_count))
74051 seq_printf(m, "Overflow: %d entries\n",
74052- atomic_read(&overflow_count));
74053+ atomic_read_unchecked(&overflow_count));
74054
74055 for (i = 0; i < nr_entries; i++) {
74056 entry = entries + i;
74057@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
74058 {
74059 struct proc_dir_entry *pe;
74060
74061+#ifdef CONFIG_GRKERNSEC_PROC_ADD
74062+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
74063+#else
74064 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
74065+#endif
74066 if (!pe)
74067 return -ENOMEM;
74068 return 0;
74069diff --git a/kernel/timer.c b/kernel/timer.c
74070index 367d008..1ee9ed9 100644
74071--- a/kernel/timer.c
74072+++ b/kernel/timer.c
74073@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
74074 /*
74075 * This function runs timers and the timer-tq in bottom half context.
74076 */
74077-static void run_timer_softirq(struct softirq_action *h)
74078+static void run_timer_softirq(void)
74079 {
74080 struct tvec_base *base = __this_cpu_read(tvec_bases);
74081
74082@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
74083 return NOTIFY_OK;
74084 }
74085
74086-static struct notifier_block __cpuinitdata timers_nb = {
74087+static struct notifier_block timers_nb = {
74088 .notifier_call = timer_cpu_notify,
74089 };
74090
74091diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
74092index c0bd030..62a1927 100644
74093--- a/kernel/trace/blktrace.c
74094+++ b/kernel/trace/blktrace.c
74095@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
74096 struct blk_trace *bt = filp->private_data;
74097 char buf[16];
74098
74099- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
74100+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
74101
74102 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
74103 }
74104@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
74105 return 1;
74106
74107 bt = buf->chan->private_data;
74108- atomic_inc(&bt->dropped);
74109+ atomic_inc_unchecked(&bt->dropped);
74110 return 0;
74111 }
74112
74113@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
74114
74115 bt->dir = dir;
74116 bt->dev = dev;
74117- atomic_set(&bt->dropped, 0);
74118+ atomic_set_unchecked(&bt->dropped, 0);
74119
74120 ret = -EIO;
74121 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
74122diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
74123index 41473b4..325fcfc 100644
74124--- a/kernel/trace/ftrace.c
74125+++ b/kernel/trace/ftrace.c
74126@@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
74127 if (unlikely(ftrace_disabled))
74128 return 0;
74129
74130+ ret = ftrace_arch_code_modify_prepare();
74131+ FTRACE_WARN_ON(ret);
74132+ if (ret)
74133+ return 0;
74134+
74135 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
74136+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
74137 if (ret) {
74138 ftrace_bug(ret, ip);
74139- return 0;
74140 }
74141- return 1;
74142+ return ret ? 0 : 1;
74143 }
74144
74145 /*
74146@@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
74147
74148 int
74149 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
74150- void *data)
74151+ void *data)
74152 {
74153 struct ftrace_func_probe *entry;
74154 struct ftrace_page *pg;
74155@@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
74156 if (!count)
74157 return 0;
74158
74159+ pax_open_kernel();
74160 sort(start, count, sizeof(*start),
74161 ftrace_cmp_ips, ftrace_swap_ips);
74162+ pax_close_kernel();
74163
74164 start_pg = ftrace_allocate_pages(count);
74165 if (!start_pg)
74166@@ -4541,8 +4548,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
74167 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
74168
74169 static int ftrace_graph_active;
74170-static struct notifier_block ftrace_suspend_notifier;
74171-
74172 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
74173 {
74174 return 0;
74175@@ -4686,6 +4691,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
74176 return NOTIFY_DONE;
74177 }
74178
74179+static struct notifier_block ftrace_suspend_notifier = {
74180+ .notifier_call = ftrace_suspend_notifier_call
74181+};
74182+
74183 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
74184 trace_func_graph_ent_t entryfunc)
74185 {
74186@@ -4699,7 +4708,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
74187 goto out;
74188 }
74189
74190- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
74191 register_pm_notifier(&ftrace_suspend_notifier);
74192
74193 ftrace_graph_active++;
74194diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
74195index ce8514f..8233573 100644
74196--- a/kernel/trace/ring_buffer.c
74197+++ b/kernel/trace/ring_buffer.c
74198@@ -346,9 +346,9 @@ struct buffer_data_page {
74199 */
74200 struct buffer_page {
74201 struct list_head list; /* list of buffer pages */
74202- local_t write; /* index for next write */
74203+ local_unchecked_t write; /* index for next write */
74204 unsigned read; /* index for next read */
74205- local_t entries; /* entries on this page */
74206+ local_unchecked_t entries; /* entries on this page */
74207 unsigned long real_end; /* real end of data */
74208 struct buffer_data_page *page; /* Actual data page */
74209 };
74210@@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
74211 unsigned long last_overrun;
74212 local_t entries_bytes;
74213 local_t entries;
74214- local_t overrun;
74215- local_t commit_overrun;
74216+ local_unchecked_t overrun;
74217+ local_unchecked_t commit_overrun;
74218 local_t dropped_events;
74219 local_t committing;
74220 local_t commits;
74221@@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
74222 *
74223 * We add a counter to the write field to denote this.
74224 */
74225- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
74226- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
74227+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
74228+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
74229
74230 /*
74231 * Just make sure we have seen our old_write and synchronize
74232@@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
74233 * cmpxchg to only update if an interrupt did not already
74234 * do it for us. If the cmpxchg fails, we don't care.
74235 */
74236- (void)local_cmpxchg(&next_page->write, old_write, val);
74237- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
74238+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
74239+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
74240
74241 /*
74242 * No need to worry about races with clearing out the commit.
74243@@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
74244
74245 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
74246 {
74247- return local_read(&bpage->entries) & RB_WRITE_MASK;
74248+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
74249 }
74250
74251 static inline unsigned long rb_page_write(struct buffer_page *bpage)
74252 {
74253- return local_read(&bpage->write) & RB_WRITE_MASK;
74254+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
74255 }
74256
74257 static int
74258@@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
74259 * bytes consumed in ring buffer from here.
74260 * Increment overrun to account for the lost events.
74261 */
74262- local_add(page_entries, &cpu_buffer->overrun);
74263+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
74264 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
74265 }
74266
74267@@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
74268 * it is our responsibility to update
74269 * the counters.
74270 */
74271- local_add(entries, &cpu_buffer->overrun);
74272+ local_add_unchecked(entries, &cpu_buffer->overrun);
74273 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
74274
74275 /*
74276@@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74277 if (tail == BUF_PAGE_SIZE)
74278 tail_page->real_end = 0;
74279
74280- local_sub(length, &tail_page->write);
74281+ local_sub_unchecked(length, &tail_page->write);
74282 return;
74283 }
74284
74285@@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74286 rb_event_set_padding(event);
74287
74288 /* Set the write back to the previous setting */
74289- local_sub(length, &tail_page->write);
74290+ local_sub_unchecked(length, &tail_page->write);
74291 return;
74292 }
74293
74294@@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74295
74296 /* Set write to end of buffer */
74297 length = (tail + length) - BUF_PAGE_SIZE;
74298- local_sub(length, &tail_page->write);
74299+ local_sub_unchecked(length, &tail_page->write);
74300 }
74301
74302 /*
74303@@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
74304 * about it.
74305 */
74306 if (unlikely(next_page == commit_page)) {
74307- local_inc(&cpu_buffer->commit_overrun);
74308+ local_inc_unchecked(&cpu_buffer->commit_overrun);
74309 goto out_reset;
74310 }
74311
74312@@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
74313 cpu_buffer->tail_page) &&
74314 (cpu_buffer->commit_page ==
74315 cpu_buffer->reader_page))) {
74316- local_inc(&cpu_buffer->commit_overrun);
74317+ local_inc_unchecked(&cpu_buffer->commit_overrun);
74318 goto out_reset;
74319 }
74320 }
74321@@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
74322 length += RB_LEN_TIME_EXTEND;
74323
74324 tail_page = cpu_buffer->tail_page;
74325- write = local_add_return(length, &tail_page->write);
74326+ write = local_add_return_unchecked(length, &tail_page->write);
74327
74328 /* set write to only the index of the write */
74329 write &= RB_WRITE_MASK;
74330@@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
74331 kmemcheck_annotate_bitfield(event, bitfield);
74332 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
74333
74334- local_inc(&tail_page->entries);
74335+ local_inc_unchecked(&tail_page->entries);
74336
74337 /*
74338 * If this is the first commit on the page, then update
74339@@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
74340
74341 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
74342 unsigned long write_mask =
74343- local_read(&bpage->write) & ~RB_WRITE_MASK;
74344+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
74345 unsigned long event_length = rb_event_length(event);
74346 /*
74347 * This is on the tail page. It is possible that
74348@@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
74349 */
74350 old_index += write_mask;
74351 new_index += write_mask;
74352- index = local_cmpxchg(&bpage->write, old_index, new_index);
74353+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
74354 if (index == old_index) {
74355 /* update counters */
74356 local_sub(event_length, &cpu_buffer->entries_bytes);
74357@@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
74358
74359 /* Do the likely case first */
74360 if (likely(bpage->page == (void *)addr)) {
74361- local_dec(&bpage->entries);
74362+ local_dec_unchecked(&bpage->entries);
74363 return;
74364 }
74365
74366@@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
74367 start = bpage;
74368 do {
74369 if (bpage->page == (void *)addr) {
74370- local_dec(&bpage->entries);
74371+ local_dec_unchecked(&bpage->entries);
74372 return;
74373 }
74374 rb_inc_page(cpu_buffer, &bpage);
74375@@ -2926,7 +2926,7 @@ static inline unsigned long
74376 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
74377 {
74378 return local_read(&cpu_buffer->entries) -
74379- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
74380+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
74381 }
74382
74383 /**
74384@@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
74385 return 0;
74386
74387 cpu_buffer = buffer->buffers[cpu];
74388- ret = local_read(&cpu_buffer->overrun);
74389+ ret = local_read_unchecked(&cpu_buffer->overrun);
74390
74391 return ret;
74392 }
74393@@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
74394 return 0;
74395
74396 cpu_buffer = buffer->buffers[cpu];
74397- ret = local_read(&cpu_buffer->commit_overrun);
74398+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
74399
74400 return ret;
74401 }
74402@@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
74403 /* if you care about this being correct, lock the buffer */
74404 for_each_buffer_cpu(buffer, cpu) {
74405 cpu_buffer = buffer->buffers[cpu];
74406- overruns += local_read(&cpu_buffer->overrun);
74407+ overruns += local_read_unchecked(&cpu_buffer->overrun);
74408 }
74409
74410 return overruns;
74411@@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
74412 /*
74413 * Reset the reader page to size zero.
74414 */
74415- local_set(&cpu_buffer->reader_page->write, 0);
74416- local_set(&cpu_buffer->reader_page->entries, 0);
74417+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
74418+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
74419 local_set(&cpu_buffer->reader_page->page->commit, 0);
74420 cpu_buffer->reader_page->real_end = 0;
74421
74422@@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
74423 * want to compare with the last_overrun.
74424 */
74425 smp_mb();
74426- overwrite = local_read(&(cpu_buffer->overrun));
74427+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
74428
74429 /*
74430 * Here's the tricky part.
74431@@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
74432
74433 cpu_buffer->head_page
74434 = list_entry(cpu_buffer->pages, struct buffer_page, list);
74435- local_set(&cpu_buffer->head_page->write, 0);
74436- local_set(&cpu_buffer->head_page->entries, 0);
74437+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
74438+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
74439 local_set(&cpu_buffer->head_page->page->commit, 0);
74440
74441 cpu_buffer->head_page->read = 0;
74442@@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
74443
74444 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
74445 INIT_LIST_HEAD(&cpu_buffer->new_pages);
74446- local_set(&cpu_buffer->reader_page->write, 0);
74447- local_set(&cpu_buffer->reader_page->entries, 0);
74448+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
74449+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
74450 local_set(&cpu_buffer->reader_page->page->commit, 0);
74451 cpu_buffer->reader_page->read = 0;
74452
74453 local_set(&cpu_buffer->entries_bytes, 0);
74454- local_set(&cpu_buffer->overrun, 0);
74455- local_set(&cpu_buffer->commit_overrun, 0);
74456+ local_set_unchecked(&cpu_buffer->overrun, 0);
74457+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
74458 local_set(&cpu_buffer->dropped_events, 0);
74459 local_set(&cpu_buffer->entries, 0);
74460 local_set(&cpu_buffer->committing, 0);
74461@@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
74462 rb_init_page(bpage);
74463 bpage = reader->page;
74464 reader->page = *data_page;
74465- local_set(&reader->write, 0);
74466- local_set(&reader->entries, 0);
74467+ local_set_unchecked(&reader->write, 0);
74468+ local_set_unchecked(&reader->entries, 0);
74469 reader->read = 0;
74470 *data_page = bpage;
74471
74472diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
74473index 3c13e46..883d039 100644
74474--- a/kernel/trace/trace.c
74475+++ b/kernel/trace/trace.c
74476@@ -4465,10 +4465,9 @@ static const struct file_operations tracing_dyn_info_fops = {
74477 };
74478 #endif
74479
74480-static struct dentry *d_tracer;
74481-
74482 struct dentry *tracing_init_dentry(void)
74483 {
74484+ static struct dentry *d_tracer;
74485 static int once;
74486
74487 if (d_tracer)
74488@@ -4488,10 +4487,9 @@ struct dentry *tracing_init_dentry(void)
74489 return d_tracer;
74490 }
74491
74492-static struct dentry *d_percpu;
74493-
74494 struct dentry *tracing_dentry_percpu(void)
74495 {
74496+ static struct dentry *d_percpu;
74497 static int once;
74498 struct dentry *d_tracer;
74499
74500diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
74501index 880073d..42db7c3 100644
74502--- a/kernel/trace/trace_events.c
74503+++ b/kernel/trace/trace_events.c
74504@@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
74505 struct ftrace_module_file_ops {
74506 struct list_head list;
74507 struct module *mod;
74508- struct file_operations id;
74509- struct file_operations enable;
74510- struct file_operations format;
74511- struct file_operations filter;
74512 };
74513
74514 static struct ftrace_module_file_ops *
74515@@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
74516
74517 file_ops->mod = mod;
74518
74519- file_ops->id = ftrace_event_id_fops;
74520- file_ops->id.owner = mod;
74521-
74522- file_ops->enable = ftrace_enable_fops;
74523- file_ops->enable.owner = mod;
74524-
74525- file_ops->filter = ftrace_event_filter_fops;
74526- file_ops->filter.owner = mod;
74527-
74528- file_ops->format = ftrace_event_format_fops;
74529- file_ops->format.owner = mod;
74530+ pax_open_kernel();
74531+ mod->trace_id.owner = mod;
74532+ mod->trace_enable.owner = mod;
74533+ mod->trace_filter.owner = mod;
74534+ mod->trace_format.owner = mod;
74535+ pax_close_kernel();
74536
74537 list_add(&file_ops->list, &ftrace_module_file_list);
74538
74539@@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
74540
74541 for_each_event(call, start, end) {
74542 __trace_add_event_call(*call, mod,
74543- &file_ops->id, &file_ops->enable,
74544- &file_ops->filter, &file_ops->format);
74545+ &mod->trace_id, &mod->trace_enable,
74546+ &mod->trace_filter, &mod->trace_format);
74547 }
74548 }
74549
74550diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
74551index fd3c8aa..5f324a6 100644
74552--- a/kernel/trace/trace_mmiotrace.c
74553+++ b/kernel/trace/trace_mmiotrace.c
74554@@ -24,7 +24,7 @@ struct header_iter {
74555 static struct trace_array *mmio_trace_array;
74556 static bool overrun_detected;
74557 static unsigned long prev_overruns;
74558-static atomic_t dropped_count;
74559+static atomic_unchecked_t dropped_count;
74560
74561 static void mmio_reset_data(struct trace_array *tr)
74562 {
74563@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
74564
74565 static unsigned long count_overruns(struct trace_iterator *iter)
74566 {
74567- unsigned long cnt = atomic_xchg(&dropped_count, 0);
74568+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
74569 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
74570
74571 if (over > prev_overruns)
74572@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
74573 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
74574 sizeof(*entry), 0, pc);
74575 if (!event) {
74576- atomic_inc(&dropped_count);
74577+ atomic_inc_unchecked(&dropped_count);
74578 return;
74579 }
74580 entry = ring_buffer_event_data(event);
74581@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
74582 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
74583 sizeof(*entry), 0, pc);
74584 if (!event) {
74585- atomic_inc(&dropped_count);
74586+ atomic_inc_unchecked(&dropped_count);
74587 return;
74588 }
74589 entry = ring_buffer_event_data(event);
74590diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
74591index 194d796..76edb8f 100644
74592--- a/kernel/trace/trace_output.c
74593+++ b/kernel/trace/trace_output.c
74594@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
74595
74596 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
74597 if (!IS_ERR(p)) {
74598- p = mangle_path(s->buffer + s->len, p, "\n");
74599+ p = mangle_path(s->buffer + s->len, p, "\n\\");
74600 if (p) {
74601 s->len = p - s->buffer;
74602 return 1;
74603@@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
74604 goto out;
74605 }
74606
74607+ pax_open_kernel();
74608 if (event->funcs->trace == NULL)
74609- event->funcs->trace = trace_nop_print;
74610+ *(void **)&event->funcs->trace = trace_nop_print;
74611 if (event->funcs->raw == NULL)
74612- event->funcs->raw = trace_nop_print;
74613+ *(void **)&event->funcs->raw = trace_nop_print;
74614 if (event->funcs->hex == NULL)
74615- event->funcs->hex = trace_nop_print;
74616+ *(void **)&event->funcs->hex = trace_nop_print;
74617 if (event->funcs->binary == NULL)
74618- event->funcs->binary = trace_nop_print;
74619+ *(void **)&event->funcs->binary = trace_nop_print;
74620+ pax_close_kernel();
74621
74622 key = event->type & (EVENT_HASHSIZE - 1);
74623
74624diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
74625index 42ca822..cdcacc6 100644
74626--- a/kernel/trace/trace_stack.c
74627+++ b/kernel/trace/trace_stack.c
74628@@ -52,7 +52,7 @@ static inline void check_stack(void)
74629 return;
74630
74631 /* we do not handle interrupt stacks yet */
74632- if (!object_is_on_stack(&this_size))
74633+ if (!object_starts_on_stack(&this_size))
74634 return;
74635
74636 local_irq_save(flags);
74637diff --git a/kernel/user.c b/kernel/user.c
74638index 33acb5e..57ebfd4 100644
74639--- a/kernel/user.c
74640+++ b/kernel/user.c
74641@@ -47,9 +47,7 @@ struct user_namespace init_user_ns = {
74642 .count = 4294967295U,
74643 },
74644 },
74645- .kref = {
74646- .refcount = ATOMIC_INIT(3),
74647- },
74648+ .count = ATOMIC_INIT(3),
74649 .owner = GLOBAL_ROOT_UID,
74650 .group = GLOBAL_ROOT_GID,
74651 .proc_inum = PROC_USER_INIT_INO,
74652diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
74653index 2b042c4..24f8ec3 100644
74654--- a/kernel/user_namespace.c
74655+++ b/kernel/user_namespace.c
74656@@ -78,7 +78,7 @@ int create_user_ns(struct cred *new)
74657 return ret;
74658 }
74659
74660- kref_init(&ns->kref);
74661+ atomic_set(&ns->count, 1);
74662 /* Leave the new->user_ns reference with the new user namespace. */
74663 ns->parent = parent_ns;
74664 ns->owner = owner;
74665@@ -104,15 +104,16 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
74666 return create_user_ns(cred);
74667 }
74668
74669-void free_user_ns(struct kref *kref)
74670+void free_user_ns(struct user_namespace *ns)
74671 {
74672- struct user_namespace *parent, *ns =
74673- container_of(kref, struct user_namespace, kref);
74674+ struct user_namespace *parent;
74675
74676- parent = ns->parent;
74677- proc_free_inum(ns->proc_inum);
74678- kmem_cache_free(user_ns_cachep, ns);
74679- put_user_ns(parent);
74680+ do {
74681+ parent = ns->parent;
74682+ proc_free_inum(ns->proc_inum);
74683+ kmem_cache_free(user_ns_cachep, ns);
74684+ ns = parent;
74685+ } while (atomic_dec_and_test(&parent->count));
74686 }
74687 EXPORT_SYMBOL(free_user_ns);
74688
74689diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
74690index 67604e5..3ebb003 100644
74691--- a/lib/Kconfig.debug
74692+++ b/lib/Kconfig.debug
74693@@ -1278,6 +1278,7 @@ config LATENCYTOP
74694 depends on DEBUG_KERNEL
74695 depends on STACKTRACE_SUPPORT
74696 depends on PROC_FS
74697+ depends on !GRKERNSEC_HIDESYM
74698 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
74699 select KALLSYMS
74700 select KALLSYMS_ALL
74701@@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
74702
74703 config PROVIDE_OHCI1394_DMA_INIT
74704 bool "Remote debugging over FireWire early on boot"
74705- depends on PCI && X86
74706+ depends on PCI && X86 && !GRKERNSEC
74707 help
74708 If you want to debug problems which hang or crash the kernel early
74709 on boot and the crashing machine has a FireWire port, you can use
74710@@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
74711
74712 config FIREWIRE_OHCI_REMOTE_DMA
74713 bool "Remote debugging over FireWire with firewire-ohci"
74714- depends on FIREWIRE_OHCI
74715+ depends on FIREWIRE_OHCI && !GRKERNSEC
74716 help
74717 This option lets you use the FireWire bus for remote debugging
74718 with help of the firewire-ohci driver. It enables unfiltered
74719diff --git a/lib/Makefile b/lib/Makefile
74720index 02ed6c0..bd243da 100644
74721--- a/lib/Makefile
74722+++ b/lib/Makefile
74723@@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
74724
74725 obj-$(CONFIG_BTREE) += btree.o
74726 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
74727-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
74728+obj-y += list_debug.o
74729 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
74730
74731 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
74732diff --git a/lib/bitmap.c b/lib/bitmap.c
74733index 06f7e4f..f3cf2b0 100644
74734--- a/lib/bitmap.c
74735+++ b/lib/bitmap.c
74736@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
74737 {
74738 int c, old_c, totaldigits, ndigits, nchunks, nbits;
74739 u32 chunk;
74740- const char __user __force *ubuf = (const char __user __force *)buf;
74741+ const char __user *ubuf = (const char __force_user *)buf;
74742
74743 bitmap_zero(maskp, nmaskbits);
74744
74745@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
74746 {
74747 if (!access_ok(VERIFY_READ, ubuf, ulen))
74748 return -EFAULT;
74749- return __bitmap_parse((const char __force *)ubuf,
74750+ return __bitmap_parse((const char __force_kernel *)ubuf,
74751 ulen, 1, maskp, nmaskbits);
74752
74753 }
74754@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
74755 {
74756 unsigned a, b;
74757 int c, old_c, totaldigits;
74758- const char __user __force *ubuf = (const char __user __force *)buf;
74759+ const char __user *ubuf = (const char __force_user *)buf;
74760 int exp_digit, in_range;
74761
74762 totaldigits = c = 0;
74763@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
74764 {
74765 if (!access_ok(VERIFY_READ, ubuf, ulen))
74766 return -EFAULT;
74767- return __bitmap_parselist((const char __force *)ubuf,
74768+ return __bitmap_parselist((const char __force_kernel *)ubuf,
74769 ulen, 1, maskp, nmaskbits);
74770 }
74771 EXPORT_SYMBOL(bitmap_parselist_user);
74772diff --git a/lib/bug.c b/lib/bug.c
74773index d0cdf14..4d07bd2 100644
74774--- a/lib/bug.c
74775+++ b/lib/bug.c
74776@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
74777 return BUG_TRAP_TYPE_NONE;
74778
74779 bug = find_bug(bugaddr);
74780+ if (!bug)
74781+ return BUG_TRAP_TYPE_NONE;
74782
74783 file = NULL;
74784 line = 0;
74785diff --git a/lib/debugobjects.c b/lib/debugobjects.c
74786index d11808c..dc2d6f8 100644
74787--- a/lib/debugobjects.c
74788+++ b/lib/debugobjects.c
74789@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
74790 if (limit > 4)
74791 return;
74792
74793- is_on_stack = object_is_on_stack(addr);
74794+ is_on_stack = object_starts_on_stack(addr);
74795 if (is_on_stack == onstack)
74796 return;
74797
74798diff --git a/lib/devres.c b/lib/devres.c
74799index 80b9c76..9e32279 100644
74800--- a/lib/devres.c
74801+++ b/lib/devres.c
74802@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
74803 void devm_iounmap(struct device *dev, void __iomem *addr)
74804 {
74805 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
74806- (void *)addr));
74807+ (void __force *)addr));
74808 iounmap(addr);
74809 }
74810 EXPORT_SYMBOL(devm_iounmap);
74811@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
74812 {
74813 ioport_unmap(addr);
74814 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
74815- devm_ioport_map_match, (void *)addr));
74816+ devm_ioport_map_match, (void __force *)addr));
74817 }
74818 EXPORT_SYMBOL(devm_ioport_unmap);
74819
74820diff --git a/lib/dma-debug.c b/lib/dma-debug.c
74821index 5e396ac..58d5de1 100644
74822--- a/lib/dma-debug.c
74823+++ b/lib/dma-debug.c
74824@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
74825
74826 void dma_debug_add_bus(struct bus_type *bus)
74827 {
74828- struct notifier_block *nb;
74829+ notifier_block_no_const *nb;
74830
74831 if (global_disable)
74832 return;
74833@@ -942,7 +942,7 @@ out:
74834
74835 static void check_for_stack(struct device *dev, void *addr)
74836 {
74837- if (object_is_on_stack(addr))
74838+ if (object_starts_on_stack(addr))
74839 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
74840 "stack [addr=%p]\n", addr);
74841 }
74842diff --git a/lib/inflate.c b/lib/inflate.c
74843index 013a761..c28f3fc 100644
74844--- a/lib/inflate.c
74845+++ b/lib/inflate.c
74846@@ -269,7 +269,7 @@ static void free(void *where)
74847 malloc_ptr = free_mem_ptr;
74848 }
74849 #else
74850-#define malloc(a) kmalloc(a, GFP_KERNEL)
74851+#define malloc(a) kmalloc((a), GFP_KERNEL)
74852 #define free(a) kfree(a)
74853 #endif
74854
74855diff --git a/lib/ioremap.c b/lib/ioremap.c
74856index 0c9216c..863bd89 100644
74857--- a/lib/ioremap.c
74858+++ b/lib/ioremap.c
74859@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
74860 unsigned long next;
74861
74862 phys_addr -= addr;
74863- pmd = pmd_alloc(&init_mm, pud, addr);
74864+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
74865 if (!pmd)
74866 return -ENOMEM;
74867 do {
74868@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
74869 unsigned long next;
74870
74871 phys_addr -= addr;
74872- pud = pud_alloc(&init_mm, pgd, addr);
74873+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
74874 if (!pud)
74875 return -ENOMEM;
74876 do {
74877diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
74878index bd2bea9..6b3c95e 100644
74879--- a/lib/is_single_threaded.c
74880+++ b/lib/is_single_threaded.c
74881@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
74882 struct task_struct *p, *t;
74883 bool ret;
74884
74885+ if (!mm)
74886+ return true;
74887+
74888 if (atomic_read(&task->signal->live) != 1)
74889 return false;
74890
74891diff --git a/lib/list_debug.c b/lib/list_debug.c
74892index c24c2f7..3fc5da0 100644
74893--- a/lib/list_debug.c
74894+++ b/lib/list_debug.c
74895@@ -11,7 +11,9 @@
74896 #include <linux/bug.h>
74897 #include <linux/kernel.h>
74898 #include <linux/rculist.h>
74899+#include <linux/mm.h>
74900
74901+#ifdef CONFIG_DEBUG_LIST
74902 /*
74903 * Insert a new entry between two known consecutive entries.
74904 *
74905@@ -19,21 +21,32 @@
74906 * the prev/next entries already!
74907 */
74908
74909-void __list_add(struct list_head *new,
74910- struct list_head *prev,
74911- struct list_head *next)
74912+static bool __list_add_debug(struct list_head *new,
74913+ struct list_head *prev,
74914+ struct list_head *next)
74915 {
74916- WARN(next->prev != prev,
74917+ if (WARN(next->prev != prev,
74918 "list_add corruption. next->prev should be "
74919 "prev (%p), but was %p. (next=%p).\n",
74920- prev, next->prev, next);
74921- WARN(prev->next != next,
74922+ prev, next->prev, next) ||
74923+ WARN(prev->next != next,
74924 "list_add corruption. prev->next should be "
74925 "next (%p), but was %p. (prev=%p).\n",
74926- next, prev->next, prev);
74927- WARN(new == prev || new == next,
74928+ next, prev->next, prev) ||
74929+ WARN(new == prev || new == next,
74930 "list_add double add: new=%p, prev=%p, next=%p.\n",
74931- new, prev, next);
74932+ new, prev, next))
74933+ return false;
74934+ return true;
74935+}
74936+
74937+void __list_add(struct list_head *new,
74938+ struct list_head *prev,
74939+ struct list_head *next)
74940+{
74941+ if (!__list_add_debug(new, prev, next))
74942+ return;
74943+
74944 next->prev = new;
74945 new->next = next;
74946 new->prev = prev;
74947@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
74948 }
74949 EXPORT_SYMBOL(__list_add);
74950
74951-void __list_del_entry(struct list_head *entry)
74952+static bool __list_del_entry_debug(struct list_head *entry)
74953 {
74954 struct list_head *prev, *next;
74955
74956@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
74957 WARN(next->prev != entry,
74958 "list_del corruption. next->prev should be %p, "
74959 "but was %p\n", entry, next->prev))
74960+ return false;
74961+ return true;
74962+}
74963+
74964+void __list_del_entry(struct list_head *entry)
74965+{
74966+ if (!__list_del_entry_debug(entry))
74967 return;
74968
74969- __list_del(prev, next);
74970+ __list_del(entry->prev, entry->next);
74971 }
74972 EXPORT_SYMBOL(__list_del_entry);
74973
74974@@ -86,15 +106,54 @@ EXPORT_SYMBOL(list_del);
74975 void __list_add_rcu(struct list_head *new,
74976 struct list_head *prev, struct list_head *next)
74977 {
74978- WARN(next->prev != prev,
74979+ if (WARN(next->prev != prev,
74980 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
74981- prev, next->prev, next);
74982- WARN(prev->next != next,
74983+ prev, next->prev, next) ||
74984+ WARN(prev->next != next,
74985 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
74986- next, prev->next, prev);
74987+ next, prev->next, prev))
74988+ return;
74989+
74990 new->next = next;
74991 new->prev = prev;
74992 rcu_assign_pointer(list_next_rcu(prev), new);
74993 next->prev = new;
74994 }
74995 EXPORT_SYMBOL(__list_add_rcu);
74996+#endif
74997+
74998+void pax_list_add_tail(struct list_head *new, struct list_head *head)
74999+{
75000+ struct list_head *prev, *next;
75001+
75002+ prev = head->prev;
75003+ next = head;
75004+
75005+#ifdef CONFIG_DEBUG_LIST
75006+ if (!__list_add_debug(new, prev, next))
75007+ return;
75008+#endif
75009+
75010+ pax_open_kernel();
75011+ next->prev = new;
75012+ new->next = next;
75013+ new->prev = prev;
75014+ prev->next = new;
75015+ pax_close_kernel();
75016+}
75017+EXPORT_SYMBOL(pax_list_add_tail);
75018+
75019+void pax_list_del(struct list_head *entry)
75020+{
75021+#ifdef CONFIG_DEBUG_LIST
75022+ if (!__list_del_entry_debug(entry))
75023+ return;
75024+#endif
75025+
75026+ pax_open_kernel();
75027+ __list_del(entry->prev, entry->next);
75028+ entry->next = LIST_POISON1;
75029+ entry->prev = LIST_POISON2;
75030+ pax_close_kernel();
75031+}
75032+EXPORT_SYMBOL(pax_list_del);
75033diff --git a/lib/radix-tree.c b/lib/radix-tree.c
75034index e796429..6e38f9f 100644
75035--- a/lib/radix-tree.c
75036+++ b/lib/radix-tree.c
75037@@ -92,7 +92,7 @@ struct radix_tree_preload {
75038 int nr;
75039 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
75040 };
75041-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
75042+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
75043
75044 static inline void *ptr_to_indirect(void *ptr)
75045 {
75046diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
75047index bb2b201..46abaf9 100644
75048--- a/lib/strncpy_from_user.c
75049+++ b/lib/strncpy_from_user.c
75050@@ -21,7 +21,7 @@
75051 */
75052 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
75053 {
75054- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
75055+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
75056 long res = 0;
75057
75058 /*
75059diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
75060index a28df52..3d55877 100644
75061--- a/lib/strnlen_user.c
75062+++ b/lib/strnlen_user.c
75063@@ -26,7 +26,7 @@
75064 */
75065 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
75066 {
75067- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
75068+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
75069 long align, res = 0;
75070 unsigned long c;
75071
75072diff --git a/lib/vsprintf.c b/lib/vsprintf.c
75073index fab33a9..3b5fe68 100644
75074--- a/lib/vsprintf.c
75075+++ b/lib/vsprintf.c
75076@@ -16,6 +16,9 @@
75077 * - scnprintf and vscnprintf
75078 */
75079
75080+#ifdef CONFIG_GRKERNSEC_HIDESYM
75081+#define __INCLUDED_BY_HIDESYM 1
75082+#endif
75083 #include <stdarg.h>
75084 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
75085 #include <linux/types.h>
75086@@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
75087 char sym[KSYM_SYMBOL_LEN];
75088 if (ext == 'B')
75089 sprint_backtrace(sym, value);
75090- else if (ext != 'f' && ext != 's')
75091+ else if (ext != 'f' && ext != 's' && ext != 'a')
75092 sprint_symbol(sym, value);
75093 else
75094 sprint_symbol_no_offset(sym, value);
75095@@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
75096 return number(buf, end, *(const netdev_features_t *)addr, spec);
75097 }
75098
75099+#ifdef CONFIG_GRKERNSEC_HIDESYM
75100+int kptr_restrict __read_mostly = 2;
75101+#else
75102 int kptr_restrict __read_mostly;
75103+#endif
75104
75105 /*
75106 * Show a '%p' thing. A kernel extension is that the '%p' is followed
75107@@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
75108 * - 'S' For symbolic direct pointers with offset
75109 * - 's' For symbolic direct pointers without offset
75110 * - 'B' For backtraced symbolic direct pointers with offset
75111+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
75112+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
75113 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
75114 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
75115 * - 'M' For a 6-byte MAC address, it prints the address in the
75116@@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75117
75118 if (!ptr && *fmt != 'K') {
75119 /*
75120- * Print (null) with the same width as a pointer so it makes
75121+ * Print (nil) with the same width as a pointer so it makes
75122 * tabular output look nice.
75123 */
75124 if (spec.field_width == -1)
75125 spec.field_width = default_width;
75126- return string(buf, end, "(null)", spec);
75127+ return string(buf, end, "(nil)", spec);
75128 }
75129
75130 switch (*fmt) {
75131@@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75132 /* Fallthrough */
75133 case 'S':
75134 case 's':
75135+#ifdef CONFIG_GRKERNSEC_HIDESYM
75136+ break;
75137+#else
75138+ return symbol_string(buf, end, ptr, spec, *fmt);
75139+#endif
75140+ case 'A':
75141+ case 'a':
75142 case 'B':
75143 return symbol_string(buf, end, ptr, spec, *fmt);
75144 case 'R':
75145@@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75146 va_end(va);
75147 return buf;
75148 }
75149+ case 'P':
75150+ break;
75151 case 'K':
75152 /*
75153 * %pK cannot be used in IRQ context because its test
75154@@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75155 }
75156 break;
75157 }
75158+
75159+#ifdef CONFIG_GRKERNSEC_HIDESYM
75160+ /* 'P' = approved pointers to copy to userland,
75161+ as in the /proc/kallsyms case, as we make it display nothing
75162+ for non-root users, and the real contents for root users
75163+ Also ignore 'K' pointers, since we force their NULLing for non-root users
75164+ above
75165+ */
75166+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
75167+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
75168+ dump_stack();
75169+ ptr = NULL;
75170+ }
75171+#endif
75172+
75173 spec.flags |= SMALL;
75174 if (spec.field_width == -1) {
75175 spec.field_width = default_width;
75176@@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75177 typeof(type) value; \
75178 if (sizeof(type) == 8) { \
75179 args = PTR_ALIGN(args, sizeof(u32)); \
75180- *(u32 *)&value = *(u32 *)args; \
75181- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
75182+ *(u32 *)&value = *(const u32 *)args; \
75183+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
75184 } else { \
75185 args = PTR_ALIGN(args, sizeof(type)); \
75186- value = *(typeof(type) *)args; \
75187+ value = *(const typeof(type) *)args; \
75188 } \
75189 args += sizeof(type); \
75190 value; \
75191@@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75192 case FORMAT_TYPE_STR: {
75193 const char *str_arg = args;
75194 args += strlen(str_arg) + 1;
75195- str = string(str, end, (char *)str_arg, spec);
75196+ str = string(str, end, str_arg, spec);
75197 break;
75198 }
75199
75200diff --git a/localversion-grsec b/localversion-grsec
75201new file mode 100644
75202index 0000000..7cd6065
75203--- /dev/null
75204+++ b/localversion-grsec
75205@@ -0,0 +1 @@
75206+-grsec
75207diff --git a/mm/Kconfig b/mm/Kconfig
75208index 278e3ab..87c384d 100644
75209--- a/mm/Kconfig
75210+++ b/mm/Kconfig
75211@@ -286,10 +286,10 @@ config KSM
75212 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
75213
75214 config DEFAULT_MMAP_MIN_ADDR
75215- int "Low address space to protect from user allocation"
75216+ int "Low address space to protect from user allocation"
75217 depends on MMU
75218- default 4096
75219- help
75220+ default 65536
75221+ help
75222 This is the portion of low virtual memory which should be protected
75223 from userspace allocation. Keeping a user from writing to low pages
75224 can help reduce the impact of kernel NULL pointer bugs.
75225@@ -320,7 +320,7 @@ config MEMORY_FAILURE
75226
75227 config HWPOISON_INJECT
75228 tristate "HWPoison pages injector"
75229- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
75230+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
75231 select PROC_PAGE_MONITOR
75232
75233 config NOMMU_INITIAL_TRIM_EXCESS
75234diff --git a/mm/filemap.c b/mm/filemap.c
75235index 83efee7..3f99381 100644
75236--- a/mm/filemap.c
75237+++ b/mm/filemap.c
75238@@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
75239 struct address_space *mapping = file->f_mapping;
75240
75241 if (!mapping->a_ops->readpage)
75242- return -ENOEXEC;
75243+ return -ENODEV;
75244 file_accessed(file);
75245 vma->vm_ops = &generic_file_vm_ops;
75246 return 0;
75247@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
75248 *pos = i_size_read(inode);
75249
75250 if (limit != RLIM_INFINITY) {
75251+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
75252 if (*pos >= limit) {
75253 send_sig(SIGXFSZ, current, 0);
75254 return -EFBIG;
75255diff --git a/mm/fremap.c b/mm/fremap.c
75256index a0aaf0e..20325c3 100644
75257--- a/mm/fremap.c
75258+++ b/mm/fremap.c
75259@@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
75260 retry:
75261 vma = find_vma(mm, start);
75262
75263+#ifdef CONFIG_PAX_SEGMEXEC
75264+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
75265+ goto out;
75266+#endif
75267+
75268 /*
75269 * Make sure the vma is shared, that it supports prefaulting,
75270 * and that the remapped range is valid and fully within
75271diff --git a/mm/highmem.c b/mm/highmem.c
75272index b32b70c..e512eb0 100644
75273--- a/mm/highmem.c
75274+++ b/mm/highmem.c
75275@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
75276 * So no dangers, even with speculative execution.
75277 */
75278 page = pte_page(pkmap_page_table[i]);
75279+ pax_open_kernel();
75280 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
75281-
75282+ pax_close_kernel();
75283 set_page_address(page, NULL);
75284 need_flush = 1;
75285 }
75286@@ -198,9 +199,11 @@ start:
75287 }
75288 }
75289 vaddr = PKMAP_ADDR(last_pkmap_nr);
75290+
75291+ pax_open_kernel();
75292 set_pte_at(&init_mm, vaddr,
75293 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
75294-
75295+ pax_close_kernel();
75296 pkmap_count[last_pkmap_nr] = 1;
75297 set_page_address(page, (void *)vaddr);
75298
75299diff --git a/mm/hugetlb.c b/mm/hugetlb.c
75300index 546db81..01d5c53 100644
75301--- a/mm/hugetlb.c
75302+++ b/mm/hugetlb.c
75303@@ -2511,6 +2511,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
75304 return 1;
75305 }
75306
75307+#ifdef CONFIG_PAX_SEGMEXEC
75308+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
75309+{
75310+ struct mm_struct *mm = vma->vm_mm;
75311+ struct vm_area_struct *vma_m;
75312+ unsigned long address_m;
75313+ pte_t *ptep_m;
75314+
75315+ vma_m = pax_find_mirror_vma(vma);
75316+ if (!vma_m)
75317+ return;
75318+
75319+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75320+ address_m = address + SEGMEXEC_TASK_SIZE;
75321+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
75322+ get_page(page_m);
75323+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
75324+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
75325+}
75326+#endif
75327+
75328 /*
75329 * Hugetlb_cow() should be called with page lock of the original hugepage held.
75330 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
75331@@ -2629,6 +2650,11 @@ retry_avoidcopy:
75332 make_huge_pte(vma, new_page, 1));
75333 page_remove_rmap(old_page);
75334 hugepage_add_new_anon_rmap(new_page, vma, address);
75335+
75336+#ifdef CONFIG_PAX_SEGMEXEC
75337+ pax_mirror_huge_pte(vma, address, new_page);
75338+#endif
75339+
75340 /* Make the old page be freed below */
75341 new_page = old_page;
75342 }
75343@@ -2788,6 +2814,10 @@ retry:
75344 && (vma->vm_flags & VM_SHARED)));
75345 set_huge_pte_at(mm, address, ptep, new_pte);
75346
75347+#ifdef CONFIG_PAX_SEGMEXEC
75348+ pax_mirror_huge_pte(vma, address, page);
75349+#endif
75350+
75351 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
75352 /* Optimization, do the COW without a second fault */
75353 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
75354@@ -2817,6 +2847,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75355 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
75356 struct hstate *h = hstate_vma(vma);
75357
75358+#ifdef CONFIG_PAX_SEGMEXEC
75359+ struct vm_area_struct *vma_m;
75360+#endif
75361+
75362 address &= huge_page_mask(h);
75363
75364 ptep = huge_pte_offset(mm, address);
75365@@ -2830,6 +2864,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75366 VM_FAULT_SET_HINDEX(hstate_index(h));
75367 }
75368
75369+#ifdef CONFIG_PAX_SEGMEXEC
75370+ vma_m = pax_find_mirror_vma(vma);
75371+ if (vma_m) {
75372+ unsigned long address_m;
75373+
75374+ if (vma->vm_start > vma_m->vm_start) {
75375+ address_m = address;
75376+ address -= SEGMEXEC_TASK_SIZE;
75377+ vma = vma_m;
75378+ h = hstate_vma(vma);
75379+ } else
75380+ address_m = address + SEGMEXEC_TASK_SIZE;
75381+
75382+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
75383+ return VM_FAULT_OOM;
75384+ address_m &= HPAGE_MASK;
75385+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
75386+ }
75387+#endif
75388+
75389 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
75390 if (!ptep)
75391 return VM_FAULT_OOM;
75392diff --git a/mm/internal.h b/mm/internal.h
75393index 9ba2110..eaf0674 100644
75394--- a/mm/internal.h
75395+++ b/mm/internal.h
75396@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
75397 * in mm/page_alloc.c
75398 */
75399 extern void __free_pages_bootmem(struct page *page, unsigned int order);
75400+extern void free_compound_page(struct page *page);
75401 extern void prep_compound_page(struct page *page, unsigned long order);
75402 #ifdef CONFIG_MEMORY_FAILURE
75403 extern bool is_free_buddy_page(struct page *page);
75404diff --git a/mm/kmemleak.c b/mm/kmemleak.c
75405index 752a705..6c3102e 100644
75406--- a/mm/kmemleak.c
75407+++ b/mm/kmemleak.c
75408@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
75409
75410 for (i = 0; i < object->trace_len; i++) {
75411 void *ptr = (void *)object->trace[i];
75412- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
75413+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
75414 }
75415 }
75416
75417@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
75418 return -ENOMEM;
75419 }
75420
75421- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
75422+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
75423 &kmemleak_fops);
75424 if (!dentry)
75425 pr_warning("Failed to create the debugfs kmemleak file\n");
75426diff --git a/mm/maccess.c b/mm/maccess.c
75427index d53adf9..03a24bf 100644
75428--- a/mm/maccess.c
75429+++ b/mm/maccess.c
75430@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
75431 set_fs(KERNEL_DS);
75432 pagefault_disable();
75433 ret = __copy_from_user_inatomic(dst,
75434- (__force const void __user *)src, size);
75435+ (const void __force_user *)src, size);
75436 pagefault_enable();
75437 set_fs(old_fs);
75438
75439@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
75440
75441 set_fs(KERNEL_DS);
75442 pagefault_disable();
75443- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
75444+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
75445 pagefault_enable();
75446 set_fs(old_fs);
75447
75448diff --git a/mm/madvise.c b/mm/madvise.c
75449index 03dfa5c..b032917 100644
75450--- a/mm/madvise.c
75451+++ b/mm/madvise.c
75452@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
75453 pgoff_t pgoff;
75454 unsigned long new_flags = vma->vm_flags;
75455
75456+#ifdef CONFIG_PAX_SEGMEXEC
75457+ struct vm_area_struct *vma_m;
75458+#endif
75459+
75460 switch (behavior) {
75461 case MADV_NORMAL:
75462 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
75463@@ -123,6 +127,13 @@ success:
75464 /*
75465 * vm_flags is protected by the mmap_sem held in write mode.
75466 */
75467+
75468+#ifdef CONFIG_PAX_SEGMEXEC
75469+ vma_m = pax_find_mirror_vma(vma);
75470+ if (vma_m)
75471+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
75472+#endif
75473+
75474 vma->vm_flags = new_flags;
75475
75476 out:
75477@@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75478 struct vm_area_struct ** prev,
75479 unsigned long start, unsigned long end)
75480 {
75481+
75482+#ifdef CONFIG_PAX_SEGMEXEC
75483+ struct vm_area_struct *vma_m;
75484+#endif
75485+
75486 *prev = vma;
75487 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
75488 return -EINVAL;
75489@@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75490 zap_page_range(vma, start, end - start, &details);
75491 } else
75492 zap_page_range(vma, start, end - start, NULL);
75493+
75494+#ifdef CONFIG_PAX_SEGMEXEC
75495+ vma_m = pax_find_mirror_vma(vma);
75496+ if (vma_m) {
75497+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
75498+ struct zap_details details = {
75499+ .nonlinear_vma = vma_m,
75500+ .last_index = ULONG_MAX,
75501+ };
75502+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
75503+ } else
75504+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
75505+ }
75506+#endif
75507+
75508 return 0;
75509 }
75510
75511@@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
75512 if (end < start)
75513 goto out;
75514
75515+#ifdef CONFIG_PAX_SEGMEXEC
75516+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
75517+ if (end > SEGMEXEC_TASK_SIZE)
75518+ goto out;
75519+ } else
75520+#endif
75521+
75522+ if (end > TASK_SIZE)
75523+ goto out;
75524+
75525 error = 0;
75526 if (end == start)
75527 goto out;
75528diff --git a/mm/memory-failure.c b/mm/memory-failure.c
75529index c6e4dd3..fdb2ca6 100644
75530--- a/mm/memory-failure.c
75531+++ b/mm/memory-failure.c
75532@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
75533
75534 int sysctl_memory_failure_recovery __read_mostly = 1;
75535
75536-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75537+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75538
75539 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
75540
75541@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
75542 pfn, t->comm, t->pid);
75543 si.si_signo = SIGBUS;
75544 si.si_errno = 0;
75545- si.si_addr = (void *)addr;
75546+ si.si_addr = (void __user *)addr;
75547 #ifdef __ARCH_SI_TRAPNO
75548 si.si_trapno = trapno;
75549 #endif
75550@@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75551 }
75552
75553 nr_pages = 1 << compound_trans_order(hpage);
75554- atomic_long_add(nr_pages, &mce_bad_pages);
75555+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
75556
75557 /*
75558 * We need/can do nothing about count=0 pages.
75559@@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75560 if (!PageHWPoison(hpage)
75561 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
75562 || (p != hpage && TestSetPageHWPoison(hpage))) {
75563- atomic_long_sub(nr_pages, &mce_bad_pages);
75564+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75565 return 0;
75566 }
75567 set_page_hwpoison_huge_page(hpage);
75568@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75569 }
75570 if (hwpoison_filter(p)) {
75571 if (TestClearPageHWPoison(p))
75572- atomic_long_sub(nr_pages, &mce_bad_pages);
75573+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75574 unlock_page(hpage);
75575 put_page(hpage);
75576 return 0;
75577@@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
75578 return 0;
75579 }
75580 if (TestClearPageHWPoison(p))
75581- atomic_long_sub(nr_pages, &mce_bad_pages);
75582+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75583 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
75584 return 0;
75585 }
75586@@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
75587 */
75588 if (TestClearPageHWPoison(page)) {
75589 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
75590- atomic_long_sub(nr_pages, &mce_bad_pages);
75591+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75592 freeit = 1;
75593 if (PageHuge(page))
75594 clear_page_hwpoison_huge_page(page);
75595@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
75596 }
75597 done:
75598 if (!PageHWPoison(hpage))
75599- atomic_long_add(1 << compound_trans_order(hpage),
75600+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
75601 &mce_bad_pages);
75602 set_page_hwpoison_huge_page(hpage);
75603 dequeue_hwpoisoned_huge_page(hpage);
75604@@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
75605 return ret;
75606
75607 done:
75608- atomic_long_add(1, &mce_bad_pages);
75609+ atomic_long_add_unchecked(1, &mce_bad_pages);
75610 SetPageHWPoison(page);
75611 /* keep elevated page count for bad page */
75612 return ret;
75613diff --git a/mm/memory.c b/mm/memory.c
75614index bb1369f..efb96b5 100644
75615--- a/mm/memory.c
75616+++ b/mm/memory.c
75617@@ -433,6 +433,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
75618 free_pte_range(tlb, pmd, addr);
75619 } while (pmd++, addr = next, addr != end);
75620
75621+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
75622 start &= PUD_MASK;
75623 if (start < floor)
75624 return;
75625@@ -447,6 +448,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
75626 pmd = pmd_offset(pud, start);
75627 pud_clear(pud);
75628 pmd_free_tlb(tlb, pmd, start);
75629+#endif
75630+
75631 }
75632
75633 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75634@@ -466,6 +469,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75635 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
75636 } while (pud++, addr = next, addr != end);
75637
75638+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
75639 start &= PGDIR_MASK;
75640 if (start < floor)
75641 return;
75642@@ -480,6 +484,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75643 pud = pud_offset(pgd, start);
75644 pgd_clear(pgd);
75645 pud_free_tlb(tlb, pud, start);
75646+#endif
75647+
75648 }
75649
75650 /*
75651@@ -1618,12 +1624,6 @@ no_page_table:
75652 return page;
75653 }
75654
75655-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
75656-{
75657- return stack_guard_page_start(vma, addr) ||
75658- stack_guard_page_end(vma, addr+PAGE_SIZE);
75659-}
75660-
75661 /**
75662 * __get_user_pages() - pin user pages in memory
75663 * @tsk: task_struct of target task
75664@@ -1709,10 +1709,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75665
75666 i = 0;
75667
75668- do {
75669+ while (nr_pages) {
75670 struct vm_area_struct *vma;
75671
75672- vma = find_extend_vma(mm, start);
75673+ vma = find_vma(mm, start);
75674 if (!vma && in_gate_area(mm, start)) {
75675 unsigned long pg = start & PAGE_MASK;
75676 pgd_t *pgd;
75677@@ -1760,7 +1760,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75678 goto next_page;
75679 }
75680
75681- if (!vma ||
75682+ if (!vma || start < vma->vm_start ||
75683 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
75684 !(vm_flags & vma->vm_flags))
75685 return i ? : -EFAULT;
75686@@ -1787,11 +1787,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75687 int ret;
75688 unsigned int fault_flags = 0;
75689
75690- /* For mlock, just skip the stack guard page. */
75691- if (foll_flags & FOLL_MLOCK) {
75692- if (stack_guard_page(vma, start))
75693- goto next_page;
75694- }
75695 if (foll_flags & FOLL_WRITE)
75696 fault_flags |= FAULT_FLAG_WRITE;
75697 if (nonblocking)
75698@@ -1865,7 +1860,7 @@ next_page:
75699 start += PAGE_SIZE;
75700 nr_pages--;
75701 } while (nr_pages && start < vma->vm_end);
75702- } while (nr_pages);
75703+ }
75704 return i;
75705 }
75706 EXPORT_SYMBOL(__get_user_pages);
75707@@ -2072,6 +2067,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
75708 page_add_file_rmap(page);
75709 set_pte_at(mm, addr, pte, mk_pte(page, prot));
75710
75711+#ifdef CONFIG_PAX_SEGMEXEC
75712+ pax_mirror_file_pte(vma, addr, page, ptl);
75713+#endif
75714+
75715 retval = 0;
75716 pte_unmap_unlock(pte, ptl);
75717 return retval;
75718@@ -2116,9 +2115,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
75719 if (!page_count(page))
75720 return -EINVAL;
75721 if (!(vma->vm_flags & VM_MIXEDMAP)) {
75722+
75723+#ifdef CONFIG_PAX_SEGMEXEC
75724+ struct vm_area_struct *vma_m;
75725+#endif
75726+
75727 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
75728 BUG_ON(vma->vm_flags & VM_PFNMAP);
75729 vma->vm_flags |= VM_MIXEDMAP;
75730+
75731+#ifdef CONFIG_PAX_SEGMEXEC
75732+ vma_m = pax_find_mirror_vma(vma);
75733+ if (vma_m)
75734+ vma_m->vm_flags |= VM_MIXEDMAP;
75735+#endif
75736+
75737 }
75738 return insert_page(vma, addr, page, vma->vm_page_prot);
75739 }
75740@@ -2201,6 +2212,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
75741 unsigned long pfn)
75742 {
75743 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
75744+ BUG_ON(vma->vm_mirror);
75745
75746 if (addr < vma->vm_start || addr >= vma->vm_end)
75747 return -EFAULT;
75748@@ -2401,7 +2413,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
75749
75750 BUG_ON(pud_huge(*pud));
75751
75752- pmd = pmd_alloc(mm, pud, addr);
75753+ pmd = (mm == &init_mm) ?
75754+ pmd_alloc_kernel(mm, pud, addr) :
75755+ pmd_alloc(mm, pud, addr);
75756 if (!pmd)
75757 return -ENOMEM;
75758 do {
75759@@ -2421,7 +2435,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
75760 unsigned long next;
75761 int err;
75762
75763- pud = pud_alloc(mm, pgd, addr);
75764+ pud = (mm == &init_mm) ?
75765+ pud_alloc_kernel(mm, pgd, addr) :
75766+ pud_alloc(mm, pgd, addr);
75767 if (!pud)
75768 return -ENOMEM;
75769 do {
75770@@ -2509,6 +2525,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
75771 copy_user_highpage(dst, src, va, vma);
75772 }
75773
75774+#ifdef CONFIG_PAX_SEGMEXEC
75775+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
75776+{
75777+ struct mm_struct *mm = vma->vm_mm;
75778+ spinlock_t *ptl;
75779+ pte_t *pte, entry;
75780+
75781+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
75782+ entry = *pte;
75783+ if (!pte_present(entry)) {
75784+ if (!pte_none(entry)) {
75785+ BUG_ON(pte_file(entry));
75786+ free_swap_and_cache(pte_to_swp_entry(entry));
75787+ pte_clear_not_present_full(mm, address, pte, 0);
75788+ }
75789+ } else {
75790+ struct page *page;
75791+
75792+ flush_cache_page(vma, address, pte_pfn(entry));
75793+ entry = ptep_clear_flush(vma, address, pte);
75794+ BUG_ON(pte_dirty(entry));
75795+ page = vm_normal_page(vma, address, entry);
75796+ if (page) {
75797+ update_hiwater_rss(mm);
75798+ if (PageAnon(page))
75799+ dec_mm_counter_fast(mm, MM_ANONPAGES);
75800+ else
75801+ dec_mm_counter_fast(mm, MM_FILEPAGES);
75802+ page_remove_rmap(page);
75803+ page_cache_release(page);
75804+ }
75805+ }
75806+ pte_unmap_unlock(pte, ptl);
75807+}
75808+
75809+/* PaX: if vma is mirrored, synchronize the mirror's PTE
75810+ *
75811+ * the ptl of the lower mapped page is held on entry and is not released on exit
75812+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
75813+ */
75814+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
75815+{
75816+ struct mm_struct *mm = vma->vm_mm;
75817+ unsigned long address_m;
75818+ spinlock_t *ptl_m;
75819+ struct vm_area_struct *vma_m;
75820+ pmd_t *pmd_m;
75821+ pte_t *pte_m, entry_m;
75822+
75823+ BUG_ON(!page_m || !PageAnon(page_m));
75824+
75825+ vma_m = pax_find_mirror_vma(vma);
75826+ if (!vma_m)
75827+ return;
75828+
75829+ BUG_ON(!PageLocked(page_m));
75830+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75831+ address_m = address + SEGMEXEC_TASK_SIZE;
75832+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75833+ pte_m = pte_offset_map(pmd_m, address_m);
75834+ ptl_m = pte_lockptr(mm, pmd_m);
75835+ if (ptl != ptl_m) {
75836+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75837+ if (!pte_none(*pte_m))
75838+ goto out;
75839+ }
75840+
75841+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
75842+ page_cache_get(page_m);
75843+ page_add_anon_rmap(page_m, vma_m, address_m);
75844+ inc_mm_counter_fast(mm, MM_ANONPAGES);
75845+ set_pte_at(mm, address_m, pte_m, entry_m);
75846+ update_mmu_cache(vma_m, address_m, entry_m);
75847+out:
75848+ if (ptl != ptl_m)
75849+ spin_unlock(ptl_m);
75850+ pte_unmap(pte_m);
75851+ unlock_page(page_m);
75852+}
75853+
75854+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
75855+{
75856+ struct mm_struct *mm = vma->vm_mm;
75857+ unsigned long address_m;
75858+ spinlock_t *ptl_m;
75859+ struct vm_area_struct *vma_m;
75860+ pmd_t *pmd_m;
75861+ pte_t *pte_m, entry_m;
75862+
75863+ BUG_ON(!page_m || PageAnon(page_m));
75864+
75865+ vma_m = pax_find_mirror_vma(vma);
75866+ if (!vma_m)
75867+ return;
75868+
75869+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75870+ address_m = address + SEGMEXEC_TASK_SIZE;
75871+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75872+ pte_m = pte_offset_map(pmd_m, address_m);
75873+ ptl_m = pte_lockptr(mm, pmd_m);
75874+ if (ptl != ptl_m) {
75875+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75876+ if (!pte_none(*pte_m))
75877+ goto out;
75878+ }
75879+
75880+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
75881+ page_cache_get(page_m);
75882+ page_add_file_rmap(page_m);
75883+ inc_mm_counter_fast(mm, MM_FILEPAGES);
75884+ set_pte_at(mm, address_m, pte_m, entry_m);
75885+ update_mmu_cache(vma_m, address_m, entry_m);
75886+out:
75887+ if (ptl != ptl_m)
75888+ spin_unlock(ptl_m);
75889+ pte_unmap(pte_m);
75890+}
75891+
75892+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
75893+{
75894+ struct mm_struct *mm = vma->vm_mm;
75895+ unsigned long address_m;
75896+ spinlock_t *ptl_m;
75897+ struct vm_area_struct *vma_m;
75898+ pmd_t *pmd_m;
75899+ pte_t *pte_m, entry_m;
75900+
75901+ vma_m = pax_find_mirror_vma(vma);
75902+ if (!vma_m)
75903+ return;
75904+
75905+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75906+ address_m = address + SEGMEXEC_TASK_SIZE;
75907+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75908+ pte_m = pte_offset_map(pmd_m, address_m);
75909+ ptl_m = pte_lockptr(mm, pmd_m);
75910+ if (ptl != ptl_m) {
75911+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75912+ if (!pte_none(*pte_m))
75913+ goto out;
75914+ }
75915+
75916+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
75917+ set_pte_at(mm, address_m, pte_m, entry_m);
75918+out:
75919+ if (ptl != ptl_m)
75920+ spin_unlock(ptl_m);
75921+ pte_unmap(pte_m);
75922+}
75923+
75924+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
75925+{
75926+ struct page *page_m;
75927+ pte_t entry;
75928+
75929+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
75930+ goto out;
75931+
75932+ entry = *pte;
75933+ page_m = vm_normal_page(vma, address, entry);
75934+ if (!page_m)
75935+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
75936+ else if (PageAnon(page_m)) {
75937+ if (pax_find_mirror_vma(vma)) {
75938+ pte_unmap_unlock(pte, ptl);
75939+ lock_page(page_m);
75940+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
75941+ if (pte_same(entry, *pte))
75942+ pax_mirror_anon_pte(vma, address, page_m, ptl);
75943+ else
75944+ unlock_page(page_m);
75945+ }
75946+ } else
75947+ pax_mirror_file_pte(vma, address, page_m, ptl);
75948+
75949+out:
75950+ pte_unmap_unlock(pte, ptl);
75951+}
75952+#endif
75953+
75954 /*
75955 * This routine handles present pages, when users try to write
75956 * to a shared page. It is done by copying the page to a new address
75957@@ -2725,6 +2921,12 @@ gotten:
75958 */
75959 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
75960 if (likely(pte_same(*page_table, orig_pte))) {
75961+
75962+#ifdef CONFIG_PAX_SEGMEXEC
75963+ if (pax_find_mirror_vma(vma))
75964+ BUG_ON(!trylock_page(new_page));
75965+#endif
75966+
75967 if (old_page) {
75968 if (!PageAnon(old_page)) {
75969 dec_mm_counter_fast(mm, MM_FILEPAGES);
75970@@ -2776,6 +2978,10 @@ gotten:
75971 page_remove_rmap(old_page);
75972 }
75973
75974+#ifdef CONFIG_PAX_SEGMEXEC
75975+ pax_mirror_anon_pte(vma, address, new_page, ptl);
75976+#endif
75977+
75978 /* Free the old page.. */
75979 new_page = old_page;
75980 ret |= VM_FAULT_WRITE;
75981@@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
75982 swap_free(entry);
75983 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
75984 try_to_free_swap(page);
75985+
75986+#ifdef CONFIG_PAX_SEGMEXEC
75987+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
75988+#endif
75989+
75990 unlock_page(page);
75991 if (swapcache) {
75992 /*
75993@@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
75994
75995 /* No need to invalidate - it was non-present before */
75996 update_mmu_cache(vma, address, page_table);
75997+
75998+#ifdef CONFIG_PAX_SEGMEXEC
75999+ pax_mirror_anon_pte(vma, address, page, ptl);
76000+#endif
76001+
76002 unlock:
76003 pte_unmap_unlock(page_table, ptl);
76004 out:
76005@@ -3093,40 +3309,6 @@ out_release:
76006 }
76007
76008 /*
76009- * This is like a special single-page "expand_{down|up}wards()",
76010- * except we must first make sure that 'address{-|+}PAGE_SIZE'
76011- * doesn't hit another vma.
76012- */
76013-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
76014-{
76015- address &= PAGE_MASK;
76016- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
76017- struct vm_area_struct *prev = vma->vm_prev;
76018-
76019- /*
76020- * Is there a mapping abutting this one below?
76021- *
76022- * That's only ok if it's the same stack mapping
76023- * that has gotten split..
76024- */
76025- if (prev && prev->vm_end == address)
76026- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
76027-
76028- expand_downwards(vma, address - PAGE_SIZE);
76029- }
76030- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
76031- struct vm_area_struct *next = vma->vm_next;
76032-
76033- /* As VM_GROWSDOWN but s/below/above/ */
76034- if (next && next->vm_start == address + PAGE_SIZE)
76035- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
76036-
76037- expand_upwards(vma, address + PAGE_SIZE);
76038- }
76039- return 0;
76040-}
76041-
76042-/*
76043 * We enter with non-exclusive mmap_sem (to exclude vma changes,
76044 * but allow concurrent faults), and pte mapped but not yet locked.
76045 * We return with mmap_sem still held, but pte unmapped and unlocked.
76046@@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
76047 unsigned long address, pte_t *page_table, pmd_t *pmd,
76048 unsigned int flags)
76049 {
76050- struct page *page;
76051+ struct page *page = NULL;
76052 spinlock_t *ptl;
76053 pte_t entry;
76054
76055- pte_unmap(page_table);
76056-
76057- /* Check if we need to add a guard page to the stack */
76058- if (check_stack_guard_page(vma, address) < 0)
76059- return VM_FAULT_SIGBUS;
76060-
76061- /* Use the zero-page for reads */
76062 if (!(flags & FAULT_FLAG_WRITE)) {
76063 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
76064 vma->vm_page_prot));
76065- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
76066+ ptl = pte_lockptr(mm, pmd);
76067+ spin_lock(ptl);
76068 if (!pte_none(*page_table))
76069 goto unlock;
76070 goto setpte;
76071 }
76072
76073 /* Allocate our own private page. */
76074+ pte_unmap(page_table);
76075+
76076 if (unlikely(anon_vma_prepare(vma)))
76077 goto oom;
76078 page = alloc_zeroed_user_highpage_movable(vma, address);
76079@@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
76080 if (!pte_none(*page_table))
76081 goto release;
76082
76083+#ifdef CONFIG_PAX_SEGMEXEC
76084+ if (pax_find_mirror_vma(vma))
76085+ BUG_ON(!trylock_page(page));
76086+#endif
76087+
76088 inc_mm_counter_fast(mm, MM_ANONPAGES);
76089 page_add_new_anon_rmap(page, vma, address);
76090 setpte:
76091@@ -3181,6 +3364,12 @@ setpte:
76092
76093 /* No need to invalidate - it was non-present before */
76094 update_mmu_cache(vma, address, page_table);
76095+
76096+#ifdef CONFIG_PAX_SEGMEXEC
76097+ if (page)
76098+ pax_mirror_anon_pte(vma, address, page, ptl);
76099+#endif
76100+
76101 unlock:
76102 pte_unmap_unlock(page_table, ptl);
76103 return 0;
76104@@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76105 */
76106 /* Only go through if we didn't race with anybody else... */
76107 if (likely(pte_same(*page_table, orig_pte))) {
76108+
76109+#ifdef CONFIG_PAX_SEGMEXEC
76110+ if (anon && pax_find_mirror_vma(vma))
76111+ BUG_ON(!trylock_page(page));
76112+#endif
76113+
76114 flush_icache_page(vma, page);
76115 entry = mk_pte(page, vma->vm_page_prot);
76116 if (flags & FAULT_FLAG_WRITE)
76117@@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76118
76119 /* no need to invalidate: a not-present page won't be cached */
76120 update_mmu_cache(vma, address, page_table);
76121+
76122+#ifdef CONFIG_PAX_SEGMEXEC
76123+ if (anon)
76124+ pax_mirror_anon_pte(vma, address, page, ptl);
76125+ else
76126+ pax_mirror_file_pte(vma, address, page, ptl);
76127+#endif
76128+
76129 } else {
76130 if (cow_page)
76131 mem_cgroup_uncharge_page(cow_page);
76132@@ -3664,6 +3867,12 @@ int handle_pte_fault(struct mm_struct *mm,
76133 if (flags & FAULT_FLAG_WRITE)
76134 flush_tlb_fix_spurious_fault(vma, address);
76135 }
76136+
76137+#ifdef CONFIG_PAX_SEGMEXEC
76138+ pax_mirror_pte(vma, address, pte, pmd, ptl);
76139+ return 0;
76140+#endif
76141+
76142 unlock:
76143 pte_unmap_unlock(pte, ptl);
76144 return 0;
76145@@ -3680,6 +3889,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76146 pmd_t *pmd;
76147 pte_t *pte;
76148
76149+#ifdef CONFIG_PAX_SEGMEXEC
76150+ struct vm_area_struct *vma_m;
76151+#endif
76152+
76153 __set_current_state(TASK_RUNNING);
76154
76155 count_vm_event(PGFAULT);
76156@@ -3691,6 +3904,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76157 if (unlikely(is_vm_hugetlb_page(vma)))
76158 return hugetlb_fault(mm, vma, address, flags);
76159
76160+#ifdef CONFIG_PAX_SEGMEXEC
76161+ vma_m = pax_find_mirror_vma(vma);
76162+ if (vma_m) {
76163+ unsigned long address_m;
76164+ pgd_t *pgd_m;
76165+ pud_t *pud_m;
76166+ pmd_t *pmd_m;
76167+
76168+ if (vma->vm_start > vma_m->vm_start) {
76169+ address_m = address;
76170+ address -= SEGMEXEC_TASK_SIZE;
76171+ vma = vma_m;
76172+ } else
76173+ address_m = address + SEGMEXEC_TASK_SIZE;
76174+
76175+ pgd_m = pgd_offset(mm, address_m);
76176+ pud_m = pud_alloc(mm, pgd_m, address_m);
76177+ if (!pud_m)
76178+ return VM_FAULT_OOM;
76179+ pmd_m = pmd_alloc(mm, pud_m, address_m);
76180+ if (!pmd_m)
76181+ return VM_FAULT_OOM;
76182+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
76183+ return VM_FAULT_OOM;
76184+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
76185+ }
76186+#endif
76187+
76188 retry:
76189 pgd = pgd_offset(mm, address);
76190 pud = pud_alloc(mm, pgd, address);
76191@@ -3789,6 +4030,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
76192 spin_unlock(&mm->page_table_lock);
76193 return 0;
76194 }
76195+
76196+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
76197+{
76198+ pud_t *new = pud_alloc_one(mm, address);
76199+ if (!new)
76200+ return -ENOMEM;
76201+
76202+ smp_wmb(); /* See comment in __pte_alloc */
76203+
76204+ spin_lock(&mm->page_table_lock);
76205+ if (pgd_present(*pgd)) /* Another has populated it */
76206+ pud_free(mm, new);
76207+ else
76208+ pgd_populate_kernel(mm, pgd, new);
76209+ spin_unlock(&mm->page_table_lock);
76210+ return 0;
76211+}
76212 #endif /* __PAGETABLE_PUD_FOLDED */
76213
76214 #ifndef __PAGETABLE_PMD_FOLDED
76215@@ -3819,6 +4077,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
76216 spin_unlock(&mm->page_table_lock);
76217 return 0;
76218 }
76219+
76220+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
76221+{
76222+ pmd_t *new = pmd_alloc_one(mm, address);
76223+ if (!new)
76224+ return -ENOMEM;
76225+
76226+ smp_wmb(); /* See comment in __pte_alloc */
76227+
76228+ spin_lock(&mm->page_table_lock);
76229+#ifndef __ARCH_HAS_4LEVEL_HACK
76230+ if (pud_present(*pud)) /* Another has populated it */
76231+ pmd_free(mm, new);
76232+ else
76233+ pud_populate_kernel(mm, pud, new);
76234+#else
76235+ if (pgd_present(*pud)) /* Another has populated it */
76236+ pmd_free(mm, new);
76237+ else
76238+ pgd_populate_kernel(mm, pud, new);
76239+#endif /* __ARCH_HAS_4LEVEL_HACK */
76240+ spin_unlock(&mm->page_table_lock);
76241+ return 0;
76242+}
76243 #endif /* __PAGETABLE_PMD_FOLDED */
76244
76245 int make_pages_present(unsigned long addr, unsigned long end)
76246@@ -3856,7 +4138,7 @@ static int __init gate_vma_init(void)
76247 gate_vma.vm_start = FIXADDR_USER_START;
76248 gate_vma.vm_end = FIXADDR_USER_END;
76249 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
76250- gate_vma.vm_page_prot = __P101;
76251+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
76252
76253 return 0;
76254 }
76255diff --git a/mm/mempolicy.c b/mm/mempolicy.c
76256index e2df1c1..1e31d57 100644
76257--- a/mm/mempolicy.c
76258+++ b/mm/mempolicy.c
76259@@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
76260 unsigned long vmstart;
76261 unsigned long vmend;
76262
76263+#ifdef CONFIG_PAX_SEGMEXEC
76264+ struct vm_area_struct *vma_m;
76265+#endif
76266+
76267 vma = find_vma(mm, start);
76268 if (!vma || vma->vm_start > start)
76269 return -EFAULT;
76270@@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
76271 if (err)
76272 goto out;
76273 }
76274+
76275 err = vma_replace_policy(vma, new_pol);
76276 if (err)
76277 goto out;
76278+
76279+#ifdef CONFIG_PAX_SEGMEXEC
76280+ vma_m = pax_find_mirror_vma(vma);
76281+ if (vma_m) {
76282+ err = vma_replace_policy(vma_m, new_pol);
76283+ if (err)
76284+ goto out;
76285+ }
76286+#endif
76287+
76288 }
76289
76290 out:
76291@@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
76292
76293 if (end < start)
76294 return -EINVAL;
76295+
76296+#ifdef CONFIG_PAX_SEGMEXEC
76297+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
76298+ if (end > SEGMEXEC_TASK_SIZE)
76299+ return -EINVAL;
76300+ } else
76301+#endif
76302+
76303+ if (end > TASK_SIZE)
76304+ return -EINVAL;
76305+
76306 if (end == start)
76307 return 0;
76308
76309@@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76310 */
76311 tcred = __task_cred(task);
76312 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
76313- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
76314- !capable(CAP_SYS_NICE)) {
76315+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
76316 rcu_read_unlock();
76317 err = -EPERM;
76318 goto out_put;
76319@@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76320 goto out;
76321 }
76322
76323+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76324+ if (mm != current->mm &&
76325+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
76326+ mmput(mm);
76327+ err = -EPERM;
76328+ goto out;
76329+ }
76330+#endif
76331+
76332 err = do_migrate_pages(mm, old, new,
76333 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
76334
76335diff --git a/mm/migrate.c b/mm/migrate.c
76336index 2fd8b4a..d70358f 100644
76337--- a/mm/migrate.c
76338+++ b/mm/migrate.c
76339@@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
76340 */
76341 tcred = __task_cred(task);
76342 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
76343- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
76344- !capable(CAP_SYS_NICE)) {
76345+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
76346 rcu_read_unlock();
76347 err = -EPERM;
76348 goto out;
76349diff --git a/mm/mlock.c b/mm/mlock.c
76350index c9bd528..da8d069 100644
76351--- a/mm/mlock.c
76352+++ b/mm/mlock.c
76353@@ -13,6 +13,7 @@
76354 #include <linux/pagemap.h>
76355 #include <linux/mempolicy.h>
76356 #include <linux/syscalls.h>
76357+#include <linux/security.h>
76358 #include <linux/sched.h>
76359 #include <linux/export.h>
76360 #include <linux/rmap.h>
76361@@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
76362 {
76363 unsigned long nstart, end, tmp;
76364 struct vm_area_struct * vma, * prev;
76365- int error;
76366+ int error = 0;
76367
76368 VM_BUG_ON(start & ~PAGE_MASK);
76369 VM_BUG_ON(len != PAGE_ALIGN(len));
76370@@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
76371 return -EINVAL;
76372 if (end == start)
76373 return 0;
76374+ if (end > TASK_SIZE)
76375+ return -EINVAL;
76376+
76377 vma = find_vma(current->mm, start);
76378 if (!vma || vma->vm_start > start)
76379 return -ENOMEM;
76380@@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
76381 for (nstart = start ; ; ) {
76382 vm_flags_t newflags;
76383
76384+#ifdef CONFIG_PAX_SEGMEXEC
76385+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76386+ break;
76387+#endif
76388+
76389 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
76390
76391 newflags = vma->vm_flags | VM_LOCKED;
76392@@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
76393 lock_limit >>= PAGE_SHIFT;
76394
76395 /* check against resource limits */
76396+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
76397 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
76398 error = do_mlock(start, len, 1);
76399 up_write(&current->mm->mmap_sem);
76400@@ -528,6 +538,12 @@ static int do_mlockall(int flags)
76401 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
76402 vm_flags_t newflags;
76403
76404+#ifdef CONFIG_PAX_SEGMEXEC
76405+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76406+ break;
76407+#endif
76408+
76409+ BUG_ON(vma->vm_end > TASK_SIZE);
76410 newflags = vma->vm_flags | VM_LOCKED;
76411 if (!(flags & MCL_CURRENT))
76412 newflags &= ~VM_LOCKED;
76413@@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
76414 lock_limit >>= PAGE_SHIFT;
76415
76416 ret = -ENOMEM;
76417+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
76418 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
76419 capable(CAP_IPC_LOCK))
76420 ret = do_mlockall(flags);
76421diff --git a/mm/mmap.c b/mm/mmap.c
76422index d1e4124..32a6988 100644
76423--- a/mm/mmap.c
76424+++ b/mm/mmap.c
76425@@ -32,6 +32,7 @@
76426 #include <linux/khugepaged.h>
76427 #include <linux/uprobes.h>
76428 #include <linux/rbtree_augmented.h>
76429+#include <linux/random.h>
76430
76431 #include <asm/uaccess.h>
76432 #include <asm/cacheflush.h>
76433@@ -48,6 +49,16 @@
76434 #define arch_rebalance_pgtables(addr, len) (addr)
76435 #endif
76436
76437+static inline void verify_mm_writelocked(struct mm_struct *mm)
76438+{
76439+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
76440+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76441+ up_read(&mm->mmap_sem);
76442+ BUG();
76443+ }
76444+#endif
76445+}
76446+
76447 static void unmap_region(struct mm_struct *mm,
76448 struct vm_area_struct *vma, struct vm_area_struct *prev,
76449 unsigned long start, unsigned long end);
76450@@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
76451 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
76452 *
76453 */
76454-pgprot_t protection_map[16] = {
76455+pgprot_t protection_map[16] __read_only = {
76456 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
76457 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
76458 };
76459
76460-pgprot_t vm_get_page_prot(unsigned long vm_flags)
76461+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
76462 {
76463- return __pgprot(pgprot_val(protection_map[vm_flags &
76464+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
76465 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
76466 pgprot_val(arch_vm_get_page_prot(vm_flags)));
76467+
76468+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76469+ if (!(__supported_pte_mask & _PAGE_NX) &&
76470+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
76471+ (vm_flags & (VM_READ | VM_WRITE)))
76472+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
76473+#endif
76474+
76475+ return prot;
76476 }
76477 EXPORT_SYMBOL(vm_get_page_prot);
76478
76479 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
76480 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
76481 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
76482+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
76483 /*
76484 * Make sure vm_committed_as in one cacheline and not cacheline shared with
76485 * other variables. It can be updated by several CPUs frequently.
76486@@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
76487 struct vm_area_struct *next = vma->vm_next;
76488
76489 might_sleep();
76490+ BUG_ON(vma->vm_mirror);
76491 if (vma->vm_ops && vma->vm_ops->close)
76492 vma->vm_ops->close(vma);
76493 if (vma->vm_file)
76494@@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
76495 * not page aligned -Ram Gupta
76496 */
76497 rlim = rlimit(RLIMIT_DATA);
76498+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
76499 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
76500 (mm->end_data - mm->start_data) > rlim)
76501 goto out;
76502@@ -888,6 +911,12 @@ static int
76503 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
76504 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76505 {
76506+
76507+#ifdef CONFIG_PAX_SEGMEXEC
76508+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
76509+ return 0;
76510+#endif
76511+
76512 if (is_mergeable_vma(vma, file, vm_flags) &&
76513 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
76514 if (vma->vm_pgoff == vm_pgoff)
76515@@ -907,6 +936,12 @@ static int
76516 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76517 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76518 {
76519+
76520+#ifdef CONFIG_PAX_SEGMEXEC
76521+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
76522+ return 0;
76523+#endif
76524+
76525 if (is_mergeable_vma(vma, file, vm_flags) &&
76526 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
76527 pgoff_t vm_pglen;
76528@@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76529 struct vm_area_struct *vma_merge(struct mm_struct *mm,
76530 struct vm_area_struct *prev, unsigned long addr,
76531 unsigned long end, unsigned long vm_flags,
76532- struct anon_vma *anon_vma, struct file *file,
76533+ struct anon_vma *anon_vma, struct file *file,
76534 pgoff_t pgoff, struct mempolicy *policy)
76535 {
76536 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
76537 struct vm_area_struct *area, *next;
76538 int err;
76539
76540+#ifdef CONFIG_PAX_SEGMEXEC
76541+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
76542+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
76543+
76544+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
76545+#endif
76546+
76547 /*
76548 * We later require that vma->vm_flags == vm_flags,
76549 * so this tests vma->vm_flags & VM_SPECIAL, too.
76550@@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76551 if (next && next->vm_end == end) /* cases 6, 7, 8 */
76552 next = next->vm_next;
76553
76554+#ifdef CONFIG_PAX_SEGMEXEC
76555+ if (prev)
76556+ prev_m = pax_find_mirror_vma(prev);
76557+ if (area)
76558+ area_m = pax_find_mirror_vma(area);
76559+ if (next)
76560+ next_m = pax_find_mirror_vma(next);
76561+#endif
76562+
76563 /*
76564 * Can it merge with the predecessor?
76565 */
76566@@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76567 /* cases 1, 6 */
76568 err = vma_adjust(prev, prev->vm_start,
76569 next->vm_end, prev->vm_pgoff, NULL);
76570- } else /* cases 2, 5, 7 */
76571+
76572+#ifdef CONFIG_PAX_SEGMEXEC
76573+ if (!err && prev_m)
76574+ err = vma_adjust(prev_m, prev_m->vm_start,
76575+ next_m->vm_end, prev_m->vm_pgoff, NULL);
76576+#endif
76577+
76578+ } else { /* cases 2, 5, 7 */
76579 err = vma_adjust(prev, prev->vm_start,
76580 end, prev->vm_pgoff, NULL);
76581+
76582+#ifdef CONFIG_PAX_SEGMEXEC
76583+ if (!err && prev_m)
76584+ err = vma_adjust(prev_m, prev_m->vm_start,
76585+ end_m, prev_m->vm_pgoff, NULL);
76586+#endif
76587+
76588+ }
76589 if (err)
76590 return NULL;
76591 khugepaged_enter_vma_merge(prev);
76592@@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76593 mpol_equal(policy, vma_policy(next)) &&
76594 can_vma_merge_before(next, vm_flags,
76595 anon_vma, file, pgoff+pglen)) {
76596- if (prev && addr < prev->vm_end) /* case 4 */
76597+ if (prev && addr < prev->vm_end) { /* case 4 */
76598 err = vma_adjust(prev, prev->vm_start,
76599 addr, prev->vm_pgoff, NULL);
76600- else /* cases 3, 8 */
76601+
76602+#ifdef CONFIG_PAX_SEGMEXEC
76603+ if (!err && prev_m)
76604+ err = vma_adjust(prev_m, prev_m->vm_start,
76605+ addr_m, prev_m->vm_pgoff, NULL);
76606+#endif
76607+
76608+ } else { /* cases 3, 8 */
76609 err = vma_adjust(area, addr, next->vm_end,
76610 next->vm_pgoff - pglen, NULL);
76611+
76612+#ifdef CONFIG_PAX_SEGMEXEC
76613+ if (!err && area_m)
76614+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
76615+ next_m->vm_pgoff - pglen, NULL);
76616+#endif
76617+
76618+ }
76619 if (err)
76620 return NULL;
76621 khugepaged_enter_vma_merge(area);
76622@@ -1120,16 +1201,13 @@ none:
76623 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
76624 struct file *file, long pages)
76625 {
76626- const unsigned long stack_flags
76627- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
76628-
76629 mm->total_vm += pages;
76630
76631 if (file) {
76632 mm->shared_vm += pages;
76633 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
76634 mm->exec_vm += pages;
76635- } else if (flags & stack_flags)
76636+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
76637 mm->stack_vm += pages;
76638 }
76639 #endif /* CONFIG_PROC_FS */
76640@@ -1165,7 +1243,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76641 * (the exception is when the underlying filesystem is noexec
76642 * mounted, in which case we dont add PROT_EXEC.)
76643 */
76644- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
76645+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
76646 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
76647 prot |= PROT_EXEC;
76648
76649@@ -1191,7 +1269,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76650 /* Obtain the address to map to. we verify (or select) it and ensure
76651 * that it represents a valid section of the address space.
76652 */
76653- addr = get_unmapped_area(file, addr, len, pgoff, flags);
76654+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
76655 if (addr & ~PAGE_MASK)
76656 return addr;
76657
76658@@ -1202,6 +1280,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76659 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
76660 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
76661
76662+#ifdef CONFIG_PAX_MPROTECT
76663+ if (mm->pax_flags & MF_PAX_MPROTECT) {
76664+#ifndef CONFIG_PAX_MPROTECT_COMPAT
76665+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
76666+ gr_log_rwxmmap(file);
76667+
76668+#ifdef CONFIG_PAX_EMUPLT
76669+ vm_flags &= ~VM_EXEC;
76670+#else
76671+ return -EPERM;
76672+#endif
76673+
76674+ }
76675+
76676+ if (!(vm_flags & VM_EXEC))
76677+ vm_flags &= ~VM_MAYEXEC;
76678+#else
76679+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
76680+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
76681+#endif
76682+ else
76683+ vm_flags &= ~VM_MAYWRITE;
76684+ }
76685+#endif
76686+
76687+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76688+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
76689+ vm_flags &= ~VM_PAGEEXEC;
76690+#endif
76691+
76692 if (flags & MAP_LOCKED)
76693 if (!can_do_mlock())
76694 return -EPERM;
76695@@ -1213,6 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76696 locked += mm->locked_vm;
76697 lock_limit = rlimit(RLIMIT_MEMLOCK);
76698 lock_limit >>= PAGE_SHIFT;
76699+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
76700 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
76701 return -EAGAIN;
76702 }
76703@@ -1279,6 +1388,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76704 }
76705 }
76706
76707+ if (!gr_acl_handle_mmap(file, prot))
76708+ return -EACCES;
76709+
76710 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
76711 }
76712
76713@@ -1356,7 +1468,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
76714 vm_flags_t vm_flags = vma->vm_flags;
76715
76716 /* If it was private or non-writable, the write bit is already clear */
76717- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
76718+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
76719 return 0;
76720
76721 /* The backer wishes to know when pages are first written to? */
76722@@ -1405,13 +1517,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
76723 unsigned long charged = 0;
76724 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
76725
76726+#ifdef CONFIG_PAX_SEGMEXEC
76727+ struct vm_area_struct *vma_m = NULL;
76728+#endif
76729+
76730+ /*
76731+ * mm->mmap_sem is required to protect against another thread
76732+ * changing the mappings in case we sleep.
76733+ */
76734+ verify_mm_writelocked(mm);
76735+
76736 /* Clear old maps */
76737 error = -ENOMEM;
76738-munmap_back:
76739 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
76740 if (do_munmap(mm, addr, len))
76741 return -ENOMEM;
76742- goto munmap_back;
76743+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
76744 }
76745
76746 /* Check against address space limit. */
76747@@ -1460,6 +1581,16 @@ munmap_back:
76748 goto unacct_error;
76749 }
76750
76751+#ifdef CONFIG_PAX_SEGMEXEC
76752+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
76753+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76754+ if (!vma_m) {
76755+ error = -ENOMEM;
76756+ goto free_vma;
76757+ }
76758+ }
76759+#endif
76760+
76761 vma->vm_mm = mm;
76762 vma->vm_start = addr;
76763 vma->vm_end = addr + len;
76764@@ -1484,6 +1615,13 @@ munmap_back:
76765 if (error)
76766 goto unmap_and_free_vma;
76767
76768+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76769+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
76770+ vma->vm_flags |= VM_PAGEEXEC;
76771+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
76772+ }
76773+#endif
76774+
76775 /* Can addr have changed??
76776 *
76777 * Answer: Yes, several device drivers can do it in their
76778@@ -1522,6 +1660,11 @@ munmap_back:
76779 vma_link(mm, vma, prev, rb_link, rb_parent);
76780 file = vma->vm_file;
76781
76782+#ifdef CONFIG_PAX_SEGMEXEC
76783+ if (vma_m)
76784+ BUG_ON(pax_mirror_vma(vma_m, vma));
76785+#endif
76786+
76787 /* Once vma denies write, undo our temporary denial count */
76788 if (correct_wcount)
76789 atomic_inc(&inode->i_writecount);
76790@@ -1529,6 +1672,7 @@ out:
76791 perf_event_mmap(vma);
76792
76793 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
76794+ track_exec_limit(mm, addr, addr + len, vm_flags);
76795 if (vm_flags & VM_LOCKED) {
76796 if (!mlock_vma_pages_range(vma, addr, addr + len))
76797 mm->locked_vm += (len >> PAGE_SHIFT);
76798@@ -1550,6 +1694,12 @@ unmap_and_free_vma:
76799 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
76800 charged = 0;
76801 free_vma:
76802+
76803+#ifdef CONFIG_PAX_SEGMEXEC
76804+ if (vma_m)
76805+ kmem_cache_free(vm_area_cachep, vma_m);
76806+#endif
76807+
76808 kmem_cache_free(vm_area_cachep, vma);
76809 unacct_error:
76810 if (charged)
76811@@ -1557,6 +1707,62 @@ unacct_error:
76812 return error;
76813 }
76814
76815+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
76816+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
76817+{
76818+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
76819+ return (random32() & 0xFF) << PAGE_SHIFT;
76820+
76821+ return 0;
76822+}
76823+#endif
76824+
76825+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
76826+{
76827+ if (!vma) {
76828+#ifdef CONFIG_STACK_GROWSUP
76829+ if (addr > sysctl_heap_stack_gap)
76830+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
76831+ else
76832+ vma = find_vma(current->mm, 0);
76833+ if (vma && (vma->vm_flags & VM_GROWSUP))
76834+ return false;
76835+#endif
76836+ return true;
76837+ }
76838+
76839+ if (addr + len > vma->vm_start)
76840+ return false;
76841+
76842+ if (vma->vm_flags & VM_GROWSDOWN)
76843+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
76844+#ifdef CONFIG_STACK_GROWSUP
76845+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
76846+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
76847+#endif
76848+ else if (offset)
76849+ return offset <= vma->vm_start - addr - len;
76850+
76851+ return true;
76852+}
76853+
76854+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
76855+{
76856+ if (vma->vm_start < len)
76857+ return -ENOMEM;
76858+
76859+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
76860+ if (offset <= vma->vm_start - len)
76861+ return vma->vm_start - len - offset;
76862+ else
76863+ return -ENOMEM;
76864+ }
76865+
76866+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
76867+ return vma->vm_start - len - sysctl_heap_stack_gap;
76868+ return -ENOMEM;
76869+}
76870+
76871 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
76872 {
76873 /*
76874@@ -1776,6 +1982,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
76875 struct mm_struct *mm = current->mm;
76876 struct vm_area_struct *vma;
76877 struct vm_unmapped_area_info info;
76878+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
76879
76880 if (len > TASK_SIZE)
76881 return -ENOMEM;
76882@@ -1783,17 +1990,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
76883 if (flags & MAP_FIXED)
76884 return addr;
76885
76886+#ifdef CONFIG_PAX_RANDMMAP
76887+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
76888+#endif
76889+
76890 if (addr) {
76891 addr = PAGE_ALIGN(addr);
76892 vma = find_vma(mm, addr);
76893- if (TASK_SIZE - len >= addr &&
76894- (!vma || addr + len <= vma->vm_start))
76895+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
76896 return addr;
76897 }
76898
76899 info.flags = 0;
76900 info.length = len;
76901 info.low_limit = TASK_UNMAPPED_BASE;
76902+
76903+#ifdef CONFIG_PAX_RANDMMAP
76904+ if (mm->pax_flags & MF_PAX_RANDMMAP)
76905+ info.low_limit += mm->delta_mmap;
76906+#endif
76907+
76908 info.high_limit = TASK_SIZE;
76909 info.align_mask = 0;
76910 return vm_unmapped_area(&info);
76911@@ -1802,10 +2018,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
76912
76913 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
76914 {
76915+
76916+#ifdef CONFIG_PAX_SEGMEXEC
76917+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
76918+ return;
76919+#endif
76920+
76921 /*
76922 * Is this a new hole at the lowest possible address?
76923 */
76924- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
76925+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
76926 mm->free_area_cache = addr;
76927 }
76928
76929@@ -1823,6 +2045,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76930 struct mm_struct *mm = current->mm;
76931 unsigned long addr = addr0;
76932 struct vm_unmapped_area_info info;
76933+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
76934
76935 /* requested length too big for entire address space */
76936 if (len > TASK_SIZE)
76937@@ -1831,12 +2054,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76938 if (flags & MAP_FIXED)
76939 return addr;
76940
76941+#ifdef CONFIG_PAX_RANDMMAP
76942+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
76943+#endif
76944+
76945 /* requesting a specific address */
76946 if (addr) {
76947 addr = PAGE_ALIGN(addr);
76948 vma = find_vma(mm, addr);
76949- if (TASK_SIZE - len >= addr &&
76950- (!vma || addr + len <= vma->vm_start))
76951+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
76952 return addr;
76953 }
76954
76955@@ -1857,6 +2083,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76956 VM_BUG_ON(addr != -ENOMEM);
76957 info.flags = 0;
76958 info.low_limit = TASK_UNMAPPED_BASE;
76959+
76960+#ifdef CONFIG_PAX_RANDMMAP
76961+ if (mm->pax_flags & MF_PAX_RANDMMAP)
76962+ info.low_limit += mm->delta_mmap;
76963+#endif
76964+
76965 info.high_limit = TASK_SIZE;
76966 addr = vm_unmapped_area(&info);
76967 }
76968@@ -1867,6 +2099,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76969
76970 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
76971 {
76972+
76973+#ifdef CONFIG_PAX_SEGMEXEC
76974+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
76975+ return;
76976+#endif
76977+
76978 /*
76979 * Is this a new hole at the highest possible address?
76980 */
76981@@ -1874,8 +2112,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
76982 mm->free_area_cache = addr;
76983
76984 /* dont allow allocations above current base */
76985- if (mm->free_area_cache > mm->mmap_base)
76986+ if (mm->free_area_cache > mm->mmap_base) {
76987 mm->free_area_cache = mm->mmap_base;
76988+ mm->cached_hole_size = ~0UL;
76989+ }
76990 }
76991
76992 unsigned long
76993@@ -1974,6 +2214,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
76994 return vma;
76995 }
76996
76997+#ifdef CONFIG_PAX_SEGMEXEC
76998+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
76999+{
77000+ struct vm_area_struct *vma_m;
77001+
77002+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
77003+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
77004+ BUG_ON(vma->vm_mirror);
77005+ return NULL;
77006+ }
77007+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
77008+ vma_m = vma->vm_mirror;
77009+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
77010+ BUG_ON(vma->vm_file != vma_m->vm_file);
77011+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
77012+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
77013+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
77014+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
77015+ return vma_m;
77016+}
77017+#endif
77018+
77019 /*
77020 * Verify that the stack growth is acceptable and
77021 * update accounting. This is shared with both the
77022@@ -1990,6 +2252,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77023 return -ENOMEM;
77024
77025 /* Stack limit test */
77026+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
77027 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
77028 return -ENOMEM;
77029
77030@@ -2000,6 +2263,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77031 locked = mm->locked_vm + grow;
77032 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
77033 limit >>= PAGE_SHIFT;
77034+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
77035 if (locked > limit && !capable(CAP_IPC_LOCK))
77036 return -ENOMEM;
77037 }
77038@@ -2029,37 +2293,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77039 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
77040 * vma is the last one with address > vma->vm_end. Have to extend vma.
77041 */
77042+#ifndef CONFIG_IA64
77043+static
77044+#endif
77045 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
77046 {
77047 int error;
77048+ bool locknext;
77049
77050 if (!(vma->vm_flags & VM_GROWSUP))
77051 return -EFAULT;
77052
77053+ /* Also guard against wrapping around to address 0. */
77054+ if (address < PAGE_ALIGN(address+1))
77055+ address = PAGE_ALIGN(address+1);
77056+ else
77057+ return -ENOMEM;
77058+
77059 /*
77060 * We must make sure the anon_vma is allocated
77061 * so that the anon_vma locking is not a noop.
77062 */
77063 if (unlikely(anon_vma_prepare(vma)))
77064 return -ENOMEM;
77065+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
77066+ if (locknext && anon_vma_prepare(vma->vm_next))
77067+ return -ENOMEM;
77068 vma_lock_anon_vma(vma);
77069+ if (locknext)
77070+ vma_lock_anon_vma(vma->vm_next);
77071
77072 /*
77073 * vma->vm_start/vm_end cannot change under us because the caller
77074 * is required to hold the mmap_sem in read mode. We need the
77075- * anon_vma lock to serialize against concurrent expand_stacks.
77076- * Also guard against wrapping around to address 0.
77077+ * anon_vma locks to serialize against concurrent expand_stacks
77078+ * and expand_upwards.
77079 */
77080- if (address < PAGE_ALIGN(address+4))
77081- address = PAGE_ALIGN(address+4);
77082- else {
77083- vma_unlock_anon_vma(vma);
77084- return -ENOMEM;
77085- }
77086 error = 0;
77087
77088 /* Somebody else might have raced and expanded it already */
77089- if (address > vma->vm_end) {
77090+ 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)
77091+ error = -ENOMEM;
77092+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
77093 unsigned long size, grow;
77094
77095 size = address - vma->vm_start;
77096@@ -2094,6 +2369,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
77097 }
77098 }
77099 }
77100+ if (locknext)
77101+ vma_unlock_anon_vma(vma->vm_next);
77102 vma_unlock_anon_vma(vma);
77103 khugepaged_enter_vma_merge(vma);
77104 validate_mm(vma->vm_mm);
77105@@ -2108,6 +2385,8 @@ int expand_downwards(struct vm_area_struct *vma,
77106 unsigned long address)
77107 {
77108 int error;
77109+ bool lockprev = false;
77110+ struct vm_area_struct *prev;
77111
77112 /*
77113 * We must make sure the anon_vma is allocated
77114@@ -2121,6 +2400,15 @@ int expand_downwards(struct vm_area_struct *vma,
77115 if (error)
77116 return error;
77117
77118+ prev = vma->vm_prev;
77119+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
77120+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
77121+#endif
77122+ if (lockprev && anon_vma_prepare(prev))
77123+ return -ENOMEM;
77124+ if (lockprev)
77125+ vma_lock_anon_vma(prev);
77126+
77127 vma_lock_anon_vma(vma);
77128
77129 /*
77130@@ -2130,9 +2418,17 @@ int expand_downwards(struct vm_area_struct *vma,
77131 */
77132
77133 /* Somebody else might have raced and expanded it already */
77134- if (address < vma->vm_start) {
77135+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
77136+ error = -ENOMEM;
77137+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
77138 unsigned long size, grow;
77139
77140+#ifdef CONFIG_PAX_SEGMEXEC
77141+ struct vm_area_struct *vma_m;
77142+
77143+ vma_m = pax_find_mirror_vma(vma);
77144+#endif
77145+
77146 size = vma->vm_end - address;
77147 grow = (vma->vm_start - address) >> PAGE_SHIFT;
77148
77149@@ -2157,6 +2453,18 @@ int expand_downwards(struct vm_area_struct *vma,
77150 vma->vm_pgoff -= grow;
77151 anon_vma_interval_tree_post_update_vma(vma);
77152 vma_gap_update(vma);
77153+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
77154+
77155+#ifdef CONFIG_PAX_SEGMEXEC
77156+ if (vma_m) {
77157+ anon_vma_interval_tree_pre_update_vma(vma_m);
77158+ vma_m->vm_start -= grow << PAGE_SHIFT;
77159+ vma_m->vm_pgoff -= grow;
77160+ anon_vma_interval_tree_post_update_vma(vma_m);
77161+ vma_gap_update(vma_m);
77162+ }
77163+#endif
77164+
77165 spin_unlock(&vma->vm_mm->page_table_lock);
77166
77167 perf_event_mmap(vma);
77168@@ -2236,6 +2544,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
77169 do {
77170 long nrpages = vma_pages(vma);
77171
77172+#ifdef CONFIG_PAX_SEGMEXEC
77173+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
77174+ vma = remove_vma(vma);
77175+ continue;
77176+ }
77177+#endif
77178+
77179 if (vma->vm_flags & VM_ACCOUNT)
77180 nr_accounted += nrpages;
77181 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
77182@@ -2281,6 +2596,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
77183 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
77184 vma->vm_prev = NULL;
77185 do {
77186+
77187+#ifdef CONFIG_PAX_SEGMEXEC
77188+ if (vma->vm_mirror) {
77189+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
77190+ vma->vm_mirror->vm_mirror = NULL;
77191+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
77192+ vma->vm_mirror = NULL;
77193+ }
77194+#endif
77195+
77196 vma_rb_erase(vma, &mm->mm_rb);
77197 mm->map_count--;
77198 tail_vma = vma;
77199@@ -2312,14 +2637,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77200 struct vm_area_struct *new;
77201 int err = -ENOMEM;
77202
77203+#ifdef CONFIG_PAX_SEGMEXEC
77204+ struct vm_area_struct *vma_m, *new_m = NULL;
77205+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
77206+#endif
77207+
77208 if (is_vm_hugetlb_page(vma) && (addr &
77209 ~(huge_page_mask(hstate_vma(vma)))))
77210 return -EINVAL;
77211
77212+#ifdef CONFIG_PAX_SEGMEXEC
77213+ vma_m = pax_find_mirror_vma(vma);
77214+#endif
77215+
77216 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
77217 if (!new)
77218 goto out_err;
77219
77220+#ifdef CONFIG_PAX_SEGMEXEC
77221+ if (vma_m) {
77222+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
77223+ if (!new_m) {
77224+ kmem_cache_free(vm_area_cachep, new);
77225+ goto out_err;
77226+ }
77227+ }
77228+#endif
77229+
77230 /* most fields are the same, copy all, and then fixup */
77231 *new = *vma;
77232
77233@@ -2332,6 +2676,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77234 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
77235 }
77236
77237+#ifdef CONFIG_PAX_SEGMEXEC
77238+ if (vma_m) {
77239+ *new_m = *vma_m;
77240+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
77241+ new_m->vm_mirror = new;
77242+ new->vm_mirror = new_m;
77243+
77244+ if (new_below)
77245+ new_m->vm_end = addr_m;
77246+ else {
77247+ new_m->vm_start = addr_m;
77248+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
77249+ }
77250+ }
77251+#endif
77252+
77253 pol = mpol_dup(vma_policy(vma));
77254 if (IS_ERR(pol)) {
77255 err = PTR_ERR(pol);
77256@@ -2354,6 +2714,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77257 else
77258 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
77259
77260+#ifdef CONFIG_PAX_SEGMEXEC
77261+ if (!err && vma_m) {
77262+ if (anon_vma_clone(new_m, vma_m))
77263+ goto out_free_mpol;
77264+
77265+ mpol_get(pol);
77266+ vma_set_policy(new_m, pol);
77267+
77268+ if (new_m->vm_file)
77269+ get_file(new_m->vm_file);
77270+
77271+ if (new_m->vm_ops && new_m->vm_ops->open)
77272+ new_m->vm_ops->open(new_m);
77273+
77274+ if (new_below)
77275+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
77276+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
77277+ else
77278+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
77279+
77280+ if (err) {
77281+ if (new_m->vm_ops && new_m->vm_ops->close)
77282+ new_m->vm_ops->close(new_m);
77283+ if (new_m->vm_file)
77284+ fput(new_m->vm_file);
77285+ mpol_put(pol);
77286+ }
77287+ }
77288+#endif
77289+
77290 /* Success. */
77291 if (!err)
77292 return 0;
77293@@ -2363,10 +2753,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77294 new->vm_ops->close(new);
77295 if (new->vm_file)
77296 fput(new->vm_file);
77297- unlink_anon_vmas(new);
77298 out_free_mpol:
77299 mpol_put(pol);
77300 out_free_vma:
77301+
77302+#ifdef CONFIG_PAX_SEGMEXEC
77303+ if (new_m) {
77304+ unlink_anon_vmas(new_m);
77305+ kmem_cache_free(vm_area_cachep, new_m);
77306+ }
77307+#endif
77308+
77309+ unlink_anon_vmas(new);
77310 kmem_cache_free(vm_area_cachep, new);
77311 out_err:
77312 return err;
77313@@ -2379,6 +2777,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77314 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77315 unsigned long addr, int new_below)
77316 {
77317+
77318+#ifdef CONFIG_PAX_SEGMEXEC
77319+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
77320+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
77321+ if (mm->map_count >= sysctl_max_map_count-1)
77322+ return -ENOMEM;
77323+ } else
77324+#endif
77325+
77326 if (mm->map_count >= sysctl_max_map_count)
77327 return -ENOMEM;
77328
77329@@ -2390,11 +2797,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77330 * work. This now handles partial unmappings.
77331 * Jeremy Fitzhardinge <jeremy@goop.org>
77332 */
77333+#ifdef CONFIG_PAX_SEGMEXEC
77334 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77335 {
77336+ int ret = __do_munmap(mm, start, len);
77337+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
77338+ return ret;
77339+
77340+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
77341+}
77342+
77343+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77344+#else
77345+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77346+#endif
77347+{
77348 unsigned long end;
77349 struct vm_area_struct *vma, *prev, *last;
77350
77351+ /*
77352+ * mm->mmap_sem is required to protect against another thread
77353+ * changing the mappings in case we sleep.
77354+ */
77355+ verify_mm_writelocked(mm);
77356+
77357 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
77358 return -EINVAL;
77359
77360@@ -2469,6 +2895,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77361 /* Fix up all other VM information */
77362 remove_vma_list(mm, vma);
77363
77364+ track_exec_limit(mm, start, end, 0UL);
77365+
77366 return 0;
77367 }
77368
77369@@ -2477,6 +2905,13 @@ int vm_munmap(unsigned long start, size_t len)
77370 int ret;
77371 struct mm_struct *mm = current->mm;
77372
77373+
77374+#ifdef CONFIG_PAX_SEGMEXEC
77375+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
77376+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
77377+ return -EINVAL;
77378+#endif
77379+
77380 down_write(&mm->mmap_sem);
77381 ret = do_munmap(mm, start, len);
77382 up_write(&mm->mmap_sem);
77383@@ -2490,16 +2925,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
77384 return vm_munmap(addr, len);
77385 }
77386
77387-static inline void verify_mm_writelocked(struct mm_struct *mm)
77388-{
77389-#ifdef CONFIG_DEBUG_VM
77390- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
77391- WARN_ON(1);
77392- up_read(&mm->mmap_sem);
77393- }
77394-#endif
77395-}
77396-
77397 /*
77398 * this is really a simplified "do_mmap". it only handles
77399 * anonymous maps. eventually we may be able to do some
77400@@ -2513,6 +2938,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77401 struct rb_node ** rb_link, * rb_parent;
77402 pgoff_t pgoff = addr >> PAGE_SHIFT;
77403 int error;
77404+ unsigned long charged;
77405
77406 len = PAGE_ALIGN(len);
77407 if (!len)
77408@@ -2520,16 +2946,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77409
77410 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
77411
77412+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
77413+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
77414+ flags &= ~VM_EXEC;
77415+
77416+#ifdef CONFIG_PAX_MPROTECT
77417+ if (mm->pax_flags & MF_PAX_MPROTECT)
77418+ flags &= ~VM_MAYEXEC;
77419+#endif
77420+
77421+ }
77422+#endif
77423+
77424 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
77425 if (error & ~PAGE_MASK)
77426 return error;
77427
77428+ charged = len >> PAGE_SHIFT;
77429+
77430 /*
77431 * mlock MCL_FUTURE?
77432 */
77433 if (mm->def_flags & VM_LOCKED) {
77434 unsigned long locked, lock_limit;
77435- locked = len >> PAGE_SHIFT;
77436+ locked = charged;
77437 locked += mm->locked_vm;
77438 lock_limit = rlimit(RLIMIT_MEMLOCK);
77439 lock_limit >>= PAGE_SHIFT;
77440@@ -2546,21 +2986,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77441 /*
77442 * Clear old maps. this also does some error checking for us
77443 */
77444- munmap_back:
77445 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
77446 if (do_munmap(mm, addr, len))
77447 return -ENOMEM;
77448- goto munmap_back;
77449+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
77450 }
77451
77452 /* Check against address space limits *after* clearing old maps... */
77453- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
77454+ if (!may_expand_vm(mm, charged))
77455 return -ENOMEM;
77456
77457 if (mm->map_count > sysctl_max_map_count)
77458 return -ENOMEM;
77459
77460- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
77461+ if (security_vm_enough_memory_mm(mm, charged))
77462 return -ENOMEM;
77463
77464 /* Can we just expand an old private anonymous mapping? */
77465@@ -2574,7 +3013,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77466 */
77467 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77468 if (!vma) {
77469- vm_unacct_memory(len >> PAGE_SHIFT);
77470+ vm_unacct_memory(charged);
77471 return -ENOMEM;
77472 }
77473
77474@@ -2588,11 +3027,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77475 vma_link(mm, vma, prev, rb_link, rb_parent);
77476 out:
77477 perf_event_mmap(vma);
77478- mm->total_vm += len >> PAGE_SHIFT;
77479+ mm->total_vm += charged;
77480 if (flags & VM_LOCKED) {
77481 if (!mlock_vma_pages_range(vma, addr, addr + len))
77482- mm->locked_vm += (len >> PAGE_SHIFT);
77483+ mm->locked_vm += charged;
77484 }
77485+ track_exec_limit(mm, addr, addr + len, flags);
77486 return addr;
77487 }
77488
77489@@ -2650,6 +3090,7 @@ void exit_mmap(struct mm_struct *mm)
77490 while (vma) {
77491 if (vma->vm_flags & VM_ACCOUNT)
77492 nr_accounted += vma_pages(vma);
77493+ vma->vm_mirror = NULL;
77494 vma = remove_vma(vma);
77495 }
77496 vm_unacct_memory(nr_accounted);
77497@@ -2666,6 +3107,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
77498 struct vm_area_struct *prev;
77499 struct rb_node **rb_link, *rb_parent;
77500
77501+#ifdef CONFIG_PAX_SEGMEXEC
77502+ struct vm_area_struct *vma_m = NULL;
77503+#endif
77504+
77505+ if (security_mmap_addr(vma->vm_start))
77506+ return -EPERM;
77507+
77508 /*
77509 * The vm_pgoff of a purely anonymous vma should be irrelevant
77510 * until its first write fault, when page's anon_vma and index
77511@@ -2689,7 +3137,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
77512 security_vm_enough_memory_mm(mm, vma_pages(vma)))
77513 return -ENOMEM;
77514
77515+#ifdef CONFIG_PAX_SEGMEXEC
77516+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
77517+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77518+ if (!vma_m)
77519+ return -ENOMEM;
77520+ }
77521+#endif
77522+
77523 vma_link(mm, vma, prev, rb_link, rb_parent);
77524+
77525+#ifdef CONFIG_PAX_SEGMEXEC
77526+ if (vma_m)
77527+ BUG_ON(pax_mirror_vma(vma_m, vma));
77528+#endif
77529+
77530 return 0;
77531 }
77532
77533@@ -2709,6 +3171,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77534 struct mempolicy *pol;
77535 bool faulted_in_anon_vma = true;
77536
77537+ BUG_ON(vma->vm_mirror);
77538+
77539 /*
77540 * If anonymous vma has not yet been faulted, update new pgoff
77541 * to match new location, to increase its chance of merging.
77542@@ -2775,6 +3239,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77543 return NULL;
77544 }
77545
77546+#ifdef CONFIG_PAX_SEGMEXEC
77547+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
77548+{
77549+ struct vm_area_struct *prev_m;
77550+ struct rb_node **rb_link_m, *rb_parent_m;
77551+ struct mempolicy *pol_m;
77552+
77553+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
77554+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
77555+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
77556+ *vma_m = *vma;
77557+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
77558+ if (anon_vma_clone(vma_m, vma))
77559+ return -ENOMEM;
77560+ pol_m = vma_policy(vma_m);
77561+ mpol_get(pol_m);
77562+ vma_set_policy(vma_m, pol_m);
77563+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
77564+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
77565+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
77566+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
77567+ if (vma_m->vm_file)
77568+ get_file(vma_m->vm_file);
77569+ if (vma_m->vm_ops && vma_m->vm_ops->open)
77570+ vma_m->vm_ops->open(vma_m);
77571+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
77572+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
77573+ vma_m->vm_mirror = vma;
77574+ vma->vm_mirror = vma_m;
77575+ return 0;
77576+}
77577+#endif
77578+
77579 /*
77580 * Return true if the calling process may expand its vm space by the passed
77581 * number of pages
77582@@ -2786,6 +3283,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
77583
77584 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
77585
77586+#ifdef CONFIG_PAX_RANDMMAP
77587+ if (mm->pax_flags & MF_PAX_RANDMMAP)
77588+ cur -= mm->brk_gap;
77589+#endif
77590+
77591+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
77592 if (cur + npages > lim)
77593 return 0;
77594 return 1;
77595@@ -2856,6 +3359,22 @@ int install_special_mapping(struct mm_struct *mm,
77596 vma->vm_start = addr;
77597 vma->vm_end = addr + len;
77598
77599+#ifdef CONFIG_PAX_MPROTECT
77600+ if (mm->pax_flags & MF_PAX_MPROTECT) {
77601+#ifndef CONFIG_PAX_MPROTECT_COMPAT
77602+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
77603+ return -EPERM;
77604+ if (!(vm_flags & VM_EXEC))
77605+ vm_flags &= ~VM_MAYEXEC;
77606+#else
77607+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
77608+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
77609+#endif
77610+ else
77611+ vm_flags &= ~VM_MAYWRITE;
77612+ }
77613+#endif
77614+
77615 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
77616 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
77617
77618diff --git a/mm/mprotect.c b/mm/mprotect.c
77619index 94722a4..9837984 100644
77620--- a/mm/mprotect.c
77621+++ b/mm/mprotect.c
77622@@ -23,10 +23,17 @@
77623 #include <linux/mmu_notifier.h>
77624 #include <linux/migrate.h>
77625 #include <linux/perf_event.h>
77626+
77627+#ifdef CONFIG_PAX_MPROTECT
77628+#include <linux/elf.h>
77629+#include <linux/binfmts.h>
77630+#endif
77631+
77632 #include <asm/uaccess.h>
77633 #include <asm/pgtable.h>
77634 #include <asm/cacheflush.h>
77635 #include <asm/tlbflush.h>
77636+#include <asm/mmu_context.h>
77637
77638 #ifndef pgprot_modify
77639 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
77640@@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
77641 return pages;
77642 }
77643
77644+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
77645+/* called while holding the mmap semaphor for writing except stack expansion */
77646+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
77647+{
77648+ unsigned long oldlimit, newlimit = 0UL;
77649+
77650+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
77651+ return;
77652+
77653+ spin_lock(&mm->page_table_lock);
77654+ oldlimit = mm->context.user_cs_limit;
77655+ if ((prot & VM_EXEC) && oldlimit < end)
77656+ /* USER_CS limit moved up */
77657+ newlimit = end;
77658+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
77659+ /* USER_CS limit moved down */
77660+ newlimit = start;
77661+
77662+ if (newlimit) {
77663+ mm->context.user_cs_limit = newlimit;
77664+
77665+#ifdef CONFIG_SMP
77666+ wmb();
77667+ cpus_clear(mm->context.cpu_user_cs_mask);
77668+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
77669+#endif
77670+
77671+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
77672+ }
77673+ spin_unlock(&mm->page_table_lock);
77674+ if (newlimit == end) {
77675+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
77676+
77677+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
77678+ if (is_vm_hugetlb_page(vma))
77679+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
77680+ else
77681+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
77682+ }
77683+}
77684+#endif
77685+
77686 int
77687 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77688 unsigned long start, unsigned long end, unsigned long newflags)
77689@@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77690 int error;
77691 int dirty_accountable = 0;
77692
77693+#ifdef CONFIG_PAX_SEGMEXEC
77694+ struct vm_area_struct *vma_m = NULL;
77695+ unsigned long start_m, end_m;
77696+
77697+ start_m = start + SEGMEXEC_TASK_SIZE;
77698+ end_m = end + SEGMEXEC_TASK_SIZE;
77699+#endif
77700+
77701 if (newflags == oldflags) {
77702 *pprev = vma;
77703 return 0;
77704 }
77705
77706+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
77707+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
77708+
77709+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
77710+ return -ENOMEM;
77711+
77712+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
77713+ return -ENOMEM;
77714+ }
77715+
77716 /*
77717 * If we make a private mapping writable we increase our commit;
77718 * but (without finer accounting) cannot reduce our commit if we
77719@@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77720 }
77721 }
77722
77723+#ifdef CONFIG_PAX_SEGMEXEC
77724+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
77725+ if (start != vma->vm_start) {
77726+ error = split_vma(mm, vma, start, 1);
77727+ if (error)
77728+ goto fail;
77729+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
77730+ *pprev = (*pprev)->vm_next;
77731+ }
77732+
77733+ if (end != vma->vm_end) {
77734+ error = split_vma(mm, vma, end, 0);
77735+ if (error)
77736+ goto fail;
77737+ }
77738+
77739+ if (pax_find_mirror_vma(vma)) {
77740+ error = __do_munmap(mm, start_m, end_m - start_m);
77741+ if (error)
77742+ goto fail;
77743+ } else {
77744+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77745+ if (!vma_m) {
77746+ error = -ENOMEM;
77747+ goto fail;
77748+ }
77749+ vma->vm_flags = newflags;
77750+ error = pax_mirror_vma(vma_m, vma);
77751+ if (error) {
77752+ vma->vm_flags = oldflags;
77753+ goto fail;
77754+ }
77755+ }
77756+ }
77757+#endif
77758+
77759 /*
77760 * First try to merge with previous and/or next vma.
77761 */
77762@@ -296,9 +399,21 @@ success:
77763 * vm_flags and vm_page_prot are protected by the mmap_sem
77764 * held in write mode.
77765 */
77766+
77767+#ifdef CONFIG_PAX_SEGMEXEC
77768+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
77769+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
77770+#endif
77771+
77772 vma->vm_flags = newflags;
77773+
77774+#ifdef CONFIG_PAX_MPROTECT
77775+ if (mm->binfmt && mm->binfmt->handle_mprotect)
77776+ mm->binfmt->handle_mprotect(vma, newflags);
77777+#endif
77778+
77779 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
77780- vm_get_page_prot(newflags));
77781+ vm_get_page_prot(vma->vm_flags));
77782
77783 if (vma_wants_writenotify(vma)) {
77784 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
77785@@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77786 end = start + len;
77787 if (end <= start)
77788 return -ENOMEM;
77789+
77790+#ifdef CONFIG_PAX_SEGMEXEC
77791+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
77792+ if (end > SEGMEXEC_TASK_SIZE)
77793+ return -EINVAL;
77794+ } else
77795+#endif
77796+
77797+ if (end > TASK_SIZE)
77798+ return -EINVAL;
77799+
77800 if (!arch_validate_prot(prot))
77801 return -EINVAL;
77802
77803@@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77804 /*
77805 * Does the application expect PROT_READ to imply PROT_EXEC:
77806 */
77807- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
77808+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
77809 prot |= PROT_EXEC;
77810
77811 vm_flags = calc_vm_prot_bits(prot);
77812@@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77813 if (start > vma->vm_start)
77814 prev = vma;
77815
77816+#ifdef CONFIG_PAX_MPROTECT
77817+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
77818+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
77819+#endif
77820+
77821 for (nstart = start ; ; ) {
77822 unsigned long newflags;
77823
77824@@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77825
77826 /* newflags >> 4 shift VM_MAY% in place of VM_% */
77827 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
77828+ if (prot & (PROT_WRITE | PROT_EXEC))
77829+ gr_log_rwxmprotect(vma->vm_file);
77830+
77831+ error = -EACCES;
77832+ goto out;
77833+ }
77834+
77835+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
77836 error = -EACCES;
77837 goto out;
77838 }
77839@@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77840 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
77841 if (error)
77842 goto out;
77843+
77844+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
77845+
77846 nstart = tmp;
77847
77848 if (nstart < prev->vm_end)
77849diff --git a/mm/mremap.c b/mm/mremap.c
77850index e1031e1..1f2a0a1 100644
77851--- a/mm/mremap.c
77852+++ b/mm/mremap.c
77853@@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
77854 continue;
77855 pte = ptep_get_and_clear(mm, old_addr, old_pte);
77856 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
77857+
77858+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
77859+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
77860+ pte = pte_exprotect(pte);
77861+#endif
77862+
77863 set_pte_at(mm, new_addr, new_pte, pte);
77864 }
77865
77866@@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
77867 if (is_vm_hugetlb_page(vma))
77868 goto Einval;
77869
77870+#ifdef CONFIG_PAX_SEGMEXEC
77871+ if (pax_find_mirror_vma(vma))
77872+ goto Einval;
77873+#endif
77874+
77875 /* We can't remap across vm area boundaries */
77876 if (old_len > vma->vm_end - addr)
77877 goto Efault;
77878@@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
77879 unsigned long ret = -EINVAL;
77880 unsigned long charged = 0;
77881 unsigned long map_flags;
77882+ unsigned long pax_task_size = TASK_SIZE;
77883
77884 if (new_addr & ~PAGE_MASK)
77885 goto out;
77886
77887- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
77888+#ifdef CONFIG_PAX_SEGMEXEC
77889+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
77890+ pax_task_size = SEGMEXEC_TASK_SIZE;
77891+#endif
77892+
77893+ pax_task_size -= PAGE_SIZE;
77894+
77895+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
77896 goto out;
77897
77898 /* Check if the location we're moving into overlaps the
77899 * old location at all, and fail if it does.
77900 */
77901- if ((new_addr <= addr) && (new_addr+new_len) > addr)
77902- goto out;
77903-
77904- if ((addr <= new_addr) && (addr+old_len) > new_addr)
77905+ if (addr + old_len > new_addr && new_addr + new_len > addr)
77906 goto out;
77907
77908 ret = do_munmap(mm, new_addr, new_len);
77909@@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77910 struct vm_area_struct *vma;
77911 unsigned long ret = -EINVAL;
77912 unsigned long charged = 0;
77913+ unsigned long pax_task_size = TASK_SIZE;
77914
77915 down_write(&current->mm->mmap_sem);
77916
77917@@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77918 if (!new_len)
77919 goto out;
77920
77921+#ifdef CONFIG_PAX_SEGMEXEC
77922+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
77923+ pax_task_size = SEGMEXEC_TASK_SIZE;
77924+#endif
77925+
77926+ pax_task_size -= PAGE_SIZE;
77927+
77928+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
77929+ old_len > pax_task_size || addr > pax_task_size-old_len)
77930+ goto out;
77931+
77932 if (flags & MREMAP_FIXED) {
77933 if (flags & MREMAP_MAYMOVE)
77934 ret = mremap_to(addr, old_len, new_addr, new_len);
77935@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77936 addr + new_len);
77937 }
77938 ret = addr;
77939+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
77940 goto out;
77941 }
77942 }
77943@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77944 goto out;
77945 }
77946
77947+ map_flags = vma->vm_flags;
77948 ret = move_vma(vma, addr, old_len, new_len, new_addr);
77949+ if (!(ret & ~PAGE_MASK)) {
77950+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
77951+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
77952+ }
77953 }
77954 out:
77955 if (ret & ~PAGE_MASK)
77956diff --git a/mm/nommu.c b/mm/nommu.c
77957index 79c3cac..4d357e0 100644
77958--- a/mm/nommu.c
77959+++ b/mm/nommu.c
77960@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
77961 int sysctl_overcommit_ratio = 50; /* default is 50% */
77962 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
77963 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
77964-int heap_stack_gap = 0;
77965
77966 atomic_long_t mmap_pages_allocated;
77967
77968@@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
77969 EXPORT_SYMBOL(find_vma);
77970
77971 /*
77972- * find a VMA
77973- * - we don't extend stack VMAs under NOMMU conditions
77974- */
77975-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
77976-{
77977- return find_vma(mm, addr);
77978-}
77979-
77980-/*
77981 * expand a stack to a given address
77982 * - not supported under NOMMU conditions
77983 */
77984@@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77985
77986 /* most fields are the same, copy all, and then fixup */
77987 *new = *vma;
77988+ INIT_LIST_HEAD(&new->anon_vma_chain);
77989 *region = *vma->vm_region;
77990 new->vm_region = region;
77991
77992diff --git a/mm/page-writeback.c b/mm/page-writeback.c
77993index 0713bfb..e3774e0 100644
77994--- a/mm/page-writeback.c
77995+++ b/mm/page-writeback.c
77996@@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
77997 }
77998 }
77999
78000-static struct notifier_block __cpuinitdata ratelimit_nb = {
78001+static struct notifier_block ratelimit_nb = {
78002 .notifier_call = ratelimit_handler,
78003 .next = NULL,
78004 };
78005diff --git a/mm/page_alloc.c b/mm/page_alloc.c
78006index 6a83cd3..bc2dcb6 100644
78007--- a/mm/page_alloc.c
78008+++ b/mm/page_alloc.c
78009@@ -338,7 +338,7 @@ out:
78010 * This usage means that zero-order pages may not be compound.
78011 */
78012
78013-static void free_compound_page(struct page *page)
78014+void free_compound_page(struct page *page)
78015 {
78016 __free_pages_ok(page, compound_order(page));
78017 }
78018@@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
78019 int i;
78020 int bad = 0;
78021
78022+#ifdef CONFIG_PAX_MEMORY_SANITIZE
78023+ unsigned long index = 1UL << order;
78024+#endif
78025+
78026 trace_mm_page_free(page, order);
78027 kmemcheck_free_shadow(page, order);
78028
78029@@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
78030 debug_check_no_obj_freed(page_address(page),
78031 PAGE_SIZE << order);
78032 }
78033+
78034+#ifdef CONFIG_PAX_MEMORY_SANITIZE
78035+ for (; index; --index)
78036+ sanitize_highpage(page + index - 1);
78037+#endif
78038+
78039 arch_free_page(page, order);
78040 kernel_map_pages(page, 1 << order, 0);
78041
78042@@ -861,8 +871,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
78043 arch_alloc_page(page, order);
78044 kernel_map_pages(page, 1 << order, 1);
78045
78046+#ifndef CONFIG_PAX_MEMORY_SANITIZE
78047 if (gfp_flags & __GFP_ZERO)
78048 prep_zero_page(page, order, gfp_flags);
78049+#endif
78050
78051 if (order && (gfp_flags & __GFP_COMP))
78052 prep_compound_page(page, order);
78053@@ -3752,7 +3764,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
78054 unsigned long pfn;
78055
78056 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
78057+#ifdef CONFIG_X86_32
78058+ /* boot failures in VMware 8 on 32bit vanilla since
78059+ this change */
78060+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
78061+#else
78062 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
78063+#endif
78064 return 1;
78065 }
78066 return 0;
78067diff --git a/mm/percpu.c b/mm/percpu.c
78068index 8c8e08f..73a5cda 100644
78069--- a/mm/percpu.c
78070+++ b/mm/percpu.c
78071@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
78072 static unsigned int pcpu_high_unit_cpu __read_mostly;
78073
78074 /* the address of the first chunk which starts with the kernel static area */
78075-void *pcpu_base_addr __read_mostly;
78076+void *pcpu_base_addr __read_only;
78077 EXPORT_SYMBOL_GPL(pcpu_base_addr);
78078
78079 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
78080diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
78081index 926b466..b23df53 100644
78082--- a/mm/process_vm_access.c
78083+++ b/mm/process_vm_access.c
78084@@ -13,6 +13,7 @@
78085 #include <linux/uio.h>
78086 #include <linux/sched.h>
78087 #include <linux/highmem.h>
78088+#include <linux/security.h>
78089 #include <linux/ptrace.h>
78090 #include <linux/slab.h>
78091 #include <linux/syscalls.h>
78092@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
78093 size_t iov_l_curr_offset = 0;
78094 ssize_t iov_len;
78095
78096+ return -ENOSYS; // PaX: until properly audited
78097+
78098 /*
78099 * Work out how many pages of struct pages we're going to need
78100 * when eventually calling get_user_pages
78101 */
78102 for (i = 0; i < riovcnt; i++) {
78103 iov_len = rvec[i].iov_len;
78104- if (iov_len > 0) {
78105- nr_pages_iov = ((unsigned long)rvec[i].iov_base
78106- + iov_len)
78107- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
78108- / PAGE_SIZE + 1;
78109- nr_pages = max(nr_pages, nr_pages_iov);
78110- }
78111+ if (iov_len <= 0)
78112+ continue;
78113+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
78114+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
78115+ nr_pages = max(nr_pages, nr_pages_iov);
78116 }
78117
78118 if (nr_pages == 0)
78119@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
78120 goto free_proc_pages;
78121 }
78122
78123+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
78124+ rc = -EPERM;
78125+ goto put_task_struct;
78126+ }
78127+
78128 mm = mm_access(task, PTRACE_MODE_ATTACH);
78129 if (!mm || IS_ERR(mm)) {
78130 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
78131diff --git a/mm/rmap.c b/mm/rmap.c
78132index 2c78f8c..9e9c624 100644
78133--- a/mm/rmap.c
78134+++ b/mm/rmap.c
78135@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78136 struct anon_vma *anon_vma = vma->anon_vma;
78137 struct anon_vma_chain *avc;
78138
78139+#ifdef CONFIG_PAX_SEGMEXEC
78140+ struct anon_vma_chain *avc_m = NULL;
78141+#endif
78142+
78143 might_sleep();
78144 if (unlikely(!anon_vma)) {
78145 struct mm_struct *mm = vma->vm_mm;
78146@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78147 if (!avc)
78148 goto out_enomem;
78149
78150+#ifdef CONFIG_PAX_SEGMEXEC
78151+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
78152+ if (!avc_m)
78153+ goto out_enomem_free_avc;
78154+#endif
78155+
78156 anon_vma = find_mergeable_anon_vma(vma);
78157 allocated = NULL;
78158 if (!anon_vma) {
78159@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78160 /* page_table_lock to protect against threads */
78161 spin_lock(&mm->page_table_lock);
78162 if (likely(!vma->anon_vma)) {
78163+
78164+#ifdef CONFIG_PAX_SEGMEXEC
78165+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
78166+
78167+ if (vma_m) {
78168+ BUG_ON(vma_m->anon_vma);
78169+ vma_m->anon_vma = anon_vma;
78170+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
78171+ avc_m = NULL;
78172+ }
78173+#endif
78174+
78175 vma->anon_vma = anon_vma;
78176 anon_vma_chain_link(vma, avc, anon_vma);
78177 allocated = NULL;
78178@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78179
78180 if (unlikely(allocated))
78181 put_anon_vma(allocated);
78182+
78183+#ifdef CONFIG_PAX_SEGMEXEC
78184+ if (unlikely(avc_m))
78185+ anon_vma_chain_free(avc_m);
78186+#endif
78187+
78188 if (unlikely(avc))
78189 anon_vma_chain_free(avc);
78190 }
78191 return 0;
78192
78193 out_enomem_free_avc:
78194+
78195+#ifdef CONFIG_PAX_SEGMEXEC
78196+ if (avc_m)
78197+ anon_vma_chain_free(avc_m);
78198+#endif
78199+
78200 anon_vma_chain_free(avc);
78201 out_enomem:
78202 return -ENOMEM;
78203@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
78204 * Attach the anon_vmas from src to dst.
78205 * Returns 0 on success, -ENOMEM on failure.
78206 */
78207-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
78208+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
78209 {
78210 struct anon_vma_chain *avc, *pavc;
78211 struct anon_vma *root = NULL;
78212@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
78213 * the corresponding VMA in the parent process is attached to.
78214 * Returns 0 on success, non-zero on failure.
78215 */
78216-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
78217+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
78218 {
78219 struct anon_vma_chain *avc;
78220 struct anon_vma *anon_vma;
78221diff --git a/mm/shmem.c b/mm/shmem.c
78222index efd0b3a..994b702 100644
78223--- a/mm/shmem.c
78224+++ b/mm/shmem.c
78225@@ -31,7 +31,7 @@
78226 #include <linux/export.h>
78227 #include <linux/swap.h>
78228
78229-static struct vfsmount *shm_mnt;
78230+struct vfsmount *shm_mnt;
78231
78232 #ifdef CONFIG_SHMEM
78233 /*
78234@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
78235 #define BOGO_DIRENT_SIZE 20
78236
78237 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
78238-#define SHORT_SYMLINK_LEN 128
78239+#define SHORT_SYMLINK_LEN 64
78240
78241 /*
78242 * shmem_fallocate and shmem_writepage communicate via inode->i_private
78243@@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
78244 static int shmem_xattr_validate(const char *name)
78245 {
78246 struct { const char *prefix; size_t len; } arr[] = {
78247+
78248+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
78249+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
78250+#endif
78251+
78252 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
78253 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
78254 };
78255@@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
78256 if (err)
78257 return err;
78258
78259+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
78260+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
78261+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
78262+ return -EOPNOTSUPP;
78263+ if (size > 8)
78264+ return -EINVAL;
78265+ }
78266+#endif
78267+
78268 return simple_xattr_set(&info->xattrs, name, value, size, flags);
78269 }
78270
78271@@ -2562,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
78272 int err = -ENOMEM;
78273
78274 /* Round up to L1_CACHE_BYTES to resist false sharing */
78275- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
78276- L1_CACHE_BYTES), GFP_KERNEL);
78277+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
78278 if (!sbinfo)
78279 return -ENOMEM;
78280
78281diff --git a/mm/slab.c b/mm/slab.c
78282index e7667a3..b62c169 100644
78283--- a/mm/slab.c
78284+++ b/mm/slab.c
78285@@ -306,7 +306,7 @@ struct kmem_list3 {
78286 * Need this for bootstrapping a per node allocator.
78287 */
78288 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
78289-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
78290+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
78291 #define CACHE_CACHE 0
78292 #define SIZE_AC MAX_NUMNODES
78293 #define SIZE_L3 (2 * MAX_NUMNODES)
78294@@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
78295 if ((x)->max_freeable < i) \
78296 (x)->max_freeable = i; \
78297 } while (0)
78298-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
78299-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
78300-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
78301-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
78302+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
78303+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
78304+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
78305+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
78306 #else
78307 #define STATS_INC_ACTIVE(x) do { } while (0)
78308 #define STATS_DEC_ACTIVE(x) do { } while (0)
78309@@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
78310 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
78311 */
78312 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
78313- const struct slab *slab, void *obj)
78314+ const struct slab *slab, const void *obj)
78315 {
78316 u32 offset = (obj - slab->s_mem);
78317 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
78318@@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
78319 struct cache_names {
78320 char *name;
78321 char *name_dma;
78322+ char *name_usercopy;
78323 };
78324
78325 static struct cache_names __initdata cache_names[] = {
78326-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
78327+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
78328 #include <linux/kmalloc_sizes.h>
78329- {NULL,}
78330+ {NULL}
78331 #undef CACHE
78332 };
78333
78334@@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
78335 if (unlikely(gfpflags & GFP_DMA))
78336 return csizep->cs_dmacachep;
78337 #endif
78338+
78339+#ifdef CONFIG_PAX_USERCOPY_SLABS
78340+ if (unlikely(gfpflags & GFP_USERCOPY))
78341+ return csizep->cs_usercopycachep;
78342+#endif
78343+
78344 return csizep->cs_cachep;
78345 }
78346
78347@@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
78348 return notifier_from_errno(err);
78349 }
78350
78351-static struct notifier_block __cpuinitdata cpucache_notifier = {
78352+static struct notifier_block cpucache_notifier = {
78353 &cpuup_callback, NULL, 0
78354 };
78355
78356@@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
78357 */
78358
78359 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
78360- sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
78361+ sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78362
78363 if (INDEX_AC != INDEX_L3)
78364 sizes[INDEX_L3].cs_cachep =
78365 create_kmalloc_cache(names[INDEX_L3].name,
78366- sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
78367+ sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78368
78369 slab_early_init = 0;
78370
78371@@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
78372 */
78373 if (!sizes->cs_cachep)
78374 sizes->cs_cachep = create_kmalloc_cache(names->name,
78375- sizes->cs_size, ARCH_KMALLOC_FLAGS);
78376+ sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78377
78378 #ifdef CONFIG_ZONE_DMA
78379 sizes->cs_dmacachep = create_kmalloc_cache(
78380 names->name_dma, sizes->cs_size,
78381 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
78382 #endif
78383+
78384+#ifdef CONFIG_PAX_USERCOPY_SLABS
78385+ sizes->cs_usercopycachep = create_kmalloc_cache(
78386+ names->name_usercopy, sizes->cs_size,
78387+ ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78388+#endif
78389+
78390 sizes++;
78391 names++;
78392 }
78393@@ -4365,10 +4379,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
78394 }
78395 /* cpu stats */
78396 {
78397- unsigned long allochit = atomic_read(&cachep->allochit);
78398- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
78399- unsigned long freehit = atomic_read(&cachep->freehit);
78400- unsigned long freemiss = atomic_read(&cachep->freemiss);
78401+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
78402+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
78403+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
78404+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
78405
78406 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
78407 allochit, allocmiss, freehit, freemiss);
78408@@ -4600,13 +4614,71 @@ static const struct file_operations proc_slabstats_operations = {
78409 static int __init slab_proc_init(void)
78410 {
78411 #ifdef CONFIG_DEBUG_SLAB_LEAK
78412- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
78413+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
78414 #endif
78415 return 0;
78416 }
78417 module_init(slab_proc_init);
78418 #endif
78419
78420+bool is_usercopy_object(const void *ptr)
78421+{
78422+ struct page *page;
78423+ struct kmem_cache *cachep;
78424+
78425+ if (ZERO_OR_NULL_PTR(ptr))
78426+ return false;
78427+
78428+ if (!slab_is_available())
78429+ return false;
78430+
78431+ if (!virt_addr_valid(ptr))
78432+ return false;
78433+
78434+ page = virt_to_head_page(ptr);
78435+
78436+ if (!PageSlab(page))
78437+ return false;
78438+
78439+ cachep = page->slab_cache;
78440+ return cachep->flags & SLAB_USERCOPY;
78441+}
78442+
78443+#ifdef CONFIG_PAX_USERCOPY
78444+const char *check_heap_object(const void *ptr, unsigned long n)
78445+{
78446+ struct page *page;
78447+ struct kmem_cache *cachep;
78448+ struct slab *slabp;
78449+ unsigned int objnr;
78450+ unsigned long offset;
78451+
78452+ if (ZERO_OR_NULL_PTR(ptr))
78453+ return "<null>";
78454+
78455+ if (!virt_addr_valid(ptr))
78456+ return NULL;
78457+
78458+ page = virt_to_head_page(ptr);
78459+
78460+ if (!PageSlab(page))
78461+ return NULL;
78462+
78463+ cachep = page->slab_cache;
78464+ if (!(cachep->flags & SLAB_USERCOPY))
78465+ return cachep->name;
78466+
78467+ slabp = page->slab_page;
78468+ objnr = obj_to_index(cachep, slabp, ptr);
78469+ BUG_ON(objnr >= cachep->num);
78470+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
78471+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
78472+ return NULL;
78473+
78474+ return cachep->name;
78475+}
78476+#endif
78477+
78478 /**
78479 * ksize - get the actual amount of memory allocated for a given object
78480 * @objp: Pointer to the object
78481diff --git a/mm/slab.h b/mm/slab.h
78482index 34a98d6..73633d1 100644
78483--- a/mm/slab.h
78484+++ b/mm/slab.h
78485@@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
78486
78487 /* Legal flag mask for kmem_cache_create(), for various configurations */
78488 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
78489- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
78490+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
78491
78492 #if defined(CONFIG_DEBUG_SLAB)
78493 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
78494@@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
78495 return s;
78496
78497 page = virt_to_head_page(x);
78498+
78499+ BUG_ON(!PageSlab(page));
78500+
78501 cachep = page->slab_cache;
78502 if (slab_equal_or_root(cachep, s))
78503 return cachep;
78504diff --git a/mm/slab_common.c b/mm/slab_common.c
78505index 3f3cd97..e050794 100644
78506--- a/mm/slab_common.c
78507+++ b/mm/slab_common.c
78508@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
78509
78510 err = __kmem_cache_create(s, flags);
78511 if (!err) {
78512- s->refcount = 1;
78513+ atomic_set(&s->refcount, 1);
78514 list_add(&s->list, &slab_caches);
78515 memcg_cache_list_add(memcg, s);
78516 } else {
78517@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
78518
78519 get_online_cpus();
78520 mutex_lock(&slab_mutex);
78521- s->refcount--;
78522- if (!s->refcount) {
78523+ if (atomic_dec_and_test(&s->refcount)) {
78524 list_del(&s->list);
78525
78526 if (!__kmem_cache_shutdown(s)) {
78527@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
78528 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
78529 name, size, err);
78530
78531- s->refcount = -1; /* Exempt from merging for now */
78532+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
78533 }
78534
78535 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
78536@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
78537
78538 create_boot_cache(s, name, size, flags);
78539 list_add(&s->list, &slab_caches);
78540- s->refcount = 1;
78541+ atomic_set(&s->refcount, 1);
78542 return s;
78543 }
78544
78545diff --git a/mm/slob.c b/mm/slob.c
78546index a99fdf7..f5b6577 100644
78547--- a/mm/slob.c
78548+++ b/mm/slob.c
78549@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
78550 /*
78551 * Return the size of a slob block.
78552 */
78553-static slobidx_t slob_units(slob_t *s)
78554+static slobidx_t slob_units(const slob_t *s)
78555 {
78556 if (s->units > 0)
78557 return s->units;
78558@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
78559 /*
78560 * Return the next free slob block pointer after this one.
78561 */
78562-static slob_t *slob_next(slob_t *s)
78563+static slob_t *slob_next(const slob_t *s)
78564 {
78565 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
78566 slobidx_t next;
78567@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
78568 /*
78569 * Returns true if s is the last free block in its page.
78570 */
78571-static int slob_last(slob_t *s)
78572+static int slob_last(const slob_t *s)
78573 {
78574 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
78575 }
78576
78577-static void *slob_new_pages(gfp_t gfp, int order, int node)
78578+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
78579 {
78580- void *page;
78581+ struct page *page;
78582
78583 #ifdef CONFIG_NUMA
78584 if (node != NUMA_NO_NODE)
78585@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
78586 if (!page)
78587 return NULL;
78588
78589- return page_address(page);
78590+ __SetPageSlab(page);
78591+ return page;
78592 }
78593
78594-static void slob_free_pages(void *b, int order)
78595+static void slob_free_pages(struct page *sp, int order)
78596 {
78597 if (current->reclaim_state)
78598 current->reclaim_state->reclaimed_slab += 1 << order;
78599- free_pages((unsigned long)b, order);
78600+ __ClearPageSlab(sp);
78601+ reset_page_mapcount(sp);
78602+ sp->private = 0;
78603+ __free_pages(sp, order);
78604 }
78605
78606 /*
78607@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
78608
78609 /* Not enough space: must allocate a new page */
78610 if (!b) {
78611- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
78612- if (!b)
78613+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
78614+ if (!sp)
78615 return NULL;
78616- sp = virt_to_page(b);
78617- __SetPageSlab(sp);
78618+ b = page_address(sp);
78619
78620 spin_lock_irqsave(&slob_lock, flags);
78621 sp->units = SLOB_UNITS(PAGE_SIZE);
78622 sp->freelist = b;
78623+ sp->private = 0;
78624 INIT_LIST_HEAD(&sp->list);
78625 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
78626 set_slob_page_free(sp, slob_list);
78627@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
78628 if (slob_page_free(sp))
78629 clear_slob_page_free(sp);
78630 spin_unlock_irqrestore(&slob_lock, flags);
78631- __ClearPageSlab(sp);
78632- reset_page_mapcount(sp);
78633- slob_free_pages(b, 0);
78634+ slob_free_pages(sp, 0);
78635 return;
78636 }
78637
78638@@ -424,11 +426,10 @@ out:
78639 */
78640
78641 static __always_inline void *
78642-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78643+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
78644 {
78645- unsigned int *m;
78646- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78647- void *ret;
78648+ slob_t *m;
78649+ void *ret = NULL;
78650
78651 gfp &= gfp_allowed_mask;
78652
78653@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78654
78655 if (!m)
78656 return NULL;
78657- *m = size;
78658+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
78659+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
78660+ m[0].units = size;
78661+ m[1].units = align;
78662 ret = (void *)m + align;
78663
78664 trace_kmalloc_node(caller, ret,
78665 size, size + align, gfp, node);
78666 } else {
78667 unsigned int order = get_order(size);
78668+ struct page *page;
78669
78670 if (likely(order))
78671 gfp |= __GFP_COMP;
78672- ret = slob_new_pages(gfp, order, node);
78673+ page = slob_new_pages(gfp, order, node);
78674+ if (page) {
78675+ ret = page_address(page);
78676+ page->private = size;
78677+ }
78678
78679 trace_kmalloc_node(caller, ret,
78680 size, PAGE_SIZE << order, gfp, node);
78681 }
78682
78683- kmemleak_alloc(ret, size, 1, gfp);
78684+ return ret;
78685+}
78686+
78687+static __always_inline void *
78688+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78689+{
78690+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78691+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
78692+
78693+ if (!ZERO_OR_NULL_PTR(ret))
78694+ kmemleak_alloc(ret, size, 1, gfp);
78695 return ret;
78696 }
78697
78698@@ -494,33 +513,110 @@ void kfree(const void *block)
78699 kmemleak_free(block);
78700
78701 sp = virt_to_page(block);
78702- if (PageSlab(sp)) {
78703+ VM_BUG_ON(!PageSlab(sp));
78704+ if (!sp->private) {
78705 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78706- unsigned int *m = (unsigned int *)(block - align);
78707- slob_free(m, *m + align);
78708- } else
78709+ slob_t *m = (slob_t *)(block - align);
78710+ slob_free(m, m[0].units + align);
78711+ } else {
78712+ __ClearPageSlab(sp);
78713+ reset_page_mapcount(sp);
78714+ sp->private = 0;
78715 __free_pages(sp, compound_order(sp));
78716+ }
78717 }
78718 EXPORT_SYMBOL(kfree);
78719
78720+bool is_usercopy_object(const void *ptr)
78721+{
78722+ if (!slab_is_available())
78723+ return false;
78724+
78725+ // PAX: TODO
78726+
78727+ return false;
78728+}
78729+
78730+#ifdef CONFIG_PAX_USERCOPY
78731+const char *check_heap_object(const void *ptr, unsigned long n)
78732+{
78733+ struct page *page;
78734+ const slob_t *free;
78735+ const void *base;
78736+ unsigned long flags;
78737+
78738+ if (ZERO_OR_NULL_PTR(ptr))
78739+ return "<null>";
78740+
78741+ if (!virt_addr_valid(ptr))
78742+ return NULL;
78743+
78744+ page = virt_to_head_page(ptr);
78745+ if (!PageSlab(page))
78746+ return NULL;
78747+
78748+ if (page->private) {
78749+ base = page;
78750+ if (base <= ptr && n <= page->private - (ptr - base))
78751+ return NULL;
78752+ return "<slob>";
78753+ }
78754+
78755+ /* some tricky double walking to find the chunk */
78756+ spin_lock_irqsave(&slob_lock, flags);
78757+ base = (void *)((unsigned long)ptr & PAGE_MASK);
78758+ free = page->freelist;
78759+
78760+ while (!slob_last(free) && (void *)free <= ptr) {
78761+ base = free + slob_units(free);
78762+ free = slob_next(free);
78763+ }
78764+
78765+ while (base < (void *)free) {
78766+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
78767+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
78768+ int offset;
78769+
78770+ if (ptr < base + align)
78771+ break;
78772+
78773+ offset = ptr - base - align;
78774+ if (offset >= m) {
78775+ base += size;
78776+ continue;
78777+ }
78778+
78779+ if (n > m - offset)
78780+ break;
78781+
78782+ spin_unlock_irqrestore(&slob_lock, flags);
78783+ return NULL;
78784+ }
78785+
78786+ spin_unlock_irqrestore(&slob_lock, flags);
78787+ return "<slob>";
78788+}
78789+#endif
78790+
78791 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
78792 size_t ksize(const void *block)
78793 {
78794 struct page *sp;
78795 int align;
78796- unsigned int *m;
78797+ slob_t *m;
78798
78799 BUG_ON(!block);
78800 if (unlikely(block == ZERO_SIZE_PTR))
78801 return 0;
78802
78803 sp = virt_to_page(block);
78804- if (unlikely(!PageSlab(sp)))
78805- return PAGE_SIZE << compound_order(sp);
78806+ VM_BUG_ON(!PageSlab(sp));
78807+ if (sp->private)
78808+ return sp->private;
78809
78810 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78811- m = (unsigned int *)(block - align);
78812- return SLOB_UNITS(*m) * SLOB_UNIT;
78813+ m = (slob_t *)(block - align);
78814+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
78815 }
78816 EXPORT_SYMBOL(ksize);
78817
78818@@ -536,23 +632,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
78819
78820 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
78821 {
78822- void *b;
78823+ void *b = NULL;
78824
78825 flags &= gfp_allowed_mask;
78826
78827 lockdep_trace_alloc(flags);
78828
78829+#ifdef CONFIG_PAX_USERCOPY_SLABS
78830+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
78831+#else
78832 if (c->size < PAGE_SIZE) {
78833 b = slob_alloc(c->size, flags, c->align, node);
78834 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
78835 SLOB_UNITS(c->size) * SLOB_UNIT,
78836 flags, node);
78837 } else {
78838- b = slob_new_pages(flags, get_order(c->size), node);
78839+ struct page *sp;
78840+
78841+ sp = slob_new_pages(flags, get_order(c->size), node);
78842+ if (sp) {
78843+ b = page_address(sp);
78844+ sp->private = c->size;
78845+ }
78846 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
78847 PAGE_SIZE << get_order(c->size),
78848 flags, node);
78849 }
78850+#endif
78851
78852 if (c->ctor)
78853 c->ctor(b);
78854@@ -564,10 +670,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
78855
78856 static void __kmem_cache_free(void *b, int size)
78857 {
78858- if (size < PAGE_SIZE)
78859+ struct page *sp;
78860+
78861+ sp = virt_to_page(b);
78862+ BUG_ON(!PageSlab(sp));
78863+ if (!sp->private)
78864 slob_free(b, size);
78865 else
78866- slob_free_pages(b, get_order(size));
78867+ slob_free_pages(sp, get_order(size));
78868 }
78869
78870 static void kmem_rcu_free(struct rcu_head *head)
78871@@ -580,17 +690,31 @@ static void kmem_rcu_free(struct rcu_head *head)
78872
78873 void kmem_cache_free(struct kmem_cache *c, void *b)
78874 {
78875+ int size = c->size;
78876+
78877+#ifdef CONFIG_PAX_USERCOPY_SLABS
78878+ if (size + c->align < PAGE_SIZE) {
78879+ size += c->align;
78880+ b -= c->align;
78881+ }
78882+#endif
78883+
78884 kmemleak_free_recursive(b, c->flags);
78885 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
78886 struct slob_rcu *slob_rcu;
78887- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
78888- slob_rcu->size = c->size;
78889+ slob_rcu = b + (size - sizeof(struct slob_rcu));
78890+ slob_rcu->size = size;
78891 call_rcu(&slob_rcu->head, kmem_rcu_free);
78892 } else {
78893- __kmem_cache_free(b, c->size);
78894+ __kmem_cache_free(b, size);
78895 }
78896
78897+#ifdef CONFIG_PAX_USERCOPY_SLABS
78898+ trace_kfree(_RET_IP_, b);
78899+#else
78900 trace_kmem_cache_free(_RET_IP_, b);
78901+#endif
78902+
78903 }
78904 EXPORT_SYMBOL(kmem_cache_free);
78905
78906diff --git a/mm/slub.c b/mm/slub.c
78907index ba2ca53..00b1f4e 100644
78908--- a/mm/slub.c
78909+++ b/mm/slub.c
78910@@ -197,7 +197,7 @@ struct track {
78911
78912 enum track_item { TRACK_ALLOC, TRACK_FREE };
78913
78914-#ifdef CONFIG_SYSFS
78915+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78916 static int sysfs_slab_add(struct kmem_cache *);
78917 static int sysfs_slab_alias(struct kmem_cache *, const char *);
78918 static void sysfs_slab_remove(struct kmem_cache *);
78919@@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
78920 if (!t->addr)
78921 return;
78922
78923- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
78924+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
78925 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
78926 #ifdef CONFIG_STACKTRACE
78927 {
78928@@ -2653,7 +2653,7 @@ static int slub_min_objects;
78929 * Merge control. If this is set then no merging of slab caches will occur.
78930 * (Could be removed. This was introduced to pacify the merge skeptics.)
78931 */
78932-static int slub_nomerge;
78933+static int slub_nomerge = 1;
78934
78935 /*
78936 * Calculate the order of allocation given an slab object size.
78937@@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
78938 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
78939 #endif
78940
78941+#ifdef CONFIG_PAX_USERCOPY_SLABS
78942+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
78943+#endif
78944+
78945 static int __init setup_slub_min_order(char *str)
78946 {
78947 get_option(&str, &slub_min_order);
78948@@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
78949 return kmalloc_dma_caches[index];
78950
78951 #endif
78952+
78953+#ifdef CONFIG_PAX_USERCOPY_SLABS
78954+ if (flags & SLAB_USERCOPY)
78955+ return kmalloc_usercopy_caches[index];
78956+
78957+#endif
78958+
78959 return kmalloc_caches[index];
78960 }
78961
78962@@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
78963 EXPORT_SYMBOL(__kmalloc_node);
78964 #endif
78965
78966+bool is_usercopy_object(const void *ptr)
78967+{
78968+ struct page *page;
78969+ struct kmem_cache *s;
78970+
78971+ if (ZERO_OR_NULL_PTR(ptr))
78972+ return false;
78973+
78974+ if (!slab_is_available())
78975+ return false;
78976+
78977+ if (!virt_addr_valid(ptr))
78978+ return false;
78979+
78980+ page = virt_to_head_page(ptr);
78981+
78982+ if (!PageSlab(page))
78983+ return false;
78984+
78985+ s = page->slab_cache;
78986+ return s->flags & SLAB_USERCOPY;
78987+}
78988+
78989+#ifdef CONFIG_PAX_USERCOPY
78990+const char *check_heap_object(const void *ptr, unsigned long n)
78991+{
78992+ struct page *page;
78993+ struct kmem_cache *s;
78994+ unsigned long offset;
78995+
78996+ if (ZERO_OR_NULL_PTR(ptr))
78997+ return "<null>";
78998+
78999+ if (!virt_addr_valid(ptr))
79000+ return NULL;
79001+
79002+ page = virt_to_head_page(ptr);
79003+
79004+ if (!PageSlab(page))
79005+ return NULL;
79006+
79007+ s = page->slab_cache;
79008+ if (!(s->flags & SLAB_USERCOPY))
79009+ return s->name;
79010+
79011+ offset = (ptr - page_address(page)) % s->size;
79012+ if (offset <= s->object_size && n <= s->object_size - offset)
79013+ return NULL;
79014+
79015+ return s->name;
79016+}
79017+#endif
79018+
79019 size_t ksize(const void *object)
79020 {
79021 struct page *page;
79022@@ -3712,17 +3776,17 @@ void __init kmem_cache_init(void)
79023
79024 /* Caches that are not of the two-to-the-power-of size */
79025 if (KMALLOC_MIN_SIZE <= 32) {
79026- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
79027+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
79028 caches++;
79029 }
79030
79031 if (KMALLOC_MIN_SIZE <= 64) {
79032- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
79033+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
79034 caches++;
79035 }
79036
79037 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
79038- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
79039+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
79040 caches++;
79041 }
79042
79043@@ -3764,6 +3828,22 @@ void __init kmem_cache_init(void)
79044 }
79045 }
79046 #endif
79047+
79048+#ifdef CONFIG_PAX_USERCOPY_SLABS
79049+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
79050+ struct kmem_cache *s = kmalloc_caches[i];
79051+
79052+ if (s && s->size) {
79053+ char *name = kasprintf(GFP_NOWAIT,
79054+ "usercopy-kmalloc-%d", s->object_size);
79055+
79056+ BUG_ON(!name);
79057+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
79058+ s->object_size, SLAB_USERCOPY);
79059+ }
79060+ }
79061+#endif
79062+
79063 printk(KERN_INFO
79064 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
79065 " CPUs=%d, Nodes=%d\n",
79066@@ -3790,7 +3870,7 @@ static int slab_unmergeable(struct kmem_cache *s)
79067 /*
79068 * We may have set a slab to be unmergeable during bootstrap.
79069 */
79070- if (s->refcount < 0)
79071+ if (atomic_read(&s->refcount) < 0)
79072 return 1;
79073
79074 return 0;
79075@@ -3848,7 +3928,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
79076
79077 s = find_mergeable(memcg, size, align, flags, name, ctor);
79078 if (s) {
79079- s->refcount++;
79080+ atomic_inc(&s->refcount);
79081 /*
79082 * Adjust the object sizes so that we clear
79083 * the complete object on kzalloc.
79084@@ -3857,7 +3937,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
79085 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
79086
79087 if (sysfs_slab_alias(s, name)) {
79088- s->refcount--;
79089+ atomic_dec(&s->refcount);
79090 s = NULL;
79091 }
79092 }
79093@@ -3919,7 +3999,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
79094 return NOTIFY_OK;
79095 }
79096
79097-static struct notifier_block __cpuinitdata slab_notifier = {
79098+static struct notifier_block slab_notifier = {
79099 .notifier_call = slab_cpuup_callback
79100 };
79101
79102@@ -3977,7 +4057,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
79103 }
79104 #endif
79105
79106-#ifdef CONFIG_SYSFS
79107+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79108 static int count_inuse(struct page *page)
79109 {
79110 return page->inuse;
79111@@ -4364,12 +4444,12 @@ static void resiliency_test(void)
79112 validate_slab_cache(kmalloc_caches[9]);
79113 }
79114 #else
79115-#ifdef CONFIG_SYSFS
79116+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79117 static void resiliency_test(void) {};
79118 #endif
79119 #endif
79120
79121-#ifdef CONFIG_SYSFS
79122+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79123 enum slab_stat_type {
79124 SL_ALL, /* All slabs */
79125 SL_PARTIAL, /* Only partially allocated slabs */
79126@@ -4613,7 +4693,7 @@ SLAB_ATTR_RO(ctor);
79127
79128 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
79129 {
79130- return sprintf(buf, "%d\n", s->refcount - 1);
79131+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
79132 }
79133 SLAB_ATTR_RO(aliases);
79134
79135@@ -5266,6 +5346,7 @@ static char *create_unique_id(struct kmem_cache *s)
79136 return name;
79137 }
79138
79139+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79140 static int sysfs_slab_add(struct kmem_cache *s)
79141 {
79142 int err;
79143@@ -5323,6 +5404,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
79144 kobject_del(&s->kobj);
79145 kobject_put(&s->kobj);
79146 }
79147+#endif
79148
79149 /*
79150 * Need to buffer aliases during bootup until sysfs becomes
79151@@ -5336,6 +5418,7 @@ struct saved_alias {
79152
79153 static struct saved_alias *alias_list;
79154
79155+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79156 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
79157 {
79158 struct saved_alias *al;
79159@@ -5358,6 +5441,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
79160 alias_list = al;
79161 return 0;
79162 }
79163+#endif
79164
79165 static int __init slab_sysfs_init(void)
79166 {
79167diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
79168index 1b7e22a..3fcd4f3 100644
79169--- a/mm/sparse-vmemmap.c
79170+++ b/mm/sparse-vmemmap.c
79171@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
79172 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
79173 if (!p)
79174 return NULL;
79175- pud_populate(&init_mm, pud, p);
79176+ pud_populate_kernel(&init_mm, pud, p);
79177 }
79178 return pud;
79179 }
79180@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
79181 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
79182 if (!p)
79183 return NULL;
79184- pgd_populate(&init_mm, pgd, p);
79185+ pgd_populate_kernel(&init_mm, pgd, p);
79186 }
79187 return pgd;
79188 }
79189diff --git a/mm/sparse.c b/mm/sparse.c
79190index 6b5fb76..db0c190 100644
79191--- a/mm/sparse.c
79192+++ b/mm/sparse.c
79193@@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
79194
79195 for (i = 0; i < PAGES_PER_SECTION; i++) {
79196 if (PageHWPoison(&memmap[i])) {
79197- atomic_long_sub(1, &mce_bad_pages);
79198+ atomic_long_sub_unchecked(1, &mce_bad_pages);
79199 ClearPageHWPoison(&memmap[i]);
79200 }
79201 }
79202diff --git a/mm/swap.c b/mm/swap.c
79203index 6310dc2..3662b3f 100644
79204--- a/mm/swap.c
79205+++ b/mm/swap.c
79206@@ -30,6 +30,7 @@
79207 #include <linux/backing-dev.h>
79208 #include <linux/memcontrol.h>
79209 #include <linux/gfp.h>
79210+#include <linux/hugetlb.h>
79211
79212 #include "internal.h"
79213
79214@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
79215
79216 __page_cache_release(page);
79217 dtor = get_compound_page_dtor(page);
79218+ if (!PageHuge(page))
79219+ BUG_ON(dtor != free_compound_page);
79220 (*dtor)(page);
79221 }
79222
79223diff --git a/mm/swapfile.c b/mm/swapfile.c
79224index e97a0e5..b50e796 100644
79225--- a/mm/swapfile.c
79226+++ b/mm/swapfile.c
79227@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
79228
79229 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
79230 /* Activity counter to indicate that a swapon or swapoff has occurred */
79231-static atomic_t proc_poll_event = ATOMIC_INIT(0);
79232+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
79233
79234 static inline unsigned char swap_count(unsigned char ent)
79235 {
79236@@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
79237 }
79238 filp_close(swap_file, NULL);
79239 err = 0;
79240- atomic_inc(&proc_poll_event);
79241+ atomic_inc_unchecked(&proc_poll_event);
79242 wake_up_interruptible(&proc_poll_wait);
79243
79244 out_dput:
79245@@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
79246
79247 poll_wait(file, &proc_poll_wait, wait);
79248
79249- if (seq->poll_event != atomic_read(&proc_poll_event)) {
79250- seq->poll_event = atomic_read(&proc_poll_event);
79251+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
79252+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
79253 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
79254 }
79255
79256@@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
79257 return ret;
79258
79259 seq = file->private_data;
79260- seq->poll_event = atomic_read(&proc_poll_event);
79261+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
79262 return 0;
79263 }
79264
79265@@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
79266 (frontswap_map) ? "FS" : "");
79267
79268 mutex_unlock(&swapon_mutex);
79269- atomic_inc(&proc_poll_event);
79270+ atomic_inc_unchecked(&proc_poll_event);
79271 wake_up_interruptible(&proc_poll_wait);
79272
79273 if (S_ISREG(inode->i_mode))
79274diff --git a/mm/util.c b/mm/util.c
79275index c55e26b..3f913a9 100644
79276--- a/mm/util.c
79277+++ b/mm/util.c
79278@@ -292,6 +292,12 @@ done:
79279 void arch_pick_mmap_layout(struct mm_struct *mm)
79280 {
79281 mm->mmap_base = TASK_UNMAPPED_BASE;
79282+
79283+#ifdef CONFIG_PAX_RANDMMAP
79284+ if (mm->pax_flags & MF_PAX_RANDMMAP)
79285+ mm->mmap_base += mm->delta_mmap;
79286+#endif
79287+
79288 mm->get_unmapped_area = arch_get_unmapped_area;
79289 mm->unmap_area = arch_unmap_area;
79290 }
79291diff --git a/mm/vmalloc.c b/mm/vmalloc.c
79292index 5123a16..f234a48 100644
79293--- a/mm/vmalloc.c
79294+++ b/mm/vmalloc.c
79295@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
79296
79297 pte = pte_offset_kernel(pmd, addr);
79298 do {
79299- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79300- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79301+
79302+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79303+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
79304+ BUG_ON(!pte_exec(*pte));
79305+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
79306+ continue;
79307+ }
79308+#endif
79309+
79310+ {
79311+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79312+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79313+ }
79314 } while (pte++, addr += PAGE_SIZE, addr != end);
79315 }
79316
79317@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
79318 pte = pte_alloc_kernel(pmd, addr);
79319 if (!pte)
79320 return -ENOMEM;
79321+
79322+ pax_open_kernel();
79323 do {
79324 struct page *page = pages[*nr];
79325
79326- if (WARN_ON(!pte_none(*pte)))
79327+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79328+ if (pgprot_val(prot) & _PAGE_NX)
79329+#endif
79330+
79331+ if (!pte_none(*pte)) {
79332+ pax_close_kernel();
79333+ WARN_ON(1);
79334 return -EBUSY;
79335- if (WARN_ON(!page))
79336+ }
79337+ if (!page) {
79338+ pax_close_kernel();
79339+ WARN_ON(1);
79340 return -ENOMEM;
79341+ }
79342 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
79343 (*nr)++;
79344 } while (pte++, addr += PAGE_SIZE, addr != end);
79345+ pax_close_kernel();
79346 return 0;
79347 }
79348
79349@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
79350 pmd_t *pmd;
79351 unsigned long next;
79352
79353- pmd = pmd_alloc(&init_mm, pud, addr);
79354+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
79355 if (!pmd)
79356 return -ENOMEM;
79357 do {
79358@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
79359 pud_t *pud;
79360 unsigned long next;
79361
79362- pud = pud_alloc(&init_mm, pgd, addr);
79363+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
79364 if (!pud)
79365 return -ENOMEM;
79366 do {
79367@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
79368 * and fall back on vmalloc() if that fails. Others
79369 * just put it in the vmalloc space.
79370 */
79371-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
79372+#ifdef CONFIG_MODULES
79373+#ifdef MODULES_VADDR
79374 unsigned long addr = (unsigned long)x;
79375 if (addr >= MODULES_VADDR && addr < MODULES_END)
79376 return 1;
79377 #endif
79378+
79379+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79380+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
79381+ return 1;
79382+#endif
79383+
79384+#endif
79385+
79386 return is_vmalloc_addr(x);
79387 }
79388
79389@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
79390
79391 if (!pgd_none(*pgd)) {
79392 pud_t *pud = pud_offset(pgd, addr);
79393+#ifdef CONFIG_X86
79394+ if (!pud_large(*pud))
79395+#endif
79396 if (!pud_none(*pud)) {
79397 pmd_t *pmd = pmd_offset(pud, addr);
79398+#ifdef CONFIG_X86
79399+ if (!pmd_large(*pmd))
79400+#endif
79401 if (!pmd_none(*pmd)) {
79402 pte_t *ptep, pte;
79403
79404@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
79405 * Allocate a region of KVA of the specified size and alignment, within the
79406 * vstart and vend.
79407 */
79408-static struct vmap_area *alloc_vmap_area(unsigned long size,
79409+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
79410 unsigned long align,
79411 unsigned long vstart, unsigned long vend,
79412 int node, gfp_t gfp_mask)
79413@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
79414 struct vm_struct *area;
79415
79416 BUG_ON(in_interrupt());
79417+
79418+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79419+ if (flags & VM_KERNEXEC) {
79420+ if (start != VMALLOC_START || end != VMALLOC_END)
79421+ return NULL;
79422+ start = (unsigned long)MODULES_EXEC_VADDR;
79423+ end = (unsigned long)MODULES_EXEC_END;
79424+ }
79425+#endif
79426+
79427 if (flags & VM_IOREMAP) {
79428 int bit = fls(size);
79429
79430@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
79431 if (count > totalram_pages)
79432 return NULL;
79433
79434+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79435+ if (!(pgprot_val(prot) & _PAGE_NX))
79436+ flags |= VM_KERNEXEC;
79437+#endif
79438+
79439 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
79440 __builtin_return_address(0));
79441 if (!area)
79442@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
79443 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
79444 goto fail;
79445
79446+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79447+ if (!(pgprot_val(prot) & _PAGE_NX))
79448+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
79449+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
79450+ else
79451+#endif
79452+
79453 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
79454 start, end, node, gfp_mask, caller);
79455 if (!area)
79456@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
79457 * For tight control over page level allocator and protection flags
79458 * use __vmalloc() instead.
79459 */
79460-
79461 void *vmalloc_exec(unsigned long size)
79462 {
79463- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
79464+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
79465 -1, __builtin_return_address(0));
79466 }
79467
79468@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
79469 unsigned long uaddr = vma->vm_start;
79470 unsigned long usize = vma->vm_end - vma->vm_start;
79471
79472+ BUG_ON(vma->vm_mirror);
79473+
79474 if ((PAGE_SIZE-1) & (unsigned long)addr)
79475 return -EINVAL;
79476
79477@@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
79478 v->addr, v->addr + v->size, v->size);
79479
79480 if (v->caller)
79481+#ifdef CONFIG_GRKERNSEC_HIDESYM
79482+ seq_printf(m, " %pK", v->caller);
79483+#else
79484 seq_printf(m, " %pS", v->caller);
79485+#endif
79486
79487 if (v->nr_pages)
79488 seq_printf(m, " pages=%d", v->nr_pages);
79489diff --git a/mm/vmstat.c b/mm/vmstat.c
79490index 9800306..76b4b27 100644
79491--- a/mm/vmstat.c
79492+++ b/mm/vmstat.c
79493@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
79494 *
79495 * vm_stat contains the global counters
79496 */
79497-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
79498+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
79499 EXPORT_SYMBOL(vm_stat);
79500
79501 #ifdef CONFIG_SMP
79502@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
79503 v = p->vm_stat_diff[i];
79504 p->vm_stat_diff[i] = 0;
79505 local_irq_restore(flags);
79506- atomic_long_add(v, &zone->vm_stat[i]);
79507+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
79508 global_diff[i] += v;
79509 #ifdef CONFIG_NUMA
79510 /* 3 seconds idle till flush */
79511@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
79512
79513 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
79514 if (global_diff[i])
79515- atomic_long_add(global_diff[i], &vm_stat[i]);
79516+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
79517 }
79518
79519 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
79520@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
79521 if (pset->vm_stat_diff[i]) {
79522 int v = pset->vm_stat_diff[i];
79523 pset->vm_stat_diff[i] = 0;
79524- atomic_long_add(v, &zone->vm_stat[i]);
79525- atomic_long_add(v, &vm_stat[i]);
79526+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
79527+ atomic_long_add_unchecked(v, &vm_stat[i]);
79528 }
79529 }
79530 #endif
79531@@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
79532 return NOTIFY_OK;
79533 }
79534
79535-static struct notifier_block __cpuinitdata vmstat_notifier =
79536+static struct notifier_block vmstat_notifier =
79537 { &vmstat_cpuup_callback, NULL, 0 };
79538 #endif
79539
79540@@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
79541 start_cpu_timer(cpu);
79542 #endif
79543 #ifdef CONFIG_PROC_FS
79544- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
79545- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
79546- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
79547- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
79548+ {
79549+ mode_t gr_mode = S_IRUGO;
79550+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79551+ gr_mode = S_IRUSR;
79552+#endif
79553+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
79554+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
79555+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79556+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
79557+#else
79558+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
79559+#endif
79560+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
79561+ }
79562 #endif
79563 return 0;
79564 }
79565diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
79566index a292e80..785ee68 100644
79567--- a/net/8021q/vlan.c
79568+++ b/net/8021q/vlan.c
79569@@ -485,7 +485,7 @@ out:
79570 return NOTIFY_DONE;
79571 }
79572
79573-static struct notifier_block vlan_notifier_block __read_mostly = {
79574+static struct notifier_block vlan_notifier_block = {
79575 .notifier_call = vlan_device_event,
79576 };
79577
79578@@ -560,8 +560,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
79579 err = -EPERM;
79580 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
79581 break;
79582- if ((args.u.name_type >= 0) &&
79583- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
79584+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
79585 struct vlan_net *vn;
79586
79587 vn = net_generic(net, vlan_net_id);
79588diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
79589index 02efb25..41541a9 100644
79590--- a/net/9p/trans_fd.c
79591+++ b/net/9p/trans_fd.c
79592@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
79593 oldfs = get_fs();
79594 set_fs(get_ds());
79595 /* The cast to a user pointer is valid due to the set_fs() */
79596- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
79597+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
79598 set_fs(oldfs);
79599
79600 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
79601diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
79602index 876fbe8..8bbea9f 100644
79603--- a/net/atm/atm_misc.c
79604+++ b/net/atm/atm_misc.c
79605@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
79606 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
79607 return 1;
79608 atm_return(vcc, truesize);
79609- atomic_inc(&vcc->stats->rx_drop);
79610+ atomic_inc_unchecked(&vcc->stats->rx_drop);
79611 return 0;
79612 }
79613 EXPORT_SYMBOL(atm_charge);
79614@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
79615 }
79616 }
79617 atm_return(vcc, guess);
79618- atomic_inc(&vcc->stats->rx_drop);
79619+ atomic_inc_unchecked(&vcc->stats->rx_drop);
79620 return NULL;
79621 }
79622 EXPORT_SYMBOL(atm_alloc_charge);
79623@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
79624
79625 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
79626 {
79627-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79628+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79629 __SONET_ITEMS
79630 #undef __HANDLE_ITEM
79631 }
79632@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
79633
79634 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
79635 {
79636-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
79637+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
79638 __SONET_ITEMS
79639 #undef __HANDLE_ITEM
79640 }
79641diff --git a/net/atm/lec.h b/net/atm/lec.h
79642index a86aff9..3a0d6f6 100644
79643--- a/net/atm/lec.h
79644+++ b/net/atm/lec.h
79645@@ -48,7 +48,7 @@ struct lane2_ops {
79646 const u8 *tlvs, u32 sizeoftlvs);
79647 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
79648 const u8 *tlvs, u32 sizeoftlvs);
79649-};
79650+} __no_const;
79651
79652 /*
79653 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
79654diff --git a/net/atm/proc.c b/net/atm/proc.c
79655index 0d020de..011c7bb 100644
79656--- a/net/atm/proc.c
79657+++ b/net/atm/proc.c
79658@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
79659 const struct k_atm_aal_stats *stats)
79660 {
79661 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
79662- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
79663- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
79664- atomic_read(&stats->rx_drop));
79665+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
79666+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
79667+ atomic_read_unchecked(&stats->rx_drop));
79668 }
79669
79670 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
79671diff --git a/net/atm/resources.c b/net/atm/resources.c
79672index 0447d5d..3cf4728 100644
79673--- a/net/atm/resources.c
79674+++ b/net/atm/resources.c
79675@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
79676 static void copy_aal_stats(struct k_atm_aal_stats *from,
79677 struct atm_aal_stats *to)
79678 {
79679-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79680+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79681 __AAL_STAT_ITEMS
79682 #undef __HANDLE_ITEM
79683 }
79684@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
79685 static void subtract_aal_stats(struct k_atm_aal_stats *from,
79686 struct atm_aal_stats *to)
79687 {
79688-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
79689+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
79690 __AAL_STAT_ITEMS
79691 #undef __HANDLE_ITEM
79692 }
79693diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
79694index 7d02ebd..4d4cc01 100644
79695--- a/net/batman-adv/bat_iv_ogm.c
79696+++ b/net/batman-adv/bat_iv_ogm.c
79697@@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
79698
79699 /* randomize initial seqno to avoid collision */
79700 get_random_bytes(&random_seqno, sizeof(random_seqno));
79701- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
79702+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
79703
79704 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
79705 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
79706@@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
79707 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
79708
79709 /* change sequence number to network order */
79710- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
79711+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
79712 batadv_ogm_packet->seqno = htonl(seqno);
79713- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
79714+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
79715
79716 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
79717 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
79718@@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
79719 return;
79720
79721 /* could be changed by schedule_own_packet() */
79722- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
79723+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
79724
79725 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
79726 has_directlink_flag = 1;
79727diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
79728index f1d37cd..4190879 100644
79729--- a/net/batman-adv/hard-interface.c
79730+++ b/net/batman-adv/hard-interface.c
79731@@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
79732 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
79733 dev_add_pack(&hard_iface->batman_adv_ptype);
79734
79735- atomic_set(&hard_iface->frag_seqno, 1);
79736+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
79737 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
79738 hard_iface->net_dev->name);
79739
79740@@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
79741 /* This can't be called via a bat_priv callback because
79742 * we have no bat_priv yet.
79743 */
79744- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
79745+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
79746 hard_iface->bat_iv.ogm_buff = NULL;
79747
79748 return hard_iface;
79749diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
79750index 6b548fd..fc32c8d 100644
79751--- a/net/batman-adv/soft-interface.c
79752+++ b/net/batman-adv/soft-interface.c
79753@@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
79754 primary_if->net_dev->dev_addr, ETH_ALEN);
79755
79756 /* set broadcast sequence number */
79757- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
79758+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
79759 bcast_packet->seqno = htonl(seqno);
79760
79761 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
79762@@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
79763 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
79764
79765 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
79766- atomic_set(&bat_priv->bcast_seqno, 1);
79767+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
79768 atomic_set(&bat_priv->tt.vn, 0);
79769 atomic_set(&bat_priv->tt.local_changes, 0);
79770 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
79771diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
79772index ae9ac9a..11e0fe7 100644
79773--- a/net/batman-adv/types.h
79774+++ b/net/batman-adv/types.h
79775@@ -48,7 +48,7 @@
79776 struct batadv_hard_iface_bat_iv {
79777 unsigned char *ogm_buff;
79778 int ogm_buff_len;
79779- atomic_t ogm_seqno;
79780+ atomic_unchecked_t ogm_seqno;
79781 };
79782
79783 struct batadv_hard_iface {
79784@@ -56,7 +56,7 @@ struct batadv_hard_iface {
79785 int16_t if_num;
79786 char if_status;
79787 struct net_device *net_dev;
79788- atomic_t frag_seqno;
79789+ atomic_unchecked_t frag_seqno;
79790 struct kobject *hardif_obj;
79791 atomic_t refcount;
79792 struct packet_type batman_adv_ptype;
79793@@ -284,7 +284,7 @@ struct batadv_priv {
79794 atomic_t orig_interval; /* uint */
79795 atomic_t hop_penalty; /* uint */
79796 atomic_t log_level; /* uint */
79797- atomic_t bcast_seqno;
79798+ atomic_unchecked_t bcast_seqno;
79799 atomic_t bcast_queue_left;
79800 atomic_t batman_queue_left;
79801 char num_ifaces;
79802diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
79803index 10aff49..ea8e021 100644
79804--- a/net/batman-adv/unicast.c
79805+++ b/net/batman-adv/unicast.c
79806@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
79807 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
79808 frag2->flags = large_tail;
79809
79810- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
79811+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
79812 frag1->seqno = htons(seqno - 1);
79813 frag2->seqno = htons(seqno);
79814
79815diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
79816index 07f0739..3c42e34 100644
79817--- a/net/bluetooth/hci_sock.c
79818+++ b/net/bluetooth/hci_sock.c
79819@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
79820 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
79821 }
79822
79823- len = min_t(unsigned int, len, sizeof(uf));
79824+ len = min((size_t)len, sizeof(uf));
79825 if (copy_from_user(&uf, optval, len)) {
79826 err = -EFAULT;
79827 break;
79828diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
79829index 22e6583..426e2f3 100644
79830--- a/net/bluetooth/l2cap_core.c
79831+++ b/net/bluetooth/l2cap_core.c
79832@@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
79833 break;
79834
79835 case L2CAP_CONF_RFC:
79836- if (olen == sizeof(rfc))
79837- memcpy(&rfc, (void *)val, olen);
79838+ if (olen != sizeof(rfc))
79839+ break;
79840+
79841+ memcpy(&rfc, (void *)val, olen);
79842
79843 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
79844 rfc.mode != chan->mode)
79845diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
79846index 1bcfb84..dad9f98 100644
79847--- a/net/bluetooth/l2cap_sock.c
79848+++ b/net/bluetooth/l2cap_sock.c
79849@@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
79850 struct sock *sk = sock->sk;
79851 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
79852 struct l2cap_options opts;
79853- int len, err = 0;
79854+ int err = 0;
79855+ size_t len = optlen;
79856 u32 opt;
79857
79858 BT_DBG("sk %p", sk);
79859@@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
79860 opts.max_tx = chan->max_tx;
79861 opts.txwin_size = chan->tx_win;
79862
79863- len = min_t(unsigned int, sizeof(opts), optlen);
79864+ len = min(sizeof(opts), len);
79865 if (copy_from_user((char *) &opts, optval, len)) {
79866 err = -EFAULT;
79867 break;
79868@@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
79869 struct bt_security sec;
79870 struct bt_power pwr;
79871 struct l2cap_conn *conn;
79872- int len, err = 0;
79873+ int err = 0;
79874+ size_t len = optlen;
79875 u32 opt;
79876
79877 BT_DBG("sk %p", sk);
79878@@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
79879
79880 sec.level = BT_SECURITY_LOW;
79881
79882- len = min_t(unsigned int, sizeof(sec), optlen);
79883+ len = min(sizeof(sec), len);
79884 if (copy_from_user((char *) &sec, optval, len)) {
79885 err = -EFAULT;
79886 break;
79887@@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
79888
79889 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
79890
79891- len = min_t(unsigned int, sizeof(pwr), optlen);
79892+ len = min(sizeof(pwr), len);
79893 if (copy_from_user((char *) &pwr, optval, len)) {
79894 err = -EFAULT;
79895 break;
79896diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
79897index ce3f665..2c7d08f 100644
79898--- a/net/bluetooth/rfcomm/sock.c
79899+++ b/net/bluetooth/rfcomm/sock.c
79900@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
79901 struct sock *sk = sock->sk;
79902 struct bt_security sec;
79903 int err = 0;
79904- size_t len;
79905+ size_t len = optlen;
79906 u32 opt;
79907
79908 BT_DBG("sk %p", sk);
79909@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
79910
79911 sec.level = BT_SECURITY_LOW;
79912
79913- len = min_t(unsigned int, sizeof(sec), optlen);
79914+ len = min(sizeof(sec), len);
79915 if (copy_from_user((char *) &sec, optval, len)) {
79916 err = -EFAULT;
79917 break;
79918diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
79919index bd6fd0f..6492cba 100644
79920--- a/net/bluetooth/rfcomm/tty.c
79921+++ b/net/bluetooth/rfcomm/tty.c
79922@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
79923 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
79924
79925 spin_lock_irqsave(&dev->port.lock, flags);
79926- if (dev->port.count > 0) {
79927+ if (atomic_read(&dev->port.count) > 0) {
79928 spin_unlock_irqrestore(&dev->port.lock, flags);
79929 return;
79930 }
79931@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
79932 return -ENODEV;
79933
79934 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
79935- dev->channel, dev->port.count);
79936+ dev->channel, atomic_read(&dev->port.count));
79937
79938 spin_lock_irqsave(&dev->port.lock, flags);
79939- if (++dev->port.count > 1) {
79940+ if (atomic_inc_return(&dev->port.count) > 1) {
79941 spin_unlock_irqrestore(&dev->port.lock, flags);
79942 return 0;
79943 }
79944@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
79945 return;
79946
79947 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
79948- dev->port.count);
79949+ atomic_read(&dev->port.count));
79950
79951 spin_lock_irqsave(&dev->port.lock, flags);
79952- if (!--dev->port.count) {
79953+ if (!atomic_dec_return(&dev->port.count)) {
79954 spin_unlock_irqrestore(&dev->port.lock, flags);
79955 if (dev->tty_dev->parent)
79956 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
79957diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
79958index 5fe2ff3..121d696 100644
79959--- a/net/bridge/netfilter/ebtables.c
79960+++ b/net/bridge/netfilter/ebtables.c
79961@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79962 tmp.valid_hooks = t->table->valid_hooks;
79963 }
79964 mutex_unlock(&ebt_mutex);
79965- if (copy_to_user(user, &tmp, *len) != 0){
79966+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
79967 BUGPRINT("c2u Didn't work\n");
79968 ret = -EFAULT;
79969 break;
79970@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
79971 goto out;
79972 tmp.valid_hooks = t->valid_hooks;
79973
79974- if (copy_to_user(user, &tmp, *len) != 0) {
79975+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
79976 ret = -EFAULT;
79977 break;
79978 }
79979@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
79980 tmp.entries_size = t->table->entries_size;
79981 tmp.valid_hooks = t->table->valid_hooks;
79982
79983- if (copy_to_user(user, &tmp, *len) != 0) {
79984+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
79985 ret = -EFAULT;
79986 break;
79987 }
79988diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
79989index a376ec1..1fbd6be 100644
79990--- a/net/caif/cfctrl.c
79991+++ b/net/caif/cfctrl.c
79992@@ -10,6 +10,7 @@
79993 #include <linux/spinlock.h>
79994 #include <linux/slab.h>
79995 #include <linux/pkt_sched.h>
79996+#include <linux/sched.h>
79997 #include <net/caif/caif_layer.h>
79998 #include <net/caif/cfpkt.h>
79999 #include <net/caif/cfctrl.h>
80000@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
80001 memset(&dev_info, 0, sizeof(dev_info));
80002 dev_info.id = 0xff;
80003 cfsrvl_init(&this->serv, 0, &dev_info, false);
80004- atomic_set(&this->req_seq_no, 1);
80005- atomic_set(&this->rsp_seq_no, 1);
80006+ atomic_set_unchecked(&this->req_seq_no, 1);
80007+ atomic_set_unchecked(&this->rsp_seq_no, 1);
80008 this->serv.layer.receive = cfctrl_recv;
80009 sprintf(this->serv.layer.name, "ctrl");
80010 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
80011@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
80012 struct cfctrl_request_info *req)
80013 {
80014 spin_lock_bh(&ctrl->info_list_lock);
80015- atomic_inc(&ctrl->req_seq_no);
80016- req->sequence_no = atomic_read(&ctrl->req_seq_no);
80017+ atomic_inc_unchecked(&ctrl->req_seq_no);
80018+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
80019 list_add_tail(&req->list, &ctrl->list);
80020 spin_unlock_bh(&ctrl->info_list_lock);
80021 }
80022@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
80023 if (p != first)
80024 pr_warn("Requests are not received in order\n");
80025
80026- atomic_set(&ctrl->rsp_seq_no,
80027+ atomic_set_unchecked(&ctrl->rsp_seq_no,
80028 p->sequence_no);
80029 list_del(&p->list);
80030 goto out;
80031diff --git a/net/can/af_can.c b/net/can/af_can.c
80032index ddac1ee..3ee0a78 100644
80033--- a/net/can/af_can.c
80034+++ b/net/can/af_can.c
80035@@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
80036 };
80037
80038 /* notifier block for netdevice event */
80039-static struct notifier_block can_netdev_notifier __read_mostly = {
80040+static struct notifier_block can_netdev_notifier = {
80041 .notifier_call = can_notifier,
80042 };
80043
80044diff --git a/net/can/gw.c b/net/can/gw.c
80045index 574dda78e..3d2b3da 100644
80046--- a/net/can/gw.c
80047+++ b/net/can/gw.c
80048@@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
80049 MODULE_ALIAS("can-gw");
80050
80051 static HLIST_HEAD(cgw_list);
80052-static struct notifier_block notifier;
80053
80054 static struct kmem_cache *cgw_cache __read_mostly;
80055
80056@@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
80057 return err;
80058 }
80059
80060+static struct notifier_block notifier = {
80061+ .notifier_call = cgw_notifier
80062+};
80063+
80064 static __init int cgw_module_init(void)
80065 {
80066 printk(banner);
80067@@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
80068 return -ENOMEM;
80069
80070 /* set notifier */
80071- notifier.notifier_call = cgw_notifier;
80072 register_netdevice_notifier(&notifier);
80073
80074 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
80075diff --git a/net/compat.c b/net/compat.c
80076index 79ae884..17c5c09 100644
80077--- a/net/compat.c
80078+++ b/net/compat.c
80079@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
80080 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
80081 __get_user(kmsg->msg_flags, &umsg->msg_flags))
80082 return -EFAULT;
80083- kmsg->msg_name = compat_ptr(tmp1);
80084- kmsg->msg_iov = compat_ptr(tmp2);
80085- kmsg->msg_control = compat_ptr(tmp3);
80086+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
80087+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
80088+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
80089 return 0;
80090 }
80091
80092@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
80093
80094 if (kern_msg->msg_namelen) {
80095 if (mode == VERIFY_READ) {
80096- int err = move_addr_to_kernel(kern_msg->msg_name,
80097+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
80098 kern_msg->msg_namelen,
80099 kern_address);
80100 if (err < 0)
80101@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
80102 kern_msg->msg_name = NULL;
80103
80104 tot_len = iov_from_user_compat_to_kern(kern_iov,
80105- (struct compat_iovec __user *)kern_msg->msg_iov,
80106+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
80107 kern_msg->msg_iovlen);
80108 if (tot_len >= 0)
80109 kern_msg->msg_iov = kern_iov;
80110@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
80111
80112 #define CMSG_COMPAT_FIRSTHDR(msg) \
80113 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
80114- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
80115+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
80116 (struct compat_cmsghdr __user *)NULL)
80117
80118 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
80119 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
80120 (ucmlen) <= (unsigned long) \
80121 ((mhdr)->msg_controllen - \
80122- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
80123+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
80124
80125 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
80126 struct compat_cmsghdr __user *cmsg, int cmsg_len)
80127 {
80128 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
80129- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
80130+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
80131 msg->msg_controllen)
80132 return NULL;
80133 return (struct compat_cmsghdr __user *)ptr;
80134@@ -219,7 +219,7 @@ Efault:
80135
80136 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
80137 {
80138- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
80139+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
80140 struct compat_cmsghdr cmhdr;
80141 struct compat_timeval ctv;
80142 struct compat_timespec cts[3];
80143@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
80144
80145 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
80146 {
80147- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
80148+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
80149 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
80150 int fdnum = scm->fp->count;
80151 struct file **fp = scm->fp->fp;
80152@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
80153 return -EFAULT;
80154 old_fs = get_fs();
80155 set_fs(KERNEL_DS);
80156- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
80157+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
80158 set_fs(old_fs);
80159
80160 return err;
80161@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
80162 len = sizeof(ktime);
80163 old_fs = get_fs();
80164 set_fs(KERNEL_DS);
80165- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
80166+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
80167 set_fs(old_fs);
80168
80169 if (!err) {
80170@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80171 case MCAST_JOIN_GROUP:
80172 case MCAST_LEAVE_GROUP:
80173 {
80174- struct compat_group_req __user *gr32 = (void *)optval;
80175+ struct compat_group_req __user *gr32 = (void __user *)optval;
80176 struct group_req __user *kgr =
80177 compat_alloc_user_space(sizeof(struct group_req));
80178 u32 interface;
80179@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80180 case MCAST_BLOCK_SOURCE:
80181 case MCAST_UNBLOCK_SOURCE:
80182 {
80183- struct compat_group_source_req __user *gsr32 = (void *)optval;
80184+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
80185 struct group_source_req __user *kgsr = compat_alloc_user_space(
80186 sizeof(struct group_source_req));
80187 u32 interface;
80188@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80189 }
80190 case MCAST_MSFILTER:
80191 {
80192- struct compat_group_filter __user *gf32 = (void *)optval;
80193+ struct compat_group_filter __user *gf32 = (void __user *)optval;
80194 struct group_filter __user *kgf;
80195 u32 interface, fmode, numsrc;
80196
80197@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
80198 char __user *optval, int __user *optlen,
80199 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
80200 {
80201- struct compat_group_filter __user *gf32 = (void *)optval;
80202+ struct compat_group_filter __user *gf32 = (void __user *)optval;
80203 struct group_filter __user *kgf;
80204 int __user *koptlen;
80205 u32 interface, fmode, numsrc;
80206@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
80207
80208 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
80209 return -EINVAL;
80210- if (copy_from_user(a, args, nas[call]))
80211+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
80212 return -EFAULT;
80213 a0 = a[0];
80214 a1 = a[1];
80215diff --git a/net/core/datagram.c b/net/core/datagram.c
80216index 368f9c3..f82d4a3 100644
80217--- a/net/core/datagram.c
80218+++ b/net/core/datagram.c
80219@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
80220 }
80221
80222 kfree_skb(skb);
80223- atomic_inc(&sk->sk_drops);
80224+ atomic_inc_unchecked(&sk->sk_drops);
80225 sk_mem_reclaim_partial(sk);
80226
80227 return err;
80228diff --git a/net/core/dev.c b/net/core/dev.c
80229index f64e439..8f959e6 100644
80230--- a/net/core/dev.c
80231+++ b/net/core/dev.c
80232@@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
80233 if (no_module && capable(CAP_NET_ADMIN))
80234 no_module = request_module("netdev-%s", name);
80235 if (no_module && capable(CAP_SYS_MODULE)) {
80236+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80237+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
80238+#else
80239 if (!request_module("%s", name))
80240 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
80241 name);
80242+#endif
80243 }
80244 }
80245 EXPORT_SYMBOL(dev_load);
80246@@ -1715,7 +1719,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
80247 {
80248 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
80249 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
80250- atomic_long_inc(&dev->rx_dropped);
80251+ atomic_long_inc_unchecked(&dev->rx_dropped);
80252 kfree_skb(skb);
80253 return NET_RX_DROP;
80254 }
80255@@ -1725,7 +1729,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
80256 nf_reset(skb);
80257
80258 if (unlikely(!is_skb_forwardable(dev, skb))) {
80259- atomic_long_inc(&dev->rx_dropped);
80260+ atomic_long_inc_unchecked(&dev->rx_dropped);
80261 kfree_skb(skb);
80262 return NET_RX_DROP;
80263 }
80264@@ -2180,7 +2184,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
80265
80266 struct dev_gso_cb {
80267 void (*destructor)(struct sk_buff *skb);
80268-};
80269+} __no_const;
80270
80271 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
80272
80273@@ -3053,7 +3057,7 @@ enqueue:
80274
80275 local_irq_restore(flags);
80276
80277- atomic_long_inc(&skb->dev->rx_dropped);
80278+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
80279 kfree_skb(skb);
80280 return NET_RX_DROP;
80281 }
80282@@ -3125,7 +3129,7 @@ int netif_rx_ni(struct sk_buff *skb)
80283 }
80284 EXPORT_SYMBOL(netif_rx_ni);
80285
80286-static void net_tx_action(struct softirq_action *h)
80287+static void net_tx_action(void)
80288 {
80289 struct softnet_data *sd = &__get_cpu_var(softnet_data);
80290
80291@@ -3456,7 +3460,7 @@ ncls:
80292 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
80293 } else {
80294 drop:
80295- atomic_long_inc(&skb->dev->rx_dropped);
80296+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
80297 kfree_skb(skb);
80298 /* Jamal, now you will not able to escape explaining
80299 * me how you were going to use this. :-)
80300@@ -4039,7 +4043,7 @@ void netif_napi_del(struct napi_struct *napi)
80301 }
80302 EXPORT_SYMBOL(netif_napi_del);
80303
80304-static void net_rx_action(struct softirq_action *h)
80305+static void net_rx_action(void)
80306 {
80307 struct softnet_data *sd = &__get_cpu_var(softnet_data);
80308 unsigned long time_limit = jiffies + 2;
80309@@ -4523,8 +4527,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
80310 else
80311 seq_printf(seq, "%04x", ntohs(pt->type));
80312
80313+#ifdef CONFIG_GRKERNSEC_HIDESYM
80314+ seq_printf(seq, " %-8s %p\n",
80315+ pt->dev ? pt->dev->name : "", NULL);
80316+#else
80317 seq_printf(seq, " %-8s %pF\n",
80318 pt->dev ? pt->dev->name : "", pt->func);
80319+#endif
80320 }
80321
80322 return 0;
80323@@ -6096,7 +6105,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
80324 } else {
80325 netdev_stats_to_stats64(storage, &dev->stats);
80326 }
80327- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
80328+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
80329 return storage;
80330 }
80331 EXPORT_SYMBOL(dev_get_stats);
80332diff --git a/net/core/flow.c b/net/core/flow.c
80333index b0901ee..7d3c2ca 100644
80334--- a/net/core/flow.c
80335+++ b/net/core/flow.c
80336@@ -61,7 +61,7 @@ struct flow_cache {
80337 struct timer_list rnd_timer;
80338 };
80339
80340-atomic_t flow_cache_genid = ATOMIC_INIT(0);
80341+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
80342 EXPORT_SYMBOL(flow_cache_genid);
80343 static struct flow_cache flow_cache_global;
80344 static struct kmem_cache *flow_cachep __read_mostly;
80345@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
80346
80347 static int flow_entry_valid(struct flow_cache_entry *fle)
80348 {
80349- if (atomic_read(&flow_cache_genid) != fle->genid)
80350+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
80351 return 0;
80352 if (fle->object && !fle->object->ops->check(fle->object))
80353 return 0;
80354@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
80355 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
80356 fcp->hash_count++;
80357 }
80358- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
80359+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
80360 flo = fle->object;
80361 if (!flo)
80362 goto ret_object;
80363@@ -280,7 +280,7 @@ nocache:
80364 }
80365 flo = resolver(net, key, family, dir, flo, ctx);
80366 if (fle) {
80367- fle->genid = atomic_read(&flow_cache_genid);
80368+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
80369 if (!IS_ERR(flo))
80370 fle->object = flo;
80371 else
80372diff --git a/net/core/iovec.c b/net/core/iovec.c
80373index 7e7aeb0..2a998cb 100644
80374--- a/net/core/iovec.c
80375+++ b/net/core/iovec.c
80376@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
80377 if (m->msg_namelen) {
80378 if (mode == VERIFY_READ) {
80379 void __user *namep;
80380- namep = (void __user __force *) m->msg_name;
80381+ namep = (void __force_user *) m->msg_name;
80382 err = move_addr_to_kernel(namep, m->msg_namelen,
80383 address);
80384 if (err < 0)
80385@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
80386 }
80387
80388 size = m->msg_iovlen * sizeof(struct iovec);
80389- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
80390+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
80391 return -EFAULT;
80392
80393 m->msg_iov = iov;
80394diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
80395index 1868625..5f4de62 100644
80396--- a/net/core/rtnetlink.c
80397+++ b/net/core/rtnetlink.c
80398@@ -58,7 +58,7 @@ struct rtnl_link {
80399 rtnl_doit_func doit;
80400 rtnl_dumpit_func dumpit;
80401 rtnl_calcit_func calcit;
80402-};
80403+} __no_const;
80404
80405 static DEFINE_MUTEX(rtnl_mutex);
80406
80407diff --git a/net/core/scm.c b/net/core/scm.c
80408index 905dcc6..14ee2d6 100644
80409--- a/net/core/scm.c
80410+++ b/net/core/scm.c
80411@@ -224,7 +224,7 @@ EXPORT_SYMBOL(__scm_send);
80412 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
80413 {
80414 struct cmsghdr __user *cm
80415- = (__force struct cmsghdr __user *)msg->msg_control;
80416+ = (struct cmsghdr __force_user *)msg->msg_control;
80417 struct cmsghdr cmhdr;
80418 int cmlen = CMSG_LEN(len);
80419 int err;
80420@@ -247,7 +247,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
80421 err = -EFAULT;
80422 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
80423 goto out;
80424- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
80425+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
80426 goto out;
80427 cmlen = CMSG_SPACE(len);
80428 if (msg->msg_controllen < cmlen)
80429@@ -263,7 +263,7 @@ EXPORT_SYMBOL(put_cmsg);
80430 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
80431 {
80432 struct cmsghdr __user *cm
80433- = (__force struct cmsghdr __user*)msg->msg_control;
80434+ = (struct cmsghdr __force_user *)msg->msg_control;
80435
80436 int fdmax = 0;
80437 int fdnum = scm->fp->count;
80438@@ -283,7 +283,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
80439 if (fdnum < fdmax)
80440 fdmax = fdnum;
80441
80442- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
80443+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
80444 i++, cmfptr++)
80445 {
80446 struct socket *sock;
80447diff --git a/net/core/sock.c b/net/core/sock.c
80448index bc131d4..029e378 100644
80449--- a/net/core/sock.c
80450+++ b/net/core/sock.c
80451@@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80452 struct sk_buff_head *list = &sk->sk_receive_queue;
80453
80454 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
80455- atomic_inc(&sk->sk_drops);
80456+ atomic_inc_unchecked(&sk->sk_drops);
80457 trace_sock_rcvqueue_full(sk, skb);
80458 return -ENOMEM;
80459 }
80460@@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80461 return err;
80462
80463 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
80464- atomic_inc(&sk->sk_drops);
80465+ atomic_inc_unchecked(&sk->sk_drops);
80466 return -ENOBUFS;
80467 }
80468
80469@@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80470 skb_dst_force(skb);
80471
80472 spin_lock_irqsave(&list->lock, flags);
80473- skb->dropcount = atomic_read(&sk->sk_drops);
80474+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
80475 __skb_queue_tail(list, skb);
80476 spin_unlock_irqrestore(&list->lock, flags);
80477
80478@@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
80479 skb->dev = NULL;
80480
80481 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
80482- atomic_inc(&sk->sk_drops);
80483+ atomic_inc_unchecked(&sk->sk_drops);
80484 goto discard_and_relse;
80485 }
80486 if (nested)
80487@@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
80488 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
80489 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
80490 bh_unlock_sock(sk);
80491- atomic_inc(&sk->sk_drops);
80492+ atomic_inc_unchecked(&sk->sk_drops);
80493 goto discard_and_relse;
80494 }
80495
80496@@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80497 struct timeval tm;
80498 } v;
80499
80500- int lv = sizeof(int);
80501- int len;
80502+ unsigned int lv = sizeof(int);
80503+ unsigned int len;
80504
80505 if (get_user(len, optlen))
80506 return -EFAULT;
80507- if (len < 0)
80508+ if (len > INT_MAX)
80509 return -EINVAL;
80510
80511 memset(&v, 0, sizeof(v));
80512@@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80513
80514 case SO_PEERNAME:
80515 {
80516- char address[128];
80517+ char address[_K_SS_MAXSIZE];
80518
80519 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
80520 return -ENOTCONN;
80521- if (lv < len)
80522+ if (lv < len || sizeof address < len)
80523 return -EINVAL;
80524 if (copy_to_user(optval, address, len))
80525 return -EFAULT;
80526@@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80527
80528 if (len > lv)
80529 len = lv;
80530- if (copy_to_user(optval, &v, len))
80531+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
80532 return -EFAULT;
80533 lenout:
80534 if (put_user(len, optlen))
80535@@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
80536 */
80537 smp_wmb();
80538 atomic_set(&sk->sk_refcnt, 1);
80539- atomic_set(&sk->sk_drops, 0);
80540+ atomic_set_unchecked(&sk->sk_drops, 0);
80541 }
80542 EXPORT_SYMBOL(sock_init_data);
80543
80544diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
80545index 750f44f..0a699b1 100644
80546--- a/net/core/sock_diag.c
80547+++ b/net/core/sock_diag.c
80548@@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
80549
80550 int sock_diag_check_cookie(void *sk, __u32 *cookie)
80551 {
80552+#ifndef CONFIG_GRKERNSEC_HIDESYM
80553 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
80554 cookie[1] != INET_DIAG_NOCOOKIE) &&
80555 ((u32)(unsigned long)sk != cookie[0] ||
80556 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
80557 return -ESTALE;
80558 else
80559+#endif
80560 return 0;
80561 }
80562 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
80563
80564 void sock_diag_save_cookie(void *sk, __u32 *cookie)
80565 {
80566+#ifdef CONFIG_GRKERNSEC_HIDESYM
80567+ cookie[0] = 0;
80568+ cookie[1] = 0;
80569+#else
80570 cookie[0] = (u32)(unsigned long)sk;
80571 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
80572+#endif
80573 }
80574 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
80575
80576@@ -97,21 +104,6 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
80577 }
80578 EXPORT_SYMBOL_GPL(sock_diag_unregister);
80579
80580-static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
80581-{
80582- if (sock_diag_handlers[family] == NULL)
80583- request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
80584- NETLINK_SOCK_DIAG, family);
80585-
80586- mutex_lock(&sock_diag_table_mutex);
80587- return sock_diag_handlers[family];
80588-}
80589-
80590-static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
80591-{
80592- mutex_unlock(&sock_diag_table_mutex);
80593-}
80594-
80595 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
80596 {
80597 int err;
80598@@ -124,12 +116,17 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
80599 if (req->sdiag_family >= AF_MAX)
80600 return -EINVAL;
80601
80602- hndl = sock_diag_lock_handler(req->sdiag_family);
80603+ if (sock_diag_handlers[req->sdiag_family] == NULL)
80604+ request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
80605+ NETLINK_SOCK_DIAG, req->sdiag_family);
80606+
80607+ mutex_lock(&sock_diag_table_mutex);
80608+ hndl = sock_diag_handlers[req->sdiag_family];
80609 if (hndl == NULL)
80610 err = -ENOENT;
80611 else
80612 err = hndl->dump(skb, nlh);
80613- sock_diag_unlock_handler(hndl);
80614+ mutex_unlock(&sock_diag_table_mutex);
80615
80616 return err;
80617 }
80618diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
80619index a55eecc..dd8428c 100644
80620--- a/net/decnet/sysctl_net_decnet.c
80621+++ b/net/decnet/sysctl_net_decnet.c
80622@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
80623
80624 if (len > *lenp) len = *lenp;
80625
80626- if (copy_to_user(buffer, addr, len))
80627+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
80628 return -EFAULT;
80629
80630 *lenp = len;
80631@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
80632
80633 if (len > *lenp) len = *lenp;
80634
80635- if (copy_to_user(buffer, devname, len))
80636+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
80637 return -EFAULT;
80638
80639 *lenp = len;
80640diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
80641index a69b4e4..dbccba5 100644
80642--- a/net/ipv4/ah4.c
80643+++ b/net/ipv4/ah4.c
80644@@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
80645 return;
80646
80647 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
80648- atomic_inc(&flow_cache_genid);
80649+ atomic_inc_unchecked(&flow_cache_genid);
80650 rt_genid_bump(net);
80651
80652 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
80653diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
80654index 3b4f0cd..8cb864c 100644
80655--- a/net/ipv4/esp4.c
80656+++ b/net/ipv4/esp4.c
80657@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
80658 return;
80659
80660 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
80661- atomic_inc(&flow_cache_genid);
80662+ atomic_inc_unchecked(&flow_cache_genid);
80663 rt_genid_bump(net);
80664
80665 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
80666diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
80667index 5cd75e2..f57ef39 100644
80668--- a/net/ipv4/fib_frontend.c
80669+++ b/net/ipv4/fib_frontend.c
80670@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
80671 #ifdef CONFIG_IP_ROUTE_MULTIPATH
80672 fib_sync_up(dev);
80673 #endif
80674- atomic_inc(&net->ipv4.dev_addr_genid);
80675+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80676 rt_cache_flush(dev_net(dev));
80677 break;
80678 case NETDEV_DOWN:
80679 fib_del_ifaddr(ifa, NULL);
80680- atomic_inc(&net->ipv4.dev_addr_genid);
80681+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80682 if (ifa->ifa_dev->ifa_list == NULL) {
80683 /* Last address was deleted from this interface.
80684 * Disable IP.
80685@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
80686 #ifdef CONFIG_IP_ROUTE_MULTIPATH
80687 fib_sync_up(dev);
80688 #endif
80689- atomic_inc(&net->ipv4.dev_addr_genid);
80690+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80691 rt_cache_flush(net);
80692 break;
80693 case NETDEV_DOWN:
80694diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
80695index 4797a80..2bd54e9 100644
80696--- a/net/ipv4/fib_semantics.c
80697+++ b/net/ipv4/fib_semantics.c
80698@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
80699 nh->nh_saddr = inet_select_addr(nh->nh_dev,
80700 nh->nh_gw,
80701 nh->nh_parent->fib_scope);
80702- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
80703+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
80704
80705 return nh->nh_saddr;
80706 }
80707diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
80708index fa3ae81..0dbe6b8 100644
80709--- a/net/ipv4/inet_hashtables.c
80710+++ b/net/ipv4/inet_hashtables.c
80711@@ -18,12 +18,15 @@
80712 #include <linux/sched.h>
80713 #include <linux/slab.h>
80714 #include <linux/wait.h>
80715+#include <linux/security.h>
80716
80717 #include <net/inet_connection_sock.h>
80718 #include <net/inet_hashtables.h>
80719 #include <net/secure_seq.h>
80720 #include <net/ip.h>
80721
80722+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
80723+
80724 /*
80725 * Allocate and initialize a new local port bind bucket.
80726 * The bindhash mutex for snum's hash chain must be held here.
80727@@ -540,6 +543,8 @@ ok:
80728 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
80729 spin_unlock(&head->lock);
80730
80731+ gr_update_task_in_ip_table(current, inet_sk(sk));
80732+
80733 if (tw) {
80734 inet_twsk_deschedule(tw, death_row);
80735 while (twrefcnt) {
80736diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
80737index 000e3d2..5472da3 100644
80738--- a/net/ipv4/inetpeer.c
80739+++ b/net/ipv4/inetpeer.c
80740@@ -503,8 +503,8 @@ relookup:
80741 if (p) {
80742 p->daddr = *daddr;
80743 atomic_set(&p->refcnt, 1);
80744- atomic_set(&p->rid, 0);
80745- atomic_set(&p->ip_id_count,
80746+ atomic_set_unchecked(&p->rid, 0);
80747+ atomic_set_unchecked(&p->ip_id_count,
80748 (daddr->family == AF_INET) ?
80749 secure_ip_id(daddr->addr.a4) :
80750 secure_ipv6_id(daddr->addr.a6));
80751diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
80752index eb9d63a..50babc1 100644
80753--- a/net/ipv4/ip_fragment.c
80754+++ b/net/ipv4/ip_fragment.c
80755@@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
80756 return 0;
80757
80758 start = qp->rid;
80759- end = atomic_inc_return(&peer->rid);
80760+ end = atomic_inc_return_unchecked(&peer->rid);
80761 qp->rid = end;
80762
80763 rc = qp->q.fragments && (end - start) > max;
80764diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
80765index d9c4f11..02b82db 100644
80766--- a/net/ipv4/ip_sockglue.c
80767+++ b/net/ipv4/ip_sockglue.c
80768@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
80769 len = min_t(unsigned int, len, opt->optlen);
80770 if (put_user(len, optlen))
80771 return -EFAULT;
80772- if (copy_to_user(optval, opt->__data, len))
80773+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
80774+ copy_to_user(optval, opt->__data, len))
80775 return -EFAULT;
80776 return 0;
80777 }
80778@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
80779 if (sk->sk_type != SOCK_STREAM)
80780 return -ENOPROTOOPT;
80781
80782- msg.msg_control = optval;
80783+ msg.msg_control = (void __force_kernel *)optval;
80784 msg.msg_controllen = len;
80785 msg.msg_flags = flags;
80786
80787diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
80788index 9a46dae..5f793a0 100644
80789--- a/net/ipv4/ipcomp.c
80790+++ b/net/ipv4/ipcomp.c
80791@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
80792 return;
80793
80794 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
80795- atomic_inc(&flow_cache_genid);
80796+ atomic_inc_unchecked(&flow_cache_genid);
80797 rt_genid_bump(net);
80798
80799 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
80800diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
80801index a2e50ae..e152b7c 100644
80802--- a/net/ipv4/ipconfig.c
80803+++ b/net/ipv4/ipconfig.c
80804@@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
80805
80806 mm_segment_t oldfs = get_fs();
80807 set_fs(get_ds());
80808- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
80809+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
80810 set_fs(oldfs);
80811 return res;
80812 }
80813@@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
80814
80815 mm_segment_t oldfs = get_fs();
80816 set_fs(get_ds());
80817- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
80818+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
80819 set_fs(oldfs);
80820 return res;
80821 }
80822@@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
80823
80824 mm_segment_t oldfs = get_fs();
80825 set_fs(get_ds());
80826- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
80827+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
80828 set_fs(oldfs);
80829 return res;
80830 }
80831diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
80832index 3ea4127..849297b 100644
80833--- a/net/ipv4/netfilter/arp_tables.c
80834+++ b/net/ipv4/netfilter/arp_tables.c
80835@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
80836 #endif
80837
80838 static int get_info(struct net *net, void __user *user,
80839- const int *len, int compat)
80840+ int len, int compat)
80841 {
80842 char name[XT_TABLE_MAXNAMELEN];
80843 struct xt_table *t;
80844 int ret;
80845
80846- if (*len != sizeof(struct arpt_getinfo)) {
80847- duprintf("length %u != %Zu\n", *len,
80848+ if (len != sizeof(struct arpt_getinfo)) {
80849+ duprintf("length %u != %Zu\n", len,
80850 sizeof(struct arpt_getinfo));
80851 return -EINVAL;
80852 }
80853@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
80854 info.size = private->size;
80855 strcpy(info.name, name);
80856
80857- if (copy_to_user(user, &info, *len) != 0)
80858+ if (copy_to_user(user, &info, len) != 0)
80859 ret = -EFAULT;
80860 else
80861 ret = 0;
80862@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
80863
80864 switch (cmd) {
80865 case ARPT_SO_GET_INFO:
80866- ret = get_info(sock_net(sk), user, len, 1);
80867+ ret = get_info(sock_net(sk), user, *len, 1);
80868 break;
80869 case ARPT_SO_GET_ENTRIES:
80870 ret = compat_get_entries(sock_net(sk), user, len);
80871@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
80872
80873 switch (cmd) {
80874 case ARPT_SO_GET_INFO:
80875- ret = get_info(sock_net(sk), user, len, 0);
80876+ ret = get_info(sock_net(sk), user, *len, 0);
80877 break;
80878
80879 case ARPT_SO_GET_ENTRIES:
80880diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
80881index 17c5e06..1b91206 100644
80882--- a/net/ipv4/netfilter/ip_tables.c
80883+++ b/net/ipv4/netfilter/ip_tables.c
80884@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
80885 #endif
80886
80887 static int get_info(struct net *net, void __user *user,
80888- const int *len, int compat)
80889+ int len, int compat)
80890 {
80891 char name[XT_TABLE_MAXNAMELEN];
80892 struct xt_table *t;
80893 int ret;
80894
80895- if (*len != sizeof(struct ipt_getinfo)) {
80896- duprintf("length %u != %zu\n", *len,
80897+ if (len != sizeof(struct ipt_getinfo)) {
80898+ duprintf("length %u != %zu\n", len,
80899 sizeof(struct ipt_getinfo));
80900 return -EINVAL;
80901 }
80902@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
80903 info.size = private->size;
80904 strcpy(info.name, name);
80905
80906- if (copy_to_user(user, &info, *len) != 0)
80907+ if (copy_to_user(user, &info, len) != 0)
80908 ret = -EFAULT;
80909 else
80910 ret = 0;
80911@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80912
80913 switch (cmd) {
80914 case IPT_SO_GET_INFO:
80915- ret = get_info(sock_net(sk), user, len, 1);
80916+ ret = get_info(sock_net(sk), user, *len, 1);
80917 break;
80918 case IPT_SO_GET_ENTRIES:
80919 ret = compat_get_entries(sock_net(sk), user, len);
80920@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80921
80922 switch (cmd) {
80923 case IPT_SO_GET_INFO:
80924- ret = get_info(sock_net(sk), user, len, 0);
80925+ ret = get_info(sock_net(sk), user, *len, 0);
80926 break;
80927
80928 case IPT_SO_GET_ENTRIES:
80929diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
80930index dc454cc..5bb917f 100644
80931--- a/net/ipv4/ping.c
80932+++ b/net/ipv4/ping.c
80933@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
80934 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
80935 0, sock_i_ino(sp),
80936 atomic_read(&sp->sk_refcnt), sp,
80937- atomic_read(&sp->sk_drops), len);
80938+ atomic_read_unchecked(&sp->sk_drops), len);
80939 }
80940
80941 static int ping_seq_show(struct seq_file *seq, void *v)
80942diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
80943index 6f08991..55867ad 100644
80944--- a/net/ipv4/raw.c
80945+++ b/net/ipv4/raw.c
80946@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
80947 int raw_rcv(struct sock *sk, struct sk_buff *skb)
80948 {
80949 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
80950- atomic_inc(&sk->sk_drops);
80951+ atomic_inc_unchecked(&sk->sk_drops);
80952 kfree_skb(skb);
80953 return NET_RX_DROP;
80954 }
80955@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
80956
80957 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
80958 {
80959+ struct icmp_filter filter;
80960+
80961 if (optlen > sizeof(struct icmp_filter))
80962 optlen = sizeof(struct icmp_filter);
80963- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
80964+ if (copy_from_user(&filter, optval, optlen))
80965 return -EFAULT;
80966+ raw_sk(sk)->filter = filter;
80967 return 0;
80968 }
80969
80970 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
80971 {
80972 int len, ret = -EFAULT;
80973+ struct icmp_filter filter;
80974
80975 if (get_user(len, optlen))
80976 goto out;
80977@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
80978 if (len > sizeof(struct icmp_filter))
80979 len = sizeof(struct icmp_filter);
80980 ret = -EFAULT;
80981- if (put_user(len, optlen) ||
80982- copy_to_user(optval, &raw_sk(sk)->filter, len))
80983+ filter = raw_sk(sk)->filter;
80984+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
80985 goto out;
80986 ret = 0;
80987 out: return ret;
80988@@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80989 0, 0L, 0,
80990 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
80991 0, sock_i_ino(sp),
80992- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80993+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
80994 }
80995
80996 static int raw_seq_show(struct seq_file *seq, void *v)
80997diff --git a/net/ipv4/route.c b/net/ipv4/route.c
80998index a0fcc47..5949bba1 100644
80999--- a/net/ipv4/route.c
81000+++ b/net/ipv4/route.c
81001@@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
81002
81003 static __net_init int rt_genid_init(struct net *net)
81004 {
81005- atomic_set(&net->rt_genid, 0);
81006+ atomic_set_unchecked(&net->rt_genid, 0);
81007 get_random_bytes(&net->ipv4.dev_addr_genid,
81008 sizeof(net->ipv4.dev_addr_genid));
81009 return 0;
81010diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
81011index ad70a96..50cb55b 100644
81012--- a/net/ipv4/tcp_input.c
81013+++ b/net/ipv4/tcp_input.c
81014@@ -4733,7 +4733,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
81015 * simplifies code)
81016 */
81017 static void
81018-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
81019+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
81020 struct sk_buff *head, struct sk_buff *tail,
81021 u32 start, u32 end)
81022 {
81023@@ -5850,6 +5850,7 @@ discard:
81024 tcp_paws_reject(&tp->rx_opt, 0))
81025 goto discard_and_undo;
81026
81027+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
81028 if (th->syn) {
81029 /* We see SYN without ACK. It is attempt of
81030 * simultaneous connect with crossed SYNs.
81031@@ -5900,6 +5901,7 @@ discard:
81032 goto discard;
81033 #endif
81034 }
81035+#endif
81036 /* "fifth, if neither of the SYN or RST bits is set then
81037 * drop the segment and return."
81038 */
81039@@ -5944,7 +5946,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
81040 goto discard;
81041
81042 if (th->syn) {
81043- if (th->fin)
81044+ if (th->fin || th->urg || th->psh)
81045 goto discard;
81046 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
81047 return 1;
81048diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
81049index eadb693..e8f7251 100644
81050--- a/net/ipv4/tcp_ipv4.c
81051+++ b/net/ipv4/tcp_ipv4.c
81052@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
81053 EXPORT_SYMBOL(sysctl_tcp_low_latency);
81054
81055
81056+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81057+extern int grsec_enable_blackhole;
81058+#endif
81059+
81060 #ifdef CONFIG_TCP_MD5SIG
81061 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
81062 __be32 daddr, __be32 saddr, const struct tcphdr *th);
81063@@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
81064 return 0;
81065
81066 reset:
81067+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81068+ if (!grsec_enable_blackhole)
81069+#endif
81070 tcp_v4_send_reset(rsk, skb);
81071 discard:
81072 kfree_skb(skb);
81073@@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
81074 TCP_SKB_CB(skb)->sacked = 0;
81075
81076 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
81077- if (!sk)
81078+ if (!sk) {
81079+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81080+ ret = 1;
81081+#endif
81082 goto no_tcp_socket;
81083-
81084+ }
81085 process:
81086- if (sk->sk_state == TCP_TIME_WAIT)
81087+ if (sk->sk_state == TCP_TIME_WAIT) {
81088+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81089+ ret = 2;
81090+#endif
81091 goto do_time_wait;
81092+ }
81093
81094 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
81095 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
81096@@ -2050,6 +2064,10 @@ no_tcp_socket:
81097 bad_packet:
81098 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
81099 } else {
81100+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81101+ if (!grsec_enable_blackhole || (ret == 1 &&
81102+ (skb->dev->flags & IFF_LOOPBACK)))
81103+#endif
81104 tcp_v4_send_reset(NULL, skb);
81105 }
81106
81107diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
81108index f35f2df..ccb5ca6 100644
81109--- a/net/ipv4/tcp_minisocks.c
81110+++ b/net/ipv4/tcp_minisocks.c
81111@@ -27,6 +27,10 @@
81112 #include <net/inet_common.h>
81113 #include <net/xfrm.h>
81114
81115+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81116+extern int grsec_enable_blackhole;
81117+#endif
81118+
81119 int sysctl_tcp_syncookies __read_mostly = 1;
81120 EXPORT_SYMBOL(sysctl_tcp_syncookies);
81121
81122@@ -742,7 +746,10 @@ embryonic_reset:
81123 * avoid becoming vulnerable to outside attack aiming at
81124 * resetting legit local connections.
81125 */
81126- req->rsk_ops->send_reset(sk, skb);
81127+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81128+ if (!grsec_enable_blackhole)
81129+#endif
81130+ req->rsk_ops->send_reset(sk, skb);
81131 } else if (fastopen) { /* received a valid RST pkt */
81132 reqsk_fastopen_remove(sk, req, true);
81133 tcp_reset(sk);
81134diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
81135index 4526fe6..1a34e43 100644
81136--- a/net/ipv4/tcp_probe.c
81137+++ b/net/ipv4/tcp_probe.c
81138@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
81139 if (cnt + width >= len)
81140 break;
81141
81142- if (copy_to_user(buf + cnt, tbuf, width))
81143+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
81144 return -EFAULT;
81145 cnt += width;
81146 }
81147diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
81148index b78aac3..e18230b 100644
81149--- a/net/ipv4/tcp_timer.c
81150+++ b/net/ipv4/tcp_timer.c
81151@@ -22,6 +22,10 @@
81152 #include <linux/gfp.h>
81153 #include <net/tcp.h>
81154
81155+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81156+extern int grsec_lastack_retries;
81157+#endif
81158+
81159 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
81160 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
81161 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
81162@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
81163 }
81164 }
81165
81166+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81167+ if ((sk->sk_state == TCP_LAST_ACK) &&
81168+ (grsec_lastack_retries > 0) &&
81169+ (grsec_lastack_retries < retry_until))
81170+ retry_until = grsec_lastack_retries;
81171+#endif
81172+
81173 if (retransmits_timed_out(sk, retry_until,
81174 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
81175 /* Has it gone just too far? */
81176diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
81177index 1f4d405..3524677 100644
81178--- a/net/ipv4/udp.c
81179+++ b/net/ipv4/udp.c
81180@@ -87,6 +87,7 @@
81181 #include <linux/types.h>
81182 #include <linux/fcntl.h>
81183 #include <linux/module.h>
81184+#include <linux/security.h>
81185 #include <linux/socket.h>
81186 #include <linux/sockios.h>
81187 #include <linux/igmp.h>
81188@@ -111,6 +112,10 @@
81189 #include <trace/events/skb.h>
81190 #include "udp_impl.h"
81191
81192+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81193+extern int grsec_enable_blackhole;
81194+#endif
81195+
81196 struct udp_table udp_table __read_mostly;
81197 EXPORT_SYMBOL(udp_table);
81198
81199@@ -569,6 +574,9 @@ found:
81200 return s;
81201 }
81202
81203+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
81204+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
81205+
81206 /*
81207 * This routine is called by the ICMP module when it gets some
81208 * sort of error condition. If err < 0 then the socket should
81209@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
81210 dport = usin->sin_port;
81211 if (dport == 0)
81212 return -EINVAL;
81213+
81214+ err = gr_search_udp_sendmsg(sk, usin);
81215+ if (err)
81216+ return err;
81217 } else {
81218 if (sk->sk_state != TCP_ESTABLISHED)
81219 return -EDESTADDRREQ;
81220+
81221+ err = gr_search_udp_sendmsg(sk, NULL);
81222+ if (err)
81223+ return err;
81224+
81225 daddr = inet->inet_daddr;
81226 dport = inet->inet_dport;
81227 /* Open fast path for connected socket.
81228@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
81229 udp_lib_checksum_complete(skb)) {
81230 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81231 IS_UDPLITE(sk));
81232- atomic_inc(&sk->sk_drops);
81233+ atomic_inc_unchecked(&sk->sk_drops);
81234 __skb_unlink(skb, rcvq);
81235 __skb_queue_tail(&list_kill, skb);
81236 }
81237@@ -1194,6 +1211,10 @@ try_again:
81238 if (!skb)
81239 goto out;
81240
81241+ err = gr_search_udp_recvmsg(sk, skb);
81242+ if (err)
81243+ goto out_free;
81244+
81245 ulen = skb->len - sizeof(struct udphdr);
81246 copied = len;
81247 if (copied > ulen)
81248@@ -1227,7 +1248,7 @@ try_again:
81249 if (unlikely(err)) {
81250 trace_kfree_skb(skb, udp_recvmsg);
81251 if (!peeked) {
81252- atomic_inc(&sk->sk_drops);
81253+ atomic_inc_unchecked(&sk->sk_drops);
81254 UDP_INC_STATS_USER(sock_net(sk),
81255 UDP_MIB_INERRORS, is_udplite);
81256 }
81257@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
81258
81259 drop:
81260 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
81261- atomic_inc(&sk->sk_drops);
81262+ atomic_inc_unchecked(&sk->sk_drops);
81263 kfree_skb(skb);
81264 return -1;
81265 }
81266@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
81267 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
81268
81269 if (!skb1) {
81270- atomic_inc(&sk->sk_drops);
81271+ atomic_inc_unchecked(&sk->sk_drops);
81272 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
81273 IS_UDPLITE(sk));
81274 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81275@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
81276 goto csum_error;
81277
81278 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
81279+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81280+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
81281+#endif
81282 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
81283
81284 /*
81285@@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
81286 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
81287 0, sock_i_ino(sp),
81288 atomic_read(&sp->sk_refcnt), sp,
81289- atomic_read(&sp->sk_drops), len);
81290+ atomic_read_unchecked(&sp->sk_drops), len);
81291 }
81292
81293 int udp4_seq_show(struct seq_file *seq, void *v)
81294diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
81295index 1b5d8cb..2e8c2d9 100644
81296--- a/net/ipv6/addrconf.c
81297+++ b/net/ipv6/addrconf.c
81298@@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
81299 p.iph.ihl = 5;
81300 p.iph.protocol = IPPROTO_IPV6;
81301 p.iph.ttl = 64;
81302- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
81303+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
81304
81305 if (ops->ndo_do_ioctl) {
81306 mm_segment_t oldfs = get_fs();
81307diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
81308index 131dd09..7647ada 100644
81309--- a/net/ipv6/ip6_gre.c
81310+++ b/net/ipv6/ip6_gre.c
81311@@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
81312 }
81313
81314
81315-static struct inet6_protocol ip6gre_protocol __read_mostly = {
81316+static struct inet6_protocol ip6gre_protocol = {
81317 .handler = ip6gre_rcv,
81318 .err_handler = ip6gre_err,
81319 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
81320diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
81321index d1e2e8e..51c19ae 100644
81322--- a/net/ipv6/ipv6_sockglue.c
81323+++ b/net/ipv6/ipv6_sockglue.c
81324@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
81325 if (sk->sk_type != SOCK_STREAM)
81326 return -ENOPROTOOPT;
81327
81328- msg.msg_control = optval;
81329+ msg.msg_control = (void __force_kernel *)optval;
81330 msg.msg_controllen = len;
81331 msg.msg_flags = flags;
81332
81333diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
81334index 125a90d..2a11f36 100644
81335--- a/net/ipv6/netfilter/ip6_tables.c
81336+++ b/net/ipv6/netfilter/ip6_tables.c
81337@@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
81338 #endif
81339
81340 static int get_info(struct net *net, void __user *user,
81341- const int *len, int compat)
81342+ int len, int compat)
81343 {
81344 char name[XT_TABLE_MAXNAMELEN];
81345 struct xt_table *t;
81346 int ret;
81347
81348- if (*len != sizeof(struct ip6t_getinfo)) {
81349- duprintf("length %u != %zu\n", *len,
81350+ if (len != sizeof(struct ip6t_getinfo)) {
81351+ duprintf("length %u != %zu\n", len,
81352 sizeof(struct ip6t_getinfo));
81353 return -EINVAL;
81354 }
81355@@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
81356 info.size = private->size;
81357 strcpy(info.name, name);
81358
81359- if (copy_to_user(user, &info, *len) != 0)
81360+ if (copy_to_user(user, &info, len) != 0)
81361 ret = -EFAULT;
81362 else
81363 ret = 0;
81364@@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81365
81366 switch (cmd) {
81367 case IP6T_SO_GET_INFO:
81368- ret = get_info(sock_net(sk), user, len, 1);
81369+ ret = get_info(sock_net(sk), user, *len, 1);
81370 break;
81371 case IP6T_SO_GET_ENTRIES:
81372 ret = compat_get_entries(sock_net(sk), user, len);
81373@@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81374
81375 switch (cmd) {
81376 case IP6T_SO_GET_INFO:
81377- ret = get_info(sock_net(sk), user, len, 0);
81378+ ret = get_info(sock_net(sk), user, *len, 0);
81379 break;
81380
81381 case IP6T_SO_GET_ENTRIES:
81382diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
81383index 70fa814..d70c28c 100644
81384--- a/net/ipv6/raw.c
81385+++ b/net/ipv6/raw.c
81386@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
81387 {
81388 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
81389 skb_checksum_complete(skb)) {
81390- atomic_inc(&sk->sk_drops);
81391+ atomic_inc_unchecked(&sk->sk_drops);
81392 kfree_skb(skb);
81393 return NET_RX_DROP;
81394 }
81395@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
81396 struct raw6_sock *rp = raw6_sk(sk);
81397
81398 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
81399- atomic_inc(&sk->sk_drops);
81400+ atomic_inc_unchecked(&sk->sk_drops);
81401 kfree_skb(skb);
81402 return NET_RX_DROP;
81403 }
81404@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
81405
81406 if (inet->hdrincl) {
81407 if (skb_checksum_complete(skb)) {
81408- atomic_inc(&sk->sk_drops);
81409+ atomic_inc_unchecked(&sk->sk_drops);
81410 kfree_skb(skb);
81411 return NET_RX_DROP;
81412 }
81413@@ -604,7 +604,7 @@ out:
81414 return err;
81415 }
81416
81417-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
81418+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
81419 struct flowi6 *fl6, struct dst_entry **dstp,
81420 unsigned int flags)
81421 {
81422@@ -916,12 +916,15 @@ do_confirm:
81423 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
81424 char __user *optval, int optlen)
81425 {
81426+ struct icmp6_filter filter;
81427+
81428 switch (optname) {
81429 case ICMPV6_FILTER:
81430 if (optlen > sizeof(struct icmp6_filter))
81431 optlen = sizeof(struct icmp6_filter);
81432- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
81433+ if (copy_from_user(&filter, optval, optlen))
81434 return -EFAULT;
81435+ raw6_sk(sk)->filter = filter;
81436 return 0;
81437 default:
81438 return -ENOPROTOOPT;
81439@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
81440 char __user *optval, int __user *optlen)
81441 {
81442 int len;
81443+ struct icmp6_filter filter;
81444
81445 switch (optname) {
81446 case ICMPV6_FILTER:
81447@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
81448 len = sizeof(struct icmp6_filter);
81449 if (put_user(len, optlen))
81450 return -EFAULT;
81451- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
81452+ filter = raw6_sk(sk)->filter;
81453+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
81454 return -EFAULT;
81455 return 0;
81456 default:
81457@@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
81458 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
81459 0,
81460 sock_i_ino(sp),
81461- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
81462+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
81463 }
81464
81465 static int raw6_seq_show(struct seq_file *seq, void *v)
81466diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
81467index 4f435371..5de9da7 100644
81468--- a/net/ipv6/tcp_ipv6.c
81469+++ b/net/ipv6/tcp_ipv6.c
81470@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
81471 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
81472 }
81473
81474+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81475+extern int grsec_enable_blackhole;
81476+#endif
81477+
81478 static void tcp_v6_hash(struct sock *sk)
81479 {
81480 if (sk->sk_state != TCP_CLOSE) {
81481@@ -1433,6 +1437,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
81482 return 0;
81483
81484 reset:
81485+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81486+ if (!grsec_enable_blackhole)
81487+#endif
81488 tcp_v6_send_reset(sk, skb);
81489 discard:
81490 if (opt_skb)
81491@@ -1514,12 +1521,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
81492 TCP_SKB_CB(skb)->sacked = 0;
81493
81494 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
81495- if (!sk)
81496+ if (!sk) {
81497+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81498+ ret = 1;
81499+#endif
81500 goto no_tcp_socket;
81501+ }
81502
81503 process:
81504- if (sk->sk_state == TCP_TIME_WAIT)
81505+ if (sk->sk_state == TCP_TIME_WAIT) {
81506+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81507+ ret = 2;
81508+#endif
81509 goto do_time_wait;
81510+ }
81511
81512 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
81513 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
81514@@ -1568,6 +1583,10 @@ no_tcp_socket:
81515 bad_packet:
81516 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
81517 } else {
81518+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81519+ if (!grsec_enable_blackhole || (ret == 1 &&
81520+ (skb->dev->flags & IFF_LOOPBACK)))
81521+#endif
81522 tcp_v6_send_reset(NULL, skb);
81523 }
81524
81525diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
81526index fb08329..2d6919e 100644
81527--- a/net/ipv6/udp.c
81528+++ b/net/ipv6/udp.c
81529@@ -51,6 +51,10 @@
81530 #include <trace/events/skb.h>
81531 #include "udp_impl.h"
81532
81533+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81534+extern int grsec_enable_blackhole;
81535+#endif
81536+
81537 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
81538 {
81539 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
81540@@ -395,7 +399,7 @@ try_again:
81541 if (unlikely(err)) {
81542 trace_kfree_skb(skb, udpv6_recvmsg);
81543 if (!peeked) {
81544- atomic_inc(&sk->sk_drops);
81545+ atomic_inc_unchecked(&sk->sk_drops);
81546 if (is_udp4)
81547 UDP_INC_STATS_USER(sock_net(sk),
81548 UDP_MIB_INERRORS,
81549@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
81550 return rc;
81551 drop:
81552 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
81553- atomic_inc(&sk->sk_drops);
81554+ atomic_inc_unchecked(&sk->sk_drops);
81555 kfree_skb(skb);
81556 return -1;
81557 }
81558@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
81559 if (likely(skb1 == NULL))
81560 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
81561 if (!skb1) {
81562- atomic_inc(&sk->sk_drops);
81563+ atomic_inc_unchecked(&sk->sk_drops);
81564 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
81565 IS_UDPLITE(sk));
81566 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81567@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
81568 goto discard;
81569
81570 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
81571+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81572+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
81573+#endif
81574 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
81575
81576 kfree_skb(skb);
81577@@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
81578 0,
81579 sock_i_ino(sp),
81580 atomic_read(&sp->sk_refcnt), sp,
81581- atomic_read(&sp->sk_drops));
81582+ atomic_read_unchecked(&sp->sk_drops));
81583 }
81584
81585 int udp6_seq_show(struct seq_file *seq, void *v)
81586diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
81587index a68c88c..d55b0c5 100644
81588--- a/net/irda/ircomm/ircomm_tty.c
81589+++ b/net/irda/ircomm/ircomm_tty.c
81590@@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81591 add_wait_queue(&port->open_wait, &wait);
81592
81593 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
81594- __FILE__, __LINE__, tty->driver->name, port->count);
81595+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81596
81597 spin_lock_irqsave(&port->lock, flags);
81598 if (!tty_hung_up_p(filp)) {
81599 extra_count = 1;
81600- port->count--;
81601+ atomic_dec(&port->count);
81602 }
81603 spin_unlock_irqrestore(&port->lock, flags);
81604 port->blocked_open++;
81605@@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81606 }
81607
81608 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
81609- __FILE__, __LINE__, tty->driver->name, port->count);
81610+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81611
81612 schedule();
81613 }
81614@@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81615 if (extra_count) {
81616 /* ++ is not atomic, so this should be protected - Jean II */
81617 spin_lock_irqsave(&port->lock, flags);
81618- port->count++;
81619+ atomic_inc(&port->count);
81620 spin_unlock_irqrestore(&port->lock, flags);
81621 }
81622 port->blocked_open--;
81623
81624 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
81625- __FILE__, __LINE__, tty->driver->name, port->count);
81626+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81627
81628 if (!retval)
81629 port->flags |= ASYNC_NORMAL_ACTIVE;
81630@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
81631
81632 /* ++ is not atomic, so this should be protected - Jean II */
81633 spin_lock_irqsave(&self->port.lock, flags);
81634- self->port.count++;
81635+ atomic_inc(&self->port.count);
81636 spin_unlock_irqrestore(&self->port.lock, flags);
81637 tty_port_tty_set(&self->port, tty);
81638
81639 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
81640- self->line, self->port.count);
81641+ self->line, atomic_read(&self->port.count));
81642
81643 /* Not really used by us, but lets do it anyway */
81644 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
81645@@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
81646 tty_kref_put(port->tty);
81647 }
81648 port->tty = NULL;
81649- port->count = 0;
81650+ atomic_set(&port->count, 0);
81651 spin_unlock_irqrestore(&port->lock, flags);
81652
81653 wake_up_interruptible(&port->open_wait);
81654@@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
81655 seq_putc(m, '\n');
81656
81657 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
81658- seq_printf(m, "Open count: %d\n", self->port.count);
81659+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
81660 seq_printf(m, "Max data size: %d\n", self->max_data_size);
81661 seq_printf(m, "Max header size: %d\n", self->max_header_size);
81662
81663diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
81664index cd6f7a9..e63fe89 100644
81665--- a/net/iucv/af_iucv.c
81666+++ b/net/iucv/af_iucv.c
81667@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
81668
81669 write_lock_bh(&iucv_sk_list.lock);
81670
81671- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
81672+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81673 while (__iucv_get_sock_by_name(name)) {
81674 sprintf(name, "%08x",
81675- atomic_inc_return(&iucv_sk_list.autobind_name));
81676+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81677 }
81678
81679 write_unlock_bh(&iucv_sk_list.lock);
81680diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
81681index df08250..02021fe 100644
81682--- a/net/iucv/iucv.c
81683+++ b/net/iucv/iucv.c
81684@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
81685 return NOTIFY_OK;
81686 }
81687
81688-static struct notifier_block __refdata iucv_cpu_notifier = {
81689+static struct notifier_block iucv_cpu_notifier = {
81690 .notifier_call = iucv_cpu_notify,
81691 };
81692
81693diff --git a/net/key/af_key.c b/net/key/af_key.c
81694index 5b426a6..970032b 100644
81695--- a/net/key/af_key.c
81696+++ b/net/key/af_key.c
81697@@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
81698 static u32 get_acqseq(void)
81699 {
81700 u32 res;
81701- static atomic_t acqseq;
81702+ static atomic_unchecked_t acqseq;
81703
81704 do {
81705- res = atomic_inc_return(&acqseq);
81706+ res = atomic_inc_return_unchecked(&acqseq);
81707 } while (!res);
81708 return res;
81709 }
81710diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
81711index 0479c64..d031db6 100644
81712--- a/net/mac80211/cfg.c
81713+++ b/net/mac80211/cfg.c
81714@@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
81715 ret = ieee80211_vif_use_channel(sdata, chandef,
81716 IEEE80211_CHANCTX_EXCLUSIVE);
81717 }
81718- } else if (local->open_count == local->monitors) {
81719+ } else if (local_read(&local->open_count) == local->monitors) {
81720 local->_oper_channel = chandef->chan;
81721 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
81722 ieee80211_hw_config(local, 0);
81723@@ -2716,7 +2716,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
81724 else
81725 local->probe_req_reg--;
81726
81727- if (!local->open_count)
81728+ if (!local_read(&local->open_count))
81729 break;
81730
81731 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
81732diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
81733index 2ed065c..948177f 100644
81734--- a/net/mac80211/ieee80211_i.h
81735+++ b/net/mac80211/ieee80211_i.h
81736@@ -28,6 +28,7 @@
81737 #include <net/ieee80211_radiotap.h>
81738 #include <net/cfg80211.h>
81739 #include <net/mac80211.h>
81740+#include <asm/local.h>
81741 #include "key.h"
81742 #include "sta_info.h"
81743 #include "debug.h"
81744@@ -909,7 +910,7 @@ struct ieee80211_local {
81745 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
81746 spinlock_t queue_stop_reason_lock;
81747
81748- int open_count;
81749+ local_t open_count;
81750 int monitors, cooked_mntrs;
81751 /* number of interfaces with corresponding FIF_ flags */
81752 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
81753diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
81754index 8be854e..ad72a69 100644
81755--- a/net/mac80211/iface.c
81756+++ b/net/mac80211/iface.c
81757@@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81758 break;
81759 }
81760
81761- if (local->open_count == 0) {
81762+ if (local_read(&local->open_count) == 0) {
81763 res = drv_start(local);
81764 if (res)
81765 goto err_del_bss;
81766@@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81767 break;
81768 }
81769
81770- if (local->monitors == 0 && local->open_count == 0) {
81771+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
81772 res = ieee80211_add_virtual_monitor(local);
81773 if (res)
81774 goto err_stop;
81775@@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81776 mutex_unlock(&local->mtx);
81777
81778 if (coming_up)
81779- local->open_count++;
81780+ local_inc(&local->open_count);
81781
81782 if (hw_reconf_flags)
81783 ieee80211_hw_config(local, hw_reconf_flags);
81784@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81785 err_del_interface:
81786 drv_remove_interface(local, sdata);
81787 err_stop:
81788- if (!local->open_count)
81789+ if (!local_read(&local->open_count))
81790 drv_stop(local);
81791 err_del_bss:
81792 sdata->bss = NULL;
81793@@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
81794 }
81795
81796 if (going_down)
81797- local->open_count--;
81798+ local_dec(&local->open_count);
81799
81800 switch (sdata->vif.type) {
81801 case NL80211_IFTYPE_AP_VLAN:
81802@@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
81803
81804 ieee80211_recalc_ps(local, -1);
81805
81806- if (local->open_count == 0) {
81807+ if (local_read(&local->open_count) == 0) {
81808 if (local->ops->napi_poll)
81809 napi_disable(&local->napi);
81810 ieee80211_clear_tx_pending(local);
81811@@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
81812 }
81813 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
81814
81815- if (local->monitors == local->open_count && local->monitors > 0)
81816+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
81817 ieee80211_add_virtual_monitor(local);
81818 }
81819
81820diff --git a/net/mac80211/main.c b/net/mac80211/main.c
81821index 1b087ff..bf600e9 100644
81822--- a/net/mac80211/main.c
81823+++ b/net/mac80211/main.c
81824@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
81825 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
81826 IEEE80211_CONF_CHANGE_POWER);
81827
81828- if (changed && local->open_count) {
81829+ if (changed && local_read(&local->open_count)) {
81830 ret = drv_config(local, changed);
81831 /*
81832 * Goal:
81833diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
81834index 79a48f3..5e185c9 100644
81835--- a/net/mac80211/pm.c
81836+++ b/net/mac80211/pm.c
81837@@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
81838 struct sta_info *sta;
81839 struct ieee80211_chanctx *ctx;
81840
81841- if (!local->open_count)
81842+ if (!local_read(&local->open_count))
81843 goto suspend;
81844
81845 ieee80211_scan_cancel(local);
81846@@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
81847 cancel_work_sync(&local->dynamic_ps_enable_work);
81848 del_timer_sync(&local->dynamic_ps_timer);
81849
81850- local->wowlan = wowlan && local->open_count;
81851+ local->wowlan = wowlan && local_read(&local->open_count);
81852 if (local->wowlan) {
81853 int err = drv_suspend(local, wowlan);
81854 if (err < 0) {
81855@@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
81856 mutex_unlock(&local->chanctx_mtx);
81857
81858 /* stop hardware - this must stop RX */
81859- if (local->open_count)
81860+ if (local_read(&local->open_count))
81861 ieee80211_stop_device(local);
81862
81863 suspend:
81864diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
81865index dd88381..eef4dd6 100644
81866--- a/net/mac80211/rate.c
81867+++ b/net/mac80211/rate.c
81868@@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
81869
81870 ASSERT_RTNL();
81871
81872- if (local->open_count)
81873+ if (local_read(&local->open_count))
81874 return -EBUSY;
81875
81876 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
81877diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
81878index c97a065..ff61928 100644
81879--- a/net/mac80211/rc80211_pid_debugfs.c
81880+++ b/net/mac80211/rc80211_pid_debugfs.c
81881@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
81882
81883 spin_unlock_irqrestore(&events->lock, status);
81884
81885- if (copy_to_user(buf, pb, p))
81886+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
81887 return -EFAULT;
81888
81889 return p;
81890diff --git a/net/mac80211/util.c b/net/mac80211/util.c
81891index f11e8c5..08d0013 100644
81892--- a/net/mac80211/util.c
81893+++ b/net/mac80211/util.c
81894@@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
81895 }
81896 #endif
81897 /* everything else happens only if HW was up & running */
81898- if (!local->open_count)
81899+ if (!local_read(&local->open_count))
81900 goto wake_up;
81901
81902 /*
81903diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
81904index 49e96df..63a51c3 100644
81905--- a/net/netfilter/Kconfig
81906+++ b/net/netfilter/Kconfig
81907@@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
81908
81909 To compile it as a module, choose M here. If unsure, say N.
81910
81911+config NETFILTER_XT_MATCH_GRADM
81912+ tristate '"gradm" match support'
81913+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
81914+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
81915+ ---help---
81916+ The gradm match allows to match on grsecurity RBAC being enabled.
81917+ It is useful when iptables rules are applied early on bootup to
81918+ prevent connections to the machine (except from a trusted host)
81919+ while the RBAC system is disabled.
81920+
81921 config NETFILTER_XT_MATCH_HASHLIMIT
81922 tristate '"hashlimit" match support'
81923 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
81924diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
81925index 3259697..54d5393 100644
81926--- a/net/netfilter/Makefile
81927+++ b/net/netfilter/Makefile
81928@@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
81929 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
81930 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
81931 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
81932+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
81933 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
81934 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
81935 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
81936diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
81937index 30e764a..c3b6a9d 100644
81938--- a/net/netfilter/ipvs/ip_vs_conn.c
81939+++ b/net/netfilter/ipvs/ip_vs_conn.c
81940@@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
81941 /* Increase the refcnt counter of the dest */
81942 atomic_inc(&dest->refcnt);
81943
81944- conn_flags = atomic_read(&dest->conn_flags);
81945+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
81946 if (cp->protocol != IPPROTO_UDP)
81947 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
81948 flags = cp->flags;
81949@@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
81950 atomic_set(&cp->refcnt, 1);
81951
81952 atomic_set(&cp->n_control, 0);
81953- atomic_set(&cp->in_pkts, 0);
81954+ atomic_set_unchecked(&cp->in_pkts, 0);
81955
81956 atomic_inc(&ipvs->conn_count);
81957 if (flags & IP_VS_CONN_F_NO_CPORT)
81958@@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
81959
81960 /* Don't drop the entry if its number of incoming packets is not
81961 located in [0, 8] */
81962- i = atomic_read(&cp->in_pkts);
81963+ i = atomic_read_unchecked(&cp->in_pkts);
81964 if (i > 8 || i < 0) return 0;
81965
81966 if (!todrop_rate[i]) return 0;
81967diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
81968index 47edf5a..235b07d 100644
81969--- a/net/netfilter/ipvs/ip_vs_core.c
81970+++ b/net/netfilter/ipvs/ip_vs_core.c
81971@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
81972 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
81973 /* do not touch skb anymore */
81974
81975- atomic_inc(&cp->in_pkts);
81976+ atomic_inc_unchecked(&cp->in_pkts);
81977 ip_vs_conn_put(cp);
81978 return ret;
81979 }
81980@@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
81981 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
81982 pkts = sysctl_sync_threshold(ipvs);
81983 else
81984- pkts = atomic_add_return(1, &cp->in_pkts);
81985+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81986
81987 if (ipvs->sync_state & IP_VS_STATE_MASTER)
81988 ip_vs_sync_conn(net, cp, pkts);
81989diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
81990index ec664cb..cd576ab 100644
81991--- a/net/netfilter/ipvs/ip_vs_ctl.c
81992+++ b/net/netfilter/ipvs/ip_vs_ctl.c
81993@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
81994 ip_vs_rs_hash(ipvs, dest);
81995 write_unlock_bh(&ipvs->rs_lock);
81996 }
81997- atomic_set(&dest->conn_flags, conn_flags);
81998+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
81999
82000 /* bind the service */
82001 if (!dest->svc) {
82002@@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
82003 " %-7s %-6d %-10d %-10d\n",
82004 &dest->addr.in6,
82005 ntohs(dest->port),
82006- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
82007+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
82008 atomic_read(&dest->weight),
82009 atomic_read(&dest->activeconns),
82010 atomic_read(&dest->inactconns));
82011@@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
82012 "%-7s %-6d %-10d %-10d\n",
82013 ntohl(dest->addr.ip),
82014 ntohs(dest->port),
82015- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
82016+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
82017 atomic_read(&dest->weight),
82018 atomic_read(&dest->activeconns),
82019 atomic_read(&dest->inactconns));
82020@@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
82021
82022 entry.addr = dest->addr.ip;
82023 entry.port = dest->port;
82024- entry.conn_flags = atomic_read(&dest->conn_flags);
82025+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
82026 entry.weight = atomic_read(&dest->weight);
82027 entry.u_threshold = dest->u_threshold;
82028 entry.l_threshold = dest->l_threshold;
82029@@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
82030 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
82031 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
82032 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
82033- (atomic_read(&dest->conn_flags) &
82034+ (atomic_read_unchecked(&dest->conn_flags) &
82035 IP_VS_CONN_F_FWD_MASK)) ||
82036 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
82037 atomic_read(&dest->weight)) ||
82038diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
82039index 44fd10c..2a163b3 100644
82040--- a/net/netfilter/ipvs/ip_vs_sync.c
82041+++ b/net/netfilter/ipvs/ip_vs_sync.c
82042@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
82043 cp = cp->control;
82044 if (cp) {
82045 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
82046- pkts = atomic_add_return(1, &cp->in_pkts);
82047+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
82048 else
82049 pkts = sysctl_sync_threshold(ipvs);
82050 ip_vs_sync_conn(net, cp->control, pkts);
82051@@ -758,7 +758,7 @@ control:
82052 if (!cp)
82053 return;
82054 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
82055- pkts = atomic_add_return(1, &cp->in_pkts);
82056+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
82057 else
82058 pkts = sysctl_sync_threshold(ipvs);
82059 goto sloop;
82060@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
82061
82062 if (opt)
82063 memcpy(&cp->in_seq, opt, sizeof(*opt));
82064- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
82065+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
82066 cp->state = state;
82067 cp->old_state = cp->state;
82068 /*
82069diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
82070index ee6b7a9..f9a89f6 100644
82071--- a/net/netfilter/ipvs/ip_vs_xmit.c
82072+++ b/net/netfilter/ipvs/ip_vs_xmit.c
82073@@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
82074 else
82075 rc = NF_ACCEPT;
82076 /* do not touch skb anymore */
82077- atomic_inc(&cp->in_pkts);
82078+ atomic_inc_unchecked(&cp->in_pkts);
82079 goto out;
82080 }
82081
82082@@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
82083 else
82084 rc = NF_ACCEPT;
82085 /* do not touch skb anymore */
82086- atomic_inc(&cp->in_pkts);
82087+ atomic_inc_unchecked(&cp->in_pkts);
82088 goto out;
82089 }
82090
82091diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
82092index e4a0c4f..c263f28 100644
82093--- a/net/netfilter/nf_conntrack_core.c
82094+++ b/net/netfilter/nf_conntrack_core.c
82095@@ -1529,6 +1529,10 @@ err_extend:
82096 #define DYING_NULLS_VAL ((1<<30)+1)
82097 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
82098
82099+#ifdef CONFIG_GRKERNSEC_HIDESYM
82100+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
82101+#endif
82102+
82103 static int nf_conntrack_init_net(struct net *net)
82104 {
82105 int ret;
82106@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
82107 goto err_stat;
82108 }
82109
82110+#ifdef CONFIG_GRKERNSEC_HIDESYM
82111+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
82112+#else
82113 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
82114+#endif
82115 if (!net->ct.slabname) {
82116 ret = -ENOMEM;
82117 goto err_slabname;
82118diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
82119index 92fd8ec..3f6ea4b 100644
82120--- a/net/netfilter/nfnetlink_log.c
82121+++ b/net/netfilter/nfnetlink_log.c
82122@@ -72,7 +72,7 @@ struct nfulnl_instance {
82123 };
82124
82125 static DEFINE_SPINLOCK(instances_lock);
82126-static atomic_t global_seq;
82127+static atomic_unchecked_t global_seq;
82128
82129 #define INSTANCE_BUCKETS 16
82130 static struct hlist_head instance_table[INSTANCE_BUCKETS];
82131@@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
82132 /* global sequence number */
82133 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
82134 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
82135- htonl(atomic_inc_return(&global_seq))))
82136+ htonl(atomic_inc_return_unchecked(&global_seq))))
82137 goto nla_put_failure;
82138
82139 if (data_len) {
82140diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
82141new file mode 100644
82142index 0000000..c566332
82143--- /dev/null
82144+++ b/net/netfilter/xt_gradm.c
82145@@ -0,0 +1,51 @@
82146+/*
82147+ * gradm match for netfilter
82148